]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Remove the redundant judgment for 'restore'
authorzhangyanzi <zhangyanzi@huawei.com>
Mon, 25 Nov 2013 11:13:52 +0000 (19:13 +0800)
committerzhangyanzi <zhangyanzi@huawei.com>
Tue, 26 Nov 2013 02:18:10 +0000 (10:18 +0800)
In the function 'restore', there is redundant judgment for the body, it
should be removed.

Change-Id: Icfc5ae20141fad9d72de227cf5c06ca8504bd22c
Closes-Bug: 1254671

cinder/api/contrib/backups.py
cinder/tests/api/contrib/test_backups.py

index e284baa29ddf1eb8210cddbba9ada3c7b2a0ce35..07c7e3a0395d452f746e6b6aedf41056cb612191 100644 (file)
@@ -224,15 +224,11 @@ class BackupsController(wsgi.Controller):
         LOG.debug(_('Restoring backup %(backup_id)s (%(body)s)'),
                   {'backup_id': id, 'body': body})
         if not self.is_valid_body(body, 'restore'):
-            raise exc.HTTPBadRequest()
-
-        context = req.environ['cinder.context']
-
-        try:
-            restore = body['restore']
-        except KeyError:
             msg = _("Incorrect request body format")
             raise exc.HTTPBadRequest(explanation=msg)
+
+        context = req.environ['cinder.context']
+        restore = body['restore']
         volume_id = restore.get('volume_id', None)
 
         LOG.audit(_("Restoring backup %(backup_id)s to volume %(volume_id)s"),
index 0ff300e75d39c1ad509458097fd4e54e7624557c..a0474f33773a50ad5a02c050a04836ebb52c0dd1 100644 (file)
@@ -685,8 +685,7 @@ class BackupsAPITestCase(test.TestCase):
         self.assertEqual(res.status_int, 400)
         self.assertEqual(res_dict['badRequest']['code'], 400)
         self.assertEqual(res_dict['badRequest']['message'],
-                         'The server could not comply with the request since'
-                         ' it is either malformed or otherwise incorrect.')
+                         'Incorrect request body format')
 
         db.backup_destroy(context.get_admin_context(), backup_id)
 
@@ -707,8 +706,7 @@ class BackupsAPITestCase(test.TestCase):
         self.assertEqual(res.status_int, 400)
         self.assertEqual(res_dict['badRequest']['code'], 400)
         self.assertEqual(res_dict['badRequest']['message'],
-                         'The server could not comply with the request since'
-                         ' it is either malformed or otherwise incorrect.')
+                         'Incorrect request body format')
 
     def test_restore_backup_volume_id_unspecified(self):