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 86910af29e..dec2ba6d78 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, + "python2_daemons": ["xcvrd"] } diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index 1dd11b5e3b..a1d5a9a69d 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -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 sudo chmod 755 $FILESYSTEM_ROOT/usr/bin/mlnx-fw-upgrade.sh -# Install mlnx-sonic-platform-common Python 2 package -MLNX_PLATFORM_COMMON_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 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 Python 2 package +MLNX_SONIC_PLATFORM_PY2_WHEEL_NAME=$(basename {{mlnx_platform_api_py2_wheel_path}}) +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_SONIC_PLATFORM_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 %} {%- if SONIC_ROUTING_STACK == "frr" %} diff --git a/platform/mellanox/mlnx-platform-api.dep b/platform/mellanox/mlnx-platform-api.dep index 865fe2a7ee..b66c0b9c3b 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 b350329b00..e7e36c1f67 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 f10f84924d..df1a8cadbb 100644 --- a/platform/mellanox/mlnx-platform-api/setup.py +++ b/platform/mellanox/mlnx-platform-api/setup.py @@ -31,6 +31,7 @@ setup( '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 84c4ac5ea9..c1d93b8ffd 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 @@ class Chassis(ChassisBase): 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") @@ -75,7 +76,7 @@ class Chassis(ChassisBase): 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 +116,6 @@ class Chassis(ChassisBase): 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 +126,23 @@ class Chassis(ChassisBase): 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 +150,7 @@ class Chassis(ChassisBase): 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 +389,11 @@ class Chassis(ChassisBase): 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 +414,7 @@ class Chassis(ChassisBase): """ 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 +422,9 @@ class Chassis(ChassisBase): 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 0552e09ae5..e70007e965 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 @@ class MPFAManager(object): 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 @@ class MPFAManager(object): 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 @@ class MPFAManager(object): 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 @@ class ONIEUpdater(object): 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 @@ class ONIEUpdater(object): 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 @@ class ONIEUpdater(object): 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 @@ class ONIEUpdater(object): 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 @@ class ONIEUpdater(object): 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 @@ class ONIEUpdater(object): 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 @@ class ONIEUpdater(object): 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 @@ class ONIEUpdater(object): 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 @@ class Component(ComponentBase): @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 @@ class ComponentSSD(Component): 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 @@ class ComponentSSD(Component): 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 @@ class ComponentSSD(Component): 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 @@ class ComponentSSD(Component): 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 @@ class ComponentBIOS(Component): 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 @@ class ComponentCPLD(Component): 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 @@ class ComponentCPLD(Component): 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/fan.py b/platform/mellanox/mlnx-platform-api/sonic_platform/fan.py index 78e79ca513..cad7d014e0 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 @@ class Fan(FanBase): 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 @@ class Fan(FanBase): 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 @@ class Fan(FanBase): 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 @@ class Fan(FanBase): 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 d80c28996a..f2a8af9547 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 @@ class Platform(PlatformBase): """ 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 611758daa8..4b397b3f3f 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 @@ try: 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 @@ class SFP(SfpBase): 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 @@ class SFP(SfpBase): 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 @@ class SFP(SfpBase): 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 29f2aee64d..5c57e213a1 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 @@ class sfp_event: 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 bb816a6619..2abc68ff4c 100644 --- a/rules/docker-platform-monitor.mk +++ b/rules/docker-platform-monitor.mk @@ -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_PY3) $(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_PCIED) $(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PSUD)