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

[Edgecore][as7726/PDDF] Add needed api to sonic_platform #12848

Closed
Closed
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
4 changes: 2 additions & 2 deletions device/accton/x86_64-accton_as7726_32x-r0/pddf/pd-plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
{
"i2c":
{
"valmap": { "F2B":"EXHAUST", "B2F":"INTAKE" }
"valmap": { "F2B":"exhaust", "B2F":"intake" }
}
},

Expand All @@ -47,7 +47,7 @@
{
"i2c":
{
"valmap": {"1":"EXHAUST", "0":"INTAKE"}
"valmap": {"1":"exhaust", "0":"intake"}
}
},

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"services_to_ignore": [],
"devices_to_ignore": [
"asic",
"psu.voltage",
"psu.temperature",
"PSU1_FAN1.speed",
"PSU2_FAN1.speed"
],
"user_defined_checkers": [],
"polling_interval": 60,
"led_color": {
"fault": "STATUS_LED_COLOR_AMBER",
"normal": "STATUS_LED_COLOR_GREEN",
"booting": "STATUS_LED_COLOR_OFF"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,58 +8,59 @@

try:
import sys
import time
from sonic_platform_pddf_base.pddf_chassis import PddfChassis
from .event import SfpEvent
from .helper import APIHelper
except ImportError as e:
raise ImportError(str(e) + "- required module not found")

NUM_COMPONENT = 6
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"

class Chassis(PddfChassis):
"""
PDDF Platform-specific Chassis class
"""

SYSLED_DEV_NAME = "DIAG_LED"

def __init__(self, pddf_data=None, pddf_plugin_data=None):
PddfChassis.__init__(self, pddf_data, pddf_plugin_data)
self.__initialize_components()
self._api_helper = APIHelper()
self._sfpevent = SfpEvent(self.get_all_sfps())


def __initialize_components(self):
from sonic_platform.component import Component
for index in range(NUM_COMPONENT):
component = Component(index)
self._component_list.append(component)

# Provide the functions/variables below for which implementation is to be overwritten
sfp_change_event_data = {'valid': 0, 'last': 0, 'present': 0}
def get_change_event(self, timeout=2000):
now = time.time()
port_dict = {}
change_dict = {}
change_dict['sfp'] = port_dict

if timeout < 1000:
timeout = 1000
timeout = timeout / float(1000) # Convert to secs

if now < (self.sfp_change_event_data['last'] + timeout) and self.sfp_change_event_data['valid']:
return True, change_dict

bitmap = 0
for i in range(34):
modpres = self.get_sfp(i+1).get_presence()
if modpres:
bitmap = bitmap | (1 << i)

changed_ports = self.sfp_change_event_data['present'] ^ bitmap
if changed_ports:
for i in range(34):
if (changed_ports & (1 << i)):
if (bitmap & (1 << i)) == 0:
port_dict[i+1] = '0'
else:
port_dict[i+1] = '1'


# Update teh cache dict
self.sfp_change_event_data['present'] = bitmap
self.sfp_change_event_data['last'] = now
self.sfp_change_event_data['valid'] = 1
return True, change_dict
else:
return True, change_dict
def get_change_event(self, timeout=0):
return self._sfpevent.get_sfp_event(timeout)

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(
Copy link
Contributor

@FuzailBrcm FuzailBrcm Nov 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who writes the reboot reason to this file ?
and if the reboot reason is HW_WATCHDOG_TIMEOUT then how it is being detected?

reboot_cause_path) or "Unknown"


return ('REBOOT_CAUSE_NON_HARDWARE', sw_reboot_cause)


def get_sfp(self, index):
Expand All @@ -84,3 +85,40 @@ def get_sfp(self, index):
sys.stderr.write("SFP index {} out of range (1-{})\n".format(
index, len(self._sfp_list)))
return sfp

def get_position_in_parent(self):
"""
Retrieves 1-based relative physical position in parent device. If the agent cannot determine the parent-relative position
for some reason, or if the associated value of entPhysicalContainedIn is '0', then the value '-1' is returned
Returns:
integer: The 1-based relative physical position in parent device or -1 if cannot determine the position
"""
return -1

def get_num_sfps(self):
return len(self._sfp_list)

def is_replaceable(self):
"""
Indicate whether this device is replaceable.
Returns:
bool: True if it is replaceable.
"""
return False


def initizalize_system_led(self):
return

def get_status_led(self):
return self.get_system_led(self.SYSLED_DEV_NAME)

def set_status_led(self, color):
return self.set_system_led(self.SYSLED_DEV_NAME, color)

def get_port_or_cage_type(self, port):
from sonic_platform_base.sfp_base import SfpBase
if port in range(1, 32):
return SfpBase.SFP_PORT_TYPE_BIT_QSFP | SfpBase.SFP_PORT_TYPE_BIT_QSFP_PLUS | SfpBase.SFP_PORT_TYPE_BIT_QSFP28
else:
return SfpBase.SFP_PORT_TYPE_BIT_SFP | SfpBase.SFP_PORT_TYPE_BIT_SFP_PLUS
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
#############################################################################
#
# Component contains an implementation of SONiC Platform Base API and
# provides the components firmware management function
#
#############################################################################

try:
import subprocess
from sonic_platform_base.component_base import ComponentBase
except ImportError as e:
raise ImportError(str(e) + "- required module not found")

CPLD_ADDR_MAPPING = {
"CPLD1": ['11', '0x60'],
"CPLD2": ['12', '0x62'],
"CPLD3": ['13', '0x64'],
"CPLD4": ['54', '0x66']
}
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"),
("CPLD4", "CPLD 4"),
("CPLD5", "CPLD 5"),
("BIOS", "Basic Input/Output System")

]

