Skip to content

Commit

Permalink
[ipintutil]Handle exception in show ip interfaces command (sonic-net#…
Browse files Browse the repository at this point in the history
…3182)

### What I did
Handle exception in show ip interfaces command when executed during config reload. Sometimes during config reload the interfaces are removed and if show ip interfaces was executed during this time we may get the below traceback. The interface would exist when the call multi_asic_get_ip_intf_from_ns was made but would have been removed in the subsequent for loop which tries to get ip interface data for each interface

```
show ip interfaces

Traceback (most recent call last):
  File "/usr/local/bin/ipintutil", line 276, in

     main()
  File "/usr/local/bin/ipintutil", line 269, in main
    ip_intfs = get_ip_intfs(af, namespace, display)
  File "/usr/local/bin/ipintutil", line 232, in get_ip_intfs
    ip_intfs_in_ns = get_ip_intfs_in_namespace(af, namespace, display)
  File "/usr/local/bin/ipintutil", line 153, in get_ip_intfs_in_namespace
    ipaddresses = multi_asic_util.multi_asic_get_ip_intf_addr_from_ns(namespace, iface)
  File "/usr/local/lib/python3.9/dist-packages/utilities_common/multi_asic.py", line 186, in multi_asic_get_ip_intf_addr_from_ns

     ipaddresses = netifaces.ifaddresses(iface)
ValueError: You must specify a valid interface name.
```

#### How I did it
Adding try exception block so that if an interface is not present, it would be skipped.

#### How to verify it
Running show ip interface command and performing config reload in parallel
  • Loading branch information
dgsudharsan authored Mar 18, 2024
1 parent 9d53201 commit 125f36f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion scripts/ipintutil
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ try:
mock_tables.dbconnector.load_namespace_config()
else:
import mock_tables.mock_single_asic
mock_tables.mock_single_asic.add_unknown_intf=True
except KeyError:
pass

Expand Down Expand Up @@ -150,7 +151,10 @@ def get_ip_intfs_in_namespace(af, namespace, display):
ip_intf_attr = []
if namespace != constants.DEFAULT_NAMESPACE and skip_ip_intf_display(iface, display):
continue
ipaddresses = multi_asic_util.multi_asic_get_ip_intf_addr_from_ns(namespace, iface)
try:
ipaddresses = multi_asic_util.multi_asic_get_ip_intf_addr_from_ns(namespace, iface)
except ValueError:
continue
if af in ipaddresses:
ifaddresses = []
bgp_neighs = {}
Expand Down
7 changes: 6 additions & 1 deletion tests/mock_tables/mock_single_asic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from sonic_py_common import multi_asic
from utilities_common import multi_asic as multi_asic_util

add_unknown_intf=False

mock_intf_table = {
'': {
'eth0': {
Expand Down Expand Up @@ -60,6 +62,8 @@ def mock_single_asic_get_ip_intf_from_ns(namespace):
interfaces = []
try:
interfaces = list(mock_intf_table[namespace].keys())
if add_unknown_intf:
interfaces.append("unknownintf")
except KeyError:
pass
return interfaces
Expand All @@ -70,7 +74,8 @@ def mock_single_asic_get_ip_intf_addr_from_ns(namespace, iface):
try:
ipaddresses = mock_intf_table[namespace][iface]
except KeyError:
pass
if add_unknown_intf:
raise ValueError("Unknow interface")
return ipaddresses


Expand Down

0 comments on commit 125f36f

Please sign in to comment.