From dd8fbae6fc80fd1cc281ca812387d1d1c1b165af Mon Sep 17 00:00:00 2001 From: vdahiya12 <67608553+vdahiya12@users.noreply.github.com> Date: Thu, 9 Feb 2023 18:01:38 -0800 Subject: [PATCH] [ycabled] add more coverage to ycabled; add minor name change for vendor API CLI return key-values pairs (#338) The main motivation of this PR is improve coverage of ycabled. While fixing unit test cases found an improvement to the name key-values returned to CLI, changed those names for keys as well Signed-off-by: vaibhav-dahiya vdahiya@microsoft.com Description Motivation and Context How Has This Been Tested? Unit-Tests and running the changes on testbed. Additional Information (Optional) --- sonic-ycabled/tests/test_y_cable_helper.py | 998 +++++++++++++++++- .../ycable/ycable_utilities/y_cable_helper.py | 9 +- 2 files changed, 984 insertions(+), 23 deletions(-) diff --git a/sonic-ycabled/tests/test_y_cable_helper.py b/sonic-ycabled/tests/test_y_cable_helper.py index 9345a8d1c..265437fbd 100644 --- a/sonic-ycabled/tests/test_y_cable_helper.py +++ b/sonic-ycabled/tests/test_y_cable_helper.py @@ -3558,20 +3558,814 @@ def test_handle_get_fec_cmd_arg_tbl_notification_no_instance(self, port_instance asic_index = 0 port = "Ethernet0" fvp = {"get_ber": True} + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == -1) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "ber", {"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.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_get_ber(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_ber_rsp_tbl = mock_swsscommon_table + xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_ber_res_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.get_ber_info.return_value = ["100", "200"] + + asic_index = 0 + port = "Ethernet0" + fvp = {"get_ber": True} + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == None) + + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(None, "ber", {"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.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_get_ber_no_target(self, port_instance, mock_swsscommon_table, port_instance_helper): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_ber_rsp_tbl = mock_swsscommon_table + xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_ber_res_tbl = mock_swsscommon_table + port_instance = MagicMock() + port_instance.get_ber_info.return_value = ["100", "200"] + + asic_index = 0 + port = "Ethernet0" + fvp = {"get_ber": True} + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == -1) + + #@patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + #@patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "ber", {"modex": "0", + "lane_mask": "0", + "direction": "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.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_get_ber_with_exception(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_ber_rsp_tbl = mock_swsscommon_table + xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_ber_res_tbl = mock_swsscommon_table + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + + def get_ber_info(self): + raise NotImplementedError + + + patched_util.get.return_value = PortInstanceHelper() + asic_index = 0 + port = "Ethernet0" + fvp = {"get_ber": True} + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == None) + + + #@patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + #@patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(None, "ber", {"modex": "0", + "lane_mask": "0", + "direction": "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.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_get_ber_with_no_target(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_ber_rsp_tbl = mock_swsscommon_table + xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_ber_res_tbl = mock_swsscommon_table + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + + def get_ber_info(self): + raise NotImplementedError + + + patched_util.get.return_value = PortInstanceHelper() + asic_index = 0 + port = "Ethernet0" + fvp = {"get_ber": True} + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == -1) + + + #@patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + #@patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "eye", {"modex": "0", + "lane_mask": "0", + "direction": "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.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_get_eye_with_with_correct_values(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_ber_rsp_tbl = mock_swsscommon_table + xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_ber_res_tbl = mock_swsscommon_table + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + + def get_eye_heights(self, target): + return [1, 2, 3] + + + patched_util.get.return_value = PortInstanceHelper() + asic_index = 0 + port = "Ethernet0" + fvp = {"get_ber": True} + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == None) + + + #@patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + #@patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "eye", {"modex": "0", + "lane_mask": "0", + "direction": "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.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_get_eye_with_with_exception(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_ber_rsp_tbl = mock_swsscommon_table + xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_ber_res_tbl = mock_swsscommon_table + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + + def get_eye_heights(self, target): + raise NotImplementedError + + + patched_util.get.return_value = PortInstanceHelper() + asic_index = 0 + port = "Ethernet0" + fvp = {"get_ber": True} + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == None) + + #@patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + #@patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(None, "eye", {"modex": "0", + "lane_mask": "0", + "direction": "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.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_get_eye_with_with_no_target(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_ber_rsp_tbl = mock_swsscommon_table + xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_ber_res_tbl = mock_swsscommon_table + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + + def get_eye_heights(self, target): + return [1, 2, 3] + + + patched_util.get.return_value = PortInstanceHelper() + asic_index = 0 + port = "Ethernet0" + fvp = {"get_ber": True} + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == -1) + + + + #@patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + #@patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec_stats", {"modex": "0", + "lane_mask": "0", + "direction": "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.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_get_fec_stats_with_with_correct_values(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_ber_rsp_tbl = mock_swsscommon_table + xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_ber_res_tbl = mock_swsscommon_table + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + + def get_fec_stats(self, target): + return {1:"1"} + + + patched_util.get.return_value = PortInstanceHelper() + asic_index = 0 + port = "Ethernet0" + fvp = {"get_ber": True} + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == None) + + + #@patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + #@patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "fec_stats", {"modex": "0", + "lane_mask": "0", + "direction": "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.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_get_fec_stats_with_with_exception(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_ber_rsp_tbl = mock_swsscommon_table + xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_ber_res_tbl = mock_swsscommon_table + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + + def get_fec_stats(self, target): + raise NotImplementedError + + + patched_util.get.return_value = PortInstanceHelper() + asic_index = 0 + port = "Ethernet0" + fvp = {"get_ber": True} + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == None) + + #@patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + #@patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(None, "fec_stats", {"modex": "0", + "lane_mask": "0", + "direction": "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.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_get_fec_stats_with_with_no_target(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_ber_rsp_tbl = mock_swsscommon_table + xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_ber_res_tbl = mock_swsscommon_table + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + + def get_eye_heights(self, target): + return [1, 2, 3] + + + patched_util.get.return_value = PortInstanceHelper() + asic_index = 0 + port = "Ethernet0" + fvp = {"get_ber": True} + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == -1) + + + #@patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + #@patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "pcs_stats", {"modex": "0", + "lane_mask": "0", + "direction": "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.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_get_pcs_stats_with_with_correct_values(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_ber_rsp_tbl = mock_swsscommon_table + xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_ber_res_tbl = mock_swsscommon_table + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + + def get_pcs_stats(self, target): + return {1:"1"} + + + patched_util.get.return_value = PortInstanceHelper() + asic_index = 0 + port = "Ethernet0" + fvp = {"get_ber": True} + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == None) + + + #@patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + #@patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "pcs_stats", {"modex": "0", + "lane_mask": "0", + "direction": "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.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_get_pcs_stats_with_with_exception(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_ber_rsp_tbl = mock_swsscommon_table + xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_ber_res_tbl = mock_swsscommon_table + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + + def get_pcs_stats(self, target): + raise NotImplementedError + + + patched_util.get.return_value = PortInstanceHelper() + asic_index = 0 + port = "Ethernet0" + fvp = {"get_ber": True} + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == None) + + #@patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + #@patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(None, "pcs_stats", {"modex": "0", + "lane_mask": "0", + "direction": "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.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_get_pcs_stats_with_with_no_target(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_ber_rsp_tbl = mock_swsscommon_table + xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_ber_res_tbl = mock_swsscommon_table + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + + def get_eye_heights(self, target): + return [1, 2, 3] + + + patched_util.get.return_value = PortInstanceHelper() + asic_index = 0 + port = "Ethernet0" + fvp = {"get_ber": True} + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == -1) + + + #@patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + #@patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "cable_alive", {"modex": "0", + "lane_mask": "0", + "direction": "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.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_get_alive_status_with_with_exception(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_ber_rsp_tbl = mock_swsscommon_table + xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_ber_res_tbl = mock_swsscommon_table + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + + def get_alive_status(): + raise NotImplementedError + + + patched_util.get.return_value = PortInstanceHelper() + asic_index = 0 + port = "Ethernet0" + fvp = {"get_ber": True} + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == None) + + #@patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + #@patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "health_check", {"modex": "0", + "lane_mask": "0", + "direction": "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.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_get_health_check_with_with_exception(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_ber_rsp_tbl = mock_swsscommon_table + xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_ber_res_tbl = mock_swsscommon_table + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + + def health_check(self): + raise NotImplementedError + + + patched_util.get.return_value = PortInstanceHelper() + asic_index = 0 + port = "Ethernet0" + fvp = {"get_ber": True} + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == None) + + + #@patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + #@patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "reset_cause", {"modex": "0", + "lane_mask": "0", + "direction": "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.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_get_reset_cause_with_with_exception(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_ber_rsp_tbl = mock_swsscommon_table + xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_ber_res_tbl = mock_swsscommon_table + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + + def reset_cause(self): + raise NotImplementedError + + + patched_util.get.return_value = PortInstanceHelper() + asic_index = 0 + port = "Ethernet0" + fvp = {"get_ber": True} + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == None) + + #@patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + #@patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "operation_time", {"modex": "0", + "lane_mask": "0", + "direction": "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.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_get_operation_time_with_with_exception(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_ber_rsp_tbl = mock_swsscommon_table + xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_ber_res_tbl = mock_swsscommon_table + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + + def operation_time(self): + raise NotImplementedError + + + patched_util.get.return_value = PortInstanceHelper() + asic_index = 0 + port = "Ethernet0" + fvp = {"get_ber": True} + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == None) + + #@patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + #@patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "debug_dump", {"modex": "0", + "lane_mask": "0", + "direction": "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.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_get_debug_dump_with_with_exception(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_ber_rsp_tbl = mock_swsscommon_table + xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_ber_res_tbl = mock_swsscommon_table + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + + def debug_dump_registers(self, option): + raise NotImplementedError + + + patched_util.get.return_value = PortInstanceHelper() + asic_index = 0 + port = "Ethernet0" + fvp = {"get_ber": True} + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == None) + + + #@patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + #@patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "debug_dump", {"modex": "0", + "lane_mask": "0", + "direction": "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.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_get_debug_dump_with_correct_values(self, mock_swsscommon_table): - rc = handle_show_ber_cmd_arg_tbl_notification( - fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) - assert(rc == -1) + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table - @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_ber_rsp_tbl = mock_swsscommon_table + xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_ber_res_tbl = mock_swsscommon_table + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + + def debug_dump_registers(self, option= None): + return {1:"1"} + + + patched_util.get.return_value = PortInstanceHelper() + asic_index = 0 + port = "Ethernet0" + fvp = {"get_ber": True} + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == None) + + #@patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') @patch('swsscommon.swsscommon.Table') - @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + #@patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "queue_info", {"modex": "0", + "lane_mask": "0", + "direction": "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.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_get_queue_info_with_correct_values(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_ber_rsp_tbl = mock_swsscommon_table + xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_ber_res_tbl = mock_swsscommon_table + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + + def queue_info(self): + return {1:"1"} + + + patched_util.get.return_value = PortInstanceHelper() + asic_index = 0 + port = "Ethernet0" + fvp = {"get_ber": True} + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == None) + + #@patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + #@patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "queue_info", {"modex": "0", + "lane_mask": "0", + "direction": "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.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) + def test_handle_get_fec_cmd_arg_tbl_notification_get_queue_info_with_exception(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_ber_rsp_tbl = mock_swsscommon_table + xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_ber_res_tbl = mock_swsscommon_table + + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + + def queue_info(self): + raise NotImplementedError + + + patched_util.get.return_value = PortInstanceHelper() + asic_index = 0 + port = "Ethernet0" + fvp = {"get_ber": True} + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == None) + + + + + #@patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') + @patch('swsscommon.swsscommon.Table') + #@patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "ber", {"modex": "0", "lane_mask": "0", "direction": "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.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0))) @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_get_fec_cmd_arg_tbl_notification_get_ber(self, port_instance, mock_swsscommon_table, port_instance_helper): + def test_handle_get_fec_cmd_arg_tbl_notification_get_ber_with_with_correct_values(self, mock_swsscommon_table): mock_table = MagicMock() mock_swsscommon_table.return_value = mock_table @@ -3580,16 +4374,25 @@ def test_handle_get_fec_cmd_arg_tbl_notification_get_ber(self, port_instance, mo xcvrd_show_ber_rsp_tbl = mock_swsscommon_table xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table xcvrd_show_ber_res_tbl = mock_swsscommon_table - port_instance = MagicMock() - port_instance.get_ber_info.return_value = ["100", "200"] - asic_index = 0 - port = "Ethernet0" - fvp = {"get_ber": True} + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + + def get_ber_info(self, target): + return [1, 2, 3] + + + patched_util.get.return_value = PortInstanceHelper() + asic_index = 0 + port = "Ethernet0" + fvp = {"get_ber": True} + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == None) - rc = handle_show_ber_cmd_arg_tbl_notification( - fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) - assert(rc == None) @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') @patch('swsscommon.swsscommon.Table') @@ -3619,6 +4422,43 @@ def test_handle_get_fec_cmd_arg_tbl_notification_get_eye(self, port_instance, mo fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) assert(rc == None) + + + @patch('swsscommon.swsscommon.Table') + @patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "eye", {"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])) + def test_handle_get_fec_cmd_arg_tbl_notification_get_eye_with_exception(self, mock_swsscommon_table): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table + xcvrd_show_ber_rsp_tbl = mock_swsscommon_table + xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table + xcvrd_show_ber_res_tbl = mock_swsscommon_table + + asic_index = 0 + port = "Ethernet0" + fvp = {"get_ber": True} + with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as patched_util: + class PortInstanceHelper(): + def __init__(self): + self.EEPROM_ERROR = -1 + + def get_ber_info(self): + raise NotImplementedError + patched_util.get.return_value = PortInstanceHelper() + + + rc = handle_show_ber_cmd_arg_tbl_notification( + fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port) + assert(rc == None) + @patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') @patch('swsscommon.swsscommon.Table') @patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port') @@ -3767,7 +4607,7 @@ def test_handle_get_fec_cmd_arg_tbl_notification_get_cable_health(self, port_ins "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.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_get_fec_cmd_arg_tbl_notification_get_reset_cause(self, port_instance, mock_swsscommon_table, port_instance_helper): + def test_handle_get_fec_cmd_arg_tbl_notification_get_reset_cause_correct_values(self, port_instance, mock_swsscommon_table, port_instance_helper): mock_table = MagicMock() mock_swsscommon_table.return_value = mock_table @@ -3777,7 +4617,7 @@ def test_handle_get_fec_cmd_arg_tbl_notification_get_reset_cause(self, port_inst xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table xcvrd_show_ber_res_tbl = mock_swsscommon_table port_instance = MagicMock() - port_instance.health_check.return_value = 0 + port_instance.reset_cause.return_value = "xyz was reset" asic_index = 0 port = "Ethernet0" @@ -3795,7 +4635,7 @@ def test_handle_get_fec_cmd_arg_tbl_notification_get_reset_cause(self, port_inst "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.y_cable_port_locks', MagicMock(return_value=[0])) - def test_handle_get_fec_cmd_arg_tbl_notification_get_reset_cause(self, port_instance, mock_swsscommon_table, port_instance_helper): + def test_handle_get_fec_cmd_arg_tbl_notification_get_operation_time(self, port_instance, mock_swsscommon_table, port_instance_helper): mock_table = MagicMock() mock_swsscommon_table.return_value = mock_table @@ -3805,7 +4645,7 @@ def test_handle_get_fec_cmd_arg_tbl_notification_get_reset_cause(self, port_inst xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table xcvrd_show_ber_res_tbl = mock_swsscommon_table port_instance = MagicMock() - port_instance.oporation_time.return_value = 0 + port_instance.operation_time.return_value = 0 asic_index = 0 port = "Ethernet0" @@ -3833,7 +4673,7 @@ def test_handle_get_fec_cmd_arg_tbl_notification_get_queue_info(self, port_insta xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table xcvrd_show_ber_res_tbl = mock_swsscommon_table port_instance = MagicMock() - port_instance.queue_info.return_value = 0 + port_instance.queue_info.return_value = {"1":"2"} asic_index = 0 port = "Ethernet0" @@ -4461,6 +5301,126 @@ def get_mux_direction(): fvp, xcvrd_config_hwmode_swmode_cmd_sts_tbl, xcvrd_config_hwmode_swmode_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_switchmode_cmd_arg_tbl_notification_with_instance_manual_with_exception(self, mock_swsscommon_table, platform_sfputil): + + mock_table = MagicMock() + mock_swsscommon_table.return_value = mock_table + + xcvrd_config_hwmode_swmode_cmd_sts_tbl = mock_swsscommon_table + xcvrd_config_hwmode_swmode_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": "manual"} + + 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 = "auto" + self.SWITCHING_MODE_MANUAL = "manual" + + def get_read_side(self): + return 1 + + def set_switching_mode(self, mode): + raise NotImplementedError + + # 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_mux_switchmode_arg_tbl_notification( + fvp, xcvrd_config_hwmode_swmode_cmd_sts_tbl, xcvrd_config_hwmode_swmode_rsp_tbl, asic_index, port) + assert(rc == -1) + + fvp = {"config": "auto"} + + 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 = "auto" + self.SWITCHING_MODE_MANUAL = "manual" + + def get_read_side(self): + return 1 + + def set_switching_mode(self, mode): + raise NotImplementedError + + # 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_mux_switchmode_arg_tbl_notification( + fvp, xcvrd_config_hwmode_swmode_cmd_sts_tbl, xcvrd_config_hwmode_swmode_rsp_tbl, asic_index, port) + assert(rc == -1) + + + fvp = {"config": "xyz"} + 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 = "auto" + self.SWITCHING_MODE_MANUAL = "manual" + + def get_read_side(self): + return 1 + + def set_switching_mode(self, mode): + raise NotImplementedError + + # 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_mux_switchmode_arg_tbl_notification( + fvp, xcvrd_config_hwmode_swmode_cmd_sts_tbl, xcvrd_config_hwmode_swmode_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 32a791540..89c9908a3 100644 --- a/sonic-ycabled/ycable/ycable_utilities/y_cable_helper.py +++ b/sonic-ycabled/ycable/ycable_utilities/y_cable_helper.py @@ -1957,6 +1957,7 @@ def handle_config_firmware_down_cmd_arg_tbl_notification(fvp, xcvrd_down_fw_cmd_ def handle_show_ber_cmd_arg_tbl_notification(fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port): fvp_dict = dict(fvp) status = 'False' + res = None if "get_ber" in fvp_dict: @@ -2049,7 +2050,7 @@ def handle_show_ber_cmd_arg_tbl_notification(fvp, xcvrd_show_ber_cmd_arg_tbl, xc helper_logger.log_warning("Failed to execute cli cmd get_alive_status API for port {} due to {}".format(physical_port,repr(e))) if res is not None: fvs_log = swsscommon.FieldValuePairs( - [("cable", str(res))]) + [("cable_alive", str(res))]) xcvrd_show_ber_res_tbl[asic_index].set(port, fvs_log) elif mode == "health_check": with y_cable_port_locks[physical_port]: @@ -2061,7 +2062,7 @@ def handle_show_ber_cmd_arg_tbl_notification(fvp, xcvrd_show_ber_cmd_arg_tbl, xc helper_logger.log_warning("Failed to execute cli cmd get_health API for port {} due to {}".format(physical_port,repr(e))) if res is not None: fvs_log = swsscommon.FieldValuePairs( - [("cable", str(res))]) + [("health_check", str(res))]) xcvrd_show_ber_res_tbl[asic_index].set(port, fvs_log) elif mode == "reset_cause": with y_cable_port_locks[physical_port]: @@ -2073,7 +2074,7 @@ def handle_show_ber_cmd_arg_tbl_notification(fvp, xcvrd_show_ber_cmd_arg_tbl, xc helper_logger.log_warning("Failed to execute reset cause cmd API for port {} due to {}".format(physical_port,repr(e))) if res is not None: fvs_log = swsscommon.FieldValuePairs( - [("cable", str(res))]) + [("reset_cause", str(res))]) xcvrd_show_ber_res_tbl[asic_index].set(port, fvs_log) elif mode == "operation_time": with y_cable_port_locks[physical_port]: @@ -2085,7 +2086,7 @@ def handle_show_ber_cmd_arg_tbl_notification(fvp, xcvrd_show_ber_cmd_arg_tbl, xc helper_logger.log_warning("Failed to execute operation time cmd API for port {} due to {}".format(physical_port,repr(e))) if res is not None: fvs_log = swsscommon.FieldValuePairs( - [("cable", str(res))]) + [("operation_time", str(res))]) xcvrd_show_ber_res_tbl[asic_index].set(port, fvs_log) elif mode == "debug_dump": option = res_dir.get("option", None)