class Component(ComponentBase):
"""Platform-specific Component class"""

DEVICE_TYPE = "component"

def __init__(self, component_index=0):
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:
return None

def __get_cpld_version(self):
# Retrieves the CPLD firmware version
cpld_version = dict()
for cpld_name in CPLD_ADDR_MAPPING:
cmd = "i2cget -f -y {0} {1} 0x1".format(CPLD_ADDR_MAPPING[cpld_name][0], CPLD_ADDR_MAPPING[cpld_name][1])
status, value = subprocess.getstatusoutput(cmd)
if not status:
cpld_version_raw = value.rstrip()
cpld_version[cpld_name] = "{}".format(int(cpld_version_raw,16))

return cpld_version


def __get_cpld_cpu_version(self):
try:
cpu_version = dict()
cmd = "i2cget -f -y 0 0x65 0x01"
status, output1 = subprocess.getstatusoutput(cmd)
if status == 0 :
cpu_version = "{}".format(output1[2:])
else :
cpu_version = 'None'
except Exception as e:
cpu_version = 'None'

return cpu_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]

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 "CPLD5" in self.name:
fw_version = self.__get_cpld_cpu_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

def get_presence(self):
"""
Retrieves the presence of the device
Returns:
bool: True if device is present, False if not
"""
return True

def get_model(self):
"""
Retrieves the model number (or part number) of the device
Returns:
string: Model/part number of device
"""
return 'N/A'

def get_serial(self):
"""
Retrieves the serial number of the device
Returns:
string: Serial number of device
"""
return 'N/A'

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_position_in_parent(self):
"""
Retrieves 1-based relative physical position in parent device.
If the agent cannot determine the parent-relative position
for some reason, or if the associated value of
entPhysicalContainedIn is'0', then the value '-1' is returned
Returns:
integer: The 1-based relative physical position in parent device
or -1 if cannot determine the position
"""
return -1

def is_replaceable(self):
"""
Indicate whether this device is replaceable.
Returns:
bool: True if it is replaceable.
"""
return False



Loading