Fix BDM JSON-Schema validation
Current BDM JSON-Schema validation doesn't work for invalid device parameter in 2nd dict, because JSON-Schema definition is wrong. This patch fixes it. Co-Authored-By: Zhenyu Zheng <zhengzhenyu@huawei.com> Conflicts: nova/api/openstack/compute/schemas/block_device_mapping.py nova/tests/unit/api/openstack/compute/test_block_device_mapping.py NOTE(mriedem): The conflicts were due to some additional validation and tests added for BDMs v2.1 in Newton which are not in Mitaka. Change-Id: I56348dc2b7abd9526dfbf21305755505765811c5 Closes-Bug: #1651064 (cherry picked from commita65551ecd0
) (cherry picked from commitc00d433d29
)
This commit is contained in:
parent
752c987789
commit
d726e0d700
|
@ -68,6 +68,6 @@ block_device_mapping['properties'].update(block_device_mapping_new_item)
|
|||
server_create = {
|
||||
'block_device_mapping_v2': {
|
||||
'type': 'array',
|
||||
'items': [block_device_mapping]
|
||||
'items': block_device_mapping
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,6 +44,6 @@ legacy_block_device_mapping = {
|
|||
server_create = {
|
||||
'block_device_mapping': {
|
||||
'type': 'array',
|
||||
'items': [legacy_block_device_mapping]
|
||||
'items': legacy_block_device_mapping
|
||||
}
|
||||
}
|
||||
|
|
|
@ -150,6 +150,21 @@ class BlockDeviceMappingTestV21(test.TestCase):
|
|||
params = {block_device_mapping.ATTRIBUTE_NAME: self.bdm}
|
||||
self._test_create(params, no_image=True)
|
||||
|
||||
def test_create_instance_with_invalid_bdm_in_2nd_dict(self):
|
||||
bdm_1st = {"source_type": "image", "delete_on_termination": True,
|
||||
"boot_index": 0,
|
||||
"uuid": "2ff3a1d3-ed70-4c3f-94ac-941461153bc0",
|
||||
"destination_type": "local"}
|
||||
bdm_2nd = {"source_type": "volume",
|
||||
"uuid": "99d92140-3d0c-4ea5-a49c-f94c38c607f0",
|
||||
"destination_type": "invalid"}
|
||||
bdm = [bdm_1st, bdm_2nd]
|
||||
|
||||
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
|
||||
|
@ -385,3 +400,8 @@ class BlockDeviceMappingTestV2(BlockDeviceMappingTestV21):
|
|||
# Add a check whether the destination type is invalid
|
||||
# in V2.1 API only. So this test is skipped in V2.0 API
|
||||
pass
|
||||
|
||||
def test_create_instance_with_invalid_bdm_in_2nd_dict(self):
|
||||
# Add a check whether the destination type is invalid
|
||||
# in V2.1 API only. So this test is skipped in V2.0 API
|
||||
pass
|
||||
|
|
|
@ -277,7 +277,7 @@ class BlockDeviceMappingTestV21(test.TestCase):
|
|||
{'device_name': 'foo2', 'volume_id': fakes.FAKE_UUID,
|
||||
'delete_on_termination': True},
|
||||
{'device_name': 'foo3', 'volume_id': fakes.FAKE_UUID,
|
||||
'delete_on_termination': 'invalid'},
|
||||
'delete_on_termination': 'False'},
|
||||
{'device_name': 'foo4', 'volume_id': fakes.FAKE_UUID,
|
||||
'delete_on_termination': False},
|
||||
{'device_name': 'foo5', 'volume_id': fakes.FAKE_UUID,
|
||||
|
@ -307,6 +307,16 @@ class BlockDeviceMappingTestV21(test.TestCase):
|
|||
self.stubs.Set(compute_api.API, '_validate_bdm', _validate_bdm)
|
||||
self._test_create(params)
|
||||
|
||||
def test_create_instance_with_bdm_delete_on_termination_invalid_2nd(self):
|
||||
bdm = [{'device_name': 'foo1', 'volume_id': fakes.FAKE_UUID,
|
||||
'delete_on_termination': 'True'},
|
||||
{'device_name': 'foo2', 'volume_id': fakes.FAKE_UUID,
|
||||
'delete_on_termination': 'invalid'}]
|
||||
|
||||
params = {'block_device_mapping': bdm}
|
||||
self.assertRaises(self.validation_error,
|
||||
self._test_create, params)
|
||||
|
||||
def test_create_instance_decide_format_legacy(self):
|
||||
ext_info = extension_info.LoadedExtensionInfo()
|
||||
CONF.set_override('extensions_blacklist',
|
||||
|
|
Loading…
Reference in New Issue