Esempio n. 1
0
    def test_restore(self):
        self._create_backup_db_entry()
        service = SwiftBackupDriver(self.ctxt)

        with tempfile.NamedTemporaryFile() as volume_file:
            backup = db.backup_get(self.ctxt, 123)
            service.restore(backup, '1234-5678-1234-8888', volume_file)
Esempio n. 2
0
 def test_backup_zlib(self):
     self._create_backup_db_entry()
     self.flags(backup_compression_algorithm='zlib')
     service = SwiftBackupDriver(self.ctxt)
     self.volume_file.seek(0)
     backup = db.backup_get(self.ctxt, 123)
     service.backup(backup, self.volume_file)
Esempio n. 3
0
 def test_backup_default_container(self):
     self._create_backup_db_entry(container=None)
     service = SwiftBackupDriver(self.ctxt)
     self.volume_file.seek(0)
     backup = db.backup_get(self.ctxt, 123)
     service.backup(backup, self.volume_file)
     backup = db.backup_get(self.ctxt, 123)
     self.assertEqual(backup['container'], 'volumebackups')
Esempio n. 4
0
 def test_get_compressor(self):
     service = SwiftBackupDriver(self.ctxt)
     compressor = service._get_compressor('None')
     self.assertIsNone(compressor)
     compressor = service._get_compressor('zlib')
     self.assertEqual(compressor, zlib)
     compressor = service._get_compressor('bz2')
     self.assertEqual(compressor, bz2)
     self.assertRaises(ValueError, service._get_compressor, 'fake')
Esempio n. 5
0
 def test_backup_custom_container(self):
     container_name = 'fake99'
     self._create_backup_db_entry(container=container_name)
     service = SwiftBackupDriver(self.ctxt)
     self.volume_file.seek(0)
     backup = db.backup_get(self.ctxt, 123)
     service.backup(backup, self.volume_file)
     backup = db.backup_get(self.ctxt, 123)
     self.assertEqual(backup['container'], container_name)
Esempio n. 6
0
 def test_check_container_exists(self):
     service = SwiftBackupDriver(self.ctxt)
     exists = service._check_container_exists('fake_container')
     self.assertEquals(exists, True)
     exists = service._check_container_exists('missing_container')
     self.assertEquals(exists, False)
     self.assertRaises(swift.ClientException,
                       service._check_container_exists,
                       'unauthorized_container')
Esempio n. 7
0
 def test_create_backup_put_object_wraps_socket_error(self):
     container_name = 'socket_error_on_put'
     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)
Esempio n. 8
0
    def test_restore_unsupported_version(self):
        container_name = 'unsupported_version'
        self._create_backup_db_entry(container=container_name)
        service = SwiftBackupDriver(self.ctxt)

        with tempfile.NamedTemporaryFile() as volume_file:
            backup = db.backup_get(self.ctxt, 123)
            self.assertRaises(exception.InvalidBackup, service.restore, backup,
                              '1234-5678-1234-8888', volume_file)
Esempio n. 9
0
    def test_restore_wraps_socket_error(self):
        container_name = 'socket_error_on_get'
        self._create_backup_db_entry(container=container_name)
        service = SwiftBackupDriver(self.ctxt)

        with tempfile.NamedTemporaryFile() as volume_file:
            backup = db.backup_get(self.ctxt, 123)
            self.assertRaises(exception.SwiftConnectionFailed, service.restore,
                              backup, '1234-5678-1234-8888', volume_file)
Esempio n. 10
0
 def test_backup_swift_url_conf(self):
     self.ctxt.service_catalog = [{u'type': u'object-store',
                                   u'name': u'swift',
                                   u'endpoints': [{
                                       u'adminURL': u'http://example.com'}]
                                   }]
     self.ctxt.project_id = "12345678"
     self.override_config("backup_swift_url", "http://public.example.com/")
     backup = SwiftBackupDriver(self.ctxt)
     self.assertEqual("%s%s" % (CONF.backup_swift_url,
                                self.ctxt.project_id),
                      backup.swift_url)
