@@ -149,7 +149,7 @@ def test_post_port_sfp_info_to_db(self):
149
149
@patch ('xcvrd.xcvrd.platform_sfputil' , MagicMock (return_value = [0 ]))
150
150
@patch ('xcvrd.xcvrd._wrapper_get_presence' , MagicMock (return_value = True ))
151
151
@patch ('xcvrd.xcvrd._wrapper_is_replaceable' , MagicMock (return_value = True ))
152
- @patch ('xcvrd.xcvrd.xcvr_table_helper ' , MagicMock ())
152
+ @patch ('xcvrd.xcvrd.XcvrTableHelper ' , MagicMock ())
153
153
@patch ('xcvrd.xcvrd._wrapper_get_transceiver_info' , MagicMock (return_value = {'type' : '22.75' ,
154
154
'vendor_rev' : '0.5' ,
155
155
'serial' : '0.7' ,
@@ -219,19 +219,21 @@ def test_post_port_sfp_dom_info_to_db(self):
219
219
port_change_event = PortChangeEvent ('Ethernet0' , 1 , 0 , PortChangeEvent .PORT_ADD )
220
220
port_mapping .handle_port_change_event (port_change_event )
221
221
stop_event = threading .Event ()
222
- post_port_sfp_dom_info_to_db (True , port_mapping , stop_event )
222
+ xcvr_table_helper = XcvrTableHelper ()
223
+ post_port_sfp_dom_info_to_db (True , port_mapping , xcvr_table_helper , stop_event )
223
224
224
225
@patch ('xcvrd.xcvrd_utilities.port_mapping.PortMapping.logical_port_name_to_physical_port_list' , MagicMock (return_value = [0 ]))
225
226
@patch ('xcvrd.xcvrd.platform_sfputil' , MagicMock (return_value = [0 ]))
226
227
@patch ('xcvrd.xcvrd._wrapper_get_presence' , MagicMock (return_value = True ))
227
228
@patch ('xcvrd.xcvrd._wrapper_is_replaceable' , MagicMock (return_value = True ))
228
- @patch ('xcvrd.xcvrd.xcvr_table_helper ' , MagicMock ())
229
+ @patch ('xcvrd.xcvrd.XcvrTableHelper ' , MagicMock ())
229
230
def test_init_port_sfp_status_tbl (self ):
230
231
port_mapping = PortMapping ()
231
232
port_change_event = PortChangeEvent ('Ethernet0' , 1 , 0 , PortChangeEvent .PORT_ADD )
232
233
port_mapping .handle_port_change_event (port_change_event )
233
234
stop_event = threading .Event ()
234
- init_port_sfp_status_tbl (port_mapping , stop_event )
235
+ xcvr_table_helper = XcvrTableHelper ()
236
+ init_port_sfp_status_tbl (port_mapping , xcvr_table_helper , stop_event )
235
237
236
238
def test_get_media_settings_key (self ):
237
239
xcvr_info_dict = {
@@ -544,10 +546,11 @@ def test_CmisManagerTask_task_worker(self, mock_chassis):
544
546
task .task_worker ()
545
547
assert mock_xcvr_api .tx_disable_channel .call_count == 2
546
548
547
- @patch ('xcvrd.xcvrd.xcvr_table_helper ' , MagicMock ())
549
+ @patch ('xcvrd.xcvrd.XcvrTableHelper ' , MagicMock ())
548
550
def test_DomInfoUpdateTask_handle_port_change_event (self ):
549
551
port_mapping = PortMapping ()
550
552
task = DomInfoUpdateTask (port_mapping )
553
+ task .xcvr_table_helper = XcvrTableHelper ()
551
554
port_change_event = PortChangeEvent ('Ethernet0' , 1 , 0 , PortChangeEvent .PORT_ADD )
552
555
task .on_port_config_change (port_change_event )
553
556
assert task .port_mapping .logical_port_list .count ('Ethernet0' )
@@ -571,7 +574,7 @@ def test_DomInfoUpdateTask_task_run_stop(self):
571
574
task .task_stop ()
572
575
assert not task .task_thread .is_alive ()
573
576
574
- @patch ('xcvrd.xcvrd.xcvr_table_helper ' , MagicMock ())
577
+ @patch ('xcvrd.xcvrd.XcvrTableHelper ' , MagicMock ())
575
578
@patch ('xcvrd.xcvrd_utilities.sfp_status_helper.detect_port_in_error_status' )
576
579
@patch ('xcvrd.xcvrd.post_port_dom_info_to_db' )
577
580
@patch ('xcvrd.xcvrd.post_port_dom_threshold_info_to_db' )
@@ -587,6 +590,7 @@ def test_DomInfoUpdateTask_task_worker(self, mock_select, mock_sub_table, mock_p
587
590
588
591
port_mapping = PortMapping ()
589
592
task = DomInfoUpdateTask (port_mapping )
593
+ task .xcvr_table_helper = XcvrTableHelper ()
590
594
task .task_stopping_event .wait = MagicMock (side_effect = [False , True ])
591
595
mock_detect_error .return_value = True
592
596
task .task_worker ()
@@ -603,7 +607,7 @@ def test_DomInfoUpdateTask_task_worker(self, mock_select, mock_sub_table, mock_p
603
607
assert mock_post_dom_info .call_count == 1
604
608
605
609
@patch ('xcvrd.xcvrd._wrapper_get_presence' , MagicMock (return_value = False ))
606
- @patch ('xcvrd.xcvrd.xcvr_table_helper ' )
610
+ @patch ('xcvrd.xcvrd.XcvrTableHelper ' )
607
611
def test_SfpStateUpdateTask_handle_port_change_event (self , mock_table_helper ):
608
612
mock_table = MagicMock ()
609
613
mock_table .get = MagicMock (return_value = (False , None ))
@@ -614,6 +618,7 @@ def test_SfpStateUpdateTask_handle_port_change_event(self, mock_table_helper):
614
618
port_mapping = PortMapping ()
615
619
retry_eeprom_set = set ()
616
620
task = SfpStateUpdateTask (port_mapping , retry_eeprom_set )
621
+ task .xcvr_table_helper = XcvrTableHelper ()
617
622
port_change_event = PortChangeEvent ('Ethernet0' , 1 , 0 , PortChangeEvent .PORT_ADD )
618
623
wait_time = 5
619
624
while wait_time > 0 :
@@ -650,12 +655,19 @@ def test_SfpStateUpdateTask_task_run_stop(self):
650
655
task .task_stop ()
651
656
assert wait_until (5 , 1 , lambda : task .task_process .is_alive () is False )
652
657
653
- @patch ('xcvrd.xcvrd.xcvr_table_helper ' , MagicMock ())
658
+ @patch ('xcvrd.xcvrd.XcvrTableHelper ' , MagicMock ())
654
659
@patch ('xcvrd.xcvrd.post_port_sfp_info_to_db' )
655
660
def test_SfpStateUpdateTask_retry_eeprom_reading (self , mock_post_sfp_info ):
661
+ mock_table = MagicMock ()
662
+ mock_table .get = MagicMock (return_value = (False , None ))
663
+
656
664
port_mapping = PortMapping ()
657
665
retry_eeprom_set = set ()
658
666
task = SfpStateUpdateTask (port_mapping , retry_eeprom_set )
667
+ task .xcvr_table_helper = XcvrTableHelper ()
668
+ task .xcvr_table_helper .get_intf_tbl = MagicMock (return_value = mock_table )
669
+ task .xcvr_table_helper .get_dom_tbl = MagicMock (return_value = mock_table )
670
+ task .xcvr_table_helper .get_app_port_tbl = MagicMock (return_value = mock_table )
659
671
task .retry_eeprom_reading ()
660
672
assert mock_post_sfp_info .call_count == 0
661
673
@@ -693,7 +705,7 @@ def test_SfpStateUpdateTask_mapping_event_from_change_event(self):
693
705
assert task ._mapping_event_from_change_event (True , port_dict ) == NORMAL_EVENT
694
706
695
707
@patch ('time.sleep' , MagicMock ())
696
- @patch ('xcvrd.xcvrd.xcvr_table_helper ' , MagicMock ())
708
+ @patch ('xcvrd.xcvrd.XcvrTableHelper ' , MagicMock ())
697
709
@patch ('xcvrd.xcvrd._wrapper_soak_sfp_insert_event' , MagicMock ())
698
710
@patch ('xcvrd.xcvrd_utilities.port_mapping.subscribe_port_config_change' , MagicMock (return_value = (None , None )))
699
711
@patch ('xcvrd.xcvrd_utilities.port_mapping.handle_port_config_change' , MagicMock ())
@@ -710,6 +722,7 @@ def test_SfpStateUpdateTask_task_worker(self, mock_updata_status, mock_post_sfp_
710
722
port_mapping = PortMapping ()
711
723
retry_eeprom_set = set ()
712
724
task = SfpStateUpdateTask (port_mapping , retry_eeprom_set )
725
+ task .xcvr_table_helper = XcvrTableHelper ()
713
726
stop_event = multiprocessing .Event ()
714
727
sfp_error_event = multiprocessing .Event ()
715
728
mock_change_event .return_value = (True , {0 : 0 }, {})
@@ -792,7 +805,7 @@ def test_SfpStateUpdateTask_task_worker(self, mock_updata_status, mock_post_sfp_
792
805
assert mock_updata_status .call_count == 1
793
806
assert mock_del_dom .call_count == 1
794
807
795
- @patch ('xcvrd.xcvrd.xcvr_table_helper ' )
808
+ @patch ('xcvrd.xcvrd.XcvrTableHelper ' )
796
809
@patch ('xcvrd.xcvrd._wrapper_get_presence' )
797
810
@patch ('xcvrd.xcvrd.notify_media_setting' )
798
811
@patch ('xcvrd.xcvrd.post_port_dom_threshold_info_to_db' )
@@ -819,6 +832,10 @@ class MockTable:
819
832
port_mapping = PortMapping ()
820
833
retry_eeprom_set = set ()
821
834
task = SfpStateUpdateTask (port_mapping , retry_eeprom_set )
835
+ task .xcvr_table_helper = XcvrTableHelper ()
836
+ task .xcvr_table_helper .get_status_tbl = mock_table_helper .get_status_tbl
837
+ task .xcvr_table_helper .get_intf_tbl = mock_table_helper .get_intf_tbl
838
+ task .xcvr_table_helper .get_dom_tbl = mock_table_helper .get_dom_tbl
822
839
port_change_event = PortChangeEvent ('Ethernet0' , 1 , 0 , PortChangeEvent .PORT_ADD )
823
840
task .port_mapping .handle_port_change_event (port_change_event )
824
841
# SFP information is in the DB, copy the SFP information for the newly added logical port
0 commit comments