Cleanup the caches when deleting a resource provider
When we delete a resource provider in the scheduler
report we should also cleanup any entries we have in
the resource provider and aggregate map caches.
Change-Id: I7f15720d3aaff5d5a504d04729b8003f51e2c37d
Related-Bug: #1661258
(cherry picked from commit 916ed4bfe4
)
This commit is contained in:
parent
0a8e0bef79
commit
ed36e85f6f
|
@ -776,6 +776,9 @@ class SchedulerReportClient(object):
|
|||
resp = self.delete(url)
|
||||
if resp:
|
||||
LOG.info(_LI("Deleted resource provider %s"), rp_uuid)
|
||||
# clean the caches
|
||||
self._resource_providers.pop(rp_uuid, None)
|
||||
self._provider_aggregate_map.pop(rp_uuid, None)
|
||||
else:
|
||||
# Check for 404 since we don't need to log a warning if we tried to
|
||||
# delete something which doesn"t actually exist.
|
||||
|
|
|
@ -1327,6 +1327,7 @@ class TestAllocations(SchedulerReportClientTestCase):
|
|||
@mock.patch("nova.objects.InstanceList.get_by_host_and_node")
|
||||
def test_delete_resource_provider_cascade(self, mock_by_host,
|
||||
mock_del_alloc, mock_delete):
|
||||
self.client._resource_providers[uuids.cn] = mock.Mock()
|
||||
cn = objects.ComputeNode(uuid=uuids.cn, host="fake_host",
|
||||
hypervisor_hostname="fake_hostname", )
|
||||
inst1 = objects.Instance(uuid=uuids.inst1)
|
||||
|
@ -1339,6 +1340,7 @@ class TestAllocations(SchedulerReportClientTestCase):
|
|||
self.assertEqual(2, mock_del_alloc.call_count)
|
||||
exp_url = "/resource_providers/%s" % uuids.cn
|
||||
mock_delete.assert_called_once_with(exp_url)
|
||||
self.assertNotIn(uuids.cn, self.client._resource_providers)
|
||||
|
||||
@mock.patch("nova.scheduler.client.report.SchedulerReportClient."
|
||||
"delete")
|
||||
|
@ -1347,6 +1349,7 @@ class TestAllocations(SchedulerReportClientTestCase):
|
|||
@mock.patch("nova.objects.InstanceList.get_by_host_and_node")
|
||||
def test_delete_resource_provider_no_cascade(self, mock_by_host,
|
||||
mock_del_alloc, mock_delete):
|
||||
self.client._provider_aggregate_map[uuids.cn] = mock.Mock()
|
||||
cn = objects.ComputeNode(uuid=uuids.cn, host="fake_host",
|
||||
hypervisor_hostname="fake_hostname", )
|
||||
inst1 = objects.Instance(uuid=uuids.inst1)
|
||||
|
@ -1359,6 +1362,7 @@ class TestAllocations(SchedulerReportClientTestCase):
|
|||
mock_del_alloc.assert_not_called()
|
||||
exp_url = "/resource_providers/%s" % uuids.cn
|
||||
mock_delete.assert_called_once_with(exp_url)
|
||||
self.assertNotIn(uuids.cn, self.client._provider_aggregate_map)
|
||||
|
||||
@mock.patch("nova.scheduler.client.report.SchedulerReportClient."
|
||||
"delete")
|
||||
|
|
Loading…
Reference in New Issue