Beispiel #1
0
 def test_s3_single_file_404(self):
     """
     Test the error message for a 404 ClientError for a single file listing
     """
     input_s3_file = {
         'src': {
             'path': self.file1,
             'type': 's3'
         },
         'dest': {
             'path': 'text1.txt',
             'type': 'local'
         },
         'dir_op': False,
         'use_src_name': False
     }
     params = {'region': 'us-east-1'}
     self.client = mock.Mock()
     self.client.head_object.side_effect = \
         ClientError(404, 'Not Found', '404', 'HeadObject', 404)
     file_gen = FileGenerator(self.client, '')
     files = file_gen.call(input_s3_file)
     # The error should include 404 and should include the key name.
     with self.assertRaisesRegexp(ClientError, '404.*text1.txt'):
         list(files)
Beispiel #2
0
 def _list_single_object(self, s3_path):
     # When we know we're dealing with a single object, we can avoid
     # a ListObjects operation (which causes concern for anyone setting
     # IAM policies with the smallest set of permissions needed) and
     # instead use a HeadObject request.
     bucket, key = find_bucket_key(s3_path)
     operation = self._service.get_operation('HeadObject')
     try:
         response = operation.call(self._endpoint, bucket=bucket,
                                   key=key)[1]
     except ClientError as e:
         # We want to try to give a more helpful error message.
         # This is what the customer is going to see so we want to
         # give as much detail as we have.
         copy_fields = e.__dict__.copy()
         if not e.error_message == 'Not Found':
             raise
         if e.http_status_code == 404:
             # The key does not exist so we'll raise a more specific
             # error message here.
             copy_fields['error_code'] = 'NoSuchKey'
             copy_fields['error_message'] = 'Key "%s" does not exist' % key
         else:
             reason = six.moves.http_client.responses[e.http_status_code]
             copy_fields['error_code'] = reason
             copy_fields['error_message'] = reason
         raise ClientError(**copy_fields)
     file_size = int(response['ContentLength'])
     last_update = parse(response['LastModified'])
     last_update = last_update.astimezone(tzlocal())
     return s3_path, file_size, last_update
Beispiel #3
0
 def test_upload_to_s3_with_multipart_upload_aborted_on_error(self):
     self.args.bucket = self.bucket
     self.args.key = self.key
     self.bundle_mock.tell.return_value = (6 << 20)
     self.bundle_mock.read.return_value = b'a' * (6 << 20)
     self.push.s3.upload_part.side_effect = ClientError(
         error_code='Error',
         error_message='Error',
         error_type='error',
         operation_name='UploadPart',
         http_status_code=400)
     with self.assertRaises(ClientError):
         self.push._upload_to_s3(self.args, self.bundle_mock)
     self.assertFalse(self.push.s3.put_object.called)
     self.push.s3.create_multipart_upload.assert_called_with(
         Bucket=self.bucket, Key=self.key)
     self.assertTrue(self.push.s3.upload_part.called)
     self.assertFalse(self.push.s3.complete_multipart_upload.called)
     self.push.s3.abort_multipart_upload.assert_called_with(
         Bucket=self.bucket, Key=self.key, UploadId=self.upload_id)