Eager load keypairs in instance metadata
In the review for e83842b80b it was
pointed out that keypairs should be added to the eager load list for
get_metadata_for_instance_id. Due to a lack of a proper context in a
thread in the ironic driver, this actually totally broke ironic.
The context problem is being fixed elsewhere, but this should be
eager-loaded to minimize DB queries anyway.
Change-Id: I67b4665bdebd45c66983c6a556d20f367fa7fbdf
Closes-Bug: #1580987
This commit is contained in:
@@ -532,7 +532,7 @@ def get_metadata_by_instance_id(instance_id, address, ctxt=None):
|
|||||||
instance = objects.Instance.get_by_uuid(
|
instance = objects.Instance.get_by_uuid(
|
||||||
ctxt, instance_id, expected_attrs=['ec2_ids', 'flavor', 'info_cache',
|
ctxt, instance_id, expected_attrs=['ec2_ids', 'flavor', 'info_cache',
|
||||||
'metadata', 'system_metadata',
|
'metadata', 'system_metadata',
|
||||||
'security_groups'])
|
'security_groups', 'keypairs'])
|
||||||
return InstanceMetadata(instance, address)
|
return InstanceMetadata(instance, address)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1232,7 +1232,7 @@ class MetadataHandlerTestCase(test.TestCase):
|
|||||||
"have been called, the context was given")
|
"have been called, the context was given")
|
||||||
mock_uuid.assert_called_once_with('CONTEXT', 'foo',
|
mock_uuid.assert_called_once_with('CONTEXT', 'foo',
|
||||||
expected_attrs=['ec2_ids', 'flavor', 'info_cache', 'metadata',
|
expected_attrs=['ec2_ids', 'flavor', 'info_cache', 'metadata',
|
||||||
'system_metadata', 'security_groups'])
|
'system_metadata', 'security_groups', 'keypairs'])
|
||||||
imd.assert_called_once_with(inst, 'bar')
|
imd.assert_called_once_with(inst, 'bar')
|
||||||
|
|
||||||
@mock.patch.object(context, 'get_admin_context')
|
@mock.patch.object(context, 'get_admin_context')
|
||||||
@@ -1249,7 +1249,7 @@ class MetadataHandlerTestCase(test.TestCase):
|
|||||||
mock_context.assert_called_once_with()
|
mock_context.assert_called_once_with()
|
||||||
mock_uuid.assert_called_once_with('CONTEXT', 'foo',
|
mock_uuid.assert_called_once_with('CONTEXT', 'foo',
|
||||||
expected_attrs=['ec2_ids', 'flavor', 'info_cache', 'metadata',
|
expected_attrs=['ec2_ids', 'flavor', 'info_cache', 'metadata',
|
||||||
'system_metadata', 'security_groups'])
|
'system_metadata', 'security_groups', 'keypairs'])
|
||||||
imd.assert_called_once_with(inst, 'bar')
|
imd.assert_called_once_with(inst, 'bar')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user