Skip to content
Permalink
Browse files

Migrate volume should check para "host" in request

The server doesn't check whether the parameter "host" is in request
body. So the 500 error has been thrown.

We should catch the KeyError and transfer the KeyError to
400 (HTTPBadRequest) instead of 500.

Closes-Bug: #1253904
Change-Id: I3fb07113816a87f284b47e32bacd57f78a32676c
  • Loading branch information...
huangtianhua authored and avishay-traeger committed Nov 22, 2013
1 parent 791f5a0 commit 58db021240cafb33f602aba50fdaa9060c15d84a
Showing with 21 additions and 1 deletion.
  1. +4 −1 cinder/api/contrib/admin_actions.py
  2. +17 −0 cinder/tests/api/contrib/test_admin_actions.py
@@ -148,7 +148,10 @@ def _migrate_volume(self, req, id, body):
except exception.NotFound:
raise exc.HTTPNotFound()
params = body['os-migrate_volume']
host = params['host']
try:
host = params['host']
except KeyError:
raise exc.HTTPBadRequest("Must specify 'host'")
force_host_copy = params.get('force_host_copy', False)
if isinstance(force_host_copy, basestring):
try:
@@ -584,6 +584,23 @@ def test_migrate_volume_as_non_admin(self):
volume = self._migrate_volume_prep()
self._migrate_volume_exec(ctx, volume, host, expected_status)

def test_migrate_volume_without_host_parameter(self):
expected_status = 400
host = 'test3'
ctx = context.RequestContext('admin', 'fake', True)
volume = self._migrate_volume_prep()
# build request to migrate without host
req = webob.Request.blank('/v2/fake/volumes/%s/action' % volume['id'])
req.method = 'POST'
req.headers['content-type'] = 'application/json'
body = {'os-migrate_volume': {'host': host,
'force_host_copy': False}}
req.body = jsonutils.dumps(body)
req.environ['cinder.context'] = ctx
resp = req.get_response(app())
# verify status
self.assertEqual(resp.status_int, expected_status)

def test_migrate_volume_host_no_exist(self):
expected_status = 400
host = 'test3'

0 comments on commit 58db021

Please sign in to comment.
You can’t perform that action at this time.