-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[as5835-54x] Add to support API2.0 #6480
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
jleveque
merged 13 commits into
sonic-net:master
from
jostar-yang:as5835-54x_20210118_api2.0
May 28, 2021
Merged
Changes from 3 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
cbf1975
[as5835-54x] Add to support API2.0
271c5db
[as5835-54x] Fix LGTM alerts
4117318
[as5835-54x] Fix fan.py to check None case
df4fc1c
[as5835-54x] Add newline and remove env py
e11eb75
[as5835-54x] Modify to support python3 only
756b05b
Merge branch 'master' into as5835-54x_20210118_api2.0
jostar-yang 02763ba
Add port sfp get_change_event function
cbe9666
[as5835-54x] Modify to use parse_dom_capability()
5da6c1f
Add psu SN, model and fix sfp.py
cbaea10
Add import sys to chassis.py
1ecaa71
Fix port index
6a63f15
Fix to use QSFP_CONTROL_OFFSET for dom_control_raw
ca5f434
Fix write api in sfpy.py
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
2 changes: 2 additions & 0 deletions
2
device/accton/x86_64-accton_as5835_54x-r0/sonic_platform/__init__.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,2 @@ | ||
| __all__ = ['chassis', 'eeprom', 'platform', 'psu', 'sfp', 'thermal', 'fan'] | ||
| from . import platform | ||
197 changes: 197 additions & 0 deletions
197
device/accton/x86_64-accton_as5835_54x-r0/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,197 @@ | ||
| #!/usr/bin/env python | ||
jleveque marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ############################################################################# | ||
| # Edgecore | ||
| # | ||
| # Module contains an implementation of SONiC Platform Base API and | ||
| # provides the Chassis information which are available in the platform | ||
| # | ||
| ############################################################################# | ||
|
|
||
| import os | ||
|
|
||
| try: | ||
| from sonic_platform_base.chassis_base import ChassisBase | ||
| from .helper import APIHelper | ||
| except ImportError as e: | ||
| raise ImportError(str(e) + "- required module not found") | ||
|
|
||
| NUM_FAN_TRAY = 5 | ||
| NUM_FAN = 2 | ||
| NUM_PSU = 2 | ||
| NUM_THERMAL = 4 | ||
| NUM_QSFP = 54 | ||
| PORT_START = 1 | ||
| PORT_END = 54 | ||
| NUM_COMPONENT = 4 | ||
| HOST_REBOOT_CAUSE_PATH = "/host/reboot-cause/" | ||
| PMON_REBOOT_CAUSE_PATH = "/usr/share/sonic/platform/api_files/reboot-cause/" | ||
| REBOOT_CAUSE_FILE = "reboot-cause.txt" | ||
| PREV_REBOOT_CAUSE_FILE = "previous-reboot-cause.txt" | ||
| HOST_CHK_CMD = "docker > /dev/null 2>&1" | ||
|
|
||
|
|
||
| class Chassis(ChassisBase): | ||
| """Platform-specific Chassis class""" | ||
|
|
||
| def __init__(self): | ||
| ChassisBase.__init__(self) | ||
| self._api_helper = APIHelper() | ||
| self._api_helper = APIHelper() | ||
| self.is_host = self._api_helper.is_host() | ||
|
|
||
| self.config_data = {} | ||
|
|
||
| self.__initialize_fan() | ||
| self.__initialize_psu() | ||
| self.__initialize_thermals() | ||
| self.__initialize_components() | ||
| self.__initialize_sfp() | ||
| self.__initialize_eeprom() | ||
|
|
||
| def __initialize_sfp(self): | ||
| from sonic_platform.sfp import Sfp | ||
| for index in range(0, PORT_END): | ||
| sfp = Sfp(index) | ||
| self._sfp_list.append(sfp) | ||
| self.sfp_module_initialized = True | ||
|
|
||
| def __initialize_fan(self): | ||
| from sonic_platform.fan import Fan | ||
| for fant_index in range(0, NUM_FAN_TRAY): | ||
| for fan_index in range(0, NUM_FAN): | ||
| fan = Fan(fant_index, fan_index) | ||
| self._fan_list.append(fan) | ||
|
|
||
| def __initialize_psu(self): | ||
| from sonic_platform.psu import Psu | ||
| for index in range(0, NUM_PSU): | ||
| psu = Psu(index) | ||
| self._psu_list.append(psu) | ||
|
|
||
| def __initialize_thermals(self): | ||
| from sonic_platform.thermal import Thermal | ||
| for index in range(0, NUM_THERMAL): | ||
| thermal = Thermal(index) | ||
| self._thermal_list.append(thermal) | ||
|
|
||
| def __initialize_eeprom(self): | ||
| from sonic_platform.eeprom import Tlv | ||
| self._eeprom = Tlv() | ||
|
|
||
| def __initialize_components(self): | ||
| from sonic_platform.component import Component | ||
| for index in range(0, NUM_COMPONENT): | ||
| component = Component(index) | ||
| self._component_list.append(component) | ||
|
|
||
| def __initialize_watchdog(self): | ||
| from sonic_platform.watchdog import Watchdog | ||
| self._watchdog = Watchdog() | ||
|
|
||
|
|
||
| def __is_host(self): | ||
| return os.system(HOST_CHK_CMD) == 0 | ||
|
|
||
| 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_name(self): | ||
| """ | ||
| Retrieves the name of the device | ||
| Returns: | ||
| string: The name of the device | ||
| """ | ||
|
|
||
| return self._api_helper.hwsku | ||
|
|
||
| def get_presence(self): | ||
| """ | ||
| Retrieves the presence of the Chassis | ||
| Returns: | ||
| bool: True if Chassis is present, False if not | ||
| """ | ||
| return True | ||
|
|
||
| def get_status(self): | ||
| """ | ||
| Retrieves the operational status of the device | ||
| Returns: | ||
| A boolean value, True if device is operating properly, False if not | ||
| """ | ||
| return True | ||
|
|
||
| def get_base_mac(self): | ||
| """ | ||
| Retrieves the base MAC address for the chassis | ||
| Returns: | ||
| A string containing the MAC address in the format | ||
| 'XX:XX:XX:XX:XX:XX' | ||
| """ | ||
| return self._eeprom.get_mac() | ||
|
|
||
| def get_serial_number(self): | ||
| """ | ||
| Retrieves the hardware serial number for the chassis | ||
| Returns: | ||
| A string containing the hardware serial number for this chassis. | ||
| """ | ||
| return self._eeprom.get_serial() | ||
|
|
||
| def get_system_eeprom_info(self): | ||
| """ | ||
| Retrieves the full content of system EEPROM information for the chassis | ||
| Returns: | ||
| A dictionary where keys are the type code defined in | ||
| OCP ONIE TlvInfo EEPROM format and values are their corresponding | ||
| values. | ||
| """ | ||
| return self._eeprom.get_eeprom() | ||
|
|
||
| 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._api_helper.read_txt_file( | ||
| reboot_cause_path) or "Unknown" | ||
|
|
||
|
|
||
| return ('REBOOT_CAUSE_NON_HARDWARE', sw_reboot_cause) | ||
|
|
||
| def get_sfp(self, index): | ||
| """ | ||
| Retrieves sfp represented by (1-based) index <index> | ||
| Args: | ||
| index: An integer, the index (1-based) of the sfp to retrieve. | ||
| The index should be the sequence of a physical port in a chassis, | ||
| starting from 1. | ||
| For example, 1 for Ethernet0, 2 for Ethernet4 and so on. | ||
| Returns: | ||
| An object dervied from SfpBase representing the specified sfp | ||
| """ | ||
| sfp = None | ||
| if not self.sfp_module_initialized: | ||
| self.__initialize_sfp() | ||
|
|
||
| try: | ||
| # The index will start from 1 | ||
| sfp = self._sfp_list[index-1] | ||
| except IndexError: | ||
| sys.stderr.write("SFP index {} out of range (1-{})\n".format( | ||
| index, len(self._sfp_list))) | ||
| return sfp | ||
jleveque marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
133 changes: 133 additions & 0 deletions
133
device/accton/x86_64-accton_as5835_54x-r0/sonic_platform/component.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,133 @@ | ||
| #!/usr/bin/env python | ||
jleveque marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ############################################################################# | ||
| # Celestica | ||
| # | ||
| # Component contains an implementation of SONiC Platform Base API and | ||
| # provides the components firmware management function | ||
| # | ||
| ############################################################################# | ||
|
|
||
| import shlex | ||
| import subprocess | ||
|
|
||
|
|
||
| try: | ||
| from sonic_platform_base.component_base import ComponentBase | ||
| from .helper import APIHelper | ||
| except ImportError as e: | ||
| raise ImportError(str(e) + "- required module not found") | ||
|
|
||
| CPLD_ADDR_MAPPING = { | ||
| "CPLD1": "3-0060", | ||
| "CPLD2": "3-0061", | ||
| "CPLD3": "3-0062", | ||
| } | ||
| SYSFS_PATH = "/sys/bus/i2c/devices/" | ||
| BIOS_VERSION_PATH = "/sys/class/dmi/id/bios_version" | ||
| COMPONENT_LIST= [ | ||
| ("CPLD1", "CPLD 1"), | ||
| ("CPLD2", "CPLD 2"), | ||
| ("CPLD3", "CPLD 3"), | ||
| ("BIOS", "Basic Input/Output System") | ||
|
|
||
| ] | ||
| COMPONENT_DES_LIST = ["CPLD","Basic Input/Output System"] | ||
|
|
||
|
|
||
| class Component(ComponentBase): | ||
| """Platform-specific Component class""" | ||
|
|
||
| DEVICE_TYPE = "component" | ||
|
|
||
| def __init__(self, component_index=0): | ||
| self._api_helper=APIHelper() | ||
| ComponentBase.__init__(self) | ||
| self.index = component_index | ||
| self.name = self.get_name() | ||
|
|
||
|
|
||
| def __run_command(self, command): | ||
| # Run bash command and print output to stdout | ||
| try: | ||
| process = subprocess.Popen( | ||
| shlex.split(command), stdout=subprocess.PIPE) | ||
| while True: | ||
| output = process.stdout.readline() | ||
| if output == '' and process.poll() is not None: | ||
| break | ||
| rc = process.poll() | ||
| if rc != 0: | ||
| return False | ||
| except Exception: | ||
| return False | ||
| return True | ||
|
|
||
| def __get_bios_version(self): | ||
| # Retrieves the BIOS firmware version | ||
| try: | ||
| with open(BIOS_VERSION_PATH, 'r') as fd: | ||
| bios_version = fd.read() | ||
| return bios_version.strip() | ||
| except Exception as e: | ||
| print('Get exception when read bios') | ||
| return None | ||
|
|
||
| def __get_cpld_version(self): | ||
| # Retrieves the CPLD firmware version | ||
| cpld_version = dict() | ||
| for cpld_name in CPLD_ADDR_MAPPING: | ||
| try: | ||
| cpld_path = "{}{}{}".format(SYSFS_PATH, CPLD_ADDR_MAPPING[cpld_name], '/version') | ||
| cpld_version_raw= self._api_helper.read_txt_file(cpld_path) | ||
| cpld_version[cpld_name] = "{}".format(int(cpld_version_raw,16)) | ||
| except Exception as e: | ||
| print('Get exception when read cpld') | ||
| cpld_version[cpld_name] = 'None' | ||
|
|
||
| return cpld_version | ||
|
|
||
| def get_name(self): | ||
| """ | ||
| Retrieves the name of the component | ||
| Returns: | ||
| A string containing the name of the component | ||
| """ | ||
| return COMPONENT_LIST[self.index][0] | ||
|
|
||
| def get_description(self): | ||
| """ | ||
| Retrieves the description of the component | ||
| Returns: | ||
| A string containing the description of the component | ||
| """ | ||
| return COMPONENT_LIST[self.index][1] | ||
| #return "testhwsku" | ||
|
|
||
| def get_firmware_version(self): | ||
| """ | ||
| Retrieves the firmware version of module | ||
| Returns: | ||
| string: The firmware versions of the module | ||
| """ | ||
| fw_version = None | ||
| if self.name == "BIOS": | ||
| fw_version = self.__get_bios_version() | ||
| elif "CPLD" in self.name: | ||
| cpld_version = self.__get_cpld_version() | ||
| fw_version = cpld_version.get(self.name) | ||
|
|
||
| return fw_version | ||
|
|
||
| def install_firmware(self, image_path): | ||
| """ | ||
| Install firmware to module | ||
| Args: | ||
| image_path: A string, path to firmware image | ||
| Returns: | ||
| A boolean, True if install successfully, False if not | ||
| """ | ||
| raise NotImplementedError | ||
|
|
||
|
|
||
|
|
||
jleveque marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Oops, something went wrong.
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.