From 44b2f5e70409b778f6f8bdd5a711f8a026aa44ea Mon Sep 17 00:00:00 2001 From: Vladyslav Drok Date: Fri, 1 Jun 2018 14:07:22 +0300 Subject: [PATCH] Commit DB changes on API startup During API startup we initialize secret stores, which should be populating secret_stores table. Story: 2002137 Task: 19827 Change-Id: I4272c00b64714347bdf048124e0bfaadbb3b7237 --- barbican/api/app.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/barbican/api/app.py b/barbican/api/app.py index 251f3debc..8f423c694 100644 --- a/barbican/api/app.py +++ b/barbican/api/app.py @@ -74,21 +74,28 @@ def main_app(func): # Configure oslo logging and configuration services. log.setup(CONF, 'barbican') + LOG = log.getLogger(__name__) config.setup_remote_pydev_debug() # Initializing the database engine and session factory before the app # starts ensures we don't lose requests due to lazy initialization of # db connections. - repositories.setup_database_engine_and_factory( - initialize_secret_stores=True - ) + try: + repositories.setup_database_engine_and_factory( + initialize_secret_stores=True + ) + repositories.commit() + except Exception: + LOG.exception('Failed to sync secret_stores table.') + repositories.rollback() + raise wsgi_app = func(global_config, **local_conf) if newrelic_loaded: wsgi_app = newrelic.agent.WSGIApplicationWrapper(wsgi_app) - LOG = log.getLogger(__name__) + LOG.info('Barbican app created and initialized') return wsgi_app return _wrapper