]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Redundant body validation for volume_upload_image
authorzhangyanzi <zhangyanzi@huawei.com>
Tue, 26 Nov 2013 06:39:18 +0000 (14:39 +0800)
committerzhangyanzi <zhangyanzi@huawei.com>
Wed, 27 Nov 2013 09:45:16 +0000 (17:45 +0800)
The body validation is redundant for os-volume_upload_image,should remove
the redundant validation.

Change-Id: Iba7a4d5f917615f8a8d6320b5fe18af66e4011e0
Closes-Bug: #1254975

cinder/api/contrib/volume_actions.py
cinder/tests/api/contrib/test_volume_actions.py

index 40179b9c70d046750aedb9c1e2351884adca93e3..9b60af0bd77f022280fde1435939d1bf3d56e163 100644 (file)
@@ -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)
index 45658ac04e958bc69b98b413f4f254cf335c5260..ff25a05ae952055b875d730ce44fc4396f3f24d6 100644 (file)
@@ -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