diff --git a/cinder/api/contrib/qos_specs_manage.py b/cinder/api/contrib/qos_specs_manage.py index 2dc95d34b2e..b24d220f329 100644 --- a/cinder/api/contrib/qos_specs_manage.py +++ b/cinder/api/contrib/qos_specs_manage.py @@ -83,10 +83,15 @@ class QoSSpecsController(wsgi.Controller): msg = _("Please specify a name for QoS specs.") raise webob.exc.HTTPBadRequest(explanation=msg) - utils.validate_dictionary_string_length(specs) + self.validate_string_length(name, 'name', min_length=1, + max_length=255, remove_whitespaces=True) name = name.strip() # Remove name from 'specs' since passing it in as separate param del specs['name'] + + # Validate the key-value pairs in the qos spec. + utils.validate_dictionary_string_length(specs) + try: spec = qos_specs.create(context, name, specs) notifier_info = dict(name=name, specs=specs) diff --git a/cinder/tests/unit/api/contrib/test_qos_specs_manage.py b/cinder/tests/unit/api/contrib/test_qos_specs_manage.py index b24bab88a74..ca672a05809 100644 --- a/cinder/tests/unit/api/contrib/test_qos_specs_manage.py +++ b/cinder/tests/unit/api/contrib/test_qos_specs_manage.py @@ -458,8 +458,7 @@ class QoSSpecManageApiTest(test.TestCase): @ddt.data({'name': 'fake_name', 'a' * 256: 'a'}, {'name': 'fake_name', 'a': 'a' * 256}, - {'name': 'fake_name' * 256, 'a': 'a'}, - {'name': 'fake_name' * 256, '': 'a'}) + {'name': 'fake_name', '': 'a'}) def test_create_qos_with_invalid_specs(self, value): body = {'qos_specs': value} req = fakes.HTTPRequest.blank('/v2/%s/qos-specs' % fake.PROJECT_ID, @@ -468,6 +467,18 @@ class QoSSpecManageApiTest(test.TestCase): self.assertRaises(exception.InvalidInput, self.controller.create, req, body) + @ddt.data({'name': None}, + {'name': 'n' * 256}, + {'name': ''}, + {'name': ' '}) + def test_create_qos_with_invalid_spec_name(self, value): + body = {'qos_specs': value} + req = fakes.HTTPRequest.blank('/v2/%s/qos-specs' % fake.PROJECT_ID, + use_admin_context=True) + req.method = 'POST' + self.assertRaises(webob.exc.HTTPBadRequest, + self.controller.create, req, body) + @mock.patch('cinder.volume.qos_specs.update', side_effect=return_qos_specs_update) def test_update(self, mock_qos_update):