Skip to content

Commit 23b6970

Browse files
authored
[ycabled] fix naming error for error condition for CLI handling (#302)
Signed-off-by: vaibhav-dahiya [email protected] This PR fixes a typo/error condition when read_side is not 1 or 2 or -1, for a case where NIC side is plugged into the ToR and a user configures a CLI for sudo config mux hwmode state active/standby <port>, in such a scenario we can trigger this xcvrd_config_hwmode_state_cmd_sts_tbl attribute error. Description Motivation and Context How Has This Been Tested? Unit-tests and loading the changes on Arista testbed
1 parent 501abb2 commit 23b6970

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

sonic-ycabled/tests/test_y_cable_helper.py

+55
Original file line numberDiff line numberDiff line change
@@ -4627,6 +4627,61 @@ def get_mux_direction():
46274627
fvp, xcvrd_config_hwmode_state_cmd_sts_tbl, xcvrd_config_hwmode_state_rsp_tbl, asic_index, port)
46284628
assert(rc == None)
46294629

4630+
@patch('swsscommon.swsscommon.Table')
4631+
@patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil')
4632+
@patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0",
4633+
"lane_mask": "0",
4634+
"direction": "0"})))
4635+
@patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0)))
4636+
@patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0]))
4637+
@patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True))
4638+
@patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0]))
4639+
@patch('os.path.isfile', MagicMock(return_value=True))
4640+
@patch('time.sleep', MagicMock(return_value=True))
4641+
def test_handle_config_mux_state_cmd_arg_tbl_notification_with_instance_cmd_arg(self, mock_swsscommon_table, platform_sfputil):
4642+
4643+
mock_table = MagicMock()
4644+
mock_swsscommon_table.return_value = mock_table
4645+
4646+
xcvrd_config_hwmode_state_cmd_sts_tbl = mock_swsscommon_table
4647+
xcvrd_config_hwmode_state_rsp_tbl = mock_swsscommon_table
4648+
asic_index = 0
4649+
task_download_firmware_thread = {}
4650+
port = "Ethernet0"
4651+
platform_sfputil.get_asic_id_for_logical_port = 0
4652+
fvp = {"config": "active"}
4653+
4654+
with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util:
4655+
class PortInstanceHelper():
4656+
def __init__(self):
4657+
self.EEPROM_ERROR = -1
4658+
self.TARGET_NIC = 1
4659+
self.TARGET_TOR_A = 1
4660+
self.TARGET_TOR_B = 1
4661+
self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1
4662+
self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2
4663+
self.download_firmware_status = 0
4664+
self.SWITCH_COUNT_MANUAL = "manual"
4665+
self.SWITCH_COUNT_AUTO = 0
4666+
self.SWITCHING_MODE_MANUAL = 0
4667+
self.SWITCHING_MODE_AUTO = 1
4668+
4669+
def get_read_side(self):
4670+
return 3
4671+
4672+
def get_switching_mode(self):
4673+
return 0
4674+
4675+
# Defining function without self argument creates an exception,
4676+
# which is what we want for this test.
4677+
def get_mux_direction():
4678+
pass
4679+
4680+
patched_util.get.return_value = PortInstanceHelper()
4681+
rc = handle_config_hwmode_state_cmd_arg_tbl_notification(
4682+
fvp, xcvrd_config_hwmode_state_cmd_sts_tbl, xcvrd_config_hwmode_state_rsp_tbl, asic_index, port)
4683+
assert(rc == -1)
4684+
46304685
@patch('swsscommon.swsscommon.Table')
46314686
@patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0",
46324687
"lane_mask": "0",

sonic-ycabled/ycable/ycable_utilities/y_cable_helper.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3127,7 +3127,7 @@ def handle_config_hwmode_state_cmd_arg_tbl_notification(fvp, xcvrd_config_hwmode
31273127
status = -1
31283128
helper_logger.log_warning("Failed to execute the toggle mux ToR A API for port {} due to {}".format(physical_port,repr(e)))
31293129
else:
3130-
set_result_and_delete_port('result', status, xcvrd_show_hwmode_state_cmd_sts_tbl[asic_index], xcvrd_config_hwmode_state_rsp_tbl[asic_index], port)
3130+
set_result_and_delete_port('result', status, xcvrd_config_hwmode_state_cmd_sts_tbl[asic_index], xcvrd_config_hwmode_state_rsp_tbl[asic_index], port)
31313131
helper_logger.log_error(
31323132
"Error: Could not get valid config read side for cli command config mux hwmode state active/standby Y cable port {}".format(port))
31333133
return -1

0 commit comments

Comments
 (0)