diff --git a/sonic-thermalctld/scripts/thermalctld b/sonic-thermalctld/scripts/thermalctld index b98cd5c4a2cd..bc25923dbf12 100644 --- a/sonic-thermalctld/scripts/thermalctld +++ b/sonic-thermalctld/scripts/thermalctld @@ -774,6 +774,8 @@ class ThermalControlDaemon(daemon_base.DaemonBase): self.thermal_manager.initialize() self.thermal_manager.load(ThermalControlDaemon.POLICY_FILE) self.thermal_manager.init_thermal_algorithm(self.chassis) + # Use thermal manager interval if it's available + self.wait_time = self.thermal_manager.get_interval() except NotImplementedError: self.log_warning('Thermal manager is not supported on this platform') except Exception as e: @@ -832,9 +834,10 @@ class ThermalControlDaemon(daemon_base.DaemonBase): except Exception as e: self.log_error('Caught exception while running thermal policy - {}'.format(repr(e))) + interval = self.thermal_manager.get_interval() if self.thermal_manager else self.INTERVAL elapsed = time.time() - begin - if elapsed < self.INTERVAL: - self.wait_time = self.INTERVAL - elapsed + if elapsed < interval: + self.wait_time = interval - elapsed else: self.wait_time = self.FAST_START_INTERVAL diff --git a/sonic-thermalctld/tests/test_thermalctld.py b/sonic-thermalctld/tests/test_thermalctld.py index 063e11c22387..9555b4c7ad64 100644 --- a/sonic-thermalctld/tests/test_thermalctld.py +++ b/sonic-thermalctld/tests/test_thermalctld.py @@ -651,12 +651,14 @@ def test_signal_handler(): def test_daemon_run(): daemon_thermalctld = thermalctld.ThermalControlDaemon() daemon_thermalctld.stop_event.wait = mock.MagicMock(return_value=True) + daemon_thermalctld.thermal_manager.get_interval = mock.MagicMock(return_value=60) ret = daemon_thermalctld.run() daemon_thermalctld.deinit() # Deinit becuase the test will hang if we assert assert ret is False daemon_thermalctld = thermalctld.ThermalControlDaemon() daemon_thermalctld.stop_event.wait = mock.MagicMock(return_value=False) + daemon_thermalctld.thermal_manager.get_interval = mock.MagicMock(return_value=60) ret = daemon_thermalctld.run() daemon_thermalctld.deinit() # Deinit becuase the test will hang if we assert assert ret is True