From 55572744dace2d2084764b8ad7fa32507f3d3b1d Mon Sep 17 00:00:00 2001 From: Brandon Minnix Date: Mon, 29 Apr 2024 12:02:33 -0400 Subject: [PATCH] Finishing changes and passing tests. --- docs/user/include_jinja_list.md | 3 ++- netutils/os_version.py | 2 +- netutils/utils.py | 3 ++- tests/unit/test_nist.py | 44 +++++++++++++++++++++++++++++++-- 4 files changed, 47 insertions(+), 5 deletions(-) diff --git a/docs/user/include_jinja_list.md b/docs/user/include_jinja_list.md index 876e0b55..08c25a07 100644 --- a/docs/user/include_jinja_list.md +++ b/docs/user/include_jinja_list.md @@ -60,8 +60,10 @@ | mac_to_format | netutils.mac.mac_to_format | | mac_to_int | netutils.mac.mac_to_int | | mac_type | netutils.mac.mac_type | +| os_platform_object_builder | netutils.nist.os_platform_object_builder | | compare_version_loose | netutils.os_version.compare_version_loose | | compare_version_strict | netutils.os_version.compare_version_strict | +| default_metadata | netutils.os_version.default_metadata | | get_upgrade_path | netutils.os_version.get_upgrade_path | | juniper_junos_metadata | netutils.os_version.juniper_junos_metadata | | version_metadata | netutils.os_version.version_metadata | @@ -81,7 +83,6 @@ | encrypt_type7 | netutils.password.encrypt_type7 | | get_hash_salt | netutils.password.get_hash_salt | | tcp_ping | netutils.ping.tcp_ping | -| os_platform_object_builder | netutils.platform_mapper.os_platform_object_builder | | regex_findall | netutils.regex.regex_findall | | regex_match | netutils.regex.regex_match | | regex_search | netutils.regex.regex_search | diff --git a/netutils/os_version.py b/netutils/os_version.py index 6ad4c02f..ae7277d5 100644 --- a/netutils/os_version.py +++ b/netutils/os_version.py @@ -142,7 +142,7 @@ def juniper_junos_metadata(version: str) -> t.Dict[str, t.Any]: Examples: >>> juniper_junos_metadata("12.3R4") - {'isservice': False, 'ismaintenance': True, 'isfrs': False, 'isspecial': False, 'service': None, 'service_build': None, 'service_respin': None, 'main': '12', 'minor': '3', 'type': 'R', 'build': '4'} + {'isservice': False, 'ismaintenance': True, 'isfrs': False, 'isspecial': False, 'service': None, 'service_build': None, 'service_respin': None, 'main': '12', 'minor': '3', 'type': 'R', 'build': '4', 'major': '12', 'patch': '4'} """ # Use regex to group the main, minor, type and build into useable pieces # re_main_minor_type_build = re.search(r"^(\d+)\.(\d+)([xXrRsS])?(\d+)?", split_version[0]) diff --git a/netutils/utils.py b/netutils/utils.py index c91c7c0a..5fb22150 100644 --- a/netutils/utils.py +++ b/netutils/utils.py @@ -93,9 +93,10 @@ "get_upgrade_path": "os_version.get_upgrade_path", "hash_data": "hash.hash_data", "get_ips_sorted": "ip.get_ips_sorted", - "os_platform_object_builder": "platform_mapper.os_platform_object_builder", + "os_platform_object_builder": "nist.os_platform_object_builder", "juniper_junos_metadata": "os_version.juniper_junos_metadata", "version_metadata": "os_version.version_metadata", + "default_metadata": "os_version.default_metadata", } diff --git a/tests/unit/test_nist.py b/tests/unit/test_nist.py index ded1a601..f637129a 100644 --- a/tests/unit/test_nist.py +++ b/tests/unit/test_nist.py @@ -8,11 +8,31 @@ # Cisco and Arista use the generic parsing { "sent": {"vendor": "cisco", "platform": "ios", "version": "15.7(2.0z)M"}, - "received": {"vendor": "cisco", "os_type": "ios", "version_string": "15.7(2.0z)M"}, + "received": { + "vendor": "cisco", + "os_type": "ios", + "version_string": "15.7(2.0z)M", + "major": "15", + "minor": "7", + "patch": None, + "prerelease": None, + "buildmetadata": None, + "vendor_metadata": False, + }, }, { "sent": {"vendor": "arista", "platform": "eos", "version": "4.15.3f"}, - "received": {"vendor": "arista", "os_type": "eos", "version_string": "4.15.3f"}, + "received": { + "vendor": "arista", + "os_type": "eos", + "version_string": "4.15.3f", + "major": "4", + "minor": "15", + "patch": None, + "prerelease": None, + "buildmetadata": None, + "vendor_metadata": False, + }, }, # Juniper Junos uses a custom parser { @@ -32,6 +52,11 @@ "service": None, "service_build": None, "service_respin": None, + "buildmetadata": None, + "vendor_metadata": True, + "prerelease": None, + "major": "12", + "patch": None, }, }, { @@ -51,6 +76,11 @@ "service": "d", "service_build": "80", "service_respin": None, + "buildmetadata": None, + "vendor_metadata": True, + "prerelease": None, + "major": "12", + "patch": "48", }, }, { @@ -70,6 +100,11 @@ "service": "d", "service_build": "80", "service_respin": None, + "buildmetadata": None, + "vendor_metadata": True, + "prerelease": None, + "major": "12", + "patch": "48", }, }, { @@ -89,6 +124,11 @@ "service": "S", "service_build": "15", "service_respin": None, + "buildmetadata": None, + "vendor_metadata": True, + "prerelease": None, + "major": "12", + "patch": "12", }, }, ]