Ejemplo n.º 1
0
    def test_swift_checksum_etag_mismatch(self):
        """This tests that when etag doesn't match swift checksum False is
            returned and None for checksum and location
        """
        context = TroveContext()
        # this backup_id will trigger fake swift client with calculate_etag
        # enabled to spit out a bad etag when a segment object is uploaded
        backup_id = 'bad_manifest_etag_123'
        user = '******'
        password = '******'

        swift_client = FakeSwiftConnection()
        with patch.object(swift,
                          'create_swift_client',
                          return_value=swift_client):
            storage_strategy = SwiftStorage(context)

            with MockBackupRunner(filename=backup_id,
                                  user=user,
                                  password=password) as runner:
                (success, note, checksum,
                 location) = storage_strategy.save(runner.manifest, runner)

        self.assertFalse(success, "The backup should have failed!")
        self.assertTrue(note.startswith("Error saving data to Swift!"))
        self.assertIsNone(checksum,
                          "Swift checksum should be None for failed backup.")
        self.assertEqual(
            'http://mockswift/v1/database_backups/'
            'bad_manifest_etag_123.gz.enc', location,
            "Incorrect swift location was returned.")
Ejemplo n.º 2
0
    def test_swift_checksum_etag_mismatch(self):
        """This tests that when etag doesn't match swift checksum False is
        returned and None for checksum and location"""
        context = TroveContext()
        # this backup_id will trigger fake swift client with calculate_etag
        # enabled to spit out a bad etag when a segment object is uploaded
        backup_id = 'bad_manifest_etag_123'
        user = '******'
        password = '******'
        backup_container = 'database_backups'

        swift_client = fake_create_swift_client(calculate_etag=True)
        when(swift).create_swift_client(context).thenReturn(swift_client)
        storage_strategy = SwiftStorage(context)

        with MockBackupRunner(filename=backup_id, user=user,
                              password=password) as runner:
            (success, note, checksum,
             location) = storage_strategy.save(backup_container, runner)

        self.assertEqual(success, False, "The backup should have failed!")
        self.assertTrue(note.startswith("Error saving data to Swift!"))
        self.assertIsNone(checksum,
                          "Swift checksum should be None for failed backup.")
        self.assertIsNone(location,
                          "Swift location should be None for failed backup.")
Ejemplo n.º 3
0
    def test_swift_checksum_save(self):
        """This tests that SwiftStorage.save returns the swift checksum for
        large files.
        """
        context = trove_testtools.TroveTestContext(self)
        backup_id = '123'
        user = '******'
        password = '******'

        swift_client = FakeSwiftConnection()
        with patch.object(remote,
                          'create_swift_client',
                          return_value=swift_client):
            storage_strategy = SwiftStorage(context)

            with MockBackupRunner(filename=backup_id,
                                  user=user,
                                  password=password) as runner:
                (success, note, checksum,
                 location) = storage_strategy.save(runner.manifest, runner)

        self.assertTrue(success, "The backup should have been successful.")
        self.assertIsNotNone(note, "A note should have been returned.")
        self.assertEqual('http://mockswift/v1/database_backups/123.gz.enc',
                         location, "Incorrect swift location was returned.")
Ejemplo n.º 4
0
    def test_swift_checksum_save(self):
        """This tests that SwiftStorage.save returns the swift checksum"""
        context = TroveContext()
        backup_id = '123'
        user = '******'
        password = '******'
        backup_container = 'database_backups'

        swift_client = FakeSwiftConnectionWithRealEtag()
        when(swift).create_swift_client(context).thenReturn(swift_client)
        storage_strategy = SwiftStorage(context)

        with MockBackupRunner(filename=backup_id,
                              user=user,
                              password=password) as runner:
            (success,
             note,
             checksum,
             location) = storage_strategy.save(backup_container, runner)

        self.assertEqual(success, True,
                         "The backup should have been successful.")
        self.assertIsNotNone(note, "A note should have been returned.")
        self.assertEqual(location, 'http://mockswift/v1/database_backups/123',
                         "Incorrect swift location was returned.")