Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
2bed003
fix no cdp
nickbhasin Sep 19, 2025
bf4887d
chore: auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 19, 2025
c674b0d
fix changelog
nickbhasin Sep 19, 2025
dcecdd0
fix changelog
nickbhasin Sep 19, 2025
f403e90
chore: auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 19, 2025
e2fee37
fix changelog
nickbhasin Sep 22, 2025
d67768e
fix changelog
nickbhasin Sep 24, 2025
78e5684
fix integration tc
nickbhasin Sep 30, 2025
b85dbf5
chore: auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 30, 2025
bb11a5d
tc fiix
nickbhasin Sep 30, 2025
5590879
remove fix
nickbhasin Oct 1, 2025
a571bea
chore: auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 1, 2025
a5ada0c
increased timeout
nickbhasin Oct 1, 2025
32fa577
fix integration tc
nickbhasin Oct 1, 2025
cc1862e
integration tcs
nickbhasin Oct 1, 2025
989a4fe
fix tc
nickbhasin Oct 1, 2025
3e46b6e
fix tc
nickbhasin Oct 1, 2025
0bcdae0
fix tc
nickbhasin Oct 1, 2025
afb29de
fix tc
nickbhasin Oct 1, 2025
4bd0218
fix tc
nickbhasin Oct 1, 2025
315074e
temp change
nickbhasin Oct 1, 2025
c1a841a
temp deletion
nickbhasin Oct 1, 2025
39311c7
fix tc
nickbhasin Oct 1, 2025
46bcabd
fix tc
nickbhasin Oct 2, 2025
be6adee
fix tc
nickbhasin Oct 3, 2025
2409829
temp removal of tc
nickbhasin Oct 3, 2025
a9b8dc4
re add deleted files
nickbhasin Oct 3, 2025
2705b1a
revert name change
nickbhasin Oct 3, 2025
99e9a00
remove unnecesarry changes
nickbhasin Oct 13, 2025
d529018
rebase main
nickbhasin Oct 30, 2025
d4f396f
added assertions
nickbhasin Oct 30, 2025
5ca3389
Merge branch 'main' into cdp_changes
nickbhasin Oct 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/fragments/cdp_fix.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bugfixes:
- cisco.nxos.nxos_l2_interfaces - Fix cdp_enable config parsing.
- cisco.nxos.nxos_l3_interfaces - Improved the code logic for handling redirects.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def __init__(self, module):
"beacon",
"link_flap.error_disable",
"cdp_enable",
"no_cdp_enable",
]

