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

Update PDDF utils and common platform APIs for Debian Bullseye #9585

Merged
merged 2 commits into from
Jan 3, 2022
Merged
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
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