Skip to content

Commit

Permalink
Merge branch 'release-1.10.60'
Browse files Browse the repository at this point in the history
* release-1.10.60:
  Bumping version to 1.10.60
  Update changelog based on model updates
  Correct dir name in documentation about recursive copying to an S3 bucket
  Rename global whitelist to universal whitelist
  Don't mutate whitelists
  Move PageSizeInjector to calling-command
  Remove constructor params in favor of class variables
  Fix spelling mistakes and remove unneeded exceptions
  Set default page size for some EC2 operations
  • Loading branch information
AWS committed Aug 30, 2016
2 parents f29f62c + 0f54256 commit 5cef427
Show file tree
Hide file tree
Showing 14 changed files with 368 additions and 19 deletions.
32 changes: 32 additions & 0 deletions .changes/1.10.60.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"category": "``route53``",
"description": "Update route53 command to latest version",
"type": "feature"
},
{
"category": "``codepipeline``",
"description": "Update codepipeline command to latest version",
"type": "feature"
},
{
"category": "``autoscaling``",
"description": "Update autoscaling command to latest version",
"type": "feature"
},
{
"category": "``ssm``",
"description": "Update ssm command to latest version",
"type": "feature"
},
{
"category": "ec2",
"description": "Set MaxResults to 1000 by default for DescribeSnapshots and DescribeVolumes.",
"type": "bugfix"
},
{
"category": "``cloudfront``",
"description": "Update cloudfront command to latest version",
"type": "feature"
}
]
11 changes: 11 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
CHANGELOG
=========

1.10.60
=======

* feature:``route53``: Update route53 command to latest version
* feature:``codepipeline``: Update codepipeline command to latest version
* feature:``autoscaling``: Update autoscaling command to latest version
* feature:``ssm``: Update ssm command to latest version
* bugfix:ec2: Set MaxResults to 1000 by default for DescribeSnapshots and DescribeVolumes.
* feature:``cloudfront``: Update cloudfront command to latest version


1.10.59
=======

