Bugfix: Overcome mysql failure during Vitrage init.

Test the connection to detect mysql failures before executing statements.
It is better to fail early because at that point we have retries.

Backported from train

Change-Id: I14a2fb643d04cad2f6ef3ab7a80b7e7c63224f74
This commit is contained in:
Idan Hefetz 2020-03-30 09:30:15 +00:00
parent f9117c8410
commit 66b6dd4879
1 changed files with 6 additions and 2 deletions

View File

@ -45,11 +45,15 @@ def get_connection_from_config(conf):
@tenacity.retry(
wait=tenacity.wait_fixed(conf.database.retry_interval),
stop=tenacity.stop_after_attempt(retries if retries >= 0 else 5),
stop=tenacity.stop_after_attempt(retries),
after=tenacity.after_log(LOG, log.WARN),
reraise=True)
def _get_connection():
"""Return an open connection to the database."""
return mgr.driver(conf, url)
conn = mgr.driver(conf, url)
session = conn._engine_facade.get_session()
session.execute('SELECT 1;')
return conn
return _get_connection()