]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Redundant check in os-migrate_volume_completion
authorzhangyanzi <zhangyanzi@huawei.com>
Tue, 26 Nov 2013 04:19:48 +0000 (12:19 +0800)
committerAvishay Traeger <avishay@il.ibm.com>
Sun, 26 Jan 2014 07:02:38 +0000 (09:02 +0200)
Remove the redundant check for 'migrate_volume_completion', and add the UT
for it.

Change-Id: I6b643dbf9ae1302cafe6748a361123d7d76c437f
Closes-Bug: #1254963

cinder/api/contrib/admin_actions.py
cinder/tests/api/contrib/test_admin_actions.py

index 800e7053df33c5074ee3832d163bc3c7a5fba5aa..588bc1a52e213678289910fb4c0ddc9e8deccd5f 100644 (file)
@@ -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:
index addf22b24426718fcce52d1ae5492d8d3ddc01cd..b46fa2d88f17b9448e0e9fc9fbf90731ac580ff0 100644 (file)
@@ -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,