[Mellanox] Add python3 support for Mellanox platform API (#6175)
python2 is end of life and SONiC is going to support python3. This PR is going to support: 1. Mellanox SONiC platform API python3 support 2. Install both python2 and python3 verson of Mellanox SONiC platform API or pmon and host side
This commit is contained in:
parent
2cd236cece
commit
51c77b179f
@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"skip_ledd": true,
|
"skip_ledd": true,
|
||||||
"skip_fancontrol": true,
|
"skip_fancontrol": true,
|
||||||
"delay_xcvrd": true
|
"delay_xcvrd": true,
|
||||||
|
"python2_daemons": ["xcvrd"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -640,11 +640,17 @@ sudo cp $files_path/$MLNX_SSD_FW_UPDATE $FILESYSTEM_ROOT/usr/bin/$MLNX_SSD_FW_UP
|
|||||||
j2 platform/mellanox/mlnx-fw-upgrade.j2 | sudo tee $FILESYSTEM_ROOT/usr/bin/mlnx-fw-upgrade.sh
|
j2 platform/mellanox/mlnx-fw-upgrade.j2 | sudo tee $FILESYSTEM_ROOT/usr/bin/mlnx-fw-upgrade.sh
|
||||||
sudo chmod 755 $FILESYSTEM_ROOT/usr/bin/mlnx-fw-upgrade.sh
|
sudo chmod 755 $FILESYSTEM_ROOT/usr/bin/mlnx-fw-upgrade.sh
|
||||||
|
|
||||||
# Install mlnx-sonic-platform-common Python 2 package
|
# Install mlnx-sonic-platform Python 2 package
|
||||||
MLNX_PLATFORM_COMMON_PY2_WHEEL_NAME=$(basename {{mlnx_platform_api_py2_wheel_path}})
|
MLNX_SONIC_PLATFORM_PY2_WHEEL_NAME=$(basename {{mlnx_platform_api_py2_wheel_path}})
|
||||||
sudo cp {{mlnx_platform_api_py2_wheel_path}} $FILESYSTEM_ROOT/$MLNX_PLATFORM_COMMON_PY2_WHEEL_NAME
|
sudo cp {{mlnx_platform_api_py2_wheel_path}} $FILESYSTEM_ROOT/$MLNX_SONIC_PLATFORM_PY2_WHEEL_NAME
|
||||||
sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip2 install $MLNX_PLATFORM_COMMON_PY2_WHEEL_NAME
|
sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip2 install $MLNX_SONIC_PLATFORM_PY2_WHEEL_NAME
|
||||||
sudo rm -rf $FILESYSTEM_ROOT/$MLNX_PLATFORM_COMMON_PY2_WHEEL_NAME
|
sudo rm -rf $FILESYSTEM_ROOT/$MLNX_SONIC_PLATFORM_PY2_WHEEL_NAME
|
||||||
|
|
||||||
|
# Install mlnx-sonic-platform Python 3 package
|
||||||
|
MLNX_SONIC_PLATFORM_PY3_WHEEL_NAME=$(basename {{mlnx_platform_api_py3_wheel_path}})
|
||||||
|
sudo cp {{mlnx_platform_api_py3_wheel_path}} $FILESYSTEM_ROOT/$MLNX_SONIC_PLATFORM_PY3_WHEEL_NAME
|
||||||
|
sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip3 install $MLNX_SONIC_PLATFORM_PY3_WHEEL_NAME
|
||||||
|
sudo rm -rf $FILESYSTEM_ROOT/$MLNX_SONIC_PLATFORM_PY3_WHEEL_NAME
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{%- if SONIC_ROUTING_STACK == "frr" %}
|
{%- if SONIC_ROUTING_STACK == "frr" %}
|
||||||
|
@ -9,3 +9,7 @@ DEP_FILES += $(shell git ls-files -- $(SPATH) | grep -Ev ' ')
|
|||||||
$(SONIC_PLATFORM_API_PY2)_CACHE_MODE := GIT_CONTENT_SHA
|
$(SONIC_PLATFORM_API_PY2)_CACHE_MODE := GIT_CONTENT_SHA
|
||||||
$(SONIC_PLATFORM_API_PY2)_DEP_FLAGS := $(SONIC_COMMON_FLAGS_LIST)
|
$(SONIC_PLATFORM_API_PY2)_DEP_FLAGS := $(SONIC_COMMON_FLAGS_LIST)
|
||||||
$(SONIC_PLATFORM_API_PY2)_DEP_FILES := $(filter-out $(SLINKS),$(DEP_FILES))
|
$(SONIC_PLATFORM_API_PY2)_DEP_FILES := $(filter-out $(SLINKS),$(DEP_FILES))
|
||||||
|
|
||||||
|
$(SONIC_PLATFORM_API_PY3)_CACHE_MODE := GIT_CONTENT_SHA
|
||||||
|
$(SONIC_PLATFORM_API_PY3)_DEP_FLAGS := $(SONIC_COMMON_FLAGS_LIST)
|
||||||
|
$(SONIC_PLATFORM_API_PY3)_DEP_FILES := $(filter-out $(SLINKS),$(DEP_FILES))
|
||||||
|
@ -7,3 +7,13 @@ $(SONIC_PLATFORM_API_PY2)_DEPENDS = $(SONIC_PY_COMMON_PY2) $(SONIC_PLATFORM_COMM
|
|||||||
SONIC_PYTHON_WHEELS += $(SONIC_PLATFORM_API_PY2)
|
SONIC_PYTHON_WHEELS += $(SONIC_PLATFORM_API_PY2)
|
||||||
|
|
||||||
export mlnx_platform_api_py2_wheel_path="$(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_PLATFORM_API_PY2))"
|
export mlnx_platform_api_py2_wheel_path="$(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_PLATFORM_API_PY2))"
|
||||||
|
|
||||||
|
# SONIC_PLATFORM_API_PY3 package
|
||||||
|
|
||||||
|
SONIC_PLATFORM_API_PY3 = mlnx_platform_api-1.0-py3-none-any.whl
|
||||||
|
$(SONIC_PLATFORM_API_PY3)_SRC_PATH = $(PLATFORM_PATH)/mlnx-platform-api
|
||||||
|
$(SONIC_PLATFORM_API_PY3)_PYTHON_VERSION = 3
|
||||||
|
$(SONIC_PLATFORM_API_PY3)_DEPENDS = $(SONIC_PY_COMMON_PY3) $(SONIC_PLATFORM_COMMON_PY3) $(SONIC_CONFIG_ENGINE_PY3) $(SONIC_PLATFORM_API_PY2)
|
||||||
|
SONIC_PYTHON_WHEELS += $(SONIC_PLATFORM_API_PY3)
|
||||||
|
|
||||||
|
export mlnx_platform_api_py3_wheel_path="$(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_PLATFORM_API_PY3))"
|
||||||
|
@ -31,6 +31,7 @@ setup(
|
|||||||
'Natural Language :: English',
|
'Natural Language :: English',
|
||||||
'Operating System :: POSIX :: Linux',
|
'Operating System :: POSIX :: Linux',
|
||||||
'Programming Language :: Python :: 2.7',
|
'Programming Language :: Python :: 2.7',
|
||||||
|
'Programming Language :: Python :: 3.7',
|
||||||
'Topic :: Utilities',
|
'Topic :: Utilities',
|
||||||
],
|
],
|
||||||
keywords='sonic SONiC platform PLATFORM',
|
keywords='sonic SONiC platform PLATFORM',
|
||||||
|
@ -68,6 +68,7 @@ class Chassis(ChassisBase):
|
|||||||
self.sfp_module_initialized = False
|
self.sfp_module_initialized = False
|
||||||
self.sfp_event_initialized = False
|
self.sfp_event_initialized = False
|
||||||
self.reboot_cause_initialized = False
|
self.reboot_cause_initialized = False
|
||||||
|
self.sdk_handle = None
|
||||||
logger.log_info("Chassis loaded successfully")
|
logger.log_info("Chassis loaded successfully")
|
||||||
|
|
||||||
|
|
||||||
@ -75,7 +76,7 @@ class Chassis(ChassisBase):
|
|||||||
if self.sfp_event_initialized:
|
if self.sfp_event_initialized:
|
||||||
self.sfp_event.deinitialize()
|
self.sfp_event.deinitialize()
|
||||||
|
|
||||||
if self.sfp_module_initialized:
|
if self.sdk_handle:
|
||||||
from sonic_platform.sfp import deinitialize_sdk_handle
|
from sonic_platform.sfp import deinitialize_sdk_handle
|
||||||
deinitialize_sdk_handle(self.sdk_handle)
|
deinitialize_sdk_handle(self.sdk_handle)
|
||||||
|
|
||||||
@ -115,11 +116,6 @@ class Chassis(ChassisBase):
|
|||||||
from sonic_platform.sfp import initialize_sdk_handle
|
from sonic_platform.sfp import initialize_sdk_handle
|
||||||
|
|
||||||
self.sfp_module = SFP
|
self.sfp_module = SFP
|
||||||
self.sdk_handle = initialize_sdk_handle()
|
|
||||||
|
|
||||||
if self.sdk_handle is None:
|
|
||||||
self.sfp_module_initialized = False
|
|
||||||
return
|
|
||||||
|
|
||||||
# Initialize SFP list
|
# Initialize SFP list
|
||||||
port_position_tuple = self._get_port_position_tuple_by_platform_name()
|
port_position_tuple = self._get_port_position_tuple_by_platform_name()
|
||||||
@ -130,15 +126,23 @@ class Chassis(ChassisBase):
|
|||||||
|
|
||||||
for index in range(self.PORT_START, self.PORT_END + 1):
|
for index in range(self.PORT_START, self.PORT_END + 1):
|
||||||
if index in range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1):
|
if index in range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1):
|
||||||
sfp_module = SFP(index, 'QSFP', self.sdk_handle, self.platform_name)
|
sfp_module = SFP(index, 'QSFP', self.get_sdk_handle, self.platform_name)
|
||||||
else:
|
else:
|
||||||
sfp_module = SFP(index, 'SFP', self.sdk_handle, self.platform_name)
|
sfp_module = SFP(index, 'SFP', self.get_sdk_handle, self.platform_name)
|
||||||
|
|
||||||
self._sfp_list.append(sfp_module)
|
self._sfp_list.append(sfp_module)
|
||||||
|
|
||||||
self.sfp_module_initialized = True
|
self.sfp_module_initialized = True
|
||||||
|
|
||||||
|
|
||||||
|
def get_sdk_handle(self):
|
||||||
|
if not self.sdk_handle:
|
||||||
|
self.sdk_handle = initialize_sdk_handle()
|
||||||
|
if self.sdk_handle is None:
|
||||||
|
logger.log_error('Failed to open SDK handle')
|
||||||
|
return self.sdk_handle
|
||||||
|
|
||||||
|
|
||||||
def initialize_thermals(self):
|
def initialize_thermals(self):
|
||||||
from sonic_platform.thermal import initialize_chassis_thermals
|
from sonic_platform.thermal import initialize_chassis_thermals
|
||||||
# Initialize thermals
|
# Initialize thermals
|
||||||
@ -146,7 +150,7 @@ class Chassis(ChassisBase):
|
|||||||
|
|
||||||
|
|
||||||
def initialize_eeprom(self):
|
def initialize_eeprom(self):
|
||||||
from eeprom import Eeprom
|
from .eeprom import Eeprom
|
||||||
# Initialize EEPROM
|
# Initialize EEPROM
|
||||||
self._eeprom = Eeprom()
|
self._eeprom = Eeprom()
|
||||||
# Get chassis name and model from eeprom
|
# Get chassis name and model from eeprom
|
||||||
@ -385,11 +389,11 @@ class Chassis(ChassisBase):
|
|||||||
if not self.reboot_cause_initialized:
|
if not self.reboot_cause_initialized:
|
||||||
self.initialize_reboot_cause()
|
self.initialize_reboot_cause()
|
||||||
|
|
||||||
for reset_file, reset_cause in self.reboot_major_cause_dict.iteritems():
|
for reset_file, reset_cause in self.reboot_major_cause_dict.items():
|
||||||
if self._verify_reboot_cause(reset_file):
|
if self._verify_reboot_cause(reset_file):
|
||||||
return reset_cause, ''
|
return reset_cause, ''
|
||||||
|
|
||||||
for reset_file, reset_cause in self.reboot_minor_cause_dict.iteritems():
|
for reset_file, reset_cause in self.reboot_minor_cause_dict.items():
|
||||||
if self._verify_reboot_cause(reset_file):
|
if self._verify_reboot_cause(reset_file):
|
||||||
return self.REBOOT_CAUSE_HARDWARE_OTHER, reset_cause
|
return self.REBOOT_CAUSE_HARDWARE_OTHER, reset_cause
|
||||||
|
|
||||||
@ -410,7 +414,7 @@ class Chassis(ChassisBase):
|
|||||||
"""
|
"""
|
||||||
for s in self._sfp_list:
|
for s in self._sfp_list:
|
||||||
try:
|
try:
|
||||||
print "index {} tx disable {} dom {} calibration {} temp {} volt {} power (tx {} rx {})".format(s.index,
|
print("index {} tx disable {} dom {} calibration {} temp {} volt {} power (tx {} rx {})".format(s.index,
|
||||||
s.dom_tx_disable_supported,
|
s.dom_tx_disable_supported,
|
||||||
s.dom_supported,
|
s.dom_supported,
|
||||||
s.calibration,
|
s.calibration,
|
||||||
@ -418,9 +422,9 @@ class Chassis(ChassisBase):
|
|||||||
s.dom_volt_supported,
|
s.dom_volt_supported,
|
||||||
s.dom_rx_power_supported,
|
s.dom_rx_power_supported,
|
||||||
s.dom_tx_power_supported
|
s.dom_tx_power_supported
|
||||||
)
|
))
|
||||||
except:
|
except:
|
||||||
print "fail to retrieve capabilities for module index {}".format(s.index)
|
print("fail to retrieve capabilities for module index {}".format(s.index))
|
||||||
|
|
||||||
|
|
||||||
def get_change_event(self, timeout=0):
|
def get_change_event(self, timeout=0):
|
||||||
|
@ -5,17 +5,20 @@
|
|||||||
#
|
#
|
||||||
# implementation of new platform api
|
# implementation of new platform api
|
||||||
#############################################################################
|
#############################################################################
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import os
|
import os
|
||||||
import io
|
import io
|
||||||
import re
|
import re
|
||||||
|
import sys
|
||||||
import glob
|
import glob
|
||||||
import tempfile
|
import tempfile
|
||||||
import subprocess
|
import subprocess
|
||||||
import ConfigParser
|
if sys.version_info[0] > 2:
|
||||||
|
import configparser
|
||||||
|
else:
|
||||||
|
import ConfigParser as configparser
|
||||||
|
|
||||||
from sonic_platform_base.component_base import ComponentBase
|
from sonic_platform_base.component_base import ComponentBase
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
@ -52,7 +55,7 @@ class MPFAManager(object):
|
|||||||
contents_path = tempfile.mkdtemp(prefix='mpfa-')
|
contents_path = tempfile.mkdtemp(prefix='mpfa-')
|
||||||
|
|
||||||
cmd = self.MPFA_EXTRACT_COMMAND.format(mpfa_path, contents_path)
|
cmd = self.MPFA_EXTRACT_COMMAND.format(mpfa_path, contents_path)
|
||||||
subprocess.check_call(cmd.split())
|
subprocess.check_call(cmd.split(), universal_newlines=True)
|
||||||
|
|
||||||
self.__contents_path = contents_path
|
self.__contents_path = contents_path
|
||||||
|
|
||||||
@ -62,7 +65,7 @@ class MPFAManager(object):
|
|||||||
if not os.path.isfile(metadata_path):
|
if not os.path.isfile(metadata_path):
|
||||||
raise RuntimeError("MPFA metadata doesn't exist: path={}".format(metadata_path))
|
raise RuntimeError("MPFA metadata doesn't exist: path={}".format(metadata_path))
|
||||||
|
|
||||||
cp = ConfigParser.ConfigParser()
|
cp = configparser.ConfigParser()
|
||||||
with io.open(metadata_path, 'r') as metadata_ini:
|
with io.open(metadata_path, 'r') as metadata_ini:
|
||||||
cp.readfp(metadata_ini)
|
cp.readfp(metadata_ini)
|
||||||
|
|
||||||
@ -79,7 +82,7 @@ class MPFAManager(object):
|
|||||||
def cleanup(self):
|
def cleanup(self):
|
||||||
if os.path.exists(self.__contents_path):
|
if os.path.exists(self.__contents_path):
|
||||||
cmd = self.MPFA_CLEANUP_COMMAND.format(self.__contents_path)
|
cmd = self.MPFA_CLEANUP_COMMAND.format(self.__contents_path)
|
||||||
subprocess.check_call(cmd.split())
|
subprocess.check_call(cmd.split(), universal_newlines=True)
|
||||||
|
|
||||||
self.__contents_path = None
|
self.__contents_path = None
|
||||||
self.__metadata = None
|
self.__metadata = None
|
||||||
@ -117,11 +120,14 @@ class ONIEUpdater(object):
|
|||||||
self.__umount_onie_fs()
|
self.__umount_onie_fs()
|
||||||
|
|
||||||
cmd = "fdisk -l | grep 'ONIE boot' | awk '{print $1}'"
|
cmd = "fdisk -l | grep 'ONIE boot' | awk '{print $1}'"
|
||||||
fs_path = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True).rstrip('\n')
|
fs_path = subprocess.check_output(cmd,
|
||||||
|
stderr=subprocess.STDOUT,
|
||||||
|
shell=True,
|
||||||
|
universal_newlines=True).rstrip('\n')
|
||||||
|
|
||||||
os.mkdir(fs_mountpoint)
|
os.mkdir(fs_mountpoint)
|
||||||
cmd = "mount -n -r -t ext4 {} {}".format(fs_path, fs_mountpoint)
|
cmd = "mount -n -r -t ext4 {} {}".format(fs_path, fs_mountpoint)
|
||||||
subprocess.check_call(cmd, shell=True)
|
subprocess.check_call(cmd, shell=True, universal_newlines=True)
|
||||||
|
|
||||||
fs_onie_path = os.path.join(fs_mountpoint, 'onie/tools/lib/onie')
|
fs_onie_path = os.path.join(fs_mountpoint, 'onie/tools/lib/onie')
|
||||||
os.symlink(fs_onie_path, onie_path)
|
os.symlink(fs_onie_path, onie_path)
|
||||||
@ -137,7 +143,7 @@ class ONIEUpdater(object):
|
|||||||
|
|
||||||
if os.path.ismount(fs_mountpoint):
|
if os.path.ismount(fs_mountpoint):
|
||||||
cmd = "umount -rf {}".format(fs_mountpoint)
|
cmd = "umount -rf {}".format(fs_mountpoint)
|
||||||
subprocess.check_call(cmd, shell=True)
|
subprocess.check_call(cmd, shell=True, universal_newlines=True)
|
||||||
|
|
||||||
if os.path.exists(fs_mountpoint):
|
if os.path.exists(fs_mountpoint):
|
||||||
os.rmdir(fs_mountpoint)
|
os.rmdir(fs_mountpoint)
|
||||||
@ -146,7 +152,7 @@ class ONIEUpdater(object):
|
|||||||
cmd = self.ONIE_FW_UPDATE_CMD_ADD.format(image_path)
|
cmd = self.ONIE_FW_UPDATE_CMD_ADD.format(image_path)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
subprocess.check_call(cmd.split())
|
subprocess.check_call(cmd.split(), universal_newlines=True)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
raise RuntimeError("Failed to stage firmware update: {}".format(str(e)))
|
raise RuntimeError("Failed to stage firmware update: {}".format(str(e)))
|
||||||
|
|
||||||
@ -154,7 +160,7 @@ class ONIEUpdater(object):
|
|||||||
cmd = self.ONIE_FW_UPDATE_CMD_REMOVE.format(os.path.basename(image_path))
|
cmd = self.ONIE_FW_UPDATE_CMD_REMOVE.format(os.path.basename(image_path))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
subprocess.check_call(cmd.split())
|
subprocess.check_call(cmd.split(), universal_newlines=True)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
raise RuntimeError("Failed to unstage firmware update: {}".format(str(e)))
|
raise RuntimeError("Failed to unstage firmware update: {}".format(str(e)))
|
||||||
|
|
||||||
@ -162,7 +168,7 @@ class ONIEUpdater(object):
|
|||||||
cmd = self.ONIE_FW_UPDATE_CMD_UPDATE
|
cmd = self.ONIE_FW_UPDATE_CMD_UPDATE
|
||||||
|
|
||||||
try:
|
try:
|
||||||
subprocess.check_call(cmd.split())
|
subprocess.check_call(cmd.split(), universal_newlines=True)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
raise RuntimeError("Failed to trigger firmware update: {}".format(str(e)))
|
raise RuntimeError("Failed to trigger firmware update: {}".format(str(e)))
|
||||||
|
|
||||||
@ -170,7 +176,9 @@ class ONIEUpdater(object):
|
|||||||
cmd = self.ONIE_FW_UPDATE_CMD_SHOW_PENDING
|
cmd = self.ONIE_FW_UPDATE_CMD_SHOW_PENDING
|
||||||
|
|
||||||
try:
|
try:
|
||||||
output = subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT).rstrip('\n')
|
output = subprocess.check_output(cmd.split(),
|
||||||
|
stderr=subprocess.STDOUT,
|
||||||
|
universal_newlines=True).rstrip('\n')
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
raise RuntimeError("Failed to get pending firmware updates: {}".format(str(e)))
|
raise RuntimeError("Failed to get pending firmware updates: {}".format(str(e)))
|
||||||
|
|
||||||
@ -255,7 +263,9 @@ class ONIEUpdater(object):
|
|||||||
cmd = self.ONIE_IMAGE_INFO_COMMAND.format(image_path)
|
cmd = self.ONIE_IMAGE_INFO_COMMAND.format(image_path)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
output = subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT).rstrip('\n')
|
output = subprocess.check_output(cmd.split(),
|
||||||
|
stderr=subprocess.STDOUT,
|
||||||
|
universal_newlines=True).rstrip('\n')
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
raise RuntimeError("Failed to get ONIE firmware info: {}".format(str(e)))
|
raise RuntimeError("Failed to get ONIE firmware info: {}".format(str(e)))
|
||||||
|
|
||||||
@ -275,7 +285,9 @@ class ONIEUpdater(object):
|
|||||||
cmd = self.ONIE_FW_UPDATE_CMD_SHOW_PENDING
|
cmd = self.ONIE_FW_UPDATE_CMD_SHOW_PENDING
|
||||||
|
|
||||||
try:
|
try:
|
||||||
output = subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT).rstrip('\n')
|
output = subprocess.check_output(cmd.split(),
|
||||||
|
stderr=subprocess.STDOUT,
|
||||||
|
universal_newlines=True).rstrip('\n')
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
raise RuntimeError("Failed to get pending firmware updates: {}".format(str(e)))
|
raise RuntimeError("Failed to get pending firmware updates: {}".format(str(e)))
|
||||||
|
|
||||||
@ -340,7 +352,11 @@ class Component(ComponentBase):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_command_result(cmdline):
|
def _get_command_result(cmdline):
|
||||||
try:
|
try:
|
||||||
proc = subprocess.Popen(cmdline, stdout=subprocess.PIPE, shell=True, stderr=subprocess.STDOUT)
|
proc = subprocess.Popen(cmdline,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
shell=True,
|
||||||
|
stderr=subprocess.STDOUT,
|
||||||
|
universal_newlines=True)
|
||||||
stdout = proc.communicate()[0]
|
stdout = proc.communicate()[0]
|
||||||
rc = proc.wait()
|
rc = proc.wait()
|
||||||
result = stdout.rstrip('\n')
|
result = stdout.rstrip('\n')
|
||||||
@ -445,7 +461,7 @@ class ComponentSSD(Component):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
print("INFO: Installing {} firmware update".format(self.name))
|
print("INFO: Installing {} firmware update".format(self.name))
|
||||||
subprocess.check_call(cmd.split())
|
subprocess.check_call(cmd.split(), universal_newlines=True)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
print("ERROR: Failed to update {} firmware: {}".format(self.name, str(e)))
|
print("ERROR: Failed to update {} firmware: {}".format(self.name, str(e)))
|
||||||
return False
|
return False
|
||||||
@ -456,7 +472,9 @@ class ComponentSSD(Component):
|
|||||||
cmd = self.SSD_INFO_COMMAND
|
cmd = self.SSD_INFO_COMMAND
|
||||||
|
|
||||||
try:
|
try:
|
||||||
output = subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT).rstrip('\n')
|
output = subprocess.check_output(cmd.split(),
|
||||||
|
stderr=subprocess.STDOUT,
|
||||||
|
universal_newlines=True).rstrip('\n')
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
raise RuntimeError("Failed to get {} info: {}".format(self.name, str(e)))
|
raise RuntimeError("Failed to get {} info: {}".format(self.name, str(e)))
|
||||||
|
|
||||||
@ -470,7 +488,9 @@ class ComponentSSD(Component):
|
|||||||
cmd = self.SSD_FIRMWARE_INFO_COMMAND.format(image_path)
|
cmd = self.SSD_FIRMWARE_INFO_COMMAND.format(image_path)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
output = subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT).rstrip('\n')
|
output = subprocess.check_output(cmd.split(),
|
||||||
|
stderr=subprocess.STDOUT,
|
||||||
|
universal_newlines=True).rstrip('\n')
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
raise RuntimeError("Failed to get {} firmware info: {}".format(self.name, str(e)))
|
raise RuntimeError("Failed to get {} firmware info: {}".format(self.name, str(e)))
|
||||||
|
|
||||||
@ -503,7 +523,9 @@ class ComponentSSD(Component):
|
|||||||
cmd = self.SSD_FIRMWARE_INFO_COMMAND.format(image_path)
|
cmd = self.SSD_FIRMWARE_INFO_COMMAND.format(image_path)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
output = subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT).rstrip('\n')
|
output = subprocess.check_output(cmd.split(),
|
||||||
|
stderr=subprocess.STDOUT,
|
||||||
|
universal_newlines=True).rstrip('\n')
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
raise RuntimeError("Failed to get {} firmware info: {}".format(self.name, str(e)))
|
raise RuntimeError("Failed to get {} firmware info: {}".format(self.name, str(e)))
|
||||||
|
|
||||||
@ -575,7 +597,9 @@ class ComponentBIOS(Component):
|
|||||||
cmd = self.BIOS_VERSION_COMMAND
|
cmd = self.BIOS_VERSION_COMMAND
|
||||||
|
|
||||||
try:
|
try:
|
||||||
version = subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT).rstrip('\n')
|
version = subprocess.check_output(cmd.split(),
|
||||||
|
stderr=subprocess.STDOUT,
|
||||||
|
universal_newlines=True).rstrip('\n')
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
raise RuntimeError("Failed to get {} version: {}".format(self.name, str(e)))
|
raise RuntimeError("Failed to get {} version: {}".format(self.name, str(e)))
|
||||||
|
|
||||||
@ -652,7 +676,7 @@ class ComponentCPLD(Component):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
print("INFO: Installing {} firmware update: path={}".format(self.name, image_path))
|
print("INFO: Installing {} firmware update: path={}".format(self.name, image_path))
|
||||||
subprocess.check_call(cmd.split())
|
subprocess.check_call(cmd.split(), universal_newlines=True)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
print("ERROR: Failed to update {} firmware: {}".format(self.name, str(e)))
|
print("ERROR: Failed to update {} firmware: {}".format(self.name, str(e)))
|
||||||
return False
|
return False
|
||||||
@ -721,7 +745,7 @@ class ComponentCPLD(Component):
|
|||||||
cpld_number = cls._read_generic_file(cls.CPLD_NUMBER_FILE, cls.CPLD_NUMBER_MAX_LENGTH)
|
cpld_number = cls._read_generic_file(cls.CPLD_NUMBER_FILE, cls.CPLD_NUMBER_MAX_LENGTH)
|
||||||
cpld_number = cpld_number.rstrip('\n')
|
cpld_number = cpld_number.rstrip('\n')
|
||||||
|
|
||||||
for cpld_idx in xrange(1, int(cpld_number) + 1):
|
for cpld_idx in range(1, int(cpld_number) + 1):
|
||||||
component_list.append(cls(cpld_idx))
|
component_list.append(cls(cpld_idx))
|
||||||
|
|
||||||
return component_list
|
return component_list
|
||||||
|
@ -144,7 +144,7 @@ class Fan(FanBase):
|
|||||||
if max_speed_in_rpm == 0:
|
if max_speed_in_rpm == 0:
|
||||||
return speed_in_rpm
|
return speed_in_rpm
|
||||||
|
|
||||||
speed = 100*speed_in_rpm/max_speed_in_rpm
|
speed = 100*speed_in_rpm//max_speed_in_rpm
|
||||||
if speed > 100:
|
if speed > 100:
|
||||||
speed = 100
|
speed = 100
|
||||||
|
|
||||||
@ -191,9 +191,9 @@ class Fan(FanBase):
|
|||||||
bus = read_str_from_file(self.psu_i2c_bus_path, raise_exception=True)
|
bus = read_str_from_file(self.psu_i2c_bus_path, raise_exception=True)
|
||||||
addr = read_str_from_file(self.psu_i2c_addr_path, raise_exception=True)
|
addr = read_str_from_file(self.psu_i2c_addr_path, raise_exception=True)
|
||||||
command = read_str_from_file(self.psu_i2c_command_path, raise_exception=True)
|
command = read_str_from_file(self.psu_i2c_command_path, raise_exception=True)
|
||||||
speed = Fan.PSU_FAN_SPEED[int(speed / 10)]
|
speed = Fan.PSU_FAN_SPEED[int(speed // 10)]
|
||||||
command = "i2cset -f -y {0} {1} {2} {3} wp".format(bus, addr, command, speed)
|
command = "i2cset -f -y {0} {1} {2} {3} wp".format(bus, addr, command, speed)
|
||||||
subprocess.check_call(command, shell = True)
|
subprocess.check_call(command, shell = True, universal_newlines=True)
|
||||||
return True
|
return True
|
||||||
except subprocess.CalledProcessError as ce:
|
except subprocess.CalledProcessError as ce:
|
||||||
logger.log_error('Failed to call command {}, return code={}, command output={}'.format(ce.cmd, ce.returncode, ce.output))
|
logger.log_error('Failed to call command {}, return code={}, command output={}'.format(ce.cmd, ce.returncode, ce.output))
|
||||||
@ -203,7 +203,7 @@ class Fan(FanBase):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
cooling_level = int(speed / 10)
|
cooling_level = int(speed // 10)
|
||||||
if cooling_level < self.min_cooling_level:
|
if cooling_level < self.min_cooling_level:
|
||||||
cooling_level = self.min_cooling_level
|
cooling_level = self.min_cooling_level
|
||||||
speed = self.min_cooling_level * 10
|
speed = self.min_cooling_level * 10
|
||||||
@ -300,5 +300,3 @@ class Fan(FanBase):
|
|||||||
return read_int_from_file(COOLING_STATE_PATH, raise_exception=True)
|
return read_int_from_file(COOLING_STATE_PATH, raise_exception=True)
|
||||||
except (ValueError, IOError) as e:
|
except (ValueError, IOError) as e:
|
||||||
raise RuntimeError("Failed to get cooling level - {}".format(e))
|
raise RuntimeError("Failed to get cooling level - {}".format(e))
|
||||||
|
|
||||||
|
|
@ -35,14 +35,18 @@ class Platform(PlatformBase):
|
|||||||
"""
|
"""
|
||||||
is_host = False
|
is_host = False
|
||||||
try:
|
try:
|
||||||
proc = subprocess.Popen("docker --version 2>/dev/null", stdout=subprocess.PIPE, shell=True, stderr=subprocess.STDOUT)
|
proc = subprocess.Popen("docker --version 2>/dev/null",
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
shell=True,
|
||||||
|
stderr=subprocess.STDOUT,
|
||||||
|
universal_newlines=True)
|
||||||
stdout = proc.communicate()[0]
|
stdout = proc.communicate()[0]
|
||||||
proc.wait()
|
proc.wait()
|
||||||
result = stdout.rstrip('\n')
|
result = stdout.rstrip('\n')
|
||||||
if result != '':
|
if result != '':
|
||||||
is_host = True
|
is_host = True
|
||||||
|
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return is_host
|
return is_host
|
||||||
|
@ -21,12 +21,20 @@ try:
|
|||||||
from sonic_platform_base.sonic_sfp.qsfp_dd import qsfp_dd_InterfaceId
|
from sonic_platform_base.sonic_sfp.qsfp_dd import qsfp_dd_InterfaceId
|
||||||
from sonic_platform_base.sonic_sfp.qsfp_dd import qsfp_dd_Dom
|
from sonic_platform_base.sonic_sfp.qsfp_dd import qsfp_dd_Dom
|
||||||
from sonic_py_common.logger import Logger
|
from sonic_py_common.logger import Logger
|
||||||
from python_sdk_api.sxd_api import *
|
|
||||||
from python_sdk_api.sx_api import *
|
|
||||||
|
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
raise ImportError (str(e) + "- required module not found")
|
raise ImportError (str(e) + "- required module not found")
|
||||||
|
|
||||||
|
try:
|
||||||
|
# python_sdk_api does not support python3 for now. Daemons like thermalctld or psud
|
||||||
|
# also import this file without actually use the sdk lib. So we catch the ImportError
|
||||||
|
# and ignore it here. Meanwhile, we have to trigger xcvrd using python2 now because it
|
||||||
|
# uses the sdk lib.
|
||||||
|
from python_sdk_api.sxd_api import *
|
||||||
|
from python_sdk_api.sx_api import *
|
||||||
|
except ImportError as e:
|
||||||
|
pass
|
||||||
|
|
||||||
# definitions of the offset and width for values in XCVR info eeprom
|
# definitions of the offset and width for values in XCVR info eeprom
|
||||||
XCVR_INTFACE_BULK_OFFSET = 0
|
XCVR_INTFACE_BULK_OFFSET = 0
|
||||||
XCVR_INTFACE_BULK_WIDTH_QSFP = 20
|
XCVR_INTFACE_BULK_WIDTH_QSFP = 20
|
||||||
@ -309,7 +317,7 @@ def deinitialize_sdk_handle(sdk_handle):
|
|||||||
class SFP(SfpBase):
|
class SFP(SfpBase):
|
||||||
"""Platform-specific SFP class"""
|
"""Platform-specific SFP class"""
|
||||||
|
|
||||||
def __init__(self, sfp_index, sfp_type, sdk_handle, platform):
|
def __init__(self, sfp_index, sfp_type, sdk_handle_getter, platform):
|
||||||
SfpBase.__init__(self)
|
SfpBase.__init__(self)
|
||||||
self.index = sfp_index + 1
|
self.index = sfp_index + 1
|
||||||
self.sfp_eeprom_path = "qsfp{}".format(self.index)
|
self.sfp_eeprom_path = "qsfp{}".format(self.index)
|
||||||
@ -317,13 +325,17 @@ class SFP(SfpBase):
|
|||||||
self._detect_sfp_type(sfp_type)
|
self._detect_sfp_type(sfp_type)
|
||||||
self.dom_tx_disable_supported = False
|
self.dom_tx_disable_supported = False
|
||||||
self._dom_capability_detect()
|
self._dom_capability_detect()
|
||||||
self.sdk_handle = sdk_handle
|
self.sdk_handle_getter = sdk_handle_getter
|
||||||
self.sdk_index = sfp_index
|
self.sdk_index = sfp_index
|
||||||
|
|
||||||
# initialize SFP thermal list
|
# initialize SFP thermal list
|
||||||
from .thermal import initialize_sfp_thermals
|
from .thermal import initialize_sfp_thermals
|
||||||
initialize_sfp_thermals(platform, self._thermal_list, self.index)
|
initialize_sfp_thermals(platform, self._thermal_list, self.index)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def sdk_handle(self):
|
||||||
|
return self.sdk_handle_getter()
|
||||||
|
|
||||||
def reinit(self):
|
def reinit(self):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -343,14 +355,18 @@ class SFP(SfpBase):
|
|||||||
presence = False
|
presence = False
|
||||||
ethtool_cmd = "ethtool -m sfp{} hex on offset 0 length 1 2>/dev/null".format(self.index)
|
ethtool_cmd = "ethtool -m sfp{} hex on offset 0 length 1 2>/dev/null".format(self.index)
|
||||||
try:
|
try:
|
||||||
proc = subprocess.Popen(ethtool_cmd, stdout=subprocess.PIPE, shell=True, stderr=subprocess.STDOUT)
|
proc = subprocess.Popen(ethtool_cmd,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
shell=True,
|
||||||
|
stderr=subprocess.STDOUT,
|
||||||
|
universal_newlines=True)
|
||||||
stdout = proc.communicate()[0]
|
stdout = proc.communicate()[0]
|
||||||
proc.wait()
|
proc.wait()
|
||||||
result = stdout.rstrip('\n')
|
result = stdout.rstrip('\n')
|
||||||
if result != '':
|
if result != '':
|
||||||
presence = True
|
presence = True
|
||||||
|
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
raise OSError("Cannot detect sfp")
|
raise OSError("Cannot detect sfp")
|
||||||
|
|
||||||
return presence
|
return presence
|
||||||
@ -361,7 +377,9 @@ class SFP(SfpBase):
|
|||||||
eeprom_raw = []
|
eeprom_raw = []
|
||||||
ethtool_cmd = "ethtool -m sfp{} hex on offset {} length {}".format(self.index, offset, num_bytes)
|
ethtool_cmd = "ethtool -m sfp{} hex on offset {} length {}".format(self.index, offset, num_bytes)
|
||||||
try:
|
try:
|
||||||
output = subprocess.check_output(ethtool_cmd, shell=True)
|
output = subprocess.check_output(ethtool_cmd,
|
||||||
|
shell=True,
|
||||||
|
universal_newlines=True)
|
||||||
output_lines = output.splitlines()
|
output_lines = output.splitlines()
|
||||||
first_line_raw = output_lines[0]
|
first_line_raw = output_lines[0]
|
||||||
if "Offset" in first_line_raw:
|
if "Offset" in first_line_raw:
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
listen to the SDK for the SFP change event and return to chassis.
|
listen to the SDK for the SFP change event and return to chassis.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from __future__ import print_function
|
|
||||||
import sys, errno
|
import sys, errno
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
@ -301,12 +301,12 @@ class sfp_event:
|
|||||||
logger.log_info("Receive PMPE plug in/out event on module {}: status {}".format(module_id, module_state))
|
logger.log_info("Receive PMPE plug in/out event on module {}: status {}".format(module_id, module_state))
|
||||||
else:
|
else:
|
||||||
logger.log_error("Receive PMPE unknown event on module {}: status {}".format(module_id, module_state))
|
logger.log_error("Receive PMPE unknown event on module {}: status {}".format(module_id, module_state))
|
||||||
for i in xrange(port_list_size):
|
for i in range(port_list_size):
|
||||||
logical_port = sx_port_log_id_t_arr_getitem(logical_port_list, i)
|
logical_port = sx_port_log_id_t_arr_getitem(logical_port_list, i)
|
||||||
rc = sx_api_port_device_get(self.handle, 1 , 0, port_attributes_list, port_cnt_p)
|
rc = sx_api_port_device_get(self.handle, 1 , 0, port_attributes_list, port_cnt_p)
|
||||||
port_cnt = uint32_t_p_value(port_cnt_p)
|
port_cnt = uint32_t_p_value(port_cnt_p)
|
||||||
|
|
||||||
for i in xrange(port_cnt):
|
for i in range(port_cnt):
|
||||||
port_attributes = sx_port_attributes_t_arr_getitem(port_attributes_list,i)
|
port_attributes = sx_port_attributes_t_arr_getitem(port_attributes_list,i)
|
||||||
if port_attributes.log_port == logical_port:
|
if port_attributes.log_port == logical_port:
|
||||||
lable_port = port_attributes.port_mapping.module_port
|
lable_port = port_attributes.port_mapping.module_port
|
||||||
|
@ -14,6 +14,7 @@ $(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SWSSSDK_PY3)
|
|||||||
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PY_COMMON_PY2)
|
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PY_COMMON_PY2)
|
||||||
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PY_COMMON_PY3)
|
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PY_COMMON_PY3)
|
||||||
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PLATFORM_API_PY2)
|
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PLATFORM_API_PY2)
|
||||||
|
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PLATFORM_API_PY3)
|
||||||
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_LEDD)
|
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_LEDD)
|
||||||
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PCIED)
|
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PCIED)
|
||||||
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PSUD)
|
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PSUD)
|
||||||
|
Loading…
Reference in New Issue
Block a user