diff --git a/awscli/customizations/codedeploy.py b/awscli/customizations/codedeploy.py index 8cc4e1dd2e41..cdd08e9ee88b 100644 --- a/awscli/customizations/codedeploy.py +++ b/awscli/customizations/codedeploy.py @@ -16,10 +16,11 @@ import os import zipfile import tempfile -import io import contextlib from datetime import datetime +import six + from awscli.argprocess import unpack_cli_arg from awscli.arguments import CustomArgument from awscli.arguments import create_argument_model_from_schema @@ -269,7 +270,7 @@ def _multipart_upload_to_s3(self, parsed_args, bundle, size_remaining): key=parsed_args.key, uploadId=upload_id, partNumber=part_num, - body=io.BytesIO(data) + body=six.BytesIO(data) ) multipart_list.append({ 'PartNumber': part_num, @@ -477,11 +478,10 @@ def _call(self, parsed_args, parsed_globals): parsed_args.version = upload_response['VersionId'] except Exception as e: raise RuntimeError( - 'Failed to upload \'{0}\' to \'{1}\': {2}'.format( - parsed_args.source, - parsed_args.s3_location, - e.message - ) + 'Failed to upload \'%s\' to \'%s\': %s' % + (parsed_args.source, + parsed_args.s3_location, + str(e)) ) self.codedeploy.register_revision(parsed_args) @@ -515,7 +515,7 @@ def _call(self, parsed_args, parsed_globals): def _compress(self, source, ignore_hidden_files=False): source_path = os.path.abspath(source) appspec_path = os.path.sep.join([source_path, 'appspec.yml']) - with tempfile.TemporaryFile() as tf: + with tempfile.TemporaryFile('w+b') as tf: zf = zipfile.ZipFile(tf, 'w') # Using 'try'/'finally' instead of 'with' statement since ZipFile # does not have support context manager in Python 2.6. diff --git a/tests/unit/customizations/test_codedeploy.py b/tests/unit/customizations/test_codedeploy.py index 668d6a18d1f2..df2b92a3cc85 100644 --- a/tests/unit/customizations/test_codedeploy.py +++ b/tests/unit/customizations/test_codedeploy.py @@ -495,9 +495,7 @@ def setUp(self): self.version_id = '12341234-1234-1234-1234-123412341234' self.upload_id = 'upload_id' self.region = 'us-east-1' - self.endpoint_url = 'https://codedeploy-{}.amazonaws.com'.format( - self.region - ) + self.endpoint_url = 'https://codedeploy-%s.amazonaws.com' % self.region self.args = argparse.Namespace() self.args.application_name = self.application_name @@ -534,7 +532,7 @@ def setUp(self): self.bundle_mock = MagicMock() self.bundle_mock.tell.return_value = (5 << 20) - self.bundle_mock.read.return_value = 'a' * (5 << 20) + self.bundle_mock.read.return_value = b'a' * (5 << 20) self.bundle_mock.__enter__.return_value = self.bundle_mock self.bundle_mock.__exit__.return_value = None @@ -585,7 +583,7 @@ def test_upload_to_s3_with_multipart_upload(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 = 'a' * (6 << 20) + self.bundle_mock.read.return_value = b'a' * (6 << 20) response = self.s3client.upload_to_s3(self.args, self.bundle_mock) self.assertDictEqual(self.upload_response, response) @@ -613,7 +611,7 @@ 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 = 'a' * (6 << 20) + self.bundle_mock.read.return_value = b'a' * (6 << 20) self.s3client.s3.UploadPart.side_effect = RuntimeError('error') with self.assertRaises(RuntimeError) as error: