summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorliyingjun <liyingjun1988@gmail.com>2014-09-06 18:41:51 +0800
committerThierry Carrez <thierry@openstack.org>2014-10-07 14:04:43 +0200
commitf98c28228b6db5b0796e9669b6bd692b82bbfa6d (patch)
treedfa945a1166604b07b2e796e4f208e30404aa7d6
parenta4dbb47cf41fbb9644cd106c6e5712e19a26faa8 (diff)
downloadnova-f98c28228b6db5b0796e9669b6bd692b82bbfa6d.tar.gz
Fix KeyError for euca-describe-images
EC2 describe images crashes on volume backed instance snapshot which has several volumes. Change-Id: Ibe278688b118db01c9c3ae1763954adf19c7ee0d Closes-bug: #1370265 (cherry picked from commit 1dea1cd710d54d4a2a584590e4ccf59dd3a41faa)
-rw-r--r--nova/api/ec2/cloud.py2
-rw-r--r--nova/tests/api/ec2/test_cloud.py51
2 files changed, 52 insertions, 1 deletions
diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py
index 5ed36b7fc6..fc0fef0357 100644
--- a/nova/api/ec2/cloud.py
+++ b/nova/api/ec2/cloud.py
@@ -210,7 +210,7 @@ def _format_mappings(properties, result):
# NOTE(yamahata): overwrite mappings with block_device_mapping
for bdm in block_device_mapping:
for i in range(len(mappings)):
- if bdm['deviceName'] == mappings[i]['deviceName']:
+ if bdm.get('deviceName') == mappings[i].get('deviceName'):
del mappings[i]
break
mappings.append(bdm)
diff --git a/nova/tests/api/ec2/test_cloud.py b/nova/tests/api/ec2/test_cloud.py
index ccea951835..909b39c550 100644
--- a/nova/tests/api/ec2/test_cloud.py
+++ b/nova/tests/api/ec2/test_cloud.py
@@ -3199,3 +3199,54 @@ class CloudTestCaseNeutronProxy(test.NoDBTestCase):
self.assertEqual(descript, group_descript)
delete = self.cloud.delete_security_group
self.assertTrue(delete(self.context, 'testgrp'))
+
+
+class FormatMappingTestCase(test.TestCase):
+
+ def test_format_mapping(self):
+ properties = {'block_device_mapping':
+ [{'guest_format': None, 'boot_index': 0,
+ 'no_device': None, 'volume_id': None,
+ 'volume_size': None, 'disk_bus': 'virtio',
+ 'image_id': None, 'source_type': 'snapshot',
+ 'device_type': 'disk',
+ 'snapshot_id': '993b31ac-452e-4fed-b745-7718385f1811',
+ 'destination_type': 'volume',
+ 'delete_on_termination': None},
+ {'guest_format': None, 'boot_index': None,
+ 'no_device': None, 'volume_id': None,
+ 'volume_size': None, 'disk_bus': None,
+ 'image_id': None, 'source_type': 'snapshot',
+ 'device_type': None,
+ 'snapshot_id': 'b409a2de-1c79-46bf-aa7e-ebdb4bf427ef',
+ 'destination_type': 'volume',
+ 'delete_on_termination': None}],
+ 'checksum': '50bdc35edb03a38d91b1b071afb20a3c',
+ 'min_ram': '0', 'disk_format': 'qcow2',
+ 'image_name': 'cirros-0.3.0-x86_64-disk', 'bdm_v2': 'True',
+ 'image_id': '4fce9db9-d89e-4eea-8d20-e2bae15292c1',
+ 'root_device_name': '/dev/vda', 'container_format': 'bare',
+ 'min_disk': '0', 'size': '9761280'}
+ result = {'description': None,
+ 'imageOwnerId': '9fd1513f52f14fe49fa1c83e40c63541',
+ 'isPublic': False, 'imageId': 'ami-00000002',
+ 'imageState': 'available', 'architecture': None,
+ 'imageLocation': 'None (xb)',
+ 'rootDeviceType': 'instance-store',
+ 'rootDeviceName': '/dev/vda',
+ 'imageType': 'machine', 'name': 'xb'}
+ cloud._format_mappings(properties, result)
+ expected = {'architecture': None,
+ 'blockDeviceMapping':
+ [{'ebs': {'snapshotId': 'snap-00000002'}}],
+ 'description': None,
+ 'imageId': 'ami-00000002',
+ 'imageLocation': 'None (xb)',
+ 'imageOwnerId': '9fd1513f52f14fe49fa1c83e40c63541',
+ 'imageState': 'available',
+ 'imageType': 'machine',
+ 'isPublic': False,
+ 'name': 'xb',
+ 'rootDeviceName': '/dev/vda',
+ 'rootDeviceType': 'instance-store'}
+ self.assertEqual(expected, result)