EC2 DescribeImages reports correct rootDeviceType

Fixes LP 1024354

A root device type of instance-store was incorrectly reported for
boot-from-volume images (i.e. the analogue of EBS-backed AMIs).

When comparing the block device mapping device name with the root
device name, we now tolerate a missing leading '/dev/' path.

Change-Id: I1d3bda780deee52f5d41e3af041aba7e6305dfde
This commit is contained in:
Eoghan Glynn 2012-07-14 21:30:43 +01:00
parent 8600394ec4
commit b898badbbc
3 changed files with 6 additions and 2 deletions

View File

@ -1303,8 +1303,10 @@ class CloudController(object):
properties = image['properties']
root_device_name = block_device.properties_root_device_name(properties)
root_device_type = 'instance-store'
for bdm in properties.get('block_device_mapping', []):
if (bdm.get('device_name') == root_device_name and
if (block_device.strip_dev(bdm.get('device_name')) ==
block_device.strip_dev(root_device_name) and
('snapshot_id' in bdm or 'volume_id' in bdm) and
not bdm.get('no_device')):
root_device_type = 'ebs'

View File

@ -71,7 +71,7 @@ _dev = re.compile('^/dev/')
def strip_dev(device_name):
"""remove leading '/dev/'"""
return _dev.sub('', device_name)
return _dev.sub('', device_name) if device_name else device_name
_pref = re.compile('^((x?v|s)d)')

View File

@ -2178,6 +2178,7 @@ class CloudTestCase(test.TestCase):
delete_on_termination=False)]
props = dict(kernel_id='cedef40a-ed67-4d10-800e-17455edce175',
ramdisk_id='76fa36fc-c930-4bf3-8c8a-ea2a2420deb6',
root_device_name='/dev/vda',
block_device_mapping=bdm)
return dict(id=id,
properties=props,
@ -2223,6 +2224,7 @@ class CloudTestCase(test.TestCase):
'snap-%08x' % snapshots[0])
self.assertEquals(created_image.get('kernelId'), 'aki-00000001')
self.assertEquals(created_image.get('ramdiskId'), 'ari-00000002')
self.assertEquals(created_image.get('rootDeviceType'), 'ebs')
self.cloud.terminate_instances(self.context, [ec2_instance_id])
for vol in volumes: