@@ -73,6 +73,58 @@ def test_CmisManagerTask_task_run_with_exception(self):
73
73
assert ("sonic-xcvrd/xcvrd/xcvrd.py" in str (trace ))
74
74
assert ("wait_for_port_config_done" in str (trace ))
75
75
76
+ @patch ('xcvrd.xcvrd_utilities.port_mapping.subscribe_port_update_event' , MagicMock (return_value = (None , None )))
77
+ @patch ('xcvrd.xcvrd_utilities.port_mapping.handle_port_update_event' , MagicMock ())
78
+ @patch ('xcvrd.xcvrd.CmisManagerTask.wait_for_port_config_done' , MagicMock ())
79
+ @patch ('xcvrd.xcvrd.log_exception_traceback' )
80
+ @patch ('xcvrd.xcvrd.XcvrTableHelper.get_status_tbl' )
81
+ @patch ('xcvrd.xcvrd.platform_chassis' )
82
+ def test_CmisManagerTask_get_xcvr_api_exception (self , mock_platform_chassis , mock_get_status_tbl , mock_log_exception_traceback ):
83
+ mock_get_status_tbl = Table ("STATE_DB" , TRANSCEIVER_STATUS_TABLE )
84
+ mock_sfp = MagicMock ()
85
+ mock_sfp .get_presence .return_value = True
86
+ mock_platform_chassis .get_sfp = MagicMock (return_value = mock_sfp )
87
+ port_mapping = PortMapping ()
88
+ port_mapping
89
+ stop_event = threading .Event ()
90
+ task = CmisManagerTask (DEFAULT_NAMESPACE , port_mapping , stop_event )
91
+ task .task_stopping_event .is_set = MagicMock (side_effect = [False , False , True ])
92
+ task .get_host_tx_status = MagicMock (return_value = 'true' )
93
+ task .get_port_admin_status = MagicMock (return_value = 'up' )
94
+ task .get_cfg_port_tbl = MagicMock ()
95
+ task .xcvr_table_helper .get_status_tbl .return_value = mock_get_status_tbl
96
+ task .get_cmis_application_desired = MagicMock (side_effect = KeyError )
97
+ port_change_event = PortChangeEvent ('Ethernet0' , 1 , 0 , PortChangeEvent .PORT_SET ,
98
+ {'speed' :'400000' , 'lanes' :'1,2,3,4,5,6,7,8' })
99
+
100
+ # Case 1: get_xcvr_api() raises an exception
101
+ task .on_port_update_event (port_change_event )
102
+ mock_sfp .get_xcvr_api = MagicMock (side_effect = NotImplementedError )
103
+ task .task_worker ()
104
+ assert mock_log_exception_traceback .call_count == 1
105
+ 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_FAILED
106
+
107
+ # Case 2: is_flat_memory() raises AttributeError. In this case, CMIS SM should transition to READY state
108
+ mock_xcvr_api = MagicMock ()
109
+ mock_sfp .get_xcvr_api = MagicMock (return_value = mock_xcvr_api )
110
+ mock_xcvr_api .is_flat_memory = MagicMock (side_effect = AttributeError )
111
+ task .task_stopping_event .is_set = MagicMock (side_effect = [False , False , True ])
112
+ task .on_port_update_event (port_change_event )
113
+ task .task_worker ()
114
+ 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
115
+
116
+ # Case 3: get_cmis_application_desired() raises an exception
117
+ mock_xcvr_api .is_flat_memory = MagicMock (return_value = False )
118
+ mock_xcvr_api .is_coherent_module = MagicMock (return_value = False )
119
+ mock_xcvr_api .get_module_type_abbreviation = MagicMock (return_value = 'QSFP-DD' )
120
+ task .task_stopping_event .is_set = MagicMock (side_effect = [False , False , True ])
121
+ task .on_port_update_event (port_change_event )
122
+ task .get_cmis_host_lanes_mask = MagicMock ()
123
+ task .task_worker ()
124
+ assert mock_log_exception_traceback .call_count == 2
125
+ 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_FAILED
126
+ assert task .get_cmis_host_lanes_mask .call_count == 0
127
+
76
128
@patch ('xcvrd.xcvrd_utilities.port_mapping.subscribe_port_config_change' , MagicMock (side_effect = NotImplementedError ))
77
129
def test_DomInfoUpdateTask_task_run_with_exception (self ):
78
130
port_mapping = PortMapping ()
0 commit comments