Merge "Avoid unnecessary joins in HostManager._get_instances_by_host"
This commit is contained in:
commit
92f7071897
|
@ -750,7 +750,13 @@ class HostManager(object):
|
|||
'instance info for this host.', host_name)
|
||||
return {}
|
||||
with context_module.target_cell(context, hm.cell_mapping) as cctxt:
|
||||
inst_list = objects.InstanceList.get_by_host(cctxt, host_name)
|
||||
# NOTE(mriedem): We pass expected_attrs=[] to avoid a default
|
||||
# join on info_cache and security_groups, which at present none
|
||||
# of the in-tree filters/weighers rely on that information. Any
|
||||
# out of tree filters which rely on it will end up lazy-loading
|
||||
# the field but we don't have a contract on out of tree filters.
|
||||
inst_list = objects.InstanceList.get_by_host(
|
||||
cctxt, host_name, expected_attrs=[])
|
||||
return {inst.uuid: inst for inst in inst_list}
|
||||
|
||||
def _get_instance_info(self, context, compute):
|
||||
|
|
|
@ -750,7 +750,8 @@ class HostManagerTestCase(test.NoDBTestCase):
|
|||
mock_get_by_host.return_value = objects.InstanceList(objects=[inst1])
|
||||
host_state.update(
|
||||
inst_dict=hm._get_instance_info(context, cn1))
|
||||
mock_get_by_host.assert_called_once_with(context, cn1.host)
|
||||
mock_get_by_host.assert_called_once_with(
|
||||
context, cn1.host, expected_attrs=[])
|
||||
self.assertTrue(host_state.instances)
|
||||
self.assertEqual(host_state.instances[uuids.instance], inst1)
|
||||
|
||||
|
|
Loading…
Reference in New Issue