Esempio n. 1
0
    def __call__(self):
        LOGGER.debug("Uploading part copy %s for filename: %s",
                     self._part_number, self._filename.src)
        total_file_size = self._filename.size
        start_range = (self._part_number - 1) * self._chunk_size
        if self._is_last_part(self._part_number):
            end_range = total_file_size - 1
        else:
            end_range = start_range + self._chunk_size - 1
        range_param = 'bytes=%s-%s' % (start_range, end_range)
        try:
            LOGGER.debug("Waiting for upload id.")
            upload_id = self._upload_context.wait_for_upload_id()
            bucket, key = find_bucket_key(self._filename.dest)
            src_bucket, src_key = find_bucket_key(self._filename.src)
            params = {
                'Bucket': bucket,
                'Key': key,
                'PartNumber': self._part_number,
                'UploadId': upload_id,
                'CopySource': {
                    'Bucket': src_bucket,
                    'Key': src_key
                },
                'CopySourceRange': range_param
            }
            RequestParamsMapper.map_upload_part_copy_params(
                params, self._params)
            response_data = self._filename.client.upload_part_copy(**params)
            etag = response_data['CopyPartResult']['ETag'][1:-1]
            self._upload_context.announce_finished_part(
                etag=etag, part_number=self._part_number)

            message = print_operation(self._filename, 0)
            result = {
                'message': message,
                'total_parts': self._total_parts(),
                'error': False
            }
            self._result_queue.put(PrintTask(**result))
        except UploadCancelledError as e:
            # We don't need to do anything in this case.  The task
            # has been cancelled, and the task that cancelled the
            # task has already queued a message.
            LOGGER.debug("Not uploading part copy, task has been cancelled.")
        except Exception as e:
            LOGGER.debug('Error during upload part copy: %s', e, exc_info=True)
            message = print_operation(self._filename,
                                      failed=True,
                                      dryrun=False)
            message += '\n' + str(e)
            result = {'message': message, 'error': True}
            self._result_queue.put(PrintTask(**result))
            self._upload_context.cancel_upload()
        else:
            LOGGER.debug("Copy part number %s completed for filename: %s",
                         self._part_number, self._filename.src)
Esempio n. 2
0
 def test_upload_part_copy(self):
     params = {}
     RequestParamsMapper.map_upload_part_copy_params(
         params, self.cli_params)
     self.assertEqual(
         params,
         {'CopySourceSSECustomerAlgorithm': 'AES256',
          'CopySourceSSECustomerKey': 'my-sse-c-copy-source-key',
          'SSECustomerAlgorithm': 'AES256',
          'SSECustomerKey': 'my-sse-c-key'})
 def test_upload_part_copy(self):
     params = {}
     RequestParamsMapper.map_upload_part_copy_params(
         params, self.cli_params)
     self.assertEqual(
         params,
         {'CopySourceSSECustomerAlgorithm': 'AES256',
          'CopySourceSSECustomerKey': 'my-sse-c-copy-source-key',
          'SSECustomerAlgorithm': 'AES256',
          'SSECustomerKey': 'my-sse-c-key'})
Esempio n. 4
0
 def test_upload_part_copy(self):
     params = {}
     RequestParamsMapper.map_upload_part_copy_params(params, self.cli_params)
     self.assertEqual(
         params,
         {
             "CopySourceSSECustomerAlgorithm": "AES256",
             "CopySourceSSECustomerKey": "my-sse-c-copy-source-key",
             "SSECustomerAlgorithm": "AES256",
             "SSECustomerKey": "my-sse-c-key",
         },
     )
Esempio n. 5
0
    def __call__(self):
        LOGGER.debug("Uploading part copy %s for filename: %s",
                     self._part_number, self._filename.src)
        total_file_size = self._filename.size
        start_range = (self._part_number - 1) * self._chunk_size
        if self._is_last_part(self._part_number):
            end_range = total_file_size - 1
        else:
            end_range = start_range + self._chunk_size - 1
        range_param = 'bytes=%s-%s' % (start_range, end_range)
        try:
            LOGGER.debug("Waiting for upload id.")
            upload_id = self._upload_context.wait_for_upload_id()
            bucket, key = find_bucket_key(self._filename.dest)
            src_bucket, src_key = find_bucket_key(self._filename.src)
            params = {'Bucket': bucket, 'Key': key,
                      'PartNumber': self._part_number,
                      'UploadId': upload_id,
                      'CopySource': {'Bucket': src_bucket, 'Key': src_key},
                      'CopySourceRange': range_param}
            RequestParamsMapper.map_upload_part_copy_params(
                params, self._params)
            response_data = self._filename.client.upload_part_copy(**params)
            etag = response_data['CopyPartResult']['ETag'][1:-1]
            self._upload_context.announce_finished_part(
                etag=etag, part_number=self._part_number)

            message = print_operation(self._filename, 0)
            result = {'message': message, 'total_parts': self._total_parts(),
                      'error': False}
            self._result_queue.put(PrintTask(**result))
        except UploadCancelledError as e:
            # We don't need to do anything in this case.  The task
            # has been cancelled, and the task that cancelled the
            # task has already queued a message.
            LOGGER.debug("Not uploading part copy, task has been cancelled.")
        except Exception as e:
            LOGGER.debug('Error during upload part copy: %s', e,
                         exc_info=True)
            message = print_operation(self._filename, failed=True,
                                      dryrun=False)
            message += '\n' + str(e)
            result = {'message': message, 'error': True}
            self._result_queue.put(PrintTask(**result))
            self._upload_context.cancel_upload()
        else:
            LOGGER.debug("Copy part number %s completed for filename: %s",
                         self._part_number, self._filename.src)
 def test_upload_part_copy(self):
     params = {}
     RequestParamsMapper.map_upload_part_copy_params(
         params, self.cli_params)
     self.assertEqual(params, {'RequestPayer': 'requester'})
Esempio n. 7
0
 def test_upload_part_copy(self):
     params = {}
     RequestParamsMapper.map_upload_part_copy_params(
         params, self.cli_params)
     self.assertEqual(params, {'RequestPayer': 'requester'})