From 30a85c8bcfb9ba7a66364df7eb1dc3dfc61341ab Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Thu, 15 Sep 2016 15:07:32 -0700 Subject: [PATCH] Fix object assumption in remove_deleted_instances() The RT tracks instance dicts for some reason. Fix that and make the test poke the previous issue. Change-Id: Iae3b2aa8e655f51f6fffd98dd02fa8e1cd9366c3 Closes-Bug: #1624119 --- nova/scheduler/client/report.py | 2 +- nova/tests/unit/scheduler/client/test_report.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/nova/scheduler/client/report.py b/nova/scheduler/client/report.py index 7b0f70edfaba..fa5041e664b5 100644 --- a/nova/scheduler/client/report.py +++ b/nova/scheduler/client/report.py @@ -442,7 +442,7 @@ class SchedulerReportClient(object): if allocations is None: allocations = {} - instance_dict = {instance.uuid: instance + instance_dict = {instance['uuid']: instance for instance in instance_uuids} removed_instances = set(allocations.keys()) - set(instance_dict.keys()) diff --git a/nova/tests/unit/scheduler/client/test_report.py b/nova/tests/unit/scheduler/client/test_report.py index 085351f49aa4..820900796486 100644 --- a/nova/tests/unit/scheduler/client/test_report.py +++ b/nova/tests/unit/scheduler/client/test_report.py @@ -769,9 +769,14 @@ class SchedulerReportClientTestCase(test.NoDBTestCase): inst2.uuid: fake_allocations, } } + + # One instance still on the node, dict form as the + # RT tracks it + inst3 = {'uuid': 'foo'} + mock_delete.return_value = True with mock.patch.object(self.client, '_allocations'): - self.client.remove_deleted_instances(cn, []) + self.client.remove_deleted_instances(cn, [inst3]) mock_get.assert_called_once_with( '/resource_providers/%s/allocations' % cn.uuid) expected_calls = [