[pddf]: Update PDDF utils and common platform APIs for Debian Bullseye (#9585)

- Why I did it
PDDF utils were python2 compliant and they needed to be migrated to Python3 (as per Bullseye)
PDDF common platform APIs file name changed as the name was already in use
Indentation issues
Dead/redundant code needed to be removed

- How I did it
Made files Python3 compliant
Indentation corrected
Redundant code removed

- How to verify it
AS7326 Accton platform uses PDDF. PDDF utils were run on this platform to verify.
This commit is contained in:
FuzailBrcm 2022-01-03 11:57:01 +05:30 committed by GitHub
parent 93247a6e24
commit fa361f164c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 1278 additions and 1998 deletions

View File

@ -15,7 +15,6 @@ command:
switch-nonpddf : switch to per platform, non-pddf mode
"""
import commands
import logging
import getopt
import os
@ -120,7 +119,7 @@ def my_log(txt):
def log_os_system(cmd, show):
logging.info('Run :'+cmd)
status, output = commands.getstatusoutput(cmd)
status, output = subprocess.getstatusoutput(cmd)
my_log (cmd +"with result:" + str(status))
my_log (" output:"+output)
if status:
@ -138,33 +137,9 @@ def driver_check():
return False
return True
# Returns platform and HW SKU
def get_platform_and_hwsku():
try:
proc = subprocess.Popen([SONIC_CFGGEN_PATH, '-H', '-v', PLATFORM_KEY],
stdout=subprocess.PIPE,
shell=False,
stderr=subprocess.STDOUT)
stdout = proc.communicate()[0]
proc.wait()
platform = stdout.rstrip('\n')
proc = subprocess.Popen([SONIC_CFGGEN_PATH, '-d', '-v', HWSKU_KEY],
stdout=subprocess.PIPE,
shell=False,
stderr=subprocess.STDOUT)
stdout = proc.communicate()[0]
proc.wait()
hwsku = stdout.rstrip('\n')
except OSError, e:
raise OSError("Cannot detect platform")
return (platform, hwsku)
def get_path_to_device():
# Get platform and hwsku
(platform, hwsku) = get_platform_and_hwsku()
(platform, hwsku) = pddf_obj.get_platform_and_hwsku()
# Load platform module from source
platform_path = "/".join([PLATFORM_ROOT_PATH, platform])
@ -193,14 +168,20 @@ def config_pddf_utils():
log_os_system('mv '+SONIC_PLATFORM_BSP_WHL_PKG+' '+SONIC_PLATFORM_BSP_WHL_PKG_BK, 1)
# PDDF whl package exist ... this must be the whl package created from
# PDDF 2.0 ref API classes and some changes on top of it ... install it
log_os_system('sync', 1)
shutil.copy(SONIC_PLATFORM_PDDF_WHL_PKG, SONIC_PLATFORM_BSP_WHL_PKG)
log_os_system('sync', 1)
print("Attemting to install the PDDF sonic_platform wheel package ...")
status, output = log_os_system("pip3 install "+ SONIC_PLATFORM_BSP_WHL_PKG, 1)
if status:
print("Error: Failed to install {}".format(SONIC_PLATFORM_BSP_WHL_PKG))
return status
if os.path.getsize(SONIC_PLATFORM_BSP_WHL_PKG) != 0:
status, output = log_os_system("pip3 install "+ SONIC_PLATFORM_BSP_WHL_PKG, 1)
if status:
print("Error: Failed to install {}".format(SONIC_PLATFORM_BSP_WHL_PKG))
return status
else:
print("Successfully installed {} package".format(SONIC_PLATFORM_BSP_WHL_PKG))
else:
print("Successfully installed {} package".format(SONIC_PLATFORM_BSP_WHL_PKG))
print("Error: Failed to copy {} properly. Exiting ...".format(SONIC_PLATFORM_PDDF_WHL_PKG))
return -1
else:
# PDDF with platform APIs 1.5 must be supported
device_plugin_path = "/".join([device_path, "plugins"])
@ -228,13 +209,17 @@ def config_pddf_utils():
if status:
print("Error: Unable to uninstall BSP sonic-platform whl package")
return status
print("Attemting to install the PDDF sonic_platform wheel package ...")
status, output = log_os_system("pip3 install "+ SONIC_PLATFORM_BSP_WHL_PKG, 1)
if status:
print("Error: Failed to install {}".format(SONIC_PLATFORM_BSP_WHL_PKG))
return status
print("Attempting to install the PDDF sonic_platform wheel package ...")
if os.path.getsize(SONIC_PLATFORM_BSP_WHL_PKG) != 0:
status, output = log_os_system("pip3 install "+ SONIC_PLATFORM_BSP_WHL_PKG, 1)
if status:
print("Error: Failed to install {}".format(SONIC_PLATFORM_BSP_WHL_PKG))
return status
else:
print("Successfully installed {} package".format(SONIC_PLATFORM_BSP_WHL_PKG))
else:
print("Successfully installed {} package".format(SONIC_PLATFORM_BSP_WHL_PKG))
print("Error: Failed to copy {} properly. Exiting ...".format(SONIC_PLATFORM_PDDF_WHL_PKG))
return -1
else:
# system rebooted in pddf mode
print("System rebooted in PDDF mode, hence keeping the PDDF 2.0 classes")
@ -353,6 +338,16 @@ def driver_install():
if status:
print("Error: pddf_pre_driver_install script failed with error %d"%status)
return status
# For debug
print(output)
# Removes the perm_kos first, then reload them in a proper sequence
for mod in perm_kos:
cmd = "modprobe -rq " + mod
status, output = log_os_system(cmd, 1)
if status:
print("driver_install: Unable to unload {}".format(mod))
# Don't exit but continue
log_os_system("depmod", 1)
for i in range(0,len(kos)):

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
MPATH := $($(PDDF_PLATFORM_API_BASE_PY2)_SRC_PATH)
MPATH := $($(PDDF_PLATFORM_API_BASE_PY3)_SRC_PATH)
DEP_FILES := $(SONIC_COMMON_FILES_LIST) platform/pddf/platform-api-pddf-base.mk platform/pddf/platform-api-pddf-base.dep
DEP_FILES += $(SONIC_COMMON_BASE_FILES_LIST)
DEP_FILES += $(shell git ls-files $(MPATH))

View File

@ -32,9 +32,9 @@ class PddfChassis(ChassisBase):
self.plugin_data = pddf_plugin_data if pddf_plugin_data else None
if not self.pddf_obj or not self.plugin_data:
try:
from . import pddfparse
from . import pddfapi
import json
self.pddf_obj = pddfparse.PddfParse()
self.pddf_obj = pddfapi.PddfApi()
with open('/usr/share/sonic/platform/pddf/pd-plugin.json') as pd:
self.plugin_data = json.load(pd)
except Exception as e:
@ -43,7 +43,12 @@ class PddfChassis(ChassisBase):
self.platform_inventory = self.pddf_obj.get_platform()
# Initialize EEPROM
self.sys_eeprom = Eeprom(self.pddf_obj, self.plugin_data)
try:
self._eeprom = Eeprom(self.pddf_obj, self.plugin_data)
except Exception as err:
sys.stderr.write("Unable to initialize syseeprom - {}".format(repr(err)))
# Dont exit as we dont want failure in loading other components
# FANs
for i in range(self.platform_inventory['num_fantrays']):
@ -66,28 +71,6 @@ class PddfChassis(ChassisBase):
thermal = Thermal(i, self.pddf_obj, self.plugin_data)
self._thermal_list.append(thermal)
# SYSTEM LED Test Cases
"""
#comment out test cases
sys_led_list= { "LOC":0,
"DIAG":0,
"FAN":0,
"SYS":0,
"PSU1":0,
"PSU2":1
}
for led in sys_led_list:
color=self.get_system_led(led, sys_led_list[led])
print color
self.set_system_led("LOC_LED","STATUS_LED_COLOR_GREEN")
color=self.get_system_led("LOC_LED")
print "Set Green: " + color
self.set_system_led("LOC_LED", "STATUS_LED_COLOR_OFF")
color=self.get_system_led("LOC_LED")
print "Set off: " + color
"""
def get_name(self):
"""
@ -95,7 +78,7 @@ class PddfChassis(ChassisBase):
Returns:
string: The name of the chassis
"""
return self.sys_eeprom.modelstr()
return self._eeprom.modelstr()
def get_presence(self):
"""
@ -111,7 +94,7 @@ class PddfChassis(ChassisBase):
Returns:
string: Model/part number of chassis
"""
return self.sys_eeprom.part_number_str()
return self._eeprom.part_number_str()
def get_serial(self):
"""
@ -119,7 +102,7 @@ class PddfChassis(ChassisBase):
Returns:
string: Serial number of chassis
"""
return self.sys_eeprom.serial_str()
return self._eeprom.serial_str()
def get_status(self):
"""
@ -138,7 +121,7 @@ class PddfChassis(ChassisBase):
A string containing the MAC address in the format
'XX:XX:XX:XX:XX:XX'
"""
return self.sys_eeprom.base_mac_addr()
return self._eeprom.base_mac_addr()
def get_serial_number(self):
"""
@ -148,7 +131,7 @@ class PddfChassis(ChassisBase):
A string containing the hardware serial number for this
chassis.
"""
return self.sys_eeprom.serial_number_str()
return self._eeprom.serial_number_str()
def get_system_eeprom_info(self):
"""
@ -158,7 +141,7 @@ class PddfChassis(ChassisBase):
OCP ONIE TlvInfo EEPROM format and values are their corresponding
values.
"""
return self.sys_eeprom.system_eeprom_info()
return self._eeprom.system_eeprom_info()
def get_reboot_cause(self):
"""
@ -173,263 +156,39 @@ class PddfChassis(ChassisBase):
"""
raise NotImplementedError
def get_component_name_list(self):
"""
Retrieves a list of the names of components available on the chassis (e.g., BIOS, CPLD, FPGA, etc.)
Returns:
A list containing the names of components available on the chassis
"""
return self._component_name_list
def get_firmware_version(self, component_name):
"""
Retrieves platform-specific hardware/firmware versions for chassis
componenets such as BIOS, CPLD, FPGA, etc.
Args:
component_name: A string, the component name.
Returns:
A string containing platform-specific component versions
"""
raise NotImplementedError
def install_component_firmware(self, component_name, image_path):
"""
Install firmware to component
Args:
component_name: A string, the component name.
image_path: A string, path to firmware image.
Returns:
A boolean, True if install was successful, False if not
"""
raise NotImplementedError
##############################################
# Component methods
##############################################
##############################################
# Module methods
##############################################
# All module methods are part of chassis_base.py
# if they need to be overwritten, define them here
def get_num_modules(self):
"""
Retrieves the number of modules available on this chassis
Returns:
An integer, the number of modules available on this chassis
"""
return len(self._module_list)
def get_all_modules(self):
"""
Retrieves all modules available on this chassis
Returns:
A list of objects derived from ModuleBase representing all
modules available on this chassis
"""
return self._module_list
def get_module(self, index):
"""
Retrieves module represented by (0-based) index <index>
Args:
index: An integer, the index (0-based) of the module to
retrieve
Returns:
An object dervied from ModuleBase representing the specified
module
"""
module = None
try:
module = self._module_list[index]
except IndexError:
sys.stderr.write("Module index {} out of range (0-{})\n".format(
index, len(self._module_list)-1))
return module
##############################################
# Fan methods
##############################################
def get_num_fans(self):
"""
Retrieves the number of fans available on this chassis
Returns:
An integer, the number of fan modules available on this chassis
"""
return len(self._fan_list)
def get_all_fans(self):
"""
Retrieves all fan modules available on this chassis
Returns:
A list of objects derived from FanBase representing all fan
modules available on this chassis
"""
return self._fan_list
def get_fan(self, index):
"""
Retrieves fan module represented by (0-based) index <index>
Args:
index: An integer, the index (0-based) of the fan module to
retrieve
Returns:
An object dervied from FanBase representing the specified fan
module
"""
fan = None
try:
fan = self._fan_list[index]
except IndexError:
sys.stderr.write("Fan index {} out of range (0-{})\n".format(
index, len(self._fan_list)-1))
return fan
# All fan methods are part of chassis_base.py
# if they need to be overwritten, define them here
##############################################
# PSU methods
##############################################
def get_num_psus(self):
"""
Retrieves the number of power supply units available on this chassis
Returns:
An integer, the number of power supply units available on this
chassis
"""
return len(self._psu_list)
def get_all_psus(self):
"""
Retrieves all power supply units available on this chassis
Returns:
A list of objects derived from PsuBase representing all power
supply units available on this chassis
"""
return self._psu_list
def get_psu(self, index):
"""
Retrieves power supply unit represented by (0-based) index <index>
Args:
index: An integer, the index (0-based) of the power supply unit to
retrieve
Returns:
An object dervied from PsuBase representing the specified power
supply unit
"""
psu = None
try:
psu = self._psu_list[index]
except IndexError:
sys.stderr.write("PSU index {} out of range (0-{})\n".format(
index, len(self._psu_list)-1))
return psu
# All psu methods are part of chassis_base.py
# if they need to be overwritten, define them here
##############################################
# THERMAL methods
##############################################
def get_num_thermals(self):
"""
Retrieves the number of thermals available on this chassis
Returns:
An integer, the number of thermals available on this chassis
"""
return len(self._thermal_list)
def get_all_thermals(self):
"""
Retrieves all thermals available on this chassis
Returns:
A list of objects derived from ThermalBase representing all thermals
available on this chassis
"""
return self._thermal_list
def get_thermal(self, index):
"""
Retrieves thermal unit represented by (0-based) index <index>
Args:
index: An integer, the index (0-based) of the thermal to
retrieve
Returns:
An object dervied from ThermalBase representing the specified thermal
"""
thermal = None
try:
thermal = self._thermal_list[index]
except IndexError:
sys.stderr.write("THERMAL index {} out of range (0-{})\n".format(
index, len(self._thermal_list)-1))
return thermal
# All thermal methods are part of chassis_base.py
# if they need to be overwritten, define them here
##############################################
# SFP methods
##############################################
def get_num_sfps(self):
"""
Retrieves the number of sfps available on this chassis
Returns:
An integer, the number of sfps available on this chassis
"""
return len(self._sfp_list)
def get_all_sfps(self):
"""
Retrieves all sfps available on this chassis
Returns:
A list of objects derived from SfpBase representing all sfps
available on this chassis
"""
return self._sfp_list
def get_sfp(self, index):
"""
Retrieves sfp represented by (0-based) index <index>
Args:
index: An integer, the index (0-based) of the sfp to retrieve.
The index should be the sequence of a physical port in a chassis,
starting from 0.
For example, 0 for Ethernet0, 1 for Ethernet4 and so on.
Returns:
An object dervied from SfpBase representing the specified sfp
"""
sfp = None
try:
sfp = self._sfp_list[index]
except IndexError:
sys.stderr.write("SFP index {} out of range (0-{})\n".format(
index, len(self._sfp_list)-1))
return sfp
# All sfp methods are part of chassis_base.py
# if they need to be overwritten, define them here
##############################################
# System LED methods
@ -464,47 +223,3 @@ class PddfChassis(ChassisBase):
##############################################
# Other methods
##############################################
def get_watchdog(self):
"""
Retreives hardware watchdog device on this chassis
Returns:
An object derived from WatchdogBase representing the hardware
watchdog device
"""
return self._watchdog
def get_eeprom(self):
"""
Retreives eeprom device on this chassis
Returns:
An object derived from WatchdogBase representing the hardware
eeprom device
"""
return self.sys_eeprom
def get_change_event(self, timeout=0):
"""
Returns a nested dictionary containing all devices which have
experienced a change at chassis level
Args:
timeout: Timeout in milliseconds (optional). If timeout == 0,
this method will block until a change is detected.
Returns:
(bool, dict):
- True if call successful, False if not;
- A nested dictionary where key is a device type,
value is a dictionary with key:value pairs in the format of
{'device_id':'device_event'},
where device_id is the device ID for this device and
device_event,
status='1' represents device inserted,
status='0' represents device removed.
Ex. {'fan':{'0':'0', '2':'1'}, 'sfp':{'11':'0'}}
indicates that fan 0 has been removed, fan 2
has been inserted and sfp 11 has been removed.
"""
raise NotImplementedError

View File

@ -8,7 +8,7 @@
try:
import json
from . import pddfparse
from . import pddfapi
from sonic_platform_base.platform_base import PlatformBase
from sonic_platform.chassis import Chassis
except ImportError as e:
@ -24,7 +24,7 @@ class PddfPlatform(PlatformBase):
def __init__(self):
# Initialize the JSON data
self.pddf_data = pddfparse.PddfParse()
self.pddf_data = pddfapi.PddfApi()
with open('/usr/share/sonic/platform/pddf/pd-plugin.json') as pd:
self.pddf_plugin_data = json.load(pd)