@@ -182,7 +182,8 @@ def test_CmisManagerTask_task_run_with_exception(self):
182
182
def test_DomInfoUpdateTask_task_run_with_exception (self ):
183
183
port_mapping = PortMapping ()
184
184
stop_event = threading .Event ()
185
- dom_info_update = DomInfoUpdateTask (DEFAULT_NAMESPACE , port_mapping , stop_event )
185
+ mock_cmis_manager = MagicMock ()
186
+ dom_info_update = DomInfoUpdateTask (DEFAULT_NAMESPACE , port_mapping , stop_event , mock_cmis_manager )
186
187
exception_received = None
187
188
trace = None
188
189
try :
@@ -356,6 +357,16 @@ def test_del_port_sfp_dom_info_from_db(self):
356
357
firmware_info_tbl = Table ("STATE_DB" , TRANSCEIVER_FIRMWARE_INFO_TABLE )
357
358
del_port_sfp_dom_info_from_db (logical_port_name , port_mapping , init_tbl , dom_tbl , dom_threshold_tbl , pm_tbl , firmware_info_tbl )
358
359
360
+ @pytest .mark .parametrize ("mock_found, mock_status_dict, expected_cmis_state" , [
361
+ (True , {'cmis_state' : CMIS_STATE_INSERTED }, CMIS_STATE_INSERTED ),
362
+ (False , {}, CMIS_STATE_UNKNOWN ),
363
+ (True , {'other_key' : 'some_value' }, CMIS_STATE_UNKNOWN )
364
+ ])
365
+ def test_get_cmis_state_from_state_db (self , mock_found , mock_status_dict , expected_cmis_state ):
366
+ status_tbl = MagicMock ()
367
+ status_tbl .get .return_value = (mock_found , mock_status_dict )
368
+ assert get_cmis_state_from_state_db ("Ethernet0" , status_tbl ) == expected_cmis_state
369
+
359
370
@patch ('xcvrd.xcvrd.get_physical_port_name_dict' , MagicMock (return_value = {0 : 'Ethernet0' }))
360
371
@patch ('xcvrd.xcvrd._wrapper_get_presence' , MagicMock (return_value = True ))
361
372
@patch ('xcvrd.xcvrd._wrapper_get_transceiver_status' , MagicMock (return_value = {'module_state' : 'ModuleReady' ,
@@ -1308,6 +1319,22 @@ def test_SffManagerTask_task_worker(self, mock_chassis):
1308
1319
assert mock_xcvr_api .tx_disable_channel .call_count == 2
1309
1320
mock_sfp .get_presence = MagicMock (return_value = True )
1310
1321
1322
+ def test_CmisManagerTask_update_port_transceiver_status_table_sw_cmis_state (self ):
1323
+ port_mapping = PortMapping ()
1324
+ stop_event = threading .Event ()
1325
+ task = CmisManagerTask (DEFAULT_NAMESPACE , port_mapping , stop_event )
1326
+ port_change_event = PortChangeEvent ('Ethernet0' , 1 , 0 , PortChangeEvent .PORT_SET )
1327
+ task .on_port_update_event (port_change_event )
1328
+
1329
+ task .xcvr_table_helper .get_status_tbl = MagicMock (return_value = None )
1330
+ task .update_port_transceiver_status_table_sw_cmis_state ("Ethernet0" , CMIS_STATE_INSERTED )
1331
+
1332
+ mock_get_status_tbl = MagicMock ()
1333
+ mock_get_status_tbl .set = MagicMock ()
1334
+ task .xcvr_table_helper .get_status_tbl .return_value = mock_get_status_tbl
1335
+ task .update_port_transceiver_status_table_sw_cmis_state ("Ethernet0" , CMIS_STATE_INSERTED )
1336
+ assert mock_get_status_tbl .set .call_count == 1
1337
+
1311
1338
@patch ('xcvrd.xcvrd._wrapper_get_sfp_type' , MagicMock (return_value = 'QSFP_DD' ))
1312
1339
def test_CmisManagerTask_handle_port_change_event (self ):
1313
1340
port_mapping = PortMapping ()
@@ -1585,12 +1612,14 @@ def test_CmisManagerTask_post_port_active_apsel_to_db(self):
1585
1612
assert int_tbl .getKeys () == []
1586
1613
1587
1614
1615
+ @patch ('xcvrd.xcvrd.XcvrTableHelper.get_status_tbl' )
1588
1616
@patch ('xcvrd.xcvrd.platform_chassis' )
1589
1617
@patch ('xcvrd.xcvrd.PortChangeObserver' , MagicMock (handle_port_update_event = MagicMock ()))
1590
1618
@patch ('xcvrd.xcvrd._wrapper_get_sfp_type' , MagicMock (return_value = 'QSFP_DD' ))
1591
1619
@patch ('xcvrd.xcvrd.CmisManagerTask.wait_for_port_config_done' , MagicMock ())
1592
1620
@patch ('xcvrd.xcvrd.is_cmis_api' , MagicMock (return_value = True ))
1593
- def test_CmisManagerTask_task_worker (self , mock_chassis ):
1621
+ def test_CmisManagerTask_task_worker (self , mock_chassis , mock_get_status_tbl ):
1622
+ mock_get_status_tbl = Table ("STATE_DB" , TRANSCEIVER_STATUS_TABLE )
1594
1623
mock_xcvr_api = MagicMock ()
1595
1624
mock_xcvr_api .set_datapath_deinit = MagicMock (return_value = True )
1596
1625
mock_xcvr_api .set_datapath_init = MagicMock (return_value = True )
@@ -1687,7 +1716,13 @@ def test_CmisManagerTask_task_worker(self, mock_chassis):
1687
1716
port_mapping = PortMapping ()
1688
1717
stop_event = threading .Event ()
1689
1718
task = CmisManagerTask (DEFAULT_NAMESPACE , port_mapping , stop_event )
1719
+ task .port_mapping .logical_port_list = ['Ethernet0' ]
1720
+ task .xcvr_table_helper .get_status_tbl .return_value = mock_get_status_tbl
1721
+ task .task_stopping_event .is_set = MagicMock (side_effect = [False , False , True ])
1722
+ task .task_worker ()
1723
+ 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
1690
1724
1725
+ task .port_mapping .logical_port_list = MagicMock ()
1691
1726
port_change_event = PortChangeEvent ('PortConfigDone' , - 1 , 0 , PortChangeEvent .PORT_SET )
1692
1727
task .on_port_update_event (port_change_event )
1693
1728
assert task .isPortConfigDone
@@ -1696,6 +1731,7 @@ def test_CmisManagerTask_task_worker(self, mock_chassis):
1696
1731
{'speed' :'400000' , 'lanes' :'1,2,3,4,5,6,7,8' })
1697
1732
task .on_port_update_event (port_change_event )
1698
1733
assert len (task .port_dict ) == 1
1734
+ 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
1699
1735
1700
1736
task .get_host_tx_status = MagicMock (return_value = 'true' )
1701
1737
task .get_port_admin_status = MagicMock (return_value = 'up' )
@@ -1707,31 +1743,38 @@ def test_CmisManagerTask_task_worker(self, mock_chassis):
1707
1743
# Case 1: Module Inserted --> DP_DEINIT
1708
1744
task .task_stopping_event .is_set = MagicMock (side_effect = [False , False , True ])
1709
1745
task .task_worker ()
1710
- assert task .port_dict [ 'Ethernet0' ][ 'cmis_state' ] == 'DP_DEINIT'
1746
+ 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
1711
1747
task .task_stopping_event .is_set = MagicMock (side_effect = [False , False , True ])
1712
1748
task .task_worker ()
1713
1749
assert mock_xcvr_api .set_datapath_deinit .call_count == 1
1714
1750
assert mock_xcvr_api .tx_disable_channel .call_count == 1
1715
1751
assert mock_xcvr_api .set_lpmode .call_count == 1
1716
- assert task .port_dict [ 'Ethernet0' ][ 'cmis_state' ] == 'AP_CONFIGURED'
1752
+ 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
1717
1753
1718
1754
# Case 2: DP_DEINIT --> AP Configured
1719
1755
task .task_stopping_event .is_set = MagicMock (side_effect = [False , False , True ])
1720
1756
task .task_worker ()
1721
1757
assert mock_xcvr_api .set_application .call_count == 1
1722
- assert task .port_dict [ 'Ethernet0' ][ 'cmis_state' ] == 'DP_INIT'
1758
+ 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
1723
1759
1724
1760
# Case 3: AP Configured --> DP_INIT
1725
1761
task .task_stopping_event .is_set = MagicMock (side_effect = [False , False , True ])
1726
1762
task .task_worker ()
1727
1763
assert mock_xcvr_api .set_datapath_init .call_count == 1
1728
- assert task .port_dict [ 'Ethernet0' ][ 'cmis_state' ] == 'DP_TXON'
1764
+ 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
1729
1765
1730
1766
# Case 4: DP_INIT --> DP_TXON
1731
1767
task .task_stopping_event .is_set = MagicMock (side_effect = [False , False , True ])
1732
1768
task .task_worker ()
1733
1769
assert mock_xcvr_api .tx_disable_channel .call_count == 2
1734
- assert task .port_dict ['Ethernet0' ]['cmis_state' ] == 'DP_ACTIVATION'
1770
+ 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
1771
+
1772
+ # Case 5: DP_TXON --> DP_ACTIVATION
1773
+ task .task_stopping_event .is_set = MagicMock (side_effect = [False , False , True ])
1774
+ task .post_port_active_apsel_to_db = MagicMock ()
1775
+ task .task_worker ()
1776
+ assert task .post_port_active_apsel_to_db .call_count == 1
1777
+ 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
1735
1778
1736
1779
@pytest .mark .parametrize ("lport, expected_dom_polling" , [
1737
1780
('Ethernet0' , 'disabled' ),
@@ -1753,7 +1796,8 @@ def mock_get(key):
1753
1796
1754
1797
port_mapping = PortMapping ()
1755
1798
stop_event = threading .Event ()
1756
- task = DomInfoUpdateTask (DEFAULT_NAMESPACE , port_mapping , stop_event )
1799
+ mock_cmis_manager = MagicMock ()
1800
+ task = DomInfoUpdateTask (DEFAULT_NAMESPACE , port_mapping , stop_event , mock_cmis_manager )
1757
1801
task .xcvr_table_helper = XcvrTableHelper (DEFAULT_NAMESPACE )
1758
1802
task .port_mapping .handle_port_change_event (PortChangeEvent ('Ethernet4' , 1 , 0 , PortChangeEvent .PORT_ADD ))
1759
1803
task .port_mapping .handle_port_change_event (PortChangeEvent ('Ethernet12' , 1 , 0 , PortChangeEvent .PORT_ADD ))
@@ -1766,12 +1810,34 @@ def mock_get(key):
1766
1810
1767
1811
assert task .get_dom_polling_from_config_db (lport ) == expected_dom_polling
1768
1812
1813
+ @pytest .mark .parametrize ("skip_cmis_manager, is_asic_index_none, mock_cmis_state, expected_result" , [
1814
+ (True , False , None , False ),
1815
+ (False , False , CMIS_STATE_INSERTED , True ),
1816
+ (False , False , CMIS_STATE_READY , False ),
1817
+ (False , False , CMIS_STATE_UNKNOWN , True ),
1818
+ (False , True , None , False ),
1819
+ ])
1820
+ @patch ('xcvrd.xcvrd.get_cmis_state_from_state_db' )
1821
+ def test_DomInfoUpdateTask_is_port_in_cmis_initialization_process (self , mock_get_cmis_state_from_state_db , skip_cmis_manager , is_asic_index_none , mock_cmis_state , expected_result ):
1822
+ port_mapping = PortMapping ()
1823
+ lport = 'Ethernet0'
1824
+ port_change_event = PortChangeEvent (lport , 1 , 0 , PortChangeEvent .PORT_ADD )
1825
+ stop_event = threading .Event ()
1826
+ task = DomInfoUpdateTask (DEFAULT_NAMESPACE , port_mapping , stop_event , skip_cmis_manager )
1827
+ task .xcvr_table_helper = XcvrTableHelper (DEFAULT_NAMESPACE )
1828
+ task .on_port_config_change (port_change_event )
1829
+ mock_get_cmis_state_from_state_db .return_value = mock_cmis_state
1830
+ if is_asic_index_none :
1831
+ lport = 'INVALID_PORT'
1832
+ assert task .is_port_in_cmis_initialization_process (lport ) == expected_result
1833
+
1769
1834
@patch ('xcvrd.xcvrd.XcvrTableHelper' , MagicMock ())
1770
1835
@patch ('xcvrd.xcvrd.delete_port_from_status_table_hw' )
1771
1836
def test_DomInfoUpdateTask_handle_port_change_event (self , mock_del_status_tbl_hw ):
1772
1837
port_mapping = PortMapping ()
1773
1838
stop_event = threading .Event ()
1774
- task = DomInfoUpdateTask (DEFAULT_NAMESPACE , port_mapping , stop_event )
1839
+ mock_cmis_manager = MagicMock ()
1840
+ task = DomInfoUpdateTask (DEFAULT_NAMESPACE , port_mapping , stop_event , mock_cmis_manager )
1775
1841
task .xcvr_table_helper = XcvrTableHelper (DEFAULT_NAMESPACE )
1776
1842
port_change_event = PortChangeEvent ('Ethernet0' , 1 , 0 , PortChangeEvent .PORT_ADD )
1777
1843
task .on_port_config_change (port_change_event )
@@ -1794,7 +1860,8 @@ def test_DomInfoUpdateTask_handle_port_change_event(self, mock_del_status_tbl_hw
1794
1860
def test_DomInfoUpdateTask_task_run_stop (self ):
1795
1861
port_mapping = PortMapping ()
1796
1862
stop_event = threading .Event ()
1797
- task = DomInfoUpdateTask (DEFAULT_NAMESPACE , port_mapping , stop_event )
1863
+ mock_cmis_manager = MagicMock ()
1864
+ task = DomInfoUpdateTask (DEFAULT_NAMESPACE , port_mapping , stop_event , mock_cmis_manager )
1798
1865
task .start ()
1799
1866
task .join ()
1800
1867
assert not task .is_alive ()
@@ -1819,10 +1886,12 @@ def test_DomInfoUpdateTask_task_worker(self, mock_post_pm_info, mock_update_stat
1819
1886
1820
1887
port_mapping = PortMapping ()
1821
1888
stop_event = threading .Event ()
1822
- task = DomInfoUpdateTask (DEFAULT_NAMESPACE , port_mapping , stop_event )
1889
+ mock_cmis_manager = MagicMock ()
1890
+ task = DomInfoUpdateTask (DEFAULT_NAMESPACE , port_mapping , stop_event , mock_cmis_manager )
1823
1891
task .xcvr_table_helper = XcvrTableHelper (DEFAULT_NAMESPACE )
1824
1892
task .task_stopping_event .wait = MagicMock (side_effect = [False , True ])
1825
1893
task .get_dom_polling_from_config_db = MagicMock (return_value = 'enabled' )
1894
+ task .is_port_in_cmis_terminal_state = MagicMock (return_value = False )
1826
1895
mock_detect_error .return_value = True
1827
1896
task .task_worker ()
1828
1897
assert task .port_mapping .logical_port_list .count ('Ethernet0' )
0 commit comments