Skip to content

Commit

Permalink
[ycabled] fix naming error for error condition for CLI handling (soni…
Browse files Browse the repository at this point in the history
…c-net#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
  • Loading branch information
vdahiya12 authored Oct 3, 2022
1 parent 501abb2 commit 23b6970
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
55 changes: 55 additions & 0 deletions sonic-ycabled/tests/test_y_cable_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion sonic-ycabled/ycable/ycable_utilities/y_cable_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 23b6970

Please sign in to comment.