log database management actions in tests

Add log messages to show actions taken in tests to try to figure out why
some tests are leaving databases behind.

Change-Id: Ie742a7b34a8fd0614c27c06ed6f6805058b88336
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
Doug Hellmann 2018-01-30 12:43:28 -05:00
parent 0b50d5752e
commit ccce5ef454
1 changed files with 7 additions and 1 deletions

View File

@ -44,6 +44,7 @@ _DB_CACHE = None
logging.register_options(CONF)
logging.setup(CONF, 'storyboard')
LOG = logging.getLogger(__name__)
class TestCase(testtools.TestCase):
@ -143,6 +144,7 @@ class DbTestCase(WorkingDirTestCase):
def setup_db(self):
self.db_name = "storyboard_test_db_%s" % uuid.uuid4()
self.db_name = self.db_name.replace("-", "_")
LOG.info('creating database %s', self.db_name)
# The engine w/o db name
engine = sqlalchemy.create_engine(
@ -163,7 +165,11 @@ class DbTestCase(WorkingDirTestCase):
def _drop_db(self):
engine = sqlalchemy.create_engine(
self.test_connection)
engine.execute("DROP DATABASE %s" % self.db_name)
try:
engine.execute("DROP DATABASE %s" % self.db_name)
except Exception as err:
LOG.error('failed to drop database %s: %s',
self.db_name, err)
db_api_base.cleanup()
PATH_PREFIX = '/v1'