Merge "The param 'readonly' is incorrect checked"

This commit is contained in:
Jenkins 2013-11-27 10:16:56 +00:00 committed by Gerrit Code Review
commit 1c6ad3872a
2 changed files with 7 additions and 0 deletions

View 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,

View 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):