Skip to content

Commit

Permalink
Handle case when create-virtual-mfa-device errors out
Browse files Browse the repository at this point in the history
This was previously propogating a KeyError and would just
display the error message 'VirtualMFADevice'.  Now
we let the error propogate and print a full error message.
  • Loading branch information
jamesls committed Aug 13, 2015
1 parent 4ae70ae commit 0b5583a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions awscli/customizations/iamvirtmfa.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ def _add_options(self, argument_table, **kwargs):
argument_table['bootstrap-method'] = self._method

def _save_file(self, parsed, **kwargs):
if 'Error' in parsed:
return
method = self._method.value
outfile = self._outfile.value
if method in parsed['VirtualMFADevice']:
Expand Down
25 changes: 25 additions & 0 deletions tests/functional/iam/test_create_virtual_mfa_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,28 @@ def test_bad_relative_filename(self):
cmdline += ' --virtual-mfa-device-name fiebaz'
cmdline += ' --outfile %s --bootstrap-method QRCodePNG' % outfile
self.assert_params_for_cmd(cmdline, expected_rc=255)

def test_bad_response(self):
# This can happen if you run the create-virtual-mfa-device
# command multiple times with the same name. You'll get
# an "already exists" error and we should handle that case
# gracefully.
self.parsed_response = {
'Error': {
'Code': 'EntityAlreadyExists',
'Message': 'MFADevice entity at the and name already exists.',
'Type': 'Sender',
},
'ResponseMetadata': {
'HTTPStatusCode': 409,
'RequestId': 'requset-id'}
}
self.http_response.status_code = 409
cmdline = self.prefix
cmdline += ' --virtual-mfa-device-name fiebaz'
cmdline += ' --outfile foo --bootstrap-method QRCodePNG'
# The error message should be in the stderr.
self.assert_params_for_cmd(
cmdline,
stderr_contains=self.parsed_response['Error']['Message'],
expected_rc=255)

0 comments on commit 0b5583a

Please sign in to comment.