def test_retain_copy(self, session_mock): settings = { 'aws_bucket': self.aws_bucket, 'aws_identity': 'identity', 'aws_secret': 'credential', 'account': 'account', 'container': 'container', 'retain_local': False } sync = SyncContainer(self.scratch_space, settings) sync.provider = mock.Mock() swift_client = mock.Mock() row = { 'deleted': 0, 'created_at': str(time.time() - 5), 'name': 'foo', 'storage_policy_index': 99 } sync.handle(row, swift_client) _, _, swift_ts = decode_timestamps(row['created_at']) swift_ts.offset += 1 sync.provider.upload_object.assert_called_once_with( row['name'], 99, swift_client) swift_client.delete_object.assert_called_once_with( settings['account'], settings['container'], row['name'], headers={'X-Timestamp': Timestamp(swift_ts).internal})
def test_retry_copy_after(self, session_mock): settings = { 'aws_bucket': self.aws_bucket, 'aws_identity': 'identity', 'aws_secret': 'credential', 'account': 'account', 'container': 'container', 'copy_after': 3600 } with self.assertRaises(RetryError): sync = SyncContainer(self.scratch_space, settings) sync.handle({'deleted': 0, 'created_at': str(time.time())}, None) current = time.time() with mock.patch('s3_sync.sync_container.time') as time_mock: time_mock.time.return_value = current + settings['copy_after'] + 1 sync = SyncContainer(self.scratch_space, settings) sync.provider = mock.Mock() sync.handle( { 'deleted': 0, 'created_at': str(time.time()), 'name': 'foo', 'storage_policy_index': 99 }, None) sync.provider.upload_object.assert_called_once_with( 'foo', 99, None)
def test_retain_copy(self, session_mock): settings = { 'aws_bucket': self.aws_bucket, 'aws_identity': 'identity', 'aws_secret': 'credential', 'account': 'account', 'container': 'container', 'retain_local': False } sync = SyncContainer(self.scratch_space, settings, self.stats_factory) sync.provider = mock.Mock() sync.provider.upload_object.return_value = SyncS3.UploadStatus.PUT swift_client = mock.Mock() swift_client.get_object_metadata.return_value = {} row = { 'deleted': 0, 'created_at': str(time.time() - 5), 'name': 'foo', 'storage_policy_index': 99 } sync.handle(row, swift_client) _, _, swift_ts = decode_timestamps(row['created_at']) sync.provider.upload_object.assert_called_once_with( row, swift_client, mock.ANY) sync.provider.delete_local_object.assert_called_once_with( swift_client, row, swift_ts, False) sync.stats_reporter.increment.assert_called_once_with( 'copied_objects', 1)
def test_no_propagate_delete(self, session_mock): settings = { 'aws_bucket': self.aws_bucket, 'aws_identity': 'identity', 'aws_secret': 'credential', 'account': 'account', 'container': 'container', 'propagate_delete': False } sync = SyncContainer(self.scratch_space, settings) sync.provider = mock.Mock() row = {'deleted': 1, 'name': 'tombstone'} sync.handle(row, None) # Make sure we do nothing with this row self.assertEqual([], sync.provider.mock_calls)
def test_propagate_delete(self, session_mock): settings = { 'aws_bucket': self.aws_bucket, 'aws_identity': 'identity', 'aws_secret': 'credential', 'account': 'account', 'container': 'container', 'propagate_delete': True } sync = SyncContainer(self.scratch_space, settings) sync.provider = mock.Mock() row = {'deleted': 1, 'name': 'tombstone'} sync.handle(row, None) # Make sure that we do not make any additional calls self.assertEqual([mock.call.delete_object(row['name'])], sync.provider.mock_calls)
def test_skips_matching_exclude_rows(self): settings = { 'aws_bucket': self.aws_bucket, 'aws_identity': 'identity', 'aws_secret': 'credential', 'account': 'account', 'container': 'container', 'exclude_pattern': '^foo-\d+$' } sync = SyncContainer(self.scratch_space, settings, self.stats_factory) sync.provider = mock.Mock() sync.handle({'name': 'foo-1'}, mock.Mock()) sync.handle({'name': 'foo-12345', 'deleted': 1}, mock.Mock()) sync.handle( { 'name': 'foo-1-bar', 'deleted': 0, 'created_at': '123456789.1234' }, mock.Mock()) self.assertEqual([ mock.call.upload_object( { 'name': 'foo-1-bar', 'deleted': 0, 'created_at': '123456789.1234' }, mock.ANY, mock.ANY) ], sync.provider.mock_calls)