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
This commit is contained in:
Hiroyuki Eguchi 2014-04-21 16:31:16 +09:00
parent fed5843972
commit 5669fc434a
2 changed files with 55 additions and 0 deletions

View File

@ -332,6 +332,38 @@ class VolumeActionsController(wsgi.Controller):
self.volume_api.retype(context, volume, new_type, policy) self.volume_api.retype(context, volume, new_type, policy)
return webob.Response(status_int=202) 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): class Volume_actions(extensions.ExtensionDescriptor):
"""Enable volume actions """Enable volume actions

View File

@ -287,6 +287,29 @@ class VolumeActionsTest(test.TestCase):
make_update_readonly_flag_test(self, 11, 400) make_update_readonly_flag_test(self, 11, 400)
make_update_readonly_flag_test(self, None, 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): class VolumeRetypeActionsTest(VolumeActionsTest):
def setUp(self): def setUp(self):