Skip to content

Commit

Permalink
Merge pull request #2998 from joguSD/s3-rc
Browse files Browse the repository at this point in the history
S3 commands ensure error RC takes precedence
  • Loading branch information
joguSD authored Dec 7, 2017
2 parents 4003426 + 3ea7eab commit cc63276
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changes/next-release/bugfix-S3-3229.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "bugfix",
"category": "S3",
"description": "S3 commands that encountered both an error and warning will now return the RC for error instead of warning."
}
2 changes: 1 addition & 1 deletion awscli/customizations/s3/subcommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,7 @@ def run(self):
rc = 0
if files[0].num_tasks_failed > 0:
rc = 1
if files[0].num_tasks_warned > 0:
elif files[0].num_tasks_warned > 0:
rc = 2
return rc

Expand Down
19 changes: 18 additions & 1 deletion tests/functional/s3/test_cp_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import mock

from awscli.testutils import BaseAWSCommandParamsTest, FileCreator
from awscli.testutils import capture_input
from awscli.testutils import capture_input, set_invalid_utime
from awscli.compat import six


Expand Down Expand Up @@ -459,6 +459,23 @@ def test_upload_unicode_path(self):
progress_message = 'Completed 10 Bytes'
self.assertIn(progress_message, stdout)

def test_cp_with_error_and_warning(self):
command = "s3 cp %s s3://bucket/foo.txt"
self.parsed_responses = [{
'Error': {
'Code': 'NoSuchBucket',
'Message': 'The specified bucket does not exist',
'BucketName': 'bucket'
}
}]
self.http_response.status_code = 404

full_path = self.files.create_file('foo.txt', 'bar')
set_invalid_utime(full_path)
_, stderr, rc = self.run_cmd(command % full_path, expected_rc=1)
self.assertIn('upload failed', stderr)
self.assertIn('warning: File has an invalid timestamp.', stderr)


class TestStreamingCPCommand(BaseAWSCommandParamsTest):
def test_streaming_upload(self):
Expand Down

0 comments on commit cc63276

Please sign in to comment.