Remove unused validation code from block_device
BDM code had some input validation code, however that is not used at all because json-schema has validated the input before passing the input to BDM code. For example, source_type and boot_index are validated with 'source_type': { 'type': 'string', 'enum': ['volume', 'image', 'snapshot', 'blank'], }, 'boot_index': { 'type': ['integer', 'string', 'null'], 'pattern': '^-?[0-9]+$', }, So Nova doesn't need to have the BDM code and this patch removes it. This patch adds the corresponding test. Change-Id: I278baead330c32d39f3d6c42077e3563205eed35
This commit is contained in:
parent
d4e70a4275
commit
b36bdf393d
|
@ -184,10 +184,7 @@ class BlockDeviceDict(dict):
|
|||
device_uuid = api_dict.get('uuid')
|
||||
destination_type = api_dict.get('destination_type')
|
||||
|
||||
if source_type not in ('volume', 'image', 'snapshot', 'blank'):
|
||||
raise exception.InvalidBDMFormat(
|
||||
details=_("Invalid source_type field."))
|
||||
elif source_type == 'blank' and device_uuid:
|
||||
if source_type == 'blank' and device_uuid:
|
||||
raise exception.InvalidBDMFormat(
|
||||
details=_("Invalid device UUID."))
|
||||
elif source_type != 'blank':
|
||||
|
@ -196,17 +193,14 @@ class BlockDeviceDict(dict):
|
|||
details=_("Missing device UUID."))
|
||||
api_dict[source_type + '_id'] = device_uuid
|
||||
if source_type == 'image' and destination_type == 'local':
|
||||
try:
|
||||
# NOTE(mriedem): boot_index can be None so we need to
|
||||
# account for that to avoid a TypeError.
|
||||
boot_index = api_dict.get('boot_index', -1)
|
||||
if boot_index is None:
|
||||
# boot_index=None is equivalent to -1.
|
||||
boot_index = -1
|
||||
boot_index = int(boot_index)
|
||||
except ValueError:
|
||||
raise exception.InvalidBDMFormat(
|
||||
details=_("Boot index is invalid."))
|
||||
# NOTE(mriedem): boot_index can be None so we need to
|
||||
# account for that to avoid a TypeError.
|
||||
boot_index = api_dict.get('boot_index', -1)
|
||||
if boot_index is None:
|
||||
# boot_index=None is equivalent to -1.
|
||||
boot_index = -1
|
||||
boot_index = int(boot_index)
|
||||
|
||||
# if this bdm is generated from --image ,then
|
||||
# source_type = image and destination_type = local is allowed
|
||||
if not (image_uuid_specified and boot_index == 0):
|
||||
|
|
|
@ -247,6 +247,17 @@ class BlockDeviceMappingTestV21(test.TestCase):
|
|||
self.assertRaises(exc.HTTPBadRequest, self._test_create,
|
||||
params, no_image=True)
|
||||
|
||||
def test_create_instance_with_invalid_boot_index(self):
|
||||
bdm = [{"source_type": "image", "delete_on_termination": True,
|
||||
"boot_index": 'invalid',
|
||||
"uuid": "2ff3a1d3-ed70-4c3f-94ac-941461153bc0",
|
||||
"destination_type": "local"}]
|
||||
|
||||
params = {block_device_mapping.ATTRIBUTE_NAME: bdm,
|
||||
'imageRef': '2ff3a1d3-ed70-4c3f-94ac-941461153bc0'}
|
||||
self.assertRaises(exception.ValidationError,
|
||||
self._test_create, params)
|
||||
|
||||
def test_create_instance_with_device_name_not_string(self):
|
||||
self.bdm[0]['device_name'] = 123
|
||||
old_create = compute_api.API.create
|
||||
|
|
|
@ -581,16 +581,6 @@ class TestBlockDeviceDict(test.NoDBTestCase):
|
|||
self.assertEqual(retexp,
|
||||
block_device.BlockDeviceDict.from_api(api_dict, True))
|
||||
|
||||
def test_from_api_invalid_source_to_local_mapping_with_string_bi(self):
|
||||
api_dict = {'id': 1,
|
||||
'source_type': 'image',
|
||||
'destination_type': 'local',
|
||||
'uuid': 'fake-volume-id-1',
|
||||
'boot_index': 'aaaa0'}
|
||||
self.assertRaises(exception.InvalidBDMFormat,
|
||||
block_device.BlockDeviceDict.from_api, api_dict,
|
||||
False)
|
||||
|
||||
def test_from_api_valid_source_to_local_mapping_with_string_bi(self):
|
||||
api_dict = {'id': 1,
|
||||
'source_type': 'image',
|
||||
|
|
Loading…
Reference in New Issue