Skip to content

Commit

Permalink
Fix issue when port is not in config DB, but TRANSCIEVER_INFO table i…
Browse files Browse the repository at this point in the history
…s changed
  • Loading branch information
noaOrMlnx committed Nov 3, 2024
1 parent fc557a1 commit 8cdc32f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions sonic-xcvrd/tests/test_xcvrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions sonic-xcvrd/xcvrd/xcvrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 8cdc32f

Please sign in to comment.