Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ipintutil]Handle exception in show ip interfaces command #3182

Merged
merged 5 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

@qiluo-msft qiluo-msft Feb 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it better to print error message and exit? If you continue, ipaddresses is not initialized and used. #Closed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think its correct. This will avoid other interfaces detail to not be shown. This is a very rare scenario during config reload.
Here is the scenario - While getting the interfaces there are 4 ports (docker0, eth0, lo0 and Loopback0). But while it enters the for loop in the parallel config reload flow Loopback0 gets deleted. However other interfaces exist and those information should be displayed. We can skip Loopback0 as we get valueerror meaning the interface does not exist now

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, there is no uninitialized variable in use.

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
Loading