From b523699ce039d77e0bc02eb2c00e436c2e28a274 Mon Sep 17 00:00:00 2001 From: zhangyanzi Date: Thu, 28 Nov 2013 10:02:16 +0800 Subject: [PATCH] Fix the wrong verification for 'readonly' A mistake verification for 'readonly', fix it, and add some tests. Change-Id: Iea20245eef2e884cf4c0d8e62c2da4f1cd967106 Closes-Bug: #1255802 --- cinder/api/contrib/volume_actions.py | 5 +++-- cinder/tests/api/contrib/test_volume_actions.py | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cinder/api/contrib/volume_actions.py b/cinder/api/contrib/volume_actions.py index 61db01cf4..8086abb62 100644 --- a/cinder/api/contrib/volume_actions.py +++ b/cinder/api/contrib/volume_actions.py @@ -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) diff --git a/cinder/tests/api/contrib/test_volume_actions.py b/cinder/tests/api/contrib/test_volume_actions.py index a348b5e3b..87558b9c5 100644 --- a/cinder/tests/api/contrib/test_volume_actions.py +++ b/cinder/tests/api/contrib/test_volume_actions.py @@ -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) -- 2.45.2