Use string interpolation so it's easier to test it, correctly log used
which will be used.
@@ -82,6 +82,12 @@ def db_setup(db_name, db_host, db_port, username=None, password=None, ensure_ind
# Hostname is provided as a URI string. Make sure we don't log the password in case one is
# included as part of the URI string.
uri_dict = uri_parser.parse_uri(db_host)
+ username_string = uri_dict.get('username', username) or username
+
+ if uri_dict.get('username', None) and username:
+ # Username argument has precedence over connection string username
+ username_string = username
+
hostnames = get_host_names_for_uri_dict(uri_dict=uri_dict)
if len(uri_dict['nodelist']) > 1:
@@ -90,9 +96,10 @@ def db_setup(db_name, db_host, db_port, username=None, password=None, ensure_ind
host_string = hostnames
else:
host_string = '%s:%s' % (db_host, db_port)
+ username_string = username
- LOG.info('Connecting to database "%s" @ "%s" as user "%s".', db_name, host_string,
- str(username))
+ LOG.info('Connecting to database "%s" @ "%s" as user "%s".' % (db_name, host_string,
+ str(username_string)))
ssl_kwargs = _get_ssl_kwargs(ssl=ssl, ssl_keyfile=ssl_keyfile, ssl_certfile=ssl_certfile,
ssl_cert_reqs=ssl_cert_reqs, ssl_ca_certs=ssl_ca_certs,
