From dc7f82cc157816529d3efc1ce97678a417c964e6 Mon Sep 17 00:00:00 2001 From: Petr Klima Date: Tue, 3 Nov 2020 11:18:55 +0000 Subject: [PATCH] get_interfaces unit test for SG350X-48P --- napalm_s350/s350.py | 27 ++++++++++---- ...t1#0#1.txt => show_lldp_local_gi1_0_1.txt} | 0 .../SG350X-48P-K9/show_ports_jumbo_frame.txt | 3 ++ .../show_lldp_local_GigabitEthernet1.txt | 37 ------------------- 4 files changed, 22 insertions(+), 45 deletions(-) rename test/unit/mocked_data/SG350X-48P-K9/{show_lldp_local_GigabitEthernet1#0#1.txt => show_lldp_local_gi1_0_1.txt} (100%) create mode 100644 test/unit/mocked_data/SG350X-48P-K9/show_ports_jumbo_frame.txt delete mode 100644 test/unit/mocked_data/test_get_interfaces/SG350X-48P-K9/show_lldp_local_GigabitEthernet1.txt diff --git a/napalm_s350/s350.py b/napalm_s350/s350.py index eb045e4..3676dca 100644 --- a/napalm_s350/s350.py +++ b/napalm_s350/s350.py @@ -282,19 +282,28 @@ class S350Driver(NetworkDriver): show_status_output = self._send_command('show interfaces status') show_description_output = self._send_command('show interfaces description') - # Since the MAC address for all the local ports are equal, get the address - # from the first port and use it everywhere. - show_system_output = self._send_command('show lldp local GigabitEthernet1') - try: - mac = show_system_output.splitlines()[0].split(':', maxsplit=1)[1].strip() - except: - mac = '0' + # by documentation SG350 + show_jumbo_frame = self._send_command('show ports jumbo-frame') + match = re.search(r'Jumbo frames are enabled', show_jumbo_frame, re.M) + if match: + mtu = 9000 + else: + mtu = 1518 + + mac = '0' for status_line in show_status_output.splitlines(): if 'Up' in status_line or 'Down' in status_line: interface, _, _, speed, _, _, link_state, _, _ = status_line.split() + # Since the MAC address for all the local ports are equal, get the address + # from the first port and use it everywhere. + if mac == '0': + show_system_output = self._send_command('show lldp local ' + interface ) + + mac = show_system_output.splitlines()[0].split(':', maxsplit=1)[1].strip() + if speed == '--': is_enabled = False speed = 0 @@ -310,11 +319,13 @@ class S350Driver(NetworkDriver): description = ' '.join(descr_line.split()[1:]) break + # last_flapped can not be get - setting to default entry = { 'is_up': is_up, 'is_enabled': is_enabled, 'speed': speed, - 'last_flapped': -1, + 'mtu': mtu, + 'last_flapped': -1.0, 'description': description, 'mac_address': napalm.base.helpers.mac(mac) } diff --git a/test/unit/mocked_data/SG350X-48P-K9/show_lldp_local_GigabitEthernet1#0#1.txt b/test/unit/mocked_data/SG350X-48P-K9/show_lldp_local_gi1_0_1.txt similarity index 100% rename from test/unit/mocked_data/SG350X-48P-K9/show_lldp_local_GigabitEthernet1#0#1.txt rename to test/unit/mocked_data/SG350X-48P-K9/show_lldp_local_gi1_0_1.txt diff --git a/test/unit/mocked_data/SG350X-48P-K9/show_ports_jumbo_frame.txt b/test/unit/mocked_data/SG350X-48P-K9/show_ports_jumbo_frame.txt new file mode 100644 index 0000000..a0130f0 --- /dev/null +++ b/test/unit/mocked_data/SG350X-48P-K9/show_ports_jumbo_frame.txt @@ -0,0 +1,3 @@ + + Jumbo frames are enabled + Jumbo frames will be enabled after reset diff --git a/test/unit/mocked_data/test_get_interfaces/SG350X-48P-K9/show_lldp_local_GigabitEthernet1.txt b/test/unit/mocked_data/test_get_interfaces/SG350X-48P-K9/show_lldp_local_GigabitEthernet1.txt deleted file mode 100644 index b6fb7f9..0000000 --- a/test/unit/mocked_data/test_get_interfaces/SG350X-48P-K9/show_lldp_local_GigabitEthernet1.txt +++ /dev/null @@ -1,37 +0,0 @@ - -Device ID: 04:eb:40:e3:91:7f -Port ID: 04:eb:40:e3:91:80 -Capabilities: Bridge -System Name: sw1 -Management address: 198.51.100..3 -Management address: fe80::eb::ff:fee3::7f%vlan1 - -802.3 Power Via Mdi: - MDI Power support Port Class: PSE - PSE MDI Power Support: Supported - PSE MDI Power State: Enabled - PSE power pair control ability: Not supported - PSE Power Pair: Spare - PSE Power class: 2 - Power Type: Type 2 PSE - Power Source: Primary Power Source - Power Priority: low - PSE Allocated Power Value: 3.9 - -4-Pair POE supported: Yes -Spare Pair Detection/Classification required: No -PD Spare Pair Desired State: Disabled - -802.3 EEE: - - Local Tx: 17 uSec - Local Rx: 17 uSec - Local Tx Echo: 17 uSec - Local Rx Echo: 17 uSec - - -802.1 PVID: 1 -802.1 PPVID: -802.1 VLAN: -802.1 Protocol: -