From bc0fef6ed6008395e73ac015e988cf3e2c436762 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Blakstad?= Date: Wed, 1 Mar 2017 12:05:55 +0100 Subject: [PATCH 01/27] Octets not parsed correctly with regular expression. --- napalm_ios/ios.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/napalm_ios/ios.py b/napalm_ios/ios.py index fec06f2..195fb98 100755 --- a/napalm_ios/ios.py +++ b/napalm_ios/ios.py @@ -1223,7 +1223,7 @@ def get_interfaces_counters(self): for line in interface_str.splitlines(): if 'packets input' in line: # '0 packets input, 0 bytes, 0 no buffer' - match = re.search(r"(\d+) packets input.*(\d+) bytes", line) + match = re.search(r"(\d+) packets input.* (\d+) bytes", line) counters[interface]['rx_unicast_packets'] = int(match.group(1)) counters[interface]['rx_octets'] = int(match.group(2)) elif 'broadcast' in line: @@ -1243,7 +1243,7 @@ def get_interfaces_counters(self): counters[interface]['rx_multicast_packets'] = -1 elif 'packets output' in line: # '0 packets output, 0 bytes, 0 underruns' - match = re.search(r"(\d+) packets output.*(\d+) bytes", line) + match = re.search(r"(\d+) packets output.* (\d+) bytes", line) counters[interface]['tx_unicast_packets'] = int(match.group(1)) counters[interface]['tx_octets'] = int(match.group(2)) counters[interface]['tx_broadcast_packets'] = -1 From b02ad3432d9d700b50d636a5868fd2c92e3a9eed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Blakstad?= Date: Wed, 1 Mar 2017 13:35:05 +0100 Subject: [PATCH 02/27] Support for discarded packets in get_interface_status --- napalm_ios/ios.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) mode change 100755 => 100644 napalm_ios/ios.py diff --git a/napalm_ios/ios.py b/napalm_ios/ios.py old mode 100755 new mode 100644 index 195fb98..c480912 --- a/napalm_ios/ios.py +++ b/napalm_ios/ios.py @@ -1194,11 +1194,13 @@ def get_interfaces_counters(self): 'rx_broadcast_packets': int, Currently doesn't determine output broadcasts, multicasts - Doesn't determine tx_discards or rx_discards + Doesn't determine tx_discards or rx_discards -> fixed with show interface summary """ counters = {} command = 'show interfaces' output = self._send_command(command) + sh_int_sum_cmd = 'show interface summary' + sh_int_sum_cmd_out = self._send_command(sh_int_sum_cmd) # Break output into per-interface sections interface_strings = re.split(r'.* line protocol is .*', output, flags=re.M) @@ -1258,6 +1260,15 @@ def get_interfaces_counters(self): match = re.search(r"(\d+) output errors", line) counters[interface]['tx_errors'] = int(match.group(1)) counters[interface]['tx_discards'] = -1 + for line in sh_int_sum_cmd_out.splitlines(): + if interface in line: + regex = r"\b" + interface + r"\b\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)" + match = re.search(regex, line) + if match: + counters[interface]['rx_discards'] = int(match.group(2)) + counters[interface]['tx_discards'] = int(match.group(4)) + + return counters From 97c1a493f84644458825f7676ba2f1433dac09ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Blakstad?= Date: Thu, 2 Mar 2017 09:14:43 +0100 Subject: [PATCH 03/27] Fix travis failures --- napalm_ios/ios.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/napalm_ios/ios.py b/napalm_ios/ios.py index c480912..563e070 100644 --- a/napalm_ios/ios.py +++ b/napalm_ios/ios.py @@ -1262,15 +1262,14 @@ def get_interfaces_counters(self): counters[interface]['tx_discards'] = -1 for line in sh_int_sum_cmd_out.splitlines(): if interface in line: - regex = r"\b" + interface + r"\b\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)" + regex = r"\b" + interface +\ + r"\b\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)" match = re.search(regex, line) if match: counters[interface]['rx_discards'] = int(match.group(2)) counters[interface]['tx_discards'] = int(match.group(4)) - - - return counters + return counters def get_environment(self): """ From fe0a7150d4fff81f8b17a4bd960694446acb397f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Blakstad?= Date: Thu, 2 Mar 2017 09:23:51 +0100 Subject: [PATCH 04/27] Fix more travis build failures --- napalm_ios/ios.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/napalm_ios/ios.py b/napalm_ios/ios.py index 563e070..187e4cf 100644 --- a/napalm_ios/ios.py +++ b/napalm_ios/ios.py @@ -1263,7 +1263,8 @@ def get_interfaces_counters(self): for line in sh_int_sum_cmd_out.splitlines(): if interface in line: regex = r"\b" + interface +\ - r"\b\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)" + r"\b\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)" + \ + r"\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)" match = re.search(regex, line) if match: counters[interface]['rx_discards'] = int(match.group(2)) From 60ef250f0b010bbe38c9cab5611f44c864990eeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Blakstad?= Date: Thu, 2 Mar 2017 20:04:49 +0100 Subject: [PATCH 05/27] Fix bug introduced when fixing travis errors --- napalm_ios/ios.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/napalm_ios/ios.py b/napalm_ios/ios.py index 187e4cf..cbae153 100644 --- a/napalm_ios/ios.py +++ b/napalm_ios/ios.py @@ -1270,7 +1270,7 @@ def get_interfaces_counters(self): counters[interface]['rx_discards'] = int(match.group(2)) counters[interface]['tx_discards'] = int(match.group(4)) - return counters + return counters def get_environment(self): """ From 1311ae7682b53355068f016997f7ccbc8045e9f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Blakstad?= Date: Fri, 3 Mar 2017 09:59:26 +0100 Subject: [PATCH 06/27] Mocked files for tests --- .../normal/expected_result.json | 60 ++++++++++++------- .../normal/show_interface_summary.txt | 14 +++++ .../normal/show_interfaces.txt | 58 +++++++++++++----- 3 files changed, 93 insertions(+), 39 deletions(-) create mode 100644 test/unit/mocked_data/test_get_interfaces_counters/normal/show_interface_summary.txt diff --git a/test/unit/mocked_data/test_get_interfaces_counters/normal/expected_result.json b/test/unit/mocked_data/test_get_interfaces_counters/normal/expected_result.json index 65e00a0..0338023 100644 --- a/test/unit/mocked_data/test_get_interfaces_counters/normal/expected_result.json +++ b/test/unit/mocked_data/test_get_interfaces_counters/normal/expected_result.json @@ -1,44 +1,58 @@ { "GigabitEthernet1": { - "tx_discards": -1, - "tx_broadcast_packets": -1, - "rx_multicast_packets": 0, - "tx_unicast_packets": 9297, - "rx_octets": 2, + "rx_unicast_packets": 215, + "rx_octets": 20133, "rx_broadcast_packets": 0, + "rx_multicast_packets": 0, "rx_errors": 0, - "tx_octets": 1, - "rx_discards": -1, + "rx_discards": 0, + "tx_unicast_packets": 103, + "tx_octets": 15306, + "tx_broadcast_packets": -1, "tx_multicast_packets": -1, "tx_errors": 0, - "rx_unicast_packets": 13799 + "tx_discards": 0 }, "GigabitEthernet2": { - "tx_discards": -1, - "tx_broadcast_packets": -1, - "rx_multicast_packets": 0, - "tx_unicast_packets": 154, - "rx_octets": 3, + "rx_unicast_packets": 0, + "rx_octets": 0, "rx_broadcast_packets": 0, + "rx_multicast_packets": 0, "rx_errors": 0, - "tx_octets": 7, - "rx_discards": -1, + "rx_discards": 0, + "tx_unicast_packets": 0, + "tx_octets": 0, + "tx_broadcast_packets": -1, "tx_multicast_packets": -1, "tx_errors": 0, - "rx_unicast_packets": 105 + "tx_discards": 0 }, "GigabitEthernet3": { - "tx_discards": -1, - "tx_broadcast_packets": -1, + "rx_unicast_packets": 0, + "rx_octets": 0, + "rx_broadcast_packets": 0, "rx_multicast_packets": 0, - "tx_unicast_packets": 3, + "rx_errors": 0, + "rx_discards": 0, + "tx_unicast_packets": 0, + "tx_octets": 0, + "tx_broadcast_packets": -1, + "tx_multicast_packets": -1, + "tx_errors": 0, + "tx_discards": 0 + }, + "GigabitEthernet4": { + "rx_unicast_packets": 0, "rx_octets": 0, "rx_broadcast_packets": 0, + "rx_multicast_packets": 0, "rx_errors": 0, - "tx_octets": 8, - "rx_discards": -1, + "rx_discards": 0, + "tx_unicast_packets": 0, + "tx_octets": 0, + "tx_broadcast_packets": -1, "tx_multicast_packets": -1, "tx_errors": 0, - "rx_unicast_packets": 0 + "tx_discards": 0 } -} +} \ No newline at end of file diff --git a/test/unit/mocked_data/test_get_interfaces_counters/normal/show_interface_summary.txt b/test/unit/mocked_data/test_get_interfaces_counters/normal/show_interface_summary.txt new file mode 100644 index 0000000..c83f788 --- /dev/null +++ b/test/unit/mocked_data/test_get_interfaces_counters/normal/show_interface_summary.txt @@ -0,0 +1,14 @@ + + *: interface is up + IHQ: pkts in input hold queue IQD: pkts dropped from input queue + OHQ: pkts in output hold queue OQD: pkts dropped from output queue + RXBS: rx rate (bits/sec) RXPS: rx rate (pkts/sec) + TXBS: tx rate (bits/sec) TXPS: tx rate (pkts/sec) + TRTL: throttle count + + Interface IHQ IQD OHQ OQD RXBS RXPS TXBS TXPS TRTL +----------------------------------------------------------------------------------------------------------------- +* GigabitEthernet1 0 0 0 0 0 0 0 0 0 + GigabitEthernet2 0 0 0 0 0 0 0 0 0 + GigabitEthernet3 0 0 0 0 0 0 0 0 0 + GigabitEthernet4 0 0 0 0 0 0 0 0 0 \ No newline at end of file diff --git a/test/unit/mocked_data/test_get_interfaces_counters/normal/show_interfaces.txt b/test/unit/mocked_data/test_get_interfaces_counters/normal/show_interfaces.txt index 67ce552..720ef19 100644 --- a/test/unit/mocked_data/test_get_interfaces_counters/normal/show_interfaces.txt +++ b/test/unit/mocked_data/test_get_interfaces_counters/normal/show_interfaces.txt @@ -1,6 +1,6 @@ GigabitEthernet1 is up, line protocol is up - Hardware is CSR vNIC, address is 0800.27f8.e842 (bia 0800.27f8.e842) - Internet address is 10.0.2.15/24 + Hardware is CSR vNIC, address is 00d6.b8ea.fc00 (bia 00d6.b8ea.fc00) + Internet address is 172.16.152.201/24 MTU 1500 bytes, BW 1000000 Kbit/sec, DLY 10 usec, reliability 255/255, txload 1/255, rxload 1/255 Encapsulation ARPA, loopback not set @@ -8,27 +8,26 @@ GigabitEthernet1 is up, line protocol is up Full Duplex, 1000Mbps, link type is auto, media type is RJ45 output flow-control is unsupported, input flow-control is unsupported ARP type: ARPA, ARP Timeout 04:00:00 - Last input 00:39:57, output 00:00:00, output hang never + Last input 00:03:20, output 00:03:20, output hang never Last clearing of "show interface" counters never Input queue: 0/375/0/0 (size/max/drops/flushes); Total output drops: 0 Queueing strategy: fifo Output queue: 0/40 (size/max) - 5 minute input rate 1000 bits/sec, 1 packets/sec - 5 minute output rate 1000 bits/sec, 1 packets/sec - 13799 packets input, 1748592 bytes, 0 no buffer + 5 minute input rate 0 bits/sec, 0 packets/sec + 5 minute output rate 0 bits/sec, 0 packets/sec + 297 packets input, 25963 bytes, 0 no buffer Received 0 broadcasts (0 IP multicasts) 0 runts, 0 giants, 0 throttles 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored 0 watchdog, 0 multicast, 0 pause input - 9297 packets output, 1355261 bytes, 0 underruns + 160 packets output, 26812 bytes, 0 underruns 0 output errors, 0 collisions, 0 interface resets 0 unknown protocol drops 0 babbles, 0 late collision, 0 deferred 0 lost carrier, 0 no carrier, 0 pause output 0 output buffer failures, 0 output buffers swapped out -GigabitEthernet2 is up, line protocol is up - Hardware is CSR vNIC, address is 0800.2779.e896 (bia 0800.2779.e896) - Internet address is 192.168.0.1/24 +GigabitEthernet2 is administratively down, line protocol is down + Hardware is CSR vNIC, address is 00d6.b8ea.fc01 (bia 00d6.b8ea.fc01) MTU 1500 bytes, BW 1000000 Kbit/sec, DLY 10 usec, reliability 255/255, txload 1/255, rxload 1/255 Encapsulation ARPA, loopback not set @@ -36,26 +35,26 @@ GigabitEthernet2 is up, line protocol is up Full Duplex, 1000Mbps, link type is auto, media type is RJ45 output flow-control is unsupported, input flow-control is unsupported ARP type: ARPA, ARP Timeout 04:00:00 - Last input 00:00:25, output 00:00:04, output hang never + Last input never, output never, output hang never Last clearing of "show interface" counters never Input queue: 0/375/0/0 (size/max/drops/flushes); Total output drops: 0 Queueing strategy: fifo Output queue: 0/40 (size/max) 5 minute input rate 0 bits/sec, 0 packets/sec 5 minute output rate 0 bits/sec, 0 packets/sec - 105 packets input, 10383 bytes, 0 no buffer + 0 packets input, 0 bytes, 0 no buffer Received 0 broadcasts (0 IP multicasts) 0 runts, 0 giants, 0 throttles 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored 0 watchdog, 0 multicast, 0 pause input - 154 packets output, 16467 bytes, 0 underruns - 0 output errors, 0 collisions, 1 interface resets + 0 packets output, 0 bytes, 0 underruns + 0 output errors, 0 collisions, 0 interface resets 0 unknown protocol drops 0 babbles, 0 late collision, 0 deferred 0 lost carrier, 0 no carrier, 0 pause output 0 output buffer failures, 0 output buffers swapped out GigabitEthernet3 is administratively down, line protocol is down - Hardware is CSR vNIC, address is 0800.2782.516b (bia 0800.2782.516b) + Hardware is CSR vNIC, address is 00d6.b8ea.fc02 (bia 00d6.b8ea.fc02) MTU 1500 bytes, BW 1000000 Kbit/sec, DLY 10 usec, reliability 255/255, txload 1/255, rxload 1/255 Encapsulation ARPA, loopback not set @@ -75,9 +74,36 @@ GigabitEthernet3 is administratively down, line protocol is down 0 runts, 0 giants, 0 throttles 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored 0 watchdog, 0 multicast, 0 pause input - 3 packets output, 258 bytes, 0 underruns + 0 packets output, 0 bytes, 0 underruns 0 output errors, 0 collisions, 0 interface resets 0 unknown protocol drops 0 babbles, 0 late collision, 0 deferred 0 lost carrier, 0 no carrier, 0 pause output 0 output buffer failures, 0 output buffers swapped out +GigabitEthernet4 is administratively down, line protocol is down + Hardware is CSR vNIC, address is 00d6.b8ea.fc03 (bia 00d6.b8ea.fc03) + MTU 1500 bytes, BW 1000000 Kbit/sec, DLY 10 usec, + reliability 255/255, txload 1/255, rxload 1/255 + Encapsulation ARPA, loopback not set + Keepalive set (10 sec) + Full Duplex, 1000Mbps, link type is auto, media type is RJ45 + output flow-control is unsupported, input flow-control is unsupported + ARP type: ARPA, ARP Timeout 04:00:00 + Last input never, output never, output hang never + Last clearing of "show interface" counters never + Input queue: 0/375/0/0 (size/max/drops/flushes); Total output drops: 0 + Queueing strategy: fifo + Output queue: 0/40 (size/max) + 5 minute input rate 0 bits/sec, 0 packets/sec + 5 minute output rate 0 bits/sec, 0 packets/sec + 0 packets input, 0 bytes, 0 no buffer + Received 0 broadcasts (0 IP multicasts) + 0 runts, 0 giants, 0 throttles + 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored + 0 watchdog, 0 multicast, 0 pause input + 0 packets output, 0 bytes, 0 underruns + 0 output errors, 0 collisions, 0 interface resets + 0 unknown protocol drops + 0 babbles, 0 late collision, 0 deferred + 0 lost carrier, 0 no carrier, 0 pause output + 0 output buffer failures, 0 output buffers swapped out \ No newline at end of file From 9b505213007ae3edaa1250fd1b43b9b3be8c315d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Blakstad?= Date: Fri, 3 Mar 2017 10:06:38 +0100 Subject: [PATCH 07/27] Mocked files for tests --- .../normal/expected_result.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/unit/mocked_data/test_get_interfaces_counters/normal/expected_result.json b/test/unit/mocked_data/test_get_interfaces_counters/normal/expected_result.json index 0338023..c0caca3 100644 --- a/test/unit/mocked_data/test_get_interfaces_counters/normal/expected_result.json +++ b/test/unit/mocked_data/test_get_interfaces_counters/normal/expected_result.json @@ -1,13 +1,13 @@ { "GigabitEthernet1": { - "rx_unicast_packets": 215, - "rx_octets": 20133, + "rx_unicast_packets": 297, + "rx_octets": 25963, "rx_broadcast_packets": 0, "rx_multicast_packets": 0, "rx_errors": 0, "rx_discards": 0, - "tx_unicast_packets": 103, - "tx_octets": 15306, + "tx_unicast_packets": 160, + "tx_octets": 26812, "tx_broadcast_packets": -1, "tx_multicast_packets": -1, "tx_errors": 0, From f26c997a2aa1a241cd776f4a16447afddfa348b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Blakstad?= Date: Mon, 6 Mar 2017 20:30:44 +0100 Subject: [PATCH 08/27] Removed unnecessary comment, modified regex with named groups and example --- napalm_ios/ios.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/napalm_ios/ios.py b/napalm_ios/ios.py index cbae153..ed51494 100644 --- a/napalm_ios/ios.py +++ b/napalm_ios/ios.py @@ -1194,7 +1194,6 @@ def get_interfaces_counters(self): 'rx_broadcast_packets': int, Currently doesn't determine output broadcasts, multicasts - Doesn't determine tx_discards or rx_discards -> fixed with show interface summary """ counters = {} command = 'show interfaces' @@ -1262,13 +1261,17 @@ def get_interfaces_counters(self): counters[interface]['tx_discards'] = -1 for line in sh_int_sum_cmd_out.splitlines(): if interface in line: + # ' Interface IHQ IQD OHQ OQD RXBS RXPS TXBS TXPS TRTL' + # '-----------------------------------------------------------------------------------------------------------------' + # ' FastEthernet0 0 0 0 0 0 0 0 0 0' regex = r"\b" + interface +\ - r"\b\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)" + \ - r"\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)" + r"\b\s+(?P\d+)\s+(?P\d+)\s+(?P\d+)" +\ + r"\s+(?P\d+)\s+(?P\d+)\s+(?P\d+)" + \ + r"\s+(?P\d+)\s+(?P\d+)\s+(?P\d+)" match = re.search(regex, line) if match: - counters[interface]['rx_discards'] = int(match.group(2)) - counters[interface]['tx_discards'] = int(match.group(4)) + counters[interface]['rx_discards'] = int(match.group("IQD")) + counters[interface]['tx_discards'] = int(match.group("OQD")) return counters From fca5890ec5ccb851616dd82877f53a8eed7108a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Blakstad?= Date: Mon, 6 Mar 2017 20:37:54 +0100 Subject: [PATCH 09/27] split regexp example with new lines to pass build test --- napalm_ios/ios.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/napalm_ios/ios.py b/napalm_ios/ios.py index ed51494..c84f9c5 100644 --- a/napalm_ios/ios.py +++ b/napalm_ios/ios.py @@ -1261,9 +1261,12 @@ def get_interfaces_counters(self): counters[interface]['tx_discards'] = -1 for line in sh_int_sum_cmd_out.splitlines(): if interface in line: - # ' Interface IHQ IQD OHQ OQD RXBS RXPS TXBS TXPS TRTL' - # '-----------------------------------------------------------------------------------------------------------------' - # ' FastEthernet0 0 0 0 0 0 0 0 0 0' + # ' Interface IHQ IQD OHQ OQD' +\ + # ' RXBS RXPS TXBS TXPS TRTL' + # '---------------------------------------------------------------' +\ + # '--------------------------------------------------' + # ' FastEthernet0 0 0 0 0' +\ + # ' 0 0 0 0 0' regex = r"\b" + interface +\ r"\b\s+(?P\d+)\s+(?P\d+)\s+(?P\d+)" +\ r"\s+(?P\d+)\s+(?P\d+)\s+(?P\d+)" + \ From fcd112987e263b7012f6ad21431412c5ce3a2ae0 Mon Sep 17 00:00:00 2001 From: Kirk Byers Date: Tue, 7 Mar 2017 15:22:47 -0800 Subject: [PATCH 10/27] Improving documentation of regex --- napalm_ios/ios.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/napalm_ios/ios.py b/napalm_ios/ios.py index c84f9c5..2d312f2 100644 --- a/napalm_ios/ios.py +++ b/napalm_ios/ios.py @@ -1261,16 +1261,13 @@ def get_interfaces_counters(self): counters[interface]['tx_discards'] = -1 for line in sh_int_sum_cmd_out.splitlines(): if interface in line: - # ' Interface IHQ IQD OHQ OQD' +\ - # ' RXBS RXPS TXBS TXPS TRTL' - # '---------------------------------------------------------------' +\ - # '--------------------------------------------------' - # ' FastEthernet0 0 0 0 0' +\ - # ' 0 0 0 0 0' - regex = r"\b" + interface +\ - r"\b\s+(?P\d+)\s+(?P\d+)\s+(?P\d+)" +\ - r"\s+(?P\d+)\s+(?P\d+)\s+(?P\d+)" + \ - r"\s+(?P\d+)\s+(?P\d+)\s+(?P\d+)" + # Line is tabular output with columns + # Interface IHQ IQD OHQ OQD RXBS RXPS TXBS TXPS TRTL + # where columns (excluding interface) are integers + regex = r"\b" + interface + \ + r"\b\s+(\d+)\s+(?P\d+)\s+(\d+)" + \ + r"\s+(?P\d+)\s+(\d+)\s+(\d+)" + \ + r"\s+(\d+)\s+(\d+)\s+(\d+)" match = re.search(regex, line) if match: counters[interface]['rx_discards'] = int(match.group("IQD")) From 6364e2659f4d8d999c37f3111aea54b4f621eb8f Mon Sep 17 00:00:00 2001 From: David Barroso Date: Sun, 26 Mar 2017 17:14:47 +0200 Subject: [PATCH 11/27] Adding profile --- napalm_ios/ios.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/napalm_ios/ios.py b/napalm_ios/ios.py index 2d312f2..355ea76 100644 --- a/napalm_ios/ios.py +++ b/napalm_ios/ios.py @@ -107,6 +107,8 @@ def __init__(self, hostname, username, password, timeout=60, optional_args=None) self.config_replace = False self.interface_map = {} + self.profile = ["ios"] + def open(self): """Open a connection to the device.""" self.device = ConnectHandler(device_type='cisco_ios', From 8fd1de0bfd2ce6b23c3aed95c4f5b2c2ad78e20a Mon Sep 17 00:00:00 2001 From: David Barroso Date: Mon, 27 Mar 2017 10:01:45 +0200 Subject: [PATCH 12/27] Ignore ctags --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index d3d0498..15d6273 100644 --- a/.gitignore +++ b/.gitignore @@ -67,3 +67,4 @@ test/unit/ios/cleanup.sh test/unit/ios/prep_test.sh report.json +tags From dd70b4255fcebf937dcf61dbf0b8c671d96264e1 Mon Sep 17 00:00:00 2001 From: Kirk Byers Date: Wed, 29 Mar 2017 13:14:58 -0700 Subject: [PATCH 13/27] Fixes issue #129; LLDP neighbor detail bug --- napalm_ios/ios.py | 7 +- requirements.txt | 4 +- .../alternate2/expected_result.json | 1 + .../alternate2/show_int_Gi1.txt | 28 +++ .../alternate2/show_lldp_neighbors.txt | 15 ++ .../show_lldp_neighbors_Gi1_detail.txt | 189 ++++++++++++++++++ ...lldp_neighbors_GigabitEthernet1_detail.txt | 189 ++++++++++++++++++ 7 files changed, 430 insertions(+), 3 deletions(-) create mode 100644 test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate2/expected_result.json create mode 100644 test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate2/show_int_Gi1.txt create mode 100644 test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate2/show_lldp_neighbors.txt create mode 100644 test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate2/show_lldp_neighbors_Gi1_detail.txt create mode 100644 test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate2/show_lldp_neighbors_GigabitEthernet1_detail.txt diff --git a/napalm_ios/ios.py b/napalm_ios/ios.py index 2d312f2..069d940 100644 --- a/napalm_ios/ios.py +++ b/napalm_ios/ios.py @@ -619,7 +619,7 @@ def _lldp_detail_parser(self, interface): port_id = re.findall(r"Port id:\s+(.+)", output) port_description = re.findall(r"Port Description(?:\s\-|:)\s+(.+)", output) chassis_id = re.findall(r"Chassis id:\s+(.+)", output) - system_name = re.findall(r"System Name:\s+(.+)", output) + system_name = re.findall(r"System Name\s*[:-]\s+(.+)", output) system_description = re.findall(r"System Description:\s*\n(.+)", output) system_capabilities = re.findall(r"System Capabilities:\s+(.+)", output) enabled_capabilities = re.findall(r"Enabled Capabilities:\s+(.+)", output) @@ -649,10 +649,15 @@ def get_lldp_neighbors_detail(self, interface=''): local_port = interface lldp_fields = self._lldp_detail_parser(interface) number_entries = len(lldp_fields[0]) + from pprint import pprint + pprint(local_port) + pprint(lldp_fields) + pprint(number_entries) # re.findall will return a list. Make sure same number of entries always returned. for test_list in lldp_fields: if len(test_list) != number_entries: + print(test_list) raise ValueError("Failure processing show lldp neighbors detail") # Standardize the fields diff --git a/requirements.txt b/requirements.txt index a2c2728..4efa8ec 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -napalm_base>=0.21.0 -netmiko>=1.2.7 +napalm_base>=0.23.2 +netmiko>=1.2.8 diff --git a/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate2/expected_result.json b/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate2/expected_result.json new file mode 100644 index 0000000..21b1c33 --- /dev/null +++ b/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate2/expected_result.json @@ -0,0 +1 @@ +{"GigabitEthernet1": [{"remote_port_description": "ABCD-U1AC04-SW1", "parent_interface": "N/A", "remote_port": "Te2/1/14", "remote_system_enable_capab": "B", "remote_chassis_id": "0102.e2ff.fdb0", "remote_system_capab": "B,R", "remote_system_name": "ABCD-U-DSW1.wan.acme.com", "remote_system_description": "Cisco IOS Software, IOS-XE Software, Catalyst 4500 L3 Switch Software (cat4500e-UNIVERSALK9-M), Version 03.06.05.E RELEASE SOFTWARE (fc2)"}, {"remote_port_description": "ABCD-U1AC04-SW1", "parent_interface": "N/A", "remote_port": "Te1/1/14", "remote_system_enable_capab": "B", "remote_chassis_id": "0102.e2ff.fdb0", "remote_system_capab": "B,R", "remote_system_name": "ABCD-U-DSW1.wan.acme.com", "remote_system_description": "Cisco IOS Software, IOS-XE Software, Catalyst 4500 L3 Switch Software (cat4500e-UNIVERSALK9-M), Version 03.06.05.E RELEASE SOFTWARE (fc2)"}, {"remote_port_description": "not advertised", "parent_interface": "N/A", "remote_port": "port-001", "remote_system_enable_capab": "S", "remote_chassis_id": "hmbbkku-la", "remote_system_capab": "S", "remote_system_name": "HMBBKKU-LA", "remote_system_description": "Hewlett-Packard HP ProBook 650 G1,A3112DD10303,5CG4543H13 + engineering"}, {"remote_port_description": "not advertised", "parent_interface": "N/A", "remote_port": "port-001", "remote_system_enable_capab": "S", "remote_chassis_id": "jniceel-la", "remote_system_capab": "S", "remote_system_name": "JNICEEL-LA", "remote_system_description": "HP HP ProBook 650 G2,,5CG64565JFL + engineering"}, {"remote_port_description": "not advertised", "parent_interface": "N/A", "remote_port": "port-001", "remote_system_enable_capab": "S", "remote_chassis_id": "swaaaer-lta", "remote_system_capab": "S", "remote_system_name": "SWAAAER-LTA", "remote_system_description": "Hewlett-Packard HP ProBook 6570b,A10112D102,5CB40117ZP + engineering"}, {"remote_port_description": "not advertised", "parent_interface": "N/A", "remote_port": "port-001", "remote_system_enable_capab": "S", "remote_chassis_id": "rberrrann-lta", "remote_system_capab": "S", "remote_system_name": "RBERRRANN-LTA", "remote_system_description": "Hewlett-Packard HP ProBook 650 G1,A3112DD11203,CNU444BMZ0 + engineering"}, {"remote_port_description": "Siemens, SIMATIC NET, CP 343-1, 6GK7 443-1EX50-0XE0 , HW: 7, FW: V3.0.23, Ethernet Port, X1 P1", "parent_interface": "N/A", "remote_port": "port-001", "remote_system_enable_capab": "S", "remote_chassis_id": "cr-443-2", "remote_system_capab": "S", "remote_system_name": "not advertised", "remote_system_description": "Siemens, SIMATIC NET, CP 443-1, 6GK7 443-1EX50-0XE0, HW: Version 7, FW: Version V3.0.23, VPH6201262"}]} diff --git a/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate2/show_int_Gi1.txt b/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate2/show_int_Gi1.txt new file mode 100644 index 0000000..4d4e9c2 --- /dev/null +++ b/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate2/show_int_Gi1.txt @@ -0,0 +1,28 @@ +GigabitEthernet1 is up, line protocol is up + Hardware is CSR vNIC, address is 2cc2.603f.437a (bia 2cc2.603f.437a) + Internet address is 10.0.0.51/24 + MTU 1500 bytes, BW 1000000 Kbit/sec, DLY 10 usec, + reliability 198/255, txload 1/255, rxload 1/255 + Encapsulation ARPA, loopback not set + Keepalive set (10 sec) + Full Duplex, 1000Mbps, link type is auto, media type is RJ45 + output flow-control is unsupported, input flow-control is unsupported + ARP type: ARPA, ARP Timeout 04:00:00 + Last input 00:00:07, output 00:00:18, output hang never + Last clearing of "show interface" counters never + Input queue: 0/375/0/0 (size/max/drops/flushes); Total output drops: 0 + Queueing strategy: fifo + Output queue: 0/40 (size/max) + 5 minute input rate 1000 bits/sec, 1 packets/sec + 5 minute output rate 0 bits/sec, 0 packets/sec + 3815699 packets input, 275467675 bytes, 0 no buffer + Received 0 broadcasts (0 IP multicasts) + 0 runts, 0 giants, 0 throttles + 2610907 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored + 0 watchdog, 0 multicast, 0 pause input + 5249863 packets output, 384472234 bytes, 0 underruns + 0 output errors, 0 collisions, 0 interface resets + 11192 unknown protocol drops + 0 babbles, 0 late collision, 0 deferred + 0 lost carrier, 0 no carrier, 0 pause output + 0 output buffer failures, 0 output buffers swapped out diff --git a/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate2/show_lldp_neighbors.txt b/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate2/show_lldp_neighbors.txt new file mode 100644 index 0000000..46097e4 --- /dev/null +++ b/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate2/show_lldp_neighbors.txt @@ -0,0 +1,15 @@ +Capability codes: + (R) Router, (B) Bridge, (T) Telephone, (C) DOCSIS Cable Device + (W) WLAN Access Point, (P) Repeater, (S) Station, (O) Other + +Device ID Local Intf Hold-time Capability Port ID +ABCD-U-DSW1.wan.acmeGi1 120 B,R Te2/1/14 +ABCD-U-DSW1.wan.acmeGi1 120 B,R Te1/1/14 +HMBBKKU-LA Gi1 120 S port-001 +JNICEEL-LA Gi1 120 S port-001 +SWAAAER-LTA Gi1 120 S port-001 +RBERRRANN-LTA Gi1 120 S port-001 +not advertised Gi1 120 S port-001 + +Total entries displayed: 7 + diff --git a/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate2/show_lldp_neighbors_Gi1_detail.txt b/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate2/show_lldp_neighbors_Gi1_detail.txt new file mode 100644 index 0000000..77964a4 --- /dev/null +++ b/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate2/show_lldp_neighbors_Gi1_detail.txt @@ -0,0 +1,189 @@ +------------------------------------------------ +Chassis id: 0102.e2ff.fdb0 +Port id: Te2/1/14 +Port Description: ABCD-U1AC04-SW1 +System Name: ABCD-U-DSW1.wan.acme.com + +System Description: +Cisco IOS Software, IOS-XE Software, Catalyst 4500 L3 Switch Software (cat4500e-UNIVERSALK9-M), Version 03.06.05.E RELEASE SOFTWARE (fc2) +Technical Support: http://www.cisco.com/techsupport +Copyright (c) 1986-2016 by Cisco Systems, Inc. +Compiled Thu 02-J + +Time remaining: 99 seconds +System Capabilities: B,R +Enabled Capabilities: B +Management Addresses: + IP: 192.168.1.13 +Auto Negotiation - not supported +Physical media capabilities: + Other/unknown +Media Attachment Unit type - not advertised +Vlan ID: - not advertised + +------------------------------------------------ +Chassis id: 0102.e2ff.fdb0 +Port id: Te1/1/14 +Port Description: ABCD-U1AC04-SW1 +System Name: ABCD-U-DSW1.wan.acme.com + +System Description: +Cisco IOS Software, IOS-XE Software, Catalyst 4500 L3 Switch Software (cat4500e-UNIVERSALK9-M), Version 03.06.05.E RELEASE SOFTWARE (fc2) +Technical Support: http://www.cisco.com/techsupport +Copyright (c) 1986-2016 by Cisco Systems, Inc. +Compiled Thu 02-J + +Time remaining: 103 seconds +System Capabilities: B,R +Enabled Capabilities: B +Management Addresses: + IP: 192.168.1.13 +Auto Negotiation - not supported +Physical media capabilities: + Other/unknown +Media Attachment Unit type - not advertised +Vlan ID: - not advertised + +------------------------------------------------ +Chassis id: hmbbkku-la +Port id: port-001 +Port Description - not advertised +System Name: HMBBKKU-LA + +System Description: +Hewlett-Packard HP ProBook 650 G1,A3112DD10303,5CG4543H13 + engineering + +Time remaining: 15 seconds +System Capabilities: S +Enabled Capabilities: S +Management Addresses: + IP: 192.168.45..57 + OID: + 1.3.6.1.4.1.24686. +Auto Negotiation - supported, enabled +Physical media capabilities: + 1000baseT(FD) + 1000baseT(HD) + 100base-TX(FD) + 100base-TX(HD) + 10base-T(FD) + 10base-T(HD) + Other/unknown +Media Attachment Unit type - not advertised +Vlan ID: - not advertised + +------------------------------------------------ +Chassis id: jniceel-la +Port id: port-001 +Port Description - not advertised +System Name: JNICEEL-LA + +System Description: +HP HP ProBook 650 G2,,5CG64565JFL + engineering + +Time remaining: 18 seconds +System Capabilities: S +Enabled Capabilities: S +Management Addresses: + IP: 192.168.45..71 + OID: + 1.3.6.1.4.1.24686. +Auto Negotiation - supported, enabled +Physical media capabilities: + 1000baseT(FD) + 1000baseT(HD) + 100base-TX(FD) + 100base-TX(HD) + 10base-T(FD) + 10base-T(HD) + Other/unknown +Media Attachment Unit type: 16 +Vlan ID: - not advertised + +------------------------------------------------ +Chassis id: swaaaer-lta +Port id: port-001 +Port Description - not advertised +System Name: SWAAAER-LTA + +System Description: +Hewlett-Packard HP ProBook 6570b,A10112D102,5CB40117ZP + engineering + +Time remaining: 16 seconds +System Capabilities: S +Enabled Capabilities: S +Management Addresses: + IP: 192.168.45..58 + OID: + 1.3.6.1.4.1.24686. +Auto Negotiation - supported, enabled +Physical media capabilities: + 1000baseT(FD) + 1000baseT(HD) + 100base-TX(FD) + 100base-TX(HD) + 10base-T(FD) + 10base-T(HD) + Other/unknown +Media Attachment Unit type - not advertised +Vlan ID: - not advertised + +------------------------------------------------ +Chassis id: rberrrann-lta +Port id: port-001 +Port Description - not advertised +System Name: RBERRRANN-LTA + +System Description: +Hewlett-Packard HP ProBook 650 G1,A3112DD11203,CNU444BMZ0 + engineering + +Time remaining: 19 seconds +System Capabilities: S +Enabled Capabilities: S +Management Addresses: + IP: 192.168.45..104 + OID: + 1.3.6.1.4.1.24686. +Auto Negotiation - supported, enabled +Physical media capabilities: + 1000baseT(FD) + 1000baseT(HD) + 100base-TX(FD) + 100base-TX(HD) + 10base-T(FD) + 10base-T(HD) + Other/unknown +Media Attachment Unit type - not advertised +Vlan ID: - not advertised + +------------------------------------------------ +Chassis id: cr-443-2 +Port id: port-001 +Port Description: Siemens, SIMATIC NET, CP 343-1, 6GK7 443-1EX50-0XE0 , HW: 7, FW: V3.0.23, Ethernet Port, X1 P1 +System Name - not advertised + +System Description: +Siemens, SIMATIC NET, CP 443-1, 6GK7 443-1EX50-0XE0, HW: Version 7, FW: Version V3.0.23, VPH6201262 + +Time remaining: 16 seconds +System Capabilities: S +Enabled Capabilities: S +Management Addresses: + IP: 192.168.24.197 + OID: + 1.3.6.1.4.1.24686. +Auto Negotiation - supported, enabled +Physical media capabilities: + 100base-T2(FD) + 100base-T2(HD) + 100base-TX(FD) + 100base-TX(HD) + 100base-T4 + 10base-T(FD) + 10base-T(HD) + Other/unknown +Media Attachment Unit type: 16 +Vlan ID: - not advertised + + +Total entries displayed: 7 diff --git a/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate2/show_lldp_neighbors_GigabitEthernet1_detail.txt b/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate2/show_lldp_neighbors_GigabitEthernet1_detail.txt new file mode 100644 index 0000000..77964a4 --- /dev/null +++ b/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate2/show_lldp_neighbors_GigabitEthernet1_detail.txt @@ -0,0 +1,189 @@ +------------------------------------------------ +Chassis id: 0102.e2ff.fdb0 +Port id: Te2/1/14 +Port Description: ABCD-U1AC04-SW1 +System Name: ABCD-U-DSW1.wan.acme.com + +System Description: +Cisco IOS Software, IOS-XE Software, Catalyst 4500 L3 Switch Software (cat4500e-UNIVERSALK9-M), Version 03.06.05.E RELEASE SOFTWARE (fc2) +Technical Support: http://www.cisco.com/techsupport +Copyright (c) 1986-2016 by Cisco Systems, Inc. +Compiled Thu 02-J + +Time remaining: 99 seconds +System Capabilities: B,R +Enabled Capabilities: B +Management Addresses: + IP: 192.168.1.13 +Auto Negotiation - not supported +Physical media capabilities: + Other/unknown +Media Attachment Unit type - not advertised +Vlan ID: - not advertised + +------------------------------------------------ +Chassis id: 0102.e2ff.fdb0 +Port id: Te1/1/14 +Port Description: ABCD-U1AC04-SW1 +System Name: ABCD-U-DSW1.wan.acme.com + +System Description: +Cisco IOS Software, IOS-XE Software, Catalyst 4500 L3 Switch Software (cat4500e-UNIVERSALK9-M), Version 03.06.05.E RELEASE SOFTWARE (fc2) +Technical Support: http://www.cisco.com/techsupport +Copyright (c) 1986-2016 by Cisco Systems, Inc. +Compiled Thu 02-J + +Time remaining: 103 seconds +System Capabilities: B,R +Enabled Capabilities: B +Management Addresses: + IP: 192.168.1.13 +Auto Negotiation - not supported +Physical media capabilities: + Other/unknown +Media Attachment Unit type - not advertised +Vlan ID: - not advertised + +------------------------------------------------ +Chassis id: hmbbkku-la +Port id: port-001 +Port Description - not advertised +System Name: HMBBKKU-LA + +System Description: +Hewlett-Packard HP ProBook 650 G1,A3112DD10303,5CG4543H13 + engineering + +Time remaining: 15 seconds +System Capabilities: S +Enabled Capabilities: S +Management Addresses: + IP: 192.168.45..57 + OID: + 1.3.6.1.4.1.24686. +Auto Negotiation - supported, enabled +Physical media capabilities: + 1000baseT(FD) + 1000baseT(HD) + 100base-TX(FD) + 100base-TX(HD) + 10base-T(FD) + 10base-T(HD) + Other/unknown +Media Attachment Unit type - not advertised +Vlan ID: - not advertised + +------------------------------------------------ +Chassis id: jniceel-la +Port id: port-001 +Port Description - not advertised +System Name: JNICEEL-LA + +System Description: +HP HP ProBook 650 G2,,5CG64565JFL + engineering + +Time remaining: 18 seconds +System Capabilities: S +Enabled Capabilities: S +Management Addresses: + IP: 192.168.45..71 + OID: + 1.3.6.1.4.1.24686. +Auto Negotiation - supported, enabled +Physical media capabilities: + 1000baseT(FD) + 1000baseT(HD) + 100base-TX(FD) + 100base-TX(HD) + 10base-T(FD) + 10base-T(HD) + Other/unknown +Media Attachment Unit type: 16 +Vlan ID: - not advertised + +------------------------------------------------ +Chassis id: swaaaer-lta +Port id: port-001 +Port Description - not advertised +System Name: SWAAAER-LTA + +System Description: +Hewlett-Packard HP ProBook 6570b,A10112D102,5CB40117ZP + engineering + +Time remaining: 16 seconds +System Capabilities: S +Enabled Capabilities: S +Management Addresses: + IP: 192.168.45..58 + OID: + 1.3.6.1.4.1.24686. +Auto Negotiation - supported, enabled +Physical media capabilities: + 1000baseT(FD) + 1000baseT(HD) + 100base-TX(FD) + 100base-TX(HD) + 10base-T(FD) + 10base-T(HD) + Other/unknown +Media Attachment Unit type - not advertised +Vlan ID: - not advertised + +------------------------------------------------ +Chassis id: rberrrann-lta +Port id: port-001 +Port Description - not advertised +System Name: RBERRRANN-LTA + +System Description: +Hewlett-Packard HP ProBook 650 G1,A3112DD11203,CNU444BMZ0 + engineering + +Time remaining: 19 seconds +System Capabilities: S +Enabled Capabilities: S +Management Addresses: + IP: 192.168.45..104 + OID: + 1.3.6.1.4.1.24686. +Auto Negotiation - supported, enabled +Physical media capabilities: + 1000baseT(FD) + 1000baseT(HD) + 100base-TX(FD) + 100base-TX(HD) + 10base-T(FD) + 10base-T(HD) + Other/unknown +Media Attachment Unit type - not advertised +Vlan ID: - not advertised + +------------------------------------------------ +Chassis id: cr-443-2 +Port id: port-001 +Port Description: Siemens, SIMATIC NET, CP 343-1, 6GK7 443-1EX50-0XE0 , HW: 7, FW: V3.0.23, Ethernet Port, X1 P1 +System Name - not advertised + +System Description: +Siemens, SIMATIC NET, CP 443-1, 6GK7 443-1EX50-0XE0, HW: Version 7, FW: Version V3.0.23, VPH6201262 + +Time remaining: 16 seconds +System Capabilities: S +Enabled Capabilities: S +Management Addresses: + IP: 192.168.24.197 + OID: + 1.3.6.1.4.1.24686. +Auto Negotiation - supported, enabled +Physical media capabilities: + 100base-T2(FD) + 100base-T2(HD) + 100base-TX(FD) + 100base-TX(HD) + 100base-T4 + 10base-T(FD) + 10base-T(HD) + Other/unknown +Media Attachment Unit type: 16 +Vlan ID: - not advertised + + +Total entries displayed: 7 From 9c920e2e65af16d5d1abc80d74d84ef2f740f6da Mon Sep 17 00:00:00 2001 From: Kirk Byers Date: Wed, 29 Mar 2017 21:23:57 -0700 Subject: [PATCH 14/27] Fix more LLDP detail issues, Fixes #126 --- napalm_ios/ios.py | 36 +++++++----- .../alternate3/expected_result.json | 1 + .../alternate3/show_int_Gi1.txt | 28 +++++++++ .../alternate3/show_lldp_neighbors.txt | 10 ++++ .../show_lldp_neighbors_Gi1_detail.txt | 57 +++++++++++++++++++ ...lldp_neighbors_GigabitEthernet1_detail.txt | 57 +++++++++++++++++++ 6 files changed, 175 insertions(+), 14 deletions(-) create mode 100644 test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate3/expected_result.json create mode 100644 test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate3/show_int_Gi1.txt create mode 100644 test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate3/show_lldp_neighbors.txt create mode 100644 test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate3/show_lldp_neighbors_Gi1_detail.txt create mode 100644 test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate3/show_lldp_neighbors_GigabitEthernet1_detail.txt diff --git a/napalm_ios/ios.py b/napalm_ios/ios.py index 069d940..f8c1c6c 100644 --- a/napalm_ios/ios.py +++ b/napalm_ios/ios.py @@ -616,15 +616,28 @@ def _lldp_detail_parser(self, interface): if '% Invalid input' in output: raise ValueError("Command not supported by network device") - port_id = re.findall(r"Port id:\s+(.+)", output) - port_description = re.findall(r"Port Description(?:\s\-|:)\s+(.+)", output) - chassis_id = re.findall(r"Chassis id:\s+(.+)", output) - system_name = re.findall(r"System Name\s*[:-]\s+(.+)", output) - system_description = re.findall(r"System Description:\s*\n(.+)", output) - system_capabilities = re.findall(r"System Capabilities:\s+(.+)", output) - enabled_capabilities = re.findall(r"Enabled Capabilities:\s+(.+)", output) - remote_address = re.findall(r"Management Addresses:\n\s+(?:IP|Other)(?::\s+?)(.+)", - output) + # Cisco generally use : for string divider, but sometimes has ' - ' + port_id = re.findall(r"Port id\s*?[:-]\s+(.+)", output) + port_description = re.findall(r"Port Description\s*?[:-]\s+(.+)", output) + chassis_id = re.findall(r"Chassis id\s*?[:-]\s+(.+)", output) + system_name = re.findall(r"System Name\s*?[:-]\s+(.+)", output) + system_description = re.findall(r"System Description\s*?[:-]\s*(not advertised|\s*\n.+)", + output) + system_description = [x.strip() for x in system_description] + system_capabilities = re.findall(r"System Capabilities\s*?[:-]\s+(.+)", output) + enabled_capabilities = re.findall(r"Enabled Capabilities\s*?[:-]\s+(.+)", output) + remote_address = re.findall(r"Management Addresses\s*[:-]\s*(not advertised|\n.+)", output) + # remote address had two possible patterns which required some secondary processing + new_remote_address = [] + for val in remote_address: + val = val.strip() + pattern = r'(?:IP|Other)(?::\s+?)(.+)' + match = re.search(pattern, val) + if match: + new_remote_address.append(match.group(1)) + else: + new_remote_address.append(val) + remote_address = new_remote_address return [port_id, port_description, chassis_id, system_name, system_description, system_capabilities, enabled_capabilities, remote_address] @@ -649,15 +662,10 @@ def get_lldp_neighbors_detail(self, interface=''): local_port = interface lldp_fields = self._lldp_detail_parser(interface) number_entries = len(lldp_fields[0]) - from pprint import pprint - pprint(local_port) - pprint(lldp_fields) - pprint(number_entries) # re.findall will return a list. Make sure same number of entries always returned. for test_list in lldp_fields: if len(test_list) != number_entries: - print(test_list) raise ValueError("Failure processing show lldp neighbors detail") # Standardize the fields diff --git a/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate3/expected_result.json b/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate3/expected_result.json new file mode 100644 index 0000000..8ff53f6 --- /dev/null +++ b/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate3/expected_result.json @@ -0,0 +1 @@ +{"GigabitEthernet1": [{"remote_port_description": "GigabitEthernet2/0", "remote_port": "Gi2/0", "remote_system_description": "Cisco IOS Software, vios_l2 Software (vios_l2-ADVENTERPRISEK9-M), Version 15.2(4.0.55)E, TEST ENGINEERING ESTG_WEEKLY BUILD, synced to END_OF_FLO_ISP", "remote_chassis_id": "00ae.3b11.1d00", "remote_system_name": "SW2.cisco.com", "parent_interface": "N/A", "remote_system_capab": "B,R", "remote_system_enable_capab": "R"}, {"remote_port_description": "not advertised", "remote_port": "0050.56c0.0001", "remote_system_description": "not advertised", "remote_chassis_id": "0050.56c0.0001", "remote_system_name": "not advertised", "parent_interface": "N/A", "remote_system_capab": "not advertised", "remote_system_enable_capab": "not advertised"}]} diff --git a/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate3/show_int_Gi1.txt b/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate3/show_int_Gi1.txt new file mode 100644 index 0000000..4d4e9c2 --- /dev/null +++ b/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate3/show_int_Gi1.txt @@ -0,0 +1,28 @@ +GigabitEthernet1 is up, line protocol is up + Hardware is CSR vNIC, address is 2cc2.603f.437a (bia 2cc2.603f.437a) + Internet address is 10.0.0.51/24 + MTU 1500 bytes, BW 1000000 Kbit/sec, DLY 10 usec, + reliability 198/255, txload 1/255, rxload 1/255 + Encapsulation ARPA, loopback not set + Keepalive set (10 sec) + Full Duplex, 1000Mbps, link type is auto, media type is RJ45 + output flow-control is unsupported, input flow-control is unsupported + ARP type: ARPA, ARP Timeout 04:00:00 + Last input 00:00:07, output 00:00:18, output hang never + Last clearing of "show interface" counters never + Input queue: 0/375/0/0 (size/max/drops/flushes); Total output drops: 0 + Queueing strategy: fifo + Output queue: 0/40 (size/max) + 5 minute input rate 1000 bits/sec, 1 packets/sec + 5 minute output rate 0 bits/sec, 0 packets/sec + 3815699 packets input, 275467675 bytes, 0 no buffer + Received 0 broadcasts (0 IP multicasts) + 0 runts, 0 giants, 0 throttles + 2610907 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored + 0 watchdog, 0 multicast, 0 pause input + 5249863 packets output, 384472234 bytes, 0 underruns + 0 output errors, 0 collisions, 0 interface resets + 11192 unknown protocol drops + 0 babbles, 0 late collision, 0 deferred + 0 lost carrier, 0 no carrier, 0 pause output + 0 output buffer failures, 0 output buffers swapped out diff --git a/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate3/show_lldp_neighbors.txt b/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate3/show_lldp_neighbors.txt new file mode 100644 index 0000000..7313180 --- /dev/null +++ b/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate3/show_lldp_neighbors.txt @@ -0,0 +1,10 @@ +Capability codes: + (R) Router, (B) Bridge, (T) Telephone, (C) DOCSIS Cable Device + (W) WLAN Access Point, (P) Repeater, (S) Station, (O) Other + +Device ID Local Intf Hold-time Capability Port ID +SW2.cisco.com Gi1 120 B,R Gi2/0 +not advertised Gi1 120 S Gi0/0 + +Total entries displayed: 2 + diff --git a/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate3/show_lldp_neighbors_Gi1_detail.txt b/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate3/show_lldp_neighbors_Gi1_detail.txt new file mode 100644 index 0000000..976ce93 --- /dev/null +++ b/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate3/show_lldp_neighbors_Gi1_detail.txt @@ -0,0 +1,57 @@ +------------------------------------------------ +Local Intf: Gi1 +Chassis id: 00ae.3b11.1d00 +Port id: Gi2/0 +Port Description: GigabitEthernet2/0 +System Name: SW2.cisco.com + +System Description: +Cisco IOS Software, vios_l2 Software (vios_l2-ADVENTERPRISEK9-M), Version 15.2(4.0.55)E, TEST ENGINEERING ESTG_WEEKLY BUILD, synced to END_OF_FLO_ISP +Technical Support: http://www.cisco.com/techsupport +Copyright (c) 1986-2015 by Cisco Systems, Inc. +Compi + +Time remaining: 108 seconds +System Capabilities: B,R +Enabled Capabilities: R +Management Addresses: + IP: 192.168.61.122 +Auto Negotiation - not supported +Physical media capabilities - not advertised +Media Attachment Unit type - not advertised +Vlan ID: - not advertised + +------------------------------------------------ +Local Intf: Gi1 +Chassis id: 0050.56c0.0001 +Port id: 0050.56c0.0001 +Port Description - not advertised +System Name - not advertised +System Description - not advertised + +Time remaining: 3514 seconds +System Capabilities - not advertised +Enabled Capabilities - not advertised +Management Addresses - not advertised +Auto Negotiation - supported, enabled +Physical media capabilities: + 1000baseT(FD) +Media Attachment Unit type - not advertised +Vlan ID: - not advertised + +MED Information: + + MED Codes: + (NP) Network Policy, (LI) Location Identification + (PS) Power Source Entity, (PD) Power Device + (IN) Inventory + + Inventory information - not advertised + Capabilities: + Device type: Endpoint Class I + Network Policies - not advertised + Power requirements - not advertised + Location - not advertised + + +Total entries displayed: 2 diff --git a/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate3/show_lldp_neighbors_GigabitEthernet1_detail.txt b/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate3/show_lldp_neighbors_GigabitEthernet1_detail.txt new file mode 100644 index 0000000..976ce93 --- /dev/null +++ b/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate3/show_lldp_neighbors_GigabitEthernet1_detail.txt @@ -0,0 +1,57 @@ +------------------------------------------------ +Local Intf: Gi1 +Chassis id: 00ae.3b11.1d00 +Port id: Gi2/0 +Port Description: GigabitEthernet2/0 +System Name: SW2.cisco.com + +System Description: +Cisco IOS Software, vios_l2 Software (vios_l2-ADVENTERPRISEK9-M), Version 15.2(4.0.55)E, TEST ENGINEERING ESTG_WEEKLY BUILD, synced to END_OF_FLO_ISP +Technical Support: http://www.cisco.com/techsupport +Copyright (c) 1986-2015 by Cisco Systems, Inc. +Compi + +Time remaining: 108 seconds +System Capabilities: B,R +Enabled Capabilities: R +Management Addresses: + IP: 192.168.61.122 +Auto Negotiation - not supported +Physical media capabilities - not advertised +Media Attachment Unit type - not advertised +Vlan ID: - not advertised + +------------------------------------------------ +Local Intf: Gi1 +Chassis id: 0050.56c0.0001 +Port id: 0050.56c0.0001 +Port Description - not advertised +System Name - not advertised +System Description - not advertised + +Time remaining: 3514 seconds +System Capabilities - not advertised +Enabled Capabilities - not advertised +Management Addresses - not advertised +Auto Negotiation - supported, enabled +Physical media capabilities: + 1000baseT(FD) +Media Attachment Unit type - not advertised +Vlan ID: - not advertised + +MED Information: + + MED Codes: + (NP) Network Policy, (LI) Location Identification + (PS) Power Source Entity, (PD) Power Device + (IN) Inventory + + Inventory information - not advertised + Capabilities: + Device type: Endpoint Class I + Network Policies - not advertised + Power requirements - not advertised + Location - not advertised + + +Total entries displayed: 2 From 20254229573a740fccd7fb16b3428ead19c875f2 Mon Sep 17 00:00:00 2001 From: Kirk Byers Date: Wed, 29 Mar 2017 21:49:27 -0700 Subject: [PATCH 15/27] Converting not advertised to N/A; making expected_result.json more readable --- napalm_ios/ios.py | 5 ++ .../alternate/expected_result.json | 2 +- .../alternate2/expected_result.json | 75 ++++++++++++++++++- .../alternate3/expected_result.json | 25 ++++++- 4 files changed, 104 insertions(+), 3 deletions(-) diff --git a/napalm_ios/ios.py b/napalm_ios/ios.py index f8c1c6c..5160d2c 100644 --- a/napalm_ios/ios.py +++ b/napalm_ios/ios.py @@ -661,6 +661,11 @@ def get_lldp_neighbors_detail(self, interface=''): for interface in lldp_neighbors: local_port = interface lldp_fields = self._lldp_detail_parser(interface) + # Convert any 'not advertised' to 'N/A' + for field in lldp_fields: + for i, value in enumerate(field): + if 'not advertised' in value: + field[i] = 'N/A' number_entries = len(lldp_fields[0]) # re.findall will return a list. Make sure same number of entries always returned. diff --git a/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate/expected_result.json b/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate/expected_result.json index 11b7563..ef2f0f7 100644 --- a/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate/expected_result.json +++ b/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate/expected_result.json @@ -4,7 +4,7 @@ "parent_interface": "N/A", "remote_chassis_id": "2cc2.603e.363b", "remote_port": "Management1", - "remote_port_description": "not advertised", + "remote_port_description": "N/A", "remote_system_capab": "B,R", "remote_system_description": "Arista Networks EOS version 4.15.2F running on an Arista Networks vEOS", "remote_system_enable_capab": "B,R", diff --git a/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate2/expected_result.json b/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate2/expected_result.json index 21b1c33..b730b31 100644 --- a/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate2/expected_result.json +++ b/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate2/expected_result.json @@ -1 +1,74 @@ -{"GigabitEthernet1": [{"remote_port_description": "ABCD-U1AC04-SW1", "parent_interface": "N/A", "remote_port": "Te2/1/14", "remote_system_enable_capab": "B", "remote_chassis_id": "0102.e2ff.fdb0", "remote_system_capab": "B,R", "remote_system_name": "ABCD-U-DSW1.wan.acme.com", "remote_system_description": "Cisco IOS Software, IOS-XE Software, Catalyst 4500 L3 Switch Software (cat4500e-UNIVERSALK9-M), Version 03.06.05.E RELEASE SOFTWARE (fc2)"}, {"remote_port_description": "ABCD-U1AC04-SW1", "parent_interface": "N/A", "remote_port": "Te1/1/14", "remote_system_enable_capab": "B", "remote_chassis_id": "0102.e2ff.fdb0", "remote_system_capab": "B,R", "remote_system_name": "ABCD-U-DSW1.wan.acme.com", "remote_system_description": "Cisco IOS Software, IOS-XE Software, Catalyst 4500 L3 Switch Software (cat4500e-UNIVERSALK9-M), Version 03.06.05.E RELEASE SOFTWARE (fc2)"}, {"remote_port_description": "not advertised", "parent_interface": "N/A", "remote_port": "port-001", "remote_system_enable_capab": "S", "remote_chassis_id": "hmbbkku-la", "remote_system_capab": "S", "remote_system_name": "HMBBKKU-LA", "remote_system_description": "Hewlett-Packard HP ProBook 650 G1,A3112DD10303,5CG4543H13 + engineering"}, {"remote_port_description": "not advertised", "parent_interface": "N/A", "remote_port": "port-001", "remote_system_enable_capab": "S", "remote_chassis_id": "jniceel-la", "remote_system_capab": "S", "remote_system_name": "JNICEEL-LA", "remote_system_description": "HP HP ProBook 650 G2,,5CG64565JFL + engineering"}, {"remote_port_description": "not advertised", "parent_interface": "N/A", "remote_port": "port-001", "remote_system_enable_capab": "S", "remote_chassis_id": "swaaaer-lta", "remote_system_capab": "S", "remote_system_name": "SWAAAER-LTA", "remote_system_description": "Hewlett-Packard HP ProBook 6570b,A10112D102,5CB40117ZP + engineering"}, {"remote_port_description": "not advertised", "parent_interface": "N/A", "remote_port": "port-001", "remote_system_enable_capab": "S", "remote_chassis_id": "rberrrann-lta", "remote_system_capab": "S", "remote_system_name": "RBERRRANN-LTA", "remote_system_description": "Hewlett-Packard HP ProBook 650 G1,A3112DD11203,CNU444BMZ0 + engineering"}, {"remote_port_description": "Siemens, SIMATIC NET, CP 343-1, 6GK7 443-1EX50-0XE0 , HW: 7, FW: V3.0.23, Ethernet Port, X1 P1", "parent_interface": "N/A", "remote_port": "port-001", "remote_system_enable_capab": "S", "remote_chassis_id": "cr-443-2", "remote_system_capab": "S", "remote_system_name": "not advertised", "remote_system_description": "Siemens, SIMATIC NET, CP 443-1, 6GK7 443-1EX50-0XE0, HW: Version 7, FW: Version V3.0.23, VPH6201262"}]} +{ + "GigabitEthernet1": [ + { + "parent_interface": "N/A", + "remote_chassis_id": "0102.e2ff.fdb0", + "remote_port": "Te2/1/14", + "remote_port_description": "ABCD-U1AC04-SW1", + "remote_system_capab": "B,R", + "remote_system_description": "Cisco IOS Software, IOS-XE Software, Catalyst 4500 L3 Switch Software (cat4500e-UNIVERSALK9-M), Version 03.06.05.E RELEASE SOFTWARE (fc2)", + "remote_system_enable_capab": "B", + "remote_system_name": "ABCD-U-DSW1.wan.acme.com" + }, + { + "parent_interface": "N/A", + "remote_chassis_id": "0102.e2ff.fdb0", + "remote_port": "Te1/1/14", + "remote_port_description": "ABCD-U1AC04-SW1", + "remote_system_capab": "B,R", + "remote_system_description": "Cisco IOS Software, IOS-XE Software, Catalyst 4500 L3 Switch Software (cat4500e-UNIVERSALK9-M), Version 03.06.05.E RELEASE SOFTWARE (fc2)", + "remote_system_enable_capab": "B", + "remote_system_name": "ABCD-U-DSW1.wan.acme.com" + }, + { + "parent_interface": "N/A", + "remote_chassis_id": "hmbbkku-la", + "remote_port": "port-001", + "remote_port_description": "N/A", + "remote_system_capab": "S", + "remote_system_description": "Hewlett-Packard HP ProBook 650 G1,A3112DD10303,5CG4543H13 + engineering", + "remote_system_enable_capab": "S", + "remote_system_name": "HMBBKKU-LA" + }, + { + "parent_interface": "N/A", + "remote_chassis_id": "jniceel-la", + "remote_port": "port-001", + "remote_port_description": "N/A", + "remote_system_capab": "S", + "remote_system_description": "HP HP ProBook 650 G2,,5CG64565JFL + engineering", + "remote_system_enable_capab": "S", + "remote_system_name": "JNICEEL-LA" + }, + { + "parent_interface": "N/A", + "remote_chassis_id": "swaaaer-lta", + "remote_port": "port-001", + "remote_port_description": "N/A", + "remote_system_capab": "S", + "remote_system_description": "Hewlett-Packard HP ProBook 6570b,A10112D102,5CB40117ZP + engineering", + "remote_system_enable_capab": "S", + "remote_system_name": "SWAAAER-LTA" + }, + { + "parent_interface": "N/A", + "remote_chassis_id": "rberrrann-lta", + "remote_port": "port-001", + "remote_port_description": "N/A", + "remote_system_capab": "S", + "remote_system_description": "Hewlett-Packard HP ProBook 650 G1,A3112DD11203,CNU444BMZ0 + engineering", + "remote_system_enable_capab": "S", + "remote_system_name": "RBERRRANN-LTA" + }, + { + "parent_interface": "N/A", + "remote_chassis_id": "cr-443-2", + "remote_port": "port-001", + "remote_port_description": "Siemens, SIMATIC NET, CP 343-1, 6GK7 443-1EX50-0XE0 , HW: 7, FW: V3.0.23, Ethernet Port, X1 P1", + "remote_system_capab": "S", + "remote_system_description": "Siemens, SIMATIC NET, CP 443-1, 6GK7 443-1EX50-0XE0, HW: Version 7, FW: Version V3.0.23, VPH6201262", + "remote_system_enable_capab": "S", + "remote_system_name": "N/A" + } + ] +} diff --git a/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate3/expected_result.json b/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate3/expected_result.json index 8ff53f6..f2ba3c3 100644 --- a/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate3/expected_result.json +++ b/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate3/expected_result.json @@ -1 +1,24 @@ -{"GigabitEthernet1": [{"remote_port_description": "GigabitEthernet2/0", "remote_port": "Gi2/0", "remote_system_description": "Cisco IOS Software, vios_l2 Software (vios_l2-ADVENTERPRISEK9-M), Version 15.2(4.0.55)E, TEST ENGINEERING ESTG_WEEKLY BUILD, synced to END_OF_FLO_ISP", "remote_chassis_id": "00ae.3b11.1d00", "remote_system_name": "SW2.cisco.com", "parent_interface": "N/A", "remote_system_capab": "B,R", "remote_system_enable_capab": "R"}, {"remote_port_description": "not advertised", "remote_port": "0050.56c0.0001", "remote_system_description": "not advertised", "remote_chassis_id": "0050.56c0.0001", "remote_system_name": "not advertised", "parent_interface": "N/A", "remote_system_capab": "not advertised", "remote_system_enable_capab": "not advertised"}]} +{ + "GigabitEthernet1": [ + { + "parent_interface": "N/A", + "remote_chassis_id": "00ae.3b11.1d00", + "remote_port": "Gi2/0", + "remote_port_description": "GigabitEthernet2/0", + "remote_system_capab": "B,R", + "remote_system_description": "Cisco IOS Software, vios_l2 Software (vios_l2-ADVENTERPRISEK9-M), Version 15.2(4.0.55)E, TEST ENGINEERING ESTG_WEEKLY BUILD, synced to END_OF_FLO_ISP", + "remote_system_enable_capab": "R", + "remote_system_name": "SW2.cisco.com" + }, + { + "parent_interface": "N/A", + "remote_chassis_id": "0050.56c0.0001", + "remote_port": "0050.56c0.0001", + "remote_port_description": "N/A", + "remote_system_capab": "N/A", + "remote_system_description": "N/A", + "remote_system_enable_capab": "N/A", + "remote_system_name": "N/A" + } + ] +} From bd241a2870c882d100b12fa2c1433eb628d0d4ed Mon Sep 17 00:00:00 2001 From: Kirk Byers Date: Thu, 30 Mar 2017 10:22:27 -0700 Subject: [PATCH 16/27] Improving LLDP mocked_data for unit tests --- .../alternate/expected_result.json | 10 +++++++ .../alternate/show_int_Gi1.txt | 28 +++++++++++++++++ .../alternate/show_int_Gi2.txt | 30 +++++++++++++++++++ .../alternate/show_lldp_neighbors.txt | 10 +++++++ .../alternate3/show_lldp_neighbors.txt | 4 +-- 5 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 test/unit/mocked_data/test_get_lldp_neighbors/alternate/expected_result.json create mode 100644 test/unit/mocked_data/test_get_lldp_neighbors/alternate/show_int_Gi1.txt create mode 100644 test/unit/mocked_data/test_get_lldp_neighbors/alternate/show_int_Gi2.txt create mode 100644 test/unit/mocked_data/test_get_lldp_neighbors/alternate/show_lldp_neighbors.txt diff --git a/test/unit/mocked_data/test_get_lldp_neighbors/alternate/expected_result.json b/test/unit/mocked_data/test_get_lldp_neighbors/alternate/expected_result.json new file mode 100644 index 0000000..7c56640 --- /dev/null +++ b/test/unit/mocked_data/test_get_lldp_neighbors/alternate/expected_result.json @@ -0,0 +1,10 @@ +{ + "GigabitEthernet1": [{ + "port": "Gi2/0", + "hostname": "SW2.cisco.com" + }], + "GigabitEthernet2": [{ + "port": "0050.56c0.0001", + "hostname": "0050.56c0.0001" + }] +} diff --git a/test/unit/mocked_data/test_get_lldp_neighbors/alternate/show_int_Gi1.txt b/test/unit/mocked_data/test_get_lldp_neighbors/alternate/show_int_Gi1.txt new file mode 100644 index 0000000..2b6cdc9 --- /dev/null +++ b/test/unit/mocked_data/test_get_lldp_neighbors/alternate/show_int_Gi1.txt @@ -0,0 +1,28 @@ +GigabitEthernet1 is up, line protocol is up + Hardware is CSR vNIC, address is 0800.27f8.e842 (bia 0800.27f8.e842) + Internet address is 10.0.2.15/24 + MTU 1500 bytes, BW 1000000 Kbit/sec, DLY 10 usec, + reliability 255/255, txload 1/255, rxload 1/255 + Encapsulation ARPA, loopback not set + Keepalive set (10 sec) + Full Duplex, 1000Mbps, link type is auto, media type is RJ45 + output flow-control is unsupported, input flow-control is unsupported + ARP type: ARPA, ARP Timeout 04:00:00 + Last input 00:42:01, output 00:00:05, output hang never + Last clearing of "show interface" counters never + Input queue: 0/375/0/0 (size/max/drops/flushes); Total output drops: 0 + Queueing strategy: fifo + Output queue: 0/40 (size/max) + 5 minute input rate 1000 bits/sec, 1 packets/sec + 5 minute output rate 1000 bits/sec, 1 packets/sec + 14028 packets input, 1766902 bytes, 0 no buffer + Received 0 broadcasts (0 IP multicasts) + 0 runts, 0 giants, 0 throttles + 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored + 0 watchdog, 0 multicast, 0 pause input + 9446 packets output, 1379617 bytes, 0 underruns + 0 output errors, 0 collisions, 0 interface resets + 0 unknown protocol drops + 0 babbles, 0 late collision, 0 deferred + 0 lost carrier, 0 no carrier, 0 pause output + 0 output buffer failures, 0 output buffers swapped out diff --git a/test/unit/mocked_data/test_get_lldp_neighbors/alternate/show_int_Gi2.txt b/test/unit/mocked_data/test_get_lldp_neighbors/alternate/show_int_Gi2.txt new file mode 100644 index 0000000..ef18819 --- /dev/null +++ b/test/unit/mocked_data/test_get_lldp_neighbors/alternate/show_int_Gi2.txt @@ -0,0 +1,30 @@ +GigabitEthernet2 is up, line protocol is up + Hardware is CSR vNIC, address is 0800.2779.e896 (bia 0800.2779.e896) + Description: blah bleh + Internet address is 192.168.0.1/24 + MTU 1500 bytes, BW 1000000 Kbit/sec, DLY 10 usec, + reliability 255/255, txload 1/255, rxload 1/255 + Encapsulation ARPA, loopback not set + Keepalive set (10 sec) + Full Duplex, 1000Mbps, link type is auto, media type is RJ45 + output flow-control is unsupported, input flow-control is unsupported + ARP type: ARPA, ARP Timeout 04:00:00 + Last input 00:00:04, output 00:00:05, output hang never + Last clearing of "show interface" counters never + Input queue: 0/375/0/0 (size/max/drops/flushes); Total output drops: 0 + Queueing strategy: fifo + Output queue: 0/40 (size/max) + 5 minute input rate 0 bits/sec, 0 packets/sec + 5 minute output rate 0 bits/sec, 0 packets/sec + 118 packets input, 11502 bytes, 0 no buffer + Received 0 broadcasts (0 IP multicasts) + 0 runts, 0 giants, 0 throttles + 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored + 0 watchdog, 0 multicast, 0 pause input + 177 packets output, 19267 bytes, 0 underruns + 0 output errors, 0 collisions, 1 interface resets + 0 unknown protocol drops + 0 babbles, 0 late collision, 0 deferred + 0 lost carrier, 0 no carrier, 0 pause output + 0 output buffer failures, 0 output buffers swapped out + diff --git a/test/unit/mocked_data/test_get_lldp_neighbors/alternate/show_lldp_neighbors.txt b/test/unit/mocked_data/test_get_lldp_neighbors/alternate/show_lldp_neighbors.txt new file mode 100644 index 0000000..b6557b4 --- /dev/null +++ b/test/unit/mocked_data/test_get_lldp_neighbors/alternate/show_lldp_neighbors.txt @@ -0,0 +1,10 @@ +Capability codes: + (R) Router, (B) Bridge, (T) Telephone, (C) DOCSIS Cable Device + (W) WLAN Access Point, (P) Repeater, (S) Station, (O) Other + +Device ID Local Intf Hold-time Capability Port ID +SW2.cisco.com Gi1 120 R Gi2/0 +0050.56c0.0001 Gi2 3601 0050.56c0.0001 + +Total entries displayed: 2 + diff --git a/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate3/show_lldp_neighbors.txt b/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate3/show_lldp_neighbors.txt index 7313180..c8e6245 100644 --- a/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate3/show_lldp_neighbors.txt +++ b/test/unit/mocked_data/test_get_lldp_neighbors_detail/alternate3/show_lldp_neighbors.txt @@ -3,8 +3,8 @@ Capability codes: (W) WLAN Access Point, (P) Repeater, (S) Station, (O) Other Device ID Local Intf Hold-time Capability Port ID -SW2.cisco.com Gi1 120 B,R Gi2/0 -not advertised Gi1 120 S Gi0/0 +SW2.cisco.com Gi1 120 R Gi2/0 +0050.56c0.0001 Gi1 3601 0050.56c0.0001 Total entries displayed: 2 From 12711c1c0d6dc19ae4ab4cd9140786a1904b0ed4 Mon Sep 17 00:00:00 2001 From: kaage Date: Fri, 31 Mar 2017 21:51:28 +0300 Subject: [PATCH 17/27] Implements new getter: get_optics --- napalm_ios/ios.py | 63 +++++++++++++++++++ .../normal/expected_result.json | 56 +++++++++++++++++ .../normal/show_int_Te1_0_1.txt | 29 +++++++++ .../normal/show_int_Te2_0_1.txt | 29 +++++++++ .../normal/show_interfaces_transceiver.txt | 11 ++++ 5 files changed, 188 insertions(+) create mode 100644 test/unit/mocked_data/test_get_optics/normal/expected_result.json create mode 100644 test/unit/mocked_data/test_get_optics/normal/show_int_Te1_0_1.txt create mode 100644 test/unit/mocked_data/test_get_optics/normal/show_int_Te2_0_1.txt create mode 100644 test/unit/mocked_data/test_get_optics/normal/show_interfaces_transceiver.txt diff --git a/napalm_ios/ios.py b/napalm_ios/ios.py index 881f93f..5f1341f 100644 --- a/napalm_ios/ios.py +++ b/napalm_ios/ios.py @@ -560,6 +560,69 @@ def _send_command_postprocess(output): output = re.sub(r"^Time source is .*$", "", output, flags=re.M) return output.strip() + def get_optics(self): + command = 'show interfaces transceiver' + output = self._send_command(command) + + # Check if router supports the command + if '% Invalid input' in output: + return {} + + # Formatting data into return data structure + optics_detail = {} + + try: + split_output = re.split(r'^---------.*$', output, flags=re.M)[1] + except IndexError: + return {} + + split_output = split_output.strip() + + for optics_entry in split_output.splitlines(): + # Example, Te1/0/1 34.6 3.29 -2.0 -3.5 + try: + int_brief, temperature, voltage, output_power, input_power = optics_entry.split() + except ValueError: + return {} + + port = self._expand_interface_name(int_brief) + + port_detail = {} + + port_detail['physical_channels'] = {} + port_detail['physical_channels']['channel'] = [] + + # Defaulting avg, min, max values to 0.0 since device does not + # return these values + optic_states = { + 'index': 0, + 'state': { + 'input_power': { + 'instant': (float(input_power) if 'input_power' else 0.0), + 'avg': 0.0, + 'min': 0.0, + 'max': 0.0 + }, + 'output_power': { + 'instant': (float(output_power) if 'output_power' else 0.0), + 'avg': 0.0, + 'min': 0.0, + 'max': 0.0 + }, + 'laser_bias_current': { + 'instant': 0.0, + 'avg': 0.0, + 'min': 0.0, + 'max': 0.0 + } + } + } + + port_detail['physical_channels']['channel'].append(optic_states) + optics_detail[port] = port_detail + + return optics_detail + def get_lldp_neighbors(self): """IOS implementation of get_lldp_neighbors.""" lldp = {} diff --git a/test/unit/mocked_data/test_get_optics/normal/expected_result.json b/test/unit/mocked_data/test_get_optics/normal/expected_result.json new file mode 100644 index 0000000..133fe6a --- /dev/null +++ b/test/unit/mocked_data/test_get_optics/normal/expected_result.json @@ -0,0 +1,56 @@ +{ + "TenGigabitEthernet1/0/1": { + "physical_channels": { + "channel": [{ + "index": 0, + "state": { + "output_power": { + "max": 0.0, + "avg": 0.0, + "instant": -2.0, + "min": 0.0 + }, + "laser_bias_current": { + "max": 0.0, + "avg": 0.0, + "instant": 0.0, + "min": 0.0 + }, + "input_power": { + "max": 0.0, + "avg": 0.0, + "instant": -3.5, + "min": 0.0 + } + } + }] + } + }, + "TenGigabitEthernet2/0/1": { + "physical_channels": { + "channel": [{ + "index": 0, + "state": { + "output_power": { + "max": 0.0, + "avg": 0.0, + "instant": -2.0, + "min": 0.0 + }, + "laser_bias_current": { + "max": 0.0, + "avg": 0.0, + "instant": 0.0, + "min": 0.0 + }, + "input_power": { + "max": 0.0, + "avg": 0.0, + "instant": -2.5, + "min": 0.0 + } + } + }] + } + } +} diff --git a/test/unit/mocked_data/test_get_optics/normal/show_int_Te1_0_1.txt b/test/unit/mocked_data/test_get_optics/normal/show_int_Te1_0_1.txt new file mode 100644 index 0000000..1401d5a --- /dev/null +++ b/test/unit/mocked_data/test_get_optics/normal/show_int_Te1_0_1.txt @@ -0,0 +1,29 @@ +TenGigabitEthernet1/0/1 is up, line protocol is up (connected) + Hardware is Ten Gigabit Ethernet, address is 0042.5a67.0e9b (bia 0042.5a67.0e9b) + Description: Uplink-to-DSW1 + MTU 1500 bytes, BW 10000000 Kbit/sec, DLY 10 usec, + reliability 255/255, txload 1/255, rxload 1/255 + Encapsulation ARPA, loopback not set + Keepalive not set + Full-duplex, 10Gb/s, link type is auto, media type is SFP-10GBase-LRM + input flow-control is off, output flow-control is unsupported + ARP type: ARPA, ARP Timeout 04:00:00 + Last input 00:00:02, output 00:00:04, output hang never + Last clearing of "show interface" counters never + Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0 + Queueing strategy: fifo + Output queue: 0/40 (size/max) + 5 minute input rate 61000 bits/sec, 52 packets/sec + 5 minute output rate 59000 bits/sec, 63 packets/sec + 13525429 packets input, 1636789604 bytes, 0 no buffer + Received 2388654 broadcasts (578107 multicasts) + 0 runts, 0 giants, 0 throttles + 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored + 0 watchdog, 578107 multicast, 0 pause input + 0 input packets with dribble condition detected + 7831375 packets output, 870124569 bytes, 0 underruns + 0 output errors, 0 collisions, 1 interface resets + 0 unknown protocol drops + 0 babbles, 0 late collision, 0 deferred + 0 lost carrier, 0 no carrier, 0 pause output + 0 output buffer failures, 0 output buffers swapped out \ No newline at end of file diff --git a/test/unit/mocked_data/test_get_optics/normal/show_int_Te2_0_1.txt b/test/unit/mocked_data/test_get_optics/normal/show_int_Te2_0_1.txt new file mode 100644 index 0000000..c06a5cf --- /dev/null +++ b/test/unit/mocked_data/test_get_optics/normal/show_int_Te2_0_1.txt @@ -0,0 +1,29 @@ +TenGigabitEthernet2/0/1 is up, line protocol is up (connected) + Hardware is Ten Gigabit Ethernet, address is 0042.5a8d.d91b (bia 0042.5a8d.d91b) + Description: Uplink-to-DSW2 + MTU 1500 bytes, BW 10000000 Kbit/sec, DLY 10 usec, + reliability 255/255, txload 1/255, rxload 1/255 + Encapsulation ARPA, loopback not set + Keepalive not set + Full-duplex, 10Gb/s, link type is auto, media type is SFP-10GBase-LRM + input flow-control is off, output flow-control is unsupported + ARP type: ARPA, ARP Timeout 04:00:00 + Last input 00:00:29, output 00:00:01, output hang never + Last clearing of "show interface" counters never + Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0 + Queueing strategy: fifo + Output queue: 0/40 (size/max) + 5 minute input rate 187000 bits/sec, 135 packets/sec + 5 minute output rate 181000 bits/sec, 113 packets/sec + 21192627 packets input, 4732793131 bytes, 0 no buffer + Received 1625861 broadcasts (279957 multicasts) + 0 runts, 0 giants, 0 throttles + 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored + 0 watchdog, 279957 multicast, 0 pause input + 0 input packets with dribble condition detected + 27963853 packets output, 3954071411 bytes, 0 underruns + 0 output errors, 0 collisions, 1 interface resets + 0 unknown protocol drops + 0 babbles, 0 late collision, 0 deferred + 0 lost carrier, 0 no carrier, 0 pause output + 0 output buffer failures, 0 output buffers swapped out \ No newline at end of file diff --git a/test/unit/mocked_data/test_get_optics/normal/show_interfaces_transceiver.txt b/test/unit/mocked_data/test_get_optics/normal/show_interfaces_transceiver.txt new file mode 100644 index 0000000..fd92124 --- /dev/null +++ b/test/unit/mocked_data/test_get_optics/normal/show_interfaces_transceiver.txt @@ -0,0 +1,11 @@ +If device is externally calibrated, only calibrated values are printed. +++ : high alarm, + : high warning, - : low warning, -- : low alarm. +NA or N/A: not applicable, Tx: transmit, Rx: receive. +mA: milliamperes, dBm: decibels (milliwatts). + + Optical Optical + Temperature Voltage Tx Power Rx Power +Port (Celsius) (Volts) (dBm) (dBm) +--------- ----------- ------- -------- -------- +Te1/0/1 34.6 3.29 -2.0 -3.5 +Te2/0/1 34.3 3.28 -2.0 -2.5 \ No newline at end of file From d32e105ecdaf5b6551e270a3bae2ebd231b7899b Mon Sep 17 00:00:00 2001 From: Kirk Byers Date: Fri, 31 Mar 2017 13:50:55 -0700 Subject: [PATCH 18/27] Set zip_safe=False; fix old references in unit test --- setup.py | 1 + test/unit/TestIOSDriver.py | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 7032080..fab6c4b 100644 --- a/setup.py +++ b/setup.py @@ -24,5 +24,6 @@ ], url="https://github.com/napalm-automation/napalm-ios", include_package_data=True, + zip_safe=False, install_requires=reqs, ) diff --git a/test/unit/TestIOSDriver.py b/test/unit/TestIOSDriver.py index 557a411..6220613 100755 --- a/test/unit/TestIOSDriver.py +++ b/test/unit/TestIOSDriver.py @@ -91,16 +91,16 @@ def test_ios_only_confirm(self): def test_ios_only_gen_full_path(self): """Test gen_full_path() method.""" - output = self.device.gen_full_path(self.device.candidate_cfg) + output = self.device._gen_full_path(self.device.candidate_cfg) self.assertEqual(output, self.device.dest_file_system + '/candidate_config.txt') - output = self.device.gen_full_path(self.device.rollback_cfg) + output = self.device._gen_full_path(self.device.rollback_cfg) self.assertEqual(output, self.device.dest_file_system + '/rollback_config.txt') - output = self.device.gen_full_path(self.device.merge_cfg) + output = self.device._gen_full_path(self.device.merge_cfg) self.assertEqual(output, self.device.dest_file_system + '/merge_config.txt') - output = self.device.gen_full_path(filename='running-config', file_system='system:') + output = self.device._gen_full_path(filename='running-config', file_system='system:') self.assertEqual(output, 'system:/running-config') def test_ios_only_check_file_exists(self): From d0f4af59bd3d212d1cd59db1f648eebe63f16901 Mon Sep 17 00:00:00 2001 From: kaage Date: Tue, 4 Apr 2017 21:55:22 +0300 Subject: [PATCH 19/27] Modifications to get_optics to survive from N/A output power value --- napalm_ios/ios.py | 7 +++ .../interface_shutdown/expected_result.json | 56 +++++++++++++++++++ .../interface_shutdown/show_int_Te1_0_1.txt | 29 ++++++++++ .../interface_shutdown/show_int_Te2_0_1.txt | 29 ++++++++++ .../show_interfaces_transceiver.txt | 11 ++++ 5 files changed, 132 insertions(+) create mode 100644 test/unit/mocked_data/test_get_optics/interface_shutdown/expected_result.json create mode 100644 test/unit/mocked_data/test_get_optics/interface_shutdown/show_int_Te1_0_1.txt create mode 100644 test/unit/mocked_data/test_get_optics/interface_shutdown/show_int_Te2_0_1.txt create mode 100644 test/unit/mocked_data/test_get_optics/interface_shutdown/show_interfaces_transceiver.txt diff --git a/napalm_ios/ios.py b/napalm_ios/ios.py index 5f1341f..9a9b6ab 100644 --- a/napalm_ios/ios.py +++ b/napalm_ios/ios.py @@ -592,6 +592,13 @@ def get_optics(self): port_detail['physical_channels'] = {} port_detail['physical_channels']['channel'] = [] + # If interface is shutdown it returns "N/A" as output power. + # Converting that to -40.0 float + try: + float(output_power) + except ValueError: + output_power = -40.0 + # Defaulting avg, min, max values to 0.0 since device does not # return these values optic_states = { diff --git a/test/unit/mocked_data/test_get_optics/interface_shutdown/expected_result.json b/test/unit/mocked_data/test_get_optics/interface_shutdown/expected_result.json new file mode 100644 index 0000000..564b09f --- /dev/null +++ b/test/unit/mocked_data/test_get_optics/interface_shutdown/expected_result.json @@ -0,0 +1,56 @@ +{ + "TenGigabitEthernet1/0/1": { + "physical_channels": { + "channel": [{ + "index": 0, + "state": { + "output_power": { + "max": 0.0, + "avg": 0.0, + "instant": -2.0, + "min": 0.0 + }, + "laser_bias_current": { + "max": 0.0, + "avg": 0.0, + "instant": 0.0, + "min": 0.0 + }, + "input_power": { + "max": 0.0, + "avg": 0.0, + "instant": -3.5, + "min": 0.0 + } + } + }] + } + }, + "TenGigabitEthernet2/0/1": { + "physical_channels": { + "channel": [{ + "index": 0, + "state": { + "output_power": { + "max": 0.0, + "avg": 0.0, + "instant": -40.0, + "min": 0.0 + }, + "laser_bias_current": { + "max": 0.0, + "avg": 0.0, + "instant": 0.0, + "min": 0.0 + }, + "input_power": { + "max": 0.0, + "avg": 0.0, + "instant": -40.0, + "min": 0.0 + } + } + }] + } + } +} diff --git a/test/unit/mocked_data/test_get_optics/interface_shutdown/show_int_Te1_0_1.txt b/test/unit/mocked_data/test_get_optics/interface_shutdown/show_int_Te1_0_1.txt new file mode 100644 index 0000000..1401d5a --- /dev/null +++ b/test/unit/mocked_data/test_get_optics/interface_shutdown/show_int_Te1_0_1.txt @@ -0,0 +1,29 @@ +TenGigabitEthernet1/0/1 is up, line protocol is up (connected) + Hardware is Ten Gigabit Ethernet, address is 0042.5a67.0e9b (bia 0042.5a67.0e9b) + Description: Uplink-to-DSW1 + MTU 1500 bytes, BW 10000000 Kbit/sec, DLY 10 usec, + reliability 255/255, txload 1/255, rxload 1/255 + Encapsulation ARPA, loopback not set + Keepalive not set + Full-duplex, 10Gb/s, link type is auto, media type is SFP-10GBase-LRM + input flow-control is off, output flow-control is unsupported + ARP type: ARPA, ARP Timeout 04:00:00 + Last input 00:00:02, output 00:00:04, output hang never + Last clearing of "show interface" counters never + Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0 + Queueing strategy: fifo + Output queue: 0/40 (size/max) + 5 minute input rate 61000 bits/sec, 52 packets/sec + 5 minute output rate 59000 bits/sec, 63 packets/sec + 13525429 packets input, 1636789604 bytes, 0 no buffer + Received 2388654 broadcasts (578107 multicasts) + 0 runts, 0 giants, 0 throttles + 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored + 0 watchdog, 578107 multicast, 0 pause input + 0 input packets with dribble condition detected + 7831375 packets output, 870124569 bytes, 0 underruns + 0 output errors, 0 collisions, 1 interface resets + 0 unknown protocol drops + 0 babbles, 0 late collision, 0 deferred + 0 lost carrier, 0 no carrier, 0 pause output + 0 output buffer failures, 0 output buffers swapped out \ No newline at end of file diff --git a/test/unit/mocked_data/test_get_optics/interface_shutdown/show_int_Te2_0_1.txt b/test/unit/mocked_data/test_get_optics/interface_shutdown/show_int_Te2_0_1.txt new file mode 100644 index 0000000..c06a5cf --- /dev/null +++ b/test/unit/mocked_data/test_get_optics/interface_shutdown/show_int_Te2_0_1.txt @@ -0,0 +1,29 @@ +TenGigabitEthernet2/0/1 is up, line protocol is up (connected) + Hardware is Ten Gigabit Ethernet, address is 0042.5a8d.d91b (bia 0042.5a8d.d91b) + Description: Uplink-to-DSW2 + MTU 1500 bytes, BW 10000000 Kbit/sec, DLY 10 usec, + reliability 255/255, txload 1/255, rxload 1/255 + Encapsulation ARPA, loopback not set + Keepalive not set + Full-duplex, 10Gb/s, link type is auto, media type is SFP-10GBase-LRM + input flow-control is off, output flow-control is unsupported + ARP type: ARPA, ARP Timeout 04:00:00 + Last input 00:00:29, output 00:00:01, output hang never + Last clearing of "show interface" counters never + Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0 + Queueing strategy: fifo + Output queue: 0/40 (size/max) + 5 minute input rate 187000 bits/sec, 135 packets/sec + 5 minute output rate 181000 bits/sec, 113 packets/sec + 21192627 packets input, 4732793131 bytes, 0 no buffer + Received 1625861 broadcasts (279957 multicasts) + 0 runts, 0 giants, 0 throttles + 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored + 0 watchdog, 279957 multicast, 0 pause input + 0 input packets with dribble condition detected + 27963853 packets output, 3954071411 bytes, 0 underruns + 0 output errors, 0 collisions, 1 interface resets + 0 unknown protocol drops + 0 babbles, 0 late collision, 0 deferred + 0 lost carrier, 0 no carrier, 0 pause output + 0 output buffer failures, 0 output buffers swapped out \ No newline at end of file diff --git a/test/unit/mocked_data/test_get_optics/interface_shutdown/show_interfaces_transceiver.txt b/test/unit/mocked_data/test_get_optics/interface_shutdown/show_interfaces_transceiver.txt new file mode 100644 index 0000000..38d0529 --- /dev/null +++ b/test/unit/mocked_data/test_get_optics/interface_shutdown/show_interfaces_transceiver.txt @@ -0,0 +1,11 @@ +If device is externally calibrated, only calibrated values are printed. +++ : high alarm, + : high warning, - : low warning, -- : low alarm. +NA or N/A: not applicable, Tx: transmit, Rx: receive. +mA: milliamperes, dBm: decibels (milliwatts). + + Optical Optical + Temperature Voltage Tx Power Rx Power +Port (Celsius) (Volts) (dBm) (dBm) +--------- ----------- ------- -------- -------- +Te1/0/1 34.6 3.29 -2.0 -3.5 +Te2/0/1 34.3 3.28 N/A -40.0 \ No newline at end of file From 7f2f76c5430407d25541ce83f9730eacd50c439a Mon Sep 17 00:00:00 2001 From: Kirk Byers Date: Fri, 31 Mar 2017 13:50:55 -0700 Subject: [PATCH 20/27] Set zip_safe=False; fix old references in unit test --- setup.py | 1 + test/unit/TestIOSDriver.py | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 7032080..fab6c4b 100644 --- a/setup.py +++ b/setup.py @@ -24,5 +24,6 @@ ], url="https://github.com/napalm-automation/napalm-ios", include_package_data=True, + zip_safe=False, install_requires=reqs, ) diff --git a/test/unit/TestIOSDriver.py b/test/unit/TestIOSDriver.py index 557a411..6220613 100755 --- a/test/unit/TestIOSDriver.py +++ b/test/unit/TestIOSDriver.py @@ -91,16 +91,16 @@ def test_ios_only_confirm(self): def test_ios_only_gen_full_path(self): """Test gen_full_path() method.""" - output = self.device.gen_full_path(self.device.candidate_cfg) + output = self.device._gen_full_path(self.device.candidate_cfg) self.assertEqual(output, self.device.dest_file_system + '/candidate_config.txt') - output = self.device.gen_full_path(self.device.rollback_cfg) + output = self.device._gen_full_path(self.device.rollback_cfg) self.assertEqual(output, self.device.dest_file_system + '/rollback_config.txt') - output = self.device.gen_full_path(self.device.merge_cfg) + output = self.device._gen_full_path(self.device.merge_cfg) self.assertEqual(output, self.device.dest_file_system + '/merge_config.txt') - output = self.device.gen_full_path(filename='running-config', file_system='system:') + output = self.device._gen_full_path(filename='running-config', file_system='system:') self.assertEqual(output, 'system:/running-config') def test_ios_only_check_file_exists(self): From 5528049d96048476d3df37580c856d16a8e096e2 Mon Sep 17 00:00:00 2001 From: Kirk Byers Date: Thu, 20 Apr 2017 09:58:13 -0700 Subject: [PATCH 21/27] Fixing infinite value to -100 in get_optics --- napalm_ios/ios.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/napalm_ios/ios.py b/napalm_ios/ios.py index 9a9b6ab..2295055 100644 --- a/napalm_ios/ios.py +++ b/napalm_ios/ios.py @@ -593,11 +593,11 @@ def get_optics(self): port_detail['physical_channels']['channel'] = [] # If interface is shutdown it returns "N/A" as output power. - # Converting that to -40.0 float + # Converting that to -100.0 float try: float(output_power) except ValueError: - output_power = -40.0 + output_power = -100.0 # Defaulting avg, min, max values to 0.0 since device does not # return these values From bb55267ea926a53fc054dcc01fab4a64a0a6f735 Mon Sep 17 00:00:00 2001 From: Kirk Byers Date: Thu, 20 Apr 2017 09:58:52 -0700 Subject: [PATCH 22/27] Fixing infinite value to -100 in get_optics --- .../test_get_optics/interface_shutdown/expected_result.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/mocked_data/test_get_optics/interface_shutdown/expected_result.json b/test/unit/mocked_data/test_get_optics/interface_shutdown/expected_result.json index 564b09f..eb6f970 100644 --- a/test/unit/mocked_data/test_get_optics/interface_shutdown/expected_result.json +++ b/test/unit/mocked_data/test_get_optics/interface_shutdown/expected_result.json @@ -34,7 +34,7 @@ "output_power": { "max": 0.0, "avg": 0.0, - "instant": -40.0, + "instant": -100.0, "min": 0.0 }, "laser_bias_current": { From 542c3572ac5d0a269c76895c8c727e0ca7109792 Mon Sep 17 00:00:00 2001 From: kaage Date: Thu, 20 Apr 2017 21:10:50 +0300 Subject: [PATCH 23/27] Modified infinite value of optical powers from -40 to -100 --- napalm_ios/ios.py | 22 ++++++++-------- .../interface_shutdown/expected_result.json | 26 +++++++++---------- .../normal/expected_result.json | 24 ++++++++--------- 3 files changed, 36 insertions(+), 36 deletions(-) diff --git a/napalm_ios/ios.py b/napalm_ios/ios.py index 9a9b6ab..a4a6f6e 100644 --- a/napalm_ios/ios.py +++ b/napalm_ios/ios.py @@ -593,28 +593,28 @@ def get_optics(self): port_detail['physical_channels']['channel'] = [] # If interface is shutdown it returns "N/A" as output power. - # Converting that to -40.0 float + # Converting that to -100.0 float try: float(output_power) except ValueError: - output_power = -40.0 + output_power = -100.0 - # Defaulting avg, min, max values to 0.0 since device does not + # Defaulting avg, min, max values to -100.0 since device does not # return these values optic_states = { 'index': 0, 'state': { 'input_power': { - 'instant': (float(input_power) if 'input_power' else 0.0), - 'avg': 0.0, - 'min': 0.0, - 'max': 0.0 + 'instant': (float(input_power) if 'input_power' else -100.0), + 'avg': -100.0, + 'min': -100.0, + 'max': -100.0 }, 'output_power': { - 'instant': (float(output_power) if 'output_power' else 0.0), - 'avg': 0.0, - 'min': 0.0, - 'max': 0.0 + 'instant': (float(output_power) if 'output_power' else -100.0), + 'avg': -100.0, + 'min': -100.0, + 'max': -100.0 }, 'laser_bias_current': { 'instant': 0.0, diff --git a/test/unit/mocked_data/test_get_optics/interface_shutdown/expected_result.json b/test/unit/mocked_data/test_get_optics/interface_shutdown/expected_result.json index 564b09f..613163d 100644 --- a/test/unit/mocked_data/test_get_optics/interface_shutdown/expected_result.json +++ b/test/unit/mocked_data/test_get_optics/interface_shutdown/expected_result.json @@ -5,10 +5,10 @@ "index": 0, "state": { "output_power": { - "max": 0.0, - "avg": 0.0, + "max": -100.0, + "avg": -100.0, "instant": -2.0, - "min": 0.0 + "min": -100.0 }, "laser_bias_current": { "max": 0.0, @@ -17,10 +17,10 @@ "min": 0.0 }, "input_power": { - "max": 0.0, - "avg": 0.0, + "max": -100.0, + "avg": -100.0, "instant": -3.5, - "min": 0.0 + "min": -100.0 } } }] @@ -32,10 +32,10 @@ "index": 0, "state": { "output_power": { - "max": 0.0, - "avg": 0.0, - "instant": -40.0, - "min": 0.0 + "max": -100.0, + "avg": -100.0, + "instant": -100.0, + "min": -100.0 }, "laser_bias_current": { "max": 0.0, @@ -44,10 +44,10 @@ "min": 0.0 }, "input_power": { - "max": 0.0, - "avg": 0.0, + "max": -100.0, + "avg": -100.0, "instant": -40.0, - "min": 0.0 + "min": -100.0 } } }] diff --git a/test/unit/mocked_data/test_get_optics/normal/expected_result.json b/test/unit/mocked_data/test_get_optics/normal/expected_result.json index 133fe6a..7ebd68a 100644 --- a/test/unit/mocked_data/test_get_optics/normal/expected_result.json +++ b/test/unit/mocked_data/test_get_optics/normal/expected_result.json @@ -5,10 +5,10 @@ "index": 0, "state": { "output_power": { - "max": 0.0, - "avg": 0.0, + "max": -100.0, + "avg": -100.0, "instant": -2.0, - "min": 0.0 + "min": -100.0 }, "laser_bias_current": { "max": 0.0, @@ -17,10 +17,10 @@ "min": 0.0 }, "input_power": { - "max": 0.0, - "avg": 0.0, + "max": -100.0, + "avg": -100.0, "instant": -3.5, - "min": 0.0 + "min": -100.0 } } }] @@ -32,10 +32,10 @@ "index": 0, "state": { "output_power": { - "max": 0.0, - "avg": 0.0, + "max": -100.0, + "avg": -100.0, "instant": -2.0, - "min": 0.0 + "min": -100.0 }, "laser_bias_current": { "max": 0.0, @@ -44,10 +44,10 @@ "min": 0.0 }, "input_power": { - "max": 0.0, - "avg": 0.0, + "max": -100.0, + "avg": -100.0, "instant": -2.5, - "min": 0.0 + "min": -100.0 } } }] From 515c2d4f0335bf6acf44bd3426075818054f9c21 Mon Sep 17 00:00:00 2001 From: kaage Date: Sat, 22 Apr 2017 12:17:31 +0300 Subject: [PATCH 24/27] Added another test case and modified get_optics to survive --- napalm_ios/ios.py | 6 +++- .../low_rx_power/expected_result.json | 29 +++++++++++++++++++ .../low_rx_power/show_int_Gi0_11.txt | 29 +++++++++++++++++++ .../show_interfaces_transceiver.txt | 10 +++++++ 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 test/unit/mocked_data/test_get_optics/low_rx_power/expected_result.json create mode 100644 test/unit/mocked_data/test_get_optics/low_rx_power/show_int_Gi0_11.txt create mode 100644 test/unit/mocked_data/test_get_optics/low_rx_power/show_interfaces_transceiver.txt diff --git a/napalm_ios/ios.py b/napalm_ios/ios.py index a4a6f6e..f78b5af 100644 --- a/napalm_ios/ios.py +++ b/napalm_ios/ios.py @@ -581,10 +581,14 @@ def get_optics(self): for optics_entry in split_output.splitlines(): # Example, Te1/0/1 34.6 3.29 -2.0 -3.5 try: - int_brief, temperature, voltage, output_power, input_power = optics_entry.split() + split_list = optics_entry.split() except ValueError: return {} + int_brief = split_list[0] + output_power = split_list[3] + input_power = split_list[4] + port = self._expand_interface_name(int_brief) port_detail = {} diff --git a/test/unit/mocked_data/test_get_optics/low_rx_power/expected_result.json b/test/unit/mocked_data/test_get_optics/low_rx_power/expected_result.json new file mode 100644 index 0000000..f42a1bf --- /dev/null +++ b/test/unit/mocked_data/test_get_optics/low_rx_power/expected_result.json @@ -0,0 +1,29 @@ +{ + "GigabitEthernet0/11": { + "physical_channels": { + "channel": [{ + "index": 0, + "state": { + "output_power": { + "max": -100.0, + "avg": -100.0, + "instant": -6.8, + "min": -100.0 + }, + "laser_bias_current": { + "max": 0.0, + "avg": 0.0, + "instant": 0.0, + "min": 0.0 + }, + "input_power": { + "max": -100.0, + "avg": -100.0, + "instant": -27.4, + "min": -100.0 + } + } + }] + } + } +} \ No newline at end of file diff --git a/test/unit/mocked_data/test_get_optics/low_rx_power/show_int_Gi0_11.txt b/test/unit/mocked_data/test_get_optics/low_rx_power/show_int_Gi0_11.txt new file mode 100644 index 0000000..3bbe09e --- /dev/null +++ b/test/unit/mocked_data/test_get_optics/low_rx_power/show_int_Gi0_11.txt @@ -0,0 +1,29 @@ +GigabitEthernet0/11 is up, line protocol is up (connected) + Hardware is Gigabit Ethernet, address is 00da.5567.3e8b (bia 00da.5567.3e8b) + Description: Uplink + MTU 1500 bytes, BW 1000000 Kbit/sec, DLY 10 usec, + reliability 255/255, txload 1/255, rxload 1/255 + Encapsulation ARPA, loopback not set + Keepalive not set + Full-duplex, 1000Mb/s, link type is auto, media type is 1000BaseLX SFP + input flow-control is off, output flow-control is unsupported + ARP type: ARPA, ARP Timeout 04:00:00 + Last input 00:00:01, output 00:00:26, output hang never + Last clearing of "show interface" counters never + Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0 + Queueing strategy: fifo + Output queue: 0/40 (size/max) + 5 minute input rate 41000 bits/sec, 68 packets/sec + 5 minute output rate 40000 bits/sec, 66 packets/sec + 285486634 packets input, 21249719318 bytes, 0 no buffer + Received 5577815 broadcasts (2476464 multicasts) + 0 runts, 0 giants, 0 throttles + 2896 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored + 0 watchdog, 2476464 multicast, 0 pause input + 0 input packets with dribble condition detected + 298435968 packets output, 78061625290 bytes, 0 underruns + 0 output errors, 0 collisions, 1 interface resets + 0 unknown protocol drops + 0 babbles, 0 late collision, 0 deferred + 0 lost carrier, 0 no carrier, 0 pause output + 0 output buffer failures, 0 output buffers swapped out \ No newline at end of file diff --git a/test/unit/mocked_data/test_get_optics/low_rx_power/show_interfaces_transceiver.txt b/test/unit/mocked_data/test_get_optics/low_rx_power/show_interfaces_transceiver.txt new file mode 100644 index 0000000..ad5771d --- /dev/null +++ b/test/unit/mocked_data/test_get_optics/low_rx_power/show_interfaces_transceiver.txt @@ -0,0 +1,10 @@ +If device is externally calibrated, only calibrated values are printed. +++ : high alarm, + : high warning, - : low warning, -- : low alarm. +NA or N/A: not applicable, Tx: transmit, Rx: receive. +mA: milliamperes, dBm: decibels (milliwatts). + + Optical Optical + Temperature Voltage Tx Power Rx Power +Port (Celsius) (Volts) (dBm) (dBm) +--------- ----------- ------- -------- -------- +Gi0/11 24.0 3.22 -6.8 -27.4 -- \ No newline at end of file From 53ad8f74bf767383055c0391ba9b19dcd87a8952 Mon Sep 17 00:00:00 2001 From: Kirk Byers Date: Tue, 2 May 2017 11:34:30 -0700 Subject: [PATCH 25/27] Release new version of napalm-ios --- requirements.txt | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 4efa8ec..4b426dd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ napalm_base>=0.23.2 -netmiko>=1.2.8 +netmiko>=1.4.0 diff --git a/setup.py b/setup.py index fab6c4b..f02f899 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ setup( name="napalm-ios", - version="0.6.1", + version="0.6.2", packages=find_packages(), author="Kirk Byers", author_email="ktbyers@twb-tech.com", From 0bd484cbca007dcba8d1c22940bfa45d5e48364e Mon Sep 17 00:00:00 2001 From: Kirk Byers Date: Fri, 31 Mar 2017 13:50:55 -0700 Subject: [PATCH 26/27] Set zip_safe=False; fix old references in unit test --- setup.py | 1 + test/unit/TestIOSDriver.py | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 7032080..fab6c4b 100644 --- a/setup.py +++ b/setup.py @@ -24,5 +24,6 @@ ], url="https://github.com/napalm-automation/napalm-ios", include_package_data=True, + zip_safe=False, install_requires=reqs, ) diff --git a/test/unit/TestIOSDriver.py b/test/unit/TestIOSDriver.py index 557a411..6220613 100755 --- a/test/unit/TestIOSDriver.py +++ b/test/unit/TestIOSDriver.py @@ -91,16 +91,16 @@ def test_ios_only_confirm(self): def test_ios_only_gen_full_path(self): """Test gen_full_path() method.""" - output = self.device.gen_full_path(self.device.candidate_cfg) + output = self.device._gen_full_path(self.device.candidate_cfg) self.assertEqual(output, self.device.dest_file_system + '/candidate_config.txt') - output = self.device.gen_full_path(self.device.rollback_cfg) + output = self.device._gen_full_path(self.device.rollback_cfg) self.assertEqual(output, self.device.dest_file_system + '/rollback_config.txt') - output = self.device.gen_full_path(self.device.merge_cfg) + output = self.device._gen_full_path(self.device.merge_cfg) self.assertEqual(output, self.device.dest_file_system + '/merge_config.txt') - output = self.device.gen_full_path(filename='running-config', file_system='system:') + output = self.device._gen_full_path(filename='running-config', file_system='system:') self.assertEqual(output, 'system:/running-config') def test_ios_only_check_file_exists(self): From 1fbde03953687b9d61850466951f7fea44f6906d Mon Sep 17 00:00:00 2001 From: Kirk Byers Date: Tue, 2 May 2017 11:34:30 -0700 Subject: [PATCH 27/27] Release new version of napalm-ios --- requirements.txt | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 4efa8ec..4b426dd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ napalm_base>=0.23.2 -netmiko>=1.2.8 +netmiko>=1.4.0 diff --git a/setup.py b/setup.py index fab6c4b..f02f899 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ setup( name="napalm-ios", - version="0.6.1", + version="0.6.2", packages=find_packages(), author="Kirk Byers", author_email="ktbyers@twb-tech.com",