@@ -149,7 +149,7 @@ def test_post_port_sfp_info_to_db(self):
149149 @patch ('xcvrd.xcvrd.platform_sfputil' , MagicMock (return_value = [0 ]))
150150 @patch ('xcvrd.xcvrd._wrapper_get_presence' , MagicMock (return_value = True ))
151151 @patch ('xcvrd.xcvrd._wrapper_is_replaceable' , MagicMock (return_value = True ))
152- @patch ('xcvrd.xcvrd.xcvr_table_helper ' , MagicMock ())
152+ @patch ('xcvrd.xcvrd.XcvrTableHelper ' , MagicMock ())
153153 @patch ('xcvrd.xcvrd._wrapper_get_transceiver_info' , MagicMock (return_value = {'type' : '22.75' ,
154154 'vendor_rev' : '0.5' ,
155155 'serial' : '0.7' ,
@@ -219,19 +219,21 @@ def test_post_port_sfp_dom_info_to_db(self):
219219 port_change_event = PortChangeEvent ('Ethernet0' , 1 , 0 , PortChangeEvent .PORT_ADD )
220220 port_mapping .handle_port_change_event (port_change_event )
221221 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 )
223224
224225 @patch ('xcvrd.xcvrd_utilities.port_mapping.PortMapping.logical_port_name_to_physical_port_list' , MagicMock (return_value = [0 ]))
225226 @patch ('xcvrd.xcvrd.platform_sfputil' , MagicMock (return_value = [0 ]))
226227 @patch ('xcvrd.xcvrd._wrapper_get_presence' , MagicMock (return_value = True ))
227228 @patch ('xcvrd.xcvrd._wrapper_is_replaceable' , MagicMock (return_value = True ))
228- @patch ('xcvrd.xcvrd.xcvr_table_helper ' , MagicMock ())
229+ @patch ('xcvrd.xcvrd.XcvrTableHelper ' , MagicMock ())
229230 def test_init_port_sfp_status_tbl (self ):
230231 port_mapping = PortMapping ()
231232 port_change_event = PortChangeEvent ('Ethernet0' , 1 , 0 , PortChangeEvent .PORT_ADD )
232233 port_mapping .handle_port_change_event (port_change_event )
233234 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 )
235237
236238 def test_get_media_settings_key (self ):
237239 xcvr_info_dict = {
@@ -544,10 +546,11 @@ def test_CmisManagerTask_task_worker(self, mock_chassis):
544546 task .task_worker ()
545547 assert mock_xcvr_api .tx_disable_channel .call_count == 2
546548
547- @patch ('xcvrd.xcvrd.xcvr_table_helper ' , MagicMock ())
549+ @patch ('xcvrd.xcvrd.XcvrTableHelper ' , MagicMock ())
548550 def test_DomInfoUpdateTask_handle_port_change_event (self ):
549551 port_mapping = PortMapping ()
550552 task = DomInfoUpdateTask (port_mapping )
553+ task .xcvr_table_helper = XcvrTableHelper ()
551554 port_change_event = PortChangeEvent ('Ethernet0' , 1 , 0 , PortChangeEvent .PORT_ADD )
552555 task .on_port_config_change (port_change_event )
553556 assert task .port_mapping .logical_port_list .count ('Ethernet0' )
@@ -571,7 +574,7 @@ def test_DomInfoUpdateTask_task_run_stop(self):
571574 task .task_stop ()
572575 assert not task .task_thread .is_alive ()
573576
574- @patch ('xcvrd.xcvrd.xcvr_table_helper ' , MagicMock ())
577+ @patch ('xcvrd.xcvrd.XcvrTableHelper ' , MagicMock ())
575578 @patch ('xcvrd.xcvrd_utilities.sfp_status_helper.detect_port_in_error_status' )
576579 @patch ('xcvrd.xcvrd.post_port_dom_info_to_db' )
577580 @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
587590
588591 port_mapping = PortMapping ()
589592 task = DomInfoUpdateTask (port_mapping )
593+ task .xcvr_table_helper = XcvrTableHelper ()
590594 task .task_stopping_event .wait = MagicMock (side_effect = [False , True ])
591595 mock_detect_error .return_value = True
592596 task .task_worker ()
@@ -603,7 +607,7 @@ def test_DomInfoUpdateTask_task_worker(self, mock_select, mock_sub_table, mock_p
603607 assert mock_post_dom_info .call_count == 1
604608
605609 @patch ('xcvrd.xcvrd._wrapper_get_presence' , MagicMock (return_value = False ))
606- @patch ('xcvrd.xcvrd.xcvr_table_helper ' )
610+ @patch ('xcvrd.xcvrd.XcvrTableHelper ' )
607611 def test_SfpStateUpdateTask_handle_port_change_event (self , mock_table_helper ):
608612 mock_table = MagicMock ()
609613 mock_table .get = MagicMock (return_value = (False , None ))
@@ -614,6 +618,7 @@ def test_SfpStateUpdateTask_handle_port_change_event(self, mock_table_helper):
614618 port_mapping = PortMapping ()
615619 retry_eeprom_set = set ()
616620 task = SfpStateUpdateTask (port_mapping , retry_eeprom_set )
621+ task .xcvr_table_helper = XcvrTableHelper ()
617622 port_change_event = PortChangeEvent ('Ethernet0' , 1 , 0 , PortChangeEvent .PORT_ADD )
618623 wait_time = 5
619624 while wait_time > 0 :
@@ -650,12 +655,19 @@ def test_SfpStateUpdateTask_task_run_stop(self):
650655 task .task_stop ()
651656 assert wait_until (5 , 1 , lambda : task .task_process .is_alive () is False )
652657
653- @patch ('xcvrd.xcvrd.xcvr_table_helper ' , MagicMock ())
658+ @patch ('xcvrd.xcvrd.XcvrTableHelper ' , MagicMock ())
654659 @patch ('xcvrd.xcvrd.post_port_sfp_info_to_db' )
655660 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+
656664 port_mapping = PortMapping ()
657665 retry_eeprom_set = set ()
658666 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 )
659671 task .retry_eeprom_reading ()
660672 assert mock_post_sfp_info .call_count == 0
661673
@@ -693,7 +705,7 @@ def test_SfpStateUpdateTask_mapping_event_from_change_event(self):
693705 assert task ._mapping_event_from_change_event (True , port_dict ) == NORMAL_EVENT
694706
695707 @patch ('time.sleep' , MagicMock ())
696- @patch ('xcvrd.xcvrd.xcvr_table_helper ' , MagicMock ())
708+ @patch ('xcvrd.xcvrd.XcvrTableHelper ' , MagicMock ())
697709 @patch ('xcvrd.xcvrd._wrapper_soak_sfp_insert_event' , MagicMock ())
698710 @patch ('xcvrd.xcvrd_utilities.port_mapping.subscribe_port_config_change' , MagicMock (return_value = (None , None )))
699711 @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_
710722 port_mapping = PortMapping ()
711723 retry_eeprom_set = set ()
712724 task = SfpStateUpdateTask (port_mapping , retry_eeprom_set )
725+ task .xcvr_table_helper = XcvrTableHelper ()
713726 stop_event = multiprocessing .Event ()
714727 sfp_error_event = multiprocessing .Event ()
715728 mock_change_event .return_value = (True , {0 : 0 }, {})
@@ -792,7 +805,7 @@ def test_SfpStateUpdateTask_task_worker(self, mock_updata_status, mock_post_sfp_
792805 assert mock_updata_status .call_count == 1
793806 assert mock_del_dom .call_count == 1
794807
795- @patch ('xcvrd.xcvrd.xcvr_table_helper ' )
808+ @patch ('xcvrd.xcvrd.XcvrTableHelper ' )
796809 @patch ('xcvrd.xcvrd._wrapper_get_presence' )
797810 @patch ('xcvrd.xcvrd.notify_media_setting' )
798811 @patch ('xcvrd.xcvrd.post_port_dom_threshold_info_to_db' )
@@ -819,6 +832,10 @@ class MockTable:
819832 port_mapping = PortMapping ()
820833 retry_eeprom_set = set ()
821834 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
822839 port_change_event = PortChangeEvent ('Ethernet0' , 1 , 0 , PortChangeEvent .PORT_ADD )
823840 task .port_mapping .handle_port_change_event (port_change_event )
824841 # SFP information is in the DB, copy the SFP information for the newly added logical port
0 commit comments