Skip to content

Commit 585541f

Browse files
authored
reset active application code as 'N/A' when port shutdown (#550)
* reset active application code as 'N/A' when port shutdown Signed-off-by: chiourung_huang <[email protected]> * Fix unit test error * reuse post_port_active_apsel_to_db function to reset active application code as 'N/A' --------- Signed-off-by: chiourung_huang <[email protected]>
1 parent 8ace0f8 commit 585541f

File tree

2 files changed

+55
-15
lines changed

2 files changed

+55
-15
lines changed

sonic-xcvrd/tests/test_xcvrd.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,6 +2002,32 @@ def test_CmisManagerTask_post_port_active_apsel_to_db(self):
20022002
'host_lane_count': '2',
20032003
'media_lane_count': '1'}
20042004

2005+
# case: partial lanes update (reset to 'N/A')
2006+
lport = "Ethernet16"
2007+
host_lanes_mask = 0xc
2008+
ret = task.post_port_active_apsel_to_db(mock_xcvr_api, lport, host_lanes_mask, reset_apsel=True)
2009+
assert int_tbl.getKeys() == ["Ethernet0", "Ethernet8", "Ethernet16"]
2010+
assert dict(int_tbl.mock_dict["Ethernet16"]) == {'active_apsel_hostlane3': 'N/A',
2011+
'active_apsel_hostlane4': 'N/A',
2012+
'host_lane_count': 'N/A',
2013+
'media_lane_count': 'N/A'}
2014+
2015+
# case: full lanes update (reset to 'N/A')
2016+
lport = "Ethernet32"
2017+
host_lanes_mask = 0xff
2018+
task.post_port_active_apsel_to_db(mock_xcvr_api, lport, host_lanes_mask, reset_apsel=True)
2019+
assert int_tbl.getKeys() == ["Ethernet0", "Ethernet8", "Ethernet16", "Ethernet32"]
2020+
assert dict(int_tbl.mock_dict["Ethernet32"]) == {'active_apsel_hostlane1': 'N/A',
2021+
'active_apsel_hostlane2': 'N/A',
2022+
'active_apsel_hostlane3': 'N/A',
2023+
'active_apsel_hostlane4': 'N/A',
2024+
'active_apsel_hostlane5': 'N/A',
2025+
'active_apsel_hostlane6': 'N/A',
2026+
'active_apsel_hostlane7': 'N/A',
2027+
'active_apsel_hostlane8': 'N/A',
2028+
'host_lane_count': 'N/A',
2029+
'media_lane_count': 'N/A'}
2030+
20052031
# case: NotImplementedError
20062032
int_tbl = Table("STATE_DB", TRANSCEIVER_INFO_TABLE) # a new empty table
20072033
lport = "Ethernet0"
@@ -2413,10 +2439,13 @@ def test_CmisManagerTask_task_worker_fastboot(self, mock_chassis, mock_get_statu
24132439
task.get_configured_laser_freq_from_db = MagicMock(return_value=193100)
24142440
task.configure_tx_output_power = MagicMock(return_value=1)
24152441
task.configure_laser_frequency = MagicMock(return_value=1)
2442+
task.post_port_active_apsel_to_db = MagicMock()
24162443

24172444
task.task_stopping_event.is_set = MagicMock(side_effect=[False, False, True])
24182445
task.task_worker()
24192446

2447+
assert mock_xcvr_api.tx_disable_channel.call_count == 1
2448+
assert task.post_port_active_apsel_to_db.call_count == 1
24202449
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_READY
24212450

24222451
@patch('xcvrd.xcvrd.XcvrTableHelper.get_status_tbl')
@@ -2548,10 +2577,12 @@ def test_CmisManagerTask_task_worker_host_tx_ready_false(self, mock_chassis, moc
25482577
task.get_configured_laser_freq_from_db = MagicMock(return_value=193100)
25492578
task.configure_tx_output_power = MagicMock(return_value=1)
25502579
task.configure_laser_frequency = MagicMock(return_value=1)
2580+
task.post_port_active_apsel_to_db = MagicMock()
25512581

25522582
task.task_stopping_event.is_set = MagicMock(side_effect=[False, False, True])
25532583
task.task_worker()
25542584

2585+
assert task.post_port_active_apsel_to_db.call_count == 1
25552586
assert mock_xcvr_api.tx_disable_channel.call_count == 1
25562587
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_READY
25572588

sonic-xcvrd/xcvrd/xcvrd.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,29 +1086,37 @@ def configure_laser_frequency(self, api, lport, freq, grid=75):
10861086
self.log_error("{} Tuning in progress, subport selection may fail!".format(lport))
10871087
return api.set_laser_freq(freq, grid)
10881088

1089-
def post_port_active_apsel_to_db(self, api, lport, host_lanes_mask):
1090-
try:
1091-
act_apsel = api.get_active_apsel_hostlane()
1092-
appl_advt = api.get_application_advertisement()
1093-
except NotImplementedError:
1094-
helper_logger.log_error("Required feature is not implemented")
1095-
return
1089+
def post_port_active_apsel_to_db(self, api, lport, host_lanes_mask, reset_apsel=False):
1090+
if reset_apsel == False:
1091+
try:
1092+
act_apsel = api.get_active_apsel_hostlane()
1093+
appl_advt = api.get_application_advertisement()
1094+
except NotImplementedError:
1095+
helper_logger.log_error("Required feature is not implemented")
1096+
return
10961097

10971098
tuple_list = []
10981099
for lane in range(self.CMIS_MAX_HOST_LANES):
10991100
if ((1 << lane) & host_lanes_mask) == 0:
11001101
continue
1101-
act_apsel_lane = act_apsel.get('ActiveAppSelLane{}'.format(lane + 1), 'N/A')
1102-
tuple_list.append(('active_apsel_hostlane{}'.format(lane + 1),
1103-
str(act_apsel_lane)))
1102+
if reset_apsel == False:
1103+
act_apsel_lane = act_apsel.get('ActiveAppSelLane{}'.format(lane + 1), 'N/A')
1104+
tuple_list.append(('active_apsel_hostlane{}'.format(lane + 1),
1105+
str(act_apsel_lane)))
1106+
else:
1107+
tuple_list.append(('active_apsel_hostlane{}'.format(lane + 1), 'N/A'))
11041108

11051109
# also update host_lane_count and media_lane_count
11061110
if len(tuple_list) > 0:
1107-
appl_advt_act = appl_advt.get(act_apsel_lane)
1108-
host_lane_count = appl_advt_act.get('host_lane_count', 'N/A') if appl_advt_act else 'N/A'
1109-
tuple_list.append(('host_lane_count', str(host_lane_count)))
1110-
media_lane_count = appl_advt_act.get('media_lane_count', 'N/A') if appl_advt_act else 'N/A'
1111-
tuple_list.append(('media_lane_count', str(media_lane_count)))
1111+
if reset_apsel == False:
1112+
appl_advt_act = appl_advt.get(act_apsel_lane)
1113+
host_lane_count = appl_advt_act.get('host_lane_count', 'N/A') if appl_advt_act else 'N/A'
1114+
tuple_list.append(('host_lane_count', str(host_lane_count)))
1115+
media_lane_count = appl_advt_act.get('media_lane_count', 'N/A') if appl_advt_act else 'N/A'
1116+
tuple_list.append(('media_lane_count', str(media_lane_count)))
1117+
else:
1118+
tuple_list.append(('host_lane_count', 'N/A'))
1119+
tuple_list.append(('media_lane_count', 'N/A'))
11121120

11131121
asic_index = self.port_mapping.get_asic_id_for_logical_port(lport)
11141122
intf_tbl = self.xcvr_table_helper.get_intf_tbl(asic_index)
@@ -1310,6 +1318,7 @@ def task_worker(self):
13101318
self.log_notice("{} Forcing Tx laser OFF".format(lport))
13111319
# Force DataPath re-init
13121320
api.tx_disable_channel(media_lanes_mask, True)
1321+
self.post_port_active_apsel_to_db(lport, host_lanes_mask, reset_apsel=True)
13131322
self.update_port_transceiver_status_table_sw_cmis_state(lport, CMIS_STATE_READY)
13141323
continue
13151324
# Configure the target output power if ZR module

0 commit comments

Comments
 (0)