From ded5b51d3c4b93e946de75a12b5d815a385bf84a Mon Sep 17 00:00:00 2001 From: Steve Baker Date: Thu, 28 Jun 2012 16:29:53 +1200 Subject: Fixes bug 1014194, metadata keys are incorrect for kernel-id and ramdisk-id Kernel and ramdisk IDs are using currently being inserted in the metadata using the keys aki-id and ari-id. They should be using the keys kernel-id and ramdisk-id. http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/instancedata-data-categories.html This bug is in a block of code which did not previously have test coverage; this change also adds that coverage. Change-Id: I2ee3663169160c0e351e548d831fef2f34f9f2fd --- Authors | 1 + nova/api/metadata/base.py | 4 ++-- nova/tests/test_metadata.py | 21 +++++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Authors b/Authors index 36422549d..e13d824ee 100644 --- a/Authors +++ b/Authors @@ -201,6 +201,7 @@ Somik Behera Soren Hansen Stanislaw Pitucha Stephanie Reese +Steve Baker Sumit Naiksatam Thierry Carrez Tim Simpson diff --git a/nova/api/metadata/base.py b/nova/api/metadata/base.py index 06e290917..582bdec82 100644 --- a/nova/api/metadata/base.py +++ b/nova/api/metadata/base.py @@ -96,9 +96,9 @@ class InstanceMetadata(): for image_type in ['kernel', 'ramdisk']: if self.instance.get('%s_id' % image_type): image_id = self.instance['%s_id' % image_type] - image_type = ec2utils.image_type(image_type) + ec2_image_type = ec2utils.image_type(image_type) ec2_id = ec2utils.glance_id_to_ec2_id(ctxt, image_id, - image_type) + ec2_image_type) self.ec2_ids['%s-id' % image_type] = ec2_id self.address = address diff --git a/nova/tests/test_metadata.py b/nova/tests/test_metadata.py index 0c3c5b574..cf48512f0 100644 --- a/nova/tests/test_metadata.py +++ b/nova/tests/test_metadata.py @@ -20,6 +20,7 @@ import base64 from copy import copy +import re import stubout import webob @@ -190,6 +191,26 @@ class MetadataTestCase(test.TestCase): self.assertEqual(base.ec2_md_print(pubkey_ent['0']['openssh-key']), self.instance['key_data']) + def test_image_type_ramdisk(self): + inst = copy(self.instance) + inst['ramdisk_id'] = 'ari-853667c0' + md = fake_InstanceMetadata(self.stubs, inst) + data = md.get_ec2_metadata(version='latest') + + self.assertTrue(data['meta-data']['ramdisk-id'] is not None) + self.assertTrue(re.match('ari-[0-9a-f]{8}', + data['meta-data']['ramdisk-id'])) + + def test_image_type_kernel(self): + inst = copy(self.instance) + inst['kernel_id'] = 'aki-c2e26ff2' + md = fake_InstanceMetadata(self.stubs, inst) + data = md.get_ec2_metadata(version='2009-04-04') + + self.assertTrue(data['meta-data']['kernel-id'] is not None) + self.assertTrue(re.match('aki-[0-9a-f]{8}', + data['meta-data']['kernel-id'])) + class MetadataHandlerTestCase(test.TestCase): """Test that metadata is returning proper values.""" -- cgit