@@ -530,6 +530,160 @@ def test_DaemonXcvrd_run(self, mock_task_stop1, mock_task_stop2, mock_task_run1,
530530 assert mock_deinit .call_count == 1
531531 assert mock_init .call_count == 1
532532
533+ @patch ('xcvrd.xcvrd._wrapper_get_sfp_type' , MagicMock (return_value = 'QSFP_DD' ))
534+ def test_CmisManagerTask_handle_port_change_event (self ):
535+ port_mapping = PortMapping ()
536+ task = CmisManagerTask (port_mapping )
537+
538+ assert not task .isPortConfigDone
539+ port_change_event = PortChangeEvent ('PortConfigDone' , - 1 , 0 , PortChangeEvent .PORT_SET )
540+ task .on_port_update_event (port_change_event )
541+ assert task .isPortConfigDone
542+
543+ port_change_event = PortChangeEvent ('Ethernet0' , 1 , 0 , PortChangeEvent .PORT_ADD )
544+ task .on_port_update_event (port_change_event )
545+ assert len (task .port_dict ) == 0
546+
547+ port_change_event = PortChangeEvent ('Ethernet0' , 1 , 0 , PortChangeEvent .PORT_REMOVE )
548+ task .on_port_update_event (port_change_event )
549+ assert len (task .port_dict ) == 0
550+
551+ port_change_event = PortChangeEvent ('Ethernet0' , 1 , 0 , PortChangeEvent .PORT_DEL )
552+ task .on_port_update_event (port_change_event )
553+ assert len (task .port_dict ) == 1
554+
555+ port_change_event = PortChangeEvent ('Ethernet0' , 1 , 0 , PortChangeEvent .PORT_SET )
556+ task .on_port_update_event (port_change_event )
557+ assert len (task .port_dict ) == 1
558+
559+ @patch ('xcvrd.xcvrd.platform_chassis' )
560+ @patch ('xcvrd.xcvrd_utilities.port_mapping.subscribe_port_update_event' , MagicMock (return_value = (None , None )))
561+ @patch ('xcvrd.xcvrd_utilities.port_mapping.handle_port_update_event' , MagicMock ())
562+ def test_CmisManagerTask_task_run_stop (self , mock_chassis ):
563+ mock_object = MagicMock ()
564+ mock_object .get_presence = MagicMock (return_value = True )
565+ mock_chassis .get_all_sfps = MagicMock (return_value = [mock_object , mock_object ])
566+
567+ port_mapping = PortMapping ()
568+ task = CmisManagerTask (port_mapping )
569+ task .task_run ()
570+ task .task_stop ()
571+ assert task .task_process is None
572+
573+ @patch ('xcvrd.xcvrd.platform_chassis' )
574+ @patch ('xcvrd.xcvrd_utilities.port_mapping.subscribe_port_update_event' , MagicMock (return_value = (None , None )))
575+ @patch ('xcvrd.xcvrd_utilities.port_mapping.handle_port_update_event' , MagicMock ())
576+ @patch ('xcvrd.xcvrd._wrapper_get_sfp_type' , MagicMock (return_value = 'QSFP_DD' ))
577+ def test_CmisManagerTask_task_worker (self , mock_chassis ):
578+ mock_xcvr_api = MagicMock ()
579+ mock_xcvr_api .set_datapath_deinit = MagicMock (return_value = True )
580+ mock_xcvr_api .set_datapath_init = MagicMock (return_value = True )
581+ mock_xcvr_api .tx_disable_channel = MagicMock (return_value = True )
582+ mock_xcvr_api .set_lpmode = MagicMock (return_value = True )
583+ mock_xcvr_api .set_application = MagicMock (return_value = True )
584+ mock_xcvr_api .is_flat_memory = MagicMock (return_value = False )
585+ mock_xcvr_api .get_module_type_abbreviation = MagicMock (return_value = 'QSFP-DD' )
586+ mock_xcvr_api .get_application_advertisement = MagicMock (return_value = {
587+ 1 : {
588+ 'host_electrical_interface_id' : '400GAUI-8 C2M (Annex 120E)' ,
589+ 'module_media_interface_id' : '400GBASE-DR4 (Cl 124)' ,
590+ 'media_lane_count' : 4 ,
591+ 'host_lane_count' : 8 ,
592+ 'host_lane_assignment_options' : 1
593+ },
594+ 2 : {
595+ 'host_electrical_interface_id' : '100GAUI-2 C2M (Annex 135G)' ,
596+ 'module_media_interface_id' : '100G-FR/100GBASE-FR1 (Cl 140)' ,
597+ 'media_lane_count' : 1 ,
598+ 'host_lane_count' : 2 ,
599+ 'host_lane_assignment_options' : 85
600+ }
601+ })
602+ mock_xcvr_api .get_module_state = MagicMock (return_value = 'ModuleReady' )
603+ mock_xcvr_api .get_config_datapath_hostlane_status = MagicMock (return_value = {
604+ 'ConfigStatusLane1' : 'ConfigSuccess' ,
605+ 'ConfigStatusLane2' : 'ConfigSuccess' ,
606+ 'ConfigStatusLane3' : 'ConfigSuccess' ,
607+ 'ConfigStatusLane4' : 'ConfigSuccess' ,
608+ 'ConfigStatusLane5' : 'ConfigSuccess' ,
609+ 'ConfigStatusLane6' : 'ConfigSuccess' ,
610+ 'ConfigStatusLane7' : 'ConfigSuccess' ,
611+ 'ConfigStatusLane8' : 'ConfigSuccess'
612+ })
613+ mock_xcvr_api .get_datapath_state = MagicMock (side_effect = [
614+ {
615+ 'DP1State' : 'DataPathDeactivated' ,
616+ 'DP2State' : 'DataPathDeactivated' ,
617+ 'DP3State' : 'DataPathDeactivated' ,
618+ 'DP4State' : 'DataPathDeactivated' ,
619+ 'DP5State' : 'DataPathDeactivated' ,
620+ 'DP6State' : 'DataPathDeactivated' ,
621+ 'DP7State' : 'DataPathDeactivated' ,
622+ 'DP8State' : 'DataPathDeactivated'
623+ },
624+ {
625+ 'DP1State' : 'DataPathInitialized' ,
626+ 'DP2State' : 'DataPathInitialized' ,
627+ 'DP3State' : 'DataPathInitialized' ,
628+ 'DP4State' : 'DataPathInitialized' ,
629+ 'DP5State' : 'DataPathInitialized' ,
630+ 'DP6State' : 'DataPathInitialized' ,
631+ 'DP7State' : 'DataPathInitialized' ,
632+ 'DP8State' : 'DataPathInitialized'
633+ },
634+ {
635+ 'DP1State' : 'DataPathActivated' ,
636+ 'DP2State' : 'DataPathActivated' ,
637+ 'DP3State' : 'DataPathActivated' ,
638+ 'DP4State' : 'DataPathActivated' ,
639+ 'DP5State' : 'DataPathActivated' ,
640+ 'DP6State' : 'DataPathActivated' ,
641+ 'DP7State' : 'DataPathActivated' ,
642+ 'DP8State' : 'DataPathActivated'
643+ }
644+ ])
645+
646+ mock_sfp = MagicMock ()
647+ mock_sfp .get_presence = MagicMock (return_value = True )
648+ mock_sfp .get_xcvr_api = MagicMock (return_value = mock_xcvr_api )
649+
650+ mock_chassis .get_all_sfps = MagicMock (return_value = [mock_sfp ])
651+ mock_chassis .get_sfp = MagicMock (return_value = mock_sfp )
652+
653+ port_mapping = PortMapping ()
654+ task = CmisManagerTask (port_mapping )
655+
656+ port_change_event = PortChangeEvent ('PortConfigDone' , - 1 , 0 , PortChangeEvent .PORT_SET )
657+ task .on_port_update_event (port_change_event )
658+ assert task .isPortConfigDone
659+
660+ port_change_event = PortChangeEvent ('Ethernet0' , 1 , 0 , PortChangeEvent .PORT_SET ,
661+ {'speed' :'400000' , 'lanes' :'1,2,3,4,5,6,7,8' })
662+ task .on_port_update_event (port_change_event )
663+ assert len (task .port_dict ) == 1
664+
665+ # Case 1: Module Inserted --> DP_DEINIT
666+ task .task_stopping_event .is_set = MagicMock (side_effect = [False , False , True ])
667+ task .task_worker ()
668+ assert mock_xcvr_api .set_datapath_deinit .call_count == 1
669+ assert mock_xcvr_api .tx_disable_channel .call_count == 1
670+ assert mock_xcvr_api .set_lpmode .call_count == 2
671+
672+ # Case 2: DP_DEINIT --> AP Configured
673+ task .task_stopping_event .is_set = MagicMock (side_effect = [False , False , True ])
674+ task .task_worker ()
675+ assert mock_xcvr_api .set_application .call_count == 1
676+
677+ # Case 3: AP Configured --> DP_INIT
678+ task .task_stopping_event .is_set = MagicMock (side_effect = [False , False , True ])
679+ task .task_worker ()
680+ assert mock_xcvr_api .set_datapath_init .call_count == 1
681+
682+ # Case 4: DP_INIT --> DP_TXON
683+ task .task_stopping_event .is_set = MagicMock (side_effect = [False , False , True ])
684+ task .task_worker ()
685+ assert mock_xcvr_api .tx_disable_channel .call_count == 2
686+
533687 @patch ('xcvrd.xcvrd.xcvr_table_helper' , MagicMock ())
534688 def test_DomInfoUpdateTask_handle_port_change_event (self ):
535689 port_mapping = PortMapping ()
0 commit comments