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:
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'