Fix race in delete allocation in ServerMovingTests

When an instance is deleted the allocation of that instance is freed
after the instance is destroyed in the db. The functional tests that
asserting resource allocation after instance delete are waiting for
the instance to disappear from the REST API. This made such tests
racy.

Fortunately the instance.delete.end notification is emitted after
the instance allocation is freed. This patch fixes the race in the
test by waiting for the instance.delete.end notification before
asserting that the allocation is freed properly.

Change-Id: I4ffd8eae73600eb2d4f6929ee6a7768adb80081d
Closes-Bug: #1719915
(cherry picked from commit 8a435c081d)
This commit is contained in:
Balazs Gibizer 2017-09-27 17:56:17 +02:00
parent cf8161ba2f
commit aabf0b0bf6
1 changed files with 10 additions and 0 deletions

View File

@ -35,6 +35,7 @@ from nova.tests.functional import integrated_helpers
from nova.tests.unit.api.openstack import fakes
from nova.tests.unit import fake_block_device
from nova.tests.unit import fake_network
from nova.tests.unit import fake_notifier
import nova.tests.unit.image.fake
from nova.tests.unit import policy_fixture
from nova.virt import fake
@ -1146,6 +1147,9 @@ class ServerMovingTests(ProviderUsageBaseTestCase):
def setUp(self):
super(ServerMovingTests, self).setUp()
fake_notifier.stub_notifier(self)
self.addCleanup(fake_notifier.reset)
fake.set_nodes(['host1'])
self.flags(host='host1')
self.compute1 = self.start_service('compute', host='host1')
@ -1327,6 +1331,12 @@ class ServerMovingTests(ProviderUsageBaseTestCase):
# Check usages after delete
self.api.delete_server(server['id'])
self._wait_until_deleted(server)
# NOTE(gibi): The resource allocation is deleted after the instance is
# destroyed in the db so wait_until_deleted might return before the
# the resource are deleted in placement. So we need to wait for the
# instance.delete.end notification as that is emitted after the
# resources are freed.
fake_notifier.wait_for_versioned_notification('instance.delete.end')
source_usages = self._get_provider_usages(source_rp_uuid)
self.assertEqual({'VCPU': 0,