From 9d2357703fe6aaa99854df8a405811eaa2cc0e9c Mon Sep 17 00:00:00 2001 From: KB-perByte Date: Wed, 27 Mar 2024 10:43:10 +0530 Subject: [PATCH] py27 compats no longer needed --- tests/unit/compat/__init__.py | 0 tests/unit/compat/mock.py | 28 -- tests/unit/compat/unittest.py | 41 --- tests/unit/mock/path.py | 8 +- tests/unit/mock/procenv.py | 10 +- .../network/ios/test_ios_acl_interfaces.py | 8 +- .../unit/modules/network/ios/test_ios_acls.py | 12 +- .../modules/network/ios/test_ios_banner.py | 10 +- .../ios/test_ios_bgp_address_family.py | 67 +++-- .../network/ios/test_ios_bgp_global.py | 12 +- .../modules/network/ios/test_ios_command.py | 18 +- .../modules/network/ios/test_ios_config.py | 40 ++- .../network/ios/test_ios_evpn_global.py | 7 +- .../modules/network/ios/test_ios_facts.py | 40 ++- .../modules/network/ios/test_ios_hostname.py | 8 +- .../network/ios/test_ios_interfaces.py | 35 ++- .../network/ios/test_ios_l2_interfaces.py | 51 +++- .../network/ios/test_ios_l3_interfaces.py | 7 +- .../unit/modules/network/ios/test_ios_lacp.py | 12 +- .../network/ios/test_ios_lacp_interfaces.py | 47 +++- .../network/ios/test_ios_lag_interfaces.py | 49 +++- .../network/ios/test_ios_lldp_global.py | 18 +- .../network/ios/test_ios_lldp_inteface.py | 16 +- .../network/ios/test_ios_logging_global.py | 64 ++++- .../unit/modules/network/ios/test_ios_ntp.py | 3 +- .../network/ios/test_ios_ntp_global.py | 95 +++++-- .../network/ios/test_ios_ospf_interfaces.py | 7 +- .../modules/network/ios/test_ios_ospfv2.py | 84 ++++-- .../modules/network/ios/test_ios_ospfv3.py | 35 ++- .../unit/modules/network/ios/test_ios_ping.py | 7 +- .../network/ios/test_ios_prefix_lists.py | 154 +++++++++-- .../network/ios/test_ios_route_maps.py | 48 +++- .../modules/network/ios/test_ios_service.py | 7 +- .../network/ios/test_ios_snmp_server.py | 242 ++++++++++++++---- .../network/ios/test_ios_static_routes.py | 50 +++- .../modules/network/ios/test_ios_system.py | 15 +- .../unit/modules/network/ios/test_ios_user.py | 23 +- .../modules/network/ios/test_ios_vlans.py | 7 +- .../unit/modules/network/ios/test_ios_vrf.py | 51 +++- .../network/ios/test_ios_vxlan_vtep.py | 7 +- 40 files changed, 1054 insertions(+), 389 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..49b5f854a 100644 --- a/tests/unit/mock/path.py +++ b/tests/unit/mock/path.py @@ -2,9 +2,11 @@ __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..a0aa41e1b 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,11 @@ __metaclass__ = type - +from unittest.mock import patch from textwrap import dedent 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 @@ -27,7 +27,9 @@ def setUp(self): "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) - self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() + self.get_resource_connection_facts = ( + self.mock_get_resource_connection_facts.start() + ) self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.acl_interfaces.acl_interfaces." diff --git a/tests/unit/modules/network/ios/test_ios_acls.py b/tests/unit/modules/network/ios/test_ios_acls.py index 5be581a7a..c0a374cb0 100644 --- a/tests/unit/modules/network/ios/test_ios_acls.py +++ b/tests/unit/modules/network/ios/test_ios_acls.py @@ -7,11 +7,11 @@ __metaclass__ = type - +from unittest.mock import patch from textwrap import dedent 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 @@ -27,7 +27,9 @@ def setUp(self): "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) - self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() + self.get_resource_connection_facts = ( + self.mock_get_resource_connection_facts.start() + ) self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.acls.acls." @@ -38,7 +40,9 @@ def setUp(self): "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.acls.acls." "AclsFacts.get_acl_names", ) - self.execute_show_command_name = self.mock_execute_show_command_name_specific.start() + self.execute_show_command_name = ( + self.mock_execute_show_command_name_specific.start() + ) def tearDown(self): super(TestIosAclsModule, self).tearDown() diff --git a/tests/unit/modules/network/ios/test_ios_banner.py b/tests/unit/modules/network/ios/test_ios_banner.py index 85e2736f0..bdb2a9258 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..3033ac118 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,11 @@ __metaclass__ = type - +from unittest.mock import patch from textwrap import dedent 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 @@ -27,7 +27,9 @@ def setUp(self): "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) - self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() + self.get_resource_connection_facts = ( + self.mock_get_resource_connection_facts.start() + ) self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.bgp_address_family.bgp_address_family." @@ -119,8 +121,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 +134,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 +325,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 +441,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 +551,16 @@ 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 +730,16 @@ 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 +962,9 @@ 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..a74413ccb 100644 --- a/tests/unit/modules/network/ios/test_ios_bgp_global.py +++ b/tests/unit/modules/network/ios/test_ios_bgp_global.py @@ -7,12 +7,14 @@ __metaclass__ = type - +from unittest.mock import patch from textwrap import dedent 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 ansible_collections.cisco.ios.tests.unit.modules.utils import ( + AnsibleFailJson, + set_module_args, +) from .ios_module import TestIosModule @@ -27,7 +29,9 @@ def setUp(self): "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) - self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() + self.get_resource_connection_facts = ( + self.mock_get_resource_connection_facts.start() + ) self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.bgp_global.bgp_global." diff --git a/tests/unit/modules/network/ios/test_ios_command.py b/tests/unit/modules/network/ios/test_ios_command.py index 42fee4028..24b2aeb41 100644 --- a/tests/unit/modules/network/ios/test_ios_command.py +++ b/tests/unit/modules/network/ios/test_ios_command.py @@ -20,11 +20,10 @@ __metaclass__ = type - +from unittest.mock import patch import json 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 +96,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..fd4ddd1a3 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,9 @@ 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 +139,9 @@ 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 +151,9 @@ 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 +162,22 @@ 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 +254,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 +278,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_global.py b/tests/unit/modules/network/ios/test_ios_evpn_global.py index d3bfa1585..0ed0c93d3 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 unittest.mock import patch from textwrap import dedent 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 @@ -27,7 +26,9 @@ def setUp(self): "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) - self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() + self.get_resource_connection_facts = ( + self.mock_get_resource_connection_facts.start() + ) self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.evpn_global.evpn_global." diff --git a/tests/unit/modules/network/ios/test_ios_facts.py b/tests/unit/modules/network/ios/test_ios_facts.py index c951b58b2..ec4ae08ea 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,12 @@ 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"], @@ -95,30 +99,38 @@ def test_ios_facts_tunnel_address_and_lineprotocol(self): set_module_args(dict(gather_subset="interfaces")) result = self.execute_module() self.assertEqual( - result["ansible_facts"]["ansible_net_interfaces"]["GigabitEthernet0/0/0.1012"][ - "macaddress" - ], + result["ansible_facts"]["ansible_net_interfaces"][ + "GigabitEthernet0/0/0.1012" + ]["macaddress"], "5e00.0003.0000", ) self.assertEqual( - result["ansible_facts"]["ansible_net_interfaces"]["GigabitEthernet0/0"]["macaddress"], + result["ansible_facts"]["ansible_net_interfaces"]["GigabitEthernet0/0"][ + "macaddress" + ], "5e00.0008.0000", ) self.assertEqual( - result["ansible_facts"]["ansible_net_interfaces"]["GigabitEthernet1"]["macaddress"], + result["ansible_facts"]["ansible_net_interfaces"]["GigabitEthernet1"][ + "macaddress" + ], "5e00.0006.0000", ) self.assertIsNone( - result["ansible_facts"]["ansible_net_interfaces"]["Tunnel1110"]["macaddress"], + result["ansible_facts"]["ansible_net_interfaces"]["Tunnel1110"][ + "macaddress" + ], ) self.assertEqual( - result["ansible_facts"]["ansible_net_interfaces"]["GigabitEthernet1"]["lineprotocol"], + result["ansible_facts"]["ansible_net_interfaces"]["GigabitEthernet1"][ + "lineprotocol" + ], "up", ) self.assertEqual( - result["ansible_facts"]["ansible_net_interfaces"]["TenGigabitEthernet2/5/5"][ - "lineprotocol" - ], + result["ansible_facts"]["ansible_net_interfaces"][ + "TenGigabitEthernet2/5/5" + ]["lineprotocol"], "down", ) diff --git a/tests/unit/modules/network/ios/test_ios_hostname.py b/tests/unit/modules/network/ios/test_ios_hostname.py index 6b16bddf0..081a542ff 100644 --- a/tests/unit/modules/network/ios/test_ios_hostname.py +++ b/tests/unit/modules/network/ios/test_ios_hostname.py @@ -7,11 +7,11 @@ __metaclass__ = type - +from unittest.mock import patch from textwrap import dedent 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 @@ -27,7 +27,9 @@ def setUp(self): "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) - self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() + self.get_resource_connection_facts = ( + self.mock_get_resource_connection_facts.start() + ) self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.hostname.hostname." diff --git a/tests/unit/modules/network/ios/test_ios_interfaces.py b/tests/unit/modules/network/ios/test_ios_interfaces.py index caac40ccb..f9964b985 100644 --- a/tests/unit/modules/network/ios/test_ios_interfaces.py +++ b/tests/unit/modules/network/ios/test_ios_interfaces.py @@ -7,11 +7,11 @@ __metaclass__ = type - +from unittest.mock import patch from textwrap import dedent 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 @@ -27,7 +27,9 @@ def setUp(self): "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) - self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() + self.get_resource_connection_facts = ( + self.mock_get_resource_connection_facts.start() + ) self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.interfaces.interfaces." @@ -150,7 +152,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 +209,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 +275,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 +581,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..9b56c2c52 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 unittest.mock import patch from textwrap import dedent 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 @@ -27,7 +26,9 @@ def setUp(self): "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) - self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() + self.get_resource_connection_facts = ( + self.mock_get_resource_connection_facts.start() + ) self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.l2_interfaces.l2_interfaces." @@ -136,7 +137,9 @@ 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,9 @@ 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 +286,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 +425,9 @@ 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 +438,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 +607,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 +714,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 +756,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..821bd02ea 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 unittest.mock import patch from textwrap import dedent 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 @@ -27,7 +26,9 @@ def setUp(self): "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) - self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() + self.get_resource_connection_facts = ( + self.mock_get_resource_connection_facts.start() + ) self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.l3_interfaces.l3_interfaces." diff --git a/tests/unit/modules/network/ios/test_ios_lacp.py b/tests/unit/modules/network/ios/test_ios_lacp.py index 6c56406e6..2314e273a 100644 --- a/tests/unit/modules/network/ios/test_ios_lacp.py +++ b/tests/unit/modules/network/ios/test_ios_lacp.py @@ -7,11 +7,11 @@ __metaclass__ = type - +from unittest.mock import patch from textwrap import dedent 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 @@ -37,13 +37,17 @@ def setUp(self): "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base." "get_resource_connection", ) - self.get_resource_connection_config = self.mock_get_resource_connection_config.start() + self.get_resource_connection_config = ( + self.mock_get_resource_connection_config.start() + ) self.mock_get_resource_connection_facts = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) - self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() + self.get_resource_connection_facts = ( + self.mock_get_resource_connection_facts.start() + ) self.mock_edit_config = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.providers.providers.CliProvider.edit_config", 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..061e71af1 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 unittest.mock import patch from textwrap import dedent 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 @@ -37,13 +36,17 @@ def setUp(self): "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base." "get_resource_connection", ) - self.get_resource_connection_config = self.mock_get_resource_connection_config.start() + self.get_resource_connection_config = ( + self.mock_get_resource_connection_config.start() + ) self.mock_get_resource_connection_facts = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) - self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() + self.get_resource_connection_facts = ( + self.mock_get_resource_connection_facts.start() + ) self.mock_edit_config = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.providers.providers.CliProvider.edit_config", @@ -83,7 +86,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 +128,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 +161,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 +203,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 +245,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 +310,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..742553cf4 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 unittest.mock import patch from textwrap import dedent 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 @@ -27,7 +26,9 @@ def setUp(self): "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) - self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() + self.get_resource_connection_facts = ( + self.mock_get_resource_connection_facts.start() + ) self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.lag_interfaces.lag_interfaces." @@ -73,7 +74,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 +125,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 +173,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 +232,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 +276,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 +335,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 +484,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..88b0cf476 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 unittest.mock import patch from textwrap import dedent 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 @@ -37,13 +36,17 @@ def setUp(self): "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base." "get_resource_connection", ) - self.get_resource_connection_config = self.mock_get_resource_connection_config.start() + self.get_resource_connection_config = ( + self.mock_get_resource_connection_config.start() + ) self.mock_get_resource_connection_facts = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) - self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() + self.get_resource_connection_facts = ( + self.mock_get_resource_connection_facts.start() + ) self.mock_edit_config = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.providers.providers.CliProvider.edit_config", @@ -154,7 +157,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..a778d3ecb 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 unittest.mock import patch from textwrap import dedent 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 @@ -37,13 +36,17 @@ def setUp(self): "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base." "get_resource_connection", ) - self.get_resource_connection_config = self.mock_get_resource_connection_config.start() + self.get_resource_connection_config = ( + self.mock_get_resource_connection_config.start() + ) self.mock_get_resource_connection_facts = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) - self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() + self.get_resource_connection_facts = ( + self.mock_get_resource_connection_facts.start() + ) self.mock_edit_config = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.providers.providers.CliProvider.edit_config", @@ -241,7 +244,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..5aefeb2b7 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 unittest.mock import patch from textwrap import dedent 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 @@ -27,7 +26,9 @@ def setUp(self): "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) - self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() + self.get_resource_connection_facts = ( + self.mock_get_resource_connection_facts.start() + ) self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.logging_global.logging_global." @@ -120,7 +121,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 +254,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 +324,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 +412,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 +433,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 +528,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 +642,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 +681,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..b4102cdb7 100644 --- a/tests/unit/modules/network/ios/test_ios_ntp.py +++ b/tests/unit/modules/network/ios/test_ios_ntp.py @@ -18,9 +18,8 @@ __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..3e04b0a2a 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 unittest.mock import patch from textwrap import dedent 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 @@ -27,7 +26,9 @@ def setUp(self): "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) - self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() + self.get_resource_connection_facts = ( + self.mock_get_resource_connection_facts.start() + ) self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.ntp_global.ntp_global." @@ -86,7 +87,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 +104,16 @@ 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,12 @@ 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 +188,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 +353,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 +370,12 @@ 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 +385,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 +456,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 +472,26 @@ 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..26ccf6d5c 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 unittest.mock import patch from textwrap import dedent 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 @@ -27,7 +26,9 @@ def setUp(self): "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) - self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() + self.get_resource_connection_facts = ( + self.mock_get_resource_connection_facts.start() + ) self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.ospf_interfaces.ospf_interfaces." diff --git a/tests/unit/modules/network/ios/test_ios_ospfv2.py b/tests/unit/modules/network/ios/test_ios_ospfv2.py index a8bc97105..922f0d014 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 unittest.mock import patch from textwrap import dedent 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 @@ -27,7 +26,9 @@ def setUp(self): "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) - self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() + self.get_resource_connection_facts = ( + self.mock_get_resource_connection_facts.start() + ) self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.ospfv2.ospfv2." @@ -76,13 +77,23 @@ 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 +295,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 +487,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 +622,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 +656,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 +705,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 +896,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 +1067,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 +1185,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..1f0ba626c 100644 --- a/tests/unit/modules/network/ios/test_ios_ospfv3.py +++ b/tests/unit/modules/network/ios/test_ios_ospfv3.py @@ -7,9 +7,8 @@ __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 @@ -25,7 +24,9 @@ def setUp(self): "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) - self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() + self.get_resource_connection_facts = ( + self.mock_get_resource_connection_facts.start() + ) self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.ospfv3.ospfv3." @@ -58,7 +59,9 @@ 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,9 @@ 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 +171,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 +214,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 +267,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 +300,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..f10694f97 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 unittest.mock import patch from textwrap import dedent 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..7812ce8d1 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,8 @@ __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 @@ -25,7 +24,9 @@ def setUp(self): "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) - self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() + self.get_resource_connection_facts = ( + self.mock_get_resource_connection_facts.start() + ) self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.prefix_lists.prefix_lists." @@ -74,7 +75,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 +127,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 +158,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 +177,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 +221,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 +240,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 +296,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 +327,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 +346,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 +390,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 +409,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 +467,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 +498,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 +517,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 +592,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..aba125136 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,8 @@ __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 @@ -25,7 +24,9 @@ def setUp(self): "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) - self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() + self.get_resource_connection_facts = ( + self.mock_get_resource_connection_facts.start() + ) self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.route_maps.route_maps." @@ -58,7 +59,9 @@ 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,9 @@ 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 +426,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 +465,9 @@ 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 +636,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 +692,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 +721,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 +748,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..526056b84 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 unittest.mock import patch from textwrap import dedent 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 @@ -27,7 +26,9 @@ def setUp(self): "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) - self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() + self.get_resource_connection_facts = ( + self.mock_get_resource_connection_facts.start() + ) self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.service.service." 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..ae42fa53e 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 unittest.mock import patch from textwrap import dedent 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 @@ -26,7 +25,9 @@ def setUp(self): "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) - self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() + self.get_resource_connection_facts = ( + self.mock_get_resource_connection_facts.start() + ) self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.snmp_server.snmp_server." @@ -168,10 +169,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 +192,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 +235,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 +326,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 +384,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 +397,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 +477,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 +496,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 +539,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 +640,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 +698,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 +1195,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 +1218,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 +1259,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 +1350,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 +1408,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 +1509,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 +1565,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 +1653,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 +1750,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 +1803,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 +1902,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 +1959,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 +1974,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..9c28648e6 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 unittest.mock import patch from textwrap import dedent 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 @@ -27,7 +26,9 @@ def setUp(self): "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) - self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() + self.get_resource_connection_facts = ( + self.mock_get_resource_connection_facts.start() + ) self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.static_routes.static_routes." @@ -232,7 +233,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 +426,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 +646,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 +839,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 +1059,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 +1252,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 +1735,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 +1861,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 +2151,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..23908ccfa 100644 --- a/tests/unit/modules/network/ios/test_ios_system.py +++ b/tests/unit/modules/network/ios/test_ios_system.py @@ -21,9 +21,8 @@ __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 +69,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 +111,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..b62041b57 100644 --- a/tests/unit/modules/network/ios/test_ios_user.py +++ b/tests/unit/modules/network/ios/test_ios_user.py @@ -20,9 +20,8 @@ __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 +116,24 @@ 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"]) @@ -158,7 +163,9 @@ def test_ios_user_set_sshkey_multiple(self): self.assertEqual(result["commands"], commands) def test_add_hashed_password(self): - hashed_password_val = "replacementforhashwhichissupposedtogohereonlyfortestingpurposes" + hashed_password_val = ( + "replacementforhashwhichissupposedtogohereonlyfortestingpurposes" + ) set_module_args( dict( name="ansible", @@ -169,7 +176,9 @@ 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..fd054b2d0 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 unittest.mock import patch from textwrap import dedent 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 @@ -27,7 +26,9 @@ def setUp(self): "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) - self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() + self.get_resource_connection_facts = ( + self.mock_get_resource_connection_facts.start() + ) self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.vlans.vlans." diff --git a/tests/unit/modules/network/ios/test_ios_vrf.py b/tests/unit/modules/network/ios/test_ios_vrf.py index d36ea41e1..555937d1c 100644 --- a/tests/unit/modules/network/ios/test_ios_vrf.py +++ b/tests/unit/modules/network/ios/test_ios_vrf.py @@ -21,9 +21,8 @@ __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 +57,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 +161,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 +185,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 +197,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 +221,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 +296,9 @@ 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 +318,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 +338,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 +411,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..7ef344fec 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 unittest.mock import patch from textwrap import dedent 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 @@ -27,7 +26,9 @@ def setUp(self): "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) - self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() + self.get_resource_connection_facts = ( + self.mock_get_resource_connection_facts.start() + ) self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.vxlan_vtep.vxlan_vtep."