From bdf06d18aa4ad81e43bf0d1a22c851b43c4cd1c5 Mon Sep 17 00:00:00 2001 From: Chris Dent Date: Thu, 29 Mar 2018 15:10:19 +0100 Subject: [PATCH] [placement] Fix bad management of _TRAITS_SYNCED flag Placement functional tests could, depending on run order, be unable to synchronise the os-traits because a previous test or this test has failed to reset the _TRAITS_SYNCED flag. This change fixes it so the tests will always reset the flag at both setUp and tearDown. In the process a nearby misleading comment which says a database is not being used is corrected. Change-Id: I595be7bca2c1bde86651b126ce501286b301d272 Closes-Bug: #1759863 --- .../placement/db/test_allocation_candidates.py | 10 ++++++++++ .../functional/api/openstack/placement/fixtures.py | 13 +++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/nova/tests/functional/api/openstack/placement/db/test_allocation_candidates.py b/nova/tests/functional/api/openstack/placement/db/test_allocation_candidates.py index d113604fe3d3..d9fedc045611 100644 --- a/nova/tests/functional/api/openstack/placement/db/test_allocation_candidates.py +++ b/nova/tests/functional/api/openstack/placement/db/test_allocation_candidates.py @@ -62,11 +62,21 @@ class ProviderDBBase(test.NoDBTestCase): super(ProviderDBBase, self).setUp() self.useFixture(fixtures.Database()) self.api_db = self.useFixture(fixtures.Database(database='api')) + # Reset the _TRAITS_SYNCED global before we start and after + # we are done since other tests (notably the gabbi tests) + # may have caused it to change. + self._reset_traits_synced() + self.addCleanup(self._reset_traits_synced) self.ctx = context.RequestContext('fake-user', 'fake-project') # For debugging purposes, populated by _create_provider and used by # _validate_allocation_requests to make failure results more readable. self.rp_uuid_to_name = {} + @staticmethod + def _reset_traits_synced(): + """Reset the _TRAITS_SYNCED boolean to base state.""" + rp_obj._TRAITS_SYNCED = False + def _create_provider(self, name, *aggs, **kwargs): parent = kwargs.get('parent') rp = rp_obj.ResourceProvider(self.ctx, name=name, diff --git a/nova/tests/functional/api/openstack/placement/fixtures.py b/nova/tests/functional/api/openstack/placement/fixtures.py index e28f4a9a7d09..cbb6ee63973d 100644 --- a/nova/tests/functional/api/openstack/placement/fixtures.py +++ b/nova/tests/functional/api/openstack/placement/fixtures.py @@ -66,9 +66,10 @@ class APIFixture(fixture.GabbiFixture): config.parse_args([], default_config_files=[], configure_db=False, init_rpc=False) - # NOTE(cdent): api and main database are not used but we still need - # to manage them to make the fixtures work correctly and not cause + # NOTE(cdent): The main database is not used but we still need to + # manage it to make the fixtures work correctly and not cause # conflicts with other tests in the same process. + self._reset_db_flags() self.api_db_fixture = fixtures.Database('api') self.main_db_fixture = fixtures.Database('main') self.api_db_fixture.reset() @@ -95,14 +96,18 @@ class APIFixture(fixture.GabbiFixture): # flag to make sure the next run will recreate the traits and # reset the _RC_CACHE so that any cached resource classes # are flushed. - rp_obj._TRAITS_SYNCED = False - rp_obj._RC_CACHE = None + self._reset_db_flags() self.output_stream_fixture.cleanUp() self.standard_logging_fixture.cleanUp() if self.conf: self.conf.reset() + @staticmethod + def _reset_db_flags(): + rp_obj._TRAITS_SYNCED = False + rp_obj._RC_CACHE = None + class AllocationFixture(APIFixture): """An APIFixture that has some pre-made Allocations."""