From 8f74906df3512237c7434c0c0359c595bbc9a18f Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Mon, 26 Sep 2016 15:47:16 -0400 Subject: [PATCH] Cleanup some redundant USES_DB_SELF usage The USES_DB_SELF flag in tests is only needed if you don't need the default database fixture setup in nova.test.TestCase, which is: 1. Setup the API DB. 2. Setup the cell DB. 3. Populate the API DB with default flavors. There were several tests which were inheriting from NoDBTestCase and setting USES_DB_SELF=True but still used the same API/cell DB fixtures as the default setup, the only difference being the default flavors weren't created in the API DB. Since these tests don't care about flavors anyway, using USES_SELF_DB is mostly redundant and confusing, so this patch cleans those up. A comment is also added for the USES_SELF_DB flag to explain what it's used for, since it's not immediately clear until you dig into how it's used - which as seen here is not always necessary. Change-Id: I04087bf3f756488007710234e6466592cda9cd10 --- nova/test.py | 7 +++++++ nova/tests/functional/db/test_aggregate.py | 17 +++-------------- nova/tests/functional/db/test_keypair.py | 6 +----- .../functional/db/test_resource_provider.py | 6 +----- 4 files changed, 12 insertions(+), 24 deletions(-) diff --git a/nova/test.py b/nova/test.py index caf1f89b8f..085629f210 100644 --- a/nova/test.py +++ b/nova/test.py @@ -169,7 +169,14 @@ class TestCase(testtools.TestCase): Due to the slowness of DB access, please consider deriving from `NoDBTestCase` first. """ + # USES_DB is set to False for tests that inherit from NoDBTestCase. USES_DB = True + # USES_DB_SELF is set to True in tests that specifically want to use the + # database but need to configure it themselves, for example to setup the + # API DB but not the cell DB. In those cases the test will override + # USES_DB_SELF = True but inherit from the NoDBTestCase class so it does + # not get the default fixture setup when using a database (which is the + # API and cell DBs, and adding the default flavors). USES_DB_SELF = False REQUIRES_LOCKING = False diff --git a/nova/tests/functional/db/test_aggregate.py b/nova/tests/functional/db/test_aggregate.py index 74a713e558..5d8810f360 100644 --- a/nova/tests/functional/db/test_aggregate.py +++ b/nova/tests/functional/db/test_aggregate.py @@ -21,7 +21,6 @@ from nova.db.sqlalchemy import api as db_api from nova.db.sqlalchemy import api_models from nova import exception from nova import test -from nova.tests import fixtures from nova.tests.unit import matchers from nova.tests.unit.objects.test_objects import compare_obj as base_compare from nova.tests import uuidsentinel @@ -110,14 +109,10 @@ def _aggregate_metadata_get_all(context, aggregate_id): return metadata -class AggregateObjectDbTestCase(test.NoDBTestCase): - - USES_DB_SELF = True +class AggregateObjectDbTestCase(test.TestCase): def setUp(self): super(AggregateObjectDbTestCase, self).setUp() - self.useFixture(fixtures.Database()) - self.useFixture(fixtures.Database(database='api')) self.context = context.RequestContext('fake-user', 'fake-project') def test_in_api(self): @@ -495,15 +490,12 @@ def compare_obj(test, result, source): comparators={'updated_at': updated_at_comparator}) -class AggregateObjectCellTestCase(test.NoDBTestCase): +class AggregateObjectCellTestCase(test.TestCase): """Tests for the case where all aggregate data is in Cell DB""" - USES_DB_SELF = True def setUp(self): super(AggregateObjectCellTestCase, self).setUp() self.context = context.RequestContext('fake-user', 'fake-project') - self.useFixture(fixtures.Database()) - self.useFixture(fixtures.Database(database='api')) self._seed_data() def _seed_data(self): @@ -610,13 +602,10 @@ class AggregateObjectMigrationTestCase(AggregateObjectCellTestCase): self.assertEqual(new_agg.name, result.name) -class AggregateMigrationTestCase(test.NoDBTestCase): - USES_DB_SELF = True +class AggregateMigrationTestCase(test.TestCase): def setUp(self): super(AggregateMigrationTestCase, self).setUp() - self.useFixture(fixtures.Database()) - self.useFixture(fixtures.Database(database='api')) self.context = context.get_admin_context() def test_migration(self): diff --git a/nova/tests/functional/db/test_keypair.py b/nova/tests/functional/db/test_keypair.py index b374efc34c..ffa47e702c 100644 --- a/nova/tests/functional/db/test_keypair.py +++ b/nova/tests/functional/db/test_keypair.py @@ -16,16 +16,12 @@ from nova import exception from nova import objects from nova.objects import keypair from nova import test -from nova.tests import fixtures -class KeyPairObjectTestCase(test.NoDBTestCase): - USES_DB_SELF = True +class KeyPairObjectTestCase(test.TestCase): def setUp(self): super(KeyPairObjectTestCase, self).setUp() - self.useFixture(fixtures.Database()) - self.useFixture(fixtures.Database(database='api')) self.context = context.RequestContext('fake-user', 'fake-project') def _api_kp(self, **values): diff --git a/nova/tests/functional/db/test_resource_provider.py b/nova/tests/functional/db/test_resource_provider.py index 355c8d7f3b..68121bc743 100644 --- a/nova/tests/functional/db/test_resource_provider.py +++ b/nova/tests/functional/db/test_resource_provider.py @@ -42,14 +42,10 @@ DISK_ALLOCATION = dict( ) -class ResourceProviderBaseCase(test.NoDBTestCase): - - USES_DB_SELF = True +class ResourceProviderBaseCase(test.TestCase): def setUp(self): super(ResourceProviderBaseCase, self).setUp() - self.useFixture(fixtures.Database()) - self.useFixture(fixtures.Database(database='api')) self.context = context.RequestContext('fake-user', 'fake-project') def _make_allocation(self, rp_uuid=None):