]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Raise HTTP exception for backup not found
authorVipin Balachandran <vbala@vmware.com>
Wed, 15 Jul 2015 08:51:46 +0000 (14:21 +0530)
committerVipin Balachandran <vbala@vmware.com>
Wed, 15 Jul 2015 08:51:46 +0000 (14:21 +0530)
If backup cannot be found while resetting its status, Cinder
exception (BackupNotFound) is raised instead of HTTP exception.
This patch handles the BackupNotFound exception and raises
HTTPNotFound exception.

APIImpact
HTTPNotFound exception (404) is raised instead of BackupNotFound
if backup cannot be found during backup reset-status.

Change-Id: I5a41c71a83c05d09c6d1e2e506adca6cfbe3e890
Closes-Bug: #1474748

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

index b0f809ecba411e750ff3e15c61e3c810fab8c637..46bb3fd8ac207e8d5a7f2b9d8e192a0236a212ca 100644 (file)
@@ -309,7 +309,7 @@ class BackupAdminController(AdminController):
         try:
             self.backup_api.reset_status(context=context, backup_id=id,
                                          status=update['status'])
-        except exception.VolumeNotFound as e:
+        except exception.BackupNotFound as e:
             raise exc.HTTPNotFound(explanation=e.msg)
         return webob.Response(status_int=202)
 
index 4441462b6618a03b9724c08d04f50993b7abae2d..d2718f31d7310d7360096efd7a3e15a9743d10e5 100644 (file)
@@ -251,6 +251,23 @@ class AdminActionsTest(test.TestCase):
                                         {'status': 'restoring'})
         self.assertEqual(resp.status_int, 400)
 
+    def test_backup_reset_status_with_invalid_backup(self):
+        ctx = context.RequestContext('admin', 'fake', True)
+        volume = db.volume_create(ctx, {'status': 'available', 'host': 'test',
+                                        'provider_location': '', 'size': 1})
+        backup = db.backup_create(ctx, {'status': 'available',
+                                        'volume_id': volume['id'],
+                                        'user_id': 'user',
+                                        'project_id': 'project'})
+
+        backup['id'] = 'fake_id'
+        resp = self._issue_backup_reset(ctx,
+                                        backup,
+                                        {'status': 'error'})
+
+        # Should raise 404 if backup doesn't exist.
+        self.assertEqual(404, resp.status_int)
+
     def test_malformed_reset_status_body(self):
         ctx = context.RequestContext('admin', 'fake', True)
         volume = db.volume_create(ctx, {'status': 'available', 'size': 1})