From b5e84020ae39222f3e155a176157f6f7f3901144 Mon Sep 17 00:00:00 2001 From: Vipin Balachandran Date: Wed, 15 Jul 2015 14:21:46 +0530 Subject: [PATCH] Raise HTTP exception for backup not found 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 | 2 +- .../unit/api/contrib/test_admin_actions.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/cinder/api/contrib/admin_actions.py b/cinder/api/contrib/admin_actions.py index b0f809ecb..46bb3fd8a 100644 --- a/cinder/api/contrib/admin_actions.py +++ b/cinder/api/contrib/admin_actions.py @@ -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) diff --git a/cinder/tests/unit/api/contrib/test_admin_actions.py b/cinder/tests/unit/api/contrib/test_admin_actions.py index 4441462b6..d2718f31d 100644 --- a/cinder/tests/unit/api/contrib/test_admin_actions.py +++ b/cinder/tests/unit/api/contrib/test_admin_actions.py @@ -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}) -- 2.45.2