From c1741fb20823d68cd46801c638ed6fe878d049cd Mon Sep 17 00:00:00 2001 From: junchao Date: Mon, 7 Dec 2020 10:37:14 +0800 Subject: [PATCH 1/3] [Mellanox] Add python3 support for Mellanox platform API --- .../pmon_daemon_control.json | 3 +- .../build_templates/sonic_debian_extension.j2 | 6 ++ platform/mellanox/mlnx-platform-api.dep | 4 ++ platform/mellanox/mlnx-platform-api.mk | 10 +++ platform/mellanox/mlnx-platform-api/setup.py | 1 + .../sonic_platform/chassis.py | 31 +++++---- .../sonic_platform/component.py | 68 +++++++++++++------ .../sonic_platform/eeprom.py | 2 + .../mlnx-platform-api/sonic_platform/fan.py | 10 ++- .../sonic_platform/platform.py | 8 ++- .../mlnx-platform-api/sonic_platform/sfp.py | 32 +++++++-- .../sonic_platform/sfp_event.py | 6 +- rules/docker-platform-monitor.mk | 1 + 13 files changed, 127 insertions(+), 55 deletions(-) diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/pmon_daemon_control.json b/device/mellanox/x86_64-mlnx_msn2700-r0/pmon_daemon_control.json index 86910af29e89..aa6edfe45b2d 100644 --- a/device/mellanox/x86_64-mlnx_msn2700-r0/pmon_daemon_control.json +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/pmon_daemon_control.json @@ -1,6 +1,7 @@ { "skip_ledd": true, "skip_fancontrol": true, - "delay_xcvrd": true + "delay_xcvrd": true, + "python3_daemons": ["psud", "thermalctld", "syseepromd"] } diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index 8d228958ab61..16280ebfe6a0 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -643,6 +643,12 @@ MLNX_PLATFORM_COMMON_PY2_WHEEL_NAME=$(basename {{mlnx_platform_api_py2_wheel_pat sudo cp {{mlnx_platform_api_py2_wheel_path}} $FILESYSTEM_ROOT/$MLNX_PLATFORM_COMMON_PY2_WHEEL_NAME sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip2 install $MLNX_PLATFORM_COMMON_PY2_WHEEL_NAME sudo rm -rf $FILESYSTEM_ROOT/$MLNX_PLATFORM_COMMON_PY2_WHEEL_NAME + +# Install mlnx-sonic-platform-common Python 3 package +MLNX_PLATFORM_COMMON_PY3_WHEEL_NAME=$(basename {{mlnx_platform_api_py3_wheel_path}}) +sudo cp {{mlnx_platform_api_py3_wheel_path}} $FILESYSTEM_ROOT/$MLNX_PLATFORM_COMMON_PY3_WHEEL_NAME +sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip3 install $MLNX_PLATFORM_COMMON_PY3_WHEEL_NAME +sudo rm -rf $FILESYSTEM_ROOT/$MLNX_PLATFORM_COMMON_PY3_WHEEL_NAME {% endif %} {%- if SONIC_ROUTING_STACK == "frr" %} diff --git a/platform/mellanox/mlnx-platform-api.dep b/platform/mellanox/mlnx-platform-api.dep index 865fe2a7ee4d..b66c0b9c3bdf 100644 --- a/platform/mellanox/mlnx-platform-api.dep +++ b/platform/mellanox/mlnx-platform-api.dep @@ -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)_DEP_FLAGS := $(SONIC_COMMON_FLAGS_LIST) $(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)) diff --git a/platform/mellanox/mlnx-platform-api.mk b/platform/mellanox/mlnx-platform-api.mk index b350329b00e1..e7e36c1f67b8 100644 --- a/platform/mellanox/mlnx-platform-api.mk +++ b/platform/mellanox/mlnx-platform-api.mk @@ -7,3 +7,13 @@ $(SONIC_PLATFORM_API_PY2)_DEPENDS = $(SONIC_PY_COMMON_PY2) $(SONIC_PLATFORM_COMM SONIC_PYTHON_WHEELS += $(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))" diff --git a/platform/mellanox/mlnx-platform-api/setup.py b/platform/mellanox/mlnx-platform-api/setup.py index f10f84924d2c..df1a8cadbb09 100644 --- a/platform/mellanox/mlnx-platform-api/setup.py +++ b/platform/mellanox/mlnx-platform-api/setup.py @@ -31,6 +31,7 @@ 'Natural Language :: English', 'Operating System :: POSIX :: Linux', 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3.7', 'Topic :: Utilities', ], keywords='sonic SONiC platform PLATFORM', diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py b/platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py index 84c4ac5ea9e6..81bc56da74c8 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py @@ -75,7 +75,7 @@ def __del__(self): if self.sfp_event_initialized: self.sfp_event.deinitialize() - if self.sfp_module_initialized: + if self.sdk_handle: from sonic_platform.sfp import deinitialize_sdk_handle deinitialize_sdk_handle(self.sdk_handle) @@ -115,11 +115,6 @@ def initialize_sfp(self): from sonic_platform.sfp import initialize_sdk_handle 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 port_position_tuple = self._get_port_position_tuple_by_platform_name() @@ -130,15 +125,23 @@ def initialize_sfp(self): for index in range(self.PORT_START, self.PORT_END + 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: - 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_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): from sonic_platform.thermal import initialize_chassis_thermals # Initialize thermals @@ -146,7 +149,7 @@ def initialize_thermals(self): def initialize_eeprom(self): - from eeprom import Eeprom + from .eeprom import Eeprom # Initialize EEPROM self._eeprom = Eeprom() # Get chassis name and model from eeprom @@ -385,11 +388,11 @@ def get_reboot_cause(self): if not self.reboot_cause_initialized: 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): 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): return self.REBOOT_CAUSE_HARDWARE_OTHER, reset_cause @@ -410,7 +413,7 @@ def _show_capabilities(self): """ for s in self._sfp_list: 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_supported, s.calibration, @@ -418,9 +421,9 @@ def _show_capabilities(self): s.dom_volt_supported, s.dom_rx_power_supported, s.dom_tx_power_supported - ) + )) 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): diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/component.py b/platform/mellanox/mlnx-platform-api/sonic_platform/component.py index 0552e09ae5f5..e70007e96562 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/component.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/component.py @@ -5,17 +5,20 @@ # # implementation of new platform api ############################################################################# -from __future__ import print_function try: import os import io import re + import sys import glob import tempfile 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 except ImportError as e: @@ -52,7 +55,7 @@ def __extract_contents(self, mpfa_path): contents_path = tempfile.mkdtemp(prefix='mpfa-') 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 @@ -62,7 +65,7 @@ def __parse_metadata(self, contents_path): if not os.path.isfile(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: cp.readfp(metadata_ini) @@ -79,7 +82,7 @@ def extract(self): def cleanup(self): if os.path.exists(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.__metadata = None @@ -117,11 +120,14 @@ def __mount_onie_fs(self): self.__umount_onie_fs() 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) 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') os.symlink(fs_onie_path, onie_path) @@ -137,7 +143,7 @@ def __umount_onie_fs(self): if os.path.ismount(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): os.rmdir(fs_mountpoint) @@ -146,7 +152,7 @@ def __stage_update(self, image_path): cmd = self.ONIE_FW_UPDATE_CMD_ADD.format(image_path) try: - subprocess.check_call(cmd.split()) + subprocess.check_call(cmd.split(), universal_newlines=True) except subprocess.CalledProcessError as e: raise RuntimeError("Failed to stage firmware update: {}".format(str(e))) @@ -154,7 +160,7 @@ def __unstage_update(self, image_path): cmd = self.ONIE_FW_UPDATE_CMD_REMOVE.format(os.path.basename(image_path)) try: - subprocess.check_call(cmd.split()) + subprocess.check_call(cmd.split(), universal_newlines=True) except subprocess.CalledProcessError as e: raise RuntimeError("Failed to unstage firmware update: {}".format(str(e))) @@ -162,7 +168,7 @@ def __trigger_update(self): cmd = self.ONIE_FW_UPDATE_CMD_UPDATE try: - subprocess.check_call(cmd.split()) + subprocess.check_call(cmd.split(), universal_newlines=True) except subprocess.CalledProcessError as e: raise RuntimeError("Failed to trigger firmware update: {}".format(str(e))) @@ -170,7 +176,9 @@ def __is_update_staged(self, image_path): cmd = self.ONIE_FW_UPDATE_CMD_SHOW_PENDING 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: raise RuntimeError("Failed to get pending firmware updates: {}".format(str(e))) @@ -255,7 +263,9 @@ def get_onie_firmware_info(self, image_path): cmd = self.ONIE_IMAGE_INFO_COMMAND.format(image_path) 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: raise RuntimeError("Failed to get ONIE firmware info: {}".format(str(e))) @@ -275,7 +285,9 @@ def update_firmware(self, image_path): cmd = self.ONIE_FW_UPDATE_CMD_SHOW_PENDING 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: raise RuntimeError("Failed to get pending firmware updates: {}".format(str(e))) @@ -340,7 +352,11 @@ def _read_generic_file(filename, len, ignore_errors=False): @staticmethod def _get_command_result(cmdline): 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] rc = proc.wait() result = stdout.rstrip('\n') @@ -445,7 +461,7 @@ def __install_firmware(self, image_path): try: 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: print("ERROR: Failed to update {} firmware: {}".format(self.name, str(e))) return False @@ -456,7 +472,9 @@ def get_firmware_version(self): cmd = self.SSD_INFO_COMMAND 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: raise RuntimeError("Failed to get {} info: {}".format(self.name, str(e))) @@ -470,7 +488,9 @@ def get_available_firmware_version(self, image_path): cmd = self.SSD_FIRMWARE_INFO_COMMAND.format(image_path) 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: raise RuntimeError("Failed to get {} firmware info: {}".format(self.name, str(e))) @@ -503,7 +523,9 @@ def get_firmware_update_notification(self, image_path): cmd = self.SSD_FIRMWARE_INFO_COMMAND.format(image_path) 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: raise RuntimeError("Failed to get {} firmware info: {}".format(self.name, str(e))) @@ -575,7 +597,9 @@ def get_firmware_version(self): cmd = self.BIOS_VERSION_COMMAND 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: raise RuntimeError("Failed to get {} version: {}".format(self.name, str(e))) @@ -652,7 +676,7 @@ def __install_firmware(self, image_path): try: 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: print("ERROR: Failed to update {} firmware: {}".format(self.name, str(e))) return False @@ -721,7 +745,7 @@ def get_component_list(cls): cpld_number = cls._read_generic_file(cls.CPLD_NUMBER_FILE, cls.CPLD_NUMBER_MAX_LENGTH) 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)) return component_list diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/eeprom.py b/platform/mellanox/mlnx-platform-api/sonic_platform/eeprom.py index b2e588a63557..54847acfd499 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/eeprom.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/eeprom.py @@ -10,8 +10,10 @@ import re if sys.version_info.major == 3: + import builtins as exceptions from io import StringIO else: + import exceptions from cStringIO import StringIO from sonic_py_common.logger import Logger diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/fan.py b/platform/mellanox/mlnx-platform-api/sonic_platform/fan.py index 78e79ca5133b..cad7d014e0f7 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/fan.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/fan.py @@ -144,7 +144,7 @@ def get_speed(self): if max_speed_in_rpm == 0: 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: speed = 100 @@ -191,9 +191,9 @@ def set_speed(self, speed): 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) 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) - subprocess.check_call(command, shell = True) + subprocess.check_call(command, shell = True, universal_newlines=True) return True except subprocess.CalledProcessError as ce: logger.log_error('Failed to call command {}, return code={}, command output={}'.format(ce.cmd, ce.returncode, ce.output)) @@ -203,7 +203,7 @@ def set_speed(self, speed): return False try: - cooling_level = int(speed / 10) + cooling_level = int(speed // 10) if cooling_level < self.min_cooling_level: cooling_level = self.min_cooling_level speed = self.min_cooling_level * 10 @@ -300,5 +300,3 @@ def get_cooling_level(cls): return read_int_from_file(COOLING_STATE_PATH, raise_exception=True) except (ValueError, IOError) as e: raise RuntimeError("Failed to get cooling level - {}".format(e)) - - \ No newline at end of file diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/platform.py b/platform/mellanox/mlnx-platform-api/sonic_platform/platform.py index d80c28996a7a..f2a8af954790 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/platform.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/platform.py @@ -35,14 +35,18 @@ def _is_host(self): """ is_host = False 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] proc.wait() result = stdout.rstrip('\n') if result != '': is_host = True - except OSError, e: + except OSError as e: pass return is_host diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py b/platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py index 611758daa862..4b397b3f3ff8 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/sfp.py @@ -21,12 +21,20 @@ 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_py_common.logger import Logger - from python_sdk_api.sxd_api import * - from python_sdk_api.sx_api import * except ImportError as e: 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 XCVR_INTFACE_BULK_OFFSET = 0 XCVR_INTFACE_BULK_WIDTH_QSFP = 20 @@ -309,7 +317,7 @@ def deinitialize_sdk_handle(sdk_handle): class SFP(SfpBase): """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) self.index = sfp_index + 1 self.sfp_eeprom_path = "qsfp{}".format(self.index) @@ -317,13 +325,17 @@ def __init__(self, sfp_index, sfp_type, sdk_handle, platform): self._detect_sfp_type(sfp_type) self.dom_tx_disable_supported = False self._dom_capability_detect() - self.sdk_handle = sdk_handle + self.sdk_handle_getter = sdk_handle_getter self.sdk_index = sfp_index # initialize SFP thermal list from .thermal import initialize_sfp_thermals initialize_sfp_thermals(platform, self._thermal_list, self.index) + @property + def sdk_handle(self): + return self.sdk_handle_getter() + def reinit(self): """ @@ -343,14 +355,18 @@ def get_presence(self): presence = False ethtool_cmd = "ethtool -m sfp{} hex on offset 0 length 1 2>/dev/null".format(self.index) 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] proc.wait() result = stdout.rstrip('\n') if result != '': presence = True - except OSError, e: + except OSError as e: raise OSError("Cannot detect sfp") return presence @@ -361,7 +377,9 @@ def _read_eeprom_specific_bytes(self, offset, num_bytes): eeprom_raw = [] ethtool_cmd = "ethtool -m sfp{} hex on offset {} length {}".format(self.index, offset, num_bytes) try: - output = subprocess.check_output(ethtool_cmd, shell=True) + output = subprocess.check_output(ethtool_cmd, + shell=True, + universal_newlines=True) output_lines = output.splitlines() first_line_raw = output_lines[0] if "Offset" in first_line_raw: diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/sfp_event.py b/platform/mellanox/mlnx-platform-api/sonic_platform/sfp_event.py index 29f2aee64de8..5c57e213a196 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/sfp_event.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/sfp_event.py @@ -3,7 +3,7 @@ listen to the SDK for the SFP change event and return to chassis. ''' -from __future__ import print_function + import sys, errno import os import time @@ -301,12 +301,12 @@ def on_pmpe(self, fd_p): logger.log_info("Receive PMPE plug in/out event on module {}: status {}".format(module_id, module_state)) else: 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) 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) - for i in xrange(port_cnt): + for i in range(port_cnt): port_attributes = sx_port_attributes_t_arr_getitem(port_attributes_list,i) if port_attributes.log_port == logical_port: lable_port = port_attributes.port_mapping.module_port diff --git a/rules/docker-platform-monitor.mk b/rules/docker-platform-monitor.mk index bb816a6619b8..3ac40d4d1909 100644 --- a/rules/docker-platform-monitor.mk +++ b/rules/docker-platform-monitor.mk @@ -23,6 +23,7 @@ $(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_XCVRD) ifeq ($(PDDF_SUPPORT),y) $(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(PDDF_PLATFORM_API_BASE_PY2) endif +$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PLATFORM_API_PY3) $(DOCKER_PLATFORM_MONITOR)_DBG_DEPENDS = $($(DOCKER_CONFIG_ENGINE_BUSTER)_DBG_DEPENDS) $(DOCKER_PLATFORM_MONITOR)_DBG_DEPENDS += $(LIBSWSSCOMMON_DBG) $(LIBSENSORS_DBG) From d9d53125dfd0bfc3bac3b9ce51deee11e8ad2b4b Mon Sep 17 00:00:00 2001 From: junchao Date: Thu, 10 Dec 2020 11:15:26 +0800 Subject: [PATCH 2/3] Fix issue: sdk_handle should be defined in __init__ method --- platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py | 1 + 1 file changed, 1 insertion(+) diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py b/platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py index 81bc56da74c8..c1d93b8ffdac 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py @@ -68,6 +68,7 @@ def __init__(self): self.sfp_module_initialized = False self.sfp_event_initialized = False self.reboot_cause_initialized = False + self.sdk_handle = None logger.log_info("Chassis loaded successfully") From 3a3be0c4210aa64ba7d9b06864ecf1f04d76f39f Mon Sep 17 00:00:00 2001 From: junchao Date: Thu, 10 Dec 2020 11:47:58 +0800 Subject: [PATCH 3/3] Change python3_daemons to python2_daemons --- device/mellanox/x86_64-mlnx_msn2700-r0/pmon_daemon_control.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/pmon_daemon_control.json b/device/mellanox/x86_64-mlnx_msn2700-r0/pmon_daemon_control.json index aa6edfe45b2d..dec2ba6d7826 100644 --- a/device/mellanox/x86_64-mlnx_msn2700-r0/pmon_daemon_control.json +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/pmon_daemon_control.json @@ -2,6 +2,6 @@ "skip_ledd": true, "skip_fancontrol": true, "delay_xcvrd": true, - "python3_daemons": ["psud", "thermalctld", "syseepromd"] + "python2_daemons": ["xcvrd"] }