Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[thermalctld][201911] Set led status after updating all other fan status #126

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 38 additions & 3 deletions sonic-thermalctld/scripts/thermalctld
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ class FanStatus(logger.Logger):
absence_fan_count = 0
fault_fan_count = 0

def __init__(self, log_identifier):
def __init__(self, log_identifier, fan=None):
"""
Constructor of FanStatus
"""
super(FanStatus, self).__init__(log_identifier)

self.fan = fan
self.presence = True
self.status = True
self.under_speed = False
self.over_speed = False
self.invalid_direction = False
Expand All @@ -71,6 +73,18 @@ class FanStatus(logger.Logger):
self.presence = presence
return True

def set_fault_status(self, status):
"""
Set and cache Fan fault status
:param status: Fan fault status, False indicate Fault
:return: True if status changed else False
"""
if status == self.status:
return False

self.status = status
return True

def _check_speed_value_available(self, speed, target_speed, tolerance, current_status):
if speed == NOT_AVAILABLE or target_speed == NOT_AVAILABLE or tolerance == NOT_AVAILABLE:
if tolerance > 100 or tolerance < 0:
Expand Down Expand Up @@ -128,7 +142,7 @@ class FanStatus(logger.Logger):
Indicate the Fan works as expect
:return: True if Fan works normal else False
"""
return self.presence and not self.under_speed and not self.over_speed and not self.invalid_direction
return self.presence and self.status and not self.under_speed and not self.over_speed and not self.invalid_direction


#
Expand Down Expand Up @@ -191,6 +205,7 @@ class FanUpdater(logger.Logger):
except Exception as e:
self.log_warning('Failed to update PSU FAN status - {}'.format(repr(e)))

self._update_led_color()
self.log_debug("End fan updating")

def _refresh_fan_status(self, fan, index, name_prefix='FAN'):
Expand All @@ -203,7 +218,7 @@ class FanUpdater(logger.Logger):
"""
fan_name = try_get(fan.get_name, '{} {}'.format(name_prefix, index + 1))
if fan_name not in self.fan_status_dict:
self.fan_status_dict[fan_name] = FanStatus(SYSLOG_IDENTIFIER)
self.fan_status_dict[fan_name] = FanStatus(SYSLOG_IDENTIFIER, fan)

fan_status = self.fan_status_dict[fan_name]

Expand All @@ -229,6 +244,13 @@ class FanUpdater(logger.Logger):
'the system, potential overheat hazard'.format(fan_name)
)

if presence and fan_status.set_fault_status(fan_fault_status):
set_led = True
self._log_on_status_changed(fan_status.status,
'Fan fault warning cleared: {} is back to normal.'.format(fan_name),
'Fan fault warning: {} is broken.'.format(fan_name)
)

if presence and fan_status.set_under_speed(speed, speed_target, speed_tolerance):
set_led = True
self._log_on_status_changed(not fan_status.under_speed,
Expand Down Expand Up @@ -286,6 +308,19 @@ class FanUpdater(logger.Logger):
except NotImplementedError as e:
self.log_warning('Failed to set led to fan, set_status_led not implemented')

def _update_led_color(self):
for fan_name, fan_status in self.fan_status_dict.items():
try:
fvs = swsscommon.FieldValuePairs([
('led_status', str(try_get(fan_status.fan.get_status_led)))
])
except Exception as e:
self.log_warning('Failed to get led status for fan - {}'.format(repr(e)))
fvs = swsscommon.FieldValuePairs([
('led_status', NOT_AVAILABLE)
])
self.table.set(fan_name, fvs)


class TemperatureStatus(logger.Logger):
TEMPERATURE_DIFF_THRESHOLD = 10
Expand Down