From 8f8326d64fb1e4719a325ec5a63169ccac4e207d Mon Sep 17 00:00:00 2001 From: Mihir Patel Date: Tue, 19 Mar 2024 21:51:25 +0000 Subject: [PATCH] Initializing cmis_state to CMIS_STATE_UNKNOWN while spawning CmisManagerTask --- sonic-xcvrd/tests/test_xcvrd.py | 7 ++++++- sonic-xcvrd/xcvrd/xcvrd.py | 10 ++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/sonic-xcvrd/tests/test_xcvrd.py b/sonic-xcvrd/tests/test_xcvrd.py index 96cd8f7a0..568b19dd2 100644 --- a/sonic-xcvrd/tests/test_xcvrd.py +++ b/sonic-xcvrd/tests/test_xcvrd.py @@ -1319,7 +1319,7 @@ def test_SffManagerTask_task_worker(self, mock_chassis): assert mock_xcvr_api.tx_disable_channel.call_count == 2 mock_sfp.get_presence = MagicMock(return_value=True) - def test_update_port_transceiver_status_table_sw_cmis_state(self): + def test_CmisManagerTask_update_port_transceiver_status_table_sw_cmis_state(self): port_mapping = PortMapping() stop_event = threading.Event() task = CmisManagerTask(DEFAULT_NAMESPACE, port_mapping, stop_event) @@ -1716,8 +1716,13 @@ def test_CmisManagerTask_task_worker(self, mock_chassis, mock_get_status_tbl): port_mapping = PortMapping() stop_event = threading.Event() task = CmisManagerTask(DEFAULT_NAMESPACE, port_mapping, stop_event) + task.port_mapping.logical_port_list = ['Ethernet0'] task.xcvr_table_helper.get_status_tbl.return_value = mock_get_status_tbl + task.task_stopping_event.is_set = MagicMock(side_effect=[False, False, True]) + task.task_worker() + assert get_cmis_state_from_state_db('Ethernet0', task.xcvr_table_helper.get_status_tbl(task.port_mapping.get_asic_id_for_logical_port('Ethernet0'))) == CMIS_STATE_UNKNOWN + task.port_mapping.logical_port_list = MagicMock() port_change_event = PortChangeEvent('PortConfigDone', -1, 0, PortChangeEvent.PORT_SET) task.on_port_update_event(port_change_event) assert task.isPortConfigDone diff --git a/sonic-xcvrd/xcvrd/xcvrd.py b/sonic-xcvrd/xcvrd/xcvrd.py index 63cf06d19..aaecb27ed 100644 --- a/sonic-xcvrd/xcvrd/xcvrd.py +++ b/sonic-xcvrd/xcvrd/xcvrd.py @@ -1252,6 +1252,10 @@ def task_worker(self): for namespace in self.namespaces: self.wait_for_port_config_done(namespace) + logical_port_list = self.port_mapping.logical_port_list + for lport in logical_port_list: + self.update_port_transceiver_status_table_sw_cmis_state(lport, CMIS_STATE_UNKNOWN) + # APPL_DB for CONFIG updates, and STATE_DB for insertion/removal port_change_observer = PortChangeObserver(self.namespaces, helper_logger, self.task_stopping_event, @@ -1643,8 +1647,10 @@ def get_dom_polling_from_config_db(self, lport): """ Checks if the port is going through CMIS initialization process - This API assumes CMIS_STATE_UNKNOWN as a transitional state since any CMIS supported platform will - eventually reach to a state in CMIS_TERMINAL_STATES irrespective of the transciver type + This API assumes CMIS_STATE_UNKNOWN as a transitional state since it is the + first state after starting CMIS state machine. + This assumption allows the DomInfoUpdateTask thread to skip polling on the port + to allow CMIS initialization to complete if needed. Returns: True if the port is in CMIS initialization process, otherwise False