]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix the wrong verification for 'readonly'
authorzhangyanzi <zhangyanzi@huawei.com>
Thu, 28 Nov 2013 02:02:16 +0000 (10:02 +0800)
committerzhangyanzi <zhangyanzi@huawei.com>
Thu, 28 Nov 2013 02:02:16 +0000 (10:02 +0800)
A mistake verification for 'readonly', fix it, and add some tests.

Change-Id: Iea20245eef2e884cf4c0d8e62c2da4f1cd967106
Closes-Bug: #1255802

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

index 61db01cf4f6e7f0f8f35acd1cb6074cca53e5e0d..8086abb628e8c2d9bf99b9209affb4dce91be94f 100644 (file)
@@ -279,8 +279,9 @@ class VolumeActionsController(wsgi.Controller):
         except exception.VolumeNotFound as error:
             raise webob.exc.HTTPNotFound(explanation=error.msg)
 
-        readonly_flag = body['os-update_readonly_flag'].get('readonly')
-        if not readonly_flag:
+        try:
+            readonly_flag = body['os-update_readonly_flag']['readonly']
+        except KeyError:
             msg = _("Must specify readonly in request.")
             raise webob.exc.HTTPBadRequest(explanation=msg)
 
index a348b5e3bc1a1b99ca6247015518bc86968a412c..87558b9c51f5f97a0e2e4f909c161071ebbfd15d 100644 (file)
@@ -251,6 +251,8 @@ class VolumeActionsTest(test.TestCase):
             self.assertEqual(res.status_int, return_code)
 
         make_update_readonly_flag_test(self, True, 202)
+        make_update_readonly_flag_test(self, False, 202)
+        make_update_readonly_flag_test(self, '1', 202)
         make_update_readonly_flag_test(self, '0', 202)
         make_update_readonly_flag_test(self, 'true', 202)
         make_update_readonly_flag_test(self, 'false', 202)