From 740bbf81bc5f8a8ff2e8b2e55152fd56b19fb372 Mon Sep 17 00:00:00 2001 From: Ifat Afek Date: Sun, 8 Oct 2017 12:54:49 +0000 Subject: [PATCH] Add exception handling to the DBHook. In some cases (not sure when), get_connection_from_config fails to get the url. Since the DB support is still WIP, for now just catch the exception and don't fail the entire API call. Note: after applying this patch on a devstack, make sure to run: sudo service apache2 restart Change-Id: I81c062266e04ae8c11d5ac2897e1779800c69c77 --- vitrage/storage/__init__.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/vitrage/storage/__init__.py b/vitrage/storage/__init__.py index c9a7d8947..d5d26709a 100644 --- a/vitrage/storage/__init__.py +++ b/vitrage/storage/__init__.py @@ -29,10 +29,17 @@ OPTS = [] def get_connection_from_config(conf): retries = conf.database.max_retries url = conf.database.connection - connection_scheme = urlparse.urlparse(url).scheme - LOG.debug('looking for %(name)r driver in %(namespace)r', - {'name': connection_scheme, 'namespace': _NAMESPACE}) - mgr = driver.DriverManager(_NAMESPACE, connection_scheme) + + try: + # TOTO(iafek): check why this call randomly fails + connection_scheme = urlparse.urlparse(url).scheme + LOG.debug('looking for %(name)r driver in %(namespace)r', + {'name': connection_scheme, 'namespace': _NAMESPACE}) + mgr = driver.DriverManager(_NAMESPACE, connection_scheme) + + except Exception as e: + LOG.exception('Failed to get scheme %s. Exception: %s ', str(url), e) + return None @tenacity.retry( wait=tenacity.wait_fixed(conf.database.retry_interval),