Skip to content

Commit

Permalink
Emit a warning if botocore/boto3 versions don't meet our supported mi…
Browse files Browse the repository at this point in the history
…nimums and remove tests for old versions (ansible-collections#442)

Emit a warning if botocore/boto3 versions don't meet our supported minimums and remove tests for old versions

SUMMARY
Rather than checking that we support (old) boto3/botocore features, emit a warning if botocore/boto3 are less than the supported versions.
ISSUE TYPE

Feature Pull Request

COMPONENT NAME
plugins/module_utils/core.py
plugins/modules/aws_s3.py
plugins/modules/cloudformation.py
plugins/modules/ec2_group.py
plugins/modules/ec2_instance.py
plugins/modules/ec2_instance_info.py
plugins/modules/ec2_vpc_subnet.py
plugins/modules/s3_bucket.py
ADDITIONAL INFORMATION

Reviewed-by: Alina Buzachis <None>
Reviewed-by: None <None>
  • Loading branch information
tremble authored Aug 6, 2021
1 parent 3b94939 commit 32b380b
Show file tree
Hide file tree
Showing 19 changed files with 400 additions and 356 deletions.
12 changes: 12 additions & 0 deletions changelogs/fragments/442-boto3-minimums.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
major_changes:
- amazon.aws collection - The amazon.aws collection has dropped support for ``botocore<1.16.0`` and ``boto3<1.13.0``.
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_s3 - Tests for compatability with older versions of the AWS SDKs have been removed (https://github.com/ansible-collections/amazon.aws/pull/442).
- cloudformation - Tests for compatability with older versions of the AWS SDKs have been removed (https://github.com/ansible-collections/amazon.aws/pull/442).
- ec2_group - Tests for compatability with older versions of the AWS SDKs have been removed (https://github.com/ansible-collections/amazon.aws/pull/442).
- ec2_instance - Tests for compatability with older versions of the AWS SDKs have been removed (https://github.com/ansible-collections/amazon.aws/pull/442).
- ec2_instance_info - Tests for compatability with older versions of the AWS SDKs have been removed (https://github.com/ansible-collections/amazon.aws/pull/442).
- ec2_vpc_subnet - Tests for compatability with older versions of the AWS SDKs have been removed (https://github.com/ansible-collections/amazon.aws/pull/442).
- s3_bucket - Tests for compatability with older versions of the AWS SDKs have been removed (https://github.com/ansible-collections/amazon.aws/pull/442).
14 changes: 11 additions & 3 deletions plugins/module_utils/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,17 @@ def __init__(self, **kwargs):

self._module = AnsibleAWSModule.default_settings["module_class"](**kwargs)

if local_settings["check_boto3"] and not HAS_BOTO3:
self._module.fail_json(
msg=missing_required_lib('botocore or boto3'))
if local_settings["check_boto3"]:
if not HAS_BOTO3:
self._module.fail_json(
msg=missing_required_lib('botocore or boto3'))
current_versions = self._gather_versions()
if not self.botocore_at_least('1.16.0'):
self.warn('botocore < 1.16.0 is not supported or tested.'
' Some features may not work.')
if not self.boto3_at_least("1.13.0"):
self.warn('boto3 < 1.13.0 is not supported or tested.'
' Some features may not work.')

self.check_mode = self._module.check_mode
self._diff = self._module._diff
Expand Down
3 changes: 0 additions & 3 deletions plugins/modules/aws_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -970,9 +970,6 @@ def main():
if dualstack and s3_url is not None and 'amazonaws.com' not in s3_url:
module.fail_json(msg='dualstack only applies to AWS S3')

if dualstack and not module.botocore_at_least('1.4.45'):
module.fail_json(msg='dualstack requires botocore >= 1.4.45')

# rgw requires an explicit url
if rgw and not s3_url:
module.fail_json(msg='rgw flavour requires s3_url')
Expand Down
12 changes: 1 addition & 11 deletions plugins/modules/cloudformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,7 @@ def create_stack(module, stack_params, cfn, events_limit):
if module.params.get('create_timeout') is not None:
stack_params['TimeoutInMinutes'] = module.params['create_timeout']
if module.params.get('termination_protection') is not None:
if boto_supports_termination_protection(cfn):
stack_params['EnableTerminationProtection'] = bool(module.params.get('termination_protection'))
else:
module.fail_json(msg="termination_protection parameter requires botocore >= 1.7.18")
stack_params['EnableTerminationProtection'] = bool(module.params.get('termination_protection'))

try:
response = cfn.create_stack(aws_retry=True, **stack_params)
Expand Down Expand Up @@ -502,8 +499,6 @@ def update_stack(module, stack_params, cfn, events_limit):

def update_termination_protection(module, cfn, stack_name, desired_termination_protection_state):
'''updates termination protection of a stack'''
if not boto_supports_termination_protection(cfn):
module.fail_json(msg="termination_protection parameter requires botocore >= 1.7.18")
stack = get_stack_facts(module, cfn, stack_name)
if stack:
if stack['EnableTerminationProtection'] is not desired_termination_protection_state:
Expand All @@ -516,11 +511,6 @@ def update_termination_protection(module, cfn, stack_name, desired_termination_p
module.fail_json_aws(e)


def boto_supports_termination_protection(cfn):
'''termination protection was added in botocore 1.7.18'''
return hasattr(cfn, "update_termination_protection")


def stack_operation(module, cfn, stack_name, operation, events_limit, op_token=None):
'''gets the status of a stack while it is created/updated/deleted'''
existed = []
Expand Down
8 changes: 0 additions & 8 deletions plugins/modules/ec2_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -1022,13 +1022,6 @@ def group_exists(client, module, vpc_id, group_id, name):
return None, {}


def verify_rules_with_descriptions_permitted(client, module, rules, rules_egress):
if not hasattr(client, "update_security_group_rule_descriptions_egress"):
all_rules = rules if rules else [] + rules_egress if rules_egress else []
if any('rule_desc' in rule for rule in all_rules):
module.fail_json(msg="Using rule descriptions requires botocore version >= 1.7.2.")


def get_diff_final_resource(client, module, security_group):
def get_account_id(security_group, module):
try:
Expand Down Expand Up @@ -1208,7 +1201,6 @@ def main():
changed = False
client = module.client('ec2', AWSRetry.jittered_backoff())

verify_rules_with_descriptions_permitted(client, module, rules, rules_egress)
group, groups = group_exists(client, module, vpc_id, group_id, name)
group_created_new = not bool(group)

Expand Down
5 changes: 0 additions & 5 deletions plugins/modules/ec2_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
can create and manage spot instances.
author:
- Ryan Scott Brown (@ryansb)
requirements: [ "boto3", "botocore" ]
options:
instance_ids:
description:
Expand Down Expand Up @@ -234,7 +233,6 @@
- Reduce the number of vCPU exposed to the instance.
- Those parameters can only be set at instance launch. The two suboptions threads_per_core and core_count are mandatory.
- See U(https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-optimize-cpu.html) for combinations available.
- Requires botocore >= 1.10.16
type: dict
suboptions:
threads_per_core:
Expand Down Expand Up @@ -1797,9 +1795,6 @@ def main():

module.params['filters'] = filters

if module.params.get('cpu_options') and not module.botocore_at_least('1.10.16'):
module.fail_json(msg="cpu_options is only supported with botocore >= 1.10.16")

existing_matches = find_instances(ec2, filters=module.params.get('filters'))
changed = False

Expand Down
3 changes: 1 addition & 2 deletions plugins/modules/ec2_instance_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
author:
- Michael Schuett (@michaeljs1990)
- Rob White (@wimnat)
requirements: [ "boto3", "botocore" ]
options:
instance_ids:
description:
Expand Down Expand Up @@ -137,7 +136,7 @@
sample: vol-12345678
cpu_options:
description: The CPU options set for the instance.
returned: always if botocore version >= 1.10.16
returned: always
type: complex
contains:
core_count:
Expand Down
8 changes: 2 additions & 6 deletions plugins/modules/ec2_vpc_subnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,8 @@ def get_subnet_info(subnet):


def waiter_params(module, params, start_time):
if not module.botocore_at_least("1.7.0"):
remaining_wait_timeout = int(module.params['wait_timeout'] + start_time - time.time())
params['WaiterConfig'] = {'Delay': 5, 'MaxAttempts': remaining_wait_timeout // 5}
remaining_wait_timeout = int(module.params['wait_timeout'] + start_time - time.time())
params['WaiterConfig'] = {'Delay': 5, 'MaxAttempts': remaining_wait_timeout // 5}
return params


Expand Down Expand Up @@ -539,9 +538,6 @@ def main():
if module.params.get('assign_instances_ipv6') and not module.params.get('ipv6_cidr'):
module.fail_json(msg="assign_instances_ipv6 is True but ipv6_cidr is None or an empty string")

if not module.botocore_at_least("1.7.0"):
module.warn("botocore >= 1.7.0 is required to use wait_timeout for custom wait times")

retry_decorator = AWSRetry.jittered_backoff(retries=10)
connection = module.client('ec2', retry_decorator=retry_decorator)

Expand Down
13 changes: 0 additions & 13 deletions plugins/modules/s3_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,9 +571,6 @@ def put_bucket_versioning(s3_client, bucket_name, required_versioning):

@AWSRetry.exponential_backoff(max_delay=120, catch_extra_error_codes=['NoSuchBucket', 'OperationAborted'])
def get_bucket_encryption(s3_client, bucket_name):
if not hasattr(s3_client, "get_bucket_encryption"):
return None

try:
result = s3_client.get_bucket_encryption(Bucket=bucket_name)
return result.get('ServerSideEncryptionConfiguration', {}).get('Rules', [])[0].get('ApplyServerSideEncryptionByDefault')
Expand Down Expand Up @@ -772,8 +769,6 @@ def get_bucket_ownership_cntrl(s3_client, module, bucket_name):
'''
Get current bucket public access block
'''
if not module.botocore_at_least('1.8.11'):
return None
try:
bucket_ownership = s3_client.get_bucket_ownership_controls(Bucket=bucket_name)
return bucket_ownership['OwnershipControls']['Rules'][0]['ObjectOwnership']
Expand Down Expand Up @@ -953,14 +948,6 @@ def main():
delete_object_ownership = module.params.get('delete_object_ownership')
object_ownership = module.params.get('object_ownership')

if delete_object_ownership is not None or object_ownership is not None:
if not module.botocore_at_least('1.8.11'):
module.fail_json(msg="Managing bucket ownership controls requires botocore version >= 1.8.11")

if not hasattr(s3_client, "get_bucket_encryption"):
if encryption is not None:
module.fail_json(msg="Using bucket encryption requires botocore version >= 1.7.41")

# Parameter validation
if encryption_key_id is not None and encryption != 'aws:kms':
module.fail_json(msg="Only 'aws:kms' is a valid option for encryption parameter when you specify encryption_key_id.")
Expand Down
2 changes: 2 additions & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ pytest-xdist
pytest-mock
# Needed for ansible.netcommon.ipaddr in tests
netaddr
# Sometimes needed where we don't have features we need in modules
awscli
2 changes: 2 additions & 0 deletions tests/integration/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# netaddr is needed for ansible.netcommon.ipv6
netaddr
virtualenv
# Sometimes needed where we don't have features we need in modules
awscli
Loading

0 comments on commit 32b380b

Please sign in to comment.