Merge "Redundant body validation for volume_upload_image"
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
# under the License.
|
||||
|
||||
import datetime
|
||||
import json
|
||||
import uuid
|
||||
import webob
|
||||
|
||||
@@ -400,13 +401,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
|
||||
|
||||
Reference in New Issue
Block a user