-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[Mellanox] Backporting reboot cause to 201811 #3198
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b4a27e5
backport new platform api to 201811, reboot cause part
4aeefb1
install new platform api on host
30fbcf8
1. remove chassis's dependency on sonic_platform_daemon.
5642953
1. add dependency of sonic_platform for base image
02adccc
adjust log message.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # SONIC_PLATFORM_API_PY2 package | ||
|
|
||
| SONIC_PLATFORM_API_PY2 = mlnx_platform_api-1.0-py2-none-any.whl | ||
| $(SONIC_PLATFORM_API_PY2)_SRC_PATH = $(PLATFORM_PATH)/mlnx-platform-api | ||
| $(SONIC_PLATFORM_API_PY2)_PYTHON_VERSION = 2 | ||
| SONIC_PYTHON_WHEELS += $(SONIC_PLATFORM_API_PY2) | ||
|
|
||
| export mlnx_platform_api_py2_wheel_path="$(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_PLATFORM_API_PY2))" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| from setuptools import setup | ||
|
|
||
| setup( | ||
| name='mlnx-platform-api', | ||
| version='1.0', | ||
| description='SONiC platform API implementation on Mellanox platform', | ||
| license='Apache 2.0', | ||
| author='SONiC Team', | ||
| author_email='[email protected]', | ||
| url='https://github.com/Azure/sonic-buildimage', | ||
| maintainer='Kevin Wang', | ||
| maintainer_email='[email protected]', | ||
| packages=[ | ||
| 'sonic_platform', | ||
| ], | ||
| classifiers=[ | ||
| 'Development Status :: 3 - Alpha', | ||
| 'Environment :: Plugins', | ||
| 'Intended Audience :: Developers', | ||
| 'Intended Audience :: Information Technology', | ||
| 'Intended Audience :: System Administrators', | ||
| 'License :: OSI Approved :: Apache Software License', | ||
| 'Natural Language :: English', | ||
| 'Operating System :: POSIX :: Linux', | ||
| 'Programming Language :: Python :: 2.7', | ||
| 'Topic :: Utilities', | ||
| ], | ||
| keywords='sonic SONiC platform PLATFORM', | ||
| ) | ||
|
|
Empty file.
110 changes: 110 additions & 0 deletions
110
platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| #!/usr/bin/env python | ||
|
|
||
| ############################################################################# | ||
| # Mellanox | ||
| # | ||
| # Module contains an implementation of SONiC Platform Base API and | ||
| # provides the Chassis information which are available in the platform | ||
| # | ||
| ############################################################################# | ||
|
|
||
| import sys | ||
|
|
||
| try: | ||
| from sonic_platform_base.chassis_base import ChassisBase | ||
| from os.path import join | ||
| import io | ||
| import re | ||
| import subprocess | ||
| import syslog | ||
| except ImportError as e: | ||
| raise ImportError (str(e) + "- required module not found") | ||
|
|
||
| HWMGMT_SYSTEM_ROOT = '/var/run/hw-management/system/' | ||
|
|
||
| #reboot cause related definitions | ||
| REBOOT_CAUSE_ROOT = HWMGMT_SYSTEM_ROOT | ||
|
|
||
| REBOOT_CAUSE_POWER_LOSS_FILE = 'reset_main_pwr_fail' | ||
| REBOOT_CAUSE_AUX_POWER_LOSS_FILE = 'reset_aux_pwr_or_ref' | ||
| REBOOT_CAUSE_THERMAL_OVERLOAD_ASIC_FILE = 'reset_asic_thermal' | ||
| REBOOT_CAUSE_WATCHDOG_FILE = 'reset_hotswap_or_wd' | ||
| REBOOT_CAUSE_MLNX_FIRMWARE_RESET = 'reset_fw_reset' | ||
| REBOOT_CAUSE_LONG_PB = 'reset_long_pb' | ||
| REBOOT_CAUSE_SHORT_PB = 'reset_short_pb' | ||
|
|
||
| REBOOT_CAUSE_FILE_LENGTH = 1 | ||
|
|
||
| # ========================== Syslog wrappers ========================== | ||
| SYSLOG_IDENTIFIER = "mlnx-chassis" | ||
| def log_warning(msg, also_print_to_console=False): | ||
| syslog.openlog(SYSLOG_IDENTIFIER) | ||
| syslog.syslog(syslog.LOG_WARNING, msg) | ||
| syslog.closelog() | ||
|
|
||
|
|
||
| class Chassis(ChassisBase): | ||
| """Platform-specific Chassis class""" | ||
|
|
||
| def __init__(self): | ||
| super(Chassis, self).__init__() | ||
|
|
||
| def _read_generic_file(self, filename, len): | ||
| """ | ||
| Read a generic file, returns the contents of the file | ||
| """ | ||
| result = '' | ||
| try: | ||
| fileobj = io.open(filename) | ||
| result = fileobj.read(len) | ||
| fileobj.close() | ||
| return result | ||
| except Exception as e: | ||
| log_warning("Fail to read file {} due to {}".format(filename, repr(e))) | ||
| return '' | ||
|
|
||
| def _verify_reboot_cause(self, filename): | ||
| ''' | ||
| Open and read the reboot cause file in | ||
| /var/run/hwmanagement/system (which is defined as REBOOT_CAUSE_ROOT) | ||
| If a reboot cause file doesn't exists, returns '0'. | ||
| ''' | ||
| try: | ||
| return bool(int(self._read_generic_file(join(REBOOT_CAUSE_ROOT, filename), REBOOT_CAUSE_FILE_LENGTH).rstrip('\n'))) | ||
| except: | ||
| return False | ||
|
|
||
| def get_reboot_cause(self): | ||
| """ | ||
| Retrieves the cause of the previous reboot | ||
|
|
||
| Returns: | ||
| A tuple (string, string) where the first element is a string | ||
| containing the cause of the previous reboot. This string must be | ||
| one of the predefined strings in this class. If the first string | ||
| is "REBOOT_CAUSE_HARDWARE_OTHER", the second string can be used | ||
| to pass a description of the reboot cause. | ||
| """ | ||
| #read reboot causes files in the following order | ||
| minor_cause = '' | ||
| if self._verify_reboot_cause(REBOOT_CAUSE_POWER_LOSS_FILE): | ||
| major_cause = self.REBOOT_CAUSE_POWER_LOSS | ||
| elif self._verify_reboot_cause(REBOOT_CAUSE_AUX_POWER_LOSS_FILE): | ||
| major_cause = self.REBOOT_CAUSE_POWER_LOSS | ||
| elif self._verify_reboot_cause(REBOOT_CAUSE_THERMAL_OVERLOAD_ASIC_FILE): | ||
| major_cause = self.REBOOT_CAUSE_THERMAL_OVERLOAD_ASIC | ||
| elif self._verify_reboot_cause(REBOOT_CAUSE_WATCHDOG_FILE): | ||
| major_cause = self.REBOOT_CAUSE_WATCHDOG | ||
| else: | ||
| major_cause = self.REBOOT_CAUSE_HARDWARE_OTHER | ||
| if self._verify_reboot_cause(REBOOT_CAUSE_MLNX_FIRMWARE_RESET): | ||
| minor_cause = "Reset by ASIC firmware" | ||
| elif self._verify_reboot_cause(REBOOT_CAUSE_LONG_PB): | ||
| minor_cause = "Reset by long press on power button" | ||
| elif self._verify_reboot_cause(REBOOT_CAUSE_SHORT_PB): | ||
| minor_cause = "Reset by short press on power button" | ||
| else: | ||
| major_cause = self.REBOOT_CAUSE_NON_HARDWARE | ||
|
|
||
| return major_cause, minor_cause | ||
|
|
19 changes: 19 additions & 0 deletions
19
platform/mellanox/mlnx-platform-api/sonic_platform/platform.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| #!/usr/bin/env python | ||
|
|
||
| ############################################################################# | ||
| # Mellanox | ||
| # | ||
| # implementation of new platform api | ||
| ############################################################################# | ||
|
|
||
| try: | ||
| from sonic_platform_base.platform_base import PlatformBase | ||
| from sonic_platform.chassis import Chassis | ||
| except ImportError as e: | ||
| raise ImportError(str(e) + "- required module not found") | ||
|
|
||
|
|
||
| class Platform(PlatformBase): | ||
| def __init__(self): | ||
| PlatformBase.__init__(self) | ||
| self._chassis = Chassis() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.