diff --git a/napalm_s350/s350.py b/napalm_s350/s350.py index 3676dca..66511b7 100644 --- a/napalm_s350/s350.py +++ b/napalm_s350/s350.py @@ -369,17 +369,27 @@ class S350Driver(NetworkDriver): #output = self._send_command('show lldp neighbors | begin \ \ Port') output = self._send_command('show lldp neighbors') - for line in output.splitlines()[2:]: + header = True # cycle trought header + for line in output.splitlines(): + if header: + # last line of header + match = re.match(r'^--------- -+ .*$', line) + if match: + header = False + continue + line_elems = line.split() local_port = line_elems[0] remote_port = line_elems[2] remote_name = line_elems[3] - neighbors[local_port] = { + neighbor = { 'hostname': remote_name, 'port': remote_port, } - + neighbor_list= [ neighbor, ] + neighbors[local_port] = neighbor_list + return neighbors def _get_lldp_line_value(self, line): diff --git a/test/unit/mocked_data/SG350X-48P-K9/show_lldp_neighbors.txt b/test/unit/mocked_data/SG350X-48P-K9/show_lldp_neighbors.txt index fb27e93..c0e2bd9 100644 --- a/test/unit/mocked_data/SG350X-48P-K9/show_lldp_neighbors.txt +++ b/test/unit/mocked_data/SG350X-48P-K9/show_lldp_neighbors.txt @@ -6,7 +6,9 @@ TP - Two Ports MAC Relay; S - S-VLAN; C - C-VLAN; O - Other Port Device ID Port ID System Name Capabilities TTL --------- ----------------- ----------------- ----------------- ------------ ----- -gi1/0/37 b0:b8:67:c2:32:aa b0:b8:67:c2:32:aa AM W 110 -te1/0/3 00:8e:73:24:5d:e2 gi28 sw1 B, R 116 -te1/0/4 sw2 te1/0/4 sw2 B, R 100 +gi1/0/1 74:ac:aa:ff:1a:5f 74:ac:aa:ff:1a:5f UBNT B, W 90 +gi1/0/35 34:e6:aa:ff:53:a8 34:e6:aa:ff:53:a8 O 3119 +te1/0/1 00:16:ff:aa:bb:00 Gi0/23 swzdsadas-vedc B 107 +te1/0/3 00:8e:ff:aa:bb:e2 gi28 sw1dsafdsfsdfsdd B, R 95 +te1/0/4 sw2dsdfssddfd te1/0/4 sw2dsdfssddfd B, R 105 diff --git a/test/unit/mocked_data/test_get_lldp_neighbors/SG350X-48P-K9/expected_result.json b/test/unit/mocked_data/test_get_lldp_neighbors/SG350X-48P-K9/expected_result.json new file mode 100644 index 0000000..51fea79 --- /dev/null +++ b/test/unit/mocked_data/test_get_lldp_neighbors/SG350X-48P-K9/expected_result.json @@ -0,0 +1,22 @@ +{ + "gi1/0/1" : [ { + "hostname" : "UBNT", + "port" : "74:ac:aa:ff:1a:5f" + } ], + "gi1/0/35" : [ { + "hostname" : "O", + "port" : "34:e6:aa:ff:53:a8" + } ], + "te1/0/1" : [ { + "hostname" : "swzdsadas-vedc", + "port" : "Gi0/23" + } ], + "te1/0/3" : [ { + "hostname" : "sw1dsafdsfsdfsdd", + "port" : "gi28" + } ], + "te1/0/4" : [ { + "hostname" : "sw2dsdfssddfd", + "port" : "te1/0/4" + } ] +} diff --git a/test/unit/mocked_data/test_get_lldp_neighbors/SG350X-48P-K9/show_lldp_neighbors.txt b/test/unit/mocked_data/test_get_lldp_neighbors/SG350X-48P-K9/show_lldp_neighbors.txt index fb27e93..c0e2bd9 100644 --- a/test/unit/mocked_data/test_get_lldp_neighbors/SG350X-48P-K9/show_lldp_neighbors.txt +++ b/test/unit/mocked_data/test_get_lldp_neighbors/SG350X-48P-K9/show_lldp_neighbors.txt @@ -6,7 +6,9 @@ TP - Two Ports MAC Relay; S - S-VLAN; C - C-VLAN; O - Other Port Device ID Port ID System Name Capabilities TTL --------- ----------------- ----------------- ----------------- ------------ ----- -gi1/0/37 b0:b8:67:c2:32:aa b0:b8:67:c2:32:aa AM W 110 -te1/0/3 00:8e:73:24:5d:e2 gi28 sw1 B, R 116 -te1/0/4 sw2 te1/0/4 sw2 B, R 100 +gi1/0/1 74:ac:aa:ff:1a:5f 74:ac:aa:ff:1a:5f UBNT B, W 90 +gi1/0/35 34:e6:aa:ff:53:a8 34:e6:aa:ff:53:a8 O 3119 +te1/0/1 00:16:ff:aa:bb:00 Gi0/23 swzdsadas-vedc B 107 +te1/0/3 00:8e:ff:aa:bb:e2 gi28 sw1dsafdsfsdfsdd B, R 95 +te1/0/4 sw2dsdfssddfd te1/0/4 sw2dsdfssddfd B, R 105