Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ycabled] fix naming error when error condition is triggered for ycabled CLI handling #302

Merged
merged 4 commits into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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