From: ling-yun Date: Fri, 3 Jan 2014 07:56:05 +0000 (+0800) Subject: add 'force' verification in _volume_upload_image X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=04e333f78ec8f22cdc0f0ab8701ae6a277bacbd5;p=openstack-build%2Fcinder-build.git add 'force' verification in _volume_upload_image _volume_upload_image API should only support to upload 'in-use' volume to image when assign 'force' parameter as true value. Now _volume_upload_image API does not do verification for 'force' parameter, so we can upload 'in-use' volume to image when assign 'force' parameter with string value 'false' or 'false111'. This patch add verification for 'force' parameter. Change-Id: I9e1d0e517d0ff97c136903dd6e50a305e18651f3 Closes-Bug: #1265718 --- diff --git a/cinder/api/contrib/volume_actions.py b/cinder/api/contrib/volume_actions.py index 1e9cc529d..ad18765d0 100644 --- a/cinder/api/contrib/volume_actions.py +++ b/cinder/api/contrib/volume_actions.py @@ -230,6 +230,16 @@ class VolumeActionsController(wsgi.Controller): raise webob.exc.HTTPBadRequest(explanation=msg) force = params.get('force', False) + if isinstance(force, basestring): + try: + force = strutils.bool_from_string(force, strict=False) + except ValueError: + msg = _("Bad value for 'force' parameter.") + raise webob.exc.HTTPBadRequest(explanation=msg) + elif not isinstance(force, bool): + msg = _("'force' is not string or bool.") + raise webob.exc.HTTPBadRequest(explanation=msg) + try: volume = self.volume_api.get(context, id) except exception.VolumeNotFound as error: