@@ -214,7 +214,7 @@ def test_CmisManagerTask_get_xcvr_api_exception(self, mock_platform_chassis, moc
214
214
mock_sfp .get_xcvr_api = MagicMock (side_effect = NotImplementedError )
215
215
task .task_worker ()
216
216
assert mock_log_exception_traceback .call_count == 1
217
- 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
217
+ assert get_cmis_state_from_state_db ('Ethernet0' , task .xcvr_table_helper .get_status_tbl (task .get_asic_id ('Ethernet0' ))) == CMIS_STATE_FAILED
218
218
219
219
# Case 2: is_flat_memory() raises AttributeError. In this case, CMIS SM should transition to READY state
220
220
mock_xcvr_api = MagicMock ()
@@ -223,7 +223,7 @@ def test_CmisManagerTask_get_xcvr_api_exception(self, mock_platform_chassis, moc
223
223
task .task_stopping_event .is_set = MagicMock (side_effect = [False , False , True ])
224
224
task .on_port_update_event (port_change_event )
225
225
task .task_worker ()
226
- 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
226
+ assert get_cmis_state_from_state_db ('Ethernet0' , task .xcvr_table_helper .get_status_tbl (task .get_asic_id ('Ethernet0' ))) == CMIS_STATE_READY
227
227
228
228
# Case 3: get_cmis_application_desired() raises an exception
229
229
mock_xcvr_api .is_flat_memory = MagicMock (return_value = False )
@@ -234,7 +234,7 @@ def test_CmisManagerTask_get_xcvr_api_exception(self, mock_platform_chassis, moc
234
234
task .get_cmis_host_lanes_mask = MagicMock ()
235
235
task .task_worker ()
236
236
assert mock_log_exception_traceback .call_count == 2
237
- 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
237
+ assert get_cmis_state_from_state_db ('Ethernet0' , task .xcvr_table_helper .get_status_tbl (task .get_asic_id ('Ethernet0' ))) == CMIS_STATE_FAILED
238
238
assert task .get_cmis_host_lanes_mask .call_count == 0
239
239
240
240
@patch ('xcvrd.xcvrd_utilities.port_event_helper.subscribe_port_config_change' , MagicMock (side_effect = NotImplementedError ))
@@ -297,7 +297,7 @@ def test_SfpStateUpdateTask_task_run_with_exception(self):
297
297
@patch ('xcvrd.xcvrd.SffManagerTask.join' )
298
298
def test_DaemonXcvrd_run_with_exception (self , mock_task_join_sff , mock_task_join_sfp ,
299
299
mock_task_join_dom , mock_init , mock_os_kill ):
300
- mock_init .return_value = ( PortMapping (), set () )
300
+ mock_init .return_value = PortMapping ()
301
301
xcvrd = DaemonXcvrd (SYSLOG_IDENTIFIER )
302
302
xcvrd .enable_sff_mgr = True
303
303
xcvrd .load_feature_flags = MagicMock ()
@@ -1199,7 +1199,7 @@ def test_DaemonXcvrd_wait_for_port_config_done(self, mock_select, mock_sub_table
1199
1199
@patch ('xcvrd.xcvrd.DomInfoUpdateTask.join' )
1200
1200
@patch ('xcvrd.xcvrd.SfpStateUpdateTask.join' )
1201
1201
def test_DaemonXcvrd_run (self , mock_task_stop1 , mock_task_stop2 , mock_task_run1 , mock_task_run2 , mock_deinit , mock_init ):
1202
- mock_init .return_value = ( PortMapping (), set () )
1202
+ mock_init .return_value = PortMapping ()
1203
1203
xcvrd = DaemonXcvrd (SYSLOG_IDENTIFIER )
1204
1204
xcvrd .load_feature_flags = MagicMock ()
1205
1205
xcvrd .stop_event .wait = MagicMock ()
@@ -1492,9 +1492,10 @@ def test_CmisManagerTask_handle_port_change_event(self):
1492
1492
1493
1493
port_change_event = PortChangeEvent ('Ethernet0' , 1 , 0 , PortChangeEvent .PORT_DEL )
1494
1494
task .on_port_update_event (port_change_event )
1495
- assert len (task .port_dict ) == 1
1495
+ assert len (task .port_dict ) == 0
1496
1496
1497
- port_change_event = PortChangeEvent ('Ethernet0' , 1 , 0 , PortChangeEvent .PORT_SET )
1497
+ port_dict = {'speed' :'400000' , 'lanes' :'1,2,3,4,5,6,7,8' }
1498
+ port_change_event = PortChangeEvent ('Ethernet0' , 1 , 0 , PortChangeEvent .PORT_SET , port_dict )
1498
1499
task .on_port_update_event (port_change_event )
1499
1500
assert len (task .port_dict ) == 1
1500
1501
@@ -1896,16 +1897,15 @@ def test_CmisManagerTask_task_worker(self, mock_chassis, mock_get_status_tbl):
1896
1897
mock_chassis .get_sfp = MagicMock (return_value = mock_sfp )
1897
1898
1898
1899
port_mapping = PortMapping ()
1900
+ port_mapping .handle_port_change_event (PortChangeEvent ('Ethernet0' , 1 , 0 , PortChangeEvent .PORT_ADD ))
1899
1901
stop_event = threading .Event ()
1900
1902
task = CmisManagerTask (DEFAULT_NAMESPACE , port_mapping , stop_event )
1901
- task .port_mapping .logical_port_list = ['Ethernet0' ]
1902
1903
task .xcvr_table_helper = XcvrTableHelper (DEFAULT_NAMESPACE )
1903
1904
task .xcvr_table_helper .get_status_tbl .return_value = mock_get_status_tbl
1904
1905
task .task_stopping_event .is_set = MagicMock (side_effect = [False , False , True ])
1905
1906
task .task_worker ()
1906
- 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_UNKNOWN
1907
+ assert get_cmis_state_from_state_db ('Ethernet0' , task .xcvr_table_helper .get_status_tbl (task .get_asic_id ('Ethernet0' ))) == CMIS_STATE_UNKNOWN
1907
1908
1908
- task .port_mapping .logical_port_list = MagicMock ()
1909
1909
port_change_event = PortChangeEvent ('PortConfigDone' , - 1 , 0 , PortChangeEvent .PORT_SET )
1910
1910
task .on_port_update_event (port_change_event )
1911
1911
assert task .isPortConfigDone
@@ -1914,7 +1914,7 @@ def test_CmisManagerTask_task_worker(self, mock_chassis, mock_get_status_tbl):
1914
1914
{'speed' :'400000' , 'lanes' :'1,2,3,4,5,6,7,8' })
1915
1915
task .on_port_update_event (port_change_event )
1916
1916
assert len (task .port_dict ) == 1
1917
- 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_INSERTED
1917
+ assert get_cmis_state_from_state_db ('Ethernet0' , task .xcvr_table_helper .get_status_tbl (task .get_asic_id ('Ethernet0' ))) == CMIS_STATE_INSERTED
1918
1918
1919
1919
task .get_host_tx_status = MagicMock (return_value = 'true' )
1920
1920
task .get_port_admin_status = MagicMock (return_value = 'up' )
@@ -1928,51 +1928,50 @@ def test_CmisManagerTask_task_worker(self, mock_chassis, mock_get_status_tbl):
1928
1928
mock_xcvr_api .decommission_all_datapaths = MagicMock (return_value = True )
1929
1929
task .task_stopping_event .is_set = MagicMock (side_effect = [False , False , True ])
1930
1930
task .task_worker ()
1931
- 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_DP_DEINIT
1931
+ assert get_cmis_state_from_state_db ('Ethernet0' , task .xcvr_table_helper .get_status_tbl (task .get_asic_id ('Ethernet0' ))) == CMIS_STATE_DP_DEINIT
1932
1932
task .task_stopping_event .is_set = MagicMock (side_effect = [False , False , True ])
1933
1933
task .task_worker ()
1934
1934
assert mock_xcvr_api .set_datapath_deinit .call_count == 1
1935
1935
assert mock_xcvr_api .tx_disable_channel .call_count == 1
1936
1936
assert mock_xcvr_api .set_lpmode .call_count == 1
1937
- 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_AP_CONF
1937
+ assert get_cmis_state_from_state_db ('Ethernet0' , task .xcvr_table_helper .get_status_tbl (task .get_asic_id ('Ethernet0' ))) == CMIS_STATE_AP_CONF
1938
1938
1939
1939
# Case 2: DP_DEINIT --> AP Configured
1940
1940
task .task_stopping_event .is_set = MagicMock (side_effect = [False , False , True ])
1941
1941
task .task_worker ()
1942
1942
assert mock_xcvr_api .set_application .call_count == 1
1943
- 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_DP_INIT
1943
+ assert get_cmis_state_from_state_db ('Ethernet0' , task .xcvr_table_helper .get_status_tbl (task .get_asic_id ('Ethernet0' ))) == CMIS_STATE_DP_INIT
1944
1944
1945
1945
# Case 3: AP Configured --> DP_INIT
1946
1946
task .task_stopping_event .is_set = MagicMock (side_effect = [False , False , True ])
1947
1947
task .task_worker ()
1948
1948
assert mock_xcvr_api .set_datapath_init .call_count == 1
1949
- 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_DP_TXON
1949
+ assert get_cmis_state_from_state_db ('Ethernet0' , task .xcvr_table_helper .get_status_tbl (task .get_asic_id ('Ethernet0' ))) == CMIS_STATE_DP_TXON
1950
1950
1951
1951
# Case 4: DP_INIT --> DP_TXON
1952
1952
task .task_stopping_event .is_set = MagicMock (side_effect = [False , False , True ])
1953
1953
task .task_worker ()
1954
1954
assert mock_xcvr_api .tx_disable_channel .call_count == 2
1955
- 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_DP_ACTIVATE
1955
+ assert get_cmis_state_from_state_db ('Ethernet0' , task .xcvr_table_helper .get_status_tbl (task .get_asic_id ('Ethernet0' ))) == CMIS_STATE_DP_ACTIVATE
1956
1956
1957
1957
# Case 5: DP_TXON --> DP_ACTIVATION
1958
1958
task .task_stopping_event .is_set = MagicMock (side_effect = [False , False , True ])
1959
1959
task .post_port_active_apsel_to_db = MagicMock ()
1960
1960
task .task_worker ()
1961
1961
assert task .post_port_active_apsel_to_db .call_count == 1
1962
- 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
1962
+ assert get_cmis_state_from_state_db ('Ethernet0' , task .xcvr_table_helper .get_status_tbl (task .get_asic_id ('Ethernet0' ))) == CMIS_STATE_READY
1963
1963
1964
1964
# Fail test coverage - Module Inserted state failing to reach DP_DEINIT
1965
1965
port_mapping = PortMapping ()
1966
+ port_mapping .handle_port_change_event (PortChangeEvent ('Ethernet1' , 1 , 0 , PortChangeEvent .PORT_ADD ))
1966
1967
stop_event = threading .Event ()
1967
1968
task = CmisManagerTask (DEFAULT_NAMESPACE , port_mapping , stop_event )
1968
- task .port_mapping .logical_port_list = ['Ethernet1' ]
1969
1969
task .xcvr_table_helper = XcvrTableHelper (DEFAULT_NAMESPACE )
1970
1970
task .xcvr_table_helper .get_status_tbl .return_value = mock_get_status_tbl
1971
1971
task .task_stopping_event .is_set = MagicMock (side_effect = [False , False , True ])
1972
1972
task .task_worker ()
1973
- assert get_cmis_state_from_state_db ('Ethernet1' , task .xcvr_table_helper .get_status_tbl (task .port_mapping . get_asic_id_for_logical_port ('Ethernet1' ))) == CMIS_STATE_UNKNOWN
1973
+ assert get_cmis_state_from_state_db ('Ethernet1' , task .xcvr_table_helper .get_status_tbl (task .get_asic_id ('Ethernet1' ))) == CMIS_STATE_UNKNOWN
1974
1974
1975
- task .port_mapping .logical_port_list = MagicMock ()
1976
1975
port_change_event = PortChangeEvent ('PortConfigDone' , - 1 , 0 , PortChangeEvent .PORT_SET )
1977
1976
task .on_port_update_event (port_change_event )
1978
1977
assert task .isPortConfigDone
@@ -1981,7 +1980,7 @@ def test_CmisManagerTask_task_worker(self, mock_chassis, mock_get_status_tbl):
1981
1980
{'speed' :'400000' , 'lanes' :'1,2,3,4,5,6,7,8' })
1982
1981
task .on_port_update_event (port_change_event )
1983
1982
assert len (task .port_dict ) == 1
1984
- assert get_cmis_state_from_state_db ('Ethernet1' , task .xcvr_table_helper .get_status_tbl (task .port_mapping . get_asic_id_for_logical_port ('Ethernet1' ))) == CMIS_STATE_INSERTED
1983
+ assert get_cmis_state_from_state_db ('Ethernet1' , task .xcvr_table_helper .get_status_tbl (task .get_asic_id ('Ethernet1' ))) == CMIS_STATE_INSERTED
1985
1984
1986
1985
task .get_host_tx_status = MagicMock (return_value = 'true' )
1987
1986
task .get_port_admin_status = MagicMock (return_value = 'up' )
@@ -1995,7 +1994,7 @@ def test_CmisManagerTask_task_worker(self, mock_chassis, mock_get_status_tbl):
1995
1994
mock_xcvr_api .decommission_all_datapaths = MagicMock (return_value = False )
1996
1995
task .task_stopping_event .is_set = MagicMock (side_effect = [False , False , True ])
1997
1996
task .task_worker ()
1998
- assert not get_cmis_state_from_state_db ('Ethernet1' , task .xcvr_table_helper .get_status_tbl (task .port_mapping . get_asic_id_for_logical_port ('Ethernet1' ))) == CMIS_STATE_DP_DEINIT
1997
+ assert not get_cmis_state_from_state_db ('Ethernet1' , task .xcvr_table_helper .get_status_tbl (task .get_asic_id ('Ethernet1' ))) == CMIS_STATE_DP_DEINIT
1999
1998
2000
1999
@patch ('xcvrd.xcvrd.XcvrTableHelper.get_status_tbl' )
2001
2000
@patch ('xcvrd.xcvrd.platform_chassis' )
@@ -2100,16 +2099,15 @@ def test_CmisManagerTask_task_worker_fastboot(self, mock_chassis, mock_get_statu
2100
2099
mock_chassis .get_sfp = MagicMock (return_value = mock_sfp )
2101
2100
2102
2101
port_mapping = PortMapping ()
2102
+ port_mapping .handle_port_change_event (PortChangeEvent ('Ethernet0' , 1 , 0 , PortChangeEvent .PORT_ADD ))
2103
2103
stop_event = threading .Event ()
2104
2104
task = CmisManagerTask (DEFAULT_NAMESPACE , port_mapping , stop_event )
2105
- task .port_mapping .logical_port_list = ['Ethernet0' ]
2106
2105
task .xcvr_table_helper = XcvrTableHelper (DEFAULT_NAMESPACE )
2107
2106
task .xcvr_table_helper .get_status_tbl .return_value = mock_get_status_tbl
2108
2107
task .task_stopping_event .is_set = MagicMock (side_effect = [False , False , True ])
2109
2108
task .task_worker ()
2110
- 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_UNKNOWN
2109
+ assert get_cmis_state_from_state_db ('Ethernet0' , task .xcvr_table_helper .get_status_tbl (task .get_asic_id ('Ethernet0' ))) == CMIS_STATE_UNKNOWN
2111
2110
2112
- task .port_mapping .logical_port_list = MagicMock ()
2113
2111
port_change_event = PortChangeEvent ('PortConfigDone' , - 1 , 0 , PortChangeEvent .PORT_SET )
2114
2112
task .on_port_update_event (port_change_event )
2115
2113
assert task .isPortConfigDone
@@ -2118,7 +2116,7 @@ def test_CmisManagerTask_task_worker_fastboot(self, mock_chassis, mock_get_statu
2118
2116
{'speed' :'400000' , 'lanes' :'1,2,3,4,5,6,7,8' })
2119
2117
task .on_port_update_event (port_change_event )
2120
2118
assert len (task .port_dict ) == 1
2121
- 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_INSERTED
2119
+ assert get_cmis_state_from_state_db ('Ethernet0' , task .xcvr_table_helper .get_status_tbl (task .get_asic_id ('Ethernet0' ))) == CMIS_STATE_INSERTED
2122
2120
2123
2121
task .get_host_tx_status = MagicMock (return_value = 'false' )
2124
2122
task .get_port_admin_status = MagicMock (return_value = 'up' )
@@ -2130,7 +2128,7 @@ def test_CmisManagerTask_task_worker_fastboot(self, mock_chassis, mock_get_statu
2130
2128
task .task_stopping_event .is_set = MagicMock (side_effect = [False , False , True ])
2131
2129
task .task_worker ()
2132
2130
2133
- 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
2131
+ assert get_cmis_state_from_state_db ('Ethernet0' , task .xcvr_table_helper .get_status_tbl (task .get_asic_id ('Ethernet0' ))) == CMIS_STATE_READY
2134
2132
2135
2133
2136
2134
@patch ('xcvrd.xcvrd.XcvrTableHelper.get_status_tbl' )
@@ -2236,16 +2234,15 @@ def test_CmisManagerTask_task_worker_host_tx_ready_false(self, mock_chassis, moc
2236
2234
mock_chassis .get_sfp = MagicMock (return_value = mock_sfp )
2237
2235
2238
2236
port_mapping = PortMapping ()
2237
+ port_mapping .handle_port_change_event (PortChangeEvent ('Ethernet0' , 1 , 0 , PortChangeEvent .PORT_ADD ))
2239
2238
stop_event = threading .Event ()
2240
2239
task = CmisManagerTask (DEFAULT_NAMESPACE , port_mapping , stop_event )
2241
- task .port_mapping .logical_port_list = ['Ethernet0' ]
2242
2240
task .xcvr_table_helper = XcvrTableHelper (DEFAULT_NAMESPACE )
2243
2241
task .xcvr_table_helper .get_status_tbl .return_value = mock_get_status_tbl
2244
2242
task .task_stopping_event .is_set = MagicMock (side_effect = [False , False , True ])
2245
2243
task .task_worker ()
2246
- 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_UNKNOWN
2244
+ assert get_cmis_state_from_state_db ('Ethernet0' , task .xcvr_table_helper .get_status_tbl (task .get_asic_id ('Ethernet0' ))) == CMIS_STATE_UNKNOWN
2247
2245
2248
- task .port_mapping .logical_port_list = MagicMock ()
2249
2246
port_change_event = PortChangeEvent ('PortConfigDone' , - 1 , 0 , PortChangeEvent .PORT_SET )
2250
2247
task .on_port_update_event (port_change_event )
2251
2248
assert task .isPortConfigDone
@@ -2254,7 +2251,7 @@ def test_CmisManagerTask_task_worker_host_tx_ready_false(self, mock_chassis, moc
2254
2251
{'speed' :'400000' , 'lanes' :'1,2,3,4,5,6,7,8' })
2255
2252
task .on_port_update_event (port_change_event )
2256
2253
assert len (task .port_dict ) == 1
2257
- 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_INSERTED
2254
+ assert get_cmis_state_from_state_db ('Ethernet0' , task .xcvr_table_helper .get_status_tbl (task .get_asic_id ('Ethernet0' ))) == CMIS_STATE_INSERTED
2258
2255
2259
2256
task .get_host_tx_status = MagicMock (return_value = 'false' )
2260
2257
task .get_port_admin_status = MagicMock (return_value = 'up' )
@@ -2267,7 +2264,7 @@ def test_CmisManagerTask_task_worker_host_tx_ready_false(self, mock_chassis, moc
2267
2264
task .task_worker ()
2268
2265
2269
2266
assert mock_xcvr_api .tx_disable_channel .call_count == 1
2270
- 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
2267
+ assert get_cmis_state_from_state_db ('Ethernet0' , task .xcvr_table_helper .get_status_tbl (task .get_asic_id ('Ethernet0' ))) == CMIS_STATE_READY
2271
2268
2272
2269
@pytest .mark .parametrize ("lport, expected_dom_polling" , [
2273
2270
('Ethernet0' , 'disabled' ),
0 commit comments