From eb6796dac2babd8acb2a1b92a5e09e44fa12c662 Mon Sep 17 00:00:00 2001 From: Sagar Paul Date: Wed, 27 Mar 2024 10:56:03 +0530 Subject: [PATCH] py27 compats no longer needed (#1045) * py27 compats no longer needed * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix ci * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- tests/unit/compat/__init__.py | 0 tests/unit/compat/mock.py | 28 --- tests/unit/compat/unittest.py | 41 --- tests/unit/mock/path.py | 9 +- tests/unit/mock/procenv.py | 10 +- .../network/ios/test_ios_acl_interfaces.py | 3 +- .../unit/modules/network/ios/test_ios_acls.py | 3 +- .../modules/network/ios/test_ios_banner.py | 8 +- .../ios/test_ios_bgp_address_family.py | 65 +++-- .../network/ios/test_ios_bgp_global.py | 3 +- .../modules/network/ios/test_ios_command.py | 19 +- .../modules/network/ios/test_ios_config.py | 43 +++- .../modules/network/ios/test_ios_evpn_evi.py | 3 +- .../network/ios/test_ios_evpn_global.py | 3 +- .../modules/network/ios/test_ios_facts.py | 12 +- .../modules/network/ios/test_ios_hostname.py | 3 +- .../network/ios/test_ios_interfaces.py | 30 ++- .../network/ios/test_ios_l2_interfaces.py | 53 +++- .../network/ios/test_ios_l3_interfaces.py | 3 +- .../unit/modules/network/ios/test_ios_lacp.py | 3 +- .../network/ios/test_ios_lacp_interfaces.py | 39 ++- .../network/ios/test_ios_lag_interfaces.py | 45 +++- .../network/ios/test_ios_lldp_global.py | 10 +- .../network/ios/test_ios_lldp_inteface.py | 8 +- .../network/ios/test_ios_logging_global.py | 60 ++++- .../unit/modules/network/ios/test_ios_ntp.py | 2 +- .../network/ios/test_ios_ntp_global.py | 107 ++++++-- .../network/ios/test_ios_ospf_interfaces.py | 3 +- .../modules/network/ios/test_ios_ospfv2.py | 81 ++++-- .../modules/network/ios/test_ios_ospfv3.py | 32 ++- .../unit/modules/network/ios/test_ios_ping.py | 7 +- .../network/ios/test_ios_prefix_lists.py | 149 +++++++++-- .../network/ios/test_ios_route_maps.py | 46 +++- .../modules/network/ios/test_ios_service.py | 3 +- .../network/ios/test_ios_snmp_server.py | 238 ++++++++++++++---- .../network/ios/test_ios_static_routes.py | 46 +++- .../modules/network/ios/test_ios_system.py | 14 +- .../unit/modules/network/ios/test_ios_user.py | 21 +- .../modules/network/ios/test_ios_vlans.py | 3 +- .../unit/modules/network/ios/test_ios_vrf.py | 52 +++- .../network/ios/test_ios_vxlan_vtep.py | 3 +- tests/unit/modules/utils.py | 8 +- tests/unit/plugins/cliconf/test_ios.py | 9 +- 43 files changed, 983 insertions(+), 345 deletions(-) delete mode 100644 tests/unit/compat/__init__.py delete mode 100644 tests/unit/compat/mock.py delete mode 100644 tests/unit/compat/unittest.py diff --git a/tests/unit/compat/__init__.py b/tests/unit/compat/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/unit/compat/mock.py b/tests/unit/compat/mock.py deleted file mode 100644 index e25e8381b..000000000 --- a/tests/unit/compat/mock.py +++ /dev/null @@ -1,28 +0,0 @@ -# pylint: skip-file -# (c) 2014, Toshio Kuratomi -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . - -# Make coding more python3-ish -from __future__ import absolute_import, division, print_function - - -__metaclass__ = type - -""" -Compat module for Python3.x's unittest.mock module -""" -from unittest.mock import * diff --git a/tests/unit/compat/unittest.py b/tests/unit/compat/unittest.py deleted file mode 100644 index df4266ec9..000000000 --- a/tests/unit/compat/unittest.py +++ /dev/null @@ -1,41 +0,0 @@ -# (c) 2014, Toshio Kuratomi -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . - -# Make coding more python3-ish -from __future__ import absolute_import, division, print_function - - -__metaclass__ = type - -""" -Compat module for Python2.7's unittest module -""" - -import sys - - -# Allow wildcard import because we really do want to import all of -# unittests's symbols into this compat shim -# pylint: disable=wildcard-import,unused-wildcard-import -if sys.version_info < (2, 7): - try: - # Need unittest2 on python2.6 - from unittest2 import * - except ImportError: - print("You need unittest2 installed on python2.6.x to run tests") -else: - from unittest import * diff --git a/tests/unit/mock/path.py b/tests/unit/mock/path.py index ce2eb1fe0..7d287a5fb 100644 --- a/tests/unit/mock/path.py +++ b/tests/unit/mock/path.py @@ -2,9 +2,12 @@ __metaclass__ = type -from ansible.utils.path import unfrackpath +from unittest.mock import MagicMock -from ansible_collections.cisco.ios.tests.unit.compat.mock import MagicMock +from ansible.utils.path import unfrackpath -mock_unfrackpath_noop = MagicMock(spec_set=unfrackpath, side_effect=lambda x, *args, **kwargs: x) +mock_unfrackpath_noop = MagicMock( + spec_set=unfrackpath, + side_effect=lambda x, *args, **kwargs: x, +) diff --git a/tests/unit/mock/procenv.py b/tests/unit/mock/procenv.py index 111c319c2..e6e09464b 100644 --- a/tests/unit/mock/procenv.py +++ b/tests/unit/mock/procenv.py @@ -27,12 +27,11 @@ from contextlib import contextmanager from io import BytesIO, StringIO +from unittest import TestCase from ansible.module_utils._text import to_bytes from ansible.module_utils.six import PY3 -from ansible_collections.cisco.ios.tests.unit.compat import unittest - @contextmanager def swap_stdin_and_argv(stdin_data="", argv_data=tuple()): @@ -78,10 +77,13 @@ def swap_stdout(): sys.stdout = old_stdout -class ModuleTestCase(unittest.TestCase): +class ModuleTestCase(TestCase): def setUp(self, module_args=None): if module_args is None: - module_args = {"_ansible_remote_tmp": "/tmp", "_ansible_keep_remote_files": False} + module_args = { + "_ansible_remote_tmp": "/tmp", + "_ansible_keep_remote_files": False, + } args = json.dumps(dict(ANSIBLE_MODULE_ARGS=module_args)) diff --git a/tests/unit/modules/network/ios/test_ios_acl_interfaces.py b/tests/unit/modules/network/ios/test_ios_acl_interfaces.py index 6bc99691c..3c8567797 100644 --- a/tests/unit/modules/network/ios/test_ios_acl_interfaces.py +++ b/tests/unit/modules/network/ios/test_ios_acl_interfaces.py @@ -7,11 +7,10 @@ __metaclass__ = type - from textwrap import dedent +from unittest.mock import patch from ansible_collections.cisco.ios.plugins.modules import ios_acl_interfaces -from ansible_collections.cisco.ios.tests.unit.compat.mock import patch from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args from .ios_module import TestIosModule diff --git a/tests/unit/modules/network/ios/test_ios_acls.py b/tests/unit/modules/network/ios/test_ios_acls.py index 5be581a7a..36d96365a 100644 --- a/tests/unit/modules/network/ios/test_ios_acls.py +++ b/tests/unit/modules/network/ios/test_ios_acls.py @@ -7,11 +7,10 @@ __metaclass__ = type - from textwrap import dedent +from unittest.mock import patch from ansible_collections.cisco.ios.plugins.modules import ios_acls -from ansible_collections.cisco.ios.tests.unit.compat.mock import patch from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args from .ios_module import TestIosModule diff --git a/tests/unit/modules/network/ios/test_ios_banner.py b/tests/unit/modules/network/ios/test_ios_banner.py index 85e2736f0..b114d1817 100644 --- a/tests/unit/modules/network/ios/test_ios_banner.py +++ b/tests/unit/modules/network/ios/test_ios_banner.py @@ -18,9 +18,9 @@ __metaclass__ = type +from unittest.mock import patch from ansible_collections.cisco.ios.plugins.modules import ios_banner -from ansible_collections.cisco.ios.tests.unit.compat.mock import patch from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args from .ios_module import TestIosModule, load_fixture @@ -77,7 +77,11 @@ def test_ios_banner_idemp(self): def test_ios_banner_create_delimiter(self): for banner_type in ("login", "motd", "exec", "incoming", "slip-ppp"): set_module_args( - dict(banner=banner_type, text="test\nbanner\nstring", multiline_delimiter="c"), + dict( + banner=banner_type, + text="test\nbanner\nstring", + multiline_delimiter="c", + ), ) commands = ["banner {0} c\ntest\nbanner\nstring\nc".format(banner_type)] self.execute_module(changed=True, commands=commands) diff --git a/tests/unit/modules/network/ios/test_ios_bgp_address_family.py b/tests/unit/modules/network/ios/test_ios_bgp_address_family.py index 259da5ece..ea5d279f4 100644 --- a/tests/unit/modules/network/ios/test_ios_bgp_address_family.py +++ b/tests/unit/modules/network/ios/test_ios_bgp_address_family.py @@ -7,11 +7,10 @@ __metaclass__ = type - from textwrap import dedent +from unittest.mock import patch from ansible_collections.cisco.ios.plugins.modules import ios_bgp_address_family -from ansible_collections.cisco.ios.tests.unit.compat.mock import patch from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args from .ios_module import TestIosModule @@ -119,8 +118,12 @@ def test_ios_bgp_address_family_merged(self): dict( neighbor_address="198.51.100.1", remote_as="65.11", - route_maps=[dict(name="test-route-out", out="true")], - prefix_lists=[dict(name="AS65100-PREFIX-OUT", out="true")], + route_maps=[ + dict(name="test-route-out", out="true"), + ], + prefix_lists=[ + dict(name="AS65100-PREFIX-OUT", out="true"), + ], ), ], ), @@ -128,7 +131,9 @@ def test_ios_bgp_address_family_merged(self): afi="nsap", bgp=dict(aggregate_timer=20, dmzlink_bw=True, scan_time=10), default_metric=10, - networks=[dict(address="192.0.1.1", route_map="test_route")], + networks=[ + dict(address="192.0.1.1", route_map="test_route"), + ], ), ], ), @@ -317,18 +322,25 @@ def test_ios_bgp_address_family_merged_idempotent(self): "send": { "cost_community": { "id": 100, - "poi": {"igp_cost": True, "transitive": True}, + "poi": { + "igp_cost": True, + "transitive": True, + }, }, }, }, "local_as": {"number": "10.64760", "set": True}, "neighbor_address": "198.51.100.1", "nexthop_self": {"all": True}, - "prefix_lists": [{"name": "AS65100-PREFIX-OUT", "out": True}], + "prefix_lists": [ + {"name": "AS65100-PREFIX-OUT", "out": True}, + ], "remote_as": 10, "route_maps": [{"name": "test-out", "out": True}], "route_server_client": True, - "slow_peer_options": {"detection": {"threshold": 150}}, + "slow_peer_options": { + "detection": {"threshold": 150}, + }, }, ], "networks": [ @@ -426,7 +438,9 @@ def test_ios_bgp_address_family_replaced(self): address="198.51.110.1", activate=True, remote_as=200, - route_maps=[dict(name="test-replaced-route", out=True)], + route_maps=[ + dict(name="test-replaced-route", out=True), + ], ), ], ), @@ -534,12 +548,17 @@ def test_ios_bgp_address_family_replaced_idempotent(self): send=dict( cost_community=dict( id=100, - poi=dict(igp_cost=True, transitive=True), + poi=dict( + igp_cost=True, + transitive=True, + ), ), ), ), nexthop_self=dict(all=True), - prefix_lists=[dict(name="AS65100-PREFIX-OUT", out="true")], + prefix_lists=[ + dict(name="AS65100-PREFIX-OUT", out="true"), + ], slow_peer=[dict(detection=dict(threshold=150))], remote_as=10, local_as=dict(number=20), @@ -709,12 +728,17 @@ def test_ios_bgp_address_family_overridden_idempotent(self): send=dict( cost_community=dict( id=100, - poi=dict(igp_cost=True, transitive=True), + poi=dict( + igp_cost=True, + transitive=True, + ), ), ), ), nexthop_self=dict(all=True), - prefix_lists=[dict(name="AS65100-PREFIX-OUT", out="true")], + prefix_lists=[ + dict(name="AS65100-PREFIX-OUT", out="true"), + ], slow_peer=[dict(detection=dict(threshold=150))], remote_as=10, local_as=dict(number=20), @@ -937,7 +961,10 @@ def test_ios_bgp_address_family_rendered(self): send=dict( cost_community=dict( id=100, - poi=dict(igp_cost=True, transitive=True), + poi=dict( + igp_cost=True, + transitive=True, + ), ), ), ), @@ -1152,7 +1179,11 @@ def test_ios_bgp_address_family_parsed(self): }, }, "networks": [ - {"address": "198.51.110.10", "mask": "255.255.255.255", "backdoor": True}, + { + "address": "198.51.110.10", + "mask": "255.255.255.255", + "backdoor": True, + }, ], "aggregate_addresses": [ { @@ -1177,7 +1208,9 @@ def test_ios_bgp_address_family_parsed(self): }, }, "route_server_client": True, - "prefix_lists": [{"name": "AS65100-PREFIX-OUT", "out": True}], + "prefix_lists": [ + {"name": "AS65100-PREFIX-OUT", "out": True}, + ], "slow_peer_options": {"detection": {"threshold": 150}}, "route_maps": [{"name": "test-out", "out": True}], }, diff --git a/tests/unit/modules/network/ios/test_ios_bgp_global.py b/tests/unit/modules/network/ios/test_ios_bgp_global.py index 6be8df1d1..16a4c9b5c 100644 --- a/tests/unit/modules/network/ios/test_ios_bgp_global.py +++ b/tests/unit/modules/network/ios/test_ios_bgp_global.py @@ -7,11 +7,10 @@ __metaclass__ = type - from textwrap import dedent +from unittest.mock import patch from ansible_collections.cisco.ios.plugins.modules import ios_bgp_global -from ansible_collections.cisco.ios.tests.unit.compat.mock import patch from ansible_collections.cisco.ios.tests.unit.modules.utils import AnsibleFailJson, set_module_args from .ios_module import TestIosModule diff --git a/tests/unit/modules/network/ios/test_ios_command.py b/tests/unit/modules/network/ios/test_ios_command.py index 42fee4028..69788ef3e 100644 --- a/tests/unit/modules/network/ios/test_ios_command.py +++ b/tests/unit/modules/network/ios/test_ios_command.py @@ -20,11 +20,11 @@ __metaclass__ = type - import json +from unittest.mock import patch + from ansible_collections.cisco.ios.plugins.modules import ios_command -from ansible_collections.cisco.ios.tests.unit.compat.mock import patch from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args from .ios_module import TestIosModule, load_fixture @@ -97,17 +97,26 @@ def test_ios_command_retries_0(self): self.assertEqual(self.run_commands.call_count, 1) def test_ios_command_match_any(self): - wait_for = ['result[0] contains "Cisco IOS"', 'result[0] contains "test string"'] + wait_for = [ + 'result[0] contains "Cisco IOS"', + 'result[0] contains "test string"', + ] set_module_args(dict(commands=["show version"], wait_for=wait_for, match="any")) self.execute_module() def test_ios_command_match_all(self): - wait_for = ['result[0] contains "Cisco IOS"', 'result[0] contains "IOSv Software"'] + wait_for = [ + 'result[0] contains "Cisco IOS"', + 'result[0] contains "IOSv Software"', + ] set_module_args(dict(commands=["show version"], wait_for=wait_for, match="all")) self.execute_module() def test_ios_command_match_all_failure(self): - wait_for = ['result[0] contains "Cisco IOS"', 'result[0] contains "test string"'] + wait_for = [ + 'result[0] contains "Cisco IOS"', + 'result[0] contains "test string"', + ] commands = ["show version", "show version"] set_module_args(dict(commands=commands, wait_for=wait_for, match="all")) self.execute_module(failed=True) diff --git a/tests/unit/modules/network/ios/test_ios_config.py b/tests/unit/modules/network/ios/test_ios_config.py index 778bb1ccb..7fa3931d0 100644 --- a/tests/unit/modules/network/ios/test_ios_config.py +++ b/tests/unit/modules/network/ios/test_ios_config.py @@ -21,10 +21,10 @@ __metaclass__ = type +from unittest.mock import MagicMock, patch from ansible_collections.cisco.ios.plugins.cliconf.ios import Cliconf from ansible_collections.cisco.ios.plugins.modules import ios_config -from ansible_collections.cisco.ios.tests.unit.compat.mock import MagicMock, patch from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args from .ios_module import TestIosModule, load_fixture @@ -123,7 +123,10 @@ def test_ios_config_lines_wo_parents(self): lines = ["hostname foo"] set_module_args(dict(lines=lines)) self.conn.get_diff = MagicMock( - return_value=self.cliconf_obj.get_diff("\n".join(lines), self.running_config), + return_value=self.cliconf_obj.get_diff( + "\n".join(lines), + self.running_config, + ), ) commands = ["hostname foo"] self.execute_module(changed=True, commands=commands) @@ -137,7 +140,10 @@ def test_ios_config_lines_w_parents(self): candidate_config = ios_config.get_candidate_config(module) self.conn.get_diff = MagicMock( - return_value=self.cliconf_obj.get_diff(candidate_config, self.running_config), + return_value=self.cliconf_obj.get_diff( + candidate_config, + self.running_config, + ), ) commands = ["interface GigabitEthernet0/0", "shutdown"] @@ -147,7 +153,10 @@ def test_ios_config_before(self): lines = ["hostname foo"] set_module_args(dict(lines=lines, before=["test1", "test2"])) self.conn.get_diff = MagicMock( - return_value=self.cliconf_obj.get_diff("\n".join(lines), self.running_config), + return_value=self.cliconf_obj.get_diff( + "\n".join(lines), + self.running_config, + ), ) commands = ["test1", "test2", "hostname foo"] self.execute_module(changed=True, commands=commands, sort=False) @@ -156,16 +165,24 @@ def test_ios_config_after(self): lines = ["hostname foo"] set_module_args(dict(lines=lines, after=["test1", "test2"])) self.conn.get_diff = MagicMock( - return_value=self.cliconf_obj.get_diff("\n".join(lines), self.running_config), + return_value=self.cliconf_obj.get_diff( + "\n".join(lines), + self.running_config, + ), ) commands = ["hostname foo", "test1", "test2"] self.execute_module(changed=True, commands=commands, sort=False) def test_ios_config_before_after_no_change(self): lines = ["hostname router"] - set_module_args(dict(lines=lines, before=["test1", "test2"], after=["test3", "test4"])) + set_module_args( + dict(lines=lines, before=["test1", "test2"], after=["test3", "test4"]), + ) self.conn.get_diff = MagicMock( - return_value=self.cliconf_obj.get_diff("\n".join(lines), self.running_config), + return_value=self.cliconf_obj.get_diff( + "\n".join(lines), + self.running_config, + ), ) self.execute_module() @@ -242,7 +259,11 @@ def test_ios_config_match_none2(self): self.execute_module(changed=True, commands=commands, sort=False) def test_ios_config_match_strict(self): - lines = ["ip address 1.2.3.4 255.255.255.0", "description test string", "shutdown"] + lines = [ + "ip address 1.2.3.4 255.255.255.0", + "description test string", + "shutdown", + ] parents = ["interface GigabitEthernet0/0"] set_module_args(dict(lines=lines, parents=parents, match="strict")) @@ -262,7 +283,11 @@ def test_ios_config_match_strict(self): self.execute_module(changed=True, commands=commands, sort=False) def test_ios_config_match_exact(self): - lines = ["ip address 1.2.3.4 255.255.255.0", "description test string", "shutdown"] + lines = [ + "ip address 1.2.3.4 255.255.255.0", + "description test string", + "shutdown", + ] parents = ["interface GigabitEthernet0/0"] set_module_args(dict(lines=lines, parents=parents, match="exact")) diff --git a/tests/unit/modules/network/ios/test_ios_evpn_evi.py b/tests/unit/modules/network/ios/test_ios_evpn_evi.py index 94008b0aa..e1178a21f 100644 --- a/tests/unit/modules/network/ios/test_ios_evpn_evi.py +++ b/tests/unit/modules/network/ios/test_ios_evpn_evi.py @@ -7,11 +7,10 @@ __metaclass__ = type - from textwrap import dedent +from unittest.mock import patch from ansible_collections.cisco.ios.plugins.modules import ios_evpn_evi -from ansible_collections.cisco.ios.tests.unit.compat.mock import patch from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args from .ios_module import TestIosModule diff --git a/tests/unit/modules/network/ios/test_ios_evpn_global.py b/tests/unit/modules/network/ios/test_ios_evpn_global.py index d3bfa1585..76f467411 100644 --- a/tests/unit/modules/network/ios/test_ios_evpn_global.py +++ b/tests/unit/modules/network/ios/test_ios_evpn_global.py @@ -7,11 +7,10 @@ __metaclass__ = type - from textwrap import dedent +from unittest.mock import patch from ansible_collections.cisco.ios.plugins.modules import ios_evpn_global -from ansible_collections.cisco.ios.tests.unit.compat.mock import patch from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args from .ios_module import TestIosModule diff --git a/tests/unit/modules/network/ios/test_ios_facts.py b/tests/unit/modules/network/ios/test_ios_facts.py index c951b58b2..4878d4ad7 100644 --- a/tests/unit/modules/network/ios/test_ios_facts.py +++ b/tests/unit/modules/network/ios/test_ios_facts.py @@ -19,11 +19,11 @@ __metaclass__ = type +from unittest.mock import patch from ansible.module_utils.six import assertCountEqual from ansible_collections.cisco.ios.plugins.modules import ios_facts -from ansible_collections.cisco.ios.tests.unit.compat.mock import patch from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args from .ios_module import TestIosModule, load_fixture @@ -80,8 +80,14 @@ def test_ios_facts_stacked(self): set_module_args(dict(gather_subset="default")) result = self.execute_module() self.assertEqual(result["ansible_facts"]["ansible_net_model"], "WS-C3750-24TS") - self.assertEqual(result["ansible_facts"]["ansible_net_serialnum"], "CAT0726R0ZU") - self.assertEqual(result["ansible_facts"]["ansible_net_operatingmode"], "autonomous") + self.assertEqual( + result["ansible_facts"]["ansible_net_serialnum"], + "CAT0726R0ZU", + ) + self.assertEqual( + result["ansible_facts"]["ansible_net_operatingmode"], + "autonomous", + ) self.assertEqual( result["ansible_facts"]["ansible_net_stacked_models"], ["WS-C3750-24TS-E", "WS-C3750-24TS-E", "WS-C3750G-12S-E"], diff --git a/tests/unit/modules/network/ios/test_ios_hostname.py b/tests/unit/modules/network/ios/test_ios_hostname.py index 6b16bddf0..359cf562a 100644 --- a/tests/unit/modules/network/ios/test_ios_hostname.py +++ b/tests/unit/modules/network/ios/test_ios_hostname.py @@ -7,11 +7,10 @@ __metaclass__ = type - from textwrap import dedent +from unittest.mock import patch from ansible_collections.cisco.ios.plugins.modules import ios_hostname -from ansible_collections.cisco.ios.tests.unit.compat.mock import patch from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args from .ios_module import TestIosModule diff --git a/tests/unit/modules/network/ios/test_ios_interfaces.py b/tests/unit/modules/network/ios/test_ios_interfaces.py index caac40ccb..63ee2341b 100644 --- a/tests/unit/modules/network/ios/test_ios_interfaces.py +++ b/tests/unit/modules/network/ios/test_ios_interfaces.py @@ -7,11 +7,10 @@ __metaclass__ = type - from textwrap import dedent +from unittest.mock import patch from ansible_collections.cisco.ios.plugins.modules import ios_interfaces -from ansible_collections.cisco.ios.tests.unit.compat.mock import patch from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args from .ios_module import TestIosModule @@ -150,7 +149,10 @@ def test_ios_interfaces_merged_idempotent(self): set_module_args( { "config": [ - {"description": "Ansible UT interface 1", "name": "GigabitEthernet1"}, + { + "description": "Ansible UT interface 1", + "name": "GigabitEthernet1", + }, { "description": "Ansible UT interface 2", "name": "GigabitEthernet0/1", @@ -204,7 +206,10 @@ def test_ios_interfaces_replaced(self): set_module_args( { "config": [ - {"description": "Ansible UT interface 1", "name": "GigabitEthernet1"}, + { + "description": "Ansible UT interface 1", + "name": "GigabitEthernet1", + }, {"name": "GigabitEthernet0/1", "speed": 1200, "mtu": 1800}, { "name": "GigabitEthernet6", @@ -267,7 +272,10 @@ def test_ios_interfaces_replaced_idempotent(self): set_module_args( { "config": [ - {"description": "Ansible UT interface 1", "name": "GigabitEthernet1"}, + { + "description": "Ansible UT interface 1", + "name": "GigabitEthernet1", + }, { "description": "Ansible UT interface 2", "name": "GigabitEthernet0/1", @@ -570,14 +578,22 @@ def test_ios_interfaces_parsed(self): "mtu": 1500, "enabled": True, }, - {"name": "GigabitEthernet1", "description": "Ansible UT interface 1", "enabled": True}, + { + "name": "GigabitEthernet1", + "description": "Ansible UT interface 1", + "enabled": True, + }, { "name": "GigabitEthernet3", "description": "Ansible UT interface 3", "enabled": False, "duplex": "auto", }, - {"name": "GigabitEthernet4", "description": "Ansible UT interface 4", "enabled": False}, + { + "name": "GigabitEthernet4", + "description": "Ansible UT interface 4", + "enabled": False, + }, { "name": "GigabitEthernet5", "description": "Ansible UT interface 5", diff --git a/tests/unit/modules/network/ios/test_ios_l2_interfaces.py b/tests/unit/modules/network/ios/test_ios_l2_interfaces.py index d9ec2b189..e84846aeb 100644 --- a/tests/unit/modules/network/ios/test_ios_l2_interfaces.py +++ b/tests/unit/modules/network/ios/test_ios_l2_interfaces.py @@ -7,11 +7,10 @@ __metaclass__ = type - from textwrap import dedent +from unittest.mock import patch from ansible_collections.cisco.ios.plugins.modules import ios_l2_interfaces -from ansible_collections.cisco.ios.tests.unit.compat.mock import patch from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args from .ios_module import TestIosModule @@ -136,7 +135,11 @@ def test_ios_l2_interfaces_merged_idempotent(self): set_module_args( dict( config=[ - dict(access=dict(vlan=10), mode="access", name="GigabitEthernet0/1"), + dict( + access=dict(vlan=10), + mode="access", + name="GigabitEthernet0/1", + ), dict( mode="trunk", name="GigabitEthernet0/2", @@ -270,7 +273,11 @@ def test_ios_l2_interfaces_replaced_idempotent(self): set_module_args( dict( config=[ - dict(access=dict(vlan=10), mode="access", name="GigabitEthernet0/1"), + dict( + access=dict(vlan=10), + mode="access", + name="GigabitEthernet0/1", + ), dict( mode="trunk", name="GigabitEthernet0/2", @@ -281,7 +288,11 @@ def test_ios_l2_interfaces_replaced_idempotent(self): pruning_vlans=["10", "20"], ), ), - dict(access=dict(vlan=20), mode="access", name="TwoGigabitEthernet1/0/1"), + dict( + access=dict(vlan=20), + mode="access", + name="TwoGigabitEthernet1/0/1", + ), dict( mode="trunk", name="GigabitEthernet0/3", @@ -416,7 +427,11 @@ def test_ios_l2_interfaces_overridden_idempotent(self): set_module_args( dict( config=[ - dict(access=dict(vlan=10), mode="access", name="GigabitEthernet0/1"), + dict( + access=dict(vlan=10), + mode="access", + name="GigabitEthernet0/1", + ), dict( mode="trunk", name="GigabitEthernet0/2", @@ -427,7 +442,11 @@ def test_ios_l2_interfaces_overridden_idempotent(self): pruning_vlans=["10", "20"], ), ), - dict(access=dict(vlan=20), mode="access", name="TwoGigabitEthernet1/0/1"), + dict( + access=dict(vlan=20), + mode="access", + name="TwoGigabitEthernet1/0/1", + ), dict( mode="trunk", name="GigabitEthernet0/3", @@ -592,7 +611,11 @@ def test_ios_l2_interfaces_parsed(self): }, "mode": "trunk", }, - {"name": "TwoGigabitEthernet1/0/1", "mode": "access", "access": {"vlan": 20}}, + { + "name": "TwoGigabitEthernet1/0/1", + "mode": "access", + "access": {"vlan": 20}, + }, { "name": "GigabitEthernet0/3", "trunk": { @@ -695,7 +718,13 @@ def test_ios_l2_interfaces_merged_mode_change(self): ) set_module_args( dict( - config=[dict(access=dict(vlan=20), mode="trunk", name="TwoGigabitEthernet1/0/1")], + config=[ + dict( + access=dict(vlan=20), + mode="trunk", + name="TwoGigabitEthernet1/0/1", + ), + ], state="merged", ), ) @@ -731,7 +760,11 @@ def test_ios_l2_interfaces_fiveGibBit(self): set_module_args( dict( config=[ - dict(access=dict(vlan=20), mode="trunk", name="FiveGigabitEthernet1/0/1"), + dict( + access=dict(vlan=20), + mode="trunk", + name="FiveGigabitEthernet1/0/1", + ), dict( access=dict(vlan_name="vlan12"), mode="trunk", diff --git a/tests/unit/modules/network/ios/test_ios_l3_interfaces.py b/tests/unit/modules/network/ios/test_ios_l3_interfaces.py index 219191e80..3e3cc038b 100644 --- a/tests/unit/modules/network/ios/test_ios_l3_interfaces.py +++ b/tests/unit/modules/network/ios/test_ios_l3_interfaces.py @@ -7,11 +7,10 @@ __metaclass__ = type - from textwrap import dedent +from unittest.mock import patch from ansible_collections.cisco.ios.plugins.modules import ios_l3_interfaces -from ansible_collections.cisco.ios.tests.unit.compat.mock import patch from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args from .ios_module import TestIosModule diff --git a/tests/unit/modules/network/ios/test_ios_lacp.py b/tests/unit/modules/network/ios/test_ios_lacp.py index 6c56406e6..f4460162a 100644 --- a/tests/unit/modules/network/ios/test_ios_lacp.py +++ b/tests/unit/modules/network/ios/test_ios_lacp.py @@ -7,11 +7,10 @@ __metaclass__ = type - from textwrap import dedent +from unittest.mock import patch from ansible_collections.cisco.ios.plugins.modules import ios_lacp -from ansible_collections.cisco.ios.tests.unit.compat.mock import patch from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args from .ios_module import TestIosModule diff --git a/tests/unit/modules/network/ios/test_ios_lacp_interfaces.py b/tests/unit/modules/network/ios/test_ios_lacp_interfaces.py index f58aa9d65..817c6869c 100644 --- a/tests/unit/modules/network/ios/test_ios_lacp_interfaces.py +++ b/tests/unit/modules/network/ios/test_ios_lacp_interfaces.py @@ -7,11 +7,10 @@ __metaclass__ = type - from textwrap import dedent +from unittest.mock import patch from ansible_collections.cisco.ios.plugins.modules import ios_lacp_interfaces -from ansible_collections.cisco.ios.tests.unit.compat.mock import patch from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args from .ios_module import TestIosModule @@ -83,7 +82,11 @@ def test_ios_lacp_interface_merged(self): set_module_args( dict( config=[ - {"name": "Port-channel10", "fast_switchover": True, "max_bundle": 12}, + { + "name": "Port-channel10", + "fast_switchover": True, + "max_bundle": 12, + }, {"name": "Port-channel40", "max_bundle": 5}, {"name": "GigabitEthernet0/0"}, {"name": "GigabitEthernet0/1", "port_priority": 20}, @@ -121,7 +124,11 @@ def test_ios_lacp_interface_merged_idempotent(self): set_module_args( dict( config=[ - {"name": "Port-channel10", "fast_switchover": True, "max_bundle": 2}, + { + "name": "Port-channel10", + "fast_switchover": True, + "max_bundle": 2, + }, {"name": "Port-channel40", "max_bundle": 5}, {"name": "GigabitEthernet0/0"}, {"name": "GigabitEthernet0/1", "port_priority": 30}, @@ -150,7 +157,11 @@ def test_ios_lacp_interface_replaced(self): set_module_args( dict( config=[ - {"name": "Port-channel10", "fast_switchover": True, "max_bundle": 12}, + { + "name": "Port-channel10", + "fast_switchover": True, + "max_bundle": 12, + }, {"name": "Port-channel40", "max_bundle": 5}, {"name": "GigabitEthernet0/0"}, {"name": "GigabitEthernet0/1", "port_priority": 20}, @@ -188,7 +199,11 @@ def test_ios_lacp_interface_overridden(self): set_module_args( dict( config=[ - {"name": "Port-channel10", "fast_switchover": True, "max_bundle": 12}, + { + "name": "Port-channel10", + "fast_switchover": True, + "max_bundle": 12, + }, {"name": "Port-channel40", "max_bundle": 5}, {"name": "GigabitEthernet0/0"}, {"name": "GigabitEthernet0/1", "port_priority": 20}, @@ -226,7 +241,11 @@ def test_ios_lacp_interface_deleted(self): set_module_args( dict( config=[ - {"name": "Port-channel10", "fast_switchover": True, "max_bundle": 12}, + { + "name": "Port-channel10", + "fast_switchover": True, + "max_bundle": 12, + }, {"name": "Port-channel40", "max_bundle": 5}, {"name": "GigabitEthernet0/0"}, {"name": "GigabitEthernet0/1", "port_priority": 20}, @@ -287,7 +306,11 @@ def test_ios_lacp_interface_rendered(self): set_module_args( dict( config=[ - {"fast_switchover": True, "max_bundle": 2, "name": "Port-channel10"}, + { + "fast_switchover": True, + "max_bundle": 2, + "name": "Port-channel10", + }, {"max_bundle": 5, "name": "Port-channel40"}, {"name": "GigabitEthernet0/0"}, {"name": "GigabitEthernet0/1", "port_priority": 30}, diff --git a/tests/unit/modules/network/ios/test_ios_lag_interfaces.py b/tests/unit/modules/network/ios/test_ios_lag_interfaces.py index 1f97bef24..71d6ff933 100644 --- a/tests/unit/modules/network/ios/test_ios_lag_interfaces.py +++ b/tests/unit/modules/network/ios/test_ios_lag_interfaces.py @@ -7,11 +7,10 @@ __metaclass__ = type - from textwrap import dedent +from unittest.mock import patch from ansible_collections.cisco.ios.plugins.modules import ios_lag_interfaces -from ansible_collections.cisco.ios.tests.unit.compat.mock import patch from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args from .ios_module import TestIosModule @@ -73,7 +72,11 @@ def test_ios_lag_interfaces_merged(self): "members": [ {"member": "GigabitEthernet0/2", "mode": "active"}, {"member": "GigabitEthernet0/3", "mode": "passive"}, - {"link": 20, "member": "GigabitEthernet0/4", "mode": "active"}, + { + "link": 20, + "member": "GigabitEthernet0/4", + "mode": "active", + }, {"link": 22, "member": "GigabitEthernet0/5"}, ], "name": "Port-channel22", @@ -120,7 +123,11 @@ def test_ios_lag_interfaces_merged_idempotent(self): "members": [ {"member": "GigabitEthernet0/2", "mode": "active"}, {"member": "GigabitEthernet0/3", "mode": "active"}, - {"link": 20, "member": "GigabitEthernet0/4", "mode": "active"}, + { + "link": 20, + "member": "GigabitEthernet0/4", + "mode": "active", + }, {"link": 22, "member": "GigabitEthernet0/5"}, ], "name": "Port-channel22", @@ -164,7 +171,11 @@ def test_ios_lag_interfaces_replaced(self): "members": [ {"member": "GigabitEthernet0/1", "mode": "active"}, {"member": "GigabitEthernet0/3", "mode": "on"}, - {"link": 20, "member": "GigabitEthernet0/4", "mode": "active"}, + { + "link": 20, + "member": "GigabitEthernet0/4", + "mode": "active", + }, {"link": 22, "member": "GigabitEthernet0/5"}, ], "name": "Port-channel22", @@ -219,7 +230,11 @@ def test_ios_lag_interfaces_replaced_idempotent(self): "members": [ {"member": "GigabitEthernet0/2", "mode": "active"}, {"member": "GigabitEthernet0/3", "mode": "active"}, - {"link": 20, "member": "GigabitEthernet0/4", "mode": "active"}, + { + "link": 20, + "member": "GigabitEthernet0/4", + "mode": "active", + }, {"link": 22, "member": "GigabitEthernet0/5"}, ], "name": "Port-channel22", @@ -259,7 +274,11 @@ def test_ios_lag_interfaces_overridden(self): "members": [ {"member": "GigabitEthernet0/2", "mode": "active"}, {"member": "GigabitEthernet0/3", "mode": "active"}, - {"link": 20, "member": "GigabitEthernet0/4", "mode": "active"}, + { + "link": 20, + "member": "GigabitEthernet0/4", + "mode": "active", + }, {"link": 22, "member": "GigabitEthernet0/5"}, ], "name": "Port-channel22", @@ -314,7 +333,11 @@ def test_ios_lag_interfaces_overridden_idempotent(self): "members": [ {"member": "GigabitEthernet0/2", "mode": "active"}, {"member": "GigabitEthernet0/3", "mode": "active"}, - {"link": 20, "member": "GigabitEthernet0/4", "mode": "active"}, + { + "link": 20, + "member": "GigabitEthernet0/4", + "mode": "active", + }, {"link": 22, "member": "GigabitEthernet0/5"}, ], "name": "Port-channel22", @@ -459,7 +482,11 @@ def test_ios_lag_interfaces_rendered(self): "members": [ {"member": "GigabitEthernet0/2", "mode": "active"}, {"member": "GigabitEthernet0/3", "mode": "active"}, - {"link": 20, "member": "GigabitEthernet0/4", "mode": "active"}, + { + "link": 20, + "member": "GigabitEthernet0/4", + "mode": "active", + }, {"link": 22, "member": "GigabitEthernet0/5"}, ], "name": "Port-channel22", diff --git a/tests/unit/modules/network/ios/test_ios_lldp_global.py b/tests/unit/modules/network/ios/test_ios_lldp_global.py index 4c54ef5c9..2c5eb1c40 100644 --- a/tests/unit/modules/network/ios/test_ios_lldp_global.py +++ b/tests/unit/modules/network/ios/test_ios_lldp_global.py @@ -7,11 +7,10 @@ __metaclass__ = type - from textwrap import dedent +from unittest.mock import patch from ansible_collections.cisco.ios.plugins.modules import ios_lldp_global -from ansible_collections.cisco.ios.tests.unit.compat.mock import patch from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args from .ios_module import TestIosModule @@ -154,7 +153,12 @@ def test_ios_lldp_global_deleted(self): state="deleted", ), ) - commands = ["no lldp holdtime", "no lldp run", "no lldp timer", "no lldp reinit"] + commands = [ + "no lldp holdtime", + "no lldp run", + "no lldp timer", + "no lldp reinit", + ] result = self.execute_module(changed=True) self.assertEqual(result["commands"], commands) diff --git a/tests/unit/modules/network/ios/test_ios_lldp_inteface.py b/tests/unit/modules/network/ios/test_ios_lldp_inteface.py index a3dfe9706..04a25993a 100644 --- a/tests/unit/modules/network/ios/test_ios_lldp_inteface.py +++ b/tests/unit/modules/network/ios/test_ios_lldp_inteface.py @@ -7,11 +7,10 @@ __metaclass__ = type - from textwrap import dedent +from unittest.mock import patch from ansible_collections.cisco.ios.plugins.modules import ios_lldp_interfaces -from ansible_collections.cisco.ios.tests.unit.compat.mock import patch from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args from .ios_module import TestIosModule @@ -241,7 +240,10 @@ def test_ios_lldp_interfaces_deleted(self): ) set_module_args( dict( - config=[dict(name="GigabitEthernet0/2"), dict(name="GigabitEthernet0/1")], + config=[ + dict(name="GigabitEthernet0/2"), + dict(name="GigabitEthernet0/1"), + ], state="deleted", ), ) diff --git a/tests/unit/modules/network/ios/test_ios_logging_global.py b/tests/unit/modules/network/ios/test_ios_logging_global.py index c3024636a..f1b3eada3 100644 --- a/tests/unit/modules/network/ios/test_ios_logging_global.py +++ b/tests/unit/modules/network/ios/test_ios_logging_global.py @@ -7,11 +7,10 @@ __metaclass__ = type - from textwrap import dedent +from unittest.mock import patch from ansible_collections.cisco.ios.plugins.modules import ios_logging_global -from ansible_collections.cisco.ios.tests.unit.compat.mock import patch from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args from .ios_module import TestIosModule @@ -120,7 +119,10 @@ def test_ios_logging_global_merged_idempotent(self): reload=dict(severity="alerts"), server_arp=True, snmp_trap=["errors"], - source_interface=[dict(interface="GBit1/0"), dict(interface="CTunnel2")], + source_interface=[ + dict(interface="GBit1/0"), + dict(interface="CTunnel2"), + ], trap="errors", userinfo=True, ), @@ -250,7 +252,10 @@ def test_ios_logging_global_deleted_list(self): ], message_counter=["log", "debug"], snmp_trap=["errors"], - source_interface=[dict(interface="GBit1/0"), dict(interface="CTunnel2")], + source_interface=[ + dict(interface="GBit1/0"), + dict(interface="CTunnel2"), + ], ), ) deleted = [ @@ -317,7 +322,10 @@ def test_ios_logging_global_overridden(self): ], message_counter=["log", "debug"], snmp_trap=["errors"], - source_interface=[dict(interface="GBit1/0"), dict(interface="CTunnel2")], + source_interface=[ + dict(interface="GBit1/0"), + dict(interface="CTunnel2"), + ], ), ) overridden = [ @@ -402,9 +410,16 @@ def test_ios_logging_global_merged(self): ipv6="2001:0db8:85a3:0000:0000:8a2e:0370:7304", discriminator="msglog01 severity includes 5", ), - dict(ipv6="2001:0db8:85a3:0000:0000:8a2e:0370:7314", sequence_num_session=True), + dict( + ipv6="2001:0db8:85a3:0000:0000:8a2e:0370:7314", + sequence_num_session=True, + ), dict(ipv6="2001:0db8:85a3:0000:0000:8a2e:0370:7324", vrf="vpn1"), - dict(ipv6="2001:0db8:85a3:0000:0000:8a2e:0370:7334", stream=10, filtered=True), + dict( + ipv6="2001:0db8:85a3:0000:0000:8a2e:0370:7334", + stream=10, + filtered=True, + ), dict( ipv6="2001:0db8:85a3:0000:0000:8a2e:0370:7344", session_id=dict(tag="ipv4"), @@ -416,7 +431,9 @@ def test_ios_logging_global_merged(self): dict( ipv6="2001:0db8:85a3:0000:0000:8a2e:0370:7374", vrf="Apn2", - transport=dict(udp=dict(discriminator="msglog01 severity includes 5")), + transport=dict( + udp=dict(discriminator="msglog01 severity includes 5"), + ), ), dict( ipv6="2001:0db8:85a3:0000:0000:8a2e:0370:7384", @@ -509,7 +526,13 @@ def test_ios_logging_global_gathered_host(self): ) set_module_args(dict(state="gathered")) gathered = dict( - hosts=[dict(hostname="172.16.1.1", vrf="vpn-1", transport=dict(tcp=dict(audit=True)))], + hosts=[ + dict( + hostname="172.16.1.1", + vrf="vpn-1", + transport=dict(tcp=dict(audit=True)), + ), + ], ) result = self.execute_module(changed=False) @@ -617,9 +640,14 @@ def test_ios_logging_global_replaced(self): """, ) playbook = dict( - config=dict(hosts=[dict(hostname="172.16.2.15", session_id=dict(text="Test"))]), + config=dict( + hosts=[dict(hostname="172.16.2.15", session_id=dict(text="Test"))], + ), ) - replaced = ["no logging host 172.16.1.1", "logging host 172.16.2.15 session-id string Test"] + replaced = [ + "no logging host 172.16.1.1", + "logging host 172.16.2.15 session-id string Test", + ] playbook["state"] = "replaced" set_module_args(playbook) result = self.execute_module(changed=True) @@ -651,8 +679,14 @@ def test_ios_logging_global_replaced_ordering_host(self): {"hostname": "172.16.0.4", "vrf": "Mgmt-intf"}, ], "origin_id": {"tag": "hostname"}, - "rate_limit": {"console": True, "except_severity": "errors", "size": 10}, - "source_interface": [{"interface": "GigabitEthernet0", "vrf": "Mgmt-intf"}], + "rate_limit": { + "console": True, + "except_severity": "errors", + "size": 10, + }, + "source_interface": [ + {"interface": "GigabitEthernet0", "vrf": "Mgmt-intf"}, + ], "trap": "informational", }, } diff --git a/tests/unit/modules/network/ios/test_ios_ntp.py b/tests/unit/modules/network/ios/test_ios_ntp.py index 3e73fdfd4..fe11b77b7 100644 --- a/tests/unit/modules/network/ios/test_ios_ntp.py +++ b/tests/unit/modules/network/ios/test_ios_ntp.py @@ -18,9 +18,9 @@ __metaclass__ = type +from unittest.mock import patch from ansible_collections.cisco.ios.plugins.modules import ios_ntp -from ansible_collections.cisco.ios.tests.unit.compat.mock import patch from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args from .ios_module import TestIosModule, load_fixture diff --git a/tests/unit/modules/network/ios/test_ios_ntp_global.py b/tests/unit/modules/network/ios/test_ios_ntp_global.py index a9d0392c1..e955c2929 100644 --- a/tests/unit/modules/network/ios/test_ios_ntp_global.py +++ b/tests/unit/modules/network/ios/test_ios_ntp_global.py @@ -7,11 +7,10 @@ __metaclass__ = type - from textwrap import dedent +from unittest.mock import patch from ansible_collections.cisco.ios.plugins.modules import ios_ntp_global -from ansible_collections.cisco.ios.tests.unit.compat.mock import patch from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args from .ios_module import TestIosModule @@ -86,7 +85,12 @@ def test_ios_ntp_global_merged_idempotent(self): allow=dict(control=dict(rate_limit=4)), authenticate=True, authentication_keys=[ - dict(algorithm="md5", encryption=7, id=2, key="SomeSecurePassword"), + dict( + algorithm="md5", + encryption=7, + id=2, + key="SomeSecurePassword", + ), ], broadcast_delay=22, logging=True, @@ -98,8 +102,18 @@ def test_ios_ntp_global_merged_idempotent(self): panic_update=True, peers=[ dict(peer="172.16.1.10", version=2), - dict(key_id=2, minpoll=5, peer="172.16.1.11", prefer=True, version=2), - dict(peer="checkPeerDomainIpv4.com", prefer=True, use_ipv4=True), + dict( + key_id=2, + minpoll=5, + peer="172.16.1.11", + prefer=True, + version=2, + ), + dict( + peer="checkPeerDomainIpv4.com", + prefer=True, + use_ipv4=True, + ), dict(peer="checkPeerDomainIpv6.com", use_ipv6=True), dict(peer="testPeerDomainIpv6.com", prefer=True, use_ipv6=True), ], @@ -109,7 +123,10 @@ def test_ios_ntp_global_merged_idempotent(self): dict(server="checkServerDomainIpv6.com", use_ipv6=True), ], source="GigabitEthernet0/1", - trusted_keys=[dict(range_start=21), dict(range_end=13, range_start=3)], + trusted_keys=[ + dict(range_start=21), + dict(range_end=13, range_start=3), + ], update_calendar=True, ), state="merged", @@ -138,7 +155,12 @@ def test_ios_ntp_global_merged(self): allow=dict(control=dict(rate_limit=4)), authenticate=True, authentication_keys=[ - dict(algorithm="md5", encryption=7, id=2, key="SomeSecurePassword"), + dict( + algorithm="md5", + encryption=7, + id=2, + key="SomeSecurePassword", + ), ], broadcast_delay=22, logging=True, @@ -150,8 +172,18 @@ def test_ios_ntp_global_merged(self): panic_update=True, peers=[ dict(peer="172.16.1.10", version=2), - dict(key=2, minpoll=5, peer="172.16.1.11", prefer=True, version=2), - dict(peer="checkPeerDomainIpv4.com", prefer=True, use_ipv4=True), + dict( + key=2, + minpoll=5, + peer="172.16.1.11", + prefer=True, + version=2, + ), + dict( + peer="checkPeerDomainIpv4.com", + prefer=True, + use_ipv4=True, + ), dict(peer="checkPeerDomainIpv6.com", use_ipv6=True), dict(peer="testPeerDomainIpv6.com", prefer=True, use_ipv6=True), ], @@ -162,7 +194,10 @@ def test_ios_ntp_global_merged(self): dict(server="checkServerDomainIpv6.com", use_ipv6=True), ], source="GigabitEthernet0/1", - trusted_keys=[dict(range_start=21), dict(range_end=13, range_start=3)], + trusted_keys=[ + dict(range_start=21), + dict(range_end=13, range_start=3), + ], update_calendar=True, ), state="merged", @@ -324,7 +359,12 @@ def test_ios_ntp_global_replaced_overridden(self): allow=dict(control=dict(rate_limit=4)), authenticate=True, authentication_keys=[ - dict(algorithm="md5", encryption=7, id=2, key="SomeSecurePassword"), + dict( + algorithm="md5", + encryption=7, + id=2, + key="SomeSecurePassword", + ), ], broadcast_delay=22, logging=True, @@ -336,8 +376,18 @@ def test_ios_ntp_global_replaced_overridden(self): panic_update=True, peers=[ dict(peer="172.16.1.10", version=2), - dict(key=2, minpoll=5, peer="172.16.1.11", prefer=True, version=2), - dict(peer="checkPeerDomainIpv4.com", prefer=True, use_ipv4=True), + dict( + key=2, + minpoll=5, + peer="172.16.1.11", + prefer=True, + version=2, + ), + dict( + peer="checkPeerDomainIpv4.com", + prefer=True, + use_ipv4=True, + ), dict(peer="checkPeerDomainIpv6.com", use_ipv6=True), dict(peer="testPeerDomainIpv6.com", prefer=True, use_ipv6=True), ], @@ -347,7 +397,10 @@ def test_ios_ntp_global_replaced_overridden(self): dict(server="checkServerDomainIpv6.com", use_ipv6=True), ], source="GigabitEthernet0/1", - trusted_keys=[dict(range_start=21), dict(range_end=13, range_start=3)], + trusted_keys=[ + dict(range_start=21), + dict(range_end=13, range_start=3), + ], update_calendar=True, ), state="replaced", @@ -415,7 +468,12 @@ def test_ios_ntp_global_replaced_overridden_idempotent(self): allow=dict(control=dict(rate_limit=4)), authenticate=True, authentication_keys=[ - dict(algorithm="md5", encryption=7, id=2, key="SomeSecurePassword"), + dict( + algorithm="md5", + encryption=7, + id=2, + key="SomeSecurePassword", + ), ], broadcast_delay=22, logging=True, @@ -426,15 +484,28 @@ def test_ios_ntp_global_replaced_overridden_idempotent(self): orphan=4, panic_update=True, peers=[ - dict(key_id=2, minpoll=5, peer="172.16.1.11", prefer=True, version=2), - dict(peer="checkPeerDomainIpv4.com", prefer=True, use_ipv4=True), + dict( + key_id=2, + minpoll=5, + peer="172.16.1.11", + prefer=True, + version=2, + ), + dict( + peer="checkPeerDomainIpv4.com", + prefer=True, + use_ipv4=True, + ), ], servers=[ dict(server="172.16.1.13", source="GigabitEthernet0/1"), dict(server="checkServerDomainIpv6.com", use_ipv6=True), ], source="Loopback888", - trusted_keys=[dict(range_start=21), dict(range_end=13, range_start=3)], + trusted_keys=[ + dict(range_start=21), + dict(range_end=13, range_start=3), + ], update_calendar=True, ), state="overridden", diff --git a/tests/unit/modules/network/ios/test_ios_ospf_interfaces.py b/tests/unit/modules/network/ios/test_ios_ospf_interfaces.py index 3721ba3ba..ea500f540 100644 --- a/tests/unit/modules/network/ios/test_ios_ospf_interfaces.py +++ b/tests/unit/modules/network/ios/test_ios_ospf_interfaces.py @@ -7,11 +7,10 @@ __metaclass__ = type - from textwrap import dedent +from unittest.mock import patch from ansible_collections.cisco.ios.plugins.modules import ios_ospf_interfaces -from ansible_collections.cisco.ios.tests.unit.compat.mock import patch from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args from .ios_module import TestIosModule diff --git a/tests/unit/modules/network/ios/test_ios_ospfv2.py b/tests/unit/modules/network/ios/test_ios_ospfv2.py index a8bc97105..e14def8d8 100644 --- a/tests/unit/modules/network/ios/test_ios_ospfv2.py +++ b/tests/unit/modules/network/ios/test_ios_ospfv2.py @@ -7,11 +7,10 @@ __metaclass__ = type - from textwrap import dedent +from unittest.mock import patch from ansible_collections.cisco.ios.plugins.modules import ios_ospfv2 -from ansible_collections.cisco.ios.tests.unit.compat.mock import patch from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args from .ios_module import TestIosModule @@ -76,13 +75,24 @@ def test_ios_ospfv2_merged(self): ), ), network=[ - dict(address="198.51.100.0", wildcard_bits="0.0.0.255", area=5), - dict(address="192.0.2.0", wildcard_bits="0.0.0.255", area=5), + dict( + address="198.51.100.0", + wildcard_bits="0.0.0.255", + area=5, + ), + dict( + address="192.0.2.0", + wildcard_bits="0.0.0.255", + area=5, + ), ], domain_id=dict(ip_address=dict(address="192.0.3.1")), max_metric=dict(on_startup=dict(time=100), router_lsa=True), passive_interfaces=dict( - interface=dict(set_interface=False, name=["GigabitEthernet0/2"]), + interface=dict( + set_interface=False, + name=["GigabitEthernet0/2"], + ), ), vrf="blue", ), @@ -284,11 +294,17 @@ def test_ios_ospfv2_overridden(self): "areas": [ { "area_id": "5", - "authentication": {"enable": True, "message_digest": True}, + "authentication": { + "enable": True, + "message_digest": True, + }, }, { "area_id": "10", - "authentication": {"enable": True, "message_digest": True}, + "authentication": { + "enable": True, + "message_digest": True, + }, "capability": True, "default_cost": 10, "filter_list": [ @@ -470,7 +486,10 @@ def test_ios_ospfv2_overridden(self): "passive_interfaces": { "default": True, "interface": { - "name": ["GigabitEthernet0/1", "GigabitEthernet0/2"], + "name": [ + "GigabitEthernet0/1", + "GigabitEthernet0/2", + ], "set_interface": False, }, }, @@ -602,7 +621,10 @@ def test_ios_ospfv2_deleted(self): """, ) set_module_args( - dict(config=dict(processes=[dict(process_id="200", vrf="blue")]), state="deleted"), + dict( + config=dict(processes=[dict(process_id="200", vrf="blue")]), + state="deleted", + ), ) commands = ["no router ospf 200 vrf blue"] self.execute_module(changed=True, commands=commands) @@ -633,7 +655,11 @@ def test_ios_ospfv2_parsed(self): "processes": [ { "areas": [ - {"area_id": "5", "authentication": {"enable": True}, "capability": True}, + { + "area_id": "5", + "authentication": {"enable": True}, + "capability": True, + }, ], "process_id": 1, }, @@ -678,11 +704,17 @@ def test_ios_ospfv2_rendered(self): "areas": [ { "area_id": "5", - "authentication": {"enable": True, "message_digest": True}, + "authentication": { + "enable": True, + "message_digest": True, + }, }, { "area_id": "10", - "authentication": {"enable": True, "message_digest": True}, + "authentication": { + "enable": True, + "message_digest": True, + }, "capability": True, "default_cost": 10, "filter_list": [ @@ -863,7 +895,10 @@ def test_ios_ospfv2_rendered(self): "passive_interfaces": { "default": True, "interface": { - "name": ["GigabitEthernet0/1", "GigabitEthernet0/2"], + "name": [ + "GigabitEthernet0/1", + "GigabitEthernet0/2", + ], "set_interface": False, }, }, @@ -1031,13 +1066,19 @@ def test_ios_ospfv2_overridden_2(self): "lsa_group": 25, }, }, - "max_metric": {"router_lsa": True, "on_startup": {"time": 100}}, + "max_metric": { + "router_lsa": True, + "on_startup": {"time": 100}, + }, "areas": [{"area_id": "10", "capability": True}], "passive_interfaces": { "default": True, "interface": { "set_interface": False, - "name": ["GigabitEthernet0/2", "GigabitEthernet0/1"], + "name": [ + "GigabitEthernet0/2", + "GigabitEthernet0/1", + ], }, }, }, @@ -1143,13 +1184,19 @@ def test_ios_ospfv2_overridden_idempotent(self): ], }, "domain_id": {"ip_address": {"address": "192.0.3.1"}}, - "max_metric": {"router_lsa": True, "on_startup": {"time": 100}}, + "max_metric": { + "router_lsa": True, + "on_startup": {"time": 100}, + }, "areas": [{"area_id": "10", "capability": True}], "passive_interfaces": { "default": True, "interface": { "set_interface": False, - "name": ["GigabitEthernet0/2", "GigabitEthernet0/1"], + "name": [ + "GigabitEthernet0/2", + "GigabitEthernet0/1", + ], }, }, }, diff --git a/tests/unit/modules/network/ios/test_ios_ospfv3.py b/tests/unit/modules/network/ios/test_ios_ospfv3.py index 30c646123..efaae19ac 100644 --- a/tests/unit/modules/network/ios/test_ios_ospfv3.py +++ b/tests/unit/modules/network/ios/test_ios_ospfv3.py @@ -7,9 +7,9 @@ __metaclass__ = type +from unittest.mock import patch from ansible_collections.cisco.ios.plugins.modules import ios_ospfv3 -from ansible_collections.cisco.ios.tests.unit.compat.mock import patch from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args from .ios_module import TestIosModule, load_fixture @@ -58,7 +58,10 @@ def test_ios_ospfv3_merged(self): afi="ipv4", unicast=True, vrf="blue", - adjacency=dict(min_adjacency=100, max_adjacency=100), + adjacency=dict( + min_adjacency=100, + max_adjacency=100, + ), ), ], ), @@ -89,7 +92,9 @@ def test_ios_ospfv3_merged_idempotent(self): areas=[ dict( area_id=10, - nssa=dict(default_information_originate=dict(metric=10)), + nssa=dict( + default_information_originate=dict(metric=10), + ), ), ], address_family=[ @@ -132,7 +137,10 @@ def test_ios_ospfv3_replaced(self): afi="ipv4", unicast=True, vrf="blue", - adjacency=dict(min_adjacency=100, max_adjacency=100), + adjacency=dict( + min_adjacency=100, + max_adjacency=100, + ), ), ], ), @@ -164,7 +172,9 @@ def test_ios_ospfv3_replaced_idempotent(self): areas=[ dict( area_id=10, - nssa=dict(default_information_originate=dict(metric=10)), + nssa=dict( + default_information_originate=dict(metric=10), + ), ), ], address_family=[ @@ -205,7 +215,9 @@ def test_ios_ospfv3_overridden(self): areas=[ dict( area_id=10, - nssa=dict(default_information_originate=dict(metric=10)), + nssa=dict( + default_information_originate=dict(metric=10), + ), ), ], address_family=[ @@ -256,7 +268,9 @@ def test_ios_ospfv3_overridden_idempotent(self): areas=[ dict( area_id=10, - nssa=dict(default_information_originate=dict(metric=10)), + nssa=dict( + default_information_originate=dict(metric=10), + ), ), ], address_family=[ @@ -287,7 +301,9 @@ def test_ios_ospfv3_overridden_idempotent(self): self.execute_module(changed=False, commands=[]) def test_ios_ospfv3_deleted(self): - set_module_args(dict(config=dict(processes=[dict(process_id="1")]), state="deleted")) + set_module_args( + dict(config=dict(processes=[dict(process_id="1")]), state="deleted"), + ) commands = ["no router ospfv3 1"] self.execute_module(changed=True, commands=commands) diff --git a/tests/unit/modules/network/ios/test_ios_ping.py b/tests/unit/modules/network/ios/test_ios_ping.py index bdb822e62..02969ffe0 100644 --- a/tests/unit/modules/network/ios/test_ios_ping.py +++ b/tests/unit/modules/network/ios/test_ios_ping.py @@ -7,11 +7,10 @@ __metaclass__ = type - from textwrap import dedent +from unittest.mock import patch from ansible_collections.cisco.ios.plugins.modules import ios_ping -from ansible_collections.cisco.ios.tests.unit.compat.mock import patch from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args from .ios_module import TestIosModule @@ -61,7 +60,9 @@ def test_ios_ping_v6(self): Success rate is 100 percent (2/2), round-trip min/avg/max = 25/25/25 ms """, ) - set_module_args(dict(count=2, dest="2001:db8:ffff:ffff:ffff:ffff:ffff:ffff", afi="ipv6")) + set_module_args( + dict(count=2, dest="2001:db8:ffff:ffff:ffff:ffff:ffff:ffff", afi="ipv6"), + ) result = self.execute_module() mock_res = { "commands": "ping ipv6 2001:db8:ffff:ffff:ffff:ffff:ffff:ffff repeat 2", diff --git a/tests/unit/modules/network/ios/test_ios_prefix_lists.py b/tests/unit/modules/network/ios/test_ios_prefix_lists.py index 2aac373dd..0df4be859 100644 --- a/tests/unit/modules/network/ios/test_ios_prefix_lists.py +++ b/tests/unit/modules/network/ios/test_ios_prefix_lists.py @@ -7,9 +7,9 @@ __metaclass__ = type +from unittest.mock import patch from ansible_collections.cisco.ios.plugins.modules import ios_prefix_lists -from ansible_collections.cisco.ios.tests.unit.compat.mock import patch from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args from .ios_module import TestIosModule, load_fixture @@ -74,7 +74,12 @@ def test_ios_prefix_lists_merged(self): prefix="35.0.0.0/8", sequence=5, ), - dict(action="deny", ge=20, prefix="35.0.0.0/8", sequence=10), + dict( + action="deny", + ge=20, + prefix="35.0.0.0/8", + sequence=10, + ), ], name="test_prefix", ), @@ -121,9 +126,24 @@ def test_ios_prefix_lists_merged_idempotent(self): dict( description="this is test description", entries=[ - dict(action="deny", le=15, prefix="1.0.0.0/8", sequence=5), - dict(action="deny", ge=10, prefix="35.0.0.0/8", sequence=10), - dict(action="deny", ge=15, prefix="12.0.0.0/8", sequence=15), + dict( + action="deny", + le=15, + prefix="1.0.0.0/8", + sequence=5, + ), + dict( + action="deny", + ge=10, + prefix="35.0.0.0/8", + sequence=10, + ), + dict( + action="deny", + ge=15, + prefix="12.0.0.0/8", + sequence=15, + ), dict( action="deny", ge=20, @@ -137,7 +157,12 @@ def test_ios_prefix_lists_merged_idempotent(self): dict( description="this is test", entries=[ - dict(action="deny", ge=15, prefix="12.0.0.0/8", sequence=50), + dict( + action="deny", + ge=15, + prefix="12.0.0.0/8", + sequence=50, + ), ], name="test", ), @@ -151,7 +176,12 @@ def test_ios_prefix_lists_merged_idempotent(self): prefix="35.0.0.0/8", sequence=5, ), - dict(action="deny", ge=20, prefix="35.0.0.0/8", sequence=10), + dict( + action="deny", + ge=20, + prefix="35.0.0.0/8", + sequence=10, + ), ], name="test_prefix", ), @@ -190,7 +220,12 @@ def test_ios_prefix_lists_replaced(self): dict( description="this is replace test", entries=[ - dict(action="deny", ge=15, prefix="12.0.0.0/8", sequence=15), + dict( + action="deny", + ge=15, + prefix="12.0.0.0/8", + sequence=15, + ), dict( action="deny", ge=20, @@ -204,7 +239,12 @@ def test_ios_prefix_lists_replaced(self): dict( description="this is replace test", entries=[ - dict(action="deny", ge=20, prefix="35.0.0.0/8", sequence=10), + dict( + action="deny", + ge=20, + prefix="35.0.0.0/8", + sequence=10, + ), ], name="test_replace", ), @@ -255,9 +295,24 @@ def test_ios_prefix_lists_replaced_idempotent(self): dict( description="this is test description", entries=[ - dict(action="deny", le=15, prefix="1.0.0.0/8", sequence=5), - dict(action="deny", ge=10, prefix="35.0.0.0/8", sequence=10), - dict(action="deny", ge=15, prefix="12.0.0.0/8", sequence=15), + dict( + action="deny", + le=15, + prefix="1.0.0.0/8", + sequence=5, + ), + dict( + action="deny", + ge=10, + prefix="35.0.0.0/8", + sequence=10, + ), + dict( + action="deny", + ge=15, + prefix="12.0.0.0/8", + sequence=15, + ), dict( action="deny", ge=20, @@ -271,7 +326,12 @@ def test_ios_prefix_lists_replaced_idempotent(self): dict( description="this is test", entries=[ - dict(action="deny", ge=15, prefix="12.0.0.0/8", sequence=50), + dict( + action="deny", + ge=15, + prefix="12.0.0.0/8", + sequence=50, + ), ], name="test", ), @@ -285,7 +345,12 @@ def test_ios_prefix_lists_replaced_idempotent(self): prefix="35.0.0.0/8", sequence=5, ), - dict(action="deny", ge=20, prefix="35.0.0.0/8", sequence=10), + dict( + action="deny", + ge=20, + prefix="35.0.0.0/8", + sequence=10, + ), ], name="test_prefix", ), @@ -324,7 +389,12 @@ def test_ios_prefix_lists_overridden(self): dict( description="this is override test", entries=[ - dict(action="deny", ge=15, prefix="12.0.0.0/8", sequence=15), + dict( + action="deny", + ge=15, + prefix="12.0.0.0/8", + sequence=15, + ), dict( action="deny", ge=20, @@ -338,7 +408,12 @@ def test_ios_prefix_lists_overridden(self): dict( description="this is override test", entries=[ - dict(action="deny", ge=20, prefix="35.0.0.0/8", sequence=10), + dict( + action="deny", + ge=20, + prefix="35.0.0.0/8", + sequence=10, + ), ], name="test_override", ), @@ -391,9 +466,24 @@ def test_ios_prefix_lists_overridden_idempotent(self): dict( description="this is test description", entries=[ - dict(action="deny", le=15, prefix="1.0.0.0/8", sequence=5), - dict(action="deny", ge=10, prefix="35.0.0.0/8", sequence=10), - dict(action="deny", ge=15, prefix="12.0.0.0/8", sequence=15), + dict( + action="deny", + le=15, + prefix="1.0.0.0/8", + sequence=5, + ), + dict( + action="deny", + ge=10, + prefix="35.0.0.0/8", + sequence=10, + ), + dict( + action="deny", + ge=15, + prefix="12.0.0.0/8", + sequence=15, + ), dict( action="deny", ge=20, @@ -407,7 +497,12 @@ def test_ios_prefix_lists_overridden_idempotent(self): dict( description="this is test", entries=[ - dict(action="deny", ge=15, prefix="12.0.0.0/8", sequence=50), + dict( + action="deny", + ge=15, + prefix="12.0.0.0/8", + sequence=50, + ), ], name="test", ), @@ -421,7 +516,12 @@ def test_ios_prefix_lists_overridden_idempotent(self): prefix="35.0.0.0/8", sequence=5, ), - dict(action="deny", ge=20, prefix="35.0.0.0/8", sequence=10), + dict( + action="deny", + ge=20, + prefix="35.0.0.0/8", + sequence=10, + ), ], name="test_prefix", ), @@ -491,7 +591,12 @@ def test_ios_prefix_lists_rendered(self): prefix="35.0.0.0/8", sequence=5, ), - dict(action="deny", ge=20, prefix="35.0.0.0/8", sequence=10), + dict( + action="deny", + ge=20, + prefix="35.0.0.0/8", + sequence=10, + ), ], name="test_prefix", ), diff --git a/tests/unit/modules/network/ios/test_ios_route_maps.py b/tests/unit/modules/network/ios/test_ios_route_maps.py index 0e450f908..27c5aa7f6 100644 --- a/tests/unit/modules/network/ios/test_ios_route_maps.py +++ b/tests/unit/modules/network/ios/test_ios_route_maps.py @@ -7,9 +7,9 @@ __metaclass__ = type +from unittest.mock import patch from ansible_collections.cisco.ios.plugins.modules import ios_route_maps -from ansible_collections.cisco.ios.tests.unit.compat.mock import patch from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args from .ios_module import TestIosModule, load_fixture @@ -58,7 +58,10 @@ def test_ios_route_maps_merged(self): additional_paths=dict(all=True), as_path=dict(acls=[100, 120]), clns=dict(address="test_osi"), - community=dict(exact_match=True, name=["new_merge"]), + community=dict( + exact_match=True, + name=["new_merge"], + ), ip=dict(address=dict(acls=[10, 100])), length=dict(maximum=50000, minimum=5000), mpls_label=True, @@ -213,7 +216,10 @@ def test_ios_route_maps_merged_idempotent(self): vpn_distinguisher=dict(address="192.0.2.1:12"), ), global_route=True, - interfaces=["GigabitEthernet0/2", "GigabitEthernet0/1"], + interfaces=[ + "GigabitEthernet0/2", + "GigabitEthernet0/1", + ], level=dict(level_1_2=True), lisp="test_lisp", local_preference=100, @@ -249,7 +255,10 @@ def test_ios_route_maps_replaced(self): additional_paths=dict(all=True), as_path=dict(acls=[100, 120]), clns=dict(address="test_osi"), - community=dict(exact_match=True, name=["new_replace"]), + community=dict( + exact_match=True, + name=["new_replace"], + ), ip=dict(address=dict(acls=[10, 100])), length=dict(maximum=50000, minimum=5000), mpls_label=True, @@ -418,7 +427,10 @@ def test_ios_route_maps_replaced_idempotent(self): vpn_distinguisher=dict(address="192.0.2.1:12"), ), global_route=True, - interfaces=["GigabitEthernet0/2", "GigabitEthernet0/1"], + interfaces=[ + "GigabitEthernet0/2", + "GigabitEthernet0/1", + ], level=dict(level_1_2=True), lisp="test_lisp", local_preference=100, @@ -454,7 +466,10 @@ def test_ios_route_maps_overridden(self): additional_paths=dict(all=True), as_path=dict(acls=[100, 120]), clns=dict(address="test_osi"), - community=dict(exact_match=True, name=["new_override"]), + community=dict( + exact_match=True, + name=["new_override"], + ), ip=dict(address=dict(acls=[10, 100])), length=dict(maximum=50000, minimum=5000), mpls_label=True, @@ -623,7 +638,10 @@ def test_ios_route_maps_overridden_idempotent(self): vpn_distinguisher=dict(address="192.0.2.1:12"), ), global_route=True, - interfaces=["GigabitEthernet0/2", "GigabitEthernet0/1"], + interfaces=[ + "GigabitEthernet0/2", + "GigabitEthernet0/1", + ], level=dict(level_1_2=True), lisp="test_lisp", local_preference=100, @@ -676,7 +694,10 @@ def test_ios_route_maps_rendered(self): name=["99", "98", "test_1", "test_2"], ), extcommunity=["110", "130"], - interfaces=["GigabitEthernet0/1", "GigabitEthernet0/2"], + interfaces=[ + "GigabitEthernet0/1", + "GigabitEthernet0/2", + ], ip=dict(address=dict(acls=[10, 100])), ipv6=dict(route_source=dict(acl="test_ipv6")), length=dict(maximum=10000, minimum=1000), @@ -702,7 +723,9 @@ def test_ios_route_maps_rendered(self): sequence=30, set=dict( as_path=dict( - prepend=dict(as_number=["65512", 65522, "65532", 65543]), + prepend=dict( + as_number=["65512", 65522, "65532", 65543], + ), ), ), ), @@ -727,7 +750,10 @@ def test_ios_route_maps_rendered(self): vpn_distinguisher=dict(address="192.0.2.1:12"), ), global_route=True, - interfaces=["GigabitEthernet0/2", "GigabitEthernet0/1"], + interfaces=[ + "GigabitEthernet0/2", + "GigabitEthernet0/1", + ], level=dict(level_1_2=True), lisp="test_lisp", local_preference=100, diff --git a/tests/unit/modules/network/ios/test_ios_service.py b/tests/unit/modules/network/ios/test_ios_service.py index cbf9a9fd7..fa92efcdc 100644 --- a/tests/unit/modules/network/ios/test_ios_service.py +++ b/tests/unit/modules/network/ios/test_ios_service.py @@ -7,11 +7,10 @@ __metaclass__ = type - from textwrap import dedent +from unittest.mock import patch from ansible_collections.cisco.ios.plugins.modules import ios_service -from ansible_collections.cisco.ios.tests.unit.compat.mock import patch from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args from .ios_module import TestIosModule diff --git a/tests/unit/modules/network/ios/test_ios_snmp_server.py b/tests/unit/modules/network/ios/test_ios_snmp_server.py index 28a11fd7c..0b8f797a1 100644 --- a/tests/unit/modules/network/ios/test_ios_snmp_server.py +++ b/tests/unit/modules/network/ios/test_ios_snmp_server.py @@ -7,11 +7,10 @@ __metaclass__ = type - from textwrap import dedent +from unittest.mock import patch from ansible_collections.cisco.ios.plugins.modules import ios_snmp_server -from ansible_collections.cisco.ios.tests.unit.compat.mock import patch from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args from .ios_module import TestIosModule @@ -168,10 +167,19 @@ def test_ios_snmp_server_merged_idempotent(self): "context": ["contextWord2", "contextWord1"], "engine_id": [ {"id": "AB0C5342FA0A", "local": True}, - {"id": "AB0C5342FAAA", "remote": {"host": "172.16.0.1", "udp_port": 22}}, - {"id": "AB0C5342FAAB", "remote": {"host": "172.16.0.2", "udp_port": 23}}, + { + "id": "AB0C5342FAAA", + "remote": {"host": "172.16.0.1", "udp_port": 22}, + }, + { + "id": "AB0C5342FAAB", + "remote": {"host": "172.16.0.2", "udp_port": 23}, + }, ], - "file_transfer": {"access_group": "testAcl", "protocol": ["ftp", "rcp"]}, + "file_transfer": { + "access_group": "testAcl", + "protocol": ["ftp", "rcp"], + }, "groups": [ {"group": "group0", "version": "v3", "version_option": "auth"}, { @@ -182,7 +190,11 @@ def test_ios_snmp_server_merged_idempotent(self): "version": "v1", }, {"group": "group2", "version": "v3", "version_option": "priv"}, - {"group": "replaceUser", "version": "v3", "version_option": "noauth"}, + { + "group": "replaceUser", + "version": "v3", + "version_option": "noauth", + }, {"acl_v6": "ipv6acl", "group": "group3", "version": "v1"}, {"acl_v4": "2", "group": "group4", "version": "v1"}, ], @@ -221,8 +233,16 @@ def test_ios_snmp_server_merged_idempotent(self): "traps": ["msdp"], "version": "2c", }, - {"community_string": "check", "host": "172.16.2.99", "traps": ["slb"]}, - {"community_string": "checktrap", "host": "172.16.2.99", "traps": ["isis"]}, + { + "community_string": "check", + "host": "172.16.2.99", + "traps": ["slb"], + }, + { + "community_string": "checktrap", + "host": "172.16.2.99", + "traps": ["isis"], + }, ], "inform": {"pending": 2}, "ip": {"dscp": 2}, @@ -304,7 +324,12 @@ def test_ios_snmp_server_merged_idempotent(self): }, "ipmulticast": True, "ipsec": { - "cryptomap": {"add": True, "attach": True, "delete": True, "detach": True}, + "cryptomap": { + "add": True, + "attach": True, + "delete": True, + "detach": True, + }, "too_many_sas": True, "tunnel": {"start": True, "stop": True}, }, @@ -357,7 +382,12 @@ def test_ios_snmp_server_merged_idempotent(self): }, }, "users": [ - {"acl_v4": "24", "group": "newfamily", "username": "newuser", "version": "v1"}, + { + "acl_v4": "24", + "group": "newfamily", + "username": "newuser", + "version": "v1", + }, { "acl_v4": "ipv4acl", "acl_v6": "ipv6acl", @@ -365,7 +395,11 @@ def test_ios_snmp_server_merged_idempotent(self): "username": "paul", "version": "v3", }, - {"group": "replaceUser", "username": "replaceUser", "version": "v3"}, + { + "group": "replaceUser", + "username": "replaceUser", + "version": "v3", + }, ], }, } @@ -441,9 +475,15 @@ def test_ios_snmp_server_merged(self): "id": "AB0C5342FAAA", "remote": {"host": "172.16.0.1", "udp_port": 22, "vrf": "mgmt"}, }, - {"id": "AB0C5342FAAB", "remote": {"host": "172.16.0.2", "udp_port": 23}}, + { + "id": "AB0C5342FAAB", + "remote": {"host": "172.16.0.2", "udp_port": 23}, + }, ], - "file_transfer": {"access_group": "testAcl", "protocol": ["ftp", "rcp"]}, + "file_transfer": { + "access_group": "testAcl", + "protocol": ["ftp", "rcp"], + }, "groups": [ {"group": "group0", "version": "v3", "version_option": "auth"}, { @@ -454,7 +494,11 @@ def test_ios_snmp_server_merged(self): "version": "v1", }, {"group": "group2", "version": "v3", "version_option": "priv"}, - {"group": "replaceUser", "version": "v3", "version_option": "noauth"}, + { + "group": "replaceUser", + "version": "v3", + "version_option": "noauth", + }, {"acl_v6": "ipv6acl", "group": "group3", "version": "v1"}, {"acl_v4": "2", "group": "group4", "version": "v1"}, ], @@ -493,8 +537,16 @@ def test_ios_snmp_server_merged(self): "traps": ["msdp"], "version": "2c", }, - {"community_string": "check", "host": "172.16.2.99", "traps": ["slb"]}, - {"community_string": "checktrap", "host": "172.16.2.99", "traps": ["isis"]}, + { + "community_string": "check", + "host": "172.16.2.99", + "traps": ["slb"], + }, + { + "community_string": "checktrap", + "host": "172.16.2.99", + "traps": ["isis"], + }, ], "inform": {"pending": 2}, "ip": {"dscp": 2}, @@ -586,7 +638,12 @@ def test_ios_snmp_server_merged(self): }, "ipmulticast": True, "ipsec": { - "cryptomap": {"add": True, "attach": True, "delete": True, "detach": True}, + "cryptomap": { + "add": True, + "attach": True, + "delete": True, + "detach": True, + }, "too_many_sas": True, "tunnel": {"start": True, "stop": True}, }, @@ -639,15 +696,29 @@ def test_ios_snmp_server_merged(self): }, }, "users": [ - {"acl_v4": "24", "group": "newfamily", "username": "newuser", "version": "v1"}, + { + "acl_v4": "24", + "group": "newfamily", + "username": "newuser", + "version": "v1", + }, { "acl_v6": "ipv6only", "group": "familypaul", "username": "paul", "version": "v3", }, - {"group": "replaceUser", "username": "replaceUser", "version": "v3"}, - {"acl_v4": "27", "group": "mfamily", "username": "flow", "version": "v3"}, + { + "group": "replaceUser", + "username": "replaceUser", + "version": "v3", + }, + { + "acl_v4": "27", + "group": "mfamily", + "username": "flow", + "version": "v3", + }, ], }, } @@ -1122,10 +1193,19 @@ def test_ios_snmp_server_overridden(self): "context": ["contextWord2", "contextWord1"], "engine_id": [ {"id": "AB0C5342FA0A", "local": True}, - {"id": "AB0C5342FAAA", "remote": {"host": "172.16.0.1", "udp_port": 22}}, - {"id": "AB0C5342FAAB", "remote": {"host": "172.16.0.2", "udp_port": 23}}, + { + "id": "AB0C5342FAAA", + "remote": {"host": "172.16.0.1", "udp_port": 22}, + }, + { + "id": "AB0C5342FAAB", + "remote": {"host": "172.16.0.2", "udp_port": 23}, + }, ], - "file_transfer": {"access_group": "testAcl", "protocol": ["ftp", "rcp"]}, + "file_transfer": { + "access_group": "testAcl", + "protocol": ["ftp", "rcp"], + }, "groups": [ {"group": "group0", "version": "v3", "version_option": "auth"}, { @@ -1136,7 +1216,11 @@ def test_ios_snmp_server_overridden(self): "version": "v1", }, {"group": "group2", "version": "v3", "version_option": "priv"}, - {"group": "replaceUser", "version": "v3", "version_option": "noauth"}, + { + "group": "replaceUser", + "version": "v3", + "version_option": "noauth", + }, ], "hosts": [ { @@ -1173,8 +1257,16 @@ def test_ios_snmp_server_overridden(self): "traps": ["msdp"], "version": "2c", }, - {"community_string": "check", "host": "172.16.2.99", "traps": ["slb"]}, - {"community_string": "checktrap", "host": "172.16.2.99", "traps": ["isis"]}, + { + "community_string": "check", + "host": "172.16.2.99", + "traps": ["slb"], + }, + { + "community_string": "checktrap", + "host": "172.16.2.99", + "traps": ["isis"], + }, ], "inform": {"pending": 2}, "ip": {"dscp": 2}, @@ -1256,7 +1348,12 @@ def test_ios_snmp_server_overridden(self): }, "ipmulticast": True, "ipsec": { - "cryptomap": {"add": True, "attach": True, "delete": True, "detach": True}, + "cryptomap": { + "add": True, + "attach": True, + "delete": True, + "detach": True, + }, "too_many_sas": True, "tunnel": {"start": True, "stop": True}, }, @@ -1309,18 +1406,35 @@ def test_ios_snmp_server_overridden(self): }, }, "users": [ - {"acl_v4": "24", "group": "newfamily", "username": "newuser", "version": "v1"}, + { + "acl_v4": "24", + "group": "newfamily", + "username": "newuser", + "version": "v1", + }, { "acl_v6": "ipv6acl", "group": "familypaul", "username": "paul", "version": "v3", }, - {"group": "replaceUser", "username": "replaceUser", "version": "v3"}, + { + "group": "replaceUser", + "username": "replaceUser", + "version": "v3", + }, ], "views": [ - {"name": "no-write.test", "family_name": "testiso", "excluded": True}, - {"name": "newView", "family_name": "TestFamilyName", "included": True}, + { + "name": "no-write.test", + "family_name": "testiso", + "excluded": True, + }, + { + "name": "newView", + "family_name": "TestFamilyName", + "included": True, + }, ], }, } @@ -1393,7 +1507,11 @@ def test_ios_snmp_server_replaced_idempotent(self): "traps": ["msdp"], "version": "2c", }, - {"community_string": "check", "host": "172.16.2.99", "traps": ["slb"]}, + { + "community_string": "check", + "host": "172.16.2.99", + "traps": ["slb"], + }, ], }, } @@ -1445,10 +1563,18 @@ def test_ios_snmp_server_parsed(self): parsed = { "engine_id": [ {"id": "AB0C5342FA0A", "local": True}, - {"id": "AB0C5342FAAB", "remote": {"host": "172.16.0.2", "udp_port": 23}}, + { + "id": "AB0C5342FAAB", + "remote": {"host": "172.16.0.2", "udp_port": 23}, + }, ], "users": [ - {"username": "paul", "group": "familypaul", "version": "v3", "acl_v6": "ipv6acl"}, + { + "username": "paul", + "group": "familypaul", + "version": "v3", + "acl_v6": "ipv6acl", + }, ], "traps": { "ospf": { @@ -1525,8 +1651,16 @@ def test_ios_snmp_server_parsed(self): "traps": ["msdp", "stun"], "version": "2c", }, - {"host": "172.16.2.99", "community_string": "check", "traps": ["slb", "pki"]}, - {"host": "172.16.2.99", "community_string": "checktrap", "traps": ["isis", "hsrp"]}, + { + "host": "172.16.2.99", + "community_string": "check", + "traps": ["slb", "pki"], + }, + { + "host": "172.16.2.99", + "community_string": "checktrap", + "traps": ["isis", "hsrp"], + }, ], "groups": [ { @@ -1614,7 +1748,11 @@ def test_ios_snmp_server_gathered(self): "version": "3", "version_option": "noauth", }, - {"host": "172.16.2.99", "community_string": "checktrap", "traps": ["isis", "hsrp"]}, + { + "host": "172.16.2.99", + "community_string": "checktrap", + "traps": ["isis", "hsrp"], + }, ], "users": [ { @@ -1663,7 +1801,10 @@ def test_ios_snmp_server_rendered(self): "config": { "engine_id": [ {"id": "AB0C5342FA0A", "local": True}, - {"id": "AB0C5342FAAB", "remote": {"host": "172.16.0.2", "udp_port": 23}}, + { + "id": "AB0C5342FAAB", + "remote": {"host": "172.16.0.2", "udp_port": 23}, + }, ], "views": [ {"family_name": "iso", "name": "ro"}, @@ -1759,8 +1900,16 @@ def test_ios_snmp_server_rendered(self): "traps": ["msdp"], "version": "2c", }, - {"host": "172.16.2.99", "community_string": "check", "traps": ["slb"]}, - {"host": "172.16.2.99", "community_string": "checktrap", "traps": ["isis"]}, + { + "host": "172.16.2.99", + "community_string": "check", + "traps": ["slb"], + }, + { + "host": "172.16.2.99", + "community_string": "checktrap", + "traps": ["isis"], + }, ], }, "state": "rendered", @@ -1808,7 +1957,10 @@ def test_ios_snmp_server_rendered_user_options(self): "username": "paul", "group": "familypaul", "version": "v3", - "authentication": {"algorithm": "md5", "password": "somepass"}, + "authentication": { + "algorithm": "md5", + "password": "somepass", + }, "encryption": { "priv": "aes", "priv_option": 128, @@ -1820,7 +1972,9 @@ def test_ios_snmp_server_rendered_user_options(self): "state": "rendered", }, ) - rendered = ["snmp-server user paul familypaul v3 auth md5 somepass priv aes 128 somepass"] + rendered = [ + "snmp-server user paul familypaul v3 auth md5 somepass priv aes 128 somepass", + ] result = self.execute_module(changed=False) self.maxDiff = None self.assertEqual(sorted(result["rendered"]), sorted(rendered)) diff --git a/tests/unit/modules/network/ios/test_ios_static_routes.py b/tests/unit/modules/network/ios/test_ios_static_routes.py index d1046cc72..57a416433 100644 --- a/tests/unit/modules/network/ios/test_ios_static_routes.py +++ b/tests/unit/modules/network/ios/test_ios_static_routes.py @@ -7,11 +7,10 @@ __metaclass__ = type - from textwrap import dedent +from unittest.mock import patch from ansible_collections.cisco.ios.plugins.modules import ios_static_routes -from ansible_collections.cisco.ios.tests.unit.compat.mock import patch from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args from .ios_module import TestIosModule @@ -232,7 +231,10 @@ def test_ios_static_routes_merged_idempotent(self): "routes": [ { "next_hops": [ - {"forward_router_address": "10.1.1.2", "track": 10}, + { + "forward_router_address": "10.1.1.2", + "track": 10, + }, { "forward_router_address": "10.1.1.3", "distance_metric": 22, @@ -422,7 +424,10 @@ def test_ios_static_routes_replaced(self): "routes": [ { "next_hops": [ - {"forward_router_address": "10.1.1.2", "track": 10}, + { + "forward_router_address": "10.1.1.2", + "track": 10, + }, { "forward_router_address": "10.1.1.3", "distance_metric": 22, @@ -639,7 +644,10 @@ def test_ios_static_routes_replaced_idempotent(self): "routes": [ { "next_hops": [ - {"forward_router_address": "10.1.1.2", "track": 10}, + { + "forward_router_address": "10.1.1.2", + "track": 10, + }, { "forward_router_address": "10.1.1.3", "distance_metric": 22, @@ -829,7 +837,10 @@ def test_ios_static_routes_overridden(self): "routes": [ { "next_hops": [ - {"forward_router_address": "10.1.1.2", "track": 10}, + { + "forward_router_address": "10.1.1.2", + "track": 10, + }, { "forward_router_address": "10.1.1.3", "distance_metric": 22, @@ -1046,7 +1057,10 @@ def test_ios_static_routes_overridden_idempotent(self): "routes": [ { "next_hops": [ - {"forward_router_address": "10.1.1.2", "track": 10}, + { + "forward_router_address": "10.1.1.2", + "track": 10, + }, { "forward_router_address": "10.1.1.3", "distance_metric": 22, @@ -1236,7 +1250,10 @@ def test_ios_delete_static_route_config_del_all(self): "routes": [ { "next_hops": [ - {"forward_router_address": "10.1.1.2", "track": 10}, + { + "forward_router_address": "10.1.1.2", + "track": 10, + }, { "forward_router_address": "10.1.1.3", "distance_metric": 22, @@ -1716,7 +1733,9 @@ def test_ios_delete_static_route_vrf_based(self): config=[ dict( vrf="testVrf2", - address_families=[dict(afi="ipv4", routes=[dict(dest="192.0.2.0/24")])], + address_families=[ + dict(afi="ipv4", routes=[dict(dest="192.0.2.0/24")]), + ], ), dict( vrf="testVrfv6", @@ -1840,7 +1859,10 @@ def test_ios_static_route_rendered(self): "routes": [ { "next_hops": [ - {"forward_router_address": "10.1.1.2", "track": 10}, + { + "forward_router_address": "10.1.1.2", + "track": 10, + }, { "forward_router_address": "10.1.1.3", "distance_metric": 22, @@ -2127,7 +2149,9 @@ def test_ios_static_route_gathered(self): "routes": [ { "dest": "10.0.0.0/8", - "next_hops": [{"interface": "Null0", "permanent": True}], + "next_hops": [ + {"interface": "Null0", "permanent": True}, + ], }, ], }, diff --git a/tests/unit/modules/network/ios/test_ios_system.py b/tests/unit/modules/network/ios/test_ios_system.py index b82d7ae48..915d7a1f7 100644 --- a/tests/unit/modules/network/ios/test_ios_system.py +++ b/tests/unit/modules/network/ios/test_ios_system.py @@ -21,9 +21,9 @@ __metaclass__ = type +from unittest.mock import patch from ansible_collections.cisco.ios.plugins.modules import ios_system -from ansible_collections.cisco.ios.tests.unit.compat.mock import patch from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args from .ios_module import TestIosModule, load_fixture @@ -70,7 +70,12 @@ def test_ios_system_domain_name(self): def test_ios_system_domain_name_complex(self): set_module_args( - dict(domain_name=[{"name": "test.com", "vrf": "test"}, {"name": "eng.example.net"}]), + dict( + domain_name=[ + {"name": "test.com", "vrf": "test"}, + {"name": "eng.example.net"}, + ], + ), ) commands = [ "ip domain name vrf test test.com", @@ -107,7 +112,10 @@ def test_ios_system_lookup_source(self): def test_ios_system_name_servers(self): name_servers = ["8.8.8.8", "8.8.4.4"] set_module_args(dict(name_servers=name_servers)) - commands = ["no ip name-server vrf management 8.8.8.8", "ip name-server 8.8.4.4"] + commands = [ + "no ip name-server vrf management 8.8.8.8", + "ip name-server 8.8.4.4", + ] self.execute_module(changed=True, commands=commands, sort=False) def rest_ios_system_name_servers_complex(self): diff --git a/tests/unit/modules/network/ios/test_ios_user.py b/tests/unit/modules/network/ios/test_ios_user.py index 3dd03ab81..a13467afb 100644 --- a/tests/unit/modules/network/ios/test_ios_user.py +++ b/tests/unit/modules/network/ios/test_ios_user.py @@ -20,9 +20,9 @@ __metaclass__ = type +from unittest.mock import patch from ansible_collections.cisco.ios.plugins.modules import ios_user -from ansible_collections.cisco.ios.tests.unit.compat.mock import patch from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args from .ios_module import TestIosModule, load_fixture @@ -117,18 +117,26 @@ def test_ios_user_view(self): self.assertEqual(result["commands"], ["username ansible view test"]) def test_ios_user_update_password_changed(self): - set_module_args(dict(name="test", configured_password="test", update_password="on_create")) + set_module_args( + dict(name="test", configured_password="test", update_password="on_create"), + ) result = self.execute_module(changed=True) self.assertEqual(result["commands"], ["username test secret test"]) def test_ios_user_update_password_on_create_ok(self): set_module_args( - dict(name="ansible", configured_password="test", update_password="on_create"), + dict( + name="ansible", + configured_password="test", + update_password="on_create", + ), ) self.execute_module() def test_ios_user_update_password_always(self): - set_module_args(dict(name="ansible", configured_password="test", update_password="always")) + set_module_args( + dict(name="ansible", configured_password="test", update_password="always"), + ) result = self.execute_module(changed=True) self.assertEqual(result["commands"], ["username ansible secret test"]) @@ -169,7 +177,10 @@ def test_add_hashed_password(self): ), ) result = self.execute_module(changed=True) - self.assertEqual(result["commands"], [f"username ansible secret 9 {hashed_password_val}"]) + self.assertEqual( + result["commands"], + [f"username ansible secret 9 {hashed_password_val}"], + ) def test_add_hpassword_with_type(self): set_module_args( diff --git a/tests/unit/modules/network/ios/test_ios_vlans.py b/tests/unit/modules/network/ios/test_ios_vlans.py index e949bb258..a8a848020 100644 --- a/tests/unit/modules/network/ios/test_ios_vlans.py +++ b/tests/unit/modules/network/ios/test_ios_vlans.py @@ -7,11 +7,10 @@ __metaclass__ = type - from textwrap import dedent +from unittest.mock import patch from ansible_collections.cisco.ios.plugins.modules import ios_vlans -from ansible_collections.cisco.ios.tests.unit.compat.mock import patch from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args from .ios_module import TestIosModule diff --git a/tests/unit/modules/network/ios/test_ios_vrf.py b/tests/unit/modules/network/ios/test_ios_vrf.py index d36ea41e1..f39061989 100644 --- a/tests/unit/modules/network/ios/test_ios_vrf.py +++ b/tests/unit/modules/network/ios/test_ios_vrf.py @@ -21,9 +21,9 @@ __metaclass__ = type +from unittest.mock import patch from ansible_collections.cisco.ios.plugins.modules import ios_vrf -from ansible_collections.cisco.ios.tests.unit.compat.mock import patch from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args from .ios_module import TestIosModule, load_fixture @@ -58,7 +58,11 @@ def tearDown(self): def load_fixtures(self, commands=None): self.get_config.return_value = load_fixture("ios_vrf_config.cfg") - self.exec_command.return_value = (0, load_fixture("ios_vrf_config.cfg").strip(), None) + self.exec_command.return_value = ( + 0, + load_fixture("ios_vrf_config.cfg").strip(), + None, + ) self.load_config.return_value = None def test_ios_vrf_name(self): @@ -158,7 +162,11 @@ def test_ios_vrfs_local_override_description(self): def test_ios_vrfs_local_override_state(self): vrfs = [{"name": "test_1", "state": "absent"}, {"name": "test_2"}] set_module_args(dict(vrfs=vrfs, description="test string")) - commands = ["no vrf definition test_1", "vrf definition test_2", "description test string"] + commands = [ + "no vrf definition test_1", + "vrf definition test_2", + "description test string", + ] self.execute_module(changed=True, commands=commands, sort=False) def test_ios_vrf_route_both(self): @@ -178,7 +186,9 @@ def test_ios_vrf_route_both(self): self.execute_module(changed=True, commands=commands, sort=False) def test_ios_vrf_route_import(self): - set_module_args(dict(name="test_6", rd="3:100", route_import=["3:100", "4:100"])) + set_module_args( + dict(name="test_6", rd="3:100", route_import=["3:100", "4:100"]), + ) commands = [ "vrf definition test_6", "rd 3:100", @@ -188,7 +198,9 @@ def test_ios_vrf_route_import(self): self.execute_module(changed=True, commands=commands, sort=False) def test_ios_vrf_route_export(self): - set_module_args(dict(name="test_7", rd="4:100", route_export=["3:100", "4:100"])) + set_module_args( + dict(name="test_7", rd="4:100", route_export=["3:100", "4:100"]), + ) commands = [ "vrf definition test_7", "rd 4:100", @@ -210,7 +222,11 @@ def test_ios_vrf_route_both_mixed(self): def test_ios_vrf_route_both_ipv4(self): set_module_args( - dict(name="test_9", rd="168.0.0.9:100", route_both_ipv4=["168.0.0.9:100", "3:100"]), + dict( + name="test_9", + rd="168.0.0.9:100", + route_both_ipv4=["168.0.0.9:100", "3:100"], + ), ) commands = [ "vrf definition test_9", @@ -281,7 +297,11 @@ def test_ios_vrf_route_both_ipv4_mixed(self): def test_ios_vrf_route_both_ipv6(self): set_module_args( - dict(name="test_13", rd="2:100", route_both_ipv6=["2:100", "168.0.0.13:100"]), + dict( + name="test_13", + rd="2:100", + route_both_ipv6=["2:100", "168.0.0.13:100"], + ), ) commands = [ "vrf definition test_13", @@ -301,7 +321,11 @@ def test_ios_vrf_route_both_ipv6(self): def test_ios_vrf_route_import_ipv6(self): set_module_args( - dict(name="test_14", rd="3:100", route_import_ipv6=["3:100", "168.0.0.14:100"]), + dict( + name="test_14", + rd="3:100", + route_import_ipv6=["3:100", "168.0.0.14:100"], + ), ) commands = [ "vrf definition test_14", @@ -317,7 +341,11 @@ def test_ios_vrf_route_import_ipv6(self): def test_ios_vrf_route_export_ipv6(self): set_module_args( - dict(name="test_15", rd="4:100", route_export_ipv6=["168.0.0.15:100", "4:100"]), + dict( + name="test_15", + rd="4:100", + route_export_ipv6=["168.0.0.15:100", "4:100"], + ), ) commands = [ "vrf definition test_15", @@ -386,7 +414,11 @@ def test_ios_vrf_all_route_both_idempotent(self): def test_ios_vrf_interface_brownfield(self): set_module_args(dict(name="test_19", interfaces=["Ethernet1"])) - commands = ["interface Ethernet1", "vrf forwarding test_19", "ip address 1.2.3.4/5"] + commands = [ + "interface Ethernet1", + "vrf forwarding test_19", + "ip address 1.2.3.4/5", + ] self.execute_module(changed=True, commands=commands, sort=False) def test_ios_mdt(self): diff --git a/tests/unit/modules/network/ios/test_ios_vxlan_vtep.py b/tests/unit/modules/network/ios/test_ios_vxlan_vtep.py index 25b0bc8a6..13e6a5380 100644 --- a/tests/unit/modules/network/ios/test_ios_vxlan_vtep.py +++ b/tests/unit/modules/network/ios/test_ios_vxlan_vtep.py @@ -7,11 +7,10 @@ __metaclass__ = type - from textwrap import dedent +from unittest.mock import patch from ansible_collections.cisco.ios.plugins.modules import ios_vxlan_vtep -from ansible_collections.cisco.ios.tests.unit.compat.mock import patch from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args from .ios_module import TestIosModule diff --git a/tests/unit/modules/utils.py b/tests/unit/modules/utils.py index 6184c48c3..87be9cf8e 100644 --- a/tests/unit/modules/utils.py +++ b/tests/unit/modules/utils.py @@ -4,12 +4,12 @@ __metaclass__ = type import json +from unittest import TestCase +from unittest.mock import patch + from ansible.module_utils import basic from ansible.module_utils._text import to_bytes -from ansible_collections.cisco.ios.tests.unit.compat import unittest -from ansible_collections.cisco.ios.tests.unit.compat.mock import patch - def set_module_args(args): if "_ansible_remote_tmp" not in args: @@ -40,7 +40,7 @@ def fail_json(*args, **kwargs): raise AnsibleFailJson(kwargs) -class ModuleTestCase(unittest.TestCase): +class ModuleTestCase(TestCase): def setUp(self): self.mock_module = patch.multiple( basic.AnsibleModule, diff --git a/tests/unit/plugins/cliconf/test_ios.py b/tests/unit/plugins/cliconf/test_ios.py index 0b7cf8704..eb094b2c7 100644 --- a/tests/unit/plugins/cliconf/test_ios.py +++ b/tests/unit/plugins/cliconf/test_ios.py @@ -31,10 +31,11 @@ except ImportError: from mock import MagicMock +from unittest import TestCase + from ansible.module_utils._text import to_bytes from ansible_collections.cisco.ios.plugins.cliconf import ios -from ansible_collections.cisco.ios.tests.unit.compat import unittest b_FIXTURE_DIR = b"%s/fixtures/ios" % ( @@ -49,7 +50,9 @@ def _connection_side_effect(*args, **kwargs): else: value = kwargs.get("command") - fixture_path = path.abspath(b"%s/%s" % (b_FIXTURE_DIR, b"_".join(value.split(b" ")))) + fixture_path = path.abspath( + b"%s/%s" % (b_FIXTURE_DIR, b"_".join(value.split(b" "))), + ) with open(fixture_path, "rb") as file_desc: return file_desc.read() except (OSError, IOError): @@ -63,7 +66,7 @@ def _connection_side_effect(*args, **kwargs): return "Nope" -class TestPluginCLIConfIOS(unittest.TestCase): +class TestPluginCLIConfIOS(TestCase): """Test class for IOS CLI Conf Methods""" def setUp(self):