[LNT] r311708 - Unify SQL logging

Matthias Braun via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 24 14:56:33 PDT 2017


Author: matze
Date: Thu Aug 24 14:56:32 2017
New Revision: 311708

URL: http://llvm.org/viewvc/llvm-project?rev=311708&view=rev
Log:
Unify SQL logging

Some code was using init_logger(show_sql=True), while other code was
passing echo=True to the V4DB constructor to get logging SQL statement
logging. This patch switches everything to the init_logger() variant and
removes the echo parameter from V4DB.

Modified:
    lnt/trunk/lnt/lnttool/import_data.py
    lnt/trunk/lnt/lnttool/updatedb.py
    lnt/trunk/lnt/server/config.py
    lnt/trunk/lnt/server/db/v4db.py
    lnt/trunk/lnt/server/ui/app.py
    lnt/trunk/tests/lnttool/PostgresDB.shtest
    lnt/trunk/tests/lnttool/UpdateDB.py
    lnt/trunk/tests/server/db/CreateV4TestSuite.py
    lnt/trunk/tests/server/db/CreateV4TestSuiteInstance.py
    lnt/trunk/tests/server/db/ImportV4TestSuiteInstance.py
    lnt/trunk/tests/server/db/search.py
    lnt/trunk/tests/server/ui/change_processing.py

Modified: lnt/trunk/lnt/lnttool/import_data.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/lnttool/import_data.py?rev=311708&r1=311707&r2=311708&view=diff
==============================================================================
--- lnt/trunk/lnt/lnttool/import_data.py (original)
+++ lnt/trunk/lnt/lnttool/import_data.py Thu Aug 24 14:56:32 2017
@@ -33,15 +33,15 @@ def action_import(instance_path, files,
     import logging
     from .common import init_logger
 
-    init_logger(logging.WARNING)
+    init_logger(logging.INFO if show_sql else logging.WARNING,
+                show_sql=show_sql)
 
     # Load the LNT instance.
     instance = lnt.server.instance.Instance.frompath(instance_path)
     config = instance.config
 
     # Get the database.
-    with contextlib.closing(config.get_database(database,
-                                                echo=show_sql)) as db:
+    with contextlib.closing(config.get_database(database)) as db:
         # Load the database.
         success = True
         for file_name in files:

Modified: lnt/trunk/lnt/lnttool/updatedb.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/lnttool/updatedb.py?rev=311708&r1=311707&r2=311708&view=diff
==============================================================================
--- lnt/trunk/lnt/lnttool/updatedb.py (original)
+++ lnt/trunk/lnt/lnttool/updatedb.py Thu Aug 24 14:56:32 2017
@@ -21,16 +21,20 @@ import click
 def action_updatedb(instance_path, database, testsuite, tmp_dir, commit,
                     show_sql, delete_machines, delete_runs, delete_order):
     """modify a database"""
+    from .common import init_logger
     from lnt.util import logger
     import contextlib
     import lnt.server.instance
+    import logging
+
+    init_logger(logging.INFO if show_sql else logging.WARNING,
+                show_sql=show_sql)
 
     # Load the instance.
     instance = lnt.server.instance.Instance.frompath(instance_path)
 
     # Get the database and test suite.
-    with contextlib.closing(instance.get_database(database,
-                                                  echo=show_sql)) as db:
+    with contextlib.closing(instance.get_database(database)) as db:
         ts = db.testsuite[testsuite]
         order = None
         # Compute a list of all the runs to delete.

Modified: lnt/trunk/lnt/server/config.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/config.py?rev=311708&r1=311707&r2=311708&view=diff
==============================================================================
--- lnt/trunk/lnt/server/config.py (original)
+++ lnt/trunk/lnt/server/config.py Thu Aug 24 14:56:32 2017
@@ -175,9 +175,9 @@ class Config:
             db.config = self
         self.api_auth_token = api_auth_token
 
-    def get_database(self, name, echo=False):
+    def get_database(self, name):
         """
-        get_database(name, echo=False) -> db or None
+        get_database(name) -> db or None
 
         Return the appropriate instance of the database with the given name, or
         None if there is no database with that name."""
@@ -190,8 +190,7 @@ class Config:
         # Instantiate the appropriate database version.
         if db_entry.db_version == '0.4':
             return lnt.server.db.v4db.V4DB(db_entry.path, self,
-                                           db_entry.baseline_revision,
-                                           echo)
+                                           db_entry.baseline_revision)
 
         raise NotImplementedError("unable to load version %r database" % (
             db_entry.db_version))

Modified: lnt/trunk/lnt/server/db/v4db.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/db/v4db.py?rev=311708&r1=311707&r2=311708&view=diff
==============================================================================
--- lnt/trunk/lnt/server/db/v4db.py (original)
+++ lnt/trunk/lnt/server/db/v4db.py Thu Aug 24 14:56:32 2017
@@ -108,7 +108,7 @@ class V4DB(object):
                 logger.error("Could not load schema '%s'" % schema_file,
                              exc_info=True)
 
