Ejemplo n.º 1
0
    def test_swift_segment_checksum_etag_mismatch(self, mock_logging):
        """This tests that when etag doesn't match segment uploaded checksum
            False is returned and None for checksum and location
        """
        context = trove_testtools.TroveTestContext(self)
        # 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_segment_etag_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.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_segment_etag_123.gz.enc', location,
            "Incorrect swift location was returned.")
Ejemplo n.º 2
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.º 3
0
 def setUp(self):
     super(SwiftMetadataTests, self).setUp()
     self.swift_client = FakeSwiftConnection()
     self.context = trove_testtools.TroveTestContext(self)
     self.create_swift_client_patch = patch.object(
         remote, 'create_swift_client',
         MagicMock(return_value=self.swift_client))
     self.create_swift_client_mock = self.create_swift_client_patch.start()
     self.addCleanup(self.create_swift_client_patch.stop)
     self.swift = SwiftStorage(self.context)
Ejemplo n.º 4
0
 def setUp(self):
     super(SwiftStorageUtils, self).setUp()
     self.context = TroveContext()
     self.swift_client = FakeSwiftConnection()
     self.create_swift_client_patch = patch.object(
         swift, 'create_swift_client',
         MagicMock(return_value=self.swift_client))
     self.create_swift_client_mock = self.create_swift_client_patch.start()
     self.addCleanup(self.create_swift_client_patch.stop)
     self.swift = SwiftStorage(self.context)
Ejemplo n.º 5
0
    def test_run_verify_checksum(self):
        """This tests that swift download cmd runs if original backup checksum
            matches swift object etag
        """

        context = trove_testtools.TroveTestContext(self)
        location = "/backup/location/123"
        backup_checksum = "fake-md5-sum"

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

            storage_strategy = SwiftStorage(context)
            download_stream = storage_strategy.load(location, backup_checksum)
        self.assertIsNotNone(download_stream)
Ejemplo n.º 6
0
    def test_run_verify_checksum_mismatch(self, mock_logging):
        """This tests that SwiftDownloadIntegrityError is raised and swift
            download cmd does not run when original backup checksum
            does not match swift object etag
        """

        context = trove_testtools.TroveTestContext(self)
        location = "/backup/location/123"
        backup_checksum = "checksum_different_then_fake_swift_etag"

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

        self.assertRaises(SwiftDownloadIntegrityError, storage_strategy.load,
                          location, backup_checksum)