Esempio n. 1
0
 def test_upload_part(self):
     params = {}
     RequestParamsMapper.map_upload_part_params(params, self.cli_params)
     self.assertEqual(
         params,
         {'SSECustomerAlgorithm': 'AES256',
          'SSECustomerKey': 'my-sse-c-key'}
     )
Esempio n. 2
0
    def __call__(self):
        LOGGER.debug("Uploading part %s for filename: %s", self._part_number,
                     self._filename.src)
        try:
            LOGGER.debug("Waiting for upload id.")
            upload_id = self._upload_context.wait_for_upload_id()
            bucket, key = find_bucket_key(self._filename.dest)
            if self._filename.is_stream:
                body = self._payload
                total = self._upload_context.expected_parts
            else:
                total = int(
                    math.ceil(self._filename.size / float(self._chunk_size)))
                body = self._read_part()
            params = {
                'Bucket': bucket,
                'Key': key,
                'PartNumber': self._part_number,
                'UploadId': upload_id,
                'Body': body
            }
            RequestParamsMapper.map_upload_part_params(params, self._params)
            try:
                response_data = self._filename.client.upload_part(**params)
            finally:
                body.close()
            etag = response_data['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': total, '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, task has been cancelled.")
        except Exception as e:
            LOGGER.debug('Error during part upload: %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("Part number %s completed for filename: %s",
                         self._part_number, self._filename.src)
Esempio n. 3
0
    def __call__(self):
        LOGGER.debug("Uploading part %s for filename: %s",
                     self._part_number, self._filename.src)
        try:
            LOGGER.debug("Waiting for upload id.")
            upload_id = self._upload_context.wait_for_upload_id()
            bucket, key = find_bucket_key(self._filename.dest)
            if self._filename.is_stream:
                body = self._payload
                total = self._upload_context.expected_parts
            else:
                total = int(math.ceil(
                    self._filename.size/float(self._chunk_size)))
                body = self._read_part()
            params = {'Bucket': bucket, 'Key': key,
                      'PartNumber': self._part_number,
                      'UploadId': upload_id,
                      'Body': body}
            RequestParamsMapper.map_upload_part_params(params, self._params)
            try:
                response_data = self._filename.client.upload_part(**params)
            finally:
                body.close()
            etag = response_data['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': total,
                      '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, task has been cancelled.")
        except Exception as e:
            LOGGER.debug('Error during part upload: %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("Part number %s completed for filename: %s",
                         self._part_number, self._filename.src)
Esempio n. 4
0
 def test_upload_part(self):
     params = {}
     RequestParamsMapper.map_upload_part_params(params, self.cli_params)
     self.assertEqual(params, {"SSECustomerAlgorithm": "AES256", "SSECustomerKey": "my-sse-c-key"})
 def test_upload_part(self):
     params = {}
     RequestParamsMapper.map_upload_part_params(params, self.cli_params)
     self.assertEqual(params, {'RequestPayer': 'requester'})
Esempio n. 6
0
 def test_upload_part(self):
     params = {}
     RequestParamsMapper.map_upload_part_params(params, self.cli_params)
     self.assertEqual(params, {'RequestPayer': 'requester'})