Reject unsupported image to local BDM
Specifying image to local BDM at nova boot is not supported. This patch adds a validation to the API to reject this not supported mapping. Closes-bug: #1377958 Change-Id: I0c38134e2aacca83d98ed0b341f15c480afe14f1
This commit is contained in:
@@ -182,6 +182,7 @@ class BlockDeviceDict(dict):
|
|||||||
|
|
||||||
source_type = api_dict.get('source_type')
|
source_type = api_dict.get('source_type')
|
||||||
device_uuid = api_dict.get('uuid')
|
device_uuid = api_dict.get('uuid')
|
||||||
|
destination_type = api_dict.get('destination_type')
|
||||||
|
|
||||||
if source_type not in ('volume', 'image', 'snapshot', 'blank'):
|
if source_type not in ('volume', 'image', 'snapshot', 'blank'):
|
||||||
raise exception.InvalidBDMFormat(
|
raise exception.InvalidBDMFormat(
|
||||||
@@ -194,6 +195,9 @@ class BlockDeviceDict(dict):
|
|||||||
raise exception.InvalidBDMFormat(
|
raise exception.InvalidBDMFormat(
|
||||||
details=_("Missing device UUID."))
|
details=_("Missing device UUID."))
|
||||||
api_dict[source_type + '_id'] = device_uuid
|
api_dict[source_type + '_id'] = device_uuid
|
||||||
|
if source_type == 'image' and destination_type == 'local':
|
||||||
|
raise exception.InvalidBDMFormat(
|
||||||
|
details=_("Mapping image to local is not supported."))
|
||||||
|
|
||||||
api_dict.pop('uuid', None)
|
api_dict.pop('uuid', None)
|
||||||
return cls(api_dict)
|
return cls(api_dict)
|
||||||
|
|||||||
@@ -534,6 +534,14 @@ class TestBlockDeviceDict(test.NoDBTestCase):
|
|||||||
self.assertRaises(exception.InvalidBDMFormat,
|
self.assertRaises(exception.InvalidBDMFormat,
|
||||||
block_device.BlockDeviceDict.from_api, api_dict)
|
block_device.BlockDeviceDict.from_api, api_dict)
|
||||||
|
|
||||||
|
def test_from_api_invalid_source_to_local_mapping(self):
|
||||||
|
api_dict = {'id': 1,
|
||||||
|
'source_type': 'image',
|
||||||
|
'destination_type': 'local',
|
||||||
|
'uuid': 'fake-volume-id-1'}
|
||||||
|
self.assertRaises(exception.InvalidBDMFormat,
|
||||||
|
block_device.BlockDeviceDict.from_api, api_dict)
|
||||||
|
|
||||||
def test_legacy(self):
|
def test_legacy(self):
|
||||||
for legacy, new in zip(self.legacy_mapping, self.new_mapping):
|
for legacy, new in zip(self.legacy_mapping, self.new_mapping):
|
||||||
self.assertThat(
|
self.assertThat(
|
||||||
|
|||||||
Reference in New Issue
Block a user