From ce2f7aaf87cd6c181d829f7e3e738156aa59639c Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Mon, 19 Oct 2020 17:12:28 +0200 Subject: [PATCH] catch ImportError rather than Exception when testing Boto3 imports --- plugins/modules/aws_direct_connect_confirm_connection.py | 5 ++--- plugins/modules/aws_direct_connect_connection.py | 5 ++--- plugins/modules/aws_direct_connect_link_aggregation_group.py | 2 +- plugins/modules/aws_s3_cors.py | 2 +- plugins/modules/ec2_transit_gateway.py | 5 ++--- plugins/modules/ec2_transit_gateway_info.py | 5 ++--- plugins/modules/lambda_policy.py | 2 +- plugins/modules/rds_snapshot_info.py | 2 +- 8 files changed, 12 insertions(+), 16 deletions(-) diff --git a/plugins/modules/aws_direct_connect_confirm_connection.py b/plugins/modules/aws_direct_connect_confirm_connection.py index ba85f94eff3..948aa63c81c 100644 --- a/plugins/modules/aws_direct_connect_confirm_connection.py +++ b/plugins/modules/aws_direct_connect_confirm_connection.py @@ -67,9 +67,8 @@ try: from botocore.exceptions import BotoCoreError, ClientError -except Exception: - pass - # handled by imported AnsibleAWSModule +except ImportError: + pass # handled by imported AnsibleAWSModule retry_params = {"tries": 10, "delay": 5, "backoff": 1.2, "catch_extra_error_codes": ["DirectConnectClientException"]} diff --git a/plugins/modules/aws_direct_connect_connection.py b/plugins/modules/aws_direct_connect_connection.py index 2fbda9124bb..9899b742fb4 100644 --- a/plugins/modules/aws_direct_connect_connection.py +++ b/plugins/modules/aws_direct_connect_connection.py @@ -166,9 +166,8 @@ try: from botocore.exceptions import BotoCoreError, ClientError -except Exception: - pass - # handled by imported AnsibleAWSModule +except ImportError: + pass # handled by imported AnsibleAWSModule retry_params = {"tries": 10, "delay": 5, "backoff": 1.2, "catch_extra_error_codes": ["DirectConnectClientException"]} diff --git a/plugins/modules/aws_direct_connect_link_aggregation_group.py b/plugins/modules/aws_direct_connect_link_aggregation_group.py index fec3f3dfc99..e3fae3ccf06 100644 --- a/plugins/modules/aws_direct_connect_link_aggregation_group.py +++ b/plugins/modules/aws_direct_connect_link_aggregation_group.py @@ -166,7 +166,7 @@ try: import botocore -except Exception: +except ImportError: pass # Handled by AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule diff --git a/plugins/modules/aws_s3_cors.py b/plugins/modules/aws_s3_cors.py index 0577c955e91..820530dc08d 100644 --- a/plugins/modules/aws_s3_cors.py +++ b/plugins/modules/aws_s3_cors.py @@ -97,7 +97,7 @@ try: from botocore.exceptions import ClientError, BotoCoreError -except Exception: +except ImportError: pass # Handled by AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule diff --git a/plugins/modules/ec2_transit_gateway.py b/plugins/modules/ec2_transit_gateway.py index 5a7ea4b248c..a0595b4b7e1 100644 --- a/plugins/modules/ec2_transit_gateway.py +++ b/plugins/modules/ec2_transit_gateway.py @@ -222,9 +222,8 @@ try: from botocore.exceptions import BotoCoreError, ClientError -except Exception: - pass - # handled by imported AnsibleAWSModule +except ImportError: + pass # handled by imported AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule from time import sleep, time diff --git a/plugins/modules/ec2_transit_gateway_info.py b/plugins/modules/ec2_transit_gateway_info.py index 676862185b4..2eacf01cd96 100644 --- a/plugins/modules/ec2_transit_gateway_info.py +++ b/plugins/modules/ec2_transit_gateway_info.py @@ -166,9 +166,8 @@ try: from botocore.exceptions import BotoCoreError, ClientError -except Exception: - pass - # handled by imported AnsibleAWSModule +except ImportError: + pass # handled by imported AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ( diff --git a/plugins/modules/lambda_policy.py b/plugins/modules/lambda_policy.py index 2860e3a6540..2fb4b4ddead 100644 --- a/plugins/modules/lambda_policy.py +++ b/plugins/modules/lambda_policy.py @@ -139,7 +139,7 @@ try: from botocore.exceptions import ClientError -except Exception: +except ImportError: pass # caught by AnsibleAWSModule diff --git a/plugins/modules/rds_snapshot_info.py b/plugins/modules/rds_snapshot_info.py index 1d7003ae55c..63a5e47b09b 100644 --- a/plugins/modules/rds_snapshot_info.py +++ b/plugins/modules/rds_snapshot_info.py @@ -298,7 +298,7 @@ try: import botocore -except Exception: +except ImportError: pass # caught by AnsibleAWSModule