Repository: napalm-automation/napalm

Issue:
Error for 'get_lldp_neighbors()' on 'ios'
I discovered a "strange" error while using NetBox which simply wraps around the NAPALM libraries.
This is what I encountered (I apologize for the extremely long line):

```
{
  "detail": "Error connecting to the device at 9.88.0.5: LLDP details could not determine the value of local interface:\n{'TenGigabitEthernet1/6': [{'port': 'Te1/3', 'hostname': 'bld-vwd-d35a'}], 'TenGigabitEthernet1/5': [{'port': 'xe-0/0/2', 'hostname': 'bld-vwd-d34a'}], 'TenGigabitEthernet5/4': [{'port': 'Te3/2', 'hostname': 'bld-vsl-a'}], 'TenGigabitEthernet2/3': [{'port': 'Te5/4', 'hostname': 'bld-vsd-d32b'}], 'GigabitEthernet9/16': [{'port': 'Gi2/1', 'hostname': 'bld-sc-b'}], 'GigabitEthernet8/16': [{'port': 'Gi2/1', 'hostname': 'bld-sc-a'}], 'TenGigabitEthernet1/4': [{'port': 'Eth3/1', 'hostname': 'bld-vdd-d33a'}], 'TenGigabitEthernet2/8': [{'port': 'xe-0/0/2', 'hostname': 'bld-vdd-d37b'}], 'TenGigabitEthernet2/4': [{'port': 'Eth3/1', 'hostname': 'bld-vdd-d33b'}], 'GigabitEthernet8/18': [{'port': 'Gi1/25', 'hostname': 'bld-vsd-d17a'}], 'TenGigabitEthernet1/8': [{'port': 'xe-0/0/2', 'hostname': 'bld-vdd-d37a'}], 'TenGigabitEthernet2/2': [{'port': 'Te5/4', 'hostname': 'bld-vid-31b'}], 'TenGigabitEthernet2/5': [{'port': 'xe-0/0/2', 'hostname': 'bld-vwd-d34b'}], 'TenGigabitEthernet2/6': [{'port': 'Te1/3', 'hostname': 'bld-vwd-d35b'}], 'TenGigabitEthernet5/5': [{'port': 'Te3/2', 'hostname': 'bld-vsl-b'}], 'TenGigabitEthernet1/2': [{'port': 'Te5/4', 'hostname': 'bld-vid-31a'}], 'TenGigabitEthernet1/3': [{'port': 'Te5/4', 'hostname': 'bld-vsd-d32a'}], 'TenGigabitEthernet1/1': [{'port': 'Te1/1', 'hostname': 'bld-vsc-b'}]}\n\nChassis id: 3820.56c1.4d29\nPort id: Te1/3\nPort Description: bld/vWD35a-vSCa/global\nSystem Name: bld-vwd-d35a.attmgmt.ibm.com\n\nSystem Description: \nCisco IOS Software, c6848x Software (c6848x-ADVENTERPRISEK9-M), Version 15.4(1)SY1, RELEASE SOFTWARE (fc8)\nTechnical Support: http://www.cisco.com/techsupport\nCopyright (c) 1986-2016 by Cisco Systems, Inc.\nCompiled Fri 09-Dec-16 07:37 by prod_rel_team\n\nTime remaining: 100 seconds\nSystem Capabilities: B,R\nEnabled Capabilities: B,R\nManagement Addresses:\n    IP: 9.88.1.89\n    IPV6: 2620:1F7:9C2:C388::A\nAuto Negotiation - supported, enabled\nPhysical media capabilities:\n    Other/unknown\nMedia Attachment Unit type - not advertised\nVlan ID: - not advertised\n\n"
```

I brought this issue up in the NetworkToCode Slack channel and I was asked to include the above along with the following two files for `show lldp neighbors` and `show lldp neighbors detail`:

--REMOVED--

This error is really odd because this device's "partner" (`bld-vsc-b`) is running the same code level is connected to the same basic devices, but isn't exhibiting any problems when attempting to use this method on it.

If you need any other information from me for this scenario, please let me know.
Thanks again.



