diff --git a/nova/tests/functional/test_servers.py b/nova/tests/functional/test_servers.py index d811589d7a5e..2c0979968154 100644 --- a/nova/tests/functional/test_servers.py +++ b/nova/tests/functional/test_servers.py @@ -1613,6 +1613,20 @@ class ServerMovingTests(ProviderUsageBaseTestCase): self._delete_and_check_allocations( server, source_rp_uuid, dest_rp_uuid) + def _restart_compute_service(self, compute): + # NOTE(gibi): The service interface cannot be used to simulate a real + # service restart as the manager object will not be recreated after a + # service.stop() and service.start() therefore the manager state will + # survive. For example the resource tracker will not be recreated after + # a stop start. The service.kill() call cannot help as it deletes + # the service from the DB which is unrealistic and causes that some + # operation that refers to the killed host (e.g. evacuate) fails. + # So this helper method tries to simulate a better compute service + # restart by cleaning up some of the internal state of the compute + # manager. + compute.manager._resource_tracker = None + compute.start() + def test_evacuate(self): source_hostname = self.compute1.host dest_hostname = self.compute2.host @@ -1656,23 +1670,44 @@ class ServerMovingTests(ProviderUsageBaseTestCase): self.assertFlavorMatchesAllocation(self.flavor1, dest_allocation) # start up the source compute - self.compute1.start() + # NOTE(gibi): This is bug 1721652. The restart should go through + # without exception. + self.assertRaises(KeyError, self._restart_compute_service, + self.compute1) + self.admin_api.put_service( source_compute_id, {'forced_down': 'false'}) + # NOTE(gibi): This is bug 1721652. After the source host is started up + # the allocation should be cleaned. source_usages = self._get_provider_usages(source_rp_uuid) - self.assertEqual({'VCPU': 0, - 'MEMORY_MB': 0, - 'DISK_GB': 0}, - source_usages) + self.assertFlavorMatchesAllocation(self.flavor1, source_usages) dest_usages = self._get_provider_usages(dest_rp_uuid) self.assertFlavorMatchesAllocation(self.flavor1, dest_usages) allocations = self._get_allocations_by_server_uuid(server['id']) - self.assertEqual(1, len(allocations)) + self.assertEqual(2, len(allocations)) dest_allocation = allocations[dest_rp_uuid]['resources'] self.assertFlavorMatchesAllocation(self.flavor1, dest_allocation) + source_allocation = allocations[source_rp_uuid]['resources'] + self.assertFlavorMatchesAllocation(self.flavor1, source_allocation) + + # NOTE(gibi): Once the bug 1721652 is fixed this should be the expected + # behavior + # source_usages = self._get_provider_usages(source_rp_uuid) + # self.assertEqual({'VCPU': 0, + # 'MEMORY_MB': 0, + # 'DISK_GB': 0}, + # source_usages) + # + # dest_usages = self._get_provider_usages(dest_rp_uuid) + # self.assertFlavorMatchesAllocation(self.flavor1, dest_usages) + # + # allocations = self._get_allocations_by_server_uuid(server['id']) + # self.assertEqual(1, len(allocations)) + # dest_allocation = allocations[dest_rp_uuid]['resources'] + # self.assertFlavorMatchesAllocation(self.flavor1, dest_allocation) self._delete_and_check_allocations( server, source_rp_uuid, dest_rp_uuid)