Merge "Fix precedence of image bdms over image mappings"
This commit is contained in:
commit
1df8248b6a
|
@ -759,8 +759,10 @@ class API(base.Base):
|
|||
image_defined_bdms)
|
||||
|
||||
if image_mapping:
|
||||
image_defined_bdms += self._prepare_image_mapping(
|
||||
instance_type, image_mapping)
|
||||
image_mapping = self._prepare_image_mapping(instance_type,
|
||||
image_mapping)
|
||||
image_defined_bdms = self._merge_bdms_lists(
|
||||
image_mapping, image_defined_bdms)
|
||||
|
||||
return image_defined_bdms
|
||||
|
||||
|
@ -781,12 +783,18 @@ class API(base.Base):
|
|||
|
||||
return flavor_defined_bdms
|
||||
|
||||
def _merge_with_image_bdms(self, block_device_mapping, image_mappings):
|
||||
"""Override any block devices from the image by device name"""
|
||||
device_names = set(bdm['device_name'] for bdm in block_device_mapping
|
||||
def _merge_bdms_lists(self, overrideable_mappings, overrider_mappings):
|
||||
"""Override any block devices from the first list by device name
|
||||
|
||||
:param overridable_mappings: list which items are overriden
|
||||
:param overrider_mappings: list which items override
|
||||
|
||||
:returns: A merged list of bdms
|
||||
"""
|
||||
device_names = set(bdm['device_name'] for bdm in overrider_mappings
|
||||
if bdm['device_name'])
|
||||
return (block_device_mapping +
|
||||
[bdm for bdm in image_mappings
|
||||
return (overrider_mappings +
|
||||
[bdm for bdm in overrideable_mappings
|
||||
if bdm['device_name'] not in device_names])
|
||||
|
||||
def _check_and_transform_bdm(self, context, base_options, instance_type,
|
||||
|
@ -833,8 +841,8 @@ class API(base.Base):
|
|||
block_device_mapping = (
|
||||
filter(not_image_and_root_bdm, block_device_mapping))
|
||||
|
||||
block_device_mapping = self._merge_with_image_bdms(
|
||||
block_device_mapping, image_defined_bdms)
|
||||
block_device_mapping = self._merge_bdms_lists(
|
||||
image_defined_bdms, block_device_mapping)
|
||||
|
||||
if min_count > 1 or max_count > 1:
|
||||
if any(map(lambda bdm: bdm['source_type'] == 'volume',
|
||||
|
|
|
@ -8851,6 +8851,22 @@ class ComputeAPITestCase(BaseTestCase):
|
|||
fake_v2_bdms, False)
|
||||
self.assertEqual(len(transformed_bdm), 1)
|
||||
|
||||
# Image BDM overrides mappings
|
||||
base_options['image_ref'] = FAKE_IMAGE_REF
|
||||
image_meta = {
|
||||
'properties': {
|
||||
'mappings': [
|
||||
{'virtual': 'ephemeral0', 'device': 'vdb'}],
|
||||
'bdm_v2': True,
|
||||
'block_device_mapping': [
|
||||
{'device_name': '/dev/vdb', 'source_type': 'blank',
|
||||
'destination_type': 'volume', 'volume_size': 1}]}}
|
||||
transformed_bdm = self.compute_api._check_and_transform_bdm(
|
||||
self.context, base_options, {}, image_meta, 1, 1, [], False)
|
||||
self.assertEqual(1, len(transformed_bdm))
|
||||
self.assertEqual('volume', transformed_bdm[0]['destination_type'])
|
||||
self.assertEqual('/dev/vdb', transformed_bdm[0]['device_name'])
|
||||
|
||||
def test_volume_size(self):
|
||||
ephemeral_size = 2
|
||||
swap_size = 3
|
||||
|
|
Loading…
Reference in New Issue