From 1166568bb581a4a2c9e5b4ff8579f9d1cf431f5a Mon Sep 17 00:00:00 2001 From: Brad House Date: Mon, 23 Dec 2024 13:13:44 -0500 Subject: [PATCH 1/2] show ip interfaces: fix exception with BGP unnumbered Without this patch an exception is thrown when running `show ip interfaces` when BGP Unnumbered is configured: ``` root@sw1:~# show ip interfaces Traceback (most recent call last): File "/usr/local/bin/ipintutil", line 280, in main() File "/usr/local/bin/ipintutil", line 273, in main ip_intfs = get_ip_intfs(af, namespace, display) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/bin/ipintutil", line 236, in get_ip_intfs ip_intfs_in_ns = get_ip_intfs_in_namespace(af, namespace, display) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/bin/ipintutil", line 149, in get_ip_intfs_in_namespace bgp_peer = get_bgp_peer() ^^^^^^^^^^^^^^ File "/usr/local/bin/ipintutil", line 51, in get_bgp_peer local_addr = data[neighbor_ip]['local_addr'] ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^ KeyError: 'local_addr' ``` This patch will allow the command to complete successfully. It shouldn't be necessary to actually query FRR for neighbor details, the prior version didn't, it just echo'd back config details. Signed-off-by: Brad House (@bradh352) --- scripts/ipintutil | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/scripts/ipintutil b/scripts/ipintutil index 85879972e0..193f44ebde 100755 --- a/scripts/ipintutil +++ b/scripts/ipintutil @@ -48,9 +48,14 @@ def get_bgp_peer(): data = config_db.get_table('BGP_NEIGHBOR') for neighbor_ip in data.keys(): - local_addr = data[neighbor_ip]['local_addr'] - neighbor_name = data[neighbor_ip]['name'] - bgp_peer.setdefault(local_addr, [neighbor_name, neighbor_ip]) + # The data collected here will only work for manually defined neighbors + # so we need to ignore errors when using BGP Unnumbered. + try: + local_addr = data[neighbor_ip]['local_addr'] + neighbor_name = data[neighbor_ip]['name'] + bgp_peer.setdefault(local_addr, [neighbor_name, neighbor_ip]) + except KeyError: + pass return bgp_peer From 253fe89137e9e1077cf794a1de3a78591e262caf Mon Sep 17 00:00:00 2001 From: Brad House Date: Tue, 7 Jan 2025 10:04:28 -0500 Subject: [PATCH 2/2] add coverage for exception handled by this PR --- tests/mock_tables/config_db.json | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/mock_tables/config_db.json b/tests/mock_tables/config_db.json index 3deca74255..8b389c7a26 100644 --- a/tests/mock_tables/config_db.json +++ b/tests/mock_tables/config_db.json @@ -2059,6 +2059,14 @@ "asn": "65200", "keepalive": "3" }, + "BGP_NEIGHBOR|Vlan100": { + "rrclient": "0", + "peer_type": "external", + "nhopself": "0", + "admin_status": "up", + "holdtime": "10", + "keepalive": "3" + }, "SCHEDULER|scheduler.0": { "type": "DWRR", "weight": "14"