Skip to content

Commit

Permalink
Merge pull request #675 from tremble/boto3/minimums
Browse files Browse the repository at this point in the history
Cleanup boto3/botocore dependencies - remove tests for unsupported versions

SUMMARY
Testing for boto3/botocore support on specific functions is very inconsistent.  Now that we have minimum supported versions we can drop the tests for previous versions.
ISSUE TYPE

Feature Pull Request

COMPONENT NAME
plugins/modules/aws_eks_cluster.py
plugins/modules/aws_msk_cluster.py
plugins/modules/aws_msk_config.py
plugins/modules/cloudformation_stack_set.py
plugins/modules/dynamodb_table.py
plugins/modules/dynamodb_ttl.py
plugins/modules/ec2_ami_copy.py
plugins/modules/ec2_asg.py
plugins/modules/ec2_launch_template.py
plugins/modules/ec2_transit_gateway.py
plugins/modules/ec2_transit_gateway_info.py
plugins/modules/ec2_vpc_peer.py
plugins/modules/ecs_ecr.py
plugins/modules/ecs_service.py
plugins/modules/ecs_task.py
plugins/modules/ecs_taskdefinition.py
plugins/modules/efs.py
plugins/modules/efs_info.py
plugins/modules/elb_target_group.py
plugins/modules/iam_role.py
plugins/modules/lambda.py
plugins/modules/rds_instance.py
plugins/modules/sqs_queue.py
ADDITIONAL INFORMATION
Depends-on: ansible-collections/amazon.aws#442
Depends-on: ansible-collections/amazon.aws#446

Reviewed-by: Markus Bergholz <[email protected]>
Reviewed-by: Alina Buzachis <None>
Reviewed-by: None <None>
  • Loading branch information
