Skip to content

Commit 501abb2

Browse files
authored
[ycabled] add some exception catching logic to some vendor specific API'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]>
1 parent 534f839 commit 501abb2

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

sonic-ycabled/tests/test_y_cable_helper.py

+18
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,24 @@ def test_update_tor_active_side_with_read_update(self):
568568

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

571+
@patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0]))
572+
@patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True))
573+
def test_update_tor_active_side_with_read_update_with_exception(self):
574+
read_side = -1
575+
state = "active"
576+
logical_port_name = "Ethernet0"
577+
with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util:
578+
579+
mock_toggle_object = MagicMock()
580+
mock_toggle_object.toggle_mux_to_tor_b.return_value = True
581+
mock_toggle_object.get_read_side = MagicMock(
582+
side_effect=NotImplementedError)
583+
patched_util.get.return_value = mock_toggle_object
584+
585+
rc = update_tor_active_side(read_side, state, logical_port_name)
586+
587+
assert(rc == (-1, -1))
588+
571589
def test_get_mux_cable_info_without_presence(self):
572590

573591
rc = get_muxcable_info_without_presence()

sonic-ycabled/ycable/ycable_utilities/y_cable_helper.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,11 @@ def toggle_mux_tor_direction_and_update_read_side(state, logical_port_name, phys
895895
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()))
896896
return (-1, -1)
897897

898-
read_side = port_instance.get_read_side()
898+
try:
899+
read_side = port_instance.get_read_side()
900+
except Exception as e:
901+
read_side = None
902+
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)))
899903

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

19641968
with y_cable_port_locks[physical_port]:
1965-
if port_instance.is_link_active(port_instance.TARGET_NIC):
1969+
try:
1970+
link_state_tor_nic = port_instance.is_link_active(port_instance.TARGET_NIC)
1971+
except Exception as e:
1972+
link_state_tor_nic = False
1973+
helper_logger.log_warning("Failed to execute the is_link_active NIC side API for port {} due to {}".format(physical_port,repr(e)))
1974+
1975+
if link_state_tor_nic:
19661976
mux_info_dict["link_status_nic"] = "up"
19671977
else:
19681978
mux_info_dict["link_status_nic"] = "down"

0 commit comments

Comments
 (0)