def delete(self, backup):
"""Delete the given backup."""
container = backup['container']
+ object_prefix = backup['service_metadata']
LOG.debug('delete started, backup: %(id)s, container: %(cont)s, '
'prefix: %(pre)s.',
{'id': backup['id'],
'cont': container,
- 'pre': backup['service_metadata']})
+ 'pre': object_prefix})
- if container is not None:
+ if container is not None and object_prefix is not None:
object_names = []
try:
object_names = self._generate_object_names(backup)
return db.volume_create(self.ctxt, vol)['id']
def _create_backup_db_entry(self, container='test-container',
- backup_id=123, parent_id=None):
+ backup_id=123, parent_id=None,
+ service_metadata=None):
backup = {'id': backup_id,
'size': 1,
'container': container,
'parent_id': parent_id,
'user_id': 'user-id',
'project_id': 'project-id',
+ 'service_metadata': service_metadata,
}
return db.backup_create(self.ctxt, backup)['id']
backup, '1234-5678-1234-8888', volume_file)
def test_delete(self):
- self._create_backup_db_entry()
+ object_prefix = 'test_prefix'
+ self._create_backup_db_entry(service_metadata=object_prefix)
service = swift_dr.SwiftBackupDriver(self.ctxt)
backup = objects.Backup.get_by_id(self.ctxt, 123)
service.delete(backup)
def test_delete_wraps_socket_error(self):
container_name = 'socket_error_on_delete'
- self._create_backup_db_entry(container=container_name)
+ object_prefix = 'test_prefix'
+ self._create_backup_db_entry(container=container_name,
+ service_metadata=object_prefix)
service = swift_dr.SwiftBackupDriver(self.ctxt)
backup = objects.Backup.get_by_id(self.ctxt, 123)
self.assertRaises(exception.SwiftConnectionFailed,
service.delete,
backup)
+ def test_delete_without_object_prefix(self):
+
+ def _fake_delete_object(self, container, object_name):
+ raise AssertionError('delete_object method should not be called.')
+
+ self.stubs.Set(swift_dr.SwiftBackupDriver,
+ 'delete_object',
+ _fake_delete_object)
+
+ self._create_backup_db_entry()
+ service = swift_dr.SwiftBackupDriver(self.ctxt)
+ backup = objects.Backup.get_by_id(self.ctxt, 123)
+ service.delete(backup)
+
def test_get_compressor(self):
service = swift_dr.SwiftBackupDriver(self.ctxt)
compressor = service._get_compressor('None')