From 6ff364f385b2bfe52a9c55ffbe357979b0dee9b4 Mon Sep 17 00:00:00 2001 From: Abhishek Sharma Date: Wed, 25 Oct 2017 05:56:33 -0500 Subject: [PATCH] Don't fail when deleting missing backup The problem here is sometimes when the path doesn't exist and we try to delete it then exception occurs & breaks the flow. In this case it happens with the volume delete flow, wherein the exception occurs just before the quota commit & commit doesn't happen even though the backup volume got deleted, hence catching the exception just where it occurs. Change-Id: I8713f846b1e2e30b4bbc4af57645fdc04bcd8386 Closes-Bug: 1726715 --- cinder/backup/drivers/posix.py | 5 ++++- cinder/tests/unit/backup/drivers/test_backup_posix.py | 7 ------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/cinder/backup/drivers/posix.py b/cinder/backup/drivers/posix.py index 3d84b8a5c41..236d4142f2d 100644 --- a/cinder/backup/drivers/posix.py +++ b/cinder/backup/drivers/posix.py @@ -127,7 +127,10 @@ class PosixBackupDriver(chunkeddriver.ChunkedBackupDriver): def delete_object(self, container, object_name): # TODO(tbarron): clean up the container path if it is empty path = os.path.join(self.backup_path, container, object_name) - os.remove(path) + try: + os.remove(path) + except OSError: + pass def _generate_object_name_prefix(self, backup): timestamp = timeutils.utcnow().strftime("%Y%m%d%H%M%S") diff --git a/cinder/tests/unit/backup/drivers/test_backup_posix.py b/cinder/tests/unit/backup/drivers/test_backup_posix.py index 70ac5005d96..35ba51ad82e 100644 --- a/cinder/tests/unit/backup/drivers/test_backup_posix.py +++ b/cinder/tests/unit/backup/drivers/test_backup_posix.py @@ -170,13 +170,6 @@ class PosixBackupDriverTestCase(test.TestCase): self.driver.delete_object(FAKE_CONTAINER, FAKE_OBJECT_NAME) - def test_delete_nonexistent_object(self): - self.mock_object(os, 'remove', side_effect=OSError) - - self.assertRaises(OSError, - self.driver.delete_object, FAKE_CONTAINER, - FAKE_OBJECT_NAME) - @mock.patch.object(posix.timeutils, 'utcnow') def test_generate_object_name_prefix(self, utcnow_mock): timestamp = '20170518102205'