From f9f2a022a222daf26dfb1ea2447e4284517ae236 Mon Sep 17 00:00:00 2001 From: Mihir Patel Date: Wed, 30 Nov 2022 00:05:45 +0000 Subject: [PATCH] Fixed test failure Signed-off-by: Mihir Patel --- sonic-xcvrd/tests/test_xcvrd.py | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/sonic-xcvrd/tests/test_xcvrd.py b/sonic-xcvrd/tests/test_xcvrd.py index 4af09bf23..df1426312 100644 --- a/sonic-xcvrd/tests/test_xcvrd.py +++ b/sonic-xcvrd/tests/test_xcvrd.py @@ -80,14 +80,25 @@ def test_post_port_dom_info_to_db(self, mock_get_sfp_type): mock_get_sfp_type.return_value = 'QSFP_DD' post_port_dom_info_to_db(logical_port_name, port_mapping, dom_tbl, stop_event) + def test_post_port_dom_threshold_info_to_db(self, mock_get_sfp_type): + logical_port_name = "Ethernet0" + port_mapping = PortMapping() + stop_event = threading.Event() + dom_threshold_tbl = Table("STATE_DB", TRANSCEIVER_DOM_THRESHOLD_TABLE) + post_port_dom_info_to_db(logical_port_name, port_mapping, dom_threshold_tbl, stop_event) + mock_get_sfp_type.return_value = 'QSFP_DD' + post_port_dom_info_to_db(logical_port_name, port_mapping, dom_threshold_tbl, stop_event) + @patch('xcvrd.xcvrd_utilities.port_mapping.PortMapping.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) @patch('xcvrd.xcvrd._wrapper_get_presence', MagicMock(return_value=True)) def test_del_port_sfp_dom_info_from_db(self): logical_port_name = "Ethernet0" port_mapping = PortMapping() dom_tbl = Table("STATE_DB", TRANSCEIVER_DOM_SENSOR_TABLE) + dom_threshold_tbl = Table("STATE_DB", TRANSCEIVER_DOM_THRESHOLD_TABLE) init_tbl = Table("STATE_DB", TRANSCEIVER_INFO_TABLE) del_port_sfp_dom_info_from_db(logical_port_name, port_mapping, init_tbl, dom_tbl) + del_port_sfp_dom_info_from_db(logical_port_name, port_mapping, init_tbl, dom_threshold_tbl) @patch('xcvrd.xcvrd_utilities.port_mapping.PortMapping.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) @patch('xcvrd.xcvrd._wrapper_get_presence', MagicMock(return_value=True)) @@ -115,8 +126,8 @@ def test_post_port_dom_threshold_info_to_db(self): logical_port_name = "Ethernet0" port_mapping = PortMapping() stop_event = threading.Event() - dom_tbl = Table("STATE_DB", TRANSCEIVER_DOM_SENSOR_TABLE) - post_port_dom_threshold_info_to_db(logical_port_name, port_mapping, dom_tbl, stop_event) + dom_threshold_tbl = Table("STATE_DB", TRANSCEIVER_DOM_THRESHOLD_TABLE) + post_port_dom_threshold_info_to_db(logical_port_name, port_mapping, dom_threshold_tbl, stop_event) @patch('xcvrd.xcvrd_utilities.port_mapping.PortMapping.logical_port_name_to_physical_port_list', MagicMock(return_value=[0])) @patch('xcvrd.xcvrd._wrapper_get_presence', MagicMock(return_value=True)) @@ -709,6 +720,7 @@ def test_SfpStateUpdateTask_handle_port_change_event(self, mock_table_helper): mock_table_helper.get_status_tbl = MagicMock(return_value=mock_table) mock_table_helper.get_int_tbl = MagicMock(return_value=mock_table) mock_table_helper.get_dom_tbl = MagicMock(return_value=mock_table) + mock_table_helper.get_dom_threshold_tbl = MagicMock(return_value=mock_table) stopping_event = multiprocessing.Event() port_mapping = PortMapping() retry_eeprom_set = set() @@ -762,6 +774,7 @@ def test_SfpStateUpdateTask_retry_eeprom_reading(self, mock_post_sfp_info): task.xcvr_table_helper = XcvrTableHelper(DEFAULT_NAMESPACE) task.xcvr_table_helper.get_intf_tbl = MagicMock(return_value=mock_table) task.xcvr_table_helper.get_dom_tbl = MagicMock(return_value=mock_table) + task.xcvr_table_helper.get_dom_threshold_tbl = MagicMock(return_value=mock_table) task.xcvr_table_helper.get_app_port_tbl = MagicMock(return_value=mock_table) task.retry_eeprom_reading() assert mock_post_sfp_info.call_count == 0 @@ -888,7 +901,7 @@ def test_SfpStateUpdateTask_task_worker(self, mock_updata_status, mock_post_sfp_ # Test state machine: handle SFP remove event task.task_worker(stop_event, sfp_error_event) assert mock_updata_status.call_count == 1 - assert mock_del_dom.call_count == 1 + assert mock_del_dom.call_count == 2 stop_event.is_set = MagicMock(side_effect=[False, True]) error = int(SFP_STATUS_INSERTED) | SfpBase.SFP_ERROR_BIT_BLOCKING | SfpBase.SFP_ERROR_BIT_POWER_BUDGET_EXCEEDED @@ -898,7 +911,7 @@ def test_SfpStateUpdateTask_task_worker(self, mock_updata_status, mock_post_sfp_ # Test state machine: handle SFP error event task.task_worker(stop_event, sfp_error_event) assert mock_updata_status.call_count == 1 - assert mock_del_dom.call_count == 1 + assert mock_del_dom.call_count == 2 @patch('xcvrd.xcvrd.XcvrTableHelper') @patch('xcvrd.xcvrd._wrapper_get_presence') @@ -920,9 +933,13 @@ class MockTable: dom_tbl = MockTable() dom_tbl.get = MagicMock(return_value=(True, (('key3', 'value3'),))) dom_tbl.set = MagicMock() + dom_threshold_tbl = MockTable() + dom_threshold_tbl.get = MagicMock(return_value=(True, (('key4', 'value4'),))) + dom_threshold_tbl.set = MagicMock() mock_table_helper.get_status_tbl = MagicMock(return_value=status_tbl) mock_table_helper.get_intf_tbl = MagicMock(return_value=int_tbl) mock_table_helper.get_dom_tbl = MagicMock(return_value=dom_tbl) + mock_table_helper.get_dom_threshold_tbl = MagicMock(return_value=dom_threshold_tbl) port_mapping = PortMapping() retry_eeprom_set = set() @@ -931,6 +948,7 @@ class MockTable: task.xcvr_table_helper.get_status_tbl = mock_table_helper.get_status_tbl task.xcvr_table_helper.get_intf_tbl = mock_table_helper.get_intf_tbl task.xcvr_table_helper.get_dom_tbl = mock_table_helper.get_dom_tbl + task.xcvr_table_helper.get_dom_threshold_tbl = mock_table_helper.get_dom_threshold_tbl port_change_event = PortChangeEvent('Ethernet0', 1, 0, PortChangeEvent.PORT_ADD) task.port_mapping.handle_port_change_event(port_change_event) # SFP information is in the DB, copy the SFP information for the newly added logical port @@ -941,6 +959,8 @@ class MockTable: int_tbl.set.assert_called_with('Ethernet0', (('key2', 'value2'),)) dom_tbl.get.assert_called_with('Ethernet0') dom_tbl.set.assert_called_with('Ethernet0', (('key3', 'value3'),)) + dom_threshold_tbl.get.assert_called_with('Ethernet0') + dom_threshold_tbl.set.assert_called_with('Ethernet0', (('key4', 'value4'),)) status_tbl.get.return_value = (False, ()) mock_get_presence.return_value = True @@ -969,7 +989,7 @@ class MockTable: assert mock_post_dom_info.call_count == 1 mock_post_dom_info.assert_called_with('Ethernet0', task.port_mapping, dom_tbl) assert mock_post_dom_th.call_count == 1 - mock_post_dom_th.assert_called_with('Ethernet0', task.port_mapping, dom_tbl) + mock_post_dom_th.assert_called_with('Ethernet0', task.port_mapping, dom_threshold_tbl) assert mock_update_media_setting.call_count == 1 assert 'Ethernet0' not in task.retry_eeprom_set