-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[platform/cel]: Backport reboot cause API to 201811 branch (#4619)
Add reboot cause API to support process-reboot-cause.service Implement chassis.get_reboot_cause platform API
- Loading branch information
Wirut Getbamrung
committed
May 26, 2020
1 parent
236707a
commit 9f8d691
Showing
9 changed files
with
257 additions
and
0 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
device/celestica/x86_64-cel_seastone-r0/sonic_platform/__init__.py
This file contains 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,2 @@ | ||
import chassis | ||
import platform |
71 changes: 71 additions & 0 deletions
71
device/celestica/x86_64-cel_seastone-r0/sonic_platform/chassis.py
This file contains 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,71 @@ | ||
#!/usr/bin/env python | ||
|
||
############################################################################# | ||
# Celestica | ||
# | ||
# Module contains an implementation of SONiC Platform Base API and | ||
# provides the Chassis information which are available in the platform | ||
# | ||
############################################################################# | ||
|
||
try: | ||
import subprocess | ||
from sonic_platform_base.chassis_base import ChassisBase | ||
except ImportError as e: | ||
raise ImportError(str(e) + "- required module not found") | ||
|
||
RESET_REGISTER = "0x103" | ||
GETREG_PATH = "/sys/devices/platform/dx010_cpld/getreg" | ||
HOST_REBOOT_CAUSE_PATH = "/host/reboot-cause/" | ||
REBOOT_CAUSE_FILE = "reboot-cause.txt" | ||
|
||
|
||
class Chassis(ChassisBase): | ||
"""Platform-specific Chassis class""" | ||
|
||
def __init__(self): | ||
ChassisBase.__init__(self) | ||
|
||
def __get_register_value(self, register): | ||
# Retrieves the cpld register value | ||
cmd = "echo {1} > {0}; cat {0}".format(GETREG_PATH, register) | ||
p = subprocess.Popen( | ||
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
raw_data, err = p.communicate() | ||
if err is not '': | ||
return None | ||
return raw_data.strip() | ||
|
||
def __read_txt_file(self, file_path): | ||
try: | ||
with open(file_path, 'r') as fd: | ||
data = fd.read() | ||
return data.strip() | ||
except IOError: | ||
pass | ||
return None | ||
|
||
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. | ||
""" | ||
reboot_cause_path = (HOST_REBOOT_CAUSE_PATH + REBOOT_CAUSE_FILE) | ||
sw_reboot_cause = self.__read_txt_file(reboot_cause_path) or "Unknown" | ||
hw_reboot_cause = self.__get_register_value(RESET_REGISTER) | ||
|
||
prev_reboot_cause = { | ||
'0x11': (self.REBOOT_CAUSE_POWER_LOSS, 'Power on reset'), | ||
'0x22': (self.REBOOT_CAUSE_WATCHDOG, 'Watchdog reset'), | ||
'0x33': (self.REBOOT_CAUSE_HARDWARE_OTHER, 'Power cycle reset triggered by CPU') | ||
}.get(hw_reboot_cause, (self.REBOOT_CAUSE_HARDWARE_OTHER, 'Unknown reason')) | ||
|
||
if sw_reboot_cause != 'Unknown' and ( hw_reboot_cause == '0x11' or hw_reboot_cause == '0x33'): | ||
prev_reboot_cause = (self.REBOOT_CAUSE_NON_HARDWARE, sw_reboot_cause) | ||
|
||
return prev_reboot_cause |
23 changes: 23 additions & 0 deletions
23
device/celestica/x86_64-cel_seastone-r0/sonic_platform/platform.py
This file contains 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,23 @@ | ||
#!/usr/bin/env python | ||
|
||
############################################################################# | ||
# Celestica | ||
# | ||
# Module contains an implementation of SONiC Platform Base API and | ||
# provides the platform information | ||
# | ||
############################################################################# | ||
|
||
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): | ||
"""Platform-specific Platform class""" | ||
|
||
def __init__(self): | ||
PlatformBase.__init__(self) | ||
self._chassis = Chassis() |
2 changes: 2 additions & 0 deletions
2
platform/broadcom/sonic-platform-modules-cel/debian/platform-modules-dx010.install
This file contains 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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
dx010/scripts/dx010_check_qsfp.sh usr/local/bin | ||
dx010/cfg/dx010-modules.conf etc/modules-load.d | ||
dx010/systemd/platform-modules-dx010.service lib/systemd/system | ||
dx010/modules/sonic_platform-1.0-py2-none-any.whl usr/share/sonic/device/x86_64-cel_seastone-r0 | ||
services/platform_api/platform_api_mgnt.sh usr/local/bin |
2 changes: 2 additions & 0 deletions
2
platform/broadcom/sonic-platform-modules-cel/debian/platform-modules-dx010.postinst
This file contains 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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
depmod -a | ||
systemctl enable platform-modules-dx010.service | ||
systemctl start platform-modules-dx010.service | ||
|
||
/usr/local/bin/platform_api_mgnt.sh install |
This file contains 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 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
34 changes: 34 additions & 0 deletions
34
platform/broadcom/sonic-platform-modules-cel/dx010/setup.py
This file contains 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,34 @@ | ||
from setuptools import setup | ||
|
||
DEVICE_NAME = 'celestica' | ||
HW_SKU = 'x86_64-cel_seastone-r0' | ||
|
||
setup( | ||
name='sonic-platform', | ||
version='1.0', | ||
description='SONiC platform API implementation on Celestica Platforms', | ||
license='Apache 2.0', | ||
author='SONiC Team', | ||
author_email='linuxnetdev@microsoft.com', | ||
url='https://github.com/Azure/sonic-buildimage', | ||
maintainer='Wirut Getbamrung', | ||
maintainer_email='wgetbumr@celestica.com', | ||
packages=[ | ||
'sonic_platform', | ||
], | ||
package_dir={ | ||
'sonic_platform': '../../../../device/{}/{}/sonic_platform'.format(DEVICE_NAME, HW_SKU)}, | ||
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', | ||
) |
41 changes: 41 additions & 0 deletions
41
platform/broadcom/sonic-platform-modules-cel/services/platform_api/platform_api_mgnt.sh
This file contains 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,41 @@ | ||
#!/bin/bash | ||
|
||
PREV_REBOOT_CAUSE="/host/reboot-cause/" | ||
DEVICE="/usr/share/sonic/device" | ||
PLATFORM=$(/usr/local/bin/sonic-cfggen -H -v DEVICE_METADATA.localhost.platform) | ||
FILES=$DEVICE/$PLATFORM/api_files | ||
|
||
install() { | ||
# Install sonic-platform package | ||
if [ -e $DEVICE/$PLATFORM/sonic_platform-1.0-py2-none-any.whl ]; then | ||
pip install $DEVICE/$PLATFORM/sonic_platform-1.0-py2-none-any.whl | ||
fi | ||
} | ||
|
||
init() { | ||
# mount needed files for sonic-platform package | ||
mkdir -p $FILES | ||
|
||
mkdir -p $FILES/reboot-cause | ||
mount -B $PREV_REBOOT_CAUSE $FILES/reboot-cause | ||
} | ||
|
||
deinit() { | ||
# deinit sonic-platform package | ||
umount -f $PREV_REBOOT_CAUSE $FILES/reboot-cause >/dev/null 2>/dev/null | ||
} | ||
|
||
uninstall() { | ||
# Uninstall sonic-platform package | ||
pip uninstall -y sonic-platform >/dev/null 2>/dev/null | ||
} | ||
|
||
case "$1" in | ||
install | uninstall | init | deinit) | ||
$1 | ||
;; | ||
*) | ||
echo "Usage: $0 {install|uninstall|init|deinit}" | ||
exit 1 | ||
;; | ||
esac |