summaryrefslogtreecommitdiffstats
path: root/ansible_collections/cisco/nxos/tests/unit
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-18 05:52:35 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-18 05:52:35 +0000
commit7fec0b69a082aaeec72fee0612766aa42f6b1b4d (patch)
treeefb569b86ca4da888717f5433e757145fa322e08 /ansible_collections/cisco/nxos/tests/unit
parentReleasing progress-linux version 7.7.0+dfsg-3~progress7.99u1. (diff)
downloadansible-7fec0b69a082aaeec72fee0612766aa42f6b1b4d.tar.xz
ansible-7fec0b69a082aaeec72fee0612766aa42f6b1b4d.zip
Merging upstream version 9.4.0+dfsg.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ansible_collections/cisco/nxos/tests/unit')
-rw-r--r--ansible_collections/cisco/nxos/tests/unit/mock/loader.py2
-rw-r--r--ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/storage/__init__.py0
-rw-r--r--ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_acls.py111
-rw-r--r--ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_bgp.py150
-rw-r--r--ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_bgp_af.py175
-rw-r--r--ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_bgp_global.py108
-rw-r--r--ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_bgp_neighbor.py138
-rw-r--r--ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_bgp_neighbor_address_family.py61
-rw-r--r--ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_bgp_neighbor_af.py259
-rw-r--r--ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_bgp_templates.py865
-rw-r--r--ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_config.py43
-rw-r--r--ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_devicealias.py (renamed from ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/storage/test_nxos_devicealias.py)6
-rw-r--r--ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_fc_interfaces.py1744
-rw-r--r--ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_interfaces.py46
-rw-r--r--ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_pim_interface.py2
-rw-r--r--ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_ping.py2
-rw-r--r--ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_route_maps.py78
-rw-r--r--ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_snmp_server.py6
-rw-r--r--ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_static_routes.py1288
-rw-r--r--ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_vsan.py (renamed from ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/storage/test_nxos_vsan.py)6
-rw-r--r--ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_zone_zoneset.py (renamed from ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/storage/test_nxos_zone_zoneset.py)106
21 files changed, 4171 insertions, 1025 deletions
diff --git a/ansible_collections/cisco/nxos/tests/unit/mock/loader.py b/ansible_collections/cisco/nxos/tests/unit/mock/loader.py
index ebff16f63..0fc53edcd 100644
--- a/ansible_collections/cisco/nxos/tests/unit/mock/loader.py
+++ b/ansible_collections/cisco/nxos/tests/unit/mock/loader.py
@@ -31,7 +31,7 @@ from ansible.parsing.dataloader import DataLoader
class DictDataLoader(DataLoader):
def __init__(self, file_mapping=None):
file_mapping = {} if file_mapping is None else file_mapping
- assert type(file_mapping) == dict
+ assert isinstance(file_mapping, dict)
super(DictDataLoader, self).__init__()
diff --git a/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/storage/__init__.py b/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/storage/__init__.py
deleted file mode 100644
index e69de29bb..000000000
--- a/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/storage/__init__.py
+++ /dev/null
diff --git a/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_acls.py b/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_acls.py
index 6436e065b..b7c0e8663 100644
--- a/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_acls.py
+++ b/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_acls.py
@@ -105,7 +105,9 @@ class TestNxosAclsModule(TestNxosModule):
source=dict(prefix="2002:1:1:1::/64"),
sequence=30,
protocol="icmp",
- protocol_options=dict(icmp=dict(echo_request=True)),
+ protocol_options=dict(
+ icmp=dict(echo_request=True),
+ ),
),
],
),
@@ -421,7 +423,11 @@ class TestNxosAclsModule(TestNxosModule):
"10 permit sctp any any",
]
result = self.execute_module(changed=False)
- self.assertEqual(sorted(result["rendered"]), sorted(commands), result["rendered"])
+ self.assertEqual(
+ sorted(result["rendered"]),
+ sorted(commands),
+ result["rendered"],
+ )
def test_nxos_acls_parsed(self):
set_module_args(
@@ -631,6 +637,7 @@ class TestNxosAclsModule(TestNxosModule):
"""\
ip access-list TEST_RESEQUENCE
10 permit ip 10.0.0.0/24 any
+ 11 permit tcp 1.1.1.1/32 range 7111 9111 192.168.0.0/24 established
20 deny tcp any eq ftp-data any eq domain
25 permit icmp any any echo-reply
27 permit icmp any any port-unreachable
@@ -740,6 +747,19 @@ class TestNxosAclsModule(TestNxosModule):
"destination": {"any": True},
},
{
+ "sequence": 11,
+ "grant": "permit",
+ "protocol": "tcp",
+ "protocol_options": {"tcp": {"established": True}},
+ "source": {
+ "host": "1.1.1.1",
+ "port_protocol": {
+ "range": {"end": "9111", "start": "7111"},
+ },
+ },
+ "destination": {"prefix": "192.168.0.0/24"},
+ },
+ {
"sequence": 20,
"grant": "deny",
"protocol": "tcp",
@@ -853,3 +873,90 @@ class TestNxosAclsModule(TestNxosModule):
]
result = self.execute_module(changed=True)
self.assertEqual(result["commands"], commands)
+
+ def test_nxos_acls_ranges(self):
+ self.execute_show_command.return_value = dedent(
+ """\
+ ip access-list acl1
+ 10 permit tcp any any range ftp-data ftp
+ 20 permit tcp any range ftp-data ftp any range telnet time
+ 30 permit tcp any range ftp-data ftp any
+ """,
+ )
+ set_module_args(
+ dict(
+ state="gathered",
+ ),
+ )
+
+ gathered = [
+ {
+ "acls": [
+ {
+ "name": "acl1",
+ "aces": [
+ {
+ "sequence": 10,
+ "grant": "permit",
+ "protocol": "tcp",
+ "source": {
+ "any": True,
+ },
+ "destination": {
+ "any": True,
+ "port_protocol": {
+ "range": {
+ "start": "ftp-data",
+ "end": "ftp",
+ },
+ },
+ },
+ },
+ {
+ "sequence": 20,
+ "grant": "permit",
+ "protocol": "tcp",
+ "source": {
+ "any": True,
+ "port_protocol": {
+ "range": {
+ "start": "ftp-data",
+ "end": "ftp",
+ },
+ },
+ },
+ "destination": {
+ "any": True,
+ "port_protocol": {
+ "range": {
+ "start": "telnet",
+ "end": "time",
+ },
+ },
+ },
+ },
+ {
+ "sequence": 30,
+ "grant": "permit",
+ "protocol": "tcp",
+ "source": {
+ "any": True,
+ "port_protocol": {
+ "range": {
+ "start": "ftp-data",
+ "end": "ftp",
+ },
+ },
+ },
+ "destination": {
+ "any": True,
+ },
+ },
+ ],
+ },
+ ],
+ "afi": "ipv4",
+ },
+ ]
+ result = self.execute_module(changed=False)
+ self.assertEqual(result["gathered"], gathered)
diff --git a/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_bgp.py b/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_bgp.py
deleted file mode 100644
index 9c57817ca..000000000
--- a/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_bgp.py
+++ /dev/null
@@ -1,150 +0,0 @@
-# (c) 2016 Red Hat Inc.
-#
-# 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.nxos.plugins.modules import nxos_bgp
-from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch
-
-from .nxos_module import TestNxosModule, load_fixture, set_module_args
-
-
-class TestNxosBgpModule(TestNxosModule):
- module = nxos_bgp
-
- def setUp(self):
- super(TestNxosBgpModule, self).setUp()
-
- self.mock_load_config = patch(
- "ansible_collections.cisco.nxos.plugins.modules.nxos_bgp.load_config",
- )
- self.load_config = self.mock_load_config.start()
-
- self.mock_get_config = patch(
- "ansible_collections.cisco.nxos.plugins.modules.nxos_bgp.get_config",
- )
- self.get_config = self.mock_get_config.start()
-
- def tearDown(self):
- super(TestNxosBgpModule, self).tearDown()
- self.mock_load_config.stop()
- self.mock_get_config.stop()
-
- def load_fixtures(self, commands=None, device=""):
- self.get_config.return_value = load_fixture("nxos_bgp", "config.cfg")
- self.load_config.return_value = []
-
- def test_nxos_bgp(self):
- set_module_args(dict(asn=65535, router_id="192.0.2.1"))
- result = self.execute_module(changed=True)
- self.assertEqual(result["commands"], ["router bgp 65535", "router-id 192.0.2.1"])
-
- def test_nxos_bgp_change_nothing(self):
- set_module_args(dict(asn=65535, router_id="192.168.1.1"))
- self.execute_module(changed=False)
-
- def test_nxos_bgp_wrong_asn(self):
- set_module_args(dict(asn=10, router_id="192.168.1.1"))
- result = self.execute_module(failed=True)
- self.assertEqual(result["msg"], "Another BGP ASN already exists.")
-
- def test_nxos_bgp_remove(self):
- set_module_args(dict(asn=65535, state="absent"))
- self.execute_module(changed=True, commands=["no router bgp 65535"])
-
- def test_nxos_bgp_remove_vrf(self):
- set_module_args(dict(asn=65535, vrf="test2", state="absent"))
- self.execute_module(changed=True, commands=["router bgp 65535", "no vrf test2"])
-
- def test_nxos_bgp_remove_nonexistant_vrf(self):
- set_module_args(dict(asn=65535, vrf="foo", state="absent"))
- self.execute_module(changed=False)
-
- def test_nxos_bgp_remove_wrong_asn(self):
- set_module_args(dict(asn=10, state="absent"))
- self.execute_module(changed=False)
-
- def test_nxos_bgp_vrf(self):
- set_module_args(dict(asn=65535, vrf="test", router_id="192.0.2.1"))
- result = self.execute_module(
- changed=True,
- commands=["router bgp 65535", "vrf test", "router-id 192.0.2.1"],
- )
- self.assertEqual(result["warnings"], ["VRF test doesn't exist."])
-
- def test_nxos_bgp_global_param(self):
- set_module_args(dict(asn=65535, shutdown=True))
- self.execute_module(changed=True, commands=["router bgp 65535", "shutdown"])
-
- def test_nxos_bgp_global_param_outside_default(self):
- set_module_args(dict(asn=65535, vrf="test", shutdown=True))
- result = self.execute_module(failed=True)
- self.assertEqual(
- result["msg"],
- 'Global params can be modified only under "default" VRF.',
- )
-
- def test_nxos_bgp_default_value(self):
- set_module_args(dict(asn=65535, graceful_restart_timers_restart="default"))
- self.execute_module(
- changed=True,
- commands=["router bgp 65535", "graceful-restart restart-time 120"],
- )
-
-
-class TestNxosBgp32BitsAS(TestNxosModule):
- module = nxos_bgp
-
- def setUp(self):
- super(TestNxosBgp32BitsAS, self).setUp()
-
- self.mock_load_config = patch(
- "ansible_collections.cisco.nxos.plugins.modules.nxos_bgp.load_config",
- )
- self.load_config = self.mock_load_config.start()
-
- self.mock_get_config = patch(
- "ansible_collections.cisco.nxos.plugins.modules.nxos_bgp.get_config",
- )
- self.get_config = self.mock_get_config.start()
-
- def tearDown(self):
- super(TestNxosBgp32BitsAS, self).tearDown()
- self.mock_load_config.stop()
- self.mock_get_config.stop()
-
- def load_fixtures(self, commands=None, device=""):
- self.get_config.return_value = load_fixture("nxos_bgp", "config_32_bits_as.cfg")
- self.load_config.return_value = []
-
- def test_nxos_bgp_change_nothing(self):
- set_module_args(dict(asn="65535.65535", router_id="192.168.1.1"))
- self.execute_module(changed=False)
-
- def test_nxos_bgp_wrong_asn(self):
- set_module_args(dict(asn="65535.10", router_id="192.168.1.1"))
- result = self.execute_module(failed=True)
- self.assertEqual(result["msg"], "Another BGP ASN already exists.")
-
- def test_nxos_bgp_remove(self):
- set_module_args(dict(asn="65535.65535", state="absent"))
- self.execute_module(changed=True, commands=["no router bgp 65535.65535"])
diff --git a/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_bgp_af.py b/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_bgp_af.py
deleted file mode 100644
index a72095c8f..000000000
--- a/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_bgp_af.py
+++ /dev/null
@@ -1,175 +0,0 @@
-# (c) 2016 Red Hat Inc.
-#
-# 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.nxos.plugins.modules import nxos_bgp_af
-from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch
-
-from .nxos_module import TestNxosModule, load_fixture, set_module_args
-
-
-class TestNxosBgpAfModule(TestNxosModule):
- module = nxos_bgp_af
-
- def setUp(self):
- super(TestNxosBgpAfModule, self).setUp()
-
- self.mock_load_config = patch(
- "ansible_collections.cisco.nxos.plugins.modules.nxos_bgp_af.load_config",
- )
- self.load_config = self.mock_load_config.start()
-
- self.mock_get_config = patch(
- "ansible_collections.cisco.nxos.plugins.modules.nxos_bgp_af.get_config",
- )
- self.get_config = self.mock_get_config.start()
-
- def tearDown(self):
- super(TestNxosBgpAfModule, self).tearDown()
- self.mock_load_config.stop()
- self.mock_get_config.stop()
-
- def load_fixtures(self, commands=None, device=""):
- self.get_config.return_value = load_fixture("nxos_bgp", "config.cfg")
- self.load_config.return_value = None
-
- def test_nxos_bgp_af(self):
- set_module_args(dict(asn=65535, afi="ipv4", safi="unicast"))
- self.execute_module(
- changed=True,
- sort=False,
- commands=["router bgp 65535", "address-family ipv4 unicast"],
- )
-
- def test_nxos_bgp_af_vrf(self):
- set_module_args(dict(asn=65535, vrf="test", afi="ipv4", safi="unicast"))
- self.execute_module(
- changed=True,
- sort=False,
- commands=[
- "router bgp 65535",
- "vrf test",
- "address-family ipv4 unicast",
- ],
- )
-
- def test_nxos_bgp_af_vrf_exists(self):
- set_module_args(dict(asn=65535, vrf="test2", afi="ipv4", safi="unicast"))
- self.execute_module(changed=False, commands=[])
-
- def test_nxos_bgp_af_dampening_routemap(self):
- set_module_args(
- dict(
- asn=65535,
- afi="ipv4",
- safi="unicast",
- dampening_routemap="route-map-a",
- ),
- )
- self.execute_module(
- changed=True,
- commands=[
- "router bgp 65535",
- "address-family ipv4 unicast",
- "dampening route-map route-map-a",
- ],
- )
-
- def test_nxos_bgp_af_dampening_manual(self):
- set_module_args(
- dict(
- asn=65535,
- afi="ipv4",
- safi="unicast",
- dampening_half_time=5,
- dampening_suppress_time=2000,
- dampening_reuse_time=1900,
- dampening_max_suppress_time=10,
- ),
- )
- self.execute_module(
- changed=True,
- commands=[
- "router bgp 65535",
- "address-family ipv4 unicast",
- "dampening 5 1900 2000 10",
- ],
- )
-
- def test_nxos_bgp_af_dampening_mix(self):
- set_module_args(
- dict(
- asn=65535,
- afi="ipv4",
- safi="unicast",
- dampening_routemap="route-map-a",
- dampening_half_time=5,
- dampening_suppress_time=2000,
- dampening_reuse_time=1900,
- dampening_max_suppress_time=10,
- ),
- )
- result = self.execute_module(failed=True)
- self.assertEqual(
- result["msg"],
- "parameters are mutually exclusive: dampening_routemap|dampening_half_time, "
- "dampening_routemap|dampening_suppress_time, dampening_routemap|dampening_reuse_time, "
- "dampening_routemap|dampening_max_suppress_time",
- )
-
- def test_nxos_bgp_af_client(self):
- set_module_args(dict(asn=65535, afi="ipv4", safi="unicast", client_to_client=False))
- self.execute_module(
- changed=True,
- commands=[
- "router bgp 65535",
- "address-family ipv4 unicast",
- "no client-to-client reflection",
- ],
- )
-
- def test_nxos_bgp_af_retain_route_target(self):
- set_module_args(dict(asn=65535, afi="l2vpn", safi="evpn", retain_route_target="abc"))
- self.execute_module(
- changed=True,
- commands=[
- "router bgp 65535",
- "address-family l2vpn evpn",
- "retain route-target route-map abc",
- ],
- )
-
- def test_nxos_bgp_af_retain_route_target_all(self):
- set_module_args(dict(asn=65535, afi="l2vpn", safi="evpn", retain_route_target="all"))
- self.execute_module(
- changed=True,
- commands=[
- "router bgp 65535",
- "address-family l2vpn evpn",
- "retain route-target all",
- ],
- )
-
- def test_nxos_bgp_af_retain_route_target_exists(self):
- set_module_args(dict(asn=65535, afi="l2vpn", safi="evpn", retain_route_target="xyz"))
- self.execute_module(changed=False, commands=[])
diff --git a/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_bgp_global.py b/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_bgp_global.py
index c2b2d5db2..22c9378eb 100644
--- a/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_bgp_global.py
+++ b/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_bgp_global.py
@@ -89,6 +89,11 @@ class TestNxosBgpGlobalModule(TestNxosModule):
remote_as="65537",
password=dict(encryption=7, key="12090404011C03162E"),
),
+ dict(
+ neighbor_address="2001:4000:4000:fff1::/64",
+ remote_as_route_map="rmap1",
+ description="TEST_NBR",
+ ),
],
vrfs=[
dict(
@@ -107,6 +112,11 @@ class TestNxosBgpGlobalModule(TestNxosModule):
key="13D4D3549493D2877B1DC116EE27A6BE",
),
),
+ dict(
+ neighbor_address="2001:4000:5000:fff1::/64",
+ remote_as_route_map="rmap2",
+ description="TEST_NBR_2",
+ ),
],
),
dict(
@@ -134,6 +144,8 @@ class TestNxosBgpGlobalModule(TestNxosModule):
"neighbor 198.51.100.21",
"remote-as 65537",
"password 7 12090404011C03162E",
+ "neighbor 2001:4000:4000:fff1::/64 remote-as route-map rmap1",
+ "description TEST_NBR",
"vrf site-1",
"local-as 200",
"log-neighbor-changes",
@@ -143,6 +155,8 @@ class TestNxosBgpGlobalModule(TestNxosModule):
"description site-1-nbr-1",
"password 3 13D4D3549493D2877B1DC116EE27A6BE",
"timers 5 15",
+ "neighbor 2001:4000:5000:fff1::/64 remote-as route-map rmap2",
+ "description TEST_NBR_2",
"vrf site-2",
"local-as 300",
"log-neighbor-changes",
@@ -308,6 +322,8 @@ class TestNxosBgpGlobalModule(TestNxosModule):
neighbor 198.51.100.21
remote-as 65537
password 7 12090404011C03162E
+ neighbor 2001:4000:4000:fff1::/64 remote-as route-map rmap1
+ description TEST_NBR
vrf site-1
local-as 200
log-neighbor-changes
@@ -344,6 +360,11 @@ class TestNxosBgpGlobalModule(TestNxosModule):
remote_as="65537",
password=dict(encryption=7, key="12090404011C03162E"),
),
+ dict(
+ neighbor_address="2001:4000:4000:fff1::/64",
+ remote_as_route_map="rmap1",
+ description="TEST_NBR",
+ ),
],
vrfs=[
dict(
@@ -465,6 +486,93 @@ class TestNxosBgpGlobalModule(TestNxosModule):
result = self.execute_module(changed=True)
self.assertEqual(set(result["commands"]), set(commands))
+ def test_nxos_bgp_global_overridden(self):
+ run_cfg = dedent(
+ """\
+ router bgp 65536
+ log-neighbor-changes
+ maxas-limit 20
+ router-id 198.51.100.2
+ neighbor 198.51.100.20
+ remote-as 65537
+ affinity-group 161
+ description NBR-1
+ shutdown
+ low-memory exempt
+ neighbor 198.51.100.21
+ remote-as 65537
+ password 7 12090404011C03162E
+ vrf site-1
+ local-as 200
+ log-neighbor-changes
+ neighbor 192.0.2.10
+ affinity-group 170
+ remote-as 65538
+ description site-1-nbr-1
+ password 3 13D4D3549493D2877B1DC116EE27A6BE
+ vrf site-2
+ local-as 300
+ log-neighbor-changes
+ neighbor-down fib-accelerate
+ """,
+ )
+ self.get_config.return_value = run_cfg
+ self.cfg_get_config.return_value = run_cfg
+
+ set_module_args(
+ dict(
+ config=dict(
+ as_number="65536",
+ router_id="198.51.100.212",
+ log_neighbor_changes=True,
+ maxas_limit=20,
+ neighbors=[
+ dict(
+ neighbor_address="198.51.100.20",
+ neighbor_affinity_group=dict(group_id=161),
+ remote_as="65537",
+ description="NBR-1",
+ low_memory=dict(exempt=True),
+ ),
+ ],
+ vrfs=[
+ dict(
+ vrf="site-1",
+ local_as="200",
+ log_neighbor_changes=True,
+ neighbors=[
+ dict(
+ neighbor_address="192.0.2.10",
+ neighbor_affinity_group=dict(group_id=190),
+ remote_as="65538",
+ description="site-1-nbr-1",
+ password=dict(
+ encryption=3,
+ key="13D4D3549493D2877B1DC116EE27A6BE",
+ ),
+ ),
+ ],
+ ),
+ ],
+ ),
+ state="overridden",
+ ),
+ ignore_provider_arg,
+ )
+ commands = [
+ "router bgp 65536",
+ "router-id 198.51.100.212",
+ "neighbor 198.51.100.20",
+ "no shutdown",
+ "no neighbor 198.51.100.21",
+ "vrf site-1",
+ "neighbor 192.0.2.10",
+ "affinity-group 190",
+ "no vrf site-2",
+ ]
+ result = self.execute_module(changed=True)
+ self.assertEqual(set(result["commands"]), set(commands))
+
def test_nxos_bgp_global_replaced_idempotent(self):
run_cfg = dedent(
"""\
diff --git a/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_bgp_neighbor.py b/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_bgp_neighbor.py
deleted file mode 100644
index 677e6f7dd..000000000
--- a/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_bgp_neighbor.py
+++ /dev/null
@@ -1,138 +0,0 @@
-# (c) 2016 Red Hat Inc.
-#
-# 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.nxos.plugins.modules import nxos_bgp_neighbor
-from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch
-
-from .nxos_module import TestNxosModule, load_fixture, set_module_args
-
-
-class TestNxosBgpNeighborModule(TestNxosModule):
- module = nxos_bgp_neighbor
-
- def setUp(self):
- super(TestNxosBgpNeighborModule, self).setUp()
-
- self.mock_load_config = patch(
- "ansible_collections.cisco.nxos.plugins.modules.nxos_bgp_neighbor.load_config",
- )
- self.load_config = self.mock_load_config.start()
-
- self.mock_get_config = patch(
- "ansible_collections.cisco.nxos.plugins.modules.nxos_bgp_neighbor.get_config",
- )
- self.get_config = self.mock_get_config.start()
-
- def tearDown(self):
- super(TestNxosBgpNeighborModule, self).tearDown()
- self.mock_load_config.stop()
- self.mock_get_config.stop()
-
- def load_fixtures(self, commands=None, device=""):
- self.get_config.return_value = load_fixture("nxos_bgp", "config.cfg")
- self.load_config.return_value = []
-
- def test_nxos_bgp_neighbor_bfd_1(self):
- # None (disable) -> enable
- set_module_args(dict(asn=65535, neighbor="1.1.1.1", bfd="enable"))
- self.execute_module(
- changed=True,
- commands=["router bgp 65535", "neighbor 1.1.1.1", "bfd"],
- )
-
- # enable -> enable (idempotence)
- set_module_args(dict(asn=65535, neighbor="1.1.1.2", bfd="enable"))
- self.execute_module(changed=False)
-
- def test_nxos_bgp_neighbor_bfd_2(self):
- # enable -> None (disable)
- set_module_args(dict(asn=65535, neighbor="1.1.1.2", bfd="disable"))
- self.execute_module(
- changed=True,
- commands=["router bgp 65535", "neighbor 1.1.1.2", "no bfd"],
- )
-
- # None (disable) -> disable (idempotence)
- set_module_args(dict(asn=65535, neighbor="1.1.1.1", bfd="disable"))
- self.execute_module(changed=False)
-
- def test_nxos_bgp_neighbor(self):
- set_module_args(dict(asn=65535, neighbor="192.0.2.3", description="some words"))
- self.execute_module(
- changed=True,
- commands=[
- "router bgp 65535",
- "neighbor 192.0.2.3",
- "description some words",
- ],
- )
-
- def test_nxos_bgp_neighbor_absent(self):
- set_module_args(dict(asn=65535, neighbor="1.1.1.1", state="absent"))
- self.execute_module(changed=True, commands=["router bgp 65535", "no neighbor 1.1.1.1"])
-
- def test_nxos_bgp_neighbor_remove_private_as(self):
- set_module_args(dict(asn=65535, neighbor="3.3.3.4", remove_private_as="all"))
- self.execute_module(changed=False, commands=[])
-
- def test_nxos_bgp_neighbor_remove_private_as_changed(self):
- set_module_args(dict(asn=65535, neighbor="3.3.3.4", remove_private_as="replace-as"))
- self.execute_module(
- changed=True,
- commands=[
- "router bgp 65535",
- "neighbor 3.3.3.4",
- "remove-private-as replace-as",
- ],
- )
-
- def test_nxos_bgp_neighbor_peertype_border_leaf(self):
- set_module_args(dict(asn=65535, neighbor="192.0.2.3", peer_type="fabric_border_leaf"))
- self.execute_module(
- changed=True,
- commands=[
- "router bgp 65535",
- "neighbor 192.0.2.3",
- "peer-type fabric-border-leaf",
- ],
- )
-
- def test_nxos_bgp_neighbor_peertype_external(self):
- set_module_args(dict(asn=65535, neighbor="192.0.2.3", peer_type="fabric_external"))
- self.execute_module(
- changed=True,
- commands=[
- "router bgp 65535",
- "neighbor 192.0.2.3",
- "peer-type fabric-external",
- ],
- )
-
- def test_nxos_bgp_neighbor_peertype_border_leaf_exists(self):
- set_module_args(dict(asn=65535, neighbor="5.5.5.5", peer_type="fabric_border_leaf"))
- self.execute_module(changed=False)
-
- def test_nxos_bgp_neighbor_peertype_external_exists(self):
- set_module_args(dict(asn=65535, neighbor="6.6.6.6", peer_type="fabric_external"))
- self.execute_module(changed=False)
diff --git a/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_bgp_neighbor_address_family.py b/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_bgp_neighbor_address_family.py
index 8f12a4279..b3943f370 100644
--- a/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_bgp_neighbor_address_family.py
+++ b/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_bgp_neighbor_address_family.py
@@ -2713,3 +2713,64 @@ class TestNxosBGPNeighborAddressFamilyModule(TestNxosModule):
)
result = self.execute_module(changed=False)
self.assertEqual(result["parsed"], parsed)
+
+ def test_nxos_bgp_nbr_af_rewrite_rt_asn(self):
+ # test merged for rewrite_rt_asn
+ self.get_config.return_value = dedent(
+ """\
+ router bgp 65536
+ neighbor 192.168.1.1
+ vrf site-1
+ neighbor 10.0.0.100
+ """,
+ )
+ set_module_args(
+ dict(
+ config=dict(
+ as_number="65536",
+ neighbors=[
+ dict(
+ neighbor_address="192.168.1.1",
+ address_family=[
+ dict(
+ afi="ipv4",
+ safi="mvpn",
+ rewrite_rt_asn=True,
+ ),
+ ],
+ ),
+ ],
+ vrfs=[
+ dict(
+ vrf="site-1",
+ neighbors=[
+ dict(
+ neighbor_address="10.0.0.100",
+ address_family=[
+ dict(
+ afi="ipv4",
+ safi="mvpn",
+ rewrite_rt_asn=True,
+ ),
+ ],
+ ),
+ ],
+ ),
+ ],
+ ),
+ state="merged",
+ ),
+ ignore_provider_arg,
+ )
+ commands = [
+ "router bgp 65536",
+ "neighbor 192.168.1.1",
+ "address-family ipv4 mvpn",
+ "rewrite-rt-asn",
+ "vrf site-1",
+ "neighbor 10.0.0.100",
+ "address-family ipv4 mvpn",
+ "rewrite-rt-asn",
+ ]
+ result = self.execute_module(changed=True)
+ self.assertEqual(set(result["commands"]), set(commands))
diff --git a/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_bgp_neighbor_af.py b/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_bgp_neighbor_af.py
deleted file mode 100644
index 8b918d0e8..000000000
--- a/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_bgp_neighbor_af.py
+++ /dev/null
@@ -1,259 +0,0 @@
-# (c) 2016 Red Hat Inc.
-#
-# 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.nxos.plugins.modules import nxos_bgp_neighbor_af
-from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch
-
-from .nxos_module import TestNxosModule, load_fixture, set_module_args
-
-
-class TestNxosBgpNeighborAfModule(TestNxosModule):
- module = nxos_bgp_neighbor_af
-
- def setUp(self):
- super(TestNxosBgpNeighborAfModule, self).setUp()
-
- self.mock_load_config = patch(
- "ansible_collections.cisco.nxos.plugins.modules.nxos_bgp_neighbor_af.load_config",
- )
- self.load_config = self.mock_load_config.start()
-
- self.mock_get_config = patch(
- "ansible_collections.cisco.nxos.plugins.modules.nxos_bgp_neighbor_af.get_config",
- )
- self.get_config = self.mock_get_config.start()
-
- def tearDown(self):
- super(TestNxosBgpNeighborAfModule, self).tearDown()
- self.mock_load_config.stop()
- self.mock_get_config.stop()
-
- def load_fixtures(self, commands=None, device=""):
- self.get_config.return_value = load_fixture("nxos_bgp", "config.cfg")
- self.load_config.return_value = []
-
- def test_nxos_bgp_neighbor_af(self):
- set_module_args(
- dict(
- asn=65535,
- neighbor="192.0.2.3",
- afi="ipv4",
- safi="unicast",
- route_reflector_client=True,
- ),
- )
- result = self.execute_module(changed=True)
- self.assertEqual(
- result["commands"],
- [
- "router bgp 65535",
- "neighbor 192.0.2.3",
- "address-family ipv4 unicast",
- "route-reflector-client",
- ],
- )
-
- def test_nxos_bgp_neighbor_af_exists(self):
- set_module_args(dict(asn=65535, neighbor="3.3.3.5", afi="ipv4", safi="unicast"))
- self.execute_module(changed=False, commands=[])
-
- def test_nxos_bgp_neighbor_af_absent(self):
- set_module_args(
- dict(
- asn=65535,
- neighbor="3.3.3.5",
- afi="ipv4",
- safi="unicast",
- state="absent",
- ),
- )
- self.execute_module(
- changed=True,
- sort=False,
- commands=[
- "router bgp 65535",
- "neighbor 3.3.3.5",
- "no address-family ipv4 unicast",
- ],
- )
-
- def test_nxos_bgp_neighbor_af_advertise_map(self):
- set_module_args(
- dict(
- asn=65535,
- neighbor="3.3.3.5",
- afi="ipv4",
- safi="unicast",
- advertise_map_exist=["my_advertise_map", "my_exist_map"],
- ),
- )
- self.execute_module(
- changed=True,
- sort=False,
- commands=[
- "router bgp 65535",
- "neighbor 3.3.3.5",
- "address-family ipv4 unicast",
- "advertise-map my_advertise_map exist-map my_exist_map",
- ],
- )
-
- def test_nxos_bgp_neighbor_af_advertise_map_non_exist(self):
- set_module_args(
- dict(
- asn=65535,
- neighbor="3.3.3.5",
- afi="ipv4",
- safi="unicast",
- advertise_map_non_exist=[
- "my_advertise_map",
- "my_non_exist_map",
- ],
- ),
- )
- self.execute_module(
- changed=True,
- sort=False,
- commands=[
- "router bgp 65535",
- "neighbor 3.3.3.5",
- "address-family ipv4 unicast",
- "advertise-map my_advertise_map non-exist-map my_non_exist_map",
- ],
- )
-
- def test_nxos_bgp_neighbor_af_max_prefix_limit_default(self):
- set_module_args(
- dict(
- asn=65535,
- neighbor="3.3.3.5",
- afi="ipv4",
- safi="unicast",
- max_prefix_limit="default",
- ),
- )
- self.execute_module(
- changed=True,
- sort=False,
- commands=[
- "router bgp 65535",
- "neighbor 3.3.3.5",
- "address-family ipv4 unicast",
- "no maximum-prefix",
- ],
- )
-
- def test_nxos_bgp_neighbor_af_max_prefix(self):
- set_module_args(
- dict(
- asn=65535,
- neighbor="3.3.3.5",
- afi="ipv4",
- safi="unicast",
- max_prefix_threshold=20,
- max_prefix_limit=20,
- ),
- )
- self.execute_module(
- changed=True,
- sort=False,
- commands=[
- "router bgp 65535",
- "neighbor 3.3.3.5",
- "address-family ipv4 unicast",
- "maximum-prefix 20 20",
- ],
- )
-
- def test_nxos_bgp_neighbor_af_disable_peer_as_check(self):
- set_module_args(
- dict(
- asn=65535,
- neighbor="3.3.3.5",
- afi="ipv4",
- safi="unicast",
- disable_peer_as_check=True,
- ),
- )
- self.execute_module(
- changed=True,
- commands=[
- "router bgp 65535",
- "neighbor 3.3.3.5",
- "address-family ipv4 unicast",
- "disable-peer-as-check",
- ],
- )
-
- def test_nxos_bgp_neighbor_af_rewrite_evpn(self):
- set_module_args(
- dict(
- asn=65535,
- neighbor="30.30.30.5",
- afi="l2vpn",
- safi="evpn",
- rewrite_evpn_rt_asn=True,
- ),
- )
- self.execute_module(
- changed=True,
- commands=[
- "router bgp 65535",
- "neighbor 30.30.30.5",
- "address-family l2vpn evpn",
- "rewrite-evpn-rt-asn",
- ],
- )
-
- def test_nxos_bgp_neighbor_af_rewrite_evpn_disable(self):
- set_module_args(
- dict(
- asn=65535,
- neighbor="30.30.30.5",
- afi="l2vpn",
- safi="evpn",
- rewrite_evpn_rt_asn=False,
- ),
- )
- self.execute_module(
- changed=True,
- commands=[
- "router bgp 65535",
- "neighbor 30.30.30.5",
- "address-family l2vpn evpn",
- "no rewrite-evpn-rt-asn",
- ],
- )
-
- def test_nxos_bgp_neighbor_af_rewrite_evpn_exists(self):
- set_module_args(
- dict(
- asn=65535,
- neighbor="7.7.7.7",
- afi="l2vpn",
- safi="evpn",
- rewrite_evpn_rt_asn=True,
- ),
- )
- self.execute_module(changed=False, commands=[])
diff --git a/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_bgp_templates.py b/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_bgp_templates.py
new file mode 100644
index 000000000..8d2fd74b5
--- /dev/null
+++ b/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_bgp_templates.py
@@ -0,0 +1,865 @@
+# (c) 2021 Red Hat Inc.
+#
+# 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 textwrap import dedent
+
+from ansible_collections.cisco.nxos.plugins.modules import nxos_bgp_templates
+from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch
+
+from .nxos_module import TestNxosModule, set_module_args
+
+
+ignore_provider_arg = True
+
+
+class TestNxosBgpTemplatesModule(TestNxosModule):
+ module = nxos_bgp_templates
+
+ def setUp(self):
+ super(TestNxosBgpTemplatesModule, self).setUp()
+
+ self.mock_get_resource_connection = patch(
+ "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection",
+ )
+ self.get_resource_connection = self.mock_get_resource_connection.start()
+
+ self.mock_get_config = patch(
+ "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.bgp_templates.bgp_templates.Bgp_templatesFacts.get_config",
+ )
+ self.get_config = self.mock_get_config.start()
+
+ def tearDown(self):
+ super(TestNxosBgpTemplatesModule, self).tearDown()
+ self.get_resource_connection.stop()
+ self.get_config.stop()
+
+ def test_nxos_bgp_templates_merged(self):
+ set_module_args(
+ dict(
+ config=dict(
+ as_number="65536",
+ neighbor=[
+ dict(
+ name="tmplt_1",
+ description="test-neighbor-template",
+ bfd=dict(
+ singlehop=True,
+ multihop=dict(
+ interval=dict(
+ tx_interval=300,
+ min_rx_interval=258,
+ multiplier=12,
+ ),
+ ),
+ ),
+ bmp_activate_server=12,
+ capability=dict(
+ suppress_4_byte_as=True,
+ ),
+ disable_connected_check=True,
+ dont_capability_negotiate=True,
+ dscp="cs1",
+ dynamic_capability=True,
+ ebgp_multihop=5,
+ graceful_shutdown=dict(
+ activate=dict(
+ route_map="rmap1",
+ ),
+ ),
+ inherit=dict(peer_session="peer_sess_1"),
+ local_as="65535",
+ log_neighbor_changes=dict(
+ disable=True,
+ ),
+ low_memory=dict(
+ exempt=True,
+ ),
+ password=dict(
+ encryption=7,
+ key="095C4F1A0A1218000F",
+ ),
+ path_attribute=[
+ dict(
+ action="discard",
+ type=10,
+ ),
+ dict(
+ action="treat-as-withdraw",
+ range=dict(
+ start=10,
+ end=15,
+ ),
+ ),
+ ],
+ ),
+ dict(
+ name="tmplt_2",
+ bfd=dict(
+ set=True,
+ ),
+ remote_as="65534",
+ remove_private_as=dict(
+ replace_as=True,
+ ),
+ shutdown=True,
+ timers=dict(
+ keepalive=200,
+ holdtime=300,
+ ),
+ transport=dict(connection_mode=dict(passive=True)),
+ ttl_security=dict(
+ hops=10,
+ ),
+ update_source="Ethernet1/1",
+ ),
+ dict(
+ name="tmplt_3",
+ bfd=dict(
+ multihop=dict(
+ set=True,
+ ),
+ ),
+ address_family=[
+ dict(
+ afi="l2vpn",
+ safi="evpn",
+ send_community="both",
+ ),
+ ],
+ ),
+ ],
+ ),
+ state="merged",
+ ),
+ ignore_provider_arg,
+ )
+ commands = [
+ "router bgp 65536",
+ "template peer tmplt_1",
+ "bfd singlehop",
+ "bfd multihop interval 300 min_rx 258 multiplier 12",
+ "bmp-activate-server 12",
+ "capability suppress 4-byte-as",
+ "description test-neighbor-template",
+ "disable-connected-check",
+ "dont-capability-negotiate",
+ "dscp cs1",
+ "dynamic-capability",
+ "ebgp-multihop 5",
+ "graceful-shutdown activate route-map rmap1",
+ "inherit peer-session peer_sess_1",
+ "local-as 65535",
+ "log-neighbor-changes disable",
+ "low-memory exempt",
+ "password 7 095C4F1A0A1218000F",
+ "path-attribute discard 10 in",
+ "path-attribute treat-as-withdraw range 10 15 in",
+ "template peer tmplt_2",
+ "bfd",
+ "remote-as 65534",
+ "remove-private-as replace-as",
+ "shutdown",
+ "timers 200 300",
+ "transport connection-mode passive",
+ "ttl-security hops 10",
+ "update-source Ethernet1/1",
+ "template peer tmplt_3",
+ "bfd multihop",
+ "address-family l2vpn evpn",
+ "send-community",
+ "send-community extended",
+ ]
+ result = self.execute_module(changed=True)
+ self.assertEqual(set(result["commands"]), set(commands))
+
+ def test_nxos_bgp_templates_merged_idempotent(self):
+ self.get_config.return_value = dedent(
+ """\
+ router bgp 65536
+ template peer tmplt_1
+ bfd singlehop
+ bfd multihop interval 300 min_rx 258 multiplier 12
+ bmp-activate-server 12
+ capability suppress 4-byte-as
+ description test-neighbor-template
+ disable-connected-check
+ dont-capability-negotiate
+ dscp cs1
+ dynamic-capability
+ ebgp-multihop 5
+ graceful-shutdown activate route-map rmap1
+ inherit peer-session peer_sess_1
+ local-as 65535
+ log-neighbor-changes disable
+ low-memory exempt
+ password 7 095C4F1A0A1218000F
+ path-attribute discard 10 in
+ path-attribute treat-as-withdraw range 10 15 in
+ template peer tmplt_2
+ bfd
+ remote-as 65534
+ remove-private-as replace-as
+ shutdown
+ timers 200 300
+ transport connection-mode passive
+ ttl-security hops 10
+ update-source Ethernet1/1
+ template peer tmplt_3
+ bfd multihop
+ """,
+ )
+ set_module_args(
+ dict(
+ config=dict(
+ as_number="65536",
+ neighbor=[
+ dict(
+ name="tmplt_1",
+ description="test-neighbor-template",
+ bfd=dict(
+ singlehop=True,
+ multihop=dict(
+ interval=dict(
+ tx_interval=300,
+ min_rx_interval=258,
+ multiplier=12,
+ ),
+ ),
+ ),
+ bmp_activate_server=12,
+ capability=dict(
+ suppress_4_byte_as=True,
+ ),
+ disable_connected_check=True,
+ dont_capability_negotiate=True,
+ dscp="cs1",
+ dynamic_capability=True,
+ ebgp_multihop=5,
+ graceful_shutdown=dict(
+ activate=dict(
+ route_map="rmap1",
+ ),
+ ),
+ inherit=dict(peer_session="peer_sess_1"),
+ local_as="65535",
+ log_neighbor_changes=dict(
+ disable=True,
+ ),
+ low_memory=dict(
+ exempt=True,
+ ),
+ password=dict(
+ encryption=7,
+ key="095C4F1A0A1218000F",
+ ),
+ path_attribute=[
+ dict(
+ action="discard",
+ type=10,
+ ),
+ dict(
+ action="treat-as-withdraw",
+ range=dict(
+ start=10,
+ end=15,
+ ),
+ ),
+ ],
+ ),
+ dict(
+ name="tmplt_2",
+ bfd=dict(
+ set=True,
+ ),
+ remote_as="65534",
+ remove_private_as=dict(
+ replace_as=True,
+ ),
+ shutdown=True,
+ timers=dict(
+ keepalive=200,
+ holdtime=300,
+ ),
+ transport=dict(connection_mode=dict(passive=True)),
+ ttl_security=dict(
+ hops=10,
+ ),
+ update_source="Ethernet1/1",
+ ),
+ dict(
+ name="tmplt_3",
+ bfd=dict(
+ multihop=dict(
+ set=True,
+ ),
+ ),
+ ),
+ ],
+ ),
+ state="merged",
+ ),
+ ignore_provider_arg,
+ )
+ result = self.execute_module(changed=False)
+ self.assertEqual(result["commands"], [])
+
+ def test_nxos_bgp_templates_deleted_single(self):
+ self.get_config.return_value = dedent(
+ """\
+ router bgp 65536
+ template peer tmplt_1
+ bfd singlehop
+ bfd multihop interval 300 min_rx 258 multiplier 12
+ bmp-activate-server 12
+ template peer tmplt_2
+ bfd
+ remote-as 65534
+ remove-private-as replace-as
+ """,
+ )
+ set_module_args(
+ dict(
+ config=dict(as_number="65536", neighbor=[dict(name="tmplt_1")]),
+ state="deleted",
+ ),
+ ignore_provider_arg,
+ )
+ commands = [
+ "router bgp 65536",
+ "no template peer tmplt_1",
+ ]
+ result = self.execute_module(changed=True)
+ self.assertEqual(set(result["commands"]), set(commands))
+
+ def test_nxos_bgp_templates_deleted_all(self):
+ self.get_config.return_value = dedent(
+ """\
+ router bgp 65536
+ template peer tmplt_1
+ bfd singlehop
+ bfd multihop interval 300 min_rx 258 multiplier 12
+ bmp-activate-server 12
+ template peer tmplt_2
+ bfd
+ remote-as 65534
+ remove-private-as replace-as
+ """,
+ )
+ set_module_args(
+ dict(
+ state="deleted",
+ ),
+ ignore_provider_arg,
+ )
+ commands = ["router bgp 65536", "no template peer tmplt_1", "no template peer tmplt_2"]
+ result = self.execute_module(changed=True)
+ self.assertEqual(set(result["commands"]), set(commands))
+
+ def test_nxos_bgp_templates_overridden(self):
+ self.get_config.return_value = dedent(
+ """\
+ router bgp 65536
+ template peer tmplt_1
+ bfd singlehop
+ bfd multihop interval 300 min_rx 258 multiplier 12
+ template peer tmplt_2
+ bfd
+ remote-as 65534
+ remove-private-as replace-as
+ path-attribute discard 10 in
+ path-attribute treat-as-withdraw range 10 15 in
+ template peer tmplt_3
+ remote-as 65533
+ """,
+ )
+ set_module_args(
+ dict(
+ config=dict(
+ as_number="65536",
+ neighbor=[
+ dict(
+ name="tmplt_1",
+ bfd=dict(
+ singlehop=True,
+ multihop=dict(
+ interval=dict(
+ tx_interval=300,
+ min_rx_interval=258,
+ multiplier=12,
+ ),
+ ),
+ ),
+ ),
+ dict(
+ name="tmplt_2",
+ remote_as="65534",
+ path_attribute=[
+ dict(
+ action="discard",
+ type=10,
+ ),
+ ],
+ ),
+ ],
+ ),
+ state="overridden",
+ ),
+ ignore_provider_arg,
+ )
+ commands = [
+ "router bgp 65536",
+ "no template peer tmplt_3",
+ "template peer tmplt_2",
+ "no bfd",
+ "no remove-private-as replace-as",
+ "no path-attribute treat-as-withdraw range 10 15 in",
+ ]
+ result = self.execute_module(changed=True)
+ self.assertEqual(set(result["commands"]), set(commands))
+
+ def test_nxos_bgp_templates_gathered(self):
+ self.get_config.return_value = dedent(
+ """\
+ router bgp 65536
+ template peer tmplt_1
+ bfd singlehop
+ bfd multihop interval 300 min_rx 258 multiplier 12
+ template peer tmplt_2
+ bfd
+ remote-as 65534
+ remove-private-as replace-as
+ path-attribute discard 10 in
+ """,
+ )
+ set_module_args(
+ dict(
+ state="gathered",
+ ),
+ ignore_provider_arg,
+ )
+ gathered = dict(
+ as_number="65536",
+ neighbor=[
+ dict(
+ name="tmplt_1",
+ bfd=dict(
+ singlehop=True,
+ multihop=dict(
+ interval=dict(
+ tx_interval=300,
+ min_rx_interval=258,
+ multiplier=12,
+ ),
+ ),
+ ),
+ ),
+ dict(
+ name="tmplt_2",
+ bfd=dict(
+ set=True,
+ ),
+ remote_as="65534",
+ path_attribute=[
+ dict(
+ action="discard",
+ type=10,
+ ),
+ ],
+ remove_private_as=dict(
+ replace_as=True,
+ ),
+ ),
+ ],
+ )
+ result = self.execute_module(changed=False)
+ self.assertEqual(result["gathered"], gathered)
+
+ def test_nxos_bgp_templates_parsed(self):
+ run_cfg = dedent(
+ """\
+ router bgp 65536
+ template peer tmplt_1
+ bfd singlehop
+ bfd multihop interval 300 min_rx 258 multiplier 12
+ template peer tmplt_2
+ bfd
+ remote-as 65534
+ remove-private-as replace-as
+ path-attribute discard 10 in
+ """,
+ )
+ set_module_args(
+ dict(
+ running_config=run_cfg,
+ state="parsed",
+ ),
+ ignore_provider_arg,
+ )
+ parsed = dict(
+ as_number="65536",
+ neighbor=[
+ dict(
+ name="tmplt_1",
+ bfd=dict(
+ singlehop=True,
+ multihop=dict(
+ interval=dict(
+ tx_interval=300,
+ min_rx_interval=258,
+ multiplier=12,
+ ),
+ ),
+ ),
+ ),
+ dict(
+ name="tmplt_2",
+ bfd=dict(
+ set=True,
+ ),
+ remote_as="65534",
+ path_attribute=[
+ dict(
+ action="discard",
+ type=10,
+ ),
+ ],
+ remove_private_as=dict(
+ replace_as=True,
+ ),
+ ),
+ ],
+ )
+ result = self.execute_module(changed=False)
+ self.assertEqual(result["parsed"], parsed)
+
+ def test_nxos_bgp_templates_af(self):
+ self.get_config.return_value = dedent(
+ """\
+ """,
+ )
+ set_module_args(
+ dict(
+ config=dict(
+ as_number="65536",
+ neighbor=[
+ dict(
+ name="tmplt_1",
+ description="test-neighbor-template",
+ address_family=[
+ dict(
+ afi="ipv4",
+ safi="unicast",
+ advertise_map=dict(
+ route_map="rmap1",
+ exist_map="rmap2",
+ ),
+ advertisement_interval=100,
+ allowas_in=dict(
+ max_occurences=10,
+ ),
+ as_override=True,
+ capability=dict(
+ additional_paths=dict(
+ receive="disable",
+ send="disable",
+ ),
+ ),
+ default_originate=dict(
+ route_map="rmap1",
+ ),
+ disable_peer_as_check=True,
+ filter_list=dict(
+ inbound="flist1",
+ outbound="flist2",
+ ),
+ inherit=dict(
+ peer_policy="tmplt_policy_1",
+ ),
+ ),
+ dict(
+ afi="ipv4",
+ safi="multicast",
+ maximum_prefix=dict(
+ max_prefix_limit=10,
+ generate_warning_threshold=80,
+ restart_interval=60,
+ warning_only=True,
+ ),
+ next_hop_self=dict(
+ all_routes=True,
+ ),
+ next_hop_third_party=True,
+ prefix_list=dict(
+ inbound="plist1",
+ outbound="plist2",
+ ),
+ ),
+ ],
+ ),
+ dict(
+ name="tmplt_2",
+ description="test-neighbor-template-2",
+ address_family=[
+ dict(
+ afi="ipv4",
+ safi="unicast",
+ route_map=dict(
+ inbound="rmap1",
+ outbound="rmap2",
+ ),
+ route_reflector_client=True,
+ soft_reconfiguration_inbound=dict(
+ always=True,
+ ),
+ soo="test",
+ suppress_inactive=True,
+ unsuppress_map="rmap1",
+ weight=2,
+ ),
+ ],
+ ),
+ ],
+ ),
+ state="merged",
+ ),
+ ignore_provider_arg,
+ )
+ commands = [
+ "router bgp 65536",
+ "template peer tmplt_1",
+ "description test-neighbor-template",
+ "address-family ipv4 unicast",
+ "advertise-map rmap1 exist-map rmap2",
+ "advertisement-interval 100",
+ "allowas-in 10",
+ "as-override",
+ "capability additional-paths receive disable",
+ "capability additional-paths send disable",
+ "default-originate route-map rmap1",
+ "disable-peer-as-check",
+ "filter-list flist1 in",
+ "filter-list flist2 out",
+ "inherit peer-policy tmplt_policy_1",
+ "address-family ipv4 multicast",
+ "maximum-prefix 10 80 restart 60 warning-only",
+ "next-hop-self all",
+ "next-hop-third-party",
+ "prefix-list plist1 in",
+ "prefix-list plist2 out",
+ "template peer tmplt_2",
+ "description test-neighbor-template-2",
+ "address-family ipv4 unicast",
+ "route-map rmap1 in",
+ "route-map rmap2 out",
+ "route-reflector-client",
+ "soft-reconfiguration inbound always",
+ "soo test",
+ "suppress-inactive",
+ "unsuppress-map rmap1",
+ "weight 2",
+ ]
+ result = self.execute_module(changed=True)
+ self.assertEqual(set(result["commands"]), set(commands))
+
+ def test_nxos_bgp_templates_af_idempotent(self):
+ self.get_config.return_value = dedent(
+ """\
+ router bgp 65536
+ template peer tmplt_1
+ description test-neighbor-template
+ address-family ipv4 unicast
+ advertise-map rmap1 exist-map rmap2
+ advertisement-interval 100
+ allowas-in 10
+ as-override
+ capability additional-paths receive disable
+ capability additional-paths send disable
+ default-originate route-map rmap1
+ disable-peer-as-check
+ filter-list flist1 in
+ filter-list flist2 out
+ inherit peer-policy tmplt_policy_1
+ address-family ipv4 multicast
+ maximum-prefix 10 80 restart 60 warning-only
+ next-hop-self all
+ no next-hop-third-party
+ prefix-list plist1 in
+ prefix-list plist2 out
+ template peer tmplt_2
+ description test-neighbor-template-2
+ address-family ipv4 unicast
+ route-map rmap1 in
+ route-map rmap2 out
+ route-reflector-client
+ soft-reconfiguration inbound always
+ soo test
+ suppress-inactive
+ unsuppress-map rmap1
+ weight 2
+ """,
+ )
+ set_module_args(
+ dict(
+ config=dict(
+ as_number="65536",
+ neighbor=[
+ dict(
+ name="tmplt_1",
+ description="test-neighbor-template",
+ address_family=[
+ dict(
+ afi="ipv4",
+ safi="unicast",
+ advertise_map=dict(
+ route_map="rmap1",
+ exist_map="rmap2",
+ ),
+ advertisement_interval=100,
+ allowas_in=dict(
+ max_occurences=10,
+ ),
+ as_override=True,
+ capability=dict(
+ additional_paths=dict(
+ receive="disable",
+ send="disable",
+ ),
+ ),
+ default_originate=dict(
+ route_map="rmap1",
+ ),
+ disable_peer_as_check=True,
+ filter_list=dict(
+ inbound="flist1",
+ outbound="flist2",
+ ),
+ inherit=dict(
+ peer_policy="tmplt_policy_1",
+ ),
+ ),
+ dict(
+ afi="ipv4",
+ safi="multicast",
+ maximum_prefix=dict(
+ max_prefix_limit=10,
+ generate_warning_threshold=80,
+ restart_interval=60,
+ warning_only=True,
+ ),
+ next_hop_self=dict(
+ all_routes=True,
+ ),
+ next_hop_third_party=False,
+ prefix_list=dict(
+ inbound="plist1",
+ outbound="plist2",
+ ),
+ ),
+ ],
+ ),
+ dict(
+ name="tmplt_2",
+ description="test-neighbor-template-2",
+ address_family=[
+ dict(
+ afi="ipv4",
+ safi="unicast",
+ route_map=dict(
+ inbound="rmap1",
+ outbound="rmap2",
+ ),
+ route_reflector_client=True,
+ soft_reconfiguration_inbound=dict(
+ always=True,
+ ),
+ soo="test",
+ suppress_inactive=True,
+ unsuppress_map="rmap1",
+ weight=2,
+ ),
+ ],
+ ),
+ ],
+ ),
+ state="merged",
+ ),
+ ignore_provider_arg,
+ )
+
+ result = self.execute_module(changed=False)
+ self.assertEqual(result["commands"], [])
+
+ def test_nxos_bgp_templates_send_comm(self):
+ self.get_config.return_value = dedent(
+ """\
+ router bgp 65536
+ template peer tmplt_1
+ address-family ipv4 unicast
+ send-community
+ send-community extended
+ template peer tmplt_2
+ address-family l2vpn evpn
+ send-community extended
+ """,
+ )
+ set_module_args(
+ dict(
+ config=dict(
+ as_number="65536",
+ neighbor=[
+ dict(
+ name="tmplt_1",
+ address_family=[
+ dict(
+ afi="ipv4",
+ safi="unicast",
+ send_community="both",
+ ),
+ ],
+ ),
+ dict(
+ name="tmplt_2",
+ address_family=[
+ dict(
+ afi="l2vpn",
+ safi="evpn",
+ send_community="standard",
+ ),
+ ],
+ ),
+ ],
+ ),
+ state="merged",
+ ),
+ ignore_provider_arg,
+ )
+ commands = [
+ "router bgp 65536",
+ "template peer tmplt_2",
+ "address-family l2vpn evpn",
+ "no send-community extended",
+ "send-community",
+ ]
+ result = self.execute_module(changed=True)
+ self.assertEqual(set(result["commands"]), set(commands))
diff --git a/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_config.py b/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_config.py
index 83e58722a..ce5c987c7 100644
--- a/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_config.py
+++ b/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_config.py
@@ -181,6 +181,47 @@ class TestNxosConfigModule(TestNxosModule):
self.assertEqual(config, result["commands"], result["commands"])
+ def test_nxos_replace_block_src(self):
+ src = load_fixture("nxos_config", "candidate.cfg")
+ args = dict(src=src, replace="block")
+ self.conn.get_diff = MagicMock(
+ return_value=self.cliconf_obj.get_diff(src, self.running_config),
+ )
+ set_module_args(args)
+
+ result = self.execute_module(changed=True)
+ config = [
+ "hostname switch01",
+ "interface Ethernet1",
+ "description test interface",
+ "no shutdown",
+ "ip routing",
+ ]
+
+ self.assertEqual(sorted(config), sorted(result["commands"]), result["commands"])
+
+ def test_nxos_replace_block_lines(self):
+ lines = ["ip address 1.2.3.4/5", "no shutdown"]
+ parents = ["interface Ethernet10"]
+ args = dict(lines=lines, parents=parents, replace="block")
+ self.conn.get_diff = MagicMock(
+ return_value=self.cliconf_obj.get_diff(
+ "\n".join(parents + lines),
+ self.running_config,
+ path=parents,
+ ),
+ )
+ set_module_args(args)
+
+ result = self.execute_module(changed=True)
+ config = [
+ "interface Ethernet10",
+ "ip address 1.2.3.4/5",
+ "no shutdown",
+ ]
+
+ self.assertEqual(config, result["commands"], result["commands"])
+
def test_nxos_config_src_and_lines_fails(self):
args = dict(src="foo", lines="foo")
set_module_args(args)
@@ -201,7 +242,7 @@ class TestNxosConfigModule(TestNxosModule):
set_module_args(args)
result = self.execute_module(failed=True)
- def test_nxos_config_replace_block_requires_lines(self):
+ def test_nxos_config_replace_block_requires_lines_or_src(self):
args = dict(replace="block")
set_module_args(args)
result = self.execute_module(failed=True)
diff --git a/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/storage/test_nxos_devicealias.py b/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_devicealias.py
index a35896fbe..640bcd150 100644
--- a/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/storage/test_nxos_devicealias.py
+++ b/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_devicealias.py
@@ -9,11 +9,11 @@ __metaclass__ = type
import pytest
-from ansible_collections.cisco.nxos.plugins.modules.storage import nxos_devicealias
+from ansible_collections.cisco.nxos.plugins.modules import nxos_devicealias
from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch
from ansible_collections.cisco.nxos.tests.unit.modules.utils import AnsibleFailJson
-from ..nxos_module import TestNxosModule, load_fixture, set_module_args
+from .nxos_module import TestNxosModule, load_fixture, set_module_args
class TestNxosDeviceAliasModule(TestNxosModule):
@@ -21,7 +21,7 @@ class TestNxosDeviceAliasModule(TestNxosModule):
def setUp(self):
super(TestNxosDeviceAliasModule, self).setUp()
- module_path = "ansible_collections.cisco.nxos.plugins.modules.storage.nxos_devicealias."
+ module_path = "ansible_collections.cisco.nxos.plugins.modules.nxos_devicealias."
self.mock_run_commands = patch(module_path + "run_commands")
self.run_commands = self.mock_run_commands.start()
diff --git a/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_fc_interfaces.py b/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_fc_interfaces.py
new file mode 100644
index 000000000..098a5b7ff
--- /dev/null
+++ b/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_fc_interfaces.py
@@ -0,0 +1,1744 @@
+# (c) 2023 Red Hat Inc.
+#
+# 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
+
+
+# remove purge
+# add non fc interfaces to the sh run
+# check else statements in config file
+
+
+from __future__ import absolute_import, division, print_function
+
+
+__metaclass__ = type
+
+from textwrap import dedent
+
+from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.rm_templates.fc_interfaces import (
+ allowed_port_modes,
+ allowed_speed_values,
+)
+from ansible_collections.cisco.nxos.plugins.modules import nxos_fc_interfaces
+from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch
+
+from .nxos_module import TestNxosModule, set_module_args
+
+
+ignore_provider_arg = True
+
+sh_run = """
+interface mgmt0
+ ip address 10.126.94.175 255.255.255.0
+ no switchport description
+ switchport speed auto
+ switchport duplex auto
+ snmp trap link-status
+ no shutdown
+ lldp transmit
+ lldp receive
+ cdp enable
+ spanning-tree port-priority 128
+ spanning-tree cost auto
+ spanning-tree link-type auto
+ no spanning-tree bpduguard
+ no spanning-tree bpdufilter
+
+interface vsan1
+ no shutdown
+ ip address 111.111.111.175 255.255.255.0
+ spanning-tree port-priority 128
+ spanning-tree cost auto
+ spanning-tree link-type auto
+ no spanning-tree bpduguard
+ no spanning-tree bpdufilter
+
+
+interface fc1/1
+ no out-of-service force
+ switchport speed auto
+ no transceiver-frequency ethernet
+ switchport rate-mode default
+ switchport fcrxbbcredit default
+ switchport mode auto
+ switchport description This is a sample line
+ switchport vl-credit default
+ switchport trunk mode on
+ no switchport beacon
+ switchport fcbbscn
+ link-state-trap
+ switchport fcrxbufsize 2112
+ no switchport owner
+ switchport encap default
+ switchport fcrxbbcredit performance-buffers default
+ no switchport ignore bit-errors
+ no switchport ignore interrupt-thresholds
+ switchport fill-pattern ARBFF speed 8000
+ switchport logical-type auto
+ switchport max-npiv-limit 0
+ switchport trunk-max-npiv-limit 0
+ no switchport link-diag
+ no shutdown
+
+interface fc1/2
+ no out-of-service force
+ switchport speed 1000
+ no transceiver-frequency ethernet
+ switchport rate-mode default
+ switchport fcrxbbcredit default
+ switchport mode E
+ no switchport description
+ switchport vl-credit default
+ switchport trunk mode off
+ no switchport beacon
+ switchport fcbbscn
+ link-state-trap
+ switchport fcrxbufsize 2112
+ no port-license
+ no errdisable detect cause link-down
+ no errdisable detect cause trustsec-violation
+ no errdisable detect cause bit-errors
+ no errdisable detect cause signal-loss
+ no errdisable detect cause sync-loss
+ no errdisable detect cause link-reset
+ no errdisable detect cause credit-loss
+ no switchport owner
+ switchport encap default
+ switchport fcrxbbcredit performance-buffers default
+ no switchport ignore bit-errors
+ no switchport ignore interrupt-thresholds
+ switchport fill-pattern ARBFF speed 8000
+ switchport logical-type auto
+ switchport max-npiv-limit 0
+ switchport trunk-max-npiv-limit 0
+ no switchport link-diag
+ no shutdown
+
+interface fc1/3
+ no out-of-service force
+ switchport speed 2000
+ no transceiver-frequency ethernet
+ switchport rate-mode default
+ switchport fcrxbbcredit default
+ switchport mode F
+ no switchport description
+ switchport vl-credit default
+ switchport trunk mode on
+ no switchport beacon
+ switchport fcbbscn
+ link-state-trap
+ switchport fcrxbufsize 2112
+ no switchport owner
+ switchport encap default
+ switchport fcrxbbcredit performance-buffers default
+ no switchport ignore bit-errors
+ no switchport ignore interrupt-thresholds
+ switchport fill-pattern ARBFF speed 8000
+ switchport logical-type auto
+ switchport max-npiv-limit 0
+ switchport trunk-max-npiv-limit 0
+ no switchport link-diag
+ no shutdown
+
+interface fc18/1
+ no out-of-service force
+ switchport speed 4000
+ no transceiver-frequency ethernet
+ switchport rate-mode default
+ switchport fcrxbbcredit default
+ switchport mode Fx
+ no switchport description
+ switchport vl-credit default
+ switchport trunk mode auto
+ no switchport beacon
+ switchport fcbbscn
+ link-state-trap
+ switchport fcrxbufsize 2112
+ no port-license
+ no switchport owner
+ switchport encap default
+ switchport fcrxbbcredit performance-buffers default
+ no switchport ignore bit-errors
+ no switchport ignore interrupt-thresholds
+ switchport fill-pattern ARBFF speed 8000
+ switchport logical-type auto
+ switchport max-npiv-limit 0
+ switchport trunk-max-npiv-limit 0
+ no switchport link-diag
+ no shutdown
+
+interface fc18/2
+ no out-of-service force
+ switchport speed 8000
+ no transceiver-frequency ethernet
+ switchport rate-mode default
+ switchport fcrxbbcredit default
+ switchport mode NP
+ no switchport description
+ switchport vl-credit default
+ switchport trunk mode on
+ no switchport beacon
+ switchport fcbbscn
+ link-state-trap
+ switchport fcrxbufsize 2112
+ no port-license
+ no switchport owner
+ switchport encap default
+ switchport fcrxbbcredit performance-buffers default
+ no switchport ignore bit-errors
+ no switchport ignore interrupt-thresholds
+ switchport fill-pattern ARBFF speed 8000
+ switchport logical-type auto
+ switchport max-npiv-limit 0
+ switchport trunk-max-npiv-limit 0
+ no switchport link-diag
+ no shutdown
+interface fc18/3
+ no out-of-service force
+ switchport speed 10000
+ no transceiver-frequency ethernet
+ switchport rate-mode default
+ switchport fcrxbbcredit default
+ switchport mode SD
+ no switchport description
+ switchport vl-credit default
+ switchport trunk mode on
+ no switchport beacon
+ switchport fcbbscn
+ link-state-trap
+ switchport fcrxbufsize 2112
+ no port-license
+ no switchport owner
+ switchport encap default
+ switchport fcrxbbcredit performance-buffers default
+ no switchport ignore bit-errors
+ no switchport ignore interrupt-thresholds
+ switchport fill-pattern ARBFF speed 8000
+ switchport logical-type auto
+ switchport max-npiv-limit 0
+ switchport trunk-max-npiv-limit 0
+ no switchport link-diag
+ no shutdown
+
+interface fc18/4
+ no out-of-service force
+ switchport speed 16000
+ no transceiver-frequency ethernet
+ switchport rate-mode default
+ switchport fcrxbbcredit default
+ switchport mode auto
+ no switchport description
+ switchport vl-credit default
+ switchport trunk mode on
+ no switchport beacon
+ switchport fcbbscn
+ link-state-trap
+ switchport fcrxbufsize 2112
+ no port-license
+ no switchport owner
+ switchport encap default
+ switchport fcrxbbcredit performance-buffers default
+ no switchport ignore bit-errors
+ no switchport ignore interrupt-thresholds
+ switchport fill-pattern ARBFF speed 8000
+ switchport logical-type auto
+ switchport max-npiv-limit 0
+ switchport trunk-max-npiv-limit 0
+ no switchport link-diag
+ no shutdown
+interface fc18/5
+ no out-of-service force
+ switchport speed 32000
+ no transceiver-frequency ethernet
+ switchport rate-mode default
+ switchport fcrxbbcredit default
+ switchport mode auto
+ no switchport description
+ switchport vl-credit default
+ switchport trunk mode on
+ no switchport beacon
+ switchport fcbbscn
+ link-state-trap
+ switchport fcrxbufsize 2112
+ no port-license
+ no switchport owner
+ switchport encap default
+ switchport fcrxbbcredit performance-buffers default
+ no switchport ignore bit-errors
+ no switchport ignore interrupt-thresholds
+ switchport fill-pattern ARBFF speed 8000
+ switchport logical-type auto
+ switchport max-npiv-limit 0
+ switchport trunk-max-npiv-limit 0
+ no switchport link-diag
+ no shutdown
+
+interface fc18/6
+ no out-of-service force
+ switchport speed 64000
+ no transceiver-frequency ethernet
+ switchport rate-mode default
+ switchport fcrxbbcredit default
+ switchport mode auto
+ no switchport description
+ switchport vl-credit default
+ switchport trunk mode on
+ no switchport beacon
+ switchport fcbbscn
+ link-state-trap
+ switchport fcrxbufsize 2112
+ no port-license
+ no switchport owner
+ switchport encap default
+ switchport fcrxbbcredit performance-buffers default
+ no switchport ignore bit-errors
+ no switchport ignore interrupt-thresholds
+ switchport fill-pattern ARBFF speed 8000
+ switchport logical-type auto
+ switchport max-npiv-limit 0
+ switchport trunk-max-npiv-limit 0
+ no switchport link-diag
+ no shutdown
+interface fc18/7
+ no out-of-service force
+ switchport speed auto max 2000
+ no transceiver-frequency ethernet
+ switchport rate-mode default
+ switchport fcrxbbcredit default
+ switchport mode auto
+ no switchport description
+ switchport vl-credit default
+ switchport trunk mode on
+ no switchport beacon
+ switchport fcbbscn
+ link-state-trap
+ switchport fcrxbufsize 2112
+ no port-license
+ no switchport owner
+ switchport encap default
+ switchport fcrxbbcredit performance-buffers default
+ no switchport ignore bit-errors
+ no switchport ignore interrupt-thresholds
+ switchport fill-pattern ARBFF speed 8000
+ switchport logical-type auto
+ switchport max-npiv-limit 0
+ switchport trunk-max-npiv-limit 0
+ no switchport link-diag
+ no shutdown
+
+interface fc18/8
+ no out-of-service force
+ switchport speed auto max 4000
+ no transceiver-frequency ethernet
+ switchport rate-mode default
+ switchport fcrxbbcredit default
+ switchport mode auto
+ no switchport description
+ switchport vl-credit default
+ switchport trunk mode on
+ no switchport beacon
+ switchport fcbbscn
+ link-state-trap
+ switchport fcrxbufsize 2112
+ no port-license
+ no switchport owner
+ switchport encap default
+ switchport fcrxbbcredit performance-buffers default
+ no switchport ignore bit-errors
+ no switchport ignore interrupt-thresholds
+ switchport fill-pattern ARBFF speed 8000
+ switchport logical-type auto
+ switchport max-npiv-limit 0
+ switchport trunk-max-npiv-limit 0
+ no switchport link-diag
+ no shutdown
+interface fc18/9
+ no out-of-service force
+ switchport speed auto max 8000
+ no transceiver-frequency ethernet
+ switchport rate-mode default
+ switchport fcrxbbcredit default
+ switchport mode auto
+ switchport description sample description
+ switchport vl-credit default
+ switchport trunk mode on
+ no switchport beacon
+ switchport fcbbscn
+ link-state-trap
+ switchport fcrxbufsize 2112
+ no port-license
+ no switchport owner
+ switchport encap default
+ switchport fcrxbbcredit performance-buffers default
+ no switchport ignore bit-errors
+ no switchport ignore interrupt-thresholds
+ switchport fill-pattern ARBFF speed 8000
+ switchport logical-type auto
+ switchport max-npiv-limit 0
+ switchport trunk-max-npiv-limit 0
+ no switchport link-diag
+ no shutdown
+
+interface fc18/10
+ no out-of-service force
+ analytics type fc-nvme
+ switchport speed auto max 16000
+ no transceiver-frequency ethernet
+ switchport rate-mode default
+ switchport fcrxbbcredit default
+ switchport mode auto
+ switchport description $
+ switchport vl-credit default
+ switchport trunk mode on
+ no switchport beacon
+ switchport fcbbscn
+ link-state-trap
+ switchport fcrxbufsize 2112
+ no port-license
+ no switchport owner
+ switchport encap default
+ switchport fcrxbbcredit performance-buffers default
+ no switchport ignore bit-errors
+ no switchport ignore interrupt-thresholds
+ switchport fill-pattern ARBFF speed 8000
+ switchport logical-type auto
+ switchport max-npiv-limit 0
+ switchport trunk-max-npiv-limit 0
+ no switchport link-diag
+ shutdown
+
+interface fc18/11
+ no out-of-service force
+ analytics type fc-scsi
+ switchport speed auto max 32000
+ no transceiver-frequency ethernet
+ switchport rate-mode default
+ switchport fcrxbbcredit default
+ switchport mode auto
+ switchport description a
+ switchport vl-credit default
+ switchport trunk mode on
+ no switchport beacon
+ switchport fcbbscn
+ link-state-trap
+ switchport fcrxbufsize 2112
+ no port-license
+ no switchport owner
+ switchport encap default
+ switchport fcrxbbcredit performance-buffers default
+ no switchport ignore bit-errors
+ no switchport ignore interrupt-thresholds
+ switchport fill-pattern ARBFF speed 8000
+ switchport logical-type auto
+ switchport max-npiv-limit 0
+ switchport trunk-max-npiv-limit 0
+ no switchport link-diag
+ shutdown
+
+interface fc18/12
+ no out-of-service force
+ analytics type fc-scsi
+ analytics type fc-nvme
+ switchport speed auto max 64000
+ no transceiver-frequency ethernet
+ switchport rate-mode default
+ switchport fcrxbbcredit default
+ switchport mode auto
+ switchport description 1
+ switchport vl-credit default
+ switchport trunk mode on
+ no switchport beacon
+ switchport fcbbscn
+ link-state-trap
+ switchport fcrxbufsize 2112
+ no port-license
+ no switchport owner
+ switchport encap default
+ switchport fcrxbbcredit performance-buffers default
+ no switchport ignore bit-errors
+ no switchport ignore interrupt-thresholds
+ switchport fill-pattern ARBFF speed 8000
+ switchport logical-type auto
+ switchport max-npiv-limit 0
+ switchport trunk-max-npiv-limit 0
+ no switchport link-diag
+ no shutdown
+
+interface fc18/13
+ no out-of-service force
+ analytics type fc-scsi
+ analytics type fc-nvme
+ switchport speed auto max 64000
+ no transceiver-frequency ethernet
+ switchport rate-mode default
+ switchport fcrxbbcredit default
+ switchport mode auto
+ switchport description 1
+ switchport vl-credit default
+ switchport trunk mode on
+ no switchport beacon
+ switchport fcbbscn
+ link-state-trap
+ switchport fcrxbufsize 2112
+ no port-license
+ no switchport owner
+ switchport encap default
+ switchport fcrxbbcredit performance-buffers default
+ no switchport ignore bit-errors
+ no switchport ignore interrupt-thresholds
+ switchport fill-pattern ARBFF speed 8000
+ switchport logical-type auto
+ switchport max-npiv-limit 0
+ switchport trunk-max-npiv-limit 0
+ no switchport link-diag
+ no shutdown
+ """
+
+gath_val = [
+ {
+ "name": "fc1/1",
+ "speed": "auto",
+ "mode": "auto",
+ "trunk_mode": "on",
+ "enabled": True,
+ "description": "This is a sample line",
+ },
+ {
+ "name": "fc1/2",
+ "speed": "1000",
+ "mode": "E",
+ "trunk_mode": "off",
+ "enabled": True,
+ },
+ {
+ "name": "fc1/3",
+ "speed": "2000",
+ "mode": "F",
+ "trunk_mode": "on",
+ "enabled": True,
+ },
+ {
+ "name": "fc18/1",
+ "speed": "4000",
+ "mode": "Fx",
+ "trunk_mode": "auto",
+ "enabled": True,
+ },
+ {
+ "name": "fc18/2",
+ "speed": "8000",
+ "mode": "NP",
+ "trunk_mode": "on",
+ "enabled": True,
+ },
+ {
+ "name": "fc18/3",
+ "speed": "10000",
+ "mode": "SD",
+ "trunk_mode": "on",
+ "enabled": True,
+ },
+ {
+ "name": "fc18/4",
+ "speed": "16000",
+ "mode": "auto",
+ "trunk_mode": "on",
+ "enabled": True,
+ },
+ {
+ "name": "fc18/5",
+ "speed": "32000",
+ "mode": "auto",
+ "trunk_mode": "on",
+ "enabled": True,
+ },
+ {
+ "name": "fc18/6",
+ "speed": "64000",
+ "mode": "auto",
+ "trunk_mode": "on",
+ "enabled": True,
+ },
+ {
+ "name": "fc18/7",
+ "speed": "auto max 2000",
+ "mode": "auto",
+ "trunk_mode": "on",
+ "enabled": True,
+ },
+ {
+ "name": "fc18/8",
+ "speed": "auto max 4000",
+ "mode": "auto",
+ "trunk_mode": "on",
+ "enabled": True,
+ },
+ {
+ "name": "fc18/9",
+ "speed": "auto max 8000",
+ "mode": "auto",
+ "trunk_mode": "on",
+ "enabled": True,
+ "description": "sample description",
+ },
+ {
+ "name": "fc18/10",
+ "speed": "auto max 16000",
+ "mode": "auto",
+ "trunk_mode": "on",
+ "enabled": False,
+ "description": "$",
+ "analytics": "fc-nvme",
+ },
+ {
+ "name": "fc18/11",
+ "speed": "auto max 32000",
+ "mode": "auto",
+ "trunk_mode": "on",
+ "enabled": False,
+ "description": "a",
+ "analytics": "fc-scsi",
+ },
+ {
+ "name": "fc18/12",
+ "speed": "auto max 64000",
+ "mode": "auto",
+ "trunk_mode": "on",
+ "enabled": True,
+ "description": "1",
+ "analytics": "fc-all",
+ },
+ {
+ "name": "fc18/13",
+ "speed": "auto max 64000",
+ "mode": "auto",
+ "trunk_mode": "on",
+ "enabled": True,
+ "description": "1",
+ "analytics": "fc-all",
+ },
+]
+
+
+class TestNxosFcInterfacesModule(TestNxosModule):
+ module = nxos_fc_interfaces
+
+ def setUp(self):
+ super(TestNxosFcInterfacesModule, self).setUp()
+
+ self.mock_get_resource_connection = patch(
+ "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection",
+ )
+ self.get_resource_connection = self.mock_get_resource_connection.start()
+
+ self.mock_get_config = patch(
+ "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.fc_interfaces.fc_interfaces.Fc_interfacesFacts.get_interfaces_data",
+ )
+ self.get_config = self.mock_get_config.start()
+ self.get_config.return_value = dedent(sh_run)
+
+ self.maxDiff = None
+
+ def tearDown(self):
+ super(TestNxosFcInterfacesModule, self).tearDown()
+ self.get_resource_connection.stop()
+ self.get_config.stop()
+
+ def test_analytics_no_to_all_3_types(self):
+ args = dict(
+ config=[
+ {
+ "name": "fc1/1",
+ "analytics": "fc-scsi",
+ "mode": "E",
+ },
+ {
+ "name": "fc1/2",
+ "analytics": "fc-nvme",
+ },
+ {
+ "name": "fc1/3",
+ "analytics": "fc-all",
+ },
+ {
+ "name": "fc18/12",
+ "analytics": "fc-scsi",
+ },
+ ],
+ state="merged",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=True)
+ self.assertEqual(
+ result["commands"],
+ [
+ "interface fc1/1",
+ "switchport mode E",
+ "analytics type fc-scsi",
+ "interface fc1/2",
+ "analytics type fc-nvme",
+ "interface fc1/3",
+ "analytics type fc-all",
+ ],
+ )
+
+ def test_gathered(self):
+ # test gathered for config
+ set_module_args(dict(state="gathered"), ignore_provider_arg)
+ result = self.execute_module(changed=False)
+ self.assertEqual(result["gathered"], gath_val)
+
+ def test_parsed(self):
+ # test parsed for config
+ set_module_args(dict(state="parsed", running_config=sh_run), ignore_provider_arg)
+ result = self.execute_module(changed=False)
+ self.assertEqual(result["parsed"], gath_val)
+
+ def test_idempotency(self):
+ args = dict(
+ config=gath_val,
+ state="merged",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=False)
+ self.assertEqual(result["commands"], [])
+
+ def test_analytics_all_to_scsi(self):
+ args = dict(
+ config=[
+ {
+ "name": "fc18/12",
+ "speed": "auto max 64000",
+ "mode": "auto",
+ "trunk_mode": "on",
+ "enabled": True,
+ "description": "1",
+ "analytics": "fc-scsi",
+ },
+ ],
+ state="merged",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=False)
+ self.assertEqual(
+ result["commands"],
+ [],
+ )
+
+ def test_analytics_all_to_scsi_replaced(self):
+ args = dict(
+ config=[
+ {
+ "name": "fc18/12",
+ "speed": "auto max 64000",
+ "mode": "auto",
+ "trunk_mode": "on",
+ "enabled": True,
+ "description": "1",
+ "analytics": "fc-scsi",
+ },
+ ],
+ state="replaced",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=True)
+ self.assertEqual(
+ result["commands"],
+ ["interface fc18/12", "no analytics type fc-all", "analytics type fc-scsi"],
+ )
+
+ def test_analytics_all_to_nvme(self):
+ args = dict(
+ config=[
+ {
+ "name": "fc18/12",
+ "speed": "auto max 64000",
+ "mode": "auto",
+ "trunk_mode": "on",
+ "enabled": True,
+ "description": "1",
+ "analytics": "fc-nvme",
+ },
+ ],
+ state="merged",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=False)
+ self.assertEqual(
+ result["commands"],
+ [],
+ )
+
+ def test_analytics_all_to_nvme_replaced(self):
+ args = dict(
+ config=[
+ {
+ "name": "fc18/12",
+ "speed": "auto max 64000",
+ "mode": "auto",
+ "trunk_mode": "on",
+ "enabled": True,
+ "description": "1",
+ "analytics": "fc-nvme",
+ },
+ ],
+ state="replaced",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=True)
+ self.assertEqual(
+ result["commands"],
+ ["interface fc18/12", "no analytics type fc-all", "analytics type fc-nvme"],
+ )
+
+ def test_analytics_all_to_none_checkthis(self):
+ args = dict(
+ config=[
+ {
+ "name": "fc18/12",
+ "speed": "auto max 64000",
+ "mode": "auto",
+ "trunk_mode": "on",
+ "enabled": True,
+ "description": "1",
+ },
+ ],
+ state="merged",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=False)
+ self.assertEqual(result["commands"], [])
+
+ def test_analytics_all_to_none_desc_change(self):
+ args = dict(
+ config=[
+ {
+ "name": "fc18/12",
+ "speed": "auto max 64000",
+ "mode": "auto",
+ "trunk_mode": "on",
+ "enabled": True,
+ "description": "2",
+ "analytics": "fc-all",
+ },
+ ],
+ state="merged",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=True)
+ self.assertEqual(result["commands"], ["interface fc18/12", "switchport description 2"])
+
+ def test_analytics_scsi_to_nvme(self):
+ args = dict(
+ config=[
+ {
+ "name": "fc18/11",
+ "speed": "auto max 32000",
+ "mode": "auto",
+ "trunk_mode": "on",
+ "enabled": False,
+ "description": "a",
+ "analytics": "fc-nvme",
+ },
+ ],
+ state="merged",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=True)
+ self.assertEqual(
+ result["commands"],
+ ["interface fc18/11", "analytics type fc-nvme"],
+ )
+
+ def test_analytics_scsi_to_nvme_replaced(self):
+ args = dict(
+ config=[
+ {
+ "name": "fc18/11",
+ "speed": "auto max 32000",
+ "mode": "auto",
+ "trunk_mode": "on",
+ "enabled": False,
+ "description": "a",
+ "analytics": "fc-nvme",
+ },
+ ],
+ state="replaced",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=True)
+ self.assertEqual(
+ result["commands"],
+ ["interface fc18/11", "no analytics type fc-all", "analytics type fc-nvme"],
+ )
+
+ def test_analytics_scsi_to_all(self):
+ args = dict(
+ config=[
+ {
+ "name": "fc18/11",
+ "speed": "auto max 32000",
+ "mode": "auto",
+ "trunk_mode": "on",
+ "enabled": False,
+ "description": "a",
+ "analytics": "fc-all",
+ },
+ ],
+ state="merged",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=True)
+ self.assertEqual(result["commands"], ["interface fc18/11", "analytics type fc-all"])
+
+ def test_analytics_scsi_to_all_replaced(self):
+ args = dict(
+ config=[
+ {
+ "name": "fc18/11",
+ "speed": "auto max 32000",
+ "mode": "auto",
+ "trunk_mode": "on",
+ "enabled": False,
+ "description": "a",
+ "analytics": "fc-all",
+ },
+ ],
+ state="replaced",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=True)
+ self.assertEqual(
+ result["commands"],
+ ["interface fc18/11", "analytics type fc-all"],
+ )
+
+ def test_analytics_scsi_to_none_checkthis(self):
+ args = dict(
+ config=[
+ {
+ "name": "fc18/11",
+ "speed": "auto max 32000",
+ "mode": "auto",
+ "trunk_mode": "on",
+ "enabled": False,
+ "description": "a",
+ },
+ ],
+ state="merged",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=False)
+ self.assertEqual(result["commands"], [])
+
+ def test_analytics_nvme_to_scsi(self):
+ args = dict(
+ config=[
+ {
+ "name": "fc18/10",
+ "analytics": "fc-scsi",
+ },
+ ],
+ state="merged",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=True)
+ self.assertEqual(
+ result["commands"],
+ ["interface fc18/10", "analytics type fc-scsi"],
+ )
+
+ def test_analytics_nvme_to_scsi_replaced(self):
+ args = dict(
+ config=[
+ {
+ "name": "fc18/10",
+ "analytics": "fc-scsi",
+ },
+ ],
+ state="replaced",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=True)
+ self.assertEqual(
+ result["commands"],
+ [
+ "interface fc18/10",
+ "no switchport description",
+ "no switchport speed auto max 16000",
+ "no switchport mode auto",
+ "switchport trunk mode on",
+ "shutdown",
+ "no analytics type fc-all",
+ "analytics type fc-scsi",
+ ],
+ )
+
+ def test_analytics_nvme_to_all(self):
+ args = dict(
+ config=[
+ {
+ "name": "fc18/10",
+ "analytics": "fc-all",
+ },
+ ],
+ state="merged",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=True)
+ self.assertEqual(
+ result["commands"],
+ ["interface fc18/10", "analytics type fc-all"],
+ )
+
+ def test_analytics_nvme_to_all_replaced(self):
+ args = dict(
+ config=[
+ {
+ "name": "fc18/10",
+ "analytics": "fc-all",
+ },
+ ],
+ state="replaced",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=True)
+ self.assertEqual(
+ result["commands"],
+ [
+ "interface fc18/10",
+ "no switchport description",
+ "no switchport speed auto max 16000",
+ "no switchport mode auto",
+ "switchport trunk mode on",
+ "shutdown",
+ "analytics type fc-all",
+ ],
+ )
+
+ def test_analytics_none_to_scsi(self):
+ args = dict(
+ config=[
+ {
+ "name": "fc1/1",
+ "analytics": "fc-scsi",
+ },
+ ],
+ state="merged",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=True)
+ self.assertEqual(result["commands"], ["interface fc1/1", "analytics type fc-scsi"])
+
+ def test_analytics_none_to_scsi_replaced(self):
+ args = dict(
+ config=[
+ {
+ "name": "fc1/1",
+ "analytics": "fc-scsi",
+ },
+ ],
+ state="replaced",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=True)
+ self.assertEqual(
+ result["commands"],
+ [
+ "interface fc1/1",
+ "no switchport description",
+ "no switchport speed auto",
+ "no switchport mode auto",
+ "switchport trunk mode on",
+ "shutdown",
+ "analytics type fc-scsi",
+ ],
+ )
+
+ def test_analytics_none_to_nvme(self):
+ args = dict(
+ config=[
+ {
+ "name": "fc1/1",
+ "analytics": "fc-nvme",
+ },
+ ],
+ state="merged",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=True)
+ self.assertEqual(result["commands"], ["interface fc1/1", "analytics type fc-nvme"])
+
+ def test_analytics_none_to_nvme_replaced(self):
+ args = dict(
+ config=[
+ {
+ "name": "fc1/1",
+ "analytics": "fc-nvme",
+ },
+ ],
+ state="replaced",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=True)
+ self.assertEqual(
+ result["commands"],
+ [
+ "interface fc1/1",
+ "no switchport description",
+ "no switchport speed auto",
+ "no switchport mode auto",
+ "switchport trunk mode on",
+ "shutdown",
+ "analytics type fc-nvme",
+ ],
+ )
+
+ def test_analytics_none_to_nvme_overridden(self):
+ args = dict(
+ config=[
+ {
+ "name": "fc1/1",
+ "analytics": "fc-nvme",
+ },
+ ],
+ state="overridden",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=True)
+ self.assertEqual(
+ result["commands"],
+ [
+ "interface fc1/2",
+ "no switchport speed 1000",
+ "no switchport mode E",
+ "switchport trunk mode on",
+ "shutdown",
+ "interface fc1/3",
+ "no switchport speed 2000",
+ "no switchport mode F",
+ "switchport trunk mode on",
+ "shutdown",
+ "interface fc18/1",
+ "no switchport speed 4000",
+ "no switchport mode Fx",
+ "switchport trunk mode on",
+ "shutdown",
+ "interface fc18/2",
+ "no switchport speed 8000",
+ "no switchport mode NP",
+ "switchport trunk mode on",
+ "shutdown",
+ "interface fc18/3",
+ "no switchport speed 10000",
+ "no switchport mode SD",
+ "switchport trunk mode on",
+ "shutdown",
+ "interface fc18/4",
+ "no switchport speed 16000",
+ "no switchport mode auto",
+ "switchport trunk mode on",
+ "shutdown",
+ "interface fc18/5",
+ "no switchport speed 32000",
+ "no switchport mode auto",
+ "switchport trunk mode on",
+ "shutdown",
+ "interface fc18/6",
+ "no switchport speed 64000",
+ "no switchport mode auto",
+ "switchport trunk mode on",
+ "shutdown",
+ "interface fc18/7",
+ "no switchport speed auto max 2000",
+ "no switchport mode auto",
+ "switchport trunk mode on",
+ "shutdown",
+ "interface fc18/8",
+ "no switchport speed auto max 4000",
+ "no switchport mode auto",
+ "switchport trunk mode on",
+ "shutdown",
+ "interface fc18/9",
+ "no switchport description",
+ "no switchport speed auto max 8000",
+ "no switchport mode auto",
+ "switchport trunk mode on",
+ "shutdown",
+ "interface fc18/10",
+ "no switchport description",
+ "no switchport speed auto max 16000",
+ "no switchport mode auto",
+ "switchport trunk mode on",
+ "no analytics type fc-all",
+ "interface fc18/11",
+ "no switchport description",
+ "no switchport speed auto max 32000",
+ "no switchport mode auto",
+ "switchport trunk mode on",
+ "no analytics type fc-all",
+ "interface fc18/12",
+ "no switchport description",
+ "no switchport speed auto max 64000",
+ "no switchport mode auto",
+ "switchport trunk mode on",
+ "shutdown",
+ "no analytics type fc-all",
+ "interface fc18/13",
+ "no switchport description",
+ "no switchport speed auto max 64000",
+ "no switchport mode auto",
+ "switchport trunk mode on",
+ "shutdown",
+ "no analytics type fc-all",
+ "interface fc1/1",
+ "no switchport description",
+ "no switchport speed auto",
+ "no switchport mode auto",
+ "switchport trunk mode on",
+ "shutdown",
+ "analytics type fc-nvme",
+ ],
+ )
+
+ def test_analytics_none_to_all(self):
+ args = dict(
+ config=[
+ {
+ "name": "fc1/1",
+ "analytics": "fc-all",
+ },
+ ],
+ state="merged",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=True)
+ self.assertEqual(result["commands"], ["interface fc1/1", "analytics type fc-all"])
+
+ def test_analytics_none_to_all_replaced(self):
+ args = dict(
+ config=[
+ {
+ "name": "fc1/1",
+ "analytics": "fc-all",
+ },
+ ],
+ state="replaced",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=True)
+ self.assertEqual(
+ result["commands"],
+ [
+ "interface fc1/1",
+ "no switchport description",
+ "no switchport speed auto",
+ "no switchport mode auto",
+ "switchport trunk mode on",
+ "shutdown",
+ "analytics type fc-all",
+ ],
+ )
+
+ def test_analytics_nvme_to_none_checkthis(self):
+ args = dict(
+ config=[
+ {
+ "name": "fc18/10",
+ },
+ ],
+ state="merged",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=False)
+ self.assertEqual(result["commands"], [])
+
+ def test_description_change_from_one_to_another(self):
+ args = dict(
+ config=[
+ {
+ "name": "fc18/9",
+ "description": "changed from sample description to new description",
+ },
+ ],
+ state="merged",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=True)
+ self.assertEqual(
+ result["commands"],
+ [
+ "interface fc18/9",
+ "switchport description changed from sample description to new description",
+ ],
+ )
+
+ def test_description_change_from_none_to_new(self):
+ args = dict(
+ config=[
+ {
+ "name": "fc18/8",
+ "description": "new sample description",
+ },
+ ],
+ state="merged",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=True)
+ self.assertEqual(
+ result["commands"],
+ [
+ "interface fc18/8",
+ "switchport description new sample description",
+ ],
+ )
+
+ def test_shut_to_noshut(self):
+ args = dict(
+ config=[
+ {
+ "name": "fc18/10",
+ "enabled": True,
+ },
+ ],
+ state="merged",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=True)
+ self.assertEqual(
+ result["commands"],
+ [
+ "interface fc18/10",
+ "no shutdown",
+ ],
+ )
+
+ def test_noshut_to_shut(self):
+ args = dict(
+ config=[
+ {
+ "name": "fc18/6",
+ "enabled": False,
+ },
+ ],
+ state="merged",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=True)
+ self.assertEqual(
+ result["commands"],
+ ["interface fc18/6", "shutdown"],
+ )
+
+ def test_trunkmode_auto_to_off(self):
+ args = dict(
+ config=[
+ {
+ "name": "fc18/1",
+ "trunk_mode": "off",
+ },
+ ],
+ state="merged",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=True)
+ self.assertEqual(
+ result["commands"],
+ ["interface fc18/1", "switchport trunk mode off"],
+ )
+
+ def test_trunkmode_auto_to_on(self):
+ args = dict(
+ config=[
+ {
+ "name": "fc18/1",
+ "trunk_mode": "on",
+ },
+ ],
+ state="merged",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=True)
+ self.assertEqual(
+ result["commands"],
+ ["interface fc18/1", "switchport trunk mode on"],
+ )
+
+ def test_trunkmode_on_to_off(self):
+ args = dict(
+ config=[
+ {
+ "name": "fc1/1",
+ "trunk_mode": "off",
+ },
+ ],
+ state="merged",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=True)
+ self.assertEqual(
+ result["commands"],
+ ["interface fc1/1", "switchport trunk mode off"],
+ )
+
+ def test_trunkmode_on_to_auto(self):
+ args = dict(
+ config=[
+ {
+ "name": "fc1/1",
+ "trunk_mode": "auto",
+ },
+ ],
+ state="merged",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=True)
+ self.assertEqual(
+ result["commands"],
+ ["interface fc1/1", "switchport trunk mode auto"],
+ )
+
+ def test_trunkmode_off_to_on(self):
+ args = dict(
+ config=[
+ {
+ "name": "fc1/2",
+ "trunk_mode": "on",
+ },
+ ],
+ state="merged",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=True)
+ self.assertEqual(
+ result["commands"],
+ ["interface fc1/2", "switchport trunk mode on"],
+ )
+
+ def test_trunkmode_off_to_auto(self):
+ args = dict(
+ config=[
+ {
+ "name": "fc1/2",
+ "trunk_mode": "auto",
+ },
+ ],
+ state="merged",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=True)
+ self.assertEqual(
+ result["commands"],
+ ["interface fc1/2", "switchport trunk mode auto"],
+ )
+
+ def test_speed_combinations(self):
+ port_speed = "auto"
+ port_name = "fc1/1"
+ for each_speed in allowed_speed_values:
+ args = dict(
+ config=[
+ {
+ "name": port_name,
+ "speed": each_speed,
+ },
+ ],
+ state="merged",
+ )
+ if each_speed == port_speed:
+ changed = False
+ cmds = []
+ else:
+ changed = True
+ cmds = [f"interface {port_name}", f"switchport speed {each_speed}"]
+
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=changed)
+ self.assertEqual(
+ result["commands"],
+ cmds,
+ )
+
+ def test_port_mode_combinations(self):
+ port_mode = "auto"
+ port_name = "fc1/1"
+ for each_mode in allowed_port_modes:
+ args = dict(
+ config=[
+ {
+ "name": port_name,
+ "mode": each_mode,
+ },
+ ],
+ state="merged",
+ )
+ if each_mode == port_mode:
+ changed = False
+ cmds = []
+ else:
+ changed = True
+ cmds = [f"interface {port_name}", f"switchport mode {each_mode}"]
+
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=changed)
+ self.assertEqual(
+ result["commands"],
+ cmds,
+ )
+
+ def test_deleted_1(self):
+ # before- trunk mode on
+ args = dict(
+ config=[
+ {
+ "name": "fc1/2",
+ },
+ ],
+ state="deleted",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=True)
+ self.assertEqual(
+ result["commands"],
+ [
+ "interface fc1/2",
+ "no switchport speed 1000",
+ "no switchport mode E",
+ "switchport trunk mode on",
+ "shutdown",
+ ],
+ )
+
+ def test_deleted_2(self):
+ # before- trunk mode off
+ args = dict(
+ config=[
+ {
+ "name": "fc1/3",
+ },
+ ],
+ state="deleted",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=True)
+ self.assertEqual(
+ result["commands"],
+ [
+ "interface fc1/3",
+ "no switchport speed 2000",
+ "no switchport mode F",
+ "switchport trunk mode on",
+ "shutdown",
+ ],
+ )
+
+ def test_deleted_3(self):
+ # before- port shut and with description and analytics config
+ args = dict(
+ config=[
+ {
+ "name": "fc18/10",
+ },
+ ],
+ state="deleted",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=True)
+ self.assertEqual(
+ result["commands"],
+ [
+ "interface fc18/10",
+ "no switchport description",
+ "no switchport speed auto max 16000",
+ "no switchport mode auto",
+ "switchport trunk mode on",
+ "no analytics type fc-all",
+ ],
+ )
+
+ def test_replaced_move_to_def(self):
+ args = dict(
+ config=[
+ {
+ "name": "fc18/10",
+ },
+ ],
+ state="replaced",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=True)
+ self.assertEqual(
+ result["commands"],
+ [
+ "interface fc18/10",
+ "no switchport description",
+ "no switchport speed auto max 16000",
+ "no switchport mode auto",
+ "switchport trunk mode on",
+ "shutdown",
+ "no analytics type fc-all",
+ ],
+ )
+
+ def test_deleted_combined(self):
+ args = dict(
+ config=[
+ {
+ "name": "fc1/2",
+ },
+ {
+ "name": "fc1/3",
+ },
+ {
+ "name": "fc18/10",
+ },
+ ],
+ state="deleted",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=True)
+ self.assertEqual(
+ result["commands"],
+ [
+ "interface fc1/2",
+ "no switchport speed 1000",
+ "no switchport mode E",
+ "switchport trunk mode on",
+ "shutdown",
+ "interface fc1/3",
+ "no switchport speed 2000",
+ "no switchport mode F",
+ "switchport trunk mode on",
+ "shutdown",
+ "interface fc18/10",
+ "no switchport description",
+ "no switchport speed auto max 16000",
+ "no switchport mode auto",
+ "switchport trunk mode on",
+ "no analytics type fc-all",
+ ],
+ )
+
+ def test_most_of_them_combined(self):
+ args = dict(
+ config=[
+ {
+ "name": "fc18/13",
+ "speed": "auto max 64000",
+ "mode": "auto",
+ "trunk_mode": "on",
+ "enabled": True,
+ "description": "1",
+ "analytics": "fc-all",
+ },
+ {
+ "name": "fc18/12",
+ "speed": "auto max 64000",
+ "mode": "auto",
+ "trunk_mode": "on",
+ "enabled": True,
+ "description": "1",
+ "analytics": "fc-scsi",
+ },
+ {
+ "name": "fc18/11",
+ "speed": "auto max 32000",
+ "mode": "auto",
+ "trunk_mode": "on",
+ "enabled": False,
+ "description": "a",
+ "analytics": "fc-all",
+ },
+ {
+ "name": "fc18/10",
+ "analytics": "fc-scsi",
+ "enabled": True,
+ },
+ {
+ "name": "fc18/9",
+ "description": "changed from sample description to new description",
+ },
+ {
+ "name": "fc18/8",
+ "description": "new sample description",
+ },
+ {
+ "name": "fc18/6",
+ "enabled": False,
+ },
+ {
+ "name": "fc18/1",
+ "trunk_mode": "off",
+ },
+ {
+ "name": "fc1/1",
+ "trunk_mode": "auto",
+ "analytics": "fc-all",
+ },
+ {
+ "name": "fc1/2",
+ "trunk_mode": "on",
+ },
+ ],
+ state="merged",
+ )
+ set_module_args(args, ignore_provider_arg)
+ result = self.execute_module(changed=True)
+ self.assertEqual(
+ result["commands"],
+ [
+ "interface fc1/1",
+ "switchport trunk mode auto",
+ "analytics type fc-all",
+ ]
+ + [
+ "interface fc1/2",
+ "switchport trunk mode on",
+ ]
+ + [
+ "interface fc18/1",
+ "switchport trunk mode off",
+ ]
+ + [
+ "interface fc18/6",
+ "shutdown",
+ ]
+ + [
+ "interface fc18/8",
+ "switchport description new sample description",
+ ]
+ + [
+ "interface fc18/9",
+ "switchport description changed from sample description to new description",
+ ]
+ + [
+ "interface fc18/10",
+ "no shutdown",
+ # "no analytics type fc-all",
+ "analytics type fc-scsi",
+ ]
+ + [
+ "interface fc18/11",
+ "analytics type fc-all",
+ ],
+ # + [
+ # "interface fc18/12",
+ # # "no analytics type fc-all",
+ # "analytics type fc-scsi",
+ # ],
+ )
diff --git a/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_interfaces.py b/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_interfaces.py
index 7dac77c98..fb8dae234 100644
--- a/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_interfaces.py
+++ b/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_interfaces.py
@@ -772,3 +772,49 @@ class TestNxosInterfacesModule(TestNxosModule):
playbook["state"] = "merged"
set_module_args(playbook, ignore_provider_arg)
self.execute_module(changed=True, commands=merged)
+
+ def test_mode_mtu(self):
+ # test mode change with MTU
+ sysdefs = dedent(
+ """\
+ !
+ ! Interfaces default to L3 !!
+ !
+ no system default switchport
+ """,
+ )
+ intf = dedent(
+ """\
+ interface Ethernet1/28
+ description Auto_Cable_Testing
+ mtu 9216
+ """,
+ )
+ self.get_resource_connection_facts.return_value = {self.SHOW_RUN_INTF: intf}
+ self.get_system_defaults.return_value = sysdefs
+
+ playbook = dict(
+ config=[
+ dict(
+ name="Ethernet1/28",
+ description="Ansible Port Turn Up1",
+ mode="layer2",
+ mtu="9216",
+ speed="1000",
+ duplex="full",
+ enabled=True,
+ ),
+ ],
+ )
+ replaced = [
+ "interface Ethernet1/28",
+ "description Ansible Port Turn Up1",
+ "switchport",
+ "mtu 9216",
+ "speed 1000",
+ "duplex full",
+ "no shutdown",
+ ]
+ playbook["state"] = "replaced"
+ set_module_args(playbook, ignore_provider_arg)
+ self.execute_module(changed=True, commands=replaced)
diff --git a/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_pim_interface.py b/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_pim_interface.py
index 886a77940..b746b8b46 100644
--- a/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_pim_interface.py
+++ b/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_pim_interface.py
@@ -63,7 +63,7 @@ class TestNxosIPInterfaceModule(TestNxosModule):
output = list()
for command in commands:
- if type(command) == dict:
+ if isinstance(command, dict):
command = command["command"]
filename = str(command).split(" | ", 1)[0].replace(" ", "_").replace("/", "_")
output.append(load_fixture(module_name, filename))
diff --git a/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_ping.py b/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_ping.py
index 73535f89e..bdaabe881 100644
--- a/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_ping.py
+++ b/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_ping.py
@@ -32,7 +32,7 @@ ignore_provider_arg = True
class TestNxosPingModule(TestNxosModule):
- """Class used for Unit Tests agains ios_ping module"""
+ """Class used for Unit Tests against nxos_ping module"""
module = nxos_ping
diff --git a/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_route_maps.py b/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_route_maps.py
index 53069a1e9..06d76fe38 100644
--- a/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_route_maps.py
+++ b/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_route_maps.py
@@ -1415,3 +1415,81 @@ class TestNxosRouteMapsModule(TestNxosModule):
]
result = self.execute_module(changed=True)
self.assertEqual(set(result["commands"]), set(commands))
+
+ def test_nxos_route_maps_extcomm_rt(self):
+ # test for extcommunity.rt
+ self.get_config.return_value = dedent(
+ """\
+ route-map test-1 permit 10
+ set extcommunity rt additive
+ route-map test-2 permit 11
+ set extcommunity rt 65000:516590 65000:516591 65000:516592 additive
+ """,
+ )
+ set_module_args(
+ dict(
+ config=[
+ dict(
+ route_map="test-1",
+ entries=[
+ dict(
+ action="permit",
+ sequence=10,
+ set=dict(
+ extcommunity=dict(
+ rt=dict(
+ extcommunity_numbers=[
+ "65000:516586",
+ ],
+ additive=True,
+ ),
+ ),
+ ),
+ ),
+ ],
+ ),
+ ],
+ state="merged",
+ ),
+ ignore_provider_arg,
+ )
+ commands = [
+ "route-map test-1 permit 10",
+ "set extcommunity rt 65000:516586 additive",
+ ]
+ result = self.execute_module(changed=True)
+ self.assertEqual(set(result["commands"]), set(commands))
+
+ set_module_args(
+ dict(
+ config=[
+ dict(
+ route_map="test-2",
+ entries=[
+ dict(
+ action="permit",
+ sequence=11,
+ set=dict(
+ extcommunity=dict(
+ rt=dict(
+ extcommunity_numbers=[
+ "65000:516590",
+ ],
+ ),
+ ),
+ ),
+ ),
+ ],
+ ),
+ ],
+ state="replaced",
+ ),
+ ignore_provider_arg,
+ )
+ commands = [
+ "route-map test-2 permit 11",
+ "no set extcommunity rt 65000:516590 65000:516591 65000:516592 additive",
+ "set extcommunity rt 65000:516590",
+ ]
+ result = self.execute_module(changed=True)
+ self.assertEqual(set(result["commands"]), set(commands))
diff --git a/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_snmp_server.py b/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_snmp_server.py
index 1b66d6455..1b7672775 100644
--- a/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_snmp_server.py
+++ b/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_snmp_server.py
@@ -793,10 +793,8 @@ class TestNxosSnmpServerModule(TestNxosModule):
ignore_provider_arg,
)
commands = [
- "no snmp-server user user2 network-admin auth md5 0x5632724fb8ac3699296af262 priv"
- " 0x5632724fb8ac3699296af262 localizedkey engineID 2:2:2:2:2",
- "no snmp-server user user3 network-admin auth md5 0x5632724fb8ac3699296af262 priv"
- " aes-128 0x5632724fb8ac3699296af262 localizedkey engineID 3:3:3:3:3",
+ "no snmp-server user user2",
+ "no snmp-server user user3",
"snmp-server user user4 network-admin auth md5 0x5632724fb8ac3699296af262 priv aes-128"
" 0x5632724fb8ac3699296af262 localizedkey engineID 3:3:3:3:3",
]
diff --git a/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_static_routes.py b/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_static_routes.py
index 69f5f74bd..76ed4a3a9 100644
--- a/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_static_routes.py
+++ b/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_static_routes.py
@@ -8,11 +8,15 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
+from textwrap import dedent
+
from ansible_collections.cisco.nxos.plugins.modules import nxos_static_routes
from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch
-from ansible_collections.cisco.nxos.tests.unit.modules.utils import set_module_args
-from .nxos_module import TestNxosModule
+from .nxos_module import TestNxosModule, set_module_args
+
+
+ignore_provider_arg = True
class TestNxosStaticRoutesModule(TestNxosModule):
@@ -21,275 +25,685 @@ class TestNxosStaticRoutesModule(TestNxosModule):
def setUp(self):
super(TestNxosStaticRoutesModule, 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.nxos.plugins.module_utils.network.nxos.config.static_routes.static_routes.Static_routes.edit_config",
+ self.mock_get_resource_connection = patch(
+ "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection",
)
- self.edit_config = self.mock_edit_config.start()
+ self.get_resource_connection = self.mock_get_resource_connection.start()
self.mock_execute_show_command = patch(
- "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.static_routes.static_routes.Static_routesFacts.get_device_data",
+ "ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.facts.static_routes.static_routes.Static_routesFacts.get_static_routes_data",
)
self.execute_show_command = self.mock_execute_show_command.start()
def tearDown(self):
super(TestNxosStaticRoutesModule, 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.get_resource_connection.stop()
self.mock_execute_show_command.stop()
- def load_fixtures(self, commands=None, device=""):
- def load_from_file(*args, **kwargs):
- non_vrf_data = ["ip route 192.0.2.16/28 192.0.2.24 name initial_route"]
- vrf_data = [
- "vrf context test\n ip route 192.0.2.96/28 192.0.2.122 vrf dest_vrf"
- "\n ip route static bfd Vlan100 192.168.1.100\n ipv6 route 2001:db8:12::/32 2001:db8::1001 name ipv6_route 3\n",
- ]
+ def test_nxos_static_routes_all_idempotent(self):
+ self.execute_show_command.return_value = dedent(
+ """\
+ ip route 192.0.2.16/28 192.0.2.23 name replaced_route1 3
+ ip route 192.0.2.16/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name replaced_route2
+ ip route 192.0.2.80/28 192.0.2.26 tag 12
+ vrf context Test
+ ip route 192.0.2.48/28 192.0.2.13
+ ip route 192.0.2.48/28 192.0.2.14 5
+ vrf context management
+ ip name-server 192.168.255.1
+ ip route 0.0.0.0/0 192.168.255.1
+ vrf context newvrf
+ ip route 10.0.10.0/25 10.0.10.3 name test_name tag 22323 11
+ ip route 10.0.11.0/25 10.0.11.10 tag 22 11
+ ip route 10.0.11.0/25 10.0.11.12 vrf Test tag 22 11
+ ip route 192.0.2.48/28 loopback22 192.0.2.13
+ ipv6 route 2200:10::/36 2048:ae12::1 vrf dest 5
+ ipv6 route 2200:10::/36 mgmt0 2048:ae12::1 tag 22 11
+ ipv6 route 2200:10::/36 port-channel22 2048:ae12::1
+ ipv6 route 2200:10::/36 Ethernet2/1 2048:ae12::1 name test_name2 22
+ vrf context trial_vrf
+ ip route 192.0.2.64/28 192.0.2.22 tag 4
+ ip route 192.0.2.64/28 192.0.2.23 name merged_route 1
+ """,
+ )
- output = non_vrf_data + vrf_data
- return output
+ config = [
+ {
+ "address_families": [
+ {
+ "afi": "ipv4",
+ "routes": [
+ {
+ "next_hops": [
+ {
+ "forward_router_address": "192.0.2.23",
+ "admin_distance": 3,
+ "route_name": "replaced_route1",
+ },
+ {
+ "interface": "Ethernet1/2",
+ "forward_router_address": "192.0.2.45",
+ "dest_vrf": "destinationVRF",
+ "route_name": "replaced_route2",
+ },
+ ],
+ "dest": "192.0.2.16/28",
+ },
+ {
+ "next_hops": [{"forward_router_address": "192.0.2.26", "tag": 12}],
+ "dest": "192.0.2.80/28",
+ },
+ ],
+ },
+ ],
+ },
+ {
+ "vrf": "Test",
+ "address_families": [
+ {
+ "afi": "ipv4",
+ "routes": [
+ {
+ "next_hops": [
+ {"forward_router_address": "192.0.2.13"},
+ {
+ "forward_router_address": "192.0.2.14",
+ "admin_distance": 5,
+ },
+ ],
+ "dest": "192.0.2.48/28",
+ },
+ ],
+ },
+ ],
+ },
+ {
+ "vrf": "management",
+ "address_families": [
+ {
+ "afi": "ipv4",
+ "routes": [
+ {
+ "next_hops": [{"forward_router_address": "192.168.255.1"}],
+ "dest": "0.0.0.0/0",
+ },
+ ],
+ },
+ ],
+ },
+ {
+ "vrf": "newvrf",
+ "address_families": [
+ {
+ "afi": "ipv4",
+ "routes": [
+ {
+ "next_hops": [
+ {
+ "forward_router_address": "10.0.10.3",
+ "admin_distance": 11,
+ "tag": 22323,
+ "route_name": "test_name",
+ },
+ ],
+ "dest": "10.0.10.0/25",
+ },
+ {
+ "next_hops": [
+ {
+ "forward_router_address": "10.0.11.10",
+ "admin_distance": 11,
+ "tag": 22,
+ },
+ {
+ "forward_router_address": "10.0.11.12",
+ "admin_distance": 11,
+ "dest_vrf": "Test",
+ "tag": 22,
+ },
+ ],
+ "dest": "10.0.11.0/25",
+ },
+ {
+ "next_hops": [
+ {
+ "interface": "loopback22",
+ "forward_router_address": "192.0.2.13",
+ },
+ ],
+ "dest": "192.0.2.48/28",
+ },
+ ],
+ },
+ {
+ "afi": "ipv6",
+ "routes": [
+ {
+ "next_hops": [
+ {
+ "forward_router_address": "2048:ae12::1",
+ "admin_distance": 5,
+ "dest_vrf": "dest",
+ },
+ {
+ "interface": "mgmt0",
+ "forward_router_address": "2048:ae12::1",
+ "admin_distance": 11,
+ "tag": 22,
+ },
+ {
+ "interface": "port-channel22",
+ "forward_router_address": "2048:ae12::1",
+ },
+ {
+ "interface": "Ethernet2/1",
+ "forward_router_address": "2048:ae12::1",
+ "admin_distance": 22,
+ "route_name": "test_name2",
+ },
+ ],
+ "dest": "2200:10::/36",
+ },
+ ],
+ },
+ ],
+ },
+ {
+ "vrf": "trial_vrf",
+ "address_families": [
+ {
+ "afi": "ipv4",
+ "routes": [
+ {
+ "next_hops": [
+ {"forward_router_address": "192.0.2.22", "tag": 4},
+ {
+ "forward_router_address": "192.0.2.23",
+ "admin_distance": 1,
+ "route_name": "merged_route",
+ },
+ ],
+ "dest": "192.0.2.64/28",
+ },
+ ],
+ },
+ ],
+ },
+ ]
- self.execute_show_command.side_effect = load_from_file
+ for state in ["merged", "replaced", "overridden"]:
+ set_module_args({"config": config, "state": state})
+ result = self.execute_module(changed=False)
+ self.assertEqual(result["commands"], [])
def test_nxos_static_routes_merged(self):
+ self.execute_show_command.return_value = dedent(
+ """\
+ ip route 192.0.2.16/28 192.0.2.23 name replaced_route1 3
+ """,
+ )
set_module_args(
dict(
config=[
- dict(
- address_families=[
- dict(
- afi="ipv4",
- routes=[
- dict(
- dest="192.0.2.32/28",
- next_hops=[
- dict(
- forward_router_address="192.0.2.40",
- interface="Ethernet1/2",
- admin_distance=5,
- ),
+ {
+ "address_families": [
+ {
+ "afi": "ipv4",
+ "routes": [
+ {
+ "next_hops": [
+ {
+ "forward_router_address": "192.0.2.23",
+ "admin_distance": 3,
+ "route_name": "replaced_route1",
+ },
+ {
+ "interface": "Ethernet1/2",
+ "forward_router_address": "192.0.2.45",
+ "dest_vrf": "destinationVRF",
+ "route_name": "replaced_route2",
+ },
],
- ),
+ "dest": "192.0.2.16/28",
+ },
+ {
+ "next_hops": [
+ {"forward_router_address": "192.0.2.26", "tag": 12},
+ ],
+ "dest": "192.0.2.80/28",
+ },
],
- ),
+ },
],
- ),
- ],
- state="merged",
- ),
- )
- commands = [
- "configure terminal",
- "ip route 192.0.2.32/28 Ethernet1/2 192.0.2.40 5",
- ]
- self.execute_module(changed=True, commands=commands)
-
- def test_nxos_static_routes_merged_idempotent(self):
- set_module_args(
- dict(
- config=[
- dict(
- address_families=[
- dict(
- afi="ipv4",
- routes=[
- dict(
- dest="192.0.2.16/28",
- next_hops=[
- dict(
- forward_router_address="192.0.2.24",
- route_name="initial_route",
- ),
+ },
+ {
+ "vrf": "Test",
+ "address_families": [
+ {
+ "afi": "ipv4",
+ "routes": [
+ {
+ "next_hops": [
+ {"forward_router_address": "192.0.2.13"},
+ {
+ "forward_router_address": "192.0.2.14",
+ "admin_distance": 5,
+ },
],
- ),
+ "dest": "192.0.2.48/28",
+ },
],
- ),
+ },
],
- ),
- ],
- state="merged",
- ),
- )
- self.execute_module(changed=False, commands=[])
-
- def test_nxos_static_routes_replaced(self):
- set_module_args(
- dict(
- config=[
- dict(
- address_families=[
- dict(
- afi="ipv4",
- routes=[
- dict(
- dest="192.0.2.16/28",
- next_hops=[
- dict(
- forward_router_address="192.0.2.50",
- tag=12,
- route_name="replaced_route",
- ),
+ },
+ {
+ "vrf": "management",
+ "address_families": [
+ {
+ "afi": "ipv4",
+ "routes": [
+ {
+ "next_hops": [{"forward_router_address": "192.168.255.1"}],
+ "dest": "0.0.0.0/0",
+ },
+ ],
+ },
+ ],
+ },
+ {
+ "vrf": "newvrf",
+ "address_families": [
+ {
+ "afi": "ipv4",
+ "routes": [
+ {
+ "next_hops": [
+ {
+ "forward_router_address": "10.0.10.3",
+ "admin_distance": 11,
+ "tag": 22323,
+ "route_name": "test_name",
+ },
],
- ),
+ "dest": "10.0.10.0/25",
+ },
+ {
+ "next_hops": [
+ {
+ "forward_router_address": "10.0.11.10",
+ "admin_distance": 11,
+ "tag": 22,
+ },
+ {
+ "forward_router_address": "10.0.11.12",
+ "admin_distance": 11,
+ "dest_vrf": "Test",
+ "tag": 22,
+ },
+ ],
+ "dest": "10.0.11.0/25",
+ },
+ {
+ "next_hops": [
+ {
+ "interface": "loopback22",
+ "forward_router_address": "192.0.2.13",
+ },
+ ],
+ "dest": "192.0.2.48/28",
+ },
],
- ),
+ },
+ {
+ "afi": "ipv6",
+ "routes": [
+ {
+ "next_hops": [
+ {
+ "forward_router_address": "2048:ae12::1",
+ "admin_distance": 5,
+ "dest_vrf": "dest",
+ },
+ {
+ "interface": "mgmt0",
+ "forward_router_address": "2048:ae12::1",
+ "admin_distance": 11,
+ "tag": 22,
+ },
+ {
+ "interface": "port-channel22",
+ "forward_router_address": "2048:ae12::1",
+ },
+ {
+ "interface": "Ethernet2/1",
+ "forward_router_address": "2048:ae12::1",
+ "admin_distance": 22,
+ "route_name": "test_name2",
+ },
+ ],
+ "dest": "2200:10::/36",
+ },
+ ],
+ },
],
- ),
+ },
+ {
+ "vrf": "trial_vrf",
+ "address_families": [
+ {
+ "afi": "ipv4",
+ "routes": [
+ {
+ "next_hops": [
+ {"forward_router_address": "192.0.2.22", "tag": 4},
+ {
+ "forward_router_address": "192.0.2.23",
+ "admin_distance": 1,
+ "route_name": "merged_route",
+ },
+ ],
+ "dest": "192.0.2.64/28",
+ },
+ ],
+ },
+ ],
+ },
],
- state="replaced",
+ state="merged",
),
)
commands = [
- "configure terminal",
- "no ip route 192.0.2.16/28 192.0.2.24 name initial_route",
- "ip route 192.0.2.16/28 192.0.2.50 name replaced_route tag 12",
+ "ip route 192.0.2.80/28 192.0.2.26 tag 12",
+ "ip route 192.0.2.16/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name replaced_route2",
+ "vrf context newvrf",
+ "ip route 10.0.10.0/25 10.0.10.3 name test_name tag 22323 11",
+ "ip route 10.0.11.0/25 10.0.11.10 tag 22 11",
+ "ip route 10.0.11.0/25 10.0.11.12 vrf Test tag 22 11",
+ "ip route 192.0.2.48/28 loopback22 192.0.2.13",
+ "ipv6 route 2200:10::/36 2048:ae12::1 vrf dest 5",
+ "ipv6 route 2200:10::/36 mgmt0 2048:ae12::1 tag 22 11",
+ "ipv6 route 2200:10::/36 port-channel22 2048:ae12::1",
+ "ipv6 route 2200:10::/36 Ethernet2/1 2048:ae12::1 name test_name2 22",
+ "vrf context Test",
+ "ip route 192.0.2.48/28 192.0.2.13",
+ "ip route 192.0.2.48/28 192.0.2.14 5",
+ "vrf context trial_vrf",
+ "ip route 192.0.2.64/28 192.0.2.22 tag 4",
+ "ip route 192.0.2.64/28 192.0.2.23 name merged_route 1",
+ "vrf context management",
+ "ip route 0.0.0.0/0 192.168.255.1",
]
self.execute_module(changed=True, commands=commands)
- def test_nxos_static_routes_replaced_idempotent(self):
+ def test_nxos_static_routes_replaced(self):
+ self.execute_show_command.return_value = dedent(
+ """\
+ ip route 192.0.2.16/28 192.0.2.23 name replaced_route1 3
+ ip route 192.0.2.16/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name replaced_route2
+ ip route 192.0.2.80/28 192.0.2.26 tag 12
+ vrf context Test
+ ip route 192.0.2.48/28 192.0.2.13
+ ip route 192.0.2.48/28 192.0.2.14 5
+ vrf context management
+ ip name-server 192.168.255.1
+ ip route 0.0.0.0/0 192.168.255.1
+ vrf context newvrf
+ ip route 10.0.10.0/25 10.0.10.3 name test_name tag 22323 11
+ ip route 10.0.11.0/25 10.0.11.10 tag 22 11
+ ip route 10.0.11.0/25 10.0.11.12 vrf Test tag 22 11
+ ip route 192.0.2.48/28 loopback22 192.0.2.13
+ ipv6 route 2200:10::/36 2048:ae12::1 vrf dest 5
+ ipv6 route 2200:10::/36 mgmt0 2048:ae12::1 tag 22 11
+ ipv6 route 2200:10::/36 port-channel22 2048:ae12::1
+ ipv6 route 2200:10::/36 Ethernet2/1 2048:ae12::1 name test_name2 22
+ vrf context trial_vrf
+ ip route 192.0.2.64/28 192.0.2.22 tag 4
+ ip route 192.0.2.64/28 192.0.2.23 name merged_route 1
+ """,
+ )
set_module_args(
dict(
config=[
- dict(
- address_families=[
- dict(
- afi="ipv4",
- routes=[
- dict(
- dest="192.0.2.16/28",
- next_hops=[
- dict(
- forward_router_address="192.0.2.24",
- route_name="initial_route",
- ),
+ {
+ "address_families": [
+ {
+ "afi": "ipv4",
+ "routes": [
+ {
+ "next_hops": [
+ {
+ "forward_router_address": "192.0.2.23",
+ "admin_distance": 3,
+ "route_name": "replaced_route1",
+ },
+ {
+ "interface": "Ethernet1/2",
+ "forward_router_address": "192.0.2.45",
+ "dest_vrf": "destinationVRF",
+ "route_name": "replaced_route2",
+ },
],
- ),
+ "dest": "192.0.2.16/28",
+ },
+ {
+ "next_hops": [
+ {"forward_router_address": "192.0.2.27", "tag": 13},
+ ],
+ "dest": "192.0.2.80/28",
+ },
],
- ),
+ },
],
- ),
- ],
- state="replaced",
- ),
- )
- self.execute_module(changed=False, commands=[])
-
- def test_nxos_static_routes_overridden(self):
- set_module_args(
- dict(
- config=[
- dict(
- address_families=[
- dict(
- afi="ipv4",
- routes=[
- dict(
- dest="192.0.2.112/28",
- next_hops=[
- dict(
- forward_router_address="192.0.2.68",
- route_name="overridden_route",
- dest_vrf="end_vrf",
- ),
+ },
+ {
+ "vrf": "trial_vrf",
+ "address_families": [
+ {
+ "afi": "ipv4",
+ "routes": [
+ {
+ "next_hops": [
+ {
+ "forward_router_address": "192.0.2.23",
+ "admin_distance": 1,
+ "route_name": "merged_route",
+ },
],
- ),
+ "dest": "192.0.2.0/28",
+ },
],
- ),
+ },
],
- ),
+ },
],
- state="overridden",
+ state="replaced",
),
)
commands = [
- "configure terminal",
- "no ip route 192.0.2.16/28 192.0.2.24 name initial_route",
- "ip route 192.0.2.112/28 192.0.2.68 vrf end_vrf name overridden_route",
- "vrf context test",
- "no ipv6 route 2001:db8:12::/32 2001:db8::1001 name ipv6_route 3",
- "no ip route 192.0.2.96/28 192.0.2.122 vrf dest_vrf",
+ "ip route 192.0.2.80/28 192.0.2.27 tag 13",
+ "no ip route 192.0.2.80/28 192.0.2.26 tag 12",
+ "vrf context trial_vrf",
+ "ip route 192.0.2.0/28 192.0.2.23 name merged_route 1",
+ "no ip route 192.0.2.64/28 192.0.2.22 tag 4",
+ "no ip route 192.0.2.64/28 192.0.2.23 name merged_route 1",
]
- self.execute_module(changed=True, commands=commands)
+ result = self.execute_module(changed=True)
+ self.assertEqual(result["commands"], commands)
- def test_nxos_static_routes_overridden_idempotent(self):
+ def test_nxos_static_routes_overridden(self):
+ self.execute_show_command.return_value = dedent(
+ """\
+ ip route 192.0.2.17/28 192.0.2.23 name replaced_route1 3
+ ip route 192.0.2.17/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name replaced_route2
+ ip route 192.0.2.79/28 192.0.2.26 tag 12
+ vrf context Test
+ ip route 192.0.2.48/28 192.0.2.13
+ ip route 192.0.2.48/28 192.0.2.14 5
+ vrf context management
+ ip name-server 192.168.255.1
+ ip route 0.0.0.0/0 192.168.255.1
+ vrf context newvrf
+ ip route 10.0.10.0/25 10.0.10.3 name test_name tag 22323 11
+ ip route 10.0.11.0/25 10.0.11.10 tag 22 11
+ ip route 10.0.11.0/25 10.0.11.12 vrf Test tag 22 11
+ ip route 192.0.2.48/28 loopback22 192.0.2.13
+ ipv6 route 2200:10::/36 2048:ae12::1 vrf dest 5
+ ipv6 route 2200:10::/36 mgmt0 2048:ae12::1 tag 22 11
+ ipv6 route 2200:10::/36 port-channel22 2048:ae12::1
+ ipv6 route 2200:10::/36 Ethernet2/1 2048:ae12::1 name test_name2 22
+ vrf context trial_vrf
+ ip route 192.0.2.64/28 192.0.2.22 tag 4
+ ip route 192.0.2.64/28 192.0.2.23 name merged_route 1
+ """,
+ )
set_module_args(
dict(
config=[
- dict(
- vrf="test",
- address_families=[
- dict(
- afi="ipv4",
- routes=[
- dict(
- dest="192.0.2.96/28",
- next_hops=[
- dict(
- forward_router_address="192.0.2.122",
- dest_vrf="dest_vrf",
- ),
+ {
+ "address_families": [
+ {
+ "afi": "ipv4",
+ "routes": [
+ {
+ "next_hops": [
+ {
+ "forward_router_address": "192.0.2.23",
+ "admin_distance": 3,
+ "route_name": "replaced_route1",
+ },
+ {
+ "interface": "Ethernet1/2",
+ "forward_router_address": "192.0.2.45",
+ "dest_vrf": "destinationVRF",
+ "route_name": "replaced_route2",
+ },
],
- ),
+ "dest": "192.0.2.16/28",
+ },
+ {
+ "next_hops": [
+ {"forward_router_address": "192.0.2.27", "tag": 13},
+ ],
+ "dest": "192.0.2.80/28",
+ },
],
- ),
+ },
],
- ),
- dict(
- address_families=[
- dict(
- afi="ipv4",
- routes=[
- dict(
- dest="192.0.2.16/28",
- next_hops=[
- dict(
- forward_router_address="192.0.2.24",
- route_name="initial_route",
- ),
+ },
+ {
+ "vrf": "trial_vrf",
+ "address_families": [
+ {
+ "afi": "ipv4",
+ "routes": [
+ {
+ "next_hops": [
+ {
+ "forward_router_address": "192.0.2.23",
+ "admin_distance": 1,
+ "route_name": "merged_route",
+ },
],
- ),
+ "dest": "192.0.2.0/28",
+ },
],
- ),
+ },
],
- ),
+ },
],
state="overridden",
),
)
- self.execute_module(changed=False, commands=[])
+ commands = [
+ "ip route 192.0.2.16/28 192.0.2.23 name replaced_route1 3",
+ "ip route 192.0.2.16/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name replaced_route2",
+ "ip route 192.0.2.80/28 192.0.2.27 tag 13",
+ "no ip route 192.0.2.17/28 192.0.2.23 name replaced_route1 3",
+ "no ip route 192.0.2.17/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name replaced_route2",
+ "no ip route 192.0.2.79/28 192.0.2.26 tag 12",
+ "vrf context trial_vrf",
+ "ip route 192.0.2.0/28 192.0.2.23 name merged_route 1",
+ "no ip route 192.0.2.64/28 192.0.2.22 tag 4",
+ "no ip route 192.0.2.64/28 192.0.2.23 name merged_route 1",
+ "vrf context Test",
+ "no ip route 192.0.2.48/28 192.0.2.13",
+ "no ip route 192.0.2.48/28 192.0.2.14 5",
+ "vrf context management",
+ "no ip route 0.0.0.0/0 192.168.255.1",
+ "vrf context newvrf",
+ "no ip route 10.0.10.0/25 10.0.10.3 name test_name tag 22323 11",
+ "no ip route 10.0.11.0/25 10.0.11.10 tag 22 11",
+ "no ip route 10.0.11.0/25 10.0.11.12 vrf Test tag 22 11",
+ "no ip route 192.0.2.48/28 loopback22 192.0.2.13",
+ "no ipv6 route 2200:10::/36 2048:ae12::1 vrf dest 5",
+ "no ipv6 route 2200:10::/36 mgmt0 2048:ae12::1 tag 22 11",
+ "no ipv6 route 2200:10::/36 port-channel22 2048:ae12::1",
+ "no ipv6 route 2200:10::/36 Ethernet2/1 2048:ae12::1 name test_name2 22",
+ ]
+ result = self.execute_module(changed=True)
+ self.assertEqual(result["commands"], commands)
def test_nxos_static_routes_deletedvrf(self):
- set_module_args(dict(config=[dict(vrf="test")], state="deleted"))
+ self.execute_show_command.return_value = dedent(
+ """\
+ ip route 192.0.2.17/28 192.0.2.23 name replaced_route1 3
+ ip route 192.0.2.17/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name replaced_route2
+ ip route 192.0.2.79/28 192.0.2.26 tag 12
+ vrf context Test
+ ip route 192.0.2.48/28 192.0.2.13
+ ip route 192.0.2.48/28 192.0.2.14 5
+ vrf context management
+ ip name-server 192.168.255.1
+ ip route 0.0.0.0/0 192.168.255.1
+ vrf context newvrf
+ ip route 10.0.10.0/25 10.0.10.3 name test_name tag 22323 11
+ ip route 10.0.11.0/25 10.0.11.10 tag 22 11
+ ip route 10.0.11.0/25 10.0.11.12 vrf Test tag 22 11
+ ip route 192.0.2.48/28 loopback22 192.0.2.13
+ ipv6 route 2200:10::/36 2048:ae12::1 vrf dest 5
+ ipv6 route 2200:10::/36 mgmt0 2048:ae12::1 tag 22 11
+ ipv6 route 2200:10::/36 port-channel22 2048:ae12::1
+ ipv6 route 2200:10::/36 Ethernet2/1 2048:ae12::1 name test_name2 22
+ vrf context trial_vrf
+ ip route 192.0.2.64/28 192.0.2.22 tag 4
+ ip route 192.0.2.64/28 192.0.2.23 name merged_route 1
+ """,
+ )
+ set_module_args(dict(config=[dict(vrf="Test")], state="deleted"))
commands = [
- "vrf context test",
- "no ip route 192.0.2.96/28 192.0.2.122 vrf dest_vrf",
- "no ipv6 route 2001:db8:12::/32 2001:db8::1001 name ipv6_route 3",
+ "vrf context Test",
+ "no ip route 192.0.2.48/28 192.0.2.13",
+ "no ip route 192.0.2.48/28 192.0.2.14 5",
]
- self.execute_module(changed=True, commands=commands)
+ result = self.execute_module(changed=True)
+ self.assertEqual(result["commands"], commands)
def test_nxos_static_routes_deletedafi(self):
+ self.execute_show_command.return_value = dedent(
+ """\
+ ip route 192.0.2.17/28 192.0.2.23 name replaced_route1 3
+ ip route 192.0.2.17/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name replaced_route2
+ ip route 192.0.2.79/28 192.0.2.26 tag 12
+ vrf context Test
+ ip route 192.0.2.48/28 192.0.2.13
+ ip route 192.0.2.48/28 192.0.2.14 5
+ vrf context management
+ ip name-server 192.168.255.1
+ ip route 0.0.0.0/0 192.168.255.1
+ vrf context newvrf
+ ip route 10.0.10.0/25 10.0.10.3 name test_name tag 22323 11
+ ip route 10.0.11.0/25 10.0.11.10 tag 22 11
+ ip route 10.0.11.0/25 10.0.11.12 vrf Test tag 22 11
+ ip route 192.0.2.48/28 loopback22 192.0.2.13
+ ipv6 route 2200:10::/36 2048:ae12::1 vrf dest 5
+ ipv6 route 2200:10::/36 mgmt0 2048:ae12::1 tag 22 11
+ ipv6 route 2200:10::/36 port-channel22 2048:ae12::1
+ ipv6 route 2200:10::/36 Ethernet2/1 2048:ae12::1 name test_name2 22
+ vrf context trial_vrf
+ ip route 192.0.2.64/28 192.0.2.22 tag 4
+ ip route 192.0.2.64/28 192.0.2.23 name merged_route 1
+ """,
+ )
set_module_args(
dict(
config=[dict(address_families=[dict(afi="ipv4")])],
@@ -297,62 +711,152 @@ class TestNxosStaticRoutesModule(TestNxosModule):
),
)
commands = [
- "configure terminal",
- "no ip route 192.0.2.16/28 192.0.2.24 name initial_route",
+ "no ip route 192.0.2.17/28 192.0.2.23 name replaced_route1 3",
+ "no ip route 192.0.2.17/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name replaced_route2",
+ "no ip route 192.0.2.79/28 192.0.2.26 tag 12",
]
- self.execute_module(changed=True, commands=commands)
+ result = self.execute_module(changed=True)
+ self.assertEqual(result["commands"], commands)
def test_nxos_static_routes_deleteddest(self):
+ self.execute_show_command.return_value = dedent(
+ """\
+ ip route 192.0.2.17/28 192.0.2.23 name replaced_route1 3
+ ip route 192.0.2.17/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name replaced_route2
+ ip route 192.0.2.79/28 192.0.2.26 tag 12
+ vrf context Test
+ ip route 192.0.2.48/28 192.0.2.13
+ ip route 192.0.2.48/28 192.0.2.14 5
+ vrf context management
+ ip name-server 192.168.255.1
+ ip route 0.0.0.0/0 192.168.255.1
+ vrf context newvrf
+ ip route 10.0.10.0/25 10.0.10.3 name test_name tag 22323 11
+ ip route 10.0.11.0/25 10.0.11.10 tag 22 11
+ ip route 10.0.11.0/25 10.0.11.12 vrf Test tag 22 11
+ ip route 192.0.2.48/28 loopback22 192.0.2.13
+ ipv6 route 2200:10::/36 2048:ae12::1 vrf dest 5
+ ipv6 route 2200:10::/36 mgmt0 2048:ae12::1 tag 22 11
+ ipv6 route 2200:10::/36 port-channel22 2048:ae12::1
+ ipv6 route 2200:10::/36 Ethernet2/1 2048:ae12::1 name test_name2 22
+ vrf context trial_vrf
+ ip route 192.0.2.64/28 192.0.2.22 tag 4
+ ip route 192.0.2.64/28 192.0.2.23 name merged_route 1
+ """,
+ )
set_module_args(
dict(
config=[
dict(
- vrf="test",
- address_families=[dict(afi="ipv4", routes=[dict(dest="192.0.2.96/28")])],
+ vrf="Test",
+ address_families=[dict(afi="ipv4", routes=[dict(dest="192.0.2.48/28")])],
),
],
state="deleted",
),
)
commands = [
- "vrf context test",
- "no ip route 192.0.2.96/28 192.0.2.122 vrf dest_vrf",
+ "vrf context Test",
+ "no ip route 192.0.2.48/28 192.0.2.13",
+ "no ip route 192.0.2.48/28 192.0.2.14 5",
]
- self.execute_module(changed=True, commands=commands)
+ result = self.execute_module(changed=True)
+ self.assertEqual(result["commands"], commands)
def test_nxos_static_routes_deletedroute(self):
+ self.execute_show_command.return_value = dedent(
+ """\
+ ip route 192.0.2.17/28 192.0.2.23 name replaced_route1 3
+ ip route 192.0.2.17/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name replaced_route2
+ ip route 192.0.2.79/28 192.0.2.26 tag 12
+ vrf context Test
+ ip route 192.0.2.48/28 192.0.2.13
+ ip route 192.0.2.48/28 192.0.2.14 5
+ vrf context management
+ ip name-server 192.168.255.1
+ ip route 0.0.0.0/0 192.168.255.1
+ vrf context newvrf
+ ip route 10.0.10.0/25 10.0.10.3 name test_name tag 22323 11
+ ip route 10.0.11.0/25 10.0.11.10 tag 22 11
+ ip route 10.0.11.0/25 10.0.11.12 vrf Test tag 22 11
+ ip route 192.0.2.48/28 loopback22 192.0.2.13
+ ipv6 route 2200:10::/36 2048:ae12::1 vrf dest 5
+ ipv6 route 2200:10::/36 mgmt0 2048:ae12::1 tag 22 11
+ ipv6 route 2200:10::/36 port-channel22 2048:ae12::1
+ ipv6 route 2200:10::/36 Ethernet2/1 2048:ae12::1 name test_name2 22
+ vrf context trial_vrf
+ ip route 192.0.2.64/28 192.0.2.22 tag 4
+ ip route 192.0.2.64/28 192.0.2.23 name merged_route 1
+ """,
+ )
set_module_args(
dict(
config=[
- dict(
- vrf="test",
- address_families=[
- dict(
- afi="ipv6",
- routes=[
- dict(
- dest="2001:db8:12::/32",
- next_hops=[
- dict(
- forward_router_address="2001:db8::1001",
- route_name="ipv6_route",
- admin_distance=3,
- ),
+ {
+ "address_families": [
+ {
+ "afi": "ipv4",
+ "routes": [
+ {
+ "next_hops": [
+ {
+ "forward_router_address": "192.0.2.23",
+ "admin_distance": 3,
+ "route_name": "replaced_route1",
+ },
+ {
+ "interface": "Ethernet1/2",
+ "forward_router_address": "192.0.2.45",
+ "dest_vrf": "destinationVRF",
+ "route_name": "replaced_route2",
+ },
],
- ),
+ "dest": "192.0.2.16/28",
+ },
+ {
+ "next_hops": [
+ {"forward_router_address": "192.0.2.26", "tag": 12},
+ ],
+ "dest": "192.0.2.80/28",
+ },
],
- ),
+ },
],
- ),
+ },
+ {
+ "vrf": "Test",
+ "address_families": [
+ {
+ "afi": "ipv4",
+ "routes": [
+ {
+ "next_hops": [
+ {"forward_router_address": "192.0.2.13"},
+ {
+ "forward_router_address": "192.0.2.14",
+ "admin_distance": 5,
+ },
+ ],
+ "dest": "192.0.2.48/28",
+ },
+ ],
+ },
+ ],
+ },
],
state="deleted",
),
)
commands = [
- "vrf context test",
- "no ipv6 route 2001:db8:12::/32 2001:db8::1001 name ipv6_route 3",
+ "no ip route 192.0.2.17/28 192.0.2.23 name replaced_route1 3",
+ "no ip route 192.0.2.17/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name replaced_route2",
+ "no ip route 192.0.2.79/28 192.0.2.26 tag 12",
+ "vrf context Test",
+ "no ip route 192.0.2.48/28 192.0.2.13",
+ "no ip route 192.0.2.48/28 192.0.2.14 5",
]
- self.execute_module(changed=True, commands=commands)
+ result = self.execute_module(changed=True)
+ self.assertEqual(result["commands"], commands)
def test_nxos_static_routes_rendered(self):
set_module_args(
@@ -369,7 +873,7 @@ class TestNxosStaticRoutesModule(TestNxosModule):
next_hops=[
dict(
forward_router_address="2048:ae12::/64",
- interface="Eth1/4",
+ interface="Ethernet1/4",
admin_distance=5,
),
],
@@ -387,128 +891,386 @@ class TestNxosStaticRoutesModule(TestNxosModule):
"ipv6 route 1200:10::/64 Ethernet1/4 2048:ae12::/64 5",
]
result = self.execute_module(changed=False)
- self.assertEqual(sorted(result["rendered"]), sorted(commands), result["rendered"])
+ self.assertEqual(result["rendered"], commands)
def test_nxos_static_routes_parsed(self):
set_module_args(
dict(
- running_config="""ip route 192.0.2.16/28 192.0.2.24 name initial_route
- vrf context test
- ip route 192.0.2.96/28 192.0.2.122 vrf dest_vrf
- ipv6 route 2001:db8:12::/32 2001:db8::1001 name ipv6_route 3""",
+ running_config=dedent(
+ """\
+ ip route 192.0.2.16/28 192.0.2.23 name replaced_route1 3
+ ip route 192.0.2.16/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name replaced_route2
+ ip route 192.0.2.80/28 192.0.2.26 tag 12
+ vrf context Test
+ ip route 192.0.2.48/28 192.0.2.13
+ ip route 192.0.2.48/28 192.0.2.14 5
+ vrf context management
+ ip name-server 192.168.255.1
+ ip route 0.0.0.0/0 192.168.255.1
+ vrf context newvrf
+ ip route 10.0.10.0/25 10.0.10.3 name test_name tag 22323 11
+ ip route 10.0.11.0/25 10.0.11.10 tag 22 11
+ ip route 10.0.11.0/25 10.0.11.12 vrf Test tag 22 11
+ ip route 192.0.2.48/28 loopback22 192.0.2.13
+ ipv6 route 2200:10::/36 2048:ae12::1 vrf dest 5
+ ipv6 route 2200:10::/36 mgmt0 2048:ae12::1 tag 22 11
+ ipv6 route 2200:10::/36 port-channel22 2048:ae12::1
+ ipv6 route 2200:10::/36 Ethernet2/1 2048:ae12::1 name test_name2 22
+ vrf context trial_vrf
+ ip route 192.0.2.64/28 192.0.2.22 tag 4
+ ip route 192.0.2.64/28 192.0.2.23 name merged_route 1
+ """,
+ ),
state="parsed",
),
)
result = self.execute_module(changed=False)
compare_list = [
{
- "vrf": "test",
"address_families": [
{
+ "afi": "ipv4",
"routes": [
{
- "dest": "192.0.2.96/28",
"next_hops": [
{
- "dest_vrf": "dest_vrf",
- "forward_router_address": "192.0.2.122",
+ "forward_router_address": "192.0.2.23",
+ "admin_distance": 3,
+ "route_name": "replaced_route1",
+ },
+ {
+ "interface": "Ethernet1/2",
+ "forward_router_address": "192.0.2.45",
+ "dest_vrf": "destinationVRF",
+ "route_name": "replaced_route2",
},
],
+ "dest": "192.0.2.16/28",
+ },
+ {
+ "next_hops": [{"forward_router_address": "192.0.2.26", "tag": 12}],
+ "dest": "192.0.2.80/28",
+ },
+ ],
+ },
+ ],
+ },
+ {
+ "vrf": "Test",
+ "address_families": [
+ {
+ "afi": "ipv4",
+ "routes": [
+ {
+ "next_hops": [
+ {"forward_router_address": "192.0.2.13"},
+ {"forward_router_address": "192.0.2.14", "admin_distance": 5},
+ ],
+ "dest": "192.0.2.48/28",
},
],
+ },
+ ],
+ },
+ {
+ "vrf": "management",
+ "address_families": [
+ {
"afi": "ipv4",
+ "routes": [
+ {
+ "next_hops": [{"forward_router_address": "192.168.255.1"}],
+ "dest": "0.0.0.0/0",
+ },
+ ],
},
+ ],
+ },
+ {
+ "vrf": "newvrf",
+ "address_families": [
{
+ "afi": "ipv4",
"routes": [
{
- "dest": "2001:db8:12::/32",
"next_hops": [
{
- "route_name": "ipv6_route",
- "forward_router_address": "2001:db8::1001",
- "admin_distance": 3,
+ "forward_router_address": "10.0.10.3",
+ "admin_distance": 11,
+ "tag": 22323,
+ "route_name": "test_name",
+ },
+ ],
+ "dest": "10.0.10.0/25",
+ },
+ {
+ "next_hops": [
+ {
+ "forward_router_address": "10.0.11.10",
+ "admin_distance": 11,
+ "tag": 22,
+ },
+ {
+ "forward_router_address": "10.0.11.12",
+ "admin_distance": 11,
+ "dest_vrf": "Test",
+ "tag": 22,
+ },
+ ],
+ "dest": "10.0.11.0/25",
+ },
+ {
+ "next_hops": [
+ {
+ "interface": "loopback22",
+ "forward_router_address": "192.0.2.13",
},
],
+ "dest": "192.0.2.48/28",
},
],
+ },
+ {
"afi": "ipv6",
+ "routes": [
+ {
+ "next_hops": [
+ {
+ "forward_router_address": "2048:ae12::1",
+ "admin_distance": 5,
+ "dest_vrf": "dest",
+ },
+ {
+ "interface": "mgmt0",
+ "forward_router_address": "2048:ae12::1",
+ "admin_distance": 11,
+ "tag": 22,
+ },
+ {
+ "interface": "port-channel22",
+ "forward_router_address": "2048:ae12::1",
+ },
+ {
+ "interface": "Ethernet2/1",
+ "forward_router_address": "2048:ae12::1",
+ "admin_distance": 22,
+ "route_name": "test_name2",
+ },
+ ],
+ "dest": "2200:10::/36",
+ },
+ ],
},
],
},
{
+ "vrf": "trial_vrf",
"address_families": [
{
+ "afi": "ipv4",
"routes": [
{
- "dest": "192.0.2.16/28",
"next_hops": [
+ {"forward_router_address": "192.0.2.22", "tag": 4},
{
- "route_name": "initial_route",
- "forward_router_address": "192.0.2.24",
+ "forward_router_address": "192.0.2.23",
+ "admin_distance": 1,
+ "route_name": "merged_route",
},
],
+ "dest": "192.0.2.64/28",
},
],
- "afi": "ipv4",
},
],
},
]
- self.assertEqual(result["parsed"], compare_list, result["parsed"])
+ self.assertEqual(result["parsed"], compare_list)
def test_nxos_static_routes_gathered(self):
+ self.execute_show_command.return_value = dedent(
+ """\
+ ip route 192.0.2.17/28 192.0.2.23 name replaced_route1 3
+ ip route 192.0.2.17/28 Ethernet1/2 192.0.2.45 vrf destinationVRF name replaced_route2
+ ip route 192.0.2.79/28 192.0.2.26 tag 12
+ vrf context Test
+ ip route 192.0.2.48/28 192.0.2.13
+ ip route 192.0.2.48/28 192.0.2.14 5
+ vrf context management
+ ip name-server 192.168.255.1
+ ip route 0.0.0.0/0 192.168.255.1
+ vrf context newvrf
+ ip route 10.0.10.0/25 10.0.10.3 name test_name tag 22323 11
+ ip route 10.0.11.0/25 10.0.11.10 tag 22 11
+ ip route 10.0.11.0/25 10.0.11.12 vrf Test tag 22 11
+ ip route 192.0.2.48/28 loopback22 192.0.2.13
+ ipv6 route 2200:10::/36 2048:ae12::1 vrf dest 5
+ ipv6 route 2200:10::/36 mgmt0 2048:ae12::1 tag 22 11
+ ipv6 route 2200:10::/36 port-channel22 2048:ae12::1
+ ipv6 route 2200:10::/36 Ethernet2/1 2048:ae12::1 name test_name2 22
+ vrf context trial_vrf
+ ip route 192.0.2.64/28 192.0.2.22 tag 4
+ ip route 192.0.2.64/28 192.0.2.23 name merged_route 1
+ """,
+ )
set_module_args(dict(config=[], state="gathered"))
result = self.execute_module(changed=False)
compare_list = [
{
- "vrf": "test",
"address_families": [
{
+ "afi": "ipv4",
"routes": [
{
- "dest": "192.0.2.96/28",
"next_hops": [
{
- "dest_vrf": "dest_vrf",
- "forward_router_address": "192.0.2.122",
+ "forward_router_address": "192.0.2.23",
+ "admin_distance": 3,
+ "route_name": "replaced_route1",
},
+ {
+ "interface": "Ethernet1/2",
+ "forward_router_address": "192.0.2.45",
+ "dest_vrf": "destinationVRF",
+ "route_name": "replaced_route2",
+ },
+ ],
+ "dest": "192.0.2.17/28",
+ },
+ {
+ "next_hops": [{"forward_router_address": "192.0.2.26", "tag": 12}],
+ "dest": "192.0.2.79/28",
+ },
+ ],
+ },
+ ],
+ },
+ {
+ "vrf": "Test",
+ "address_families": [
+ {
+ "afi": "ipv4",
+ "routes": [
+ {
+ "next_hops": [
+ {"forward_router_address": "192.0.2.13"},
+ {"forward_router_address": "192.0.2.14", "admin_distance": 5},
],
+ "dest": "192.0.2.48/28",
},
],
+ },
+ ],
+ },
+ {
+ "vrf": "management",
+ "address_families": [
+ {
"afi": "ipv4",
+ "routes": [
+ {
+ "next_hops": [{"forward_router_address": "192.168.255.1"}],
+ "dest": "0.0.0.0/0",
+ },
+ ],
},
+ ],
+ },
+ {
+ "vrf": "newvrf",
+ "address_families": [
{
+ "afi": "ipv4",
"routes": [
{
- "dest": "2001:db8:12::/32",
"next_hops": [
{
- "route_name": "ipv6_route",
- "forward_router_address": "2001:db8::1001",
- "admin_distance": 3,
+ "forward_router_address": "10.0.10.3",
+ "admin_distance": 11,
+ "tag": 22323,
+ "route_name": "test_name",
+ },
+ ],
+ "dest": "10.0.10.0/25",
+ },
+ {
+ "next_hops": [
+ {
+ "forward_router_address": "10.0.11.10",
+ "admin_distance": 11,
+ "tag": 22,
+ },
+ {
+ "forward_router_address": "10.0.11.12",
+ "admin_distance": 11,
+ "dest_vrf": "Test",
+ "tag": 22,
+ },
+ ],
+ "dest": "10.0.11.0/25",
+ },
+ {
+ "next_hops": [
+ {
+ "interface": "loopback22",
+ "forward_router_address": "192.0.2.13",
},
],
+ "dest": "192.0.2.48/28",
},
],
+ },
+ {
"afi": "ipv6",
+ "routes": [
+ {
+ "next_hops": [
+ {
+ "forward_router_address": "2048:ae12::1",
+ "admin_distance": 5,
+ "dest_vrf": "dest",
+ },
+ {
+ "interface": "mgmt0",
+ "forward_router_address": "2048:ae12::1",
+ "admin_distance": 11,
+ "tag": 22,
+ },
+ {
+ "interface": "port-channel22",
+ "forward_router_address": "2048:ae12::1",
+ },
+ {
+ "interface": "Ethernet2/1",
+ "forward_router_address": "2048:ae12::1",
+ "admin_distance": 22,
+ "route_name": "test_name2",
+ },
+ ],
+ "dest": "2200:10::/36",
+ },
+ ],
},
],
},
{
+ "vrf": "trial_vrf",
"address_families": [
{
+ "afi": "ipv4",
"routes": [
{
- "dest": "192.0.2.16/28",
"next_hops": [
+ {"forward_router_address": "192.0.2.22", "tag": 4},
{
- "route_name": "initial_route",
- "forward_router_address": "192.0.2.24",
+ "forward_router_address": "192.0.2.23",
+ "admin_distance": 1,
+ "route_name": "merged_route",
},
],
+ "dest": "192.0.2.64/28",
},
],
- "afi": "ipv4",
},
],
},
diff --git a/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/storage/test_nxos_vsan.py b/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_vsan.py
index db79f8668..af9ee7ad3 100644
--- a/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/storage/test_nxos_vsan.py
+++ b/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_vsan.py
@@ -9,11 +9,11 @@ __metaclass__ = type
import pytest
-from ansible_collections.cisco.nxos.plugins.modules.storage import nxos_vsan
+from ansible_collections.cisco.nxos.plugins.modules import nxos_vsan
from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch
from ansible_collections.cisco.nxos.tests.unit.modules.utils import AnsibleFailJson
-from ..nxos_module import TestNxosModule, load_fixture, set_module_args
+from .nxos_module import TestNxosModule, load_fixture, set_module_args
class TestNxosVsanModule(TestNxosModule):
@@ -21,7 +21,7 @@ class TestNxosVsanModule(TestNxosModule):
def setUp(self):
super(TestNxosVsanModule, self).setUp()
- module_path = "ansible_collections.cisco.nxos.plugins.modules.storage.nxos_vsan."
+ module_path = "ansible_collections.cisco.nxos.plugins.modules.nxos_vsan."
self.mock_run_commands = patch(module_path + "run_commands")
self.run_commands = self.mock_run_commands.start()
diff --git a/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/storage/test_nxos_zone_zoneset.py b/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_zone_zoneset.py
index b49dbf2fd..6afe78a5b 100644
--- a/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/storage/test_nxos_zone_zoneset.py
+++ b/ansible_collections/cisco/nxos/tests/unit/modules/network/nxos/test_nxos_zone_zoneset.py
@@ -8,10 +8,10 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-from ansible_collections.cisco.nxos.plugins.modules.storage import nxos_zone_zoneset
+from ansible_collections.cisco.nxos.plugins.modules import nxos_zone_zoneset
from ansible_collections.cisco.nxos.tests.unit.compat.mock import patch
-from ..nxos_module import TestNxosModule, load_fixture, set_module_args
+from .nxos_module import TestNxosModule, load_fixture, set_module_args
class TestNxosZoneZonesetModule(TestNxosModule):
@@ -19,7 +19,7 @@ class TestNxosZoneZonesetModule(TestNxosModule):
def setUp(self):
super(TestNxosZoneZonesetModule, self).setUp()
- module_path = "ansible_collections.cisco.nxos.plugins.modules.storage.nxos_zone_zoneset."
+ module_path = "ansible_collections.cisco.nxos.plugins.modules.nxos_zone_zoneset."
self.mock_run_commands = patch(module_path + "run_commands")
self.run_commands = self.mock_run_commands.start()
@@ -34,7 +34,9 @@ class TestNxosZoneZonesetModule(TestNxosModule):
)
self.execute_show_cmd_zoneset = self.mock_execute_show_cmd_zoneset.start()
- self.mock_execute_show_cmd_zone = patch(module_path + "ShowZone.execute_show_zone_vsan_cmd")
+ self.mock_execute_show_cmd_zone = patch(
+ module_path + "ShowZone.execute_show_zone_vsan_cmd",
+ )
self.execute_show_cmd_zone = self.mock_execute_show_cmd_zone.start()
self.mock_execute_show_cmd_zone_status = patch(
@@ -213,13 +215,20 @@ class TestNxosZoneZonesetModule(TestNxosModule):
# Test zone add/removal
def test_zone_add_rem(self):
- a = dict(zone_zoneset_details=[dict(vsan=923, zone=[dict(name="zoneB", remove=True)])])
+ a = dict(
+ zone_zoneset_details=[
+ dict(vsan=923, zone=[dict(name="zoneB", remove=True)]),
+ ],
+ )
set_module_args(a, True)
self.execute_show_cmd_zone_status.return_value = load_fixture(
"nxos_zone_zoneset",
"shzonestatus_1.cfg",
)
- self.execute_show_cmd_zone.return_value = load_fixture("nxos_zone_zoneset", "shzone_0.cfg")
+ self.execute_show_cmd_zone.return_value = load_fixture(
+ "nxos_zone_zoneset",
+ "shzone_0.cfg",
+ )
result = self.execute_module(changed=True)
self.assertEqual(
result["commands"],
@@ -232,13 +241,20 @@ class TestNxosZoneZonesetModule(TestNxosModule):
)
def test_zone_add_rem_1(self):
- a = dict(zone_zoneset_details=[dict(vsan=923, zone=[dict(name="zoneC", remove=True)])])
+ a = dict(
+ zone_zoneset_details=[
+ dict(vsan=923, zone=[dict(name="zoneC", remove=True)]),
+ ],
+ )
set_module_args(a, True)
self.execute_show_cmd_zone_status.return_value = load_fixture(
"nxos_zone_zoneset",
"shzonestatus_1.cfg",
)
- self.execute_show_cmd_zone.return_value = load_fixture("nxos_zone_zoneset", "shzone_0.cfg")
+ self.execute_show_cmd_zone.return_value = load_fixture(
+ "nxos_zone_zoneset",
+ "shzone_0.cfg",
+ )
result = self.execute_module(changed=False, failed=False)
m = "zone 'zoneC' is not present in vsan 923"
assert m in str(result["messages"])
@@ -251,7 +267,10 @@ class TestNxosZoneZonesetModule(TestNxosModule):
"nxos_zone_zoneset",
"shzonestatus_1.cfg",
)
- self.execute_show_cmd_zone.return_value = load_fixture("nxos_zone_zoneset", "shzone_0.cfg")
+ self.execute_show_cmd_zone.return_value = load_fixture(
+ "nxos_zone_zoneset",
+ "shzone_0.cfg",
+ )
result = self.execute_module(changed=True)
self.assertEqual(
result["commands"],
@@ -270,7 +289,10 @@ class TestNxosZoneZonesetModule(TestNxosModule):
"nxos_zone_zoneset",
"shzonestatus_1.cfg",
)
- self.execute_show_cmd_zone.return_value = load_fixture("nxos_zone_zoneset", "shzone_0.cfg")
+ self.execute_show_cmd_zone.return_value = load_fixture(
+ "nxos_zone_zoneset",
+ "shzone_0.cfg",
+ )
result = self.execute_module(changed=False, failed=False)
m = "zone 'zoneB' is already present in vsan 923"
assert m in str(result["messages"])
@@ -293,7 +315,10 @@ class TestNxosZoneZonesetModule(TestNxosModule):
"nxos_zone_zoneset",
"shzonestatus_1.cfg",
)
- self.execute_show_cmd_zone.return_value = load_fixture("nxos_zone_zoneset", "shzone_0.cfg")
+ self.execute_show_cmd_zone.return_value = load_fixture(
+ "nxos_zone_zoneset",
+ "shzone_0.cfg",
+ )
result = self.execute_module(changed=True)
self.assertEqual(
result["commands"],
@@ -312,14 +337,19 @@ class TestNxosZoneZonesetModule(TestNxosModule):
mem1 = {"pwwn": "11:11:11:11:11:11:11:11", "remove": True}
mem2 = {"device_alias": "test123", "remove": True}
a = dict(
- zone_zoneset_details=[dict(vsan=923, zone=[dict(name="zoneA", members=[mem1, mem2])])],
+ zone_zoneset_details=[
+ dict(vsan=923, zone=[dict(name="zoneA", members=[mem1, mem2])]),
+ ],
)
set_module_args(a, True)
self.execute_show_cmd_zone_status.return_value = load_fixture(
"nxos_zone_zoneset",
"shzonestatus_1.cfg",
)
- self.execute_show_cmd_zone.return_value = load_fixture("nxos_zone_zoneset", "shzone_0.cfg")
+ self.execute_show_cmd_zone.return_value = load_fixture(
+ "nxos_zone_zoneset",
+ "shzone_0.cfg",
+ )
result = self.execute_module(changed=True)
self.assertEqual(
result["commands"],
@@ -338,14 +368,19 @@ class TestNxosZoneZonesetModule(TestNxosModule):
mem1 = {"pwwn": "11:11:11:11:11:11:11:11", "remove": True}
mem2 = {"device_alias": "test123", "remove": True}
a = dict(
- zone_zoneset_details=[dict(vsan=923, zone=[dict(name="zoneA1", members=[mem1, mem2])])],
+ zone_zoneset_details=[
+ dict(vsan=923, zone=[dict(name="zoneA1", members=[mem1, mem2])]),
+ ],
)
set_module_args(a, True)
self.execute_show_cmd_zone_status.return_value = load_fixture(
"nxos_zone_zoneset",
"shzonestatus_1.cfg",
)
- self.execute_show_cmd_zone.return_value = load_fixture("nxos_zone_zoneset", "shzone_0.cfg")
+ self.execute_show_cmd_zone.return_value = load_fixture(
+ "nxos_zone_zoneset",
+ "shzone_0.cfg",
+ )
result = self.execute_module(changed=False, failed=False)
m = "zone 'zoneA1' is not present in vsan 923 , hence cannot remove the members"
assert m in str(result["messages"])
@@ -369,7 +404,10 @@ class TestNxosZoneZonesetModule(TestNxosModule):
"nxos_zone_zoneset",
"shzonestatus_0.cfg",
)
- self.execute_show_cmd_zone.return_value = load_fixture("nxos_zone_zoneset", "shzone_1.cfg")
+ self.execute_show_cmd_zone.return_value = load_fixture(
+ "nxos_zone_zoneset",
+ "shzone_1.cfg",
+ )
result = self.execute_module(changed=True)
self.assertEqual(
result["commands"],
@@ -387,13 +425,20 @@ class TestNxosZoneZonesetModule(TestNxosModule):
def test_zonemem_add_rem_4(self):
mem2 = {"device_alias": "test123", "devtype": "both", "remove": True}
- a = dict(zone_zoneset_details=[dict(vsan=922, zone=[dict(name="zoneA", members=[mem2])])])
+ a = dict(
+ zone_zoneset_details=[
+ dict(vsan=922, zone=[dict(name="zoneA", members=[mem2])]),
+ ],
+ )
set_module_args(a, True)
self.execute_show_cmd_zone_status.return_value = load_fixture(
"nxos_zone_zoneset",
"shzonestatus_0.cfg",
)
- self.execute_show_cmd_zone.return_value = load_fixture("nxos_zone_zoneset", "shzone_1.cfg")
+ self.execute_show_cmd_zone.return_value = load_fixture(
+ "nxos_zone_zoneset",
+ "shzone_1.cfg",
+ )
result = self.execute_module(changed=True)
self.assertEqual(
result["commands"],
@@ -408,7 +453,9 @@ class TestNxosZoneZonesetModule(TestNxosModule):
# Test zoneset add/removal
def test_zoneset_add_rem(self):
a = dict(
- zone_zoneset_details=[dict(vsan=922, zoneset=[dict(name="zsetname21", remove=True)])],
+ zone_zoneset_details=[
+ dict(vsan=922, zoneset=[dict(name="zsetname21", remove=True)]),
+ ],
)
set_module_args(a, True)
self.execute_show_cmd_zone_status.return_value = load_fixture(
@@ -430,7 +477,9 @@ class TestNxosZoneZonesetModule(TestNxosModule):
)
def test_zoneset_add_rem_1(self):
- a = dict(zone_zoneset_details=[dict(vsan=922, zoneset=[dict(name="zsetname21New")])])
+ a = dict(
+ zone_zoneset_details=[dict(vsan=922, zoneset=[dict(name="zsetname21New")])],
+ )
set_module_args(a, True)
self.execute_show_cmd_zone_status.return_value = load_fixture(
"nxos_zone_zoneset",
@@ -451,7 +500,9 @@ class TestNxosZoneZonesetModule(TestNxosModule):
)
def test_zoneset_add_rem_2(self):
- a = dict(zone_zoneset_details=[dict(vsan=922, zoneset=[dict(name="zsetname21")])])
+ a = dict(
+ zone_zoneset_details=[dict(vsan=922, zoneset=[dict(name="zsetname21")])],
+ )
set_module_args(a, True)
self.execute_show_cmd_zone_status.return_value = load_fixture(
"nxos_zone_zoneset",
@@ -570,7 +621,9 @@ class TestNxosZoneZonesetModule(TestNxosModule):
# Test zoneset activate/deactivate
def test_zoneset_activate_deactivate(self):
a = dict(
- zone_zoneset_details=[dict(vsan=221, zoneset=[dict(name="zsv221", action="activate")])],
+ zone_zoneset_details=[
+ dict(vsan=221, zoneset=[dict(name="zsv221", action="activate")]),
+ ],
)
set_module_args(a, True)
self.execute_show_cmd_zone_status.return_value = load_fixture(
@@ -659,14 +712,19 @@ class TestNxosZoneZonesetModule(TestNxosModule):
mem1 = {"pwwn": "21:01:00:1b:32:a1:c0:a8", "remove": True}
mem2 = {"pwwn": "50:06:01:6a:47:e4:6e:59", "remove": True}
a = dict(
- zone_zoneset_details=[dict(vsan=221, zone=[dict(name="zv221", members=[mem1, mem2])])],
+ zone_zoneset_details=[
+ dict(vsan=221, zone=[dict(name="zv221", members=[mem1, mem2])]),
+ ],
)
set_module_args(a, True)
self.execute_show_cmd_zone_status.return_value = load_fixture(
"nxos_zone_zoneset",
"shzonestatus_4.cfg",
)
- self.execute_show_cmd_zone.return_value = load_fixture("nxos_zone_zoneset", "shzone_2.cfg")
+ self.execute_show_cmd_zone.return_value = load_fixture(
+ "nxos_zone_zoneset",
+ "shzone_2.cfg",
+ )
self.execute_show_cmd_zoneset_active.return_value = load_fixture(
"nxos_zone_zoneset",
"shzonesetactive_0.cfg",