ensure DatabaseFixture removes db on cleanup
The DatabaseFixture was previously just ensuring that tests which used it had a clean database when they started. It did not ensure there was no working database around when it wasn't being used, so tests which leaked into the database might pass even if they were listed as a NoDBTest, because there was an in memory test db from a prior run. This adds a cleanup path to the fixture which blows away the db at the end of the test (which itself is tested). There were 46 tests which failed when we got this isolation correct, and this changes all those test classes containing those tests to require a db. Many of these could have narrower fixes, but this returns us to an isolated state. Change-Id: Id0480035d8e615ae602da9737cd2c94bc7967067 Closes-Bug: #1431519 Closes-Bug: #1431551
This commit is contained in:
parent
42a800e796
commit
c943cbbc40
|
@ -199,6 +199,10 @@ class Database(fixtures.Fixture):
|
|||
DB_SCHEMA = "".join(line for line in conn.connection.iterdump())
|
||||
engine.dispose()
|
||||
|
||||
def cleanup(self):
|
||||
engine = session.get_engine()
|
||||
engine.dispose()
|
||||
|
||||
def reset(self):
|
||||
self._cache_schema()
|
||||
engine = session.get_engine()
|
||||
|
@ -209,6 +213,7 @@ class Database(fixtures.Fixture):
|
|||
def setUp(self):
|
||||
super(Database, self).setUp()
|
||||
self.reset()
|
||||
self.addCleanup(self.cleanup)
|
||||
|
||||
|
||||
class RPCFixture(fixtures.Fixture):
|
||||
|
|
|
@ -18,7 +18,7 @@ from nova import objects
|
|||
from nova import test
|
||||
|
||||
|
||||
class EC2UtilsTestCase(test.NoDBTestCase):
|
||||
class EC2UtilsTestCase(test.TestCase):
|
||||
def setUp(self):
|
||||
self.ctxt = context.get_admin_context()
|
||||
ec2utils.reset_cache()
|
||||
|
|
|
@ -36,7 +36,7 @@ from nova.tests.unit import matchers
|
|||
CONF = cfg.CONF
|
||||
|
||||
|
||||
class BlockDeviceMappingTestV21(test.NoDBTestCase):
|
||||
class BlockDeviceMappingTestV21(test.TestCase):
|
||||
validation_error = exception.ValidationError
|
||||
|
||||
def _setup_controller(self):
|
||||
|
|
|
@ -34,7 +34,7 @@ from nova.tests.unit.image import fake
|
|||
CONF = cfg.CONF
|
||||
|
||||
|
||||
class BlockDeviceMappingTestV21(test.NoDBTestCase):
|
||||
class BlockDeviceMappingTestV21(test.TestCase):
|
||||
validation_error = exception.ValidationError
|
||||
|
||||
def _setup_controller(self):
|
||||
|
|
|
@ -45,7 +45,7 @@ from nova import utils
|
|||
FAKE_UUID = 'a47ae74e-ab08-547f-9eee-ffd23fc46c16'
|
||||
|
||||
|
||||
class NetworkPolicyTestCase(test.NoDBTestCase):
|
||||
class NetworkPolicyTestCase(test.TestCase):
|
||||
def setUp(self):
|
||||
super(NetworkPolicyTestCase, self).setUp()
|
||||
|
||||
|
|
|
@ -3301,7 +3301,7 @@ class FloatingIPTestCase(test.TestCase):
|
|||
'public'))
|
||||
|
||||
|
||||
class InstanceDNSTestCase(test.NoDBTestCase):
|
||||
class InstanceDNSTestCase(test.TestCase):
|
||||
"""Tests nova.network.manager instance DNS."""
|
||||
def setUp(self):
|
||||
super(InstanceDNSTestCase, self).setUp()
|
||||
|
|
|
@ -193,7 +193,7 @@ class TestNeutronClient(test.NoDBTestCase):
|
|||
self.assertEqual('new_token1', token_store.admin_auth_token)
|
||||
|
||||
|
||||
class TestNeutronv2Base(test.NoDBTestCase):
|
||||
class TestNeutronv2Base(test.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestNeutronv2Base, self).setUp()
|
||||
|
@ -2798,7 +2798,7 @@ class TestNeutronv2(TestNeutronv2Base):
|
|||
self.assertEqual(expected_results, has_pci_request_id)
|
||||
|
||||
|
||||
class TestNeutronv2WithMock(test.NoDBTestCase):
|
||||
class TestNeutronv2WithMock(test.TestCase):
|
||||
"""Used to test Neutron V2 API with mock."""
|
||||
|
||||
def setUp(self):
|
||||
|
|
|
@ -1481,7 +1481,7 @@ class TestRemoteInstanceListObject(test_objects._RemoteTest,
|
|||
pass
|
||||
|
||||
|
||||
class TestInstanceObjectMisc(test.NoDBTestCase):
|
||||
class TestInstanceObjectMisc(test.TestCase):
|
||||
def test_expected_cols(self):
|
||||
self.stubs.Set(instance, '_INSTANCE_OPTIONAL_JOINED_FIELDS', ['bar'])
|
||||
self.assertEqual(['bar'], instance._expected_cols(['foo', 'bar']))
|
||||
|
|
|
@ -73,7 +73,7 @@ class SchedulerManagerTestCase(test.NoDBTestCase):
|
|||
delete_aggregate.assert_called_once_with('agg')
|
||||
|
||||
|
||||
class SchedulerV3PassthroughTestCase(test.NoDBTestCase):
|
||||
class SchedulerV3PassthroughTestCase(test.TestCase):
|
||||
def setUp(self):
|
||||
super(SchedulerV3PassthroughTestCase, self).setUp()
|
||||
self.manager = manager.SchedulerManager()
|
||||
|
|
|
@ -27,7 +27,7 @@ from nova import test
|
|||
CONF = cfg.CONF
|
||||
|
||||
|
||||
class BaseAPITestCase(test.NoDBTestCase):
|
||||
class BaseAPITestCase(test.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(BaseAPITestCase, self).setUp()
|
||||
|
|
|
@ -205,3 +205,18 @@ class TestDatabaseFixture(testtools.TestCase):
|
|||
result = conn.execute("select * from instance_types")
|
||||
rows = result.fetchall()
|
||||
self.assertEqual(len(rows), 5, "Rows %s" % rows)
|
||||
|
||||
def test_fixture_cleanup(self):
|
||||
# because this sets up reasonable db connection strings
|
||||
self.useFixture(conf_fixture.ConfFixture())
|
||||
fix = fixtures.Database()
|
||||
self.useFixture(fix)
|
||||
|
||||
# manually do the cleanup that addCleanup will do
|
||||
fix.cleanup()
|
||||
|
||||
# ensure the db contains nothing
|
||||
engine = session.get_engine()
|
||||
conn = engine.connect()
|
||||
schema = "".join(line for line in conn.connection.iterdump())
|
||||
self.assertEqual(schema, "BEGIN TRANSACTION;COMMIT;")
|
||||
|
|
|
@ -24,7 +24,7 @@ from nova import utils
|
|||
CONF = cfg.CONF
|
||||
|
||||
|
||||
class PipelibTest(test.NoDBTestCase):
|
||||
class PipelibTest(test.TestCase):
|
||||
def setUp(self):
|
||||
super(PipelibTest, self).setUp()
|
||||
self.cloudpipe = pipelib.CloudPipe()
|
||||
|
|
Loading…
Reference in New Issue