diff --git a/changelogs/fragments/629-imports-cleanup.yml b/changelogs/fragments/629-imports-cleanup.yml new file mode 100644 index 00000000000..211aea45988 --- /dev/null +++ b/changelogs/fragments/629-imports-cleanup.yml @@ -0,0 +1,2 @@ +minor_changes: +- various community.aws modules - remove unused imports (https://github.com/ansible-collections/community.aws/pull/629) diff --git a/plugins/modules/ec2_vpc_endpoint.py b/plugins/modules/ec2_vpc_endpoint.py index 62424f93a11..75ba2479afe 100644 --- a/plugins/modules/ec2_vpc_endpoint.py +++ b/plugins/modules/ec2_vpc_endpoint.py @@ -200,7 +200,6 @@ import datetime import json -import time import traceback try: diff --git a/plugins/modules/ec2_vpc_endpoint_info.py b/plugins/modules/ec2_vpc_endpoint_info.py index fabeb46afe4..f84434cb9af 100644 --- a/plugins/modules/ec2_vpc_endpoint_info.py +++ b/plugins/modules/ec2_vpc_endpoint_info.py @@ -109,8 +109,6 @@ vpc_id: "vpc-1111ffff" ''' -import json - try: import botocore except ImportError: diff --git a/plugins/modules/ec2_vpc_peering_info.py b/plugins/modules/ec2_vpc_peering_info.py index 6b810a25099..f43d1378aa8 100644 --- a/plugins/modules/ec2_vpc_peering_info.py +++ b/plugins/modules/ec2_vpc_peering_info.py @@ -200,8 +200,6 @@ type: list ''' -import json - try: import botocore except ImportError: @@ -210,8 +208,8 @@ from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.core import normalize_boto3_result from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_tag_list_to_ansible_dict from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_filter_list +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_tag_list_to_ansible_dict from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict diff --git a/plugins/modules/kinesis_stream.py b/plugins/modules/kinesis_stream.py index 0f28856bfa9..f3ff171b421 100644 --- a/plugins/modules/kinesis_stream.py +++ b/plugins/modules/kinesis_stream.py @@ -180,22 +180,17 @@ } ''' -import re -import datetime import time -from functools import reduce try: - import botocore.exceptions + import botocore except ImportError: pass # Handled by AnsibleAWSModule from ansible.module_utils._text import to_native from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict -from ansible.module_utils.common.dict_transformations import snake_dict_to_camel_dict from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_tag_list from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_tag_list_to_ansible_dict from ansible_collections.amazon.aws.plugins.module_utils.ec2 import compare_aws_tags diff --git a/plugins/modules/wafv2_ip_set.py b/plugins/modules/wafv2_ip_set.py index 179b065cf4d..1efaf31f77a 100644 --- a/plugins/modules/wafv2_ip_set.py +++ b/plugins/modules/wafv2_ip_set.py @@ -116,14 +116,16 @@ returned: Always, as long as the ip set exists type: str """ -from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule, is_boto3_error_code, get_boto3_client_method_parameters -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict, ansible_dict_to_boto3_tag_list try: from botocore.exceptions import ClientError, BotoCoreError except ImportError: pass # caught by AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_tag_list +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict + class IpSet: def __init__(self, wafv2, name, scope, fail_json_aws): diff --git a/plugins/modules/wafv2_ip_set_info.py b/plugins/modules/wafv2_ip_set_info.py index 251fc0b5483..0c2bf3f0e4e 100644 --- a/plugins/modules/wafv2_ip_set_info.py +++ b/plugins/modules/wafv2_ip_set_info.py @@ -69,14 +69,15 @@ returned: Always, as long as the ip set exists type: str """ -from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule, is_boto3_error_code, get_boto3_client_method_parameters -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict try: from botocore.exceptions import ClientError, BotoCoreError except ImportError: pass # caught by AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict + def list_ip_sets(wafv2, scope, fail_json_aws, Nextmarker=None): # there is currently no paginator for wafv2 diff --git a/plugins/modules/wafv2_resources.py b/plugins/modules/wafv2_resources.py index 70dffaa5f0d..bbed06a0499 100644 --- a/plugins/modules/wafv2_resources.py +++ b/plugins/modules/wafv2_resources.py @@ -59,15 +59,16 @@ returned: Always, as long as the wafv2 exists type: list """ -from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule, is_boto3_error_code, get_boto3_client_method_parameters -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict, ansible_dict_to_boto3_tag_list -from ansible_collections.community.aws.plugins.module_utils.wafv2 import wafv2_list_web_acls try: from botocore.exceptions import ClientError, BotoCoreError except ImportError: pass # caught by AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict +from ansible_collections.community.aws.plugins.module_utils.wafv2 import wafv2_list_web_acls + def get_web_acl(wafv2, name, scope, id, fail_json_aws): try: diff --git a/plugins/modules/wafv2_resources_info.py b/plugins/modules/wafv2_resources_info.py index 5add2169cf9..6ab7aa04ca1 100644 --- a/plugins/modules/wafv2_resources_info.py +++ b/plugins/modules/wafv2_resources_info.py @@ -48,15 +48,16 @@ returned: Always, as long as the wafv2 exists type: list """ -from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule, is_boto3_error_code, get_boto3_client_method_parameters -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict, ansible_dict_to_boto3_tag_list -from ansible_collections.community.aws.plugins.module_utils.wafv2 import wafv2_list_web_acls try: from botocore.exceptions import ClientError, BotoCoreError except ImportError: pass # caught by AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict +from ansible_collections.community.aws.plugins.module_utils.wafv2 import wafv2_list_web_acls + def get_web_acl(wafv2, name, scope, id, fail_json_aws): try: diff --git a/plugins/modules/wafv2_rule_group.py b/plugins/modules/wafv2_rule_group.py index 474897f8ca9..179ac2e85f2 100644 --- a/plugins/modules/wafv2_rule_group.py +++ b/plugins/modules/wafv2_rule_group.py @@ -200,15 +200,20 @@ metric_name: blub sampled_requests_enabled: False """ -from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule, is_boto3_error_code, get_boto3_client_method_parameters -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import snake_dict_to_camel_dict, camel_dict_to_snake_dict, ansible_dict_to_boto3_tag_list -from ansible_collections.community.aws.plugins.module_utils.wafv2 import wafv2_list_rule_groups, compare_priority_rules, wafv2_snake_dict_to_camel_dict try: from botocore.exceptions import ClientError, BotoCoreError except ImportError: pass # caught by AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_tag_list +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import snake_dict_to_camel_dict +from ansible_collections.community.aws.plugins.module_utils.wafv2 import compare_priority_rules +from ansible_collections.community.aws.plugins.module_utils.wafv2 import wafv2_list_rule_groups +from ansible_collections.community.aws.plugins.module_utils.wafv2 import wafv2_snake_dict_to_camel_dict + class RuleGroup: def __init__(self, wafv2, name, scope, fail_json_aws): diff --git a/plugins/modules/wafv2_rule_group_info.py b/plugins/modules/wafv2_rule_group_info.py index ce50b2983f4..47d1e68cc55 100644 --- a/plugins/modules/wafv2_rule_group_info.py +++ b/plugins/modules/wafv2_rule_group_info.py @@ -93,15 +93,16 @@ metric_name: blub sampled_requests_enabled: False """ -from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule, is_boto3_error_code, get_boto3_client_method_parameters -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict, ansible_dict_to_boto3_tag_list -from ansible_collections.community.aws.plugins.module_utils.wafv2 import wafv2_list_rule_groups try: from botocore.exceptions import ClientError, BotoCoreError except ImportError: pass # caught by AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict +from ansible_collections.community.aws.plugins.module_utils.wafv2 import wafv2_list_rule_groups + def get_rule_group(wafv2, name, scope, id, fail_json_aws): try: diff --git a/plugins/modules/wafv2_web_acl.py b/plugins/modules/wafv2_web_acl.py index 63b7ca38fcb..1476b1d48d0 100644 --- a/plugins/modules/wafv2_web_acl.py +++ b/plugins/modules/wafv2_web_acl.py @@ -190,15 +190,20 @@ metric_name: blub sampled_requests_enabled: false """ -from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule, is_boto3_error_code, get_boto3_client_method_parameters -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import snake_dict_to_camel_dict, camel_dict_to_snake_dict, ansible_dict_to_boto3_tag_list -from ansible_collections.community.aws.plugins.module_utils.wafv2 import wafv2_list_web_acls, compare_priority_rules, wafv2_snake_dict_to_camel_dict try: from botocore.exceptions import ClientError, BotoCoreError except ImportError: pass # caught by AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_tag_list +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import snake_dict_to_camel_dict +from ansible_collections.community.aws.plugins.module_utils.wafv2 import compare_priority_rules +from ansible_collections.community.aws.plugins.module_utils.wafv2 import wafv2_list_web_acls +from ansible_collections.community.aws.plugins.module_utils.wafv2 import wafv2_snake_dict_to_camel_dict + class WebACL: def __init__(self, wafv2, name, scope, fail_json_aws): diff --git a/plugins/modules/wafv2_web_acl_info.py b/plugins/modules/wafv2_web_acl_info.py index 0e6a5d4f4ba..54545c10acc 100644 --- a/plugins/modules/wafv2_web_acl_info.py +++ b/plugins/modules/wafv2_web_acl_info.py @@ -88,15 +88,16 @@ metric_name: blub sampled_requests_enabled: false """ -from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule, is_boto3_error_code, get_boto3_client_method_parameters -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict, ansible_dict_to_boto3_tag_list -from ansible_collections.community.aws.plugins.module_utils.wafv2 import wafv2_list_web_acls try: from botocore.exceptions import ClientError, BotoCoreError except ImportError: pass # caught by AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict +from ansible_collections.community.aws.plugins.module_utils.wafv2 import wafv2_list_web_acls + def get_web_acl(wafv2, name, scope, id, fail_json_aws): try: diff --git a/scripts/inventory/ec2.py b/scripts/inventory/ec2.py index d47a67e9308..d903de14ac8 100644 --- a/scripts/inventory/ec2.py +++ b/scripts/inventory/ec2.py @@ -140,34 +140,35 @@ 'webserver-ansible-blue-172.31.0.1' ''' -import sys -import os import argparse +import json +import os import re -from time import time +import sys +from collections import defaultdict from copy import deepcopy from datetime import date, datetime +from time import time + import boto from boto import ec2 -from boto import rds from boto import elasticache +from boto import rds from boto import route53 from boto import sts -from ansible.module_utils import six -from ansible_collections.amazon.aws.plugins.module_utils import ec2 as ec2_utils -from ansible.module_utils.six.moves import configparser - HAS_BOTO3 = False try: - import boto3 # noqa + # Used so that we can cleanly fail, some of our (optional) dependencies need this + import boto3 # pylint: disable=unused-import HAS_BOTO3 = True except ImportError: pass -from collections import defaultdict +from ansible.module_utils import six +from ansible.module_utils.six.moves import configparser +from ansible_collections.amazon.aws.plugins.module_utils import ec2 as ec2_utils -import json DEFAULTS = { 'all_elasticache_clusters': 'False', diff --git a/tests/unit/compat/builtins.py b/tests/unit/compat/builtins.py index f60ee678228..349d310e86d 100644 --- a/tests/unit/compat/builtins.py +++ b/tests/unit/compat/builtins.py @@ -26,7 +26,7 @@ # One unittest needs to import builtins via __import__() so we need to have # the string that represents it try: - import __builtin__ + import __builtin__ # pylint: disable=unused-import except ImportError: BUILTINS = 'builtins' else: diff --git a/tests/unit/plugins/modules/test_aws_acm.py b/tests/unit/plugins/modules/test_aws_acm.py index a36f3f237e2..5b0f86abf15 100644 --- a/tests/unit/plugins/modules/test_aws_acm.py +++ b/tests/unit/plugins/modules/test_aws_acm.py @@ -17,10 +17,13 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -from ansible_collections.community.aws.plugins.modules.aws_acm import pem_chain_split, chain_compare -from ansible.module_utils._text import to_bytes, to_text + from pprint import pprint +from ansible_collections.community.aws.plugins.modules.aws_acm import chain_compare +from ansible_collections.community.aws.plugins.modules.aws_acm import pem_chain_split +from ansible.module_utils._text import to_text + def test_chain_compare(): diff --git a/tests/unit/plugins/modules/test_aws_direct_connect_confirm_connection.py b/tests/unit/plugins/modules/test_aws_direct_connect_confirm_connection.py index eae4889e391..17bd5c7e45d 100644 --- a/tests/unit/plugins/modules/test_aws_direct_connect_confirm_connection.py +++ b/tests/unit/plugins/modules/test_aws_direct_connect_confirm_connection.py @@ -9,9 +9,8 @@ pass from ansible_collections.amazon.aws.plugins.module_utils.ec2 import HAS_BOTO3 -from ansible_collections.community.aws.tests.unit.compat.mock import MagicMock -from ansible_collections.community.aws.tests.unit.compat.mock import patch from ansible_collections.community.aws.tests.unit.compat.mock import call +from ansible_collections.community.aws.tests.unit.compat.mock import patch from ansible_collections.community.aws.tests.unit.plugins.modules.utils import AnsibleExitJson from ansible_collections.community.aws.tests.unit.plugins.modules.utils import AnsibleFailJson from ansible_collections.community.aws.tests.unit.plugins.modules.utils import ModuleTestCase diff --git a/tests/unit/plugins/modules/test_aws_direct_connect_connection.py b/tests/unit/plugins/modules/test_aws_direct_connect_connection.py index 5b94572cee2..fe0febdfc69 100644 --- a/tests/unit/plugins/modules/test_aws_direct_connect_connection.py +++ b/tests/unit/plugins/modules/test_aws_direct_connect_connection.py @@ -7,7 +7,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import placeboify, maybe_sleep +# Magic... Incorrectly identified by pylint as unused +from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import maybe_sleep # pylint: disable=unused-import +from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import placeboify # pylint: disable=unused-import + from ansible_collections.community.aws.plugins.modules import aws_direct_connect_connection diff --git a/tests/unit/plugins/modules/test_aws_direct_connect_link_aggregation_group.py b/tests/unit/plugins/modules/test_aws_direct_connect_link_aggregation_group.py index 8c4406c7560..8bce744421b 100644 --- a/tests/unit/plugins/modules/test_aws_direct_connect_link_aggregation_group.py +++ b/tests/unit/plugins/modules/test_aws_direct_connect_link_aggregation_group.py @@ -10,9 +10,15 @@ import pytest import os import collections -from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import placeboify, maybe_sleep + +# Magic... Incorrectly identified by pylint as unused +from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import maybe_sleep # pylint: disable=unused-import +from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import placeboify # pylint: disable=unused-import + +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_conn +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import get_aws_connection_info + from ansible_collections.community.aws.plugins.modules import aws_direct_connect_link_aggregation_group as lag_module -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import get_aws_connection_info, boto3_conn @pytest.fixture(scope="module") diff --git a/tests/unit/plugins/modules/test_aws_direct_connect_virtual_interface.py b/tests/unit/plugins/modules/test_aws_direct_connect_virtual_interface.py index ce2630fce18..a0a715acc0b 100644 --- a/tests/unit/plugins/modules/test_aws_direct_connect_virtual_interface.py +++ b/tests/unit/plugins/modules/test_aws_direct_connect_virtual_interface.py @@ -7,7 +7,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import placeboify, maybe_sleep +# Magic... Incorrectly identified by pylint as unused +from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import maybe_sleep # pylint: disable=unused-import +from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import placeboify # pylint: disable=unused-import + from ansible_collections.community.aws.plugins.modules import aws_direct_connect_virtual_interface diff --git a/tests/unit/plugins/modules/test_data_pipeline.py b/tests/unit/plugins/modules/test_data_pipeline.py index 8c136bbe537..b7971aac602 100644 --- a/tests/unit/plugins/modules/test_data_pipeline.py +++ b/tests/unit/plugins/modules/test_data_pipeline.py @@ -7,16 +7,19 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type +import collections import os import json -import collections - import pytest -from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import placeboify, maybe_sleep -from ansible_collections.community.aws.plugins.modules import data_pipeline from ansible.module_utils._text import to_text +# Magic... Incorrectly identified by pylint as unused +from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import maybe_sleep # pylint: disable=unused-import +from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import placeboify # pylint: disable=unused-import + +from ansible_collections.community.aws.plugins.modules import data_pipeline + # test_api_gateway.py requires the `boto3` and `botocore` modules boto3 = pytest.importorskip('boto3') diff --git a/tests/unit/plugins/modules/test_ec2_vpc_vpn.py b/tests/unit/plugins/modules/test_ec2_vpc_vpn.py index ee8f284a1f6..49ef596a5b1 100644 --- a/tests/unit/plugins/modules/test_ec2_vpc_vpn.py +++ b/tests/unit/plugins/modules/test_ec2_vpc_vpn.py @@ -4,10 +4,12 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import pytest import os -from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import placeboify -from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import maybe_sleep +import pytest + +# Magic... Incorrectly identified by pylint as unused +from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import placeboify # pylint: disable=unused-import +from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import maybe_sleep # pylint: disable=unused-import import ansible_collections.amazon.aws.plugins.module_utils.core as aws_core import ansible_collections.amazon.aws.plugins.module_utils.ec2 as aws_ec2 diff --git a/tests/unit/plugins/modules/test_lambda.py b/tests/unit/plugins/modules/test_lambda.py index 3562590e5c2..348a00f5a8f 100644 --- a/tests/unit/plugins/modules/test_lambda.py +++ b/tests/unit/plugins/modules/test_lambda.py @@ -11,16 +11,13 @@ import copy import pytest -from ansible.module_utils import basic from ansible_collections.amazon.aws.plugins.module_utils.ec2 import HAS_BOTO3 -from ansible_collections.community.aws.tests.unit.compat.mock import MagicMock -from ansible_collections.community.aws.tests.unit.compat.mock import Mock from ansible_collections.community.aws.tests.unit.compat.mock import patch from ansible_collections.community.aws.tests.unit.plugins.modules.utils import AnsibleExitJson -from ansible_collections.community.aws.tests.unit.plugins.modules.utils import AnsibleFailJson from ansible_collections.community.aws.tests.unit.plugins.modules.utils import ModuleTestCase from ansible_collections.community.aws.tests.unit.plugins.modules.utils import set_module_args + if not HAS_BOTO3: pytestmark = pytest.mark.skip("lambda.py requires the `boto3` and `botocore` modules")