From fa3453fcc1bc7061f9e39d872bdda6a6944ccaad Mon Sep 17 00:00:00 2001 From: Jim Rollenhagen Date: Thu, 12 May 2016 07:32:27 -0400 Subject: [PATCH] Eager load keypairs in instance metadata In the review for e83842b80b73c451f78a4bb9e7bd5dfcebdefcab 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 --- nova/api/metadata/base.py | 2 +- nova/tests/unit/test_metadata.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/nova/api/metadata/base.py b/nova/api/metadata/base.py index b091c111a543..4d85e2270710 100644 --- a/nova/api/metadata/base.py +++ b/nova/api/metadata/base.py @@ -532,7 +532,7 @@ def get_metadata_by_instance_id(instance_id, address, ctxt=None): instance = objects.Instance.get_by_uuid( ctxt, instance_id, expected_attrs=['ec2_ids', 'flavor', 'info_cache', 'metadata', 'system_metadata', - 'security_groups']) + 'security_groups', 'keypairs']) return InstanceMetadata(instance, address) diff --git a/nova/tests/unit/test_metadata.py b/nova/tests/unit/test_metadata.py index 0301f7ca8abf..4dc537958929 100644 --- a/nova/tests/unit/test_metadata.py +++ b/nova/tests/unit/test_metadata.py @@ -1232,7 +1232,7 @@ class MetadataHandlerTestCase(test.TestCase): "have been called, the context was given") mock_uuid.assert_called_once_with('CONTEXT', 'foo', expected_attrs=['ec2_ids', 'flavor', 'info_cache', 'metadata', - 'system_metadata', 'security_groups']) + 'system_metadata', 'security_groups', 'keypairs']) imd.assert_called_once_with(inst, 'bar') @mock.patch.object(context, 'get_admin_context') @@ -1249,7 +1249,7 @@ class MetadataHandlerTestCase(test.TestCase): mock_context.assert_called_once_with() mock_uuid.assert_called_once_with('CONTEXT', 'foo', expected_attrs=['ec2_ids', 'flavor', 'info_cache', 'metadata', - 'system_metadata', 'security_groups']) + 'system_metadata', 'security_groups', 'keypairs']) imd.assert_called_once_with(inst, 'bar')