Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reset active application code as 'N/A' when port shutdown #550

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions sonic-xcvrd/tests/test_xcvrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1870,6 +1870,27 @@ def get_host_lane_assignment_option_side_effect(app):
appl = get_cmis_application_desired(mock_xcvr_api, host_lane_count, speed)
assert task.get_cmis_host_lanes_mask(mock_xcvr_api, appl, host_lane_count, subport) == expected

@patch('swsscommon.swsscommon.FieldValuePairs')
def test_CmisManagerTask_reset_port_active_apsel_to_db_error_cases(self, mock_field_value_pairs):
port_mapping = PortMapping()
stop_event = threading.Event()
task = CmisManagerTask(DEFAULT_NAMESPACE, port_mapping, stop_event)
lport = "Ethernet0"
host_lanes_mask = 0xff

# Case: table does not exist
task.xcvr_table_helper = XcvrTableHelper(DEFAULT_NAMESPACE)
task.xcvr_table_helper.get_intf_tbl = MagicMock(return_value=None)
task.reset_port_active_apsel_to_db(lport, host_lanes_mask)
assert mock_field_value_pairs.call_count == 0

# Case: lport is not in the table
int_tbl = MagicMock()
int_tbl.get = MagicMock(return_value=(False, dict))
task.xcvr_table_helper.get_intf_tbl = MagicMock(return_value=int_tbl)
task.reset_port_active_apsel_to_db(lport, host_lanes_mask)
assert mock_field_value_pairs.call_count == 0

@patch('swsscommon.swsscommon.FieldValuePairs')
def test_CmisManagerTask_post_port_active_apsel_to_db_error_cases(self, mock_field_value_pairs):
mock_xcvr_api = MagicMock()
Expand Down Expand Up @@ -2384,10 +2405,13 @@ def test_CmisManagerTask_task_worker_fastboot(self, mock_chassis, mock_get_statu
task.get_configured_laser_freq_from_db = MagicMock(return_value=193100)
task.configure_tx_output_power = MagicMock(return_value=1)
task.configure_laser_frequency = MagicMock(return_value=1)
task.reset_port_active_apsel_to_db = MagicMock()

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

assert mock_xcvr_api.tx_disable_channel.call_count == 1
assert task.reset_port_active_apsel_to_db.call_count == 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_READY

@patch('xcvrd.xcvrd.XcvrTableHelper.get_status_tbl')
Expand Down Expand Up @@ -2519,10 +2543,12 @@ def test_CmisManagerTask_task_worker_host_tx_ready_false(self, mock_chassis, moc
task.get_configured_laser_freq_from_db = MagicMock(return_value=193100)
task.configure_tx_output_power = MagicMock(return_value=1)
task.configure_laser_frequency = MagicMock(return_value=1)
task.reset_port_active_apsel_to_db = MagicMock()

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

assert task.reset_port_active_apsel_to_db.call_count == 1
assert mock_xcvr_api.tx_disable_channel.call_count == 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_READY

Expand Down
22 changes: 22 additions & 0 deletions sonic-xcvrd/xcvrd/xcvrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,27 @@ def post_port_active_apsel_to_db(self, api, lport, host_lanes_mask):
intf_tbl.set(lport, fvs)
self.log_notice("{}: updated TRANSCEIVER_INFO_TABLE {}".format(lport, tuple_list))

def reset_port_active_apsel_to_db(self, lport, host_lanes_mask):
tuple_list = []
for lane in range(self.CMIS_MAX_HOST_LANES):
if ((1 << lane) & host_lanes_mask) == 0:
continue
tuple_list.append(('active_apsel_hostlane{}'.format(lane + 1), 'N/A'))
tuple_list.append(('host_lane_count', 'N/A'))
tuple_list.append(('media_lane_count', 'N/A'))
asic_index = self.port_mapping.get_asic_id_for_logical_port(lport)
intf_tbl = self.xcvr_table_helper.get_intf_tbl(asic_index)
if not intf_tbl:
helper_logger.log_warning("Active ApSel db update: TRANSCEIVER_INFO table not found for {}".format(lport))
return
found, _ = intf_tbl.get(lport)
if not found:
helper_logger.log_warning("Active ApSel db update: {} not found in INTF_TABLE".format(lport))
return
fvs = swsscommon.FieldValuePairs(tuple_list)
intf_tbl.set(lport, fvs)
self.log_notice("{}: updated TRANSCEIVER_INFO_TABLE {}".format(lport, tuple_list))

def wait_for_port_config_done(self, namespace):
# Connect to APPL_DB and subscribe to PORT table notifications
appl_db = daemon_base.db_connect("APPL_DB", namespace=namespace)
Expand Down Expand Up @@ -1468,6 +1489,7 @@ def task_worker(self):
self.log_notice("{} Forcing Tx laser OFF".format(lport))
# Force DataPath re-init
api.tx_disable_channel(media_lanes_mask, True)
self.reset_port_active_apsel_to_db(lport, host_lanes_mask)
self.update_port_transceiver_status_table_sw_cmis_state(lport, CMIS_STATE_READY)
continue
# Configure the target output power if ZR module
Expand Down
Loading