From: zhangyanzi Date: Tue, 26 Nov 2013 06:39:18 +0000 (+0800) Subject: Redundant body validation for volume_upload_image X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=4a8ad10c3d5d79e09805c28486bd0f8a5a16c511;p=openstack-build%2Fcinder-build.git Redundant body validation for volume_upload_image The body validation is redundant for os-volume_upload_image,should remove the redundant validation. Change-Id: Iba7a4d5f917615f8a8d6320b5fe18af66e4011e0 Closes-Bug: #1254975 --- diff --git a/cinder/api/contrib/volume_actions.py b/cinder/api/contrib/volume_actions.py index 40179b9c7..9b60af0bd 100644 --- a/cinder/api/contrib/volume_actions.py +++ b/cinder/api/contrib/volume_actions.py @@ -215,12 +215,7 @@ class VolumeActionsController(wsgi.Controller): def _volume_upload_image(self, req, id, body): """Uploads the specified volume to image service.""" context = req.environ['cinder.context'] - try: - params = body['os-volume_upload_image'] - except (TypeError, KeyError): - msg = _("Invalid request body") - raise webob.exc.HTTPBadRequest(explanation=msg) - + params = body['os-volume_upload_image'] if not params.get("image_name"): msg = _("No image_name was specified in request.") raise webob.exc.HTTPBadRequest(explanation=msg) diff --git a/cinder/tests/api/contrib/test_volume_actions.py b/cinder/tests/api/contrib/test_volume_actions.py index 45658ac04..ff25a05ae 100644 --- a/cinder/tests/api/contrib/test_volume_actions.py +++ b/cinder/tests/api/contrib/test_volume_actions.py @@ -15,6 +15,7 @@ # under the License. import datetime +import json import uuid import webob @@ -395,13 +396,28 @@ class VolumeImageActionsTest(test.TestCase): body) def test_volume_upload_image_typeerror(self): + id = 1 body = {"os-volume_upload_image_fake": "fake"} - req = fakes.HTTPRequest.blank('/v2/tenant1/volumes/%s/action' % id) - self.assertRaises(webob.exc.HTTPBadRequest, - self.controller._volume_upload_image, - req, - id, - body) + req = webob.Request.blank('/v2/tenant1/volumes/%s/action' % id) + req.method = 'POST' + req.headers['Content-Type'] = 'application/json' + req.body = json.dumps(body) + res = req.get_response(fakes.wsgi_app()) + self.assertEqual(res.status_int, 400) + + def test_volume_upload_image_without_type(self): + id = 1 + vol = {"container_format": 'bare', + "disk_format": 'raw', + "image_name": None, + "force": True} + body = {"": vol} + req = webob.Request.blank('/v2/tenant1/volumes/%s/action' % id) + req.method = 'POST' + req.headers['Content-Type'] = 'application/json' + req.body = json.dumps(body) + res = req.get_response(fakes.wsgi_app()) + self.assertEqual(res.status_int, 400) def test_extend_volume_valueerror(self): id = 1