From: Hiroyuki Eguchi Date: Mon, 21 Apr 2014 07:31:16 +0000 (+0900) Subject: Add set-bootable command X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=5669fc434acd72dfe710760360f8eafd416fb77c;p=openstack-build%2Fcinder-build.git Add set-bootable command Bootable Status is set to "True" automatically when user create a volume from a image. But user have to set bootable status manually when creating a bootable volume manually. blueprint add-bootable-option this commit is related to https://review.openstack.org/#/c/83691/ Change-Id: Ib6cdca15950fe86b4fb2a43cfc7338e28260e453 --- diff --git a/cinder/api/contrib/volume_actions.py b/cinder/api/contrib/volume_actions.py index 22cb24eea..0f8a8b860 100644 --- a/cinder/api/contrib/volume_actions.py +++ b/cinder/api/contrib/volume_actions.py @@ -332,6 +332,38 @@ class VolumeActionsController(wsgi.Controller): self.volume_api.retype(context, volume, new_type, policy) return webob.Response(status_int=202) + @wsgi.action('os-set_bootable') + def _set_bootable(self, req, id, body): + """Update bootable status of a volume.""" + context = req.environ['cinder.context'] + try: + volume = self.volume_api.get(context, id) + except exception.VolumeNotFound as error: + raise webob.exc.HTTPNotFound(explanation=error.msg) + + try: + bootable = body['os-set_bootable']['bootable'] + except KeyError: + msg = _("Must specify bootable in request.") + raise webob.exc.HTTPBadRequest(explanation=msg) + + if isinstance(bootable, basestring): + try: + bootable = strutils.bool_from_string(bootable, + strict=True) + except ValueError: + msg = _("Bad value for 'bootable'") + raise webob.exc.HTTPBadRequest(explanation=msg) + + elif not isinstance(bootable, bool): + msg = _("'bootable' not string or bool") + raise webob.exc.HTTPBadRequest(explanation=msg) + + update_dict = {'bootable': bootable} + + self.volume_api.update(context, volume, update_dict) + return webob.Response(status_int=200) + class Volume_actions(extensions.ExtensionDescriptor): """Enable volume actions diff --git a/cinder/tests/api/contrib/test_volume_actions.py b/cinder/tests/api/contrib/test_volume_actions.py index f38281010..86eb12320 100644 --- a/cinder/tests/api/contrib/test_volume_actions.py +++ b/cinder/tests/api/contrib/test_volume_actions.py @@ -287,6 +287,29 @@ class VolumeActionsTest(test.TestCase): make_update_readonly_flag_test(self, 11, 400) make_update_readonly_flag_test(self, None, 400) + def test_set_bootable(self): + + def make_set_bootable_test(self, bootable, return_code): + body = {"os-set_bootable": {"bootable": bootable}} + if bootable is None: + body = {"os-set_bootable": {}} + 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) + + make_set_bootable_test(self, True, 200) + make_set_bootable_test(self, False, 200) + make_set_bootable_test(self, '1', 200) + make_set_bootable_test(self, '0', 200) + make_set_bootable_test(self, 'true', 200) + make_set_bootable_test(self, 'false', 200) + make_set_bootable_test(self, 'tt', 400) + make_set_bootable_test(self, 11, 400) + make_set_bootable_test(self, None, 400) + class VolumeRetypeActionsTest(VolumeActionsTest): def setUp(self):