Merge "swift backup driver: Ignore 404 during object deletion"

This commit is contained in:
Zuul 2024-05-21 05:20:38 +00:00 committed by Gerrit Code Review
commit ccff71a251
3 changed files with 18 additions and 0 deletions

View File

@ -420,6 +420,9 @@ class SwiftBackupDriver(chunkeddriver.ChunkedBackupDriver):
headers=self._headers()) headers=self._headers())
except socket.error as err: except socket.error as err:
raise exception.SwiftConnectionFailed(reason=err) raise exception.SwiftConnectionFailed(reason=err)
except swift_exc.ClientException as err:
if err.http_status != 404:
raise
def _generate_object_name_prefix(self, backup): def _generate_object_name_prefix(self, backup):
"""Generates a Swift backup object name prefix.""" """Generates a Swift backup object name prefix."""

View File

@ -888,6 +888,17 @@ class BackupSwiftTestCase(test.TestCase):
backup = objects.Backup.get_by_id(self.ctxt, fake.BACKUP_ID) backup = objects.Backup.get_by_id(self.ctxt, fake.BACKUP_ID)
service.delete_backup(backup) service.delete_backup(backup)
def test_delete_not_found(self):
volume_id = '9ab256c8-3175-4ad8-baa1-0000007f9d31'
container_name = 'not_found_on_delete'
object_prefix = 'test_prefix'
self._create_backup_db_entry(volume_id=volume_id,
container=container_name,
service_metadata=object_prefix)
service = swift_dr.SwiftBackupDriver(self.ctxt)
backup = objects.Backup.get_by_id(self.ctxt, fake.BACKUP_ID)
service.delete_backup(backup)
def test_delete_wraps_socket_error(self): def test_delete_wraps_socket_error(self):
volume_id = 'f74cb6fa-2900-40df-87ac-0000000f72ea' volume_id = 'f74cb6fa-2900-40df-87ac-0000000f72ea'
container_name = 'socket_error_on_delete' container_name = 'socket_error_on_delete'

View File

@ -20,6 +20,7 @@ import socket
import zlib import zlib
from swiftclient import client as swift from swiftclient import client as swift
from swiftclient import exceptions as swift_exc
class FakeSwiftClient(object): class FakeSwiftClient(object):
@ -105,4 +106,7 @@ class FakeSwiftConnection(object):
def delete_object(self, container, name, headers=None): def delete_object(self, container, name, headers=None):
if container == 'socket_error_on_delete': if container == 'socket_error_on_delete':
raise socket.error(111, 'ECONNREFUSED') raise socket.error(111, 'ECONNREFUSED')
if container == 'not_found_on_delete':
raise swift_exc.ClientException(
msg='404 Not Found', http_status=404, http_reason='Not Found')
pass pass