Fix Image RootDeviceType detection for bdm v2

Change-Id: Ia94a3188ddb1340514aa1fe6695ac8173439a185
This commit is contained in:
Feodor Tersin 2015-02-21 09:38:41 +03:00
parent 1c30d32264
commit f388b531a3
3 changed files with 16 additions and 3 deletions

View File

@ -441,7 +441,8 @@ def _format_image(context, image, os_image, images_dict, ids_dict,
for bdm in properties.get('block_device_mapping', []):
if (('snapshot_id' in bdm or 'volume_id' in bdm) and
not bdm.get('no_device') and
(root_device_name ==
(bdm.get('boot_index') == 0 or
root_device_name ==
instance_api._block_device_strip_dev(
bdm.get('device_name')))):
root_device_type = 'ebs'

View File

@ -23,8 +23,6 @@ CONF = config.CONF
class ImageTest(base.EC2TestCase):
@testtools.skipUnless(CONF.aws.run_incompatible_tests,
"Openstack doesn't report right RootDeviceType")
@testtools.skipUnless(CONF.aws.ebs_image_id, "EBS image id is not defined")
def test_check_ebs_image_type(self):
image_id = CONF.aws.ebs_image_id

View File

@ -435,6 +435,20 @@ class ImagePrivateTestCase(test_base.BaseTestCase):
self.assertEqual('None (fake_name)', image['imageLocation'])
self.assertEqual('fake_name', image['name'])
os_image['properties'] = {
'bdm_v2': True,
'root_device_name': '/dev/vda',
'block_device_mapping': [
{'boot_index': 0,
'snapshot_id': fakes.ID_OS_SNAPSHOT_2}]}
image = image_api._format_image(
'fake_context', fakes.DB_IMAGE_1, fakes.OSImage(os_image),
None, image_ids,
snapshot_ids={fakes.ID_OS_SNAPSHOT_2: fakes.ID_EC2_SNAPSHOT_2})
self.assertEqual('ebs', image['rootDeviceType'])
def test_cloud_format_mappings(self):
properties = {
'mappings': [