diff --git a/sonic-thermalctld/scripts/thermalctld b/sonic-thermalctld/scripts/thermalctld index ddc16b5a350b..09b573c2899d 100644 --- a/sonic-thermalctld/scripts/thermalctld +++ b/sonic-thermalctld/scripts/thermalctld @@ -561,21 +561,13 @@ class TemperatureUpdater(logger.Logger): table_keys = self.table.getKeys() for tk in table_keys: self.table._del(tk) + if self.is_chassis_system and self.chassis_table is not None: + self.chassis_table._del(tk) if self.phy_entity_table: phy_entity_keys = self.phy_entity_table.getKeys() for pek in phy_entity_keys: self.phy_entity_table._del(pek) - def deinit(self): - """ - Deinitializer of TemperatureUpdater - :return: - """ - for name in self.temperature_status_dict.keys(): - self.table._del(name) - if self.is_chassis_system and self.chassis_table is not None: - self.chassis_table._del(name) - def _log_on_status_changed(self, normal_status, normal_log, abnormal_log): """ Log when any status changed @@ -794,8 +786,6 @@ class ThermalMonitor(ProcessTaskBase): while not self.task_stopping_event.wait(self.wait_time): self.main() - self.temperature_updater.deinit() - self.logger.log_info("Stop thermal monitoring loop") diff --git a/sonic-thermalctld/tests/test_thermalctld.py b/sonic-thermalctld/tests/test_thermalctld.py index 805aaeed38a8..3c8d14c89e4a 100644 --- a/sonic-thermalctld/tests/test_thermalctld.py +++ b/sonic-thermalctld/tests/test_thermalctld.py @@ -25,6 +25,7 @@ from sonic_py_common import daemon_base from .mock_platform import MockChassis, MockFan, MockPsu, MockSfp, MockThermal +from .mock_swsscommon import Table daemon_base.db_connect = mock.MagicMock() @@ -414,13 +415,21 @@ def test_deinit(self): chassis = MockChassis() temp_updater = thermalctld.TemperatureUpdater(chassis, multiprocessing.Event()) temp_updater.temperature_status_dict = {'key1': 'value1', 'key2': 'value2'} + temp_updater.table = Table("STATE_DB", "xtable") temp_updater.table._del = mock.MagicMock() - - temp_updater.deinit() + temp_updater.table.getKeys = mock.MagicMock(return_value=['key1','key2']) + temp_updater.phy_entity_table = Table("STATE_DB", "ytable") + temp_updater.phy_entity_table._del = mock.MagicMock() + temp_updater.phy_entity_table.getKeys = mock.MagicMock(return_value=['key1','key2']) + temp_updater.chassis_table = Table("STATE_DB", "ctable") + temp_updater.chassis_table._del = mock.MagicMock() + temp_updater.is_chassis_system = True + + temp_updater.__del__() + assert temp_updater.table.getKeys.call_count == 1 assert temp_updater.table._del.call_count == 2 expected_calls = [mock.call('key1'), mock.call('key2')] temp_updater.table._del.assert_has_calls(expected_calls, any_order=True) - def test_over_temper(self): chassis = MockChassis()