Skip to content

Commit

Permalink
Ensure functional db connection in configure_db()
Browse files Browse the repository at this point in the history
During initial database setup, ensure we can physically connect
to the database and allow a failed connection to make use of the
new retry mechanism instead of registry startup failing outright.

Fixes lp bug #959426.

Change-Id: I1c87b19913c4204465e5d2027f2f184f0f358fd0
  • Loading branch information
Adam Gandelman committed Mar 24, 2012
1 parent 2d36fac commit 12757d7
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion glance/registry/db/api.py
Expand Up @@ -91,6 +91,8 @@ def configure_db(conf):
try:
_ENGINE = create_engine(sql_connection, **engine_args)
_ENGINE.create = wrap_db_error(_ENGINE.create)
_ENGINE.connect = wrap_db_error(_ENGINE.connect)
_ENGINE.connect()
except Exception, err:
msg = _("Error configuring registry database with supplied "
"sql_connection '%(sql_connection)s'. "
Expand Down Expand Up @@ -137,7 +139,9 @@ def get_session(autocommit=True, expire_on_commit=False):

def is_db_connection_error(args):
"""Return True if error in connecting to db."""
conn_err_codes = ('2002', '2006')
# NOTE(adam_g): This is currently MySQL specific and needs to be extended
# to support Postgres and others.
conn_err_codes = ('2002', '2003', '2006')
for err_code in conn_err_codes:
if args.find(err_code) != -1:
return True
Expand Down

0 comments on commit 12757d7

Please sign in to comment.