Skip to content

Commit

Permalink
[pddf]: Update PDDF utils and common platform APIs for Debian Bullseye (
Browse files Browse the repository at this point in the history
sonic-net#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.
  • Loading branch information
FuzailBrcm authored and seanwu-ec committed Jan 12, 2022
1 parent 7ce4ae6 commit 673afd3
Show file tree
Hide file tree
Showing 10 changed files with 1,282 additions and 2,002 deletions.
71 changes: 33 additions & 38 deletions platform/pddf/i2c/utils/pddf_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
switch-nonpddf : switch to per platform, non-pddf mode
"""

import commands
import logging
import getopt
import os
Expand Down Expand Up @@ -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:
Expand All @@ -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])
Expand Down Expand Up @@ -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"])
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)):
Expand Down
Loading

0 comments on commit 673afd3

Please sign in to comment.