@@ -2511,6 +2511,145 @@ def test_CmisManagerTask_get_configured_tx_power_from_db(self, mock_table_helper
25112511 task .xcvr_table_helper .get_cfg_port_tbl = mock_table_helper .get_cfg_port_tbl
25122512 assert task .get_configured_tx_power_from_db ('Ethernet0' ) == - 10
25132513
2514+ @patch ('xcvrd.xcvrd.XcvrTableHelper.get_status_sw_tbl' )
2515+ @patch ('xcvrd.xcvrd.platform_chassis' )
2516+ @patch ('xcvrd.xcvrd_utilities.common.is_fast_reboot_enabled' , MagicMock (return_value = False ))
2517+ @patch ('xcvrd.xcvrd_utilities.common.get_cmis_application_desired' , MagicMock (return_value = 1 ))
2518+ def test_CmisManagerTask_process_single_lport_invalid_host_lanes_mask (self , mock_chassis , mock_get_status_sw_tbl ):
2519+ """Test process_single_lport when get_cmis_host_lanes_mask returns invalid value (<=0)"""
2520+ mock_get_status_sw_tbl = Table ("STATE_DB" , TRANSCEIVER_STATUS_SW_TABLE )
2521+
2522+ # Setup mock SFP and API
2523+ mock_xcvr_api = MagicMock ()
2524+ mock_xcvr_api .get_presence = MagicMock (return_value = True )
2525+ mock_xcvr_api .is_flat_memory = MagicMock (return_value = False )
2526+ mock_xcvr_api .get_module_type_abbreviation = MagicMock (return_value = 'QSFP-DD' )
2527+ mock_xcvr_api .is_coherent_module = MagicMock (return_value = False )
2528+ mock_xcvr_api .get_module_state = MagicMock (return_value = 'ModuleReady' )
2529+ mock_xcvr_api .get_datapath_state = MagicMock (return_value = {
2530+ 'DP1State' : 'DataPathDeactivated' ,
2531+ 'DP2State' : 'DataPathDeactivated' ,
2532+ 'DP3State' : 'DataPathDeactivated' ,
2533+ 'DP4State' : 'DataPathDeactivated' ,
2534+ 'DP5State' : 'DataPathDeactivated' ,
2535+ 'DP6State' : 'DataPathDeactivated' ,
2536+ 'DP7State' : 'DataPathDeactivated' ,
2537+ 'DP8State' : 'DataPathDeactivated'
2538+ })
2539+ mock_xcvr_api .get_media_lane_count = MagicMock (return_value = 8 )
2540+ mock_xcvr_api .get_media_lane_assignment_option = MagicMock (return_value = 1 )
2541+
2542+ mock_sfp = MagicMock ()
2543+ mock_sfp .get_presence = MagicMock (return_value = True )
2544+ mock_sfp .get_xcvr_api = MagicMock (return_value = mock_xcvr_api )
2545+ mock_chassis .get_sfp = MagicMock (return_value = mock_sfp )
2546+
2547+ # Setup port mapping and task
2548+ port_mapping = PortMapping ()
2549+ port_mapping .handle_port_change_event (PortChangeEvent ('Ethernet0' , 1 , 0 , PortChangeEvent .PORT_ADD ))
2550+ stop_event = threading .Event ()
2551+ task = CmisManagerTask (DEFAULT_NAMESPACE , port_mapping , stop_event , platform_chassis = mock_chassis )
2552+ task .xcvr_table_helper = XcvrTableHelper (DEFAULT_NAMESPACE )
2553+ task .xcvr_table_helper .get_status_sw_tbl .return_value = mock_get_status_sw_tbl
2554+
2555+ # Properly set up the port via port change event
2556+ port_change_event = PortChangeEvent ('Ethernet0' , 1 , 0 , PortChangeEvent .PORT_SET ,
2557+ {'speed' :'400000' , 'lanes' :'1,2,3,4,5,6,7,8' })
2558+ task .on_port_update_event (port_change_event )
2559+
2560+ # Set port to INSERTED state
2561+ task .update_port_transceiver_status_table_sw_cmis_state ('Ethernet0' , CMIS_STATE_INSERTED )
2562+ task .port_dict ['Ethernet0' ]['host_tx_ready' ] = 'true'
2563+ task .port_dict ['Ethernet0' ]['admin_status' ] = 'up'
2564+
2565+ # Mock get_cmis_host_lanes_mask to return invalid value (0)
2566+ task .get_cmis_host_lanes_mask = MagicMock (return_value = 0 )
2567+
2568+ # Create port info
2569+ info = task .port_dict ['Ethernet0' ]
2570+
2571+ # Process the port - should fail due to invalid host_lanes_mask
2572+ task .process_single_lport ('Ethernet0' , info , {})
2573+
2574+ # Verify state transitioned to FAILED
2575+ assert common .get_cmis_state_from_state_db ('Ethernet0' , mock_get_status_sw_tbl ) == CMIS_STATE_FAILED
2576+
2577+ @patch ('xcvrd.xcvrd.XcvrTableHelper.get_status_sw_tbl' )
2578+ @patch ('xcvrd.xcvrd.platform_chassis' )
2579+ @patch ('xcvrd.xcvrd_utilities.common.is_fast_reboot_enabled' , MagicMock (return_value = False ))
2580+ def test_CmisManagerTask_process_single_lport_tx_power_config_failure (self , mock_chassis , mock_get_status_sw_tbl ):
2581+ """Test process_single_lport when configure_tx_output_power fails for coherent module"""
2582+ mock_get_status_sw_tbl = Table ("STATE_DB" , TRANSCEIVER_STATUS_SW_TABLE )
2583+
2584+ # Setup mock coherent module API
2585+ mock_xcvr_api = MagicMock ()
2586+ mock_xcvr_api .get_presence = MagicMock (return_value = True )
2587+ mock_xcvr_api .is_flat_memory = MagicMock (return_value = False )
2588+ mock_xcvr_api .get_module_type_abbreviation = MagicMock (return_value = 'QSFP-DD' )
2589+ mock_xcvr_api .is_coherent_module = MagicMock (return_value = True )
2590+ mock_xcvr_api .get_module_state = MagicMock (return_value = 'ModuleReady' )
2591+ mock_xcvr_api .get_datapath_state = MagicMock (return_value = {
2592+ 'DP1State' : 'DataPathDeactivated' ,
2593+ 'DP2State' : 'DataPathDeactivated' ,
2594+ 'DP3State' : 'DataPathDeactivated' ,
2595+ 'DP4State' : 'DataPathDeactivated' ,
2596+ 'DP5State' : 'DataPathDeactivated' ,
2597+ 'DP6State' : 'DataPathDeactivated' ,
2598+ 'DP7State' : 'DataPathDeactivated' ,
2599+ 'DP8State' : 'DataPathDeactivated'
2600+ })
2601+ mock_xcvr_api .get_tx_config_power = MagicMock (return_value = - 5 ) # Different from configured
2602+ mock_xcvr_api .get_laser_config_freq = MagicMock (return_value = 193100 )
2603+ mock_xcvr_api .set_lpmode = MagicMock (return_value = True )
2604+ mock_xcvr_api .get_datapath_deinit_duration = MagicMock (return_value = 600000.0 )
2605+ mock_xcvr_api .get_module_pwr_up_duration = MagicMock (return_value = 70000.0 )
2606+
2607+ mock_sfp = MagicMock ()
2608+ mock_sfp .get_presence = MagicMock (return_value = True )
2609+ mock_sfp .get_xcvr_api = MagicMock (return_value = mock_xcvr_api )
2610+ mock_chassis .get_sfp = MagicMock (return_value = mock_sfp )
2611+
2612+ # Setup port mapping and task
2613+ port_mapping = PortMapping ()
2614+ port_mapping .handle_port_change_event (PortChangeEvent ('Ethernet0' , 1 , 0 , PortChangeEvent .PORT_ADD ))
2615+ stop_event = threading .Event ()
2616+ task = CmisManagerTask (DEFAULT_NAMESPACE , port_mapping , stop_event , platform_chassis = mock_chassis )
2617+ task .xcvr_table_helper = XcvrTableHelper (DEFAULT_NAMESPACE )
2618+ task .xcvr_table_helper .get_status_sw_tbl .return_value = mock_get_status_sw_tbl
2619+
2620+ # Properly set up the port via port change event
2621+ port_change_event = PortChangeEvent ('Ethernet0' , 1 , 0 , PortChangeEvent .PORT_SET ,
2622+ {'speed' :'400000' , 'lanes' :'1,2,3,4,5,6,7,8' })
2623+ task .on_port_update_event (port_change_event )
2624+
2625+ # Set port to DP_PRE_INIT_CHECK state with coherent module settings
2626+ task .update_port_transceiver_status_table_sw_cmis_state ('Ethernet0' , CMIS_STATE_DP_PRE_INIT_CHECK )
2627+ task .port_dict ['Ethernet0' ]['host_tx_ready' ] = 'true'
2628+ task .port_dict ['Ethernet0' ]['admin_status' ] = 'up'
2629+ task .port_dict ['Ethernet0' ]['appl' ] = 1
2630+ task .port_dict ['Ethernet0' ]['host_lanes_mask' ] = 0xff
2631+ task .port_dict ['Ethernet0' ]['media_lanes_mask' ] = 0xff
2632+ task .port_dict ['Ethernet0' ]['tx_power' ] = - 10 # Configured tx power
2633+ task .port_dict ['Ethernet0' ]['laser_freq' ] = 193100
2634+
2635+ # Mock configure_tx_output_power to return failure (not 1)
2636+ task .configure_tx_output_power = MagicMock (return_value = 0 )
2637+
2638+ # Mock is_cmis_application_update_required to return True so we proceed
2639+ task .is_cmis_application_update_required = MagicMock (return_value = True )
2640+
2641+ # Create port info
2642+ info = task .port_dict ['Ethernet0' ]
2643+
2644+ # Process the port - should log error when tx power config fails
2645+ task .process_single_lport ('Ethernet0' , info , {})
2646+
2647+ # Verify configure_tx_output_power was called
2648+ assert task .configure_tx_output_power .called
2649+ # The state should still progress (error is logged but not fatal)
2650+ # Verify we moved to DP_DEINIT state (the state machine continues despite tx power config failure)
2651+ assert common .get_cmis_state_from_state_db ('Ethernet0' , mock_get_status_sw_tbl ) == CMIS_STATE_DP_DEINIT
2652+
25142653 @patch ('xcvrd.xcvrd.platform_chassis' )
25152654 @patch ('xcvrd.xcvrd_utilities.common.is_fast_reboot_enabled' , MagicMock (return_value = (False )))
25162655 @patch ('xcvrd.cmis.cmis_manager_task.PortChangeObserver' , MagicMock (handle_port_update_event = MagicMock ()))
0 commit comments