summaryrefslogtreecommitdiffstats
path: root/ansible_collections/cisco/ios/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'ansible_collections/cisco/ios/tests/unit')
-rw-r--r--ansible_collections/cisco/ios/tests/unit/compat/__init__.py0
-rw-r--r--ansible_collections/cisco/ios/tests/unit/compat/mock.py28
-rw-r--r--ansible_collections/cisco/ios/tests/unit/compat/unittest.py41
-rw-r--r--ansible_collections/cisco/ios/tests/unit/mock/path.py9
-rw-r--r--ansible_collections/cisco/ios/tests/unit/mock/procenv.py10
-rw-r--r--ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_show_interfaces31
-rw-r--r--ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_acl_interfaces.py3
-rw-r--r--ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_acls.py610
-rw-r--r--ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_banner.py8
-rw-r--r--ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_bgp.py344
-rw-r--r--ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_bgp_address_family.py65
-rw-r--r--ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_bgp_global.py284
-rw-r--r--ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_command.py19
-rw-r--r--ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_config.py43
-rw-r--r--ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_evpn_evi.py3
-rw-r--r--ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_evpn_global.py3
-rw-r--r--ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_facts.py20
-rw-r--r--ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_hostname.py3
-rw-r--r--ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_interfaces.py30
-rw-r--r--ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_l2_interfaces.py53
-rw-r--r--ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_l3_interfaces.py108
-rw-r--r--ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lacp.py3
-rw-r--r--ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lacp_interfaces.py39
-rw-r--r--ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lag_interfaces.py45
-rw-r--r--ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lldp_global.py10
-rw-r--r--ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lldp_inteface.py8
-rw-r--r--ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_logging_global.py60
-rw-r--r--ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ntp.py110
-rw-r--r--ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ntp_global.py107
-rw-r--r--ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ospf_interfaces.py3
-rw-r--r--ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ospfv2.py83
-rw-r--r--ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ospfv3.py32
-rw-r--r--ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ping.py7
-rw-r--r--ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_prefix_lists.py149
-rw-r--r--ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_route_maps.py46
-rw-r--r--ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_service.py3
-rw-r--r--ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_snmp_server.py290
-rw-r--r--ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_static_routes.py46
-rw-r--r--ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_system.py14
-rw-r--r--ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_user.py66
-rw-r--r--ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_vlans.py828
-rw-r--r--ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_vrf.py52
-rw-r--r--ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_vxlan_vtep.py3
-rw-r--r--ansible_collections/cisco/ios/tests/unit/modules/utils.py8
-rw-r--r--ansible_collections/cisco/ios/tests/unit/plugins/cliconf/test_ios.py9
45 files changed, 2680 insertions, 1056 deletions
diff --git a/ansible_collections/cisco/ios/tests/unit/compat/__init__.py b/ansible_collections/cisco/ios/tests/unit/compat/__init__.py
deleted file mode 100644
index e69de29bb..000000000
--- a/ansible_collections/cisco/ios/tests/unit/compat/__init__.py
+++ /dev/null
diff --git a/ansible_collections/cisco/ios/tests/unit/compat/mock.py b/ansible_collections/cisco/ios/tests/unit/compat/mock.py
deleted file mode 100644
index e25e8381b..000000000
--- a/ansible_collections/cisco/ios/tests/unit/compat/mock.py
+++ /dev/null
@@ -1,28 +0,0 @@
-# pylint: skip-file
-# (c) 2014, Toshio Kuratomi <tkuratomi@ansible.com>
-#
-# 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 <http://www.gnu.org/licenses/>.
-
-# 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/ansible_collections/cisco/ios/tests/unit/compat/unittest.py b/ansible_collections/cisco/ios/tests/unit/compat/unittest.py
deleted file mode 100644
index df4266ec9..000000000
--- a/ansible_collections/cisco/ios/tests/unit/compat/unittest.py
+++ /dev/null
@@ -1,41 +0,0 @@
-# (c) 2014, Toshio Kuratomi <tkuratomi@ansible.com>
-#
-# 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 <http://www.gnu.org/licenses/>.
-
-# 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/ansible_collections/cisco/ios/tests/unit/mock/path.py b/ansible_collections/cisco/ios/tests/unit/mock/path.py
index ce2eb1fe0..7d287a5fb 100644
--- a/ansible_collections/cisco/ios/tests/unit/mock/path.py
+++ b/ansible_collections/cisco/ios/tests/unit/mock/path.py
@@ -2,9 +2,12 @@ from __future__ import absolute_import, division, print_function
__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/ansible_collections/cisco/ios/tests/unit/mock/procenv.py b/ansible_collections/cisco/ios/tests/unit/mock/procenv.py
index 111c319c2..e6e09464b 100644
--- a/ansible_collections/cisco/ios/tests/unit/mock/procenv.py
+++ b/ansible_collections/cisco/ios/tests/unit/mock/procenv.py
@@ -27,12 +27,11 @@ import sys
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/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_show_interfaces b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_show_interfaces
index 9888c8e22..e2ee95fbd 100644
--- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_show_interfaces
+++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_show_interfaces
@@ -1,4 +1,4 @@
-GigabitEthernet0/0 is up, line protocol is up
+GigabitEthernet0/0/0.1012 is up, line protocol is up
Hardware is iGbE, address is 5e00.0003.0000 (bia 5e00.0003.0000)
Description: OOB Management
Internet address is 10.8.38.66/24
@@ -27,6 +27,35 @@ GigabitEthernet0/0 is up, line protocol is up
0 babbles, 0 late collision, 0 deferred
1 lost carrier, 0 no carrier, 0 pause output
0 output buffer failures, 0 output buffers swapped out
+GigabitEthernet0/0 is up, line protocol is up
+ Hardware is iGbE, address is 5e00.0008.0000 (bia 5e00.0008.0000)
+ Description: OOB Management
+ Internet address is 10.8.38.66/24
+ MTU 1500 bytes, BW 1000000 Kbit/sec, DLY 10 usec,
+ reliability 253/255, txload 1/255, rxload 1/255
+ Encapsulation ARPA, loopback not set
+ Keepalive set (10 sec)
+ Full Duplex, Auto Speed, link type is auto, media type is RJ45
+ output flow-control is unsupported, input flow-control is unsupported
+ ARP type: ARPA, ARP Timeout 04:00:00
+ Last input 00:00:00, output 00:00:00, output hang never
+ Last clearing of "show interface" counters never
+ Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0
+ Queueing strategy: fifo
+ Output queue: 0/40 (size/max)
+ 5 minute input rate 3000 bits/sec, 2 packets/sec
+ 5 minute output rate 2000 bits/sec, 2 packets/sec
+ 8463791 packets input, 1445150230 bytes, 0 no buffer
+ Received 0 broadcasts (0 IP multicasts)
+ 0 runts, 0 giants, 0 throttles
+ 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored
+ 0 watchdog, 0 multicast, 0 pause input
+ 3521571 packets output, 348781823 bytes, 0 underruns
+ 0 output errors, 0 collisions, 1 interface resets
+ 4150764 unknown protocol drops
+ 0 babbles, 0 late collision, 0 deferred
+ 1 lost carrier, 0 no carrier, 0 pause output
+ 0 output buffer failures, 0 output buffers swapped out
GigabitEthernet1 is up, line protocol is up
Hardware is CSR vNIC, address is 5e00.0006.0000 (bia 5e00.0006.0000)
Description: OOB Management
diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_acl_interfaces.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_acl_interfaces.py
index 6bc99691c..3c8567797 100644
--- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_acl_interfaces.py
+++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_acl_interfaces.py
@@ -7,11 +7,10 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-
from textwrap import dedent
+from unittest.mock import patch
from ansible_collections.cisco.ios.plugins.modules import ios_acl_interfaces
-from ansible_collections.cisco.ios.tests.unit.compat.mock import patch
from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args
from .ios_module import TestIosModule
diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_acls.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_acls.py
index 33c4a1ddb..36d96365a 100644
--- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_acls.py
+++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_acls.py
@@ -7,11 +7,10 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-
from textwrap import dedent
+from unittest.mock import patch
from ansible_collections.cisco.ios.plugins.modules import ios_acls
-from ansible_collections.cisco.ios.tests.unit.compat.mock import patch
from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args
from .ios_module import TestIosModule
@@ -91,7 +90,10 @@ class TestIosAclsModule(TestIosModule):
aces=[
dict(
grant="deny",
- source=dict(address="192.0.2.0", wildcard_bits="0.0.0.255"),
+ source=dict(
+ address="192.0.2.0",
+ wildcard_bits="0.0.0.255",
+ ),
),
],
),
@@ -137,7 +139,9 @@ class TestIosAclsModule(TestIosModule):
protocol_options=dict(tcp=dict(ack="True")),
sequence="200",
source=dict(object_group="test_network_og"),
- destination=dict(object_group="test_network_og"),
+ destination=dict(
+ object_group="test_network_og",
+ ),
dscp="ef",
ttl=dict(eq=10),
),
@@ -223,7 +227,10 @@ class TestIosAclsModule(TestIosModule):
{
"aces": [
{
- "destination": {"any": True, "port_protocol": {"eq": "22"}},
+ "destination": {
+ "any": True,
+ "port_protocol": {"eq": "22"},
+ },
"grant": "permit",
"protocol": "tcp",
"sequence": 10,
@@ -233,14 +240,20 @@ class TestIosAclsModule(TestIosModule):
},
},
{
- "destination": {"any": True, "port_protocol": {"eq": "22"}},
+ "destination": {
+ "any": True,
+ "port_protocol": {"eq": "22"},
+ },
"grant": "permit",
"protocol": "tcp",
"sequence": 20,
"source": {"host": "10.160.114.111"},
},
{
- "destination": {"any": True, "port_protocol": {"eq": "22"}},
+ "destination": {
+ "any": True,
+ "port_protocol": {"eq": "22"},
+ },
"grant": "permit",
"protocol": "tcp",
"sequence": 30,
@@ -361,7 +374,9 @@ class TestIosAclsModule(TestIosModule):
"grant": "permit",
"protocol": "ipv6",
"sequence": 10,
- "source": {"address": "2001:ABAD:BEEF:1221::/64"},
+ "source": {
+ "address": "2001:ABAD:BEEF:1221::/64",
+ },
},
{
"destination": {
@@ -380,7 +395,10 @@ class TestIosAclsModule(TestIosModule):
"aces": [
{"remarks": ["empty remark 1"], "sequence": 10},
{"remarks": ["empty remark 2"], "sequence": 20},
- {"remarks": ["empty remark never ends"], "sequence": 30},
+ {
+ "remarks": ["empty remark never ends"],
+ "sequence": 30,
+ },
],
"name": "empty_ipv6_acl",
},
@@ -402,7 +420,10 @@ class TestIosAclsModule(TestIosModule):
"sequence": 40,
"source": {"any": True},
},
- {"remarks": ["I am new set of ipv6 ace"], "sequence": 50},
+ {
+ "remarks": ["I am new set of ipv6 ace"],
+ "sequence": 50,
+ },
{
"destination": {"any": True},
"grant": "permit",
@@ -422,64 +443,58 @@ class TestIosAclsModule(TestIosModule):
)
result = self.execute_module(changed=True)
commands = [
- "ip access-list extended mytest",
- "remark I am a test ace",
- "remark I am right after the test ace",
- "remark I third the test ace",
- "100 permit ip host 100.100.100.100 any",
- "remark I am the next test ace",
- "remark I am the next ace to the next ace",
- "110 permit ip host 10.40.150.0 any",
- "remark I am the peace ace",
- "remark Peace out",
"ip access-list extended 199",
"10 permit ip 10.40.150.0 0.0.0.255 any",
"20 permit ip any 10.40.150.0 0.0.0.255",
+ "ip access-list standard 42",
+ "10 permit 10.182.250.0 0.0.0.255",
+ "ip access-list extended empty_ip_ex_acl",
+ "remark empty remark 1",
+ "remark empty remark 2",
+ "remark empty remark never ends",
"ip access-list extended NET-MGMT-VTY",
"10 permit tcp 10.57.66.243 0.0.0.7 any eq 22",
"20 permit tcp host 10.160.114.111 any eq 22",
"30 permit tcp host 10.160.115.22 any eq 22",
"40 deny ip any any log",
- "ip access-list extended empty_ip_ex_acl",
- "remark empty remark 1",
- "remark empty remark 2",
- "remark empty remark never ends",
+ "ip access-list extended mytest",
+ "100 remark I am a test ace",
+ "100 remark I am right after the test ace",
+ "100 remark I third the test ace",
+ "100 permit ip host 100.100.100.100 any",
+ "110 remark I am the next test ace",
+ "110 remark I am the next ace to the next ace",
+ "110 permit ip host 10.40.150.0 any",
+ "remark I am the peace ace",
+ "remark Peace out",
"ip access-list extended TEST",
- "remark FIRST REMARK BEFORE LINE 10",
- "remark ============",
- "remark ALLOW HOST FROM BUILDING 10",
+ "10 remark FIRST REMARK BEFORE LINE 10",
+ "10 remark ============",
+ "10 remark ALLOW HOST FROM BUILDING 10",
"10 permit ip host 1.1.1.1 any",
- "remark FIRST REMARK BEFORE LINE 20",
- "remark ============",
- "remark ALLOW HOST FROM BUILDING 20",
+ "20 remark FIRST REMARK BEFORE LINE 20",
+ "20 remark ============",
+ "20 remark ALLOW HOST FROM BUILDING 20",
"20 permit ip host 2.2.2.2 any",
- "remark FIRST REMARK BEFORE LINE 30",
- "remark ============",
- "remark ALLOW NEW HOST FROM BUILDING 10",
+ "30 remark FIRST REMARK BEFORE LINE 30",
+ "30 remark ============",
+ "30 remark ALLOW NEW HOST FROM BUILDING 10",
"30 permit ip host 3.3.3.3 any",
"remark FIRST REMARK AT END OF ACL",
"remark SECOND REMARK AT END OF ACL",
- "ip access-list standard 42",
- "10 permit 10.182.250.0 0.0.0.255",
"ipv6 access-list R1_TRAFFIC",
"permit ipv6 2001:ABAD:BEEF:1221::/64 any sequence 10",
"deny tcp host 2001:ABAD:BEEF:2345::1 host 2001:ABAD:BEEF:1212::1 eq www sequence 20",
"ipv6 access-list empty_ipv6_acl",
- "remark empty remark 1",
- " sequence 10",
- "remark empty remark 2",
- " sequence 20",
- "remark empty remark never ends",
- " sequence 30",
+ "10 remark empty remark 1",
+ "20 remark empty remark 2",
+ "30 remark empty remark never ends",
"ipv6 access-list ipv6_acl",
- "remark I am a ipv6 ace",
- " sequence 10",
- "remark I am test",
- " sequence 20",
+ "10 remark I am a ipv6 ace",
+ "20 remark I am test",
"permit tcp any any sequence 30",
"permit udp any any sequence 40",
- "remark I am new set of ipv6 ace",
- " sequence 50",
+ "50 remark I am new set of ipv6 ace",
"permit icmp any any sequence 60",
]
self.assertEqual(sorted(result["commands"]), sorted(commands))
@@ -518,7 +533,10 @@ class TestIosAclsModule(TestIosModule):
"sequence": 10,
"grant": "deny",
"protocol": "tcp",
- "source": {"any": True, "port_protocol": {"eq": "www"}},
+ "source": {
+ "any": True,
+ "port_protocol": {"eq": "www"},
+ },
"destination": {
"any": True,
"port_protocol": {"eq": "telnet"},
@@ -536,7 +554,6 @@ class TestIosAclsModule(TestIosModule):
)
result = self.execute_module(changed=False)
self.assertEqual(sorted(result["commands"]), [])
- # self.execute_module(changed=False, commands=[], sort=True)
def test_ios_acls_replaced(self):
self.execute_show_command.return_value = dedent(
@@ -550,11 +567,23 @@ class TestIosAclsModule(TestIosModule):
ip access-list standard test_acl
remark remark check 1
remark some random remark 2
+ ip access-list standard testRobustReplace
+ 10 remark Remarks for 10
+ 10 permit 192.168.1.0 0.0.0.255
+ 20 remark Remarks for 20
+ 20 permit 0.0.0.0 255.0.0.0
+ 30 remark Remarks for 30
+ 30 permit 172.16.0.0 0.15.255.255
+ 40 remark Remarks for 40
+ 40 permit 192.0.2.0 0.0.0.255
+ 50 remark Remarks for 50
+ 50 permit 198.51.100.0 0.0.0.255
""",
)
self.execute_show_command_name.return_value = dedent(
"""\
Standard IP access list test_acl
+ Standard IP access list testRobustReplace
""",
)
set_module_args(
@@ -588,6 +617,21 @@ class TestIosAclsModule(TestIosModule):
acl_type="standard",
aces=[dict(remarks=["Another remark here"])],
),
+ dict(
+ name="testRobustReplace",
+ acl_type="standard",
+ aces=[
+ dict(
+ sequence=10,
+ grant="permit",
+ remarks=["Remarks for 10"],
+ source=dict(
+ address="192.168.1.0",
+ wildcard_bits="0.0.0.255",
+ ),
+ ),
+ ],
+ ),
],
),
],
@@ -599,9 +643,17 @@ class TestIosAclsModule(TestIosModule):
"ip access-list extended replace_acl",
"deny tcp 198.51.100.0 0.0.0.255 198.51.101.0 0.0.0.255 eq telnet ack tos min-monetary-cost",
"ip access-list standard test_acl",
- "no remark remark check 1",
- "no remark some random remark 2",
+ "no remark",
"remark Another remark here",
+ "ip access-list standard testRobustReplace",
+ "no 20 remark",
+ "no 20 permit 0.0.0.0 255.0.0.0",
+ "no 30 remark",
+ "no 30 permit 172.16.0.0 0.15.255.255",
+ "no 40 remark",
+ "no 40 permit 192.0.2.0 0.0.0.255",
+ "no 50 remark",
+ "no 50 permit 198.51.100.0 0.0.0.255",
]
self.assertEqual(sorted(result["commands"]), sorted(commands))
@@ -620,9 +672,21 @@ class TestIosAclsModule(TestIosModule):
ip access-list extended test-idem
10 permit ip host 10.153.14.21 any
20 permit ip host 10.153.14.22 any
+ ip access-list standard test-acl-no-seq
+ permit 10.0.0.0 0.255.255.255
+ permit 172.31.16.0 0.0.7.255
+ """,
+ )
+ self.execute_show_command_name.return_value = dedent(
+ """\
+ Standard IP access list test_acl
+ Standard IP access list test-acl-no-seq
+ Extended IP access list 110
+ Extended IP access list test-idem
+ Extended IP access list test_pre
+ IPv6 access list R1_TRAFFIC
""",
)
- self.execute_show_command_name.return_value = dedent("")
set_module_args(
dict(
config=[
@@ -641,7 +705,10 @@ class TestIosAclsModule(TestIosModule):
"address": "198.51.100.0",
"wildcard_bits": "0.0.0.255",
},
- "destination": {"any": True, "port_protocol": {"eq": "22"}},
+ "destination": {
+ "any": True,
+ "port_protocol": {"eq": "22"},
+ },
"log": {"set": True, "user_cookie": "testLog"},
},
{
@@ -706,6 +773,26 @@ class TestIosAclsModule(TestIosModule):
},
],
},
+ {
+ "name": "test-acl-no-seq",
+ "acl_type": "standard",
+ "aces": [
+ {
+ "grant": "permit",
+ "source": {
+ "address": "10.0.0.0",
+ "wildcard_bits": "0.255.255.255",
+ },
+ },
+ {
+ "grant": "permit",
+ "source": {
+ "address": "172.31.16.0",
+ "wildcard_bits": "0.0.7.255",
+ },
+ },
+ ],
+ },
],
},
{
@@ -718,7 +805,10 @@ class TestIosAclsModule(TestIosModule):
"sequence": 10,
"grant": "deny",
"protocol": "tcp",
- "source": {"any": True, "port_protocol": {"eq": "www"}},
+ "source": {
+ "any": True,
+ "port_protocol": {"eq": "www"},
+ },
"destination": {
"any": True,
"port_protocol": {"eq": "telnet"},
@@ -737,6 +827,64 @@ class TestIosAclsModule(TestIosModule):
result = self.execute_module(changed=False)
self.assertEqual(sorted(result["commands"]), [])
+ def test_ios_acls_replaced_changetype(self):
+ self.execute_show_command.return_value = dedent(
+ """\
+ ip access-list extended 110
+ 10 permit tcp 198.51.100.0 0.0.0.255 any eq 22 log (tag = testLog)
+ 20 deny icmp 192.0.2.0 0.0.0.255 192.0.3.0 0.0.0.255 echo dscp ef ttl eq 10
+ 30 deny icmp object-group test_network_og any dscp ef ttl eq 10
+ ip access-list standard test_acl
+ remark remark check 1
+ remark some random remark 2
+ """,
+ )
+ self.execute_show_command_name.return_value = dedent(
+ """\
+ Standard IP access list test_acl
+ """,
+ )
+ set_module_args(
+ dict(
+ config=[
+ dict(
+ afi="ipv4",
+ acls=[
+ dict(
+ name="110",
+ acl_type="standard",
+ aces=[
+ dict(
+ grant="deny",
+ source=dict(
+ address="198.51.100.0",
+ wildcard_bits="0.0.0.255",
+ ),
+ ),
+ ],
+ ),
+ dict(
+ name="test_acl",
+ acl_type="standard",
+ aces=[dict(remarks=["Another remark here"])],
+ ),
+ ],
+ ),
+ ],
+ state="replaced",
+ ),
+ )
+ result = self.execute_module(changed=True)
+ commands = [
+ "no ip access-list extended 110",
+ "ip access-list standard 110",
+ "deny 198.51.100.0 0.0.0.255",
+ "ip access-list standard test_acl",
+ "no remark",
+ "remark Another remark here",
+ ]
+ self.assertEqual(sorted(result["commands"]), sorted(commands))
+
def test_ios_acls_overridden(self):
self.execute_show_command.return_value = dedent(
"""\
@@ -831,7 +979,10 @@ class TestIosAclsModule(TestIosModule):
"address": "198.51.100.0",
"wildcard_bits": "0.0.0.255",
},
- "destination": {"any": True, "port_protocol": {"eq": "22"}},
+ "destination": {
+ "any": True,
+ "port_protocol": {"eq": "22"},
+ },
"log": {"set": True, "user_cookie": "testLog"},
},
{
@@ -874,7 +1025,10 @@ class TestIosAclsModule(TestIosModule):
"sequence": 10,
"grant": "deny",
"protocol": "tcp",
- "source": {"any": True, "port_protocol": {"eq": "www"}},
+ "source": {
+ "any": True,
+ "port_protocol": {"eq": "www"},
+ },
"destination": {
"any": True,
"port_protocol": {"eq": "telnet"},
@@ -909,7 +1063,10 @@ class TestIosAclsModule(TestIosModule):
self.execute_show_command_name.return_value = dedent("")
set_module_args(dict(config=[dict(afi="ipv4")], state="deleted"))
result = self.execute_module(changed=True)
- commands = ["no ip access-list extended 110", "no ip access-list standard test_acl"]
+ commands = [
+ "no ip access-list extended 110",
+ "no ip access-list standard test_acl",
+ ]
self.assertEqual(sorted(result["commands"]), sorted(commands))
def test_ios_acls_deleted_acl_based(self):
@@ -938,7 +1095,10 @@ class TestIosAclsModule(TestIosModule):
grant="deny",
protocol_options=dict(icmp=dict(echo="True")),
sequence="10",
- source=dict(address="192.0.2.0", wildcard_bits="0.0.0.255"),
+ source=dict(
+ address="192.0.2.0",
+ wildcard_bits="0.0.0.255",
+ ),
destination=dict(
address="192.0.3.0",
wildcard_bits="0.0.0.255",
@@ -960,7 +1120,10 @@ class TestIosAclsModule(TestIosModule):
grant="deny",
protocol_options=dict(tcp=dict(ack="True")),
sequence="10",
- source=dict(any="True", port_protocol=dict(eq="www")),
+ source=dict(
+ any="True",
+ port_protocol=dict(eq="www"),
+ ),
destination=dict(
any="True",
port_protocol=dict(eq="telnet"),
@@ -994,9 +1157,15 @@ class TestIosAclsModule(TestIosModule):
dict(
grant="deny",
sequence="10",
- remarks=["check for remark", "remark for acl 110"],
+ remarks=[
+ "check for remark",
+ "remark for acl 110",
+ ],
protocol_options=dict(tcp=dict(syn="True")),
- source=dict(address="192.0.2.0", wildcard_bits="0.0.0.255"),
+ source=dict(
+ address="192.0.2.0",
+ wildcard_bits="0.0.0.255",
+ ),
destination=dict(
address="192.0.3.0",
wildcard_bits="0.0.0.255",
@@ -1015,9 +1184,9 @@ class TestIosAclsModule(TestIosModule):
)
commands = [
"ip access-list extended 110",
+ "10 remark check for remark",
+ "10 remark remark for acl 110",
"10 deny tcp 192.0.2.0 0.0.0.255 192.0.3.0 0.0.0.255 eq www syn dscp ef ttl eq 10",
- "remark check for remark",
- "remark remark for acl 110",
]
result = self.execute_module(changed=False)
self.assertEqual(sorted(result["rendered"]), sorted(commands))
@@ -1046,7 +1215,9 @@ class TestIosAclsModule(TestIosModule):
"source": {"any": True, "port_protocol": {"eq": "www"}},
"destination": {
"any": True,
- "port_protocol": {"range": {"start": 10, "end": 20}},
+ "port_protocol": {
+ "range": {"start": 10, "end": 20},
+ },
},
"dscp": "af11",
"protocol_options": {"tcp": {"ack": True}},
@@ -1077,11 +1248,13 @@ class TestIosAclsModule(TestIosModule):
def test_ios_acls_parsed_matches(self):
self.execute_show_command_name.return_value = dedent("")
set_module_args(
- dict(
- running_config="""ip access-list standard R1_TRAFFIC\n10 permit 10.11.12.13 (2 matches)\n
- 40 permit 128.0.0.0, wildcard bits 63.255.255.255 (2 matches)\n60 permit 134.107.136.0, wildcard bits 0.0.0.255 (1 match)""",
- state="parsed",
- ),
+ {
+ "running_config": """ip access-list standard R1_TRAFFIC
+ 10 permit 10.11.12.13
+ 40 permit 128.0.0.0 63.255.255.255
+ 60 permit 134.107.136.0 0.0.0.255""",
+ "state": "parsed",
+ },
)
result = self.execute_module(changed=False)
parsed_list = [
@@ -1092,16 +1265,26 @@ class TestIosAclsModule(TestIosModule):
"name": "R1_TRAFFIC",
"acl_type": "standard",
"aces": [
- {"sequence": 10, "grant": "permit", "source": {"host": "10.11.12.13"}},
+ {
+ "sequence": 10,
+ "grant": "permit",
+ "source": {"host": "10.11.12.13"},
+ },
{
"sequence": 40,
"grant": "permit",
- "protocol_options": {"protocol_number": 128},
+ "source": {
+ "address": "128.0.0.0",
+ "wildcard_bits": "63.255.255.255",
+ },
},
{
"sequence": 60,
"grant": "permit",
- "protocol_options": {"protocol_number": 134},
+ "source": {
+ "address": "134.107.136.0",
+ "wildcard_bits": "0.0.0.255",
+ },
},
],
},
@@ -1246,9 +1429,8 @@ class TestIosAclsModule(TestIosModule):
"permit 433 198.51.101.0 0.0.0.255 198.51.102.0 0.0.0.255 eq telnet log check tos max-throughput",
"permit 198.51.105.0 0.0.0.255 198.51.106.0 0.0.0.255 time-range 20 tos max-throughput",
"ip access-list standard test_acl",
+ "no remark",
"remark Another remark here",
- "no remark remark check 1",
- "no remark some random remark 2",
]
self.assertEqual(sorted(result["commands"]), sorted(commands))
@@ -1446,6 +1628,11 @@ class TestIosAclsModule(TestIosModule):
dict(
running_config=dedent(
"""\
+ ip access-list standard 99
+ 10 remark standalone remarks
+ 20 permit 192.15.0.1
+ 30 permit 192.15.0.2
+ 40 permit 192.15.0.3
ip access-list standard 2
30 permit 172.16.1.11
20 permit 172.16.1.10
@@ -1543,7 +1730,10 @@ class TestIosAclsModule(TestIosModule):
"sequence": 70,
"grant": "permit",
"protocol": "tcp",
- "source": {"address": "10.1.1.0", "wildcard_bits": "0.0.0.255"},
+ "source": {
+ "address": "10.1.1.0",
+ "wildcard_bits": "0.0.0.255",
+ },
"destination": {
"address": "172.16.1.0",
"port_protocol": {"eq": "telnet"},
@@ -1557,9 +1747,43 @@ class TestIosAclsModule(TestIosModule):
"name": "2",
"acl_type": "standard",
"aces": [
- {"sequence": 30, "grant": "permit", "source": {"host": "172.16.1.11"}},
- {"sequence": 20, "grant": "permit", "source": {"host": "172.16.1.10"}},
- {"sequence": 10, "grant": "permit", "source": {"host": "172.16.1.2"}},
+ {
+ "sequence": 30,
+ "grant": "permit",
+ "source": {"host": "172.16.1.11"},
+ },
+ {
+ "sequence": 20,
+ "grant": "permit",
+ "source": {"host": "172.16.1.10"},
+ },
+ {
+ "sequence": 10,
+ "grant": "permit",
+ "source": {"host": "172.16.1.2"},
+ },
+ ],
+ },
+ {
+ "name": "99",
+ "acl_type": "standard",
+ "aces": [
+ {
+ "sequence": 20,
+ "grant": "permit",
+ "source": {"host": "192.15.0.1"},
+ },
+ {
+ "sequence": 30,
+ "grant": "permit",
+ "source": {"host": "192.15.0.2"},
+ },
+ {
+ "sequence": 40,
+ "grant": "permit",
+ "source": {"host": "192.15.0.3"},
+ },
+ {"sequence": 10, "remarks": ["standalone remarks"]},
],
},
{
@@ -1570,7 +1794,10 @@ class TestIosAclsModule(TestIosModule):
"sequence": 10,
"grant": "permit",
"protocol": "icmp",
- "source": {"address": "10.1.1.0", "wildcard_bits": "0.0.0.255"},
+ "source": {
+ "address": "10.1.1.0",
+ "wildcard_bits": "0.0.0.255",
+ },
"destination": {
"address": "172.16.1.0",
"wildcard_bits": "0.0.0.255",
@@ -1594,7 +1821,10 @@ class TestIosAclsModule(TestIosModule):
"grant": "permit",
"protocol": "tcp",
"source": {"host": "10.1.1.1"},
- "destination": {"host": "10.5.5.5", "port_protocol": {"eq": "www"}},
+ "destination": {
+ "host": "10.5.5.5",
+ "port_protocol": {"eq": "www"},
+ },
},
{
"sequence": 30,
@@ -1710,6 +1940,28 @@ class TestIosAclsModule(TestIosModule):
],
},
{
+ "name": "99",
+ "acl_type": "standard",
+ "aces": [
+ {
+ "sequence": 20,
+ "grant": "permit",
+ "source": {"host": "192.15.0.1"},
+ },
+ {
+ "sequence": 30,
+ "grant": "permit",
+ "source": {"host": "192.15.0.2"},
+ },
+ {
+ "sequence": 40,
+ "grant": "permit",
+ "source": {"host": "192.15.0.3"},
+ },
+ {"sequence": 10, "remarks": ["standalone remarks"]},
+ ],
+ },
+ {
"name": "2",
"acl_type": "standard",
"aces": [
@@ -1806,6 +2058,11 @@ class TestIosAclsModule(TestIosModule):
"50 permit ip any 10.1.1.0 0.0.0.255",
"60 permit tcp any host 10.1.1.1 eq telnet",
"70 permit tcp 10.1.1.0 0.0.0.255 172.16.1.0 0.0.0.255 eq telnet time-range EVERYOTHERDAY",
+ "ip access-list standard 99",
+ "20 permit host 192.15.0.1",
+ "30 permit host 192.15.0.2",
+ "40 permit host 192.15.0.3",
+ "10 remark standalone remarks",
"ip access-list standard 2",
"30 permit host 172.16.1.11",
"20 permit host 172.16.1.10",
@@ -1820,3 +2077,196 @@ class TestIosAclsModule(TestIosModule):
]
result = self.execute_module(changed=False)
self.assertEqual(sorted(result["rendered"]), sorted(commands))
+
+ def test_ios_acls_overridden_sticky_remarks(self):
+ self.execute_show_command.return_value = dedent(
+ """\
+ ip access-list standard test123
+ 10 remark TEST
+ 10 permit 8.8.8.8
+ 20 remark TEST
+ 20 permit 8.8.4.4
+ """,
+ )
+ self.execute_show_command_name.return_value = dedent("")
+
+ set_module_args(
+ dict(
+ config=[
+ dict(
+ afi="ipv4",
+ acls=[
+ dict(
+ name="test123",
+ acl_type="standard",
+ aces=[
+ dict(
+ grant="permit",
+ source=dict(
+ address="8.8.128.0",
+ wildcard_bits="0.0.0.63",
+ ),
+ remarks=["TEST", "TEST 2"],
+ sequence=10,
+ ),
+ dict(
+ grant="permit",
+ source=dict(
+ host="8.8.4.4",
+ ),
+ remarks=["TEST"],
+ sequence=20,
+ ),
+ ],
+ ),
+ ],
+ ),
+ ],
+ state="overridden",
+ ),
+ )
+ result = self.execute_module(changed=True)
+ commands = [
+ "ip access-list standard test123",
+ "no 10 remark",
+ "no 10 permit host 8.8.8.8",
+ "10 remark TEST",
+ "10 remark TEST 2",
+ "10 permit 8.8.128.0 0.0.0.63",
+ ]
+ self.assertEqual(sorted(result["commands"]), sorted(commands))
+
+ def test_ios_acls_overridden_remarks_complex(self):
+ self.execute_show_command.return_value = dedent(
+ """\
+ ip access-list extended TEST
+ 10 remark FIRST REMARK BEFORE SEQUENCE 10
+ 10 remark ============
+ 10 remark REMARKS FOR SEQUENCE 10 NO FOLLOWING ACE
+ 20 remark FIRST REMARK BEFORE SEQUENCE 20
+ 20 remark ============
+ 20 remark ALLOW HOST FROM SEQUENCE 20
+ 20 permit ip host 1.1.1.1 any
+ 30 remark FIRST REMARK BEFORE SEQUENCE 30
+ 30 remark ============
+ 30 remark ALLOW HOST FROM SEQUENCE 30
+ 30 permit ip host 2.2.2.2 any
+ 40 remark FIRST REMARK BEFORE SEQUENCE 40
+ 40 remark ============
+ 40 remark ALLOW NEW HOST FROM SEQUENCE 40
+ 40 permit ip host 3.3.3.3 any
+ remark Remark not specific to sequence
+ remark ============
+ remark End Remarks
+ ip access-list extended test_acl
+ 10 deny tcp 192.0.2.0 0.0.0.255 192.0.3.0 0.0.0.255 eq www fin option traceroute ttl eq 10
+ ip access-list extended 110
+ 10 deny icmp 192.0.2.0 0.0.0.255 192.0.3.0 0.0.0.255 echo dscp ef ttl eq 10
+ ip access-list extended 123
+ 10 deny tcp 198.51.100.0 0.0.0.255 198.51.101.0 0.0.0.255 eq telnet ack tos 12
+ 20 deny tcp 192.0.3.0 0.0.0.255 192.0.4.0 0.0.0.255 eq www ack dscp ef ttl lt 20
+ ipv6 access-list R1_TRAFFIC
+ sequence 10 deny tcp any eq www any eq telnet ack dscp af11
+ """,
+ )
+ self.execute_show_command_name.return_value = dedent("")
+ set_module_args(
+ dict(
+ config=[
+ {
+ "afi": "ipv4",
+ "acls": [
+ {
+ "name": "TEST",
+ "acl_type": "extended",
+ "aces": [
+ {
+ "sequence": 10,
+ "remarks": [
+ "FIRST REMARK BEFORE SEQUENCE 10",
+ "============",
+ "REMARKS FOR SEQUENCE 10 NO FOLLOWING ACE",
+ ],
+ "grant": "permit",
+ "protocol": "ip",
+ "source": {"host": "1.1.1.1"},
+ "destination": {"any": True},
+ },
+ {
+ "sequence": 20,
+ "remarks": [
+ "FIRST REMARK BEFORE SEQUENCE 20",
+ "============",
+ "ALLOW HOST FROM SEQUENCE 20",
+ ],
+ "grant": "permit",
+ "protocol": "ip",
+ "source": {"host": "192.168.0.1"},
+ "destination": {"any": True},
+ },
+ {
+ "sequence": 30,
+ "remarks": [
+ "FIRST REMARK BEFORE SEQUENCE 30",
+ "============",
+ "ALLOW HOST FROM SEQUENCE 30 updated",
+ ],
+ "grant": "permit",
+ "protocol": "ip",
+ "source": {"host": "2.2.2.2"},
+ "destination": {"any": True},
+ },
+ {
+ "sequence": 40,
+ "remarks": [
+ "FIRST REMARK BEFORE SEQUENCE 40",
+ "============",
+ "ALLOW NEW HOST FROM SEQUENCE 40",
+ ],
+ "grant": "permit",
+ "protocol": "ip",
+ "source": {"host": "3.3.3.3"},
+ "destination": {"any": True},
+ },
+ {
+ "remarks": [
+ "Remark not specific to sequence",
+ "============",
+ "End Remarks 1",
+ ],
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ state="overridden",
+ ),
+ )
+ result = self.execute_module(changed=True)
+ commands = [
+ "no ipv6 access-list R1_TRAFFIC",
+ "ip access-list extended TEST",
+ "no 10", # removes all remarks and ace entry for sequence 10
+ "no 20 permit ip host 1.1.1.1 any", # removing the ace automatically removes the remarks
+ "no 30 remark", # just remove remarks for sequence 30
+ "no remark", # remove all remarks at end of acl, that has no sequence
+ "10 remark FIRST REMARK BEFORE SEQUENCE 10",
+ "10 remark ============",
+ "10 remark REMARKS FOR SEQUENCE 10 NO FOLLOWING ACE",
+ "10 permit ip host 1.1.1.1 any",
+ "20 remark FIRST REMARK BEFORE SEQUENCE 20",
+ "20 remark ============",
+ "20 remark ALLOW HOST FROM SEQUENCE 20",
+ "20 permit ip host 192.168.0.1 any",
+ "30 remark FIRST REMARK BEFORE SEQUENCE 30",
+ "30 remark ============",
+ "30 remark ALLOW HOST FROM SEQUENCE 30 updated",
+ "remark Remark not specific to sequence",
+ "remark ============",
+ "remark End Remarks 1",
+ "no ip access-list extended 110",
+ "no ip access-list extended 123",
+ "no ip access-list extended test_acl",
+ ]
+ self.assertEqual(sorted(result["commands"]), sorted(commands))
diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_banner.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_banner.py
index 85e2736f0..b114d1817 100644
--- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_banner.py
+++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_banner.py
@@ -18,9 +18,9 @@ from __future__ import absolute_import, division, print_function
__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 @@ class TestIosBannerModule(TestIosModule):
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/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_bgp.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_bgp.py
deleted file mode 100644
index 0145a3c6a..000000000
--- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_bgp.py
+++ /dev/null
@@ -1,344 +0,0 @@
-#
-# (c) 2019, Ansible by Red Hat, inc
-# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-#
-
-from __future__ import absolute_import, division, print_function
-
-
-__metaclass__ = type
-
-from ansible_collections.cisco.ios.plugins.module_utils.network.ios.providers.cli.config.bgp.process import (
- Provider,
-)
-from ansible_collections.cisco.ios.plugins.modules import ios_bgp
-
-from .ios_module import TestIosModule, load_fixture
-
-
-class TestIosBgpModule(TestIosModule):
- module = ios_bgp
-
- def setUp(self):
- super(TestIosBgpModule, self).setUp()
- self._bgp_config = load_fixture("ios_bgp_config.cfg")
-
- def test_ios_bgp(self):
- obj = Provider(
- params=dict(
- config=dict(
- bgp_as=64496,
- router_id="192.0.2.2",
- networks=None,
- address_family=None,
- ),
- operation="merge",
- ),
- )
- commands = obj.render(self._bgp_config)
- self.assertEqual(commands, ["router bgp 64496", "bgp router-id 192.0.2.2", "exit"])
-
- def test_ios_bgp_idempotent(self):
- obj = Provider(
- params=dict(
- config=dict(
- bgp_as=64496,
- router_id="192.0.2.1",
- networks=None,
- address_family=None,
- ),
- operation="merge",
- ),
- )
- commands = obj.render(self._bgp_config)
- self.assertEqual(commands, [])
-
- def test_ios_bgp_remove(self):
- obj = Provider(
- params=dict(
- config=dict(bgp_as=64496, networks=None, address_family=None),
- operation="delete",
- ),
- )
- commands = obj.render(self._bgp_config)
- self.assertEqual(commands, ["no router bgp 64496"])
-
- def test_ios_bgp_neighbor(self):
- obj = Provider(
- params=dict(
- config=dict(
- bgp_as=64496,
- neighbors=[dict(neighbor="192.51.100.2", remote_as=64496)],
- networks=None,
- address_family=None,
- ),
- operation="merge",
- ),
- )
- commands = obj.render(self._bgp_config)
- self.assertEqual(
- commands,
- ["router bgp 64496", "neighbor 192.51.100.2 remote-as 64496", "exit"],
- )
-
- def test_ios_bgp_neighbor_idempotent(self):
- obj = Provider(
- params=dict(
- config=dict(
- bgp_as=64496,
- neighbors=[
- dict(
- neighbor="192.51.100.1",
- remote_as=64496,
- timers=dict(keepalive=120, holdtime=360, min_neighbor_holdtime=360),
- ),
- ],
- networks=None,
- address_family=None,
- ),
- operation="merge",
- ),
- )
- commands = obj.render(self._bgp_config)
- self.assertEqual(commands, [])
-
- def test_ios_bgp_network(self):
- obj = Provider(
- params=dict(
- config=dict(
- bgp_as=64496,
- networks=[dict(prefix="192.0.1.0", masklen=23, route_map="RMAP_1")],
- address_family=None,
- ),
- operation="merge",
- ),
- )
- commands = obj.render(self._bgp_config)
- self.assertEqual(
- sorted(commands),
- sorted(
- [
- "router bgp 64496",
- "network 192.0.1.0 mask 255.255.254.0 route-map RMAP_1",
- "exit",
- ],
- ),
- )
-
- def test_ios_bgp_network_idempotent(self):
- obj = Provider(
- params=dict(
- config=dict(
- bgp_as=64496,
- networks=[
- dict(prefix="192.0.2.0", masklen=23, route_map="RMAP_1"),
- dict(prefix="198.51.100.0", masklen=25, route_map="RMAP_2"),
- ],
- address_family=None,
- ),
- operation="merge",
- ),
- )
- commands = obj.render(self._bgp_config)
- self.assertEqual(commands, [])
-
- def test_ios_bgp_address_family_redistribute(self):
- rd_1 = dict(protocol="ospf", id="233", metric=90, route_map=None)
-
- config = dict(
- bgp_as=64496,
- address_family=[dict(afi="ipv4", safi="unicast", redistribute=[rd_1])],
- networks=None,
- )
-
- obj = Provider(params=dict(config=config, operation="merge"))
-
- commands = obj.render(self._bgp_config)
- cmd = [
- "router bgp 64496",
- "address-family ipv4",
- "redistribute ospf 233 metric 90",
- "exit-address-family",
- "exit",
- ]
- self.assertEqual(sorted(commands), sorted(cmd))
-
- def test_ios_bgp_address_family_redistribute_idempotent(self):
- rd_1 = dict(protocol="eigrp", metric=10, route_map="RMAP_3", id=None)
- rd_2 = dict(protocol="static", metric=100, id=None, route_map=None)
-
- config = dict(
- bgp_as=64496,
- address_family=[dict(afi="ipv4", safi="unicast", redistribute=[rd_1, rd_2])],
- networks=None,
- )
-
- obj = Provider(params=dict(config=config, operation="merge"))
-
- commands = obj.render(self._bgp_config)
- self.assertEqual(commands, [])
-
- def test_ios_bgp_address_family_neighbors(self):
- af_nbr_1 = dict(neighbor="192.51.100.1", maximum_prefix=35, activate=True)
- af_nbr_2 = dict(neighbor="192.51.100.3", route_reflector_client=True, activate=True)
-
- config = dict(
- bgp_as=64496,
- address_family=[dict(afi="ipv4", safi="multicast", neighbors=[af_nbr_1, af_nbr_2])],
- networks=None,
- )
-
- obj = Provider(params=dict(config=config, operation="merge"))
-
- commands = obj.render(self._bgp_config)
- cmd = [
- "router bgp 64496",
- "address-family ipv4 multicast",
- "neighbor 192.51.100.1 activate",
- "neighbor 192.51.100.1 maximum-prefix 35",
- "neighbor 192.51.100.3 activate",
- "neighbor 192.51.100.3 route-reflector-client",
- "exit-address-family",
- "exit",
- ]
- self.assertEqual(sorted(commands), sorted(cmd))
-
- def test_ios_bgp_address_family_neighbors_idempotent(self):
- af_nbr_1 = dict(neighbor="203.0.113.1", remove_private_as=True, maximum_prefix=100)
-
- config = dict(
- bgp_as=64496,
- address_family=[dict(afi="ipv4", safi="unicast", neighbors=[af_nbr_1])],
- networks=None,
- )
-
- obj = Provider(params=dict(config=config, operation="merge"))
-
- commands = obj.render(self._bgp_config)
- self.assertEqual(commands, [])
-
- def test_ios_bgp_address_family_networks(self):
- net = dict(prefix="1.0.0.0", masklen=8, route_map="RMAP_1")
- net2 = dict(prefix="192.168.1.0", masklen=24, route_map="RMAP_2")
-
- config = dict(
- bgp_as=64496,
- address_family=[dict(afi="ipv4", safi="multicast", networks=[net, net2])],
- networks=None,
- )
-
- obj = Provider(params=dict(config=config, operation="merge"))
-
- commands = obj.render(self._bgp_config)
- cmd = [
- "router bgp 64496",
- "address-family ipv4 multicast",
- "network 1.0.0.0 mask 255.0.0.0 route-map RMAP_1",
- "network 192.168.1.0 mask 255.255.255.0 route-map RMAP_2",
- "exit-address-family",
- "exit",
- ]
- self.assertEqual(sorted(commands), sorted(cmd))
-
- def test_ios_bgp_address_family_networks_idempotent(self):
- net = dict(prefix="203.0.113.0", masklen=27, route_map="RMAP_1")
- net2 = dict(prefix="192.0.2.0", masklen=26, route_map="RMAP_2")
-
- config = dict(
- bgp_as=64496,
- address_family=[dict(afi="ipv4", safi="multicast", networks=[net, net2])],
- networks=None,
- )
-
- obj = Provider(params=dict(config=config, operation="merge"))
-
- commands = obj.render(self._bgp_config)
- self.assertEqual(commands, [])
-
- def test_ios_bgp_operation_override(self):
- net_1 = dict(prefix="1.0.0.0", masklen=8, route_map="RMAP_1")
- net_2 = dict(prefix="192.168.1.0", masklen=24, route_map="RMAP_2")
- nbr_1 = dict(neighbor="192.51.100.1", remote_as=64496, update_source="GigabitEthernet0/1")
- nbr_2 = dict(
- neighbor="192.51.100.3",
- remote_as=64496,
- timers=dict(keepalive=300, holdtime=360, min_neighbor_holdtime=360),
- )
- af_nbr_1 = dict(neighbor="192.51.100.1", maximum_prefix=35)
- af_nbr_2 = dict(neighbor="192.51.100.3", route_reflector_client=True)
-
- af_1 = dict(afi="ipv4", safi="unicast", neighbors=[af_nbr_1, af_nbr_2])
- af_2 = dict(afi="ipv4", safi="multicast", networks=[net_1, net_2])
- config = dict(
- bgp_as=64496,
- neighbors=[nbr_1, nbr_2],
- address_family=[af_1, af_2],
- networks=None,
- )
-
- obj = Provider(params=dict(config=config, operation="override"))
- commands = obj.render(self._bgp_config)
-
- cmd = [
- "no router bgp 64496",
- "router bgp 64496",
- "neighbor 192.51.100.1 remote-as 64496",
- "neighbor 192.51.100.1 update-source GigabitEthernet0/1",
- "neighbor 192.51.100.3 remote-as 64496",
- "neighbor 192.51.100.3 timers 300 360 360",
- "address-family ipv4",
- "neighbor 192.51.100.1 maximum-prefix 35",
- "neighbor 192.51.100.3 route-reflector-client",
- "exit-address-family",
- "address-family ipv4 multicast",
- "network 1.0.0.0 mask 255.0.0.0 route-map RMAP_1",
- "network 192.168.1.0 mask 255.255.255.0 route-map RMAP_2",
- "exit-address-family",
- "exit",
- ]
-
- self.assertEqual(sorted(commands), sorted(cmd))
-
- def test_ios_bgp_operation_replace(self):
- rd = dict(protocol="ospf", id=223, metric=110, route_map=None)
- net = dict(prefix="203.0.113.0", masklen=27, route_map="RMAP_1")
- net2 = dict(prefix="192.0.2.0", masklen=26, route_map="RMAP_2")
-
- af_1 = dict(afi="ipv4", safi="unicast", redistribute=[rd])
- af_2 = dict(afi="ipv4", safi="multicast", networks=[net, net2])
-
- config = dict(bgp_as=64496, address_family=[af_1, af_2], networks=None)
- obj = Provider(params=dict(config=config, operation="replace"))
- commands = obj.render(self._bgp_config)
-
- cmd = [
- "router bgp 64496",
- "address-family ipv4",
- "redistribute ospf 223 metric 110",
- "no redistribute eigrp",
- "no redistribute static",
- "exit-address-family",
- "exit",
- ]
-
- self.assertEqual(sorted(commands), sorted(cmd))
-
- def test_ios_bgp_operation_replace_with_new_as(self):
- rd = dict(protocol="ospf", id=223, metric=110, route_map=None)
-
- af_1 = dict(afi="ipv4", safi="unicast", redistribute=[rd])
-
- config = dict(bgp_as=64497, address_family=[af_1], networks=None)
- obj = Provider(params=dict(config=config, operation="replace"))
- commands = obj.render(self._bgp_config)
-
- cmd = [
- "no router bgp 64496",
- "router bgp 64497",
- "address-family ipv4",
- "redistribute ospf 223 metric 110",
- "exit-address-family",
- "exit",
- ]
-
- self.assertEqual(sorted(commands), sorted(cmd))
diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_bgp_address_family.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_bgp_address_family.py
index 259da5ece..ea5d279f4 100644
--- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_bgp_address_family.py
+++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_bgp_address_family.py
@@ -7,11 +7,10 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-
from textwrap import dedent
+from unittest.mock import patch
from ansible_collections.cisco.ios.plugins.modules import ios_bgp_address_family
-from ansible_collections.cisco.ios.tests.unit.compat.mock import patch
from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args
from .ios_module import TestIosModule
@@ -119,8 +118,12 @@ class TestIosBgpAddressFamilyModule(TestIosModule):
dict(
neighbor_address="198.51.100.1",
remote_as="65.11",
- route_maps=[dict(name="test-route-out", out="true")],
- prefix_lists=[dict(name="AS65100-PREFIX-OUT", out="true")],
+ route_maps=[
+ dict(name="test-route-out", out="true"),
+ ],
+ prefix_lists=[
+ dict(name="AS65100-PREFIX-OUT", out="true"),
+ ],
),
],
),
@@ -128,7 +131,9 @@ class TestIosBgpAddressFamilyModule(TestIosModule):
afi="nsap",
bgp=dict(aggregate_timer=20, dmzlink_bw=True, scan_time=10),
default_metric=10,
- networks=[dict(address="192.0.1.1", route_map="test_route")],
+ networks=[
+ dict(address="192.0.1.1", route_map="test_route"),
+ ],
),
],
),
@@ -317,18 +322,25 @@ class TestIosBgpAddressFamilyModule(TestIosModule):
"send": {
"cost_community": {
"id": 100,
- "poi": {"igp_cost": True, "transitive": True},
+ "poi": {
+ "igp_cost": True,
+ "transitive": True,
+ },
},
},
},
"local_as": {"number": "10.64760", "set": True},
"neighbor_address": "198.51.100.1",
"nexthop_self": {"all": True},
- "prefix_lists": [{"name": "AS65100-PREFIX-OUT", "out": True}],
+ "prefix_lists": [
+ {"name": "AS65100-PREFIX-OUT", "out": True},
+ ],
"remote_as": 10,
"route_maps": [{"name": "test-out", "out": True}],
"route_server_client": True,
- "slow_peer_options": {"detection": {"threshold": 150}},
+ "slow_peer_options": {
+ "detection": {"threshold": 150},
+ },
},
],
"networks": [
@@ -426,7 +438,9 @@ class TestIosBgpAddressFamilyModule(TestIosModule):
address="198.51.110.1",
activate=True,
remote_as=200,
- route_maps=[dict(name="test-replaced-route", out=True)],
+ route_maps=[
+ dict(name="test-replaced-route", out=True),
+ ],
),
],
),
@@ -534,12 +548,17 @@ class TestIosBgpAddressFamilyModule(TestIosModule):
send=dict(
cost_community=dict(
id=100,
- poi=dict(igp_cost=True, transitive=True),
+ poi=dict(
+ igp_cost=True,
+ transitive=True,
+ ),
),
),
),
nexthop_self=dict(all=True),
- prefix_lists=[dict(name="AS65100-PREFIX-OUT", out="true")],
+ prefix_lists=[
+ dict(name="AS65100-PREFIX-OUT", out="true"),
+ ],
slow_peer=[dict(detection=dict(threshold=150))],
remote_as=10,
local_as=dict(number=20),
@@ -709,12 +728,17 @@ class TestIosBgpAddressFamilyModule(TestIosModule):
send=dict(
cost_community=dict(
id=100,
- poi=dict(igp_cost=True, transitive=True),
+ poi=dict(
+ igp_cost=True,
+ transitive=True,
+ ),
),
),
),
nexthop_self=dict(all=True),
- prefix_lists=[dict(name="AS65100-PREFIX-OUT", out="true")],
+ prefix_lists=[
+ dict(name="AS65100-PREFIX-OUT", out="true"),
+ ],
slow_peer=[dict(detection=dict(threshold=150))],
remote_as=10,
local_as=dict(number=20),
@@ -937,7 +961,10 @@ class TestIosBgpAddressFamilyModule(TestIosModule):
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 @@ class TestIosBgpAddressFamilyModule(TestIosModule):
},
},
"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 @@ class TestIosBgpAddressFamilyModule(TestIosModule):
},
},
"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/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_bgp_global.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_bgp_global.py
index 95aa8d8e9..16a4c9b5c 100644
--- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_bgp_global.py
+++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_bgp_global.py
@@ -7,11 +7,10 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-
from textwrap import dedent
+from unittest.mock import patch
from ansible_collections.cisco.ios.plugins.modules import ios_bgp_global
-from ansible_collections.cisco.ios.tests.unit.compat.mock import patch
from ansible_collections.cisco.ios.tests.unit.modules.utils import AnsibleFailJson, set_module_args
from .ios_module import TestIosModule
@@ -67,8 +66,16 @@ class TestIosBgpGlobalModule(TestIosModule):
"netmask": "255.255.0.0",
"summary_only": True,
},
- {"address": "192.0.2.4", "as_set": True, "netmask": "255.255.255.0"},
- {"address": "192.0.2.5", "as_set": True, "netmask": "255.255.255.0"},
+ {
+ "address": "192.0.2.4",
+ "as_set": True,
+ "netmask": "255.255.255.0",
+ },
+ {
+ "address": "192.0.2.5",
+ "as_set": True,
+ "netmask": "255.255.255.0",
+ },
],
"as_number": "65000",
"auto_summary": True,
@@ -83,7 +90,9 @@ class TestIosBgpGlobalModule(TestIosModule):
"med": {"confed": True, "missing_as_worst": True},
},
"confederation": {"identifier": "22"},
- "consistency_checker": {"error_message": {"interval": 10, "set": True}},
+ "consistency_checker": {
+ "error_message": {"interval": 10, "set": True},
+ },
"dampening": {
"max_suppress": 44,
"penalty_half_time": 22,
@@ -98,12 +107,23 @@ class TestIosBgpGlobalModule(TestIosModule):
"neighbors": {"time": 31},
},
"inject_maps": [
- {"copy_attributes": True, "exist_map_name": "mp2", "name": "map1"},
- {"copy_attributes": True, "exist_map_name": "mp3", "name": "map2"},
+ {
+ "copy_attributes": True,
+ "exist_map_name": "mp2",
+ "name": "map1",
+ },
+ {
+ "copy_attributes": True,
+ "exist_map_name": "mp3",
+ "name": "map2",
+ },
],
"listen": {
"limit": 200,
- "range": {"host_with_subnet": "192.0.2.9/24", "peer_group": "mygrp"},
+ "range": {
+ "host_with_subnet": "192.0.2.9/24",
+ "peer_group": "mygrp",
+ },
},
"log_neighbor_changes": True,
"maxas_limit": 2,
@@ -132,8 +152,16 @@ class TestIosBgpGlobalModule(TestIosModule):
},
"bmp": {"buffer_size": 22},
"distance": {
- "bgp": {"routes_external": 2, "routes_internal": 3, "routes_local": 4},
- "mbgp": {"routes_external": 2, "routes_internal": 3, "routes_local": 5},
+ "bgp": {
+ "routes_external": 2,
+ "routes_internal": 3,
+ "routes_local": 4,
+ },
+ "mbgp": {
+ "routes_external": 2,
+ "routes_internal": 3,
+ "routes_local": 5,
+ },
},
"distributes": [
{"out": True, "prefix": "workcheck"},
@@ -141,6 +169,7 @@ class TestIosBgpGlobalModule(TestIosModule):
],
"maximum_paths": {"ibgp": 22},
"maximum_secondary_paths": {"ibgp": 22, "paths": 12},
+ "template": {"peer_policy": "Test1"},
"neighbors": [
{
"neighbor_address": "192.0.2.3",
@@ -165,7 +194,13 @@ class TestIosBgpGlobalModule(TestIosModule):
],
"redistribute": [
{"application": {"metric": 22, "name": "ap1"}},
- {"application": {"metric": 33, "name": "ap112", "route_map": "mp1"}},
+ {
+ "application": {
+ "metric": 33,
+ "name": "ap112",
+ "route_map": "mp1",
+ },
+ },
{"connected": {"metric": 22}},
{"static": {"metric": 33, "route_map": "mp1"}},
{"mobile": {"metric": 211}},
@@ -232,6 +267,7 @@ class TestIosBgpGlobalModule(TestIosModule):
"neighbor 192.0.2.3 remote-as 300",
"neighbor 192.0.2.3 timers 10 20",
"redistribute connected metric 22",
+ "template peer-policy Test1",
"redistribute mobile metric 211",
"redistribute application ap1 metric 22",
"redistribute static metric 33 route-map mp1",
@@ -347,11 +383,23 @@ class TestIosBgpGlobalModule(TestIosModule):
config=dict(
as_number="65000",
aggregate_address=dict(
- dict(address="192.168.0.11", attribute_map="map1", netmask="255.255.0.0"),
+ dict(
+ address="192.168.0.11",
+ attribute_map="map1",
+ netmask="255.255.0.0",
+ ),
),
aggregate_addresses=[
- dict(address="192.168.0.1", attribute_map="map", netmask="255.255.0.0"),
- dict(address="192.168.0.2", attribute_map="map2", netmask="255.255.0.0"),
+ dict(
+ address="192.168.0.1",
+ attribute_map="map",
+ netmask="255.255.0.0",
+ ),
+ dict(
+ address="192.168.0.2",
+ attribute_map="map2",
+ netmask="255.255.0.0",
+ ),
],
bgp=dict(
advertise_best_external=True,
@@ -361,7 +409,11 @@ class TestIosBgpGlobalModule(TestIosModule):
),
redistribute=[dict(connected=dict(set=True, metric=10))],
neighbors=[
- dict(address="192.0.2.1", remote_as=200, description="replace neighbor"),
+ dict(
+ address="192.0.2.1",
+ remote_as=200,
+ description="replace neighbor",
+ ),
],
),
state="overridden",
@@ -403,21 +455,41 @@ class TestIosBgpGlobalModule(TestIosModule):
config=dict(
as_number="65000",
aggregate_address=dict(
- dict(address="192.168.0.11", attribute_map="map1", netmask="255.255.0.0"),
+ dict(
+ address="192.168.0.11",
+ attribute_map="map1",
+ netmask="255.255.0.0",
+ ),
),
aggregate_addresses=[
- dict(address="192.168.0.1", attribute_map="map", netmask="255.255.0.0"),
- dict(address="192.168.0.2", attribute_map="map2", netmask="255.255.0.0"),
+ dict(
+ address="192.168.0.1",
+ attribute_map="map",
+ netmask="255.255.0.0",
+ ),
+ dict(
+ address="192.168.0.2",
+ attribute_map="map2",
+ netmask="255.255.0.0",
+ ),
],
bgp=dict(
advertise_best_external=True,
bestpath_options=dict(compare_routerid=True),
+ default=dict(
+ ipv4_unicast=False,
+ route_target=dict(filter=True),
+ ),
log_neighbor_changes=True,
nopeerup_delay_options=dict(cold_boot=20, post_boot=10),
),
redistribute=[dict(connected=dict(set=True, metric=10))],
neighbors=[
- dict(address="192.0.2.1", remote_as=200, description="replace neighbor"),
+ dict(
+ address="192.0.2.1",
+ remote_as=200,
+ description="replace neighbor",
+ ),
],
),
state="replaced",
@@ -425,6 +497,7 @@ class TestIosBgpGlobalModule(TestIosModule):
)
commands = [
"router bgp 65000",
+ "no bgp default ipv4-unicast",
"no timers bgp 100 200 150",
"bgp log-neighbor-changes",
"bgp nopeerup-delay cold-boot 20",
@@ -481,6 +554,7 @@ class TestIosBgpGlobalModule(TestIosModule):
self.execute_show_command.return_value = dedent(
"""\
router bgp 65000
+ no bgp default ipv4-unicast
bgp nopeerup-delay post-boot 10
bgp bestpath compare-routerid
bgp advertise-best-external
@@ -496,6 +570,7 @@ class TestIosBgpGlobalModule(TestIosModule):
set_module_args(dict(config=dict(as_number=65000), state="deleted"))
commands = [
"router bgp 65000",
+ "bgp default ipv4-unicast",
"no timers bgp 100 200 150",
"no bgp advertise-best-external",
"no bgp bestpath compare-routerid",
@@ -561,7 +636,10 @@ class TestIosBgpGlobalModule(TestIosModule):
},
"listen": {
"limit": 200,
- "range": {"ipv4_with_subnet": "192.0.2.9/24", "peer_group": "mygrp"},
+ "range": {
+ "ipv4_with_subnet": "192.0.2.9/24",
+ "peer_group": "mygrp",
+ },
},
"log_neighbor_changes": True,
"nopeerup_delay": [
@@ -575,10 +653,22 @@ class TestIosBgpGlobalModule(TestIosModule):
},
"bmp": {"buffer_size": 22, "server": 2},
"distance": {
- "bgp": {"routes_external": 2, "routes_internal": 3, "routes_local": 4},
- "mbgp": {"routes_external": 2, "routes_internal": 3, "routes_local": 5},
+ "bgp": {
+ "routes_external": 2,
+ "routes_internal": 3,
+ "routes_local": 4,
+ },
+ "mbgp": {
+ "routes_external": 2,
+ "routes_internal": 3,
+ "routes_local": 5,
+ },
+ },
+ "distribute_list": {
+ "out": True,
+ "acl": "5000",
+ "interface": "Loopback0",
},
- "distribute_list": {"out": True, "acl": "5000", "interface": "Loopback0"},
"maximum_paths": {"ibgp": 2, "paths": 2},
"maximum_secondary_paths": {"ibgp": 22, "paths": 22},
"neighbors": [
@@ -613,7 +703,11 @@ class TestIosBgpGlobalModule(TestIosModule):
"send_community": {"extended": True},
"password": "new password",
},
- {"activate": True, "neighbor_address": "172.21.1.2", "remote_as": 45000},
+ {
+ "activate": True,
+ "neighbor_address": "172.21.1.2",
+ "remote_as": 45000,
+ },
{"neighbor_address": "192.0.2.3", "remote_as": 300},
{
"neighbor_address": "192.0.2.4",
@@ -655,7 +749,13 @@ class TestIosBgpGlobalModule(TestIosModule):
"redistribute": [
{"static": {"metric": 33, "route_map": "mp1"}},
{"application": {"metric": 22, "name": "ap1"}},
- {"application": {"metric": 33, "name": "ap112", "route_map": "mp1"}},
+ {
+ "application": {
+ "metric": 33,
+ "name": "ap112",
+ "route_map": "mp1",
+ },
+ },
{"connected": {"metric": 22}},
{"mobile": {"metric": 211}},
],
@@ -751,6 +851,7 @@ class TestIosBgpGlobalModule(TestIosModule):
"bgp": {
"nopeerup_delay_options": {"post_boot": 10},
"bestpath_options": {"compare_routerid": True},
+ "default": {"ipv4_unicast": True, "route_target": {"filter": True}},
"advertise_best_external": True,
},
"timers": {"keepalive": 100, "holdtime": 200, "min_holdtime": 150},
@@ -764,3 +865,136 @@ class TestIosBgpGlobalModule(TestIosModule):
],
}
self.assertEqual(parsed_list, result["parsed"])
+
+ def test_ios_bgp_global_action_states_specific_default(self):
+ self.execute_show_command.return_value = dedent(
+ """\
+ router bgp 6500
+ bgp log-neighbor-changes
+ no bgp default ipv4-unicast
+ no bgp default route-target filter
+ neighbor 192.0.2.1 remote-as 100
+ neighbor 192.0.2.1 description Test description
+ neighbor 192.0.2.2 remote-as 200
+ neighbor 192.0.2.2 description Test description 2
+ neighbor 192.0.2.2 shutdown
+ !
+ address-family ipv4
+ exit-address-family
+ """,
+ )
+ for stt in ["merged", "replaced", "overridden"]:
+ set_module_args(
+ {
+ "config": {
+ "as_number": "6500",
+ "bgp": {
+ "default": {
+ "ipv4_unicast": False,
+ "route_target": {
+ "filter": False,
+ },
+ },
+ "log_neighbor_changes": True,
+ },
+ "neighbors": [
+ {
+ "neighbor_address": "192.0.2.1",
+ "remote_as": "100",
+ "description": "Test description",
+ "shutdown": { # Don't have in config, adding
+ "set": True,
+ },
+ },
+ {
+ "neighbor_address": "192.0.2.2",
+ "remote_as": "200",
+ "description": "Test description 2",
+ "shutdown": { # Have in config negating with false
+ "set": False,
+ },
+ },
+ ],
+ },
+ "state": stt,
+ },
+ )
+ commands = [
+ "router bgp 6500",
+ "neighbor 192.0.2.1 shutdown",
+ "no neighbor 192.0.2.2 shutdown",
+ ]
+ result = self.execute_module(changed=True)
+ self.assertEqual(sorted(result["commands"]), sorted(commands))
+
+ def test_ios_bgp_global_action_states_no_default(self):
+ self.execute_show_command.return_value = dedent(
+ """\
+ router bgp 6500
+ bgp log-neighbor-changes
+ no bgp default ipv4-unicast
+ no bgp default route-target filter
+ neighbor 192.0.2.1 remote-as 100
+ neighbor 192.0.2.1 description Test description
+ neighbor 192.0.2.1 shutdown
+ neighbor 192.0.2.2 remote-as 200
+ neighbor 192.0.2.2 description Test description 2
+ neighbor 192.0.2.2 shutdown
+ neighbor 192.0.2.3 remote-as 300
+ neighbor 192.0.2.3 description Test description 3
+ neighbor 192.0.2.4 remote-as 400
+ neighbor 192.0.2.4 description Test description 4
+ !
+ address-family ipv4
+ exit-address-family
+ """,
+ )
+ for stt in ["replaced", "overridden"]:
+ set_module_args(
+ {
+ "config": {
+ "as_number": "6500",
+ "bgp": {
+ "default": {
+ "ipv4_unicast": False,
+ "route_target": {
+ "filter": False,
+ },
+ },
+ "log_neighbor_changes": True,
+ },
+ "neighbors": [
+ {
+ "neighbor_address": "192.0.2.1",
+ "remote_as": "100",
+ "description": "Test description",
+ "shutdown": { # Have in config not adding again (idempotent)
+ "set": True,
+ },
+ },
+ {
+ "neighbor_address": "192.0.2.2",
+ "remote_as": "200",
+ "description": "Test description 2", # Have in config but don't want (to be removed)
+ },
+ {
+ "neighbor_address": "192.0.2.3",
+ "remote_as": "300",
+ "description": "Test description 3", # Don't have in config don't want
+ },
+ {
+ "neighbor_address": "192.0.2.4",
+ "remote_as": "400",
+ "description": "Test description 4",
+ "shutdown": { # Don't have in config, explicitly don't want
+ "set": False,
+ },
+ },
+ ],
+ },
+ "state": stt,
+ },
+ )
+ commands = ["router bgp 6500", "no neighbor 192.0.2.2 shutdown"]
+ result = self.execute_module(changed=True)
+ self.assertEqual(sorted(result["commands"]), sorted(commands))
diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_command.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_command.py
index 42fee4028..69788ef3e 100644
--- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_command.py
+++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_command.py
@@ -20,11 +20,11 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-
import json
+from unittest.mock import patch
+
from ansible_collections.cisco.ios.plugins.modules import ios_command
-from ansible_collections.cisco.ios.tests.unit.compat.mock import patch
from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args
from .ios_module import TestIosModule, load_fixture
@@ -97,17 +97,26 @@ class TestIosCommandModule(TestIosModule):
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/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_config.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_config.py
index 778bb1ccb..7fa3931d0 100644
--- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_config.py
+++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_config.py
@@ -21,10 +21,10 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
+from unittest.mock import MagicMock, patch
from ansible_collections.cisco.ios.plugins.cliconf.ios import Cliconf
from ansible_collections.cisco.ios.plugins.modules import ios_config
-from ansible_collections.cisco.ios.tests.unit.compat.mock import MagicMock, patch
from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args
from .ios_module import TestIosModule, load_fixture
@@ -123,7 +123,10 @@ class TestIosConfigModule(TestIosModule):
lines = ["hostname foo"]
set_module_args(dict(lines=lines))
self.conn.get_diff = MagicMock(
- return_value=self.cliconf_obj.get_diff("\n".join(lines), self.running_config),
+ return_value=self.cliconf_obj.get_diff(
+ "\n".join(lines),
+ self.running_config,
+ ),
)
commands = ["hostname foo"]
self.execute_module(changed=True, commands=commands)
@@ -137,7 +140,10 @@ class TestIosConfigModule(TestIosModule):
candidate_config = ios_config.get_candidate_config(module)
self.conn.get_diff = MagicMock(
- return_value=self.cliconf_obj.get_diff(candidate_config, self.running_config),
+ return_value=self.cliconf_obj.get_diff(
+ candidate_config,
+ self.running_config,
+ ),
)
commands = ["interface GigabitEthernet0/0", "shutdown"]
@@ -147,7 +153,10 @@ class TestIosConfigModule(TestIosModule):
lines = ["hostname foo"]
set_module_args(dict(lines=lines, before=["test1", "test2"]))
self.conn.get_diff = MagicMock(
- return_value=self.cliconf_obj.get_diff("\n".join(lines), self.running_config),
+ return_value=self.cliconf_obj.get_diff(
+ "\n".join(lines),
+ self.running_config,
+ ),
)
commands = ["test1", "test2", "hostname foo"]
self.execute_module(changed=True, commands=commands, sort=False)
@@ -156,16 +165,24 @@ class TestIosConfigModule(TestIosModule):
lines = ["hostname foo"]
set_module_args(dict(lines=lines, after=["test1", "test2"]))
self.conn.get_diff = MagicMock(
- return_value=self.cliconf_obj.get_diff("\n".join(lines), self.running_config),
+ return_value=self.cliconf_obj.get_diff(
+ "\n".join(lines),
+ self.running_config,
+ ),
)
commands = ["hostname foo", "test1", "test2"]
self.execute_module(changed=True, commands=commands, sort=False)
def test_ios_config_before_after_no_change(self):
lines = ["hostname router"]
- set_module_args(dict(lines=lines, before=["test1", "test2"], after=["test3", "test4"]))
+ set_module_args(
+ dict(lines=lines, before=["test1", "test2"], after=["test3", "test4"]),
+ )
self.conn.get_diff = MagicMock(
- return_value=self.cliconf_obj.get_diff("\n".join(lines), self.running_config),
+ return_value=self.cliconf_obj.get_diff(
+ "\n".join(lines),
+ self.running_config,
+ ),
)
self.execute_module()
@@ -242,7 +259,11 @@ class TestIosConfigModule(TestIosModule):
self.execute_module(changed=True, commands=commands, sort=False)
def test_ios_config_match_strict(self):
- lines = ["ip address 1.2.3.4 255.255.255.0", "description test string", "shutdown"]
+ lines = [
+ "ip address 1.2.3.4 255.255.255.0",
+ "description test string",
+ "shutdown",
+ ]
parents = ["interface GigabitEthernet0/0"]
set_module_args(dict(lines=lines, parents=parents, match="strict"))
@@ -262,7 +283,11 @@ class TestIosConfigModule(TestIosModule):
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/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_evpn_evi.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_evpn_evi.py
index 94008b0aa..e1178a21f 100644
--- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_evpn_evi.py
+++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_evpn_evi.py
@@ -7,11 +7,10 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-
from textwrap import dedent
+from unittest.mock import patch
from ansible_collections.cisco.ios.plugins.modules import ios_evpn_evi
-from ansible_collections.cisco.ios.tests.unit.compat.mock import patch
from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args
from .ios_module import TestIosModule
diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_evpn_global.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_evpn_global.py
index d3bfa1585..76f467411 100644
--- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_evpn_global.py
+++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_evpn_global.py
@@ -7,11 +7,10 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-
from textwrap import dedent
+from unittest.mock import patch
from ansible_collections.cisco.ios.plugins.modules import ios_evpn_global
-from ansible_collections.cisco.ios.tests.unit.compat.mock import patch
from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args
from .ios_module import TestIosModule
diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_facts.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_facts.py
index a99d7f011..4878d4ad7 100644
--- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_facts.py
+++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_facts.py
@@ -19,11 +19,11 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
+from unittest.mock import patch
from ansible.module_utils.six import assertCountEqual
from ansible_collections.cisco.ios.plugins.modules import ios_facts
-from ansible_collections.cisco.ios.tests.unit.compat.mock import patch
from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args
from .ios_module import TestIosModule, load_fixture
@@ -80,8 +80,14 @@ class TestIosFactsModule(TestIosModule):
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,10 +101,16 @@ class TestIosFactsModule(TestIosModule):
set_module_args(dict(gather_subset="interfaces"))
result = self.execute_module()
self.assertEqual(
- result["ansible_facts"]["ansible_net_interfaces"]["GigabitEthernet0/0"]["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"],
+ "5e00.0008.0000",
+ )
+ self.assertEqual(
result["ansible_facts"]["ansible_net_interfaces"]["GigabitEthernet1"]["macaddress"],
"5e00.0006.0000",
)
diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_hostname.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_hostname.py
index 6b16bddf0..359cf562a 100644
--- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_hostname.py
+++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_hostname.py
@@ -7,11 +7,10 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-
from textwrap import dedent
+from unittest.mock import patch
from ansible_collections.cisco.ios.plugins.modules import ios_hostname
-from ansible_collections.cisco.ios.tests.unit.compat.mock import patch
from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args
from .ios_module import TestIosModule
diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_interfaces.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_interfaces.py
index caac40ccb..63ee2341b 100644
--- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_interfaces.py
+++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_interfaces.py
@@ -7,11 +7,10 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-
from textwrap import dedent
+from unittest.mock import patch
from ansible_collections.cisco.ios.plugins.modules import ios_interfaces
-from ansible_collections.cisco.ios.tests.unit.compat.mock import patch
from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args
from .ios_module import TestIosModule
@@ -150,7 +149,10 @@ class TestIosInterfacesModule(TestIosModule):
set_module_args(
{
"config": [
- {"description": "Ansible UT interface 1", "name": "GigabitEthernet1"},
+ {
+ "description": "Ansible UT interface 1",
+ "name": "GigabitEthernet1",
+ },
{
"description": "Ansible UT interface 2",
"name": "GigabitEthernet0/1",
@@ -204,7 +206,10 @@ class TestIosInterfacesModule(TestIosModule):
set_module_args(
{
"config": [
- {"description": "Ansible UT interface 1", "name": "GigabitEthernet1"},
+ {
+ "description": "Ansible UT interface 1",
+ "name": "GigabitEthernet1",
+ },
{"name": "GigabitEthernet0/1", "speed": 1200, "mtu": 1800},
{
"name": "GigabitEthernet6",
@@ -267,7 +272,10 @@ class TestIosInterfacesModule(TestIosModule):
set_module_args(
{
"config": [
- {"description": "Ansible UT interface 1", "name": "GigabitEthernet1"},
+ {
+ "description": "Ansible UT interface 1",
+ "name": "GigabitEthernet1",
+ },
{
"description": "Ansible UT interface 2",
"name": "GigabitEthernet0/1",
@@ -570,14 +578,22 @@ class TestIosInterfacesModule(TestIosModule):
"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/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_l2_interfaces.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_l2_interfaces.py
index d9ec2b189..e84846aeb 100644
--- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_l2_interfaces.py
+++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_l2_interfaces.py
@@ -7,11 +7,10 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-
from textwrap import dedent
+from unittest.mock import patch
from ansible_collections.cisco.ios.plugins.modules import ios_l2_interfaces
-from ansible_collections.cisco.ios.tests.unit.compat.mock import patch
from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args
from .ios_module import TestIosModule
@@ -136,7 +135,11 @@ class TestIosL2InterfacesModule(TestIosModule):
set_module_args(
dict(
config=[
- dict(access=dict(vlan=10), mode="access", name="GigabitEthernet0/1"),
+ dict(
+ access=dict(vlan=10),
+ mode="access",
+ name="GigabitEthernet0/1",
+ ),
dict(
mode="trunk",
name="GigabitEthernet0/2",
@@ -270,7 +273,11 @@ class TestIosL2InterfacesModule(TestIosModule):
set_module_args(
dict(
config=[
- dict(access=dict(vlan=10), mode="access", name="GigabitEthernet0/1"),
+ dict(
+ access=dict(vlan=10),
+ mode="access",
+ name="GigabitEthernet0/1",
+ ),
dict(
mode="trunk",
name="GigabitEthernet0/2",
@@ -281,7 +288,11 @@ class TestIosL2InterfacesModule(TestIosModule):
pruning_vlans=["10", "20"],
),
),
- dict(access=dict(vlan=20), mode="access", name="TwoGigabitEthernet1/0/1"),
+ dict(
+ access=dict(vlan=20),
+ mode="access",
+ name="TwoGigabitEthernet1/0/1",
+ ),
dict(
mode="trunk",
name="GigabitEthernet0/3",
@@ -416,7 +427,11 @@ class TestIosL2InterfacesModule(TestIosModule):
set_module_args(
dict(
config=[
- dict(access=dict(vlan=10), mode="access", name="GigabitEthernet0/1"),
+ dict(
+ access=dict(vlan=10),
+ mode="access",
+ name="GigabitEthernet0/1",
+ ),
dict(
mode="trunk",
name="GigabitEthernet0/2",
@@ -427,7 +442,11 @@ class TestIosL2InterfacesModule(TestIosModule):
pruning_vlans=["10", "20"],
),
),
- dict(access=dict(vlan=20), mode="access", name="TwoGigabitEthernet1/0/1"),
+ dict(
+ access=dict(vlan=20),
+ mode="access",
+ name="TwoGigabitEthernet1/0/1",
+ ),
dict(
mode="trunk",
name="GigabitEthernet0/3",
@@ -592,7 +611,11 @@ class TestIosL2InterfacesModule(TestIosModule):
},
"mode": "trunk",
},
- {"name": "TwoGigabitEthernet1/0/1", "mode": "access", "access": {"vlan": 20}},
+ {
+ "name": "TwoGigabitEthernet1/0/1",
+ "mode": "access",
+ "access": {"vlan": 20},
+ },
{
"name": "GigabitEthernet0/3",
"trunk": {
@@ -695,7 +718,13 @@ class TestIosL2InterfacesModule(TestIosModule):
)
set_module_args(
dict(
- config=[dict(access=dict(vlan=20), mode="trunk", name="TwoGigabitEthernet1/0/1")],
+ config=[
+ dict(
+ access=dict(vlan=20),
+ mode="trunk",
+ name="TwoGigabitEthernet1/0/1",
+ ),
+ ],
state="merged",
),
)
@@ -731,7 +760,11 @@ class TestIosL2InterfacesModule(TestIosModule):
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/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_l3_interfaces.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_l3_interfaces.py
index de9442b59..3e3cc038b 100644
--- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_l3_interfaces.py
+++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_l3_interfaces.py
@@ -7,11 +7,10 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-
from textwrap import dedent
+from unittest.mock import patch
from ansible_collections.cisco.ios.plugins.modules import ios_l3_interfaces
-from ansible_collections.cisco.ios.tests.unit.compat.mock import patch
from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args
from .ios_module import TestIosModule
@@ -46,6 +45,9 @@ class TestIosL3InterfacesModule(TestIosModule):
interface GigabitEthernet0/3.100
encapsulation dot1Q 20
ip address 192.168.0.3 255.255.255.0
+ interface VirtualPortGroup0
+ ip address 192.168.0.4 255.255.255.0
+ ipv6 address fe80:0:3a2:84::3 link-local
interface Serial3/0
ipv6 address fd5d:12c9:2201:1::1/64
interface Serial7/0
@@ -58,7 +60,20 @@ class TestIosL3InterfacesModule(TestIosModule):
name="GigabitEthernet0/3.100",
ipv4=[dict(address="192.168.0.3/24", secondary=True)],
),
- dict(name="Serial3/0", ipv6=[dict(address="FD5D:12C9:2201:1::1/64", cga=True)]),
+ dict(
+ name="Serial3/0",
+ ipv6=[dict(address="FD5D:12C9:2201:1::1/64", cga=True)],
+ ),
+ dict(
+ name="VirtualPortGroup0",
+ ipv4=[dict(address="192.168.0.4/24", secondary=True)],
+ ipv6=[
+ dict(
+ address="fe80:0:3a2:84::3",
+ link_local=True,
+ ),
+ ],
+ ),
],
state="merged",
),
@@ -94,7 +109,10 @@ class TestIosL3InterfacesModule(TestIosModule):
name="GigabitEthernet0/1",
ipv4=[dict(address="192.168.0.1/24", secondary=True)],
),
- dict(name="GigabitEthernet0/2", ipv4=[dict(address="192.168.0.2/24")]),
+ dict(
+ name="GigabitEthernet0/2",
+ ipv4=[dict(address="192.168.0.2/24")],
+ ),
dict(name="Serial1/0", ipv4=[dict(address="192.168.0.3/24")]),
],
state="overridden",
@@ -171,13 +189,19 @@ class TestIosL3InterfacesModule(TestIosModule):
set_module_args(
dict(
config=[
- dict(name="GigabitEthernet0/3", ipv6=[dict(address="FD5D:12C9:2202:1::1/64")]),
+ dict(
+ name="GigabitEthernet0/3",
+ ipv6=[dict(address="FD5D:12C9:2202:1::1/64")],
+ ),
dict(
name="GigabitEthernet0/2",
ipv4=[dict(address="192.168.0.2/24", secondary=False)],
),
dict(name="Serial1/0", ipv4=[dict(address="192.168.0.5/24")]),
- dict(name="GigabitEthernet0/3.100", ipv4=[dict(address="192.168.0.4/24")]),
+ dict(
+ name="GigabitEthernet0/3.100",
+ ipv4=[dict(address="192.168.0.4/24")],
+ ),
],
state="replaced",
),
@@ -206,7 +230,9 @@ class TestIosL3InterfacesModule(TestIosModule):
),
)
result = self.execute_module(changed=False)
- parsed_list = [{"name": "GigabitEthernet0/3.100", "ipv4": [{"address": "192.168.0.3/24"}]}]
+ parsed_list = [
+ {"name": "GigabitEthernet0/3.100", "ipv4": [{"address": "192.168.0.3/24"}]},
+ ]
self.assertEqual(parsed_list, result["parsed"])
def test_ios_l3_interfaces_rendered(self):
@@ -279,6 +305,8 @@ class TestIosL3InterfacesModule(TestIosModule):
ip address 192.168.0.3 255.255.255.0
interface Serial1/0
description Configured by PAUL
+ interface Vlan901
+ ip unnumbered Loopback2
""",
)
set_module_args(
@@ -286,7 +314,14 @@ class TestIosL3InterfacesModule(TestIosModule):
config=[
dict(
name="GigabitEthernet0/1",
- ipv4=[dict(dhcp=dict(client_id="GigabitEthernet0/2", hostname="test.com"))],
+ ipv4=[
+ dict(
+ dhcp=dict(
+ client_id="GigabitEthernet0/2",
+ hostname="test.com",
+ ),
+ ),
+ ],
),
dict(name="GigabitEthernet0/2", ipv4=[dict(pool="PoolName1")]),
dict(name="Serial1/0", ipv6=[dict(autoconfig=dict(default=True))]),
@@ -296,8 +331,14 @@ class TestIosL3InterfacesModule(TestIosModule):
ipv6=[dict(address="FD5D:12C9:2201:1::1/64", anycast=True)],
),
dict(name="Vlan51", ipv4=[dict(address="192.168.0.4/31")]),
- dict(name="Serial4/0", ipv6=[dict(address="FD5D:12C9:2201:2::1/64", cga=True)]),
- dict(name="Serial5/0", ipv6=[dict(address="FD5D:12C9:2201:3::1/64", eui=True)]),
+ dict(
+ name="Serial4/0",
+ ipv6=[dict(address="FD5D:12C9:2201:2::1/64", cga=True)],
+ ),
+ dict(
+ name="Serial5/0",
+ ipv6=[dict(address="FD5D:12C9:2201:3::1/64", eui=True)],
+ ),
dict(
name="Serial6/0",
ipv6=[dict(address="FD5D:12C9:2201:4::1/64", link_local=True)],
@@ -320,6 +361,20 @@ class TestIosL3InterfacesModule(TestIosModule):
),
],
),
+ dict(
+ autostate=False,
+ name="Vlan901",
+ ipv6=[
+ dict(
+ enable=True,
+ ),
+ ],
+ ipv4=[
+ dict(
+ source_interface=dict(name="Loopback1"),
+ ),
+ ],
+ ),
],
state="merged",
),
@@ -347,6 +402,10 @@ class TestIosL3InterfacesModule(TestIosModule):
"ipv6 address fd5d:12c9:2201:3::1/64 eui",
"interface Vlan51",
"ip address 192.168.0.4 255.255.255.254",
+ "interface Vlan901",
+ "ip unnumbered Loopback1",
+ "ipv6 enable",
+ "no autostate",
]
result = self.execute_module(changed=True)
@@ -381,16 +440,32 @@ class TestIosL3InterfacesModule(TestIosModule):
config=[
dict(
name="GigabitEthernet0/1",
- ipv4=[dict(dhcp=dict(client_id="GigabitEthernet0/2", hostname="test.com"))],
+ ipv4=[
+ dict(
+ dhcp=dict(
+ client_id="GigabitEthernet0/2",
+ hostname="test.com",
+ ),
+ ),
+ ],
+ ),
+ dict(
+ name="GigabitEthernet0/3.100",
+ ipv4=[dict(address="192.168.0.3/24")],
),
- dict(name="GigabitEthernet0/3.100", ipv4=[dict(address="192.168.0.3/24")]),
dict(name="Serial2/0", ipv6=[dict(dhcp=dict(rapid_commit=True))]),
dict(
name="Serial3/0",
ipv6=[dict(address="FD5D:12C9:2201:1::1/64", anycast=True)],
),
- dict(name="Serial4/0", ipv6=[dict(address="FD5D:12C9:2201:2::1/64", cga=True)]),
- dict(name="Serial5/0", ipv6=[dict(address="FD5D:12C9:2201:3::1/64", eui=True)]),
+ dict(
+ name="Serial4/0",
+ ipv6=[dict(address="FD5D:12C9:2201:2::1/64", cga=True)],
+ ),
+ dict(
+ name="Serial5/0",
+ ipv6=[dict(address="FD5D:12C9:2201:3::1/64", eui=True)],
+ ),
dict(
name="Serial6/0",
ipv6=[dict(address="FD5D:12C9:2201:4::1/64", link_local=True)],
@@ -433,7 +508,10 @@ class TestIosL3InterfacesModule(TestIosModule):
set_module_args(
dict(
config=[
- dict(name="GigabitEthernet0/3.100", ipv4=[dict(address="192.168.1.3/24")]),
+ dict(
+ name="GigabitEthernet0/3.100",
+ ipv4=[dict(address="192.168.1.3/24")],
+ ),
],
state="replaced",
),
diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lacp.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lacp.py
index 6c56406e6..f4460162a 100644
--- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lacp.py
+++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lacp.py
@@ -7,11 +7,10 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-
from textwrap import dedent
+from unittest.mock import patch
from ansible_collections.cisco.ios.plugins.modules import ios_lacp
-from ansible_collections.cisco.ios.tests.unit.compat.mock import patch
from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args
from .ios_module import TestIosModule
diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lacp_interfaces.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lacp_interfaces.py
index f58aa9d65..817c6869c 100644
--- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lacp_interfaces.py
+++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lacp_interfaces.py
@@ -7,11 +7,10 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-
from textwrap import dedent
+from unittest.mock import patch
from ansible_collections.cisco.ios.plugins.modules import ios_lacp_interfaces
-from ansible_collections.cisco.ios.tests.unit.compat.mock import patch
from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args
from .ios_module import TestIosModule
@@ -83,7 +82,11 @@ class TestIosLacpInterfaceModule(TestIosModule):
set_module_args(
dict(
config=[
- {"name": "Port-channel10", "fast_switchover": True, "max_bundle": 12},
+ {
+ "name": "Port-channel10",
+ "fast_switchover": True,
+ "max_bundle": 12,
+ },
{"name": "Port-channel40", "max_bundle": 5},
{"name": "GigabitEthernet0/0"},
{"name": "GigabitEthernet0/1", "port_priority": 20},
@@ -121,7 +124,11 @@ class TestIosLacpInterfaceModule(TestIosModule):
set_module_args(
dict(
config=[
- {"name": "Port-channel10", "fast_switchover": True, "max_bundle": 2},
+ {
+ "name": "Port-channel10",
+ "fast_switchover": True,
+ "max_bundle": 2,
+ },
{"name": "Port-channel40", "max_bundle": 5},
{"name": "GigabitEthernet0/0"},
{"name": "GigabitEthernet0/1", "port_priority": 30},
@@ -150,7 +157,11 @@ class TestIosLacpInterfaceModule(TestIosModule):
set_module_args(
dict(
config=[
- {"name": "Port-channel10", "fast_switchover": True, "max_bundle": 12},
+ {
+ "name": "Port-channel10",
+ "fast_switchover": True,
+ "max_bundle": 12,
+ },
{"name": "Port-channel40", "max_bundle": 5},
{"name": "GigabitEthernet0/0"},
{"name": "GigabitEthernet0/1", "port_priority": 20},
@@ -188,7 +199,11 @@ class TestIosLacpInterfaceModule(TestIosModule):
set_module_args(
dict(
config=[
- {"name": "Port-channel10", "fast_switchover": True, "max_bundle": 12},
+ {
+ "name": "Port-channel10",
+ "fast_switchover": True,
+ "max_bundle": 12,
+ },
{"name": "Port-channel40", "max_bundle": 5},
{"name": "GigabitEthernet0/0"},
{"name": "GigabitEthernet0/1", "port_priority": 20},
@@ -226,7 +241,11 @@ class TestIosLacpInterfaceModule(TestIosModule):
set_module_args(
dict(
config=[
- {"name": "Port-channel10", "fast_switchover": True, "max_bundle": 12},
+ {
+ "name": "Port-channel10",
+ "fast_switchover": True,
+ "max_bundle": 12,
+ },
{"name": "Port-channel40", "max_bundle": 5},
{"name": "GigabitEthernet0/0"},
{"name": "GigabitEthernet0/1", "port_priority": 20},
@@ -287,7 +306,11 @@ class TestIosLacpInterfaceModule(TestIosModule):
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/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lag_interfaces.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lag_interfaces.py
index 1f97bef24..71d6ff933 100644
--- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lag_interfaces.py
+++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lag_interfaces.py
@@ -7,11 +7,10 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-
from textwrap import dedent
+from unittest.mock import patch
from ansible_collections.cisco.ios.plugins.modules import ios_lag_interfaces
-from ansible_collections.cisco.ios.tests.unit.compat.mock import patch
from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args
from .ios_module import TestIosModule
@@ -73,7 +72,11 @@ class TestIosLagInterfacesModule(TestIosModule):
"members": [
{"member": "GigabitEthernet0/2", "mode": "active"},
{"member": "GigabitEthernet0/3", "mode": "passive"},
- {"link": 20, "member": "GigabitEthernet0/4", "mode": "active"},
+ {
+ "link": 20,
+ "member": "GigabitEthernet0/4",
+ "mode": "active",
+ },
{"link": 22, "member": "GigabitEthernet0/5"},
],
"name": "Port-channel22",
@@ -120,7 +123,11 @@ class TestIosLagInterfacesModule(TestIosModule):
"members": [
{"member": "GigabitEthernet0/2", "mode": "active"},
{"member": "GigabitEthernet0/3", "mode": "active"},
- {"link": 20, "member": "GigabitEthernet0/4", "mode": "active"},
+ {
+ "link": 20,
+ "member": "GigabitEthernet0/4",
+ "mode": "active",
+ },
{"link": 22, "member": "GigabitEthernet0/5"},
],
"name": "Port-channel22",
@@ -164,7 +171,11 @@ class TestIosLagInterfacesModule(TestIosModule):
"members": [
{"member": "GigabitEthernet0/1", "mode": "active"},
{"member": "GigabitEthernet0/3", "mode": "on"},
- {"link": 20, "member": "GigabitEthernet0/4", "mode": "active"},
+ {
+ "link": 20,
+ "member": "GigabitEthernet0/4",
+ "mode": "active",
+ },
{"link": 22, "member": "GigabitEthernet0/5"},
],
"name": "Port-channel22",
@@ -219,7 +230,11 @@ class TestIosLagInterfacesModule(TestIosModule):
"members": [
{"member": "GigabitEthernet0/2", "mode": "active"},
{"member": "GigabitEthernet0/3", "mode": "active"},
- {"link": 20, "member": "GigabitEthernet0/4", "mode": "active"},
+ {
+ "link": 20,
+ "member": "GigabitEthernet0/4",
+ "mode": "active",
+ },
{"link": 22, "member": "GigabitEthernet0/5"},
],
"name": "Port-channel22",
@@ -259,7 +274,11 @@ class TestIosLagInterfacesModule(TestIosModule):
"members": [
{"member": "GigabitEthernet0/2", "mode": "active"},
{"member": "GigabitEthernet0/3", "mode": "active"},
- {"link": 20, "member": "GigabitEthernet0/4", "mode": "active"},
+ {
+ "link": 20,
+ "member": "GigabitEthernet0/4",
+ "mode": "active",
+ },
{"link": 22, "member": "GigabitEthernet0/5"},
],
"name": "Port-channel22",
@@ -314,7 +333,11 @@ class TestIosLagInterfacesModule(TestIosModule):
"members": [
{"member": "GigabitEthernet0/2", "mode": "active"},
{"member": "GigabitEthernet0/3", "mode": "active"},
- {"link": 20, "member": "GigabitEthernet0/4", "mode": "active"},
+ {
+ "link": 20,
+ "member": "GigabitEthernet0/4",
+ "mode": "active",
+ },
{"link": 22, "member": "GigabitEthernet0/5"},
],
"name": "Port-channel22",
@@ -459,7 +482,11 @@ class TestIosLagInterfacesModule(TestIosModule):
"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/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lldp_global.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lldp_global.py
index 4c54ef5c9..2c5eb1c40 100644
--- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lldp_global.py
+++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lldp_global.py
@@ -7,11 +7,10 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-
from textwrap import dedent
+from unittest.mock import patch
from ansible_collections.cisco.ios.plugins.modules import ios_lldp_global
-from ansible_collections.cisco.ios.tests.unit.compat.mock import patch
from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args
from .ios_module import TestIosModule
@@ -154,7 +153,12 @@ class TestIosLldpGlobalModule(TestIosModule):
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/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lldp_inteface.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lldp_inteface.py
index a3dfe9706..04a25993a 100644
--- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lldp_inteface.py
+++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lldp_inteface.py
@@ -7,11 +7,10 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-
from textwrap import dedent
+from unittest.mock import patch
from ansible_collections.cisco.ios.plugins.modules import ios_lldp_interfaces
-from ansible_collections.cisco.ios.tests.unit.compat.mock import patch
from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args
from .ios_module import TestIosModule
@@ -241,7 +240,10 @@ class TestIosLldpInterfacesModule(TestIosModule):
)
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/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_logging_global.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_logging_global.py
index c3024636a..f1b3eada3 100644
--- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_logging_global.py
+++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_logging_global.py
@@ -7,11 +7,10 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-
from textwrap import dedent
+from unittest.mock import patch
from ansible_collections.cisco.ios.plugins.modules import ios_logging_global
-from ansible_collections.cisco.ios.tests.unit.compat.mock import patch
from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args
from .ios_module import TestIosModule
@@ -120,7 +119,10 @@ class TestIosLoggingGlobalModule(TestIosModule):
reload=dict(severity="alerts"),
server_arp=True,
snmp_trap=["errors"],
- source_interface=[dict(interface="GBit1/0"), dict(interface="CTunnel2")],
+ source_interface=[
+ dict(interface="GBit1/0"),
+ dict(interface="CTunnel2"),
+ ],
trap="errors",
userinfo=True,
),
@@ -250,7 +252,10 @@ class TestIosLoggingGlobalModule(TestIosModule):
],
message_counter=["log", "debug"],
snmp_trap=["errors"],
- source_interface=[dict(interface="GBit1/0"), dict(interface="CTunnel2")],
+ source_interface=[
+ dict(interface="GBit1/0"),
+ dict(interface="CTunnel2"),
+ ],
),
)
deleted = [
@@ -317,7 +322,10 @@ class TestIosLoggingGlobalModule(TestIosModule):
],
message_counter=["log", "debug"],
snmp_trap=["errors"],
- source_interface=[dict(interface="GBit1/0"), dict(interface="CTunnel2")],
+ source_interface=[
+ dict(interface="GBit1/0"),
+ dict(interface="CTunnel2"),
+ ],
),
)
overridden = [
@@ -402,9 +410,16 @@ class TestIosLoggingGlobalModule(TestIosModule):
ipv6="2001:0db8:85a3:0000:0000:8a2e:0370:7304",
discriminator="msglog01 severity includes 5",
),
- dict(ipv6="2001:0db8:85a3:0000:0000:8a2e:0370:7314", sequence_num_session=True),
+ dict(
+ ipv6="2001:0db8:85a3:0000:0000:8a2e:0370:7314",
+ sequence_num_session=True,
+ ),
dict(ipv6="2001:0db8:85a3:0000:0000:8a2e:0370:7324", vrf="vpn1"),
- dict(ipv6="2001:0db8:85a3:0000:0000:8a2e:0370:7334", stream=10, filtered=True),
+ dict(
+ ipv6="2001:0db8:85a3:0000:0000:8a2e:0370:7334",
+ stream=10,
+ filtered=True,
+ ),
dict(
ipv6="2001:0db8:85a3:0000:0000:8a2e:0370:7344",
session_id=dict(tag="ipv4"),
@@ -416,7 +431,9 @@ class TestIosLoggingGlobalModule(TestIosModule):
dict(
ipv6="2001:0db8:85a3:0000:0000:8a2e:0370:7374",
vrf="Apn2",
- transport=dict(udp=dict(discriminator="msglog01 severity includes 5")),
+ transport=dict(
+ udp=dict(discriminator="msglog01 severity includes 5"),
+ ),
),
dict(
ipv6="2001:0db8:85a3:0000:0000:8a2e:0370:7384",
@@ -509,7 +526,13 @@ class TestIosLoggingGlobalModule(TestIosModule):
)
set_module_args(dict(state="gathered"))
gathered = dict(
- hosts=[dict(hostname="172.16.1.1", vrf="vpn-1", transport=dict(tcp=dict(audit=True)))],
+ hosts=[
+ dict(
+ hostname="172.16.1.1",
+ vrf="vpn-1",
+ transport=dict(tcp=dict(audit=True)),
+ ),
+ ],
)
result = self.execute_module(changed=False)
@@ -617,9 +640,14 @@ class TestIosLoggingGlobalModule(TestIosModule):
""",
)
playbook = dict(
- config=dict(hosts=[dict(hostname="172.16.2.15", session_id=dict(text="Test"))]),
+ config=dict(
+ hosts=[dict(hostname="172.16.2.15", session_id=dict(text="Test"))],
+ ),
)
- replaced = ["no logging host 172.16.1.1", "logging host 172.16.2.15 session-id string Test"]
+ replaced = [
+ "no logging host 172.16.1.1",
+ "logging host 172.16.2.15 session-id string Test",
+ ]
playbook["state"] = "replaced"
set_module_args(playbook)
result = self.execute_module(changed=True)
@@ -651,8 +679,14 @@ class TestIosLoggingGlobalModule(TestIosModule):
{"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/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ntp.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ntp.py
deleted file mode 100644
index 3e73fdfd4..000000000
--- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ntp.py
+++ /dev/null
@@ -1,110 +0,0 @@
-# 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 <http://www.gnu.org/licenses/>.
-
-# Make coding more python3-ish
-from __future__ import absolute_import, division, print_function
-
-
-__metaclass__ = type
-
-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
-
-
-class TestIosNtpModule(TestIosModule):
- module = ios_ntp
-
- def setUp(self):
- super(TestIosNtpModule, self).setUp()
-
- self.mock_get_config = patch(
- "ansible_collections.cisco.ios.plugins.modules.ios_ntp.get_config",
- )
- self.get_config = self.mock_get_config.start()
-
- self.mock_load_config = patch(
- "ansible_collections.cisco.ios.plugins.modules.ios_ntp.load_config",
- )
- self.load_config = self.mock_load_config.start()
-
- def tearDown(self):
- super(TestIosNtpModule, self).tearDown()
- self.mock_get_config.stop()
- self.mock_load_config.stop()
-
- def load_fixtures(self, commands=None):
- self.get_config.return_value = load_fixture("ios_ntp_config.cfg").strip()
- self.load_config.return_value = dict(diff=None, session="session")
-
- def test_ios_ntp_idempotent(self):
- set_module_args(
- dict(
- server="10.75.32.5",
- source_int="Loopback0",
- acl="NTP_ACL",
- logging=True,
- auth=True,
- auth_key="15435A030726242723273C21181319000A",
- key_id="10",
- vrf="my_mgmt_vrf",
- state="present",
- ),
- )
- commands = []
- self.execute_module(changed=False, commands=commands)
-
- def test_ios_ntp_config(self):
- set_module_args(
- dict(
- server="10.75.33.5",
- source_int="Vlan2",
- acl="NTP_ACL",
- logging=True,
- auth=True,
- auth_key="15435A030726242723273C21181319000A",
- key_id="10",
- state="present",
- ),
- )
- commands = ["ntp server 10.75.33.5", "ntp source Vlan2"]
- self.execute_module(changed=True, commands=commands)
-
- def test_ios_ntp_remove(self):
- set_module_args(
- dict(
- server="10.75.32.5",
- source_int="Loopback0",
- acl="NTP_ACL",
- logging=True,
- auth=True,
- auth_key="15435A030726242723273C21181319000A",
- key_id="10",
- vrf="my_mgmt_vrf",
- state="absent",
- ),
- )
- commands = [
- "no ntp server vrf my_mgmt_vrf 10.75.32.5",
- "no ntp source Loopback0",
- "no ntp access-group peer NTP_ACL",
- "no ntp logging",
- "no ntp authenticate",
- "no ntp trusted-key 10",
- "no ntp authentication-key 10 md5 15435A030726242723273C21181319000A 7",
- ]
- self.execute_module(changed=True, commands=commands)
diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ntp_global.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ntp_global.py
index a9d0392c1..e955c2929 100644
--- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ntp_global.py
+++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ntp_global.py
@@ -7,11 +7,10 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-
from textwrap import dedent
+from unittest.mock import patch
from ansible_collections.cisco.ios.plugins.modules import ios_ntp_global
-from ansible_collections.cisco.ios.tests.unit.compat.mock import patch
from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args
from .ios_module import TestIosModule
@@ -86,7 +85,12 @@ class TestIosNtpGlobalModule(TestIosModule):
allow=dict(control=dict(rate_limit=4)),
authenticate=True,
authentication_keys=[
- dict(algorithm="md5", encryption=7, id=2, key="SomeSecurePassword"),
+ dict(
+ algorithm="md5",
+ encryption=7,
+ id=2,
+ key="SomeSecurePassword",
+ ),
],
broadcast_delay=22,
logging=True,
@@ -98,8 +102,18 @@ class TestIosNtpGlobalModule(TestIosModule):
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 @@ class TestIosNtpGlobalModule(TestIosModule):
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 @@ class TestIosNtpGlobalModule(TestIosModule):
allow=dict(control=dict(rate_limit=4)),
authenticate=True,
authentication_keys=[
- dict(algorithm="md5", encryption=7, id=2, key="SomeSecurePassword"),
+ dict(
+ algorithm="md5",
+ encryption=7,
+ id=2,
+ key="SomeSecurePassword",
+ ),
],
broadcast_delay=22,
logging=True,
@@ -150,8 +172,18 @@ class TestIosNtpGlobalModule(TestIosModule):
panic_update=True,
peers=[
dict(peer="172.16.1.10", version=2),
- dict(key=2, minpoll=5, peer="172.16.1.11", prefer=True, version=2),
- dict(peer="checkPeerDomainIpv4.com", prefer=True, use_ipv4=True),
+ dict(
+ key=2,
+ minpoll=5,
+ peer="172.16.1.11",
+ prefer=True,
+ version=2,
+ ),
+ dict(
+ peer="checkPeerDomainIpv4.com",
+ prefer=True,
+ use_ipv4=True,
+ ),
dict(peer="checkPeerDomainIpv6.com", use_ipv6=True),
dict(peer="testPeerDomainIpv6.com", prefer=True, use_ipv6=True),
],
@@ -162,7 +194,10 @@ class TestIosNtpGlobalModule(TestIosModule):
dict(server="checkServerDomainIpv6.com", use_ipv6=True),
],
source="GigabitEthernet0/1",
- trusted_keys=[dict(range_start=21), dict(range_end=13, range_start=3)],
+ trusted_keys=[
+ dict(range_start=21),
+ dict(range_end=13, range_start=3),
+ ],
update_calendar=True,
),
state="merged",
@@ -324,7 +359,12 @@ class TestIosNtpGlobalModule(TestIosModule):
allow=dict(control=dict(rate_limit=4)),
authenticate=True,
authentication_keys=[
- dict(algorithm="md5", encryption=7, id=2, key="SomeSecurePassword"),
+ dict(
+ algorithm="md5",
+ encryption=7,
+ id=2,
+ key="SomeSecurePassword",
+ ),
],
broadcast_delay=22,
logging=True,
@@ -336,8 +376,18 @@ class TestIosNtpGlobalModule(TestIosModule):
panic_update=True,
peers=[
dict(peer="172.16.1.10", version=2),
- dict(key=2, minpoll=5, peer="172.16.1.11", prefer=True, version=2),
- dict(peer="checkPeerDomainIpv4.com", prefer=True, use_ipv4=True),
+ dict(
+ key=2,
+ minpoll=5,
+ peer="172.16.1.11",
+ prefer=True,
+ version=2,
+ ),
+ dict(
+ peer="checkPeerDomainIpv4.com",
+ prefer=True,
+ use_ipv4=True,
+ ),
dict(peer="checkPeerDomainIpv6.com", use_ipv6=True),
dict(peer="testPeerDomainIpv6.com", prefer=True, use_ipv6=True),
],
@@ -347,7 +397,10 @@ class TestIosNtpGlobalModule(TestIosModule):
dict(server="checkServerDomainIpv6.com", use_ipv6=True),
],
source="GigabitEthernet0/1",
- trusted_keys=[dict(range_start=21), dict(range_end=13, range_start=3)],
+ trusted_keys=[
+ dict(range_start=21),
+ dict(range_end=13, range_start=3),
+ ],
update_calendar=True,
),
state="replaced",
@@ -415,7 +468,12 @@ class TestIosNtpGlobalModule(TestIosModule):
allow=dict(control=dict(rate_limit=4)),
authenticate=True,
authentication_keys=[
- dict(algorithm="md5", encryption=7, id=2, key="SomeSecurePassword"),
+ dict(
+ algorithm="md5",
+ encryption=7,
+ id=2,
+ key="SomeSecurePassword",
+ ),
],
broadcast_delay=22,
logging=True,
@@ -426,15 +484,28 @@ class TestIosNtpGlobalModule(TestIosModule):
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/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ospf_interfaces.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ospf_interfaces.py
index 3721ba3ba..ea500f540 100644
--- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ospf_interfaces.py
+++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ospf_interfaces.py
@@ -7,11 +7,10 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-
from textwrap import dedent
+from unittest.mock import patch
from ansible_collections.cisco.ios.plugins.modules import ios_ospf_interfaces
-from ansible_collections.cisco.ios.tests.unit.compat.mock import patch
from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args
from .ios_module import TestIosModule
diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ospfv2.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ospfv2.py
index b73e34395..e14def8d8 100644
--- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ospfv2.py
+++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ospfv2.py
@@ -7,11 +7,10 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-
from textwrap import dedent
+from unittest.mock import patch
from ansible_collections.cisco.ios.plugins.modules import ios_ospfv2
-from ansible_collections.cisco.ios.tests.unit.compat.mock import patch
from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args
from .ios_module import TestIosModule
@@ -76,13 +75,24 @@ class TestIosOspfV2Module(TestIosModule):
),
),
network=[
- dict(address="198.51.100.0", wildcard_bits="0.0.0.255", area=5),
- dict(address="192.0.2.0", wildcard_bits="0.0.0.255", area=5),
+ dict(
+ address="198.51.100.0",
+ wildcard_bits="0.0.0.255",
+ area=5,
+ ),
+ dict(
+ address="192.0.2.0",
+ wildcard_bits="0.0.0.255",
+ area=5,
+ ),
],
domain_id=dict(ip_address=dict(address="192.0.3.1")),
max_metric=dict(on_startup=dict(time=100), router_lsa=True),
passive_interfaces=dict(
- interface=dict(set_interface=False, name=["GigabitEthernet0/2"]),
+ interface=dict(
+ set_interface=False,
+ name=["GigabitEthernet0/2"],
+ ),
),
vrf="blue",
),
@@ -284,11 +294,17 @@ class TestIosOspfV2Module(TestIosModule):
"areas": [
{
"area_id": "5",
- "authentication": {"enable": True, "message_digest": True},
+ "authentication": {
+ "enable": True,
+ "message_digest": True,
+ },
},
{
"area_id": "10",
- "authentication": {"enable": True, "message_digest": True},
+ "authentication": {
+ "enable": True,
+ "message_digest": True,
+ },
"capability": True,
"default_cost": 10,
"filter_list": [
@@ -470,7 +486,10 @@ class TestIosOspfV2Module(TestIosModule):
"passive_interfaces": {
"default": True,
"interface": {
- "name": ["GigabitEthernet0/1", "GigabitEthernet0/2"],
+ "name": [
+ "GigabitEthernet0/1",
+ "GigabitEthernet0/2",
+ ],
"set_interface": False,
},
},
@@ -535,6 +554,7 @@ class TestIosOspfV2Module(TestIosModule):
"default-information originate always metric 25 metric-type 26 route-map rmap1",
"default-metric 50",
"discard-route external 5 internal 2",
+ "distance 2 192.168.1.0 0.0.0.255 acl1",
"distance ospf inter-area 2 intra-area 3 external 1",
"domain-id 192.168.1.0 secondary",
"domain-tag 54",
@@ -601,7 +621,10 @@ class TestIosOspfV2Module(TestIosModule):
""",
)
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)
@@ -632,7 +655,11 @@ class TestIosOspfV2Module(TestIosModule):
"processes": [
{
"areas": [
- {"area_id": "5", "authentication": {"enable": True}, "capability": True},
+ {
+ "area_id": "5",
+ "authentication": {"enable": True},
+ "capability": True,
+ },
],
"process_id": 1,
},
@@ -677,11 +704,17 @@ class TestIosOspfV2Module(TestIosModule):
"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": [
@@ -862,7 +895,10 @@ class TestIosOspfV2Module(TestIosModule):
"passive_interfaces": {
"default": True,
"interface": {
- "name": ["GigabitEthernet0/1", "GigabitEthernet0/2"],
+ "name": [
+ "GigabitEthernet0/1",
+ "GigabitEthernet0/2",
+ ],
"set_interface": False,
},
},
@@ -933,6 +969,7 @@ class TestIosOspfV2Module(TestIosModule):
"default-information originate always metric 25 metric-type 26 route-map rmap1",
"default-metric 50",
"discard-route external 5 internal 2",
+ "distance 2 192.168.1.0 0.0.0.255 acl1",
"distance ospf inter-area 2 intra-area 3 external 1",
"domain-id 192.168.1.0 secondary",
"domain-tag 54",
@@ -1029,13 +1066,19 @@ class TestIosOspfV2Module(TestIosModule):
"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",
+ ],
},
},
},
@@ -1141,13 +1184,19 @@ class TestIosOspfV2Module(TestIosModule):
],
},
"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/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ospfv3.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ospfv3.py
index 30c646123..efaae19ac 100644
--- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ospfv3.py
+++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ospfv3.py
@@ -7,9 +7,9 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
+from unittest.mock import patch
from ansible_collections.cisco.ios.plugins.modules import ios_ospfv3
-from ansible_collections.cisco.ios.tests.unit.compat.mock import patch
from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args
from .ios_module import TestIosModule, load_fixture
@@ -58,7 +58,10 @@ class TestIosOspfV3Module(TestIosModule):
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 @@ class TestIosOspfV3Module(TestIosModule):
areas=[
dict(
area_id=10,
- nssa=dict(default_information_originate=dict(metric=10)),
+ nssa=dict(
+ default_information_originate=dict(metric=10),
+ ),
),
],
address_family=[
@@ -132,7 +137,10 @@ class TestIosOspfV3Module(TestIosModule):
afi="ipv4",
unicast=True,
vrf="blue",
- adjacency=dict(min_adjacency=100, max_adjacency=100),
+ adjacency=dict(
+ min_adjacency=100,
+ max_adjacency=100,
+ ),
),
],
),
@@ -164,7 +172,9 @@ class TestIosOspfV3Module(TestIosModule):
areas=[
dict(
area_id=10,
- nssa=dict(default_information_originate=dict(metric=10)),
+ nssa=dict(
+ default_information_originate=dict(metric=10),
+ ),
),
],
address_family=[
@@ -205,7 +215,9 @@ class TestIosOspfV3Module(TestIosModule):
areas=[
dict(
area_id=10,
- nssa=dict(default_information_originate=dict(metric=10)),
+ nssa=dict(
+ default_information_originate=dict(metric=10),
+ ),
),
],
address_family=[
@@ -256,7 +268,9 @@ class TestIosOspfV3Module(TestIosModule):
areas=[
dict(
area_id=10,
- nssa=dict(default_information_originate=dict(metric=10)),
+ nssa=dict(
+ default_information_originate=dict(metric=10),
+ ),
),
],
address_family=[
@@ -287,7 +301,9 @@ class TestIosOspfV3Module(TestIosModule):
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/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ping.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ping.py
index bdb822e62..02969ffe0 100644
--- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ping.py
+++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ping.py
@@ -7,11 +7,10 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-
from textwrap import dedent
+from unittest.mock import patch
from ansible_collections.cisco.ios.plugins.modules import ios_ping
-from ansible_collections.cisco.ios.tests.unit.compat.mock import patch
from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args
from .ios_module import TestIosModule
@@ -61,7 +60,9 @@ class TestIosPingModule(TestIosModule):
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/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_prefix_lists.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_prefix_lists.py
index 2aac373dd..0df4be859 100644
--- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_prefix_lists.py
+++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_prefix_lists.py
@@ -7,9 +7,9 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
+from unittest.mock import patch
from ansible_collections.cisco.ios.plugins.modules import ios_prefix_lists
-from ansible_collections.cisco.ios.tests.unit.compat.mock import patch
from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args
from .ios_module import TestIosModule, load_fixture
@@ -74,7 +74,12 @@ class TestIosPrefixListsModule(TestIosModule):
prefix="35.0.0.0/8",
sequence=5,
),
- dict(action="deny", ge=20, prefix="35.0.0.0/8", sequence=10),
+ dict(
+ action="deny",
+ ge=20,
+ prefix="35.0.0.0/8",
+ sequence=10,
+ ),
],
name="test_prefix",
),
@@ -121,9 +126,24 @@ class TestIosPrefixListsModule(TestIosModule):
dict(
description="this is test description",
entries=[
- dict(action="deny", le=15, prefix="1.0.0.0/8", sequence=5),
- dict(action="deny", ge=10, prefix="35.0.0.0/8", sequence=10),
- dict(action="deny", ge=15, prefix="12.0.0.0/8", sequence=15),
+ dict(
+ action="deny",
+ le=15,
+ prefix="1.0.0.0/8",
+ sequence=5,
+ ),
+ dict(
+ action="deny",
+ ge=10,
+ prefix="35.0.0.0/8",
+ sequence=10,
+ ),
+ dict(
+ action="deny",
+ ge=15,
+ prefix="12.0.0.0/8",
+ sequence=15,
+ ),
dict(
action="deny",
ge=20,
@@ -137,7 +157,12 @@ class TestIosPrefixListsModule(TestIosModule):
dict(
description="this is test",
entries=[
- dict(action="deny", ge=15, prefix="12.0.0.0/8", sequence=50),
+ dict(
+ action="deny",
+ ge=15,
+ prefix="12.0.0.0/8",
+ sequence=50,
+ ),
],
name="test",
),
@@ -151,7 +176,12 @@ class TestIosPrefixListsModule(TestIosModule):
prefix="35.0.0.0/8",
sequence=5,
),
- dict(action="deny", ge=20, prefix="35.0.0.0/8", sequence=10),
+ dict(
+ action="deny",
+ ge=20,
+ prefix="35.0.0.0/8",
+ sequence=10,
+ ),
],
name="test_prefix",
),
@@ -190,7 +220,12 @@ class TestIosPrefixListsModule(TestIosModule):
dict(
description="this is replace test",
entries=[
- dict(action="deny", ge=15, prefix="12.0.0.0/8", sequence=15),
+ dict(
+ action="deny",
+ ge=15,
+ prefix="12.0.0.0/8",
+ sequence=15,
+ ),
dict(
action="deny",
ge=20,
@@ -204,7 +239,12 @@ class TestIosPrefixListsModule(TestIosModule):
dict(
description="this is replace test",
entries=[
- dict(action="deny", ge=20, prefix="35.0.0.0/8", sequence=10),
+ dict(
+ action="deny",
+ ge=20,
+ prefix="35.0.0.0/8",
+ sequence=10,
+ ),
],
name="test_replace",
),
@@ -255,9 +295,24 @@ class TestIosPrefixListsModule(TestIosModule):
dict(
description="this is test description",
entries=[
- dict(action="deny", le=15, prefix="1.0.0.0/8", sequence=5),
- dict(action="deny", ge=10, prefix="35.0.0.0/8", sequence=10),
- dict(action="deny", ge=15, prefix="12.0.0.0/8", sequence=15),
+ dict(
+ action="deny",
+ le=15,
+ prefix="1.0.0.0/8",
+ sequence=5,
+ ),
+ dict(
+ action="deny",
+ ge=10,
+ prefix="35.0.0.0/8",
+ sequence=10,
+ ),
+ dict(
+ action="deny",
+ ge=15,
+ prefix="12.0.0.0/8",
+ sequence=15,
+ ),
dict(
action="deny",
ge=20,
@@ -271,7 +326,12 @@ class TestIosPrefixListsModule(TestIosModule):
dict(
description="this is test",
entries=[
- dict(action="deny", ge=15, prefix="12.0.0.0/8", sequence=50),
+ dict(
+ action="deny",
+ ge=15,
+ prefix="12.0.0.0/8",
+ sequence=50,
+ ),
],
name="test",
),
@@ -285,7 +345,12 @@ class TestIosPrefixListsModule(TestIosModule):
prefix="35.0.0.0/8",
sequence=5,
),
- dict(action="deny", ge=20, prefix="35.0.0.0/8", sequence=10),
+ dict(
+ action="deny",
+ ge=20,
+ prefix="35.0.0.0/8",
+ sequence=10,
+ ),
],
name="test_prefix",
),
@@ -324,7 +389,12 @@ class TestIosPrefixListsModule(TestIosModule):
dict(
description="this is override test",
entries=[
- dict(action="deny", ge=15, prefix="12.0.0.0/8", sequence=15),
+ dict(
+ action="deny",
+ ge=15,
+ prefix="12.0.0.0/8",
+ sequence=15,
+ ),
dict(
action="deny",
ge=20,
@@ -338,7 +408,12 @@ class TestIosPrefixListsModule(TestIosModule):
dict(
description="this is override test",
entries=[
- dict(action="deny", ge=20, prefix="35.0.0.0/8", sequence=10),
+ dict(
+ action="deny",
+ ge=20,
+ prefix="35.0.0.0/8",
+ sequence=10,
+ ),
],
name="test_override",
),
@@ -391,9 +466,24 @@ class TestIosPrefixListsModule(TestIosModule):
dict(
description="this is test description",
entries=[
- dict(action="deny", le=15, prefix="1.0.0.0/8", sequence=5),
- dict(action="deny", ge=10, prefix="35.0.0.0/8", sequence=10),
- dict(action="deny", ge=15, prefix="12.0.0.0/8", sequence=15),
+ dict(
+ action="deny",
+ le=15,
+ prefix="1.0.0.0/8",
+ sequence=5,
+ ),
+ dict(
+ action="deny",
+ ge=10,
+ prefix="35.0.0.0/8",
+ sequence=10,
+ ),
+ dict(
+ action="deny",
+ ge=15,
+ prefix="12.0.0.0/8",
+ sequence=15,
+ ),
dict(
action="deny",
ge=20,
@@ -407,7 +497,12 @@ class TestIosPrefixListsModule(TestIosModule):
dict(
description="this is test",
entries=[
- dict(action="deny", ge=15, prefix="12.0.0.0/8", sequence=50),
+ dict(
+ action="deny",
+ ge=15,
+ prefix="12.0.0.0/8",
+ sequence=50,
+ ),
],
name="test",
),
@@ -421,7 +516,12 @@ class TestIosPrefixListsModule(TestIosModule):
prefix="35.0.0.0/8",
sequence=5,
),
- dict(action="deny", ge=20, prefix="35.0.0.0/8", sequence=10),
+ dict(
+ action="deny",
+ ge=20,
+ prefix="35.0.0.0/8",
+ sequence=10,
+ ),
],
name="test_prefix",
),
@@ -491,7 +591,12 @@ class TestIosPrefixListsModule(TestIosModule):
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/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_route_maps.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_route_maps.py
index 0e450f908..27c5aa7f6 100644
--- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_route_maps.py
+++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_route_maps.py
@@ -7,9 +7,9 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
+from unittest.mock import patch
from ansible_collections.cisco.ios.plugins.modules import ios_route_maps
-from ansible_collections.cisco.ios.tests.unit.compat.mock import patch
from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args
from .ios_module import TestIosModule, load_fixture
@@ -58,7 +58,10 @@ class TestIosRouteMapsModule(TestIosModule):
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 @@ class TestIosRouteMapsModule(TestIosModule):
vpn_distinguisher=dict(address="192.0.2.1:12"),
),
global_route=True,
- interfaces=["GigabitEthernet0/2", "GigabitEthernet0/1"],
+ interfaces=[
+ "GigabitEthernet0/2",
+ "GigabitEthernet0/1",
+ ],
level=dict(level_1_2=True),
lisp="test_lisp",
local_preference=100,
@@ -249,7 +255,10 @@ class TestIosRouteMapsModule(TestIosModule):
additional_paths=dict(all=True),
as_path=dict(acls=[100, 120]),
clns=dict(address="test_osi"),
- community=dict(exact_match=True, name=["new_replace"]),
+ community=dict(
+ exact_match=True,
+ name=["new_replace"],
+ ),
ip=dict(address=dict(acls=[10, 100])),
length=dict(maximum=50000, minimum=5000),
mpls_label=True,
@@ -418,7 +427,10 @@ class TestIosRouteMapsModule(TestIosModule):
vpn_distinguisher=dict(address="192.0.2.1:12"),
),
global_route=True,
- interfaces=["GigabitEthernet0/2", "GigabitEthernet0/1"],
+ interfaces=[
+ "GigabitEthernet0/2",
+ "GigabitEthernet0/1",
+ ],
level=dict(level_1_2=True),
lisp="test_lisp",
local_preference=100,
@@ -454,7 +466,10 @@ class TestIosRouteMapsModule(TestIosModule):
additional_paths=dict(all=True),
as_path=dict(acls=[100, 120]),
clns=dict(address="test_osi"),
- community=dict(exact_match=True, name=["new_override"]),
+ community=dict(
+ exact_match=True,
+ name=["new_override"],
+ ),
ip=dict(address=dict(acls=[10, 100])),
length=dict(maximum=50000, minimum=5000),
mpls_label=True,
@@ -623,7 +638,10 @@ class TestIosRouteMapsModule(TestIosModule):
vpn_distinguisher=dict(address="192.0.2.1:12"),
),
global_route=True,
- interfaces=["GigabitEthernet0/2", "GigabitEthernet0/1"],
+ interfaces=[
+ "GigabitEthernet0/2",
+ "GigabitEthernet0/1",
+ ],
level=dict(level_1_2=True),
lisp="test_lisp",
local_preference=100,
@@ -676,7 +694,10 @@ class TestIosRouteMapsModule(TestIosModule):
name=["99", "98", "test_1", "test_2"],
),
extcommunity=["110", "130"],
- interfaces=["GigabitEthernet0/1", "GigabitEthernet0/2"],
+ interfaces=[
+ "GigabitEthernet0/1",
+ "GigabitEthernet0/2",
+ ],
ip=dict(address=dict(acls=[10, 100])),
ipv6=dict(route_source=dict(acl="test_ipv6")),
length=dict(maximum=10000, minimum=1000),
@@ -702,7 +723,9 @@ class TestIosRouteMapsModule(TestIosModule):
sequence=30,
set=dict(
as_path=dict(
- prepend=dict(as_number=["65512", 65522, "65532", 65543]),
+ prepend=dict(
+ as_number=["65512", 65522, "65532", 65543],
+ ),
),
),
),
@@ -727,7 +750,10 @@ class TestIosRouteMapsModule(TestIosModule):
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/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_service.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_service.py
index cbf9a9fd7..fa92efcdc 100644
--- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_service.py
+++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_service.py
@@ -7,11 +7,10 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-
from textwrap import dedent
+from unittest.mock import patch
from ansible_collections.cisco.ios.plugins.modules import ios_service
-from ansible_collections.cisco.ios.tests.unit.compat.mock import patch
from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args
from .ios_module import TestIosModule
diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_snmp_server.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_snmp_server.py
index c45f3548a..0b8f797a1 100644
--- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_snmp_server.py
+++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_snmp_server.py
@@ -7,11 +7,10 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-
from textwrap import dedent
+from unittest.mock import patch
from ansible_collections.cisco.ios.plugins.modules import ios_snmp_server
-from ansible_collections.cisco.ios.tests.unit.compat.mock import patch
from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args
from .ios_module import TestIosModule
@@ -54,11 +53,13 @@ class TestIosSnmpServerModule(TestIosModule):
snmp-server engineID remote 172.16.0.2 udp-port 23 AB0C5342FAAB
snmp-server engineID remote 172.16.0.1 udp-port 22 AB0C5342FAAA
snmp-server user newuser newfamily v1 access 24
- snmp-server user paul familypaul v3 access ipv6 ipv6acl
+ snmp-server user paul familypaul v3 access ipv6 ipv6acl ipv4acl
snmp-server user replaceUser replaceUser v3
snmp-server group group0 v3 auth
- snmp-server group group1 v1 notify me access 2
+ snmp-server group group1 v1 notify me access ipv6 ipv6acl 2
snmp-server group group2 v3 priv
+ snmp-server group group3 v1 access ipv6 ipv6acl
+ snmp-server group group4 v1 access 2
snmp-server group replaceUser v3 noauth
snmp-server community commu1 view view1 RO ipv6 te
snmp-server community commu2 RO 1322
@@ -166,15 +167,36 @@ class TestIosSnmpServerModule(TestIosModule):
"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"},
- {"acl_v4": "2", "group": "group1", "notify": "me", "version": "v1"},
+ {
+ "acl_v4": "2",
+ "acl_v6": "ipv6acl",
+ "group": "group1",
+ "notify": "me",
+ "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"},
],
"hosts": [
{
@@ -211,8 +233,16 @@ class TestIosSnmpServerModule(TestIosModule):
"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},
@@ -294,7 +324,12 @@ class TestIosSnmpServerModule(TestIosModule):
},
"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},
},
@@ -347,14 +382,24 @@ class TestIosSnmpServerModule(TestIosModule):
},
},
"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",
"group": "familypaul",
"username": "paul",
"version": "v3",
},
- {"group": "replaceUser", "username": "replaceUser", "version": "v3"},
+ {
+ "group": "replaceUser",
+ "username": "replaceUser",
+ "version": "v3",
+ },
],
},
}
@@ -430,14 +475,32 @@ class TestIosSnmpServerModule(TestIosModule):
"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"},
- {"acl_v4": "2", "group": "group1", "notify": "me", "version": "v1"},
+ {
+ "acl_v4": "2",
+ "acl_v6": "ipv6acl",
+ "group": "group1",
+ "notify": "me",
+ "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"},
],
"hosts": [
{
@@ -474,8 +537,16 @@ class TestIosSnmpServerModule(TestIosModule):
"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},
@@ -567,7 +638,12 @@ class TestIosSnmpServerModule(TestIosModule):
},
"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},
},
@@ -620,15 +696,29 @@ class TestIosSnmpServerModule(TestIosModule):
},
},
"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",
+ },
],
},
}
@@ -692,8 +782,10 @@ class TestIosSnmpServerModule(TestIosModule):
"snmp-server host 172.16.2.99 check slb",
"snmp-server host 172.16.2.99 checktrap isis",
"snmp-server group group0 v3 auth",
- "snmp-server group group1 v1 notify me access 2",
+ "snmp-server group group1 v1 notify me access ipv6 ipv6acl 2",
"snmp-server group group2 v3 priv",
+ "snmp-server group group3 v1 access ipv6 ipv6acl",
+ "snmp-server group group4 v1 access 2",
"snmp-server group replaceUser v3 noauth",
"snmp-server engineID remote 172.16.0.1 udp-port 22 vrf mgmt AB0C5342FAAA",
"snmp-server community commu1 view view1 ro ipv6 te",
@@ -723,8 +815,10 @@ class TestIosSnmpServerModule(TestIosModule):
snmp-server user replaceUser replaceUser v3
snmp-server user flow mfamily v3 access 27
snmp-server group group0 v3 auth
- snmp-server group group1 v1 notify me access 2
+ snmp-server group group1 v1 notify me access ipv6 ipv6acl 2
snmp-server group group2 v3 priv
+ snmp-server group group3 v1 access ipv6 ipv6acl
+ snmp-server group group4 v1 access 2
snmp-server group replaceUser v3 noauth
snmp-server community commu1 view view1 RO ipv6 te
snmp-server community commu2 RO 1322
@@ -985,8 +1079,10 @@ class TestIosSnmpServerModule(TestIosModule):
"no snmp-server host 172.16.2.99 check slb",
"no snmp-server host 172.16.2.99 checktrap isis",
"no snmp-server group group0 v3 auth",
- "no snmp-server group group1 v1 notify me access 2",
+ "no snmp-server group group1 v1 notify me access ipv6 ipv6acl 2",
"no snmp-server group group2 v3 priv",
+ "no snmp-server group group3 v1 access ipv6 ipv6acl",
+ "no snmp-server group group4 v1 access 2",
"no snmp-server group replaceUser v3 noauth",
"no snmp-server engineID local AB0C5342FA0A",
"no snmp-server engineID remote 172.16.0.1 udp-port 22 AB0C5342FAAA",
@@ -1097,15 +1193,34 @@ class TestIosSnmpServerModule(TestIosModule):
"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"},
- {"acl_v4": "2", "group": "group1", "notify": "me", "version": "v1"},
+ {
+ "acl_v4": "2",
+ "acl_v6": "ipv6acl",
+ "group": "group1",
+ "notify": "me",
+ "version": "v1",
+ },
{"group": "group2", "version": "v3", "version_option": "priv"},
- {"group": "replaceUser", "version": "v3", "version_option": "noauth"},
+ {
+ "group": "replaceUser",
+ "version": "v3",
+ "version_option": "noauth",
+ },
],
"hosts": [
{
@@ -1142,8 +1257,16 @@ class TestIosSnmpServerModule(TestIosModule):
"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},
@@ -1225,7 +1348,12 @@ class TestIosSnmpServerModule(TestIosModule):
},
"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},
},
@@ -1278,18 +1406,35 @@ class TestIosSnmpServerModule(TestIosModule):
},
},
"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,
+ },
],
},
}
@@ -1318,7 +1463,7 @@ class TestIosSnmpServerModule(TestIosModule):
"snmp-server host 172.16.2.1 version 2c trapsac tty",
"snmp-server host 172.16.2.99 checktrap isis",
"snmp-server group group0 v3 auth",
- "snmp-server group group1 v1 notify me access 2",
+ "snmp-server group group1 v1 notify me access ipv6 ipv6acl 2",
"snmp-server engineID local AB0C5342FA0A",
"snmp-server engineID remote 172.16.0.1 udp-port 22 AB0C5342FAAA",
"snmp-server community commu1 view view1 ro ipv6 te",
@@ -1362,7 +1507,11 @@ class TestIosSnmpServerModule(TestIosModule):
"traps": ["msdp"],
"version": "2c",
},
- {"community_string": "check", "host": "172.16.2.99", "traps": ["slb"]},
+ {
+ "community_string": "check",
+ "host": "172.16.2.99",
+ "traps": ["slb"],
+ },
],
},
}
@@ -1414,10 +1563,18 @@ class TestIosSnmpServerModule(TestIosModule):
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": {
@@ -1494,8 +1651,16 @@ class TestIosSnmpServerModule(TestIosModule):
"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": [
{
@@ -1583,7 +1748,11 @@ class TestIosSnmpServerModule(TestIosModule):
"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": [
{
@@ -1632,7 +1801,10 @@ class TestIosSnmpServerModule(TestIosModule):
"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"},
@@ -1728,8 +1900,16 @@ class TestIosSnmpServerModule(TestIosModule):
"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",
@@ -1777,7 +1957,10 @@ class TestIosSnmpServerModule(TestIosModule):
"username": "paul",
"group": "familypaul",
"version": "v3",
- "authentication": {"algorithm": "md5", "password": "somepass"},
+ "authentication": {
+ "algorithm": "md5",
+ "password": "somepass",
+ },
"encryption": {
"priv": "aes",
"priv_option": 128,
@@ -1789,7 +1972,9 @@ class TestIosSnmpServerModule(TestIosModule):
"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))
@@ -1902,10 +2087,11 @@ class TestIosSnmpServerModule(TestIosModule):
},
}
overridden = [
- "no snmp-server user flow mfamily v3 access 27",
+ "snmp-server user replaceUser replaceUser v3 auth md5 replaceUser access 22",
"snmp-server user flow mfamily v3 access 27",
"no snmp-server user newuser newfamily v1 access 24",
]
+
playbook["state"] = "overridden"
set_module_args(playbook)
result = self.execute_module(changed=True)
diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_static_routes.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_static_routes.py
index d1046cc72..57a416433 100644
--- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_static_routes.py
+++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_static_routes.py
@@ -7,11 +7,10 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-
from textwrap import dedent
+from unittest.mock import patch
from ansible_collections.cisco.ios.plugins.modules import ios_static_routes
-from ansible_collections.cisco.ios.tests.unit.compat.mock import patch
from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args
from .ios_module import TestIosModule
@@ -232,7 +231,10 @@ class TestIosStaticRoutesModule(TestIosModule):
"routes": [
{
"next_hops": [
- {"forward_router_address": "10.1.1.2", "track": 10},
+ {
+ "forward_router_address": "10.1.1.2",
+ "track": 10,
+ },
{
"forward_router_address": "10.1.1.3",
"distance_metric": 22,
@@ -422,7 +424,10 @@ class TestIosStaticRoutesModule(TestIosModule):
"routes": [
{
"next_hops": [
- {"forward_router_address": "10.1.1.2", "track": 10},
+ {
+ "forward_router_address": "10.1.1.2",
+ "track": 10,
+ },
{
"forward_router_address": "10.1.1.3",
"distance_metric": 22,
@@ -639,7 +644,10 @@ class TestIosStaticRoutesModule(TestIosModule):
"routes": [
{
"next_hops": [
- {"forward_router_address": "10.1.1.2", "track": 10},
+ {
+ "forward_router_address": "10.1.1.2",
+ "track": 10,
+ },
{
"forward_router_address": "10.1.1.3",
"distance_metric": 22,
@@ -829,7 +837,10 @@ class TestIosStaticRoutesModule(TestIosModule):
"routes": [
{
"next_hops": [
- {"forward_router_address": "10.1.1.2", "track": 10},
+ {
+ "forward_router_address": "10.1.1.2",
+ "track": 10,
+ },
{
"forward_router_address": "10.1.1.3",
"distance_metric": 22,
@@ -1046,7 +1057,10 @@ class TestIosStaticRoutesModule(TestIosModule):
"routes": [
{
"next_hops": [
- {"forward_router_address": "10.1.1.2", "track": 10},
+ {
+ "forward_router_address": "10.1.1.2",
+ "track": 10,
+ },
{
"forward_router_address": "10.1.1.3",
"distance_metric": 22,
@@ -1236,7 +1250,10 @@ class TestIosStaticRoutesModule(TestIosModule):
"routes": [
{
"next_hops": [
- {"forward_router_address": "10.1.1.2", "track": 10},
+ {
+ "forward_router_address": "10.1.1.2",
+ "track": 10,
+ },
{
"forward_router_address": "10.1.1.3",
"distance_metric": 22,
@@ -1716,7 +1733,9 @@ class TestIosStaticRoutesModule(TestIosModule):
config=[
dict(
vrf="testVrf2",
- address_families=[dict(afi="ipv4", routes=[dict(dest="192.0.2.0/24")])],
+ address_families=[
+ dict(afi="ipv4", routes=[dict(dest="192.0.2.0/24")]),
+ ],
),
dict(
vrf="testVrfv6",
@@ -1840,7 +1859,10 @@ class TestIosStaticRoutesModule(TestIosModule):
"routes": [
{
"next_hops": [
- {"forward_router_address": "10.1.1.2", "track": 10},
+ {
+ "forward_router_address": "10.1.1.2",
+ "track": 10,
+ },
{
"forward_router_address": "10.1.1.3",
"distance_metric": 22,
@@ -2127,7 +2149,9 @@ class TestIosStaticRoutesModule(TestIosModule):
"routes": [
{
"dest": "10.0.0.0/8",
- "next_hops": [{"interface": "Null0", "permanent": True}],
+ "next_hops": [
+ {"interface": "Null0", "permanent": True},
+ ],
},
],
},
diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_system.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_system.py
index b82d7ae48..915d7a1f7 100644
--- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_system.py
+++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_system.py
@@ -21,9 +21,9 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
+from unittest.mock import patch
from ansible_collections.cisco.ios.plugins.modules import ios_system
-from ansible_collections.cisco.ios.tests.unit.compat.mock import patch
from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args
from .ios_module import TestIosModule, load_fixture
@@ -70,7 +70,12 @@ class TestIosSystemModule(TestIosModule):
def test_ios_system_domain_name_complex(self):
set_module_args(
- dict(domain_name=[{"name": "test.com", "vrf": "test"}, {"name": "eng.example.net"}]),
+ dict(
+ domain_name=[
+ {"name": "test.com", "vrf": "test"},
+ {"name": "eng.example.net"},
+ ],
+ ),
)
commands = [
"ip domain name vrf test test.com",
@@ -107,7 +112,10 @@ class TestIosSystemModule(TestIosModule):
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/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_user.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_user.py
index 8cd3c07c3..a13467afb 100644
--- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_user.py
+++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_user.py
@@ -20,9 +20,9 @@ from __future__ import absolute_import, division, print_function
__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
@@ -93,18 +93,23 @@ class TestIosUserModule(TestIosModule):
def test_ios_user_purge(self):
set_module_args(dict(purge=True))
result = self.execute_module(changed=True)
- cmd = {
- "command": "no username ansible",
- "answer": "y",
- "newline": False,
- "prompt": "This operation will remove all username related configurations with same name",
- }
+ cmd = [
+ "ip ssh pubkey-chain",
+ "no username ansible",
+ "exit",
+ {
+ "command": "no username ansible",
+ "answer": "y",
+ "newline": False,
+ "prompt": "This operation will remove all username related configurations with same name",
+ },
+ ]
result_cmd = []
for i in result["commands"]:
result_cmd.append(i)
- self.assertEqual(result_cmd, [cmd])
+ self.assertEqual(result_cmd, cmd)
def test_ios_user_view(self):
set_module_args(dict(name="ansible", view="test"))
@@ -112,18 +117,26 @@ class TestIosUserModule(TestIosModule):
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"])
@@ -151,3 +164,34 @@ class TestIosUserModule(TestIosModule):
]
result = self.execute_module(changed=True, commands=commands)
self.assertEqual(result["commands"], commands)
+
+ def test_add_hashed_password(self):
+ hashed_password_val = "replacementforhashwhichissupposedtogohereonlyfortestingpurposes"
+ set_module_args(
+ dict(
+ name="ansible",
+ hashed_password={
+ "type": 9,
+ "value": hashed_password_val,
+ },
+ ),
+ )
+ result = self.execute_module(changed=True)
+ self.assertEqual(
+ result["commands"],
+ [f"username ansible secret 9 {hashed_password_val}"],
+ )
+
+ def test_add_hpassword_with_type(self):
+ set_module_args(
+ dict(
+ name="ansible",
+ hashed_password={
+ "type": 0,
+ "value": "test",
+ },
+ password_type="password",
+ ),
+ )
+ result = self.execute_module(changed=True)
+ self.assertEqual(result["commands"], ["username ansible password 0 test"])
diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_vlans.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_vlans.py
index c19d58ffd..10b30e140 100644
--- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_vlans.py
+++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_vlans.py
@@ -7,14 +7,13 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-
from textwrap import dedent
+from unittest.mock import patch
from ansible_collections.cisco.ios.plugins.modules import ios_vlans
-from ansible_collections.cisco.ios.tests.unit.compat.mock import patch
from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args
-from .ios_module import TestIosModule, load_fixture
+from .ios_module import TestIosModule
class TestIosVlansModule(TestIosModule):
@@ -23,50 +22,22 @@ class TestIosVlansModule(TestIosModule):
def setUp(self):
super(TestIosVlansModule, self).setUp()
- self.mock_get_config = patch(
- "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config",
- )
- self.get_config = self.mock_get_config.start()
-
- self.mock_load_config = patch(
- "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config",
- )
- self.load_config = self.mock_load_config.start()
-
- self.mock_get_resource_connection_config = patch(
- "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.mock_get_resource_connection_facts = patch(
- "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts."
- "get_resource_connection",
- )
- 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",
- )
- self.edit_config = self.mock_edit_config.start()
-
- self.mock_get_resource_connection_facts_2 = patch(
"ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base."
"get_resource_connection",
)
- self.get_resource_connection_facts_2 = self.mock_get_resource_connection_facts_2.start()
-
- self.mock_execute_show_command_2 = patch(
- "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.vlans.vlans."
- "VlansFacts.get_vlans_data",
- )
- self.execute_show_command_2 = self.mock_execute_show_command_2.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."
"VlansFacts.get_vlans_data",
)
self.execute_show_command = self.mock_execute_show_command.start()
+ self.mock_execute_show_command_conf = patch(
+ "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.vlans.vlans."
+ "VlansFacts.get_vlan_conf_data",
+ )
+ self.execute_show_command_conf = self.mock_execute_show_command_conf.start()
self.mock_l2_device_command = patch(
"ansible_collections.cisco.ios.plugins.modules.ios_vlans._is_l2_device",
)
@@ -74,24 +45,55 @@ class TestIosVlansModule(TestIosModule):
def tearDown(self):
super(TestIosVlansModule, self).tearDown()
- self.mock_get_resource_connection_config.stop()
- self.mock_get_resource_connection_facts.stop()
- self.mock_edit_config.stop()
- self.mock_get_config.stop()
- self.mock_load_config.stop()
self.mock_execute_show_command.stop()
+ self.mock_execute_show_command_conf.stop()
self.mock_l2_device_command.stop()
- self.mock_get_resource_connection_facts_2.stop()
- self.mock_execute_show_command_2.stop()
-
- def load_fixtures(self, commands=None):
- def load_from_file(*args, **kwargs):
- return load_fixture("ios_vlans_config.cfg")
+ def test_ios_vlans_merged(self):
self.mock_l2_device_command.side_effect = True
- self.execute_show_command.side_effect = load_from_file
+ self.mock_execute_show_command_conf.side_effect = ""
+ self.execute_show_command.return_value = dedent(
+ """\
+ VLAN Name Status Ports
+ ---- -------------------------------- --------- -------------------------------
+ 1 default active Gi0/1, Gi0/2
+ 123 RemoteIsInMyName act/unsup Fa0/1, Fa0/4, Fa0/5, Fa0/6, Fa0/7, Fa0/8, Fa0/9, Fa0/10, Fa0/11, Fa0/12
+ Fa0/13, Fa0/14, Fa0/15, Fa0/16, Fa0/17, Fa0/18, Fa0/19, Fa0/20, Fa0/21
+ Fa0/22, Fa0/23, Fa0/24, Fa0/25, Fa0/26, Fa0/27, Fa0/28, Fa0/29, Fa0/30
+ Fa0/31, Fa0/32, Fa0/33, Fa0/34, Fa0/35, Fa0/36, Fa0/37, Fa0/38, Fa0/39
+ Fa0/40, Fa0/41, Fa0/42, Fa0/43, Fa0/44, Fa0/45, Fa0/46, Fa0/47, Fa0/48
+ 150 VLAN0150 active
+ 888 a_very_long_vlan_name_a_very_long_vlan_name
+ active
+ 1002 fddi-default act/unsup
+ 1003 trcrf-default act/unsup
+ 1004 fddinet-default act/unsup
+ 1005 trbrf-default act/unsup
- def test_ios_vlans_merged(self):
+ VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2
+ ---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------
+ 1 enet 100001 1500 - - - - - 0 0
+ 123 enet 100123 610 - - - - - 0 0
+ 150 enet 100150 1500 - - - - - 0 0
+ 888 enet 100888 1500 - - - - - 0 0
+ 1002 fddi 101002 1500 - - - - - 0 0
+ 1003 trcrf 101003 4472 1005 3276 - - srb 0 0
+ 1004 fdnet 101004 1500 - - - ieee - 0 0
+ 1005 trbrf 101005 4472 - - 15 ibm - 0 0
+
+
+ VLAN AREHops STEHops Backup CRF
+ ---- ------- ------- ----------
+ 1003 7 7 off
+
+ Remote SPAN VLANs
+ ------------------------------------------------------------------------------
+ 150
+
+ Primary Secondary Type Ports
+ ------- --------- ----------------- ------------------------------------------
+ """,
+ )
set_module_args(
dict(
config=[
@@ -107,14 +109,70 @@ class TestIosVlansModule(TestIosModule):
),
)
result = self.execute_module(changed=True)
- commands = ["vlan 200", "name test_vlan_200", "state active", "remote-span", "no shutdown"]
+ commands = [
+ "vlan 200",
+ "name test_vlan_200",
+ "state active",
+ "remote-span",
+ "no shutdown",
+ ]
self.assertEqual(result["commands"], commands)
def test_ios_vlans_merged_idempotent(self):
+ self.mock_l2_device_command.side_effect = True
+ self.mock_execute_show_command_conf.side_effect = ""
+ self.execute_show_command.return_value = dedent(
+ """\
+ VLAN Name Status Ports
+ ---- -------------------------------- --------- -------------------------------
+ 1 default active Gi0/1, Gi0/2
+ 123 RemoteIsInMyName act/unsup Fa0/1, Fa0/4, Fa0/5, Fa0/6, Fa0/7, Fa0/8, Fa0/9, Fa0/10, Fa0/11, Fa0/12
+ Fa0/13, Fa0/14, Fa0/15, Fa0/16, Fa0/17, Fa0/18, Fa0/19, Fa0/20, Fa0/21
+ Fa0/22, Fa0/23, Fa0/24, Fa0/25, Fa0/26, Fa0/27, Fa0/28, Fa0/29, Fa0/30
+ Fa0/31, Fa0/32, Fa0/33, Fa0/34, Fa0/35, Fa0/36, Fa0/37, Fa0/38, Fa0/39
+ Fa0/40, Fa0/41, Fa0/42, Fa0/43, Fa0/44, Fa0/45, Fa0/46, Fa0/47, Fa0/48
+ 150 VLAN0150 active
+ 888 a_very_long_vlan_name_a_very_long_vlan_name
+ active
+ 1002 fddi-default act/unsup
+ 1003 trcrf-default act/unsup
+ 1004 fddinet-default act/unsup
+ 1005 trbrf-default act/unsup
+
+ VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2
+ ---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------
+ 1 enet 100001 1500 - - - - - 0 0
+ 123 enet 100123 610 - - - - - 0 0
+ 150 enet 100150 1500 - - - - - 0 0
+ 888 enet 100888 1500 - - - - - 0 0
+ 1002 fddi 101002 1500 - - - - - 0 0
+ 1003 trcrf 101003 4472 1005 3276 - - srb 0 0
+ 1004 fdnet 101004 1500 - - - ieee - 0 0
+ 1005 trbrf 101005 4472 - - 15 ibm - 0 0
+
+
+ VLAN AREHops STEHops Backup CRF
+ ---- ------- ------- ----------
+ 1003 7 7 off
+
+ Remote SPAN VLANs
+ ------------------------------------------------------------------------------
+ 150
+
+ Primary Secondary Type Ports
+ ------- --------- ----------------- ------------------------------------------
+ """,
+ )
set_module_args(
dict(
config=[
- dict(mtu=1500, name="default", shutdown="disabled", state="active", vlan_id=1),
+ dict(
+ mtu=1500,
+ name="default",
+ shutdown="disabled",
+ state="active",
+ vlan_id=1,
+ ),
dict(
mtu=610,
name="RemoteIsInMyName",
@@ -172,6 +230,50 @@ class TestIosVlansModule(TestIosModule):
self.execute_module(changed=False, commands=[], sort=True)
def test_ios_vlans_replaced(self):
+ self.mock_l2_device_command.side_effect = True
+ self.mock_execute_show_command_conf.side_effect = ""
+ self.execute_show_command.return_value = dedent(
+ """\
+ VLAN Name Status Ports
+ ---- -------------------------------- --------- -------------------------------
+ 1 default active Gi0/1, Gi0/2
+ 123 RemoteIsInMyName act/unsup Fa0/1, Fa0/4, Fa0/5, Fa0/6, Fa0/7, Fa0/8, Fa0/9, Fa0/10, Fa0/11, Fa0/12
+ Fa0/13, Fa0/14, Fa0/15, Fa0/16, Fa0/17, Fa0/18, Fa0/19, Fa0/20, Fa0/21
+ Fa0/22, Fa0/23, Fa0/24, Fa0/25, Fa0/26, Fa0/27, Fa0/28, Fa0/29, Fa0/30
+ Fa0/31, Fa0/32, Fa0/33, Fa0/34, Fa0/35, Fa0/36, Fa0/37, Fa0/38, Fa0/39
+ Fa0/40, Fa0/41, Fa0/42, Fa0/43, Fa0/44, Fa0/45, Fa0/46, Fa0/47, Fa0/48
+ 150 VLAN0150 active
+ 888 a_very_long_vlan_name_a_very_long_vlan_name
+ active
+ 1002 fddi-default act/unsup
+ 1003 trcrf-default act/unsup
+ 1004 fddinet-default act/unsup
+ 1005 trbrf-default act/unsup
+
+ VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2
+ ---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------
+ 1 enet 100001 1500 - - - - - 0 0
+ 123 enet 100123 610 - - - - - 0 0
+ 150 enet 100150 1500 - - - - - 0 0
+ 888 enet 100888 1500 - - - - - 0 0
+ 1002 fddi 101002 1500 - - - - - 0 0
+ 1003 trcrf 101003 4472 1005 3276 - - srb 0 0
+ 1004 fdnet 101004 1500 - - - ieee - 0 0
+ 1005 trbrf 101005 4472 - - 15 ibm - 0 0
+
+
+ VLAN AREHops STEHops Backup CRF
+ ---- ------- ------- ----------
+ 1003 7 7 off
+
+ Remote SPAN VLANs
+ ------------------------------------------------------------------------------
+ 150
+
+ Primary Secondary Type Ports
+ ------- --------- ----------------- ------------------------------------------
+ """,
+ )
set_module_args(
dict(
config=[
@@ -182,14 +284,26 @@ class TestIosVlansModule(TestIosModule):
remote_span=True,
vlan_id=200,
),
- dict(name="Replace_RemoteIsInMyName", remote_span=True, vlan_id=123),
+ dict(
+ name="Replace_RemoteIsInMyName",
+ remote_span=True,
+ vlan_id=123,
+ ),
dict(
name="pvlan-primary",
private_vlan=dict(type="primary", associated=[11, 12]),
vlan_id=10,
),
- dict(name="pvlan-community", private_vlan=dict(type="community"), vlan_id=11),
- dict(name="pvlan-isolated", private_vlan=dict(type="isolated"), vlan_id=12),
+ dict(
+ name="pvlan-community",
+ private_vlan=dict(type="community"),
+ vlan_id=11,
+ ),
+ dict(
+ name="pvlan-isolated",
+ private_vlan=dict(type="isolated"),
+ vlan_id=12,
+ ),
],
state="replaced",
),
@@ -202,38 +316,79 @@ class TestIosVlansModule(TestIosModule):
"remote-span",
"no shutdown",
"vlan 123",
+ "name Replace_RemoteIsInMyName",
"no state active",
- "no shutdown",
"no mtu 610",
- "name Replace_RemoteIsInMyName",
"remote-span",
+ "shutdown",
"vlan 10",
- "no state active",
- "no shutdown",
- "no mtu 4472",
"name pvlan-primary",
"private-vlan primary",
"private-vlan association 11,12",
"vlan 11",
- "no state active",
- "no shutdown",
- "no mtu 4472",
"name pvlan-community",
"private-vlan community",
"vlan 12",
- "no state active",
- "no shutdown",
- "no mtu 4472",
"name pvlan-isolated",
"private-vlan isolated",
]
self.assertEqual(result["commands"], commands)
def test_ios_vlans_replaced_idempotent(self):
+ self.mock_l2_device_command.side_effect = True
+ self.mock_execute_show_command_conf.side_effect = ""
+ self.execute_show_command.return_value = dedent(
+ """\
+ VLAN Name Status Ports
+ ---- -------------------------------- --------- -------------------------------
+ 1 default active Gi0/1, Gi0/2
+ 123 RemoteIsInMyName act/unsup Fa0/1, Fa0/4, Fa0/5, Fa0/6, Fa0/7, Fa0/8, Fa0/9, Fa0/10, Fa0/11, Fa0/12
+ Fa0/13, Fa0/14, Fa0/15, Fa0/16, Fa0/17, Fa0/18, Fa0/19, Fa0/20, Fa0/21
+ Fa0/22, Fa0/23, Fa0/24, Fa0/25, Fa0/26, Fa0/27, Fa0/28, Fa0/29, Fa0/30
+ Fa0/31, Fa0/32, Fa0/33, Fa0/34, Fa0/35, Fa0/36, Fa0/37, Fa0/38, Fa0/39
+ Fa0/40, Fa0/41, Fa0/42, Fa0/43, Fa0/44, Fa0/45, Fa0/46, Fa0/47, Fa0/48
+ 150 VLAN0150 active
+ 888 a_very_long_vlan_name_a_very_long_vlan_name
+ active
+ 1002 fddi-default act/unsup
+ 1003 trcrf-default act/unsup
+ 1004 fddinet-default act/unsup
+ 1005 trbrf-default act/unsup
+
+ VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2
+ ---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------
+ 1 enet 100001 1500 - - - - - 0 0
+ 123 enet 100123 610 - - - - - 0 0
+ 150 enet 100150 1500 - - - - - 0 0
+ 888 enet 100888 1500 - - - - - 0 0
+ 1002 fddi 101002 1500 - - - - - 0 0
+ 1003 trcrf 101003 4472 1005 3276 - - srb 0 0
+ 1004 fdnet 101004 1500 - - - ieee - 0 0
+ 1005 trbrf 101005 4472 - - 15 ibm - 0 0
+
+
+ VLAN AREHops STEHops Backup CRF
+ ---- ------- ------- ----------
+ 1003 7 7 off
+
+ Remote SPAN VLANs
+ ------------------------------------------------------------------------------
+ 150
+
+ Primary Secondary Type Ports
+ ------- --------- ----------------- ------------------------------------------
+ """,
+ )
set_module_args(
dict(
config=[
- dict(mtu=1500, name="default", shutdown="disabled", state="active", vlan_id=1),
+ dict(
+ mtu=1500,
+ name="default",
+ shutdown="disabled",
+ state="active",
+ vlan_id=1,
+ ),
dict(
mtu=610,
name="RemoteIsInMyName",
@@ -291,6 +446,50 @@ class TestIosVlansModule(TestIosModule):
self.execute_module(changed=False, commands=[], sort=True)
def test_ios_vlans_overridden(self):
+ self.mock_l2_device_command.side_effect = True
+ self.mock_execute_show_command_conf.side_effect = ""
+ self.execute_show_command.return_value = dedent(
+ """\
+ VLAN Name Status Ports
+ ---- -------------------------------- --------- -------------------------------
+ 1 default active Gi0/1, Gi0/2
+ 123 RemoteIsInMyName act/unsup Fa0/1, Fa0/4, Fa0/5, Fa0/6, Fa0/7, Fa0/8, Fa0/9, Fa0/10, Fa0/11, Fa0/12
+ Fa0/13, Fa0/14, Fa0/15, Fa0/16, Fa0/17, Fa0/18, Fa0/19, Fa0/20, Fa0/21
+ Fa0/22, Fa0/23, Fa0/24, Fa0/25, Fa0/26, Fa0/27, Fa0/28, Fa0/29, Fa0/30
+ Fa0/31, Fa0/32, Fa0/33, Fa0/34, Fa0/35, Fa0/36, Fa0/37, Fa0/38, Fa0/39
+ Fa0/40, Fa0/41, Fa0/42, Fa0/43, Fa0/44, Fa0/45, Fa0/46, Fa0/47, Fa0/48
+ 150 VLAN0150 active
+ 888 a_very_long_vlan_name_a_very_long_vlan_name
+ active
+ 1002 fddi-default act/unsup
+ 1003 trcrf-default act/unsup
+ 1004 fddinet-default act/unsup
+ 1005 trbrf-default act/unsup
+
+ VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2
+ ---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------
+ 1 enet 100001 1500 - - - - - 0 0
+ 123 enet 100123 610 - - - - - 0 0
+ 150 enet 100150 1500 - - - - - 0 0
+ 888 enet 100888 1500 - - - - - 0 0
+ 1002 fddi 101002 1500 - - - - - 0 0
+ 1003 trcrf 101003 4472 1005 3276 - - srb 0 0
+ 1004 fdnet 101004 1500 - - - ieee - 0 0
+ 1005 trbrf 101005 4472 - - 15 ibm - 0 0
+
+
+ VLAN AREHops STEHops Backup CRF
+ ---- ------- ------- ----------
+ 1003 7 7 off
+
+ Remote SPAN VLANs
+ ------------------------------------------------------------------------------
+ 150
+
+ Primary Secondary Type Ports
+ ------- --------- ----------------- ------------------------------------------
+ """,
+ )
set_module_args(
dict(
config=[
@@ -301,35 +500,123 @@ class TestIosVlansModule(TestIosModule):
remote_span=True,
vlan_id=200,
),
- dict(name="Override_RemoteIsInMyName", remote_span=True, vlan_id=123),
+ dict(
+ name="Override_RemoteIsInMyName",
+ remote_span=True,
+ vlan_id=123,
+ ),
],
state="overridden",
),
)
result = self.execute_module(changed=True)
commands = [
- "vlan 123",
+ "vlan 1",
+ "no name default",
"no state active",
- "no shutdown",
- "no mtu 610",
- "name Override_RemoteIsInMyName",
- "remote-span",
- "no vlan 150",
- "no vlan 888",
+ "no mtu 1500",
+ "shutdown",
+ "vlan 150",
+ "no name VLAN0150",
+ "no state active",
+ "no mtu 1500",
+ "no remote-span",
+ "shutdown",
+ "vlan 888",
+ "no name a_very_long_vlan_name_a_very_long_vlan_name",
+ "no state active",
+ "no mtu 1500",
+ "shutdown",
+ "vlan 1002",
+ "no name fddi-default",
+ "no state active",
+ "no mtu 1500",
+ "shutdown",
+ "vlan 1003",
+ "no name trcrf-default",
+ "no state active",
+ "no mtu 4472",
+ "shutdown",
+ "vlan 1004",
+ "no name fddinet-default",
+ "no state active",
+ "no mtu 1500",
+ "shutdown",
+ "vlan 1005",
+ "no name trbrf-default",
+ "no state active",
+ "no mtu 4472",
+ "shutdown",
"vlan 200",
"name test_vlan_200",
"state active",
"remote-span",
"no shutdown",
+ "vlan 123",
+ "name Override_RemoteIsInMyName",
+ "no state active",
+ "no mtu 610",
+ "remote-span",
+ "shutdown",
]
self.assertEqual(result["commands"], commands)
def test_ios_vlans_overridden_idempotent(self):
+ self.mock_l2_device_command.side_effect = True
+ self.mock_execute_show_command_conf.side_effect = ""
+ self.execute_show_command.return_value = dedent(
+ """\
+ VLAN Name Status Ports
+ ---- -------------------------------- --------- -------------------------------
+ 1 default active Gi0/1, Gi0/2
+ 123 RemoteIsInMyName act/unsup Fa0/1, Fa0/4, Fa0/5, Fa0/6, Fa0/7, Fa0/8, Fa0/9, Fa0/10, Fa0/11, Fa0/12
+ Fa0/13, Fa0/14, Fa0/15, Fa0/16, Fa0/17, Fa0/18, Fa0/19, Fa0/20, Fa0/21
+ Fa0/22, Fa0/23, Fa0/24, Fa0/25, Fa0/26, Fa0/27, Fa0/28, Fa0/29, Fa0/30
+ Fa0/31, Fa0/32, Fa0/33, Fa0/34, Fa0/35, Fa0/36, Fa0/37, Fa0/38, Fa0/39
+ Fa0/40, Fa0/41, Fa0/42, Fa0/43, Fa0/44, Fa0/45, Fa0/46, Fa0/47, Fa0/48
+ 150 VLAN0150 active
+ 888 a_very_long_vlan_name_a_very_long_vlan_name
+ active
+ 1002 fddi-default act/unsup
+ 1003 trcrf-default act/unsup
+ 1004 fddinet-default act/unsup
+ 1005 trbrf-default act/unsup
+
+ VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2
+ ---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------
+ 1 enet 100001 1500 - - - - - 0 0
+ 123 enet 100123 610 - - - - - 0 0
+ 150 enet 100150 1500 - - - - - 0 0
+ 888 enet 100888 1500 - - - - - 0 0
+ 1002 fddi 101002 1500 - - - - - 0 0
+ 1003 trcrf 101003 4472 1005 3276 - - srb 0 0
+ 1004 fdnet 101004 1500 - - - ieee - 0 0
+ 1005 trbrf 101005 4472 - - 15 ibm - 0 0
+
+
+ VLAN AREHops STEHops Backup CRF
+ ---- ------- ------- ----------
+ 1003 7 7 off
+
+ Remote SPAN VLANs
+ ------------------------------------------------------------------------------
+ 150
+
+ Primary Secondary Type Ports
+ ------- --------- ----------------- ------------------------------------------
+ """,
+ )
set_module_args(
dict(
config=[
- dict(mtu=1500, name="default", shutdown="disabled", state="active", vlan_id=1),
+ dict(
+ mtu=1500,
+ name="default",
+ shutdown="disabled",
+ state="active",
+ vlan_id=1,
+ ),
dict(
mtu=610,
name="RemoteIsInMyName",
@@ -386,13 +673,108 @@ class TestIosVlansModule(TestIosModule):
)
self.execute_module(changed=False, commands=[], sort=True)
- def test_ios_delete_vlans(self):
+ def test_ios_delete_vlans_config(self):
+ self.mock_l2_device_command.side_effect = True
+ self.mock_execute_show_command_conf.side_effect = ""
+ self.execute_show_command.return_value = dedent(
+ """\
+ VLAN Name Status Ports
+ ---- -------------------------------- --------- -------------------------------
+ 1 default active Gi0/1, Gi0/2
+ 123 RemoteIsInMyName act/unsup Fa0/1, Fa0/4, Fa0/5, Fa0/6, Fa0/7, Fa0/8, Fa0/9, Fa0/10, Fa0/11, Fa0/12
+ Fa0/13, Fa0/14, Fa0/15, Fa0/16, Fa0/17, Fa0/18, Fa0/19, Fa0/20, Fa0/21
+ Fa0/22, Fa0/23, Fa0/24, Fa0/25, Fa0/26, Fa0/27, Fa0/28, Fa0/29, Fa0/30
+ Fa0/31, Fa0/32, Fa0/33, Fa0/34, Fa0/35, Fa0/36, Fa0/37, Fa0/38, Fa0/39
+ Fa0/40, Fa0/41, Fa0/42, Fa0/43, Fa0/44, Fa0/45, Fa0/46, Fa0/47, Fa0/48
+ 150 VLAN0150 active
+ 888 a_very_long_vlan_name_a_very_long_vlan_name
+ active
+ 1002 fddi-default act/unsup
+ 1003 trcrf-default act/unsup
+ 1004 fddinet-default act/unsup
+ 1005 trbrf-default act/unsup
+
+ VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2
+ ---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------
+ 1 enet 100001 1500 - - - - - 0 0
+ 123 enet 100123 610 - - - - - 0 0
+ 150 enet 100150 1500 - - - - - 0 0
+ 888 enet 100888 1500 - - - - - 0 0
+ 1002 fddi 101002 1500 - - - - - 0 0
+ 1003 trcrf 101003 4472 1005 3276 - - srb 0 0
+ 1004 fdnet 101004 1500 - - - ieee - 0 0
+ 1005 trbrf 101005 4472 - - 15 ibm - 0 0
+
+
+ VLAN AREHops STEHops Backup CRF
+ ---- ------- ------- ----------
+ 1003 7 7 off
+
+ Remote SPAN VLANs
+ ------------------------------------------------------------------------------
+ 150
+
+ Primary Secondary Type Ports
+ ------- --------- ----------------- ------------------------------------------
+ """,
+ )
set_module_args(dict(config=[dict(vlan_id=150)], state="deleted"))
result = self.execute_module(changed=True)
- commands = ["no vlan 150"]
+ commands = [
+ "vlan 150",
+ "no name VLAN0150",
+ "no state active",
+ "no mtu 1500",
+ "no remote-span",
+ "shutdown",
+ ]
self.assertEqual(result["commands"], commands)
def test_vlans_rendered(self):
+ self.mock_l2_device_command.side_effect = True
+ self.mock_execute_show_command_conf.side_effect = ""
+ self.execute_show_command.return_value = dedent(
+ """\
+ VLAN Name Status Ports
+ ---- -------------------------------- --------- -------------------------------
+ 1 default active Gi0/1, Gi0/2
+ 123 RemoteIsInMyName act/unsup Fa0/1, Fa0/4, Fa0/5, Fa0/6, Fa0/7, Fa0/8, Fa0/9, Fa0/10, Fa0/11, Fa0/12
+ Fa0/13, Fa0/14, Fa0/15, Fa0/16, Fa0/17, Fa0/18, Fa0/19, Fa0/20, Fa0/21
+ Fa0/22, Fa0/23, Fa0/24, Fa0/25, Fa0/26, Fa0/27, Fa0/28, Fa0/29, Fa0/30
+ Fa0/31, Fa0/32, Fa0/33, Fa0/34, Fa0/35, Fa0/36, Fa0/37, Fa0/38, Fa0/39
+ Fa0/40, Fa0/41, Fa0/42, Fa0/43, Fa0/44, Fa0/45, Fa0/46, Fa0/47, Fa0/48
+ 150 VLAN0150 active
+ 888 a_very_long_vlan_name_a_very_long_vlan_name
+ active
+ 1002 fddi-default act/unsup
+ 1003 trcrf-default act/unsup
+ 1004 fddinet-default act/unsup
+ 1005 trbrf-default act/unsup
+
+ VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2
+ ---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------
+ 1 enet 100001 1500 - - - - - 0 0
+ 123 enet 100123 610 - - - - - 0 0
+ 150 enet 100150 1500 - - - - - 0 0
+ 888 enet 100888 1500 - - - - - 0 0
+ 1002 fddi 101002 1500 - - - - - 0 0
+ 1003 trcrf 101003 4472 1005 3276 - - srb 0 0
+ 1004 fdnet 101004 1500 - - - ieee - 0 0
+ 1005 trbrf 101005 4472 - - 15 ibm - 0 0
+
+
+ VLAN AREHops STEHops Backup CRF
+ ---- ------- ------- ----------
+ 1003 7 7 off
+
+ Remote SPAN VLANs
+ ------------------------------------------------------------------------------
+ 150
+
+ Primary Secondary Type Ports
+ ------- --------- ----------------- ------------------------------------------
+ """,
+ )
set_module_args(
dict(
config=[
@@ -407,7 +789,13 @@ class TestIosVlansModule(TestIosModule):
state="rendered",
),
)
- commands = ["name test_vlan_200", "no shutdown", "remote-span", "state active", "vlan 200"]
+ commands = [
+ "name test_vlan_200",
+ "no shutdown",
+ "remote-span",
+ "state active",
+ "vlan 200",
+ ]
result = self.execute_module(changed=False)
self.assertEqual(sorted(result["rendered"]), commands)
@@ -598,6 +986,50 @@ class TestIosVlansModule(TestIosModule):
self.assertEqual(result["parsed"], parsed)
def test_ios_vlans_gathered(self):
+ self.mock_l2_device_command.side_effect = True
+ self.mock_execute_show_command_conf.side_effect = ""
+ self.execute_show_command.return_value = dedent(
+ """\
+ VLAN Name Status Ports
+ ---- -------------------------------- --------- -------------------------------
+ 1 default active Gi0/1, Gi0/2
+ 123 RemoteIsInMyName act/unsup Fa0/1, Fa0/4, Fa0/5, Fa0/6, Fa0/7, Fa0/8, Fa0/9, Fa0/10, Fa0/11, Fa0/12
+ Fa0/13, Fa0/14, Fa0/15, Fa0/16, Fa0/17, Fa0/18, Fa0/19, Fa0/20, Fa0/21
+ Fa0/22, Fa0/23, Fa0/24, Fa0/25, Fa0/26, Fa0/27, Fa0/28, Fa0/29, Fa0/30
+ Fa0/31, Fa0/32, Fa0/33, Fa0/34, Fa0/35, Fa0/36, Fa0/37, Fa0/38, Fa0/39
+ Fa0/40, Fa0/41, Fa0/42, Fa0/43, Fa0/44, Fa0/45, Fa0/46, Fa0/47, Fa0/48
+ 150 VLAN0150 active
+ 888 a_very_long_vlan_name_a_very_long_vlan_name
+ active
+ 1002 fddi-default act/unsup
+ 1003 trcrf-default act/unsup
+ 1004 fddinet-default act/unsup
+ 1005 trbrf-default act/unsup
+
+ VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2
+ ---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------
+ 1 enet 100001 1500 - - - - - 0 0
+ 123 enet 100123 610 - - - - - 0 0
+ 150 enet 100150 1500 - - - - - 0 0
+ 888 enet 100888 1500 - - - - - 0 0
+ 1002 fddi 101002 1500 - - - - - 0 0
+ 1003 trcrf 101003 4472 1005 3276 - - srb 0 0
+ 1004 fdnet 101004 1500 - - - ieee - 0 0
+ 1005 trbrf 101005 4472 - - 15 ibm - 0 0
+
+
+ VLAN AREHops STEHops Backup CRF
+ ---- ------- ------- ----------
+ 1003 7 7 off
+
+ Remote SPAN VLANs
+ ------------------------------------------------------------------------------
+ 150
+
+ Primary Secondary Type Ports
+ ------- --------- ----------------- ------------------------------------------
+ """,
+ )
set_module_args(dict(state="gathered"))
gathered = [
{
@@ -664,6 +1096,22 @@ class TestIosVlansModule(TestIosModule):
self.assertEqual(result["gathered"], gathered)
def test_ios_vlans_config_merged(self):
+ self.mock_l2_device_command.side_effect = True
+ self.mock_execute_show_command_conf.side_effect = ""
+ self.execute_show_command.return_value = dedent(
+ """\
+ vlan configuration 102
+ member evpn-instance 102 vni 10102
+ vlan configuration 201
+ member evpn-instance 201 vni 10201
+ vlan configuration 202
+ member evpn-instance 202 vni 10202
+ vlan configuration 901
+ member vni 50901
+ vlan configuration 902
+ member vni 50902
+ """,
+ )
set_module_args(
dict(
config=[
@@ -676,7 +1124,6 @@ class TestIosVlansModule(TestIosModule):
),
],
state="merged",
- configuration=True,
),
)
result = self.execute_module(changed=True)
@@ -687,21 +1134,37 @@ class TestIosVlansModule(TestIosModule):
self.assertEqual(result["commands"], commands)
def test_ios_vlans_config_merged_idempotent(self):
- self.execute_show_command_2 = self.mock_execute_show_command_2.start()
- self.execute_show_command_2.return_value = dedent(
+ self.mock_l2_device_command.side_effect = True
+ self.mock_execute_show_command_conf.side_effect = dedent(
"""\
vlan configuration 101
- member evpn-instance 101 vni 10101
+ member evpn-instance 101 vni 10101
vlan configuration 102
- member evpn-instance 102 vni 10102
+ member evpn-instance 102 vni 10102
vlan configuration 201
- member evpn-instance 201 vni 10201
+ member evpn-instance 201 vni 10201
vlan configuration 202
- member evpn-instance 202 vni 10202
+ member evpn-instance 202 vni 10202
vlan configuration 901
- member vni 50901
+ member vni 50901
vlan configuration 902
- member vni 50902
+ member vni 50902
+ """,
+ )
+ self.execute_show_command.return_value = dedent(
+ """\
+ vlan configuration 101
+ member evpn-instance 101 vni 10101
+ vlan configuration 102
+ member evpn-instance 102 vni 10102
+ vlan configuration 201
+ member evpn-instance 201 vni 10201
+ vlan configuration 202
+ member evpn-instance 202 vni 10202
+ vlan configuration 901
+ member vni 50901
+ vlan configuration 902
+ member vni 50902
""",
)
set_module_args(
@@ -716,27 +1179,27 @@ class TestIosVlansModule(TestIosModule):
),
],
state="merged",
- configuration=True,
),
)
self.execute_module(changed=False, commands=[], sort=True)
def test_ios_vlans_config_overridden(self):
- self.execute_show_command_2 = self.mock_execute_show_command_2.start()
- self.execute_show_command_2.return_value = dedent(
+ self.mock_l2_device_command.side_effect = True
+ self.mock_execute_show_command_conf.side_effect = ""
+ self.execute_show_command.return_value = dedent(
"""\
vlan configuration 101
- member evpn-instance 101 vni 10101
+ member evpn-instance 101 vni 10101
vlan configuration 102
- member evpn-instance 102 vni 10102
+ member evpn-instance 102 vni 10102
vlan configuration 201
- member evpn-instance 201 vni 10201
+ member evpn-instance 201 vni 10201
vlan configuration 202
- member evpn-instance 202 vni 10202
+ member evpn-instance 202 vni 10202
vlan configuration 901
- member vni 50901
+ member vni 50901
vlan configuration 902
- member vni 50902
+ member vni 50902
""",
)
set_module_args(
@@ -758,29 +1221,29 @@ class TestIosVlansModule(TestIosModule):
),
],
state="overridden",
- configuration=True,
),
)
result = self.execute_module(changed=True)
commands = [
- "vlan configuration 101",
- "no member evpn-instance 101 vni 10101",
- "vlan configuration 102",
- "no member evpn-instance 102 vni 10102",
+ "vlan configuration 201",
+ "no member evpn-instance 201 vni 10201",
+ "vlan configuration 202",
+ "no member evpn-instance 202 vni 10202",
+ "vlan configuration 901",
+ "no member vni 50901",
+ "vlan configuration 902",
+ "no member vni 50902",
"vlan configuration 101",
"member evpn-instance 102 vni 10102",
"vlan configuration 102",
"member evpn-instance 101 vni 10101",
- "no vlan configuration 201",
- "no vlan configuration 202",
- "no vlan configuration 901",
- "no vlan configuration 902",
]
self.assertEqual(result["commands"], commands)
- def test_ios_delete_vlans_config(self):
- self.execute_show_command_2 = self.mock_execute_show_command_2.start()
- self.execute_show_command_2.return_value = dedent(
+ def test_ios_delete_vlans_config_2(self):
+ self.mock_l2_device_command.side_effect = True
+ self.mock_execute_show_command_conf.side_effect = ""
+ self.execute_show_command.return_value = dedent(
"""\
vlan configuration 101
member evpn-instance 101 vni 10101
@@ -801,16 +1264,48 @@ class TestIosVlansModule(TestIosModule):
config=[
{"vlan_id": 101},
],
- configuration=True,
state="deleted",
),
)
result = self.execute_module(changed=True)
+ commands = ["vlan configuration 101", "no member evpn-instance 101 vni 10101"]
+ self.assertEqual(result["commands"], commands)
+
+ def test_ios_purged_vlans_config(self):
+ self.mock_l2_device_command.side_effect = True
+ self.mock_execute_show_command_conf.side_effect = ""
+ self.execute_show_command.return_value = dedent(
+ """\
+ vlan configuration 101
+ member evpn-instance 101 vni 10101
+ vlan configuration 102
+ member evpn-instance 102 vni 10102
+ vlan configuration 201
+ member evpn-instance 201 vni 10201
+ vlan configuration 202
+ member evpn-instance 202 vni 10202
+ vlan configuration 901
+ member vni 50901
+ vlan configuration 902
+ member vni 50902
+ """,
+ )
+ set_module_args(
+ dict(
+ config=[
+ {"vlan_id": 101},
+ ],
+ state="purged",
+ ),
+ )
+ result = self.execute_module(changed=True)
commands = ["no vlan configuration 101"]
self.assertEqual(result["commands"], commands)
- def test_vlans_config_rendered(self):
- self.execute_show_command_2.return_value = dedent(
+ def test_ios_vlans_config_rendered(self):
+ self.mock_l2_device_command.side_effect = True
+ self.mock_execute_show_command_conf.side_effect = ""
+ self.execute_show_command.return_value = dedent(
"""\
""",
)
@@ -825,7 +1320,6 @@ class TestIosVlansModule(TestIosModule):
),
),
],
- configuration=True,
state="rendered",
),
)
@@ -836,11 +1330,50 @@ class TestIosVlansModule(TestIosModule):
result = self.execute_module(changed=False)
self.assertEqual(result["rendered"], commands)
- def test_vlans_config_parsed(self):
+ def test_ios_vlans_config_parsed(self):
set_module_args(
dict(
running_config=dedent(
"""\
+ VLAN Name Status Ports
+ ---- -------------------------------- --------- -------------------------------
+ 1 default active Gi0/1, Gi0/2
+ 101 RemoteIsInMyName act/unsup Fa0/1, Fa0/4, Fa0/5, Fa0/6, Fa0/7, Fa0/8, Fa0/9, Fa0/10, Fa0/11, Fa0/12
+ Fa0/13, Fa0/14, Fa0/15, Fa0/16, Fa0/17, Fa0/18, Fa0/19, Fa0/20, Fa0/21
+ Fa0/22, Fa0/23, Fa0/24, Fa0/25, Fa0/26, Fa0/27, Fa0/28, Fa0/29, Fa0/30
+ Fa0/31, Fa0/32, Fa0/33, Fa0/34, Fa0/35, Fa0/36, Fa0/37, Fa0/38, Fa0/39
+ Fa0/40, Fa0/41, Fa0/42, Fa0/43, Fa0/44, Fa0/45, Fa0/46, Fa0/47, Fa0/48
+ 150 VLAN0150 active
+ 888 a_very_long_vlan_name_a_very_long_vlan_name
+ active
+ 1002 fddi-default act/unsup
+ 1003 trcrf-default act/unsup
+ 1004 fddinet-default act/unsup
+ 1005 trbrf-default act/unsup
+
+ VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2
+ ---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------
+ 1 enet 100001 1500 - - - - - 0 0
+ 101 enet 100101 610 - - - - - 0 0
+ 150 enet 100150 1500 - - - - - 0 0
+ 888 enet 100888 1500 - - - - - 0 0
+ 1002 fddi 101002 1500 - - - - - 0 0
+ 1003 trcrf 101003 4472 1005 3276 - - srb 0 0
+ 1004 fdnet 101004 1500 - - - ieee - 0 0
+ 1005 trbrf 101005 4472 - - 15 ibm - 0 0
+
+
+ VLAN AREHops STEHops Backup CRF
+ ---- ------- ------- ----------
+ 1003 7 7 off
+
+ Remote SPAN VLANs
+ ------------------------------------------------------------------------------
+ 150
+
+ Primary Secondary Type Ports
+ ------- --------- ----------------- ------------------------------------------
+
vlan configuration 101
member evpn-instance 101 vni 10101
vlan configuration 102
@@ -850,30 +1383,69 @@ class TestIosVlansModule(TestIosModule):
""",
),
state="parsed",
- configuration=True,
),
)
parsed = [
{
- "member": {
- "evi": 101,
- "vni": 10101,
- },
+ "name": "default",
+ "vlan_id": 1,
+ "state": "active",
+ "shutdown": "disabled",
+ "mtu": 1500,
+ },
+ {
+ "name": "RemoteIsInMyName",
"vlan_id": 101,
+ "state": "active",
+ "shutdown": "enabled",
+ "mtu": 610,
+ "member": {"evi": 101, "vni": 10101},
},
{
- "member": {
- "evi": 102,
- "vni": 10102,
- },
- "vlan_id": 102,
+ "name": "VLAN0150",
+ "vlan_id": 150,
+ "state": "active",
+ "shutdown": "disabled",
+ "mtu": 1500,
+ "remote_span": True,
+ },
+ {
+ "name": "a_very_long_vlan_name_a_very_long_vlan_name",
+ "vlan_id": 888,
+ "state": "active",
+ "shutdown": "disabled",
+ "mtu": 1500,
+ },
+ {
+ "name": "fddi-default",
+ "vlan_id": 1002,
+ "state": "active",
+ "shutdown": "enabled",
+ "mtu": 1500,
},
{
- "member": {
- "vni": 50901,
- },
- "vlan_id": 901,
+ "name": "trcrf-default",
+ "vlan_id": 1003,
+ "state": "active",
+ "shutdown": "enabled",
+ "mtu": 4472,
+ },
+ {
+ "name": "fddinet-default",
+ "vlan_id": 1004,
+ "state": "active",
+ "shutdown": "enabled",
+ "mtu": 1500,
+ },
+ {
+ "name": "trbrf-default",
+ "vlan_id": 1005,
+ "state": "active",
+ "shutdown": "enabled",
+ "mtu": 4472,
},
+ {"vlan_id": 102, "member": {"evi": 102, "vni": 10102}},
+ {"vlan_id": 901, "member": {"vni": 50901}},
]
result = self.execute_module(changed=False)
diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_vrf.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_vrf.py
index d36ea41e1..f39061989 100644
--- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_vrf.py
+++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_vrf.py
@@ -21,9 +21,9 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
+from unittest.mock import patch
from ansible_collections.cisco.ios.plugins.modules import ios_vrf
-from ansible_collections.cisco.ios.tests.unit.compat.mock import patch
from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args
from .ios_module import TestIosModule, load_fixture
@@ -58,7 +58,11 @@ class TestIosVrfModule(TestIosModule):
def load_fixtures(self, commands=None):
self.get_config.return_value = load_fixture("ios_vrf_config.cfg")
- self.exec_command.return_value = (0, load_fixture("ios_vrf_config.cfg").strip(), None)
+ self.exec_command.return_value = (
+ 0,
+ load_fixture("ios_vrf_config.cfg").strip(),
+ None,
+ )
self.load_config.return_value = None
def test_ios_vrf_name(self):
@@ -158,7 +162,11 @@ class TestIosVrfModule(TestIosModule):
def test_ios_vrfs_local_override_state(self):
vrfs = [{"name": "test_1", "state": "absent"}, {"name": "test_2"}]
set_module_args(dict(vrfs=vrfs, description="test string"))
- commands = ["no vrf definition test_1", "vrf definition test_2", "description test string"]
+ commands = [
+ "no vrf definition test_1",
+ "vrf definition test_2",
+ "description test string",
+ ]
self.execute_module(changed=True, commands=commands, sort=False)
def test_ios_vrf_route_both(self):
@@ -178,7 +186,9 @@ class TestIosVrfModule(TestIosModule):
self.execute_module(changed=True, commands=commands, sort=False)
def test_ios_vrf_route_import(self):
- set_module_args(dict(name="test_6", rd="3:100", route_import=["3:100", "4:100"]))
+ set_module_args(
+ dict(name="test_6", rd="3:100", route_import=["3:100", "4:100"]),
+ )
commands = [
"vrf definition test_6",
"rd 3:100",
@@ -188,7 +198,9 @@ class TestIosVrfModule(TestIosModule):
self.execute_module(changed=True, commands=commands, sort=False)
def test_ios_vrf_route_export(self):
- set_module_args(dict(name="test_7", rd="4:100", route_export=["3:100", "4:100"]))
+ set_module_args(
+ dict(name="test_7", rd="4:100", route_export=["3:100", "4:100"]),
+ )
commands = [
"vrf definition test_7",
"rd 4:100",
@@ -210,7 +222,11 @@ class TestIosVrfModule(TestIosModule):
def test_ios_vrf_route_both_ipv4(self):
set_module_args(
- dict(name="test_9", rd="168.0.0.9:100", route_both_ipv4=["168.0.0.9:100", "3:100"]),
+ dict(
+ name="test_9",
+ rd="168.0.0.9:100",
+ route_both_ipv4=["168.0.0.9:100", "3:100"],
+ ),
)
commands = [
"vrf definition test_9",
@@ -281,7 +297,11 @@ class TestIosVrfModule(TestIosModule):
def test_ios_vrf_route_both_ipv6(self):
set_module_args(
- dict(name="test_13", rd="2:100", route_both_ipv6=["2:100", "168.0.0.13:100"]),
+ dict(
+ name="test_13",
+ rd="2:100",
+ route_both_ipv6=["2:100", "168.0.0.13:100"],
+ ),
)
commands = [
"vrf definition test_13",
@@ -301,7 +321,11 @@ class TestIosVrfModule(TestIosModule):
def test_ios_vrf_route_import_ipv6(self):
set_module_args(
- dict(name="test_14", rd="3:100", route_import_ipv6=["3:100", "168.0.0.14:100"]),
+ dict(
+ name="test_14",
+ rd="3:100",
+ route_import_ipv6=["3:100", "168.0.0.14:100"],
+ ),
)
commands = [
"vrf definition test_14",
@@ -317,7 +341,11 @@ class TestIosVrfModule(TestIosModule):
def test_ios_vrf_route_export_ipv6(self):
set_module_args(
- dict(name="test_15", rd="4:100", route_export_ipv6=["168.0.0.15:100", "4:100"]),
+ dict(
+ name="test_15",
+ rd="4:100",
+ route_export_ipv6=["168.0.0.15:100", "4:100"],
+ ),
)
commands = [
"vrf definition test_15",
@@ -386,7 +414,11 @@ class TestIosVrfModule(TestIosModule):
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/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_vxlan_vtep.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_vxlan_vtep.py
index 25b0bc8a6..13e6a5380 100644
--- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_vxlan_vtep.py
+++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_vxlan_vtep.py
@@ -7,11 +7,10 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-
from textwrap import dedent
+from unittest.mock import patch
from ansible_collections.cisco.ios.plugins.modules import ios_vxlan_vtep
-from ansible_collections.cisco.ios.tests.unit.compat.mock import patch
from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args
from .ios_module import TestIosModule
diff --git a/ansible_collections/cisco/ios/tests/unit/modules/utils.py b/ansible_collections/cisco/ios/tests/unit/modules/utils.py
index 6184c48c3..87be9cf8e 100644
--- a/ansible_collections/cisco/ios/tests/unit/modules/utils.py
+++ b/ansible_collections/cisco/ios/tests/unit/modules/utils.py
@@ -4,12 +4,12 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
import json
+from unittest import TestCase
+from unittest.mock import patch
+
from ansible.module_utils import basic
from ansible.module_utils._text import to_bytes
-from ansible_collections.cisco.ios.tests.unit.compat import unittest
-from ansible_collections.cisco.ios.tests.unit.compat.mock import patch
-
def set_module_args(args):
if "_ansible_remote_tmp" not in args:
@@ -40,7 +40,7 @@ def fail_json(*args, **kwargs):
raise AnsibleFailJson(kwargs)
-class ModuleTestCase(unittest.TestCase):
+class ModuleTestCase(TestCase):
def setUp(self):
self.mock_module = patch.multiple(
basic.AnsibleModule,
diff --git a/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/test_ios.py b/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/test_ios.py
index 0b7cf8704..eb094b2c7 100644
--- a/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/test_ios.py
+++ b/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/test_ios.py
@@ -31,10 +31,11 @@ try:
except ImportError:
from mock import MagicMock
+from unittest import TestCase
+
from ansible.module_utils._text import to_bytes
from ansible_collections.cisco.ios.plugins.cliconf import ios
-from ansible_collections.cisco.ios.tests.unit.compat import unittest
b_FIXTURE_DIR = b"%s/fixtures/ios" % (
@@ -49,7 +50,9 @@ def _connection_side_effect(*args, **kwargs):
else:
value = kwargs.get("command")
- fixture_path = path.abspath(b"%s/%s" % (b_FIXTURE_DIR, b"_".join(value.split(b" "))))
+ fixture_path = path.abspath(
+ b"%s/%s" % (b_FIXTURE_DIR, b"_".join(value.split(b" "))),
+ )
with open(fixture_path, "rb") as file_desc:
return file_desc.read()
except (OSError, IOError):
@@ -63,7 +66,7 @@ def _connection_side_effect(*args, **kwargs):
return "Nope"
-class TestPluginCLIConfIOS(unittest.TestCase):
+class TestPluginCLIConfIOS(TestCase):
"""Test class for IOS CLI Conf Methods"""
def setUp(self):