From 17e0aebb0d064742e11dfba7c7a9f31eb6fe7bf2 Mon Sep 17 00:00:00 2001 From: bewing Date: Mon, 4 Nov 2024 19:37:18 -0600 Subject: [PATCH] Improve nxos_ssh version handling (#2152) Closes #2151 --- napalm/nxos_ssh/nxos_ssh.py | 2 +- .../issue2151/expected_result.json | 76 +++++++++++++++++++ .../issue2151/show_hostname.txt | 1 + .../test_get_facts/issue2151/show_hosts.txt | 7 ++ .../issue2151/show_interface_status.txt | 69 +++++++++++++++++ .../issue2151/show_inventory___json.txt | 34 +++++++++ .../test_get_facts/issue2151/show_version.txt | 50 ++++++++++++ 7 files changed, 238 insertions(+), 1 deletion(-) create mode 100644 test/nxos_ssh/mocked_data/test_get_facts/issue2151/expected_result.json create mode 100644 test/nxos_ssh/mocked_data/test_get_facts/issue2151/show_hostname.txt create mode 100644 test/nxos_ssh/mocked_data/test_get_facts/issue2151/show_hosts.txt create mode 100644 test/nxos_ssh/mocked_data/test_get_facts/issue2151/show_interface_status.txt create mode 100644 test/nxos_ssh/mocked_data/test_get_facts/issue2151/show_inventory___json.txt create mode 100644 test/nxos_ssh/mocked_data/test_get_facts/issue2151/show_version.txt diff --git a/napalm/nxos_ssh/nxos_ssh.py b/napalm/nxos_ssh/nxos_ssh.py index 7206756d4..5a71662a8 100644 --- a/napalm/nxos_ssh/nxos_ssh.py +++ b/napalm/nxos_ssh/nxos_ssh.py @@ -621,7 +621,7 @@ def get_facts(self): _, uptime_str = line.split(" uptime is ") uptime = self.parse_uptime(uptime_str) - if "system: " in line or "NXOS: " in line: + if "system: " in line or line.strip().startswith("NXOS: version"): line = line.strip() os_version = line.split()[2] os_version = os_version.strip() diff --git a/test/nxos_ssh/mocked_data/test_get_facts/issue2151/expected_result.json b/test/nxos_ssh/mocked_data/test_get_facts/issue2151/expected_result.json new file mode 100644 index 000000000..4f2b4860e --- /dev/null +++ b/test/nxos_ssh/mocked_data/test_get_facts/issue2151/expected_result.json @@ -0,0 +1,76 @@ +{ + "os_version": "10.3(5)", + "uptime": 4338547, + "interface_list": [ + "Management0", + "Ethernet1/1", + "Ethernet1/2", + "Ethernet1/3", + "Ethernet1/4", + "Ethernet1/5", + "Ethernet1/6", + "Ethernet1/7", + "Ethernet1/8", + "Ethernet1/9", + "Ethernet1/10", + "Ethernet1/11", + "Ethernet1/12", + "Ethernet1/13", + "Ethernet1/14", + "Ethernet1/15", + "Ethernet1/16", + "Ethernet1/17", + "Ethernet1/18", + "Ethernet1/19", + "Ethernet1/20", + "Ethernet1/21", + "Ethernet1/22", + "Ethernet1/23", + "Ethernet1/24", + "Ethernet1/25", + "Ethernet1/26", + "Ethernet1/27", + "Ethernet1/28", + "Ethernet1/29", + "Ethernet1/30", + "Ethernet1/31", + "Ethernet1/32", + "Ethernet1/33", + "Ethernet1/34", + "Ethernet1/35", + "Ethernet1/36", + "Ethernet1/37", + "Ethernet1/38", + "Ethernet1/39", + "Ethernet1/40", + "Ethernet1/41", + "Ethernet1/42", + "Ethernet1/43", + "Ethernet1/44", + "Ethernet1/45", + "Ethernet1/46", + "Ethernet1/47", + "Ethernet1/48", + "Ethernet1/49", + "Ethernet1/50", + "Ethernet1/51", + "Ethernet1/52", + "Port-channel1", + "Port-channel16", + "Port-channel17", + "Port-channel32", + "Port-channel33", + "Port-channel34", + "Port-channel35", + "Port-channel50", + "Port-channel51", + "Port-channel360", + "Vlan1", + "Vlan351" + ], + "vendor": "Cisco", + "serial_number": "TM6012EC74B", + "model": "Nexus 3048 Chassis", + "hostname": "SWITCH_NXOSv", + "fqdn": "SWITCH_NXOSv.y.z.a.com" +} diff --git a/test/nxos_ssh/mocked_data/test_get_facts/issue2151/show_hostname.txt b/test/nxos_ssh/mocked_data/test_get_facts/issue2151/show_hostname.txt new file mode 100644 index 000000000..c82c8bda3 --- /dev/null +++ b/test/nxos_ssh/mocked_data/test_get_facts/issue2151/show_hostname.txt @@ -0,0 +1 @@ +SWITCH_NXOSv.y.z.a.com \ No newline at end of file diff --git a/test/nxos_ssh/mocked_data/test_get_facts/issue2151/show_hosts.txt b/test/nxos_ssh/mocked_data/test_get_facts/issue2151/show_hosts.txt new file mode 100644 index 000000000..303a24bf1 --- /dev/null +++ b/test/nxos_ssh/mocked_data/test_get_facts/issue2151/show_hosts.txt @@ -0,0 +1,7 @@ +DNS lookup enabled +Vrf Name: default Default domain is y.z.a.com +Name servers are 8.8.8.4 8.8.8.8 + + + +Host Address diff --git a/test/nxos_ssh/mocked_data/test_get_facts/issue2151/show_interface_status.txt b/test/nxos_ssh/mocked_data/test_get_facts/issue2151/show_interface_status.txt new file mode 100644 index 000000000..105efd980 --- /dev/null +++ b/test/nxos_ssh/mocked_data/test_get_facts/issue2151/show_interface_status.txt @@ -0,0 +1,69 @@ + +-------------------------------------------------------------------------------- +Port Name Status Vlan Duplex Speed Type +-------------------------------------------------------------------------------- +mgmt0 -- connected routed full 1000 -- +Eth1/1 -- connected 353 full 100 10/100/1g +Eth1/2 -- notconnec 353 auto auto 10/100/1g +Eth1/3 -- disabled 366 auto auto 10/100/1g +Eth1/4 -- connected 351 full 1000 10/100/1g +Eth1/5 -- connected 351 full 1000 10/100/1g +Eth1/6 -- connected 351 full 1000 10/100/1g +Eth1/7 -- connected 351 full 1000 10/100/1g +Eth1/8 -- connected 351 full 1000 10/100/1g +Eth1/9 -- connected 351 full 1000 10/100/1g +Eth1/10 -- connected 351 full 1000 10/100/1g +Eth1/11 -- connected 351 full 1000 10/100/1g +Eth1/12 -- connected 351 full 1000 10/100/1g +Eth1/13 -- connected 351 full 1000 10/100/1g +Eth1/14 -- connected 351 full 1000 10/100/1g +Eth1/15 -- connected 351 full 1000 10/100/1g +Eth1/16 -- connected trunk full 1000 10/100/1g +Eth1/17 -- connected trunk full 1000 10/100/1g +Eth1/18 -- connected 369 full 1000 10/100/1g +Eth1/19 -- notconnec 351 auto auto 10/100/1g +Eth1/20 -- connected 351 full 100 10/100/1g +Eth1/21 -- connected 351 half 100 10/100/1g +Eth1/22 -- connected 351 half 100 10/100/1g +Eth1/23 -- disabled 366 auto auto 10/100/1g +Eth1/24 -- connected 352 full 1000 10/100/1g +Eth1/25 -- connected 352 half 100 10/100/1g +Eth1/26 -- connected 352 full 1000 10/100/1g +Eth1/27 -- connected 352 half 100 10/100/1g +Eth1/28 -- connected 352 full 100 10/100/1g +Eth1/29 -- connected 352 full 100 10/100/1g +Eth1/30 -- connected 352 full 100 10/100/1g +Eth1/31 -- disabled 366 auto auto 10/100/1g +Eth1/32 -- connected trunk full 1000 10/100/1g +Eth1/33 -- connected trunk full 1000 10/100/1g +Eth1/34 -- connected trunk full 1000 10/100/1g +Eth1/35 -- connected trunk full 1000 10/100/1g +Eth1/36 -- connected 351 full 1000 10/100/1g +Eth1/37 -- connected 351 full 1000 10/100/1g +Eth1/38 -- connected 351 full 1000 10/100/1g +Eth1/39 -- connected 351 full 1000 10/100/1g +Eth1/40 -- connected 351 full 1000 10/100/1g +Eth1/41 -- disabled 350 auto auto 10/100/1g +Eth1/42 -- connected 351 full 1000 10/100/1g +Eth1/43 -- connected 351 full 1000 10/100/1g +Eth1/44 -- connected 351 full 1000 10/100/1g +Eth1/45 -- connected 351 full 1000 10/100/1g +Eth1/46 -- disabled 366 auto auto 10/100/1g +Eth1/47 -- connected trunk full 1000 10/100/1g +Eth1/48 -- connected trunk full 1000 10/100/1g +Eth1/49 -- xcvrAbsen 366 full 10G -- +Eth1/50 -- connected trunk full 1000 1000base-SX +Eth1/51 -- connected trunk full 1000 1000base-SX +Eth1/52 -- connected trunk full 1000 1000base-SX +Po1 -- connected trunk full 1000 -- +Po16 -- connected trunk full 1000 -- +Po17 -- connected trunk full 1000 -- +Po32 -- connected trunk full 1000 -- +Po33 -- connected trunk full 1000 -- +Po34 -- connected trunk full 1000 -- +Po35 -- connected trunk full 1000 -- +Po50 -- connected trunk full 1000 -- +Po51 -- connected trunk full 1000 -- +Po360 -- connected trunk full 1000 -- +Vlan1 -- down routed auto auto -- +Vlan351 -- connected routed auto auto -- \ No newline at end of file diff --git a/test/nxos_ssh/mocked_data/test_get_facts/issue2151/show_inventory___json.txt b/test/nxos_ssh/mocked_data/test_get_facts/issue2151/show_inventory___json.txt new file mode 100644 index 000000000..15cbe724c --- /dev/null +++ b/test/nxos_ssh/mocked_data/test_get_facts/issue2151/show_inventory___json.txt @@ -0,0 +1,34 @@ +{ + "TABLE_inv": { + "ROW_inv": [ + { + "name": "Chassis", + "desc": "Nexus 6001 Chassis", + "productid": "N6K-C6001-64P", + "vendorid": "V01", + "serialnum": "TM6012EC74B" + }, + { + "name": "Module 1", + "desc": "Nexus 64 Supervisor", + "productid": "N6K-C6001-64P", + "vendorid": "V01", + "serialnum": "FOC11111111" + }, + { + "name": "Module 2", + "desc": "Nexus 4xQSFP Ethernet Module", + "productid": "N6K-C6001-M4Q", + "vendorid": "V01", + "serialnum": "FOC11111111" + }, + { + "name": "Fan 1", + "desc": "Chassis fan module", + "productid": "N6K-C6001-FAN-B", + "vendorid": "N/A", + "serialnum": "N/A" + } + ] + } +} diff --git a/test/nxos_ssh/mocked_data/test_get_facts/issue2151/show_version.txt b/test/nxos_ssh/mocked_data/test_get_facts/issue2151/show_version.txt new file mode 100644 index 000000000..cafe1098d --- /dev/null +++ b/test/nxos_ssh/mocked_data/test_get_facts/issue2151/show_version.txt @@ -0,0 +1,50 @@ +Cisco Nexus Operating System (NX-OS) Software +TAC support: http://www.cisco.com/tac +Copyright (C) 2002-2017, Cisco and/or its affiliates. +All rights reserved. +The copyrights to certain works contained in this software are +owned by other third parties and used and distributed under their own +licenses, such as open source. This software is provided "as is," and unless +otherwise stated, there is no warranty, express or implied, including but not +limited to warranties of merchantability and fitness for a particular purpose. +Certain components of this software are licensed under +the GNU General Public License (GPL) version 2.0 or +GNU General Public License (GPL) version 3.0 or the GNU +Lesser General Public License (LGPL) Version 2.1 or +Lesser General Public License (LGPL) Version 2.0. +A copy of each such license is available at +http://www.opensource.org/licenses/gpl-2.0.php and +http://opensource.org/licenses/gpl-3.0.html and +http://www.opensource.org/licenses/lgpl-2.1.php and +http://www.gnu.org/licenses/old-licenses/library.txt. + +Software + BIOS: version 01.09 + NXOS: version 10.3(5) [Maintenance Release] + Host NXOS: version 10.3(5) + BIOS compile time: 10/08/2023 + NXOS image file is: bootflash:///nxos64-cs.10.3.5.M.bin + NXOS compile time: 4/30/2024 12:00:00 [05/08/2024 05:39:13] + NXOS boot mode: LXC + +Hardware + cisco Nexus 3048 Chassis + Intel(R) Celeron(R) CPU P4505 @ 1.87GHz with 3903332 kB of memory. + Processor Board ID TM6012EC74B + + Device name: SWITCH_NXOSv + bootflash: 1848240 kB + usb1: 0 kB (expansion flash) + +Kernel uptime is 50 day(s), 5 hour(s), 9 minute(s), 7 second(s) + +Last reset at 829281 usecs after Thu Oct 26 20:25:34 2017 + + Reason: Reset Requested by CLI command reload + System version: 7.0(3)I4(7) + Service: + +plugin + Core Plugin, Ethernet Plugin + +Active Package(s):