[Mellanox] enhance the reboot cause handling on 201811 (#3253)

* [Mellanox/mlnx-platform-api] enable mellanox's platform-api to be loaded as a whole.

* [chassis] update reboot-cause handling code to adapt the hw-management currently running on 201811

* [chassis]handle the case that reboot cause file can be any dir matching pattern "hwmonX".
This commit is contained in:
Stephen Sun 2019-08-03 00:58:53 +08:00 committed by Joe LeVeque
parent c07c48218b
commit ca38147744
2 changed files with 28 additions and 2 deletions

View File

@ -0,0 +1,2 @@
__all__ = ["platform", "chassis"]
from sonic_platform import *

View File

@ -13,6 +13,8 @@ import sys
try:
from sonic_platform_base.chassis_base import ChassisBase
from os.path import join
from glob import glob
import os
import io
import re
import subprocess
@ -20,10 +22,13 @@ try:
except ImportError as e:
raise ImportError (str(e) + "- required module not found")
# The default dir for reboot cause files
HWMGMT_SYSTEM_ROOT = '/var/run/hw-management/system/'
# The hwmon root dir used in case of the hw-mgmt v1.x.x is used.
HWMON_ROOT_PATTERN = '/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*'
#reboot cause related definitions
REBOOT_CAUSE_ROOT = HWMGMT_SYSTEM_ROOT
REBOOT_CAUSE_ROOT = None
REBOOT_CAUSE_POWER_LOSS_FILE = 'reset_main_pwr_fail'
REBOOT_CAUSE_AUX_POWER_LOSS_FILE = 'reset_aux_pwr_or_ref'
@ -37,18 +42,37 @@ REBOOT_CAUSE_FILE_LENGTH = 1
# ========================== Syslog wrappers ==========================
SYSLOG_IDENTIFIER = "mlnx-chassis"
def log_warning(msg, also_print_to_console=False):
def log_warning(msg):
syslog.openlog(SYSLOG_IDENTIFIER)
syslog.syslog(syslog.LOG_WARNING, msg)
syslog.closelog()
def log_info(msg):
syslog.openlog(SYSLOG_IDENTIFIER)
syslog.syslog(syslog.LOG_INFO, msg)
syslog.closelog()
class Chassis(ChassisBase):
"""Platform-specific Chassis class"""
def __init__(self):
global REBOOT_CAUSE_ROOT
super(Chassis, self).__init__()
# adaptively reboot cause root dir initialization
REBOOT_CAUSE_ROOT = HWMGMT_SYSTEM_ROOT
if not os.path.exists(REBOOT_CAUSE_ROOT):
log_warning("reboot cause dir {} doesn't exist, trying other alternatives".format(REBOOT_CAUSE_ROOT))
possible_reboot_cause_dir_list = glob(HWMON_ROOT_PATTERN)
if possible_reboot_cause_dir_list is None or len(possible_reboot_cause_dir_list) == 0:
log_warning("can't find reboot cause files in {}".format(HWMON_ROOT_PATTERN))
else:
REBOOT_CAUSE_ROOT = possible_reboot_cause_dir_list[0]
if len(possible_reboot_cause_dir_list) > 1:
log_warning("found multiple reboot cause dir {}, pick the first one".format(possible_reboot_cause_dir_list))
else:
log_info("pick {} as reboot cause file".format(REBOOT_CAUSE_ROOT))
def _read_generic_file(self, filename, len):
"""
Read a generic file, returns the contents of the file