"""
import hashlib
-import httplib
import json
import os
import socket
preauthtoken=self.context.auth_token,
starting_backoff=self.swift_backoff)
- def _check_container_exists(self, container):
- LOG.debug(_('_check_container_exists: container: %s') % container)
- try:
- self.conn.head_container(container)
- except swift.ClientException as error:
- if error.http_status == httplib.NOT_FOUND:
- LOG.debug(_('container %s does not exist') % container)
- return False
- else:
- raise
- else:
- LOG.debug(_('container %s exists') % container)
- return True
-
def _create_container(self, context, backup):
backup_id = backup['id']
container = backup['container']
if container is None:
container = CONF.backup_swift_container
self.db.backup_update(context, backup_id, {'container': container})
- if not self._check_container_exists(container):
- self.conn.put_container(container)
+ # NOTE(gfidente): accordingly to the Object Storage API reference, we
+ # do not need to check if a container already exists, container PUT
+ # requests are idempotent and a code of 202 (Accepted) is returned when
+ # the container already existed.
+ self.conn.put_container(container)
return container
def _generate_swift_object_name_prefix(self, backup):
backup = db.backup_get(self.ctxt, 123)
self.assertEqual(backup['container'], container_name)
- def test_create_backup_container_check_wraps_socket_error(self):
- container_name = 'socket_error_on_head'
- self._create_backup_db_entry(container=container_name)
- service = SwiftBackupDriver(self.ctxt)
- self.volume_file.seek(0)
- backup = db.backup_get(self.ctxt, 123)
- self.assertRaises(exception.SwiftConnectionFailed,
- service.backup,
- backup, self.volume_file)
-
def test_create_backup_put_object_wraps_socket_error(self):
container_name = 'socket_error_on_put'
self._create_backup_db_entry(container=container_name)
compressor = service._get_compressor('bz2')
self.assertEqual(compressor, bz2)
self.assertRaises(ValueError, service._get_compressor, 'fake')
-
- def test_check_container_exists(self):
- service = SwiftBackupDriver(self.ctxt)
- exists = service._check_container_exists('fake_container')
- self.assertEqual(exists, True)
- exists = service._check_container_exists('missing_container')
- self.assertEqual(exists, False)
- self.assertRaises(swift.ClientException,
- service._check_container_exists,
- 'unauthorized_container')