ansible-zuul[bot] authored Aug 10, 2021
2 parents 7a3d808 + 17e8577 commit 90dea24
Show file tree
Hide file tree
Showing 56 changed files with 101 additions and 1,085 deletions.
26 changes: 26 additions & 0 deletions changelogs/fragments/675-boto3-minimums.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
major_changes:
- community.aws collection - The community.aws collection has dropped support for ``botocore<1.16.0`` and ``boto3<1.13.0`` (https://github.com/ansible-collections/community.aws/pull/675).
Most modules will continue to work with older versions of the AWS SDK, however compatability with older versions of the SDK is not guaranteed and will not be tested.
When using older versions of the SDK a warning will be emitted by Ansible (https://github.com/ansible-collections/amazon.aws/pull/442).
minor_changes:
- aws_eks_cluster - Tests for compatability with older versions of the AWS SDKs have been removed (https://github.com/ansible-collections/community.aws/pull/675).
- cloudformation_stack_set - Tests for compatability with older versions of the AWS SDKs have been removed (https://github.com/ansible-collections/community.aws/pull/675).
- dynamodb_table - Tests for compatability with older versions of the AWS SDKs have been removed (https://github.com/ansible-collections/community.aws/pull/675).
- dynamodb_ttl - Tests for compatability with older versions of the AWS SDKs have been removed (https://github.com/ansible-collections/community.aws/pull/675).
- ec2_ami_copy - Tests for compatability with older versions of the AWS SDKs have been removed (https://github.com/ansible-collections/community.aws/pull/675).
- ec2_asg - Tests for compatability with older versions of the AWS SDKs have been removed (https://github.com/ansible-collections/community.aws/pull/675).
- ec2_launch_template - Tests for compatability with older versions of the AWS SDKs have been removed (https://github.com/ansible-collections/community.aws/pull/675).
- ec2_transit_gateway - Tests for compatability with older versions of the AWS SDKs have been removed (https://github.com/ansible-collections/community.aws/pull/675).
- ec2_transit_gateway_info - Tests for compatability with older versions of the AWS SDKs have been removed (https://github.com/ansible-collections/community.aws/pull/675).
- ec2_vpc_peer - Tests for compatability with older versions of the AWS SDKs have been removed (https://github.com/ansible-collections/community.aws/pull/675).
- ecs_ecr - Tests for compatability with older versions of the AWS SDKs have been removed (https://github.com/ansible-collections/community.aws/pull/675).
- ecs_service - Tests for compatability with older versions of the AWS SDKs have been removed (https://github.com/ansible-collections/community.aws/pull/675).
- ecs_task - Tests for compatability with older versions of the AWS SDKs have been removed (https://github.com/ansible-collections/community.aws/pull/675).
- ecs_taskdefinition - Tests for compatability with older versions of the AWS SDKs have been removed (https://github.com/ansible-collections/community.aws/pull/675).
- efs - Tests for compatability with older versions of the AWS SDKs have been removed (https://github.com/ansible-collections/community.aws/pull/675).
- efs_info - Tests for compatability with older versions of the AWS SDKs have been removed (https://github.com/ansible-collections/community.aws/pull/675).
- elb_target_group - Tests for compatability with older versions of the AWS SDKs have been removed (https://github.com/ansible-collections/community.aws/pull/675).
- iam_role - Tests for compatability with older versions of the AWS SDKs have been removed (https://github.com/ansible-collections/community.aws/pull/675).
- lambda - Tests for compatability with older versions of the AWS SDKs have been removed (https://github.com/ansible-collections/community.aws/pull/675).
- rds_instance - Tests for compatability with older versions of the AWS SDKs have been removed (https://github.com/ansible-collections/community.aws/pull/675).
- sqs_queue - Tests for compatability with older versions of the AWS SDKs have been removed (https://github.com/ansible-collections/community.aws/pull/675).
8 changes: 0 additions & 8 deletions plugins/modules/aws_eks_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,6 @@ def main():
supports_check_mode=True,
)

if not module.botocore_at_least("1.10.32"):
module.fail_json(msg='aws_eks_cluster module requires botocore >= 1.10.32')

if (not module.botocore_at_least("1.12.38") and
module.params.get('state') == 'absent' and
module.params.get('wait')):
module.fail_json(msg='aws_eks_cluster: wait=yes when state=absent requires botocore >= 1.12.38')

client = module.client('eks')

if module.params.get('state') == 'present':
Expand Down
13 changes: 6 additions & 7 deletions plugins/modules/aws_msk_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
module: aws_msk_cluster
short_description: Manage Amazon MSK clusters.
version_added: "2.0.0"
requirements:
- botocore >= 1.17.42
- boto3 >= 1.17.9
description:
- Create, delete and modify Amazon MSK (Managed Streaming for Apache Kafka) clusters.
author:
Expand All @@ -34,6 +31,7 @@
- The version of Apache Kafka.
- This version should exist in given configuration.
- This parameter is required when I(state=present).
- Update operation requires botocore version >= 1.16.19.
type: str
configuration_arn:
description:
Expand All @@ -52,7 +50,7 @@
instance_type:
description:
- The type of Amazon EC2 instances to use for Kafka brokers.
- Update operation requires boto3 version >= 1.16.58
- Update operation requires botocore version >= 1.19.58.
choices:
- kafka.t3.small
- kafka.m5.large
Expand Down Expand Up @@ -522,7 +520,7 @@ def create_or_update_cluster(client, module):
}
},
"broker_type": {
"boto3_version": "1.16.58",
"botocore_version": "1.19.58",
"current_value": cluster["BrokerNodeGroupInfo"]["InstanceType"],
"target_value": module.params.get("instance_type"),
"update_params": {
Expand All @@ -546,6 +544,7 @@ def create_or_update_cluster(client, module):
}
},
"cluster_kafka_version": {
"botocore_version": "1.16.19",
"current_value": cluster["CurrentBrokerSoftwareInfo"]["KafkaVersion"],
"target_value": module.params.get("version"),
"update_params": {
Expand Down Expand Up @@ -578,8 +577,8 @@ def create_or_update_cluster(client, module):

for method, options in msk_cluster_changes.items():

if 'boto3_version' in options:
if not module.boto3_at_least(options["boto3_version"]):
if 'botocore_version' in options:
if not module.botocore_at_least(options["botocore_version"]):
continue

try:
Expand Down
17 changes: 4 additions & 13 deletions plugins/modules/aws_msk_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
short_description: Manage Amazon MSK cluster configurations.
version_added: "2.0.0"
requirements:
- botocore >= 1.17.42
- boto3 >= 1.17.9
- botocore >= 1.17.48
- boto3
description:
- Create, delete and modify Amazon MSK (Managed Streaming for Apache Kafka) cluster configurations.
author:
Expand Down Expand Up @@ -104,9 +104,6 @@
)


BOTOCORE_MIN_VERSION = "1.17.42"


def dict_to_prop(d):
"""convert dictionary to multi-line properties"""
if len(d) == 0:
Expand Down Expand Up @@ -138,8 +135,6 @@ def get_configurations_with_backoff(client):
def find_active_config(client, module):
"""
looking for configuration by name
status is not returned for list_configurations in botocore 1.17.42
delete_configuration method was added in botocore 1.17.48
"""

name = module.params["name"]
Expand Down Expand Up @@ -284,12 +279,8 @@ def main():

module = AnsibleAWSModule(argument_spec=module_args, supports_check_mode=True)

if not module.botocore_at_least(BOTOCORE_MIN_VERSION):
module.fail_json(
msg="aws_msk_config module requires botocore >= {0}".format(
BOTOCORE_MIN_VERSION
)
)
# Support for update_configuration and delete_configuration added in 1.17.48
module.require_botocore_at_least('1.17.48')

client = module.client("kafka", retry_decorator=AWSRetry.jittered_backoff())

Expand Down
2 changes: 0 additions & 2 deletions plugins/modules/cloudformation_stack_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,8 +529,6 @@ def main():
mutually_exclusive=[['template_url', 'template', 'template_body']],
supports_check_mode=True
)
if not (module.boto3_at_least('1.6.0') and module.botocore_at_least('1.10.26')):
module.fail_json(msg="Boto3 or botocore version is too low. This module requires at least boto3 1.6 and botocore 1.10.26")

# Wrap the cloudformation client methods that this module uses with
# automatic backoff / retry for throttling error codes
Expand Down
2 changes: 0 additions & 2 deletions plugins/modules/dynamodb_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,6 @@ def main():
if module.params.get('tags'):
try:
boto3_dynamodb = module.client('dynamodb')
if not hasattr(boto3_dynamodb, 'tag_resource'):
module.fail_json(msg='boto3 connection does not have tag_resource(), likely due to using an old version')
boto3_sts = module.client('sts')
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg='Failed to connect to AWS')
Expand Down
4 changes: 0 additions & 4 deletions plugins/modules/dynamodb_ttl.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,6 @@ def main():
argument_spec=argument_spec,
)

if not module.botocore_at_least('1.5.24'):
# TTL was added in 1.5.24
module.fail_json(msg='Found botocore in version {0}, but >= {1} is required for TTL support'.format(botocore.__version__, '1.5.24'))

try:
dbclient = module.client('dynamodb')
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
Expand Down
1 change: 0 additions & 1 deletion plugins/modules/ec2_ami_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ def main():
tag_equality=dict(type='bool', default=False))

module = AnsibleAWSModule(argument_spec=argument_spec)
# TODO: Check botocore version
ec2 = module.client('ec2')
copy_image(module, ec2)

Expand Down
16 changes: 0 additions & 16 deletions plugins/modules/ec2_asg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1825,22 +1825,6 @@ def main():
]
)

if (
module.params.get('max_instance_lifetime') is not None
and not module.botocore_at_least('1.13.21')
):
module.fail_json(
msg='Botocore needs to be version 1.13.21 or higher to use max_instance_lifetime.'
)

if (
module.params.get('mixed_instances_policy') is not None
and not module.botocore_at_least('1.12.45')
):
module.fail_json(
msg='Botocore needs to be version 1.12.45 or higher to use mixed_instances_policy.'
)

state = module.params.get('state')
replace_instances = module.params.get('replace_instances')
replace_all_instances = module.params.get('replace_all_instances')
Expand Down
3 changes: 0 additions & 3 deletions plugins/modules/ec2_launch_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,9 +719,6 @@ def main():
supports_check_mode=True
)

if not module.boto3_at_least('1.6.0'):
module.fail_json(msg="ec2_launch_template requires boto3 >= 1.6.0")

for interface in (module.params.get('network_interfaces') or []):
if interface.get('ipv6_addresses'):
interface['ipv6_addresses'] = [{'ipv6_address': x} for x in interface['ipv6_addresses']]
Expand Down
3 changes: 0 additions & 3 deletions plugins/modules/ec2_transit_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,6 @@ def __init__(self, module, results):
self._connection = self._module.client('ec2')
self._check_mode = self._module.check_mode

if not hasattr(self._connection, 'describe_transit_gateways'):
self._module.fail_json(msg='transit gateway module requires boto3 >= 1.9.52')

def process(self):
""" Process the request based on state parameter .
state = present will search for an existing tgw based and return the object data.
Expand Down
3 changes: 0 additions & 3 deletions plugins/modules/ec2_transit_gateway_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,6 @@ def __init__(self, module, results):
self._connection = self._module.client('ec2')
self._check_mode = self._module.check_mode

if not hasattr(self._connection, 'describe_transit_gateways'):
self._module.fail_json(msg='transit gateway module requires boto3 >= 1.9.52')

@AWSRetry.exponential_backoff()
def describe_transit_gateways(self):
"""
Expand Down
2 changes: 0 additions & 2 deletions plugins/modules/ec2_vpc_peer.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,6 @@ def create_peer_connection(client, module):
params['VpcId'] = module.params.get('vpc_id')
params['PeerVpcId'] = module.params.get('peer_vpc_id')
if module.params.get('peer_region'):
if not module.botocore_at_least('1.8.6'):
module.fail_json(msg="specifying peer_region parameter requires botocore >= 1.8.6")
params['PeerRegion'] = module.params.get('peer_region')
if module.params.get('peer_owner_id'):
params['PeerOwnerId'] = str(module.params.get('peer_owner_id'))
Expand Down
1 change: 0 additions & 1 deletion plugins/modules/ecs_ecr.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
scan_on_push:
description:
- if C(true), images are scanned for known vulnerabilities after being pushed to the repository.
- I(scan_on_push) requires botocore >= 1.13.3
required: false
default: false
type: bool
Expand Down
41 changes: 6 additions & 35 deletions plugins/modules/ecs_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@
network_configuration:
description:
- Network configuration of the service. Only applicable for task definitions created with I(network_mode=awsvpc).
- I(assign_public_ip) requires botocore >= 1.8.4
type: dict
suboptions:
subnets:
Expand All @@ -146,7 +145,6 @@
assign_public_ip:
description:
- Whether the task's elastic network interface receives a public IP address.
- This option requires botocore >= 1.8.4.
type: bool
launch_type:
description:
Expand All @@ -164,7 +162,6 @@
health_check_grace_period_seconds:
description:
- Seconds to wait before health checking the freshly added/updated services.
- This option requires botocore >= 1.8.20.
required: false
type: int
service_registries:
Expand Down Expand Up @@ -516,13 +513,10 @@ def format_network_configuration(self, network_config):
self.module.fail_json_aws(e, msg="Couldn't look up security groups")
result['securityGroups'] = groups
if network_config['assign_public_ip'] is not None:
if self.module.botocore_at_least('1.8.4'):
if network_config['assign_public_ip'] is True:
result['assignPublicIp'] = "ENABLED"
else:
result['assignPublicIp'] = "DISABLED"
if network_config['assign_public_ip'] is True:
result['assignPublicIp'] = "ENABLED"
else:
self.module.fail_json(msg='botocore needs to be version 1.8.4 or higher to use assign_public_ip in network_configuration')
result['assignPublicIp'] = "DISABLED"
return dict(awsvpcConfiguration=result)

def find_in_array(self, array_of_services, service_name, field_name='serviceArn'):
Expand Down Expand Up @@ -640,16 +634,9 @@ def jsonize(self, service):
def delete_service(self, service, cluster=None):
return self.ecs.delete_service(cluster=cluster, service=service)

def ecs_api_handles_network_configuration(self):
# There doesn't seem to be a nice way to inspect botocore to look
# for attributes (and networkConfiguration is not an explicit argument
# to e.g. ecs.run_task, it's just passed as a keyword argument)
return self.module.botocore_at_least('1.7.44')

def health_check_setable(self, params):
load_balancers = params.get('loadBalancers', [])
# check if botocore (and thus boto3) is new enough for using the healthCheckGracePeriodSeconds parameter
return len(load_balancers) > 0 and self.module.botocore_at_least('1.8.20')
return len(load_balancers) > 0


def main():
Expand Down Expand Up @@ -710,8 +697,6 @@ def main():

service_mgr = EcsServiceManager(module)
if module.params['network_configuration']:
if not service_mgr.ecs_api_handles_network_configuration():
module.fail_json(msg='botocore needs to be version 1.7.44 or higher to use network configuration')
network_configuration = service_mgr.format_network_configuration(module.params['network_configuration'])
else:
network_configuration = None
Expand All @@ -729,16 +714,6 @@ def main():

results = dict(changed=False)

if module.params['launch_type']:
if not module.botocore_at_least('1.8.4'):
module.fail_json(msg='botocore needs to be version 1.8.4 or higher to use launch_type')
if module.params['force_new_deployment']:
if not module.botocore_at_least('1.8.4'):
module.fail_json(msg='botocore needs to be version 1.8.4 or higher to use force_new_deployment')
if module.params['health_check_grace_period_seconds']:
if not module.botocore_at_least('1.8.20'):
module.fail_json(msg='botocore needs to be version 1.8.20 or higher to use health_check_grace_period_seconds')

if module.params['state'] == 'present':

matching = False
Expand Down Expand Up @@ -773,15 +748,11 @@ def main():
# check various parameters and boto versions and give a helpful error in boto is not new enough for feature

if module.params['scheduling_strategy']:
if not module.botocore_at_least('1.10.37'):
module.fail_json(msg='botocore needs to be version 1.10.37 or higher to use scheduling_strategy')
elif (existing['schedulingStrategy']) != module.params['scheduling_strategy']:
if (existing['schedulingStrategy']) != module.params['scheduling_strategy']:
module.fail_json(msg="It is not possible to update the scheduling strategy of an existing service")

if module.params['service_registries']:
if not module.botocore_at_least('1.9.15'):
module.fail_json(msg='botocore needs to be version 1.9.15 or higher to use service_registries')
elif (existing['serviceRegistries'] or []) != serviceRegistries:
if (existing['serviceRegistries'] or []) != serviceRegistries:
module.fail_json(msg="It is not possible to update the service registries of an existing service")

if (existing['loadBalancers'] or []) != loadBalancers:
Expand Down
Loading

0 comments on commit 90dea24

Please sign in to comment.