From 5f67f3eebeb36b8ad6489d97dc17d189cbd77499 Mon Sep 17 00:00:00 2001 From: Jan Krupa Date: Wed, 2 Apr 2025 10:23:28 +0200 Subject: [PATCH] Fix LLDP neighbors detail retrieval on ASR9K devices The original implementation of the get_lldp_neighbors_detail method fails with an XMLCLIError exception when used on Cisco ASR9K devices. This is due to the ASR9K requiring a more specific XML path in the RPC call. Added a try/except block that: 1. First attempts the generic LLDP query 2. If that fails with XMLCLIError, tries a more specific query that includes the exact node path (Rack 0, Slot 0, Instance CPU0) 3. Also added an informative log message to indicate when fallback occurs This change maintains backward compatibility with standard IOS-XR devices while adding support for ASR9K devices. --- napalm/iosxr/iosxr.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/napalm/iosxr/iosxr.py b/napalm/iosxr/iosxr.py index 524f8cbf1..02103e628 100644 --- a/napalm/iosxr/iosxr.py +++ b/napalm/iosxr/iosxr.py @@ -879,7 +879,20 @@ def get_lldp_neighbors_detail(self, interface=""): "" ) - result_tree = ETREE.fromstring(self.device.make_rpc_call(rpc_command)) + try: + result_tree = ETREE.fromstring(self.device.make_rpc_call(rpc_command)) + except napalm.pyIOSXR.exceptions.XMLCLIError: + logger.info( + "Attempting more specific ASR9K rpc call for LLDP neighbors query" + ) + rpc_command = ( + "" + "" + "00CPU0" + "" + "" + ) + result_tree = ETREE.fromstring(self.device.make_rpc_call(rpc_command)) for neighbor in result_tree.xpath(".//Neighbors/DetailTable/Detail/Entry"): interface_name = napalm.base.helpers.convert(