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

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

Merged
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__all__ = ["platform", "chassis"]
from sonic_platform import *
28 changes: 26 additions & 2 deletions platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,22 @@
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
import syslog
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'
Expand All @@ -37,18 +42,37 @@

# ========================== 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
Expand Down