From 40bf16c8c90051903b3f662996fd0a15b90fd2bc Mon Sep 17 00:00:00 2001 From: Rajesh Tailor Date: Wed, 17 Jun 2015 04:35:35 -0700 Subject: [PATCH] Incorrect exception caught in qos-specs create api Caught InvalidQoSSpecs exception instead of InvalidInput exception in qos-specs create api, as _verify_prepare_qos_specs method raises InvalidQoSSpecs exception if invalid value is passed. Closes-Bug: 1466065 Change-Id: Idb7b4e6c9e323c2ca732a27a8e3286a1fa00c1f8 --- cinder/api/contrib/qos_specs_manage.py | 2 +- .../unit/api/contrib/test_qos_specs_manage.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/cinder/api/contrib/qos_specs_manage.py b/cinder/api/contrib/qos_specs_manage.py index 434bacd9d..428dfd6ba 100644 --- a/cinder/api/contrib/qos_specs_manage.py +++ b/cinder/api/contrib/qos_specs_manage.py @@ -139,7 +139,7 @@ class QoSSpecsController(wsgi.Controller): rpc.get_notifier('QoSSpecs').info(context, 'qos_specs.create', notifier_info) - except exception.InvalidInput as err: + except exception.InvalidQoSSpecs as err: notifier_err = dict(name=name, error_message=err) self._notify_qos_specs_error(context, 'qos_specs.create', 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 27119667a..10a080d3c 100644 --- a/cinder/tests/unit/api/contrib/test_qos_specs_manage.py +++ b/cinder/tests/unit/api/contrib/test_qos_specs_manage.py @@ -95,6 +95,8 @@ def return_qos_specs_create(context, name, specs): raise exception.QoSSpecsExists(specs_id=name) elif name == "555": raise exception.QoSSpecsCreateFailed(name=id, qos_specs=specs) + elif name == "444": + raise exception.InvalidQoSSpecs(reason=name) pass @@ -289,6 +291,19 @@ class QoSSpecManageApiTest(test.TestCase): self.assertEqual(1, notifier.get_notification_count()) self.assertEqual('qos_specs_1', res_dict['qos_specs']['name']) + @mock.patch('cinder.volume.qos_specs.create', + side_effect=return_qos_specs_create) + def test_create_invalid_input(self, mock_qos_get_specs): + body = {"qos_specs": {"name": "444", + "consumer": "invalid_consumer"}} + req = fakes.HTTPRequest.blank('/v2/fake/qos-specs') + + notifier = fake_notifier.get_fake_notifier() + with mock.patch('cinder.rpc.get_notifier', return_value=notifier): + self.assertRaises(webob.exc.HTTPBadRequest, + self.controller.create, req, body) + self.assertEqual(1, notifier.get_notification_count()) + @mock.patch('cinder.volume.qos_specs.create', side_effect=return_qos_specs_create) @mock.patch('cinder.volume.qos_specs.get_qos_specs_by_name', -- 2.45.2