Prevent races in opportunistic db test cases

Previously opportunistic db test cases used to share openstack_citest
database among all test cases, which could be run concurrently in
different test running processes.

With recent changes made to our CI, we now can create and drop
database schemas on demand in tests. Providing each opportunistic db
test case with its own DB will effectively prevent possible races.

Related-Bug: #1288916

Change-Id: I7f6e272eaeb776b6a645ba502853892e79312afd
This commit is contained in:
Roman Podoliaka 2014-02-19 15:38:23 +02:00
parent 4f638de853
commit b5e4815563
1 changed files with 21 additions and 9 deletions

View File

@ -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,