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
This commit is contained in:
Ifat Afek 2017-10-08 12:54:49 +00:00
parent 0602dd5eaf
commit 740bbf81bc
1 changed files with 11 additions and 4 deletions

View File

@ -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),