@@ -3837,6 +3837,7 @@ def test_SfpStateUpdateTask_handle_port_change_event(self, mock_del_port_sfp_dom
38373837 mock_table_helper .get_int_tbl = MagicMock (return_value = mock_table )
38383838 mock_table_helper .get_dom_tbl = MagicMock (return_value = mock_table )
38393839 mock_table_helper .get_dom_threshold_tbl = MagicMock (return_value = mock_table )
3840+ mock_table_helper .get_state_port_tbl = MagicMock (return_value = mock_table )
38403841 stop_event = threading .Event ()
38413842 sfp_error_event = threading .Event ()
38423843 port_mapping = PortMapping ()
@@ -3846,6 +3847,7 @@ def test_SfpStateUpdateTask_handle_port_change_event(self, mock_del_port_sfp_dom
38463847 task .xcvr_table_helper .get_status_tbl = mock_table_helper .get_status_tbl
38473848 task .xcvr_table_helper .get_intf_tbl = mock_table_helper .get_intf_tbl
38483849 task .xcvr_table_helper .get_dom_tbl = mock_table_helper .get_dom_tbl
3850+ task .xcvr_table_helper .get_state_port_tbl = mock_table_helper .get_state_port_tbl
38493851 port_change_event = PortChangeEvent ('Ethernet0' , 1 , 0 , PortChangeEvent .PORT_ADD )
38503852 wait_time = 5
38513853 while wait_time > 0 :
@@ -3860,6 +3862,19 @@ def test_SfpStateUpdateTask_handle_port_change_event(self, mock_del_port_sfp_dom
38603862 assert task .port_mapping .get_logical_to_physical ('Ethernet0' ) == [1 ]
38613863 assert mock_del_port_sfp_dom_info_from_db .call_count == 0
38623864
3865+ port_change_event = PortChangeEvent ('Ethernet0' , 1 , 0 , PortChangeEvent .PORT_SET )
3866+ wait_time = 5
3867+ while wait_time > 0 :
3868+ task .on_port_config_change (port_change_event )
3869+ if task .port_mapping .logical_port_list :
3870+ break
3871+ wait_time -= 1
3872+ time .sleep (1 )
3873+ assert task .port_mapping .logical_port_list .count ('Ethernet0' )
3874+ assert task .port_mapping .get_asic_id_for_logical_port ('Ethernet0' ) == 0
3875+ assert task .port_mapping .get_physical_to_logical (1 ) == ['Ethernet0' ]
3876+ assert task .port_mapping .get_logical_to_physical ('Ethernet0' ) == [1 ]
3877+
38633878 port_change_event = PortChangeEvent ('Ethernet0' , 1 , 0 , PortChangeEvent .PORT_REMOVE )
38643879 wait_time = 5
38653880 while wait_time > 0 :
@@ -4140,6 +4155,60 @@ class MockTable:
41404155 mock_update_status .assert_called_with (
41414156 'Ethernet0' , status_sw_tbl , task .sfp_error_dict [1 ][0 ], 'Blocking EEPROM from being read|Power budget exceeded' )
41424157
4158+ @patch ('xcvrd.xcvrd.XcvrTableHelper' )
4159+ @patch ('xcvrd.xcvrd._wrapper_get_presence' )
4160+ @patch ('xcvrd.xcvrd_utilities.media_settings_parser.notify_media_setting' )
4161+ @patch ('xcvrd.xcvrd.post_port_sfp_info_to_db' )
4162+ def test_SfpStateUpdateTask_on_update_logical_port (self , mock_post_sfp_info ,
4163+ mock_update_media_setting , mock_get_presence , mock_table_helper ):
4164+ class MockTable :
4165+ pass
4166+
4167+ status_sw_tbl = MockTable ()
4168+ status_sw_tbl .get = MagicMock (return_value = (True , (('status' , SFP_STATUS_INSERTED ),)))
4169+ status_sw_tbl .set = MagicMock ()
4170+ int_tbl = MockTable ()
4171+ int_tbl .get = MagicMock (return_value = (True , (('key2' , 'value2' ),)))
4172+ int_tbl .set = MagicMock ()
4173+ state_port_tbl = MockTable ()
4174+ state_port_tbl .get = MagicMock (return_value = (True , (('key5' , 'value5' ),)))
4175+ state_port_tbl .set = MagicMock ()
4176+ mock_table_helper .get_status_sw_tbl = MagicMock (return_value = status_sw_tbl )
4177+ mock_table_helper .get_intf_tbl = MagicMock (return_value = int_tbl )
4178+ mock_table_helper .get_state_port_tbl = MagicMock (return_value = state_port_tbl )
4179+
4180+ port_mapping = PortMapping ()
4181+ mock_sfp_obj_dict = MagicMock ()
4182+ stop_event = threading .Event ()
4183+ sfp_error_event = threading .Event ()
4184+ task = SfpStateUpdateTask (DEFAULT_NAMESPACE , port_mapping , mock_sfp_obj_dict , stop_event , sfp_error_event )
4185+ task .xcvr_table_helper = XcvrTableHelper (DEFAULT_NAMESPACE )
4186+ task .xcvr_table_helper .get_status_sw_tbl = mock_table_helper .get_status_sw_tbl
4187+ task .xcvr_table_helper .get_intf_tbl = mock_table_helper .get_intf_tbl
4188+ task .xcvr_table_helper .get_state_port_tbl = mock_table_helper .get_state_port_tbl
4189+ port_change_event = PortChangeEvent ('Ethernet0' , 1 , 0 , PortChangeEvent .PORT_ADD )
4190+ task .port_mapping .handle_port_change_event (port_change_event )
4191+
4192+ status_sw_tbl .get .return_value = (False , ())
4193+ mock_get_presence .return_value = True
4194+ mock_post_sfp_info .return_value = SFP_EEPROM_NOT_READY
4195+ # SFP information is not in the DB, and SFP is present
4196+ task .on_update_logical_port (port_change_event )
4197+ assert mock_post_sfp_info .call_count == 1
4198+ mock_post_sfp_info .assert_called_with ('Ethernet0' , task .port_mapping , int_tbl , {})
4199+ assert mock_update_media_setting .call_count == 0
4200+ assert 'Ethernet0' in task .retry_eeprom_set
4201+ task .retry_eeprom_set .clear ()
4202+
4203+ mock_post_sfp_info .return_value = None
4204+ mock_post_sfp_info .reset_mock ()
4205+ # SFP information is in the DB, and SFP is present
4206+ task .on_update_logical_port (port_change_event )
4207+ assert mock_post_sfp_info .call_count == 1
4208+ mock_post_sfp_info .assert_called_with ('Ethernet0' , task .port_mapping , int_tbl , {})
4209+ assert mock_update_media_setting .call_count == 1
4210+ assert 'Ethernet0' not in task .retry_eeprom_set
4211+
41434212 def test_sfp_insert_events (self ):
41444213 from xcvrd .xcvrd import _wrapper_soak_sfp_insert_event
41454214 sfp_insert_events = {}
0 commit comments