Skip to content

Commit

Permalink
Merge pull request #629 from tremble/cleanup/unsed-imports
Browse files Browse the repository at this point in the history
Cleanup / unused imports

SUMMARY
Running a slightly more nit-picky pylint picked up on a number of unused imports.  For general code cleanliness we should clean these up.  (When we don't, we often see things copied and pasted all over the place)
Also

reorders various imports (in the same files) based on the recommendations from PEP.
splits imports (in the same files) onto single lines to make rebase-conflicts easier to fix.

ISSUE TYPE

Feature Pull Request

COMPONENT NAME
plugins/modules/ec2_vpc_endpoint.py
plugins/modules/ec2_vpc_endpoint_info.py
plugins/modules/ec2_vpc_peering_info.py
plugins/modules/kinesis_stream.py
plugins/modules/wafv2_ip_set.py
plugins/modules/wafv2_ip_set_info.py
plugins/modules/wafv2_resources.py
plugins/modules/wafv2_resources_info.py
plugins/modules/wafv2_rule_group.py
plugins/modules/wafv2_rule_group_info.py
plugins/modules/wafv2_web_acl.py
plugins/modules/wafv2_web_acl_info.py
scripts/inventory/ec2.py
tests/unit/compat/builtins.py
tests/unit/plugins/modules/test_aws_acm.py
tests/unit/plugins/modules/test_aws_direct_connect_confirm_connection.py
tests/unit/plugins/modules/test_aws_direct_connect_connection.py
tests/unit/plugins/modules/test_aws_direct_connect_link_aggregation_group.py
tests/unit/plugins/modules/test_aws_direct_connect_virtual_interface.py
tests/unit/plugins/modules/test_data_pipeline.py
tests/unit/plugins/modules/test_ec2_vpc_vpn.py
tests/unit/plugins/modules/test_lambda.py
ADDITIONAL INFORMATION

Reviewed-by: Markus Bergholz <git@osuv.de>
Reviewed-by: Alina Buzachis <None>
  • Loading branch information
ansible-zuul[bot] authored Jul 9, 2021
2 parents bdba2b7 + fe960ac commit 2463775
Show file tree
Hide file tree
Showing 23 changed files with 91 additions and 65 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/629-imports-cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- various community.aws modules - remove unused imports (https://github.com/ansible-collections/community.aws/pull/629)
1 change: 0 additions & 1 deletion plugins/modules/ec2_vpc_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@

import datetime
import json
import time
import traceback

try:
Expand Down
2 changes: 0 additions & 2 deletions plugins/modules/ec2_vpc_endpoint_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@
vpc_id: "vpc-1111ffff"
'''

import json

try:
import botocore
except ImportError:
Expand Down
4 changes: 1 addition & 3 deletions plugins/modules/ec2_vpc_peering_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,6 @@
type: list
'''

import json

try:
import botocore
except ImportError:
Expand All @@ -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


Expand Down
7 changes: 1 addition & 6 deletions plugins/modules/kinesis_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions plugins/modules/wafv2_ip_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 3 additions & 2 deletions plugins/modules/wafv2_ip_set_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions plugins/modules/wafv2_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 4 additions & 3 deletions plugins/modules/wafv2_resources_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 8 additions & 3 deletions plugins/modules/wafv2_rule_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
7 changes: 4 additions & 3 deletions plugins/modules/wafv2_rule_group_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 8 additions & 3 deletions plugins/modules/wafv2_web_acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
7 changes: 4 additions & 3 deletions plugins/modules/wafv2_web_acl_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
23 changes: 12 additions & 11 deletions scripts/inventory/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/compat/builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 5 additions & 2 deletions tests/unit/plugins/modules/test_aws_acm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
11 changes: 7 additions & 4 deletions tests/unit/plugins/modules/test_data_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
8 changes: 5 additions & 3 deletions tests/unit/plugins/modules/test_ec2_vpc_vpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 2463775

Please sign in to comment.