Skip to content

Commit

Permalink
[psud][thermalctld] Always get fan/PSU LED status from platform API t…
Browse files Browse the repository at this point in the history
…o avoid status inconsistencies (sonic-net#59)

- psud will change PSU led and thermalctld cannot detect the led status change, so it would be better to always get PSU led from platform API
- there might be delay between set led color and it take effect
  • Loading branch information
Junchao-Mellanox authored Jun 9, 2020
1 parent 0f4fd83 commit c617191
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 33 deletions.
27 changes: 11 additions & 16 deletions sonic-psud/scripts/psud
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ def log_on_status_changed(normal_status, normal_log, abnormal_log):
#

class PsuStatus(object):
update_led_color = True

def __init__(self, psu):
self.psu = psu
self.presence = True
Expand Down Expand Up @@ -325,7 +323,6 @@ class DaemonPsud(DaemonBase):
)

if set_led:
PsuStatus.update_led_color = True
self._set_psu_led(psu, psu_status)

def _set_psu_led(self, psu, psu_status):
Expand All @@ -339,19 +336,17 @@ class DaemonPsud(DaemonBase):
if not platform_chassis:
return

if PsuStatus.update_led_color:
for index, psu_status in self.psu_status_dict.items():
try:
fvs = swsscommon.FieldValuePairs([
('led_status', str(try_get(psu_status.psu.get_status_led)))
])
except Exception as e:
logger.log_warning('Failed to get led status for psu {}'.format(index))
fvs = swsscommon.FieldValuePairs([
('led_status', NOT_AVAILABLE)
])
psu_tbl.set(PSU_INFO_KEY_TEMPLATE.format(index), fvs)
PsuStatus.update_led_color = False
for index, psu_status in self.psu_status_dict.items():
try:
fvs = swsscommon.FieldValuePairs([
('led_status', str(try_get(psu_status.psu.get_status_led)))
])
except Exception as e:
logger.log_warning('Failed to get led status for psu {}'.format(index))
fvs = swsscommon.FieldValuePairs([
('led_status', NOT_AVAILABLE)
])
psu_tbl.set(PSU_INFO_KEY_TEMPLATE.format(index), fvs)
#
# Main =========================================================================
#
Expand Down
31 changes: 14 additions & 17 deletions sonic-thermalctld/scripts/thermalctld
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def log_on_status_changed(normal_status, normal_log, abnormal_log):
class FanStatus(object):
absence_fan_count = 0
fault_fan_count = 0
update_led_color = True

def __init__(self, fan=None, is_psu_fan=False):
"""
Expand Down Expand Up @@ -310,9 +309,9 @@ class FanUpdater(object):
# TODO: handle invalid fan direction

# We don't set PSU led here, PSU led will be handled in psud
if set_led and not is_psu_fan:
self._set_fan_led(fan_drawer, fan, fan_name, fan_status)
FanStatus.update_led_color = True
if set_led:
if not is_psu_fan:
self._set_fan_led(fan_drawer, fan, fan_name, fan_status)

fvs = swsscommon.FieldValuePairs(
[('presence', str(presence)),
Expand Down Expand Up @@ -351,19 +350,17 @@ class FanUpdater(object):
logger.log_warning('Failed to set led to fan, set_status_led not implemented')

def _update_led_color(self):
if FanStatus.update_led_color:
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:
logger.log_warning('Failed to get led status for fan')
fvs = swsscommon.FieldValuePairs([
('led_status', NOT_AVAILABLE)
])
self.table.set(fan_name, fvs)
FanStatus.update_led_color = False
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:
logger.log_warning('Failed to get led status for fan')
fvs = swsscommon.FieldValuePairs([
('led_status', NOT_AVAILABLE)
])
self.table.set(fan_name, fvs)


class TemperatureStatus(object):
Expand Down

0 comments on commit c617191

Please sign in to comment.