Discussion:
Also thought I would comment that the outputs above were taken from devices in a lab which emulates the production network as best as possible, but is definitely not as "clean" as I would like them to be.
Trying to understand your comment that this was not taken from production device. Does that mean this device in which you are showing output, does or does not exhibit the same issue? 
I was just stating that I didn't do an in-depth review or other "scrubbing" of any proprietary information from the posted files and wanted to cover myself from the corporate overlords in case they found this one day with the hostnames and IP addresses publicly available.

That is all I was trying to communicate.

Resolving patch:
diff --git a/napalm/ios/ios.py b/napalm/ios/ios.py
--- a/napalm/ios/ios.py
+++ b/napalm/ios/ios.py
@@ -824,6 +824,8 @@ def get_lldp_neighbors_detail(self, interface=''):
                     local_intf = match.group(1)
             else:
                 system_name_match = re.search(r"^System Name:\s+(\S.*)$", lldp_entry, flags=re.M)
+                # Cisco is inconsistent on whether the domain name appears in LLDP brief output
+                system_name_alt = re.search(r"^System Name:\s+(\S.*?)\.", lldp_entry, flags=re.M)
                 port_id_match = re.search(r"^Port id:\s+(\S+)\s*$", lldp_entry, flags=re.M)
                 # Try to find the local_intf from the reverse_neighbors table
                 if system_name_match and port_id_match:
@@ -832,6 +834,11 @@ def get_lldp_neighbors_detail(self, interface=''):
                     system_name = system_name.strip()
                     key = "{}_{}".format(system_name, port_id)
                     local_intf = reverse_neighbors.get(key)
+                    if local_intf is None and system_name_alt:
+                        system_name_alt = system_name_alt.group(1)[:20]
+                        system_name_alt = system_name_alt.strip()
+                        alt_key = "{}_{}".format(system_name_alt, port_id)
+                        local_intf = reverse_neighbors.get(alt_key)
 
             if local_intf is not None:
                 lldp_fields = self._lldp_detail_parser(local_intf, lldp_entry=lldp_entry)


