diff --git a/sonic-xcvrd/tests/test_xcvrd.py b/sonic-xcvrd/tests/test_xcvrd.py index bd7eda753..40e2e5efa 100644 --- a/sonic-xcvrd/tests/test_xcvrd.py +++ b/sonic-xcvrd/tests/test_xcvrd.py @@ -261,6 +261,9 @@ def test_CmisManagerTask_get_xcvr_api_exception(self, mock_platform_chassis, moc port_change_event = PortChangeEvent('Ethernet0', 1, 0, PortChangeEvent.PORT_SET, {'speed':'400000', 'lanes':'1,2,3,4,5,6,7,8'}) + task.port_mapping.logical_to_physical['Ethernet0'] = 1 + task.port_mapping.logical_to_asic['Ethernet0'] = 0 + # Case 1: get_xcvr_api() raises an exception task.on_port_update_event(port_change_event) mock_sfp.get_xcvr_api = MagicMock(side_effect=NotImplementedError) @@ -1693,6 +1696,8 @@ def test_CmisManagerTask_update_port_transceiver_status_table_sw_cmis_state(self @patch('xcvrd.xcvrd._wrapper_get_sfp_type', MagicMock(return_value='QSFP_DD')) def test_CmisManagerTask_handle_port_change_event(self): port_mapping = PortMapping() + port_mapping.logical_port_list = ['Ethernet0'] + port_mapping.logical_to_physical['Ethernet0'] = 1 stop_event = threading.Event() task = CmisManagerTask(DEFAULT_NAMESPACE, port_mapping, stop_event) @@ -2199,6 +2204,7 @@ def test_CmisManagerTask_task_worker(self, mock_chassis, mock_get_status_tbl): port_change_event = PortChangeEvent('Ethernet0', 1, 0, PortChangeEvent.PORT_SET, {'speed':'400000', 'lanes':'1,2,3,4,5,6,7,8'}) + task.port_mapping.logical_to_physical['Ethernet0'] = 1 task.on_port_update_event(port_change_event) assert len(task.port_dict) == 1 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_INSERTED @@ -2260,6 +2266,7 @@ def test_CmisManagerTask_task_worker(self, mock_chassis, mock_get_status_tbl): assert get_cmis_state_from_state_db('Ethernet1', task.xcvr_table_helper.get_status_tbl(task.port_mapping.get_asic_id_for_logical_port('Ethernet1'))) == CMIS_STATE_UNKNOWN task.port_mapping.logical_port_list = MagicMock() + task.port_mapping.logical_to_physical['Ethernet1'] = 2 port_change_event = PortChangeEvent('PortConfigDone', -1, 0, PortChangeEvent.PORT_SET) task.on_port_update_event(port_change_event) assert task.isPortConfigDone @@ -2403,6 +2410,7 @@ def test_CmisManagerTask_task_worker_fastboot(self, mock_chassis, mock_get_statu port_change_event = PortChangeEvent('Ethernet0', 1, 0, PortChangeEvent.PORT_SET, {'speed':'400000', 'lanes':'1,2,3,4,5,6,7,8'}) + task.port_mapping.logical_to_physical['Ethernet0'] = 1 task.on_port_update_event(port_change_event) assert len(task.port_dict) == 1 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_INSERTED @@ -2532,6 +2540,7 @@ def test_CmisManagerTask_task_worker_host_tx_ready_false(self, mock_chassis, moc 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() + task.port_mapping.logical_to_physical['Ethernet0'] = 1 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 89789899f..3fb5293e1 100644 --- a/sonic-xcvrd/xcvrd/xcvrd.py +++ b/sonic-xcvrd/xcvrd/xcvrd.py @@ -712,6 +712,10 @@ def on_port_update_event(self, port_change_event): if pport is None: return + if not self.port_mapping.is_logical_port(lport): + helper_logger.log_info("lport {} does not exist in CONFIG DB. Ignoring port update event".format(lport)) + return + # Skip if the port/cage type is not a CMIS # 'index' can be -1 if STATE_DB|PORT_TABLE if lport not in self.port_dict: