Skip to content

Commit

Permalink
fix ntctemplate reverse mapping for cisco xe
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffkala committed Sep 5, 2024
1 parent ceb1693 commit 61873fa
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/user/lib_mapper/ntctemplates.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
| cisco_s300 || cisco_s300 |
| cisco_tp || cisco_tp |
| cisco_wlc || cisco_wlc |
| cisco_xe || cisco_ios |
| cisco_xe || cisco_xe |
| cisco_xr || cisco_xr |
| cloudgenix_ion || cloudgenix_ion |
| coriant || coriant |
Expand Down
1 change: 1 addition & 0 deletions docs/user/lib_mapper/ntctemplates_reverse.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
| cisco_s300 || cisco_s300 |
| cisco_tp || cisco_tp |
| cisco_wlc || cisco_wlc |
| cisco_xe || cisco_ios |
| cisco_xr || cisco_xr |
| cloudgenix_ion || cloudgenix_ion |
| coriant || coriant |
Expand Down
10 changes: 5 additions & 5 deletions netutils/lib_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@
# ntc templates is primarily based on netmiko, so a copy is in order
_NTCTEMPLATES_LIB_MAPPER = copy.deepcopy(NETMIKO_LIB_MAPPER)
_NTCTEMPLATES_LIB_MAPPER["aruba_aoscx"] = "aruba_aoscx"
_NTCTEMPLATES_LIB_MAPPER["cisco_xe"] = "cisco_ios" # no reverse
_NTCTEMPLATES_LIB_MAPPER["huawei_vrp"] = "huawei_vrp"
_NTCTEMPLATES_LIB_MAPPER["vmware_nsxv"] = "vmware_nsxv"
_NTCTEMPLATES_LIB_MAPPER["watchguard_firebox"] = "watchguard_firebox"
Expand All @@ -270,12 +269,13 @@
key: _NTCTEMPLATES_LIB_MAPPER[key] for key in sorted(_NTCTEMPLATES_LIB_MAPPER)
}
# Normalized | NTCTemplates
NTCTEMPLATES_LIB_MAPPER_REVERSE: t.Dict[str, str] = {
value: key
for key, value in NTCTEMPLATES_LIB_MAPPER.items()
if key not in ["f5_ltm", "f5_tmsh", "f5_linux", "cisco_xe"]
_NTCTEMPLATES_LIB_MAPPER_REVERSE: t.Dict[str, str] = {
value: key for key, value in NTCTEMPLATES_LIB_MAPPER.items() if key not in ["f5_ltm", "f5_tmsh", "f5_linux"]
}

_NTCTEMPLATES_LIB_MAPPER_REVERSE["cisco_xe"] = "cisco_ios" # only reverse

NTCTEMPLATES_LIB_MAPPER_REVERSE = copy.deepcopy(_NTCTEMPLATES_LIB_MAPPER_REVERSE)

# NAPALM | Normalized
NAPALM_LIB_MAPPER: t.Dict[str, str] = {
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/test_lib_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def test_lib_mapper_reverse(lib):
"FORWARDNETWORKS",
"HIERCONFIG",
"NETUTILSPARSER",
"NTCTEMPLATES",
"NAPALM",
"PYATS",
"PYNTC",
Expand All @@ -87,6 +88,14 @@ def test_lib_mapper_reverse(lib):
assert mapper == rev_mapper


def test_lib_mapper_ntctemplates_reverse_only():
"""Cisco XE is the only one that has a reverse ONLY mapping."""
assert lib_mapper.NTCTEMPLATES_LIB_MAPPER_REVERSE["cisco_xe"] == "cisco_ios"
assert lib_mapper.NTCTEMPLATES_LIB_MAPPER_REVERSE["cisco_ios"] == "cisco_ios"
assert lib_mapper.NTCTEMPLATES_LIB_MAPPER["cisco_ios"] == "cisco_ios"
assert lib_mapper.NTCTEMPLATES_LIB_MAPPER["cisco_xe"] == "cisco_xe"


@pytest.mark.parametrize("lib", LIBRARIES)
def test_lib_mapper_alpha(lib):
original = list(getattr(lib_mapper, f"{lib}_LIB_MAPPER").keys())
Expand Down

0 comments on commit 61873fa

Please sign in to comment.