Skip to content

Commit

Permalink
Fix ec2 pagination bug
Browse files Browse the repository at this point in the history
Resolves aws#2452

Fixes a bug where cli json input would get processed after ec2
auto pagination injection.

This was due to a subtle behavior of the event system. A handler
registered at the top level without any delimiters will always
be called *after* any events registered that do have delimiters
regarless of when or how they were registered.

The handler for --cli-input-json was registered against
'calling-command', and the handler for the ec2 pagination injection
was registered against 'calling-command.ec2.operation-name'. So then
even though the ec2 pagination injection was using register_last, it
was being called first.

The solution is to use 'calling-command.*' instead for the event
that --cli-input-json is registered against. This puts it in the same
pool as the other delimited handlers. This had the potential to break
other handlers depending on the existing ordering, but there were
very few registered to that event. Running the tests revealed no
issues, however.
  • Loading branch information
JordonPhillips committed Mar 27, 2017
1 parent 04a7705 commit fd40a77
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changes/next-release/bugfix-ec2-77933.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"description": "Fixed a bug causing some ec2 commands to fail with an invalid parameter combination error when arguments were supplied via --cli-input-json. Resolves `#2452 <https://github.com/aws/aws-cli/issues/2452>`__",
"category": "ec2",
"type": "bugfix"
}
2 changes: 1 addition & 1 deletion awscli/customizations/cliinputjson.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(self, session):

def _register_argument_action(self):
self._session.register(
'calling-command', self.add_to_call_parameters)
'calling-command.*', self.add_to_call_parameters)
super(CliInputJSONArgument, self)._register_argument_action()

def add_to_call_parameters(self, call_parameters, parsed_args,
Expand Down
20 changes: 20 additions & 0 deletions tests/functional/ec2/test_describe_volumes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,25 @@
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
import json
import shutil

from awscli.testutils import BaseAWSCommandParamsTest
from awscli.testutils import FileCreator


class TestDescribeVolumes(BaseAWSCommandParamsTest):

prefix = 'ec2 describe-volumes'

def setUp(self):
super(TestDescribeVolumes, self).setUp()
self.file_creator = FileCreator()

def tearDown(self):
super(TestDescribeVolumes, self).tearDown()
shutil.rmtree(self.file_creator.rootdir)

def test_max_results_set_by_default(self):
command = self.prefix
params = {'MaxResults': 1000}
Expand All @@ -39,3 +51,11 @@ def test_max_results_not_overwritten(self):

command = self.prefix + ' --page-size 5'
self.assert_params_for_cmd(command, params)

def test_max_results_with_cli_input_json(self):
params = {'VolumeIds': ['vol-12345']}
file_path = self.file_creator.create_file(
'params.json', json.dumps(params))

command = self.prefix + ' --cli-input-json file://%s' % file_path
self.assert_params_for_cmd(command, params)
2 changes: 1 addition & 1 deletion tests/unit/customizations/test_cliinputjson.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def tearDown(self):

def test_register_argument_action(self):
register_args = self.session.register.call_args_list
self.assertEqual(register_args[0][0][0], 'calling-command')
self.assertEqual(register_args[0][0][0], 'calling-command.*')
self.assertEqual(register_args[0][0][1],
self.argument.add_to_call_parameters)

Expand Down

0 comments on commit fd40a77

Please sign in to comment.