Skip to content

Commit

Permalink
[thermalctld] fix some redundant removal of state DB tables (sonic-ne…
Browse files Browse the repository at this point in the history
  • Loading branch information
vdahiya12 authored Dec 9, 2022
1 parent 56046dc commit 9657a26
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
14 changes: 2 additions & 12 deletions sonic-thermalctld/scripts/thermalctld
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")


Expand Down
15 changes: 12 additions & 3 deletions sonic-thermalctld/tests/test_thermalctld.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 9657a26

Please sign in to comment.