From f63fc94b699fb5f7f9c6628d49900dd0ac721781 Mon Sep 17 00:00:00 2001 From: andywongarista <78833093+andywongarista@users.noreply.github.com> Date: Thu, 5 Aug 2021 22:01:44 -0700 Subject: [PATCH] [thermalctld] Use interval set in thermal policy if available (#164) Description Update thermalctld to retrieve interval from thermal manager (which in turn loads an interval from thermal_policy.json) instead of using a constant. Motivation and Context Azure/sonic-platform-common#178 This will allow platform vendors to specify an alternate interval for running thermal policies, e.g. 15 seconds instead of the current 60. How Has This Been Tested? Verified that thermalctld runs without exiting. Also ran test_thermalctld.py --- sonic-thermalctld/scripts/thermalctld | 7 +++++-- sonic-thermalctld/tests/test_thermalctld.py | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/sonic-thermalctld/scripts/thermalctld b/sonic-thermalctld/scripts/thermalctld index b98cd5c4a..bc25923db 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 063e11c22..9555b4c7a 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