diff --git a/cinder/tests/unit/api/contrib/test_types_manage.py b/cinder/tests/unit/api/contrib/test_types_manage.py index 81beff6ae85..95bbb38c9be 100644 --- a/cinder/tests/unit/api/contrib/test_types_manage.py +++ b/cinder/tests/unit/api/contrib/test_types_manage.py @@ -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, diff --git a/cinder/utils.py b/cinder/utils.py index ff0e59659c4..8e8bada962a 100644 --- a/cinder/utils.py +++ b/cinder/utils.py @@ -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,