From 9f71073d37e9131bdd3cc3d69115e7479ac54db0 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Wed, 30 Dec 2020 10:37:23 +0100 Subject: [PATCH] Remove ansible.netcommon dependency. (#1561) --- .../remove-ansible.netcommon-dependency.yml | 4 +++ galaxy.yml | 1 - .../modules/net_tools/nios/nios_network.py | 27 ++++++++++++++++++- tests/requirements.yml | 2 -- tests/utils/shippable/shippable.sh | 1 - 5 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 changelogs/fragments/remove-ansible.netcommon-dependency.yml diff --git a/changelogs/fragments/remove-ansible.netcommon-dependency.yml b/changelogs/fragments/remove-ansible.netcommon-dependency.yml new file mode 100644 index 0000000000..b91cfa54fd --- /dev/null +++ b/changelogs/fragments/remove-ansible.netcommon-dependency.yml @@ -0,0 +1,4 @@ +major_changes: +- "The community.general collection no longer depends on the ansible.netcommon collection (https://github.com/ansible-collections/community.general/pull/1561)." +minor_changes: +- "nios_network - no longer requires the ansible.netcommon collection (https://github.com/ansible-collections/community.general/pull/1561)." diff --git a/galaxy.yml b/galaxy.yml index 9f952a741b..ee7c9d51e7 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -9,7 +9,6 @@ license_file: COPYING tags: [community] # NOTE: No more dependencies can be added to this list dependencies: - ansible.netcommon: '>=1.0.0' community.kubernetes: '>=1.0.0' repository: https://github.com/ansible-collections/community.general documentation: https://docs.ansible.com/ansible/latest/collections/community/general/ diff --git a/plugins/modules/net_tools/nios/nios_network.py b/plugins/modules/net_tools/nios/nios_network.py index 54b8dfb18b..0a87356627 100644 --- a/plugins/modules/net_tools/nios/nios_network.py +++ b/plugins/modules/net_tools/nios/nios_network.py @@ -173,14 +173,39 @@ EXAMPLES = ''' RETURN = ''' # ''' +import socket + from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.six import iteritems from ansible_collections.community.general.plugins.module_utils.net_tools.nios.api import WapiModule -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import validate_ip_address, validate_ip_v6_address from ansible_collections.community.general.plugins.module_utils.net_tools.nios.api import NIOS_IPV4_NETWORK, NIOS_IPV6_NETWORK from ansible_collections.community.general.plugins.module_utils.net_tools.nios.api import NIOS_IPV4_NETWORK_CONTAINER, NIOS_IPV6_NETWORK_CONTAINER +# The following function validate_ip_address has been taken from +# https://github.com/ansible-collections/ansible.netcommon/blob/20124ecbb420daa0f5bb9cdaa865a952657aa0e7/plugins/module_utils/network/common/utils.py#L496 +# The code there is licensed under BSD 2-clause. +# Copyright (c) 2016 Red Hat Inc. +def validate_ip_address(address): + try: + socket.inet_aton(address) + except socket.error: + return False + return address.count(".") == 3 + + +# The following function validate_ip_v6_address has been taken from +# https://github.com/ansible-collections/ansible.netcommon/blob/20124ecbb420daa0f5bb9cdaa865a952657aa0e7/plugins/module_utils/network/common/utils.py#L504 +# The code there is licensed under BSD 2-clause. +# Copyright (c) 2016 Red Hat Inc. +def validate_ip_v6_address(address): + try: + socket.inet_pton(socket.AF_INET6, address) + except socket.error: + return False + return True + + def options(module): ''' Transforms the module argument into a valid WAPI struct This function will transform the options argument into a structure that diff --git a/tests/requirements.yml b/tests/requirements.yml index 74b10a453c..492a1f698c 100644 --- a/tests/requirements.yml +++ b/tests/requirements.yml @@ -1,9 +1,7 @@ integration_tests_dependencies: -- ansible.netcommon - ansible.posix - community.crypto - community.kubernetes unit_tests_dependencies: -- ansible.netcommon - community.internal_test_tools - community.kubernetes diff --git a/tests/utils/shippable/shippable.sh b/tests/utils/shippable/shippable.sh index 957ac67de5..1b966ec0fc 100755 --- a/tests/utils/shippable/shippable.sh +++ b/tests/utils/shippable/shippable.sh @@ -74,7 +74,6 @@ else fi # START: HACK install dependencies -retry ansible-galaxy -vvv collection install ansible.netcommon retry ansible-galaxy -vvv collection install community.kubernetes if [ "${script}" != "sanity" ] || [ "${test}" == "sanity/extra" ]; then