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 2 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
5 changes: 4 additions & 1 deletion scripts/ipintutil
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,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
9 changes: 9 additions & 0 deletions tests/show_ip_int_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ def verify_output(output, expected_output):
print(new_output)
assert new_output == expected_output

def upd_mock_single_asic_get_ip_intf_from_ns(namespace):
return mock_single_asic_get_ip_intf_from_ns(namespace).append("Loopback0")

@pytest.mark.usefixtures('setup_teardown_single_asic')
class TestShowIpInt(object):
Expand All @@ -116,6 +118,13 @@ def test_show_intf_invalid_af_option(self):
assert return_code == 1
assert result == show_error_invalid_af

def test_show_ip_intf_v4_exception(self):
from .mock_tables import mock_single_asic
mock_single_asic.multi_asic_util.multi_asic_get_ip_intf_from_ns = upd_mock_single_asic_get_ip_intf_from_ns
return_code, result = get_result_and_return_code(["ipintutil"])
assert return_code == 0
verify_output(result, show_ipv4_intf_with_multple_ips)
mock_single_asic.multi_asic_util.multi_asic_get_ip_intf_from_ns = mock_single_asic.mock_single_asic_get_ip_intf_from_ns

@pytest.mark.usefixtures('setup_teardown_multi_asic')
class TestMultiAsicShowIpInt(object):
Expand Down
Loading