diff --git a/build_debian.sh b/build_debian.sh index cbb4a559e78b..f94f1665f570 100755 --- a/build_debian.sh +++ b/build_debian.sh @@ -275,7 +275,6 @@ sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y in ntpstat \ openssh-server \ python \ - python-jsonschema \ python-apt \ traceroute \ iputils-ping \ diff --git a/dockers/docker-platform-monitor/Dockerfile.j2 b/dockers/docker-platform-monitor/Dockerfile.j2 index 9662f7248001..fc46dc6a52b9 100755 --- a/dockers/docker-platform-monitor/Dockerfile.j2 +++ b/dockers/docker-platform-monitor/Dockerfile.j2 @@ -24,13 +24,13 @@ RUN apt-get update && \ python3-smbus \ ethtool \ dmidecode \ - i2c-tools \ - python-jsonschema + i2c-tools # TODO: Remove these lines once we no longer need Python 2 RUN apt-get install -f -y python-dev python-pip RUN pip2 install --upgrade 'pip<21' RUN apt-get purge -y python-pip +RUN pip2 install 'setuptools==40.8.0' # On Arista devices, the sonic_platform wheel is not installed in the container. # Instead, the installation directory is mounted from the host OS. However, this method diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index b1955919149e..fd5a9735bfaf 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -193,19 +193,25 @@ sudo cp {{platform_common_py2_wheel_path}} $FILESYSTEM_ROOT/$PLATFORM_COMMON_PY2 sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip2 install $PLATFORM_COMMON_PY2_WHEEL_NAME sudo rm -rf $FILESYSTEM_ROOT/$PLATFORM_COMMON_PY2_WHEEL_NAME +# Install sonic-platform-common Python 3 package +PLATFORM_COMMON_PY3_WHEEL_NAME=$(basename {{platform_common_py3_wheel_path}}) +sudo cp {{platform_common_py3_wheel_path}} $FILESYSTEM_ROOT/$PLATFORM_COMMON_PY3_WHEEL_NAME +sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip3 install $PLATFORM_COMMON_PY3_WHEEL_NAME +sudo rm -rf $FILESYSTEM_ROOT/$PLATFORM_COMMON_PY3_WHEEL_NAME + {% if pddf_support == "y" %} # Install pddf-platform-api-base Python 2 package PLATFORM_PDDF_COMMON_PY2_WHEEL_NAME=$(basename {{pddf_platform_api_base_py2_wheel_path}}) sudo cp {{pddf_platform_api_base_py2_wheel_path}} $FILESYSTEM_ROOT/$PLATFORM_PDDF_COMMON_PY2_WHEEL_NAME sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip2 install $PLATFORM_PDDF_COMMON_PY2_WHEEL_NAME sudo rm -rf $FILESYSTEM_ROOT/$PLATFORM_PDDF_COMMON_PY2_WHEEL_NAME -{% endif %} -# Install sonic-platform-common Python 3 package -PLATFORM_COMMON_PY3_WHEEL_NAME=$(basename {{platform_common_py3_wheel_path}}) -sudo cp {{platform_common_py3_wheel_path}} $FILESYSTEM_ROOT/$PLATFORM_COMMON_PY3_WHEEL_NAME -sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip3 install $PLATFORM_COMMON_PY3_WHEEL_NAME -sudo rm -rf $FILESYSTEM_ROOT/$PLATFORM_COMMON_PY3_WHEEL_NAME +# Install pddf-platform-api-base Python 3 package +PLATFORM_PDDF_COMMON_PY3_WHEEL_NAME=$(basename {{pddf_platform_api_base_py3_wheel_path}}) +sudo cp {{pddf_platform_api_base_py3_wheel_path}} $FILESYSTEM_ROOT/$PLATFORM_PDDF_COMMON_PY3_WHEEL_NAME +sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip3 install $PLATFORM_PDDF_COMMON_PY3_WHEEL_NAME +sudo rm -rf $FILESYSTEM_ROOT/$PLATFORM_PDDF_COMMON_PY3_WHEEL_NAME +{% endif %} {# Barefoot platform vendors' sonic_platform packages import the Python 'thrift' library #} {% if sonic_asic_platform == "barefoot" %} diff --git a/platform/pddf/platform-api-pddf-base.dep b/platform/pddf/platform-api-pddf-base.dep index 9184925b1e6f..aaaedb068384 100644 --- a/platform/pddf/platform-api-pddf-base.dep +++ b/platform/pddf/platform-api-pddf-base.dep @@ -7,3 +7,7 @@ DEP_FILES += $(shell git ls-files $(MPATH)) $(PDDF_PLATFORM_API_BASE_PY2)_CACHE_MODE := GIT_CONTENT_SHA $(PDDF_PLATFORM_API_BASE_PY2)_DEP_FLAGS := $(SONIC_COMMON_FLAGS_LIST) $(PDDF_PLATFORM_API_BASE_PY2)_DEP_FILES := $(DEP_FILES) + +$(PDDF_PLATFORM_API_BASE_PY3)_CACHE_MODE := GIT_CONTENT_SHA +$(PDDF_PLATFORM_API_BASE_PY3)_DEP_FLAGS := $(SONIC_COMMON_FLAGS_LIST) +$(PDDF_PLATFORM_API_BASE_PY3)_DEP_FILES := $(DEP_FILES) diff --git a/platform/pddf/platform-api-pddf-base.mk b/platform/pddf/platform-api-pddf-base.mk index 80478d4f3db1..ce818707ba7e 100644 --- a/platform/pddf/platform-api-pddf-base.mk +++ b/platform/pddf/platform-api-pddf-base.mk @@ -13,3 +13,16 @@ SONIC_PYTHON_WHEELS += $(PDDF_PLATFORM_API_BASE_PY2) export pddf_platform_api_base_py2_wheel_path="$(addprefix $(PYTHON_WHEELS_PATH)/,$(PDDF_PLATFORM_API_BASE_PY2))" export PDDF_PLATFORM_API_BASE_PY2 + +PDDF_PLATFORM_API_BASE_PY3 = sonic_platform_pddf_common-$(PDDF_PLATFORM_API_BASE_VERSION)-py3-none-any.whl +$(PDDF_PLATFORM_API_BASE_PY3)_SRC_PATH = $(PLATFORM_PDDF_PATH)/platform-api-pddf-base +$(PDDF_PLATFORM_API_BASE_PY3)_PYTHON_VERSION = 3 +$(PDDF_PLATFORM_API_BASE_PY3)_DEPENDS = $(SONIC_CONFIG_ENGINE) +# Synthetic dependency to avoid building the Python 2 and 3 packages +# simultaneously and any potential conflicts which may arise +$(PDDF_PLATFORM_API_BASE_PY3)_DEPENDS += $(PDDF_PLATFORM_API_BASE_PY2) +$(PDDF_PLATFORM_API_BASE_PY3)_TEST = n +SONIC_PYTHON_WHEELS += $(PDDF_PLATFORM_API_BASE_PY3) + +export pddf_platform_api_base_py3_wheel_path="$(addprefix $(PYTHON_WHEELS_PATH)/,$(PDDF_PLATFORM_API_BASE_PY3))" +export PDDF_PLATFORM_API_BASE_PY3 diff --git a/platform/pddf/platform-api-pddf-base/setup.py b/platform/pddf/platform-api-pddf-base/setup.py index 5f5ac9194cd9..0d8b4a6b2df2 100755 --- a/platform/pddf/platform-api-pddf-base/setup.py +++ b/platform/pddf/platform-api-pddf-base/setup.py @@ -14,6 +14,9 @@ packages=[ 'sonic_platform_pddf_base', ], + install_requires=[ + 'jsonschema==2.6.0' + ], classifiers=[ 'Development Status :: 3 - Alpha', 'Environment :: Plugins', @@ -24,6 +27,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/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_chassis.py b/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_chassis.py index 942be25ed1c7..0e77a90dbab1 100755 --- a/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_chassis.py +++ b/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_chassis.py @@ -18,6 +18,7 @@ except ImportError as e: raise ImportError(str(e) + "- required module not found") + class PddfChassis(ChassisBase): """ PDDF Generic Chassis class @@ -33,7 +34,7 @@ def __init__(self, pddf_data=None, pddf_plugin_data=None): self.plugin_data = pddf_plugin_data if pddf_plugin_data else None if not self.pddf_obj or not self.plugin_data: try: - import pddfparse + from . import pddfparse import json self.pddf_obj = pddfparse.PddfParse() with open('/usr/share/sonic/platform/pddf/pd-plugin.json') as pd: @@ -67,8 +68,8 @@ def __init__(self, pddf_data=None, pddf_plugin_data=None): thermal = Thermal(i, self.pddf_obj, self.plugin_data) self._thermal_list.append(thermal) - # SYSTEM LED Test Cases - """ + # SYSTEM LED Test Cases + """ #comment out test cases sys_led_list= { "LOC":0, "DIAG":0, @@ -90,8 +91,6 @@ def __init__(self, pddf_data=None, pddf_plugin_data=None): print "Set off: " + color """ - - def get_name(self): """ Retrieves the name of the chassis @@ -438,34 +437,32 @@ def get_sfp(self, index): # System LED methods ############################################## def set_system_led(self, led_device_name, color): - result, msg = self.pddf_obj.is_supported_sysled_state(led_device_name, color); + result, msg = self.pddf_obj.is_supported_sysled_state(led_device_name, color) if result == False: - print msg - return (False) + print(msg) + return (False) - index=self.pddf_obj.data[led_device_name]['dev_attr']['index'] - device_name=self.pddf_obj.data[led_device_name]['dev_info']['device_name'] + index = self.pddf_obj.data[led_device_name]['dev_attr']['index'] + device_name = self.pddf_obj.data[led_device_name]['dev_info']['device_name'] self.pddf_obj.create_attr('device_name', device_name, self.pddf_obj.get_led_path()) self.pddf_obj.create_attr('index', index, self.pddf_obj.get_led_path()) self.pddf_obj.create_attr('color', color, self.pddf_obj.get_led_cur_state_path()) self.pddf_obj.create_attr('dev_ops', 'set_status', self.pddf_obj.get_led_path()) return (True) - def get_system_led(self, led_device_name): - if (not led_device_name in self.pddf_obj.data.keys()): - status= "[FAILED] " + led_device_name + " is not configured" - return (status) + if led_device_name not in self.pddf_obj.data.keys(): + status = "[FAILED] " + led_device_name + " is not configured" + return (status) - index=self.pddf_obj.data[led_device_name]['dev_attr']['index'] - device_name=self.pddf_obj.data[led_device_name]['dev_info']['device_name'] + index = self.pddf_obj.data[led_device_name]['dev_attr']['index'] + device_name = self.pddf_obj.data[led_device_name]['dev_info']['device_name'] self.pddf_obj.create_attr('device_name', device_name, self.pddf_obj.get_led_path()) self.pddf_obj.create_attr('index', index, self.pddf_obj.get_led_path()) self.pddf_obj.create_attr('dev_ops', 'get_status', self.pddf_obj.get_led_path()) - color=self.pddf_obj.get_led_color() + color = self.pddf_obj.get_led_color() return (color) - ############################################## # Other methods ############################################## @@ -513,4 +510,3 @@ def get_change_event(self, timeout=0): has been inserted and sfp 11 has been removed. """ raise NotImplementedError - diff --git a/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_eeprom.py b/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_eeprom.py index 222cdcf4edd3..592485d617e4 100644 --- a/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_eeprom.py +++ b/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_eeprom.py @@ -67,47 +67,41 @@ def __init__(self, pddf_data=None, pddf_plugin_data=None): tlv_index += ord(eeprom[tlv_index+1]) + 2 def serial_number_str(self): - (is_valid, results) = self.get_tlv_field( - self.eeprom_data, self._TLV_CODE_SERIAL_NUMBER) + (is_valid, results) = self.get_tlv_field(self.eeprom_data, self._TLV_CODE_SERIAL_NUMBER) if not is_valid: return "N/A" return results[2] def base_mac_addr(self): - (is_valid, t) = self.get_tlv_field( - self.eeprom_data, self._TLV_CODE_MAC_BASE) + (is_valid, t) = self.get_tlv_field(self.eeprom_data, self._TLV_CODE_MAC_BASE) if not is_valid or t[1] != 6: return super(TlvInfoDecoder, self).switchaddrstr(e) return ":".join([binascii.b2a_hex(T) for T in t[2]]) def modelstr(self): - (is_valid, results) = self.get_tlv_field( - self.eeprom_data, self._TLV_CODE_PRODUCT_NAME) + (is_valid, results) = self.get_tlv_field(self.eeprom_data, self._TLV_CODE_PRODUCT_NAME) if not is_valid: return "N/A" return results[2] def part_number_str(self): - (is_valid, results) = self.get_tlv_field( - self.eeprom_data, self._TLV_CODE_PART_NUMBER) + (is_valid, results) = self.get_tlv_field(self.eeprom_data, self._TLV_CODE_PART_NUMBER) if not is_valid: return "N/A" return results[2] def serial_str(self): - (is_valid, results) = self.get_tlv_field( - self.eeprom_data, self._TLV_CODE_SERVICE_TAG) + (is_valid, results) = self.get_tlv_field(self.eeprom_data, self._TLV_CODE_SERVICE_TAG) if not is_valid: return "N/A" return results[2] def revision_str(self): - (is_valid, results) = self.get_tlv_field( - self.eeprom_data, self._TLV_CODE_DEVICE_VERSION) + (is_valid, results) = self.get_tlv_field(self.eeprom_data, self._TLV_CODE_DEVICE_VERSION) if not is_valid: return "N/A" diff --git a/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_fan.py b/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_fan.py index f189ca2a4e2e..5930345070b4 100755 --- a/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_fan.py +++ b/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_fan.py @@ -22,7 +22,7 @@ class PddfFan(FanBase): plugin_data = {} def __init__(self, tray_idx, fan_idx=0, pddf_data=None, pddf_plugin_data=None, is_psu_fan=False, psu_index=0): - # idx is 0-based + # idx is 0-based if not pddf_data or not pddf_plugin_data: raise ValueError('PDDF JSON data error') @@ -30,12 +30,12 @@ def __init__(self, tray_idx, fan_idx=0, pddf_data=None, pddf_plugin_data=None, i self.plugin_data = pddf_plugin_data self.platform = self.pddf_obj.get_platform() - if tray_idx<0 or tray_idx>=self.platform['num_fantrays']: - print "Invalid fantray index %d\n"%tray_idx + if tray_idx < 0 or tray_idx >= self.platform['num_fantrays']: + print("Invalid fantray index %d\n" % tray_idx) return - - if fan_idx<0 or fan_idx>=self.platform['num_fans_pertray']: - print "Invalid fan index (within a tray) %d\n"%fan_idx + + if fan_idx < 0 or fan_idx >= self.platform['num_fans_pertray']: + print("Invalid fan index (within a tray) %d\n" % fan_idx) return self.fantray_index = tray_idx+1 @@ -160,7 +160,7 @@ def get_speed(self): if not output: return 0 - + output['status'] = output['status'].rstrip() if output['status'].isalpha(): return 0 @@ -185,7 +185,7 @@ def get_speed_rpm(self): output = self.pddf_obj.get_attr_name_output(device, attr) if not output: return 0 - + output['status'] = output['status'].rstrip() if output['status'].isalpha(): return 0 @@ -229,7 +229,7 @@ def get_target_speed(self): if not output: return 0 - + output['status'] = output['status'].rstrip() if output['status'].isalpha(): return 0 @@ -250,7 +250,7 @@ def get_speed_tolerance(self): An integer, the percentage of variance from target speed which is considered tolerable """ - # Fix the speed vairance to 10 percent. If it changes based on platforms, overwrite + # Fix the speed vairance to 10 percent. If it changes based on platforms, overwrite # this value in derived pddf fan class return 10 @@ -266,28 +266,27 @@ def set_speed(self, speed): A boolean, True if speed is set successfully, False if not """ if self.is_psu_fan: - print "Setting PSU fan speed is not allowed" + print("Setting PSU fan speed is not allowed") return False else: - if speed<0 or speed>100: - print "Error: Invalid speed %d. Please provide a valid speed percentage"%speed + if speed < 0 or speed > 100: + print("Error: Invalid speed %d. Please provide a valid speed percentage" % speed) return False if 'duty_cycle_to_pwm' not in self.plugin_data['FAN']: - print "Setting fan speed is not allowed !" + print("Setting fan speed is not allowed !") return False else: duty_cycle_to_pwm = eval(self.plugin_data['FAN']['duty_cycle_to_pwm']) pwm = int(round(duty_cycle_to_pwm(speed))) - status = False idx = (self.fantray_index-1)*self.platform['num_fans_pertray'] + self.fan_index attr = "fan" + str(idx) + "_pwm" output = self.pddf_obj.set_attr_name_output("FAN-CTRL", attr, pwm) if not output: return False - + status = output['status'] return status @@ -296,36 +295,34 @@ def set_status_led(self, color): index = str(self.fantray_index-1) led_device_name = "FANTRAY{}".format(self.fantray_index) + "_LED" - result, msg = self.pddf_obj.is_supported_sysled_state(led_device_name, color); + result, msg = self.pddf_obj.is_supported_sysled_state(led_device_name, color) if result == False: - print msg - return (False) + print(msg) + return (False) - - device_name=self.pddf_obj.data[led_device_name]['dev_info']['device_name'] + device_name = self.pddf_obj.data[led_device_name]['dev_info']['device_name'] self.pddf_obj.create_attr('device_name', device_name, self.pddf_obj.get_led_path()) self.pddf_obj.create_attr('index', index, self.pddf_obj.get_led_path()) self.pddf_obj.create_attr('color', color, self.pddf_obj.get_led_cur_state_path()) self.pddf_obj.create_attr('dev_ops', 'set_status', self.pddf_obj.get_led_path()) return (True) - def get_status_led(self): index = str(self.fantray_index-1) fan_led_device = "FANTRAY{}".format(self.fantray_index) + "_LED" - if (not fan_led_device in self.pddf_obj.data.keys()): + if fan_led_device not in self.pddf_obj.data.keys(): # Implement a generic status_led color scheme if self.get_status(): return self.STATUS_LED_COLOR_GREEN else: return self.STATUS_LED_COLOR_OFF - device_name=self.pddf_obj.data[fan_led_device]['dev_info']['device_name'] + device_name = self.pddf_obj.data[fan_led_device]['dev_info']['device_name'] self.pddf_obj.create_attr('device_name', device_name, self.pddf_obj.get_led_path()) self.pddf_obj.create_attr('index', index, self.pddf_obj.get_led_path()) self.pddf_obj.create_attr('dev_ops', 'get_status', self.pddf_obj.get_led_path()) - color=self.pddf_obj.get_led_color() + color = self.pddf_obj.get_led_color() return (color) def dump_sysfs(self): diff --git a/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_platform.py b/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_platform.py index 20b87db99910..00eefc9a815e 100755 --- a/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_platform.py +++ b/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_platform.py @@ -10,7 +10,7 @@ try: import json - import pddfparse + from . import pddfparse from sonic_platform_base.platform_base import PlatformBase from sonic_platform.chassis import Chassis except ImportError as e: @@ -23,6 +23,7 @@ class PddfPlatform(PlatformBase): """ pddf_data = {} pddf_plugin_data = {} + def __init__(self): # Initialize the JSON data self.pddf_data = pddfparse.PddfParse() @@ -30,7 +31,7 @@ def __init__(self): self.pddf_plugin_data = json.load(pd) if not self.pddf_data or not self.pddf_plugin_data: - print "Error: PDDF JSON data is not loaded properly ... Exiting" + print("Error: PDDF JSON data is not loaded properly ... Exiting") raise ValueError PlatformBase.__init__(self) diff --git a/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_psu.py b/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_psu.py index b378be7dad39..58b69ce0aa73 100755 --- a/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_psu.py +++ b/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_psu.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# All the supported PSU SysFS aattributes are +# All the supported PSU SysFS aattributes are #- psu_present #- psu_model_name #- psu_power_good @@ -18,7 +18,7 @@ from sonic_platform_base.psu_base import PsuBase from sonic_platform.fan import Fan except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class PddfPsu(PsuBase): @@ -27,7 +27,6 @@ class PddfPsu(PsuBase): pddf_obj = {} plugin_data = {} - def __init__(self, index, pddf_data=None, pddf_plugin_data=None): PsuBase.__init__(self) if not pddf_data or not pddf_plugin_data: @@ -37,7 +36,7 @@ def __init__(self, index, pddf_data=None, pddf_plugin_data=None): self.plugin_data = pddf_plugin_data self.platform = self.pddf_obj.get_platform() self.psu_index = index + 1 - + self._fan_list = [] # _fan_list under PsuBase class is a global variable, hence we need to use _fan_list per class instatiation self.num_psu_fans = int(self.pddf_obj.get_num_psu_fans('PSU{}'.format(index+1))) for psu_fan_idx in range(self.num_psu_fans): @@ -75,11 +74,11 @@ def get_presence(self): status = 0 device = "PSU{}".format(self.psu_index) output = self.pddf_obj.get_attr_name_output(device, "psu_present") - if not output: - return False + if not output: + return False mode = output['mode'] - status = output['status'] + status = output['status'] vmap = self.plugin_data['PSU']['psu_present'][mode]['valmap'] @@ -98,7 +97,7 @@ def get_model(self): device = "PSU{}".format(self.psu_index) output = self.pddf_obj.get_attr_name_output(device, "psu_model_name") if not output: - return None + return None model = output['status'] @@ -118,7 +117,7 @@ def get_serial(self): device = "PSU{}".format(self.psu_index) output = self.pddf_obj.get_attr_name_output(device, "psu_serial_num") if not output: - return None + return None serial = output['status'] @@ -138,7 +137,7 @@ def get_status(self): return False mode = output['mode'] - status = output ['status'] + status = output['status'] vmap = self.plugin_data['PSU']['psu_power_good'][mode]['valmap'] @@ -157,9 +156,9 @@ def get_mfr_id(self): device = "PSU{}".format(self.psu_index) output = self.pddf_obj.get_attr_name_output(device, "psu_mfr_id") if not output: - return None + return None - mfr = output['status'] + mfr = output['status'] return mfr.rstrip('\n') @@ -171,11 +170,11 @@ def get_voltage(self): A float number, the output voltage in volts, e.g. 12.1 """ - device = "PSU{}".format(self.psu_index) + device = "PSU{}".format(self.psu_index) output = self.pddf_obj.get_attr_name_output(device, "psu_v_out") if not output: return 0.0 - + v_out = output['status'] return float(v_out)/1000 @@ -230,12 +229,12 @@ def set_status_led(self, color): index = str(self.psu_index-1) led_device_name = "PSU{}".format(self.psu_index) + "_LED" - result, msg = self.pddf_obj.is_supported_sysled_state(led_device_name, color); + result, msg = self.pddf_obj.is_supported_sysled_state(led_device_name, color) if result == False: - print msg - return (False) + print(msg) + return (False) - device_name=self.pddf_obj.data[led_device_name]['dev_info']['device_name'] + device_name = self.pddf_obj.data[led_device_name]['dev_info']['device_name'] self.pddf_obj.create_attr('device_name', device_name, self.pddf_obj.get_led_path()) self.pddf_obj.create_attr('index', index, self.pddf_obj.get_led_path()) self.pddf_obj.create_attr('color', color, self.pddf_obj.get_led_cur_state_path()) @@ -245,18 +244,18 @@ def set_status_led(self, color): def get_status_led(self): index = str(self.psu_index-1) psu_led_device = "PSU{}_LED".format(self.psu_index) - if (not psu_led_device in self.pddf_obj.data.keys()): + if psu_led_device not in self.pddf_obj.data.keys(): # Implement a generic status_led color scheme if self.get_powergood_status(): return self.STATUS_LED_COLOR_GREEN else: return self.STATUS_LED_COLOR_OFF - device_name=self.pddf_obj.data[psu_led_device]['dev_info']['device_name'] + device_name = self.pddf_obj.data[psu_led_device]['dev_info']['device_name'] self.pddf_obj.create_attr('device_name', device_name, self.pddf_obj.get_led_path()) self.pddf_obj.create_attr('index', index, self.pddf_obj.get_led_path()) self.pddf_obj.create_attr('dev_ops', 'get_status', self.pddf_obj.get_led_path()) - color=self.pddf_obj.get_led_color() + color = self.pddf_obj.get_led_color() return (color) def get_input_voltage(self): diff --git a/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_sfp.py b/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_sfp.py index d53c23061b2d..dc37bba6e888 100755 --- a/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_sfp.py +++ b/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_sfp.py @@ -10,8 +10,8 @@ from sonic_platform_base.sonic_sfp.sff8472 import sff8472Dom from sonic_platform_base.sonic_sfp.sff8472 import sffbase from sonic_platform_base.sonic_sfp.inf8628 import inf8628InterfaceId -except ImportError, e: - raise ImportError (str(e) + "- required module not found") +except ImportError as e: + raise ImportError(str(e) + "- required module not found") # definitions of the offset and width for values in XCVR info eeprom XCVR_INTFACE_BULK_OFFSET = 0 @@ -58,7 +58,7 @@ OSFP_HW_REV_OFFSET = 164 OSFP_VENDOR_SN_OFFSET = 166 -#definitions of the offset and width for values in DOM info eeprom +# definitions of the offset and width for values in DOM info eeprom QSFP_DOM_REV_OFFSET = 1 QSFP_DOM_REV_WIDTH = 1 QSFP_TEMPE_OFFSET = 22 @@ -107,10 +107,10 @@ 'LengthCable(UnitsOfm)', 'LengthOM3(UnitsOf10m)') sfp_compliance_code_tup = ('10GEthernetComplianceCode', 'InfinibandComplianceCode', - 'ESCONComplianceCodes', 'SONETComplianceCodes', - 'EthernetComplianceCodes','FibreChannelLinkLength', - 'FibreChannelTechnology', 'SFP+CableTechnology', - 'FibreChannelTransmissionMedia','FibreChannelSpeed') + 'ESCONComplianceCodes', 'SONETComplianceCodes', + 'EthernetComplianceCodes', 'FibreChannelLinkLength', + 'FibreChannelTechnology', 'SFP+CableTechnology', + 'FibreChannelTransmissionMedia', 'FibreChannelSpeed') qsfp_compliance_code_tup = ('10/40G Ethernet Compliance Code', 'SONET Compliance codes', 'SAS/SATA compliance codes', 'Gigabit Ethernet Compliant codes', @@ -126,6 +126,7 @@ DOM_OFFSET = 0 DOM_OFFSET1 = 384 + class PddfSfp(SfpBase): """ PDDF generic Sfp class @@ -154,7 +155,7 @@ def __read_eeprom_specific_bytes(self, offset, num_bytes): for n in range(0, num_bytes): eeprom_raw[n] = hex(ord(raw[n]))[2:].zfill(2) except Exception as e: - print "Error: Unable to open eeprom_path: %s"%(str(e)) + print("Error: Unable to open eeprom_path: %s" % (str(e))) finally: if sysfsfile_eeprom: sysfsfile_eeprom.close() @@ -174,29 +175,29 @@ def __init__(self, index, pddf_data=None, pddf_plugin_data=None): self._port_start = 0 self._port_end = int(self.platform['num_ports']) if index < self._port_start or index >= self._port_end: - print "Invalid port index %d"%index - return + print("Invalid port index %d" % index) + return self.port_index = index+1 self.device = 'PORT{}'.format(self.port_index) self.sfp_type = self.pddf_obj.get_device_type(self.device) - self.is_qsfp_port = True if (self.sfp_type=='QSFP' or self.sfp_type=='QSFP28') else False - self.is_osfp_port = True if (self.sfp_type=='OSFP' or self.sfp_type=='QSFP-DD') else False + self.is_qsfp_port = True if (self.sfp_type == 'QSFP' or self.sfp_type == 'QSFP28') else False + self.is_osfp_port = True if (self.sfp_type == 'OSFP' or self.sfp_type == 'QSFP-DD') else False self.eeprom_path = self.pddf_obj.get_path(self.device, 'eeprom') - self.info_dict_keys = ['type', 'hardware_rev', 'serial', 'manufacturer', 'model', 'connector', 'encoding', - 'ext_identifier', 'ext_rateselect_compliance', 'cable_type', 'cable_length', 'nominal_bit_rate', - 'specification_compliance', 'vendor_date', 'vendor_oui', 'application_advertisement'] + self.info_dict_keys = ['type', 'hardware_rev', 'serial', 'manufacturer', 'model', 'connector', 'encoding', + 'ext_identifier', 'ext_rateselect_compliance', 'cable_type', 'cable_length', 'nominal_bit_rate', + 'specification_compliance', 'vendor_date', 'vendor_oui', 'application_advertisement'] self.dom_dict_keys = ['rx_los', 'tx_fault', 'reset_status', 'power_lpmode', 'tx_disable', 'tx_disable_channel', - 'temperature', 'voltage', 'rx1power', 'rx2power', 'rx3power', 'rx4power', 'tx1bias', 'tx2bias', - 'tx3bias', 'tx4bias', 'tx1power', 'tx2power', 'tx3power', 'tx4power'] + 'temperature', 'voltage', 'rx1power', 'rx2power', 'rx3power', 'rx4power', 'tx1bias', 'tx2bias', + 'tx3bias', 'tx4bias', 'tx1power', 'tx2power', 'tx3power', 'tx4power'] - self.threshold_dict_keys = ['temphighalarm', 'temphighwarning', 'templowalarm', 'templowwarning', - 'vcchighalarm', 'vcchighwarning', 'vcclowalarm', 'vcclowwarning', 'rxpowerhighalarm', - 'rxpowerhighwarning', 'rxpowerlowalarm', 'rxpowerlowwarning', 'txpowerhighalarm', 'txpowerhighwarning', - 'txpowerlowalarm', 'txpowerlowwarning', 'txbiashighalarm', 'txbiashighwarning', 'txbiaslowalarm', - 'txbiaslowwarning'] + self.threshold_dict_keys = ['temphighalarm', 'temphighwarning', 'templowalarm', 'templowwarning', + 'vcchighalarm', 'vcchighwarning', 'vcclowalarm', 'vcclowwarning', 'rxpowerhighalarm', + 'rxpowerhighwarning', 'rxpowerlowalarm', 'rxpowerlowwarning', 'txpowerhighalarm', 'txpowerhighwarning', + 'txpowerlowalarm', 'txpowerlowwarning', 'txbiashighalarm', 'txbiashighwarning', 'txbiaslowalarm', + 'txbiaslowwarning'] SfpBase.__init__(self) @@ -226,9 +227,8 @@ def get_transceiver_info(self): ======================================================================== """ # check present status - if not self.get_presence(): - return None - + if not self.get_presence(): + return None if self.is_osfp_port: sfpi_obj = inf8628InterfaceId() @@ -267,7 +267,6 @@ def get_transceiver_info(self): if sfpi_obj is None: return None - if self.is_osfp_port: sfp_type_raw = self.__read_eeprom_specific_bytes((offset + type_offset), XCVR_TYPE_WIDTH) @@ -275,19 +274,21 @@ def get_transceiver_info(self): sfp_type_data = sfpi_obj.parse_sfp_type(sfp_type_raw, 0) sfp_type_abbrv_name = sfpi_obj.parse_sfp_type_abbrv_name(sfp_typ_raw, 0) else: - sfp_interface_bulk_raw = self.__read_eeprom_specific_bytes((offset + XCVR_INTFACE_BULK_OFFSET), interface_info_bulk_width) + sfp_interface_bulk_raw = self.__read_eeprom_specific_bytes( + (offset + XCVR_INTFACE_BULK_OFFSET), interface_info_bulk_width) if sfp_interface_bulk_raw is not None: sfp_interface_bulk_data = sfpi_obj.parse_sfp_info_bulk(sfp_interface_bulk_raw, 0) - sfp_vendor_oui_raw = self.__read_eeprom_specific_bytes((offset + XCVR_VENDOR_OUI_OFFSET), XCVR_VENDOR_OUI_WIDTH) + sfp_vendor_oui_raw = self.__read_eeprom_specific_bytes( + (offset + XCVR_VENDOR_OUI_OFFSET), XCVR_VENDOR_OUI_WIDTH) if sfp_vendor_oui_raw is not None: sfp_vendor_oui_data = sfpi_obj.parse_vendor_oui(sfp_vendor_oui_raw, 0) - sfp_vendor_date_raw = self.__read_eeprom_specific_bytes((offset + XCVR_VENDOR_DATE_OFFSET), XCVR_VENDOR_DATE_WIDTH) + sfp_vendor_date_raw = self.__read_eeprom_specific_bytes( + (offset + XCVR_VENDOR_DATE_OFFSET), XCVR_VENDOR_DATE_WIDTH) if sfp_vendor_date_raw is not None: sfp_vendor_date_data = sfpi_obj.parse_vendor_date(sfp_vendor_date_raw, 0) - sfp_vendor_name_raw = self.__read_eeprom_specific_bytes( (offset + vendor_name_offset), XCVR_VENDOR_NAME_WIDTH) sfp_vendor_name_data = sfpi_obj.parse_vendor_name( @@ -327,7 +328,8 @@ def get_transceiver_info(self): xcvr_info_dict['hardware_rev'] = sfp_vendor_rev_data['data']['Vendor Rev']['value'] if sfp_vendor_rev_data else 'N/A' xcvr_info_dict['serial'] = sfp_vendor_sn_data['data']['Vendor SN']['value'] if sfp_vendor_sn_data else 'N/A' xcvr_info_dict['vendor_oui'] = sfp_vendor_oui_data['data']['Vendor OUI']['value'] if sfp_vendor_oui_data else 'N/A' - xcvr_info_dict['vendor_date'] = sfp_vendor_date_data['data']['VendorDataCode(YYYY-MM-DD Lot)']['value'] if sfp_vendor_date_data else 'N/A' + xcvr_info_dict['vendor_date'] = sfp_vendor_date_data['data'][ + 'VendorDataCode(YYYY-MM-DD Lot)']['value'] if sfp_vendor_date_data else 'N/A' xcvr_info_dict['cable_type'] = "Unknown" xcvr_info_dict['cable_length'] = "Unknown" @@ -342,9 +344,10 @@ def get_transceiver_info(self): compliance_code_dict[key] = sfp_interface_bulk_data['data']['Specification compliance']['value'][key]['value'] xcvr_info_dict['specification_compliance'] = str(compliance_code_dict) - nkey='Nominal Bit Rate(100Mbs)' + nkey = 'Nominal Bit Rate(100Mbs)' if nkey in sfp_interface_bulk_data['data']: - xcvr_info_dict['nominal_bit_rate'] = str(sfp_interface_bulk_data['data']['Nominal Bit Rate(100Mbs)']['value']) + xcvr_info_dict['nominal_bit_rate'] = str( + sfp_interface_bulk_data['data']['Nominal Bit Rate(100Mbs)']['value']) else: xcvr_info_dict['nominal_bit_rate'] = 'N/A' elif sfp_type == 'OSFP': @@ -360,7 +363,8 @@ def get_transceiver_info(self): compliance_code_dict[key] = sfp_interface_bulk_data['data']['Specification compliance']['value'][key]['value'] xcvr_info_dict['specification_compliance'] = str(compliance_code_dict) - xcvr_info_dict['nominal_bit_rate'] = str(sfp_interface_bulk_data['data']['NominalSignallingRate(UnitsOf100Mbd)']['value']) + xcvr_info_dict['nominal_bit_rate'] = str( + sfp_interface_bulk_data['data']['NominalSignallingRate(UnitsOf100Mbd)']['value']) return xcvr_info_dict @@ -419,19 +423,19 @@ def get_transceiver_bulk_status(self): else: return None - dom_temperature_raw = self.__read_eeprom_specific_bytes( (offset + QSFP_TEMPE_OFFSET), QSFP_TEMPE_WIDTH) + dom_temperature_raw = self.__read_eeprom_specific_bytes((offset + QSFP_TEMPE_OFFSET), QSFP_TEMPE_WIDTH) if dom_temperature_raw is not None: dom_temperature_data = sfpd_obj.parse_temperature(dom_temperature_raw, 0) else: return None - dom_voltage_raw = self.__read_eeprom_specific_bytes( (offset + QSFP_VOLT_OFFSET), QSFP_VOLT_WIDTH) + dom_voltage_raw = self.__read_eeprom_specific_bytes((offset + QSFP_VOLT_OFFSET), QSFP_VOLT_WIDTH) if dom_voltage_raw is not None: dom_voltage_data = sfpd_obj.parse_voltage(dom_voltage_raw, 0) else: return None - qsfp_dom_rev_raw = self.__read_eeprom_specific_bytes( (offset + QSFP_DOM_REV_OFFSET), QSFP_DOM_REV_WIDTH) + qsfp_dom_rev_raw = self.__read_eeprom_specific_bytes((offset + QSFP_DOM_REV_OFFSET), QSFP_DOM_REV_WIDTH) if qsfp_dom_rev_raw is not None: qsfp_dom_rev_data = sfpd_obj.parse_sfp_dom_rev(qsfp_dom_rev_raw, 0) else: @@ -446,7 +450,8 @@ def get_transceiver_bulk_status(self): qsfp_dom_rev = qsfp_dom_rev_data['data']['dom_rev']['value'] qsfp_tx_power_support = qspf_dom_capability_data['data']['Tx_power_support']['value'] if (qsfp_dom_rev[0:8] != 'SFF-8636' or (qsfp_dom_rev[0:8] == 'SFF-8636' and qsfp_tx_power_support != 'on')): - dom_channel_monitor_raw = self.__read_eeprom_specific_bytes((offset + QSFP_CHANNL_MON_OFFSET), QSFP_CHANNL_MON_WIDTH) + dom_channel_monitor_raw = self.__read_eeprom_specific_bytes( + (offset + QSFP_CHANNL_MON_OFFSET), QSFP_CHANNL_MON_WIDTH) if dom_channel_monitor_raw is not None: dom_channel_monitor_data = sfpd_obj.parse_channel_monitor_params(dom_channel_monitor_raw, 0) else: @@ -457,13 +462,14 @@ def get_transceiver_bulk_status(self): xcvr_dom_info_dict['tx3power'] = 'N/A' xcvr_dom_info_dict['tx4power'] = 'N/A' else: - dom_channel_monitor_raw = self.__read_eeprom_specific_bytes((offset + QSFP_CHANNL_MON_OFFSET), QSFP_CHANNL_MON_WITH_TX_POWER_WIDTH) + dom_channel_monitor_raw = self.__read_eeprom_specific_bytes( + (offset + QSFP_CHANNL_MON_OFFSET), QSFP_CHANNL_MON_WITH_TX_POWER_WIDTH) if dom_channel_monitor_raw is not None: - dom_channel_monitor_data = sfpd_obj.parse_channel_monitor_params_with_tx_power(dom_channel_monitor_raw, 0) + dom_channel_monitor_data = sfpd_obj.parse_channel_monitor_params_with_tx_power( + dom_channel_monitor_raw, 0) else: return None - xcvr_dom_info_dict['tx1power'] = dom_channel_monitor_data['data']['TX1Power']['value'] xcvr_dom_info_dict['tx2power'] = dom_channel_monitor_data['data']['TX2Power']['value'] xcvr_dom_info_dict['tx3power'] = dom_channel_monitor_data['data']['TX3Power']['value'] @@ -489,19 +495,20 @@ def get_transceiver_bulk_status(self): if sfpd_obj is None: return None - dom_temperature_raw = self.__read_eeprom_specific_bytes( (offset + SFP_TEMPE_OFFSET), SFP_TEMPE_WIDTH) + dom_temperature_raw = self.__read_eeprom_specific_bytes((offset + SFP_TEMPE_OFFSET), SFP_TEMPE_WIDTH) if dom_temperature_raw is not None: dom_temperature_data = sfpd_obj.parse_temperature(dom_temperature_raw, 0) else: return None - dom_voltage_raw = self.__read_eeprom_specific_bytes( (offset + SFP_VOLT_OFFSET), SFP_VOLT_WIDTH) + dom_voltage_raw = self.__read_eeprom_specific_bytes((offset + SFP_VOLT_OFFSET), SFP_VOLT_WIDTH) if dom_voltage_raw is not None: dom_voltage_data = sfpd_obj.parse_voltage(dom_voltage_raw, 0) else: return None - dom_channel_monitor_raw = self.__read_eeprom_specific_bytes( (offset + SFP_CHANNL_MON_OFFSET), SFP_CHANNL_MON_WIDTH) + dom_channel_monitor_raw = self.__read_eeprom_specific_bytes( + (offset + SFP_CHANNL_MON_OFFSET), SFP_CHANNL_MON_WIDTH) if dom_channel_monitor_raw is not None: dom_channel_monitor_data = sfpd_obj.parse_channel_monitor_params(dom_channel_monitor_raw, 0) else: @@ -527,7 +534,6 @@ def get_transceiver_bulk_status(self): xcvr_dom_info_dict['reset_status'] = self.get_reset_status() xcvr_dom_info_dict['lp_mode'] = self.get_lpmode() - return xcvr_dom_info_dict def get_transceiver_threshold_info(self): @@ -591,7 +597,8 @@ def get_transceiver_threshold_info(self): xcvr_dom_threshold_info_dict['vcchighwarning'] = module_threshold_data['VccHighWarning']['value'] xcvr_dom_threshold_info_dict['vcclowwarning'] = module_threshold_data['VccLowWarning']['value'] - dom_thres_raw = self.__read_eeprom_specific_bytes(QSFP_CHANNEL_THRESHOLD_OFFSET, QSFP_CHANNEL_THRESHOLD_WIDTH) + dom_thres_raw = self.__read_eeprom_specific_bytes( + QSFP_CHANNEL_THRESHOLD_OFFSET, QSFP_CHANNEL_THRESHOLD_WIDTH) if dom_thres_raw: channel_threshold_values = sfpd_obj.parse_channel_threshold_values( dom_thres_raw, 0) @@ -647,8 +654,6 @@ def get_transceiver_threshold_info(self): xcvr_dom_threshold_info_dict['rxpowerhighwarning'] = dom_module_threshold_data['data']['RXPowerHighWarning']['value'] xcvr_dom_threshold_info_dict['rxpowerlowwarning'] = dom_module_threshold_data['data']['RXPowerLowWarning']['value'] - - return xcvr_dom_threshold_info_dict def get_reset_status(self): @@ -668,7 +673,7 @@ def get_reset_status(self): status = int(output['status'].rstrip()) - if status==1: + if status == 1: reset_status = True else: reset_status = False @@ -715,13 +720,13 @@ def get_rx_los(self): else: status = int(output['status'].rstrip()) - if status==1: + if status == 1: rx_los = True else: rx_los = False return rx_los - + def get_tx_fault(self): """ Retrieves the TX fault status of SFP @@ -761,7 +766,7 @@ def get_tx_fault(self): else: status = int(output['status'].rstrip()) - if status==1: + if status == 1: tx_fault = True else: tx_fault = False @@ -821,7 +826,7 @@ def get_tx_disable(self): else: status = int(output['status'].rstrip()) - if status==1: + if status == 1: tx_disable = True else: tx_disable = False @@ -852,7 +857,7 @@ def get_tx_disable_channel(self): tx_disabled |= 1 << i return tx_disabled else: - # SFP doesnt support this + # SFP doesnt support this return 0 def get_lpmode(self): @@ -884,13 +889,15 @@ def get_lpmode(self): status = ord(eeprom.read(1)) if ((status & 0x3) == 0x3): - lpmode = True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 + # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 + lpmode = True else: - lpmode = False # High Power Mode if one of the following conditions is matched: - # 1. "Power override" bit is 0 - # 2. "Power override" bit is 1 and "Power set" bit is 0 + # High Power Mode if one of the following conditions is matched: + # 1. "Power override" bit is 0 + # 2. "Power override" bit is 1 and "Power set" bit is 0 + lpmode = False except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False finally: if eeprom is not None: @@ -919,7 +926,6 @@ def get_power_override(self): if not self.get_presence(): return power_override - if self.is_osfp_port: pass elif self.is_qsfp_port: @@ -1032,7 +1038,7 @@ def reset(self): # TODO: Implement a wrapper set function to write the sequence path = self.pddf_obj.get_path(device, 'xcvr_reset') - # TODO: put the optic based reset logic using EEPROM + # TODO: put the optic based reset logic using EEPROM if path is None: pass else: @@ -1040,7 +1046,7 @@ def reset(self): f = open(path, 'r+') except IOError as e: return False - + try: f.seek(0) f.write('1') @@ -1054,7 +1060,7 @@ def reset(self): status = False return status - + def tx_disable(self, tx_disable): """ Disable SFP TX for all channels @@ -1087,13 +1093,13 @@ def tx_disable(self, tx_disable): eeprom_f.seek(QSFP_CONTROL_OFFSET) eeprom_f.write(buf[0]) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False finally: if eeprom_f is not None: eeprom_f.close() time.sleep(0.01) - + status = True else: status_control_raw = self.__read_eeprom_specific_bytes( @@ -1113,7 +1119,7 @@ def tx_disable(self, tx_disable): eeprom_f.seek(SFP_STATUS_CONTROL_OFFSET) eeprom_f.write(buf[0]) except Exception as e: - print("Error: unable to open file: %s" % str(e)) + print(("Error: unable to open file: %s" % str(e))) return False finally: if eeprom_f: @@ -1168,7 +1174,7 @@ def tx_disable_channel(self, channel, disable): eeprom_f.seek(QSFP_CONTROL_OFFSET) eeprom_f.write(buf[0]) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False finally: if eeprom_f is not None: @@ -1208,7 +1214,7 @@ def set_lpmode(self, lpmode): return False # Fill in write buffer - regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode + regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode buffer = create_string_buffer(1) buffer[0] = chr(regval) @@ -1218,7 +1224,7 @@ def set_lpmode(self, lpmode): eeprom_f.write(buffer[0]) return True except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False finally: if eeprom_f is not None: @@ -1286,7 +1292,7 @@ def set_power_override(self, power_override, power_set): eeprom_f.seek(QSFP_POWEROVERRIDE_OFFSET) eeprom_f.write(buffer[0]) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False finally: if eeprom_f is not None: @@ -1298,14 +1304,13 @@ def set_power_override(self, power_override, power_set): return status - def get_name(self): """ Retrieves the name of the device Returns: string: The name of the device """ - # Name of the port/sfp ? + # Name of the port/sfp ? return 'PORT{}'.format(self.port_index) def get_presence(self): diff --git a/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_thermal.py b/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_thermal.py index 01cd4080db10..cd09041e152f 100755 --- a/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_thermal.py +++ b/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_thermal.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -# All the supported Temperature Sensor SysFS aattributes are +# All the supported Temperature Sensor SysFS aattributes are #- temp1_high_crit_threshold #- temp1_high_threshold #- temp1_input @@ -13,7 +13,6 @@ raise ImportError(str(e) + "- required module not found") - class PddfThermal(ThermalBase): """PDDF generic Thermal class""" pddf_obj = {} @@ -37,24 +36,23 @@ def get_name(self): if 'display_name' in self.thermal_obj['dev_attr']: return str(self.thermal_obj['dev_attr']['display_name']) # In case of errors - return (self.thermal_obj_name) + return (self.thermal_obj_name) def get_temperature(self): output = self.pddf_obj.get_attr_name_output(self.thermal_obj_name, "temp1_input") if not output: - return None + return None if output['status'].isalpha(): attr_value = None else: attr_value = float(output['status']) - - if output['mode']=='bmc': - return attr_value + + if output['mode'] == 'bmc': + return attr_value else: return (attr_value/float(1000)) - def get_high_threshold(self): output = self.pddf_obj.get_attr_name_output(self.thermal_obj_name, "temp1_high_threshold") if not output: @@ -65,12 +63,11 @@ def get_high_threshold(self): else: attr_value = float(output['status']) - if output['mode']=='bmc': - return attr_value + if output['mode'] == 'bmc': + return attr_value else: return (attr_value/float(1000)) - def get_low_threshold(self): output = self.pddf_obj.get_attr_name_output(self.thermal_obj_name, "temp1_low_threshold") if not output: @@ -80,31 +77,29 @@ def get_low_threshold(self): attr_value = None else: attr_value = float(output['status']) - - if output['mode']=='bmc': - return attr_value + + if output['mode'] == 'bmc': + return attr_value else: return (attr_value/float(1000)) - def set_high_threshold(self, temperature): node = self.pddf_obj.get_path(self.thermal_obj_name, "temp1_high_threshold") if node is None: - print "ERROR %s does not exist"%node + print("ERROR %s does not exist" % node) return None - - cmd = "echo '%d' > %s"%(temperature * 1000, node) - os.system(cmd) - return (True) + cmd = "echo '%d' > %s" % (temperature * 1000, node) + os.system(cmd) + return (True) def set_low_threshold(self, temperature): node = self.pddf_obj.get_path(self.thermal_obj_name, "temp1_low_threshold") if node is None: - print "ERROR %s does not exist"%node + print("ERROR %s does not exist" % node) return None - cmd = "echo '%d' > %s"%(temperature * 1000, node) + cmd = "echo '%d' > %s" % (temperature * 1000, node) os.system(cmd) return (True) @@ -126,12 +121,11 @@ def get_high_critical_threshold(self): else: attr_value = float(output['status']) - if output['mode']=='bmc': + if output['mode'] == 'bmc': return attr_value else: return (attr_value/float(1000)) - def get_low_critical_threshold(self): """ Retrieves the low critical threshold temperature of thermal @@ -149,26 +143,25 @@ def get_low_critical_threshold(self): else: attr_value = float(output['status']) - if output['mode']=='bmc': + if output['mode'] == 'bmc': return attr_value else: return (attr_value/float(1000)) - # Helper Functions + def get_temp_label(self): - if 'bmc' in self.pddf_obj.data[self.thermal_obj_name].keys(): - return None + if 'bmc' in self.pddf_obj.data[self.thermal_obj_name].keys(): + return None else: if self.thermal_obj_name in self.pddf_obj.data.keys(): - dev= self.pddf_obj.data[self.thermal_obj_name] + dev = self.pddf_obj.data[self.thermal_obj_name] topo_info = dev['i2c']['topo_info'] - label="%s-i2c-%d-%x" % (topo_info['dev_type'], int(topo_info['parent_bus'], 0), - int(topo_info['dev_addr'], 0)) - return (label) + label = "%s-i2c-%d-%x" % (topo_info['dev_type'], int(topo_info['parent_bus'], 0), + int(topo_info['dev_addr'], 0)) + return (label) else: return None - def dump_sysfs(self): return self.pddf_obj.cli_dump_dsysfs('temp-sensors') diff --git a/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddfparse.py b/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddfparse.py index aa47beaa0fc7..6ca59206fd56 100755 --- a/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddfparse.py +++ b/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddfparse.py @@ -8,24 +8,24 @@ import time import unicodedata -bmc_cache={} -cache={} +bmc_cache = {} +cache = {} SONIC_CFGGEN_PATH = '/usr/local/bin/sonic-cfggen' HWSKU_KEY = 'DEVICE_METADATA.localhost.hwsku' PLATFORM_KEY = 'DEVICE_METADATA.localhost.platform' -dirname=os.path.dirname(os.path.realpath(__file__)) +dirname = os.path.dirname(os.path.realpath(__file__)) color_map = { - "STATUS_LED_COLOR_GREEN" : "green", - "STATUS_LED_COLOR_RED" : "red", - "STATUS_LED_COLOR_AMBER" : "amber", - "STATUS_LED_COLOR_BLUE" : "blue", - "STATUS_LED_COLOR_GREEN_BLINK" : "blinking green", - "STATUS_LED_COLOR_RED_BLINK" : "blinking red", - "STATUS_LED_COLOR_AMBER_BLINK" : "blinking amber", - "STATUS_LED_COLOR_BLUE_BLINK" : "blinking blue", - "STATUS_LED_COLOR_OFF" : "off" + "STATUS_LED_COLOR_GREEN": "green", + "STATUS_LED_COLOR_RED": "red", + "STATUS_LED_COLOR_AMBER": "amber", + "STATUS_LED_COLOR_BLUE": "blue", + "STATUS_LED_COLOR_GREEN_BLINK": "blinking green", + "STATUS_LED_COLOR_RED_BLINK": "blinking red", + "STATUS_LED_COLOR_AMBER_BLINK": "blinking amber", + "STATUS_LED_COLOR_BLUE_BLINK": "blinking blue", + "STATUS_LED_COLOR_OFF": "off" } @@ -37,17 +37,16 @@ def __init__(self): try: with open('/usr/share/sonic/platform/pddf/pddf-device.json') as f: - self.data = json.load(f) + self.data = json.load(f) except IOError: if os.path.exists('/usr/share/sonic/platform'): os.unlink("/usr/share/sonic/platform") - - self.data_sysfs_obj={} - self.sysfs_obj={} - + self.data_sysfs_obj = {} + self.sysfs_obj = {} # Returns platform and HW SKU + def get_platform_and_hwsku(self): try: proc = subprocess.Popen([SONIC_CFGGEN_PATH, '-H', '-v', PLATFORM_KEY], @@ -65,7 +64,7 @@ def get_platform_and_hwsku(self): stdout = proc.communicate()[0] proc.wait() hwsku = stdout.rstrip('\n') - except OSError, e: + except OSError as e: raise OSError("Cannot detect platform") return (platform, hwsku) @@ -75,16 +74,15 @@ def get_platform_and_hwsku(self): ################################################################################################################# def runcmd(self, cmd): rc = os.system(cmd) - if rc!=0: - print "%s -- command failed"%cmd - return rc + if rc != 0: + print("%s -- command failed" % cmd) + return rc def get_dev_idx(self, dev, ops): - parent=dev['dev_info']['virt_parent'] - pdev=self.data[parent] - - return pdev['dev_attr']['dev_idx'] + parent = dev['dev_info']['virt_parent'] + pdev = self.data[parent] + return pdev['dev_attr']['dev_idx'] def get_path(self, target, attr): aa = target + attr @@ -95,88 +93,85 @@ def get_path(self, target, attr): string = None p = re.search(r'\d+$', target) if p is None: - for bb in filter(re.compile(target).search,self.data.keys()): - path = self.dev_parse(self.data[bb], { "cmd": "show_attr", "target":bb, "attr":attr }) + for bb in filter(re.compile(target).search, self.data.keys()): + path = self.dev_parse(self.data[bb], {"cmd": "show_attr", "target": bb, "attr": attr}) if path != "": string = path else: if target in self.data.keys(): - path = self.dev_parse(self.data[target], { "cmd": "show_attr", "target":target, "attr":attr }) + path = self.dev_parse(self.data[target], {"cmd": "show_attr", "target": target, "attr": attr}) if path != "": string = path - if string is not None: string = string.rstrip() - cache[aa]=string + cache[aa] = string return string - def get_device_type(self, key): - if not key in self.data.keys(): - return None + if key not in self.data.keys(): + return None return self.data[key]['dev_info']['device_type'] def get_platform(self): return self.data['PLATFORM'] def get_num_psu_fans(self, dev): - if not dev in self.data.keys(): + if dev not in self.data.keys(): return 0 - if not 'num_psu_fans' in self.data[dev]['dev_attr']: + if 'num_psu_fans' not in self.data[dev]['dev_attr']: return 0 - + return self.data[dev]['dev_attr']['num_psu_fans'] - def get_led_path(self): - return ("pddf/devices/led") + def get_led_path(self): + return ("pddf/devices/led") - def get_led_cur_state_path(self): - return ("pddf/devices/led/cur_state") + def get_led_cur_state_path(self): + return ("pddf/devices/led/cur_state") - def get_led_color(self): - color_f="/sys/kernel/pddf/devices/led/cur_state/color" + def get_led_color(self): + color_f = "/sys/kernel/pddf/devices/led/cur_state/color" try: - with open(color_f, 'r') as f: - color = f.read().strip("\r\n") + with open(color_f, 'r') as f: + color = f.read().strip("\r\n") except IOError: - return ("Error") + return ("Error") - return (color_map[color]) + return (color_map[color]) - def get_led_color_devtype(self, key): - attr_list=self.data[key]['i2c']['attr_list'] + attr_list = self.data[key]['i2c']['attr_list'] for attr in attr_list: if 'attr_devtype' in attr: - return attr['attr_devtype'].strip() + return attr['attr_devtype'].strip() else: - return 'cpld' + return 'cpld' def get_led_color_from_gpio(self, led_device_name): - attr_list=self.data[led_device_name]['i2c']['attr_list'] - attr=attr_list[0] + attr_list = self.data[led_device_name]['i2c']['attr_list'] + attr = attr_list[0] if ':' in attr['bits']: - bits_list=attr['bits'].split(':') + bits_list = attr['bits'].split(':') bits_list.sort(reverse=True) - max_bit=int(bits_list[0]) + max_bit = int(bits_list[0]) else: - max_bit=0 - base_offset=int(attr['swpld_addr_offset'], 16) + max_bit = 0 + base_offset = int(attr['swpld_addr_offset'], 16) value = 0 bit = 0 while bit <= max_bit: - offset=base_offset + bit + offset = base_offset + bit if 'attr_devname' in attr: attr_path = self.get_gpio_attr_path(self.data[attr['attr_devname']], hex(offset)) else: - status= "[FAILED] attr_devname is not configured" - return (status) + status = "[FAILED] attr_devname is not configured" + return (status) if not os.path.exists(attr_path): - status= "[FAILED] {} does not exist".format(attr_path) - return (status) + status = "[FAILED] {} does not exist".format(attr_path) + return (status) cmd = 'cat ' + attr_path gpio_value = subprocess.check_output(cmd, shell=True) value |= int(gpio_value) << bit @@ -184,110 +179,107 @@ def get_led_color_from_gpio(self, led_device_name): for attr in attr_list: if int(attr['value'].strip(), 16) == value: - return(color_map[attr['attr_name']]) - return (color_map['STATUS_LED_COLOR_OFF']) - + return(color_map[attr['attr_name']]) + return (color_map['STATUS_LED_COLOR_OFF']) def get_led_color_from_cpld(self, led_device_name): - index=self.data[led_device_name]['dev_attr']['index'] - device_name=self.data[led_device_name]['dev_info']['device_name'] + index = self.data[led_device_name]['dev_attr']['index'] + device_name = self.data[led_device_name]['dev_info']['device_name'] self.create_attr('device_name', device_name, self.get_led_path()) self.create_attr('index', index, self.get_led_path()) self.create_attr('dev_ops', 'get_status', self.get_led_path()) return self.get_led_color() def set_led_color_from_gpio(self, led_device_name, color): - attr_list=self.data[led_device_name]['i2c']['attr_list'] + attr_list = self.data[led_device_name]['i2c']['attr_list'] for attr in attr_list: if attr['attr_name'].strip() == color.strip(): - base_offset=int(attr['swpld_addr_offset'], 16) - if ':' in attr['bits']: - bits_list=attr['bits'].split(':') - bits_list.sort(reverse=True) - max_bit = int(bits_list[0]) - else: - max_bit=0 - value=int(attr['value'], 16) - i = 0 - while i <= max_bit: - _value =(value>>i) & 1 - base_offset += i - attr_path = self.get_gpio_attr_path(self.data[attr['attr_devname']], hex(base_offset)) - i += 1 - try: - cmd = "echo {} > {}".format(_value, attr_path) - self.runcmd(cmd) - except Exception as e: - print "Invalid gpio path : " + attr_path - return (False) + base_offset = int(attr['swpld_addr_offset'], 16) + if ':' in attr['bits']: + bits_list = attr['bits'].split(':') + bits_list.sort(reverse=True) + max_bit = int(bits_list[0]) + else: + max_bit = 0 + value = int(attr['value'], 16) + i = 0 + while i <= max_bit: + _value = (value >> i) & 1 + base_offset += i + attr_path = self.get_gpio_attr_path(self.data[attr['attr_devname']], hex(base_offset)) + i += 1 + try: + cmd = "echo {} > {}".format(_value, attr_path) + self.runcmd(cmd) + except Exception as e: + print("Invalid gpio path : " + attr_path) + return (False) return (True) def set_led_color_from_cpld(self, led_device_name, color): - index=self.data[led_device_name]['dev_attr']['index'] - device_name=self.data[led_device_name]['dev_info']['device_name'] + index = self.data[led_device_name]['dev_attr']['index'] + device_name = self.data[led_device_name]['dev_info']['device_name'] self.create_attr('device_name', device_name, self.get_led_path()) self.create_attr('index', index, self.get_led_path()) self.create_attr('color', color, self.get_led_cur_state_path()) self.create_attr('dev_ops', 'set_status', self.get_led_path()) - return (True) - + return (True) def get_system_led_color(self, led_device_name): - if (not led_device_name in self.data.keys()): - status= "[FAILED] " + led_device_name + " is not configured" + if led_device_name not in self.data.keys(): + status = "[FAILED] " + led_device_name + " is not configured" return (status) type = self.get_led_color_devtype(led_device_name) if type == 'gpio': - color = self.get_led_color_from_gpio(led_device_name) - elif type == 'cpld': - color = self.get_led_color_from_cpld(led_device_name) + color = self.get_led_color_from_gpio(led_device_name) + elif type == 'cpld': + color = self.get_led_color_from_cpld(led_device_name) return color def set_system_led_color(self, led_device_name, color): - result, msg = self.is_supported_sysled_state(led_device_name, color); + result, msg = self.is_supported_sysled_state(led_device_name, color) if result == False: - print msg - return (result) + print(msg) + return (result) type = self.get_led_color_devtype(led_device_name) if type == 'gpio': - return (self.set_led_color_from_gpio(led_device_name, color)) - else: - return (self.set_led_color_from_cpld(led_device_name, color)) + return (self.set_led_color_from_gpio(led_device_name, color)) + else: + return (self.set_led_color_from_cpld(led_device_name, color)) ################################################################################################################### # SHOW ATTRIBIUTES DEFS ################################################################################################################### def is_led_device_configured(self, device_name, attr_name): if device_name in self.data.keys(): - attr_list=self.data[device_name]['i2c']['attr_list'] + attr_list = self.data[device_name]['i2c']['attr_list'] for attr in attr_list: if attr['attr_name'].strip() == attr_name.strip(): return (True) return (False) - def show_device_sysfs(self, dev, ops): - parent=dev['dev_info']['device_parent'] - pdev=self.data[parent] + parent = dev['dev_info']['device_parent'] + pdev = self.data[parent] if pdev['dev_info']['device_parent'] == 'SYSTEM': - return "/sys/bus/i2c/devices/"+"i2c-%d"%int(pdev['i2c']['topo_info']['dev_addr'], 0) + return "/sys/bus/i2c/devices/"+"i2c-%d" % int(pdev['i2c']['topo_info']['dev_addr'], 0) return self.show_device_sysfs(pdev, ops) + "/" + "i2c-%d" % int(dev['i2c']['topo_info']['parent_bus'], 0) + # This is alid for 'at24' type of EEPROM devices. Only one attribtue 'eeprom' - # This is alid for 'at24' type of EEPROM devices. Only one attribtue 'eeprom' def show_attr_eeprom_device(self, dev, ops): str = "" - attr_name=ops['attr'] - attr_list=dev['i2c']['attr_list'] - KEY="eeprom" - dsysfs_path="" + attr_name = ops['attr'] + attr_list = dev['i2c']['attr_list'] + KEY = "eeprom" + dsysfs_path = "" - if not KEY in self.data_sysfs_obj: - self.data_sysfs_obj[KEY]=[] + if KEY not in self.data_sysfs_obj: + self.data_sysfs_obj[KEY] = [] for attr in attr_list: if attr_name == attr['attr_name'] or attr_name == 'all': @@ -297,28 +289,27 @@ def show_attr_eeprom_device(self, dev, ops): real_name = attr['attr_name'] dsysfs_path = self.show_device_sysfs(dev, ops) + \ - "/%d-00%x"%(int(dev['i2c']['topo_info']['parent_bus'], 0), - int(dev['i2c']['topo_info']['dev_addr'], 0)) + \ - "/%s"%real_name - if not dsysfs_path in self.data_sysfs_obj[KEY]: + "/%d-00%x" % (int(dev['i2c']['topo_info']['parent_bus'], 0), + int(dev['i2c']['topo_info']['dev_addr'], 0)) + \ + "/%s" % real_name + if dsysfs_path not in self.data_sysfs_obj[KEY]: self.data_sysfs_obj[KEY].append(dsysfs_path) str += dsysfs_path+"\n" return str def show_attr_gpio_device(self, dev, ops): ret = "" - KEY="gpio" - if not KEY in self.data_sysfs_obj: - self.data_sysfs_obj[KEY]=[] + KEY = "gpio" + if KEY not in self.data_sysfs_obj: + self.data_sysfs_obj[KEY] = [] return ret - def show_attr_mux_device(self, dev, ops): ret = "" - KEY="mux" - if not KEY in self.data_sysfs_obj: - self.data_sysfs_obj[KEY]=[] + KEY = "mux" + if KEY not in self.data_sysfs_obj: + self.data_sysfs_obj[KEY] = [] return ret @@ -330,24 +321,24 @@ def get_gpio_attr_path(self, dev, offset): return path def show_attr_psu_i2c_device(self, dev, ops): - target=ops['target'] - attr_name=ops['attr'] + target = ops['target'] + attr_name = ops['attr'] ret = "" - KEY="psu" - dsysfs_path="" + KEY = "psu" + dsysfs_path = "" - if not KEY in self.data_sysfs_obj: - self.data_sysfs_obj[KEY]=[] + if KEY not in self.data_sysfs_obj: + self.data_sysfs_obj[KEY] = [] - if target == 'all' or target == dev['dev_info']['virt_parent'] : - attr_list=dev['i2c']['attr_list'] + if target == 'all' or target == dev['dev_info']['virt_parent']: + attr_list = dev['i2c']['attr_list'] for attr in attr_list: - if attr_name == attr['attr_name'] or attr_name == 'all' : + if attr_name == attr['attr_name'] or attr_name == 'all': if 'attr_devtype' in attr.keys() and attr['attr_devtype'] == "gpio": # Check and enable the gpio from class attr_path = self.get_gpio_attr_path(self.data[attr['attr_devname']], attr['attr_offset']) if (os.path.exists(attr_path)): - if not attr_path in self.data_sysfs_obj[KEY]: + if attr_path not in self.data_sysfs_obj[KEY]: self.data_sysfs_obj[KEY].append(attr_path) ret += attr_path + '\n' else: @@ -357,29 +348,26 @@ def show_attr_psu_i2c_device(self, dev, ops): real_name = attr['attr_name'] dsysfs_path = self.show_device_sysfs(dev, ops) + \ - "/%d-00%x" %(int(dev['i2c']['topo_info']['parent_bus'], 0), - int(dev['i2c']['topo_info']['dev_addr'], 0)) + \ - "/%s"%real_name - if not dsysfs_path in self.data_sysfs_obj[KEY]: + "/%d-00%x" % (int(dev['i2c']['topo_info']['parent_bus'], 0), + int(dev['i2c']['topo_info']['dev_addr'], 0)) + \ + "/%s" % real_name + if dsysfs_path not in self.data_sysfs_obj[KEY]: self.data_sysfs_obj[KEY].append(dsysfs_path) ret += dsysfs_path+"\n" return ret - def show_attr_psu_device(self, dev, ops): - return self.show_attr_psu_i2c_device(dev, ops ) - + return self.show_attr_psu_i2c_device(dev, ops) def show_attr_fan_device(self, dev, ops): ret = "" - attr_name=ops['attr'] - attr_list=dev['i2c']['attr_list'] - KEY="fan" - dsysfs_path="" - - if not KEY in self.data_sysfs_obj: - self.data_sysfs_obj[KEY]=[] + attr_name = ops['attr'] + attr_list = dev['i2c']['attr_list'] + KEY = "fan" + dsysfs_path = "" + if KEY not in self.data_sysfs_obj: + self.data_sysfs_obj[KEY] = [] for attr in attr_list: if attr_name == attr['attr_name'] or attr_name == 'all': @@ -387,7 +375,7 @@ def show_attr_fan_device(self, dev, ops): # Check and enable the gpio from class attr_path = self.get_gpio_attr_path(self.data[attr['attr_devname']], attr['attr_offset']) if (os.path.exists(attr_path)): - if not attr_path in self.data_sysfs_obj[KEY]: + if attr_path not in self.data_sysfs_obj[KEY]: self.data_sysfs_obj[KEY].append(attr_path) ret += attr_path + '\n' else: @@ -396,11 +384,11 @@ def show_attr_fan_device(self, dev, ops): else: real_name = attr['attr_name'] - dsysfs_path= self.show_device_sysfs(dev, ops) + \ - "/%d-00%x" %(int(dev['i2c']['topo_info']['parent_bus'], 0), - int(dev['i2c']['topo_info']['dev_addr'], 0)) + \ - "/%s"%real_name - if not dsysfs_path in self.data_sysfs_obj[KEY]: + dsysfs_path = self.show_device_sysfs(dev, ops) + \ + "/%d-00%x" % (int(dev['i2c']['topo_info']['parent_bus'], 0), + int(dev['i2c']['topo_info']['dev_addr'], 0)) + \ + "/%s" % real_name + if dsysfs_path not in self.data_sysfs_obj[KEY]: self.data_sysfs_obj[KEY].append(dsysfs_path) ret += dsysfs_path+"\n" return ret @@ -408,19 +396,18 @@ def show_attr_fan_device(self, dev, ops): # This is only valid for LM75 def show_attr_temp_sensor_device(self, dev, ops): str = "" - attr_name=ops['attr'] - attr_list=dev['i2c']['attr_list'] - KEY="temp-sensors" - dsysfs_path="" - - if not KEY in self.data_sysfs_obj: - self.data_sysfs_obj[KEY]=[] + attr_name = ops['attr'] + attr_list = dev['i2c']['attr_list'] + KEY = "temp-sensors" + dsysfs_path = "" + if KEY not in self.data_sysfs_obj: + self.data_sysfs_obj[KEY] = [] for attr in attr_list: if attr_name == attr['attr_name'] or attr_name == 'all': - path = self.show_device_sysfs(dev, ops)+"/%d-00%x/" %(int(dev['i2c']['topo_info']['parent_bus'], 0), - int(dev['i2c']['topo_info']['dev_addr'], 0)) + path = self.show_device_sysfs(dev, ops)+"/%d-00%x/" % (int(dev['i2c']['topo_info']['parent_bus'], 0), + int(dev['i2c']['topo_info']['dev_addr'], 0)) if 'drv_attr_name' in attr.keys(): real_name = attr['drv_attr_name'] else: @@ -428,50 +415,48 @@ def show_attr_temp_sensor_device(self, dev, ops): if (os.path.exists(path)): full_path = glob.glob(path + 'hwmon/hwmon*/' + real_name)[0] - dsysfs_path=full_path - if not dsysfs_path in self.data_sysfs_obj[KEY]: + dsysfs_path = full_path + if dsysfs_path not in self.data_sysfs_obj[KEY]: self.data_sysfs_obj[KEY].append(dsysfs_path) str += full_path + "\n" return str def show_attr_sysstatus_device(self, dev, ops): ret = "" - attr_name=ops['attr'] - attr_list=dev['attr_list'] - KEY="sys-status" - dsysfs_path="" - - if not KEY in self.data_sysfs_obj: - self.data_sysfs_obj[KEY]=[] + attr_name = ops['attr'] + attr_list = dev['attr_list'] + KEY = "sys-status" + dsysfs_path = "" + if KEY not in self.data_sysfs_obj: + self.data_sysfs_obj[KEY] = [] for attr in attr_list: - if attr_name == attr['attr_name'] or attr_name == 'all': - dsysfs_path = "/sys/kernel/pddf/devices/sysstatus/sysstatus_data/" + attr['attr_name'] - if not dsysfs_path in self.data_sysfs_obj[KEY]: - self.data_sysfs_obj[KEY].append(dsysfs_path) - ret += dsysfs_path+"\n" + if attr_name == attr['attr_name'] or attr_name == 'all': + dsysfs_path = "/sys/kernel/pddf/devices/sysstatus/sysstatus_data/" + attr['attr_name'] + if dsysfs_path not in self.data_sysfs_obj[KEY]: + self.data_sysfs_obj[KEY].append(dsysfs_path) + ret += dsysfs_path+"\n" return ret - def show_attr_xcvr_i2c_device(self, dev, ops): - target=ops['target'] - attr_name=ops['attr'] + target = ops['target'] + attr_name = ops['attr'] ret = "" dsysfs_path = "" - KEY="xcvr" - if not KEY in self.data_sysfs_obj: - self.data_sysfs_obj[KEY]=[] + KEY = "xcvr" + if KEY not in self.data_sysfs_obj: + self.data_sysfs_obj[KEY] = [] - if target == 'all' or target == dev['dev_info']['virt_parent'] : - attr_list=dev['i2c']['attr_list'] + if target == 'all' or target == dev['dev_info']['virt_parent']: + attr_list = dev['i2c']['attr_list'] for attr in attr_list: - if attr_name == attr['attr_name'] or attr_name == 'all' : + if attr_name == attr['attr_name'] or attr_name == 'all': if 'attr_devtype' in attr.keys() and attr['attr_devtype'] == "gpio": # Check and enable the gpio from class attr_path = self.get_gpio_attr_path(self.data[attr['attr_devname']], attr['attr_offset']) if (os.path.exists(attr_path)): - if not attr_path in self.data_sysfs_obj[KEY]: + if attr_path not in self.data_sysfs_obj[KEY]: self.data_sysfs_obj[KEY].append(attr_path) ret += attr_path + '\n' else: @@ -481,238 +466,228 @@ def show_attr_xcvr_i2c_device(self, dev, ops): real_name = attr['attr_name'] dsysfs_path = self.show_device_sysfs(dev, ops) + \ - "/%d-00%x" %(int(dev['i2c']['topo_info']['parent_bus'], 0), - int(dev['i2c']['topo_info']['dev_addr'], 0)) + \ - "/%s"%real_name - if not dsysfs_path in self.data_sysfs_obj[KEY]: + "/%d-00%x" % (int(dev['i2c']['topo_info']['parent_bus'], 0), + int(dev['i2c']['topo_info']['dev_addr'], 0)) + \ + "/%s" % real_name + if dsysfs_path not in self.data_sysfs_obj[KEY]: self.data_sysfs_obj[KEY].append(dsysfs_path) ret += dsysfs_path+"\n" return ret - def show_attr_xcvr_device(self, dev, ops): - return self.show_attr_xcvr_i2c_device(dev, ops ) + return self.show_attr_xcvr_i2c_device(dev, ops) def show_attr_cpld_device(self, dev, ops): ret = "" - KEY="cpld" - if not KEY in self.data_sysfs_obj: - self.data_sysfs_obj[KEY]=[] + KEY = "cpld" + if KEY not in self.data_sysfs_obj: + self.data_sysfs_obj[KEY] = [] return ret - ################################################################################################################### # SHOW DEFS ################################################################################################################### + def check_led_cmds(self, key, ops): - name = ops['target']+'_LED' - if (ops['target']=='config' or ops['attr']=='all') or \ - (name==self.data[key]['dev_info']['device_name'] and - ops['attr']==self.data[key]['dev_attr']['index']): - return (True) - else: - return (False) + name = ops['target']+'_LED' + if (ops['target'] == 'config' or ops['attr'] == 'all') or \ + (name == self.data[key]['dev_info']['device_name'] and + ops['attr'] == self.data[key]['dev_attr']['index']): + return (True) + else: + return (False) def dump_sysfs_obj(self, obj, key_type): - if (key_type == 'keys'): - for key in obj.keys(): - print key - return + if (key_type == 'keys'): + for key in obj.keys(): + print(key) + return - for key in obj: - if (key == key_type or key_type == 'all'): - print key+":" - for entry in obj[key]: - print "\t"+entry + for key in obj: + if (key == key_type or key_type == 'all'): + print(key+":") + for entry in obj[key]: + print("\t"+entry) def add_list_sysfs_obj(self, obj, KEY, list): for sysfs in list: - if not sysfs in obj[KEY]: + if sysfs not in obj[KEY]: obj[KEY].append(sysfs) def sysfs_attr(self, key, value, path, obj, obj_key): - sysfs_path="/sys/kernel/%s/%s"%(path, key) - if not sysfs_path in obj[obj_key]: - obj[obj_key].append(sysfs_path) - + sysfs_path = "/sys/kernel/%s/%s" % (path, key) + if sysfs_path not in obj[obj_key]: + obj[obj_key].append(sysfs_path) def sysfs_device(self, attr, path, obj, obj_key): - for key in attr.keys(): - sysfs_path="/sys/kernel/%s/%s"%(path, key) - if not sysfs_path in obj[obj_key]: - obj[obj_key].append(sysfs_path) + for key in attr.keys(): + sysfs_path = "/sys/kernel/%s/%s" % (path, key) + if sysfs_path not in obj[obj_key]: + obj[obj_key].append(sysfs_path) def show_eeprom_device(self, dev, ops): - return - + return def show_mux_device(self, dev, ops): - KEY ='mux' - if not KEY in self.sysfs_obj: - self.sysfs_obj[KEY] = [] - self.sysfs_device(dev['i2c']['topo_info'], "pddf/devices/mux", self.sysfs_obj, KEY) - self.sysfs_device(dev['i2c']['dev_attr'], "pddf/devices/mux", self.sysfs_obj, KEY) - sysfs_path= "/sys/kernel/pddf/devices/mux/dev_ops" - if not sysfs_path in self.sysfs_obj[KEY]: - self.sysfs_obj[KEY].append(sysfs_path) - list=['/sys/kernel/pddf/devices/mux/i2c_type', - '/sys/kernel/pddf/devices/mux/i2c_name', - '/sys/kernel/pddf/devices/mux/error'] - self.add_list_sysfs_obj(self.sysfs_obj, KEY, list) + KEY = 'mux' + if KEY not in self.sysfs_obj: + self.sysfs_obj[KEY] = [] + self.sysfs_device(dev['i2c']['topo_info'], "pddf/devices/mux", self.sysfs_obj, KEY) + self.sysfs_device(dev['i2c']['dev_attr'], "pddf/devices/mux", self.sysfs_obj, KEY) + sysfs_path = "/sys/kernel/pddf/devices/mux/dev_ops" + if sysfs_path not in self.sysfs_obj[KEY]: + self.sysfs_obj[KEY].append(sysfs_path) + list = ['/sys/kernel/pddf/devices/mux/i2c_type', + '/sys/kernel/pddf/devices/mux/i2c_name', + '/sys/kernel/pddf/devices/mux/error'] + self.add_list_sysfs_obj(self.sysfs_obj, KEY, list) def show_gpio_device(self, dev, ops): - KEY ='gpio' - if not KEY in self.sysfs_obj: - self.sysfs_obj[KEY] = [] - self.sysfs_device(dev['i2c']['topo_info'], "pddf/devices/gpio", self.sysfs_obj, KEY) - self.sysfs_device(dev['i2c']['dev_attr'], "pddf/devices/gpio", self.sysfs_obj, KEY) - sysfs_path= "/sys/kernel/pddf/devices/gpio/dev_ops" - if not sysfs_path in self.sysfs_obj[KEY]: - self.sysfs_obj[KEY].append(sysfs_path) - list=['/sys/kernel/pddf/devices/gpio/i2c_type', - '/sys/kernel/pddf/devices/gpio/i2c_name', - '/sys/kernel/pddf/devices/gpio/error'] - self.add_list_sysfs_obj(self.sysfs_obj, KEY, list) - + KEY = 'gpio' + if KEY not in self.sysfs_obj: + self.sysfs_obj[KEY] = [] + self.sysfs_device(dev['i2c']['topo_info'], "pddf/devices/gpio", self.sysfs_obj, KEY) + self.sysfs_device(dev['i2c']['dev_attr'], "pddf/devices/gpio", self.sysfs_obj, KEY) + sysfs_path = "/sys/kernel/pddf/devices/gpio/dev_ops" + if sysfs_path not in self.sysfs_obj[KEY]: + self.sysfs_obj[KEY].append(sysfs_path) + list = ['/sys/kernel/pddf/devices/gpio/i2c_type', + '/sys/kernel/pddf/devices/gpio/i2c_name', + '/sys/kernel/pddf/devices/gpio/error'] + self.add_list_sysfs_obj(self.sysfs_obj, KEY, list) def show_psu_i2c_device(self, dev, ops): - KEY ='psu' - path='pddf/devices/psu/i2c' + KEY = 'psu' + path = 'pddf/devices/psu/i2c' if dev['i2c']['topo_info']['dev_type'] in self.data['PLATFORM']['pddf_dev_types']['PSU']: - if not KEY in self.sysfs_obj: - self.sysfs_obj[KEY] = [] - self.sysfs_device(dev['i2c']['topo_info'], path, self.sysfs_obj, KEY) - sysfs_path = "/sys/kernel/pddf/devices/psu/i2c/psu_idx" - self.sysfs_obj[KEY].append(sysfs_path) - - for attr in dev['i2c']['attr_list']: - self.sysfs_device(attr, "pddf/devices/psu/i2c", self.sysfs_obj, KEY) - sysfs_path = "/sys/kernel/pddf/devices/psu/i2c/dev_ops" - if not sysfs_path in self.sysfs_obj[KEY]: - self.sysfs_obj[KEY].append(sysfs_path) - list=['/sys/kernel/pddf/devices/psu/i2c/i2c_type', - '/sys/kernel/pddf/devices/fan/i2c/i2c_name', - '/sys/kernel/pddf/devices/psu/i2c/error', - '/sys/kernel/pddf/devices/psu/i2c/attr_ops'] - self.add_list_sysfs_obj(self.sysfs_obj, KEY, list) + if KEY not in self.sysfs_obj: + self.sysfs_obj[KEY] = [] + self.sysfs_device(dev['i2c']['topo_info'], path, self.sysfs_obj, KEY) + sysfs_path = "/sys/kernel/pddf/devices/psu/i2c/psu_idx" + self.sysfs_obj[KEY].append(sysfs_path) + for attr in dev['i2c']['attr_list']: + self.sysfs_device(attr, "pddf/devices/psu/i2c", self.sysfs_obj, KEY) + sysfs_path = "/sys/kernel/pddf/devices/psu/i2c/dev_ops" + if sysfs_path not in self.sysfs_obj[KEY]: + self.sysfs_obj[KEY].append(sysfs_path) + list = ['/sys/kernel/pddf/devices/psu/i2c/i2c_type', + '/sys/kernel/pddf/devices/fan/i2c/i2c_name', + '/sys/kernel/pddf/devices/psu/i2c/error', + '/sys/kernel/pddf/devices/psu/i2c/attr_ops'] + self.add_list_sysfs_obj(self.sysfs_obj, KEY, list) def show_psu_device(self, dev, ops): - self.show_psu_i2c_device(dev, ops ) - return + self.show_psu_i2c_device(dev, ops) + return def show_client_device(self): - KEY ='client' - if not KEY in self.sysfs_obj: - self.sysfs_obj[KEY] = [] - list=['/sys/kernel/pddf/devices/showall'] - self.add_list_sysfs_obj(self.sysfs_obj, KEY, list) - + KEY = 'client' + if KEY not in self.sysfs_obj: + self.sysfs_obj[KEY] = [] + list = ['/sys/kernel/pddf/devices/showall'] + self.add_list_sysfs_obj(self.sysfs_obj, KEY, list) def show_fan_device(self, dev, ops): - KEY ='fan' - path='pddf/devices/fan/i2c' + KEY = 'fan' + path = 'pddf/devices/fan/i2c' if dev['i2c']['topo_info']['dev_type'] in self.data['PLATFORM']['pddf_dev_types']['FAN']: - if not KEY in self.sysfs_obj: - self.sysfs_obj[KEY] = [] - - self.sysfs_device(dev['i2c']['topo_info'], path, self.sysfs_obj, KEY) - self.sysfs_device(dev['i2c']['dev_attr'], path, self.sysfs_obj, KEY) - for attr in dev['i2c']['attr_list']: - self.sysfs_device(attr, path, self.sysfs_obj, KEY) - list=['/sys/kernel/pddf/devices/fan/i2c/i2c_type', - '/sys/kernel/pddf/devices/fan/i2c/i2c_name', - '/sys/kernel/pddf/devices/fan/i2c/error', - '/sys/kernel/pddf/devices/fan/i2c/attr_ops', - '/sys/kernel/pddf/devices/fan/i2c/dev_ops'] - self.add_list_sysfs_obj(self.sysfs_obj, KEY, list) + if KEY not in self.sysfs_obj: + self.sysfs_obj[KEY] = [] + self.sysfs_device(dev['i2c']['topo_info'], path, self.sysfs_obj, KEY) + self.sysfs_device(dev['i2c']['dev_attr'], path, self.sysfs_obj, KEY) + for attr in dev['i2c']['attr_list']: + self.sysfs_device(attr, path, self.sysfs_obj, KEY) + list = ['/sys/kernel/pddf/devices/fan/i2c/i2c_type', + '/sys/kernel/pddf/devices/fan/i2c/i2c_name', + '/sys/kernel/pddf/devices/fan/i2c/error', + '/sys/kernel/pddf/devices/fan/i2c/attr_ops', + '/sys/kernel/pddf/devices/fan/i2c/dev_ops'] + self.add_list_sysfs_obj(self.sysfs_obj, KEY, list) def show_temp_sensor_device(self, dev, ops): - return + return def show_sysstatus_device(self, dev, ops): - KEY ='sysstatus' - if not KEY in self.sysfs_obj: + KEY = 'sysstatus' + if KEY not in self.sysfs_obj: self.sysfs_obj[KEY] = [] for attr in dev['attr_list']: - self.sysfs_device(attr, "pddf/devices/sysstatus", self.sysfs_obj, KEY) - sysfs_path= "/sys/kernel/pddf/devices/sysstatus/attr_ops" - if not sysfs_path in self.sysfs_obj[KEY]: - self.sysfs_obj[KEY].append(sysfs_path) - + self.sysfs_device(attr, "pddf/devices/sysstatus", self.sysfs_obj, KEY) + sysfs_path = "/sys/kernel/pddf/devices/sysstatus/attr_ops" + if sysfs_path not in self.sysfs_obj[KEY]: + self.sysfs_obj[KEY].append(sysfs_path) def show_xcvr_i2c_device(self, dev, ops): - KEY ='xcvr' + KEY = 'xcvr' if dev['i2c']['topo_info']['dev_type'] in self.data['PLATFORM']['pddf_dev_types']['PORT_MODULE']: - if not KEY in self.sysfs_obj: - self.sysfs_obj[KEY] = [] - self.sysfs_device(dev['i2c']['topo_info'], "pddf/devices/xcvr/i2c", self.sysfs_obj, KEY) - - for attr in dev['i2c']['attr_list']: - self.sysfs_device(attr, "pddf/devices/xcvr/i2c", self.sysfs_obj, KEY) - sysfs_path = "/sys/kernel/pddf/devices/xcvr/i2c/dev_ops" - if not sysfs_path in self.sysfs_obj[KEY]: - self.sysfs_obj[KEY].append(sysfs_path) - list=['/sys/kernel/pddf/devices/xcvr/i2c/i2c_type', - '/sys/kernel/pddf/devices/xcvr/i2c/i2c_name', - '/sys/kernel/pddf/devices/xcvr/i2c/error', - '/sys/kernel/pddf/devices/xcvr/i2c/attr_ops'] - self.add_list_sysfs_obj(self.sysfs_obj, KEY, list) + if KEY not in self.sysfs_obj: + self.sysfs_obj[KEY] = [] + self.sysfs_device(dev['i2c']['topo_info'], "pddf/devices/xcvr/i2c", self.sysfs_obj, KEY) + for attr in dev['i2c']['attr_list']: + self.sysfs_device(attr, "pddf/devices/xcvr/i2c", self.sysfs_obj, KEY) + sysfs_path = "/sys/kernel/pddf/devices/xcvr/i2c/dev_ops" + if sysfs_path not in self.sysfs_obj[KEY]: + self.sysfs_obj[KEY].append(sysfs_path) + list = ['/sys/kernel/pddf/devices/xcvr/i2c/i2c_type', + '/sys/kernel/pddf/devices/xcvr/i2c/i2c_name', + '/sys/kernel/pddf/devices/xcvr/i2c/error', + '/sys/kernel/pddf/devices/xcvr/i2c/attr_ops'] + self.add_list_sysfs_obj(self.sysfs_obj, KEY, list) def show_xcvr_device(self, dev, ops): - self.show_xcvr_i2c_device(dev, ops ) - return + self.show_xcvr_i2c_device(dev, ops) + return def show_cpld_device(self, dev, ops): - KEY ='cpld' + KEY = 'cpld' if dev['i2c']['topo_info']['dev_type'] in self.data['PLATFORM']['pddf_dev_types']['CPLD']: - if not KEY in self.sysfs_obj: - self.sysfs_obj[KEY] = [] - self.sysfs_device(dev['i2c']['topo_info'], "pddf/devices/cpld", self.sysfs_obj, KEY) - sysfs_path= "/sys/kernel/pddf/devices/cpld/dev_ops" - if not sysfs_path in self.sysfs_obj[KEY]: - self.sysfs_obj[KEY].append(sysfs_path) - list=['/sys/kernel/pddf/devices/cpld/i2c_type', - '/sys/kernel/pddf/devices/cpld/i2c_name', - '/sys/kernel/pddf/devices/cpld/error'] - self.add_list_sysfs_obj(self.sysfs_obj, KEY, list) + if KEY not in self.sysfs_obj: + self.sysfs_obj[KEY] = [] + self.sysfs_device(dev['i2c']['topo_info'], "pddf/devices/cpld", self.sysfs_obj, KEY) + sysfs_path = "/sys/kernel/pddf/devices/cpld/dev_ops" + if sysfs_path not in self.sysfs_obj[KEY]: + self.sysfs_obj[KEY].append(sysfs_path) + list = ['/sys/kernel/pddf/devices/cpld/i2c_type', + '/sys/kernel/pddf/devices/cpld/i2c_name', + '/sys/kernel/pddf/devices/cpld/error'] + self.add_list_sysfs_obj(self.sysfs_obj, KEY, list) def show_led_platform_device(self, key, ops): - if ops['attr']=='all' or ops['attr']=='PLATFORM': - KEY='platform' - if not KEY in self.sysfs_obj: + if ops['attr'] == 'all' or ops['attr'] == 'PLATFORM': + KEY = 'platform' + if KEY not in self.sysfs_obj: self.sysfs_obj[KEY] = [] - path='pddf/devices/platform' + path = 'pddf/devices/platform' self.sysfs_attr('num_psus', self.data['PLATFORM']['num_psus'], path, self.sysfs_obj, KEY) self.sysfs_attr('num_fantrays', self.data['PLATFORM']['num_fantrays'], path, self.sysfs_obj, KEY) def show_led_device(self, key, ops): if self.check_led_cmds(key, ops): - KEY='led' - if not KEY in self.sysfs_obj: + KEY = 'led' + if KEY not in self.sysfs_obj: self.sysfs_obj[KEY] = [] - path="pddf/devices/led" + path = "pddf/devices/led" for attr in self.data[key]['i2c']['attr_list']: - self.sysfs_attr('device_name', self.data[key]['dev_info']['device_name'],path,self.sysfs_obj,KEY) - self.sysfs_attr('swpld_addr', self.data[key]['dev_info']['device_name'],path,self.sysfs_obj,KEY) - self.sysfs_attr('swpld_addr_offset', self.data[key]['dev_info']['device_name'],path, - self.sysfs_obj, KEY) + self.sysfs_attr('device_name', self.data[key]['dev_info']['device_name'], path, self.sysfs_obj, KEY) + self.sysfs_attr('swpld_addr', self.data[key]['dev_info']['device_name'], path, self.sysfs_obj, KEY) + self.sysfs_attr('swpld_addr_offset', self.data[key]['dev_info']['device_name'], path, + self.sysfs_obj, KEY) self.sysfs_device(self.data[key]['dev_attr'], path, self.sysfs_obj, KEY) for attr_key in attr.keys(): - attr_path="pddf/devices/led/" + attr['attr_name'] + attr_path = "pddf/devices/led/" + attr['attr_name'] if (attr_key != 'attr_name' and attr_key != 'swpld_addr' and attr_key != 'swpld_addr_offset'): self.sysfs_attr(attr_key, attr[attr_key], attr_path, self.sysfs_obj, KEY) - sysfs_path="/sys/kernel/pddf/devices/led/dev_ops" - if not sysfs_path in self.sysfs_obj[KEY]: + sysfs_path = "/sys/kernel/pddf/devices/led/dev_ops" + if sysfs_path not in self.sysfs_obj[KEY]: self.sysfs_obj[KEY].append(sysfs_path) - list=['/sys/kernel/pddf/devices/led/cur_state/color', + list = ['/sys/kernel/pddf/devices/led/cur_state/color', '/sys/kernel/pddf/devices/led/cur_state/color_state'] self.add_list_sysfs_obj(self.sysfs_obj, KEY, list) - def validate_xcvr_device(self, dev, ops): devtype_list = ['optoe1', 'optoe2'] dev_attribs = ['xcvr_present', 'xcvr_reset', 'xcvr_intr_status', 'xcvr_lpmode'] @@ -723,7 +698,7 @@ def validate_xcvr_device(self, dev, ops): if 'attr_name' in attr.keys() and 'eeprom' in attr.values(): ret_val = "xcvr validation success" else: - print "xcvr validation Failed" + print("xcvr validation Failed") return elif dev['i2c']['topo_info']['dev_type'] in self.data['PLATFORM']['pddf_dev_types']['PORT_MODULE']: @@ -731,9 +706,9 @@ def validate_xcvr_device(self, dev, ops): if attr.get("attr_name") in dev_attribs: ret_val = "Success" else: - print "xcvr validation Failed" + print("xcvr validation Failed") return - print ret_val + print(ret_val) def validate_eeprom_device(self, dev, ops): devtype_list = ['24c02'] @@ -746,7 +721,7 @@ def validate_eeprom_device(self, dev, ops): for attr in dev['i2c']['attr_list']: if attr.get("attr_name") in dev_attribs: ret_val = "eeprom success" - print ret_val + print(ret_val) def validate_mux_device(self, dev, ops): devtype_list = ['pca9548', 'pca954x'] @@ -757,7 +732,7 @@ def validate_mux_device(self, dev, ops): for attr in dev['i2c']['channel']: if attr.get("chn") in dev_channels: ret_val = "Mux success" - print ret_val + print(ret_val) def validate_cpld_device(self, dev, ops): devtype_list = ['i2c_cpld'] @@ -765,20 +740,19 @@ def validate_cpld_device(self, dev, ops): if dev['i2c']['topo_info']['dev_type'] in devtype_list: ret_val = "cpld success" - print ret_val - + print(ret_val) def validate_sysstatus_device(self, dev, ops): dev_attribs = ['board_info', 'cpld1_version', 'power_module_status', 'system_reset5', - 'system_reset6', 'system_reset7', 'misc1', 'cpld2_version', 'cpld3_version' - ] + 'system_reset6', 'system_reset7', 'misc1', 'cpld2_version', 'cpld3_version' + ] ret_val = "sysstatus failed" if dev['dev_info']['device_type'] == "SYSSTAT": - for attr in dev['attr_list']: - if attr.get("attr_name") in dev_attribs: - ret_val = "sysstatus success" - print ret_val + for attr in dev['attr_list']: + if attr.get("attr_name") in dev_attribs: + ret_val = "sysstatus success" + print(ret_val) def validate_temp_sensor_device(self, dev, ops): devtype_list = ['lm75'] @@ -790,7 +764,7 @@ def validate_temp_sensor_device(self, dev, ops): for attr in dev['i2c']['attr_list']: if attr.get("attr_name") in dev_attribs: ret_val = "tempsensor success" - print ret_val + print(ret_val) def validate_fan_device(self, dev, ops): ret_val = "fan failed" @@ -799,12 +773,12 @@ def validate_fan_device(self, dev, ops): if dev['i2c']['dev_attr']['num_fan'] is not None: ret_val = "fan success" - print ret_val + print(ret_val) def validate_psu_device(self, dev, ops): dev_attribs = ['psu_present', 'psu_model_name', 'psu_power_good', 'psu_mfr_id', 'psu_serial_num', - 'psu_fan_dir', 'psu_v_out', 'psu_i_out', 'psu_p_out', 'psu_fan1_speed_rpm' - ] + 'psu_fan_dir', 'psu_v_out', 'psu_i_out', 'psu_p_out', 'psu_fan1_speed_rpm' + ] ret_val = "psu failed" if dev['i2c']['topo_info']['dev_type'] in self.data['PLATFORM']['pddf_dev_types']['PSU']: @@ -814,272 +788,263 @@ def validate_psu_device(self, dev, ops): if attr.get("attr_offset") is not None: if attr.get("attr_mask") is not None: if attr.get("attr_len") is not None: - ret_val = "psu success" + ret_val = "psu success" else: ret_val = "psu failed" - print ret_val + print(ret_val) ################################################################################################################### - # SPYTEST + # SPYTEST ################################################################################################################### def verify_attr(self, key, attr, path): - node="/sys/kernel/%s/%s"%(path, key) - try: - with open(node, 'r') as f: - status = f.read() - except IOError: - print "PDDF_VERIFY_ERR: IOError: node:%s key:%s"%(node, key) - return + node = "/sys/kernel/%s/%s" % (path, key) + try: + with open(node, 'r') as f: + status = f.read() + except IOError: + print("PDDF_VERIFY_ERR: IOError: node:%s key:%s" % (node, key)) + return - status=status.rstrip("\n\r") - if attr[key]!=status: - print "PDDF_VERIFY_ERR: node: %s switch:%s"%(node, status) + status = status.rstrip("\n\r") + if attr[key] != status: + print("PDDF_VERIFY_ERR: node: %s switch:%s" % (node, status)) def verify_device(self, attr, path, ops): - for key in attr.keys(): - self.verify_attr(key, attr, path) - + for key in attr.keys(): + self.verify_attr(key, attr, path) def get_led_device(self, device_name): self.create_attr('device_name', self.data[device_name]['dev_info']['device_name'], "pddf/devices/led") self.create_attr('index', self.data[device_name]['dev_attr']['index'], "pddf/devices/led") - cmd="echo 'verify' > /sys/kernel/pddf/devices/led/dev_ops" + cmd = "echo 'verify' > /sys/kernel/pddf/devices/led/dev_ops" self.runcmd(cmd) def validate_sysfs_creation(self, obj, validate_type): - dir = '/sys/kernel/pddf/devices/'+validate_type - if (os.path.exists(dir) or validate_type=='client'): - for sysfs in obj[validate_type]: - if(not os.path.exists(sysfs)): - print "[SYSFS FILE] " + sysfs + ": does not exist" - else: - print "[SYSFS DIR] " + dir + ": does not exist" + dir = '/sys/kernel/pddf/devices/'+validate_type + if (os.path.exists(dir) or validate_type == 'client'): + for sysfs in obj[validate_type]: + if not os.path.exists(sysfs): + print("[SYSFS FILE] " + sysfs + ": does not exist") + else: + print("[SYSFS DIR] " + dir + ": does not exist") def validate_dsysfs_creation(self, obj, validate_type): if validate_type in obj.keys(): # There is a possibility that some components dont have any device-self.data attr if not obj[validate_type]: - print "[SYSFS ATTR] for " + validate_type + ": empty" + print("[SYSFS ATTR] for " + validate_type + ": empty") else: - for sysfs in obj[validate_type]: - if(not os.path.exists(sysfs)): - print "[SYSFS FILE] " + sysfs + ": does not exist" + for sysfs in obj[validate_type]: + if not os.path.exists(sysfs): + print("[SYSFS FILE] " + sysfs + ": does not exist") else: - print "[SYSFS DIR] " + dir + ": not configured" - - + print("[SYSFS DIR] " + dir + ": not configured") def verify_sysfs_data(self, verify_type): - if (verify_type=='LED'): + if (verify_type == 'LED'): for key in self.data.keys(): if key != 'PLATFORM': - attr=self.data[key]['dev_info'] + attr = self.data[key]['dev_info'] if attr['device_type'] == 'LED': self.get_led_device(key) self.verify_attr('device_name', self.data[key]['dev_info'], "pddf/devices/led") self.verify_attr('index', self.data[key]['dev_attr'], "pddf/devices/led") for attr in self.data[key]['i2c']['attr_list']: - path="pddf/devices/led/" + attr['attr_name'] + path = "pddf/devices/led/" + attr['attr_name'] for entry in attr.keys(): if (entry != 'attr_name' and entry != 'swpld_addr' and entry != 'swpld_addr_offset'): - self.verify_attr(entry, attr, path) - if ( entry == 'swpld_addr' or entry == 'swpld_addr_offset'): - self.verify_attr(entry, attr, 'pddf/devices/led') - - + self.verify_attr(entry, attr, path) + if (entry == 'swpld_addr' or entry == 'swpld_addr_offset'): + self.verify_attr(entry, attr, 'pddf/devices/led') def schema_validation(self, validate_type): - process_validate_type = 0 - for key in self.data.keys(): - if (key != 'PLATFORM'): - temp_obj={} - schema_list=[] + process_validate_type = 0 + for key in self.data.keys(): + if (key != 'PLATFORM'): + temp_obj = {} + schema_list = [] + try: + device_type = self.data[key]["dev_info"]["device_type"] + except Exception as e: + print("dev_info or device_type ERROR: " + key) + print(e) + + if validate_type == 'mismatch': + process_validate_type = 1 + device_type = "PSU" + schema_file = "/usr/local/bin/schema/FAN.schema" + schema_list.append(schema_file) + elif validate_type == 'missing': + process_validate_type = 1 + schema_file = "/usr/local/bin/schema/PLATFORM.schema" + schema_list.append(schema_file) + + elif validate_type == 'empty': + process_validate_type = 1 + if not device_type: + print("Empty device_type for " + key) + continue + elif (validate_type == 'all' or validate_type == device_type): + process_validate_type = 1 + if "bmc" in self.data[key].keys(): + schema_file = "/usr/local/bin/schema/"+device_type + "_BMC.schema" + schema_list.append(schema_file) + + if "i2c" in self.data[key].keys(): + schema_file = "/usr/local/bin/schema/"+device_type + ".schema" + schema_list.append(schema_file) + if device_type: + temp_obj[device_type] = self.data[key] + for schema_file in schema_list: + if (os.path.exists(schema_file)): + print("Validate " + schema_file + ";" + key) + json_data = json.dumps(temp_obj) + with open(schema_file, 'r') as f: + schema = json.load(f) try: - device_type=self.data[key]["dev_info"]["device_type"] + validate(temp_obj, schema) except Exception as e: - print "dev_info or device_type ERROR: " + key - print e - - if validate_type == 'mismatch': - process_validate_type = 1 - device_type="PSU" - schema_file="/usr/local/bin/schema/FAN.schema" - schema_list.append(schema_file) - elif validate_type == 'missing': - process_validate_type = 1 - schema_file="/usr/local/bin/schema/PLATFORM.schema" - schema_list.append(schema_file) - - elif validate_type == 'empty': - process_validate_type = 1 - if not device_type: - print "Empty device_type for " + key - continue - elif (validate_type=='all' or validate_type==device_type): - process_validate_type = 1 - if "bmc" in self.data[key].keys(): - schema_file="/usr/local/bin/schema/"+device_type + "_BMC.schema" - schema_list.append(schema_file) - - if "i2c" in self.data[key].keys(): - schema_file="/usr/local/bin/schema/"+device_type + ".schema" - schema_list.append(schema_file) - if device_type: - temp_obj[device_type]=self.data[key] - for schema_file in schema_list: - if (os.path.exists(schema_file)): - print "Validate " + schema_file + ";" + key - json_data=json.dumps(temp_obj) - with open(schema_file, 'r') as f: - schema=json.load(f) - try: - validate(temp_obj, schema) - except Exception as e: - print "Validation ERROR: " + schema_file + ";" + key - if validate_type == 'mismatch': - return - else: - print e - else: - print "ERROR Missing File: " + schema_file - if not process_validate_type: - print "device_type: " + validate_type + " not configured" + print("Validation ERROR: " + schema_file + ";" + key) + if validate_type == 'mismatch': + return + else: + print(e) + else: + print("ERROR Missing File: " + schema_file) + if not process_validate_type: + print("device_type: " + validate_type + " not configured") def modules_validation(self, validate_type): kos = [] supported_type = False - module_validation_status=[] + module_validation_status = [] - if validate_type == "bmc": - kos=['ipmi_devintf', 'ipmi_si', 'ipmi_msghandler'] - validate_type = 'ipmi' + if validate_type == "bmc": + kos = ['ipmi_devintf', 'ipmi_si', 'ipmi_msghandler'] + validate_type = 'ipmi' else: - # generate the KOS list from pddf device JSON file - kos.extend(self.data['PLATFORM']['pddf_kos']) + # generate the KOS list from pddf device JSON file + kos.extend(self.data['PLATFORM']['pddf_kos']) - if 'custom_kos' in self.data['PLATFORM']: - kos.extend(self.data['PLATFORM']['custom_kos']) + if 'custom_kos' in self.data['PLATFORM']: + kos.extend(self.data['PLATFORM']['custom_kos']) for mod in kos: if validate_type in mod or validate_type == "pddf": - supported_type=True - cmd = "lsmod | grep " + mod - try: - subprocess.check_output(cmd, shell=True) - except Exception as e: - module_validation_status.append(mod) + supported_type = True + cmd = "lsmod | grep " + mod + try: + subprocess.check_output(cmd, shell=True) + except Exception as e: + module_validation_status.append(mod) if supported_type: if module_validation_status: - module_validation_status.append(":ERROR not loaded") - print str(module_validation_status)[1:-1] + module_validation_status.append(":ERROR not loaded") + print(str(module_validation_status)[1:-1]) else: - print "Loaded" + print("Loaded") else: - print validate_type + " not configured" - - + print(validate_type + " not configured") ################################################################################################################### # PARSE DEFS ################################################################################################################### + def psu_parse(self, dev, ops): - parse_str="" - ret="" + parse_str = "" + ret = "" for ifce in dev['i2c']['interface']: - ret=getattr(self, ops['cmd']+"_psu_device")(self.data[ifce['dev']], ops ) - if not ret is None: + ret = getattr(self, ops['cmd']+"_psu_device")(self.data[ifce['dev']], ops) + if ret is not None: if str(ret).isdigit(): - if ret!=0: + if ret != 0: # in case if 'create' functions - print "{}_psu_device failed".format(ops['cmd']) + print("{}_psu_device failed".format(ops['cmd'])) return ret else: pass else: # in case of 'show_attr' functions - parse_str+=ret + parse_str += ret return parse_str def fan_parse(self, dev, ops): - parse_str="" - ret=getattr(self, ops['cmd']+"_fan_device")(dev, ops ) - if not ret is None: + parse_str = "" + ret = getattr(self, ops['cmd']+"_fan_device")(dev, ops) + if ret is not None: if str(ret).isdigit(): - if ret!=0: + if ret != 0: # in case if 'create' functions - print "{}_fan_device failed".format(ops['cmd']) + print("{}_fan_device failed".format(ops['cmd'])) return ret else: pass else: # in case of 'show_attr' functions - parse_str+=ret + parse_str += ret return parse_str def temp_sensor_parse(self, dev, ops): - parse_str="" - ret=getattr(self, ops['cmd']+"_temp_sensor_device")(dev, ops ) - if not ret is None: - if str(ret).isdigit() : - if ret!=0: + parse_str = "" + ret = getattr(self, ops['cmd']+"_temp_sensor_device")(dev, ops) + if ret is not None: + if str(ret).isdigit(): + if ret != 0: # in case if 'create' functions - print "{}_temp_sensor_device failed".format(ops['cmd']) + print("{}_temp_sensor_device failed".format(ops['cmd'])) return ret else: pass else: # in case of 'show_attr' functions - parse_str+=ret + parse_str += ret return parse_str def cpld_parse(self, dev, ops): parse_str = "" ret = getattr(self, ops['cmd']+"_cpld_device")(dev, ops) - if not ret is None: + if ret is not None: if str(ret).isdigit(): - if ret!=0: + if ret != 0: # in case if 'create' functions - print "{}_cpld_device failed".format(ops['cmd']) + print("{}_cpld_device failed".format(ops['cmd'])) return ret else: pass else: # in case of 'show_attr' functions - parse_str+=ret + parse_str += ret return parse_str - - - - def sysstatus_parse(self, dev,ops): + def sysstatus_parse(self, dev, ops): parse_str = "" ret = getattr(self, ops['cmd']+"_sysstatus_device")(dev, ops) - if not ret is None: + if ret is not None: if str(ret).isdigit(): - if ret!=0: + if ret != 0: # in case if 'create' functions - print "{}_sysstatus_device failed".format(ops['cmd']) + print("{}_sysstatus_device failed".format(ops['cmd'])) return ret else: pass else: # in case of 'show_attr' functions - parse_str+=ret + parse_str += ret - return parse_str + return parse_str def gpio_parse(self, dev, ops): parse_str = "" ret = getattr(self, ops['cmd']+"_gpio_device")(dev, ops) - if not ret is None: + if ret is not None: if str(ret).isdigit(): - if ret!=0: + if ret != 0: # in case if 'create' functions - print "{}_temp_sensor_device failed".format(ops['cmd']) + print("{}_temp_sensor_device failed".format(ops['cmd'])) return ret else: pass @@ -1089,15 +1054,14 @@ def gpio_parse(self, dev, ops): return parse_str - def mux_parse(self, dev, ops): parse_str = "" ret = getattr(self, ops['cmd']+"_mux_device")(dev, ops) - if not ret is None: + if ret is not None: if str(ret).isdigit(): - if ret!=0: + if ret != 0: # in case if 'create' functions - print "{}_mux_device() cmd failed".format(ops['cmd']) + print("{}_mux_device() cmd failed".format(ops['cmd'])) return ret else: pass @@ -1105,10 +1069,10 @@ def mux_parse(self, dev, ops): parse_str += ret for ch in dev['i2c']['channel']: - ret = self.dev_parse(self.data[ch['dev']], ops) - if not ret is None: + ret = self.dev_parse(self.data[ch['dev']], ops) + if ret is not None: if str(ret).isdigit(): - if ret!=0: + if ret != 0: # in case if 'create' functions return ret else: @@ -1120,10 +1084,10 @@ def mux_parse(self, dev, ops): def mux_parse_reverse(self, dev, ops): parse_str = "" for ch in reversed(dev['i2c']['channel']): - ret = self.dev_parse(self.data[ch['dev']], ops) - if not ret is None: + ret = self.dev_parse(self.data[ch['dev']], ops) + if ret is not None: if str(ret).isdigit(): - if ret!=0: + if ret != 0: # in case if 'create' functions return ret else: @@ -1132,11 +1096,11 @@ def mux_parse_reverse(self, dev, ops): parse_str += ret ret = getattr(self, ops['cmd']+"_mux_device")(dev, ops) - if not ret is None: + if ret is not None: if str(ret).isdigit(): - if ret!=0: + if ret != 0: # in case if 'create' functions - print "{}_mux_device() cmd failed".format(ops['cmd']) + print("{}_mux_device() cmd failed".format(ops['cmd'])) return ret else: pass @@ -1145,15 +1109,14 @@ def mux_parse_reverse(self, dev, ops): return parse_str - def eeprom_parse(self, dev, ops): parse_str = "" ret = getattr(self, ops['cmd']+"_eeprom_device")(dev, ops) - if not ret is None: + if ret is not None: if str(ret).isdigit(): - if ret!=0: + if ret != 0: # in case if 'create' functions - print "{}_eeprom_device() cmd failed".format(ops['cmd']) + print("{}_eeprom_device() cmd failed".format(ops['cmd'])) return ret else: pass @@ -1163,20 +1126,20 @@ def eeprom_parse(self, dev, ops): return parse_str def optic_parse(self, dev, ops): - parse_str="" - ret="" + parse_str = "" + ret = "" for ifce in dev['i2c']['interface']: - ret=getattr(self, ops['cmd']+"_xcvr_device")(self.data[ifce['dev']], ops ) - if not ret is None: + ret = getattr(self, ops['cmd']+"_xcvr_device")(self.data[ifce['dev']], ops) + if ret is not None: if str(ret).isdigit(): - if ret!=0: + if ret != 0: # in case if 'create' functions - print "{}_eeprom_device() cmd failed".format(ops['cmd']) + print("{}_eeprom_device() cmd failed".format(ops['cmd'])) return ret else: pass else: - parse_str+=ret + parse_str += ret return parse_str def cpu_parse(self, bus, ops): @@ -1184,10 +1147,10 @@ def cpu_parse(self, bus, ops): for dev in bus['i2c']['CONTROLLERS']: dev1 = self.data[dev['dev']] for d in dev1['i2c']['DEVICES']: - ret=self.dev_parse(self.data[d['dev']], ops) - if not ret is None: + ret = self.dev_parse(self.data[d['dev']], ops) + if ret is not None: if str(ret).isdigit(): - if ret!=0: + if ret != 0: # in case if 'create' functions return ret else: @@ -1201,10 +1164,10 @@ def cpu_parse_reverse(self, bus, ops): for dev in reversed(bus['i2c']['CONTROLLERS']): dev1 = self.data[dev['dev']] for d in dev1['i2c']['DEVICES']: - ret=self.dev_parse(self.data[d['dev']], ops) - if not ret is None: + ret = self.dev_parse(self.data[d['dev']], ops) + if ret is not None: if str(ret).isdigit(): - if ret!=0: + if ret != 0: # in case if 'create' functions return ret else: @@ -1213,68 +1176,67 @@ def cpu_parse_reverse(self, bus, ops): parse_str += ret return parse_str - def dev_parse(self, dev, ops): - attr=dev['dev_info'] - if attr['device_type'] == 'CPU': - if ops['cmd']=='delete': - return self.cpu_parse_reverse(dev, ops) - else: - return self.cpu_parse(dev, ops) - - if attr['device_type'] == 'EEPROM': - return self.eeprom_parse(dev, ops) - - if attr['device_type'] == 'MUX': - if ops['cmd']=='delete': - return self.mux_parse_reverse(dev, ops) - else: - return self.mux_parse(dev, ops) + attr = dev['dev_info'] + if attr['device_type'] == 'CPU': + if ops['cmd'] == 'delete': + return self.cpu_parse_reverse(dev, ops) + else: + return self.cpu_parse(dev, ops) - if attr['device_type'] == 'GPIO': - return self.gpio_parse(dev, ops) + if attr['device_type'] == 'EEPROM': + return self.eeprom_parse(dev, ops) - if attr['device_type'] == 'PSU': - return self.psu_parse(dev, ops) + if attr['device_type'] == 'MUX': + if ops['cmd'] == 'delete': + return self.mux_parse_reverse(dev, ops) + else: + return self.mux_parse(dev, ops) + + if attr['device_type'] == 'GPIO': + return self.gpio_parse(dev, ops) - if attr['device_type'] == 'FAN': - return self.fan_parse(dev, ops) + if attr['device_type'] == 'PSU': + return self.psu_parse(dev, ops) - if attr['device_type'] == 'TEMP_SENSOR': - return self.temp_sensor_parse(dev, ops) + if attr['device_type'] == 'FAN': + return self.fan_parse(dev, ops) - if attr['device_type'] == 'SFP' or attr['device_type'] == 'QSFP' or \ - attr['device_type'] == 'SFP28' or attr['device_type'] == 'QSFP28' or \ - attr['device_type'] == 'QSFP-DD': - return self.optic_parse(dev, ops) + if attr['device_type'] == 'TEMP_SENSOR': + return self.temp_sensor_parse(dev, ops) - if attr['device_type'] == 'CPLD': - return self.cpld_parse(dev, ops) + if attr['device_type'] == 'SFP' or attr['device_type'] == 'QSFP' or \ + attr['device_type'] == 'SFP28' or attr['device_type'] == 'QSFP28' or \ + attr['device_type'] == 'QSFP-DD': + return self.optic_parse(dev, ops) - if attr['device_type'] == 'SYSSTAT': - return self.sysstatus_parse(dev,ops) + if attr['device_type'] == 'CPLD': + return self.cpld_parse(dev, ops) + + if attr['device_type'] == 'SYSSTAT': + return self.sysstatus_parse(dev, ops) def is_supported_sysled_state(self, sysled_name, sysled_state): - if not sysled_name in self.data.keys(): - return False, "[FAILED] " + sysled_name + " is not configured" - for attr in self.data[sysled_name]['i2c']['attr_list']: - if attr['attr_name'] == sysled_state: - return True, "supported" - return False, "[FAILED]: Invalid color" + if sysled_name not in self.data.keys(): + return False, "[FAILED] " + sysled_name + " is not configured" + for attr in self.data[sysled_name]['i2c']['attr_list']: + if attr['attr_name'] == sysled_state: + return True, "supported" + return False, "[FAILED]: Invalid color" def create_attr(self, key, value, path): - cmd = "echo '%s' > /sys/kernel/%s/%s"%(value, path, key) - self.runcmd(cmd) + cmd = "echo '%s' > /sys/kernel/%s/%s" % (value, path, key) + self.runcmd(cmd) def create_led_platform_device(self, key, ops): - if ops['attr']=='all' or ops['attr']=='PLATFORM': - path='pddf/devices/platform' + if ops['attr'] == 'all' or ops['attr'] == 'PLATFORM': + path = 'pddf/devices/platform' self.create_attr('num_psus', self.data['PLATFORM']['num_psus'], path) self.create_attr('num_fantrays', self.data['PLATFORM']['num_fantrays'], path) def create_led_device(self, key, ops): - if ops['attr']=='all' or ops['attr']==self.data[key]['dev_info']['device_name']: - path="pddf/devices/led" + if ops['attr'] == 'all' or ops['attr'] == self.data[key]['dev_info']['device_name']: + path = "pddf/devices/led" for attr in self.data[key]['i2c']['attr_list']: self.create_attr('device_name', self.data[key]['dev_info']['device_name'], path) self.create_device(self.data[key]['dev_attr'], path, ops) @@ -1283,111 +1245,107 @@ def create_led_device(self, key, ops): self.create_attr(attr_key, attr[attr_key], path) elif (attr_key != 'attr_name' and attr_key != 'descr' and attr_key != 'attr_devtype' and attr_key != 'attr_devname'): - state_path=path+'/state_attr' - self.create_attr(attr_key, attr[attr_key],state_path) - cmd="echo '" + attr['attr_name']+"' > /sys/kernel/pddf/devices/led/dev_ops" + state_path = path+'/state_attr' + self.create_attr(attr_key, attr[attr_key], state_path) + cmd = "echo '" + attr['attr_name']+"' > /sys/kernel/pddf/devices/led/dev_ops" self.runcmd(cmd) - def led_parse(self, ops): - getattr(self, ops['cmd']+"_led_platform_device")("PLATFORM", ops) - for key in self.data.keys(): - if key != 'PLATFORM' and 'dev_info' in self.data[key]: - attr=self.data[key]['dev_info'] - if attr['device_type'] == 'LED': - getattr(self, ops['cmd']+"_led_device")(key, ops) - + getattr(self, ops['cmd']+"_led_platform_device")("PLATFORM", ops) + for key in self.data.keys(): + if key != 'PLATFORM' and 'dev_info' in self.data[key]: + attr = self.data[key]['dev_info'] + if attr['device_type'] == 'LED': + getattr(self, ops['cmd']+"_led_device")(key, ops) def get_device_list(self, list, type): - for key in self.data.keys(): - if key != 'PLATFORM' and 'dev_info' in self.data[key]: - attr=self.data[key]['dev_info'] - if attr['device_type'] == type: - list.append(self.data[key]) - + for key in self.data.keys(): + if key != 'PLATFORM' and 'dev_info' in self.data[key]: + attr = self.data[key]['dev_info'] + if attr['device_type'] == type: + list.append(self.data[key]) def create_pddf_devices(self): - self.led_parse({ "cmd": "create", "target":"all", "attr":"all" }) + self.led_parse({"cmd": "create", "target": "all", "attr": "all"}) create_ret = 0 - create_ret = self.dev_parse(self.data['SYSTEM'], { "cmd": "create", "target":"all", "attr":"all" } ) - if create_ret!=0: + create_ret = self.dev_parse(self.data['SYSTEM'], {"cmd": "create", "target": "all", "attr": "all"}) + if create_ret != 0: return create_ret if 'SYSSTATUS' in self.data: - create_ret = self.dev_parse(self.data['SYSSTATUS'], { "cmd": "create", "target":"all", "attr":"all" } ) - if create_ret!=0: + create_ret = self.dev_parse(self.data['SYSSTATUS'], {"cmd": "create", "target": "all", "attr": "all"}) + if create_ret != 0: return create_ret - + def delete_pddf_devices(self): - self.dev_parse(self.data['SYSTEM'], { "cmd": "delete", "target":"all", "attr":"all" } ) + self.dev_parse(self.data['SYSTEM'], {"cmd": "delete", "target": "all", "attr": "all"}) if 'SYSSTATUS' in self.data: - self.dev_parse(self.data['SYSSTATUS'], { "cmd": "delete", "target":"all", "attr":"all" } ) + self.dev_parse(self.data['SYSSTATUS'], {"cmd": "delete", "target": "all", "attr": "all"}) def populate_pddf_sysfsobj(self): - self.dev_parse(self.data['SYSTEM'], { "cmd": "show", "target":"all", "attr":"all" } ) + self.dev_parse(self.data['SYSTEM'], {"cmd": "show", "target": "all", "attr": "all"}) if 'SYSSTATUS' in self.data: - self.dev_parse(self.data['SYSSTATUS'], { "cmd": "show", "target":"all", "attr":"all" } ) - self.led_parse({ "cmd": "show", "target":"all", "attr":"all" }) + self.dev_parse(self.data['SYSSTATUS'], {"cmd": "show", "target": "all", "attr": "all"}) + self.led_parse({"cmd": "show", "target": "all", "attr": "all"}) self.show_client_device() def cli_dump_dsysfs(self, component): - self.dev_parse(self.data['SYSTEM'], { "cmd": "show_attr", "target":"all", "attr":"all" } ) + self.dev_parse(self.data['SYSTEM'], {"cmd": "show_attr", "target": "all", "attr": "all"}) if 'SYSSTATUS' in self.data: - self.dev_parse(self.data['SYSSTATUS'], { "cmd": "show_attr", "target":"all", "attr":"all" } ) + self.dev_parse(self.data['SYSSTATUS'], {"cmd": "show_attr", "target": "all", "attr": "all"}) if component in self.data_sysfs_obj: return self.data_sysfs_obj[component] else: - return None - + return None def validate_pddf_devices(self, *args): - self.populate_pddf_sysfsobj() - v_ops = { 'cmd': 'validate', 'target':'all', 'attr':'all' } - self.dev_parse(self.data['SYSTEM'], v_ops ) + self.populate_pddf_sysfsobj() + v_ops = {'cmd': 'validate', 'target': 'all', 'attr': 'all'} + self.dev_parse(self.data['SYSTEM'], v_ops) ################################################################################################################### - # BMC APIs + # BMC APIs ################################################################################################################### def populate_bmc_cache_db(self, bmc_attr): bmc_cmd = str(bmc_attr['bmc_cmd']).strip() o_list = subprocess.check_output(bmc_cmd, shell=True).strip().split('\n') - bmc_cache[bmc_cmd]={} - bmc_cache[bmc_cmd]['time']=time.time() + bmc_cache[bmc_cmd] = {} + bmc_cache[bmc_cmd]['time'] = time.time() for entry in o_list: name = entry.split()[0] - bmc_cache[bmc_cmd][name]=entry + bmc_cache[bmc_cmd][name] = entry def non_raw_ipmi_get_request(self, bmc_attr): - bmc_db_update_time=1 + bmc_db_update_time = 1 value = 'N/A' bmc_cmd = str(bmc_attr['bmc_cmd']).strip() field_name = str(bmc_attr['field_name']).strip() - field_pos= int(bmc_attr['field_pos'])-1 + field_pos = int(bmc_attr['field_pos'])-1 - if not bmc_cmd in bmc_cache: - self.populate_bmc_cache_db(bmc_attr) + if bmc_cmd not in bmc_cache: + self.populate_bmc_cache_db(bmc_attr) else: - now = time.time() - if (int(now - bmc_cache[bmc_cmd]['time']) > bmc_db_update_time): - self.populate_bmc_cache_db(bmc_attr) + now = time.time() + if (int(now - bmc_cache[bmc_cmd]['time']) > bmc_db_update_time): + self.populate_bmc_cache_db(bmc_attr) try: - data=bmc_cache[bmc_cmd][field_name] - value = data.split()[field_pos] + data = bmc_cache[bmc_cmd][field_name] + value = data.split()[field_pos] except Exception as e: - pass + pass if 'mult' in bmc_attr.keys() and not value.isalpha(): if value.isalpha(): value = 0.0 value = float(value) * float(bmc_attr['mult']) - + return str(value) def raw_ipmi_get_request(self, bmc_attr): value = 'N/A' - cmd = bmc_attr['bmc_cmd'] + " 2>/dev/null" - if bmc_attr['type'] == 'raw': + cmd = bmc_attr['bmc_cmd'] + " 2>/dev/null" + if bmc_attr['type'] == 'raw': try: value = subprocess.check_output(cmd, shell=True).strip() except Exception as e: @@ -1397,7 +1355,7 @@ def raw_ipmi_get_request(self, bmc_attr): value = str(int(value, 16)) return value - if bmc_attr['type'] == 'mask': + if bmc_attr['type'] == 'mask': mask = int(bmc_attr['mask'].encode('utf-8'), 16) try: value = subprocess.check_output(cmd, shell=True).strip() @@ -1406,10 +1364,10 @@ def raw_ipmi_get_request(self, bmc_attr): if value != 'N/A': value = str(int(value, 16) & mask) - + return value - if bmc_attr['type'] == 'ascii': + if bmc_attr['type'] == 'ascii': try: value = subprocess.check_output(cmd, shell=True) except Exception as e: @@ -1417,19 +1375,19 @@ def raw_ipmi_get_request(self, bmc_attr): if value != 'N/A': tmp = ''.join(chr(int(i, 16)) for i in value.split()) - tmp = "".join(i for i in unicode(tmp) if unicodedata.category(i)[0]!="C") + tmp = "".join(i for i in str(tmp) if unicodedata.category(i)[0] != "C") value = str(tmp) return (value) - return value + return value - def bmc_get_cmd(self, bmc_attr): - if int(bmc_attr['raw']) == 1: + def bmc_get_cmd(self, bmc_attr): + if int(bmc_attr['raw']) == 1: value = self.raw_ipmi_get_request(bmc_attr) - else: + else: value = self.non_raw_ipmi_get_request(bmc_attr) - return (value) + return (value) def non_raw_ipmi_set_request(self, bmc_attr, val): value = 'N/A' @@ -1439,14 +1397,14 @@ def non_raw_ipmi_set_request(self, bmc_attr, val): def raw_ipmi_set_request(self, bmc_attr, val): value = 'N/A' # TODO: Implement this - return value + return value - def bmc_set_cmd(self, bmc_attr, val): - if int(bmc_attr['raw']) == 1: + def bmc_set_cmd(self, bmc_attr, val): + if int(bmc_attr['raw']) == 1: value = self.raw_ipmi_set_request(bmc_attr, val) - else: + else: value = self.non_raw_ipmi_set_request(bmc_attr, val) - return (value) + return (value) # bmc-based attr: return attr obj # non-bmc-based attr: return empty obj @@ -1459,43 +1417,43 @@ def check_bmc_based_attr(self, device_name, attr_name): return attr # Required attr_name is not supported in BMC object return {} - return None + return None def get_attr_name_output(self, device_name, attr_name): - bmc_attr = self.check_bmc_based_attr(device_name, attr_name) - output={"mode":"", "status":""} - + bmc_attr = self.check_bmc_based_attr(device_name, attr_name) + output = {"mode": "", "status": ""} + if bmc_attr is not None: - if bmc_attr=={}: - return {} - output['mode']="bmc" - output['status']=self.bmc_get_cmd(bmc_attr) + if bmc_attr == {}: + return {} + output['mode'] = "bmc" + output['status'] = self.bmc_get_cmd(bmc_attr) else: - output['mode']="i2c" - node = self.get_path(device_name, attr_name) - if node is None: - return {} - try: - with open(node, 'r') as f: - output['status'] = f.read() - except IOError: - return {} + output['mode'] = "i2c" + node = self.get_path(device_name, attr_name) + if node is None: + return {} + try: + with open(node, 'r') as f: + output['status'] = f.read() + except IOError: + return {} return output def set_attr_name_output(self, device_name, attr_name, val): - bmc_attr = self.check_bmc_based_attr(device_name, attr_name) - output={"mode":"", "status":""} - + bmc_attr = self.check_bmc_based_attr(device_name, attr_name) + output = {"mode": "", "status": ""} + if bmc_attr is not None: - if bmc_attr=={}: - return {} - output['mode']="bmc" - output['status']=False # No set operation allowed for BMC attributes as they are handled by BMC itself + if bmc_attr == {}: + return {} + output['mode'] = "bmc" + output['status'] = False # No set operation allowed for BMC attributes as they are handled by BMC itself else: - output['mode']="i2c" + output['mode'] = "i2c" node = self.get_path(device_name, attr_name) if node is None: - return {} + return {} try: with open(node, 'w') as f: f.write(str(val)) @@ -1505,4 +1463,3 @@ def set_attr_name_output(self, device_name, attr_name, val): output['status'] = True return output - diff --git a/slave.mk b/slave.mk index 86bf063b31cd..54470e27dc34 100644 --- a/slave.mk +++ b/slave.mk @@ -867,6 +867,7 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \ $(addprefix $(PYTHON_WHEELS_PATH)/,$(REDIS_DUMP_LOAD_PY2)) \ $(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_PLATFORM_API_PY2)) \ $(if $(findstring y,$(PDDF_SUPPORT)),$(addprefix $(PYTHON_WHEELS_PATH)/,$(PDDF_PLATFORM_API_BASE_PY2))) \ + $(if $(findstring y,$(PDDF_SUPPORT)),$(addprefix $(PYTHON_WHEELS_PATH)/,$(PDDF_PLATFORM_API_BASE_PY3))) \ $(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_YANG_MODELS_PY3)) \ $(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_CTRMGRD)) \ $(addprefix $(FILES_PATH)/,$($(SONIC_CTRMGRD)_FILES)) \