]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Incorrect exception caught in qos-specs create api
authorRajesh Tailor <rajesh.tailor@nttdata.com>
Wed, 17 Jun 2015 11:35:35 +0000 (04:35 -0700)
committerRajesh Tailor <rajesh.tailor@nttdata.com>
Thu, 18 Jun 2015 13:12:57 +0000 (06:12 -0700)
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
cinder/tests/unit/api/contrib/test_qos_specs_manage.py

index 434bacd9d44ef083937bfe2c76b4ff250579eafb..428dfd6bab6fc37f19198ca7bda0911176a448a5 100644 (file)
@@ -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',
index 27119667aad13e35df63d6abe090e3fd7e3fe833..10a080d3c1521476df22b71d8eeca5c8e5a191d5 100644 (file)
@@ -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',