From 23b6970b52b8b9f9947e4109370695cb5d05704a Mon Sep 17 00:00:00 2001 From: vdahiya12 <67608553+vdahiya12@users.noreply.github.com> Date: Mon, 3 Oct 2022 14:23:37 -0700 Subject: [PATCH] [ycabled] fix naming error for error condition for CLI handling (#302) Signed-off-by: vaibhav-dahiya vdahiya@microsoft.com 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 , 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 --- sonic-ycabled/tests/test_y_cable_helper.py | 55 +++++++++++++++++++ .../ycable/ycable_utilities/y_cable_helper.py | 2 +- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/sonic-ycabled/tests/test_y_cable_helper.py b/sonic-ycabled/tests/test_y_cable_helper.py index b4a5b7b17131..93c1eeedbc42 100644 --- a/sonic-ycabled/tests/test_y_cable_helper.py +++ b/sonic-ycabled/tests/test_y_cable_helper.py @@ -4627,6 +4627,61 @@ def get_mux_direction(): fvp, xcvrd_config_hwmode_state_cmd_sts_tbl, xcvrd_config_hwmode_state_rsp_tbl, asic_index, port) assert(rc == None) + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "activate_firmware", {"modex": "0", + "lane_mask": "0", + "direction": "0"}))) + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @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)) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + @patch('os.path.isfile', MagicMock(return_value=True)) + @patch('time.sleep', MagicMock(return_value=True)) + def test_handle_config_mux_state_cmd_arg_tbl_notification_with_instance_cmd_arg(self, mock_swsscommon_table, platform_sfputil): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_hwmode_state_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_hwmode_state_rsp_tbl = mock_swsscommon_table + asic_index = 0 + task_download_firmware_thread = {} + port = "Ethernet0" + platform_sfputil.get_asic_id_for_logical_port = 0 + fvp = {"config": "active"} + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + self.TARGET_NIC = 1 + self.TARGET_TOR_A = 1 + self.TARGET_TOR_B = 1 + self.FIRMWARE_DOWNLOAD_STATUS_INPROGRESS = 1 + self.FIRMWARE_DOWNLOAD_STATUS_FAILED = 2 + self.download_firmware_status = 0 + self.SWITCH_COUNT_MANUAL = "manual" + self.SWITCH_COUNT_AUTO = 0 + self.SWITCHING_MODE_MANUAL = 0 + self.SWITCHING_MODE_AUTO = 1 + + def get_read_side(self): + return 3 + + def get_switching_mode(self): + return 0 + + # Defining function without self argument creates an exception, + # which is what we want for this test. + def get_mux_direction(): + pass + + patched_util.get.return_value = PortInstanceHelper() + rc = handle_config_hwmode_state_cmd_arg_tbl_notification( + fvp, xcvrd_config_hwmode_state_cmd_sts_tbl, xcvrd_config_hwmode_state_rsp_tbl, asic_index, port) + assert(rc == -1) + @patch('swsscommon.swsscommon.Table') @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec", {"modex": "0", "lane_mask": "0", diff --git a/sonic-ycabled/ycable/ycable_utilities/y_cable_helper.py b/sonic-ycabled/ycable/ycable_utilities/y_cable_helper.py index 9a264ba01722..e083b89c4b99 100644 --- a/sonic-ycabled/ycable/ycable_utilities/y_cable_helper.py +++ b/sonic-ycabled/ycable/ycable_utilities/y_cable_helper.py @@ -3127,7 +3127,7 @@ def handle_config_hwmode_state_cmd_arg_tbl_notification(fvp, xcvrd_config_hwmode status = -1 helper_logger.log_warning("Failed to execute the toggle mux ToR A API for port {} due to {}".format(physical_port,repr(e))) else: - 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) + 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) helper_logger.log_error( "Error: Could not get valid config read side for cli command config mux hwmode state active/standby Y cable port {}".format(port)) return -1