Skip to content

Commit

Permalink
[psud] Store PSU temperature and voltage information to database (zhe…
Browse files Browse the repository at this point in the history
…nggen-xu#61)

System health feature requires PSU temperature and voltage information, need store them to database for host side use.
  • Loading branch information
Junchao-Mellanox authored Jul 6, 2020
1 parent 9b8bfa1 commit ef9716a
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions sonic-psud/scripts/psud
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ PSU_INFO_TABLE = 'PSU_INFO'
PSU_INFO_KEY_TEMPLATE = 'PSU {}'
PSU_INFO_PRESENCE_FIELD = 'presence'
PSU_INFO_STATUS_FIELD = 'status'
PSU_INFO_TEMP_FIELD = 'temp'
PSU_INFO_TEMP_TH_FIELD = 'temp_threshold'
PSU_INFO_VOLTAGE_FIELD = 'voltage'
PSU_INFO_VOLTAGE_MAX_TH_FIELD = 'voltage_max_threshold'
PSU_INFO_VOLTAGE_MIN_TH_FIELD = 'voltage_min_threshold'

PSU_INFO_UPDATE_PERIOD_SECS = 3

Expand Down Expand Up @@ -247,7 +252,7 @@ class DaemonPsud(DaemonBase):

while not self.stop.wait(PSU_INFO_UPDATE_PERIOD_SECS):
psu_db_update(psu_tbl, psu_num)
self.update_psu_data()
self.update_psu_data(psu_tbl)
self._update_led_color(psu_tbl)

logger.log_info("Stop daemon main loop")
Expand All @@ -260,17 +265,17 @@ class DaemonPsud(DaemonBase):

logger.log_info("Shutting down...")

def update_psu_data(self):
def update_psu_data(self, psu_tbl):
if not platform_chassis:
return

for index, psu in enumerate(platform_chassis.get_all_psus()):
try:
self._update_single_psu_data(index + 1, psu)
self._update_single_psu_data(index + 1, psu, psu_tbl)
except Exception as e:
logger.log_warning("Failed to update PSU data - {}".format(e))

def _update_single_psu_data(self, index, psu):
def _update_single_psu_data(self, index, psu, psu_tbl):
name = try_get(psu.get_name)
if not name:
name = PSU_INFO_KEY_TEMPLATE.format(index)
Expand Down Expand Up @@ -325,6 +330,16 @@ class DaemonPsud(DaemonBase):
if set_led:
self._set_psu_led(psu, psu_status)

fvs = swsscommon.FieldValuePairs(
[(PSU_INFO_TEMP_FIELD, str(temperature)),
(PSU_INFO_TEMP_TH_FIELD, str(temperature_threshold)),
(PSU_INFO_VOLTAGE_FIELD, str(voltage)),
(PSU_INFO_VOLTAGE_MIN_TH_FIELD, str(voltage_low_threshold)),
(PSU_INFO_VOLTAGE_MAX_TH_FIELD, str(voltage_high_threshold)),
])
psu_tbl.set(PSU_INFO_KEY_TEMPLATE.format(index), fvs)


def _set_psu_led(self, psu, psu_status):
try:
color = psu.STATUS_LED_COLOR_GREEN if psu_status.is_ok() else psu.STATUS_LED_COLOR_RED
Expand Down

0 comments on commit ef9716a

Please sign in to comment.