Skip to content

Commit

Permalink
Add UT coverage and rename sff_mgr enable flag to enable_sff_mgr_cont…
Browse files Browse the repository at this point in the history
…rolled_tx
  • Loading branch information
longhuan-cisco committed Dec 12, 2024
1 parent 20cba36 commit c01b549
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
38 changes: 38 additions & 0 deletions sonic-xcvrd/tests/test_xcvrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1673,6 +1673,44 @@ 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)

# high power enabling failure case and enable_sff_mgr_controlled_tx is False
mock_xcvr_api.tx_disable_channel.call_count = 0
mock_xcvr_api.set_high_power_class.call_count = 0
task.enable_sff_mgr_controlled_tx = False
task.get_host_tx_status = MagicMock(return_value='true')
task.get_admin_status = MagicMock(return_value='up')
mock_xcvr_api.set_high_power_class = MagicMock(return_value=False)
port_change_event = PortChangeEvent('Ethernet4', 2, 0, PortChangeEvent.PORT_SET, {
'type': 'QSFP28',
'subport': '0',
'lanes': '1,2,3,4',
})
task.on_port_update_event(port_change_event)
assert len(task.port_dict) == 2
task.task_stopping_event.is_set = MagicMock(side_effect=[False] + [False] * len(task.port_dict) + [True])
task.task_worker()
assert mock_xcvr_api.tx_disable_channel.call_count == 0
assert mock_xcvr_api.set_high_power_class.call_count == 1

# high power enabling exception case
mock_xcvr_api.tx_disable_channel.call_count = 0
mock_xcvr_api.set_high_power_class.call_count = 0
task.enable_sff_mgr_controlled_tx = False
task.get_host_tx_status = MagicMock(return_value='true')
task.get_admin_status = MagicMock(return_value='up')
mock_xcvr_api.set_high_power_class = MagicMock(side_effect=AttributeError("Attribute not found"))
port_change_event = PortChangeEvent('Ethernet8', 3, 0, PortChangeEvent.PORT_SET, {
'type': 'QSFP28',
'subport': '0',
'lanes': '1,2,3,4',
})
task.on_port_update_event(port_change_event)
assert len(task.port_dict) == 3
task.task_stopping_event.is_set = MagicMock(side_effect=[False] + [False] * len(task.port_dict) + [True])
task.task_worker()
assert mock_xcvr_api.tx_disable_channel.call_count == 0
assert mock_xcvr_api.set_high_power_class.call_count == 1

def test_CmisManagerTask_update_port_transceiver_status_table_sw_cmis_state(self):
port_mapping = PortMapping()
stop_event = threading.Event()
Expand Down
4 changes: 2 additions & 2 deletions sonic-xcvrd/xcvrd/sff_mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,8 @@ def task_worker(self):

if xcvr_inserted:
try:
if api.handle_high_power_class():
self.log_notice("{}: done handling high power class".format(lport))
if api.set_high_power_class(True):
self.log_notice("{}: done enabling high power class".format(lport))
else:
self.log_error("{}: failed to enable high power class".format(lport))
except (AttributeError, NotImplementedError):
Expand Down
10 changes: 5 additions & 5 deletions sonic-xcvrd/xcvrd/xcvrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2052,12 +2052,12 @@ def retry_eeprom_reading(self):


class DaemonXcvrd(daemon_base.DaemonBase):
def __init__(self, log_identifier, skip_cmis_mgr=False, enable_sff_mgr=False):
def __init__(self, log_identifier, skip_cmis_mgr=False, enable_sff_mgr_controlled_tx=False):
super(DaemonXcvrd, self).__init__(log_identifier, enable_runtime_log_config=True)
self.stop_event = threading.Event()
self.sfp_error_event = threading.Event()
self.skip_cmis_mgr = skip_cmis_mgr
self.enable_sff_mgr = enable_sff_mgr
self.enable_sff_mgr_controlled_tx = enable_sff_mgr_controlled_tx
self.namespaces = ['']
self.threads = []

Expand Down Expand Up @@ -2222,7 +2222,7 @@ def run(self):
port_mapping_data = self.init()

# Start the SFF manager
sff_manager = SffManagerTask(self.enable_sff_mgr, self.namespaces, self.stop_event, platform_chassis, helper_logger)
sff_manager = SffManagerTask(self.enable_sff_mgr_controlled_tx, self.namespaces, self.stop_event, platform_chassis, helper_logger)
sff_manager.start()
self.threads.append(sff_manager)

Expand Down Expand Up @@ -2304,10 +2304,10 @@ def run(self):
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--skip_cmis_mgr', action='store_true')
parser.add_argument('--enable_sff_mgr', action='store_true')
parser.add_argument('--enable_sff_mgr_controlled_tx', action='store_true')

args = parser.parse_args()
xcvrd = DaemonXcvrd(SYSLOG_IDENTIFIER, args.skip_cmis_mgr, args.enable_sff_mgr)
xcvrd = DaemonXcvrd(SYSLOG_IDENTIFIER, args.skip_cmis_mgr, args.enable_sff_mgr_controlled_tx)
xcvrd.run()


Expand Down

0 comments on commit c01b549

Please sign in to comment.