diff --git a/openstack/common/db/sqlalchemy/test_base.py b/openstack/common/db/sqlalchemy/test_base.py index e994fe76..ac36e872 100644 --- a/openstack/common/db/sqlalchemy/test_base.py +++ b/openstack/common/db/sqlalchemy/test_base.py @@ -21,9 +21,9 @@ import fixtures from oslotest import base as test_base import six +from openstack.common.db.sqlalchemy import provision from openstack.common.db.sqlalchemy import session from openstack.common.db.sqlalchemy import utils -from openstack.common.fixture import lockutils class DbFixture(fixtures.Fixture): @@ -43,12 +43,14 @@ class DbFixture(fixtures.Fixture): self.test = test + def cleanUp(self): + self.test.engine.dispose() + def setUp(self): super(DbFixture, self).setUp() self.test.engine = session.create_engine(self._get_uri()) self.test.sessionmaker = session.get_maker(self.test.engine) - self.addCleanup(self.test.engine.dispose) class DbTestCase(test_base.BaseTestCase): @@ -103,11 +105,24 @@ class OpportunisticFixture(DbFixture): DRIVER = abc.abstractproperty(lambda: None) DBNAME = PASSWORD = USERNAME = 'openstack_citest' + def setUp(self): + self._provisioning_engine = provision.get_engine( + utils.get_connect_string(backend=self.DRIVER, + user=self.USERNAME, + passwd=self.PASSWORD, + database=self.DBNAME) + ) + self._uri = provision.create_database(self._provisioning_engine) + + super(OpportunisticFixture, self).setUp() + + def cleanUp(self): + super(OpportunisticFixture, self).cleanUp() + + provision.drop_database(self._provisioning_engine, self._uri) + def _get_uri(self): - return utils.get_connect_string(backend=self.DRIVER, - user=self.USERNAME, - passwd=self.PASSWORD, - database=self.DBNAME) + return self._uri @six.add_metaclass(abc.ABCMeta) @@ -121,9 +136,6 @@ class OpportunisticTestCase(DbTestCase): FIXTURE = abc.abstractproperty(lambda: None) def setUp(self): - # TODO(bnemec): Remove this once infra is ready for - # https://review.openstack.org/#/c/74963/ to merge. - self.useFixture(lockutils.LockFixture('opportunistic-db')) credentials = { 'backend': self.FIXTURE.DRIVER, 'user': self.FIXTURE.USERNAME,