From: zhangyanzi Date: Tue, 26 Nov 2013 04:19:48 +0000 (+0800) Subject: Redundant check in os-migrate_volume_completion X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=a0693a91f55b2b08a46f1396dd1a1102783df9c6;p=openstack-build%2Fcinder-build.git Redundant check in os-migrate_volume_completion Remove the redundant check for 'migrate_volume_completion', and add the UT for it. Change-Id: I6b643dbf9ae1302cafe6748a361123d7d76c437f Closes-Bug: #1254963 --- diff --git a/cinder/api/contrib/admin_actions.py b/cinder/api/contrib/admin_actions.py index 800e7053d..588bc1a52 100644 --- a/cinder/api/contrib/admin_actions.py +++ b/cinder/api/contrib/admin_actions.py @@ -173,11 +173,7 @@ class VolumeAdminController(AdminController): volume = self._get(context, id) except exception.NotFound: raise exc.HTTPNotFound() - try: - params = body['os-migrate_volume_completion'] - except KeyError: - raise exc.HTTPBadRequest("Body does not contain " - "'os-migrate_volume_completion'") + params = body['os-migrate_volume_completion'] try: new_volume_id = params['new_volume'] except KeyError: diff --git a/cinder/tests/api/contrib/test_admin_actions.py b/cinder/tests/api/contrib/test_admin_actions.py index addf22b24..b46fa2d88 100644 --- a/cinder/tests/api/contrib/test_admin_actions.py +++ b/cinder/tests/api/contrib/test_admin_actions.py @@ -653,12 +653,15 @@ class AdminActionsTest(test.TestCase): force_host_copy=1) def _migrate_volume_comp_exec(self, ctx, volume, new_volume, error, - expected_status, expected_id): + expected_status, expected_id, no_body=False): req = webob.Request.blank('/v2/fake/volumes/%s/action' % volume['id']) req.method = 'POST' req.headers['content-type'] = 'application/json' - body_dict = {'new_volume': new_volume['id'], 'error': error} - req.body = jsonutils.dumps({'os-migrate_volume_completion': body_dict}) + body = {'new_volume': new_volume['id'], 'error': error} + if no_body: + req.body = jsonutils.dumps({'': body}) + else: + req.body = jsonutils.dumps({'os-migrate_volume_completion': body}) req.environ['cinder.context'] = ctx resp = req.get_response(app()) resp_dict = ast.literal_eval(resp.body) @@ -707,6 +710,16 @@ class AdminActionsTest(test.TestCase): volume = self._migrate_volume_comp_exec(ctx, volume1, volume2, False, expected_status, expected_id) + def test_migrate_volume_comp_no_action(self): + admin_ctx = context.get_admin_context() + volume = db.volume_create(admin_ctx, {'id': 'fake1'}) + new_volume = db.volume_create(admin_ctx, {'id': 'fake2'}) + expected_status = 400 + expected_id = None + ctx = context.RequestContext('fake', 'fake') + self._migrate_volume_comp_exec(ctx, volume, new_volume, False, + expected_status, expected_id, True) + def test_migrate_volume_comp_from_nova(self): admin_ctx = context.get_admin_context() volume = db.volume_create(admin_ctx,