diff options
author | Jenkins <jenkins@review.openstack.org> | 2014-07-23 15:06:21 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2014-07-23 15:06:21 +0000 |
commit | 548090f500cfe5b08fe3d77589572c208e1a3ee9 (patch) | |
tree | c58525ce183a7cc8aee5b1d7c39fe3deae8ad463 | |
parent | 1814bf80cd9ce332370833ec4dc8b2feed6120a1 (diff) | |
parent | b69899e1ba519c3a5dc2db2e1c04d1eb50519114 (diff) | |
download | oslo-db-548090f500cfe5b08fe3d77589572c208e1a3ee9.tar.gz |
Merge "Add host argument to get_connect_string()"
-rw-r--r-- | oslo/db/sqlalchemy/utils.py | 6 | ||||
-rw-r--r-- | tests/sqlalchemy/test_utils.py | 5 |
2 files changed, 9 insertions, 2 deletions
diff --git a/oslo/db/sqlalchemy/utils.py b/oslo/db/sqlalchemy/utils.py index a58b1bf..5aa9341 100644 --- a/oslo/db/sqlalchemy/utils.py +++ b/oslo/db/sqlalchemy/utils.py @@ -656,7 +656,8 @@ def _change_deleted_column_type_to_id_type_sqlite(migrate_engine, table_name, execute() -def get_connect_string(backend, database, user=None, passwd=None): +def get_connect_string(backend, database, user=None, passwd=None, + host='localhost'): """Get database connection Try to get a connection with a very specific set of values, if we get @@ -665,11 +666,12 @@ def get_connect_string(backend, database, user=None, passwd=None): args = {'backend': backend, 'user': user, 'passwd': passwd, + 'host': host, 'database': database} if backend == 'sqlite': template = '%(backend)s:///%(database)s' else: - template = "%(backend)s://%(user)s:%(passwd)s@localhost/%(database)s" + template = "%(backend)s://%(user)s:%(passwd)s@%(host)s/%(database)s" return template % args diff --git a/tests/sqlalchemy/test_utils.py b/tests/sqlalchemy/test_utils.py index 431fdb3..231d106 100644 --- a/tests/sqlalchemy/test_utils.py +++ b/tests/sqlalchemy/test_utils.py @@ -685,6 +685,11 @@ class TestConnectionUtils(test_utils.BaseTestCase): self.assertEqual(utils.get_db_connection_info(conn_pieces), ('dude', 'pass', 'test', 'localhost')) + def test_connect_string_host(self): + self.full_credentials['host'] = 'myhost' + connect_string = utils.get_connect_string(**self.full_credentials) + self.assertEqual(connect_string, 'mysql://dude:pass@myhost/test') + class MyModelSoftDeletedProjectId(declarative_base(), models.ModelBase, models.SoftDeleteMixin): |