diff --git a/cinder/api/contrib/types_manage.py b/cinder/api/contrib/types_manage.py index b22d239ad74..9998da443f3 100644 --- a/cinder/api/contrib/types_manage.py +++ b/cinder/api/contrib/types_manage.py @@ -58,6 +58,7 @@ class VolumeTypesManageController(wsgi.Controller): name = vol_type.get('name', None) description = vol_type.get('description') specs = vol_type.get('extra_specs', {}) + utils.validate_extra_specs(specs) is_public = vol_type.get('os-volume-type-access:is_public', True) if name is None or len(name.strip()) == 0: diff --git a/cinder/tests/unit/api/contrib/test_types_manage.py b/cinder/tests/unit/api/contrib/test_types_manage.py index 48cffe45253..81beff6ae85 100644 --- a/cinder/tests/unit/api/contrib/test_types_manage.py +++ b/cinder/tests/unit/api/contrib/test_types_manage.py @@ -17,6 +17,8 @@ import mock import six import webob +import ddt + from cinder.api.contrib import types_manage from cinder import context from cinder import exception @@ -134,6 +136,7 @@ def return_volume_types_get_default_not_found(): return {} +@ddt.ddt class VolumeTypesManageApiTest(test.TestCase): def setUp(self): super(VolumeTypesManageApiTest, self).setUp() @@ -339,6 +342,18 @@ class VolumeTypesManageApiTest(test.TestCase): self.controller._create, req, body) + @ddt.data({'a' * 256: 'a'}, + {'a': 'a' * 256}, + {'': 'a'}) + def test_create_type_with_invalid_extra_specs(self, value): + body = {"volume_type": {"name": "vol_type_1", + "os-volume-type-access:is_public": False, + "description": "test description"}} + body['volume_type']['extra_specs'] = value + req = fakes.HTTPRequest.blank('/v2/%s/types' % fake.PROJECT_ID) + self.assertRaises(exception.InvalidInput, + self.controller._create, req, body) + @mock.patch('cinder.volume.volume_types.update') @mock.patch('cinder.volume.volume_types.get_volume_type') def test_update(self, mock_get, mock_update):