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

[ycabled] add some exception catching logic to some vendor specific API's #301

Merged
merged 5 commits into from
Sep 29, 2022
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
18 changes: 18 additions & 0 deletions sonic-ycabled/tests/test_y_cable_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,24 @@ def test_update_tor_active_side_with_read_update(self):

assert(rc == (-1, -1))

@patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0]))
@patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True))
def test_update_tor_active_side_with_read_update_with_exception(self):
read_side = -1
state = "active"
logical_port_name = "Ethernet0"
with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util:

mock_toggle_object = MagicMock()
mock_toggle_object.toggle_mux_to_tor_b.return_value = True
mock_toggle_object.get_read_side = MagicMock(
side_effect=NotImplementedError)
patched_util.get.return_value = mock_toggle_object

rc = update_tor_active_side(read_side, state, logical_port_name)

assert(rc == (-1, -1))

def test_get_mux_cable_info_without_presence(self):

rc = get_muxcable_info_without_presence()
Expand Down
14 changes: 12 additions & 2 deletions sonic-ycabled/ycable/ycable_utilities/y_cable_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,11 @@ def toggle_mux_tor_direction_and_update_read_side(state, logical_port_name, phys
helper_logger.log_error("Error: Could not get port instance for read side for while processing a toggle Y cable port {} {}".format(physical_port, threading.currentThread().getName()))
return (-1, -1)

read_side = port_instance.get_read_side()
try:
read_side = port_instance.get_read_side()
except Exception as e:
read_side = None
helper_logger.log_warning("Failed to execute the get_read_side API for port {} due to {} from update_read_side".format(logical_port_name,repr(e)))
zjswhhh marked this conversation as resolved.
Show resolved Hide resolved

if read_side is None or read_side is port_instance.EEPROM_ERROR or read_side < 0:
helper_logger.log_error(
Expand Down Expand Up @@ -1962,7 +1966,13 @@ def get_muxcable_info(physical_port, logical_port_name):
mux_info_dict["link_status_peer"] = "down"

with y_cable_port_locks[physical_port]:
if port_instance.is_link_active(port_instance.TARGET_NIC):
try:
link_state_tor_nic = port_instance.is_link_active(port_instance.TARGET_NIC)
except Exception as e:
link_state_tor_nic = False
helper_logger.log_warning("Failed to execute the is_link_active NIC side API for port {} due to {}".format(physical_port,repr(e)))

if link_state_tor_nic:
mux_info_dict["link_status_nic"] = "up"
else:
mux_info_dict["link_status_nic"] = "down"
Expand Down