From 6e5d7d1a0ef1fd7d94c3c3b02454621f6fa51906 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Fri, 20 Sep 2024 22:59:52 +0200 Subject: [PATCH 1/3] Fix UnboundLocalError: cannot access local variable 'seconds' where it is not associated with a value Stacktrace: File "/data/apps/netbox/.asdf/installs/python/3.11.9/lib/python3.11/site-packages/napalm/nxos_ssh/nxos_ssh.py", line 511, in parse_uptime + seconds ^^^^^^^ --- napalm/nxos_ssh/nxos_ssh.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/napalm/nxos_ssh/nxos_ssh.py b/napalm/nxos_ssh/nxos_ssh.py index fcec00c28..ef71aa016 100644 --- a/napalm/nxos_ssh/nxos_ssh.py +++ b/napalm/nxos_ssh/nxos_ssh.py @@ -484,7 +484,7 @@ def parse_uptime(uptime_str): Return the uptime in seconds as an integer """ # Initialize to zero - (years, weeks, days, hours, minutes) = (0, 0, 0, 0, 0) + (years, weeks, days, hours, minutes, seconds) = (0, 0, 0, 0, 0, 0) uptime_str = uptime_str.strip() time_list = uptime_str.split(",") From 19706c3380976f16886286a48e2057cdf5b9e0eb Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Fri, 20 Sep 2024 23:01:53 +0200 Subject: [PATCH 2/3] Fix unexpected speed unit in show interfaces parsing Sometimes unit is "Kbit/sec": MTU 1500 bytes, BW 1000000 Kbit/sec, DLY 10 usec, reliability 255/255, txload 1/255, rxload 1/255 --- napalm/nxos_ssh/nxos_ssh.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/napalm/nxos_ssh/nxos_ssh.py b/napalm/nxos_ssh/nxos_ssh.py index ef71aa016..7206756d4 100644 --- a/napalm/nxos_ssh/nxos_ssh.py +++ b/napalm/nxos_ssh/nxos_ssh.py @@ -168,8 +168,7 @@ def parse_intf_section(interface): mtu = int(speed_data["mtu"]) speed_unit = speed_data["speed_unit"] speed_unit = speed_unit.rstrip(",") - # This was alway in Kbit (in the data I saw) - if speed_unit != "Kbit": + if speed_unit not in ["Kbit", "Kbit/sec"]: msg = "Unexpected speed unit in show interfaces parsing:\n\n{}".format( interface ) From 3d6568350a76903538b8431de129a16c033c4ae7 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 14 Oct 2024 23:05:42 +0200 Subject: [PATCH 3/3] Add tests on NXOSSSHDriver.parse_uptime method --- test/nxos_ssh/test_static_methods.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 test/nxos_ssh/test_static_methods.py diff --git a/test/nxos_ssh/test_static_methods.py b/test/nxos_ssh/test_static_methods.py new file mode 100644 index 000000000..9dd066a8f --- /dev/null +++ b/test/nxos_ssh/test_static_methods.py @@ -0,0 +1,20 @@ +"""Tests for uptime utils""" + +from napalm.nxos_ssh import NXOSSSHDriver + + +def test_parse_uptime(): + """ + Test uptime parsing + """ + assert ( + NXOSSSHDriver.parse_uptime("0 day(s), 0 hour(s), 0 minute(s), 1 second(s)") == 1 + ) + assert ( + NXOSSSHDriver.parse_uptime("1 day(s), 0 hour(s), 0 minute(s), 0 second(s)") + == 86400 + ) + assert ( + NXOSSSHDriver.parse_uptime("4 day(s), 15 hour(s), 48 minute(s), 52 second(s)") + == 402532 + )