Test patch:
diff --git a/test/ios/mocked_data/test_get_lldp_neighbors/inconsistent_domain_name/expected_result.json b/test/ios/mocked_data/test_get_lldp_neighbors/inconsistent_domain_name/expected_result.json
new file mode 100644
--- /dev/null
+++ b/test/ios/mocked_data/test_get_lldp_neighbors/inconsistent_domain_name/expected_result.json
@@ -0,0 +1,86 @@
+{
+    "TenGigabitEthernet1/6": [
+        {
+            "port": "Te1/3",
+            "hostname": "foo-vwd-d35a.foo.domain.com"
+        }
+    ],
+    "TenGigabitEthernet1/5": [
+        {
+            "port": "xe-0/0/2",
+            "hostname": "foo-vwd-d34a"
+        }
+    ],
+    "TenGigabitEthernet5/4": [
+        {
+            "port": "Te3/2",
+            "hostname": "foo-vsl-a.wan.domain.com"
+        }
+    ],
+    "TenGigabitEthernet2/3": [
+        {
+            "port": "Te5/4",
+            "hostname": "foo-vsd-d32b.foo.domain.com"
+        }
+    ],
+    "GigabitEthernet9/16": [
+        {
+            "port": "Gi2/1",
+            "hostname": "foo-sc-b.subd.domain.com"
+        }
+    ],
+    "GigabitEthernet8/16": [
+        {
+            "port": "Gi2/1",
+            "hostname": "foo-sc-a.subd.domain.com"
+        }
+    ],
+    "TenGigabitEthernet1/4": [
+        {
+            "port": "Eth3/1",
+            "hostname": "foo-vdd-d33a.foo.domain.com"
+        }
+    ],
+    "TenGigabitEthernet2/8": [
+        {
+            "port": "xe-0/0/2",
+            "hostname": "foo-vdd-d37b"
+        }
+    ],
+    "TenGigabitEthernet2/4": [
+        {
+            "port": "Eth3/1",
+            "hostname": "foo-vdd-d33b.foo.domain.com"
+        }
+    ],
+    "GigabitEthernet8/18": [
+        {
+            "port": "Gi1/25",
+            "hostname": "foo-vsd-d17a.subd.domain.com"
+        }
+    ],
+    "TenGigabitEthernet1/8": [
+        {
+            "port": "xe-0/0/2",
+            "hostname": "foo-vdd-d37a"
+        }
+    ],
+    "TenGigabitEthernet2/2": [
+        {
+            "port": "Te5/4",
+            "hostname": "foo-vid-31b.foo.domain.com"
+        }
+    ],
+    "TenGigabitEthernet2/5": [
+        {
+            "port": "xe-0/0/2",
+            "hostname": "foo-vwd-d34b"
+        }
+    ],
+    "TenGigabitEthernet2/6": [
+        {
+            "port": "Te1/3",
+            "hostname": "foo-vwd-d35b.foo.domain.com"
+        }
+    ]
+}
diff --git a/test/ios/mocked_data/test_get_lldp_neighbors/inconsistent_domain_name/show_lldp_neighbors.txt b/test/ios/mocked_data/test_get_lldp_neighbors/inconsistent_domain_name/show_lldp_neighbors.txt
new file mode 100644
--- /dev/null
+++ b/test/ios/mocked_data/test_get_lldp_neighbors/inconsistent_domain_name/show_lldp_neighbors.txt
@@ -0,0 +1,21 @@
+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
+foo-vwd-d35a        Te1/6          120        B,R             Te1/3
+foo-vwd-d34a        Te1/5          120        B,R             xe-0/0/2
+foo-vsl-a           Te5/4          120        B,R             Te3/2
+foo-vsd-d32b        Te2/3          120        B,R             Te5/4
+foo-sc-b            Gi9/16         120        B,R             Gi2/1
+foo-sc-a            Gi8/16         120        B,R             Gi2/1
+foo-vdd-d33a        Te1/4          120        B,R             Eth3/1
+foo-vdd-d37b        Te2/8          120        B,R             xe-0/0/2
+foo-vdd-d33b        Te2/4          120        B,R             Eth3/1
+foo-vsd-d17a        Gi8/18         120        R               Gi1/25
+foo-vdd-d37a        Te1/8          120        B,R             xe-0/0/2
+foo-vid-31b         Te2/2          120        B,R             Te5/4
+foo-vwd-d34b        Te2/5          120        B,R             xe-0/0/2
+foo-vwd-d35b        Te2/6          120        B,R             Te1/3
+
+Total entries displayed: 14
diff --git a/test/ios/mocked_data/test_get_lldp_neighbors/inconsistent_domain_name/show_lldp_neighbors_detail.txt b/test/ios/mocked_data/test_get_lldp_neighbors/inconsistent_domain_name/show_lldp_neighbors_detail.txt
new file mode 100644
--- /dev/null
+++ b/test/ios/mocked_data/test_get_lldp_neighbors/inconsistent_domain_name/show_lldp_neighbors_detail.txt
@@ -0,0 +1,317 @@
+foo-vsc-a#sh lldp nei det
+------------------------------------------------
+Chassis id: 3820.56c1.4d29
+Port id: Te1/3
+Port Description: foo/vWD35a-vSCa/global
+System Name: foo-vwd-d35a.foo.domain.com
+
+System Description: 
+Cisco IOS Software, c6848x Software (c6848x-ADVENTERPRISEK9-M), Version 15.4(1)SY1, RELEASE SOFTWARE (fc8)
+Technical Support: http://www.cisco.com/techsupport
+Copyright (c) 1986-2016 by Cisco Systems, Inc.
+Compiled Fri 09-Dec-16 07:37 by prod_rel_team
+
+Time remaining: 111 seconds
+System Capabilities: B,R
+Enabled Capabilities: B,R
+Management Addresses:
+    IP: 10.0.1.89
+    IPV6: 2001:DB8:9C2:C388::A
+Auto Negotiation - supported, enabled
+Physical media capabilities:
+    Other/unknown
+Media Attachment Unit type - not advertised
+Vlan ID: - not advertised
+
+------------------------------------------------
+Chassis id: 40a6.77dd.63c0
+Port id: xe-0/0/2
+Port Description: foo/vWD34a-vSCa/global</[local description]>
+System Name: foo-vwd-d34a
+
+System Description: 
+Juniper Networks, Inc. qfx5100-48s-6q Ethernet Switch, kernel JUNOS 16.1R5.7, Build date: 2017-08-18 17:55:45 UTC Copyright (c) 1996-2017 Juniper Networks, Inc.
+
+Time remaining: 104 seconds
+System Capabilities: B,R
+Enabled Capabilities: B,R
+Management Addresses:
+    IP: 10.0.1.69
+    OID:
+        0.1.3.6.1.2.1.31.1.1.1.1.0.
+Auto Negotiation - not supported
+Physical media capabilities:
+    Other/unknown
+Media Attachment Unit type - not advertised
+Vlan ID: - not advertised
+
+------------------------------------------------
+Chassis id: 68ef.bdeb.6940
+Port id: Te3/2
+Port Description: TenGigabitEthernet3/2
+System Name: foo-vsl-a.wan.domain.com
+
+System Description: 
+Cisco IOS Software, s72033_rp Software (s72033_rp-ADVIPSERVICESK9-M), Version 15.1(2)SY9, RELEASE SOFTWARE (fc1)
+Technical Support: http://www.cisco.com/techsupport
+Copyright (c) 1986-2016 by Cisco Systems, Inc.
+Compiled Thu 29-Sep-16 04:07 by prod_rel_te
+
+Time remaining: 106 seconds
+System Capabilities: B,R
+Enabled Capabilities: B,R
+Management Addresses:
+    IP: 9.0.41.207
+Auto Negotiation - not supported
+Physical media capabilities:
+    Other/unknown
+Media Attachment Unit type - not advertised
+Vlan ID: 4094
+
+------------------------------------------------
+Chassis id: 00d0.7990.e800
+Port id: Te5/4
+Port Description: TenGigabitEthernet5/4
+System Name: foo-vsd-d32b.foo.domain.com
+
+System Description: 
+Cisco IOS Software, s72033_rp Software (s72033_rp-ADVIPSERVICESK9-M), Version 15.1(2)SY9, RELEASE SOFTWARE (fc1)
+Technical Support: http://www.cisco.com/techsupport
+Copyright (c) 1986-2016 by Cisco Systems, Inc.
+Compiled Thu 29-Sep-16 04:07 by prod_rel_te
+
+Time remaining: 98 seconds
+System Capabilities: B,R
+Enabled Capabilities: B,R
+Management Addresses:
+    IP: 10.0.1.43
+    IPV6: 2001:DB8:0:8D01::B
+Auto Negotiation - not supported
+Physical media capabilities:
+    Other/unknown
+Media Attachment Unit type - not advertised
+Vlan ID: - not advertised
+
+------------------------------------------------
+Chassis id: 0007.b30f.c7c0
+Port id: Gi2/1
+Port Description: GigabitEthernet2/1
+System Name: foo-sc-b.subd.domain.com
+
+System Description: 
+Cisco IOS Software, s72033_rp Software (s72033_rp-IPSERVICESK9-M), Version 15.1(2)SY6, RELEASE SOFTWARE (fc4)
+Technical Support: http://www.cisco.com/techsupport
+Copyright (c) 1986-2015 by Cisco Systems, Inc.
+Compiled Thu 10-Sep-15 01:59 by prod_rel_team
+
+Time remaining: 115 seconds
+System Capabilities: B,R
+Enabled Capabilities: B,R
+Management Addresses:
+    IP: 9.17.4.6
+Auto Negotiation - not supported
+Physical media capabilities:
+    1000baseX(FD)
+Media Attachment Unit type: 26
+Vlan ID: - not advertised
+
+------------------------------------------------
+Chassis id: 0007.b30f.cbc0
+Port id: Gi2/1
+Port Description: GigabitEthernet2/1
+System Name: foo-sc-a.subd.domain.com
+
+System Description: 
+Cisco IOS Software, s72033_rp Software (s72033_rp-IPSERVICESK9-M), Version 15.1(2)SY6, RELEASE SOFTWARE (fc4)
+Technical Support: http://www.cisco.com/techsupport
+Copyright (c) 1986-2015 by Cisco Systems, Inc.
+Compiled Thu 10-Sep-15 01:59 by prod_rel_team
+
+Time remaining: 110 seconds
+System Capabilities: B,R
+Enabled Capabilities: B,R
+Management Addresses:
+    IP: 9.17.4.2
+Auto Negotiation - not supported
+Physical media capabilities:
+    1000baseX(FD)
+Media Attachment Unit type: 26
+Vlan ID: - not advertised
+
+------------------------------------------------
+Chassis id: 8478.ac56.60b8
+Port id: Eth3/1
+Port Description: foo/vDD33a-vSCa/global
+System Name: foo-vdd-d33a.foo.domain.com
+
+System Description: 
+Cisco NX-OS(tm) n7000, Software (n7000-s2-dk9), Version 6.2(16), RELEASE SOFTWARE Copyright (c) 2002-2013 by Cisco Systems, Inc. Compiled 1/27/2016 9:00:00
+
+Time remaining: 92 seconds
+System Capabilities: B,R
+Enabled Capabilities: B,R
+Management Addresses:
+    IP: 9.0.43.231
+Auto Negotiation - not supported
+Physical media capabilities - not advertised
+Media Attachment Unit type - not advertised
+Vlan ID: - not advertised
+
+------------------------------------------------
+Chassis id: 84b5.9ccc.8440
+Port id: xe-0/0/2
+Port Description: foo/vDD37b-vSCa/global</[local description]>
+System Name: foo-vdd-d37b
+
+System Description: 
+Juniper Networks, Inc. qfx5100-48s-6q Ethernet Switch, kernel JUNOS 14.1X53-D30.3, Build date: 2015-10-02 10:44:32 UTC Copyright (c) 1996-2015 Juniper Networks, Inc.
+
+Time remaining: 96 seconds
+System Capabilities: B,R
+Enabled Capabilities: B,R
+Management Addresses:
+    IP: 10.0.1.118
+    OID:
+        0.1.3.6.1.2.1.31.1.1.1.1.0.
+Auto Negotiation - not supported
+Physical media capabilities:
+    Other/unknown
+Media Attachment Unit type - not advertised
+Vlan ID: - not advertised
+
+------------------------------------------------
+Chassis id: 8478.ac56.6080
+Port id: Eth3/1
+Port Description: foo/vDD33b-vSCa/global
+System Name: foo-vdd-d33b.foo.domain.com
+
+System Description: 
+Cisco NX-OS(tm) n7000, Software (n7000-s2-dk9), Version 6.2(16), RELEASE SOFTWARE Copyright (c) 2002-2013 by Cisco Systems, Inc. Compiled 1/27/2016 9:00:00
+
+Time remaining: 92 seconds
+System Capabilities: B,R
+Enabled Capabilities: B,R
+Management Addresses:
+    IP: 9.0.43.233
+Auto Negotiation - not supported
+Physical media capabilities - not advertised
+Media Attachment Unit type - not advertised
+Vlan ID: - not advertised
+
+------------------------------------------------
+Chassis id: 001d.7048.1386
+Port id: Gi1/25
+Port Description: GigabitEthernet1/25
+System Name: foo-vsd-d17a.subd.domain.com
+
+System Description: 
+Cisco IOS Software, s6523_rp Software (s6523_rp-ADVIPSERVICESK9-M), Version 12.2(33)SXI13, RELEASE SOFTWARE (fc3)
+Technical Support: http://www.cisco.com/techsupport
+Copyright (c) 1986-2014 by Cisco Systems, Inc.
+Compiled Tue 11-Mar-14 10:52 by prod_rel_t
+
+Time remaining: 94 seconds
+System Capabilities: B,R
+Enabled Capabilities: R
+Management Addresses:
+    IP: 10.0.2.41
+Auto Negotiation - not supported
+Physical media capabilities:
+    1000baseT(FD)
+Media Attachment Unit type - not advertised
+Vlan ID: - not advertised
+
+------------------------------------------------
+Chassis id: 84b5.9cca.d8c0
+Port id: xe-0/0/2
+Port Description: foo/vDD37a-vSCa/global</[local description]>
+System Name: foo-vdd-d37a
+
+System Description: 
+Juniper Networks, Inc. qfx5100-48s-6q Ethernet Switch, kernel JUNOS 14.1X53-D30.3, Build date: 2015-10-02 10:44:32 UTC Copyright (c) 1996-2015 Juniper Networks, Inc.
+
+Time remaining: 107 seconds
+System Capabilities: B,R
+Enabled Capabilities: B,R
+Management Addresses:
+    IP: 10.0.1.117
+    OID:
+        0.1.3.6.1.2.1.31.1.1.1.1.0.
+Auto Negotiation - not supported
+Physical media capabilities:
+    Other/unknown
+Media Attachment Unit type - not advertised
+Vlan ID: - not advertised
+
+------------------------------------------------
+Chassis id: 0019.07c3.b400
+Port id: Te5/4
+Port Description: TenGigabitEthernet5/4
+System Name: foo-vid-31b.foo.domain.com
+
+System Description: 
+Cisco IOS Software, s72033_rp Software (s72033_rp-ADVIPSERVICESK9-M), Version 15.1(2)SY9, RELEASE SOFTWARE (fc1)
+Technical Support: http://www.cisco.com/techsupport
+Copyright (c) 1986-2016 by Cisco Systems, Inc.
+Compiled Thu 29-Sep-16 04:07 by prod_rel_te
+
+Time remaining: 90 seconds
+System Capabilities: B,R
+Enabled Capabilities: B,R
+Management Addresses:
+    IP: 10.0.1.27
+    IPV6: 2001:DB8:9C2::1F:9C02:B
+Auto Negotiation - not supported
+Physical media capabilities:
+    Other/unknown
+Media Attachment Unit type - not advertised
+Vlan ID: - not advertised
+
+------------------------------------------------
+Chassis id: dc38.e156.7e40
+Port id: xe-0/0/2
+Port Description: foo/vWD34b-vSCa/global</[local description]>
+System Name: foo-vwd-d34b
+
+System Description: 
+Juniper Networks, Inc. qfx5100-48s-6q Ethernet Switch, kernel JUNOS 16.1R5.7, Build date: 2017-08-18 17:55:45 UTC Copyright (c) 1996-2017 Juniper Networks, Inc.
+
+Time remaining: 96 seconds
+System Capabilities: B,R
+Enabled Capabilities: B,R
+Management Addresses:
+    IP: 10.0.1.70
+    OID:
+        0.1.3.6.1.2.1.31.1.1.1.1.0.
+Auto Negotiation - not supported
+Physical media capabilities:
+    Other/unknown
+Media Attachment Unit type - not advertised
+Vlan ID: - not advertised
+
+------------------------------------------------
+Chassis id: 3820.56c1.558c
+Port id: Te1/3
+Port Description: foo/vWD35b-vSCa/global
+System Name: foo-vwd-d35b.foo.domain.com
+
+System Description: 
+Cisco IOS Software, c6848x Software (c6848x-ADVENTERPRISEK9-M), Version 15.4(1)SY1, RELEASE SOFTWARE (fc8)
+Technical Support: http://www.cisco.com/techsupport
+Copyright (c) 1986-2016 by Cisco Systems, Inc.
+Compiled Fri 09-Dec-16 07:37 by prod_rel_team
+
+Time remaining: 91 seconds
+System Capabilities: B,R
+Enabled Capabilities: B,R
+Management Addresses:
+    IP: 10.0.1.91
+    IPV6: 2001:DB8:9C2:C388::B
+Auto Negotiation - supported, enabled
+Physical media capabilities:
+    Other/unknown
+Media Attachment Unit type - not advertised
+Vlan ID: - not advertised
+
+
+Total entries displayed: 14