Esempio n. 11
0
    def test_backup_default_container_notify(self, _send_progress,
                                             _send_progress_end):
        self._create_backup_db_entry(container=None)
        # If the backup_object_number_per_notification is set to 1,
        # the _send_progress method will be called for sure.
        CONF.set_override("backup_object_number_per_notification", 1)
        CONF.set_override("backup_swift_enable_progress_timer", False)
        service = SwiftBackupDriver(self.ctxt)
        self.volume_file.seek(0)
        backup = db.backup_get(self.ctxt, 123)
        service.backup(backup, self.volume_file)
        self.assertTrue(_send_progress.called)
        self.assertTrue(_send_progress_end.called)

        # If the backup_object_number_per_notification is increased to
        # another value, the _send_progress method will not be called.
        _send_progress.reset_mock()
        _send_progress_end.reset_mock()
        CONF.set_override("backup_object_number_per_notification", 10)
        service = SwiftBackupDriver(self.ctxt)
        self.volume_file.seek(0)
        backup = db.backup_get(self.ctxt, 123)
        service.backup(backup, self.volume_file)
        self.assertFalse(_send_progress.called)
        self.assertTrue(_send_progress_end.called)

        # If the timer is enabled, the _send_progress will be called,
        # since the timer can trigger the progress notification.
        _send_progress.reset_mock()
        _send_progress_end.reset_mock()
        CONF.set_override("backup_object_number_per_notification", 10)
        CONF.set_override("backup_swift_enable_progress_timer", True)
        service = SwiftBackupDriver(self.ctxt)
        self.volume_file.seek(0)
        backup = db.backup_get(self.ctxt, 123)
        service.backup(backup, self.volume_file)
        self.assertTrue(_send_progress.called)
        self.assertTrue(_send_progress_end.called)
Esempio n. 12
0
    def test_backup_backup_metadata_fail(self):
        """Test of when an exception occurs in backup().

        In backup(), after an exception occurs in
        self._backup_metadata(), we want to check the process of an
        exception handler.
        """
        self._create_backup_db_entry()
        self.flags(backup_compression_algorithm='none')
        service = SwiftBackupDriver(self.ctxt)
        self.volume_file.seek(0)
        backup = db.backup_get(self.ctxt, 123)

        def fake_backup_metadata(self, backup, object_meta):
            raise exception.BackupDriverException(message=_('fake'))

        # Raise a pseudo exception.BackupDriverException.
        self.stubs.Set(SwiftBackupDriver, '_backup_metadata',
                       fake_backup_metadata)

        # We expect that an exception be notified directly.
        self.assertRaises(exception.BackupDriverException, service.backup,
                          backup, self.volume_file)
Esempio n. 13
0
 def test_delete(self):
     self._create_backup_db_entry()
     service = SwiftBackupDriver(self.ctxt)
     backup = db.backup_get(self.ctxt, 123)
     service.delete(backup)
Esempio n. 14
0
 def test_delete(self):
     self._create_backup_db_entry()
     service = SwiftBackupDriver(self.ctxt)
     backup = db.backup_get(self.ctxt, 123)
     service.delete(backup)
Esempio n. 15
0
    def test_backup_default_container_notify(self, _send_progress,
                                             _send_progress_end):
        self._create_backup_db_entry(container=None)
        # If the backup_object_number_per_notification is set to 1,
        # the _send_progress method will be called for sure.
        CONF.set_override("backup_object_number_per_notification", 1)
        CONF.set_override("backup_swift_enable_progress_timer", False)
        service = SwiftBackupDriver(self.ctxt)
        self.volume_file.seek(0)
        backup = db.backup_get(self.ctxt, 123)
        service.backup(backup, self.volume_file)
        self.assertTrue(_send_progress.called)
        self.assertTrue(_send_progress_end.called)

        # If the backup_object_number_per_notification is increased to
        # another value, the _send_progress method will not be called.
        _send_progress.reset_mock()
        _send_progress_end.reset_mock()
        CONF.set_override("backup_object_number_per_notification", 10)
        service = SwiftBackupDriver(self.ctxt)
        self.volume_file.seek(0)
        backup = db.backup_get(self.ctxt, 123)
        service.backup(backup, self.volume_file)
        self.assertFalse(_send_progress.called)
        self.assertTrue(_send_progress_end.called)

        # If the timer is enabled, the _send_progress will be called,
        # since the timer can trigger the progress notification.
        _send_progress.reset_mock()
        _send_progress_end.reset_mock()
        CONF.set_override("backup_object_number_per_notification", 10)
        CONF.set_override("backup_swift_enable_progress_timer", True)
        service = SwiftBackupDriver(self.ctxt)
        self.volume_file.seek(0)
        backup = db.backup_get(self.ctxt, 123)
        service.backup(backup, self.volume_file)
        self.assertTrue(_send_progress.called)
        self.assertTrue(_send_progress_end.called)