Merge "Avoid unnecessary joins in delete_resource_provider"
This commit is contained in:
commit
1ca69e839f
|
@ -2171,8 +2171,12 @@ class SchedulerReportClient(object):
|
|||
# Delete any allocations for this resource provider.
|
||||
# Since allocations are by consumer, we get the consumers on this
|
||||
# host, which are its instances.
|
||||
instances = objects.InstanceList.get_by_host_and_node(context,
|
||||
host, nodename)
|
||||
# TODO(mriedem): Optimize this up by adding an
|
||||
# InstanceList.get_uuids_by_host_and_node method.
|
||||
# Pass expected_attrs=[] to avoid joining on extra columns we
|
||||
# don't use.
|
||||
instances = objects.InstanceList.get_by_host_and_node(
|
||||
context, host, nodename, expected_attrs=[])
|
||||
for instance in instances:
|
||||
self.delete_allocation_for_instance(context, instance.uuid)
|
||||
try:
|
||||
|
|
|
@ -3202,6 +3202,8 @@ class TestAllocations(SchedulerReportClientTestCase):
|
|||
resp_mock = mock.Mock(status_code=204)
|
||||
mock_delete.return_value = resp_mock
|
||||
self.client.delete_resource_provider(self.context, cn, cascade=True)
|
||||
mock_by_host.assert_called_once_with(
|
||||
self.context, cn.host, cn.hypervisor_hostname, expected_attrs=[])
|
||||
self.assertEqual(2, mock_del_alloc.call_count)
|
||||
exp_url = "/resource_providers/%s" % uuids.cn
|
||||
mock_delete.assert_called_once_with(
|
||||
|
|
Loading…
Reference in New Issue