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
This commit is contained in:
@@ -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.
|
||||
|
@@ -1309,6 +1309,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)
|
||||
@@ -1321,6 +1322,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")
|
||||
@@ -1329,6 +1331,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)
|
||||
@@ -1341,6 +1344,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")
|
||||
|
Reference in New Issue
Block a user