]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Volume extend error does not catch exception
authorZhang Jinnan <zhang.jinnan@99cloud.net>
Fri, 25 Sep 2015 16:51:00 +0000 (00:51 +0800)
committerZhang Jinnan <zhang.jinnan@99cloud.net>
Mon, 12 Oct 2015 11:36:25 +0000 (19:36 +0800)
Volume extension API does not throw HTTPBadRequest response,
when input to the API is invalid.
This patch handles invalid input to the volume extension API
and return HTTPBadRequest.

APIImpact
Change-Id: I93e81514c9c1bea9fa80cfb14c5f1d4b00dd0c28

cinder/api/contrib/volume_actions.py
cinder/tests/unit/api/contrib/test_volume_actions.py

index 71123bff4afc2954c2530c4ed59e3205b16a1c41..c6e0c7195ec09b6211b4e5b2c2f50ac7bfe48b05 100644 (file)
@@ -315,7 +315,11 @@ class VolumeActionsController(wsgi.Controller):
             raise webob.exc.HTTPBadRequest(explanation=msg)
 
         size = int(body['os-extend']['new_size'])
-        self.volume_api.extend(context, volume, size)
+        try:
+            self.volume_api.extend(context, volume, size)
+        except exception.InvalidVolume as error:
+            raise webob.exc.HTTPBadRequest(explanation=error.msg)
+
         return webob.Response(status_int=202)
 
     @wsgi.action('os-update_readonly_flag')
index 2aa931e22e2900986195245e90f302515452edb4..14930d0954c5da3e0b12cd0622a334c8838f8a2e 100644 (file)
@@ -342,6 +342,22 @@ class VolumeActionsTest(test.TestCase):
         res = req.get_response(fakes.wsgi_app())
         self.assertEqual(202, res.status_int)
 
+    def test_extend_volume_invalid_status(self):
+        def fake_extend_volume(*args, **kwargs):
+            msg = "Volume status must be available"
+            raise exception.InvalidVolume(reason=msg)
+        self.stubs.Set(volume.API, 'extend',
+                       fake_extend_volume)
+
+        body = {'os-extend': {'new_size': 5}}
+        req = webob.Request.blank('/v2/fake/volumes/1/action')
+        req.method = "POST"
+        req.body = jsonutils.dumps(body)
+        req.headers["content-type"] = "application/json"
+
+        res = req.get_response(fakes.wsgi_app())
+        self.assertEqual(400, res.status_int)
+
     def test_update_readonly_flag(self):
         def fake_update_readonly_flag(*args, **kwargs):
             return {}