From 8a435c081df1653620cff5918ea66643d3487fd7 Mon Sep 17 00:00:00 2001 From: Balazs Gibizer Date: Wed, 27 Sep 2017 17:56:17 +0200 Subject: [PATCH] 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 --- nova/tests/functional/test_servers.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/nova/tests/functional/test_servers.py b/nova/tests/functional/test_servers.py index 593369edbd69..420e0137fc61 100644 --- a/nova/tests/functional/test_servers.py +++ b/nova/tests/functional/test_servers.py @@ -36,6 +36,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 @@ -1143,6 +1144,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') @@ -1324,6 +1328,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_notifications('instance.delete.end') source_usages = self._get_provider_usages(source_rp_uuid) self.assertEqual({'VCPU': 0,