Validate extra_specs type
Currently volume type creation with extra_specs set to null or a string fails with AttributeError. This is because the current validation logic assumes that extra_specs is a dictionary. This patch fixes it by checking whether extra_specs is a dictionary and raises InvalidInput if it is not. Change-Id: Icc3580b5b1d784fa9c7fe07ac1c539af1b292075 Closes-bug: #1599106
This commit is contained in:
parent
4415c6fcb5
commit
618139e5f7
@ -344,7 +344,9 @@ class VolumeTypesManageApiTest(test.TestCase):
|
||||
|
||||
@ddt.data({'a' * 256: 'a'},
|
||||
{'a': 'a' * 256},
|
||||
{'': 'a'})
|
||||
{'': 'a'},
|
||||
'foo',
|
||||
None)
|
||||
def test_create_type_with_invalid_extra_specs(self, value):
|
||||
body = {"volume_type": {"name": "vol_type_1",
|
||||
"os-volume-type-access:is_public": False,
|
||||
|
@ -1063,6 +1063,10 @@ def validate_integer(value, name, min_value=None, max_value=None):
|
||||
|
||||
def validate_extra_specs(specs):
|
||||
"""Validating key and value of extra specs."""
|
||||
if not isinstance(specs, dict):
|
||||
msg = _('extra_specs must be a dictionary.')
|
||||
raise exception.InvalidInput(reason=msg)
|
||||
|
||||
for key, value in specs.items():
|
||||
if key is not None:
|
||||
check_string_length(key, 'Key "%s"' % key,
|
||||
|
Loading…
x
Reference in New Issue
Block a user