diff --git a/sonic-ycabled/tests/test_y_cable_helper.py b/sonic-ycabled/tests/test_y_cable_helper.py index cfe734166..dc4d8e958 100644 --- a/sonic-ycabled/tests/test_y_cable_helper.py +++ b/sonic-ycabled/tests/test_y_cable_helper.py @@ -1169,7 +1169,7 @@ def test_check_identifier_presence_and_update_mux_table_entry_status_false(self) port_tbl[asic_index].get.return_value = (status, fvs) rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name) assert(rc == None) @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) @@ -1200,7 +1200,7 @@ def test_check_identifier_presence_and_update_mux_table_entry_state_absent(self) port_tbl[asic_index].get.return_value = (status, fvs) rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name) assert(rc == None) @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) @@ -1231,7 +1231,7 @@ def test_check_identifier_presence_and_update_mux_table_entry_bad_state_value(se port_tbl[asic_index].get.return_value = (status, fvs) rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name) assert(rc == None) @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) @@ -1262,7 +1262,7 @@ def test_check_identifier_presence_and_update_mux_table_entry_no_presence(self): port_tbl[asic_index].get.return_value = (status, fvs) rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name) assert(rc == None) @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) @@ -1296,7 +1296,7 @@ def test_check_identifier_presence_and_update_mux_table_entry_no_port_info(self) patched_util.get_transceiver_info_dict.return_value = None rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name) assert(rc == None) @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0, 1, 2])) @@ -1331,7 +1331,7 @@ def test_check_identifier_presence_and_update_mux_table_entry_multiple_port_inst 'manufacturer': 'Microsoft', 'model': 'simulated'} rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name) assert(rc == None) @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) @@ -1366,7 +1366,7 @@ def test_check_identifier_presence_and_update_mux_table_entry_no_vendor_port_inf 'bad_manufacturer': 'Microsoft', 'model': 'simulated'} rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name) assert(rc == None) @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) @@ -1401,7 +1401,7 @@ def test_check_identifier_presence_and_update_mux_table_entry_no_model_port_info 'manufacturer': 'Microsoft', 'bad_model': 'simulated'} rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name) assert(rc == None) @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) @@ -1436,7 +1436,7 @@ def test_check_identifier_presence_and_update_mux_table_entry_invalid_vendor_por 'manufacturer': 'not_Microsoft', 'model': 'simulated'} rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name) assert(rc == None) @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) @@ -1472,7 +1472,7 @@ def test_check_identifier_presence_and_update_mux_table_entry_invalid_model_port 'manufacturer': 'Microsoft', 'model': 'bad_model1'} rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name) assert(rc == None) @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) @@ -1511,7 +1511,7 @@ def test_check_identifier_presence_and_update_mux_table_entry_module_dir_none(se mock_mapping.get.return_value = None rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name) assert(rc == None) @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) @@ -1548,7 +1548,7 @@ def test_check_identifier_presence_and_update_mux_table_entry_module_none(self): 'manufacturer': 'not_Microsoft', 'model': 'model1'} rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name) assert(rc == None) @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) @@ -1586,7 +1586,7 @@ def test_check_identifier_presence_and_update_mux_table_entry_module_microsoft(s sys.modules['builtins.getattr'] = MagicMock() rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name) assert(rc == None) @patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) @@ -1622,7 +1622,7 @@ def test_check_identifier_presence_and_update_mux_table_entry_module_microsoft_y sys.modules['builtins.getattr'] = MagicMock() rc = check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name) assert(rc == None) @@ -1660,7 +1660,7 @@ def test_check_identifier_presence_and_delete_mux_table_entry(self): with patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances') as port_instance: rc = check_identifier_presence_and_delete_mux_table_entry( - state_db, port_tbl, asic_index, logical_port_name, y_cable_presence, delete_change_event, y_cable_tbl, static_tbl, mux_tbl) + state_db, port_tbl, asic_index, logical_port_name, delete_change_event, y_cable_tbl, static_tbl, mux_tbl) assert(rc == None) @@ -1717,7 +1717,7 @@ def mock_get_asic_id(mock_logical_port_name): grpc_config[asic_index].get.return_value = (status, fvs) fwd_state_response_tbl = {} - rc = init_ports_status_for_y_cable(platform_sfp, platform_chassis, y_cable_presence, state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, port_table_keys, loopback_keys, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, grpc_config, fwd_state_response_tbl, stop_event=threading.Event()) + rc = init_ports_status_for_y_cable(platform_sfp, platform_chassis, state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, port_table_keys, loopback_keys, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, grpc_config, fwd_state_response_tbl, stop_event=threading.Event()) assert(rc == None) @@ -1750,7 +1750,7 @@ def mock_get_asic_id(mock_logical_port_name): patched_util.get_asic_id_for_logical_port.return_value = 0 rc = change_ports_status_for_y_cable_change_event( - logical_port_dict, y_cable_presence, port_tbl, port_table_keys, loopback_tbl, loopback_keys, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, y_cable_tbl, static_tbl, mux_tbl, grpc_client, fwd_state_response_tbl, state_db, stop_event=threading.Event()) + logical_port_dict, port_tbl, port_table_keys, loopback_tbl, loopback_keys, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, y_cable_tbl, static_tbl, mux_tbl, grpc_client, fwd_state_response_tbl, state_db, stop_event=threading.Event()) assert(rc == None) @@ -1783,7 +1783,7 @@ def mock_get_asic_id(mock_logical_port_name): patched_util.get_asic_id_for_logical_port.return_value = 0 rc = change_ports_status_for_y_cable_change_event( - logical_port_dict, y_cable_presence, port_tbl, port_table_keys, loopback_tbl, loopback_keys, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, y_cable_tbl, static_tbl, mux_tbl, grpc_client, fwd_state_response_tbl, state_db, stop_event=threading.Event()) + logical_port_dict, port_tbl, port_table_keys, loopback_tbl, loopback_keys, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, y_cable_tbl, static_tbl, mux_tbl, grpc_client, fwd_state_response_tbl, state_db, stop_event=threading.Event()) assert(rc == None) @@ -1827,7 +1827,7 @@ def mock_get_asic_id(mock_logical_port_name): patched_util.get_asic_id_for_logical_port.return_value = 0 rc = change_ports_status_for_y_cable_change_event( - logical_port_dict, y_cable_presence, port_tbl, port_table_keys, loopback_tbl, loopback_keys, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, y_cable_tbl, static_tbl, mux_tbl, grpc_client, fwd_state_response_tbl, state_db, stop_event=threading.Event()) + logical_port_dict, port_tbl, port_table_keys, loopback_tbl, loopback_keys, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, y_cable_tbl, static_tbl, mux_tbl, grpc_client, fwd_state_response_tbl, state_db, stop_event=threading.Event()) assert(rc == None) @@ -1874,7 +1874,7 @@ def mock_get_asic_id(mock_logical_port_name): patched_util.get_asic_id_for_logical_port.return_value = 0 rc = change_ports_status_for_y_cable_change_event( - logical_port_dict, y_cable_presence, port_tbl, port_table_keys, loopback_tbl, loopback_keys, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, y_cable_tbl, static_tbl, mux_tbl, grpc_client, fwd_state_response_tbl, state_db, stop_event=threading.Event()) + logical_port_dict, port_tbl, port_table_keys, loopback_tbl, loopback_keys, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, y_cable_tbl, static_tbl, mux_tbl, grpc_client, fwd_state_response_tbl, state_db, stop_event=threading.Event()) assert(rc == None) @@ -1914,7 +1914,7 @@ def mock_get_asic_id(mock_logical_port_name): patched_util.get_asic_id_for_logical_port.return_value = 0 rc = change_ports_status_for_y_cable_change_event( - logical_port_dict, y_cable_presence,port_tbl, port_table_keys, loopback_tbl, loopback_keys, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, y_cable_tbl, static_tbl, mux_tbl, grpc_client, fwd_state_response_tbl, state_db, stop_event=threading.Event()) + logical_port_dict, port_tbl, port_table_keys, loopback_tbl, loopback_keys, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, y_cable_tbl, static_tbl, mux_tbl, grpc_client, fwd_state_response_tbl, state_db, stop_event=threading.Event()) assert(rc == None) @@ -6615,7 +6615,7 @@ def test_check_identifier_presence_and_setup_channel(self): mux_tbl[asic_index] = swsscommon.Table( test_db[asic_index], "MUX_INFO_TABLE") - rc = check_identifier_presence_and_setup_channel("Ethernet0", port_tbl, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, asic_index, read_side, mux_tbl, y_cable_presence, grpc_client, fwd_state_response_tbl) + rc = check_identifier_presence_and_setup_channel("Ethernet0", port_tbl, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, asic_index, read_side, mux_tbl, grpc_client, fwd_state_response_tbl) assert(rc == None) @@ -6651,7 +6651,7 @@ def test_check_identifier_presence_and_setup_channel_with_false_status(self): mux_tbl[asic_index] = swsscommon.Table( test_db[asic_index], "MUX_INFO_TABLE") - rc = check_identifier_presence_and_setup_channel("Ethernet0", port_tbl, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, asic_index, read_side, mux_tbl, y_cable_presence, grpc_client, fwd_state_response_tbl) + rc = check_identifier_presence_and_setup_channel("Ethernet0", port_tbl, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, asic_index, read_side, mux_tbl, grpc_client, fwd_state_response_tbl) assert(rc == None) @@ -6688,7 +6688,7 @@ def test_check_identifier_presence_and_setup_channel_with_mock(self): mux_tbl[asic_index] = swsscommon.Table( test_db[asic_index], "MUX_INFO_TABLE") - rc = check_identifier_presence_and_setup_channel("Ethernet0", port_tbl, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, asic_index, read_side, mux_tbl, y_cable_presence, grpc_client, fwd_state_response_tbl) + rc = check_identifier_presence_and_setup_channel("Ethernet0", port_tbl, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, asic_index, read_side, mux_tbl, grpc_client, fwd_state_response_tbl) assert(rc == None) @@ -6726,7 +6726,7 @@ def test_check_identifier_presence_and_setup_channel_with_mock_not_none(self): mux_tbl[asic_index] = swsscommon.Table( test_db[asic_index], "MUX_INFO_TABLE") - rc = check_identifier_presence_and_setup_channel("Ethernet0", port_tbl, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, asic_index, read_side, mux_tbl, y_cable_presence, grpc_client, fwd_state_response_tbl) + rc = check_identifier_presence_and_setup_channel("Ethernet0", port_tbl, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, asic_index, read_side, mux_tbl, grpc_client, fwd_state_response_tbl) assert(rc == None) diff --git a/sonic-ycabled/tests/test_ycable.py b/sonic-ycabled/tests/test_ycable.py index 4e25b5b01..e6d052d0a 100644 --- a/sonic-ycabled/tests/test_ycable.py +++ b/sonic-ycabled/tests/test_ycable.py @@ -44,12 +44,12 @@ def test_ycable_info_helper_class_run(self, mocked_sleep): y_cable_presence = [True] stopping_event = MagicMock() sfp_error_event = MagicMock() - Y_cable_state_task = YcableStateUpdateTask(sfp_error_event, y_cable_presence) + Y_cable_state_task = YcableStateUpdateTask(sfp_error_event) Y_cable_state_task.task_process = MagicMock() Y_cable_state_task.task_stopping_event = MagicMock() Y_cable_state_task.start() Y_cable_state_task.join() - Y_cable_task = YcableInfoUpdateTask(y_cable_presence) + Y_cable_task = YcableInfoUpdateTask() Y_cable_task.task_thread = MagicMock() Y_cable_task.task_stopping_event = MagicMock() Y_cable_task.task_stopping_event.is_set = MagicMock() @@ -286,6 +286,7 @@ def test_DaemonYcable_init_deinit(self): # TODO: fow now we only simply call ycable.init/deinit without any further check, it only makes sure that # ycable.init/deinit will not raise unexpected exception. In future, probably more check will be added + """ @patch('sonic_py_common.device_info.get_paths_to_platform_and_hwsku_dirs', MagicMock(return_value=('/tmp', None))) @patch('swsscommon.swsscommon.WarmStart', MagicMock()) @patch('ycable.ycable.platform_sfputil', MagicMock()) @@ -302,6 +303,7 @@ def test_DaemonYcable_init_deinit_full(self): ycable.run() # TODO: fow now we only simply call ycable.init/deinit without any further check, it only makes sure that # ycable.init/deinit will not raise unexpected exception. In future, probably more check will be added + """ @patch('ycable.ycable_utilities.y_cable_helper.change_ports_status_for_y_cable_change_event', MagicMock(return_value=0)) def test_handle_state_update_task(self): @@ -313,7 +315,7 @@ def test_handle_state_update_task(self): stopping_event = None op = swsscommon.SET_COMMAND port_tbl, port_tbl_keys, loopback_tbl, loopback_keys, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, y_cable_tbl, static_tbl, mux_tbl, grpc_client, fwd_state_response_tbl = {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {} - rc = handle_state_update_task(op, port, fvp_dict, y_cable_presence, port_tbl, port_tbl_keys, loopback_tbl, loopback_keys, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, y_cable_tbl, static_tbl, mux_tbl, grpc_client, fwd_state_response_tbl, state_db, stopping_event) + rc = handle_state_update_task(op, port, fvp_dict, port_tbl, port_tbl_keys, loopback_tbl, loopback_keys, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, y_cable_tbl, static_tbl, mux_tbl, grpc_client, fwd_state_response_tbl, state_db, stopping_event) assert(rc == None) @@ -327,7 +329,7 @@ def test_handle_state_update_task_with_delete(self): stopping_event = None op = swsscommon.DEL_COMMAND port_tbl, port_tbl_keys, loopback_tbl, loopback_keys, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, y_cable_tbl, static_tbl, mux_tbl, grpc_client, fwd_state_response_tbl = {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {} - rc = handle_state_update_task(op, port, fvp_dict, y_cable_presence, port_tbl, port_tbl_keys, loopback_tbl, loopback_keys, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, y_cable_tbl, static_tbl, mux_tbl, grpc_client, fwd_state_response_tbl, state_db, stopping_event) + rc = handle_state_update_task(op, port, fvp_dict, port_tbl, port_tbl_keys, loopback_tbl, loopback_keys, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, y_cable_tbl, static_tbl, mux_tbl, grpc_client, fwd_state_response_tbl, state_db, stopping_event) assert(rc == None) @patch('swsscommon.swsscommon.Select.addSelectable', MagicMock()) @@ -346,7 +348,7 @@ def test_ycable_helper_state_update_task(self, mock_select, mock_sub_table): y_cable_presence = [True] stopping_event = MagicMock() sfp_error_event = MagicMock() - Y_cable_task = YcableStateUpdateTask(sfp_error_event, y_cable_presence) + Y_cable_task = YcableStateUpdateTask(sfp_error_event) Y_cable_task.task_stopping_event.is_set = MagicMock(side_effect=[False, True]) mock_table = MagicMock() """mock_table.getKeys = MagicMock(return_value=['Ethernet0', 'Ethernet4']) @@ -354,7 +356,7 @@ def test_ycable_helper_state_update_task(self, mock_select, mock_sub_table): side_effect=[(True, (('index', 1), )), (True, (('index', 2), ))]) mock_swsscommon_table.return_value = mock_table """ - Y_cable_task.task_worker(stopping_event, sfp_error_event, y_cable_presence) + Y_cable_task.task_worker(stopping_event, sfp_error_event) assert swsscommon.Select.select.call_count == 1 diff --git a/sonic-ycabled/ycable/ycable.py b/sonic-ycabled/ycable/ycable.py index 0b6ad0406..38b959e89 100644 --- a/sonic-ycabled/ycable/ycable.py +++ b/sonic-ycabled/ycable/ycable.py @@ -104,7 +104,7 @@ def detect_port_in_error_status(logical_port_name, status_tbl): else: return False -def handle_state_update_task(op, port, fvp_dict, y_cable_presence, port_tbl, port_tbl_keys, loopback_tbl, loopback_keys, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, y_cable_tbl, static_tbl, mux_tbl, grpc_client, fwd_state_response_tbl, state_db, stopping_event): +def handle_state_update_task(op, port, fvp_dict, port_tbl, port_tbl_keys, loopback_tbl, loopback_keys, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, y_cable_tbl, static_tbl, mux_tbl, grpc_client, fwd_state_response_tbl, state_db, stopping_event): port_dict = {} if op == swsscommon.SET_COMMAND: @@ -113,7 +113,7 @@ def handle_state_update_task(op, port, fvp_dict, y_cable_presence, port_tbl, por port_dict[port] = SFP_STATUS_REMOVED y_cable_helper.change_ports_status_for_y_cable_change_event( - port_dict, y_cable_presence, port_tbl, port_tbl_keys, loopback_tbl, loopback_keys, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, y_cable_tbl, static_tbl, mux_tbl, grpc_client, fwd_state_response_tbl, state_db, stopping_event) + port_dict, port_tbl, port_tbl_keys, loopback_tbl, loopback_keys, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, y_cable_tbl, static_tbl, mux_tbl, grpc_client, fwd_state_response_tbl, state_db, stopping_event) # # Helper classes =============================================================== @@ -125,16 +125,15 @@ def handle_state_update_task(op, port, fvp_dict, y_cable_presence, port_tbl, por class YcableInfoUpdateTask(threading.Thread): - def __init__(self, y_cable_presence): + def __init__(self): threading.Thread.__init__(self) self.exc = None self.task_stopping_event = threading.Event() - self.y_cable_presence = y_cable_presence self.table_helper = y_cable_table_helper.YcableInfoUpdateTableHelper() self.name = "YcableInfoUpdateTask" - def task_worker(self, y_cable_presence): + def task_worker(self): helper_logger.log_info("Start Ycable monitoring loop") # Connect to STATE_DB and create transceiver ycable config table @@ -149,8 +148,7 @@ def task_worker(self, y_cable_presence): logger.log_warning("Got invalid asic index for {}, ignored".format(logical_port_name)) continue - if y_cable_presence[0] is True: - y_cable_helper.check_identifier_presence_and_update_mux_info_entry(self.table_helper.get_state_db(), self.table_helper.get_mux_tbl(), asic_index, logical_port_name, self.table_helper.get_y_cable_tbl(), self.table_helper.get_port_tbl()) + y_cable_helper.check_identifier_presence_and_update_mux_info_entry(self.table_helper.get_state_db(), self.table_helper.get_mux_tbl(), asic_index, logical_port_name, self.table_helper.get_y_cable_tbl(), self.table_helper.get_port_tbl()) helper_logger.log_info("Stop DOM monitoring loop") @@ -159,7 +157,7 @@ def run(self): return try: - self.task_worker(self.y_cable_presence) + self.task_worker() except Exception as e: helper_logger.log_error("Exception occured at child thread YcableInfoUpdateTask due to {} {}".format(repr(e), traceback.format_exc())) @@ -177,18 +175,17 @@ def join(self): class YcableStateUpdateTask(threading.Thread): - def __init__(self, sfp_error_event, y_cable_presence): + def __init__(self, sfp_error_event): threading.Thread.__init__(self) self.exc = None self.task_stopping_event = threading.Event() self.sfp_insert_events = {} self.sfp_error_event = sfp_error_event - self.y_cable_presence = y_cable_presence self.table_helper = y_cable_table_helper.YcableStateUpdateTableHelper() self.name = "YcableStateUpdateTask" - def task_worker(self, stopping_event, sfp_error_event, y_cable_presence): + def task_worker(self, stopping_event, sfp_error_event): helper_logger.log_info("Start Ycable monitoring loop") # Connect to STATE_DB and listen to ycable transceiver status update tables @@ -235,14 +232,14 @@ def task_worker(self, stopping_event, sfp_error_event, y_cable_presence): continue # Check if all tables are created in table_helper - handle_state_update_task(op, port, fvp_dict, y_cable_presence, self.table_helper.get_port_tbl(), self.table_helper.port_table_keys, self.table_helper.get_loopback_tbl(), self.table_helper.loopback_keys, self.table_helper.get_hw_mux_cable_tbl(), self.table_helper.get_hw_mux_cable_tbl_peer(), self.table_helper.get_y_cable_tbl(), self.table_helper.get_static_tbl(), self.table_helper.get_mux_tbl(), self.table_helper.get_grpc_config_tbl(), self.table_helper.get_fwd_state_response_tbl(), self.table_helper.state_db, stopping_event) + handle_state_update_task(op, port, fvp_dict, self.table_helper.get_port_tbl(), self.table_helper.port_table_keys, self.table_helper.get_loopback_tbl(), self.table_helper.loopback_keys, self.table_helper.get_hw_mux_cable_tbl(), self.table_helper.get_hw_mux_cable_tbl_peer(), self.table_helper.get_y_cable_tbl(), self.table_helper.get_static_tbl(), self.table_helper.get_mux_tbl(), self.table_helper.get_grpc_config_tbl(), self.table_helper.get_fwd_state_response_tbl(), self.table_helper.state_db, stopping_event) def run(self): if self.task_stopping_event.is_set(): return try: - self.task_worker(self.task_stopping_event, self.sfp_error_event, self.y_cable_presence) + self.task_worker(self.task_stopping_event, self.sfp_error_event) except Exception as e: helper_logger.log_error("Exception occured at child thread YcableStateUpdateTask due to {} {}".format(repr(e), traceback.format_exc())) self.exc = e @@ -266,7 +263,6 @@ def __init__(self, log_identifier): self.num_asics = multi_asic.get_num_asics() self.stop_event = threading.Event() self.sfp_error_event = threading.Event() - self.y_cable_presence = [False] self.table_helper = y_cable_table_helper.DaemonYcableTableHelper() self.threads = [] self.name = "DaemonYcable" @@ -367,7 +363,7 @@ def init(self): # Init port y_cable status table y_cable_helper.init_ports_status_for_y_cable( - platform_sfputil, platform_chassis, self.y_cable_presence, self.table_helper.get_state_db(), self.table_helper.get_port_tbl(), self.table_helper.get_y_cable_tbl(), self.table_helper.get_static_tbl(), self.table_helper.get_mux_tbl(), self.table_helper.port_table_keys, self.table_helper.loopback_keys , self.table_helper.get_hw_mux_cable_tbl(), self.table_helper.get_hw_mux_cable_tbl_peer(), self.table_helper.get_grpc_config_tbl(), self.table_helper.get_fwd_state_response_tbl(), self.stop_event, is_vs) + platform_sfputil, platform_chassis, self.table_helper.get_state_db(), self.table_helper.get_port_tbl(), self.table_helper.get_y_cable_tbl(), self.table_helper.get_static_tbl(), self.table_helper.get_mux_tbl(), self.table_helper.port_table_keys, self.table_helper.loopback_keys , self.table_helper.get_hw_mux_cable_tbl(), self.table_helper.get_hw_mux_cable_tbl_peer(), self.table_helper.get_grpc_config_tbl(), self.table_helper.get_fwd_state_response_tbl(), self.stop_event, is_vs) # Deinitialize daemon def deinit(self): @@ -382,8 +378,7 @@ def deinit(self): logger.log_warning("Got invalid asic index for {}, ignored".format(logical_port_name)) continue - if self.y_cable_presence[0] is True: - y_cable_helper.delete_ports_status_for_y_cable(self.table_helper.get_y_cable_tbl(), self.table_helper.get_static_tbl(), self.table_helper.get_mux_tbl(), self.table_helper.get_port_tbl(), self.table_helper.get_grpc_config_tbl()) + y_cable_helper.delete_ports_status_for_y_cable(self.table_helper.get_y_cable_tbl(), self.table_helper.get_static_tbl(), self.table_helper.get_mux_tbl(), self.table_helper.get_port_tbl(), self.table_helper.get_grpc_config_tbl()) global_values = globals() val = global_values.get('platform_chassis') @@ -399,30 +394,29 @@ def run(self): self.init() # Start the ycable task update thread - ycable_info_update = YcableInfoUpdateTask(self.y_cable_presence) + ycable_info_update = YcableInfoUpdateTask() ycable_info_update.start() self.threads.append(ycable_info_update) # Start the sfp state info update process - ycable_state_update = YcableStateUpdateTask(self.sfp_error_event, self.y_cable_presence) + ycable_state_update = YcableStateUpdateTask(self.sfp_error_event) ycable_state_update.start() self.threads.append(ycable_state_update) # Start the Y-cable state info update process if Y cable presence established y_cable_state_worker_update = None - if self.y_cable_presence[0] is True: - y_cable_state_worker_update = y_cable_helper.YCableTableUpdateTask() - y_cable_state_worker_update.start() - self.threads.append(y_cable_state_worker_update) - y_cable_cli_worker_update = y_cable_helper.YCableCliUpdateTask() - y_cable_cli_worker_update.start() - self.threads.append(y_cable_cli_worker_update) - # enable async client only if there are active-active cables - active_active_cable_presence = check_presence_for_active_active_cable_type(self.table_helper.get_port_tbl()) - if active_active_cable_presence is True: - y_cable_async_noti_worker = y_cable_helper.YCableAsyncNotificationTask() - y_cable_async_noti_worker.start() - self.threads.append(y_cable_async_noti_worker) + y_cable_state_worker_update = y_cable_helper.YCableTableUpdateTask() + y_cable_state_worker_update.start() + self.threads.append(y_cable_state_worker_update) + y_cable_cli_worker_update = y_cable_helper.YCableCliUpdateTask() + y_cable_cli_worker_update.start() + self.threads.append(y_cable_cli_worker_update) + # enable async client only if there are active-active cables + active_active_cable_presence = check_presence_for_active_active_cable_type(self.table_helper.get_port_tbl()) + if active_active_cable_presence is True: + y_cable_async_noti_worker = y_cable_helper.YCableAsyncNotificationTask() + y_cable_async_noti_worker.start() + self.threads.append(y_cable_async_noti_worker) # Start main loop self.log_info("Start daemon main loop") @@ -451,11 +445,10 @@ def run(self): ycable_state_update.join() # Stop the Y-cable state info update process - if self.y_cable_presence[0] is True: - if y_cable_state_worker_update.is_alive(): - y_cable_state_worker_update.join() - if y_cable_cli_worker_update.is_alive(): - y_cable_cli_worker_update.join() + if y_cable_state_worker_update.is_alive(): + y_cable_state_worker_update.join() + if y_cable_cli_worker_update.is_alive(): + y_cable_cli_worker_update.join() # Start daemon deinitialization sequence diff --git a/sonic-ycabled/ycable/ycable_utilities/y_cable_helper.py b/sonic-ycabled/ycable/ycable_utilities/y_cable_helper.py index 3fd1c6786..6a8b8d9a1 100644 --- a/sonic-ycabled/ycable/ycable_utilities/y_cable_helper.py +++ b/sonic-ycabled/ycable/ycable_utilities/y_cable_helper.py @@ -641,7 +641,7 @@ def process_loopback_interface_and_get_read_side(loopback_keys): return -1 -def check_identifier_presence_and_setup_channel(logical_port_name, port_tbl, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, asic_index, read_side, mux_tbl, y_cable_presence, grpc_client, fwd_state_response_tbl): +def check_identifier_presence_and_setup_channel(logical_port_name, port_tbl, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, asic_index, read_side, mux_tbl, grpc_client, fwd_state_response_tbl): global grpc_port_stubs global grpc_port_channels @@ -665,7 +665,6 @@ def check_identifier_presence_and_setup_channel(logical_port_name, port_tbl, hw_ if val in CONFIG_MUX_STATES and cable_type == "active-active": # import the module and load the port instance - y_cable_presence[:] = [True] physical_port_list = logical_port_name_to_physical_port_list( logical_port_name) @@ -753,7 +752,7 @@ def setup_grpc_channels(stop_event, loopback_keys, hw_mux_cable_tbl, hw_mux_cabl if logical_port_name in port_table_keys[asic_index]: check_identifier_presence_and_setup_channel( - logical_port_name, port_tbl, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, asic_index, read_side, mux_tbl, y_cable_presence, grpc_client, fwd_state_response_tbl) + logical_port_name, port_tbl, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, asic_index, read_side, mux_tbl, grpc_client, fwd_state_response_tbl) else: # This port does not exist in Port table of config but is present inside # logical_ports after loading the port_mappings from port_config_file @@ -1154,7 +1153,7 @@ def create_tables_and_insert_mux_unknown_entries(state_db, y_cable_tbl, static_t post_port_mux_static_info_to_db( logical_port_name, static_tbl[asic_index], y_cable_tbl) -def check_identifier_presence_and_update_mux_table_entry(state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence): +def check_identifier_presence_and_update_mux_table_entry(state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name): global y_cable_port_instances global y_cable_port_locks @@ -1253,7 +1252,7 @@ def check_identifier_presence_and_update_mux_table_entry(state_db, port_tbl, y_c mux_asic_table = mux_tbl.get(asic_index, None) static_mux_asic_table = static_tbl.get( asic_index, None) - if y_cable_presence[0] is True and y_cable_asic_table is not None and mux_asic_table is not None and static_mux_asic_table is not None: + if y_cable_asic_table is not None and mux_asic_table is not None and static_mux_asic_table is not None: # fill in the newly found entry read_y_cable_and_update_statedb_port_tbl( logical_port_name, y_cable_tbl[asic_index]) @@ -1262,7 +1261,6 @@ def check_identifier_presence_and_update_mux_table_entry(state_db, port_tbl, y_c else: # first create the state db y cable table and then fill in the entry - y_cable_presence[:] = [True] # fill the newly found entry read_y_cable_and_update_statedb_port_tbl( logical_port_name, y_cable_tbl[asic_index]) @@ -1294,11 +1292,8 @@ def check_identifier_presence_and_update_mux_table_entry(state_db, port_tbl, y_c "Could not retreive state value inside mux_info_dict for {}, inside MUX_CABLE table".format(logical_port_name)) -def check_identifier_presence_and_delete_mux_table_entry(state_db, port_tbl, asic_index, logical_port_name, y_cable_presence, delete_change_event, y_cable_tbl, static_tbl, mux_tbl): +def check_identifier_presence_and_delete_mux_table_entry(state_db, port_tbl, asic_index, logical_port_name, delete_change_event, y_cable_tbl, static_tbl, mux_tbl): - # if there is No Y cable do not do anything here - if y_cable_presence[0] is False: - return (status, fvs) = port_tbl[asic_index].get(logical_port_name) if status is False: @@ -1310,37 +1305,36 @@ def check_identifier_presence_and_delete_mux_table_entry(state_db, port_tbl, asi # Convert list of tuples to a dictionary mux_table_dict = dict(fvs) if "state" in mux_table_dict: - if y_cable_presence[0] is True: - # delete this entry in the y cable table found and update the delete event - #We dont delete the values here, rather just update the values in state DB - (status, fvs) = y_cable_tbl[asic_index].get(logical_port_name) - if status is False: - helper_logger.log_debug("Could not retreive fieldvalue pairs for {}, inside state_db table {} while deleting mux entry".format( - logical_port_name, y_cable_tbl[asic_index].getTableName())) - mux_port_dict = dict(fvs) - read_side = mux_port_dict.get("read_side", None) - active_side = -1 - update_table_mux_status_for_statedb_port_tbl( - y_cable_tbl[asic_index], "unknown", read_side, active_side, logical_port_name) - #delete_port_from_y_cable_table(logical_port_name, static_tbl[asic_index]) - #delete_port_from_y_cable_table(logical_port_name, mux_tbl[asic_index]) - delete_change_event[:] = [True] - # delete the y_cable instance - physical_port_list = logical_port_name_to_physical_port_list(logical_port_name) + # delete this entry in the y cable table found and update the delete event + #We dont delete the values here, rather just update the values in state DB + (status, fvs) = y_cable_tbl[asic_index].get(logical_port_name) + if status is False: + helper_logger.log_debug("Could not retreive fieldvalue pairs for {}, inside state_db table {} while deleting mux entry".format( + logical_port_name, y_cable_tbl[asic_index].getTableName())) + mux_port_dict = dict(fvs) + read_side = mux_port_dict.get("read_side", None) + active_side = -1 + update_table_mux_status_for_statedb_port_tbl( + y_cable_tbl[asic_index], "unknown", read_side, active_side, logical_port_name) + #delete_port_from_y_cable_table(logical_port_name, static_tbl[asic_index]) + #delete_port_from_y_cable_table(logical_port_name, mux_tbl[asic_index]) + delete_change_event[:] = [True] + # delete the y_cable instance + physical_port_list = logical_port_name_to_physical_port_list(logical_port_name) - if len(physical_port_list) == 1: + if len(physical_port_list) == 1: - physical_port = physical_port_list[0] - if y_cable_port_instances.get(physical_port) is not None: - y_cable_port_instances.pop(physical_port) - if y_cable_port_instances.get(physical_port) is not None: - y_cable_port_locks.pop(physical_port) - else: - helper_logger.log_warning( - "Error: Retreived multiple ports for a Y cable port {} while delete entries".format(logical_port_name)) + physical_port = physical_port_list[0] + if y_cable_port_instances.get(physical_port) is not None: + y_cable_port_instances.pop(physical_port) + if y_cable_port_instances.get(physical_port) is not None: + y_cable_port_locks.pop(physical_port) + else: + helper_logger.log_warning( + "Error: Retreived multiple ports for a Y cable port {} while delete entries".format(logical_port_name)) -def init_ports_status_for_y_cable(platform_sfp, platform_chassis, y_cable_presence, state_db ,port_tbl, y_cable_tbl, static_tbl, mux_tbl, port_table_keys, loopback_keys , hw_mux_cable_tbl, hw_mux_cable_tbl_peer, grpc_client, fwd_state_response_tbl, stop_event=threading.Event(), is_vs=False): +def init_ports_status_for_y_cable(platform_sfp, platform_chassis, state_db ,port_tbl, y_cable_tbl, static_tbl, mux_tbl, port_table_keys, loopback_keys , hw_mux_cable_tbl, hw_mux_cable_tbl_peer, grpc_client, fwd_state_response_tbl, stop_event=threading.Event(), is_vs=False): global y_cable_platform_sfputil global y_cable_platform_chassis global y_cable_port_instances @@ -1376,11 +1370,11 @@ def init_ports_status_for_y_cable(platform_sfp, platform_chassis, y_cable_presen (status, cable_type) = check_mux_cable_port_type(logical_port_name, port_tbl, asic_index) if status and cable_type == "active-standby": check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, hw_mux_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + state_db, port_tbl, hw_mux_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name) if status and cable_type == "active-active": grpc_port_stats[logical_port_name] = {} check_identifier_presence_and_setup_channel( - logical_port_name, port_tbl, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, asic_index, read_side, mux_tbl, y_cable_presence, grpc_client, fwd_state_response_tbl) + logical_port_name, port_tbl, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, asic_index, read_side, mux_tbl, grpc_client, fwd_state_response_tbl) else: # This port does not exist in Port table of config but is present inside # logical_ports after loading the port_mappings from port_config_file @@ -1389,7 +1383,7 @@ def init_ports_status_for_y_cable(platform_sfp, platform_chassis, y_cable_presen "Could not retreive port inside config_db PORT table {} for Y-Cable initiation".format(logical_port_name)) -def change_ports_status_for_y_cable_change_event(port_dict, y_cable_presence, port_tbl, port_table_keys, loopback_tbl, loopback_keys, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, y_cable_tbl, static_tbl, mux_tbl, grpc_client, fwd_state_response_tbl, state_db, stop_event=threading.Event()): +def change_ports_status_for_y_cable_change_event(port_dict, port_tbl, port_table_keys, loopback_tbl, loopback_keys, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, y_cable_tbl, static_tbl, mux_tbl, grpc_client, fwd_state_response_tbl, state_db, stop_event=threading.Event()): global read_side delete_change_event = [False] @@ -1418,21 +1412,21 @@ def change_ports_status_for_y_cable_change_event(port_dict, y_cable_presence, po (status, cable_type) = check_mux_cable_port_type(logical_port_name, port_tbl, asic_index) if status and cable_type == "active-standby": check_identifier_presence_and_update_mux_table_entry( - state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name, y_cable_presence) + state_db, port_tbl, y_cable_tbl, static_tbl, mux_tbl, asic_index, logical_port_name) if status and cable_type == "active-active": check_identifier_presence_and_setup_channel( - logical_port_name, port_tbl, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, asic_index, read_side, mux_tbl, y_cable_presence, grpc_client, fwd_state_response_tbl) + logical_port_name, port_tbl, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, asic_index, read_side, mux_tbl, grpc_client, fwd_state_response_tbl) elif value == SFP_STATUS_REMOVED: helper_logger.log_info("Got SFP deleted ycable event") check_identifier_presence_and_delete_mux_table_entry( - state_db, port_tbl, asic_index, logical_port_name, y_cable_presence, delete_change_event, y_cable_tbl, static_tbl, mux_tbl) + state_db, port_tbl, asic_index, logical_port_name, delete_change_event, y_cable_tbl, static_tbl, mux_tbl) else: try: # Now that the value is in bitmap format, let's convert it to number event_bits = int(value) if event_bits in errors_block_eeprom_reading: check_identifier_presence_and_delete_mux_table_entry( - state_db, port_tbl, asic_index, logical_port_name, y_cable_presence, delete_change_event, y_cable_tbl, static_tbl, mux_tbl) + state_db, port_tbl, asic_index, logical_port_name, delete_change_event, y_cable_tbl, static_tbl, mux_tbl) except (TypeError, ValueError) as e: helper_logger.log_error("Got unrecognized event {}, ignored".format(value)) @@ -1441,9 +1435,8 @@ def change_ports_status_for_y_cable_change_event(port_dict, y_cable_presence, po continue # If there was a delete event and y_cable_presence was true, reaccess the y_cable presence - if y_cable_presence[0] is True and delete_change_event[0] is True: + if delete_change_event[0] is True: - y_cable_presence[:] = [False] state_db = {} yc_hw_mux_cable_table = {} namespaces = multi_asic.get_front_end_namespaces() @@ -1454,9 +1447,6 @@ def change_ports_status_for_y_cable_change_event(port_dict, y_cable_presence, po yc_hw_mux_cable_table[asic_id] = swsscommon.Table( state_db[asic_id], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME) y_cable_table_size = len(yc_hw_mux_cable_table[asic_id].getKeys()) - if y_cable_table_size > 0: - y_cable_presence[:] = [True] - break def delete_ports_status_for_y_cable(y_cable_tbl, static_tbl, mux_tbl, port_tbl, grpc_config):