From fd40a779ae76e7fbe3022b29259a1641b5397a7b Mon Sep 17 00:00:00 2001 From: JordonPhillips Date: Mon, 27 Mar 2017 14:16:11 -0700 Subject: [PATCH] Fix ec2 pagination bug Resolves #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. --- .changes/next-release/bugfix-ec2-77933.json | 5 +++++ awscli/customizations/cliinputjson.py | 2 +- tests/functional/ec2/test_describe_volumes.py | 20 +++++++++++++++++++ .../unit/customizations/test_cliinputjson.py | 2 +- 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 .changes/next-release/bugfix-ec2-77933.json diff --git a/.changes/next-release/bugfix-ec2-77933.json b/.changes/next-release/bugfix-ec2-77933.json new file mode 100644 index 000000000000..744c9652fd68 --- /dev/null +++ b/.changes/next-release/bugfix-ec2-77933.json @@ -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 `__", + "category": "ec2", + "type": "bugfix" +} diff --git a/awscli/customizations/cliinputjson.py b/awscli/customizations/cliinputjson.py index 909d60ec5190..f33da58d4bdc 100644 --- a/awscli/customizations/cliinputjson.py +++ b/awscli/customizations/cliinputjson.py @@ -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, diff --git a/tests/functional/ec2/test_describe_volumes.py b/tests/functional/ec2/test_describe_volumes.py index ab564e80236a..87d76b947a09 100644 --- a/tests/functional/ec2/test_describe_volumes.py +++ b/tests/functional/ec2/test_describe_volumes.py @@ -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} @@ -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) diff --git a/tests/unit/customizations/test_cliinputjson.py b/tests/unit/customizations/test_cliinputjson.py index 3baa5c938bde..89ab9c01e372 100644 --- a/tests/unit/customizations/test_cliinputjson.py +++ b/tests/unit/customizations/test_cliinputjson.py @@ -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)