Skip to content

Commit 0e327c5

Browse files
authored
show ip interfaces: fix exception with BGP unnumbered (sonic-net#3695)
* 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 <module> 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) * add coverage for exception handled by this PR --------- Signed-off-by: Brad House (@bradh352)
1 parent 7100f73 commit 0e327c5

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

scripts/ipintutil

+8-3
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,14 @@ def get_bgp_peer():
4848
data = config_db.get_table('BGP_NEIGHBOR')
4949

5050
for neighbor_ip in data.keys():
51-
local_addr = data[neighbor_ip]['local_addr']
52-
neighbor_name = data[neighbor_ip]['name']
53-
bgp_peer.setdefault(local_addr, [neighbor_name, neighbor_ip])
51+
# The data collected here will only work for manually defined neighbors
52+
# so we need to ignore errors when using BGP Unnumbered.
53+
try:
54+
local_addr = data[neighbor_ip]['local_addr']
55+
neighbor_name = data[neighbor_ip]['name']
56+
bgp_peer.setdefault(local_addr, [neighbor_name, neighbor_ip])
57+
except KeyError:
58+
pass
5459
return bgp_peer
5560

5661

tests/mock_tables/config_db.json

+8
Original file line numberDiff line numberDiff line change
@@ -2059,6 +2059,14 @@
20592059
"asn": "65200",
20602060
"keepalive": "3"
20612061
},
2062+
"BGP_NEIGHBOR|Vlan100": {
2063+
"rrclient": "0",
2064+
"peer_type": "external",
2065+
"nhopself": "0",
2066+
"admin_status": "up",
2067+
"holdtime": "10",
2068+
"keepalive": "3"
2069+
},
20622070
"SCHEDULER|scheduler.0": {
20632071
"type": "DWRR",
20642072
"weight": "14"

0 commit comments

Comments
 (0)