Skip to content

Commit 8bad10a

Browse files
authored
Clear all data from DB table when the daemon stops (#228)
Description Clear all data from DB table when the daemon stops Motivation and Context Clean up when the daemon stops How Has This Been Tested? Check Thermal and physical info data if they are cleared after stopping the thermalctld.
1 parent da3dbcc commit 8bad10a

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

sonic-thermalctld/scripts/thermalctld

+23-8
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,19 @@ class FanUpdater(logger.Logger):
206206
self.drawer_table = swsscommon.Table(state_db, FanUpdater.FAN_DRAWER_INFO_TABLE_NAME)
207207
self.phy_entity_table = swsscommon.Table(state_db, PHYSICAL_ENTITY_INFO_TABLE)
208208

209-
def deinit(self):
210-
"""
211-
Deinitializer of FanUpdater
212-
:return:
213-
"""
214-
for name in self.fan_status_dict.keys():
215-
self.table._del(name)
209+
def __del__(self):
210+
if self.table:
211+
table_keys = self.table.getKeys()
212+
for tk in table_keys:
213+
self.table._del(tk)
214+
if self.drawer_table:
215+
drawer_keys = self.drawer_table.getKeys()
216+
for dtk in drawer_keys:
217+
self.drawer_table._del(dtk)
218+
if self.phy_entity_table:
219+
phy_entity_keys = self.phy_entity_table.getKeys()
220+
for pek in phy_entity_keys:
221+
self.phy_entity_table._del(pek)
216222

217223
def _log_on_status_changed(self, normal_status, normal_log, abnormal_log):
218224
"""
@@ -550,6 +556,16 @@ class TemperatureUpdater(logger.Logger):
550556
except Exception as e:
551557
self.chassis_table = None
552558

559+
def __del__(self):
560+
if self.table:
561+
table_keys = self.table.getKeys()
562+
for tk in table_keys:
563+
self.table._del(tk)
564+
if self.phy_entity_table:
565+
phy_entity_keys = self.phy_entity_table.getKeys()
566+
for pek in phy_entity_keys:
567+
self.phy_entity_table._del(pek)
568+
553569
def deinit(self):
554570
"""
555571
Deinitializer of TemperatureUpdater
@@ -778,7 +794,6 @@ class ThermalMonitor(ProcessTaskBase):
778794
while not self.task_stopping_event.wait(self.wait_time):
779795
self.main()
780796

781-
self.fan_updater.deinit()
782797
self.temperature_updater.deinit()
783798

784799
self.logger.log_info("Stop thermal monitoring loop")

sonic-thermalctld/tests/test_thermalctld.py

-10
Original file line numberDiff line numberDiff line change
@@ -154,16 +154,6 @@ class TestFanUpdater(object):
154154
"""
155155
Test cases to cover functionality in FanUpdater class
156156
"""
157-
def test_deinit(self):
158-
fan_updater = thermalctld.FanUpdater(MockChassis(), multiprocessing.Event())
159-
fan_updater.fan_status_dict = {'key1': 'value1', 'key2': 'value2'}
160-
fan_updater.table._del = mock.MagicMock()
161-
162-
fan_updater.deinit()
163-
assert fan_updater.table._del.call_count == 2
164-
expected_calls = [mock.call('key1'), mock.call('key2')]
165-
fan_updater.table._del.assert_has_calls(expected_calls, any_order=True)
166-
167157
@mock.patch('thermalctld.try_get', mock.MagicMock(return_value=thermalctld.NOT_AVAILABLE))
168158
@mock.patch('thermalctld.update_entity_info', mock.MagicMock())
169159
def test_refresh_fan_drawer_status_fan_drawer_get_name_not_impl(self):

0 commit comments

Comments
 (0)