Skip to content

Commit

Permalink
[ycabled] add some exception catching logic to some vendor specific A…
Browse files Browse the repository at this point in the history
…PI's (sonic-net#301)

This PR adds a try/catch block for some abstract muxcable API's. In particular the exception logic is added for all the API's where there is a possibility for exceptions to be passed by Vendor API's implementation, in this regard ycabled will have all abstract muxcable API's covered by exception logic with this PR.
If the exception is caught it will be just logged and daemon will resume its normal operation.

Description
Motivation and Context
How Has This Been Tested?
Unit-tests and deploying changes on testbed

Signed-off-by: vaibhav-dahiya <[email protected]>
  • Loading branch information
vdahiya12 authored Sep 29, 2022
1 parent 534f839 commit 501abb2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
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)))

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

0 comments on commit 501abb2

Please sign in to comment.