Skip to content

Commit ca38147

Browse files
stephenxsjleveque
authored andcommitted
[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".
1 parent c07c482 commit ca38147

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
__all__ = ["platform", "chassis"]
2+
from sonic_platform import *

platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py

+26-2
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,22 @@
1313
try:
1414
from sonic_platform_base.chassis_base import ChassisBase
1515
from os.path import join
16+
from glob import glob
17+
import os
1618
import io
1719
import re
1820
import subprocess
1921
import syslog
2022
except ImportError as e:
2123
raise ImportError (str(e) + "- required module not found")
2224

25+
# The default dir for reboot cause files
2326
HWMGMT_SYSTEM_ROOT = '/var/run/hw-management/system/'
27+
# The hwmon root dir used in case of the hw-mgmt v1.x.x is used.
28+
HWMON_ROOT_PATTERN = '/sys/devices/platform/mlxplat/mlxreg-io/hwmon/hwmon*'
2429

2530
#reboot cause related definitions
26-
REBOOT_CAUSE_ROOT = HWMGMT_SYSTEM_ROOT
31+
REBOOT_CAUSE_ROOT = None
2732

2833
REBOOT_CAUSE_POWER_LOSS_FILE = 'reset_main_pwr_fail'
2934
REBOOT_CAUSE_AUX_POWER_LOSS_FILE = 'reset_aux_pwr_or_ref'
@@ -37,18 +42,37 @@
3742

3843
# ========================== Syslog wrappers ==========================
3944
SYSLOG_IDENTIFIER = "mlnx-chassis"
40-
def log_warning(msg, also_print_to_console=False):
45+
def log_warning(msg):
4146
syslog.openlog(SYSLOG_IDENTIFIER)
4247
syslog.syslog(syslog.LOG_WARNING, msg)
4348
syslog.closelog()
4449

50+
def log_info(msg):
51+
syslog.openlog(SYSLOG_IDENTIFIER)
52+
syslog.syslog(syslog.LOG_INFO, msg)
53+
syslog.closelog()
4554

4655
class Chassis(ChassisBase):
4756
"""Platform-specific Chassis class"""
4857

4958
def __init__(self):
59+
global REBOOT_CAUSE_ROOT
5060
super(Chassis, self).__init__()
5161

62+
# adaptively reboot cause root dir initialization
63+
REBOOT_CAUSE_ROOT = HWMGMT_SYSTEM_ROOT
64+
if not os.path.exists(REBOOT_CAUSE_ROOT):
65+
log_warning("reboot cause dir {} doesn't exist, trying other alternatives".format(REBOOT_CAUSE_ROOT))
66+
possible_reboot_cause_dir_list = glob(HWMON_ROOT_PATTERN)
67+
if possible_reboot_cause_dir_list is None or len(possible_reboot_cause_dir_list) == 0:
68+
log_warning("can't find reboot cause files in {}".format(HWMON_ROOT_PATTERN))
69+
else:
70+
REBOOT_CAUSE_ROOT = possible_reboot_cause_dir_list[0]
71+
if len(possible_reboot_cause_dir_list) > 1:
72+
log_warning("found multiple reboot cause dir {}, pick the first one".format(possible_reboot_cause_dir_list))
73+
else:
74+
log_info("pick {} as reboot cause file".format(REBOOT_CAUSE_ROOT))
75+
5276
def _read_generic_file(self, filename, len):
5377
"""
5478
Read a generic file, returns the contents of the file

0 commit comments

Comments
 (0)