Expand Down
2 changes: 1 addition & 1 deletion awscli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"""
import os

__version__ = '1.10.59'
__version__ = '1.10.60'

#
# Get our data path to be added to botocore's search path
Expand Down
64 changes: 64 additions & 0 deletions awscli/customizations/ec2/paginate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# 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.


def register_ec2_page_size_injector(event_emitter):
EC2PageSizeInjector().register(event_emitter)


class EC2PageSizeInjector(object):

# Operations to auto-paginate and their specific whitelists.
# Format:
# Key: Operation
# Value: List of parameters to add to whitelist for that operation.
TARGET_OPERATIONS = {
"describe-volumes": [],
"describe-snapshots": ['OwnerIds', 'RestorableByUserIds']
}

# Parameters which should be whitelisted for every operation.
UNIVERSAL_WHITELIST = ['NextToken', 'DryRun', 'PaginationConfig']

DEFAULT_PAGE_SIZE = 1000

def register(self, event_emitter):
"""Register `inject` for each target operation."""
event_template = "calling-command.ec2.%s"
for operation in self.TARGET_OPERATIONS:
event = event_template % operation
event_emitter.register_last(event, self.inject)

def inject(self, event_name, parsed_globals, call_parameters, **kwargs):
"""Conditionally inject PageSize."""
if not parsed_globals.paginate:
return

pagination_config = call_parameters.get('PaginationConfig', {})
if 'PageSize' in pagination_config:
return

operation_name = event_name.split('.')[-1]

whitelisted_params = self.TARGET_OPERATIONS.get(operation_name)
if whitelisted_params is None:
return

whitelisted_params = whitelisted_params + self.UNIVERSAL_WHITELIST

for param in call_parameters:
if param not in whitelisted_params:
return

pagination_config['PageSize'] = self.DEFAULT_PAGE_SIZE
call_parameters['PaginationConfig'] = pagination_config
2 changes: 1 addition & 1 deletion awscli/examples/s3/cp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ this example, the directory ``myDir`` has the files ``test1.txt`` and ``test2.jp

Output::

upload: myDir/test1.txt to s3://mybucket2/test1.txt
upload: myDir/test1.txt to s3://mybucket/test1.txt

**Recursively copying S3 objects to another bucket**

Expand Down
2 changes: 2 additions & 0 deletions awscli/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
from awscli.customizations.ec2.protocolarg import register_protocol_args
from awscli.customizations.ec2.runinstances import register_runinstances
from awscli.customizations.ec2.secgroupsimplify import register_secgroup
from awscli.customizations.ec2.paginate import register_ec2_page_size_injector
from awscli.customizations.ecr import register_ecr_commands
from awscli.customizations.emr.emr import emr_initialize
from awscli.customizations.gamelift import register_gamelift_commands
Expand Down Expand Up @@ -142,3 +143,4 @@ def awscli_initialize(event_handlers):
register_create_keys_from_csr_arguments)
register_cloudfront(event_handlers)
register_gamelift_commands(event_handlers)
register_ec2_page_size_injector(event_handlers)
2 changes: 1 addition & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
# The short X.Y version.
version = '1.10.'
# The full version, including alpha/beta/rc tags.
release = '1.10.59'
release = '1.10.60'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ universal = 1

[metadata]
requires-dist =
botocore==1.4.49
botocore==1.4.50
colorama>=0.2.5,<=0.3.7
docutils>=0.10
rsa>=3.1.2,<=3.5.0
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import awscli


requires = ['botocore==1.4.49',
requires = ['botocore==1.4.50',
'colorama>=0.2.5,<=0.3.7',
'docutils>=0.10',
'rsa>=3.1.2,<=3.5.0',
Expand Down
43 changes: 43 additions & 0 deletions tests/functional/ec2/test_describe_snapshots.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# 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.
from awscli.testutils import BaseAWSCommandParamsTest


class TestDescribeSnapshots(BaseAWSCommandParamsTest):

prefix = 'ec2 describe-snapshots'

def test_max_results_set_by_default(self):
command = self.prefix
params = {'MaxResults': 1000}
self.assert_params_for_cmd(command, params)

def test_max_results_not_set_with_snapshot_ids(self):
command = self.prefix + ' --snapshot-ids snap-example'
params = {'SnapshotIds': ['snap-example']}
self.assert_params_for_cmd(command, params)

def test_max_results_not_set_with_filter(self):
command = self.prefix + ' --filters Name=snapshot-id,Values=snap-snap'
params = {'Filters': [{
'Name': 'snapshot-id', 'Values': ['snap-snap']
}]}
self.assert_params_for_cmd(command, params)

def test_max_results_not_overwritten(self):
command = self.prefix + ' --max-results 5'
params = {'MaxResults': 5}
self.assert_params_for_cmd(command, params)

command = self.prefix + ' --page-size 5'
self.assert_params_for_cmd(command, params)
41 changes: 41 additions & 0 deletions tests/functional/ec2/test_describe_volumes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# 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.
from awscli.testutils import BaseAWSCommandParamsTest


class TestDescribeVolumes(BaseAWSCommandParamsTest):

prefix = 'ec2 describe-volumes'

def test_max_results_set_by_default(self):
command = self.prefix
params = {'MaxResults': 1000}
self.assert_params_for_cmd(command, params)

def test_max_results_not_set_with_volume_ids(self):
command = self.prefix + ' --volume-ids id-volume'
params = {'VolumeIds': ['id-volume']}
self.assert_params_for_cmd(command, params)

def test_max_results_not_set_with_filter(self):
command = self.prefix + ' --filters Name=volume-id,Values=id-volume'
params = {'Filters': [{'Name': 'volume-id', 'Values': ['id-volume']}]}
self.assert_params_for_cmd(command, params)

def test_max_results_not_overwritten(self):
command = self.prefix + ' --max-results 5'
params = {'MaxResults': 5}
self.assert_params_for_cmd(command, params)

command = self.prefix + ' --page-size 5'
self.assert_params_for_cmd(command, params)
57 changes: 43 additions & 14 deletions tests/integration/test_ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,52 @@
from awscli.testutils import unittest, aws


class BaseEC2Test(unittest.TestCase):
def assert_dry_run_success(self, command):
class TestDescribeInstances(unittest.TestCase):
def setUp(self):
self.prefix = 'ec2 describe-instances --region us-west-2'

def test_describe_instances_with_id(self):
command = self.prefix + ' --instance-ids malformed-id'
result = aws(command)
expected_response = ('Request would have succeeded, '
'but DryRun flag is set.')
self.assertIn(expected_response, result.stderr)
self.assertIn('InvalidInstanceID.Malformed', result.stderr)

def test_describe_instances_with_filter(self):
command = self.prefix + ' --filters Name=instance-id,Values='
command += 'malformed-id'
result = aws(command)
reservations = result.json["Reservations"]
self.assertEqual(len(reservations), 0)

class TestDescribeInstances(BaseEC2Test):

class TestDescribeSnapshots(unittest.TestCase):
def setUp(self):
self.prefix = 'ec2 describe-instances --region us-west-2 --dry-run'
self.prefix = 'ec2 describe-snapshots --region us-west-2'

def test_describe_instances_with_id(self):
command = self.prefix + ' --instance-ids id-example'
self.assert_dry_run_success(command)
def test_describe_snapshot_with_snapshot_id(self):
command = self.prefix + ' --snapshot-ids malformed-id'
result = aws(command)
self.assertIn('InvalidParameterValue', result.stderr)

def test_describe_instances_with_filter(self):
command = self.prefix + ' --filters Name=private-dns-name,Values='
command += 'sample-dns-name'
self.assert_dry_run_success(command)
def test_describe_snapshots_with_filter(self):
command = self.prefix
command += ' --filters Name=snapshot-id,Values=malformed-id'
result = aws(command)
snapshots = result.json['Snapshots']
self.assertEqual(len(snapshots), 0)


class TestDescribeVolumes(unittest.TestCase):
def setUp(self):
self.prefix = 'ec2 describe-volumes --region us-west-2'

def test_describe_volumes_with_volume_id(self):
command = self.prefix + ' --volume-ids malformed-id'
result = aws(command)
self.assertIn('InvalidParameterValue', result.stderr)

def test_describe_volumes_with_filter(self):
command = self.prefix
command += ' --filters Name=volume-id,Values=malformed-id'
result = aws(command)
volumes = result.json['Volumes']
self.assertEqual(len(volumes), 0)
12 changes: 12 additions & 0 deletions tests/unit/customizations/ec2/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# 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.

0 comments on commit 5cef427

Please sign in to comment.