Merge "Support volume_readonly_update using XML format" into stable/havana

This commit is contained in:
Jenkins 2014-03-03 17:39:00 +00:00 committed by Gerrit Code Review
commit 0123feb082
2 changed files with 24 additions and 15 deletions

View File

@ -20,6 +20,7 @@ from cinder.api import xmlutil
from cinder import exception
from cinder.openstack.common import log as logging
from cinder.openstack.common.rpc import common as rpc_common
from cinder.openstack.common import strutils
from cinder import utils
from cinder import volume
@ -234,16 +235,17 @@ class VolumeActionsController(wsgi.Controller):
context = req.environ['cinder.context']
volume = self.volume_api.get(context, id)
if not self.is_valid_body(body, 'os-update_readonly_flag'):
msg = _("No 'os-update_readonly_flag' was specified "
"in request.")
raise webob.exc.HTTPBadRequest(explanation=msg)
readonly_flag = body['os-update_readonly_flag'].get('readonly')
if isinstance(readonly_flag, basestring):
try:
readonly_flag = strutils.bool_from_string(readonly_flag,
strict=True)
except ValueError:
msg = _("Bad value for 'readonly'")
raise webob.exc.HTTPBadRequest(explanation=msg)
if not isinstance(readonly_flag, bool):
msg = _("Volume 'readonly' flag must be specified "
"in request as a boolean.")
elif not isinstance(readonly_flag, bool):
msg = _("'readonly' not string or bool")
raise webob.exc.HTTPBadRequest(explanation=msg)
self.volume_api.update_readonly_flag(context, volume, readonly_flag)

View File

@ -209,14 +209,21 @@ class VolumeActionsTest(test.TestCase):
self.stubs.Set(volume.API, 'update_readonly_flag',
fake_update_readonly_flag)
body = {'os-update_readonly_flag': {'readonly': True}}
req = webob.Request.blank('/v2/fake/volumes/1/action')
req.method = "POST"
req.body = jsonutils.dumps(body)
req.headers["content-type"] = "application/json"
def make_update_readonly_flag_test(self, readonly, return_code):
body = {"os-update_readonly_flag": {"readonly": readonly}}
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(res.status_int, return_code)
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 202)
make_update_readonly_flag_test(self, True, 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)
make_update_readonly_flag_test(self, 'tt', 400)
make_update_readonly_flag_test(self, 11, 400)
def stub_volume_get(self, context, volume_id):