Skip to content

Commit

Permalink
show ip interfaces: fix exception with BGP unnumbered (sonic-net#3695)
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
bradh352 authored Jan 8, 2025
1 parent 7100f73 commit 0e327c5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
11 changes: 8 additions & 3 deletions scripts/ipintutil
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
8 changes: 8 additions & 0 deletions tests/mock_tables/config_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 0e327c5

Please sign in to comment.