]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
The param 'readonly' is incorrect checked
authorzhangyanzi <zhangyanzi@huawei.com>
Mon, 25 Nov 2013 11:33:49 +0000 (19:33 +0800)
committerzhangyanzi <zhangyanzi@huawei.com>
Mon, 25 Nov 2013 11:43:47 +0000 (19:43 +0800)
In the function os-update_readonly_flag, the param 'readonly' is incorrect
checked, without the param in request, i think it should raise exception
with message like "Must specify readonly in request."

Change-Id: I19e15e988ffa2d093d374f6a33ce94d45ffe2c30
Closes-bug: 1254682

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

index 40179b9c70d046750aedb9c1e2351884adca93e3..61db01cf4f6e7f0f8f35acd1cb6074cca53e5e0d 100644 (file)
@@ -280,6 +280,10 @@ class VolumeActionsController(wsgi.Controller):
             raise webob.exc.HTTPNotFound(explanation=error.msg)
 
         readonly_flag = body['os-update_readonly_flag'].get('readonly')
+        if not readonly_flag:
+            msg = _("Must specify readonly in request.")
+            raise webob.exc.HTTPBadRequest(explanation=msg)
+
         if isinstance(readonly_flag, basestring):
             try:
                 readonly_flag = strutils.bool_from_string(readonly_flag,
index 45658ac04e958bc69b98b413f4f254cf335c5260..a348b5e3bc1a1b99ca6247015518bc86968a412c 100644 (file)
@@ -241,6 +241,8 @@ class VolumeActionsTest(test.TestCase):
 
         def make_update_readonly_flag_test(self, readonly, return_code):
             body = {"os-update_readonly_flag": {"readonly": readonly}}
+            if readonly is None:
+                body = {"os-update_readonly_flag": {}}
             req = webob.Request.blank('/v2/fake/volumes/1/action')
             req.method = "POST"
             req.body = jsonutils.dumps(body)
@@ -254,6 +256,7 @@ class VolumeActionsTest(test.TestCase):
         make_update_readonly_flag_test(self, 'false', 202)
         make_update_readonly_flag_test(self, 'tt', 400)
         make_update_readonly_flag_test(self, 11, 400)
+        make_update_readonly_flag_test(self, None, 400)
 
 
 def stub_volume_get(self, context, volume_id):