Handle case where oslo_db.tests has not been imported

It seems possible to use the connection_trace functionality
without having 'oslo_db.tests' be loaded so it seems like
the code here should be handling that module not being loaded
and the associated key error that is raised when it fails.

Change-Id: I6ef05ff83365ce0b86ec72a444e714f7a29c91c8
Closes-Bug: #1493675
This commit is contained in:
Joshua Harlow 2015-09-08 23:19:06 -07:00
parent 9c709ef38a
commit e501a565ae
1 changed files with 6 additions and 3 deletions

View File

@ -377,9 +377,12 @@ def _add_trace_comments(engine):
os.path.dirname(sys.modules['oslo_db'].__file__),
os.path.dirname(sys.modules['sqlalchemy'].__file__)
])
skip_paths = set([
os.path.dirname(sys.modules['oslo_db.tests'].__file__),
])
try:
skip_paths = set([
os.path.dirname(sys.modules['oslo_db.tests'].__file__),
])
except KeyError:
skip_paths = set()
@sqlalchemy.event.listens_for(engine, "before_cursor_execute", retval=True)
def before_cursor_execute(conn, cursor, statement, parameters, context,