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>
Change-Id: I56348dc2b7abd9526dfbf21305755505765811c5
Closes-Bug: #1651064
(cherry picked from commit a65551ecd0
)
This commit is contained in:
parent
c80c8e6dbf
commit
c00d433d29
|
@ -69,7 +69,7 @@ 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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,6 +84,6 @@ block_device_mapping_v232['properties'].update(
|
|||
server_create_v232 = {
|
||||
'block_device_mapping_v2': {
|
||||
'type': 'array',
|
||||
'items': [block_device_mapping_v232]
|
||||
'items': block_device_mapping_v232
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -186,6 +186,21 @@ class BlockDeviceMappingTestV21(test.TestCase):
|
|||
self.assertRaises(exception.ValidationError,
|
||||
self._test_create, params)
|
||||
|
||||
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
|
||||
|
|
|
@ -321,7 +321,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,
|
||||
|
@ -351,6 +351,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