Remove method get_connect_string and is_backend_avail

method get_connect_string  is deprecated and will be removed
from oslo_db in a few releases.Please use the provisioning
system for dealing with URLs and database provisioning.

method is_backend_avail  is deprecated and will be removed
from oslo_db in a few releases.Please use the provisioning
system to access databases based on backend availability.

Change-Id: Idc27d45e96aad7b28b4332b0d8ab8c10bca73e67
This commit is contained in:
zhangyangyang 2017-10-11 17:17:18 +08:00
parent e2fa4c2246
commit 73e72f6cc2
2 changed files with 0 additions and 81 deletions

View File

@ -711,54 +711,6 @@ def _change_deleted_column_type_to_id_type_sqlite(engine, table_name,
execute()
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
these then we'll run the tests, otherwise they are skipped
DEPRECATED: this function is deprecated and will be removed from oslo_db
in a few releases. Please use the provisioning system for dealing
with URLs and database provisioning.
"""
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@%(host)s/%(database)s"
return template % args
def is_backend_avail(backend, database, user=None, passwd=None):
"""Return True if the given backend is available.
DEPRECATED: this function is deprecated and will be removed from oslo_db
in a few releases. Please use the provisioning system to access
databases based on backend availability.
"""
from oslo_db.sqlalchemy import provision
connect_uri = get_connect_string(backend=backend,
database=database,
user=user,
passwd=passwd)
try:
eng = provision.Backend._ensure_backend_available(connect_uri)
eng.dispose()
except exception.BackendNotAvailable:
return False
else:
return True
def get_db_connection_info(conn_pieces):
database = conn_pieces.path.strip('/')
loc_pieces = conn_pieces.netloc.split('@')

View File

@ -992,34 +992,6 @@ class TestConnectionUtils(test_utils.BaseTestCase):
patch_onconnect.start()
self.addCleanup(patch_onconnect.stop)
def test_connect_string(self):
connect_string = utils.get_connect_string(**self.full_credentials)
self.assertEqual(self.connect_string, connect_string)
def test_connect_string_sqlite(self):
sqlite_credentials = {'backend': 'sqlite', 'database': 'test.db'}
connect_string = utils.get_connect_string(**sqlite_credentials)
self.assertEqual('sqlite:///test.db', connect_string)
def test_is_backend_avail(self):
self.mox.StubOutWithMock(sqlalchemy.engine.base.Engine, 'connect')
fake_connection = self.mox.CreateMockAnything()
fake_connection.close()
sqlalchemy.engine.base.Engine.connect().AndReturn(fake_connection)
self.mox.ReplayAll()
self.assertTrue(utils.is_backend_avail(**self.full_credentials))
def test_is_backend_unavail(self):
log = self.useFixture(fixtures.FakeLogger())
err = OperationalError("Can't connect to database", None, None)
error_msg = "The postgresql backend is unavailable: %s\n" % err
self.mox.StubOutWithMock(sqlalchemy.engine.base.Engine, 'connect')
sqlalchemy.engine.base.Engine.connect().AndRaise(err)
self.mox.ReplayAll()
self.assertFalse(utils.is_backend_avail(**self.full_credentials))
self.assertEqual(error_msg, log.output)
def test_ensure_backend_available(self):
self.mox.StubOutWithMock(sqlalchemy.engine.base.Engine, 'connect')
fake_connection = self.mox.CreateMockAnything()
@ -1073,11 +1045,6 @@ class TestConnectionUtils(test_utils.BaseTestCase):
self.assertEqual(('dude', 'pass', 'test', 'localhost'),
utils.get_db_connection_info(conn_pieces))
def test_connect_string_host(self):
self.full_credentials['host'] = 'myhost'
connect_string = utils.get_connect_string(**self.full_credentials)
self.assertEqual('postgresql://dude:pass@myhost/test', connect_string)
class MyModelSoftDeletedProjectId(declarative_base(), models.ModelBase,
models.SoftDeleteMixin):