Skip to content

Commit cfa600f

Browse files
[thermalctld] Initialize fan led in thermalctld for the first run (sonic-net#167)
Initialize fan led in thermalcltd for the first run. Add a flag "led_initialized" in FanStatus and set it as False on __init__ function. FanUpdater will use this flag to determine if fan led should be set even if no fan event detected.
1 parent 8509f43 commit cfa600f

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

sonic-thermalctld/scripts/thermalctld

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class FanStatus(logger.Logger):
7979
self.under_speed = False
8080
self.over_speed = False
8181
self.invalid_direction = False
82+
self.led_initialized = False
8283

8384
@classmethod
8485
def get_bad_fan_count(cls):
@@ -315,7 +316,7 @@ class FanUpdater(logger.Logger):
315316
fan_fault_status = try_get(fan.get_status, False)
316317
fan_direction = try_get(fan.get_direction)
317318

318-
set_led = False
319+
set_led = not fan_status.led_initialized
319320
if fan_status.set_presence(presence):
320321
set_led = True
321322
self._log_on_status_changed(fan_status.presence,
@@ -383,16 +384,16 @@ class FanUpdater(logger.Logger):
383384
:return:
384385
"""
385386
try:
386-
if fan_status.is_ok():
387-
fan.set_status_led(fan.STATUS_LED_COLOR_GREEN)
388-
fan_drawer.set_status_led(fan.STATUS_LED_COLOR_GREEN)
389-
else:
390-
# TODO: wait for Kebo to define the mapping of fan status to led color,
391-
# just set it to red so far
392-
fan.set_status_led(fan.STATUS_LED_COLOR_RED)
393-
fan_drawer.set_status_led(fan.STATUS_LED_COLOR_RED)
387+
led_color = fan.STATUS_LED_COLOR_GREEN if fan_status.is_ok() else fan.STATUS_LED_COLOR_RED
388+
fan.set_status_led(led_color)
389+
fan_drawer.set_status_led(led_color)
394390
except NotImplementedError as e:
395391
self.log_warning('Failed to set status LED for fan {}, set_status_led not implemented'.format(fan_name))
392+
393+
# Set led_initialized to True even if there is NotImplementedError as it is not neccessary to
394+
# print the warning log again and again. But if there is other exception, we could not
395+
# reach this line, and it will retry setting led color in the next run.
396+
fan_status.led_initialized = True
396397

397398
def _update_led_color(self):
398399
for fan_name, fan_status in self.fan_status_dict.items():

0 commit comments

Comments
 (0)