Add a reset for traits DB sync

Some functional tests were failing, due to standard traits not being
found. The cause was that there is a flag that ensures that these
standard traits are only loaded once from the os_traits module to the
DB. The test fixtures, though, would clean up the DB between runs, and
the traits would never be re-loaded. This patch fixes that by directly
resetting this flag in the base test code.

Closes-bug: #1701035

Change-Id: I5dc0220310986c5b9fe5b71013c573c3d98cb9aa
This commit is contained in:
EdLeafe 2017-06-28 16:44:08 +00:00
parent a86e31f693
commit ff6c50335e
2 changed files with 15 additions and 0 deletions

View File

@ -294,6 +294,9 @@ class TestCase(testtools.TestCase):
# caching of that value.
utils._IS_NEUTRON = None
# Reset the traits sync flag
objects.resource_provider._TRAITS_SYNCED = False
mox_fixture = self.useFixture(moxstubout.MoxStubout())
self.mox = mox_fixture.mox
self.stubs = mox_fixture.stubs

View File

@ -13,6 +13,7 @@
import mock
import six
import nova
from nova import context
from nova import exception
from nova import objects
@ -581,3 +582,14 @@ class TestResourceClass(test.NoDBTestCase):
rc = objects.ResourceClass(self.context)
exc = self.assertRaises(exception.ObjectActionError, rc.create)
self.assertIn('name is required', str(exc))
class TestTraitSync(test_objects._LocalTest):
@mock.patch("nova.objects.resource_provider._trait_sync")
def test_sync_flag(self, mock_sync):
synced = nova.objects.resource_provider._TRAITS_SYNCED
self.assertFalse(synced)
# Sync the traits
nova.objects.resource_provider._ensure_trait_sync(self.context)
synced = nova.objects.resource_provider._TRAITS_SYNCED
self.assertTrue(synced)