-    def __init__(self, path, config, baseline_revision=0, echo=False):
+    def __init__(self, path, config, baseline_revision=0):
         # If the path includes no database type, assume sqlite.
         if lnt.server.db.util.path_has_no_database_type(path):
             path = 'sqlite:///' + path
@@ -116,7 +116,6 @@ class V4DB(object):
         self.path = path
         self.config = config
         self.baseline_revision = baseline_revision
-        self.echo = echo
         with V4DB._engine_lock:
             if path not in V4DB._engine:
                 connect_args = {}
@@ -125,7 +124,7 @@ class V4DB(object):
                     # open for a long time. Make it less likely to hit
                     # "(OperationalError) database is locked" because of that.
                     connect_args['timeout'] = 30
-                engine = sqlalchemy.create_engine(path, echo=echo,
+                engine = sqlalchemy.create_engine(path,
                                                   connect_args=connect_args)
                 V4DB._engine[path] = engine
         self.engine = V4DB._engine[path]
@@ -177,10 +176,11 @@ class V4DB(object):
 
     def settings(self):
         """All the setting needed to recreate this instnace elsewhere."""
-        return {'path': self.path,
-                'config': self.config,
-                'baseline_revision': self.baseline_revision,
-                'echo': self.echo}
+        return {
+            'path': self.path,
+            'config': self.config,
+            'baseline_revision': self.baseline_revision,
+        }
 
     @property
     def testsuite(self):

Modified: lnt/trunk/lnt/server/ui/app.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/ui/app.py?rev=311708&r1=311707&r2=311708&view=diff
==============================================================================
--- lnt/trunk/lnt/server/ui/app.py (original)
+++ lnt/trunk/lnt/server/ui/app.py Thu Aug 24 14:56:32 2017
@@ -99,17 +99,15 @@ class Request(flask.Request):
         """
 
         if self.db is None:
-            echo = bool(self.args.get('db_log') or self.form.get('db_log'))
             try:
-                self.db = current_app.old_config.get_database(g.db_name,
-                                                              echo=echo)
+                self.db = current_app.old_config.get_database(g.db_name)
             except DatabaseError:
-                self.db = current_app.old_config.get_database(g.db_name,
-                                                              echo=echo)
+                self.db = current_app.old_config.get_database(g.db_name)
             # Enable SQL logging with db_log.
             #
             # FIXME: Conditionalize on an is_production variable.
-            if echo:
+            show_sql = bool(self.args.get('db_log') or self.form.get('db_log'))
+            if show_sql:
                 g.db_log = StringIO.StringIO()
                 logger = logging.getLogger("sqlalchemy")
                 logger.addHandler(logging.StreamHandler(g.db_log))

Modified: lnt/trunk/tests/lnttool/PostgresDB.shtest
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/tests/lnttool/PostgresDB.shtest?rev=311708&r1=311707&r2=311708&view=diff
==============================================================================
--- lnt/trunk/tests/lnttool/PostgresDB.shtest (original)
+++ lnt/trunk/tests/lnttool/PostgresDB.shtest Thu Aug 24 14:56:32 2017
@@ -21,7 +21,7 @@ lnt import "${TESTDIR}/instance" "${SHAR
 # default.
 #
 lnt updatedb "${TESTDIR}/instance" --testsuite nts --delete-run 1 \
-	--commit --show-sql > "${TESTDIR}/runrm.out"
+	--commit --show-sql >& "${TESTDIR}/runrm.out"
 # RUN: FileCheck --check-prefix CHECK-RUNRM %s < "%t.install/runrm.out"
 
 # CHECK-RUNRM: DELETE FROM "NT_Sample" WHERE "NT_Sample"."ID" = %(ID)s
@@ -37,7 +37,7 @@ lnt import "${TESTDIR}/instance" "${SHAR
 #
 lnt updatedb "${TESTDIR}/instance" --testsuite nts \
 	--delete-machine "LNT SAMPLE MACHINE" --commit \
-	--show-sql > "${TESTDIR}/machinerm.out"
+	--show-sql >& "${TESTDIR}/machinerm.out"
 # RUN: FileCheck --check-prefix CHECK-MACHINERM %s < "%t.install/machinerm.out"
 
 # CHECK-MACHINERM: DELETE FROM "NT_Sample" WHERE "NT_Sample"."ID" = %(ID)s

Modified: lnt/trunk/tests/lnttool/UpdateDB.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/tests/lnttool/UpdateDB.py?rev=311708&r1=311707&r2=311708&view=diff
==============================================================================
--- lnt/trunk/tests/lnttool/UpdateDB.py (original)
+++ lnt/trunk/tests/lnttool/UpdateDB.py Thu Aug 24 14:56:32 2017
@@ -9,7 +9,7 @@
 # default.
 #
 # RUN: lnt updatedb %t.install --testsuite nts \
-# RUN:     --commit --delete-run 1 --show-sql > %t.out
+# RUN:     --commit --delete-run 1 --show-sql >& %t.out
 # RUN: FileCheck --check-prefix CHECK-RUNRM %s < %t.out
 
 # CHECK-RUNRM: DELETE FROM "NT_Sample" WHERE "NT_Sample"."ID" = ?
@@ -25,7 +25,7 @@
 # RUN: lnt import %t.install %{shared_inputs}/sample-a-small.plist \
 # RUN:     --commit --show-sample-count
 # RUN: lnt updatedb %t.install --testsuite nts \
-# RUN:     --delete-machine "LNT SAMPLE MACHINE" --commit --show-sql > %t.out
+# RUN:     --delete-machine "LNT SAMPLE MACHINE" --commit --show-sql >& %t.out
 # RUN: FileCheck --check-prefix CHECK-MACHINERM %s < %t.out
 
 # CHECK-MACHINERM: DELETE FROM "NT_Sample" WHERE "NT_Sample"."ID" = ?

Modified: lnt/trunk/tests/server/db/CreateV4TestSuite.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/tests/server/db/CreateV4TestSuite.py?rev=311708&r1=311707&r2=311708&view=diff
==============================================================================
--- lnt/trunk/tests/server/db/CreateV4TestSuite.py (original)
+++ lnt/trunk/tests/server/db/CreateV4TestSuite.py Thu Aug 24 14:56:32 2017
@@ -11,7 +11,7 @@ from lnt.server.db import testsuite
 from lnt.server.db import v4db
 
 # Create an in memory database.
-db = v4db.V4DB("sqlite:///:memory:", Config.dummy_instance(), echo=True)
+db = v4db.V4DB("sqlite:///:memory:", Config.dummy_instance())
 
 # We expect exactly the NTS test suite.
 test_suites = list(db.query(testsuite.TestSuite))

Modified: lnt/trunk/tests/server/db/CreateV4TestSuiteInstance.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/tests/server/db/CreateV4TestSuiteInstance.py?rev=311708&r1=311707&r2=311708&view=diff
==============================================================================
--- lnt/trunk/tests/server/db/CreateV4TestSuiteInstance.py (original)
+++ lnt/trunk/tests/server/db/CreateV4TestSuiteInstance.py Thu Aug 24 14:56:32 2017
@@ -11,7 +11,7 @@ from lnt.server.db import v4db
 from lnt.server.db.fieldchange import RegressionState
 
 # Create an in memory database.
-db = v4db.V4DB("sqlite:///:memory:", Config.dummy_instance(), echo=True)
+db = v4db.V4DB("sqlite:///:memory:", Config.dummy_instance())
 
 # Get the test suite wrapper.
 ts_db = db.testsuite['nts']

Modified: lnt/trunk/tests/server/db/ImportV4TestSuiteInstance.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/tests/server/db/ImportV4TestSuiteInstance.py?rev=311708&r1=311707&r2=311708&view=diff
==============================================================================
--- lnt/trunk/tests/server/db/ImportV4TestSuiteInstance.py (original)
+++ lnt/trunk/tests/server/db/ImportV4TestSuiteInstance.py Thu Aug 24 14:56:32 2017
@@ -69,7 +69,7 @@ from lnt.server.db import testsuite
 from lnt.server.db import v4db
 
 # Load the test database.
-db = v4db.V4DB("sqlite:///%s" % sys.argv[1], Config.dummy_instance(), echo=True)
+db = v4db.V4DB("sqlite:///%s" % sys.argv[1], Config.dummy_instance())
 
 # Get the status kinds, and validate the IDs align with the testing IDs.
 pass_kind = db.query(db.StatusKind).filter_by(id = lnt.testing.PASS).one()

Modified: lnt/trunk/tests/server/db/search.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/tests/server/db/search.py?rev=311708&r1=311707&r2=311708&view=diff
==============================================================================
--- lnt/trunk/tests/server/db/search.py (original)
+++ lnt/trunk/tests/server/db/search.py Thu Aug 24 14:56:32 2017
@@ -31,7 +31,7 @@ class SearchTest(unittest.TestCase):
                          ('supermachine', '7623')]
         
         # Get the database.
-        self.db = config.get_database('default', echo=False)
+        self.db = config.get_database('default')
         # Load the database.
         for r in imported_runs:
             with tempfile.NamedTemporaryFile() as f:

Modified: lnt/trunk/tests/server/ui/change_processing.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/tests/server/ui/change_processing.py?rev=311708&r1=311707&r2=311708&view=diff
==============================================================================
--- lnt/trunk/tests/server/ui/change_processing.py (original)
+++ lnt/trunk/tests/server/ui/change_processing.py Thu Aug 24 14:56:32 2017
@@ -35,7 +35,7 @@ class ChangeProcessingTests(unittest.Tes
     def setUp(self):
         """Bind to the LNT test instance."""
 
-        self.db = v4db.V4DB("sqlite:///:memory:", Config.dummy_instance(), echo=False)
+        self.db = v4db.V4DB("sqlite:///:memory:", Config.dummy_instance())
 
         # Get the test suite wrapper.
         ts_db = self.ts_db = self.db.testsuite['nts']




More information about the llvm-commits mailing list