def execute_module(self):
Expand Down Expand Up @@ -107,6 +108,12 @@ def _compare(self, want, have):
for the L2_interfaces network resource.
"""
begin = len(self.commands)
want_without_name = want.copy()
want_without_name.pop("name", None)
pre_pop_want = bool(want_without_name)
want_cdp = want.pop("cdp_enable", None)
have_cdp = have.pop("cdp_enable", None)
self.handle_cdp(want_cdp, have_cdp, "cdp_enable", pre_pop_want)
self.compare(parsers=self.parsers, want=want, have=have)
self._compare_lists(want, have)
if len(self.commands) != begin:
Expand Down Expand Up @@ -175,3 +182,16 @@ def process_list_attrs(self, param):
vlanList = val.get("trunk").get(vlan, [])
if vlanList and vlanList != "none":
val["trunk"][vlan] = vlan_range_to_list(val.get("trunk").get(vlan))

def handle_cdp(self, want_cdp, have_cdp, parser, want):
if want_cdp is None and have_cdp is None:
if self.state == "replaced" or (self.state == "overridden" and want):
self.addcmd({parser: True}, parser, True)
else:
if want_cdp is True and have_cdp is False:
self.addcmd({parser: want_cdp}, parser, not want_cdp)
elif want_cdp is False and have_cdp is None:
self.addcmd({parser: not want_cdp}, parser, not want_cdp)
elif want_cdp is None and have_cdp is False:
if self.state in ["overridden", "deleted"] and not want:
self.addcmd({parser: not have_cdp}, parser, have_cdp)
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,12 @@ def compare_lists(self, wanted, haved, parser):
def handle_redirects(self, want_redirects, have_redirects, parser, want):
if want_redirects is None and have_redirects is None:
if self.state == "replaced" or (self.state == "overridden" and want):
self.addcmd({"redirects": True}, parser, True)
self.addcmd({parser: True}, parser, True)
else:
if want_redirects is True and have_redirects is False:
self.addcmd({"redirects": want_redirects}, parser, not want_redirects)
self.addcmd({parser: want_redirects}, parser, not want_redirects)
elif want_redirects is False and have_redirects is None:
self.addcmd({"redirects": not want_redirects}, parser, not want_redirects)
self.addcmd({parser: not want_redirects}, parser, not want_redirects)
elif want_redirects is None and have_redirects is False:
if self.state in ["overridden", "deleted"] and not want:
self.addcmd({"redirects": not have_redirects}, parser, have_redirects)
self.addcmd({parser: not have_redirects}, parser, have_redirects)
18 changes: 16 additions & 2 deletions plugins/module_utils/network/nxos/rm_templates/l2_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,27 @@ def __init__(self, lines=None, module=None):
"name": "cdp_enable",
"getval": re.compile(
r"""
\s+cdp\s+(?P<cdp_enable>enable)
\s+cdp\senable
$""", re.VERBOSE,
),
"setval": "cdp enable",
"result": {
'{{ name }}': {
'cdp_enable': "{{ True if cdp_enable }}",
'cdp_enable': True,
},
},
},
{
"name": "no_cdp_enable",
"getval": re.compile(
r"""
\s+no\scdp\senable
$""", re.VERBOSE,
),
"setval": "no cdp enable",
"result": {
'{{ name }}': {
'cdp_enable': False,
},
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
---
- name: Cleanup
ignore_errors: true
when: ansible_connection == 'ansible.netcommon.network_cli'
cisco.nxos.nxos_config:
lines:
- "default interface {{ nxos_int1 }}"
- "default interface {{ nxos_int2 }}"
vars:
ansible_connection: ansible.netcommon.network_cli

- name: Cleanup for httpapi
when: ansible_connection == 'ansible.netcommon.httpapi'
ignore_errors: true
cisco.nxos.nxos_config:
lines:
- "{{ item }}"
loop:
- "default interface {{ nxos_int1 }}"
- "default interface {{ nxos_int2 }}"
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- ansible.builtin.debug:
msg: START nxos_lacp empty_config integration tests on connection={{ ansible_connection }}
msg: START nxos_l2_interfaces empty_config integration tests on connection={{ ansible_connection }}

- name: Merged with empty configuration should give appropriate error message
register: result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@
- result.changed == true
- "'interface {{ test_int1 }}' in result.commands"
- "'no switchport trunk allowed vlan' in result.commands"
- "'no cdp enable' in result.commands"
- "'interface {{ test_int2 }}' in result.commands"
- "'switchport access vlan 6' in result.commands"
- "'switchport trunk allowed vlan 10-12' in result.commands"
- "'no cdp enable' in result.commands"

- name: Gather l2_interfaces post facts
cisco.nxos.nxos_facts: *id001
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,14 @@
- "'interface {{ test_int1 }}' in result.commands"
- "'switchport access vlan 8' in result.commands"
- "'switchport trunk allowed vlan 10-12' in result.commands"
- "'no cdp enable' in result.commands"
- "'interface {{ test_int2 }}' in result.commands"
- "'no switchport trunk native vlan 15' in result.commands"
- "'no cdp enable' in result.commands"
- "'interface {{ test_int3 }}' in result.commands"
- "'switchport trunk allowed vlan none' in result.commands"
- result.commands|length == 7
- "'no cdp enable' in result.commands"
- result.commands|length == 10

- name: Gather l2_interfaces post facts
cisco.nxos.nxos_facts: *id001
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
trunk:
native_vlan: 10
allowed_vlans: 2,4,15
cdp_enable: false
- name: "{{ nxos_int2 }}"
access:
vlan: 30
cdp_enable: false
state: merged
tags: base_config

Expand All @@ -45,13 +47,16 @@
- name: "{{ nxos_int1 }}"
trunk:
native_vlan: 20
cdp_enable: true
- name: "{{ nxos_int2 }}"
access:
vlan: 31
cdp_enable: true
- name: "{{ nxos_int3 }}"
trunk:
native_vlan: 20
allowed_vlans: 5-10, 15
cdp_enable: true
state: overridden

- ansible.builtin.assert:
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/modules/network/nxos/test_nxos_l2_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ def test_l2_interfaces_merged(self):
default interface Ethernet1/6
interface Ethernet1/6
switchport
no cdp enable
""",
)

Expand All @@ -196,13 +197,15 @@ def test_l2_interfaces_merged(self):
"trunk": {
"allowed_vlans": "10-12",
},
"cdp_enable": True,
},
],
),
)

expected_commands = [
"interface Ethernet1/6",
"cdp enable",
"switchport mode trunk",
"switchport trunk allowed vlan 10-12",
]
Expand Down Expand Up @@ -252,6 +255,7 @@ def test_l2_interfaces_replaced(self):
"trunk": {
"allowed_vlans": "none",
},
"cdp_enable": True,
},
],
state="replaced",
Expand All @@ -260,9 +264,11 @@ def test_l2_interfaces_replaced(self):

expected_commands = [
"interface Ethernet1/6",
"no cdp enable",
"switchport access vlan 8",
"switchport trunk allowed vlan 10-12",
"interface Ethernet1/7",
"no cdp enable",
"no switchport trunk native vlan 15",
"interface Ethernet1/8",
"switchport trunk allowed vlan none",
Expand Down Expand Up @@ -305,6 +311,7 @@ def test_l2_interfaces_overridden(self):
"interface Ethernet1/6",
"no switchport trunk allowed vlan",
"interface Ethernet1/7",
"no cdp enable",
"switchport access vlan 6",
"switchport trunk allowed vlan 10-12",
]
Expand Down
Loading