From 9d74e67a4c75c5d306be7701d7a6a249d217fbf4 Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Fri, 13 Nov 2020 02:10:00 +0000 Subject: [PATCH 01/24] [sonic-utilities] Install Python 3 package --- .../build_templates/sonic_debian_extension.j2 | 10 +++---- platform/p4/docker-sonic-p4.mk | 2 +- platform/vs/docker-sonic-vs.mk | 4 +-- rules/sonic-utilities.dep | 12 ++++----- rules/sonic-utilities.mk | 27 ++++++------------- slave.mk | 4 +-- 6 files changed, 24 insertions(+), 35 deletions(-) diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index 82fb75d6c058..ce72f379a15c 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -205,11 +205,11 @@ sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y in # Install prerequisites needed for using the Python m2crypto package, used by sonic-utilities sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y install openssl -# Install SONiC Utilities Python 2 package -SONIC_UTILITIES_PY2_WHEEL_NAME=$(basename {{sonic_utilities_py2_wheel_path}}) -sudo cp {{sonic_utilities_py2_wheel_path}} $FILESYSTEM_ROOT/$SONIC_UTILITIES_PY2_WHEEL_NAME -sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip2 install $SONIC_UTILITIES_PY2_WHEEL_NAME -sudo rm -rf $FILESYSTEM_ROOT/$SONIC_UTILITIES_PY2_WHEEL_NAME +# Install SONiC Utilities Python package +SONIC_UTILITIES_PY3_WHEEL_NAME=$(basename {{sonic_utilities_py3_wheel_path}}) +sudo cp {{sonic_utilities_py3_wheel_path}} $FILESYSTEM_ROOT/$SONIC_UTILITIES_PY3_WHEEL_NAME +sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip3 install $SONIC_UTILITIES_PY3_WHEEL_NAME +sudo rm -rf $FILESYSTEM_ROOT/$SONIC_UTILITIES_PY3_WHEEL_NAME # Install sonic-utilities data files (and any dependencies via 'apt-get -y install -f') sudo dpkg --root=$FILESYSTEM_ROOT -i $debs_path/sonic-utilities-data_*.deb || \ diff --git a/platform/p4/docker-sonic-p4.mk b/platform/p4/docker-sonic-p4.mk index b499a99aefe5..940b85ed5d2a 100644 --- a/platform/p4/docker-sonic-p4.mk +++ b/platform/p4/docker-sonic-p4.mk @@ -12,7 +12,7 @@ $(DOCKER_SONIC_P4)_DEPENDS += $(SWSS) \ $(LIBTEAMDCTL) \ $(LIBTEAM_UTILS) \ $(SONIC_DEVICE_DATA) \ - $(SONIC_UTILITIES_PY2) \ + $(SONIC_UTILITIES_PY3) \ $(IPROUTE2) # ifeq ($(ROUTING_STACK), quagga) diff --git a/platform/vs/docker-sonic-vs.mk b/platform/vs/docker-sonic-vs.mk index 299ca7c14c13..afaf2d8e835b 100644 --- a/platform/vs/docker-sonic-vs.mk +++ b/platform/vs/docker-sonic-vs.mk @@ -22,8 +22,8 @@ $(DOCKER_SONIC_VS)_PYTHON_WHEELS += $(SWSSSDK_PY2) \ $(SONIC_PY_COMMON_PY2) \ $(SONIC_PY_COMMON_PY3) \ $(SONIC_YANG_MODELS_PY3) \ - $(SONIC_YANG_MGMT_PY2) \ - $(SONIC_UTILITIES_PY2) \ + $(SONIC_YANG_MGMT_PY3) \ + $(SONIC_UTILITIES_PY3) \ $(SONIC_HOST_SERVICES_PY3) ifeq ($(INSTALL_DEBUG_TOOLS), y) diff --git a/rules/sonic-utilities.dep b/rules/sonic-utilities.dep index 8686c79b61b7..848b8d66296e 100644 --- a/rules/sonic-utilities.dep +++ b/rules/sonic-utilities.dep @@ -1,10 +1,10 @@ -SPATH := $($(SONIC_UTILITIES_PY2)_SRC_PATH) +SPATH := $($(SONIC_UTILITIES_PY3)_SRC_PATH) DEP_FILES := $(SONIC_COMMON_FILES_LIST) rules/sonic-utilities.mk rules/sonic-utilities.dep DEP_FILES += $(SONIC_COMMON_BASE_FILES_LIST) SMDEP_FILES := $(addprefix $(SPATH)/,$(shell cd $(SPATH) && git ls-files)) -$(SONIC_UTILITIES_PY2)_CACHE_MODE := GIT_CONTENT_SHA -$(SONIC_UTILITIES_PY2)_DEP_FLAGS := $(SONIC_COMMON_FLAGS_LIST) -$(SONIC_UTILITIES_PY2)_DEP_FILES := $(DEP_FILES) -$(SONIC_UTILITIES_PY2)_SMDEP_FILES := $(SMDEP_FILES) -$(SONIC_UTILITIES_PY2)_SMDEP_PATHS := $(SPATH) +$(SONIC_UTILITIES_PY3)_CACHE_MODE := GIT_CONTENT_SHA +$(SONIC_UTILITIES_PY3)_DEP_FLAGS := $(SONIC_COMMON_FLAGS_LIST) +$(SONIC_UTILITIES_PY3)_DEP_FILES := $(DEP_FILES) +$(SONIC_UTILITIES_PY3)_SMDEP_FILES := $(SMDEP_FILES) +$(SONIC_UTILITIES_PY3)_SMDEP_PATHS := $(SPATH) diff --git a/rules/sonic-utilities.mk b/rules/sonic-utilities.mk index f3b6e332545d..7119b4b98eb0 100644 --- a/rules/sonic-utilities.mk +++ b/rules/sonic-utilities.mk @@ -1,27 +1,16 @@ # sonic utilities package -# -# NOTE: sonic-config-engine is a build-time dependency of sonic-utilities -# due to unit tests which are run during the build. However, -# sonic-platform-common and swsssdk are runtime dependencies, and should be -# added here also. However, the current build system assumes all runtime -# dependencies are .deb packages. -# -SONIC_UTILITIES_PY2 = sonic_utilities-1.2-py2-none-any.whl -$(SONIC_UTILITIES_PY2)_SRC_PATH = $(SRC_PATH)/sonic-utilities -$(SONIC_UTILITIES_PY2)_PYTHON_VERSION = 2 -$(SONIC_UTILITIES_PY2)_DEPENDS += $(SONIC_PY_COMMON_PY2) \ - $(SONIC_PY_COMMON_PY3) \ - $(SWSSSDK_PY2) \ - $(SONIC_CONFIG_ENGINE_PY2) \ - $(SONIC_YANG_MGMT_PY2) \ +SONIC_UTILITIES_PY3 = sonic_utilities-1.2-py3-none-any.whl +$(SONIC_UTILITIES_PY3)_SRC_PATH = $(SRC_PATH)/sonic-utilities +$(SONIC_UTILITIES_PY3)_PYTHON_VERSION = 3 +$(SONIC_UTILITIES_PY3)_DEPENDS += $(SONIC_PY_COMMON_PY3) \ + $(SWSSSDK_PY3) \ + $(SONIC_CONFIG_ENGINE_PY3) \ $(SONIC_YANG_MGMT_PY3) \ $(SONIC_YANG_MODELS_PY3) -$(SONIC_UTILITIES_PY2)_DEBS_DEPENDS = $(LIBYANG) \ +$(SONIC_UTILITIES_PY3)_DEBS_DEPENDS = $(LIBYANG) \ $(LIBYANG_CPP) \ - $(LIBYANG_PY2) \ $(LIBYANG_PY3) \ $(LIBSWSSCOMMON) \ - $(PYTHON_SWSSCOMMON) \ $(PYTHON3_SWSSCOMMON) -SONIC_PYTHON_WHEELS += $(SONIC_UTILITIES_PY2) +SONIC_PYTHON_WHEELS += $(SONIC_UTILITIES_PY3) diff --git a/slave.mk b/slave.mk index a959936f1aa4..88d64e6bc409 100644 --- a/slave.mk +++ b/slave.mk @@ -825,7 +825,7 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \ $$(addprefix $(FILES_PATH)/,$$($$*_FILES)) \ $(if $(findstring y,$(ENABLE_ZTP)),$(addprefix $(IMAGE_DISTRO_DEBS_PATH)/,$(SONIC_ZTP))) \ $(if $(findstring y,$(INCLUDE_HOST_SERVICE)),$(addprefix $(IMAGE_DISTRO_DEBS_PATH)/,$(SONIC_HOST_SERVICE))) \ - $(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_UTILITIES_PY2)) \ + $(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_UTILITIES_PY3)) \ $(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_PY_COMMON_PY2)) \ $(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_PY_COMMON_PY3)) \ $(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_CONFIG_ENGINE_PY2)) \ @@ -886,7 +886,7 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \ export multi_instance="false" export python_swss_debs="$(addprefix $(IMAGE_DISTRO_DEBS_PATH)/,$($(LIBSWSSCOMMON)_RDEPENDS))" export python_swss_debs+=" $(addprefix $(IMAGE_DISTRO_DEBS_PATH)/,$(LIBSWSSCOMMON)) $(addprefix $(IMAGE_DISTRO_DEBS_PATH)/,$(PYTHON_SWSSCOMMON)) $(addprefix $(IMAGE_DISTRO_DEBS_PATH)/,$(PYTHON3_SWSSCOMMON))" - export sonic_utilities_py2_wheel_path="$(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_UTILITIES_PY2))" + export sonic_utilities_py3_wheel_path="$(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_UTILITIES_PY3))" export sonic_host_services_py3_wheel_path="$(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_HOST_SERVICES_PY3))" $(foreach docker, $($*_DOCKERS),\ From 64ad57b13649cb254a2648a45cd0be72999d190d Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Sun, 15 Nov 2020 19:07:55 +0000 Subject: [PATCH 02/24] [sonic-utilities] Update submodule --- src/sonic-utilities | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-utilities b/src/sonic-utilities index 3f158352b2ce..bd8d6c7b89df 160000 --- a/src/sonic-utilities +++ b/src/sonic-utilities @@ -1 +1 @@ -Subproject commit 3f158352b2cef171a0aa5e89d075ed4328cef6dd +Subproject commit bd8d6c7b89dffe7f95d48c71a8092fd77d40b32d From 302255decf3a0993ac6f0e4f0ef6e59d0c5ad125 Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Mon, 16 Nov 2020 01:40:41 +0000 Subject: [PATCH 03/24] Update submodule further --- src/sonic-utilities | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-utilities b/src/sonic-utilities index bd8d6c7b89df..f46c27e92a22 160000 --- a/src/sonic-utilities +++ b/src/sonic-utilities @@ -1 +1 @@ -Subproject commit bd8d6c7b89dffe7f95d48c71a8092fd77d40b32d +Subproject commit f46c27e92a22c361457563fdb111dbf440b897c4 From baf95b80832c7bc03f78a90e9c2927ea4edad12a Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Mon, 16 Nov 2020 04:28:37 +0000 Subject: [PATCH 04/24] Add 'pyang' to install dependencies of sonic-yang-mgmt package --- src/sonic-yang-mgmt/setup.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/sonic-yang-mgmt/setup.py b/src/sonic-yang-mgmt/setup.py index e1b037cdcdfa..0c44c2e6a545 100644 --- a/src/sonic-yang-mgmt/setup.py +++ b/src/sonic-yang-mgmt/setup.py @@ -25,13 +25,14 @@ license="GNU General Public License v3", long_description=readme + '\n\n', install_requires = [ - 'xmltodict==0.12.0', - 'ijson==2.6.1' + 'ijson==2.6.1', + 'pyang==2.1.1', + 'xmltodict==0.12.0' ], tests_require = [ + 'ijson==2.6.1', 'pytest>3', - 'xmltodict==0.12.0', - 'ijson==2.6.1' + 'xmltodict==0.12.0' ], setup_requires = [ 'pytest-runner', From 170f6833f9a4ac2b1f0cad4999d97658f612d9af Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Mon, 16 Nov 2020 07:32:29 +0000 Subject: [PATCH 05/24] Install pyang in Buster slave container --- sonic-slave-buster/Dockerfile.j2 | 1 + 1 file changed, 1 insertion(+) diff --git a/sonic-slave-buster/Dockerfile.j2 b/sonic-slave-buster/Dockerfile.j2 index b58027bf30d4..909a8e0b2e9c 100644 --- a/sonic-slave-buster/Dockerfile.j2 +++ b/sonic-slave-buster/Dockerfile.j2 @@ -392,6 +392,7 @@ RUN pip3 install Pympler==0.8 # For sonic_yang_model build RUN pip2 install pyang==2.1.1 +RUN pip3 install pyang==2.1.1 # For mgmt-framework build RUN pip2 install mmh3 From 37028c37e1af48546aa52b17b2a1463486ab8d15 Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Mon, 16 Nov 2020 17:42:11 +0000 Subject: [PATCH 06/24] Install Python 3 libyang package in VS container --- platform/vs/docker-sonic-vs.mk | 2 ++ 1 file changed, 2 insertions(+) diff --git a/platform/vs/docker-sonic-vs.mk b/platform/vs/docker-sonic-vs.mk index afaf2d8e835b..9cb59ca2188f 100644 --- a/platform/vs/docker-sonic-vs.mk +++ b/platform/vs/docker-sonic-vs.mk @@ -12,6 +12,7 @@ $(DOCKER_SONIC_VS)_DEPENDS += $(SWSS) \ $(LIBYANG) \ $(LIBYANG_CPP) \ $(LIBYANG_PY2) \ + $(LIBYANG_PY3) \ $(SONIC_UTILITIES_DATA) \ $(SONIC_HOST_SERVICES_DATA) @@ -22,6 +23,7 @@ $(DOCKER_SONIC_VS)_PYTHON_WHEELS += $(SWSSSDK_PY2) \ $(SONIC_PY_COMMON_PY2) \ $(SONIC_PY_COMMON_PY3) \ $(SONIC_YANG_MODELS_PY3) \ + $(SONIC_YANG_MGMT_PY2) \ $(SONIC_YANG_MGMT_PY3) \ $(SONIC_UTILITIES_PY3) \ $(SONIC_HOST_SERVICES_PY3) From 40a115b16a7789715ca6bc6c5e502d41a3e52478 Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Mon, 16 Nov 2020 20:59:47 +0000 Subject: [PATCH 07/24] Install Python 3 sonic-config-engine package in host OS --- files/build_templates/sonic_debian_extension.j2 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index ce72f379a15c..7f154a602a09 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -144,12 +144,18 @@ sudo cp {{sonic_py_common_py3_wheel_path}} $FILESYSTEM_ROOT/$SONIC_PY_COMMON_PY3 sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip3 install $SONIC_PY_COMMON_PY3_WHEEL_NAME sudo rm -rf $FILESYSTEM_ROOT/$SONIC_PY_COMMON_PY3_WHEEL_NAME -# Install SONiC config engine Python package +# Install SONiC config engine Python 2 package CONFIG_ENGINE_PY2_WHEEL_NAME=$(basename {{config_engine_py2_wheel_path}}) sudo cp {{config_engine_py2_wheel_path}} $FILESYSTEM_ROOT/$CONFIG_ENGINE_PY2_WHEEL_NAME sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip2 install $CONFIG_ENGINE_PY2_WHEEL_NAME sudo rm -rf $FILESYSTEM_ROOT/$CONFIG_ENGINE_PY2_WHEEL_NAME +# Install SONiC config engine Python 3 package +CONFIG_ENGINE_PY3_WHEEL_NAME=$(basename {{config_engine_py3_wheel_path}}) +sudo cp {{config_engine_py3_wheel_path}} $FILESYSTEM_ROOT/$CONFIG_ENGINE_PY3_WHEEL_NAME +sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip3 install $CONFIG_ENGINE_PY3_WHEEL_NAME +sudo rm -rf $FILESYSTEM_ROOT/$CONFIG_ENGINE_PY3_WHEEL_NAME + # Install sonic-yang-models py3 package, install dependencies sudo dpkg --root=$FILESYSTEM_ROOT -i $debs_path/libyang_*.deb sudo dpkg --root=$FILESYSTEM_ROOT -i $debs_path/libyang-cpp_*.deb From 093e1b9aa5bf1eb0294f325fb832cb93d5a1c4d4 Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Mon, 16 Nov 2020 21:06:03 +0000 Subject: [PATCH 08/24] Revert "Add 'pyang' to install dependencies of sonic-yang-mgmt package" This reverts commit 1a3233c106c4028f2c23bdbe145b02d196906ab2. --- src/sonic-yang-mgmt/setup.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/sonic-yang-mgmt/setup.py b/src/sonic-yang-mgmt/setup.py index 0c44c2e6a545..e1b037cdcdfa 100644 --- a/src/sonic-yang-mgmt/setup.py +++ b/src/sonic-yang-mgmt/setup.py @@ -25,14 +25,13 @@ license="GNU General Public License v3", long_description=readme + '\n\n', install_requires = [ - 'ijson==2.6.1', - 'pyang==2.1.1', - 'xmltodict==0.12.0' + 'xmltodict==0.12.0', + 'ijson==2.6.1' ], tests_require = [ - 'ijson==2.6.1', 'pytest>3', - 'xmltodict==0.12.0' + 'xmltodict==0.12.0', + 'ijson==2.6.1' ], setup_requires = [ 'pytest-runner', From 8f9ab6620eb96029acedbbbef815363f3c5b8085 Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Tue, 17 Nov 2020 19:50:38 +0000 Subject: [PATCH 09/24] [sonic-confic-engine] Use integer division in config_samples.py --- src/sonic-config-engine/config_samples.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sonic-config-engine/config_samples.py b/src/sonic-config-engine/config_samples.py index be8ab3e0a955..9072e0209c3e 100644 --- a/src/sonic-config-engine/config_samples.py +++ b/src/sonic-config-engine/config_samples.py @@ -13,10 +13,10 @@ def generate_t1_sample_config(data): for port in natsorted(data['PORT']): data['PORT'][port]['admin_status'] = 'up' data['PORT'][port]['mtu'] = '9100' - local_addr = '10.0.{}.{}'.format(2 * port_count / 256, 2 * port_count % 256) - peer_addr = '10.0.{}.{}'.format(2 * port_count / 256, 2 * port_count % 256 + 1) - peer_name='ARISTA{0:02d}{1}'.format(1+port_count%(total_port_amount/2), 'T2' if port_count < (total_port_amount/2) else 'T0') - peer_asn = 65200 if port_count < total_port_amount/2 else 64001 + port_count - total_port_amount/2 + local_addr = '10.0.{}.{}'.format(2 * port_count // 256, 2 * port_count % 256) + peer_addr = '10.0.{}.{}'.format(2 * port_count // 256, 2 * port_count % 256 + 1) + peer_name='ARISTA{0:02d}{1}'.format(1+port_count%(total_port_amount // 2), 'T2' if port_count < (total_port_amount // 2) else 'T0') + peer_asn = 65200 if port_count < (total_port_amount // 2) else 64001 + port_count - (total_port_amount // 2) data['INTERFACE']['{}|{}/31'.format(port, local_addr)] = {} data['BGP_NEIGHBOR'][peer_addr] = { 'rrclient': 0, From 25e5e550a19a758e4cf37eebe8464a51a7fbd4e0 Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Tue, 17 Nov 2020 19:51:11 +0000 Subject: [PATCH 10/24] [x86_64-kvm_x86_64-r0] Use Python 3-compliant print function in eeprom.py --- device/virtual/x86_64-kvm_x86_64-r0/plugins/eeprom.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/device/virtual/x86_64-kvm_x86_64-r0/plugins/eeprom.py b/device/virtual/x86_64-kvm_x86_64-r0/plugins/eeprom.py index 5cc8cb68018f..4fa5d4e91eaa 100644 --- a/device/virtual/x86_64-kvm_x86_64-r0/plugins/eeprom.py +++ b/device/virtual/x86_64-kvm_x86_64-r0/plugins/eeprom.py @@ -35,7 +35,7 @@ def read_eeprom(self): """ def decode_eeprom(self, e): - print e + print(e) def serial_number_str(self, e): """Return service tag instead of serial number""" From 53877c113cb9200580c2ca5c6cec65f5b5deea2b Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Wed, 18 Nov 2020 19:59:42 +0000 Subject: [PATCH 11/24] Update utilities further * src/sonic-utilities f46c27e...9d55082 (3): > [configlet][portconfig] Remove calls to dict.has_key() which is not available in Python 3 (#1247) > Remove unnecessary conversions to list() and calls to dict.keys() (#1243) > Clean up LGTM alerts (#1239) --- src/sonic-utilities | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-utilities b/src/sonic-utilities index f46c27e92a22..9d550829d7cc 160000 --- a/src/sonic-utilities +++ b/src/sonic-utilities @@ -1 +1 @@ -Subproject commit f46c27e92a22c361457563fdb111dbf440b897c4 +Subproject commit 9d550829d7ccd5a6fb89dbfb3bbbb40357820e4d From b757b0c31b99eff2cffde53c286862504c64f473 Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Wed, 18 Nov 2020 20:55:25 +0000 Subject: [PATCH 12/24] Update swsssdk submodule --- src/sonic-py-swsssdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-py-swsssdk b/src/sonic-py-swsssdk index 9d9f0c60239d..1664be94387c 160000 --- a/src/sonic-py-swsssdk +++ b/src/sonic-py-swsssdk @@ -1 +1 @@ -Subproject commit 9d9f0c60239d9b02e7589b8cedeafcc4e60bd7c8 +Subproject commit 1664be94387ccb3088f4176bf4b701c68796ef50 From e70daa29d22f456540749f799b3cf8ccdcbb5594 Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Thu, 19 Nov 2020 19:02:15 +0000 Subject: [PATCH 13/24] Explicitly install Python 3 pyangbind and uninstall enum 34 in host and VS container --- files/build_templates/sonic_debian_extension.j2 | 8 ++++++++ platform/vs/docker-sonic-vs/Dockerfile.j2 | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index 7f154a602a09..461c629284e7 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -150,6 +150,14 @@ sudo cp {{config_engine_py2_wheel_path}} $FILESYSTEM_ROOT/$CONFIG_ENGINE_PY2_WHE sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip2 install $CONFIG_ENGINE_PY2_WHEEL_NAME sudo rm -rf $FILESYSTEM_ROOT/$CONFIG_ENGINE_PY2_WHEEL_NAME +# For sonic-config-engine Python 3 package +# Install pyangbind here, outside sonic-config-engine dependencies, as pyangbind causes enum34 to be installed. +# Then immediately uninstall enum34, as enum34 should not be installed for Python >= 3.4, as it causes a +# conflict with the new 'enum' module in the standard library +# https://github.com/robshakir/pyangbind/issues/232 +sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip3 install pyangbind==0.8.1 +sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip3 uninstall -y enum34 + # Install SONiC config engine Python 3 package CONFIG_ENGINE_PY3_WHEEL_NAME=$(basename {{config_engine_py3_wheel_path}}) sudo cp {{config_engine_py3_wheel_path}} $FILESYSTEM_ROOT/$CONFIG_ENGINE_PY3_WHEEL_NAME diff --git a/platform/vs/docker-sonic-vs/Dockerfile.j2 b/platform/vs/docker-sonic-vs/Dockerfile.j2 index 054446e525b0..2798095556cb 100644 --- a/platform/vs/docker-sonic-vs/Dockerfile.j2 +++ b/platform/vs/docker-sonic-vs/Dockerfile.j2 @@ -83,6 +83,14 @@ RUN pip2 install urllib3 RUN pip2 install requests RUN pip2 install crontab +# For sonic-config-engine Python 3 package +# Install pyangbind here, outside sonic-config-engine dependencies, as pyangbind causes enum34 to be installed. +# Then immediately uninstall enum34, as enum34 should not be installed for Python >= 3.4, as it causes a +# conflict with the new 'enum' module in the standard library +# https://github.com/robshakir/pyangbind/issues/232 +RUN pip3 install pyangbind==0.8.1 +RUN pip3 uninstall -y enum34 + {% if docker_sonic_vs_debs.strip() -%} # Copy locally-built Debian package dependencies {%- for deb in docker_sonic_vs_debs.split(' ') %} From 3c47a6ae075e3a246e104115bdfee49fd3984d53 Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Fri, 20 Nov 2020 18:00:20 +0000 Subject: [PATCH 14/24] Update utils further --- src/sonic-utilities | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-utilities b/src/sonic-utilities index 9d550829d7cc..0d1d6e1ee0cf 160000 --- a/src/sonic-utilities +++ b/src/sonic-utilities @@ -1 +1 @@ -Subproject commit 9d550829d7ccd5a6fb89dbfb3bbbb40357820e4d +Subproject commit 0d1d6e1ee0cfea502b1992ee81b08eb1b504f18e From 576d9b8bc2f2d6dadf8ca812ff3f84a7202caf13 Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Sat, 21 Nov 2020 19:12:14 +0000 Subject: [PATCH 15/24] Update utils further --- src/sonic-utilities | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-utilities b/src/sonic-utilities index 0d1d6e1ee0cf..b44536466d13 160000 --- a/src/sonic-utilities +++ b/src/sonic-utilities @@ -1 +1 @@ -Subproject commit 0d1d6e1ee0cfea502b1992ee81b08eb1b504f18e +Subproject commit b44536466d132ad44d11da4bc014752a71aa32ec From c95f65d3b0a8ebe42d2993a0e3a1ee77d0aaeaa1 Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Sat, 21 Nov 2020 21:04:35 +0000 Subject: [PATCH 16/24] Make all eeprom plugins Python 3-compliant to work with Python 3 decode-syseeprom --- .../x86_64-accton_as4630_54pe-r0/plugins/eeprom.py | 5 +---- .../x86_64-accton_as5712_54x-r0/plugins/eeprom.py | 5 +---- .../x86_64-accton_as5812_54t-r0/plugins/eeprom.py | 3 +-- .../x86_64-accton_as5812_54x-r0/plugins/eeprom.py | 5 +---- .../x86_64-accton_as5835_54t-r0/plugins/eeprom.py | 5 +---- .../x86_64-accton_as5835_54x-r0/plugins/eeprom.py | 5 +---- .../x86_64-accton_as6712_32x-r0/plugins/eeprom.py | 4 +--- .../x86_64-accton_as7116_54x-r0/plugins/eeprom.py | 5 +---- .../sonic_platform/eeprom.py | 8 ++++++-- .../x86_64-accton_as7212_54x-r0/plugins/eeprom.py | 5 +---- .../x86_64-accton_as7312_54x-r0/plugins/eeprom.py | 5 +---- .../x86_64-accton_as7312_54xs-r0/plugins/eeprom.py | 5 +---- .../x86_64-accton_as7315_27xb-r0/plugins/eeprom.py | 5 +---- .../x86_64-accton_as7326_56x-r0/plugins/eeprom.py | 5 +---- .../x86_64-accton_as7512_32x-r0/plugins/eeprom.py | 5 +---- .../x86_64-accton_as7712_32x-r0/plugins/eeprom.py | 3 +-- .../x86_64-accton_as7716_32x-r0/plugins/eeprom.py | 5 +---- .../x86_64-accton_as7716_32xb-r0/plugins/eeprom.py | 5 +---- .../x86_64-accton_as7726_32x-r0/plugins/eeprom.py | 5 +---- .../x86_64-accton_as7816_64x-r0/plugins/eeprom.py | 5 +---- .../x86_64-accton_as9716_32d-r0/plugins/eeprom.py | 5 +---- .../x86_64-accton_minipack-r0/plugins/eeprom.py | 5 +---- .../plugins/eeprom.py | 5 +---- .../plugins/eeprom.py | 5 +---- .../plugins/eeprom.py | 12 +++++++----- device/broadcom/x86_64-bcm_xlr-r0/plugins/eeprom.py | 4 +--- .../celestica/x86_64-cel_e1031-r0/plugins/eeprom.py | 4 +--- .../x86_64-cel_e1031-r0/sonic_platform/eeprom.py | 12 +++++++----- .../x86_64-cel_midstone-r0/plugins/eeprom.py | 4 +--- .../x86_64-cel_seastone-r0/plugins/eeprom.py | 4 +--- .../x86_64-cel_seastone-r0/sonic_platform/eeprom.py | 12 +++++++----- .../x86_64-cel_seastone_2-r0/plugins/eeprom.py | 4 +--- .../x86_64-cel_silverstone-r0/plugins/eeprom.py | 4 +--- .../sonic_platform/eeprom.py | 12 +++++++----- .../arm64-centec_e530_24x2c-r0/plugins/eeprom.py | 4 +--- .../arm64-centec_e530_48t4x_p-r0/plugins/eeprom.py | 4 +--- .../x86_64-centec_e582_48x2q4z-r0/plugins/eeprom.py | 5 +---- .../x86_64-centec_e582_48x6q-r0/plugins/eeprom.py | 5 +---- .../x86_64-ew_es6220_x48q2h4-r0/plugins/eeprom.py | 5 +---- .../cig/x86_64-cig_cs5435_54p-r0/plugins/eeprom.py | 5 +---- .../cig/x86_64-cig_cs6436_54p-r0/plugins/eeprom.py | 6 +----- .../cig/x86_64-cig_cs6436_56p-r0/plugins/eeprom.py | 5 +---- device/common/pddf/plugins/eeprom.py | 4 +--- .../x86_64-dellemc_s5296f_c3538-r0/plugins/eeprom.py | 4 +--- .../delta/x86_64-delta_ag5648-r0/plugins/eeprom.py | 3 +-- .../delta/x86_64-delta_ag9032v1-r0/plugins/eeprom.py | 5 +---- .../x86_64-delta_ag9032v2a-r0/plugins/eeprom.py | 5 +---- .../delta/x86_64-delta_ag9064-r0/plugins/eeprom.py | 5 +---- .../delta/x86_64-delta_agc032-r0/plugins/eeprom.py | 4 +--- .../x86_64-delta_et-6248brb-r0/plugins/eeprom.py | 5 +---- .../x86_64-delta_et-c032if-r0/plugins/eeprom.py | 5 +---- .../x86_64-ingrasys_s8810_32q-r0/plugins/eeprom.py | 4 +--- .../x86_64-ingrasys_s8900_54xc-r0/plugins/eeprom.py | 4 +--- .../x86_64-ingrasys_s8900_64xc-r0/plugins/eeprom.py | 4 +--- .../x86_64-ingrasys_s9100-r0/plugins/eeprom.py | 4 +--- .../x86_64-ingrasys_s9130_32x-r0/plugins/eeprom.py | 4 +--- .../x86_64-ingrasys_s9180_32x-r0/plugins/eeprom.py | 4 +--- .../x86_64-ingrasys_s9200_64x-r0/plugins/eeprom.py | 4 +--- .../x86_64-ingrasys_s9230_64x-r0/plugins/eeprom.py | 4 +--- .../x86_64-ingrasys_s9280_64x-r0/plugins/eeprom.py | 4 +--- .../x86_64-inventec_d6254qs-r0/plugins/eeprom.py | 4 +--- .../x86_64-inventec_d6332-r0/plugins/eeprom.py | 4 +--- .../x86_64-inventec_d6356-r0/plugins/eeprom.py | 4 +--- .../x86_64-inventec_d6556-r0/plugins/eeprom.py | 4 +--- .../x86_64-inventec_d7032q28b-r0/plugins/eeprom.py | 4 +--- .../x86_64-inventec_d7054q28b-r0/plugins/eeprom.py | 4 +--- .../x86_64-inventec_d7264q28b-r0/plugins/eeprom.py | 4 +--- .../x86_64-juniper_qfx5200-r0/plugins/eeprom.py | 4 +--- .../x86_64-juniper_qfx5210-r0/plugins/eeprom.py | 6 +----- .../plugins/eeprom.py | 4 +--- .../plugins/eeprom.py | 4 +--- .../armhf-marvell_et6448m_52x-r0/plugins/eeprom.py | 4 +--- .../plugins/eeprom.py | 4 +--- .../plugins/eeprom.py | 4 +--- .../x86_64-marvell_slm5401_54x-r0/plugins/eeprom.py | 5 +---- .../x86_64-mlnx_msn2700-r0/plugins/eeprom.py | 12 +++++++----- .../plugins/eeprom.py | 5 +---- .../x86_64-pegatron_porsche-r0/plugins/eeprom.py | 5 +---- .../x86_64-quanta_ix1b_rglbmc-r0/plugins/eeprom.py | 5 +---- .../x86_64-quanta_ix7_rglbmc-r0/plugins/eeprom.py | 5 +---- .../x86_64-quanta_ix8_rglbmc-r0/plugins/eeprom.py | 5 +---- .../x86_64-quanta_ix8c_bwde-r0/plugins/eeprom.py | 3 +-- .../x86_64-quanta_ix9_bwde-r0/plugins/eeprom.py | 3 +-- device/wnc/x86_64-wnc_osw1800-r0/plugins/eeprom.py | 5 +---- .../sonic_platform/eeprom.py | 11 ++++++----- .../services/platform_api/sonic_platform/eeprom.py | 11 +++++++---- .../d6332/sonic_platform/eeprom.py | 3 +-- .../d6356/sonic_platform/eeprom.py | 3 +-- .../d7054q28b/sonic_platform/eeprom.py | 3 +-- .../mlnx-platform-api/sonic_platform/eeprom.py | 9 +++++---- .../sonic_platform_pddf_base/pddf_eeprom.py | 4 +--- .../sonic_platform_ref/eeprom.py | 4 +--- 92 files changed, 142 insertions(+), 322 deletions(-) diff --git a/device/accton/x86_64-accton_as4630_54pe-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as4630_54pe-r0/plugins/eeprom.py index 0d7def70fdc0..5f7cee8d0b3e 100755 --- a/device/accton/x86_64-accton_as4630_54pe-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as4630_54pe-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,7 +8,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/accton/x86_64-accton_as5712_54x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as5712_54x-r0/plugins/eeprom.py index 7681caafeef4..e7f6a39411d5 100644 --- a/device/accton/x86_64-accton_as5712_54x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as5712_54x-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,7 +8,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/accton/x86_64-accton_as5812_54t-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as5812_54t-r0/plugins/eeprom.py index 7681caafeef4..384f903dc2ad 100644 --- a/device/accton/x86_64-accton_as5812_54t-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as5812_54t-r0/plugins/eeprom.py @@ -1,7 +1,6 @@ #!/usr/bin/env python try: - import exceptions import binascii import time import optparse @@ -11,7 +10,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/accton/x86_64-accton_as5812_54x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as5812_54x-r0/plugins/eeprom.py index 7681caafeef4..e7f6a39411d5 100644 --- a/device/accton/x86_64-accton_as5812_54x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as5812_54x-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,7 +8,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/accton/x86_64-accton_as5835_54t-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as5835_54t-r0/plugins/eeprom.py index 7681caafeef4..e7f6a39411d5 100644 --- a/device/accton/x86_64-accton_as5835_54t-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as5835_54t-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,7 +8,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/accton/x86_64-accton_as5835_54x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as5835_54x-r0/plugins/eeprom.py index 7681caafeef4..e7f6a39411d5 100644 --- a/device/accton/x86_64-accton_as5835_54x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as5835_54x-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,7 +8,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/accton/x86_64-accton_as6712_32x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as6712_32x-r0/plugins/eeprom.py index 7681caafeef4..b653e8f90d9a 100644 --- a/device/accton/x86_64-accton_as6712_32x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as6712_32x-r0/plugins/eeprom.py @@ -1,7 +1,6 @@ #!/usr/bin/env python try: - import exceptions import binascii import time import optparse @@ -10,8 +9,7 @@ import sys from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo - import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/accton/x86_64-accton_as7116_54x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as7116_54x-r0/plugins/eeprom.py index 1e7d1046d93d..1183e929ea01 100644 --- a/device/accton/x86_64-accton_as7116_54x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as7116_54x-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,7 +8,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/eeprom.py b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/eeprom.py index 714ac8153e0e..836a5e30ac8e 100644 --- a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/eeprom.py +++ b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/eeprom.py @@ -11,10 +11,14 @@ import glob import os import sys - import imp import re from array import array - from cStringIO import StringIO + + if sys.version_info.major == 3: + from io import StringIO + else: + from cStringIO import StringIO + from sonic_platform_base.sonic_eeprom import eeprom_dts from sonic_platform_base.sonic_eeprom import eeprom_tlvinfo except ImportError as e: diff --git a/device/accton/x86_64-accton_as7212_54x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as7212_54x-r0/plugins/eeprom.py index 7681caafeef4..e7f6a39411d5 100755 --- a/device/accton/x86_64-accton_as7212_54x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as7212_54x-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,7 +8,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/accton/x86_64-accton_as7312_54x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as7312_54x-r0/plugins/eeprom.py index 7681caafeef4..e7f6a39411d5 100644 --- a/device/accton/x86_64-accton_as7312_54x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as7312_54x-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,7 +8,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/accton/x86_64-accton_as7312_54xs-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as7312_54xs-r0/plugins/eeprom.py index 7681caafeef4..e7f6a39411d5 100644 --- a/device/accton/x86_64-accton_as7312_54xs-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as7312_54xs-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,7 +8,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/accton/x86_64-accton_as7315_27xb-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as7315_27xb-r0/plugins/eeprom.py index 171593068ae5..414249503088 100644 --- a/device/accton/x86_64-accton_as7315_27xb-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as7315_27xb-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,7 +8,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/accton/x86_64-accton_as7326_56x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as7326_56x-r0/plugins/eeprom.py index 1e7d1046d93d..1183e929ea01 100644 --- a/device/accton/x86_64-accton_as7326_56x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as7326_56x-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,7 +8,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/accton/x86_64-accton_as7512_32x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as7512_32x-r0/plugins/eeprom.py index 6e2c0c8bb96f..6c4d1915337d 100644 --- a/device/accton/x86_64-accton_as7512_32x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as7512_32x-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Cavium # @@ -10,7 +8,6 @@ ############################################################################# try: - import exceptions import binascii import time import optparse @@ -20,7 +17,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/accton/x86_64-accton_as7712_32x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as7712_32x-r0/plugins/eeprom.py index 7681caafeef4..384f903dc2ad 100644 --- a/device/accton/x86_64-accton_as7712_32x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as7712_32x-r0/plugins/eeprom.py @@ -1,7 +1,6 @@ #!/usr/bin/env python try: - import exceptions import binascii import time import optparse @@ -11,7 +10,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/accton/x86_64-accton_as7716_32x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as7716_32x-r0/plugins/eeprom.py index c0122e65844a..abb1cf9eb8bf 100755 --- a/device/accton/x86_64-accton_as7716_32x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as7716_32x-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,7 +8,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/accton/x86_64-accton_as7716_32xb-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as7716_32xb-r0/plugins/eeprom.py index 6fa5719afbad..34924aaed973 100755 --- a/device/accton/x86_64-accton_as7716_32xb-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as7716_32xb-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,7 +8,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/accton/x86_64-accton_as7726_32x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as7726_32x-r0/plugins/eeprom.py index 68ed5f9466b0..1a411807e3ed 100755 --- a/device/accton/x86_64-accton_as7726_32x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as7726_32x-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,7 +8,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/accton/x86_64-accton_as7816_64x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as7816_64x-r0/plugins/eeprom.py index 1e7d1046d93d..1183e929ea01 100644 --- a/device/accton/x86_64-accton_as7816_64x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as7816_64x-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,7 +8,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/accton/x86_64-accton_as9716_32d-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as9716_32d-r0/plugins/eeprom.py index bb125d3c0cbb..6cf20f4046d3 100644 --- a/device/accton/x86_64-accton_as9716_32d-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as9716_32d-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,7 +8,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") def eeprom_check(): diff --git a/device/accton/x86_64-accton_minipack-r0/plugins/eeprom.py b/device/accton/x86_64-accton_minipack-r0/plugins/eeprom.py index c1ac366fc3fa..a3bd41b12d31 100644 --- a/device/accton/x86_64-accton_minipack-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_minipack-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,7 +8,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/eeprom.py b/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/eeprom.py index c0122e65844a..abb1cf9eb8bf 100644 --- a/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/eeprom.py +++ b/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,7 +8,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/eeprom.py b/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/eeprom.py index c0122e65844a..abb1cf9eb8bf 100644 --- a/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/eeprom.py +++ b/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,7 +8,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/eeprom.py b/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/eeprom.py index 937cc003f60e..bf3795429309 100644 --- a/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/eeprom.py +++ b/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/eeprom.py @@ -1,6 +1,3 @@ -#!/usr/bin/python - - try: import importlib import time @@ -23,10 +20,15 @@ from thrift.protocol import TMultiplexedProtocol from argparse import ArgumentParser - from cStringIO import StringIO + + if sys.version_info.major == 3: + from io import StringIO + else: + from cStringIO import StringIO + from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") diff --git a/device/broadcom/x86_64-bcm_xlr-r0/plugins/eeprom.py b/device/broadcom/x86_64-bcm_xlr-r0/plugins/eeprom.py index 25ea4849f7d5..dc74870344d8 100644 --- a/device/broadcom/x86_64-bcm_xlr-r0/plugins/eeprom.py +++ b/device/broadcom/x86_64-bcm_xlr-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Broadcom XLR/GTS 'eeprom' support # @@ -16,7 +14,7 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") diff --git a/device/celestica/x86_64-cel_e1031-r0/plugins/eeprom.py b/device/celestica/x86_64-cel_e1031-r0/plugins/eeprom.py index 6577631c8908..43a40dec8539 100644 --- a/device/celestica/x86_64-cel_e1031-r0/plugins/eeprom.py +++ b/device/celestica/x86_64-cel_e1031-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica Haliburton # @@ -11,7 +9,7 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") diff --git a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/eeprom.py b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/eeprom.py index 20f3db111f66..0058fccfa0ca 100644 --- a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/eeprom.py +++ b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica Haliburton # @@ -13,13 +11,17 @@ import glob import os import sys - import imp import re from array import array - from cStringIO import StringIO + + if sys.version_info.major == 3: + from io import StringIO + else: + from cStringIO import StringIO + from sonic_platform_base.sonic_eeprom import eeprom_dts from sonic_platform_base.sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError(str(e) + "- required module not found") CACHE_ROOT = '/var/cache/sonic/decode-syseeprom' diff --git a/device/celestica/x86_64-cel_midstone-r0/plugins/eeprom.py b/device/celestica/x86_64-cel_midstone-r0/plugins/eeprom.py index 86e7f1b2af15..08e42ad1c40f 100755 --- a/device/celestica/x86_64-cel_midstone-r0/plugins/eeprom.py +++ b/device/celestica/x86_64-cel_midstone-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica Midstone-200i # @@ -11,7 +9,7 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") diff --git a/device/celestica/x86_64-cel_seastone-r0/plugins/eeprom.py b/device/celestica/x86_64-cel_seastone-r0/plugins/eeprom.py index 29f01a07fc73..da2c87ce9cec 100644 --- a/device/celestica/x86_64-cel_seastone-r0/plugins/eeprom.py +++ b/device/celestica/x86_64-cel_seastone-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica DX010 # @@ -11,7 +9,7 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/eeprom.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/eeprom.py index dffda1a3c050..b2b4a8122590 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/eeprom.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica Seastone-DX010 # @@ -13,13 +11,17 @@ import glob import os import sys - import imp import re from array import array - from cStringIO import StringIO + + if sys.version_info.major == 3: + from io import StringIO + else: + from cStringIO import StringIO + from sonic_platform_base.sonic_eeprom import eeprom_dts from sonic_platform_base.sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError(str(e) + "- required module not found") CACHE_ROOT = '/var/cache/sonic/decode-syseeprom' diff --git a/device/celestica/x86_64-cel_seastone_2-r0/plugins/eeprom.py b/device/celestica/x86_64-cel_seastone_2-r0/plugins/eeprom.py index 2ae540870c41..ff7beb84805d 100644 --- a/device/celestica/x86_64-cel_seastone_2-r0/plugins/eeprom.py +++ b/device/celestica/x86_64-cel_seastone_2-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica Seastone2 # @@ -11,7 +9,7 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") diff --git a/device/celestica/x86_64-cel_silverstone-r0/plugins/eeprom.py b/device/celestica/x86_64-cel_silverstone-r0/plugins/eeprom.py index 34c50a6ce31f..fab05edf9e15 100644 --- a/device/celestica/x86_64-cel_silverstone-r0/plugins/eeprom.py +++ b/device/celestica/x86_64-cel_silverstone-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica Silverstone # @@ -11,7 +9,7 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") diff --git a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/eeprom.py b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/eeprom.py index dd0c9332b54e..a2e3d946f656 100644 --- a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/eeprom.py +++ b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica Silverstone # @@ -13,13 +11,17 @@ import glob import os import sys - import imp import re from array import array - from cStringIO import StringIO + + if sys.version_info.major == 3: + from io import StringIO + else: + from cStringIO import StringIO + from sonic_platform_base.sonic_eeprom import eeprom_dts from sonic_platform_base.sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError(str(e) + "- required module not found") CACHE_ROOT = '/var/cache/sonic/decode-syseeprom' diff --git a/device/centec/arm64-centec_e530_24x2c-r0/plugins/eeprom.py b/device/centec/arm64-centec_e530_24x2c-r0/plugins/eeprom.py index 3d0c220d2421..cf57d35d99ef 100644 --- a/device/centec/arm64-centec_e530_24x2c-r0/plugins/eeprom.py +++ b/device/centec/arm64-centec_e530_24x2c-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Centec E550-24X8Y2C # @@ -11,7 +9,7 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") diff --git a/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/eeprom.py b/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/eeprom.py index 3d0c220d2421..cf57d35d99ef 100644 --- a/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/eeprom.py +++ b/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Centec E550-24X8Y2C # @@ -11,7 +9,7 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") diff --git a/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/eeprom.py b/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/eeprom.py index 3fd55c63d8b7..ed2448c7d290 100644 --- a/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/eeprom.py +++ b/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Centec E582-48X6Q # @@ -10,7 +8,6 @@ ############################################################################# try: - import exceptions import binascii import time import optparse @@ -20,7 +17,7 @@ import subprocess from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") diff --git a/device/centec/x86_64-centec_e582_48x6q-r0/plugins/eeprom.py b/device/centec/x86_64-centec_e582_48x6q-r0/plugins/eeprom.py index 3fd55c63d8b7..ed2448c7d290 100644 --- a/device/centec/x86_64-centec_e582_48x6q-r0/plugins/eeprom.py +++ b/device/centec/x86_64-centec_e582_48x6q-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Centec E582-48X6Q # @@ -10,7 +8,6 @@ ############################################################################# try: - import exceptions import binascii import time import optparse @@ -20,7 +17,7 @@ import subprocess from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") diff --git a/device/centec/x86_64-ew_es6220_x48q2h4-r0/plugins/eeprom.py b/device/centec/x86_64-ew_es6220_x48q2h4-r0/plugins/eeprom.py index 8ac693f7cf58..fbe9bc5be02f 100644 --- a/device/centec/x86_64-ew_es6220_x48q2h4-r0/plugins/eeprom.py +++ b/device/centec/x86_64-ew_es6220_x48q2h4-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # EmbedWay # @@ -10,7 +8,6 @@ ############################################################################# try: - import exceptions import binascii import time import optparse @@ -20,7 +17,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/cig/x86_64-cig_cs5435_54p-r0/plugins/eeprom.py b/device/cig/x86_64-cig_cs5435_54p-r0/plugins/eeprom.py index 5019b9c40a9a..e22124e5fc89 100755 --- a/device/cig/x86_64-cig_cs5435_54p-r0/plugins/eeprom.py +++ b/device/cig/x86_64-cig_cs5435_54p-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,7 +8,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/cig/x86_64-cig_cs6436_54p-r0/plugins/eeprom.py b/device/cig/x86_64-cig_cs6436_54p-r0/plugins/eeprom.py index 5019b9c40a9a..ce0e273f2203 100755 --- a/device/cig/x86_64-cig_cs6436_54p-r0/plugins/eeprom.py +++ b/device/cig/x86_64-cig_cs6436_54p-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -10,8 +7,7 @@ import sys from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo - import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/cig/x86_64-cig_cs6436_56p-r0/plugins/eeprom.py b/device/cig/x86_64-cig_cs6436_56p-r0/plugins/eeprom.py index 5019b9c40a9a..e22124e5fc89 100755 --- a/device/cig/x86_64-cig_cs6436_56p-r0/plugins/eeprom.py +++ b/device/cig/x86_64-cig_cs6436_56p-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,7 +8,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/common/pddf/plugins/eeprom.py b/device/common/pddf/plugins/eeprom.py index 7671c50bd345..c645cbd8bc04 100755 --- a/device/common/pddf/plugins/eeprom.py +++ b/device/common/pddf/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - try: import os import sys @@ -8,7 +6,7 @@ import pddfparse #from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") diff --git a/device/dell/x86_64-dellemc_s5296f_c3538-r0/plugins/eeprom.py b/device/dell/x86_64-dellemc_s5296f_c3538-r0/plugins/eeprom.py index da50f1f851f9..a1cc6a5864fc 100644 --- a/device/dell/x86_64-dellemc_s5296f_c3538-r0/plugins/eeprom.py +++ b/device/dell/x86_64-dellemc_s5296f_c3538-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # DellEMC S5296f # @@ -13,7 +11,7 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") diff --git a/device/delta/x86_64-delta_ag5648-r0/plugins/eeprom.py b/device/delta/x86_64-delta_ag5648-r0/plugins/eeprom.py index 786e1fdc85e3..7d4054fb5a0c 100644 --- a/device/delta/x86_64-delta_ag5648-r0/plugins/eeprom.py +++ b/device/delta/x86_64-delta_ag5648-r0/plugins/eeprom.py @@ -10,7 +10,6 @@ ############################################################################# try: - import exceptions import binascii import time import optparse @@ -20,7 +19,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/delta/x86_64-delta_ag9032v1-r0/plugins/eeprom.py b/device/delta/x86_64-delta_ag9032v1-r0/plugins/eeprom.py index 786e1fdc85e3..9112318a7915 100644 --- a/device/delta/x86_64-delta_ag9032v1-r0/plugins/eeprom.py +++ b/device/delta/x86_64-delta_ag9032v1-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Mellanox # @@ -10,7 +8,6 @@ ############################################################################# try: - import exceptions import binascii import time import optparse @@ -20,7 +17,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/delta/x86_64-delta_ag9032v2a-r0/plugins/eeprom.py b/device/delta/x86_64-delta_ag9032v2a-r0/plugins/eeprom.py index fc741c11e9ea..c023b80c6501 100644 --- a/device/delta/x86_64-delta_ag9032v2a-r0/plugins/eeprom.py +++ b/device/delta/x86_64-delta_ag9032v2a-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Mellanox # @@ -10,7 +8,6 @@ ############################################################################# try: - import exceptions import binascii import time import optparse @@ -20,7 +17,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/delta/x86_64-delta_ag9064-r0/plugins/eeprom.py b/device/delta/x86_64-delta_ag9064-r0/plugins/eeprom.py index e4048ed302de..37a4dfd71be2 100644 --- a/device/delta/x86_64-delta_ag9064-r0/plugins/eeprom.py +++ b/device/delta/x86_64-delta_ag9064-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Mellanox # @@ -10,7 +8,6 @@ ############################################################################# try: - import exceptions import binascii import time import optparse @@ -20,7 +17,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/delta/x86_64-delta_agc032-r0/plugins/eeprom.py b/device/delta/x86_64-delta_agc032-r0/plugins/eeprom.py index 631adbfc6bbd..a57cd91c0ca0 100644 --- a/device/delta/x86_64-delta_agc032-r0/plugins/eeprom.py +++ b/device/delta/x86_64-delta_agc032-r0/plugins/eeprom.py @@ -1,8 +1,6 @@ -#!/usr/bin/env python - try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/delta/x86_64-delta_et-6248brb-r0/plugins/eeprom.py b/device/delta/x86_64-delta_et-6248brb-r0/plugins/eeprom.py index 11c9285f47db..5029ffc8d554 100644 --- a/device/delta/x86_64-delta_et-6248brb-r0/plugins/eeprom.py +++ b/device/delta/x86_64-delta_et-6248brb-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Mellanox # @@ -10,7 +8,6 @@ ############################################################################# try: - import exceptions import binascii import time import optparse @@ -20,7 +17,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/delta/x86_64-delta_et-c032if-r0/plugins/eeprom.py b/device/delta/x86_64-delta_et-c032if-r0/plugins/eeprom.py index 1a624414637c..5254f3da2e3f 100644 --- a/device/delta/x86_64-delta_et-c032if-r0/plugins/eeprom.py +++ b/device/delta/x86_64-delta_et-c032if-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Mellanox # @@ -10,7 +8,6 @@ ############################################################################# try: - import exceptions import binascii import time import optparse @@ -20,7 +17,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/ingrasys/x86_64-ingrasys_s8810_32q-r0/plugins/eeprom.py b/device/ingrasys/x86_64-ingrasys_s8810_32q-r0/plugins/eeprom.py index 4f919ccd7273..f669e3d14692 100644 --- a/device/ingrasys/x86_64-ingrasys_s8810_32q-r0/plugins/eeprom.py +++ b/device/ingrasys/x86_64-ingrasys_s8810_32q-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Ingrasys S8810-32Q # @@ -11,7 +9,7 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") diff --git a/device/ingrasys/x86_64-ingrasys_s8900_54xc-r0/plugins/eeprom.py b/device/ingrasys/x86_64-ingrasys_s8900_54xc-r0/plugins/eeprom.py index 414ff38221bf..200b59c55c90 100644 --- a/device/ingrasys/x86_64-ingrasys_s8900_54xc-r0/plugins/eeprom.py +++ b/device/ingrasys/x86_64-ingrasys_s8900_54xc-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Dell Z9100 # @@ -11,7 +9,7 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") diff --git a/device/ingrasys/x86_64-ingrasys_s8900_64xc-r0/plugins/eeprom.py b/device/ingrasys/x86_64-ingrasys_s8900_64xc-r0/plugins/eeprom.py index 1b8de3f16bca..574e6ac06b2f 100644 --- a/device/ingrasys/x86_64-ingrasys_s8900_64xc-r0/plugins/eeprom.py +++ b/device/ingrasys/x86_64-ingrasys_s8900_64xc-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Ingrasys S8900-64XC # @@ -11,7 +9,7 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") diff --git a/device/ingrasys/x86_64-ingrasys_s9100-r0/plugins/eeprom.py b/device/ingrasys/x86_64-ingrasys_s9100-r0/plugins/eeprom.py index 83bf65a389bd..198aab9035b4 100644 --- a/device/ingrasys/x86_64-ingrasys_s9100-r0/plugins/eeprom.py +++ b/device/ingrasys/x86_64-ingrasys_s9100-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Ingrasys S9100 # @@ -11,7 +9,7 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") diff --git a/device/ingrasys/x86_64-ingrasys_s9130_32x-r0/plugins/eeprom.py b/device/ingrasys/x86_64-ingrasys_s9130_32x-r0/plugins/eeprom.py index 71ce941f1abb..a7faf85f5ca8 100644 --- a/device/ingrasys/x86_64-ingrasys_s9130_32x-r0/plugins/eeprom.py +++ b/device/ingrasys/x86_64-ingrasys_s9130_32x-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Ingrasys S9130-32X # @@ -11,7 +9,7 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") diff --git a/device/ingrasys/x86_64-ingrasys_s9180_32x-r0/plugins/eeprom.py b/device/ingrasys/x86_64-ingrasys_s9180_32x-r0/plugins/eeprom.py index d1270eeffbf6..b5f65c52b696 100644 --- a/device/ingrasys/x86_64-ingrasys_s9180_32x-r0/plugins/eeprom.py +++ b/device/ingrasys/x86_64-ingrasys_s9180_32x-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Ingrasys S9180-32X # @@ -11,7 +9,7 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") diff --git a/device/ingrasys/x86_64-ingrasys_s9200_64x-r0/plugins/eeprom.py b/device/ingrasys/x86_64-ingrasys_s9200_64x-r0/plugins/eeprom.py index 64ddb99554b0..3152c7297936 100644 --- a/device/ingrasys/x86_64-ingrasys_s9200_64x-r0/plugins/eeprom.py +++ b/device/ingrasys/x86_64-ingrasys_s9200_64x-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Ingrasys S9200-64X # @@ -11,7 +9,7 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") diff --git a/device/ingrasys/x86_64-ingrasys_s9230_64x-r0/plugins/eeprom.py b/device/ingrasys/x86_64-ingrasys_s9230_64x-r0/plugins/eeprom.py index 770b0cf43baf..cc3b5e668f5e 100644 --- a/device/ingrasys/x86_64-ingrasys_s9230_64x-r0/plugins/eeprom.py +++ b/device/ingrasys/x86_64-ingrasys_s9230_64x-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Ingrasys S9230-64X # @@ -11,7 +9,7 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") diff --git a/device/ingrasys/x86_64-ingrasys_s9280_64x-r0/plugins/eeprom.py b/device/ingrasys/x86_64-ingrasys_s9280_64x-r0/plugins/eeprom.py index ecf171539843..5f4485434068 100644 --- a/device/ingrasys/x86_64-ingrasys_s9280_64x-r0/plugins/eeprom.py +++ b/device/ingrasys/x86_64-ingrasys_s9280_64x-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Ingrasys S9280-64X # @@ -11,7 +9,7 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") diff --git a/device/inventec/x86_64-inventec_d6254qs-r0/plugins/eeprom.py b/device/inventec/x86_64-inventec_d6254qs-r0/plugins/eeprom.py index de5c24ba0e6d..c94ecca1200f 100644 --- a/device/inventec/x86_64-inventec_d6254qs-r0/plugins/eeprom.py +++ b/device/inventec/x86_64-inventec_d6254qs-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Inventec d7032q28b # @@ -11,7 +9,7 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") diff --git a/device/inventec/x86_64-inventec_d6332-r0/plugins/eeprom.py b/device/inventec/x86_64-inventec_d6332-r0/plugins/eeprom.py index b58e704a5566..78a82a32ac36 100644 --- a/device/inventec/x86_64-inventec_d6332-r0/plugins/eeprom.py +++ b/device/inventec/x86_64-inventec_d6332-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Inventec d6356j # @@ -11,7 +9,7 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") diff --git a/device/inventec/x86_64-inventec_d6356-r0/plugins/eeprom.py b/device/inventec/x86_64-inventec_d6356-r0/plugins/eeprom.py index 953570d79cd7..d3db6ca00d24 100644 --- a/device/inventec/x86_64-inventec_d6356-r0/plugins/eeprom.py +++ b/device/inventec/x86_64-inventec_d6356-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Inventec d6356 # @@ -11,7 +9,7 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") diff --git a/device/inventec/x86_64-inventec_d6556-r0/plugins/eeprom.py b/device/inventec/x86_64-inventec_d6556-r0/plugins/eeprom.py index de5c24ba0e6d..c94ecca1200f 100644 --- a/device/inventec/x86_64-inventec_d6556-r0/plugins/eeprom.py +++ b/device/inventec/x86_64-inventec_d6556-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Inventec d7032q28b # @@ -11,7 +9,7 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") diff --git a/device/inventec/x86_64-inventec_d7032q28b-r0/plugins/eeprom.py b/device/inventec/x86_64-inventec_d7032q28b-r0/plugins/eeprom.py index de5c24ba0e6d..c94ecca1200f 100644 --- a/device/inventec/x86_64-inventec_d7032q28b-r0/plugins/eeprom.py +++ b/device/inventec/x86_64-inventec_d7032q28b-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Inventec d7032q28b # @@ -11,7 +9,7 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") diff --git a/device/inventec/x86_64-inventec_d7054q28b-r0/plugins/eeprom.py b/device/inventec/x86_64-inventec_d7054q28b-r0/plugins/eeprom.py index de5c24ba0e6d..c94ecca1200f 100644 --- a/device/inventec/x86_64-inventec_d7054q28b-r0/plugins/eeprom.py +++ b/device/inventec/x86_64-inventec_d7054q28b-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Inventec d7032q28b # @@ -11,7 +9,7 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") diff --git a/device/inventec/x86_64-inventec_d7264q28b-r0/plugins/eeprom.py b/device/inventec/x86_64-inventec_d7264q28b-r0/plugins/eeprom.py index de5c24ba0e6d..c94ecca1200f 100644 --- a/device/inventec/x86_64-inventec_d7264q28b-r0/plugins/eeprom.py +++ b/device/inventec/x86_64-inventec_d7264q28b-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Inventec d7032q28b # @@ -11,7 +9,7 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") diff --git a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/eeprom.py b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/eeprom.py index 49a903290a18..b39974726354 100644 --- a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/eeprom.py +++ b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/eeprom.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # # Name: eeprom.py version: 1.0 # @@ -37,8 +36,7 @@ from sonic_eeprom import eeprom_tlvinfo import syslog from array import * - -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") SYSLOG_IDENTIFIER = "eeprom.py" diff --git a/device/juniper/x86_64-juniper_qfx5210-r0/plugins/eeprom.py b/device/juniper/x86_64-juniper_qfx5210-r0/plugins/eeprom.py index a5453dc4f0a3..b5dd80463551 100644 --- a/device/juniper/x86_64-juniper_qfx5210-r0/plugins/eeprom.py +++ b/device/juniper/x86_64-juniper_qfx5210-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -14,8 +11,7 @@ import syslog from struct import * from array import * - -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") SYSLOG_IDENTIFIER = "eeprom.py" diff --git a/device/marvell/arm64-marvell_db98cx8580_16cd-r0/plugins/eeprom.py b/device/marvell/arm64-marvell_db98cx8580_16cd-r0/plugins/eeprom.py index ea525f5d74b1..3463ca3e89e0 100644 --- a/device/marvell/arm64-marvell_db98cx8580_16cd-r0/plugins/eeprom.py +++ b/device/marvell/arm64-marvell_db98cx8580_16cd-r0/plugins/eeprom.py @@ -1,8 +1,6 @@ -#!/usr/bin/env python - try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") diff --git a/device/marvell/arm64-marvell_db98cx8580_32cd-r0/plugins/eeprom.py b/device/marvell/arm64-marvell_db98cx8580_32cd-r0/plugins/eeprom.py index ea525f5d74b1..3463ca3e89e0 100644 --- a/device/marvell/arm64-marvell_db98cx8580_32cd-r0/plugins/eeprom.py +++ b/device/marvell/arm64-marvell_db98cx8580_32cd-r0/plugins/eeprom.py @@ -1,8 +1,6 @@ -#!/usr/bin/env python - try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") diff --git a/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/eeprom.py b/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/eeprom.py index ea525f5d74b1..3463ca3e89e0 100644 --- a/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/eeprom.py +++ b/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/eeprom.py @@ -1,8 +1,6 @@ -#!/usr/bin/env python - try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") diff --git a/device/marvell/x86_64-marvell_db98cx8580_16cd-r0/plugins/eeprom.py b/device/marvell/x86_64-marvell_db98cx8580_16cd-r0/plugins/eeprom.py index ea525f5d74b1..3463ca3e89e0 100644 --- a/device/marvell/x86_64-marvell_db98cx8580_16cd-r0/plugins/eeprom.py +++ b/device/marvell/x86_64-marvell_db98cx8580_16cd-r0/plugins/eeprom.py @@ -1,8 +1,6 @@ -#!/usr/bin/env python - try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") diff --git a/device/marvell/x86_64-marvell_db98cx8580_32cd-r0/plugins/eeprom.py b/device/marvell/x86_64-marvell_db98cx8580_32cd-r0/plugins/eeprom.py index ea525f5d74b1..3463ca3e89e0 100644 --- a/device/marvell/x86_64-marvell_db98cx8580_32cd-r0/plugins/eeprom.py +++ b/device/marvell/x86_64-marvell_db98cx8580_32cd-r0/plugins/eeprom.py @@ -1,8 +1,6 @@ -#!/usr/bin/env python - try: from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") diff --git a/device/marvell/x86_64-marvell_slm5401_54x-r0/plugins/eeprom.py b/device/marvell/x86_64-marvell_slm5401_54x-r0/plugins/eeprom.py index 7681caafeef4..e7f6a39411d5 100755 --- a/device/marvell/x86_64-marvell_slm5401_54x-r0/plugins/eeprom.py +++ b/device/marvell/x86_64-marvell_slm5401_54x-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,7 +8,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/eeprom.py b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/eeprom.py index fbfe0d99ae71..e191f47d826a 100644 --- a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/eeprom.py +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Mellanox # @@ -10,7 +8,6 @@ ############################################################################# try: - import exceptions import binascii import time import optparse @@ -18,12 +15,17 @@ import os import sys import syslog - from cStringIO import StringIO + + if sys.version_info.major == 3: + from io import StringIO + else: + from cStringIO import StringIO + from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo from sonic_py_common.device_info import get_machine_info import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") SYSLOG_IDENTIFIER = "eeprom.py" diff --git a/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/plugins/eeprom.py b/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/plugins/eeprom.py index 96dcc5975328..51caf72ac6d0 100644 --- a/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/plugins/eeprom.py +++ b/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,7 +8,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/pegatron/x86_64-pegatron_porsche-r0/plugins/eeprom.py b/device/pegatron/x86_64-pegatron_porsche-r0/plugins/eeprom.py index 6964c6bade4f..68dbc88ce842 100755 --- a/device/pegatron/x86_64-pegatron_porsche-r0/plugins/eeprom.py +++ b/device/pegatron/x86_64-pegatron_porsche-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,7 +8,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/eeprom.py b/device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/eeprom.py index 989f7fe50794..2f0b219a73bb 100755 --- a/device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/eeprom.py +++ b/device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,7 +8,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/quanta/x86_64-quanta_ix7_rglbmc-r0/plugins/eeprom.py b/device/quanta/x86_64-quanta_ix7_rglbmc-r0/plugins/eeprom.py index 2a35f3a22a17..d65115b0b6e5 100644 --- a/device/quanta/x86_64-quanta_ix7_rglbmc-r0/plugins/eeprom.py +++ b/device/quanta/x86_64-quanta_ix7_rglbmc-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,7 +8,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/quanta/x86_64-quanta_ix8_rglbmc-r0/plugins/eeprom.py b/device/quanta/x86_64-quanta_ix8_rglbmc-r0/plugins/eeprom.py index 2a35f3a22a17..d65115b0b6e5 100644 --- a/device/quanta/x86_64-quanta_ix8_rglbmc-r0/plugins/eeprom.py +++ b/device/quanta/x86_64-quanta_ix8_rglbmc-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -11,7 +8,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/quanta/x86_64-quanta_ix8c_bwde-r0/plugins/eeprom.py b/device/quanta/x86_64-quanta_ix8c_bwde-r0/plugins/eeprom.py index 2a35f3a22a17..3ac2cc5167f2 100644 --- a/device/quanta/x86_64-quanta_ix8c_bwde-r0/plugins/eeprom.py +++ b/device/quanta/x86_64-quanta_ix8c_bwde-r0/plugins/eeprom.py @@ -1,7 +1,6 @@ #!/usr/bin/env python try: - import exceptions import binascii import time import optparse @@ -11,7 +10,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/quanta/x86_64-quanta_ix9_bwde-r0/plugins/eeprom.py b/device/quanta/x86_64-quanta_ix9_bwde-r0/plugins/eeprom.py index 2a35f3a22a17..3ac2cc5167f2 100644 --- a/device/quanta/x86_64-quanta_ix9_bwde-r0/plugins/eeprom.py +++ b/device/quanta/x86_64-quanta_ix9_bwde-r0/plugins/eeprom.py @@ -1,7 +1,6 @@ #!/usr/bin/env python try: - import exceptions import binascii import time import optparse @@ -11,7 +10,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo import subprocess -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/wnc/x86_64-wnc_osw1800-r0/plugins/eeprom.py b/device/wnc/x86_64-wnc_osw1800-r0/plugins/eeprom.py index a073374794fa..7cb133ba5123 100644 --- a/device/wnc/x86_64-wnc_osw1800-r0/plugins/eeprom.py +++ b/device/wnc/x86_64-wnc_osw1800-r0/plugins/eeprom.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python - try: - import exceptions import binascii import time import optparse @@ -10,7 +7,7 @@ import sys from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") diff --git a/platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/eeprom.py b/platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/eeprom.py index a1ebe5f224a9..e25d224c1e8b 100644 --- a/platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/eeprom.py +++ b/platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/eeprom.py @@ -1,6 +1,3 @@ -#!/usr/bin/python - - try: import os import sys @@ -12,12 +9,16 @@ sys.path.append(os.path.dirname(__file__)) - from cStringIO import StringIO + if sys.version_info.major == 3: + from io import StringIO + else: + from cStringIO import StringIO + from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo from .platform_thrift_client import thrift_try -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") diff --git a/platform/broadcom/sonic-platform-modules-cel/services/platform_api/sonic_platform/eeprom.py b/platform/broadcom/sonic-platform-modules-cel/services/platform_api/sonic_platform/eeprom.py index 53306c003474..7756c0f2f839 100644 --- a/platform/broadcom/sonic-platform-modules-cel/services/platform_api/sonic_platform/eeprom.py +++ b/platform/broadcom/sonic-platform-modules-cel/services/platform_api/sonic_platform/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # @@ -13,9 +11,14 @@ import os import sys import re - from cStringIO import StringIO + + if sys.version_info.major == 3: + from io import StringIO + else: + from cStringIO import StringIO + from sonic_platform_base.sonic_eeprom import eeprom_tlvinfo -except ImportError, e: +except ImportError as e: raise ImportError(str(e) + "- required module not found") CACHE_ROOT = '/var/cache/sonic/decode-syseeprom' diff --git a/platform/broadcom/sonic-platform-modules-inventec/d6332/sonic_platform/eeprom.py b/platform/broadcom/sonic-platform-modules-inventec/d6332/sonic_platform/eeprom.py index 3995bc70fd5b..0d210b47beb2 100644 --- a/platform/broadcom/sonic-platform-modules-inventec/d6332/sonic_platform/eeprom.py +++ b/platform/broadcom/sonic-platform-modules-inventec/d6332/sonic_platform/eeprom.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # # Name: eeprom.py, version: 1.0 # @@ -7,7 +6,7 @@ try: from sonic_eeprom import eeprom_tlvinfo -except ( ImportError, e ): +except ImportError as e: raise ImportError(str(e) + "- required module not found") EEPROM_TOTAL_LEN_HIGH_OFFSET = 9 diff --git a/platform/broadcom/sonic-platform-modules-inventec/d6356/sonic_platform/eeprom.py b/platform/broadcom/sonic-platform-modules-inventec/d6356/sonic_platform/eeprom.py index 5840246fddc2..ef0d6385534e 100644 --- a/platform/broadcom/sonic-platform-modules-inventec/d6356/sonic_platform/eeprom.py +++ b/platform/broadcom/sonic-platform-modules-inventec/d6356/sonic_platform/eeprom.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # # Name: eeprom.py, version: 1.0 # @@ -8,7 +7,7 @@ try: from sonic_eeprom import eeprom_tlvinfo import binascii -except ImportError, e: +except ImportError as e: raise ImportError(str(e) + "- required module not found") class Eeprom(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/platform/broadcom/sonic-platform-modules-inventec/d7054q28b/sonic_platform/eeprom.py b/platform/broadcom/sonic-platform-modules-inventec/d7054q28b/sonic_platform/eeprom.py index b0ebee54ee24..70a4b0ecb437 100644 --- a/platform/broadcom/sonic-platform-modules-inventec/d7054q28b/sonic_platform/eeprom.py +++ b/platform/broadcom/sonic-platform-modules-inventec/d7054q28b/sonic_platform/eeprom.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # # Name: eeprom.py, version: 1.0 # @@ -8,7 +7,7 @@ try: from sonic_eeprom import eeprom_tlvinfo import binascii -except ImportError, e: +except ImportError as e: raise ImportError(str(e) + "- required module not found") class Eeprom(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/eeprom.py b/platform/mellanox/mlnx-platform-api/sonic_platform/eeprom.py index 6557a6c4ba63..53b8e7173686 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/eeprom.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Mellanox # @@ -7,11 +5,14 @@ # provides the eeprom information which are available in the platform # ############################################################################# -import exceptions import os import sys import re -from cStringIO import StringIO + +if sys.version_info.major == 3: + from io import StringIO +else: + from cStringIO import StringIO try: from sonic_platform_base.sonic_eeprom import eeprom_tlvinfo 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 95ca7b574622..222cdcf4edd3 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 @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # PDDF # @@ -9,7 +7,7 @@ try: from sonic_eeprom import eeprom_tlvinfo import binascii -except ImportError, e: +except ImportError as e: raise ImportError(str(e) + "- required module not found") diff --git a/platform/pddf/platform-api-pddf-base/sonic_platform_ref/eeprom.py b/platform/pddf/platform-api-pddf-base/sonic_platform_ref/eeprom.py index 4857895c2a01..c25d711354f5 100644 --- a/platform/pddf/platform-api-pddf-base/sonic_platform_ref/eeprom.py +++ b/platform/pddf/platform-api-pddf-base/sonic_platform_ref/eeprom.py @@ -1,8 +1,6 @@ -#!/usr/bin/env python - try: from sonic_platform_pddf_base.pddf_eeprom import PddfEeprom -except ImportError, e: +except ImportError as e: raise ImportError(str(e) + "- required module not found") From 11887ec648e03a3d522d7c32d8907a119af71c47 Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Sun, 22 Nov 2020 02:43:22 +0000 Subject: [PATCH 17/24] Update utils further --- src/sonic-utilities | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-utilities b/src/sonic-utilities index b44536466d13..f9eb739fa238 160000 --- a/src/sonic-utilities +++ b/src/sonic-utilities @@ -1 +1 @@ -Subproject commit b44536466d132ad44d11da4bc014752a71aa32ec +Subproject commit f9eb739fa238284c10ecb7c00b07094ac90b27db From 59ffeda2319f26b1ebf83ad150d8eb1a6d2dc379 Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Mon, 23 Nov 2020 22:25:54 +0000 Subject: [PATCH 18/24] Make all other platform plugins compliant with both Python 2 and 3 --- .../plugins/sfputil.py | 10 +- .../plugins/sfputil.py | 48 +++++----- .../plugins/sfputil.py | 58 ++++++------ .../plugins/sfputil.py | 60 ++++++------ .../plugins/sfputil.py | 50 +++++----- .../plugins/sfputil.py | 76 +++++++-------- .../plugins/sfputil.py | 46 +++++----- .../plugins/sfputil.py | 32 +++---- .../sonic_platform/sfp.py | 2 +- .../plugins/sfputil.py | 20 ++-- .../plugins/sfputil.py | 44 ++++----- .../plugins/sfputil.py | 42 ++++----- .../plugins/sfputil.py | 40 ++++---- .../plugins/sfputil.py | 18 ++-- .../plugins/sfputil.py | 22 ++--- .../plugins/sfputil.py | 34 +++---- .../plugins/sfputil.py | 36 ++++---- .../plugins/sfputil.py | 50 +++++----- .../plugins/sfputil.py | 40 ++++---- .../plugins/sfputil.py | 34 +++---- .../plugins/sfputil.py | 86 ++++++++--------- .../plugins/led_control.py | 14 +-- .../plugins/sfputil.py | 52 +++++------ .../plugins/led_control.py | 2 +- .../plugins/sfputil.py | 20 ++-- .../plugins/led_control.py | 2 +- .../plugins/sfputil.py | 20 ++-- .../plugins/eeprom.py | 10 +- .../plugins/pltfm_mgr_rpc/pltfm_mgr_rpc.py | 60 ++++++------ .../plugins/pltfm_mgr_rpc/ttypes.py | 12 +-- .../plugins/sfputil.py | 12 +-- .../x86_64-cel_e1031-r0/plugins/sfputil.py | 10 +- .../x86_64-cel_e1031-r0/sonic_platform/psu.py | 6 +- .../x86_64-cel_e1031-r0/sonic_platform/sfp.py | 2 +- .../x86_64-cel_midstone-r0/plugins/sfputil.py | 12 +-- .../x86_64-cel_seastone-r0/plugins/sfputil.py | 12 +-- .../sonic_platform/__init__.py | 4 +- .../sonic_platform/chassis.py | 2 +- .../sonic_platform/component.py | 2 +- .../sonic_platform/fan.py | 2 +- .../sonic_platform/psu.py | 8 +- .../sonic_platform/sfp.py | 2 +- .../sonic_platform/thermal.py | 2 +- .../sonic_platform/watchdog.py | 2 +- .../plugins/sfputil.py | 14 +-- .../plugins/sfputil.py | 14 +-- .../sonic_platform/chassis.py | 2 +- .../sonic_platform/component.py | 2 +- .../sonic_platform/fan.py | 2 +- .../sonic_platform/psu.py | 2 +- .../sonic_platform/thermal.py | 18 ++-- .../plugins/led_control.py | 2 +- .../plugins/sfputil.py | 4 +- .../plugins/led_control.py | 2 +- .../plugins/sfputil.py | 2 +- .../plugins/led_control.py | 2 +- .../plugins/sfputil.py | 6 +- .../plugins/led_control.py | 2 +- .../plugins/sfputil.py | 6 +- .../plugins/sfputil.py | 22 ++--- .../plugins/sfputil.py | 16 ++-- .../plugins/sfputil.py | 16 ++-- .../plugins/sfputil.py | 58 ++++++------ device/common/pddf/plugins/fanutil.py | 20 ++-- device/common/pddf/plugins/ledutil.py | 12 +-- device/common/pddf/plugins/psuutil.py | 26 +++--- device/common/pddf/plugins/sfputil.py | 12 +-- device/common/pddf/plugins/sysstatutil.py | 14 +-- device/common/pddf/plugins/thermalutil.py | 14 +-- .../plugins/sfputil.py | 22 ++--- .../plugins/psuutil.py | 2 +- .../plugins/sfputil.py | 14 +-- .../plugins/psuutil.py | 2 +- .../plugins/sfputil.py | 14 +-- .../plugins/psuutil.py | 6 +- .../plugins/sfputil.py | 38 ++++---- .../plugins/psuutil.py | 6 +- .../plugins/sfputil.py | 42 ++++----- .../plugins/psuutil.py | 6 +- .../plugins/sfputil.py | 36 ++++---- .../plugins/psuutil.py | 6 +- .../plugins/sfputil.py | 16 ++-- .../plugins/psuutil.py | 6 +- .../plugins/sfputil.py | 8 +- .../x86_64-delta_ag5648-r0/plugins/sfputil.py | 14 +-- .../plugins/sfputil.py | 12 +-- .../plugins/sfputil.py | 12 +-- .../x86_64-delta_ag9064-r0/plugins/sfputil.py | 12 +-- .../x86_64-delta_agc032-r0/plugins/sfputil.py | 22 ++--- .../plugins/psuutil.py | 4 +- .../plugins/sfputil.py | 6 +- .../plugins/sfputil.py | 24 ++--- .../plugins/sfputil.py | 32 +++---- .../plugins/sfputil.py | 40 ++++---- .../plugins/sfputil.py | 12 +-- .../plugins/sfputil.py | 14 +-- .../plugins/sfputil.py | 18 ++-- .../plugins/psuutil.py | 6 +- .../plugins/sfputil.py | 20 ++-- .../plugins/sfputil.py | 18 ++-- .../plugins/sfputil.py | 14 +-- .../plugins/sfputil.py | 16 ++-- .../plugins/sfputil.py | 16 ++-- .../plugins/sfputil.py | 14 +-- .../plugins/sfputil.py | 16 ++-- .../plugins/sfputil.py | 16 ++-- .../plugins/sfputil.py | 12 +-- .../plugins/sfputil.py | 16 ++-- .../plugins/sfputil.py | 16 ++-- .../plugins/led_control.py | 20 ++-- .../plugins/qfx5200_eeprom_data.py | 48 +++++----- .../plugins/qfx5200_sfp_init.py | 28 +++--- .../plugins/sfputil.py | 92 +++++++++---------- .../plugins/qfx5210_eeprom_data.py | 45 +++++---- .../plugins/sfputil.py | 66 ++++++------- .../plugins/sfputil.py | 35 ++++--- .../plugins/sfputil.py | 35 ++++--- .../plugins/psuutil.py | 16 ++-- .../plugins/sfputil.py | 20 ++-- .../plugins/sfputil.py | 35 ++++--- .../plugins/sfputil.py | 35 ++++--- .../plugins/sfputil.py | 20 ++-- .../plugins/sfplpmget.py | 2 +- .../plugins/sfplpmset.py | 2 +- .../x86_64-mlnx_msn2700-r0/plugins/sfputil.py | 28 +++--- .../plugins/sfputil.py | 14 +-- .../plugins/sfputil.py | 2 +- .../plugins/sfputil.py | 20 ++-- .../plugins/sfputil.py | 26 +++--- .../plugins/sfputil.py | 12 +-- .../plugins/sfputil.py | 12 +-- .../plugins/sfputil.py | 12 +-- .../plugins/sfputil.py | 26 +++--- .../x86_64-wnc_osw1800-r0/plugins/sfputil.py | 14 +-- 134 files changed, 1362 insertions(+), 1337 deletions(-) diff --git a/device/accton/x86_64-accton_as4630_54pe-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as4630_54pe-r0/plugins/sfputil.py index 33a2630f1d71..bd16ac366f14 100755 --- a/device/accton/x86_64-accton_as4630_54pe-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as4630_54pe-r0/plugins/sfputil.py @@ -49,7 +49,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(self.PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -76,7 +76,7 @@ def get_presence(self, port_num): content = val_file.readline().rstrip() val_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False if content == "1": @@ -108,7 +108,7 @@ def get_low_power_mode(self, port_num): return 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: @@ -138,7 +138,7 @@ def set_low_power_mode(self, port_num, lpmode): eeprom.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 is not None: @@ -163,7 +163,7 @@ def get_transceiver_change_event(self, timeout=0): port_dict = {} if timeout == 0: - cd_ms = sys.maxint + cd_ms = sys.maxsize else: cd_ms = timeout diff --git a/device/accton/x86_64-accton_as5712_54x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as5712_54x-r0/plugins/sfputil.py index b1727f0a79b6..9ed06a3cb618 100755 --- a/device/accton/x86_64-accton_as5712_54x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as5712_54x-r0/plugins/sfputil.py @@ -32,7 +32,7 @@ class SfpUtil(SfpUtilBase): BASE_CPLD3_PATH = "/sys/bus/i2c/devices/{0}-0062/" I2C_BUS_ORDER = -1 - #The sidebands of QSFP is different. + #The sidebands of QSFP is different. qsfp_sb_map = [0, 2, 4, 1, 3, 5] _port_to_is_present = {} @@ -111,10 +111,10 @@ def qsfp_port_start(self): @property def qsfp_port_end(self): return self.QSFP_PORT_END - + @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -129,7 +129,7 @@ def update_i2c_order(self): eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom" if os.path.exists(eeprom_path): self.I2C_BUS_ORDER = 1 - return self.I2C_BUS_ORDER + return self.I2C_BUS_ORDER def get_presence(self, port_num): # Check for invalid port_num @@ -150,9 +150,9 @@ def get_presence(self, port_num): content = val_file.readline().rstrip() val_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False - + if content == "1": return True @@ -167,22 +167,22 @@ def qsfp_sb_remap(self, port_num): def get_low_power_mode_cpld(self, port_num): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False - + order = self.update_i2c_order() lp_mode_path = self.BASE_CPLD3_PATH.format(order) - lp_mode_path = lp_mode_path + "module_lp_mode_" + lp_mode_path = lp_mode_path + "module_lp_mode_" q = self.qsfp_sb_remap(port_num) lp_mode_path = lp_mode_path + str(q) - + content="0" try: val_file = open(lp_mode_path) content = val_file.readline().rstrip() val_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False - + if content == "1": return True @@ -191,7 +191,7 @@ def get_low_power_mode_cpld(self, port_num): def get_low_power_mode(self, port_num): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False - + if not self.get_presence(port_num): return self.get_low_power_mode_cpld(port_num) @@ -210,7 +210,7 @@ def get_low_power_mode(self, port_num): else: return False # High Power Mode if "Power set" bit is 0 except IOError as err: - print "Error: unable to open file: %s" % str(err) + print("Error: unable to open file: %s" % str(err)) return False finally: if eeprom is not None: @@ -238,7 +238,7 @@ def set_low_power_mode(self, port_num, lpmode): eeprom.write(buffer[0]) return True except IOError as err: - print "Error: unable to open file: %s" % str(err) + print("Error: unable to open file: %s" % str(err)) return False finally: if eeprom is not None: @@ -248,16 +248,16 @@ def set_low_power_mode(self, port_num, lpmode): def reset(self, port_num): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False - + order = self.update_i2c_order() lp_mode_path = self.BASE_CPLD3_PATH.format(order) - mod_rst_path = lp_mode_path + "module_reset_" + mod_rst_path = lp_mode_path + "module_reset_" q = self.qsfp_sb_remap(port_num) mod_rst_path = mod_rst_path + str(q) try: reg_file = open(mod_rst_path, 'r+', buffering=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 #toggle reset @@ -273,19 +273,19 @@ def reset(self, port_num): def _get_presence_bitmap(self): nodes = [] order = self.update_i2c_order() - + present_path = self.BASE_CPLD2_PATH.format(order) nodes.append(present_path + "module_present_all") present_path = self.BASE_CPLD3_PATH.format(order) nodes.append(present_path + "module_present_all") bitmap = "" - for node in nodes: + for node in nodes: try: reg_file = open(node) - + except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False bitmap += reg_file.readline().rstrip() + " " reg_file.close() @@ -293,9 +293,9 @@ def _get_presence_bitmap(self): rev = bitmap.split(" ") rev = "".join(rev[::-1]) return int(rev,16) - - data = {'valid':0, 'last':0, 'present':0} + + data = {'valid':0, 'last':0, 'present':0} def get_transceiver_change_event(self, timeout=2000): now = time.time() port_dict = {} @@ -323,7 +323,7 @@ def get_transceiver_change_event(self, timeout=2000): else: port_dict[port] = SFP_STATUS_INSERTED - # Update cache + # Update cache self.data['present'] = reg_value self.data['last'] = now self.data['valid'] = 1 diff --git a/device/accton/x86_64-accton_as5812_54t-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as5812_54t-r0/plugins/sfputil.py index 44399d1e64ee..f932f6a6d49f 100755 --- a/device/accton/x86_64-accton_as5812_54t-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as5812_54t-r0/plugins/sfputil.py @@ -29,9 +29,9 @@ class SfpUtil(SfpUtilBase): BASE_CPLD_PATH = "/sys/bus/i2c/devices/{0}-0060/" I2C_BUS_ORDER = -1 - #The sidebands of QSFP is different. - #present is in-order. - #But lp_mode and reset are not. + #The sidebands of QSFP is different. + #present is in-order. + #But lp_mode and reset are not. qsfp_sb_map = [0, 2, 4, 1, 3, 5] _port_to_is_present = {} @@ -62,10 +62,10 @@ def qsfp_port_start(self): @property def qsfp_port_end(self): return self.QSFP_PORT_END - + @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -89,7 +89,7 @@ def update_i2c_order(self): eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom" if os.path.exists(eeprom_path): self.I2C_BUS_ORDER = 1 - return self.I2C_BUS_ORDER + return self.I2C_BUS_ORDER def get_presence(self, port_num): # Check for invalid port_num @@ -98,7 +98,7 @@ def get_presence(self, port_num): order = self.update_i2c_order() present_path = self.BASE_CPLD_PATH.format(order) - present_path = present_path + "module_present_" + str(port_num) + present_path = present_path + "module_present_" + str(port_num) self.__port_to_is_present = present_path content="0" @@ -107,9 +107,9 @@ def get_presence(self, port_num): content = val_file.readline().rstrip() val_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False - + if content == "1": return True @@ -118,21 +118,21 @@ def get_presence(self, port_num): def get_low_power_mode_cpld(self, port_num): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False - + order = self.update_i2c_order() lp_mode_path = self.BASE_CPLD_PATH.format(order) - lp_mode_path = lp_mode_path + "module_lp_mode_" + lp_mode_path = lp_mode_path + "module_lp_mode_" lp_mode_path = lp_mode_path + str(port_num) - + content="0" try: val_file = open(lp_mode_path) content = val_file.readline().rstrip() val_file.close() except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False - + if content == "1": return True @@ -141,7 +141,7 @@ def get_low_power_mode_cpld(self, port_num): def get_low_power_mode(self, port_num): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False - + if not self.get_presence(port_num): return self.get_low_power_mode_cpld(port_num) @@ -159,7 +159,7 @@ def get_low_power_mode(self, port_num): else: return False # High Power Mode if "Power set" bit is 0 except IOError as err: - print "Error: unable to open file: %s" % str(err) + print("Error: unable to open file: %s" % str(err)) return False finally: if eeprom is not None: @@ -187,7 +187,7 @@ def set_low_power_mode(self, port_num, lpmode): eeprom.write(buffer[0]) return True except IOError as err: - print "Error: unable to open file: %s" % str(err) + print("Error: unable to open file: %s" % str(err)) return False finally: if eeprom is not None: @@ -197,17 +197,17 @@ def set_low_power_mode(self, port_num, lpmode): def reset(self, port_num): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False - + order = self.update_i2c_order() lp_mode_path = self.BASE_CPLD_PATH.format(order) - mod_rst_path = lp_mode_path + "module_reset_" + mod_rst_path = lp_mode_path + "module_reset_" mod_rst_path = mod_rst_path + str(port_num) print(mod_rst_path) - + try: reg_file = open(mod_rst_path, 'r+', buffering=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 #toggle reset @@ -223,17 +223,17 @@ def reset(self, port_num): def _get_presence_bitmap(self): nodes = [] order = self.update_i2c_order() - + present_path = self.BASE_CPLD_PATH.format(order) nodes.append(present_path + "module_present_all") bitmap = "" - for node in nodes: + for node in nodes: try: reg_file = open(node) - + except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False bitmap += reg_file.readline().rstrip() + " " reg_file.close() @@ -241,15 +241,15 @@ def _get_presence_bitmap(self): rev = bitmap.split(" ") rev = "".join(rev[::-1]) return int(rev,16) - - data = {'present':0} + + data = {'present':0} def get_transceiver_change_event(self, timeout=2000): port_dict = {} port = 0 if timeout == 0: - cd_ms = sys.maxint + cd_ms = sys.maxsize else: cd_ms = timeout @@ -274,7 +274,7 @@ def get_transceiver_change_event(self, timeout=2000): else: port_dict[port] = SFP_STATUS_INSERTED - # Update cache + # Update cache self.data['present'] = reg_value return True, port_dict diff --git a/device/accton/x86_64-accton_as5812_54x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as5812_54x-r0/plugins/sfputil.py index 008b2fdd9cf5..e4a6d13a84b8 100755 --- a/device/accton/x86_64-accton_as5812_54x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as5812_54x-r0/plugins/sfputil.py @@ -30,9 +30,9 @@ class SfpUtil(SfpUtilBase): BASE_CPLD3_PATH = "/sys/bus/i2c/devices/{0}-0062/" I2C_BUS_ORDER = -1 - #The sidebands of QSFP is different. - #present is in-order. - #But lp_mode and reset are not. + #The sidebands of QSFP is different. + #present is in-order. + #But lp_mode and reset are not. qsfp_sb_map = [0, 2, 4, 1, 3, 5] _port_to_is_present = {} @@ -111,10 +111,10 @@ def qsfp_port_start(self): @property def qsfp_port_end(self): return self.QSFP_PORT_END - + @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -138,7 +138,7 @@ def update_i2c_order(self): eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom" if os.path.exists(eeprom_path): self.I2C_BUS_ORDER = 1 - return self.I2C_BUS_ORDER + return self.I2C_BUS_ORDER def get_presence(self, port_num): # Check for invalid port_num @@ -147,11 +147,11 @@ def get_presence(self, port_num): order = self.update_i2c_order() if port_num <= 24: - present_path = self.BASE_CPLD2_PATH.format(order) + present_path = self.BASE_CPLD2_PATH.format(order) else: present_path = self.BASE_CPLD3_PATH.format(order) - - present_path = present_path + "module_present_" + str(port_num) + + present_path = present_path + "module_present_" + str(port_num) self.__port_to_is_present = present_path content="0" @@ -160,9 +160,9 @@ def get_presence(self, port_num): content = val_file.readline().rstrip() val_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False - + if content == "1": return True @@ -177,22 +177,22 @@ def qsfp_sb_remap(self, port_num): def get_low_power_mode_cpld(self, port_num): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False - + order = self.update_i2c_order() lp_mode_path = self.BASE_CPLD3_PATH.format(order) - lp_mode_path = lp_mode_path + "module_lp_mode_" + lp_mode_path = lp_mode_path + "module_lp_mode_" q = self.qsfp_sb_remap(port_num) lp_mode_path = lp_mode_path + str(q) - + content = "0" try: val_file = open(lp_mode_path) content = val_file.readline().rstrip() val_file.close() except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False - + if content == "1": return True @@ -201,7 +201,7 @@ def get_low_power_mode_cpld(self, port_num): def get_low_power_mode(self, port_num): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False - + if not self.get_presence(port_num): return self.get_low_power_mode_cpld(port_num) @@ -220,7 +220,7 @@ def get_low_power_mode(self, port_num): else: return False # High Power Mode if "Power set" bit is 0 except IOError as err: - print "Error: unable to open file: %s" % str(err) + print("Error: unable to open file: %s" % str(err)) return False finally: if eeprom is not None: @@ -248,7 +248,7 @@ def set_low_power_mode(self, port_num, lpmode): eeprom.write(buffer[0]) return True except IOError as err: - print "Error: unable to open file: %s" % str(err) + print("Error: unable to open file: %s" % str(err)) return False finally: if eeprom is not None: @@ -258,17 +258,17 @@ def set_low_power_mode(self, port_num, lpmode): def reset(self, port_num): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False - + order = self.update_i2c_order() lp_mode_path = self.BASE_CPLD3_PATH.format(order) - mod_rst_path = lp_mode_path + "module_reset_" + mod_rst_path = lp_mode_path + "module_reset_" q = self.qsfp_sb_remap(port_num) mod_rst_path = mod_rst_path + str(q) - + try: reg_file = open(mod_rst_path, 'r+', buffering=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 #toggle reset @@ -284,19 +284,19 @@ def reset(self, port_num): def _get_presence_bitmap(self): nodes = [] order = self.update_i2c_order() - + present_path = self.BASE_CPLD2_PATH.format(order) nodes.append(present_path + "module_present_all") present_path = self.BASE_CPLD3_PATH.format(order) nodes.append(present_path + "module_present_all") bitmap = "" - for node in nodes: + for node in nodes: try: reg_file = open(node) - + except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False bitmap += reg_file.readline().rstrip() + " " reg_file.close() @@ -304,9 +304,9 @@ def _get_presence_bitmap(self): rev = bitmap.split(" ") rev = "".join(rev[::-1]) return int(rev,16) - - data = {'valid':0, 'last':0, 'present':0} + + data = {'valid':0, 'last':0, 'present':0} def get_transceiver_change_event(self, timeout=2000): now = time.time() port_dict = {} @@ -334,7 +334,7 @@ def get_transceiver_change_event(self, timeout=2000): else: port_dict[port] = SFP_STATUS_INSERTED - # Update cache + # Update cache self.data['present'] = reg_value self.data['last'] = now self.data['valid'] = 1 diff --git a/device/accton/x86_64-accton_as5835_54t-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as5835_54t-r0/plugins/sfputil.py index 34e8f724ae42..696442f9bd66 100644 --- a/device/accton/x86_64-accton_as5835_54t-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as5835_54t-r0/plugins/sfputil.py @@ -64,10 +64,10 @@ def qsfp_port_start(self): @property def qsfp_port_end(self): return self.PORT_END - + @property def qsfp_ports(self): - return range(self.PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -83,7 +83,7 @@ def __init__(self): # For port 49~54 are QSFP, here presumed they're all split to 4 lanes. - def get_cage_num(self, port_num): + def get_cage_num(self, port_num): cage_num = port_num if (port_num >= self.PORT_START): cage_num = (port_num - self.PORT_START)/4 @@ -95,7 +95,7 @@ def get_presence(self, port_num): # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False - + cage_num = self.get_cage_num(port_num) path = "/sys/bus/i2c/devices/3-0062/module_present_{0}" port_ps = path.format(cage_num) @@ -106,40 +106,40 @@ def get_presence(self, port_num): content = val_file.readline().rstrip() val_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False - + if content == "1": return True return False - def get_low_power_mode_cpld(self, port_num): + def get_low_power_mode_cpld(self, port_num): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False cage_num = self.get_cage_num(port_num) path = "/sys/bus/i2c/devices/3-0062/module_lpmode_{0}" lp_mode_path = path.format(cage_num) - + try: val_file = open(lp_mode_path) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = val_file.readline().rstrip() val_file.close() - + if content == "1": return True return False - def get_low_power_mode(self, port_num): + def get_low_power_mode(self, port_num): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False - + if not self.get_presence(port_num): return False @@ -158,7 +158,7 @@ def get_low_power_mode(self, port_num): else: return False # High Power Mode if "Power set" bit is 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 is not None: @@ -167,7 +167,7 @@ def get_low_power_mode(self, port_num): def set_low_power_mode(self, port_num, lpmode): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: - return False + return False try: eeprom = None @@ -186,7 +186,7 @@ def set_low_power_mode(self, port_num, lpmode): eeprom.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 is not None: @@ -196,14 +196,14 @@ def set_low_power_mode(self, port_num, lpmode): def reset(self, port_num): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False - + cage_num = self.get_cage_num(port_num) path = "/sys/bus/i2c/devices/3-0062/module_reset_{0}" port_ps = path.format(cage_num) try: reg_file = open(port_ps, mode="w", buffering=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 #toggle reset @@ -213,7 +213,7 @@ def reset(self, port_num): reg_file.seek(0) reg_file.write('1') reg_file.close() - + return True @property @@ -223,7 +223,7 @@ def _get_presence_bitmap(self): try: reg_file = open("/sys/bus/i2c/devices/3-0062/module_present_all") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False bitmap += reg_file.readline().rstrip() + " " reg_file.close() @@ -247,7 +247,7 @@ def _get_presence_bitmap(self): rev = "".join(rev[::-1]) return int(rev,16) - data = {'valid':0, 'present':0} + data = {'valid':0, 'present':0} def get_transceiver_change_event(self, timeout=0): start_time = time.time() @@ -260,13 +260,13 @@ def get_transceiver_change_event(self, timeout=0): elif timeout > 0: timeout = timeout / float(1000) # Convert to secs else: - print "get_transceiver_change_event:Invalid timeout value", timeout + print("get_transceiver_change_event:Invalid timeout value", timeout) return False, {} end_time = start_time + timeout if start_time > end_time: - print 'get_transceiver_change_event:' \ - 'time wrap / invalid timeout value', timeout + print('get_transceiver_change_event:' \ + 'time wrap / invalid timeout value', timeout) return False, {} # Time wrap or possibly incorrect timeout @@ -286,7 +286,7 @@ def get_transceiver_change_event(self, timeout=0): else: port_dict[port] = SFP_STATUS_INSERTED - # Update cache + # Update cache self.data['present'] = reg_value self.data['valid'] = 1 return True, port_dict @@ -301,5 +301,5 @@ def get_transceiver_change_event(self, timeout=0): if timeout > 0: time.sleep(timeout) return True, {} - print "get_transceiver_change_event: Should not reach here." + print("get_transceiver_change_event: Should not reach here.") return False, {} diff --git a/device/accton/x86_64-accton_as5835_54x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as5835_54x-r0/plugins/sfputil.py index 7782f708fccd..6fe4c2b21a11 100644 --- a/device/accton/x86_64-accton_as5835_54x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as5835_54x-r0/plugins/sfputil.py @@ -35,14 +35,14 @@ class SfpUtil(SfpUtilBase): 2: "3-0062", } _port_to_i2c_mapping = { - 1: 42, - 2: 43, - 3: 44, - 4: 45, - 5: 46, - 6: 47, - 7: 48, - 8: 49, + 1: 42, + 2: 43, + 3: 44, + 4: 45, + 5: 46, + 6: 47, + 7: 48, + 8: 49, 9: 50, 10: 51, 11: 52, @@ -124,10 +124,10 @@ def qsfp_port_start(self): @property def qsfp_port_end(self): return self.QSFP_PORT_END - + @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -143,7 +143,7 @@ def __init__(self): # For port 49~54 are QSFP, here presumed they're all split to 4 lanes. - def get_cage_num(self, port_num): + def get_cage_num(self, port_num): cage_num = port_num if (port_num >= self.QSFP_PORT_START): cage_num = (port_num - self.QSFP_PORT_START)/4 @@ -152,14 +152,14 @@ def get_cage_num(self, port_num): return cage_num # For cage 1~38 are at cpld2, others are at cpld3. - def get_cpld_num(self, port_num): + def get_cpld_num(self, port_num): return 1 if (port_num < 39) else 2 def get_presence(self, port_num): # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False - + cage_num = self.get_cage_num(port_num) cpld_i = self.get_cpld_num(port_num) @@ -173,15 +173,15 @@ def get_presence(self, port_num): content = val_file.readline().rstrip() val_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False - + if content == "1": return True return False - def get_low_power_mode_cpld(self, port_num): + def get_low_power_mode_cpld(self, port_num): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False @@ -191,25 +191,25 @@ def get_low_power_mode_cpld(self, port_num): cpld_ps = self._cpld_mapping[cpld_i] path = "/sys/bus/i2c/devices/{0}/module_lpmode_{1}" lp_mode_path = path.format(cpld_ps, cage_num) - + try: val_file = open(lp_mode_path) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = val_file.readline().rstrip() val_file.close() - + if content == "1": return True return False - def get_low_power_mode(self, port_num): + def get_low_power_mode(self, port_num): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False - + if not self.get_presence(port_num): return False @@ -228,7 +228,7 @@ def get_low_power_mode(self, port_num): else: return False # High Power Mode if "Power set" bit is 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 is not None: @@ -237,7 +237,7 @@ def get_low_power_mode(self, port_num): def set_low_power_mode(self, port_num, lpmode): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: - return False + return False try: eeprom = None @@ -256,7 +256,7 @@ def set_low_power_mode(self, port_num, lpmode): eeprom.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 is not None: @@ -266,7 +266,7 @@ def set_low_power_mode(self, port_num, lpmode): def reset(self, port_num): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False - + cage_num = self.get_cage_num(port_num) cpld_i = self.get_cpld_num(port_num) cpld_ps = self._cpld_mapping[cpld_i] @@ -275,7 +275,7 @@ def reset(self, port_num): try: reg_file = open(port_ps, mode='w', buffering=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 #toggle reset @@ -285,7 +285,7 @@ def reset(self, port_num): reg_file.seek(0) reg_file.write('1') reg_file.close() - + return True @property @@ -295,19 +295,19 @@ def _get_presence_bitmap(self): nodes.append("/sys/bus/i2c/devices/3-0062/module_present_all") bitmap = "" - for node in nodes: + for node in nodes: try: reg_file = open(node) - + except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False bitmap += reg_file.readline().rstrip() + " " reg_file.close() rev = bitmap.split(" ") rev.pop() # Remove the last useless character - + # Convert bitmap into continuously port order rev[4] = hex((int(rev[4],16) | ((int(rev[5],16) & 0x3) << 6)))[2:] # Port 33-40 rev[5] = hex((int(rev[5],16) >> 2) | ((int(rev[6],16) & 0x3) << 6))[2:] # Port 41-48 @@ -317,14 +317,14 @@ def _get_presence_bitmap(self): for i in range (2, 8): val = (int(tmp,16) >> i) & 0x1 rev.append(hex(val)[2:]) - + for i in range (0,6): rev[i] = rev[i].zfill(2) rev = "".join(rev[::-1]) return int(rev,16) - data = {'valid':0, 'present':0} + data = {'valid':0, 'present':0} def get_transceiver_change_event(self, timeout=0): start_time = time.time() @@ -337,13 +337,13 @@ def get_transceiver_change_event(self, timeout=0): elif timeout > 0: timeout = timeout / float(1000) # Convert to secs else: - print "get_transceiver_change_event:Invalid timeout value", timeout + print("get_transceiver_change_event:Invalid timeout value", timeout) return False, {} end_time = start_time + timeout if start_time > end_time: - print 'get_transceiver_change_event:' \ - 'time wrap / invalid timeout value', timeout + print('get_transceiver_change_event:' \ + 'time wrap / invalid timeout value', timeout) return False, {} # Time wrap or possibly incorrect timeout @@ -363,7 +363,7 @@ def get_transceiver_change_event(self, timeout=0): else: port_dict[port] = SFP_STATUS_INSERTED - # Update cache + # Update cache self.data['present'] = reg_value self.data['valid'] = 1 return True, port_dict @@ -378,7 +378,7 @@ def get_transceiver_change_event(self, timeout=0): if timeout > 0: time.sleep(timeout) return True, {} - print "get_transceiver_change_event: Should not reach here." + print("get_transceiver_change_event: Should not reach here.") return False, {} diff --git a/device/accton/x86_64-accton_as6712_32x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as6712_32x-r0/plugins/sfputil.py index 6889280608fb..744fc13b1b74 100644 --- a/device/accton/x86_64-accton_as6712_32x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as6712_32x-r0/plugins/sfputil.py @@ -85,10 +85,10 @@ def qsfp_port_start(self): @property def qsfp_port_end(self): return self.QSFP_PORT_END - + @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -108,13 +108,13 @@ def get_cpld_dev_path(self, port_num): cpld_num = 0 else: cpld_num = 1 - + #cpld can be at either bus 0 or bus 1. cpld_path = self.I2C_DEV_PATH + str(0) + self.CPLD_ADDRESS[cpld_num] - if not os.path.exists(cpld_path): + if not os.path.exists(cpld_path): cpld_path = self.I2C_DEV_PATH + str(1) + self.CPLD_ADDRESS[cpld_num] return cpld_path - + def get_presence(self, port_num): # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: @@ -122,7 +122,7 @@ def get_presence(self, port_num): cpld_path = self.get_cpld_dev_path(port_num) - present_path = cpld_path + "/module_present_" + present_path = cpld_path + "/module_present_" present_path += str(self._port_to_i2c_mapping[port_num][0]) self.__port_to_is_present = present_path @@ -133,20 +133,20 @@ def get_presence(self, port_num): content = val_file.readline().rstrip() val_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False - + if content == "1": return True return False - def get_low_power_mode_cpld(self, port_num): + def get_low_power_mode_cpld(self, port_num): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False - + cpld_path = self.get_cpld_dev_path(port_num) - _path = cpld_path + "/module_lp_mode_" + _path = cpld_path + "/module_lp_mode_" _path += str(self._port_to_i2c_mapping[port_num][0]) content="0" @@ -155,18 +155,18 @@ def get_low_power_mode_cpld(self, port_num): content = reg_file.readline().rstrip() reg_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False - + if content == "1": return True return False - def get_low_power_mode(self, port_num): + def get_low_power_mode(self, port_num): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False - + if not self.get_presence(port_num): return False @@ -185,7 +185,7 @@ def get_low_power_mode(self, port_num): else: return False # High Power Mode if "Power set" bit is 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 is not None: @@ -194,7 +194,7 @@ def get_low_power_mode(self, port_num): def set_low_power_mode(self, port_num, lpmode): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: - return False + return False try: eeprom = None @@ -213,7 +213,7 @@ def set_low_power_mode(self, port_num, lpmode): eeprom.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 is not None: @@ -223,15 +223,15 @@ def set_low_power_mode(self, port_num, lpmode): def reset(self, port_num): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False - + cpld_path = self.get_cpld_dev_path(port_num) - _path = cpld_path + "/module_reset_" + _path = cpld_path + "/module_reset_" _path += str(self._port_to_i2c_mapping[port_num][0]) try: reg_file = open(_path, 'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_file.seek(0) @@ -240,7 +240,7 @@ def reset(self, port_num): reg_file.seek(0) reg_file.write('0') reg_file.close() - + return True @property @@ -258,7 +258,7 @@ def get_transceiver_status(self): reg_file = open(node) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False bitmap += reg_file.readline().rstrip() + " " reg_file.close() diff --git a/device/accton/x86_64-accton_as7116_54x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7116_54x-r0/plugins/sfputil.py index 3562043ad9fc..d2706275e7bb 100644 --- a/device/accton/x86_64-accton_as7116_54x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7116_54x-r0/plugins/sfputil.py @@ -2,8 +2,8 @@ try: import time - from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError, e: + from sonic_sfp.sfputilbase import SfpUtilBase +except ImportError as e: raise ImportError (str(e) + "- required module not found") SFP_STATUS_INSERTED = '1' @@ -75,7 +75,7 @@ class SfpUtil(SfpUtilBase): 53 : 26, } - _qsfp_ports = range(_qsfp_port_start, _ports_in_block + 1) + _qsfp_ports = list(range(_qsfp_port_start, _ports_in_block + 1)) _present_status = dict() @@ -83,24 +83,24 @@ def __init__(self): eeprom_path = '/sys/bus/i2c/devices/{0}-0050/sfp_eeprom' for x in range(self._port_start, self._port_end + 1): port_eeprom_path = eeprom_path.format(self._port_to_i2c_mapping[x]) - self._port_to_eeprom_mapping[x] = port_eeprom_path + self._port_to_eeprom_mapping[x] = port_eeprom_path self._present_status[x] = SFP_STATUS_REMOVED - + SfpUtilBase.__init__(self) - + def reset(self, port_num): # Check for invalid port_num if port_num < self._qsfp_port_start or port_num > self._port_end: - print "Error: port %d is not qsfp port" % port_num + print("Error: port %d is not qsfp port" % port_num) return False path = "/sys/bus/i2c/devices/{0}-0050/sfp_port_reset" port_ps = path.format(self._port_to_i2c_mapping[port_num]) - + try: reg_file = open(port_ps, 'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False #toggle reset @@ -132,14 +132,14 @@ def get_presence(self, port_num): reg_value = reg_file.readline().rstrip() reg_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False - + if reg_value == '1': return True return False - + def get_transceiver_change_event(self, timeout=0): raise NotImplementedError @@ -155,7 +155,7 @@ def port_end(self): def qsfp_ports(self): return self._qsfp_ports - @property + @property def port_to_eeprom_mapping(self): return self._port_to_eeprom_mapping @@ -166,8 +166,8 @@ def get_transceiver_change_event(self, timeout=0): if self._present_status[phy_port] != last_present_status: ret_present[phy_port] = last_present_status self._present_status[phy_port] = last_present_status - + time.sleep(2) - - return True, ret_present + + return True, ret_present diff --git a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/sfp.py b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/sfp.py index 63fdb0684405..264545bd82e3 100644 --- a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/sfp.py +++ b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/sfp.py @@ -168,7 +168,7 @@ class Sfp(SfpBase): 52: 25, 53: 26, } - _sfp_port = range(48, PORT_END + 1) + _sfp_port = list(range(48, PORT_END + 1)) RESET_PATH = "/sys/bus/i2c/devices/{}-0050/sfp_port_reset" PRS_PATH = "/sys/bus/i2c/devices/{}-0050/sfp_is_present" diff --git a/device/accton/x86_64-accton_as7212_54x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7212_54x-r0/plugins/sfputil.py index 92ba72507285..18cc406e5e12 100755 --- a/device/accton/x86_64-accton_as7212_54x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7212_54x-r0/plugins/sfputil.py @@ -3,7 +3,7 @@ try: import time from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") @@ -50,7 +50,7 @@ class sfputil(SfpUtilBase): 24 : 49, } - _qsfp_ports = range(0, ports_in_block + 1) + _qsfp_ports = list(range(0, ports_in_block + 1)) def __init__(self): # Override port_to_eeprom_mapping for class initialization @@ -67,11 +67,11 @@ def reset(self, port_num): path = "/sys/bus/i2c/devices/{0}-0050/sfp_port_reset" port_ps = path.format(self.port_to_i2c_mapping[port_num+1]) - + try: reg_file = open(port_ps, 'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False #toggle reset @@ -88,7 +88,7 @@ def set_low_power_mode(self, port_nuM, lpmode): def get_low_power_mode(self, port_num): raise NotImplementedErro - + def get_presence(self, port_num): # Check for invalid port_num if port_num < self._port_start or port_num > self._port_end: @@ -103,9 +103,9 @@ def get_presence(self, port_num): reg_value = reg_file.readline().rstrip() reg_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False - + if reg_value == '1': return True @@ -118,12 +118,12 @@ def port_start(self): @property def port_end(self): return self._port_end - + @property def qsfp_ports(self): - return range(0, self.ports_in_block + 1) + return list(range(0, self.ports_in_block + 1)) - @property + @property def port_to_eeprom_mapping(self): return self._port_to_eeprom_mapping diff --git a/device/accton/x86_64-accton_as7312_54x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7312_54x-r0/plugins/sfputil.py index 52b57e210ebb..69d3d25b061e 100644 --- a/device/accton/x86_64-accton_as7312_54x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7312_54x-r0/plugins/sfputil.py @@ -33,14 +33,14 @@ class SfpUtil(SfpUtilBase): 2: "6-0064", } _port_to_i2c_mapping = { - 1: 18, - 2: 19, - 3: 20, - 4: 21, - 5: 22, - 6: 23, - 7: 24, - 8: 25, + 1: 18, + 2: 19, + 3: 20, + 4: 21, + 5: 22, + 6: 23, + 7: 24, + 8: 25, 9: 26, 10: 27, 11: 28, @@ -104,10 +104,10 @@ def qsfp_port_start(self): @property def qsfp_port_end(self): return self.QSFP_PORT_END - + @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -121,12 +121,12 @@ def __init__(self): SfpUtilBase.__init__(self) - def get_cpld_num(self, port_num): + def get_cpld_num(self, port_num): cpld_i = 1 if (port_num > 24 and port_num < self.qsfp_port_start): cpld_i = 2 - if (port_num > 52): + if (port_num > 52): cpld_i = 2 return cpld_i @@ -135,7 +135,7 @@ def get_presence(self, port_num): # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False - + cpld_i = self.get_cpld_num(port_num) cpld_ps = self._cpld_mapping[cpld_i] @@ -148,9 +148,9 @@ def get_presence(self, port_num): content = val_file.readline().rstrip() val_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False - + if content == "1": return True @@ -176,16 +176,16 @@ def get_low_power_mode(self, port_num): else: return 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 + # 2. "Power override" bit is 1 and "Power set" bit is 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 is not None: eeprom.close() time.sleep(0.01) - def set_low_power_mode(self, port_num, lpmode): + def set_low_power_mode(self, port_num, lpmode): # Check for invalid port_num if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False @@ -207,7 +207,7 @@ def set_low_power_mode(self, port_num, lpmode): eeprom.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 is not None: @@ -217,7 +217,7 @@ def set_low_power_mode(self, port_num, lpmode): def reset(self, port_num): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False - + cpld_i = self.get_cpld_num(port_num) cpld_ps = self._cpld_mapping[cpld_i] path = "/sys/bus/i2c/devices/{0}/module_reset_{1}" @@ -225,14 +225,14 @@ def reset(self, port_num): try: reg_file = open(port_ps, 'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = '0' reg_file.write(reg_value) reg_file.close() - + return True def get_transceiver_change_event(self): diff --git a/device/accton/x86_64-accton_as7312_54xs-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7312_54xs-r0/plugins/sfputil.py index 90349ff53908..e5dac3001f5e 100644 --- a/device/accton/x86_64-accton_as7312_54xs-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7312_54xs-r0/plugins/sfputil.py @@ -33,14 +33,14 @@ class SfpUtil(SfpUtilBase): 2: "6-0064", } _port_to_i2c_mapping = { - 1: 18, - 2: 19, - 3: 20, - 4: 21, - 5: 22, - 6: 23, - 7: 24, - 8: 25, + 1: 18, + 2: 19, + 3: 20, + 4: 21, + 5: 22, + 6: 23, + 7: 24, + 8: 25, 9: 26, 10: 27, 11: 28, @@ -104,10 +104,10 @@ def qsfp_port_start(self): @property def qsfp_port_end(self): return self.QSFP_PORT_END - + @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -121,12 +121,12 @@ def __init__(self): SfpUtilBase.__init__(self) - def get_cpld_num(self, port_num): + def get_cpld_num(self, port_num): cpld_i = 1 if (port_num > 24 and port_num < self.qsfp_port_start): cpld_i = 2 - if (port_num > 52): + if (port_num > 52): cpld_i = 2 return cpld_i @@ -135,7 +135,7 @@ def get_presence(self, port_num): # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False - + cpld_i = self.get_cpld_num(port_num) cpld_ps = self._cpld_mapping[cpld_i] @@ -148,7 +148,7 @@ def get_presence(self, port_num): content = val_file.readline().rstrip() val_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False # content is a string, either "0" or "1" @@ -177,16 +177,16 @@ def get_low_power_mode(self, port_num): else: return 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 + # 2. "Power override" bit is 1 and "Power set" bit is 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 is not None: eeprom.close() time.sleep(0.01) - def set_low_power_mode(self, port_num, lpmode): + def set_low_power_mode(self, port_num, lpmode): # Check for invalid port_num if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False @@ -208,7 +208,7 @@ def set_low_power_mode(self, port_num, lpmode): eeprom.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 is not None: @@ -218,7 +218,7 @@ def set_low_power_mode(self, port_num, lpmode): def reset(self, port_num): if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False - + cpld_i = self.get_cpld_num(port_num) cpld_ps = self._cpld_mapping[cpld_i] path = "/sys/bus/i2c/devices/{0}/module_reset_{1}" @@ -226,14 +226,14 @@ def reset(self, port_num): try: reg_file = open(port_ps, 'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = '0' reg_file.write(reg_value) reg_file.close() - + return True def get_transceiver_change_event(self): diff --git a/device/accton/x86_64-accton_as7315_27xb-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7315_27xb-r0/plugins/sfputil.py index dc37f5ea360c..d10177850216 100644 --- a/device/accton/x86_64-accton_as7315_27xb-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7315_27xb-r0/plugins/sfputil.py @@ -34,14 +34,14 @@ class SfpUtil(SfpUtilBase): _cpld_mapping = [ "8-0063", "7-0064"] _port_to_i2c_mapping = { - 1: 26, - 2: 27, - 3: 28, - 4: 29, - 5: 30, - 6: 31, - 7: 32, - 8: 33, + 1: 26, + 2: 27, + 3: 28, + 4: 29, + 5: 30, + 6: 31, + 7: 32, + 8: 33, 9: 34, 10: 35, 11: 36, @@ -78,10 +78,10 @@ def qsfp_port_start(self): @property def qsfp_port_end(self): return self.QSFP_PORT_END - + @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -96,7 +96,7 @@ def __init__(self): self.get_transceiver_change_event() SfpUtilBase.__init__(self) - def get_cpld_num(self, port_num): + def get_cpld_num(self, port_num): cpld_i = 0 if (port_num >= self.qsfp_port_start): cpld_i = 1 @@ -107,11 +107,11 @@ def get_presence(self, port_num): # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False - + cpld_i = self.get_cpld_num(port_num) cpld_ps = self._cpld_mapping[cpld_i] path = "/sys/bus/i2c/devices/{0}/present_{1}" - index = ((port_num-1)%24) +1 + index = ((port_num-1)%24) +1 port_ps = path.format(cpld_ps, index) content = "0" @@ -120,9 +120,9 @@ def get_presence(self, port_num): content = val_file.readline().rstrip() val_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False - + if content == "1": return True @@ -148,16 +148,16 @@ def get_low_power_mode(self, port_num): else: return 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 + # 2. "Power override" bit is 1 and "Power set" bit is 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 is not None: eeprom.close() time.sleep(0.01) - def set_low_power_mode(self, port_num, lpmode): + def set_low_power_mode(self, port_num, lpmode): # Check for invalid port_num if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: return False @@ -179,7 +179,7 @@ def set_low_power_mode(self, port_num, lpmode): eeprom.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 is not None: @@ -206,7 +206,7 @@ def _get_present_bitmap(self): reg_file = open(node[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 cpld_bm = reg_file.readline().rstrip().zfill(node[1]/4) bitmap.append(cpld_bm) diff --git a/device/accton/x86_64-accton_as7326_56x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7326_56x-r0/plugins/sfputil.py index f9e0aae1b2a9..32fd1354fe7c 100644 --- a/device/accton/x86_64-accton_as7326_56x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7326_56x-r0/plugins/sfputil.py @@ -113,7 +113,7 @@ def qsfp_port_end(self): @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -151,7 +151,7 @@ def get_presence(self, port_num): content = val_file.readline().rstrip() val_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False if content == "1": @@ -179,10 +179,10 @@ def get_low_power_mode(self, port_num): else: return 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 + # 2. "Power override" bit is 1 and "Power set" bit is 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 is not None: @@ -211,7 +211,7 @@ def set_low_power_mode(self, port_num, lpmode): eeprom.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 is not None: @@ -226,12 +226,12 @@ def reset(self, port_num): cpld_ps = self._cpld_mapping[cpld_i] path = "/sys/bus/i2c/devices/{0}/module_reset_{1}" port_ps = path.format(cpld_ps, port_num) - + self.__port_to_mod_rst = port_ps try: reg_file = open(self.__port_to_mod_rst, 'r+', buffering=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 #toggle reset @@ -241,7 +241,7 @@ def reset(self, port_num): reg_file.seek(0) reg_file.write('0') reg_file.close() - + return True @property def _get_present_bitmap(self): @@ -262,7 +262,7 @@ def _get_present_bitmap(self): try: reg_file = open(node[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 bitmap = reg_file.readline().rstrip() bitmap = bin(int(bitmap, 16))[2:].zfill(node[1]) diff --git a/device/accton/x86_64-accton_as7512_32x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7512_32x-r0/plugins/sfputil.py index a4f405fa6afd..d5bfae40bdbf 100644 --- a/device/accton/x86_64-accton_as7512_32x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7512_32x-r0/plugins/sfputil.py @@ -5,7 +5,7 @@ import string from ctypes import create_string_buffer from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") @@ -19,8 +19,8 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} - _qsfp_ports = range(0, ports_in_block + 1) - + _qsfp_ports = list(range(0, ports_in_block + 1)) + def __init__(self): # Override port_to_eeprom_mapping for class initialization eeprom_path = '/sys/bus/i2c/devices/{0}-0050/sfp_eeprom' @@ -45,9 +45,9 @@ def get_presence(self, port_num): reg_value = reg_file.readline().rstrip() reg_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False - + if reg_value == '1': return True @@ -63,7 +63,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(0, self.ports_in_block + 1) + return list(range(0, self.ports_in_block + 1)) @property def port_to_eeprom_mapping(self): @@ -97,16 +97,16 @@ def get_low_power_mode(self, port_num): else: return 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 + # 2. "Power override" bit is 1 and "Power set" bit is 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 is not None: eeprom.close() time.sleep(0.01) - def set_low_power_mode(self, port_num, lpmode): + def set_low_power_mode(self, port_num, lpmode): # Check for invalid port_num if port_num < self._port_start or port_num > self._port_end: return False @@ -128,9 +128,9 @@ def set_low_power_mode(self, port_num, lpmode): eeprom.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 is not None: eeprom.close() - time.sleep(0.01) \ No newline at end of file + time.sleep(0.01) diff --git a/device/accton/x86_64-accton_as7712_32x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7712_32x-r0/plugins/sfputil.py index 8cfde932e7e3..19e7f9f31d5e 100644 --- a/device/accton/x86_64-accton_as7712_32x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7712_32x-r0/plugins/sfputil.py @@ -4,8 +4,8 @@ import time import string from ctypes import create_string_buffer - from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError, e: + from sonic_sfp.sfputilbase import SfpUtilBase +except ImportError as e: raise ImportError (str(e) + "- required module not found") #from xcvrd @@ -56,7 +56,7 @@ class SfpUtil(SfpUtilBase): 24 : 49, } - _qsfp_ports = range(0, ports_in_block + 1) + _qsfp_ports = list(range(0, ports_in_block + 1)) def __init__(self): eeprom_path = '/sys/bus/i2c/devices/{0}-0050/eeprom' @@ -72,11 +72,11 @@ def reset(self, port_num): path = "/sys/bus/i2c/devices/4-0060/module_reset_{0}" port_ps = path.format(port_num) - + try: reg_file = open(port_ps, 'w', buffering=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 #toggle reset @@ -87,7 +87,7 @@ def reset(self, port_num): reg_file.write('0') reg_file.close() return True - + def get_presence(self, port_num): # Check for invalid port_num if port_num < self._port_start or port_num > self._port_end: @@ -102,9 +102,9 @@ def get_presence(self, port_num): reg_value = reg_file.readline().rstrip() reg_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False - + if reg_value == '1': return True @@ -117,12 +117,12 @@ def port_start(self): @property def port_end(self): return self._port_end - + @property def qsfp_ports(self): - return range(self.port_start, self.ports_in_block + 1) + return list(range(self.port_start, self.ports_in_block + 1)) - @property + @property def port_to_eeprom_mapping(self): return self._port_to_eeprom_mapping @@ -146,16 +146,16 @@ def get_low_power_mode(self, port_num): else: return 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 + # 2. "Power override" bit is 1 and "Power set" bit is 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 is not None: eeprom.close() time.sleep(0.01) - def set_low_power_mode(self, port_num, lpmode): + def set_low_power_mode(self, port_num, lpmode): # Check for invalid port_num if port_num < self._port_start or port_num > self._port_end: return False @@ -177,7 +177,7 @@ def set_low_power_mode(self, port_num, lpmode): eeprom.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 is not None: @@ -197,7 +197,7 @@ def _get_all_presence(self): reg_file = open(node) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False bitmap += reg_file.readline().rstrip() + " " reg_file.close() @@ -239,4 +239,4 @@ def get_transceiver_change_event(self, timeout=2000): else: return True, {} return False, {} - + diff --git a/device/accton/x86_64-accton_as7716_32x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7716_32x-r0/plugins/sfputil.py index b8e4e8d1317d..7944c623760d 100755 --- a/device/accton/x86_64-accton_as7716_32x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7716_32x-r0/plugins/sfputil.py @@ -21,10 +21,10 @@ class SfpUtil(SfpUtilBase): PORT_START = 1 PORT_END = 32 PORTS_IN_BLOCK = 32 - + BASE_OOM_PATH = "/sys/bus/i2c/devices/{0}-0050/" BASE_CPLD_PATH = "/sys/bus/i2c/devices/11-0060/" - + _port_to_is_present = {} _port_to_lp_mode = {} @@ -61,7 +61,7 @@ class SfpUtil(SfpUtilBase): 29: 49, 30: 50, 31: 51, - 32: 52, + 32: 52, } @property @@ -71,10 +71,10 @@ def port_start(self): @property def port_end(self): return self.PORT_END - + @property def qsfp_ports(self): - return range(self.PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -83,7 +83,7 @@ def port_to_eeprom_mapping(self): def __init__(self): eeprom_path = self.BASE_OOM_PATH + "eeprom" - for x in range(self.port_start, self.port_end+1): + for x in range(self.port_start, self.port_end+1): self.port_to_eeprom_mapping[x] = eeprom_path.format( self._port_to_i2c_mapping[x] ) @@ -93,7 +93,7 @@ def get_presence(self, port_num): # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False - + present_path = self.BASE_CPLD_PATH + "module_present_" + str(port_num) self.__port_to_is_present = present_path @@ -103,9 +103,9 @@ def get_presence(self, port_num): content = val_file.readline().rstrip() val_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False - + if content == "1": return True @@ -131,16 +131,16 @@ def get_low_power_mode(self, port_num): else: return 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 + # 2. "Power override" bit is 1 and "Power set" bit is 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 is not None: eeprom.close() time.sleep(0.01) - def set_low_power_mode(self, port_num, lpmode): + def set_low_power_mode(self, port_num, lpmode): # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False @@ -162,7 +162,7 @@ def set_low_power_mode(self, port_num, lpmode): eeprom.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 is not None: @@ -172,20 +172,20 @@ def set_low_power_mode(self, port_num, lpmode): def reset(self, port_num): if port_num < self.port_start or port_num > self.port_end: return False - + mod_rst_path = self.BASE_CPLD_PATH + "module_reset_" + str(port_num) self.__port_to_mod_rst = mod_rst_path try: reg_file = open(self.__port_to_mod_rst, 'r+') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = '1' reg_file.write(reg_value) reg_file.close() - + return True @property @@ -199,7 +199,7 @@ def _get_present_bitmap(self): reg_file = open(node) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False bitmap += reg_file.readline().rstrip() + " " reg_file.close() @@ -241,4 +241,4 @@ def get_transceiver_change_event(self, timeout=2000): else: return True, {} return False, {} - + diff --git a/device/accton/x86_64-accton_as7716_32xb-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7716_32xb-r0/plugins/sfputil.py index 8bc5869e6b94..18c04888630d 100755 --- a/device/accton/x86_64-accton_as7716_32xb-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7716_32xb-r0/plugins/sfputil.py @@ -7,7 +7,7 @@ import time import os import sys, getopt - import commands + import subprocess from sonic_sfp.sfputilbase import SfpUtilBase except ImportError as e: raise ImportError("%s - required module not found" % str(e)) @@ -19,11 +19,11 @@ class SfpUtil(SfpUtilBase): PORT_START = 0 PORT_END = 31 PORTS_IN_BLOCK = 32 - + BASE_OOM_PATH = "/sys/bus/i2c/devices/{0}-0050/" BASE_CPLD_PATH = "/sys/bus/i2c/devices/0-0060/" BASE_I2C_PATH = "/sys/bus/i2c/devices/" - + _port_to_is_present = {} _port_to_lp_mode = {} @@ -60,7 +60,7 @@ class SfpUtil(SfpUtilBase): 28: [30, 49], 29: [31, 50], 30: [32, 51], - 31: [33, 52], + 31: [33, 52], } @property @@ -70,20 +70,20 @@ def port_start(self): @property def port_end(self): return self.PORT_END - + @property def qsfp_ports(self): - return range(self.PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): return self._port_to_eeprom_mapping - + def get_presence(self, port_num): - # Check for invalid port_num + # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False - + present_path = self.BASE_CPLD_PATH + "module_present_" + str(port_num+1) self.__port_to_is_present = present_path @@ -93,47 +93,47 @@ def get_presence(self, port_num): content = val_file.readline().rstrip() val_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False - + if content == "1": return True return False def __init__(self): - eeprom_path = self.BASE_I2C_PATH + eeprom_path = self.BASE_I2C_PATH - for x in range(0, self.port_end+1): + for x in range(0, self.port_end+1): self.port_to_eeprom_mapping[x] = eeprom_path.format( self._port_to_i2c_mapping[x][1] ) - if(x < 9): + if(x < 9): if(self.get_presence(x)==1): - self.port_to_eeprom_mapping[x] = self.BASE_I2C_PATH + "0-000" +str(x+1) + "/eeprom" - + self.port_to_eeprom_mapping[x] = self.BASE_I2C_PATH + "0-000" +str(x+1) + "/eeprom" + else: - if(self.get_presence(x)==1): + if(self.get_presence(x)==1): self.port_to_eeprom_mapping[x] = self.BASE_I2C_PATH + "0-00" +str(x+1)+ "/eeprom" - + SfpUtilBase.__init__(self) - - def get_low_power_mode(self, port_num): + + def get_low_power_mode(self, port_num): raise NotImplementedError - + def set_low_power_mode(self, port_num, lpmode): raise NotImplementedError def reset(self, port_num): if port_num < self.port_start or port_num > self.port_end: return False - - mod_rst_cmd = "ipmitool raw 0x34 0x11 " + str(port_num+1) + " 0x11 0x1" - (status, output) = commands.getstatusoutput (mod_rst_cmd) + + mod_rst_cmd = "ipmitool raw 0x34 0x11 " + str(port_num+1) + " 0x11 0x1" + subprocess.check_output(mod_rst_cmd) return True - + def get_transceiver_change_event(self): """ TODO: This function need to be implemented diff --git a/device/accton/x86_64-accton_as7726_32x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7726_32x-r0/plugins/sfputil.py index f8ef438af954..64da760ad821 100755 --- a/device/accton/x86_64-accton_as7726_32x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7726_32x-r0/plugins/sfputil.py @@ -18,14 +18,14 @@ class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" - + PORT_START = 1 PORT_END = 32 #34 cages actually, but last 2 are not at port_config.ini. PORTS_IN_BLOCK = 32 - + BASE_OOM_PATH = "/sys/bus/i2c/devices/{0}-0050/" BASE_CPLD_PATH = "/sys/bus/i2c/devices/11-0060/" - + _port_to_is_present = {} _port_to_lp_mode = {} @@ -62,9 +62,9 @@ class SfpUtil(SfpUtilBase): 29: 41, 30: 42, 31: 43, - 32: 44, - 33: 15, - 34: 16, + 32: 44, + 33: 15, + 34: 16, } @property @@ -74,10 +74,10 @@ def port_start(self): @property def port_end(self): return self.PORT_END - + @property def qsfp_ports(self): - return range(self.PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -85,7 +85,7 @@ def port_to_eeprom_mapping(self): def __init__(self): eeprom_path = self.BASE_OOM_PATH + "eeprom" - + for x in range(self.port_start, self.port_end+1): self.port_to_eeprom_mapping[x] = eeprom_path.format( self._port_to_i2c_mapping[x] @@ -106,9 +106,9 @@ def get_presence(self, port_num): content = val_file.readline().rstrip() val_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False - + if content == "1": return True @@ -134,16 +134,16 @@ def get_low_power_mode(self, port_num): else: return 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 + # 2. "Power override" bit is 1 and "Power set" bit is 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 is not None: eeprom.close() time.sleep(0.01) - def set_low_power_mode(self, port_num, lpmode): + def set_low_power_mode(self, port_num, lpmode): # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False @@ -165,7 +165,7 @@ def set_low_power_mode(self, port_num, lpmode): eeprom.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 is not None: @@ -175,14 +175,14 @@ def set_low_power_mode(self, port_num, lpmode): def reset(self, port_num): if port_num < self.port_start or port_num > self.port_end: return False - + mod_rst_path = self.BASE_CPLD_PATH + "module_reset_" + str(port_num) - + self.__port_to_mod_rst = mod_rst_path try: reg_file = open(self.__port_to_mod_rst, 'r+', buffering=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 #toggle reset @@ -192,7 +192,7 @@ def reset(self, port_num): reg_file.seek(0) reg_file.write('0') reg_file.close() - + return True @property @@ -208,7 +208,7 @@ def get_transceiver_status(self): reg_file = open(node) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False bitmap += reg_file.readline().rstrip() + " " reg_file.close() diff --git a/device/accton/x86_64-accton_as7816_64x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7816_64x-r0/plugins/sfputil.py index afb6f0c74147..3572aec3348d 100644 --- a/device/accton/x86_64-accton_as7816_64x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7816_64x-r0/plugins/sfputil.py @@ -4,8 +4,8 @@ import time import string from ctypes import create_string_buffer - from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError, e: + from sonic_sfp.sfputilbase import SfpUtilBase +except ImportError as e: raise ImportError (str(e) + "- required module not found") #from xcvrd @@ -86,7 +86,7 @@ class SfpUtil(SfpUtilBase): 51 : 87, 52 : 88,} - _qsfp_ports = range(0, ports_in_block + 1) + _qsfp_ports = list(range(0, ports_in_block + 1)) def __init__(self): eeprom_path = '/sys/bus/i2c/devices/{0}-0050/eeprom' @@ -101,11 +101,11 @@ def reset(self, port_num): return False path = "/sys/bus/i2c/devices/19-0060/module_reset_{0}" port_ps = path.format(port_num) - + try: reg_file = open(port_ps, 'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False #HW will clear reset after set. @@ -113,7 +113,7 @@ def reset(self, port_num): reg_file.write('1') reg_file.close() return True - + def get_presence(self, port_num): # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: @@ -121,16 +121,16 @@ def get_presence(self, port_num): path = "/sys/bus/i2c/devices/19-0060/module_present_{0}" port_ps = path.format(port_num) - + reg_value = '0' try: reg_file = open(port_ps) reg_value = reg_file.readline().rstrip() reg_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False - + if reg_value == '1': return True @@ -143,12 +143,12 @@ def port_start(self): @property def port_end(self): return self._port_end - + @property def qsfp_ports(self): - return range(0, self.ports_in_block + 1) + return list(range(0, self.ports_in_block + 1)) - @property + @property def port_to_eeprom_mapping(self): return self._port_to_eeprom_mapping @@ -172,16 +172,16 @@ def get_low_power_mode(self, port_num): else: return 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 + # 2. "Power override" bit is 1 and "Power set" bit is 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 is not None: eeprom.close() time.sleep(0.01) - def set_low_power_mode(self, port_num, lpmode): + def set_low_power_mode(self, port_num, lpmode): # Check for invalid port_num if port_num < self._port_start or port_num > self._port_end: return False @@ -203,7 +203,7 @@ def set_low_power_mode(self, port_num, lpmode): eeprom.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 is not None: @@ -223,7 +223,7 @@ def _get_present_bitmap(self): reg_file = open(node) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False bitmap += reg_file.readline().rstrip() + " " reg_file.close() diff --git a/device/accton/x86_64-accton_as9716_32d-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as9716_32d-r0/plugins/sfputil.py index ea356bc9a328..8a41a2bb576e 100755 --- a/device/accton/x86_64-accton_as9716_32d-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as9716_32d-r0/plugins/sfputil.py @@ -15,15 +15,15 @@ class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" - + PORT_START = 0 PORT_END = 33 PORTS_IN_BLOCK = 34 - + BASE_OOM_PATH = "/sys/bus/i2c/devices/{0}-0050/" BASE_CPLD1_PATH = "/sys/bus/i2c/devices/20-0061/" BASE_CPLD2_PATH = "/sys/bus/i2c/devices/21-0062/" - + _port_to_is_present = {} _port_to_lp_mode = {} @@ -60,9 +60,9 @@ class SfpUtil(SfpUtilBase): 28: [29, 53], 29: [30, 54], 30: [31, 55], - 31: [32, 56], - 32: [33, 57], - 33: [34, 58], + 31: [32, 56], + 32: [33, 57], + 33: [34, 58], } @property @@ -72,10 +72,10 @@ def port_start(self): @property def port_end(self): return self.PORT_END - + @property def qsfp_ports(self): - return range(self.PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -83,7 +83,7 @@ def port_to_eeprom_mapping(self): def __init__(self): eeprom_path = self.BASE_OOM_PATH + "eeprom" - + for x in range(0, self.port_end+1): self.port_to_eeprom_mapping[x] = eeprom_path.format( self._port_to_i2c_mapping[x][1] @@ -107,7 +107,7 @@ def get_presence(self, port_num): content = val_file.readline().rstrip() val_file.close() except IOError as e: - print "Error: unable to access file: %s" % str(e) + print("Error: unable to access file: %s" % str(e)) return False if content == "1": @@ -115,7 +115,7 @@ def get_presence(self, port_num): return False - def get_low_power_mode(self, port_num): + def get_low_power_mode(self, port_num): # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False @@ -135,15 +135,15 @@ def get_low_power_mode(self, port_num): else: return 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 + # 2. "Power override" bit is 1 and "Power set" bit is 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 is not None: eeprom.close() time.sleep(0.01) - + def set_low_power_mode(self, port_num, lpmode): # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: @@ -156,10 +156,10 @@ def set_low_power_mode(self, port_num, lpmode): return False # Port is not present, unable to set the eeprom # Fill in write buffer - # 0x3:Low Power Mode. "Power override" bit is 1 and "Power set" bit is 1 - # 0x9:High Power Mode. "Power override" bit is 1 ,"Power set" bit is 0 and "High Power Class Enable" bit is 1 - regval = 0x3 if lpmode else 0x9 - + # 0x3:Low Power Mode. "Power override" bit is 1 and "Power set" bit is 1 + # 0x9:High Power Mode. "Power override" bit is 1 ,"Power set" bit is 0 and "High Power Class Enable" bit is 1 + regval = 0x3 if lpmode else 0x9 + buffer = create_string_buffer(1) buffer[0] = chr(regval) @@ -169,7 +169,7 @@ def set_low_power_mode(self, port_num, lpmode): eeprom.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 is not None: @@ -179,26 +179,26 @@ def set_low_power_mode(self, port_num, lpmode): def reset(self, port_num): if port_num < self.port_start or port_num > self.port_end: return False - + if port_num < 16 : mod_rst_path = self.BASE_CPLD1_PATH + "module_reset_" + str(port_num+1) else: mod_rst_path = self.BASE_CPLD2_PATH + "module_reset_" + str(port_num+1) - + self.__port_to_mod_rst = mod_rst_path try: reg_file = open(self.__port_to_mod_rst, 'r+') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = '1' reg_file.write(reg_value) reg_file.close() - + return True - + def get_cpld_interrupt(self): port_dict={} for i in range(0,4): @@ -206,24 +206,24 @@ def get_cpld_interrupt(self): cpld_i2c_path = self.BASE_CPLD1_PATH + "cpld_intr_" + str(i+1) else: cpld_i2c_path = self.BASE_CPLD2_PATH + "cpld_intr_" +str(i+1) - + start_i=(i*8) end_i=(i*8+8) try: val_file = open(cpld_i2c_path) except IOError as e: - print "Error: unable to open file: %s" % str(e) - + print("Error: unable to open file: %s" % str(e)) + for k in range (start_i, end_i): - port_dict[k]=0 + port_dict[k]=0 return port_dict status = val_file.readline().rstrip() val_file.close() status=status.strip() status= int(status, 16) - - interrupt_status = ~(status & 0xff) + + interrupt_status = ~(status & 0xff) if interrupt_status: port_shift=0 for k in range (start_i, end_i): @@ -234,7 +234,7 @@ def get_cpld_interrupt(self): port_shift=port_shift+1 return port_dict - + def get_transceiver_change_event(self, timeout=0): start_time = time.time() port_dict = {} @@ -246,25 +246,25 @@ def get_transceiver_change_event(self, timeout=0): elif timeout > 0: timeout = timeout / float(1000) # Convert to secs else: - print "get_transceiver_change_event:Invalid timeout value", timeout + print("get_transceiver_change_event:Invalid timeout value", timeout) return False, {} end_time = start_time + timeout if start_time > end_time: - print 'get_transceiver_change_event:' \ - 'time wrap / invalid timeout value', timeout + print('get_transceiver_change_event:' \ + 'time wrap / invalid timeout value', timeout) return False, {} # Time wrap or possibly incorrect timeout - + #for i in range(self.port_start, self.port_end+1): # ori_present[i]=self.get_presence(i) - - while timeout >= 0: + + while timeout >= 0: change_status=0 - + port_dict = self.get_cpld_interrupt() present=0 - for key, value in port_dict.iteritems(): + for key, value in port_dict.items(): if value==1: present=self.get_presence(key) change_status=1 @@ -272,8 +272,8 @@ def get_transceiver_change_event(self, timeout=0): port_dict[key]='1' else: port_dict[key]='0' - - if change_status: + + if change_status: return True, port_dict if forever: time.sleep(1) @@ -285,5 +285,5 @@ def get_transceiver_change_event(self, timeout=0): if timeout > 0: time.sleep(timeout) return True, {} - print "get_evt_change_event: Should not reach here." - return False, {} \ No newline at end of file + print("get_evt_change_event: Should not reach here.") + return False, {} diff --git a/device/accton/x86_64-accton_minipack-r0/plugins/led_control.py b/device/accton/x86_64-accton_minipack-r0/plugins/led_control.py index 26e2a7f7c8a2..d662759f4a1b 100755 --- a/device/accton/x86_64-accton_minipack-r0/plugins/led_control.py +++ b/device/accton/x86_64-accton_minipack-r0/plugins/led_control.py @@ -17,19 +17,19 @@ from socket import * from select import * from minipack.pimutil import PimUtil -except ImportError, e: +except ImportError as e: raise ImportError(str(e) + " - required module not found") class LedControl(LedControlBase): """Platform specific LED control class""" SONIC_PORT_NAME_PREFIX = "Ethernet" - - + + def __init__(self): pim=PimUtil() pim.init_pim_fpga() - + def _port_name_to_index(self, port_name): # Strip "Ethernet" off port name if not port_name.startswith(self.SONIC_PORT_NAME_PREFIX): @@ -37,7 +37,7 @@ def _port_name_to_index(self, port_name): port_idx = int(port_name[len(self.SONIC_PORT_NAME_PREFIX):]) return port_idx - + def _port_state_to_mode(self, port_idx, state): if state == "up": return 1, 4 #port linkup, led is green @@ -49,11 +49,11 @@ def port_link_state_change(self, portname, state): port_idx = self._port_name_to_index(portname) new_control, led_mode = self._port_state_to_mode(port_idx, state) color, control=pim.get_port_led(port_idx) - + if color==led_mode: if control==new_control: return - + pim.set_port_led(port_idx, led_mode, new_control)#port linkup, led is green #port linkdown, led is off diff --git a/device/accton/x86_64-accton_minipack-r0/plugins/sfputil.py b/device/accton/x86_64-accton_minipack-r0/plugins/sfputil.py index 6f62d8ed4c07..cdbac3096bce 100755 --- a/device/accton/x86_64-accton_minipack-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_minipack-r0/plugins/sfputil.py @@ -8,19 +8,19 @@ from sonic_sfp.sfputilbase import SfpUtilBase import os import sys, getopt - from minipack.pimutil import PimUtil + from minipack.pimutil import PimUtil except ImportError as e: raise ImportError("%s - required module not found" % str(e)) class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" - + PORT_START = 0 PORT_END = 128 - + LOCAL_OOM_PATH = "/usr/local/bin/minipack_qsfp/port%d_eeprom" - + _port_to_is_present = {} _port_to_lp_mode = {} @@ -33,10 +33,10 @@ def port_start(self): @property def port_end(self): return self.PORT_END - + @property def qsfp_ports(self): - return range(self.PORT_START, self.PORT_END + 1) + return list(range(self.PORT_START, self.PORT_END + 1)) @property def port_to_eeprom_mapping(self): @@ -56,15 +56,15 @@ def sfp_map(self, index): def __init__(self): - for x in range(0, self.port_end): + for x in range(0, self.port_end): self.port_to_eeprom_mapping[x] = self.LOCAL_OOM_PATH %x SfpUtilBase.__init__(self) pim=PimUtil() pim.init_pim_fpga() - + def __del__(self): - self.value=0 + self.value=0 def get_presence(self, port_num): # Check for invalid port_num @@ -74,54 +74,54 @@ def get_presence(self, port_num): pim=PimUtil() status=pim.get_qsfp_presence(port_num) return status - - def get_low_power_mode(self, port_num): + + def get_low_power_mode(self, port_num): if port_num < self.port_start or port_num > self.port_end: return False pim=PimUtil() return pim.get_low_power_mode(port_num) - + def set_low_power_mode(self, port_num, lpmode): if port_num < self.port_start or port_num > self.port_end: return False pim=PimUtil() - pim.set_low_power_mode(port_num, lpmode) - return True + pim.set_low_power_mode(port_num, lpmode) + return True def reset(self, port_num): if port_num < self.port_start or port_num > self.port_end: return False pim=PimUtil() pim.reset(port_num) - return True - + return True + def get_transceiver_change_event(self, timeout=0): pim=PimUtil() start_time = time.time() port_dict = {} forever = False - + if timeout == 0: forever = True elif timeout > 0: timeout = timeout / float(1000) # Convert to secs else: - print "get_transceiver_change_event:Invalid timeout value", timeout + print("get_transceiver_change_event:Invalid timeout value", timeout) return False, {} end_time = start_time + timeout if start_time > end_time: - print 'get_transceiver_change_event:' \ - 'time wrap / invalid timeout value', timeout + print('get_transceiver_change_event:' \ + 'time wrap / invalid timeout value', timeout) return False, {} # Time wrap or possibly incorrect timeout - - while timeout >= 0: + + while timeout >= 0: change_status=0 port_dict = pim.get_qsfp_interrupt() present=0 - for key, value in port_dict.iteritems(): + for key, value in port_dict.items(): if value==1: present=self.get_presence(key) change_status=1 @@ -129,8 +129,8 @@ def get_transceiver_change_event(self, timeout=0): port_dict[key]='1' else: port_dict[key]='0' - - if change_status: + + if change_status: return True, port_dict if forever: time.sleep(1) @@ -142,5 +142,5 @@ def get_transceiver_change_event(self, timeout=0): if timeout > 0: time.sleep(timeout) return True, {} - print "get_evt_change_event: Should not reach here." + print("get_evt_change_event: Should not reach here.") return False, {} diff --git a/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/led_control.py b/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/led_control.py index bab96d69dc47..8516a840e6b7 100644 --- a/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/led_control.py +++ b/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/led_control.py @@ -8,7 +8,7 @@ # try: # from sonic_led.led_control_base import LedControlBase # import swsssdk -# except ImportError, e: +# except ImportError as e: # raise ImportError (str(e) + " - required module not found") import time diff --git a/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/sfputil.py b/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/sfputil.py index 9e502578f153..fcfc34940173 100644 --- a/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/sfputil.py +++ b/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/sfputil.py @@ -2,8 +2,8 @@ try: import time - from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError, e: + from sonic_sfp.sfputilbase import SfpUtilBase +except ImportError as e: raise ImportError (str(e) + "- required module not found") @@ -26,7 +26,7 @@ class SfpUtil(SfpUtilBase): port_reset_path = "/sys/bus/i2c/devices/{0}-005f/sfp{1}_port_reset" present_path = "/sys/bus/i2c/devices/{0}-005f/sfp{1}_is_present" - _qsfp_ports = range(first_port, port_num + 1) + _qsfp_ports = list(range(first_port, port_num + 1)) @property def port_start(self): return self.first_port @@ -37,9 +37,9 @@ def port_end(self): @property def qsfp_ports(self): - return range(self.first_port, self.port_num + 1) + return list(range(self.first_port, self.port_num + 1)) - @property + @property def port_to_eeprom_mapping(self): return self.port_to_eeprom @@ -68,11 +68,11 @@ def reset(self, port_num): i2c_index = (port_num / 8) + 1 path = self.port_reset_path port_path = path.format(self.port_to_i2cbus_mapping[i2c_index], (index + 1)) - + try: reg_file = open(port_path, 'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # reset @@ -90,7 +90,7 @@ def set_low_power_mode(self, port_nuM, lpmode): def get_low_power_mode(self, port_num): raise NotImplementedError - + def get_presence(self, port_num): # Check for invalid port_num if port_num < self.first_port or port_num > self.last_port: @@ -101,11 +101,11 @@ def get_presence(self, port_num): path = self.present_path port_path = path.format(self.port_to_i2cbus_mapping[i2c_index], (index + 1)) - + try: reg_file = open(port_path) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_file.readline().rstrip() diff --git a/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/led_control.py b/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/led_control.py index 457b1d750b28..71e6299963f4 100644 --- a/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/led_control.py +++ b/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/led_control.py @@ -8,7 +8,7 @@ # try: # from sonic_led.led_control_base import LedControlBase # import swsssdk -# except ImportError, e: +# except ImportError as e: # raise ImportError (str(e) + " - required module not found") import time diff --git a/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/sfputil.py b/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/sfputil.py index cc3cd4e8611d..641c62c4ab56 100644 --- a/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/sfputil.py +++ b/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/sfputil.py @@ -2,8 +2,8 @@ try: import time - from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError, e: + from sonic_sfp.sfputilbase import SfpUtilBase +except ImportError as e: raise ImportError (str(e) + "- required module not found") @@ -30,7 +30,7 @@ class SfpUtil(SfpUtilBase): present_path_1 = "/sys/bus/i2c/devices/{0}-0020/sfp{1}_is_present" present_path = "/sys/bus/i2c/devices/{0}-005f/sfp{1}_is_present" - _qsfp_ports = range(first_port, port_num) + _qsfp_ports = list(range(first_port, port_num)) @property def port_start(self): @@ -42,9 +42,9 @@ def port_end(self): @property def qsfp_ports(self): - return range(self.first_port, self.port_num + 1) + return list(range(self.first_port, self.port_num + 1)) - @property + @property def port_to_eeprom_mapping(self): return self.port_to_eeprom @@ -79,12 +79,12 @@ def reset(self, port_num): else: path = self.port_reset_path port_path = path.format(self.port_to_i2cbus_mapping[cpld_index], index) - + try: reg_file = open(port_path, 'w') except IOError as e: if cpld_index < 5: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # reset @@ -102,7 +102,7 @@ def set_low_power_mode(self, port_nuM, lpmode): def get_low_power_mode(self, port_num): raise NotImplementedError - + def get_presence(self, port_num): # Check for invalid port_num if port_num < self.first_port or port_num > self.last_port: @@ -116,12 +116,12 @@ def get_presence(self, port_num): path = self.present_path port_path = path.format(self.port_to_i2cbus_mapping[cpld_index], index) - + try: reg_file = open(port_path) except IOError as e: if cpld_index < 5: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_file.readline().rstrip() diff --git a/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/eeprom.py b/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/eeprom.py index bf3795429309..3b0ee5fff37e 100644 --- a/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/eeprom.py +++ b/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/eeprom.py @@ -32,6 +32,12 @@ raise ImportError (str(e) + "- required module not found") +if sys.version_info.major == 3: + STRING_TYPE = str +else: + STRING_TYPE = basestring + + eeprom_default_dict = { "prod_name" : ("Product Name", "0x21", 12), "odm_pcba_part_num" : ("Part Number", "0x22", 13), @@ -141,7 +147,7 @@ def eeprom_init(self): f.close() eeprom_params = "" - for attr, val in eeprom.__dict__.iteritems(): + for attr, val in eeprom.__dict__.items(): if val is None: continue @@ -149,7 +155,7 @@ def eeprom_init(self): if elem is None: continue - if isinstance(val, basestring): + if isinstance(val, STRING_TYPE): value = val.replace('\0', '') else: value = str(val) diff --git a/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/pltfm_mgr_rpc/pltfm_mgr_rpc.py b/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/pltfm_mgr_rpc/pltfm_mgr_rpc.py index b256b6285fc3..16608e977d24 100644 --- a/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/pltfm_mgr_rpc/pltfm_mgr_rpc.py +++ b/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/pltfm_mgr_rpc/pltfm_mgr_rpc.py @@ -1020,7 +1020,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -1079,7 +1079,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -1121,7 +1121,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -1194,7 +1194,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -1236,7 +1236,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -1309,7 +1309,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -1369,7 +1369,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -1441,7 +1441,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -1501,7 +1501,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -1574,7 +1574,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -1634,7 +1634,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -1707,7 +1707,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -1779,7 +1779,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -1851,7 +1851,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -1911,7 +1911,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -1984,7 +1984,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -2044,7 +2044,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -2116,7 +2116,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -2176,7 +2176,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -2248,7 +2248,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -2290,7 +2290,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -2362,7 +2362,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -2434,7 +2434,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -2506,7 +2506,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -2566,7 +2566,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -2638,7 +2638,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -2710,7 +2710,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -2782,7 +2782,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -2842,7 +2842,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -2914,7 +2914,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): diff --git a/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/pltfm_mgr_rpc/ttypes.py b/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/pltfm_mgr_rpc/ttypes.py index ce03e14f8691..22b59d885bb7 100644 --- a/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/pltfm_mgr_rpc/ttypes.py +++ b/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/pltfm_mgr_rpc/ttypes.py @@ -171,7 +171,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -483,7 +483,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -651,7 +651,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -891,7 +891,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -987,7 +987,7 @@ def validate(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): @@ -1050,7 +1050,7 @@ def __str__(self): def __repr__(self): L = ['%s=%r' % (key, value) - for key, value in self.__dict__.items()] + for key, value in list(self.__dict__.items())] return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) def __eq__(self, other): diff --git a/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/sfputil.py b/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/sfputil.py index 00ab0f94ec1a..aa65b67813d4 100644 --- a/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/sfputil.py +++ b/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/sfputil.py @@ -51,12 +51,12 @@ def port_end(self): @property def qsfp_ports(self): self.update_port_info() - return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): - print "dependency on sysfs has been removed" - raise Exception() + print("dependency on sysfs has been removed") + raise Exception() def __init__(self): self.ready = False @@ -127,8 +127,8 @@ def get_presence(self, port_num): presence = pltfm_mgr.pltfm_mgr_qsfp_presence_get(port_num) self.thrift_teardown() except Exception as e: - print e.__doc__ - print e.message + print(e.__doc__) + print(e.message) return presence @@ -200,7 +200,7 @@ def get_transceiver_change_event(self, timeout=0): elif timeout > 0: timeout = timeout / float(1000) # Convert to secs else: - print "get_transceiver_change_event:Invalid timeout value", timeout + print("get_transceiver_change_event:Invalid timeout value", timeout) return False, {} while forever or timeout > 0: diff --git a/device/celestica/x86_64-cel_e1031-r0/plugins/sfputil.py b/device/celestica/x86_64-cel_e1031-r0/plugins/sfputil.py index 9cbec7127261..f8f37ae03126 100644 --- a/device/celestica/x86_64-cel_e1031-r0/plugins/sfputil.py +++ b/device/celestica/x86_64-cel_e1031-r0/plugins/sfputil.py @@ -69,7 +69,7 @@ class SfpUtil(SfpUtilBase): 52: 16 } _port_to_eeprom_mapping = {} - _sfp_port = range(49, PORT_END + 1) + _sfp_port = list(range(49, PORT_END + 1)) @property def port_start(self): @@ -129,7 +129,7 @@ def get_transceiver_change_event(self, timeout=0): try: # We get notified when there is an SCI interrupt from GPIO SUS7 fd = open("/sys/devices/platform/hlx-ich.0/sci_int_gpio_sus7", "r") - fd.read() + fd.read() epoll.register(fd.fileno(), select.EPOLLIN & select.EPOLLET) events = epoll.poll(timeout=timeout_sec if timeout != 0 else -1) @@ -143,14 +143,14 @@ def get_transceiver_change_event(self, timeout=0): if change == 1: port_dict[str(port_num)] = str(int(self.get_presence(port_num))) found_flag = 1 - + if not found_flag: return False, {} return True, port_dict - + finally: fd.close() epoll.close() - return False, {} \ No newline at end of file + return False, {} diff --git a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/psu.py b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/psu.py index 9777bb6fea64..9ffa2f838247 100644 --- a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/psu.py +++ b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/psu.py @@ -84,7 +84,7 @@ def get_voltage(self): if vout_label_path: dir_name = os.path.dirname(vout_label_path) basename = os.path.basename(vout_label_path) - in_num = filter(str.isdigit, basename) + in_num = list(filter(str.isdigit, basename)) vout_path = os.path.join( dir_name, voltage_name.format(in_num)) vout_val = self.__read_txt_file(vout_path) @@ -107,7 +107,7 @@ def get_current(self): if curr_label_path: dir_name = os.path.dirname(curr_label_path) basename = os.path.basename(curr_label_path) - cur_num = filter(str.isdigit, basename) + cur_num = list(filter(str.isdigit, basename)) cur_path = os.path.join( dir_name, current_name.format(cur_num)) cur_val = self.__read_txt_file(cur_path) @@ -130,7 +130,7 @@ def get_power(self): if pw_label_path: dir_name = os.path.dirname(pw_label_path) basename = os.path.basename(pw_label_path) - pw_num = filter(str.isdigit, basename) + pw_num = list(filter(str.isdigit, basename)) pw_path = os.path.join( dir_name, current_name.format(pw_num)) pw_val = self.__read_txt_file(pw_path) diff --git a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/sfp.py b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/sfp.py index 5932b30c326e..a3494daba4bf 100644 --- a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/sfp.py +++ b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/sfp.py @@ -81,7 +81,7 @@ class Sfp(SfpBase): 51: 17, 52: 16 } - _sfp_port = range(49, PORT_END + 1) + _sfp_port = list(range(49, PORT_END + 1)) PRS_PATH = "/sys/devices/platform/e1031.smc/SFP/sfp_modabs" PLATFORM_ROOT_PATH = '/usr/share/sonic/device' PMON_HWSKU_PATH = '/usr/share/sonic/hwsku' diff --git a/device/celestica/x86_64-cel_midstone-r0/plugins/sfputil.py b/device/celestica/x86_64-cel_midstone-r0/plugins/sfputil.py index 4d2a444c198b..8b3b06ff00ef 100755 --- a/device/celestica/x86_64-cel_midstone-r0/plugins/sfputil.py +++ b/device/celestica/x86_64-cel_midstone-r0/plugins/sfputil.py @@ -32,7 +32,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.QSFP_PORT_END+1) + return list(range(self.QSFP_PORT_START, self.QSFP_PORT_END+1)) @property def port_to_eeprom_mapping(self): @@ -59,7 +59,7 @@ def get_presence(self, port_num): try: reg_file = open("/sys/devices/platform/ms200i_cpld/qsfp_modprs") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -90,7 +90,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/devices/platform/ms200i_cpld/qsfp_lpmode") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) content = reg_file.readline().rstrip() @@ -120,7 +120,7 @@ def set_low_power_mode(self, port_num, lpmode): try: reg_file = open("/sys/devices/platform/ms200i_cpld/qsfp_lpmode", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -162,7 +162,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -194,7 +194,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_value | mask diff --git a/device/celestica/x86_64-cel_seastone-r0/plugins/sfputil.py b/device/celestica/x86_64-cel_seastone-r0/plugins/sfputil.py index c361659b0f17..a7f4215652cb 100644 --- a/device/celestica/x86_64-cel_seastone-r0/plugins/sfputil.py +++ b/device/celestica/x86_64-cel_seastone-r0/plugins/sfputil.py @@ -29,7 +29,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(self.PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -54,7 +54,7 @@ def get_presence(self, port_num): try: reg_file = open("/sys/devices/platform/dx010_cpld/qsfp_modprs", "r") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -85,7 +85,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/devices/platform/dx010_cpld/qsfp_lpmode", "r") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -116,7 +116,7 @@ def set_low_power_mode(self, port_num, lpmode): try: reg_file = open("/sys/devices/platform/dx010_cpld/qsfp_lpmode", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -156,7 +156,7 @@ def reset(self, port_num): try: reg_file = open("/sys/devices/platform/dx010_cpld/qsfp_reset", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -190,7 +190,7 @@ def reset(self, port_num): try: reg_file = open("/sys/devices/platform/dx010_cpld/qsfp_reset", "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_value | mask diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/__init__.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/__init__.py index 7b86fa12b515..db1748e44d2c 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/__init__.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/__init__.py @@ -1,2 +1,2 @@ -import chassis -import platform +from . import chassis +from . import platform diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/chassis.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/chassis.py index 4bd9d0851b5a..92ebc3ccdd13 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/chassis.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/chassis.py @@ -11,7 +11,7 @@ try: import sys from sonic_platform_base.chassis_base import ChassisBase - from helper import APIHelper + from .helper import APIHelper except ImportError as e: raise ImportError(str(e) + "- required module not found") diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/component.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/component.py index e51cd639a2ef..c04b1a4166b0 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/component.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/component.py @@ -14,7 +14,7 @@ try: from sonic_platform_base.component_base import ComponentBase - from helper import APIHelper + from .helper import APIHelper except ImportError as e: raise ImportError(str(e) + "- required module not found") diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/fan.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/fan.py index c38b57f83cd9..8fe630423880 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/fan.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/fan.py @@ -14,7 +14,7 @@ try: from sonic_platform_base.fan_base import FanBase - from helper import APIHelper + from .helper import APIHelper except ImportError as e: raise ImportError(str(e) + "- required module not found") diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/psu.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/psu.py index d34c130dd4be..72a881b2ac33 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/psu.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/psu.py @@ -14,7 +14,7 @@ try: from sonic_platform_base.psu_base import PsuBase from sonic_platform.fan import Fan - from helper import APIHelper + from .helper import APIHelper except ImportError as e: raise ImportError(str(e) + "- required module not found") @@ -94,7 +94,7 @@ def get_voltage(self): if vout_label_path: dir_name = os.path.dirname(vout_label_path) basename = os.path.basename(vout_label_path) - in_num = filter(str.isdigit, basename) + in_num = list(filter(str.isdigit, basename)) vout_path = os.path.join( dir_name, voltage_name.format(in_num)) vout_val = self._api_helper.read_txt_file(vout_path) @@ -117,7 +117,7 @@ def get_current(self): if curr_label_path: dir_name = os.path.dirname(curr_label_path) basename = os.path.basename(curr_label_path) - cur_num = filter(str.isdigit, basename) + cur_num = list(filter(str.isdigit, basename)) cur_path = os.path.join( dir_name, current_name.format(cur_num)) cur_val = self._api_helper.read_txt_file(cur_path) @@ -140,7 +140,7 @@ def get_power(self): if pw_label_path: dir_name = os.path.dirname(pw_label_path) basename = os.path.basename(pw_label_path) - pw_num = filter(str.isdigit, basename) + pw_num = list(filter(str.isdigit, basename)) pw_path = os.path.join( dir_name, current_name.format(pw_num)) pw_val = self._api_helper.read_txt_file(pw_path) diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/sfp.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/sfp.py index 3e84bd7c41c2..57ad04378b90 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/sfp.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/sfp.py @@ -20,7 +20,7 @@ from sonic_platform_base.sonic_sfp.sff8436 import sff8436Dom from sonic_platform_base.sonic_sfp.inf8628 import inf8628InterfaceId from sonic_platform_base.sonic_sfp.sfputilhelper import SfpUtilHelper - from helper import APIHelper + from .helper import APIHelper except ImportError as e: raise ImportError(str(e) + "- required module not found") diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/thermal.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/thermal.py index 18c2bd30c03e..7737d79cfe3e 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/thermal.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/thermal.py @@ -14,7 +14,7 @@ try: from sonic_platform_base.thermal_base import ThermalBase - from helper import APIHelper + from .helper import APIHelper except ImportError as e: raise ImportError(str(e) + "- required module not found") diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/watchdog.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/watchdog.py index e410a940ee7e..c055f0047eed 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/watchdog.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/watchdog.py @@ -13,7 +13,7 @@ try: from sonic_platform_base.watchdog_base import WatchdogBase - from helper import APIHelper + from .helper import APIHelper except ImportError as e: raise ImportError(str(e) + "- required module not found") diff --git a/device/celestica/x86_64-cel_seastone_2-r0/plugins/sfputil.py b/device/celestica/x86_64-cel_seastone_2-r0/plugins/sfputil.py index db3ca9976e32..b2541d42f53d 100755 --- a/device/celestica/x86_64-cel_seastone_2-r0/plugins/sfputil.py +++ b/device/celestica/x86_64-cel_seastone_2-r0/plugins/sfputil.py @@ -35,7 +35,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.QSFP_PORT_END + 1) + return list(range(self.QSFP_PORT_START, self.QSFP_PORT_END + 1)) @property def port_to_eeprom_mapping(self): @@ -73,7 +73,7 @@ def __init__(self): def get_presence(self, port_num): # Check for invalid port_num - if port_num not in range(self.port_start, self.port_end + 1): + if port_num not in list(range(self.port_start, self.port_end + 1)): return False # Get path for access port presence status @@ -87,7 +87,7 @@ def get_presence(self, port_num): content = reg_file.readline().rstrip() reg_value = int(content) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # Module present is active low @@ -106,7 +106,7 @@ def get_low_power_mode(self, port_num): reg_file = open( "/".join([self.PORT_INFO_PATH, port_name, "qsfp_lpmode"]), "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # Read status @@ -128,7 +128,7 @@ def set_low_power_mode(self, port_num, lpmode): reg_file = open( "/".join([self.PORT_INFO_PATH, port_name, "qsfp_lpmode"]), "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = hex(lpmode) @@ -149,7 +149,7 @@ def reset(self, port_num): reg_file = open( "/".join([self.PORT_INFO_PATH, port_name, "qsfp_reset"]), "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # Convert our register value back to a hex string and write back @@ -165,7 +165,7 @@ def reset(self, port_num): reg_file = open( "/".join([self.PORT_INFO_PATH, port_name, "qsfp_reset"]), "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_file.seek(0) diff --git a/device/celestica/x86_64-cel_silverstone-r0/plugins/sfputil.py b/device/celestica/x86_64-cel_silverstone-r0/plugins/sfputil.py index 33b761b9397a..d6a3df3c08bd 100755 --- a/device/celestica/x86_64-cel_silverstone-r0/plugins/sfputil.py +++ b/device/celestica/x86_64-cel_silverstone-r0/plugins/sfputil.py @@ -41,7 +41,7 @@ def qsfp_ports(self): @property def osfp_ports(self): - return range(self.OSFP_PORT_START, self.OSFP_PORT_END + 1) + return list(range(self.OSFP_PORT_START, self.OSFP_PORT_END + 1)) @property def port_to_eeprom_mapping(self): @@ -78,7 +78,7 @@ def __init__(self): def get_presence(self, port_num): # Check for invalid port_num - if port_num not in range(self.port_start, self.port_end + 1): + if port_num not in list(range(self.port_start, self.port_end + 1)): return False # Get path for access port presence status @@ -92,7 +92,7 @@ def get_presence(self, port_num): content = reg_file.readline().rstrip() reg_value = int(content) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # Module present is active low @@ -111,7 +111,7 @@ def get_low_power_mode(self, port_num): reg_file = open("/".join([self.PORT_INFO_PATH, port_name, "qsfp_lpmode"])) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # Read status @@ -133,7 +133,7 @@ def set_low_power_mode(self, port_num, lpmode): reg_file = open("/".join([self.PORT_INFO_PATH, port_name, "qsfp_lpmode"]), "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = hex(lpmode) @@ -154,7 +154,7 @@ def reset(self, port_num): reg_file = open("/".join([self.PORT_INFO_PATH, port_name, "qsfp_reset"]), "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # Convert our register value back to a hex string and write back @@ -170,7 +170,7 @@ def reset(self, port_num): reg_file = open( "/".join([self.PORT_INFO_PATH, port_name, "qsfp_reset"]), "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_file.seek(0) diff --git a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/chassis.py b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/chassis.py index 21a3ff2a9173..816ca48c8e99 100644 --- a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/chassis.py +++ b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/chassis.py @@ -22,7 +22,7 @@ from sonic_platform.sfp import Sfp from sonic_platform.psu import Psu from sonic_platform.thermal import Thermal - from helper import APIHelper + from .helper import APIHelper except ImportError as e: raise ImportError(str(e) + "- required module not found") diff --git a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/component.py b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/component.py index 737908b5b50e..7220bebbd808 100644 --- a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/component.py +++ b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/component.py @@ -13,7 +13,7 @@ try: from sonic_platform_base.component_base import ComponentBase - from helper import APIHelper + from .helper import APIHelper except ImportError as e: raise ImportError(str(e) + "- required module not found") diff --git a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/fan.py b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/fan.py index d1b36effc1ac..d9822a0137a0 100644 --- a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/fan.py +++ b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/fan.py @@ -14,7 +14,7 @@ try: from sonic_platform_base.fan_base import FanBase - from helper import APIHelper + from .helper import APIHelper except ImportError as e: raise ImportError(str(e) + "- required module not found") diff --git a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/psu.py b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/psu.py index c5d2270d2657..9ec2cdcb8c93 100644 --- a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/psu.py +++ b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/psu.py @@ -15,7 +15,7 @@ try: from sonic_platform_base.psu_base import PsuBase - from helper import APIHelper + from .helper import APIHelper from sonic_platform.fan import Fan except ImportError as e: raise ImportError(str(e) + "- required module not found") diff --git a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/thermal.py b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/thermal.py index e3138e6bb897..089d5d88effc 100644 --- a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/thermal.py +++ b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/thermal.py @@ -14,7 +14,7 @@ try: from sonic_platform_base.thermal_base import ThermalBase - from helper import APIHelper + from .helper import APIHelper except ImportError as e: raise ImportError(str(e) + "- required module not found") @@ -48,19 +48,19 @@ def __init__(self, thermal_index): self.sensor_des = self.THERMAL_LIST[self.index][1] self.sensor_reading_addr = self.THERMAL_LIST[self.index][2] def __set_threshold(self, key, value): - print(key, value) + print('{} {}'.format(key, value)) def get_temperature(self): """ Retrieves current temperature reading from thermal Returns: A float number of current temperature in Celsius up to nearest thousandth - of one degree Celsius, e.g. 30.125 + of one degree Celsius, e.g. 30.125 """ temperature = 0.0 status, raw_ss_read = self._api_helper.ipmi_raw( IPMI_SENSOR_NETFN, IPMI_SS_READ_CMD.format(self.sensor_reading_addr)) - if status and len(raw_ss_read.split()) > 0: + if status and len(raw_ss_read.split()) > 0: ss_read = raw_ss_read.split()[0] temperature = float(int(ss_read, 16)) return temperature @@ -75,7 +75,7 @@ def get_high_threshold(self): high_threshold = 0.0 status, raw_up_thres_read = self._api_helper.ipmi_raw( IPMI_SENSOR_NETFN, IPMI_SS_THRESHOLD_CMD.format(self.sensor_reading_addr)) - if status and len(raw_up_thres_read.split()) > 6: + if status and len(raw_up_thres_read.split()) > 6: ss_read = raw_up_thres_read.split()[4] high_threshold = float(int(ss_read, 16)) return high_threshold @@ -92,8 +92,8 @@ def get_low_threshold(self): def set_high_threshold(self, temperature): """ Sets the high threshold temperature of thermal - Args : - temperature: A float number up to nearest thousandth of one degree Celsius, + Args : + temperature: A float number up to nearest thousandth of one degree Celsius, e.g. 30.125 Returns: A boolean, True if threshold is set successfully, False if not @@ -104,7 +104,7 @@ def set_high_threshold(self, temperature): def set_low_threshold(self, temperature): """ Sets the low threshold temperature of thermal - Args : + Args : temperature: A float number up to nearest thousandth of one degree Celsius, e.g. 30.125 Returns: @@ -150,4 +150,4 @@ def get_status(self): Returns: A boolean value, True if device is operating properly, False if not """ - return self.get_presence() \ No newline at end of file + return self.get_presence() diff --git a/device/centec/arm64-centec_e530_24x2c-r0/plugins/led_control.py b/device/centec/arm64-centec_e530_24x2c-r0/plugins/led_control.py index e8ba30134c2f..936c7e18cafb 100644 --- a/device/centec/arm64-centec_e530_24x2c-r0/plugins/led_control.py +++ b/device/centec/arm64-centec_e530_24x2c-r0/plugins/led_control.py @@ -10,7 +10,7 @@ import syslog from socket import * from select import * -except ImportError, e: +except ImportError as e: raise ImportError(str(e) + " - required module not found") diff --git a/device/centec/arm64-centec_e530_24x2c-r0/plugins/sfputil.py b/device/centec/arm64-centec_e530_24x2c-r0/plugins/sfputil.py index 8404fcfcf180..0d6ef42e9add 100644 --- a/device/centec/arm64-centec_e530_24x2c-r0/plugins/sfputil.py +++ b/device/centec/arm64-centec_e530_24x2c-r0/plugins/sfputil.py @@ -15,7 +15,7 @@ def DBG_PRINT(str): - print str + "\n" + print(str + "\n") SFP_STATUS_INSERTED = '1' SFP_STATUS_REMOVED = '0' @@ -37,7 +37,7 @@ def sfp_base(self): @property def qsfp_ports(self): - return range(25, self.PORTS_IN_BLOCK + 1) + return list(range(25, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): diff --git a/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/led_control.py b/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/led_control.py index edbdb8a02df2..65cb38ab8dc4 100644 --- a/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/led_control.py +++ b/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/led_control.py @@ -10,7 +10,7 @@ import syslog from socket import * from select import * -except ImportError, e: +except ImportError as e: raise ImportError(str(e) + " - required module not found") diff --git a/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/sfputil.py b/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/sfputil.py index 3426dcf12be1..7c5225e402fd 100644 --- a/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/sfputil.py +++ b/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/sfputil.py @@ -15,7 +15,7 @@ def DBG_PRINT(str): - print str + "\n" + print(str + "\n") class SfpUtil(SfpUtilBase): diff --git a/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/led_control.py b/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/led_control.py index 4459096cb011..ce9aa1709438 100644 --- a/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/led_control.py +++ b/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/led_control.py @@ -16,7 +16,7 @@ import syslog from socket import * from select import * -except ImportError, e: +except ImportError as e: raise ImportError(str(e) + " - required module not found") diff --git a/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/sfputil.py b/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/sfputil.py index 4d4b3f3e5558..e4123b13098d 100644 --- a/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/sfputil.py +++ b/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/sfputil.py @@ -20,7 +20,7 @@ def DBG_PRINT(str): - print str + "\n" + print(str + "\n") class SfpUtil(SfpUtilBase): @@ -40,7 +40,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(49, self.PORTS_IN_BLOCK + 1) + return list(range(49, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -107,7 +107,7 @@ def __init__(self): try: if not os.path.exists("/var/cache/sonic/sfp"): - os.makedirs("/var/cache/sonic/sfp", 0777) + os.makedirs("/var/cache/sonic/sfp", 0o777) for x in range(1, self.port_end + 1): if not self.get_presence(x): if os.path.exists(self.eeprom_mapping[x]): diff --git a/device/centec/x86_64-centec_e582_48x6q-r0/plugins/led_control.py b/device/centec/x86_64-centec_e582_48x6q-r0/plugins/led_control.py index d25bf6f8b473..5bc52a444916 100644 --- a/device/centec/x86_64-centec_e582_48x6q-r0/plugins/led_control.py +++ b/device/centec/x86_64-centec_e582_48x6q-r0/plugins/led_control.py @@ -16,7 +16,7 @@ import syslog from socket import * from select import * -except ImportError, e: +except ImportError as e: raise ImportError(str(e) + " - required module not found") diff --git a/device/centec/x86_64-centec_e582_48x6q-r0/plugins/sfputil.py b/device/centec/x86_64-centec_e582_48x6q-r0/plugins/sfputil.py index 8d1281492d6c..1926a028beec 100644 --- a/device/centec/x86_64-centec_e582_48x6q-r0/plugins/sfputil.py +++ b/device/centec/x86_64-centec_e582_48x6q-r0/plugins/sfputil.py @@ -20,7 +20,7 @@ def DBG_PRINT(str): - print str + "\n" + print(str + "\n") class SfpUtil(SfpUtilBase): @@ -40,7 +40,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(49, self.PORTS_IN_BLOCK + 1) + return list(range(49, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -107,7 +107,7 @@ def __init__(self): try: if not os.path.exists("/var/cache/sonic/sfp"): - os.makedirs("/var/cache/sonic/sfp", 0777) + os.makedirs("/var/cache/sonic/sfp", 0o777) for x in range(1, self.port_end + 1): if not self.get_presence(x): if os.path.exists(self.eeprom_mapping[x]): diff --git a/device/centec/x86_64-ew_es6220_x48q2h4-r0/plugins/sfputil.py b/device/centec/x86_64-ew_es6220_x48q2h4-r0/plugins/sfputil.py index 5ac85e067618..ab476ae648b3 100644 --- a/device/centec/x86_64-ew_es6220_x48q2h4-r0/plugins/sfputil.py +++ b/device/centec/x86_64-ew_es6220_x48q2h4-r0/plugins/sfputil.py @@ -32,7 +32,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(0, self.PORTS_IN_BLOCK + 1) + return list(range(0, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -50,27 +50,27 @@ def get_presence(self, port_name): #modify by zhw to get sfp presence # Check for invalid port_num port_num = int(port_name[8:]) - + if port_num < (self.port_start+1) or port_num > (self.port_end+1): return False - + #cpld info from "CPLD Register for es5800A2.2(V1.1)" - cpld_map = {0: '0x82', 1: '0x83', 2: '0x84', 3: '0x85', 4: '0x86', 5: '0x87', 6: '0x8E'} + cpld_map = {0: '0x82', 1: '0x83', 2: '0x84', 3: '0x85', 4: '0x86', 5: '0x87', 6: '0x8E'} cpld_key = (port_num - 1)/8 cpld_mask = (1 << (port_num - 1)%8) - + #use i2cget cmd to get cpld data output = os.popen('i2cdetect -l | grep CP') bus_num = output.read()[4] cmd = "i2cget -y "+bus_num+" 0x5 "+cpld_map[cpld_key] - tmp = os.popen(cmd).read().replace("\n", "") - cpld_value = int(tmp, 16) + tmp = os.popen(cmd).read().replace("\n", "") + cpld_value = int(tmp, 16) if cpld_value & cpld_mask == 0: return True else: return False - + def get_low_power_mode(self, port_num): ''' # Check for invalid port_num @@ -104,7 +104,7 @@ def set_low_power_mode(self, port_num, lpmode): try: reg_file = open("/sys/devices/platform/dell-s6000-cpld.0/qsfp_lpmode", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -140,7 +140,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -166,7 +166,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_value | mask diff --git a/device/cig/x86_64-cig_cs5435_54p-r0/plugins/sfputil.py b/device/cig/x86_64-cig_cs5435_54p-r0/plugins/sfputil.py index 2863b80c9950..bc5b945b44f0 100755 --- a/device/cig/x86_64-cig_cs5435_54p-r0/plugins/sfputil.py +++ b/device/cig/x86_64-cig_cs5435_54p-r0/plugins/sfputil.py @@ -3,7 +3,7 @@ try: import time from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") @@ -75,7 +75,7 @@ class SfpUtil(SfpUtilBase): 54 : 63, } - _qsfp_ports = range(_qsfp_port_start, _ports_in_block + 1) + _qsfp_ports = list(range(_qsfp_port_start, _ports_in_block + 1)) def get_presence(self, port_num): # Check for invalid port_num @@ -89,7 +89,7 @@ def get_presence(self, port_num): try: reg_file = open(port_ps) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False try: @@ -100,7 +100,7 @@ def get_presence(self, port_num): try: reg_value = reg_file.readline().rstrip() except IOError as e: - print "Error:try again to read file failed: %s %s" % (str(e), port_ps) + print("Error:try again to read file failed: %s %s" % (str(e), port_ps)) reg_file.close() return False @@ -139,7 +139,7 @@ def reset(self, port_num): try: reg_file = open(port_ps, 'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False #toggle reset @@ -166,7 +166,7 @@ def set_low_power_mode(self, port_num, lpmode): try: reg_file = open(port_ps,'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_file.seek(0) @@ -196,13 +196,13 @@ def get_low_power_mode(self, port_num): try: reg_file = open(port_ps) except IOError as e: - print "Error: unable to open file:%s %s" % (str(e), port_ps) + print("Error: unable to open file:%s %s" % (str(e), port_ps)) return False try: reg_value = reg_file.readline().rstrip() except IOError as e: - print "Error: unable to open file:%s %s" % (str(e), port_ps) + print("Error: unable to open file:%s %s" % (str(e), port_ps)) reg_file.close() return False diff --git a/device/cig/x86_64-cig_cs6436_54p-r0/plugins/sfputil.py b/device/cig/x86_64-cig_cs6436_54p-r0/plugins/sfputil.py index 2863b80c9950..bc5b945b44f0 100755 --- a/device/cig/x86_64-cig_cs6436_54p-r0/plugins/sfputil.py +++ b/device/cig/x86_64-cig_cs6436_54p-r0/plugins/sfputil.py @@ -3,7 +3,7 @@ try: import time from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") @@ -75,7 +75,7 @@ class SfpUtil(SfpUtilBase): 54 : 63, } - _qsfp_ports = range(_qsfp_port_start, _ports_in_block + 1) + _qsfp_ports = list(range(_qsfp_port_start, _ports_in_block + 1)) def get_presence(self, port_num): # Check for invalid port_num @@ -89,7 +89,7 @@ def get_presence(self, port_num): try: reg_file = open(port_ps) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False try: @@ -100,7 +100,7 @@ def get_presence(self, port_num): try: reg_value = reg_file.readline().rstrip() except IOError as e: - print "Error:try again to read file failed: %s %s" % (str(e), port_ps) + print("Error:try again to read file failed: %s %s" % (str(e), port_ps)) reg_file.close() return False @@ -139,7 +139,7 @@ def reset(self, port_num): try: reg_file = open(port_ps, 'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False #toggle reset @@ -166,7 +166,7 @@ def set_low_power_mode(self, port_num, lpmode): try: reg_file = open(port_ps,'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_file.seek(0) @@ -196,13 +196,13 @@ def get_low_power_mode(self, port_num): try: reg_file = open(port_ps) except IOError as e: - print "Error: unable to open file:%s %s" % (str(e), port_ps) + print("Error: unable to open file:%s %s" % (str(e), port_ps)) return False try: reg_value = reg_file.readline().rstrip() except IOError as e: - print "Error: unable to open file:%s %s" % (str(e), port_ps) + print("Error: unable to open file:%s %s" % (str(e), port_ps)) reg_file.close() return False diff --git a/device/cig/x86_64-cig_cs6436_56p-r0/plugins/sfputil.py b/device/cig/x86_64-cig_cs6436_56p-r0/plugins/sfputil.py index 1e15c0e886f7..fbc9bbe02002 100755 --- a/device/cig/x86_64-cig_cs6436_56p-r0/plugins/sfputil.py +++ b/device/cig/x86_64-cig_cs6436_56p-r0/plugins/sfputil.py @@ -3,7 +3,7 @@ try: import time from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") @@ -17,7 +17,7 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _global_port_pres_dict = {} - + _port_to_i2c_mapping = { 1 : 8, 2 : 9, @@ -74,11 +74,11 @@ class SfpUtil(SfpUtilBase): 53 : 60, 54 : 61, 55 : 62, - 56 : 63, + 56 : 63, } - _qsfp_ports = range(_qsfp_port_start, _ports_in_block + 1) - + _qsfp_ports = list(range(_qsfp_port_start, _ports_in_block + 1)) + def get_presence(self, port_num): # Check for invalid port_num if port_num < self._port_start or port_num > self._port_end: @@ -87,29 +87,29 @@ def get_presence(self, port_num): path = "/sys/bus/i2c/devices/{0}-0050/sfp_is_present" port_ps = path.format(self._port_to_i2c_mapping[port_num]) - + try: reg_file = open(port_ps) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False try: reg_value = reg_file.readline().rstrip() except IOError as e: time.sleep(1) - + try: reg_value = reg_file.readline().rstrip() except IOError as e: - print "Error:try again to read file failed: %s %s" % (str(e), port_ps) + print("Error:try again to read file failed: %s %s" % (str(e), port_ps)) reg_file.close() return False reg_file.close() if reg_value == '1': return True - + reg_file.close() if reg_value == '1': return True @@ -120,13 +120,13 @@ def init_global_port_presence(self): for port_num in range(self.port_start, (self.port_end + 1)): self._global_port_pres_dict[port_num] = '0' - + def __init__(self): eeprom_path = '/sys/bus/i2c/devices/{0}-0050/sfp_eeprom' for x in range(self._port_start, self._port_end + 1): port_eeprom_path = eeprom_path.format(self._port_to_i2c_mapping[x]) self._port_to_eeprom_mapping[x] = port_eeprom_path - + self.init_global_port_presence() SfpUtilBase.__init__(self) @@ -137,11 +137,11 @@ def reset(self, port_num): path = "/sys/bus/i2c/devices/{0}-0050/sfp_port_reset" port_ps = path.format(self._port_to_i2c_mapping[port_num]) - + try: reg_file = open(port_ps, 'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False #toggle reset @@ -152,23 +152,23 @@ def reset(self, port_num): reg_file.write('0') reg_file.close() return True - + def set_low_power_mode(self, port_num, lpmode): # Check for invalid port_num if port_num < self._qsfp_port_start or port_num > self._port_end: return False - pre_value = self.get_presence(port_num) + pre_value = self.get_presence(port_num) if pre_value == False: return False - + path = "/sys/bus/i2c/devices/{0}-0050/sfp_lpmode" port_ps = path.format(self._port_to_i2c_mapping[port_num]) - + try: reg_file = open(port_ps,'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_file.seek(0) @@ -187,34 +187,34 @@ def get_low_power_mode(self, port_num): if port_num < self._qsfp_port_start or port_num > self._port_end: return False - - pre_value = self.get_presence(port_num) + + pre_value = self.get_presence(port_num) if pre_value == False: return False - + path = "/sys/bus/i2c/devices/{0}-0050/sfp_lpmode" port_ps = path.format(self._port_to_i2c_mapping[port_num]) - + try: reg_file = open(port_ps) except IOError as e: - print "Error: unable to open file:%s %s" % (str(e), port_ps) + print("Error: unable to open file:%s %s" % (str(e), port_ps)) return False try: reg_value = reg_file.readline().rstrip() except IOError as e: - print "Error: unable to open file:%s %s" % (str(e), port_ps) - reg_file.close() + print("Error: unable to open file:%s %s" % (str(e), port_ps)) + reg_file.close() return False - + reg_file.close() if reg_value == '1': return True return False - + def get_transceiver_change_event(self): port_dict = {} while True: @@ -247,6 +247,6 @@ def port_end(self): def qsfp_ports(self): return self._qsfp_ports - @property + @property def port_to_eeprom_mapping(self): return self._port_to_eeprom_mapping diff --git a/device/common/pddf/plugins/fanutil.py b/device/common/pddf/plugins/fanutil.py index 2701fa5f2326..ce2d8118c1d3 100755 --- a/device/common/pddf/plugins/fanutil.py +++ b/device/common/pddf/plugins/fanutil.py @@ -1,7 +1,7 @@ #!/usr/bin/env python -# Sample pddf_fanutil file +# Sample pddf_fanutil file # All the supported FAN SysFS aattributes are #- fan_present #- fan_direction @@ -44,7 +44,7 @@ def get_num_fans(self): def get_presence(self, idx): # 1 based fan index if idx<1 or idx>self.num_fans: - print "Invalid fan index %d\n"%idx + print("Invalid fan index %d\n"%idx) return False attr_name = "fan"+ str(idx) +"_present" @@ -67,7 +67,7 @@ def get_presence(self, idx): def get_status(self, idx): # 1 based fan index if idx<1 or idx>self.num_fans: - print "Invalid fan index %d\n"%idx + print("Invalid fan index %d\n"%idx) return False speed = self.get_speed(idx) @@ -77,7 +77,7 @@ def get_status(self, idx): def get_direction(self, idx): # 1 based fan index if idx<1 or idx>self.num_fans: - print "Invalid fan index %d\n"%idx + print("Invalid fan index %d\n"%idx) return None attr = "fan" + str(idx) + "_direction" @@ -116,14 +116,14 @@ def get_directions(self): direction = vmap[str(val)] - print "FAN-%d direction is %s"%(i, direction) + print("FAN-%d direction is %s"%(i, direction)) return 0 def get_speed(self, idx): # 1 based fan index if idx<1 or idx>self.num_fans: - print "Invalid fan index %d\n"%idx + print("Invalid fan index %d\n"%idx) return 0 attr = "fan" + str(idx) + "_input" @@ -165,17 +165,17 @@ def get_speeds(self): def set_speed(self, val): if val<0 or val>100: - print "Error: Invalid speed %d. Please provide a valid speed percentage"%val + print("Error: Invalid speed %d. Please provide a valid speed percentage"%val) return False - + num_fan = self.num_fans if 'duty_cycle_to_pwm' not in 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(plugin_data['FAN']['duty_cycle_to_pwm']) pwm = duty_cycle_to_pwm(val) - print "New Speed: %d%% - PWM value to be set is %d\n"%(val,pwm) + print("New Speed: %d%% - PWM value to be set is %d\n"%(val,pwm)) for i in range(1, num_fan+1): attr = "fan" + str(i) + "_pwm" diff --git a/device/common/pddf/plugins/ledutil.py b/device/common/pddf/plugins/ledutil.py index adbfe9cc62e1..dc0a4c9b8683 100755 --- a/device/common/pddf/plugins/ledutil.py +++ b/device/common/pddf/plugins/ledutil.py @@ -18,11 +18,11 @@ def __init__(self): self.cur_state_path="pddf/devices/led/cur_state" def set_status_led(self, led_device_name, color, color_state="SOLID"): - if (not led_device_name in pddf_obj.data.keys()): + if (not led_device_name in list(pddf_obj.data.keys())): status="ERROR: " + led_device_name + " is not configured" return (status) - if (not color in self.color_map.keys()): + if (not color in list(self.color_map.keys())): status="ERROR: Invalid color" return (status) @@ -35,7 +35,7 @@ def set_status_led(self, led_device_name, color, color_state="SOLID"): return ("Executed") def get_status_led(self, led_device_name): - if (not led_device_name in pddf_obj.data.keys()): + if (not led_device_name in list(pddf_obj.data.keys())): status="ERROR: " + led_device_name + " is not configured" return (status) @@ -43,8 +43,8 @@ def get_status_led(self, led_device_name): pddf_obj.create_attr('device_name', led_device_name, self.path) pddf_obj.create_attr('index', index, self.path) pddf_obj.create_attr('dev_ops', 'get_status', self.path) - color_f="/sys/kernel/" + self.cur_state_path +"/color" - color_state_f="/sys/kernel/" + self.cur_state_path +"/color_state" + color_f="/sys/kernel/" + self.cur_state_path +"/color" + color_state_f="/sys/kernel/" + self.cur_state_path +"/color_state" try: with open(color_f, 'r') as f: @@ -53,6 +53,6 @@ def get_status_led(self, led_device_name): color_state = f.read().strip("\r\n") except IOError: status="ERROR :" + color_f + " open failed" - return (status) + return (status) status = "%s-%s:\t%s %s\n"%(led_device_name, index, color, color_state) return (status) diff --git a/device/common/pddf/plugins/psuutil.py b/device/common/pddf/plugins/psuutil.py index 01cf4b126ee1..2a88263479e3 100755 --- a/device/common/pddf/plugins/psuutil.py +++ b/device/common/pddf/plugins/psuutil.py @@ -1,8 +1,8 @@ #!/usr/bin/env python # -# Sample pddf_psuutil file +# Sample pddf_psuutil file # -# All the supported PSU SysFS aattributes are +# All the supported PSU SysFS aattributes are #- psu_present #- psu_model_name #- psu_power_good @@ -88,7 +88,7 @@ def get_powergood_status(self, idx): return False if idx<1 or idx>self.platform['num_psus']: - print "Invalid index %d\n"%idx + print("Invalid index %d\n"%idx) return False device = "PSU"+"%d"%(idx) @@ -111,7 +111,7 @@ def get_model(self, idx): return None if idx<1 or idx>self.platform['num_psus']: - print "Invalid index %d\n"%idx + print("Invalid index %d\n"%idx) return None device = "PSU"+"%d"%(idx) @@ -132,7 +132,7 @@ def get_mfr_id(self, idx): return None if idx<1 or idx>self.platform['num_psus']: - print "Invalid index %d\n"%idx + print("Invalid index %d\n"%idx) return None device = "PSU"+"%d"%(idx) @@ -149,7 +149,7 @@ def get_serial(self, idx): return None if idx<1 or idx>self.platform['num_psus']: - print "Invalid index %d\n"%idx + print("Invalid index %d\n"%idx) return None device = "PSU"+"%d"%(idx) @@ -166,7 +166,7 @@ def get_direction(self, idx): return None if idx<1 or idx>self.platform['num_psus']: - print "Invalid index %d\n"%idx + print("Invalid index %d\n"%idx) return None device = "PSU"+"%d"%(idx) @@ -190,7 +190,7 @@ def get_output_voltage(self, idx): return 0.0 if idx<1 or idx>self.platform['num_psus']: - print "Invalid index %d\n"%idx + print("Invalid index %d\n"%idx) return 0.0 device = "PSU"+"%d"%(idx) @@ -208,7 +208,7 @@ def get_output_current(self, idx): return 0.0 if idx<1 or idx>self.platform['num_psus']: - print "Invalid index %d\n"%idx + print("Invalid index %d\n"%idx) return 0.0 device = "PSU"+"%d"%(idx) @@ -226,7 +226,7 @@ def get_output_power(self, idx): return 0.0 if idx<1 or idx>self.platform['num_psus']: - print "Invalid index %d\n"%idx + print("Invalid index %d\n"%idx) return 0.0 device = "PSU"+"%d"%(idx) @@ -244,7 +244,7 @@ def get_fan_rpm(self, idx, fan_idx): return 0 if idx<1 or idx>self.platform['num_psus']: - print "Invalid index %d\n"%idx + print("Invalid index %d\n"%idx) return 0 @@ -252,7 +252,7 @@ def get_fan_rpm(self, idx, fan_idx): num_fans = pddf_obj.get_num_psu_fans(device) if fan_idx<1 or fan_idx>num_fans: - print "Invalid PSU-fan index %d\n"%fan_idx + print("Invalid PSU-fan index %d\n"%fan_idx) return 0 output = pddf_obj.get_attr_name_output(device, "psu_fan"+str(fan_idx)+"_speed_rpm") @@ -265,7 +265,7 @@ def get_fan_rpm(self, idx, fan_idx): return 0 else: speed = int(output['status']) - + return speed def dump_sysfs(self): diff --git a/device/common/pddf/plugins/sfputil.py b/device/common/pddf/plugins/sfputil.py index 394aff1c42be..a15e000ca7a8 100755 --- a/device/common/pddf/plugins/sfputil.py +++ b/device/common/pddf/plugins/sfputil.py @@ -10,7 +10,7 @@ import time from ctypes import create_string_buffer from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") class SfpUtil(SfpUtilBase): @@ -113,7 +113,7 @@ def reset(self, port_num): try: reg_file = open(port_ps, 'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False try: @@ -151,7 +151,7 @@ def get_low_power_mode(self, port_num): eeprom.seek(93) lpmode = ord(eeprom.read(1)) - + if ((lpmode & 0x3) == 0x3): return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 else: @@ -159,7 +159,7 @@ def get_low_power_mode(self, port_num): # 1. "Power override" bit is 0 # 2. "Power override" bit is 1 and "Power set" bit is 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 is not None: @@ -200,13 +200,13 @@ def set_low_power_mode(self, port_num, lpmode): regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode buffer = create_string_buffer(1) buffer[0] = chr(regval) - + # Write to eeprom eeprom.seek(93) eeprom.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 is not None: diff --git a/device/common/pddf/plugins/sysstatutil.py b/device/common/pddf/plugins/sysstatutil.py index e8b3e8008652..2c5b44f78ae3 100755 --- a/device/common/pddf/plugins/sysstatutil.py +++ b/device/common/pddf/plugins/sysstatutil.py @@ -24,7 +24,7 @@ def get_board_info(self): try: with open(node, 'r') as f: status = f.read() - print "board_info : %s" %status + print("board_info : %s" %status) except IOError: return False @@ -36,7 +36,7 @@ def get_cpld_versio(self): try: with open(node, 'r') as f: status = f.read() - print "cpld1_version : %s" %status + print("cpld1_version : %s" %status) except IOError: return False @@ -48,7 +48,7 @@ def get_power_module_status(self): try: with open(node, 'r') as f: status = f.read() - print "power_module_status : %s" %status + print("power_module_status : %s" %status) except IOError: return False @@ -62,9 +62,9 @@ def get_system_reset_status(self): try: with open(node, 'r') as f: status = f.read() - print "system_reset%s : %s" %(i, status) + print("system_reset%s : %s" %(i, status)) except IOError: - print "system_reset%s not supported" %i + print("system_reset%s not supported" %i) def get_misc_status(self): @@ -76,9 +76,9 @@ def get_misc_status(self): try: with open(node, 'r') as f: status = f.read() - print "misc%s : %s" %(i, status) + print("misc%s : %s" %(i, status)) except IOError: - print "system_reset%s not supported" %i + print("system_reset%s not supported" %i) def dump_sysfs(self): diff --git a/device/common/pddf/plugins/thermalutil.py b/device/common/pddf/plugins/thermalutil.py index ebf29608a46a..3e1682f4862c 100755 --- a/device/common/pddf/plugins/thermalutil.py +++ b/device/common/pddf/plugins/thermalutil.py @@ -15,7 +15,7 @@ def __init__(self): pddf_obj = pddfparse.PddfParse() self.platform = pddf_obj.get_platform() - self.num_thermals = self.platform['num_temps'] + self.num_thermals = self.platform['num_temps'] self.info=[] def get_num_thermals(self): @@ -27,7 +27,7 @@ def get_thermal_info(self): list.sort() for dev in list: data={} - device_name = dev['dev_info']['device_name'] + device_name = dev['dev_info']['device_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)) attr_list = dev['i2c']['attr_list'] @@ -43,12 +43,12 @@ def get_thermal_info(self): attr_value = int(f.read()) except IOError: return False - data[attr_name] = attr_value/float(1000) + data[attr_name] = attr_value/float(1000) self.info.append(data) def show_thermal_temp_values(self, idx): if idx<1 or idx>self.num_thermals: - print "Invalid temperature sensor idx %d"%idx + print("Invalid temperature sensor idx %d"%idx) return None self.get_thermal_info() thermal_name = "TEMP"+"%d"%idx @@ -63,11 +63,11 @@ def show_thermal_temp_values(self, idx): return (label, value) - def show_temp_values(self): + def show_temp_values(self): self.get_thermal_info() for temp in self.info: - print temp['label'] - print "temp1\t %+.1f C (high = %+.1f C, hyst = %+.1f C)" % (temp['temp1_input'], temp['temp1_max'], temp['temp1_max_hyst']) + print(temp['label']) + print("temp1\t %+.1f C (high = %+.1f C, hyst = %+.1f C)" % (temp['temp1_input'], temp['temp1_max'], temp['temp1_max_hyst'])) def dump_sysfs(self): diff --git a/device/dell/x86_64-dell_s6000_s1220-r0/plugins/sfputil.py b/device/dell/x86_64-dell_s6000_s1220-r0/plugins/sfputil.py index b27bf4bc22ea..3f89d30ad630 100644 --- a/device/dell/x86_64-dell_s6000_s1220-r0/plugins/sfputil.py +++ b/device/dell/x86_64-dell_s6000_s1220-r0/plugins/sfputil.py @@ -33,7 +33,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(0, self.PORTS_IN_BLOCK + 1) + return list(range(0, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -46,7 +46,7 @@ def get_transceiver_status(self): reg_file = open("/sys/devices/platform/dell-s6000-cpld.0/qsfp_modprs") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -76,7 +76,7 @@ def get_presence(self, port_num): try: reg_file = open("/sys/devices/platform/dell-s6000-cpld.0/qsfp_modprs") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -101,7 +101,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/devices/platform/dell-s6000-cpld.0/qsfp_lpmode") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) content = reg_file.readline().rstrip() @@ -125,7 +125,7 @@ def set_low_power_mode(self, port_num, lpmode): try: reg_file = open("/sys/devices/platform/dell-s6000-cpld.0/qsfp_lpmode", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -161,7 +161,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -187,7 +187,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_value | mask @@ -209,13 +209,13 @@ def get_transceiver_change_event(self, timeout=0): elif timeout > 0: timeout = timeout / float(1000) # Convert to secs else: - print "get_transceiver_change_event:Invalid timeout value", timeout + print("get_transceiver_change_event:Invalid timeout value", timeout) return False, {} end_time = start_time + timeout if start_time > end_time: - print 'get_transceiver_change_event:' \ - 'time wrap / invalid timeout value', timeout + print('get_transceiver_change_event:' \ + 'time wrap / invalid timeout value', timeout) return False, {} # Time wrap or possibly incorrect timeout @@ -252,5 +252,5 @@ def get_transceiver_change_event(self, timeout=0): if timeout > 0: time.sleep(timeout) return True, {} - print "get_transceiver_change_event: Should not reach here." + print("get_transceiver_change_event: Should not reach here.") return False, {} diff --git a/device/dell/x86_64-dell_s6100_c2538-r0/plugins/psuutil.py b/device/dell/x86_64-dell_s6100_c2538-r0/plugins/psuutil.py index 2f3673801526..0d2717331111 100644 --- a/device/dell/x86_64-dell_s6100_c2538-r0/plugins/psuutil.py +++ b/device/dell/x86_64-dell_s6100_c2538-r0/plugins/psuutil.py @@ -26,7 +26,7 @@ def get_pmc_register(self, reg_name): retval = 'ERR' mb_reg_file = mailbox_dir+'/' + reg_name if (not os.path.isfile(mb_reg_file)): - logging.error(mb_reg_file, "not found !") + logging.error(mb_reg_file + " not found !") return retval try: diff --git a/device/dell/x86_64-dell_s6100_c2538-r0/plugins/sfputil.py b/device/dell/x86_64-dell_s6100_c2538-r0/plugins/sfputil.py index ff4426ba10c2..efd77416ea19 100644 --- a/device/dell/x86_64-dell_s6100_c2538-r0/plugins/sfputil.py +++ b/device/dell/x86_64-dell_s6100_c2538-r0/plugins/sfputil.py @@ -125,7 +125,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(0, self.PORTS_IN_BLOCK + 1) + return list(range(0, self.PORTS_IN_BLOCK + 1)) @property def iom1_port_start(self): @@ -271,7 +271,7 @@ def get_presence(self, port_num): reg_file = open(qsfp_path, "r") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -320,7 +320,7 @@ def get_low_power_mode(self, port_num): reg_file = open(qsfp_path, "r") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -369,7 +369,7 @@ def set_low_power_mode(self, port_num, lpmode): reg_file = open(qsfp_path, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -430,7 +430,7 @@ def reset(self, port_num): reg_file = open(qsfp_path, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -469,7 +469,7 @@ def reset(self, port_num): reg_file = open(qsfp_path, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_value | mask @@ -483,7 +483,7 @@ def get_register(self, reg_file): retval = 'ERR' if (not os.path.isfile(reg_file)): - print reg_file, 'not found !' + print(reg_file + ' not found !') return retval try: diff --git a/device/dell/x86_64-dell_z9100_c2538-r0/plugins/psuutil.py b/device/dell/x86_64-dell_z9100_c2538-r0/plugins/psuutil.py index f96fac6f46cf..e2dfd30bf6bb 100644 --- a/device/dell/x86_64-dell_z9100_c2538-r0/plugins/psuutil.py +++ b/device/dell/x86_64-dell_z9100_c2538-r0/plugins/psuutil.py @@ -26,7 +26,7 @@ def get_pmc_register(self, reg_name): retval = 'ERR' mb_reg_file = mailbox_dir+'/' + reg_name if (not os.path.isfile(mb_reg_file)): - logging.error(mb_reg_file, "not found !") + logging.error(mb_reg_file + " not found !") return retval try: diff --git a/device/dell/x86_64-dell_z9100_c2538-r0/plugins/sfputil.py b/device/dell/x86_64-dell_z9100_c2538-r0/plugins/sfputil.py index 98c01216902d..1e2aa1084dc7 100644 --- a/device/dell/x86_64-dell_z9100_c2538-r0/plugins/sfputil.py +++ b/device/dell/x86_64-dell_z9100_c2538-r0/plugins/sfputil.py @@ -78,7 +78,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(self.PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.PORT_START, self.PORTS_IN_BLOCK + 1)) @property def iom1_port_start(self): @@ -165,7 +165,7 @@ def get_presence(self, port_num): reg_file = open(qsfp_path, "r") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -197,7 +197,7 @@ def get_low_power_mode(self, port_num): reg_file = open(qsfp_path, "r") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -230,7 +230,7 @@ def set_low_power_mode(self, port_num, lpmode): except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -270,7 +270,7 @@ def reset(self, port_num): reg_file = open(qsfp_path, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -299,7 +299,7 @@ def reset(self, port_num): reg_file = open(qsfp_path, "w+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_value | mask @@ -313,7 +313,7 @@ def get_register(self, reg_file): retval = 'ERR' if (not os.path.isfile(reg_file)): - print reg_file, 'not found !' + print(reg_file + ' not found !') return retval try: diff --git a/device/dell/x86_64-dellemc_s5232f_c3538-r0/plugins/psuutil.py b/device/dell/x86_64-dellemc_s5232f_c3538-r0/plugins/psuutil.py index c3e2a6d73bd0..842b8f710143 100644 --- a/device/dell/x86_64-dellemc_s5232f_c3538-r0/plugins/psuutil.py +++ b/device/dell/x86_64-dellemc_s5232f_c3538-r0/plugins/psuutil.py @@ -6,9 +6,13 @@ import os.path import logging -import commands import sys +if sys.version_info[0] < 3: + import commands +else: + import subprocess as commands + S5232F_MAX_PSUS = 2 IPMI_PSU1_DATA = "docker exec -it pmon ipmitool raw 0x04 0x2d 0x31 | awk '{print substr($0,9,1)}'" diff --git a/device/dell/x86_64-dellemc_s5232f_c3538-r0/plugins/sfputil.py b/device/dell/x86_64-dellemc_s5232f_c3538-r0/plugins/sfputil.py index b5b1408ef9b1..8d6727bdbd10 100644 --- a/device/dell/x86_64-dellemc_s5232f_c3538-r0/plugins/sfputil.py +++ b/device/dell/x86_64-dellemc_s5232f_c3538-r0/plugins/sfputil.py @@ -49,7 +49,7 @@ class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" PORT_START = 1 - PORT_END = 34 + PORT_END = 34 PORTS_IN_BLOCK = 32 BASE_RES_PATH = "/sys/bus/pci/devices/0000:04:00.0/resource0" @@ -68,7 +68,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(self.PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -102,7 +102,7 @@ def pci_get_value(self, resource, offset): mm.close() close(fd) return val - + def init_global_port_presence(self): for port_num in range(self.port_start, (self.port_end + 1)): presence = self.get_presence(port_num) @@ -110,7 +110,7 @@ def init_global_port_presence(self): self._global_port_pres_dict[port_num] = '1' else: self._global_port_pres_dict[port_num] = '0' - + def __init__(self): eeprom_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-0050/eeprom" @@ -120,7 +120,7 @@ def __init__(self): port_num) port_num = 0 self.init_global_port_presence() - + SfpUtilBase.__init__(self) def get_presence(self, port_num): @@ -133,7 +133,7 @@ def get_presence(self, port_num): status = self.pci_get_value(self.BASE_RES_PATH, port_offset) reg_value = int(status) - + # Absence of status throws error if (reg_value == "" ): return False @@ -195,7 +195,7 @@ def set_low_power_mode(self, port_num, lpmode): # Mask off 6th bit for lpmode mask = (1 << 6) - + # LPMode is active high; set or clear the bit accordingly if lpmode is True: reg_value = reg_value | mask @@ -268,7 +268,7 @@ def get_transceiver_change_event(self, timeout=0): if elapsed_time_ms > timeout: break time.sleep(sleep_time) - + return True, port_dict @@ -391,26 +391,26 @@ def get_transceiver_dom_info_dict(self, port_num): except IOError: print("Error: reading sysfs file %s" % file_path) return None - + sfpd_obj = sff8472Dom(None,1) if sfpd_obj is None: return transceiver_dom_info_dict - dom_temperature_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_TEMPE_OFFSET), + dom_temperature_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (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 transceiver_dom_info_dict - dom_voltage_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_VOLT_OFFSET), + dom_voltage_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (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: + else: return transceiver_dom_info_dict - dom_channel_monitor_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_MODULE_THRESHOLD_OFFSET), + dom_channel_monitor_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_MODULE_THRESHOLD_OFFSET), SFP_MODULE_THRESHOLD_WIDTH) if dom_channel_monitor_raw is not None: dom_channel_monitor_data = sfpd_obj.parse_channel_monitor_params(dom_channel_monitor_raw, 0) @@ -439,7 +439,7 @@ def get_transceiver_dom_info_dict(self, port_num): transceiver_dom_info_dict['tx4power'] = 'N/A' return transceiver_dom_info_dict - + def get_transceiver_dom_threshold_info_dict(self, port_num): transceiver_dom_threshold_info_dict = {} dom_info_dict_keys = ['temphighalarm', 'temphighwarning', @@ -526,14 +526,14 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): except IOError: print("Error: reading sysfs file %s" % file_path) return None - + sfpd_obj = sff8472Dom(None,1) if sfpd_obj is None: return transceiver_dom_threshold_info_dict - - dom_module_threshold_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, + + dom_module_threshold_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_MODULE_THRESHOLD_OFFSET), SFP_MODULE_THRESHOLD_WIDTH) - + if dom_module_threshold_raw is not None: dom_module_threshold_data = sfpd_obj.parse_alarm_warning_threshold(dom_module_threshold_raw, 0) else: @@ -566,5 +566,5 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): transceiver_dom_threshold_info_dict['rxpowerlowalarm'] = dom_module_threshold_data['data']['RXPowerLowAlarm']['value'] transceiver_dom_threshold_info_dict['rxpowerhighwarning'] = dom_module_threshold_data['data']['RXPowerHighWarning']['value'] transceiver_dom_threshold_info_dict['rxpowerlowwarning'] = dom_module_threshold_data['data']['RXPowerLowWarning']['value'] - + return transceiver_dom_threshold_info_dict diff --git a/device/dell/x86_64-dellemc_s5248f_c3538-r0/plugins/psuutil.py b/device/dell/x86_64-dellemc_s5248f_c3538-r0/plugins/psuutil.py index 8004697d7c0a..746eecaaf403 100644 --- a/device/dell/x86_64-dellemc_s5248f_c3538-r0/plugins/psuutil.py +++ b/device/dell/x86_64-dellemc_s5248f_c3538-r0/plugins/psuutil.py @@ -6,9 +6,13 @@ import os.path import logging -import commands import sys +if sys.version_info[0] < 3: + import commands +else: + import subprocess as commands + S5248F_MAX_PSUS = 2 IPMI_PSU_DATA = "docker exec -it pmon ipmitool sdr list" diff --git a/device/dell/x86_64-dellemc_s5248f_c3538-r0/plugins/sfputil.py b/device/dell/x86_64-dellemc_s5248f_c3538-r0/plugins/sfputil.py index d9417fef8fbd..76824d151693 100644 --- a/device/dell/x86_64-dellemc_s5248f_c3538-r0/plugins/sfputil.py +++ b/device/dell/x86_64-dellemc_s5248f_c3538-r0/plugins/sfputil.py @@ -66,8 +66,8 @@ class SfpUtil(SfpUtilBase): 6: 7, 7: 8, 8: 9, - 9: 10, - 10: 11, + 9: 10, + 10: 11, 11: 12, 12: 13, 13: 14, @@ -106,7 +106,7 @@ class SfpUtil(SfpUtilBase): 46: 47, 47: 48, 48: 49, - # DD + QSFP28 + # DD + QSFP28 49: 50, 50: 50, 51: 51, @@ -132,7 +132,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(49, self.PORTS_IN_BLOCK + 1) + return list(range(49, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -166,7 +166,7 @@ def pci_get_value(self, resource, offset): mm.close() close(fd) return val - + def init_global_port_presence(self): for port_num in range(self.port_start, (self.port_end + 1)): presence = self.get_presence(port_num) @@ -174,7 +174,7 @@ def init_global_port_presence(self): self._global_port_pres_dict[port_num] = '1' else: self._global_port_pres_dict[port_num] = '0' - + def __init__(self): eeprom_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-0050/eeprom" @@ -194,7 +194,7 @@ def get_presence(self, port_num): status = self.pci_get_value(self.BASE_RES_PATH, port_offset) reg_value = int(status) - + # Absence of status throws error if (reg_value == "" ): return False @@ -254,7 +254,7 @@ def set_low_power_mode(self, port_num, lpmode): # Mask off 6th bit for lpmode mask = (1 << 6) - + # LPMode is active high; set or clear the bit accordingly if lpmode is True: reg_value = reg_value | mask @@ -318,7 +318,7 @@ def get_transceiver_change_event(self, timeout=0): return True, port_dict time.sleep(0.5) - + def get_transceiver_dom_info_dict(self, port_num): transceiver_dom_info_dict = {} @@ -438,27 +438,27 @@ def get_transceiver_dom_info_dict(self, port_num): except IOError: print("Error: reading sysfs file %s" % file_path) return None - + sfpd_obj = sff8472Dom(None,1) if sfpd_obj is None: return transceiver_dom_info_dict dom_temperature_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_TEMPE_OFFSET), - SFP_TEMPE_WIDTH) - + SFP_TEMPE_WIDTH) + if dom_temperature_raw is not None: dom_temperature_data = sfpd_obj.parse_temperature(dom_temperature_raw, 0) else: return transceiver_dom_info_dict - dom_voltage_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_VOLT_OFFSET), + dom_voltage_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (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: + else: return transceiver_dom_info_dict - dom_channel_monitor_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_MODULE_THRESHOLD_OFFSET), + dom_channel_monitor_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_MODULE_THRESHOLD_OFFSET), SFP_MODULE_THRESHOLD_WIDTH) if dom_channel_monitor_raw is not None: dom_channel_monitor_data = sfpd_obj.parse_channel_monitor_params(dom_channel_monitor_raw, 0) @@ -487,7 +487,7 @@ def get_transceiver_dom_info_dict(self, port_num): transceiver_dom_info_dict['tx4power'] = 'N/A' return transceiver_dom_info_dict - + def get_transceiver_dom_threshold_info_dict(self, port_num): transceiver_dom_threshold_info_dict = {} dom_info_dict_keys = ['temphighalarm', 'temphighwarning', @@ -574,14 +574,14 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): except IOError: print("Error: reading sysfs file %s" % file_path) return None - + sfpd_obj = sff8472Dom(None,1) if sfpd_obj is None: return transceiver_dom_threshold_info_dict - - dom_module_threshold_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, + + dom_module_threshold_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_MODULE_THRESHOLD_OFFSET), SFP_MODULE_THRESHOLD_WIDTH) - + if dom_module_threshold_raw is not None: dom_module_threshold_data = sfpd_obj.parse_alarm_warning_threshold(dom_module_threshold_raw, 0) else: @@ -614,5 +614,5 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): transceiver_dom_threshold_info_dict['rxpowerlowalarm'] = dom_module_threshold_data['data']['RXPowerLowAlarm']['value'] transceiver_dom_threshold_info_dict['rxpowerhighwarning'] = dom_module_threshold_data['data']['RXPowerHighWarning']['value'] transceiver_dom_threshold_info_dict['rxpowerlowwarning'] = dom_module_threshold_data['data']['RXPowerLowWarning']['value'] - + return transceiver_dom_threshold_info_dict diff --git a/device/dell/x86_64-dellemc_s5296f_c3538-r0/plugins/psuutil.py b/device/dell/x86_64-dellemc_s5296f_c3538-r0/plugins/psuutil.py index eedadc516825..e318325febf4 100644 --- a/device/dell/x86_64-dellemc_s5296f_c3538-r0/plugins/psuutil.py +++ b/device/dell/x86_64-dellemc_s5296f_c3538-r0/plugins/psuutil.py @@ -5,9 +5,13 @@ import logging -import commands import sys +if sys.version_info[0] < 3: + import commands +else: + import subprocess as commands + S5296F_MAX_PSUS = 2 IPMI_PSU_DATA = "docker exec -it pmon ipmitool sdr list" diff --git a/device/dell/x86_64-dellemc_s5296f_c3538-r0/plugins/sfputil.py b/device/dell/x86_64-dellemc_s5296f_c3538-r0/plugins/sfputil.py index a2e459478f05..85ce9551e033 100644 --- a/device/dell/x86_64-dellemc_s5296f_c3538-r0/plugins/sfputil.py +++ b/device/dell/x86_64-dellemc_s5296f_c3538-r0/plugins/sfputil.py @@ -71,7 +71,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(97, self.PORTS_IN_BLOCK + 1) + return list(range(97, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -105,7 +105,7 @@ def pci_get_value(self, resource, offset): mm.close() close(fd) return val - + def init_global_port_presence(self): for port_num in range(self.port_start, (self.port_end + 1)): presence = self.get_presence(port_num) @@ -113,7 +113,7 @@ def init_global_port_presence(self): self._global_port_pres_dict[port_num] = '1' else: self._global_port_pres_dict[port_num] = '0' - + def __init__(self): eeprom_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-0050/eeprom" @@ -132,7 +132,7 @@ def get_presence(self, port_num): status = self.pci_get_value(self.BASE_RES_PATH, port_offset) reg_value = int(status) - + # Absence of status throws error if (reg_value == "" ): return False @@ -191,7 +191,7 @@ def set_low_power_mode(self, port_num, lpmode): # Mask off 4th bit for presence mask = (1 << 6) - + # LPMode is active high; set or clear the bit accordingly if lpmode is True: reg_value = reg_value | mask @@ -264,7 +264,7 @@ def get_transceiver_change_event(self, timeout=0): if elapsed_time_ms > timeout: break time.sleep(sleep_time) - + return True, port_dict @@ -375,25 +375,25 @@ def get_transceiver_dom_info_dict(self, port_num): except IOError: print("Error: reading sysfs file %s" % file_path) return None - + sfpd_obj = sff8472Dom(None,1) if sfpd_obj is None: return None - dom_temperature_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_TEMPE_OFFSET), + dom_temperature_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (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 transceiver_dom_info_dict - dom_voltage_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_VOLT_OFFSET), + dom_voltage_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (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: + else: return transceiver_dom_info_dict - dom_channel_monitor_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_MODULE_THRESHOLD_OFFSET), + dom_channel_monitor_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_MODULE_THRESHOLD_OFFSET), SFP_MODULE_THRESHOLD_WIDTH) if dom_channel_monitor_raw is not None: dom_channel_monitor_data = sfpd_obj.parse_channel_monitor_params(dom_channel_monitor_raw, 0) @@ -422,7 +422,7 @@ def get_transceiver_dom_info_dict(self, port_num): transceiver_dom_info_dict['tx4power'] = 'N/A' return transceiver_dom_info_dict - + def get_transceiver_dom_threshold_info_dict(self, port_num): transceiver_dom_threshold_info_dict = {} dom_info_dict_keys = ['temphighalarm', 'temphighwarning', @@ -509,14 +509,14 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): except IOError: print("Error: reading sysfs file %s" % file_path) return None - + sfpd_obj = sff8472Dom(None,1) if sfpd_obj is None: return transceiver_dom_threshold_info_dict - - dom_module_threshold_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, + + dom_module_threshold_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_MODULE_THRESHOLD_OFFSET), SFP_MODULE_THRESHOLD_WIDTH) - + if dom_module_threshold_raw is not None: dom_module_threshold_data = sfpd_obj.parse_alarm_warning_threshold(dom_module_threshold_raw, 0) else: @@ -549,6 +549,6 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): transceiver_dom_threshold_info_dict['rxpowerlowalarm'] = dom_module_threshold_data['data']['RXPowerLowAlarm']['value'] transceiver_dom_threshold_info_dict['rxpowerhighwarning'] = dom_module_threshold_data['data']['RXPowerHighWarning']['value'] transceiver_dom_threshold_info_dict['rxpowerlowwarning'] = dom_module_threshold_data['data']['RXPowerLowWarning']['value'] - + return transceiver_dom_threshold_info_dict - + diff --git a/device/dell/x86_64-dellemc_z9264f_c3538-r0/plugins/psuutil.py b/device/dell/x86_64-dellemc_z9264f_c3538-r0/plugins/psuutil.py index c72a2d6675b3..58546d4028f8 100644 --- a/device/dell/x86_64-dellemc_z9264f_c3538-r0/plugins/psuutil.py +++ b/device/dell/x86_64-dellemc_z9264f_c3538-r0/plugins/psuutil.py @@ -6,9 +6,13 @@ import os.path import logging -import commands import sys +if sys.version_info[0] < 3: + import commands +else: + import subprocess as commands + Z9264F_MAX_PSUS = 2 IPMI_PSU_DATA = "docker exec -it pmon ipmitool sdr list" diff --git a/device/dell/x86_64-dellemc_z9264f_c3538-r0/plugins/sfputil.py b/device/dell/x86_64-dellemc_z9264f_c3538-r0/plugins/sfputil.py index 6aa18d85e2e7..60c2f4724308 100644 --- a/device/dell/x86_64-dellemc_z9264f_c3538-r0/plugins/sfputil.py +++ b/device/dell/x86_64-dellemc_z9264f_c3538-r0/plugins/sfputil.py @@ -77,7 +77,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(self.PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -250,7 +250,7 @@ def reset(self, port_num): def get_register(self, reg_file): retval = 'ERR' if (not path.isfile(reg_file)): - print reg_file, 'not found !' + print(reg_file + ' not found !') return retval try: @@ -337,7 +337,7 @@ def get_transceiver_change_event(self, timeout=0): self.epoll = -1 return False, {} - + def get_transceiver_dom_info_dict(self, port_num): transceiver_dom_info_dict = {} @@ -593,14 +593,14 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): except IOError: print("Error: reading sysfs file %s" % file_path) return None - + sfpd_obj = sff8472Dom(None,1) if sfpd_obj is None: return transceiver_dom_threshold_info_dict - - dom_module_threshold_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, + + dom_module_threshold_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_MODULE_THRESHOLD_OFFSET), SFP_MODULE_THRESHOLD_WIDTH) - + if dom_module_threshold_raw is not None: dom_module_threshold_data = sfpd_obj.parse_alarm_warning_threshold(dom_module_threshold_raw, 0) else: @@ -633,5 +633,5 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): transceiver_dom_threshold_info_dict['rxpowerlowalarm'] = dom_module_threshold_data['data']['RXPowerLowAlarm']['value'] transceiver_dom_threshold_info_dict['rxpowerhighwarning'] = dom_module_threshold_data['data']['RXPowerHighWarning']['value'] transceiver_dom_threshold_info_dict['rxpowerlowwarning'] = dom_module_threshold_data['data']['RXPowerLowWarning']['value'] - + return transceiver_dom_threshold_info_dict diff --git a/device/dell/x86_64-dellemc_z9332f_d1508-r0/plugins/psuutil.py b/device/dell/x86_64-dellemc_z9332f_d1508-r0/plugins/psuutil.py index b2c373de358f..d098693217d0 100644 --- a/device/dell/x86_64-dellemc_z9332f_d1508-r0/plugins/psuutil.py +++ b/device/dell/x86_64-dellemc_z9332f_d1508-r0/plugins/psuutil.py @@ -6,9 +6,13 @@ import os.path import logging -import commands import sys +if sys.version_info[0] < 3: + import commands +else: + import subprocess as commands + Z9332F_MAX_PSUS = 2 IPMI_PSU1_DATA = "docker exec -it pmon ipmitool raw 0x04 0x2d 0x2f | awk '{print substr($0,9,1)}'" diff --git a/device/dell/x86_64-dellemc_z9332f_d1508-r0/plugins/sfputil.py b/device/dell/x86_64-dellemc_z9332f_d1508-r0/plugins/sfputil.py index 1ea6af1f8d26..b9c9acf34ede 100644 --- a/device/dell/x86_64-dellemc_z9332f_d1508-r0/plugins/sfputil.py +++ b/device/dell/x86_64-dellemc_z9332f_d1508-r0/plugins/sfputil.py @@ -28,8 +28,8 @@ class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" PORT_START = 1 - PORT_END = 34 - PORTS_IN_BLOCK = 34 + PORT_END = 34 + PORTS_IN_BLOCK = 34 BASE_RES_PATH = "/sys/bus/pci/devices/0000:09:00.0/resource0" @@ -84,7 +84,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(self.PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -273,7 +273,7 @@ def reset(self, port_num): def get_register(self, reg_file): retval = 'ERR' if (not path.isfile(reg_file)): - print reg_file, 'not found !' + print(reg_file + ' not found !') return retval try: diff --git a/device/delta/x86_64-delta_ag5648-r0/plugins/sfputil.py b/device/delta/x86_64-delta_ag5648-r0/plugins/sfputil.py index 864977414251..b4c5706b2d32 100644 --- a/device/delta/x86_64-delta_ag5648-r0/plugins/sfputil.py +++ b/device/delta/x86_64-delta_ag5648-r0/plugins/sfputil.py @@ -35,7 +35,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(0, self.PORTS_IN_BLOCK + 1) + return list(range(0, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -58,7 +58,7 @@ def get_response(self, port_num): try: reg_file = open("/sys/devices/platform/delta-ag5648-cpld.0/sfp_response", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # set the bit corresponding to our port @@ -81,7 +81,7 @@ def get_presence(self, port_num): try: reg_file = open("/sys/devices/platform/delta-ag5648-cpld.0/sfp_present") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -106,7 +106,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/devices/platform/delta-ag5648-cpld.0/sfp_lpmode") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) content = reg_file.readline().rstrip() @@ -130,7 +130,7 @@ def set_low_power_mode(self, port_num, lpmode): try: reg_file = open("/sys/devices/platform/delta-ag5648-cpld.0/sfp_lpmode", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -166,7 +166,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -192,7 +192,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_value | mask diff --git a/device/delta/x86_64-delta_ag9032v1-r0/plugins/sfputil.py b/device/delta/x86_64-delta_ag9032v1-r0/plugins/sfputil.py index 748e2b6643f4..c620540d2911 100644 --- a/device/delta/x86_64-delta_ag9032v1-r0/plugins/sfputil.py +++ b/device/delta/x86_64-delta_ag9032v1-r0/plugins/sfputil.py @@ -31,7 +31,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(0, self.PORTS_IN_BLOCK + 1) + return list(range(0, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -53,7 +53,7 @@ def get_presence(self, port_num): try: reg_file = open("/sys/devices/platform/delta-ag9032v1-swpld.0/sfp_present") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -78,7 +78,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/devices/platform/delta-ag9032v1-swpld.0/sfp_lpmode") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) content = reg_file.readline().rstrip() @@ -102,7 +102,7 @@ def set_low_power_mode(self, port_num, lpmode): try: reg_file = open("/sys/devices/platform/delta-ag9032v1-swpld.0/sfp_lpmode", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -138,7 +138,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -164,7 +164,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_value | mask diff --git a/device/delta/x86_64-delta_ag9032v2a-r0/plugins/sfputil.py b/device/delta/x86_64-delta_ag9032v2a-r0/plugins/sfputil.py index 9abaa8cf01c1..ace5d9f3736b 100644 --- a/device/delta/x86_64-delta_ag9032v2a-r0/plugins/sfputil.py +++ b/device/delta/x86_64-delta_ag9032v2a-r0/plugins/sfputil.py @@ -31,7 +31,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(0, self.PORT_END - self.PORT_START + 1) + return list(range(0, self.PORT_END - self.PORT_START + 1)) @property def port_to_eeprom_mapping(self): @@ -53,7 +53,7 @@ def get_presence(self, port_num): try: reg_file = open("/sys/devices/platform/delta-ag9032v2a-swpld1.0/sfp_is_present") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -78,7 +78,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/devices/platform/delta-ag9032v2a-swpld1.0/qsfp_lpmode") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) content = reg_file.readline().rstrip() @@ -102,7 +102,7 @@ def set_low_power_mode(self, port_num, lpmode): try: reg_file = open("/sys/devices/platform/delta-ag9032v2a-swpld1.0/qsfp_lpmode", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -138,7 +138,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -164,7 +164,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_value | mask diff --git a/device/delta/x86_64-delta_ag9064-r0/plugins/sfputil.py b/device/delta/x86_64-delta_ag9064-r0/plugins/sfputil.py index 8b1b1aea1d82..f86fac5f2af2 100644 --- a/device/delta/x86_64-delta_ag9064-r0/plugins/sfputil.py +++ b/device/delta/x86_64-delta_ag9064-r0/plugins/sfputil.py @@ -31,7 +31,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(0, self.PORTS_IN_BLOCK + 1) + return list(range(0, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -53,7 +53,7 @@ def get_presence(self, port_num): try: reg_file = open("/sys/devices/platform/delta-ag9064-cpld.0/qsfp_present") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -78,7 +78,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/devices/platform/delta-ag9064-cpld.0/qsfp_lpmode") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) content = reg_file.readline().rstrip() @@ -102,7 +102,7 @@ def set_low_power_mode(self, port_num, lpmode): try: reg_file = open("/sys/devices/platform/delta-ag9064-cpld.0/qsfp_lpmode", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -138,7 +138,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -164,7 +164,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_value | mask diff --git a/device/delta/x86_64-delta_agc032-r0/plugins/sfputil.py b/device/delta/x86_64-delta_agc032-r0/plugins/sfputil.py index a448d4101939..b6a2601e42ac 100644 --- a/device/delta/x86_64-delta_agc032-r0/plugins/sfputil.py +++ b/device/delta/x86_64-delta_agc032-r0/plugins/sfputil.py @@ -36,7 +36,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(0, self.PORTS_IN_BLOCK) + return list(range(0, self.PORTS_IN_BLOCK)) @property def port_to_eeprom_mapping(self): @@ -70,7 +70,7 @@ def get_presence(self, port_num): if int(present.readline()) == 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 return False @@ -87,14 +87,14 @@ def get_low_power_mode(self, port_num): if port_num < 16: lpmode_path = "SWPLD2/qsfp_p{}_lpmode".format(port) else: - lpmode_path = "SWPLD3/qsfp_p{}_lpmode".format(port) + lpmode_path = "SWPLD3/qsfp_p{}_lpmode".format(port) try: with open("/sys/devices/platform/delta-agc032-swpld.0/" + lpmode_path, 'r') as lpmode: if int(lpmode.readline()) == 1: 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 return False @@ -111,12 +111,12 @@ def set_low_power_mode(self, port_num, lpmode): if port_num < 16: lpmode_path = "SWPLD2/qsfp_p{}_lpmode".format(port) else: - lpmode_path = "SWPLD3/qsfp_p{}_lpmode".format(port) + lpmode_path = "SWPLD3/qsfp_p{}_lpmode".format(port) try: file = open("/sys/devices/platform/delta-agc032-swpld.0/" + lpmode_path, 'r+') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False file.seek(0) @@ -143,12 +143,12 @@ def reset(self, port_num): if port_num < 16: reset_path = "SWPLD2/qsfp_p{}_rst".format(port) else: - reset_path = "SWPLD3/qsfp_p{}_rst".format(port) + reset_path = "SWPLD3/qsfp_p{}_rst".format(port) try: file = open("/sys/devices/platform/delta-agc032-swpld.0/" + reset_path, 'r+') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False file.seek(0) @@ -162,7 +162,7 @@ def reset(self, port_num): try: file = open("/sys/devices/platform/delta-agc032-swpld.0/" + reset_path, 'r+') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False file.seek(0) @@ -177,7 +177,7 @@ def get_eeprom_dict(self, port_num): try: file = open("/sys/devices/platform/delta-agc032-cpupld.0/cpu_i2c_mux_sel", 'r+') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # Switch CPLD to FRONT-PORT EEPROM MUX @@ -191,7 +191,7 @@ def get_eeprom_dict(self, port_num): try: file = open("/sys/devices/platform/delta-agc032-cpupld.0/cpu_i2c_mux_sel", 'r+') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # Switch CPLD to FRONT-PORT EEPROM MUX diff --git a/device/delta/x86_64-delta_et-6248brb-r0/plugins/psuutil.py b/device/delta/x86_64-delta_et-6248brb-r0/plugins/psuutil.py index 99e8f1d17dd8..35dac38245d6 100644 --- a/device/delta/x86_64-delta_et-6248brb-r0/plugins/psuutil.py +++ b/device/delta/x86_64-delta_et-6248brb-r0/plugins/psuutil.py @@ -31,7 +31,7 @@ def get_psu_status(self, index): try: reg_file = open(self.psu_path.format(index)) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False if int(reg_file.readline()) == 1: @@ -46,7 +46,7 @@ def get_psu_presence(self, index): try: reg_file = open(self.psu_presence.format(index)) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False if int(reg_file.readline()) == 0: diff --git a/device/delta/x86_64-delta_et-6248brb-r0/plugins/sfputil.py b/device/delta/x86_64-delta_et-6248brb-r0/plugins/sfputil.py index 84a3bfc3dac0..c8d30d3beeeb 100644 --- a/device/delta/x86_64-delta_et-6248brb-r0/plugins/sfputil.py +++ b/device/delta/x86_64-delta_et-6248brb-r0/plugins/sfputil.py @@ -31,7 +31,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(0) + return list(range(0)) @property def port_to_eeprom_mapping(self): @@ -52,13 +52,13 @@ def get_presence(self, port_num): # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False - + presence_path = "/sys/devices/platform/delta-et6248brb-gpio.0/SFP/sfp_mod_p{}" try: reg_file = open(presence_path.format(port_num - 47)) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False if int(reg_file.readline()) == 0: diff --git a/device/delta/x86_64-delta_et-c032if-r0/plugins/sfputil.py b/device/delta/x86_64-delta_et-c032if-r0/plugins/sfputil.py index 4802c3a8f0ce..fc607c8b84f4 100644 --- a/device/delta/x86_64-delta_et-c032if-r0/plugins/sfputil.py +++ b/device/delta/x86_64-delta_et-c032if-r0/plugins/sfputil.py @@ -16,7 +16,7 @@ class SfpUtil(SfpUtilBase): PORT_START = 0 PORT_START_SFP = 32 - PORT_END = 33 + PORT_END = 33 PORTS_IN_BLOCK = 34 EEPROM_OFFSET = 1 @@ -38,7 +38,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(0, self.PORTS_IN_BLOCK + 1) + return list(range(0, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -51,7 +51,7 @@ def get_transceiver_status(self): reg_file = open("/sys/devices/platform/delta-et-c032if-cpld.0/sfp_is_present") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -78,7 +78,7 @@ def get_presence(self, port_num): try: reg_file = open("/sys/devices/platform/delta-et-c032if-cpld.0/sfp_is_present") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -103,7 +103,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/devices/platform/delta-et-c032if-cpld.0/sfp_lp_mode") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) content = reg_file.readline().rstrip() @@ -127,7 +127,7 @@ def set_low_power_mode(self, port_num, lpmode): try: reg_file = open("/sys/devices/platform/delta-et-c032if-cpld.0/sfp_lp_mode", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -163,7 +163,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -189,7 +189,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_value | mask @@ -209,13 +209,13 @@ def get_transceiver_change_event(self, timeout=0): elif timeout > 0: timeout = timeout / float(1000) # Convert to secs else: - print "get_transceiver_change_event:Invalid timeout value", timeout + print("get_transceiver_change_event:Invalid timeout value", timeout) return False, {} end_time = start_time + timeout if start_time > end_time: - print 'get_transceiver_change_event:' \ - 'time wrap / invalid timeout value', timeout + print('get_transceiver_change_event:' \ + 'time wrap / invalid timeout value', timeout) return False, {} # Time wrap or possibly incorrect timeout while timeout >= 0: @@ -251,5 +251,5 @@ def get_transceiver_change_event(self, timeout=0): if timeout > 0: time.sleep(timeout) return True, {} - print "get_transceiver_change_event: Should not reach here." + print("get_transceiver_change_event: Should not reach here.") return False, {} diff --git a/device/ingrasys/x86_64-ingrasys_s8810_32q-r0/plugins/sfputil.py b/device/ingrasys/x86_64-ingrasys_s8810_32q-r0/plugins/sfputil.py index 8d195f644e18..9bdc732c7ed5 100644 --- a/device/ingrasys/x86_64-ingrasys_s8810_32q-r0/plugins/sfputil.py +++ b/device/ingrasys/x86_64-ingrasys_s8810_32q-r0/plugins/sfputil.py @@ -26,7 +26,7 @@ class SfpUtil(SfpUtilBase): LP_GPIO_BASE = 160 RST_GPIO_BASE = 128 GPIO_OFFSET = 0 - + BASE_DIR_PATH = "/sys/class/gpio/gpio{0}/direction" BASE_VAL_PATH = "/sys/class/gpio/gpio{0}/value" @@ -42,7 +42,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(0, self.PORTS_IN_BLOCK + 1) + return list(range(0, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -57,7 +57,7 @@ def set_gpio_offset(self): try: gpiochip_no = int(d[8:],10) except ValueError as e: - print "Error: %s" % str(e) + print("Error: %s" % str(e)) if gpiochip_no > 255: self.GPIO_OFFSET=256 return True @@ -92,7 +92,7 @@ def get_presence(self, port_num): port_num + self.ABS_GPIO_BASE) val_file = open(abs_device_file) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = val_file.readline().rstrip() @@ -113,11 +113,11 @@ def get_low_power_mode(self, port_num): port_num + self.LP_GPIO_BASE) val_file = open(lpmode_val_device_file) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False - + content = val_file.readline().rstrip() - + # content is a string, either "0" or "1" if content == "1": return True @@ -134,9 +134,9 @@ def set_low_power_mode(self, port_num, lpmode): port_num + self.LP_GPIO_BASE) val_file = open(lpmode_val_device_file, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False - + val_file.write("1" if lpmode is True else "0") val_file.close() @@ -146,29 +146,29 @@ def reset(self, port_num): # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False - + try: reset_val_device_file = self.BASE_VAL_PATH.format( port_num + self.RST_GPIO_BASE) val_file = open(reset_val_device_file, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False - + val_file.write("1") val_file.close() - + # Sleep 1 second to allow it to settle time.sleep(1) - + try: reset_val_device_file = self.BASE_VAL_PATH.format( port_num + self.RST_GPIO_BASE) val_file = open(reset_val_device_file, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False - + val_file.write("0") val_file.close() diff --git a/device/ingrasys/x86_64-ingrasys_s8900_54xc-r0/plugins/sfputil.py b/device/ingrasys/x86_64-ingrasys_s8900_54xc-r0/plugins/sfputil.py index 586e6e189743..8fdea71c64f3 100644 --- a/device/ingrasys/x86_64-ingrasys_s8900_54xc-r0/plugins/sfputil.py +++ b/device/ingrasys/x86_64-ingrasys_s8900_54xc-r0/plugins/sfputil.py @@ -20,7 +20,7 @@ class SfpUtil(SfpUtilBase): QSFP_PORT_START = 48 PORTS_IN_BLOCK = 54 GPIO_OFFSET = 0 - + BASE_DIR_PATH = "/sys/class/gpio/gpio{0}/direction" BASE_VAL_PATH = "/sys/class/gpio/gpio{0}/value" @@ -100,7 +100,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -115,7 +115,7 @@ def set_gpio_offset(self): try: gpiochip_no = int(d[8:],10) except ValueError as e: - print "Error: %s" % str(e) + print("Error: %s" % str(e)) if gpiochip_no > 255: self.GPIO_OFFSET=256 return True @@ -179,7 +179,7 @@ def init_abs_to_gpio_mapping(self): 53: 245+self.GPIO_OFFSET } return True - + def init_lpmode_to_gpio_mapping(self): self.lpmode_to_gpio_mapping = { 48: 224+self.GPIO_OFFSET, @@ -190,7 +190,7 @@ def init_lpmode_to_gpio_mapping(self): 53: 229+self.GPIO_OFFSET } return True - + def init_reset_to_gpio_mapping(self): self.reset_to_gpio_mapping = { 48: 208+self.GPIO_OFFSET, @@ -228,7 +228,7 @@ def get_presence(self, port_num): self.abs_to_gpio_mapping[port_num]) val_file = open(abs_device_file) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = val_file.readline().rstrip() @@ -249,11 +249,11 @@ def get_low_power_mode(self, port_num): self.lpmode_to_gpio_mapping[port_num]) val_file = open(lpmode_val_device_file) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False - + content = val_file.readline().rstrip() - + # content is a string, either "0" or "1" if content == "1": return True @@ -270,9 +270,9 @@ def set_low_power_mode(self, port_num, lpmode): self.lpmode_to_gpio_mapping[port_num]) val_file = open(lpmode_val_device_file, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False - + val_file.write("1" if lpmode is True else "0") val_file.close() @@ -281,32 +281,32 @@ def set_low_power_mode(self, port_num, lpmode): def reset(self, port_num): # Check for invalid port_num if port_num < self.qsfp_port_start or port_num > self.port_end: - print "Error: unable to reset non-QSFP module: port %s" % str(port_num) + print("Error: unable to reset non-QSFP module: port %s" % str(port_num)) return False - + try: - print "port %s" % str(port_num) + print("port %s" % str(port_num)) reset_val_device_file = self.BASE_VAL_PATH.format( self.reset_to_gpio_mapping[port_num]) val_file = open(reset_val_device_file, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False - + val_file.write("1") val_file.close() - + # Sleep 1 second to allow it to settle time.sleep(1) - + try: reset_val_device_file = self.BASE_VAL_PATH.format( self.reset_to_gpio_mapping[port_num]) val_file = open(reset_val_device_file, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False - + val_file.write("0") val_file.close() diff --git a/device/ingrasys/x86_64-ingrasys_s8900_64xc-r0/plugins/sfputil.py b/device/ingrasys/x86_64-ingrasys_s8900_64xc-r0/plugins/sfputil.py index 26355bf441e6..7931cb5f1bb9 100644 --- a/device/ingrasys/x86_64-ingrasys_s8900_64xc-r0/plugins/sfputil.py +++ b/device/ingrasys/x86_64-ingrasys_s8900_64xc-r0/plugins/sfputil.py @@ -102,7 +102,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -133,7 +133,7 @@ def get_presence(self, port_num): try: reg_file = open("/sys/devices/platform/ingrasys-s8900-64xc-cpld.0/qsfp_modprs") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -158,7 +158,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/devices/platform/ingrasys-s8900-64xc-cpld.0/qsfp_lpmode") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -183,7 +183,7 @@ def set_low_power_mode(self, port_num, lpmode): try: reg_file = open("/sys/devices/platform/ingrasys-s8900-64xc-cpld.0/qsfp_lpmode", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -219,7 +219,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -245,7 +245,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_value | mask diff --git a/device/ingrasys/x86_64-ingrasys_s9100-r0/plugins/sfputil.py b/device/ingrasys/x86_64-ingrasys_s9100-r0/plugins/sfputil.py index 849bd13d94d3..593f287a14f1 100644 --- a/device/ingrasys/x86_64-ingrasys_s9100-r0/plugins/sfputil.py +++ b/device/ingrasys/x86_64-ingrasys_s9100-r0/plugins/sfputil.py @@ -73,7 +73,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(0, self.PORTS_IN_BLOCK + 1) + return list(range(0, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -88,7 +88,7 @@ def set_gpio_offset(self): try: gpiochip_no = int(d[8:],10) except ValueError as e: - print "Error: %s" % str(e) + print("Error: %s" % str(e)) if gpiochip_no > 255: self.GPIO_OFFSET=256 return True @@ -231,7 +231,7 @@ def get_presence(self, port_num): self.abs_to_gpio_mapping[port_num]) val_file = open(abs_device_file) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = val_file.readline().rstrip() @@ -253,7 +253,7 @@ def get_low_power_mode(self, port_num): self.lpmode_to_gpio_mapping[port_num]) val_file = open(lpmode_val_device_file) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = val_file.readline().rstrip() @@ -275,7 +275,7 @@ def set_low_power_mode(self, port_num, lpmode): self.lpmode_to_gpio_mapping[port_num]) val_file = open(lpmode_val_device_file, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False val_file.write("1" if lpmode is True else "0") @@ -293,7 +293,7 @@ def reset(self, port_num): self.reset_to_gpio_mapping[port_num]) val_file = open(reset_val_device_file, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False val_file.write("1") @@ -307,7 +307,7 @@ def reset(self, port_num): self.reset_to_gpio_mapping[port_num]) val_file = open(reset_val_device_file, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False val_file.write("0") diff --git a/device/ingrasys/x86_64-ingrasys_s9130_32x-r0/plugins/sfputil.py b/device/ingrasys/x86_64-ingrasys_s9130_32x-r0/plugins/sfputil.py index 4827ad3bfa80..06603aef6a0a 100644 --- a/device/ingrasys/x86_64-ingrasys_s9130_32x-r0/plugins/sfputil.py +++ b/device/ingrasys/x86_64-ingrasys_s9130_32x-r0/plugins/sfputil.py @@ -41,7 +41,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(0, self.PORTS_IN_BLOCK + 1) + return list(range(0, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -49,14 +49,14 @@ def port_to_eeprom_mapping(self): def set_gpio_offset(self): sys_gpio_dir = "/sys/class/gpio" - self.GPIO_OFFSET = 0 - gpiochip_no = 0 + self.GPIO_OFFSET = 0 + gpiochip_no = 0 for d in os.listdir(sys_gpio_dir): if "gpiochip" in d: try: gpiochip_no = int(d[8:],10) except ValueError as e: - print "Error: %s" % str(e) + print("Error: %s" % str(e)) if gpiochip_no > 255: self.GPIO_OFFSET=256 return True @@ -99,7 +99,7 @@ def get_presence(self, port_num): gpio_file_path = self.GPIO_VAL_PATH.format(gpio_index) gpio_file = open(gpio_file_path) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # content is a string containing the gpio value @@ -127,7 +127,7 @@ def get_low_power_mode(self, port_num): gpio_file_path = self.GPIO_VAL_PATH.format(gpio_index) gpio_file = open(gpio_file_path) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # content is a string containing the gpio value @@ -154,7 +154,7 @@ def set_low_power_mode(self, port_num, lpmode): gpio_file_path = self.GPIO_VAL_PATH.format(gpio_index) gpio_file = open(gpio_file_path, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # the gpio pin is ACTIVE_HIGH @@ -185,7 +185,7 @@ def reset(self, port_num): gpio_file_path = self.GPIO_VAL_PATH.format(gpio_index) gpio_file = open(gpio_file_path, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # set the gpio to take port into reset @@ -203,7 +203,7 @@ def reset(self, port_num): try: gpio_file = open(gpio_file_path, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # set gpio back low to take port out of reset diff --git a/device/ingrasys/x86_64-ingrasys_s9180_32x-r0/plugins/psuutil.py b/device/ingrasys/x86_64-ingrasys_s9180_32x-r0/plugins/psuutil.py index 25cdfb031882..ec35a487eead 100644 --- a/device/ingrasys/x86_64-ingrasys_s9180_32x-r0/plugins/psuutil.py +++ b/device/ingrasys/x86_64-ingrasys_s9180_32x-r0/plugins/psuutil.py @@ -20,14 +20,14 @@ class PsuUtil(PsuBase): def set_gpio_offset(self): sys_gpio_dir = "/sys/class/gpio" - self.GPIO_OFFSET = 0 - gpiochip_no = 0 + self.GPIO_OFFSET = 0 + gpiochip_no = 0 for d in os.listdir(sys_gpio_dir): if "gpiochip" in d: try: gpiochip_no = int(d[8:],10) except ValueError as e: - print "Error: %s" % str(e) + print("Error: %s" % str(e)) if gpiochip_no > 255: self.GPIO_OFFSET=256 return True diff --git a/device/ingrasys/x86_64-ingrasys_s9180_32x-r0/plugins/sfputil.py b/device/ingrasys/x86_64-ingrasys_s9180_32x-r0/plugins/sfputil.py index 00c5e10e0b0d..530554ed9fb6 100644 --- a/device/ingrasys/x86_64-ingrasys_s9180_32x-r0/plugins/sfputil.py +++ b/device/ingrasys/x86_64-ingrasys_s9180_32x-r0/plugins/sfputil.py @@ -76,7 +76,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(0, self.PORTS_IN_BLOCK + 1) + return list(range(0, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -94,7 +94,7 @@ def set_gpio_offset(self): try: gpiochip_no = int(d[8:],10) except ValueError as e: - print "Error: %s" % str(e) + print("Error: %s" % str(e)) if gpiochip_no > 255: self.GPIO_OFFSET=256 return True @@ -172,12 +172,12 @@ def init_lpmode_to_gpio_mapping(self): 28: 157+self.GPIO_OFFSET, 29: 156+self.GPIO_OFFSET, 30: 159+self.GPIO_OFFSET, - 31: 158+self.GPIO_OFFSET + 31: 158+self.GPIO_OFFSET } return True def init_reset_to_gpio_mapping(self): - self.reset_to_gpio_mapping = { + self.reset_to_gpio_mapping = { 0: 129+self.GPIO_OFFSET, 1: 128+self.GPIO_OFFSET, 2: 131+self.GPIO_OFFSET, @@ -209,7 +209,7 @@ def init_reset_to_gpio_mapping(self): 28: 125+self.GPIO_OFFSET, 29: 124+self.GPIO_OFFSET, 30: 127+self.GPIO_OFFSET, - 31: 126+self.GPIO_OFFSET + 31: 126+self.GPIO_OFFSET } return True @@ -239,7 +239,7 @@ def get_presence(self, port_num): self.abs_to_gpio_mapping[port_num]) val_file = open(abs_device_file) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = val_file.readline().rstrip() @@ -261,7 +261,7 @@ def get_low_power_mode(self, port_num): self.lpmode_to_gpio_mapping[port_num]) val_file = open(lpmode_val_device_file) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = val_file.readline().rstrip() @@ -283,7 +283,7 @@ def set_low_power_mode(self, port_num, lpmode): self.lpmode_to_gpio_mapping[port_num]) val_file = open(lpmode_val_device_file, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False val_file.write("1" if lpmode is True else "0") @@ -301,7 +301,7 @@ def reset(self, port_num): self.reset_to_gpio_mapping[port_num]) val_file = open(reset_val_device_file, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False val_file.write("1") @@ -315,7 +315,7 @@ def reset(self, port_num): self.reset_to_gpio_mapping[port_num]) val_file = open(reset_val_device_file, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False val_file.write("0") diff --git a/device/ingrasys/x86_64-ingrasys_s9200_64x-r0/plugins/sfputil.py b/device/ingrasys/x86_64-ingrasys_s9200_64x-r0/plugins/sfputil.py index 584b0e9716b8..a1e71ec610e0 100644 --- a/device/ingrasys/x86_64-ingrasys_s9200_64x-r0/plugins/sfputil.py +++ b/device/ingrasys/x86_64-ingrasys_s9200_64x-r0/plugins/sfputil.py @@ -14,7 +14,7 @@ class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" PORT_START = 0 - PORT_END = 63 + PORT_END = 63 PORTS_IN_BLOCK = 64 EEPROM_OFFSET = 29 @@ -98,7 +98,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(0, self.PORTS_IN_BLOCK + 1) + return list(range(0, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -124,7 +124,7 @@ def get_presence(self, port_num): try: reg_file = open("/sys/devices/platform/ingrasys-s9200-cpld.0/qsfp_modprs") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -152,7 +152,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/devices/platform/ingrasys-s9200-cpld.0/qsfp_lpmode") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) content = reg_file.readline().rstrip() @@ -175,15 +175,15 @@ def set_low_power_mode(self, port_num, lpmode): # logic port to physical port mapping port_num = self._logic_to_phy_port_mapping[port_num] - + try: reg_file = open("/sys/devices/platform/ingrasys-s9200-cpld.0/qsfp_lpmode", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() - + # content is a string containing the hex representation of the register reg_value = int(content, 16) @@ -219,7 +219,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -247,7 +247,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_value | mask diff --git a/device/ingrasys/x86_64-ingrasys_s9230_64x-r0/plugins/sfputil.py b/device/ingrasys/x86_64-ingrasys_s9230_64x-r0/plugins/sfputil.py index 2f7a5395bb47..b962a424c9e2 100644 --- a/device/ingrasys/x86_64-ingrasys_s9230_64x-r0/plugins/sfputil.py +++ b/device/ingrasys/x86_64-ingrasys_s9230_64x-r0/plugins/sfputil.py @@ -108,7 +108,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(0, self.PORTS_IN_BLOCK + 1) + return list(range(0, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -150,13 +150,13 @@ def get_presence(self, port_num): try: reg_file = open(reg_path) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # content is a string containing the status register value content = reg_file.readline().rstrip() reg_file.close() - + reg_value = int(content, 16) # mask for presence bit (bit 1) mask = (1 << self.CPLD_PRES_BIT) @@ -183,7 +183,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open(reg_path) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # content is a string containing the status register value @@ -216,7 +216,7 @@ def set_low_power_mode(self, port_num, lpmode): try: reg_file = open(reg_path, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # content is a string containing the status register value @@ -257,7 +257,7 @@ def reset(self, port_num): try: reg_file = open(reg_path, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # content is a string containing the status register value @@ -280,7 +280,7 @@ def reset(self, port_num): try: reg_file = open(reg_path, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_value | mask diff --git a/device/ingrasys/x86_64-ingrasys_s9280_64x-r0/plugins/sfputil.py b/device/ingrasys/x86_64-ingrasys_s9280_64x-r0/plugins/sfputil.py index 57edb81cd109..9e1ec0f60cb0 100644 --- a/device/ingrasys/x86_64-ingrasys_s9280_64x-r0/plugins/sfputil.py +++ b/device/ingrasys/x86_64-ingrasys_s9280_64x-r0/plugins/sfputil.py @@ -19,7 +19,7 @@ class SfpUtil(SfpUtilBase): EEPROM_OFFSET = 41 CPLD1_PORTS = 12 CPLDx_PORTS = 13 - #TODO: check init sequence for CPLD i2c bus + #TODO: check init sequence for CPLD i2c bus CPLD_OFFSET = 1 CPLD_PRES_BIT = 1 CPLD_RESET_BIT = 0 @@ -110,7 +110,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(0, self.PORTS_IN_BLOCK + 1) + return list(range(0, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -157,13 +157,13 @@ def get_presence(self, port_num): try: reg_file = open(reg_path) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # content is a string containing the status register value content = reg_file.readline().rstrip() reg_file.close() - + reg_value = int(content, 16) # mask for presence bit (bit 1) mask = (1 << self.CPLD_PRES_BIT) @@ -190,7 +190,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open(reg_path) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # content is a string containing the status register value @@ -223,7 +223,7 @@ def set_low_power_mode(self, port_num, lpmode): try: reg_file = open(reg_path, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # content is a string containing the status register value @@ -264,7 +264,7 @@ def reset(self, port_num): try: reg_file = open(reg_path, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # content is a string containing the status register value @@ -287,7 +287,7 @@ def reset(self, port_num): try: reg_file = open(reg_path, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_value | mask diff --git a/device/inventec/x86_64-inventec_d6254qs-r0/plugins/sfputil.py b/device/inventec/x86_64-inventec_d6254qs-r0/plugins/sfputil.py index 6cd470795fb6..62a67f72e1a4 100644 --- a/device/inventec/x86_64-inventec_d6254qs-r0/plugins/sfputil.py +++ b/device/inventec/x86_64-inventec_d6254qs-r0/plugins/sfputil.py @@ -95,7 +95,7 @@ def qsfp_port_end(self): @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -117,7 +117,7 @@ def get_presence(self, port_num): try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/present") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -137,7 +137,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/lpmod") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) reg_value = int(reg_file.readline().rstrip()) @@ -151,13 +151,13 @@ def set_low_power_mode(self, port_num, lpmode): if port_num < self.port_start or port_num > self.port_end: return False if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: - print "\nError:SFP's don't support this property" + print("\nError:SFP's don't support this property") return False try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/lpmod", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -179,13 +179,13 @@ def reset(self, port_num): if port_num < self.port_start or port_num > self.port_end: return False if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: - print "\nError:SFP's don't support this property" + print("\nError:SFP's don't support this property") return False try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 0 @@ -199,7 +199,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 1 diff --git a/device/inventec/x86_64-inventec_d6332-r0/plugins/sfputil.py b/device/inventec/x86_64-inventec_d6332-r0/plugins/sfputil.py index 0f2d3aad1720..46c2f22378dd 100755 --- a/device/inventec/x86_64-inventec_d6332-r0/plugins/sfputil.py +++ b/device/inventec/x86_64-inventec_d6332-r0/plugins/sfputil.py @@ -7,7 +7,7 @@ import time import os, re, socket from sonic_sfp.sfputilbase import SfpUtilBase - from collections import OrderedDict + from collections import OrderedDict from sonic_sfp.sff8472 import sff8472Dom except ImportError as e: raise ImportError("%s - required module not found" % str(e)) @@ -120,7 +120,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(0, self.PORTS_IN_BLOCK + 1) + return list(range(0, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -143,7 +143,7 @@ def get_presence(self, port_num): try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/present") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -161,7 +161,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/lpmod") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) reg_value = int(reg_file.readline().rstrip()) @@ -178,7 +178,7 @@ def set_low_power_mode(self, port_num, lpmode): try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/lpmod", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False lpmode = int(reg_file.readline().rstrip()) @@ -203,7 +203,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 0 @@ -217,7 +217,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 1 diff --git a/device/inventec/x86_64-inventec_d6356-r0/plugins/sfputil.py b/device/inventec/x86_64-inventec_d6356-r0/plugins/sfputil.py index 116a3d9acbc9..ba1b93ea6531 100755 --- a/device/inventec/x86_64-inventec_d6356-r0/plugins/sfputil.py +++ b/device/inventec/x86_64-inventec_d6356-r0/plugins/sfputil.py @@ -163,7 +163,7 @@ def qsfp_port_end(self): @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -185,7 +185,7 @@ def get_presence(self, port_num): try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/present") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -205,7 +205,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/lpmod") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) reg_value = int(reg_file.readline().rstrip()) @@ -219,13 +219,13 @@ def set_low_power_mode(self, port_num, lpmode): if port_num < self.port_start or port_num > self.port_end: return False if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: - print "\nError:SFP's don't support this property" + print("\nError:SFP's don't support this property") return False try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/lpmod", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -247,13 +247,13 @@ def reset(self, port_num): if port_num < self.port_start or port_num > self.port_end: return False if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: - print "\nError:SFP's don't support this property" + print("\nError:SFP's don't support this property") return False try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 0 @@ -267,7 +267,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 1 diff --git a/device/inventec/x86_64-inventec_d6556-r0/plugins/sfputil.py b/device/inventec/x86_64-inventec_d6556-r0/plugins/sfputil.py index 155b956827f1..3cd6c43d7cde 100644 --- a/device/inventec/x86_64-inventec_d6556-r0/plugins/sfputil.py +++ b/device/inventec/x86_64-inventec_d6556-r0/plugins/sfputil.py @@ -97,7 +97,7 @@ def qsfp_port_end(self): @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -119,7 +119,7 @@ def get_presence(self, port_num): try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/present") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -139,7 +139,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/lpmod") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) reg_value = int(reg_file.readline().rstrip()) @@ -153,13 +153,13 @@ def set_low_power_mode(self, port_num, lpmode): if port_num < self.port_start or port_num > self.port_end: return False if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: - print "\nError:SFP's don't support this property" + print("\nError:SFP's don't support this property") return False try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/lpmod", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -181,13 +181,13 @@ def reset(self, port_num): if port_num < self.port_start or port_num > self.port_end: return False if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: - print "\nError:SFP's don't support this property" + print("\nError:SFP's don't support this property") return False try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 0 @@ -201,7 +201,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 1 diff --git a/device/inventec/x86_64-inventec_d7032q28b-r0/plugins/sfputil.py b/device/inventec/x86_64-inventec_d7032q28b-r0/plugins/sfputil.py index d109f49f2e7d..5321e0c072e8 100644 --- a/device/inventec/x86_64-inventec_d7032q28b-r0/plugins/sfputil.py +++ b/device/inventec/x86_64-inventec_d7032q28b-r0/plugins/sfputil.py @@ -73,7 +73,7 @@ def qsfp_port_end(self): @property def qsfp_ports(self): - return range(0, self.PORTS_IN_BLOCK + 1) + return list(range(0, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -95,7 +95,7 @@ def get_presence(self, port_num): try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/present") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -113,7 +113,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/lpmod") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) reg_value = int(reg_file.readline().rstrip()) @@ -130,7 +130,7 @@ def set_low_power_mode(self, port_num, lpmode): try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/lpmod", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -155,7 +155,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 0 @@ -169,7 +169,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 1 diff --git a/device/inventec/x86_64-inventec_d7054q28b-r0/plugins/sfputil.py b/device/inventec/x86_64-inventec_d7054q28b-r0/plugins/sfputil.py index 5dffdd0335b0..93baaa88ac3e 100755 --- a/device/inventec/x86_64-inventec_d7054q28b-r0/plugins/sfputil.py +++ b/device/inventec/x86_64-inventec_d7054q28b-r0/plugins/sfputil.py @@ -95,7 +95,7 @@ def qsfp_port_end(self): @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -117,7 +117,7 @@ def get_presence(self, port_num): try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/present") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -137,7 +137,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/lpmod") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) reg_value = int(reg_file.readline().rstrip()) @@ -151,13 +151,13 @@ def set_low_power_mode(self, port_num, lpmode): if port_num < self.port_start or port_num > self.port_end: return False if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: - print "\nError:SFP's don't support this property" + print("\nError:SFP's don't support this property") return False try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/lpmod", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -179,13 +179,13 @@ def reset(self, port_num): if port_num < self.port_start or port_num > self.port_end: return False if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: - print "\nError:SFP's don't support this property" + print("\nError:SFP's don't support this property") return False try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 0 @@ -199,7 +199,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 1 diff --git a/device/inventec/x86_64-inventec_d7264q28b-r0/plugins/sfputil.py b/device/inventec/x86_64-inventec_d7264q28b-r0/plugins/sfputil.py index 6f23ad01bd2c..3f9880512f88 100755 --- a/device/inventec/x86_64-inventec_d7264q28b-r0/plugins/sfputil.py +++ b/device/inventec/x86_64-inventec_d7264q28b-r0/plugins/sfputil.py @@ -105,7 +105,7 @@ def qsfp_port_end(self): @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -127,7 +127,7 @@ def get_presence(self, port_num): try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/present") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -147,7 +147,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/lpmod") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) reg_value = int(reg_file.readline().rstrip()) @@ -161,13 +161,13 @@ def set_low_power_mode(self, port_num, lpmode): if port_num < self.port_start or port_num > self.port_end: return False if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: - print "\nError:SFP's don't support this property" + print("\nError:SFP's don't support this property") return False try: reg_file = open("/sys/class/swps/port"+str(port_num)+"/lpmod", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -189,13 +189,13 @@ def reset(self, port_num): if port_num < self.port_start or port_num > self.port_end: return False if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end: - print "\nError:SFP's don't support this property" + print("\nError:SFP's don't support this property") return False try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 0 @@ -209,7 +209,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 1 diff --git a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/led_control.py b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/led_control.py index d85b65696d69..d54e538a34b1 100644 --- a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/led_control.py +++ b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/led_control.py @@ -7,9 +7,9 @@ # Copyright (c) 2020, Juniper Networks, Inc. # All rights reserved. # -# Notice and Disclaimer: This code is licensed to you under the GNU General -# Public License as published by the Free Software Foundation, version 3 or -# any later version. This code is not an official Juniper product. You can +# Notice and Disclaimer: This code is licensed to you under the GNU General +# Public License as published by the Free Software Foundation, version 3 or +# any later version. This code is not an official Juniper product. You can # obtain a copy of the License at # # OSS License: @@ -27,8 +27,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . # -# Third-Party Code: This code may depend on other components under separate -# copyright notice and license terms. Your use of the source code for those +# Third-Party Code: This code may depend on other components under separate +# copyright notice and license terms. Your use of the source code for those # components is subject to the terms and conditions of the respective license # as noted in the Third-Party source code file. @@ -39,7 +39,7 @@ import glob from socket import * from select import * -except ImportError, e: +except ImportError as e: raise ImportError(str(e) + " - required module not found") @@ -78,7 +78,7 @@ def gpio_create_file(self,gpio_pin): gpio_export_file.write(str(gpio_pin)) gpio_export_file.close() except IOError as e: - print "Error: unable to open export file: %s" % str(e) + print("Error: unable to open export file: %s" % str(e)) return False return True @@ -96,7 +96,7 @@ def gpio_port_led_slave_init(self,gpio_base_path, gpio_port_start, gpio_port_end fp = open(flist[0] + "/base") gpio_base = int(fp.readline().rstrip()) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return for port in range(gpio_port_start, gpio_port_end + 1): self.gpio_port_led_init(gpio_base, port) @@ -119,7 +119,7 @@ def gpio_led_write(self,gpio_pin, value): gpio_file.write(str(value)) success = True except IOError as e: - print "error: unable to open file: %s" % str(e) + print("error: unable to open file: %s" % str(e)) return success @@ -132,7 +132,7 @@ def gpio_led_read(self,gpio_pin): reg_file = open(gpio_pin_path +"/value") value = int(reg_file.readline().rstrip()) except IOError as e: - print "error: unable to open file: %s" % str(e) + print("error: unable to open file: %s" % str(e)) return value diff --git a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/qfx5200_eeprom_data.py b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/qfx5200_eeprom_data.py index 7d7465212050..84fecd1e3731 100644 --- a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/qfx5200_eeprom_data.py +++ b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/qfx5200_eeprom_data.py @@ -2,14 +2,14 @@ # # Name: juniper_qfx5200_eepromconv.py version: 1.0 # -# Description: This file contains the code to store the contents of Main Board EEPROM and CPU Board EEPROM in file +# Description: This file contains the code to store the contents of Main Board EEPROM and CPU Board EEPROM in file # # Copyright (c) 2020, Juniper Networks, Inc. # All rights reserved. # -# Notice and Disclaimer: This code is licensed to you under the GNU General -# Public License as published by the Free Software Foundation, version 3 or -# any later version. This code is not an official Juniper product. You can +# Notice and Disclaimer: This code is licensed to you under the GNU General +# Public License as published by the Free Software Foundation, version 3 or +# any later version. This code is not an official Juniper product. You can # obtain a copy of the License at # # OSS License: @@ -27,16 +27,20 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . # -# Third-Party Code: This code may depend on other components under separate -# copyright notice and license terms. Your use of the source code for those -# components is subject to the terms and conditions of the respective license +# Third-Party Code: This code may depend on other components under separate +# copyright notice and license terms. Your use of the source code for those +# components is subject to the terms and conditions of the respective license # as noted in the Third-Party source code file. -import os -import commands import binascii +import os +import sys from sonic_eeprom import eeprom_tlvinfo +if sys.version_info[0] < 3: + import commands +else: + import subprocess as commands def fantype_detect(): @@ -53,13 +57,13 @@ def fantype_detect(): fantype_path = os.path.join(refpgaTMC_path, filename) cat_string = "cat " fantype_string = cat_string + fantype_path - status,fan_type=commands.getstatusoutput(fantype_string) + status,fan_type = commands.getstatusoutput(fantype_string) if ((fan_type == AFO) or (fan_type == AFI)): return fan_type else: pass - return default_fantype + return default_fantype @@ -69,7 +73,7 @@ def main(): eeprom_qfx5200 = Eeprom() fan_type = fantype_detect() - + # creating the "/var/run/eeprom" file and storing values of CPU board EEPROM and MAIN Board EEPROM in this file. eeprom_file = open ("/var/run/eeprom", "a+") eeprom_file.write("\n") @@ -95,20 +99,20 @@ def main(): eeprom_dict = eeprom_qfx5200.system_eeprom_info() key = '0x29' - if key in eeprom_dict.keys(): + if key in list(eeprom_dict.keys()): onie_version_str = eeprom_dict.get('0x29', None) else: onie_version_str = "N/A" eeprom_file.write("ONIE Version=%s\r\n" % onie_version_str) vendor_value_formatted, vendor_value_hexvalue = eeprom_qfx5200.vendor_ext_str() - + eeprom_hex = '/etc/init.d/eeprom_qfx5200_hex' with open(eeprom_hex, 'wb+') as Hexfile: Hexfile.write(vendor_value_hexvalue) - # Assembly ID + # Assembly ID ASMID_str = "0D83" with open(eeprom_hex, 'rb+') as AsmID_Hexfile: AsmID_Hexfile.seek(24, 0) @@ -144,7 +148,7 @@ def main(): HWMajorRev_write = eeprom_hexfile.read(2) eeprom_file.write("\t") eeprom_file.write("HW Major Revision=0x%s\r\n" % HWMajorRev_write) - + eeprom_hexfile.seek(30, 0) HWMinorRev_write = eeprom_hexfile.read(2) @@ -182,14 +186,14 @@ def main(): try: os.system(MainEepromCreate) except OSError: - print 'Error: Execution of "%s" failed', MainEepromCreate + print('Error: Execution of "%s" failed', MainEepromCreate) return False MainEepromFileCmd = 'cat /sys/bus/i2c/devices/i2c-0/0-0057/eeprom > /etc/init.d/MainEeprom_qfx5200_ascii' try: os.system(MainEepromFileCmd) except OSError: - print 'Error: Execution of "%s" failed', MainEepromFileCmd + print('Error: Execution of "%s" failed', MainEepromFileCmd) return False maineeprom_ascii = '/etc/init.d/MainEeprom_qfx5200_ascii' @@ -245,7 +249,7 @@ def main(): FRUModelNumber_read = eeprom_hexfile.read(46) FRUModelNumber_write = binascii.unhexlify(FRUModelNumber_read) eeprom_file.write("FRU Model Number=%s\r\n" % str(FRUModelNumber_write)) - + eeprom_hexfile.seek(204, 0) FRUModelMajorNumber_read = eeprom_hexfile.read(2) eeprom_file.write("FRU Model Major Number=0x%s\r\n" % str(FRUModelMajorNumber_read)) @@ -264,7 +268,7 @@ def main(): eeprom_file.write("Chassis Serial Number=%s\r\n" % str(SerialNumber_write)) eeprom_file.close() return True - + class Eeprom(eeprom_tlvinfo.TlvInfoDecoder): def __init__(self): self.__eeprom_path = "/sys/class/i2c-adapter/i2c-0/0-0051/eeprom" @@ -371,7 +375,7 @@ def platform_str(self): def MACsize_str(self): (is_valid, t) = self.get_tlv_field(self.__eeprom_data, self._TLV_CODE_MAC_SIZE) - + if not is_valid: return "N/A" @@ -402,7 +406,7 @@ def onie_version_str(self): for c in results[2:2 + ord(results[1])]: value += "0x%02X " % (ord(c),) - + return value def vendor_ext_str(self): diff --git a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/qfx5200_sfp_init.py b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/qfx5200_sfp_init.py index 3f33e4dc152a..374b5322f2dd 100644 --- a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/qfx5200_sfp_init.py +++ b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/qfx5200_sfp_init.py @@ -2,14 +2,14 @@ # # Name: juniper_sfp_init.py version: 1.0 # -# Description: Platform-specific SFP Transceiver Initialization for Juniper QFX5200 +# Description: Platform-specific SFP Transceiver Initialization for Juniper QFX5200 # # Copyright (c) 2020, Juniper Networks, Inc. # All rights reserved. # -# Notice and Disclaimer: This code is licensed to you under the GNU General -# Public License as published by the Free Software Foundation, version 3 or -# any later version. This code is not an official Juniper product. You can +# Notice and Disclaimer: This code is licensed to you under the GNU General +# Public License as published by the Free Software Foundation, version 3 or +# any later version. This code is not an official Juniper product. You can # obtain a copy of the License at # # OSS License: @@ -27,9 +27,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . # -# Third-Party Code: This code may depend on other components under separate -# copyright notice and license terms. Your use of the source code for those -# components is subject to the terms and conditions of the respective license +# Third-Party Code: This code may depend on other components under separate +# copyright notice and license terms. Your use of the source code for those +# components is subject to the terms and conditions of the respective license # as noted in the Third-Party source code file. import time @@ -57,7 +57,7 @@ def i2c_eeprom_dev_update(port, create_eeprom): i2c_file = open(port_i2c_path + "/new_device", "w") i2c_file.write("optoe2 0x50") except IOError as e: - print "Error: unable to write to i2c file: %s" % str(e) + print("Error: unable to write to i2c file: %s" % str(e)) return else: if os.path.exists(port_eeprom_path): @@ -65,7 +65,7 @@ def i2c_eeprom_dev_update(port, create_eeprom): i2c_file = open(port_i2c_path + "/delete_device", "w") i2c_file.write("0x50") except IOError as e: - print "Error: unable to write to i2c file: %s" % str(e) + print("Error: unable to write to i2c file: %s" % str(e)) return def gpio_sfp_init(): @@ -76,7 +76,7 @@ def gpio_sfp_init(): #Reset all ports for port in range(jnpr_sfp.GPIO_PORT_START, jnpr_sfp.GPIO_PORT_END + 1): logger.log_debug("GPIO SFP port {}".format(port)) - + jnpr_sfp.gpio_sfp_reset_set(port, 0) i2c_eeprom_dev_update(port, True) @@ -90,13 +90,13 @@ def gpio_sfp_init(): if __name__ == '__main__': if DEBUG == True: - print "Initializing Juniper SFP module" + print("Initializing Juniper SFP module") gpio_sfp_init() if DEBUG == True: - print "Juniper GPIO presence pin mapping:" + print("Juniper GPIO presence pin mapping:") pprint(jnpr_sfp.gpio_sfp_presence) - print "Juniper GPIO reset pin mapping:" + print("Juniper GPIO reset pin mapping:") pprint(jnpr_sfp.gpio_sfp_reset) - print "Juniper GPIO lpmode pin mapping:" + print("Juniper GPIO lpmode pin mapping:") pprint(jnpr_sfp.gpio_sfp_lpmode) diff --git a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/sfputil.py b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/sfputil.py index 91957139967d..288c8b58e768 100644 --- a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/sfputil.py +++ b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/sfputil.py @@ -2,14 +2,14 @@ # # Name: sfputil.py version: 1.0 # -# Description: Platform-specific SFP transceiver interface for Juniper QFX5200 +# Description: Platform-specific SFP transceiver interface for Juniper QFX5200 # # Copyright (c) 2020, Juniper Networks, Inc. # All rights reserved. # -# Notice and Disclaimer: This code is licensed to you under the GNU General -# Public License as published by the Free Software Foundation, version 3 or -# any later version. This code is not an official Juniper product. You can +# Notice and Disclaimer: This code is licensed to you under the GNU General +# Public License as published by the Free Software Foundation, version 3 or +# any later version. This code is not an official Juniper product. You can # obtain a copy of the License at # # OSS License: @@ -27,9 +27,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . # -# Third-Party Code: This code may depend on other components under separate -# copyright notice and license terms. Your use of the source code for those -# components is subject to the terms and conditions of the respective license +# Third-Party Code: This code may depend on other components under separate +# copyright notice and license terms. Your use of the source code for those +# components is subject to the terms and conditions of the respective license # as noted in the Third-Party source code file. try: @@ -56,17 +56,17 @@ qfx5200_qsfp_cable_length_tup = ('Length(km)', 'Length OM3(2m)', 'Length OM2(m)', 'Length OM1(m)', 'Length Cable Assembly(m)') - + qfx5200_sfp_cable_length_tup = ('LengthSMFkm-UnitsOfKm', 'LengthSMF(UnitsOf100m)', 'Length50um(UnitsOf10m)', 'Length62.5um(UnitsOfm)', 'LengthCable(UnitsOfm)', 'LengthOM3(UnitsOf10m)') - + qfx5200_sfp_compliance_code_tup = ('10GEthernetComplianceCode', 'InfinibandComplianceCode', 'ESCONComplianceCodes', 'SONETComplianceCodes', 'EthernetComplianceCodes','FibreChannelLinkLength', 'FibreChannelTechnology', 'SFP+CableTechnology', 'FibreChannelTransmissionMedia','FibreChannelSpeed') - + qfx5200_qsfp_compliance_code_tup = ('10/40G Ethernet Compliance Code', 'SONET Compliance codes', 'SAS/SATA compliance codes', 'Gigabit Ethernet Compliant codes', 'Fibre Channel link length/Transmitter Technology', @@ -155,9 +155,9 @@ def gpio_create_file(gpio_pin): gpio_export_file.write(str(gpio_pin)) gpio_export_file.close() except IOError as e: - print "Error: unable to open export file: %s" % str(e) + print("Error: unable to open export file: %s" % str(e)) return False - + return True def gpio_sfp_port_init(gpio_base, port): @@ -179,9 +179,9 @@ def gpio_sfp_slave_init(gpio_base_path, gpio_port_start, gpio_port_end): fp = open(flist[0]+"/base") gpio_base = int(fp.readline().rstrip()) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return - + for port in range(gpio_port_start, gpio_port_end + 1): gpio_sfp_port_init(gpio_base, port) @@ -199,8 +199,8 @@ def gpio_sfp_read(gpio_pin): reg_file = open(gpio_pin_path +"/value") value = int(reg_file.readline().rstrip()) except IOError as e: - print "error: unable to open file: %s" % str(e) - + print("error: unable to open file: %s" % str(e)) + return value def gpio_sfp_write(gpio_pin, value): @@ -212,34 +212,34 @@ def gpio_sfp_write(gpio_pin, value): gpio_file.write(str(value)) success = True except IOError as e: - print "error: unable to open file: %s" % str(e) + print("error: unable to open file: %s" % str(e)) return success def gpio_sfp_presence_get(port): - if port not in gpio_sfp_presence.keys(): - print "Port:" + str(port) + " not in sfp dict" + if port not in list(gpio_sfp_presence.keys()): + print("Port:" + str(port) + " not in sfp dict") return 0 gpio_pin = gpio_sfp_presence[port] return gpio_sfp_read(gpio_pin) def gpio_sfp_lpmode_get(port): - if port not in gpio_sfp_lpmode.keys(): + if port not in list(gpio_sfp_lpmode.keys()): return 0 gpio_pin = gpio_sfp_lpmode[port] return gpio_sfp_read(gpio_pin) def gpio_sfp_lpmode_set(port, value): - if port not in gpio_sfp_lpmode.keys(): + if port not in list(gpio_sfp_lpmode.keys()): return False gpio_pin = gpio_sfp_lpmode[port] return gpio_sfp_write(gpio_pin, value) def gpio_sfp_reset_set(port, value): - if port not in gpio_sfp_reset.keys(): + if port not in list(gpio_sfp_reset.keys()): return False gpio_pin = gpio_sfp_reset[port] @@ -291,7 +291,7 @@ class SfpUtil(SfpUtilBase): 30: 44, 31: 45 } - + port_ctle_settings = { 0: 119, # 0x77 1: 102, # 0x66 @@ -309,7 +309,7 @@ class SfpUtil(SfpUtilBase): 13: 85, # 0x55 14: 68, # 0x44 15: 51, # 0x33 - 16: 68, # 0x44 + 16: 68, # 0x44 17: 85, # 0x55 18: 102, # 0x66 19: 102, # 0x66 @@ -323,7 +323,7 @@ class SfpUtil(SfpUtilBase): 27: 85, # 0x55 28: 102, # 0x66 29: 102, # 0x66 - 30: 119, # 0x77 + 30: 119, # 0x77 31: 119 # 0x77 } @@ -362,7 +362,7 @@ def set_bit(self, data, pos): def is_100g_optics(self, part_num): ret = part_num in self.optics_list_100g return ret - + def is_40g_optics(self, part_num): ret = part_num in self.optics_list_40g return ret @@ -379,7 +379,7 @@ def process_TxCTLE(self, eeprom, port_num, part_num): if self.is_100g_optics(part_num): logger.log_debug(" QFX5200: TxCTLE port {} and SFP PN NUM {} ".format(port_num,part_num)) # Accessing page 3 of optics - regval = 3 + regval = 3 buffer = create_string_buffer(1) buffer[0] = chr(regval) eeprom.seek(127) @@ -425,7 +425,7 @@ def qsfp_port_end(self): @property def qsfp_ports(self): - return range(0, self.PORTS_IN_BLOCK + 1) + return list(range(0, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -436,12 +436,12 @@ def __init__(self): eeprom_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-0050/eeprom" for x in range(0, self.port_end + 1): self.port_to_eeprom_mapping[x] = eeprom_path.format(self.port_to_i2cbus_mapping[x]) - + logger.log_debug("QFX5200: SfpUtil __init__") if os.path.isfile(self.cmd): logger.log_debug("QFX5200: SfpUtil removing sfppresence file") os.remove(self.cmd) - + SfpUtilBase.__init__(self) def get_presence(self, port_num): @@ -464,7 +464,7 @@ def set_low_power_mode(self, port_num, lpmode): lpmode = 1 else: lpmode = 0 - + status = gpio_sfp_lpmode_set(port_num, lpmode) return status @@ -478,7 +478,7 @@ def write_to_file(self, file_name, from_list): try: fp1 = open(file_name, 'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False for i in from_list: @@ -488,13 +488,13 @@ def write_to_file(self, file_name, from_list): fp1.close() return True - + # Reading from a file to a list def read_from_file(self, file_name): try: fp = open(file_name, 'r') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False to_list = fp.readlines() @@ -771,10 +771,10 @@ def get_transceiver_info_dict(self, port_num): if key in sfp_interface_bulk_data['data']['Specification compliance']['value']: compliance_code_dict[key] = sfp_interface_bulk_data['data']['Specification compliance']['value'][key]['value'] transceiver_info_dict['specification_compliance'] = str(compliance_code_dict) - - if sfp_interface_bulk_data['data'].has_key('Nominal Bit Rate(100Mbs)'): + + if 'Nominal Bit Rate(100Mbs)' in sfp_interface_bulk_data['data']: transceiver_info_dict['nominal_bit_rate'] = str(sfp_interface_bulk_data['data']['Nominal Bit Rate(100Mbs)']['value']) - else: + else: transceiver_info_dict['nominal_bit_rate'] = 'N/A' else: for key in qfx5200_sfp_cable_length_tup: @@ -784,17 +784,17 @@ def get_transceiver_info_dict(self, port_num): else: transceiver_info_dict['cable_type'] = key transceiver_info_dict['cable_length'] = 'N/A' - + for key in qfx5200_sfp_compliance_code_tup: if key in sfp_interface_bulk_data['data']['Specification compliance']['value']: compliance_code_dict[key] = sfp_interface_bulk_data['data']['Specification compliance']['value'][key]['value'] transceiver_info_dict['specification_compliance'] = str(compliance_code_dict) - if sfp_interface_bulk_data['data'].has_key('NominalSignallingRate(UnitsOf100Mbd)'): + if 'NominalSignallingRate(UnitsOf100Mbd)' in sfp_interface_bulk_data['data']: transceiver_info_dict['nominal_bit_rate'] = str(sfp_interface_bulk_data['data']['NominalSignallingRate(UnitsOf100Mbd)']['value']) - else: + else: transceiver_info_dict['nominal_bit_rate'] = 'N/A' - + logger.log_debug("QFX5200: get_transceiver_info_dict End") return transceiver_info_dict @@ -1061,14 +1061,14 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): except IOError: print("Error: reading sysfs file %s" % file_path) return None - + sfpd_obj = sff8472Dom(None,1) if sfpd_obj is None: return transceiver_dom_threshold_info_dict - - dom_module_threshold_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, + + dom_module_threshold_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_MODULE_THRESHOLD_OFFSET), SFP_MODULE_THRESHOLD_WIDTH) - + if dom_module_threshold_raw is not None: dom_module_threshold_data = sfpd_obj.parse_alarm_warning_threshold(dom_module_threshold_raw, 0) else: @@ -1101,7 +1101,7 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): transceiver_dom_threshold_info_dict['rxpowerlowalarm'] = dom_module_threshold_data['data']['RXPowerLowAlarm']['value'] transceiver_dom_threshold_info_dict['rxpowerhighwarning'] = dom_module_threshold_data['data']['RXPowerHighWarning']['value'] transceiver_dom_threshold_info_dict['rxpowerlowwarning'] = dom_module_threshold_data['data']['RXPowerLowWarning']['value'] - + logger.log_debug("QFX5200: get_transceiver_dom_threshold_info_dict End") return transceiver_dom_threshold_info_dict diff --git a/device/juniper/x86_64-juniper_qfx5210-r0/plugins/qfx5210_eeprom_data.py b/device/juniper/x86_64-juniper_qfx5210-r0/plugins/qfx5210_eeprom_data.py index 973a2abe492b..eae6b42dd8e5 100644 --- a/device/juniper/x86_64-juniper_qfx5210-r0/plugins/qfx5210_eeprom_data.py +++ b/device/juniper/x86_64-juniper_qfx5210-r0/plugins/qfx5210_eeprom_data.py @@ -2,14 +2,14 @@ # # Name: juniper_qfx5210_eepromconv.py version: 1.0 # -# Description: This file contains the code to store the contents of Board EEPROM in file +# Description: This file contains the code to store the contents of Board EEPROM in file # # Copyright (c) 2020, Juniper Networks, Inc. # All rights reserved. # -# Notice and Disclaimer: This code is licensed to you under the GNU General -# Public License as published by the Free Software Foundation, version 3 or -# any later version. This code is not an official Juniper product. You can +# Notice and Disclaimer: This code is licensed to you under the GNU General +# Public License as published by the Free Software Foundation, version 3 or +# any later version. This code is not an official Juniper product. You can # obtain a copy of the License at # # OSS License: @@ -27,34 +27,33 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . # -# Third-Party Code: This code may depend on other components under separate -# copyright notice and license terms. Your use of the source code for those -# components is subject to the terms and conditions of the respective license +# Third-Party Code: This code may depend on other components under separate +# copyright notice and license terms. Your use of the source code for those +# components is subject to the terms and conditions of the respective license # as noted in the Third-Party source code file. import os -import commands import binascii from sonic_eeprom import eeprom_tlvinfo def main(): eeprom_qfx5210 = Eeprom() - FANTYPE_PATH = '/sys/bus/i2c/devices/17-0068/fan1_direction' + FANTYPE_PATH = '/sys/bus/i2c/devices/17-0068/fan1_direction' isPlatformAFO = False try: fan_type_file = open(FANTYPE_PATH) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) fan_type = -1 else: fan_type = fan_type_file.read() fan_type_file.close() - + if (int(fan_type) == -1 or int(fan_type) == 0): if (int(fan_type) == -1): - print "unable to open sys file for fan handling, defaulting it to AFO" - + print("unable to open sys file for fan handling, defaulting it to AFO") + isPlatformAFO = True else: isPlatformAFO = False @@ -67,7 +66,7 @@ def main(): else: eeprom_file.write("Fan Type=AFI\r\n") eeprom_file.write("\n") - + # Write the contents of CPU Board EEPROM to file eeprom_file.write("CPU Board EEPROM (0x56)\r\n") eeprom_file.write("===============================\r\n") @@ -81,12 +80,12 @@ def main(): eeprom_file.write("Vendor Name=%s\r\n" % eeprom_qfx5210.vendor_name_str()) eeprom_file.write("Manufacture Name=%s\r\n" % eeprom_qfx5210.manufacture_name_str()) - CPUeepromFileCmd = 'cat /sys/devices/pci0000:00/0000:00:1f.3/i2c-0/0-0056/eeprom > /etc/init.d/eeprom_qfx5210_ascii' + CPUeepromFileCmd = 'cat /sys/devices/pci0000:00/0000:00:1f.3/i2c-0/0-0056/eeprom > /etc/init.d/eeprom_qfx5210_ascii' # Write the contents of CPU EEPROM to file try: os.system(CPUeepromFileCmd) except OSError: - print 'Error: Execution of "%s" failed', CPUeepromFileCmd + print('Error: Execution of "%s" failed', CPUeepromFileCmd) return False eeprom_ascii = '/etc/init.d/eeprom_qfx5210_ascii' @@ -94,11 +93,11 @@ def main(): with open(eeprom_ascii, 'rb') as Hexformat: content = Hexformat.read() Hexformatoutput = binascii.hexlify(content) - + eeprom_hex = '/etc/init.d/eeprom_qfx5210_hex' with open(eeprom_hex, 'wb+') as Hexfile: Hexfile.write(Hexformatoutput) - + #Write contents of CPU EEPROM to new file in hexa format with open(eeprom_hex, 'rb') as eeprom_hexfile: eeprom_hexfile.seek(350, 0) @@ -146,10 +145,10 @@ def main(): CLEI_read = eeprom_hexfile.read(20) CLEI_name = binascii.unhexlify(CLEI_read) eeprom_file.write("CLEI code=%s\r\n" % str(CLEI_name)) - + eeprom_dict = eeprom_qfx5210.system_eeprom_info() key = '0x29' - if key in eeprom_dict.keys(): + if key in list(eeprom_dict.keys()): onie_version_str = eeprom_dict.get('0x29', None) else: onie_version_str = "N/A" @@ -159,7 +158,7 @@ def main(): eeprom_file.write("CRC=%s\r\n" % crc_str) eeprom_file.close() return True - + class Eeprom(eeprom_tlvinfo.TlvInfoDecoder): def __init__(self): self.__eeprom_path = "/sys/class/i2c-adapter/i2c-0/0-0056/eeprom" @@ -266,7 +265,7 @@ def platform_str(self): def MACsize_str(self): (is_valid, t) = self.get_tlv_field(self.__eeprom_data, self._TLV_CODE_MAC_SIZE) - + if not is_valid: return "N/A" @@ -297,7 +296,7 @@ def onie_version_str(self): for c in results[2:2 + ord(results[1])]: value += "0x%02X " % (ord(c),) - + return value def vendor_ext_str(self): diff --git a/device/juniper/x86_64-juniper_qfx5210-r0/plugins/sfputil.py b/device/juniper/x86_64-juniper_qfx5210-r0/plugins/sfputil.py index 034a2e68bad5..fc5b10a4b481 100644 --- a/device/juniper/x86_64-juniper_qfx5210-r0/plugins/sfputil.py +++ b/device/juniper/x86_64-juniper_qfx5210-r0/plugins/sfputil.py @@ -9,7 +9,7 @@ import string from ctypes import create_string_buffer from sonic_py_common.logger import Logger -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") SYSLOG_IDENTIFIER = "sfputil" @@ -18,7 +18,7 @@ qfx5210_qsfp_cable_length_tup = ('Length(km)', 'Length OM3(2m)', 'Length OM2(m)', 'Length OM1(m)', 'Length Cable Assembly(m)') - + qfx5210_sfp_cable_length_tup = ('LengthSMFkm-UnitsOfKm', 'LengthSMF(UnitsOf100m)', 'Length50um(UnitsOf10m)', 'Length62.5um(UnitsOfm)', 'LengthCable(UnitsOfm)', 'LengthOM3(UnitsOf10m)') @@ -42,7 +42,7 @@ class SfpUtil(SfpUtilBase): _port_start = 0 _port_end = 63 ports_in_block = 64 - cmd = '/var/run/sfppresence' + cmd = '/var/run/sfppresence' _port_to_eeprom_mapping = {} port_to_i2c_mapping = { 60 : 25, @@ -111,7 +111,7 @@ class SfpUtil(SfpUtilBase): 51 : 88,} # sys.path.append('/usr/local/bin') - _qsfp_ports = range(0, ports_in_block + 1) + _qsfp_ports = list(range(0, ports_in_block + 1)) def __init__(self): @@ -127,11 +127,11 @@ def reset(self, port_num): return False path = "/sys/bus/i2c/devices/19-0060/module_reset_{0}" port_ps = path.format(port_num+1) - + try: reg_file = open(port_ps, 'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False #HW will clear reset after set. @@ -139,7 +139,7 @@ def reset(self, port_num): reg_file.write('1') reg_file.close() return True - + def get_presence(self, port_num): # Check for invalid port_num if port_num < self._port_start or port_num > self._port_end: @@ -151,7 +151,7 @@ def get_presence(self, port_num): try: reg_file = open(port_ps) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_file.readline().rstrip() @@ -167,12 +167,12 @@ def port_start(self): @property def port_end(self): return self._port_end - + @property def qsfp_ports(self): - return range(0, self.ports_in_block + 1) + return list(range(0, self.ports_in_block + 1)) - @property + @property def port_to_eeprom_mapping(self): return self._port_to_eeprom_mapping @@ -181,7 +181,7 @@ def write_to_file(self, file_name, from_list): try: fp1 = open(file_name, 'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False for i in from_list: @@ -191,20 +191,20 @@ def write_to_file(self, file_name, from_list): fp1.close() return True - + # Reading from a file to a list def read_from_file(self, file_name): try: fp = open(file_name, 'r') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False to_list = fp.readlines() to_list = [x.rstrip() for x in to_list] fp.close() return to_list - + def sfp_detect(self): x = 0 ret_dict = {} @@ -228,7 +228,7 @@ def sfp_detect(self): new_path = path.format(x + 1) reg_file = open(new_path, 'r') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False, defl_dict sfp_present = reg_file.readline().rstrip() @@ -266,16 +266,16 @@ def get_low_power_mode(self, port_num): else: return 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 + # 2. "Power override" bit is 1 and "Power set" bit is 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 is not None: eeprom.close() time.sleep(0.01) - def set_low_power_mode(self, port_num, lpmode): + def set_low_power_mode(self, port_num, lpmode): # Check for invalid port_num if port_num < self._port_start or port_num > self._port_end: return False @@ -297,7 +297,7 @@ def set_low_power_mode(self, port_num, lpmode): eeprom.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 is not None: @@ -496,10 +496,10 @@ def get_transceiver_info_dict(self, port_num): if key in sfp_interface_bulk_data['data']['Specification compliance']['value']: compliance_code_dict[key] = sfp_interface_bulk_data['data']['Specification compliance']['value'][key]['value'] transceiver_info_dict['specification_compliance'] = str(compliance_code_dict) - - if sfp_interface_bulk_data['data'].has_key('Nominal Bit Rate(100Mbs)'): + + if 'Nominal Bit Rate(100Mbs)' in sfp_interface_bulk_data['data']: transceiver_info_dict['nominal_bit_rate'] = str(sfp_interface_bulk_data['data']['Nominal Bit Rate(100Mbs)']['value']) - else: + else: transceiver_info_dict['nominal_bit_rate'] = 'N/A' else: for key in qfx5210_sfp_cable_length_tup: @@ -509,18 +509,18 @@ def get_transceiver_info_dict(self, port_num): else: transceiver_info_dict['cable_type'] = key transceiver_info_dict['cable_length'] = 'N/A' - + for key in qfx5210_sfp_compliance_code_tup: if key in sfp_interface_bulk_data['data']['Specification compliance']['value']: compliance_code_dict[key] = sfp_interface_bulk_data['data']['Specification compliance']['value'][key]['value'] transceiver_info_dict['specification_compliance'] = str(compliance_code_dict) - if sfp_interface_bulk_data['data'].has_key('NominalSignallingRate(UnitsOf100Mbd)'): + if 'NominalSignallingRate(UnitsOf100Mbd)' in sfp_interface_bulk_data['data']: transceiver_info_dict['nominal_bit_rate'] = str(sfp_interface_bulk_data['data']['NominalSignallingRate(UnitsOf100Mbd)']['value']) - else: + else: transceiver_info_dict['nominal_bit_rate'] = 'N/A' #transceiver_info_dict['nominal_bit_rate'] = str(sfp_interface_bulk_data['data']['NominalSignallingRate(UnitsOf100Mbd)']['value']) - + return transceiver_info_dict def get_transceiver_dom_info_dict(self, port_num): @@ -696,7 +696,7 @@ def get_transceiver_dom_info_dict(self, port_num): transceiver_dom_info_dict['tx4power'] = 'N/A' return transceiver_dom_info_dict - + def get_transceiver_dom_threshold_info_dict(self, port_num): transceiver_dom_threshold_info_dict = {} dom_info_dict_keys = ['temphighalarm', 'temphighwarning', @@ -784,14 +784,14 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): except IOError: print("Error: reading sysfs file %s" % file_path) return None - + sfpd_obj = sff8472Dom(None,1) if sfpd_obj is None: return transceiver_dom_threshold_info_dict - - dom_module_threshold_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, + + dom_module_threshold_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_MODULE_THRESHOLD_OFFSET), SFP_MODULE_THRESHOLD_WIDTH) - + if dom_module_threshold_raw is not None: dom_module_threshold_data = sfpd_obj.parse_alarm_warning_threshold(dom_module_threshold_raw, 0) else: @@ -824,6 +824,6 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): transceiver_dom_threshold_info_dict['rxpowerlowalarm'] = dom_module_threshold_data['data']['RXPowerLowAlarm']['value'] transceiver_dom_threshold_info_dict['rxpowerhighwarning'] = dom_module_threshold_data['data']['RXPowerHighWarning']['value'] transceiver_dom_threshold_info_dict['rxpowerlowwarning'] = dom_module_threshold_data['data']['RXPowerLowWarning']['value'] - + logger.log_debug("QFX5210: get_transceiver_dom_threshold_info_dict End") return transceiver_dom_threshold_info_dict diff --git a/device/marvell/arm64-marvell_db98cx8580_16cd-r0/plugins/sfputil.py b/device/marvell/arm64-marvell_db98cx8580_16cd-r0/plugins/sfputil.py index da13b129a9a3..2ba575ba8cea 100644 --- a/device/marvell/arm64-marvell_db98cx8580_16cd-r0/plugins/sfputil.py +++ b/device/marvell/arm64-marvell_db98cx8580_16cd-r0/plugins/sfputil.py @@ -5,21 +5,20 @@ import time import sys import re - import subprocess from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") if sys.version_info[0] < 3: - import commands as cmd + import commands else: - import subprocess as cmd + import subprocess as commands smbus_present = 1 try: import smbus -except ImportError, e: +except ImportError as e: smbus_present = 0 class SfpUtil(SfpUtilBase): @@ -30,7 +29,7 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} - _qsfp_ports = range(_port_start, ports_in_block + 1) + _qsfp_ports = list(range(_port_start, ports_in_block + 1)) def __init__(self): os.system("modprobe i2c-dev") @@ -51,11 +50,11 @@ def reset(self, port_num): return False port_ps = "/sys/bus/i2c/devices/0-0050/sfp_port_reset" - + try: reg_file = open(port_ps, 'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False #toggle reset @@ -77,7 +76,7 @@ def i2c_get(self, device_addr, offset): status = 0 if smbus_present == 0: x = "i2cget -y 0 " + hex(device_addr) + " " + hex(offset) - cmdstatus, status = cmd.getstatusoutput(x) + cmdstatus, status = commands.getstatusoutput(x) if cmdstatus != 0: return cmdstatus status = int(status, 16) @@ -93,7 +92,7 @@ def i2c_set(self, device_addr, offset, value): else: bus = smbus.SMBus(0) bus.write_byte_data(device_addr, offset, value) - + def get_presence(self, port_num): # Check for invalid port_num if port_num < self._port_start or port_num > self._port_end: @@ -122,8 +121,8 @@ def get_presence(self, port_num): path = "/sys/bus/i2c/devices/0-0050/eeprom" try: reg_file = open(path) - reg_file.seek(01) - reg_file.read(02) + reg_file.seek(0o1) + reg_file.read(0o2) except IOError as e: return False @@ -177,7 +176,7 @@ def read_porttab_mappings(self, porttabfile): # Leave the old code for backward compatibility #if len(line.split()) >= 4: # fp_port_index = (line.split()[3]) - # print(fp_port_index) + # print(fp_port_index) else: fp_port_index = portname.split("Ethernet").pop() fp_port_index = int(fp_port_index.split("s").pop(0))+1 @@ -226,7 +225,7 @@ def read_porttab_mappings(self, porttabfile): self.logical_to_physical = logical_to_physical self.physical_to_logical = physical_to_logical - + #print(self.logical_to_physical) '''print("logical: " + self.logical) print("logical to bcm: " + self.logical_to_bcm) @@ -241,15 +240,15 @@ def port_start(self): @property def port_end(self): return self._port_end - + @property def qsfp_ports(self): return self._qsfp_ports - @property + @property def port_to_eeprom_mapping(self): return self._port_to_eeprom_mapping - + @property def get_transceiver_change_event(self): - raise NotImplementedError + raise NotImplementedError diff --git a/device/marvell/arm64-marvell_db98cx8580_32cd-r0/plugins/sfputil.py b/device/marvell/arm64-marvell_db98cx8580_32cd-r0/plugins/sfputil.py index 80b11bf0630e..72c2e1944743 100644 --- a/device/marvell/arm64-marvell_db98cx8580_32cd-r0/plugins/sfputil.py +++ b/device/marvell/arm64-marvell_db98cx8580_32cd-r0/plugins/sfputil.py @@ -5,21 +5,20 @@ import time import sys import re - import subprocess from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") if sys.version_info[0] < 3: - import commands as cmd + import commands else: - import subprocess as cmd + import subprocess as commands smbus_present = 1 try: import smbus -except ImportError, e: +except ImportError as e: smbus_present = 0 class SfpUtil(SfpUtilBase): @@ -30,7 +29,7 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} - _qsfp_ports = range(_port_start, ports_in_block + 1) + _qsfp_ports = list(range(_port_start, ports_in_block + 1)) def __init__(self): os.system("modprobe i2c-dev") @@ -51,11 +50,11 @@ def reset(self, port_num): return False port_ps = "/sys/bus/i2c/devices/0-0050/sfp_port_reset" - + try: reg_file = open(port_ps, 'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False #toggle reset @@ -77,7 +76,7 @@ def i2c_get(self, device_addr, offset): status = 0 if smbus_present == 0: x = "i2cget -y 0 " + hex(device_addr) + " " + hex(offset) - cmdstatus, status = cmd.getstatusoutput(x) + cmdstatus, status = commands.getstatusoutput(x) if cmdstatus != 0: return cmdstatus status = int(status, 16) @@ -93,7 +92,7 @@ def i2c_set(self, device_addr, offset, value): else: bus = smbus.SMBus(0) bus.write_byte_data(device_addr, offset, value) - + def get_presence(self, port_num): # Check for invalid port_num if port_num < self._port_start or port_num > self._port_end: @@ -128,8 +127,8 @@ def get_presence(self, port_num): path = "/sys/bus/i2c/devices/0-0050/eeprom" try: reg_file = open(path) - reg_file.seek(01) - reg_file.read(02) + reg_file.seek(0o1) + reg_file.read(0o2) except IOError as e: return False @@ -183,7 +182,7 @@ def read_porttab_mappings(self, porttabfile): # Leave the old code for backward compatibility #if len(line.split()) >= 4: # fp_port_index = (line.split()[3]) - # print(fp_port_index) + # print(fp_port_index) else: fp_port_index = portname.split("Ethernet").pop() fp_port_index = int(fp_port_index.split("s").pop(0))+1 @@ -232,7 +231,7 @@ def read_porttab_mappings(self, porttabfile): self.logical_to_physical = logical_to_physical self.physical_to_logical = physical_to_logical - + #print(self.logical_to_physical) '''print("logical: " + self.logical) print("logical to bcm: " + self.logical_to_bcm) @@ -247,15 +246,15 @@ def port_start(self): @property def port_end(self): return self._port_end - + @property def qsfp_ports(self): return self._qsfp_ports - @property + @property def port_to_eeprom_mapping(self): return self._port_to_eeprom_mapping - + @property def get_transceiver_change_event(self): - raise NotImplementedError + raise NotImplementedError diff --git a/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/psuutil.py b/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/psuutil.py index 16965414e64b..298acfc5c0ed 100755 --- a/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/psuutil.py +++ b/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/psuutil.py @@ -3,15 +3,15 @@ import sys import os.path if sys.version_info[0] < 3: - import commands as cmd + import commands else: - import subprocess as cmd + import subprocess as commands smbus_present = 1 try: import smbus except ImportError as e: - smbus_present = 0 + smbus_present = 0 try: from sonic_psu.psu_base import PsuBase @@ -32,8 +32,8 @@ def get_num_psus(self): def get_psu_status(self, index): if index is None: return False - if smbus_present == 0: - cmdstatus, psustatus = cmd.getstatusoutput('i2cget -y 0 0x41 0xa') #need to verify the cpld register logic + if smbus_present == 0: + cmdstatus, psustatus = commands.getstatusoutput('i2cget -y 0 0x41 0xa') #need to verify the cpld register logic psustatus = int(psustatus, 16) else : bus = smbus.SMBus(0) @@ -48,15 +48,15 @@ def get_psu_status(self, index): psustatus = psustatus&8 if psustatus == 8 : return True - + return False def get_psu_presence(self, index): if index is None: return False - if smbus_present == 0: - cmdstatus, psustatus = cmd.getstatusoutput('i2cget -y 0 0x41 0xa') #need to verify the cpld register logic + if smbus_present == 0: + cmdstatus, psustatus = commands.getstatusoutput('i2cget -y 0 0x41 0xa') #need to verify the cpld register logic psustatus = int(psustatus, 16) else : bus = smbus.SMBus(0) diff --git a/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/sfputil.py b/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/sfputil.py index 431d2bc615aa..252ec9cd9930 100755 --- a/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/sfputil.py +++ b/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/sfputil.py @@ -7,19 +7,19 @@ import sys import glob from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") if sys.version_info[0] < 3: - import commands as cmd + import commands else: - import subprocess as cmd + import subprocess as commands smbus_present = 1 try: import smbus -except ImportError, e: +except ImportError as e: smbus_present = 0 class SfpUtil(SfpUtilBase): @@ -37,7 +37,7 @@ class SfpUtil(SfpUtilBase): 52 : 5 } - _qsfp_ports = range(_port_start, ports_in_block + 1) + _qsfp_ports = list(range(_port_start, ports_in_block + 1)) _changed_ports = [0,0,0,0] def __init__(self): @@ -83,7 +83,7 @@ def reset(self, port_num): try: reg_file = open(port_ps, 'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False #toggle reset @@ -113,9 +113,9 @@ def get_presence(self, port_num): pos = [1,2,4,8] bit_pos = pos[prt] if smbus_present == 0: - cmdstatus, sfpstatus = cmd.getstatusoutput('i2cget -y 0 0x41 0x3') #need to verify the cpld register logic + cmdstatus, sfpstatus = commands.getstatusoutput('i2cget -y 0 0x41 0x3') #need to verify the cpld register logic sfpstatus = int(sfpstatus, 16) - else : + else: bus = smbus.SMBus(0) DEVICE_ADDRESS = 0x41 DEVICE_REG = 0x3 @@ -126,7 +126,7 @@ def get_presence(self, port_num): return True return False - + def read_porttab_mappings(self, porttabfile): logical = [] logical_to_physical = {} @@ -235,7 +235,7 @@ def get_transceiver_change_event(self, timeout): port = 0 if timeout == 0: - cd_ms = sys.maxint + cd_ms = sys.maxsize else: cd_ms = timeout changed_port = 0 diff --git a/device/marvell/x86_64-marvell_db98cx8580_16cd-r0/plugins/sfputil.py b/device/marvell/x86_64-marvell_db98cx8580_16cd-r0/plugins/sfputil.py index da13b129a9a3..2ba575ba8cea 100644 --- a/device/marvell/x86_64-marvell_db98cx8580_16cd-r0/plugins/sfputil.py +++ b/device/marvell/x86_64-marvell_db98cx8580_16cd-r0/plugins/sfputil.py @@ -5,21 +5,20 @@ import time import sys import re - import subprocess from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") if sys.version_info[0] < 3: - import commands as cmd + import commands else: - import subprocess as cmd + import subprocess as commands smbus_present = 1 try: import smbus -except ImportError, e: +except ImportError as e: smbus_present = 0 class SfpUtil(SfpUtilBase): @@ -30,7 +29,7 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} - _qsfp_ports = range(_port_start, ports_in_block + 1) + _qsfp_ports = list(range(_port_start, ports_in_block + 1)) def __init__(self): os.system("modprobe i2c-dev") @@ -51,11 +50,11 @@ def reset(self, port_num): return False port_ps = "/sys/bus/i2c/devices/0-0050/sfp_port_reset" - + try: reg_file = open(port_ps, 'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False #toggle reset @@ -77,7 +76,7 @@ def i2c_get(self, device_addr, offset): status = 0 if smbus_present == 0: x = "i2cget -y 0 " + hex(device_addr) + " " + hex(offset) - cmdstatus, status = cmd.getstatusoutput(x) + cmdstatus, status = commands.getstatusoutput(x) if cmdstatus != 0: return cmdstatus status = int(status, 16) @@ -93,7 +92,7 @@ def i2c_set(self, device_addr, offset, value): else: bus = smbus.SMBus(0) bus.write_byte_data(device_addr, offset, value) - + def get_presence(self, port_num): # Check for invalid port_num if port_num < self._port_start or port_num > self._port_end: @@ -122,8 +121,8 @@ def get_presence(self, port_num): path = "/sys/bus/i2c/devices/0-0050/eeprom" try: reg_file = open(path) - reg_file.seek(01) - reg_file.read(02) + reg_file.seek(0o1) + reg_file.read(0o2) except IOError as e: return False @@ -177,7 +176,7 @@ def read_porttab_mappings(self, porttabfile): # Leave the old code for backward compatibility #if len(line.split()) >= 4: # fp_port_index = (line.split()[3]) - # print(fp_port_index) + # print(fp_port_index) else: fp_port_index = portname.split("Ethernet").pop() fp_port_index = int(fp_port_index.split("s").pop(0))+1 @@ -226,7 +225,7 @@ def read_porttab_mappings(self, porttabfile): self.logical_to_physical = logical_to_physical self.physical_to_logical = physical_to_logical - + #print(self.logical_to_physical) '''print("logical: " + self.logical) print("logical to bcm: " + self.logical_to_bcm) @@ -241,15 +240,15 @@ def port_start(self): @property def port_end(self): return self._port_end - + @property def qsfp_ports(self): return self._qsfp_ports - @property + @property def port_to_eeprom_mapping(self): return self._port_to_eeprom_mapping - + @property def get_transceiver_change_event(self): - raise NotImplementedError + raise NotImplementedError diff --git a/device/marvell/x86_64-marvell_db98cx8580_32cd-r0/plugins/sfputil.py b/device/marvell/x86_64-marvell_db98cx8580_32cd-r0/plugins/sfputil.py index 80b11bf0630e..72c2e1944743 100644 --- a/device/marvell/x86_64-marvell_db98cx8580_32cd-r0/plugins/sfputil.py +++ b/device/marvell/x86_64-marvell_db98cx8580_32cd-r0/plugins/sfputil.py @@ -5,21 +5,20 @@ import time import sys import re - import subprocess from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") if sys.version_info[0] < 3: - import commands as cmd + import commands else: - import subprocess as cmd + import subprocess as commands smbus_present = 1 try: import smbus -except ImportError, e: +except ImportError as e: smbus_present = 0 class SfpUtil(SfpUtilBase): @@ -30,7 +29,7 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} - _qsfp_ports = range(_port_start, ports_in_block + 1) + _qsfp_ports = list(range(_port_start, ports_in_block + 1)) def __init__(self): os.system("modprobe i2c-dev") @@ -51,11 +50,11 @@ def reset(self, port_num): return False port_ps = "/sys/bus/i2c/devices/0-0050/sfp_port_reset" - + try: reg_file = open(port_ps, 'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False #toggle reset @@ -77,7 +76,7 @@ def i2c_get(self, device_addr, offset): status = 0 if smbus_present == 0: x = "i2cget -y 0 " + hex(device_addr) + " " + hex(offset) - cmdstatus, status = cmd.getstatusoutput(x) + cmdstatus, status = commands.getstatusoutput(x) if cmdstatus != 0: return cmdstatus status = int(status, 16) @@ -93,7 +92,7 @@ def i2c_set(self, device_addr, offset, value): else: bus = smbus.SMBus(0) bus.write_byte_data(device_addr, offset, value) - + def get_presence(self, port_num): # Check for invalid port_num if port_num < self._port_start or port_num > self._port_end: @@ -128,8 +127,8 @@ def get_presence(self, port_num): path = "/sys/bus/i2c/devices/0-0050/eeprom" try: reg_file = open(path) - reg_file.seek(01) - reg_file.read(02) + reg_file.seek(0o1) + reg_file.read(0o2) except IOError as e: return False @@ -183,7 +182,7 @@ def read_porttab_mappings(self, porttabfile): # Leave the old code for backward compatibility #if len(line.split()) >= 4: # fp_port_index = (line.split()[3]) - # print(fp_port_index) + # print(fp_port_index) else: fp_port_index = portname.split("Ethernet").pop() fp_port_index = int(fp_port_index.split("s").pop(0))+1 @@ -232,7 +231,7 @@ def read_porttab_mappings(self, porttabfile): self.logical_to_physical = logical_to_physical self.physical_to_logical = physical_to_logical - + #print(self.logical_to_physical) '''print("logical: " + self.logical) print("logical to bcm: " + self.logical_to_bcm) @@ -247,15 +246,15 @@ def port_start(self): @property def port_end(self): return self._port_end - + @property def qsfp_ports(self): return self._qsfp_ports - @property + @property def port_to_eeprom_mapping(self): return self._port_to_eeprom_mapping - + @property def get_transceiver_change_event(self): - raise NotImplementedError + raise NotImplementedError diff --git a/device/marvell/x86_64-marvell_slm5401_54x-r0/plugins/sfputil.py b/device/marvell/x86_64-marvell_slm5401_54x-r0/plugins/sfputil.py index fa706867a585..02937b48a18c 100755 --- a/device/marvell/x86_64-marvell_slm5401_54x-r0/plugins/sfputil.py +++ b/device/marvell/x86_64-marvell_slm5401_54x-r0/plugins/sfputil.py @@ -3,7 +3,7 @@ try: import time from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") @@ -50,7 +50,7 @@ class sfputil(SfpUtilBase): 24 : 49, } - _qsfp_ports = range(0, ports_in_block + 1) + _qsfp_ports = list(range(0, ports_in_block + 1)) def __init__(self): # Override port_to_eeprom_mapping for class initialization @@ -67,11 +67,11 @@ def reset(self, port_num): path = "/sys/bus/i2c/devices/{0}-0050/sfp_port_reset" port_ps = path.format(self.port_to_i2c_mapping[port_num+1]) - + try: reg_file = open(port_ps, 'w') except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False #toggle reset @@ -88,7 +88,7 @@ def set_low_power_mode(self, port_nuM, lpmode): def get_low_power_mode(self, port_num): raise NotImplementedErro - + def get_presence(self, port_num): # Check for invalid port_num if port_num < self._port_start or port_num > self._port_end: @@ -97,11 +97,11 @@ def get_presence(self, port_num): path = "/sys/bus/i2c/devices/{0}-0050/sfp_is_present" port_ps = path.format(self.port_to_i2c_mapping[port_num+1]) - + try: reg_file = open(port_ps) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_file.readline().rstrip() @@ -117,12 +117,12 @@ def port_start(self): @property def port_end(self): return self._port_end - + @property def qsfp_ports(self): - return range(0, self.ports_in_block + 1) + return list(range(0, self.ports_in_block + 1)) - @property + @property def port_to_eeprom_mapping(self): return self._port_to_eeprom_mapping diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfplpmget.py b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfplpmget.py index 2f19edfa1a52..9ef787ff62c4 100644 --- a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfplpmget.py +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfplpmget.py @@ -46,6 +46,6 @@ def mgmt_phy_mod_pwr_attr_get(handle, module_id, power_attr_type): else: print("LPM UNKNOWN") -print "LPM ON" if lpm_status else "LPM OFF" +print("LPM ON" if lpm_status else "LPM OFF") sx_api_close(handle) diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfplpmset.py b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfplpmset.py index 132d34257558..5b005219cbe8 100644 --- a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfplpmset.py +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfplpmset.py @@ -143,7 +143,7 @@ def set_lpmode(handle, cmd, module_id): # Get SFP module sfp_module = int(sys.argv[1]) - 1 -print "[+] opening sdk" +print("[+] opening sdk") rc, handle = sx_api_open(None) if (rc != SX_STATUS_SUCCESS): diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfputil.py b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfputil.py index 09ba9f22e51e..3462ac782fa8 100644 --- a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfputil.py +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfputil.py @@ -21,7 +21,7 @@ # I2C page size for sfp SFP_I2C_PAGE_SIZE = 256 -# parameters for DB connection +# parameters for DB connection REDIS_TIMEOUT_USECS = 0 # parameters for SFP presence @@ -79,12 +79,12 @@ def port_end(self): @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): - print "dependency on sysfs has been removed" - raise Exception() + print("dependency on sysfs has been removed") + raise Exception() def get_port_position_tuple_by_platform_name(self): p = subprocess.Popen(GET_PLATFORM_CMD, shell=True, stdout=subprocess.PIPE) @@ -122,7 +122,7 @@ def get_presence(self, port_num): if result != '': presence = True - except OSError, e: + except OSError as e: return presence return presence @@ -139,7 +139,7 @@ def get_low_power_mode(self, port_num): if 'LPM ON' in output: return True except subprocess.CalledProcessError as e: - print "Error! Unable to get LPM for {}, rc = {}, err msg: {}".format(port_num, e.returncode, e.output) + print("Error! Unable to get LPM for {}, rc = {}, err msg: {}".format(port_num, e.returncode, e.output)) return False return False @@ -161,7 +161,7 @@ def set_low_power_mode(self, port_num, lpmode): try: subprocess.check_output(lpm_cmd, shell=True) except subprocess.CalledProcessError as e: - print "Error! Unable to set LPM for {}, rc = {}, err msg: {}".format(port_num, e.returncode, e.output) + print("Error! Unable to set LPM for {}, rc = {}, err msg: {}".format(port_num, e.returncode, e.output)) return False return True @@ -177,7 +177,7 @@ def reset(self, port_num): subprocess.check_output(lpm_cmd, shell=True) return True except subprocess.CalledProcessError as e: - print "Error! Unable to set LPM for {}, rc = {}, err msg: {}".format(port_num, e.returncode, e.output) + print("Error! Unable to set LPM for {}, rc = {}, err msg: {}".format(port_num, e.returncode, e.output)) return False return False @@ -424,7 +424,7 @@ def get_transceiver_info_dict(self, port_num): if key in sfp_interface_bulk_data['data']['Specification compliance']['value']: compliance_code_dict[key] = sfp_interface_bulk_data['data']['Specification compliance']['value'][key]['value'] transceiver_info_dict['specification_compliance'] = str(compliance_code_dict) - + transceiver_info_dict['nominal_bit_rate'] = str(sfp_interface_bulk_data['data']['Nominal Bit Rate(100Mbs)']['value']) else: for key in sfp_cable_length_tup: @@ -447,15 +447,15 @@ def get_transceiver_dom_info_dict(self, port_num): # Below part is added to avoid failing xcvrd # Currently, the way in which dom data is read has been changed from # using sysfs to using ethtool. - # The ethtool returns None for ports without dom support, resulting in - # None being returned. However, this fails xcvrd to add the + # The ethtool returns None for ports without dom support, resulting in + # None being returned. However, this fails xcvrd to add the # TRANSCEIVER_DOM_SENSOR table entry of associated port to CONFIG_DB # and then causes SNMP fail. # To address this issue a default dict is initialized with all data set to # 'N/A' and is returned is the above case. # BTW, in the original implementation which sysfs is used to read dom data, - # even though non-None data is returned for ports without dom support, - # it does not contain valid data. This can result in wrong data in + # even though non-None data is returned for ports without dom support, + # it does not contain valid data. This can result in wrong data in # TRANSCEIVER_DOM_SENSOR table. transceiver_dom_info_dict['temperature'] = 'N/A' transceiver_dom_info_dict['voltage'] = 'N/A' @@ -571,7 +571,7 @@ def get_transceiver_dom_info_dict(self, port_num): sfpd_obj = sff8472Dom(None, calibration_type) if sfpd_obj is None: - print "no sff8472Dom" + print("no sff8472Dom") return None dom_temperature_raw = eeprom_domraw[SFP_TEMPE_OFFSET:SFP_TEMPE_OFFSET+SFP_TEMPE_WIDTH] diff --git a/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/plugins/sfputil.py b/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/plugins/sfputil.py index 33e98016384a..db85cd0d595b 100644 --- a/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/plugins/sfputil.py +++ b/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/plugins/sfputil.py @@ -31,7 +31,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(0, self.PORTS_IN_BLOCK + 1) + return list(range(0, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -60,7 +60,7 @@ def get_presence(self, port_num): try: reg_file = open("file_path") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -91,7 +91,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open(file_path) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) content = reg_file.readline().rstrip() @@ -119,12 +119,12 @@ def set_low_power_mode(self, port_num, lpmode): try: reg_file = open(file_path, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # LPMode is active high; set or clear the bit accordingly if lpmode is True: - reg_value = 1 + reg_value = 1 else: reg_value = 0 @@ -153,7 +153,7 @@ def reset(self, port_num): try: reg_file = open(file_path, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False # ResetL is active low @@ -171,7 +171,7 @@ def reset(self, port_num): try: reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 1 diff --git a/device/nokia/armhf-nokia_ixs7215_52x-r0/plugins/sfputil.py b/device/nokia/armhf-nokia_ixs7215_52x-r0/plugins/sfputil.py index 9b12e38226d5..1ca3b9ec6f2d 100755 --- a/device/nokia/armhf-nokia_ixs7215_52x-r0/plugins/sfputil.py +++ b/device/nokia/armhf-nokia_ixs7215_52x-r0/plugins/sfputil.py @@ -26,7 +26,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(0, 0) + return list(range(0, 0)) @property def port_to_eeprom_mapping(self): diff --git a/device/pegatron/x86_64-pegatron_porsche-r0/plugins/sfputil.py b/device/pegatron/x86_64-pegatron_porsche-r0/plugins/sfputil.py index 28909f00110c..0db85c29545f 100755 --- a/device/pegatron/x86_64-pegatron_porsche-r0/plugins/sfputil.py +++ b/device/pegatron/x86_64-pegatron_porsche-r0/plugins/sfputil.py @@ -5,7 +5,7 @@ import re import time from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError, e: +except ImportError as e: raise ImportError (str(e) + "- required module not found") @@ -21,8 +21,8 @@ class SfpUtil(SfpUtilBase): port_to_eeprom_mapping = {} port_to_i2c_mapping = {} - sfp_ports = range(0, ports_in_block) - qsfp_ports = range(ports_in_block - 6, ports_in_block) + sfp_ports = list(range(0, ports_in_block)) + qsfp_ports = list(range(ports_in_block - 6, ports_in_block)) def __init__(self): @@ -51,11 +51,11 @@ def get_presence(self, port_num): presence_path = '/sys/bus/i2c/devices/6-0074/sfp'+str(port_num+1)+'_present' else: presence_path = '/sys/bus/i2c/devices/8-0076/sfp'+str(port_num+1)+'_present' - + try: file = open(presence_path) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False value = int(file.readline().rstrip()) @@ -71,11 +71,11 @@ def get_low_power_mode(self, port_num): return False lowpower_path = '/sys/bus/i2c/devices/8-0076/sfp'+str(port_num+1)+'_lowpower' - + try: file = open(lowpower_path) except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False value = int(file.readline().rstrip()) @@ -101,7 +101,7 @@ def set_low_power_mode(self, port_num, lpmode): try: file = open(lowpower_path, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False file.seek(0) @@ -118,7 +118,7 @@ def reset(self, port_num): try: file = open(reset_path, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False file.seek(0) @@ -131,7 +131,7 @@ def reset(self, port_num): try: file = open(reset_path, "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False file.seek(0) diff --git a/device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/sfputil.py b/device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/sfputil.py index 851f4b90277d..c967ccfc224a 100755 --- a/device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/sfputil.py +++ b/device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/sfputil.py @@ -2,8 +2,8 @@ try: import time - from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError, e: + from sonic_sfp.sfputilbase import SfpUtilBase +except ImportError as e: raise ImportError (str(e) + "- required module not found") @@ -50,7 +50,7 @@ class SfpUtil(SfpUtilBase): 32 : 63, } - _qsfp_ports = range(0, ports_in_block + 1) + _qsfp_ports = list(range(0, ports_in_block + 1)) def __init__(self): eeprom_path = '/sys/bus/i2c/devices/{0}-0050/eeprom' @@ -67,7 +67,7 @@ def reset(self, port_num): try: reg_file = open("/sys/class/cpld-qsfp28/port-"+str(port_num+1)+"/reset", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 0 @@ -81,7 +81,7 @@ def reset(self, port_num): try: reg_file = open("/sys/class/cpld-qsfp28/port-"+str(port_num+1)+"/reset", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 1 @@ -98,7 +98,7 @@ def set_low_power_mode(self, port_num, lpmode): try: reg_file = open("/sys/class/cpld-qsfp28/port-"+str(port_num+1)+"/lpmode", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -122,7 +122,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/class/cpld-qsfp28/port-"+str(port_num+1)+"/lpmode") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -131,7 +131,7 @@ def get_low_power_mode(self, port_num): return False return True - + def get_presence(self, port_num): # Check for invalid port_num if port_num < self._port_start or port_num > self._port_end: @@ -139,11 +139,11 @@ def get_presence(self, port_num): #path = "/sys/class/cpld-qsfp28/port-{0}/module_present" #port_ps = path.format(self.port_to_i2c_mapping[port_num+1]) - + try: reg_file = open("/sys/class/cpld-qsfp28/port-"+str(port_num+1)+"/module_present") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_file.readline().rstrip() @@ -159,12 +159,12 @@ def port_start(self): @property def port_end(self): return self._port_end - + @property def qsfp_ports(self): - return range(0, self.ports_in_block + 1) + return list(range(0, self.ports_in_block + 1)) - @property + @property def port_to_eeprom_mapping(self): return self._port_to_eeprom_mapping diff --git a/device/quanta/x86_64-quanta_ix7_rglbmc-r0/plugins/sfputil.py b/device/quanta/x86_64-quanta_ix7_rglbmc-r0/plugins/sfputil.py index 85a4aad26dae..8fed7617c942 100644 --- a/device/quanta/x86_64-quanta_ix7_rglbmc-r0/plugins/sfputil.py +++ b/device/quanta/x86_64-quanta_ix7_rglbmc-r0/plugins/sfputil.py @@ -65,7 +65,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(self.PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -85,7 +85,7 @@ def get_presence(self, port_num): try: reg_file = open("/sys/class/cpld-qsfp28/port-"+str(port_num)+"/module_present") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_file.readline().rstrip() @@ -102,7 +102,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/class/cpld-qsfp28/port-"+str(port_num)+"/lpmode") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -120,7 +120,7 @@ def set_low_power_mode(self, port_num, lpmode): try: reg_file = open("/sys/class/cpld-qsfp28/port-"+str(port_num)+"/lpmode", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -144,7 +144,7 @@ def reset(self, port_num): try: reg_file = open("/sys/class/cpld-qsfp28/port-"+str(port_num)+"/reset", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 0 @@ -158,7 +158,7 @@ def reset(self, port_num): try: reg_file = open("/sys/class/cpld-qsfp28/port-"+str(port_num)+"/reset", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 1 diff --git a/device/quanta/x86_64-quanta_ix8_rglbmc-r0/plugins/sfputil.py b/device/quanta/x86_64-quanta_ix8_rglbmc-r0/plugins/sfputil.py index 627c99fee0c9..ab84d5994a22 100644 --- a/device/quanta/x86_64-quanta_ix8_rglbmc-r0/plugins/sfputil.py +++ b/device/quanta/x86_64-quanta_ix8_rglbmc-r0/plugins/sfputil.py @@ -99,7 +99,7 @@ def qsfp_port_end(self): @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -122,7 +122,7 @@ def get_presence(self, port_num): else: reg_file = open("/sys/class/gpio/gpio"+str((port_num-self.qsfp_port_start)*4+34)+"/value") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_file.readline().rstrip() @@ -143,7 +143,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/class/gpio/gpio"+str((port_num-self.qsfp_port_start)*4+35)+"/value") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -161,7 +161,7 @@ def set_low_power_mode(self, port_num, lpmode): try: reg_file = open("/sys/class/gpio/gpio"+str((port_num-self.qsfp_port_start)*4+35)+"/value", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -185,7 +185,7 @@ def reset(self, port_num): try: reg_file = open("/sys/class/gpio/gpio"+str((port_num-self.qsfp_port_start)*4+32)+"/value", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 0 @@ -199,7 +199,7 @@ def reset(self, port_num): try: reg_file = open("/sys/class/gpio/gpio"+str((port_num-self.qsfp_port_start)*4+32)+"/value", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 1 diff --git a/device/quanta/x86_64-quanta_ix8c_bwde-r0/plugins/sfputil.py b/device/quanta/x86_64-quanta_ix8c_bwde-r0/plugins/sfputil.py index 627c99fee0c9..ab84d5994a22 100644 --- a/device/quanta/x86_64-quanta_ix8c_bwde-r0/plugins/sfputil.py +++ b/device/quanta/x86_64-quanta_ix8c_bwde-r0/plugins/sfputil.py @@ -99,7 +99,7 @@ def qsfp_port_end(self): @property def qsfp_ports(self): - return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1) + return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)) @property def port_to_eeprom_mapping(self): @@ -122,7 +122,7 @@ def get_presence(self, port_num): else: reg_file = open("/sys/class/gpio/gpio"+str((port_num-self.qsfp_port_start)*4+34)+"/value") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_file.readline().rstrip() @@ -143,7 +143,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/class/gpio/gpio"+str((port_num-self.qsfp_port_start)*4+35)+"/value") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -161,7 +161,7 @@ def set_low_power_mode(self, port_num, lpmode): try: reg_file = open("/sys/class/gpio/gpio"+str((port_num-self.qsfp_port_start)*4+35)+"/value", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -185,7 +185,7 @@ def reset(self, port_num): try: reg_file = open("/sys/class/gpio/gpio"+str((port_num-self.qsfp_port_start)*4+32)+"/value", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 0 @@ -199,7 +199,7 @@ def reset(self, port_num): try: reg_file = open("/sys/class/gpio/gpio"+str((port_num-self.qsfp_port_start)*4+32)+"/value", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 1 diff --git a/device/quanta/x86_64-quanta_ix9_bwde-r0/plugins/sfputil.py b/device/quanta/x86_64-quanta_ix9_bwde-r0/plugins/sfputil.py index 6dc23d8195f4..f6afa59ce7c6 100644 --- a/device/quanta/x86_64-quanta_ix9_bwde-r0/plugins/sfputil.py +++ b/device/quanta/x86_64-quanta_ix9_bwde-r0/plugins/sfputil.py @@ -2,8 +2,8 @@ try: import time - from sonic_sfp.sfputilbase import SfpUtilBase -except ImportError, e: + from sonic_sfp.sfputilbase import SfpUtilBase +except ImportError as e: raise ImportError (str(e) + "- required module not found") @@ -50,7 +50,7 @@ class SfpUtil(SfpUtilBase): 32 : 63, } - _qsfp_ports = range(0, ports_in_block + 1) + _qsfp_ports = list(range(0, ports_in_block + 1)) def __init__(self): eeprom_path = '/sys/bus/i2c/devices/{0}-0050/eeprom' @@ -67,7 +67,7 @@ def reset(self, port_num): try: reg_file = open("/sys/class/cpld-qsfpdd/port-"+str(port_num+1)+"/reset", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 0 @@ -81,7 +81,7 @@ def reset(self, port_num): try: reg_file = open("/sys/class/cpld-qsfpdd/port-"+str(port_num+1)+"/reset", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = 1 @@ -98,7 +98,7 @@ def set_low_power_mode(self, port_num, lpmode): try: reg_file = open("/sys/class/cpld-qsfpdd/port-"+str(port_num+1)+"/lpmode", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -122,7 +122,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/class/cpld-qsfpdd/port-"+str(port_num+1)+"/lpmode") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = int(reg_file.readline().rstrip()) @@ -131,16 +131,16 @@ def get_low_power_mode(self, port_num): return False return True - + def get_presence(self, port_num): # Check for invalid port_num if port_num < self._port_start or port_num > self._port_end: return False - + try: reg_file = open("/sys/class/cpld-qsfpdd/port-"+str(port_num+1)+"/module_present") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_file.readline().rstrip() @@ -156,12 +156,12 @@ def port_start(self): @property def port_end(self): return self._port_end - + @property def qsfp_ports(self): - return range(0, self.ports_in_block + 1) + return list(range(0, self.ports_in_block + 1)) - @property + @property def port_to_eeprom_mapping(self): return self._port_to_eeprom_mapping diff --git a/device/wnc/x86_64-wnc_osw1800-r0/plugins/sfputil.py b/device/wnc/x86_64-wnc_osw1800-r0/plugins/sfputil.py index 549790bfb44f..ebb3d1c9bfa7 100644 --- a/device/wnc/x86_64-wnc_osw1800-r0/plugins/sfputil.py +++ b/device/wnc/x86_64-wnc_osw1800-r0/plugins/sfputil.py @@ -12,7 +12,7 @@ from sff8472 import sff8472Dom from sff8436 import sff8436InterfaceId from sff8436 import sff8436Dom -except ImportError, e: +except ImportError as e: raise ImportError("%s - required module not found" % str(e)) @@ -37,7 +37,7 @@ def port_end(self): @property def qsfp_ports(self): - return range(self.PORT_START + 48, self.PORTS_IN_BLOCK) + return list(range(self.PORT_START + 48, self.PORTS_IN_BLOCK)) @property def port_to_eeprom_mapping(self): @@ -77,7 +77,7 @@ def get_presence(self, port_num): try: reg_file = open(presence_path, "rb") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -98,7 +98,7 @@ def get_low_power_mode(self, port_num): try: reg_file = open("/sys/bus/i2c/devices/4-0032/qsfp_lpmode") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) content = reg_file.readline().rstrip() reg_value = int(content, 16) @@ -118,7 +118,7 @@ def set_low_power_mode(self, port_num, lpmode): try: reg_file = open("/sys/bus/i2c/devices/4-0032/qsfp_lpmode", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -144,7 +144,7 @@ def reset(self, port_num): try: reg_file = open("/sys/bus/i2c/devices/4-0032/reset_control", "r+") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False content = reg_file.readline().rstrip() @@ -160,7 +160,7 @@ def reset(self, port_num): try: reg_file = open("/sys/bus/i2c/devices/4-0032/reset_control", "w") except IOError as e: - print "Error: unable to open file: %s" % str(e) + print("Error: unable to open file: %s" % str(e)) return False reg_value = reg_value | (1 << bit_mask) From 695a509e760e76799a1282888add3e313b36b9ba Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Tue, 24 Nov 2020 00:43:46 +0000 Subject: [PATCH 19/24] Update shebangs to Python 3, remove unnecessary ones --- .../plugins/psuutil.py | 2 - .../plugins/psuutil.py | 2 - .../plugins/eeprom.py | 2 - .../plugins/psuutil.py | 2 - .../plugins/psuutil.py | 2 - .../plugins/psuutil.py | 2 - .../plugins/psuutil.py | 2 - .../plugins/eeprom.py | 2 - .../plugins/psuutil.py | 2 - .../plugins/sfputil.py | 2 - .../sonic_platform/chassis.py | 2 - .../sonic_platform/component.py | 2 - .../sonic_platform/eeprom.py | 2 - .../sonic_platform/fan.py | 2 - .../sonic_platform/platform.py | 2 - .../sonic_platform/psu.py | 2 - .../sonic_platform/sfp.py | 2 - .../plugins/sfputil.py | 2 - .../plugins/psuutil.py | 2 - .../plugins/psuutil.py | 2 - .../plugins/psuutil.py | 2 - .../plugins/psuutil.py | 2 - .../plugins/eeprom.py | 2 - .../plugins/psuutil.py | 2 - .../plugins/sfputil.py | 2 - .../plugins/psuutil.py | 2 - .../plugins/psuutil.py | 2 - .../plugins/psuutil.py | 2 - .../plugins/psuutil.py | 2 - .../plugins/sfputil.py | 2 - .../plugins/psuutil.py | 2 - .../plugins/led_control.py | 2 - .../plugins/psuutil.py | 2 - .../plugins/led_control.py | 4 -- .../plugins/psuutil.py | 2 - .../plugins/sfputil.py | 2 - .../plugins/led_control.py | 2 - .../plugins/psuutil.py | 2 - .../plugins/sfputil.py | 2 - .../x86_64-arista_common/platform_reboot | 2 +- .../x86_64-arista_common/plugins/eeprom.py | 2 - .../plugins/led_control.py | 2 - .../x86_64-arista_common/plugins/psuutil.py | 2 - .../x86_64-arista_common/plugins/sfputil.py | 2 - .../plugins/psuutil.py | 2 - .../plugins/sfputil.py | 2 - .../x86_64-bcm_xlr-r0/plugins/psuutil.py | 2 - .../x86_64-bcm_xlr-r0/plugins/sfputil.py | 2 - .../x86_64-cel_e1031-r0/plugins/psuutil.py | 2 - .../x86_64-cel_e1031-r0/plugins/sfputil.py | 2 - .../sonic_platform/chassis.py | 2 - .../sonic_platform/component.py | 2 - .../x86_64-cel_e1031-r0/sonic_platform/fan.py | 2 - .../sonic_platform/platform.py | 2 - .../x86_64-cel_e1031-r0/sonic_platform/psu.py | 2 - .../x86_64-cel_e1031-r0/sonic_platform/sfp.py | 2 - .../sonic_platform/thermal.py | 2 - .../sonic_platform/watchdog.py | 2 - .../x86_64-cel_midstone-r0/plugins/psuutil.py | 2 - .../x86_64-cel_seastone-r0/plugins/sfputil.py | 2 - .../sonic_platform/chassis.py | 2 - .../sonic_platform/component.py | 2 - .../sonic_platform/fan.py | 2 - .../sonic_platform/helper.py | 2 - .../sonic_platform/platform.py | 2 - .../sonic_platform/psu.py | 2 - .../sonic_platform/sfp.py | 2 - .../sonic_platform/thermal.py | 2 - .../sonic_platform/watchdog.py | 2 - .../plugins/psuutil.py | 2 - .../plugins/sfputil.py | 2 - .../sonic_platform_config/event.py | 2 - .../sonic_platform_config/watchdog.py | 2 - .../plugins/psuutil.py | 4 +- .../plugins/sfputil.py | 2 - .../sonic_platform/chassis.py | 2 - .../sonic_platform/component.py | 2 - .../sonic_platform/fan.py | 2 - .../sonic_platform/helper.py | 2 - .../sonic_platform/platform.py | 2 - .../sonic_platform/psu.py | 2 - .../sonic_platform/sfp.py | 2 - .../sonic_platform/thermal.py | 2 - .../plugins/led_control.py | 1 - .../plugins/psuutil.py | 2 - .../plugins/sfputil.py | 2 - .../plugins/led_control.py | 2 - .../plugins/psuutil.py | 2 - .../plugins/sfputil.py | 2 - .../plugins/led_control.py | 2 - .../plugins/psuutil.py | 2 - .../plugins/sfputil.py | 2 - .../plugins/led_control.py | 2 - .../plugins/psuutil.py | 2 - .../plugins/sfputil.py | 2 - .../plugins/sfputil.py | 2 - .../plugins/sfputil.py | 2 - .../plugins/sfputil.py | 2 - device/common/pddf/plugins/fanutil.py | 3 - device/common/pddf/plugins/ledutil.py | 2 - device/common/pddf/plugins/psuutil.py | 1 - device/common/pddf/plugins/sfputil.py | 2 - device/common/pddf/plugins/sysstatutil.py | 2 - device/common/pddf/plugins/thermalutil.py | 2 - .../platform_reboot | 9 +-- .../plugins/eeprom.py | 2 - .../plugins/eeprom.py | 2 - .../plugins/eeprom.py | 2 - .../plugins/eeprom.py | 2 - .../plugins/eeprom.py | 2 - .../plugins/eeprom.py | 2 - .../plugins/eeprom.py | 2 - .../x86_64-delta_ag5648-r0/plugins/eeprom.py | 2 - .../plugins/led_control.py | 1 - .../plugins/psuutil.py | 1 - .../plugins/qfx5200_eeprom_data.py | 2 +- .../plugins/qfx5200_sfp_init.py | 2 +- .../plugins/sfputil.py | 2 - .../plugins/psuutil.py | 2 - .../plugins/qfx5210_eeprom_data.py | 2 +- .../plugins/sfputil.py | 2 - .../plugins/sfputil.py | 2 - .../plugins/sfputil.py | 2 - .../plugins/psuutil.py | 2 - .../plugins/sfputil.py | 2 - .../plugins/sfputil.py | 2 - .../plugins/sfputil.py | 2 - .../plugins/sfputil.py | 2 - .../x86_64-mlnx_msn2010-r0/plugins/psuutil.py | 2 - .../x86_64-mlnx_msn2100-r0/plugins/psuutil.py | 2 - .../x86_64-mlnx_msn2700-r0/plugins/fanutil.py | 2 - .../x86_64-mlnx_msn2700-r0/plugins/psuutil.py | 2 - .../plugins/sfplpmget.py | 3 +- .../plugins/sfplpmset.py | 3 +- .../plugins/sfpreset.py | 57 ++++++++++--------- .../plugins/thermalutil.py | 2 - .../plugins/sfputil.py | 2 - .../plugins/sfputil.py | 2 - .../plugins/eeprom.py | 2 - .../plugins/eeprom.py | 2 - .../plugins/sfputil.py | 2 - .../x86_64-kvm_x86_64-r0/plugins/eeprom.py | 2 - 142 files changed, 43 insertions(+), 306 deletions(-) diff --git a/device/accton/x86_64-accton_as4630_54pe-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as4630_54pe-r0/plugins/psuutil.py index a646981334e6..3e0d2cea5f1e 100755 --- a/device/accton/x86_64-accton_as4630_54pe-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as4630_54pe-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Accton # diff --git a/device/accton/x86_64-accton_as5712_54x-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as5712_54x-r0/plugins/psuutil.py index 841070637b3e..33a27c378823 100755 --- a/device/accton/x86_64-accton_as5712_54x-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as5712_54x-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Accton # diff --git a/device/accton/x86_64-accton_as5812_54t-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as5812_54t-r0/plugins/eeprom.py index 384f903dc2ad..e7f6a39411d5 100644 --- a/device/accton/x86_64-accton_as5812_54t-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as5812_54t-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - try: import binascii import time diff --git a/device/accton/x86_64-accton_as5812_54t-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as5812_54t-r0/plugins/psuutil.py index cfcd62e5828e..6193c5e900ea 100755 --- a/device/accton/x86_64-accton_as5812_54t-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as5812_54t-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Accton # diff --git a/device/accton/x86_64-accton_as5812_54x-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as5812_54x-r0/plugins/psuutil.py index 841070637b3e..33a27c378823 100755 --- a/device/accton/x86_64-accton_as5812_54x-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as5812_54x-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Accton # diff --git a/device/accton/x86_64-accton_as5835_54t-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as5835_54t-r0/plugins/psuutil.py index c95bc27897dc..10303e4b9ad0 100644 --- a/device/accton/x86_64-accton_as5835_54t-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as5835_54t-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Accton # diff --git a/device/accton/x86_64-accton_as5835_54x-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as5835_54x-r0/plugins/psuutil.py index c95bc27897dc..10303e4b9ad0 100644 --- a/device/accton/x86_64-accton_as5835_54x-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as5835_54x-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Accton # diff --git a/device/accton/x86_64-accton_as6712_32x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as6712_32x-r0/plugins/eeprom.py index b653e8f90d9a..5c409f60faf0 100644 --- a/device/accton/x86_64-accton_as6712_32x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as6712_32x-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - try: import binascii import time diff --git a/device/accton/x86_64-accton_as6712_32x-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as6712_32x-r0/plugins/psuutil.py index 191654429e6b..d72809288e5c 100644 --- a/device/accton/x86_64-accton_as6712_32x-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as6712_32x-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Accton # diff --git a/device/accton/x86_64-accton_as7116_54x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7116_54x-r0/plugins/sfputil.py index d2706275e7bb..bc904dbc9d46 100644 --- a/device/accton/x86_64-accton_as7116_54x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7116_54x-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - try: import time from sonic_sfp.sfputilbase import SfpUtilBase diff --git a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/chassis.py b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/chassis.py index 90b05465d27a..38dcaf489f8b 100644 --- a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/chassis.py +++ b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/chassis.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # # Module contains an implementation of SONiC Platform Base API and diff --git a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/component.py b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/component.py index c8f109aa4db9..4371d9efb62b 100644 --- a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/component.py +++ b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/component.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Component contains an implementation of SONiC Platform Base API and # provides the components firmware management function diff --git a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/eeprom.py b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/eeprom.py index 836a5e30ac8e..9cdd09106331 100644 --- a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/eeprom.py +++ b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Platform and model specific eeprom subclass, inherits from the base class, # and provides the followings: diff --git a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/fan.py b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/fan.py index 54878e3e1baa..4b49fb4910c6 100644 --- a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/fan.py +++ b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/fan.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # # Module contains an implementation of SONiC Platform Base API and diff --git a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/platform.py b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/platform.py index 44e03cdadbb3..768a9ebad5e6 100644 --- a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/platform.py +++ b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/platform.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Module contains an implementation of SONiC Platform Base API and # provides the platform information diff --git a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/psu.py b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/psu.py index b1c8029dced9..620d004cc97b 100644 --- a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/psu.py +++ b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/psu.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # psuutil.py # Platform-specific PSU status interface for SONiC diff --git a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/sfp.py b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/sfp.py index 264545bd82e3..16f3ee4a77c2 100644 --- a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/sfp.py +++ b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/sfp.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Sfp contains an implementation of SONiC Platform Base API and # provides the sfp device status which are available in the platform diff --git a/device/accton/x86_64-accton_as7212_54x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7212_54x-r0/plugins/sfputil.py index 18cc406e5e12..fc0765f7ffcc 100755 --- a/device/accton/x86_64-accton_as7212_54x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7212_54x-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - try: import time from sonic_sfp.sfputilbase import SfpUtilBase diff --git a/device/accton/x86_64-accton_as7312_54x-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as7312_54x-r0/plugins/psuutil.py index d73e65bf7981..de0ae8504e6e 100644 --- a/device/accton/x86_64-accton_as7312_54x-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as7312_54x-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Accton # diff --git a/device/accton/x86_64-accton_as7312_54xs-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as7312_54xs-r0/plugins/psuutil.py index d73e65bf7981..de0ae8504e6e 100644 --- a/device/accton/x86_64-accton_as7312_54xs-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as7312_54xs-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Accton # diff --git a/device/accton/x86_64-accton_as7315_27xb-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as7315_27xb-r0/plugins/psuutil.py index 7ec16640e5a8..171a181ec092 100644 --- a/device/accton/x86_64-accton_as7315_27xb-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as7315_27xb-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Accton # diff --git a/device/accton/x86_64-accton_as7326_56x-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as7326_56x-r0/plugins/psuutil.py index a3c30bc478e7..a682bfde3b01 100644 --- a/device/accton/x86_64-accton_as7326_56x-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as7326_56x-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Accton # diff --git a/device/accton/x86_64-accton_as7712_32x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as7712_32x-r0/plugins/eeprom.py index 384f903dc2ad..e7f6a39411d5 100644 --- a/device/accton/x86_64-accton_as7712_32x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as7712_32x-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - try: import binascii import time diff --git a/device/accton/x86_64-accton_as7712_32x-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as7712_32x-r0/plugins/psuutil.py index d7600a2af4b1..e5c8aab97ce0 100644 --- a/device/accton/x86_64-accton_as7712_32x-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as7712_32x-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Accton # diff --git a/device/accton/x86_64-accton_as7712_32x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7712_32x-r0/plugins/sfputil.py index 19e7f9f31d5e..93160d9ad249 100644 --- a/device/accton/x86_64-accton_as7712_32x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7712_32x-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - try: import time import string diff --git a/device/accton/x86_64-accton_as7716_32x-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as7716_32x-r0/plugins/psuutil.py index d8fddc23550b..f34753f549a0 100755 --- a/device/accton/x86_64-accton_as7716_32x-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as7716_32x-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Accton # diff --git a/device/accton/x86_64-accton_as7716_32xb-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as7716_32xb-r0/plugins/psuutil.py index 5a4b0fe83d87..e803a060e134 100755 --- a/device/accton/x86_64-accton_as7716_32xb-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as7716_32xb-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Accton # diff --git a/device/accton/x86_64-accton_as7726_32x-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as7726_32x-r0/plugins/psuutil.py index 44fb45662d50..169feecc9adb 100755 --- a/device/accton/x86_64-accton_as7726_32x-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as7726_32x-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Accton # diff --git a/device/accton/x86_64-accton_as7816_64x-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as7816_64x-r0/plugins/psuutil.py index 707c7c897c82..512127fa18fb 100755 --- a/device/accton/x86_64-accton_as7816_64x-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as7816_64x-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Accton # diff --git a/device/accton/x86_64-accton_as7816_64x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7816_64x-r0/plugins/sfputil.py index 3572aec3348d..b6e3400b6c1f 100644 --- a/device/accton/x86_64-accton_as7816_64x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7816_64x-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - try: import time import string diff --git a/device/accton/x86_64-accton_as9716_32d-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as9716_32d-r0/plugins/psuutil.py index 25eceb7428c7..63ea48e2424b 100644 --- a/device/accton/x86_64-accton_as9716_32d-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as9716_32d-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Accton # diff --git a/device/accton/x86_64-accton_minipack-r0/plugins/led_control.py b/device/accton/x86_64-accton_minipack-r0/plugins/led_control.py index d662759f4a1b..c452552a3dc7 100755 --- a/device/accton/x86_64-accton_minipack-r0/plugins/led_control.py +++ b/device/accton/x86_64-accton_minipack-r0/plugins/led_control.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python -# # led_control.py # # Platform-specific LED control functionality for SONiC diff --git a/device/accton/x86_64-accton_minipack-r0/plugins/psuutil.py b/device/accton/x86_64-accton_minipack-r0/plugins/psuutil.py index 99e1bbae9377..53a172c771b9 100644 --- a/device/accton/x86_64-accton_minipack-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_minipack-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Accton # diff --git a/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/led_control.py b/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/led_control.py index 8516a840e6b7..b46770fbe694 100644 --- a/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/led_control.py +++ b/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/led_control.py @@ -1,7 +1,3 @@ -#!/usr/bin/env python -# -# led_control.py -# # Platform-specific LED control functionality for SONiC # diff --git a/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/psuutil.py b/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/psuutil.py index 7a3b87f24d2d..376a51f037bb 100644 --- a/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/psuutil.py +++ b/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Alphanetworks # diff --git a/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/sfputil.py b/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/sfputil.py index fcfc34940173..59be952ebb50 100644 --- a/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/sfputil.py +++ b/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - try: import time from sonic_sfp.sfputilbase import SfpUtilBase diff --git a/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/led_control.py b/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/led_control.py index 71e6299963f4..7d2c86afb4e5 100644 --- a/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/led_control.py +++ b/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/led_control.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python -# # led_control.py # # Platform-specific LED control functionality for SONiC diff --git a/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/psuutil.py b/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/psuutil.py index 7a3b87f24d2d..376a51f037bb 100644 --- a/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/psuutil.py +++ b/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Alphanetworks # diff --git a/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/sfputil.py b/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/sfputil.py index 641c62c4ab56..a5c7830c2a2c 100644 --- a/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/sfputil.py +++ b/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - try: import time from sonic_sfp.sfputilbase import SfpUtilBase diff --git a/device/arista/x86_64-arista_common/platform_reboot b/device/arista/x86_64-arista_common/platform_reboot index b8b1a5d7bfe5..76cc3c5a2b34 100755 --- a/device/arista/x86_64-arista_common/platform_reboot +++ b/device/arista/x86_64-arista_common/platform_reboot @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import arista.platforms from arista.utils.sonic_reboot import reboot diff --git a/device/arista/x86_64-arista_common/plugins/eeprom.py b/device/arista/x86_64-arista_common/plugins/eeprom.py index 5c0286979056..3cc5a6b13c59 100644 --- a/device/arista/x86_64-arista_common/plugins/eeprom.py +++ b/device/arista/x86_64-arista_common/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # # Arista eeprom processing for SONiC # Uses the arista driver library to obtain the TlvInfoDecoder diff --git a/device/arista/x86_64-arista_common/plugins/led_control.py b/device/arista/x86_64-arista_common/plugins/led_control.py index febb04ad1616..8ea9f70a8604 100644 --- a/device/arista/x86_64-arista_common/plugins/led_control.py +++ b/device/arista/x86_64-arista_common/plugins/led_control.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # # Arista LED controls for SONiC # diff --git a/device/arista/x86_64-arista_common/plugins/psuutil.py b/device/arista/x86_64-arista_common/plugins/psuutil.py index 46ec6b32e2e4..14755365257b 100644 --- a/device/arista/x86_64-arista_common/plugins/psuutil.py +++ b/device/arista/x86_64-arista_common/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # # Arista PSU interface for SONiC # diff --git a/device/arista/x86_64-arista_common/plugins/sfputil.py b/device/arista/x86_64-arista_common/plugins/sfputil.py index 5e02eef69aef..4c99ad533f27 100644 --- a/device/arista/x86_64-arista_common/plugins/sfputil.py +++ b/device/arista/x86_64-arista_common/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # # Arista SFP transceiver interface for SONiC # diff --git a/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/psuutil.py b/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/psuutil.py index 2c0e2fdb224e..796b1d0afecb 100644 --- a/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/psuutil.py +++ b/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - try: import os import sys diff --git a/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/sfputil.py b/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/sfputil.py index aa65b67813d4..b120179b1e34 100644 --- a/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/sfputil.py +++ b/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - try: import os import sys diff --git a/device/broadcom/x86_64-bcm_xlr-r0/plugins/psuutil.py b/device/broadcom/x86_64-bcm_xlr-r0/plugins/psuutil.py index 5cfdda1578b9..fefc3c3494e5 100644 --- a/device/broadcom/x86_64-bcm_xlr-r0/plugins/psuutil.py +++ b/device/broadcom/x86_64-bcm_xlr-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - import os.path try: diff --git a/device/broadcom/x86_64-bcm_xlr-r0/plugins/sfputil.py b/device/broadcom/x86_64-bcm_xlr-r0/plugins/sfputil.py index 3dc25793ba4a..f526706f5dd4 100644 --- a/device/broadcom/x86_64-bcm_xlr-r0/plugins/sfputil.py +++ b/device/broadcom/x86_64-bcm_xlr-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - try: import time import os diff --git a/device/celestica/x86_64-cel_e1031-r0/plugins/psuutil.py b/device/celestica/x86_64-cel_e1031-r0/plugins/psuutil.py index 71b8d4ad3c59..8e019efbebcd 100644 --- a/device/celestica/x86_64-cel_e1031-r0/plugins/psuutil.py +++ b/device/celestica/x86_64-cel_e1031-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - import os.path try: diff --git a/device/celestica/x86_64-cel_e1031-r0/plugins/sfputil.py b/device/celestica/x86_64-cel_e1031-r0/plugins/sfputil.py index f8f37ae03126..b9580b065cf0 100644 --- a/device/celestica/x86_64-cel_e1031-r0/plugins/sfputil.py +++ b/device/celestica/x86_64-cel_e1031-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - try: import time import os diff --git a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/chassis.py b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/chassis.py index 42a81748a44a..40c4bb4ef73b 100644 --- a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/chassis.py +++ b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/chassis.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # diff --git a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/component.py b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/component.py index fe34bc45c670..a621da45ad3f 100644 --- a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/component.py +++ b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/component.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # diff --git a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/fan.py b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/fan.py index 2c5bc5c0c45c..18cf513800aa 100644 --- a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/fan.py +++ b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/fan.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # diff --git a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/platform.py b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/platform.py index a632de87e742..7d98ec9f7cdf 100644 --- a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/platform.py +++ b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/platform.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # diff --git a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/psu.py b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/psu.py index 9ffa2f838247..52e71a2480d0 100644 --- a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/psu.py +++ b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/psu.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # diff --git a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/sfp.py b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/sfp.py index a3494daba4bf..608111d7e2fd 100644 --- a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/sfp.py +++ b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/sfp.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # diff --git a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/thermal.py b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/thermal.py index 6c37f3b7ce88..157f49a7c3e2 100644 --- a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/thermal.py +++ b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/thermal.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # diff --git a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/watchdog.py b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/watchdog.py index b539bc06f618..882285251784 100644 --- a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/watchdog.py +++ b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/watchdog.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # diff --git a/device/celestica/x86_64-cel_midstone-r0/plugins/psuutil.py b/device/celestica/x86_64-cel_midstone-r0/plugins/psuutil.py index 4e6c5eec5d85..d8455b816f9a 100644 --- a/device/celestica/x86_64-cel_midstone-r0/plugins/psuutil.py +++ b/device/celestica/x86_64-cel_midstone-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # diff --git a/device/celestica/x86_64-cel_seastone-r0/plugins/sfputil.py b/device/celestica/x86_64-cel_seastone-r0/plugins/sfputil.py index a7f4215652cb..ca960dd8136d 100644 --- a/device/celestica/x86_64-cel_seastone-r0/plugins/sfputil.py +++ b/device/celestica/x86_64-cel_seastone-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python -# # Platform-specific SFP transceiver interface for SONiC # diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/chassis.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/chassis.py index 92ebc3ccdd13..5466d629fb2f 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/chassis.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/chassis.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/component.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/component.py index c04b1a4166b0..291b5bd3e384 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/component.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/component.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/fan.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/fan.py index 8fe630423880..10875ee30753 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/fan.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/fan.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/helper.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/helper.py index 04149ae514f6..376110e6acc9 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/helper.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/helper.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - import os import struct import subprocess diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/platform.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/platform.py index a632de87e742..7d98ec9f7cdf 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/platform.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/platform.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/psu.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/psu.py index 72a881b2ac33..7080081ceff1 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/psu.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/psu.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/sfp.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/sfp.py index 57ad04378b90..bf650ab792d5 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/sfp.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/sfp.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/thermal.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/thermal.py index 7737d79cfe3e..9e891b65e405 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/thermal.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/thermal.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/watchdog.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/watchdog.py index c055f0047eed..31bb911d2401 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/watchdog.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/watchdog.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # diff --git a/device/celestica/x86_64-cel_seastone_2-r0/plugins/psuutil.py b/device/celestica/x86_64-cel_seastone_2-r0/plugins/psuutil.py index f315e875542c..5b407e017f43 100644 --- a/device/celestica/x86_64-cel_seastone_2-r0/plugins/psuutil.py +++ b/device/celestica/x86_64-cel_seastone_2-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - import os.path import subprocess import sys diff --git a/device/celestica/x86_64-cel_seastone_2-r0/plugins/sfputil.py b/device/celestica/x86_64-cel_seastone_2-r0/plugins/sfputil.py index b2541d42f53d..cd14023f9f18 100755 --- a/device/celestica/x86_64-cel_seastone_2-r0/plugins/sfputil.py +++ b/device/celestica/x86_64-cel_seastone_2-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python -# # Platform-specific SFP transceiver interface for SONiC # diff --git a/device/celestica/x86_64-cel_seastone_2-r0/sonic_platform_config/event.py b/device/celestica/x86_64-cel_seastone_2-r0/sonic_platform_config/event.py index 0153d29418f2..ed3b78cf7fd6 100644 --- a/device/celestica/x86_64-cel_seastone_2-r0/sonic_platform_config/event.py +++ b/device/celestica/x86_64-cel_seastone_2-r0/sonic_platform_config/event.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica Seastone2 # diff --git a/device/celestica/x86_64-cel_seastone_2-r0/sonic_platform_config/watchdog.py b/device/celestica/x86_64-cel_seastone_2-r0/sonic_platform_config/watchdog.py index 70eae5b95b3b..cc87c3d6b32a 100644 --- a/device/celestica/x86_64-cel_seastone_2-r0/sonic_platform_config/watchdog.py +++ b/device/celestica/x86_64-cel_seastone_2-r0/sonic_platform_config/watchdog.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica Seastone2 # diff --git a/device/celestica/x86_64-cel_silverstone-r0/plugins/psuutil.py b/device/celestica/x86_64-cel_silverstone-r0/plugins/psuutil.py index d5e197e82d2b..109e23b1e653 100644 --- a/device/celestica/x86_64-cel_silverstone-r0/plugins/psuutil.py +++ b/device/celestica/x86_64-cel_silverstone-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - import os.path import subprocess import sys @@ -88,4 +86,4 @@ def get_psu_presence(self, index): if presence: return True else: - return False \ No newline at end of file + return False diff --git a/device/celestica/x86_64-cel_silverstone-r0/plugins/sfputil.py b/device/celestica/x86_64-cel_silverstone-r0/plugins/sfputil.py index d6a3df3c08bd..c089b42c3638 100755 --- a/device/celestica/x86_64-cel_silverstone-r0/plugins/sfputil.py +++ b/device/celestica/x86_64-cel_silverstone-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python -# # Platform-specific SFP transceiver interface for SONiC # This plugin supports QSFP-DD, QSFP and SFP. diff --git a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/chassis.py b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/chassis.py index 816ca48c8e99..a599bdf7c5d0 100644 --- a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/chassis.py +++ b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/chassis.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # diff --git a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/component.py b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/component.py index 7220bebbd808..bbbb9f1d458d 100644 --- a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/component.py +++ b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/component.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # diff --git a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/fan.py b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/fan.py index d9822a0137a0..a2cb9c094b1f 100644 --- a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/fan.py +++ b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/fan.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # diff --git a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/helper.py b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/helper.py index 82f0eea6b448..42fa127b6073 100644 --- a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/helper.py +++ b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/helper.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - import os import struct import subprocess diff --git a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/platform.py b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/platform.py index a632de87e742..7d98ec9f7cdf 100644 --- a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/platform.py +++ b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/platform.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # diff --git a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/psu.py b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/psu.py index 9ec2cdcb8c93..a70b1e28a7dd 100644 --- a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/psu.py +++ b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/psu.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # diff --git a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/sfp.py b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/sfp.py index c0187033b889..b04b49ca4382 100644 --- a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/sfp.py +++ b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/sfp.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # diff --git a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/thermal.py b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/thermal.py index 089d5d88effc..bd87ab77bff7 100644 --- a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/thermal.py +++ b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/thermal.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Celestica # diff --git a/device/centec/arm64-centec_e530_24x2c-r0/plugins/led_control.py b/device/centec/arm64-centec_e530_24x2c-r0/plugins/led_control.py index 936c7e18cafb..d9fc2c14f684 100644 --- a/device/centec/arm64-centec_e530_24x2c-r0/plugins/led_control.py +++ b/device/centec/arm64-centec_e530_24x2c-r0/plugins/led_control.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # # led_control.py # diff --git a/device/centec/arm64-centec_e530_24x2c-r0/plugins/psuutil.py b/device/centec/arm64-centec_e530_24x2c-r0/plugins/psuutil.py index 1e83c12c1131..c18fe699c37a 100644 --- a/device/centec/arm64-centec_e530_24x2c-r0/plugins/psuutil.py +++ b/device/centec/arm64-centec_e530_24x2c-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Centec # diff --git a/device/centec/arm64-centec_e530_24x2c-r0/plugins/sfputil.py b/device/centec/arm64-centec_e530_24x2c-r0/plugins/sfputil.py index 0d6ef42e9add..920ad0894079 100644 --- a/device/centec/arm64-centec_e530_24x2c-r0/plugins/sfputil.py +++ b/device/centec/arm64-centec_e530_24x2c-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # sfputil.py # # Platform-specific SFP transceiver interface for SONiC diff --git a/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/led_control.py b/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/led_control.py index 65cb38ab8dc4..3768e099baf5 100644 --- a/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/led_control.py +++ b/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/led_control.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python -# # led_control.py # # Platform-specific LED control functionality for SONiC diff --git a/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/psuutil.py b/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/psuutil.py index 1e83c12c1131..c18fe699c37a 100644 --- a/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/psuutil.py +++ b/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Centec # diff --git a/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/sfputil.py b/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/sfputil.py index 7c5225e402fd..de0b32bf2eb2 100644 --- a/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/sfputil.py +++ b/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # sfputil.py # # Platform-specific SFP transceiver interface for SONiC diff --git a/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/led_control.py b/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/led_control.py index ce9aa1709438..da593262789a 100644 --- a/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/led_control.py +++ b/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/led_control.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python -# # led_control.py # # Platform-specific LED control functionality for SONiC diff --git a/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/psuutil.py b/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/psuutil.py index 6505318ed948..146d390d2ef0 100644 --- a/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/psuutil.py +++ b/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Centec # diff --git a/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/sfputil.py b/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/sfputil.py index e4123b13098d..92f76ce3217a 100644 --- a/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/sfputil.py +++ b/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # sfputil.py # # Platform-specific SFP transceiver interface for SONiC diff --git a/device/centec/x86_64-centec_e582_48x6q-r0/plugins/led_control.py b/device/centec/x86_64-centec_e582_48x6q-r0/plugins/led_control.py index 5bc52a444916..024330f71bb1 100644 --- a/device/centec/x86_64-centec_e582_48x6q-r0/plugins/led_control.py +++ b/device/centec/x86_64-centec_e582_48x6q-r0/plugins/led_control.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python -# # led_control.py # # Platform-specific LED control functionality for SONiC diff --git a/device/centec/x86_64-centec_e582_48x6q-r0/plugins/psuutil.py b/device/centec/x86_64-centec_e582_48x6q-r0/plugins/psuutil.py index 6505318ed948..146d390d2ef0 100644 --- a/device/centec/x86_64-centec_e582_48x6q-r0/plugins/psuutil.py +++ b/device/centec/x86_64-centec_e582_48x6q-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Centec # diff --git a/device/centec/x86_64-centec_e582_48x6q-r0/plugins/sfputil.py b/device/centec/x86_64-centec_e582_48x6q-r0/plugins/sfputil.py index 1926a028beec..f4bbfa04b8db 100644 --- a/device/centec/x86_64-centec_e582_48x6q-r0/plugins/sfputil.py +++ b/device/centec/x86_64-centec_e582_48x6q-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # sfputil.py # # Platform-specific SFP transceiver interface for SONiC diff --git a/device/cig/x86_64-cig_cs5435_54p-r0/plugins/sfputil.py b/device/cig/x86_64-cig_cs5435_54p-r0/plugins/sfputil.py index bc5b945b44f0..1e5f95a32a90 100755 --- a/device/cig/x86_64-cig_cs5435_54p-r0/plugins/sfputil.py +++ b/device/cig/x86_64-cig_cs5435_54p-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - try: import time from sonic_sfp.sfputilbase import SfpUtilBase diff --git a/device/cig/x86_64-cig_cs6436_54p-r0/plugins/sfputil.py b/device/cig/x86_64-cig_cs6436_54p-r0/plugins/sfputil.py index bc5b945b44f0..1e5f95a32a90 100755 --- a/device/cig/x86_64-cig_cs6436_54p-r0/plugins/sfputil.py +++ b/device/cig/x86_64-cig_cs6436_54p-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - try: import time from sonic_sfp.sfputilbase import SfpUtilBase diff --git a/device/cig/x86_64-cig_cs6436_56p-r0/plugins/sfputil.py b/device/cig/x86_64-cig_cs6436_56p-r0/plugins/sfputil.py index fbc9bbe02002..019592b83454 100755 --- a/device/cig/x86_64-cig_cs6436_56p-r0/plugins/sfputil.py +++ b/device/cig/x86_64-cig_cs6436_56p-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - try: import time from sonic_sfp.sfputilbase import SfpUtilBase diff --git a/device/common/pddf/plugins/fanutil.py b/device/common/pddf/plugins/fanutil.py index ce2d8118c1d3..5020586130b6 100755 --- a/device/common/pddf/plugins/fanutil.py +++ b/device/common/pddf/plugins/fanutil.py @@ -1,6 +1,3 @@ -#!/usr/bin/env python - - # Sample pddf_fanutil file # All the supported FAN SysFS aattributes are #- fan_present diff --git a/device/common/pddf/plugins/ledutil.py b/device/common/pddf/plugins/ledutil.py index dc0a4c9b8683..74db17744eb7 100755 --- a/device/common/pddf/plugins/ledutil.py +++ b/device/common/pddf/plugins/ledutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - import sys sys.path.append('/usr/share/sonic/platform/plugins') import pddfparse diff --git a/device/common/pddf/plugins/psuutil.py b/device/common/pddf/plugins/psuutil.py index 2a88263479e3..a869b33440f3 100755 --- a/device/common/pddf/plugins/psuutil.py +++ b/device/common/pddf/plugins/psuutil.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # # Sample pddf_psuutil file # diff --git a/device/common/pddf/plugins/sfputil.py b/device/common/pddf/plugins/sfputil.py index a15e000ca7a8..0b058e5df57a 100755 --- a/device/common/pddf/plugins/sfputil.py +++ b/device/common/pddf/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - import os.path import sys sys.path.append('/usr/share/sonic/platform/plugins') diff --git a/device/common/pddf/plugins/sysstatutil.py b/device/common/pddf/plugins/sysstatutil.py index 2c5b44f78ae3..f746f8ff3723 100755 --- a/device/common/pddf/plugins/sysstatutil.py +++ b/device/common/pddf/plugins/sysstatutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - import os.path import sys sys.path.append('/usr/share/sonic/platform/plugins') diff --git a/device/common/pddf/plugins/thermalutil.py b/device/common/pddf/plugins/thermalutil.py index 3e1682f4862c..5e6ecf9da2ee 100755 --- a/device/common/pddf/plugins/thermalutil.py +++ b/device/common/pddf/plugins/thermalutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - import os.path import sys import json diff --git a/device/dell/x86_64-dell_s6000_s1220-r0/platform_reboot b/device/dell/x86_64-dell_s6000_s1220-r0/platform_reboot index dc6e3d517a84..449a45bc57e9 100755 --- a/device/dell/x86_64-dell_s6000_s1220-r0/platform_reboot +++ b/device/dell/x86_64-dell_s6000_s1220-r0/platform_reboot @@ -1,4 +1,5 @@ -#!/usr/bin/python +#!/usr/bin/python3 + import sys import os import struct @@ -10,14 +11,14 @@ WARM_RESET = 0x6 # Warm Reset def io_reg_write(resource, offset, val): fd = os.open(resource, os.O_RDWR) if(fd < 0): - print 'file open failed %s" % resource' + print('file open failed %s" % resource') return if(os.lseek(fd, offset, os.SEEK_SET) != offset): - print 'lseek failed on %s' % resource + print('lseek failed on %s' % resource) return ret = os.write(fd, struct.pack('B', val)) if(ret != 1): - print 'write failed %d' % ret + print('write failed %d' % ret) return os.close(fd) diff --git a/device/dell/x86_64-dell_s6000_s1220-r0/plugins/eeprom.py b/device/dell/x86_64-dell_s6000_s1220-r0/plugins/eeprom.py index 10364c2c9f8e..dc16fde7d770 100644 --- a/device/dell/x86_64-dell_s6000_s1220-r0/plugins/eeprom.py +++ b/device/dell/x86_64-dell_s6000_s1220-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Dell S6000 # diff --git a/device/dell/x86_64-dell_s6100_c2538-r0/plugins/eeprom.py b/device/dell/x86_64-dell_s6100_c2538-r0/plugins/eeprom.py index 46706fe5c9aa..664833deed39 100644 --- a/device/dell/x86_64-dell_s6100_c2538-r0/plugins/eeprom.py +++ b/device/dell/x86_64-dell_s6100_c2538-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Dell S6100 # diff --git a/device/dell/x86_64-dell_z9100_c2538-r0/plugins/eeprom.py b/device/dell/x86_64-dell_z9100_c2538-r0/plugins/eeprom.py index d447748ad114..eca797ee7637 100644 --- a/device/dell/x86_64-dell_z9100_c2538-r0/plugins/eeprom.py +++ b/device/dell/x86_64-dell_z9100_c2538-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Dell Z9100 # diff --git a/device/dell/x86_64-dellemc_s5232f_c3538-r0/plugins/eeprom.py b/device/dell/x86_64-dellemc_s5232f_c3538-r0/plugins/eeprom.py index 18e3b61318db..2374ceb790c5 100644 --- a/device/dell/x86_64-dellemc_s5232f_c3538-r0/plugins/eeprom.py +++ b/device/dell/x86_64-dellemc_s5232f_c3538-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # DellEMC S5232f # diff --git a/device/dell/x86_64-dellemc_s5248f_c3538-r0/plugins/eeprom.py b/device/dell/x86_64-dellemc_s5248f_c3538-r0/plugins/eeprom.py index 8b115e20c3a0..dc7eeb330215 100644 --- a/device/dell/x86_64-dellemc_s5248f_c3538-r0/plugins/eeprom.py +++ b/device/dell/x86_64-dellemc_s5248f_c3538-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # DellEMC S5248f # diff --git a/device/dell/x86_64-dellemc_z9264f_c3538-r0/plugins/eeprom.py b/device/dell/x86_64-dellemc_z9264f_c3538-r0/plugins/eeprom.py index e8284f686b1e..e4dcfbd3cf08 100644 --- a/device/dell/x86_64-dellemc_z9264f_c3538-r0/plugins/eeprom.py +++ b/device/dell/x86_64-dellemc_z9264f_c3538-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # DellEMC Z9264f # diff --git a/device/dell/x86_64-dellemc_z9332f_d1508-r0/plugins/eeprom.py b/device/dell/x86_64-dellemc_z9332f_d1508-r0/plugins/eeprom.py index 2400b0f4153c..a346f1957be4 100644 --- a/device/dell/x86_64-dellemc_z9332f_d1508-r0/plugins/eeprom.py +++ b/device/dell/x86_64-dellemc_z9332f_d1508-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # DellEMC Z9332f # diff --git a/device/delta/x86_64-delta_ag5648-r0/plugins/eeprom.py b/device/delta/x86_64-delta_ag5648-r0/plugins/eeprom.py index 7d4054fb5a0c..9112318a7915 100644 --- a/device/delta/x86_64-delta_ag5648-r0/plugins/eeprom.py +++ b/device/delta/x86_64-delta_ag5648-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Mellanox # diff --git a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/led_control.py b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/led_control.py index d54e538a34b1..6078177d8bc5 100644 --- a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/led_control.py +++ b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/led_control.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # # Name: led_control.py version: 1.0 # diff --git a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/psuutil.py b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/psuutil.py index a7fef390b2a0..2038f8e50ee7 100644 --- a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/psuutil.py +++ b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/psuutil.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # # Name: psuutil.py version: 1.0 # diff --git a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/qfx5200_eeprom_data.py b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/qfx5200_eeprom_data.py index 84fecd1e3731..e257aae91e93 100644 --- a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/qfx5200_eeprom_data.py +++ b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/qfx5200_eeprom_data.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Name: juniper_qfx5200_eepromconv.py version: 1.0 # diff --git a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/qfx5200_sfp_init.py b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/qfx5200_sfp_init.py index 374b5322f2dd..4a133d3de912 100644 --- a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/qfx5200_sfp_init.py +++ b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/qfx5200_sfp_init.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Name: juniper_sfp_init.py version: 1.0 # diff --git a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/sfputil.py b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/sfputil.py index 288c8b58e768..3a676430721c 100644 --- a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/sfputil.py +++ b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python -# # Name: sfputil.py version: 1.0 # # Description: Platform-specific SFP transceiver interface for Juniper QFX5200 diff --git a/device/juniper/x86_64-juniper_qfx5210-r0/plugins/psuutil.py b/device/juniper/x86_64-juniper_qfx5210-r0/plugins/psuutil.py index 707c7c897c82..512127fa18fb 100644 --- a/device/juniper/x86_64-juniper_qfx5210-r0/plugins/psuutil.py +++ b/device/juniper/x86_64-juniper_qfx5210-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Accton # diff --git a/device/juniper/x86_64-juniper_qfx5210-r0/plugins/qfx5210_eeprom_data.py b/device/juniper/x86_64-juniper_qfx5210-r0/plugins/qfx5210_eeprom_data.py index eae6b42dd8e5..c80322406f5e 100644 --- a/device/juniper/x86_64-juniper_qfx5210-r0/plugins/qfx5210_eeprom_data.py +++ b/device/juniper/x86_64-juniper_qfx5210-r0/plugins/qfx5210_eeprom_data.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Name: juniper_qfx5210_eepromconv.py version: 1.0 # diff --git a/device/juniper/x86_64-juniper_qfx5210-r0/plugins/sfputil.py b/device/juniper/x86_64-juniper_qfx5210-r0/plugins/sfputil.py index fc5b10a4b481..9fd51a6b1c84 100644 --- a/device/juniper/x86_64-juniper_qfx5210-r0/plugins/sfputil.py +++ b/device/juniper/x86_64-juniper_qfx5210-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - try: import time from sonic_sfp.sfputilbase import * diff --git a/device/marvell/arm64-marvell_db98cx8580_16cd-r0/plugins/sfputil.py b/device/marvell/arm64-marvell_db98cx8580_16cd-r0/plugins/sfputil.py index 2ba575ba8cea..193adf148ffc 100644 --- a/device/marvell/arm64-marvell_db98cx8580_16cd-r0/plugins/sfputil.py +++ b/device/marvell/arm64-marvell_db98cx8580_16cd-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - try: import os import time diff --git a/device/marvell/arm64-marvell_db98cx8580_32cd-r0/plugins/sfputil.py b/device/marvell/arm64-marvell_db98cx8580_32cd-r0/plugins/sfputil.py index 72c2e1944743..6dc6a0a8c897 100644 --- a/device/marvell/arm64-marvell_db98cx8580_32cd-r0/plugins/sfputil.py +++ b/device/marvell/arm64-marvell_db98cx8580_32cd-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - try: import os import time diff --git a/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/psuutil.py b/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/psuutil.py index 298acfc5c0ed..65f339e6647d 100755 --- a/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/psuutil.py +++ b/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - import sys import os.path if sys.version_info[0] < 3: diff --git a/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/sfputil.py b/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/sfputil.py index 252ec9cd9930..74cf86ed1034 100755 --- a/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/sfputil.py +++ b/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - try: import os import time diff --git a/device/marvell/x86_64-marvell_db98cx8580_16cd-r0/plugins/sfputil.py b/device/marvell/x86_64-marvell_db98cx8580_16cd-r0/plugins/sfputil.py index 2ba575ba8cea..193adf148ffc 100644 --- a/device/marvell/x86_64-marvell_db98cx8580_16cd-r0/plugins/sfputil.py +++ b/device/marvell/x86_64-marvell_db98cx8580_16cd-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - try: import os import time diff --git a/device/marvell/x86_64-marvell_db98cx8580_32cd-r0/plugins/sfputil.py b/device/marvell/x86_64-marvell_db98cx8580_32cd-r0/plugins/sfputil.py index 72c2e1944743..6dc6a0a8c897 100644 --- a/device/marvell/x86_64-marvell_db98cx8580_32cd-r0/plugins/sfputil.py +++ b/device/marvell/x86_64-marvell_db98cx8580_32cd-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - try: import os import time diff --git a/device/marvell/x86_64-marvell_slm5401_54x-r0/plugins/sfputil.py b/device/marvell/x86_64-marvell_slm5401_54x-r0/plugins/sfputil.py index 02937b48a18c..aeb3a0d512f9 100755 --- a/device/marvell/x86_64-marvell_slm5401_54x-r0/plugins/sfputil.py +++ b/device/marvell/x86_64-marvell_slm5401_54x-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - try: import time from sonic_sfp.sfputilbase import SfpUtilBase diff --git a/device/mellanox/x86_64-mlnx_msn2010-r0/plugins/psuutil.py b/device/mellanox/x86_64-mlnx_msn2010-r0/plugins/psuutil.py index a51a9b07292c..051e6bfe1044 100644 --- a/device/mellanox/x86_64-mlnx_msn2010-r0/plugins/psuutil.py +++ b/device/mellanox/x86_64-mlnx_msn2010-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Mellanox # diff --git a/device/mellanox/x86_64-mlnx_msn2100-r0/plugins/psuutil.py b/device/mellanox/x86_64-mlnx_msn2100-r0/plugins/psuutil.py index b14b1d9dac4d..8498b0ce906c 100644 --- a/device/mellanox/x86_64-mlnx_msn2100-r0/plugins/psuutil.py +++ b/device/mellanox/x86_64-mlnx_msn2100-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Mellanox # diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/fanutil.py b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/fanutil.py index 429bf44750a2..0a5559c34b06 100644 --- a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/fanutil.py +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/fanutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Mellanox # diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/psuutil.py b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/psuutil.py index cd01a1905a06..64f1ab9a080d 100644 --- a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/psuutil.py +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/psuutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Mellanox # diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfplpmget.py b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfplpmget.py index 9ef787ff62c4..5964736dbb53 100644 --- a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfplpmget.py +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfplpmget.py @@ -1,4 +1,5 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 + """ This utility get the power mode of a given module. """ diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfplpmset.py b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfplpmset.py index 5b005219cbe8..8fbc87daf720 100644 --- a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfplpmset.py +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfplpmset.py @@ -1,4 +1,5 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 + """ This utility set the power mode of a given module. """ diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfpreset.py b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfpreset.py index 2e6de2e8bc8c..af237b705e9f 100644 --- a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfpreset.py +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfpreset.py @@ -1,28 +1,29 @@ -#!/usr/bin/env python -""" -This utility reset the given SFP module. -""" - -import sys -import errno -from python_sdk_api.sx_api import * - -# Check if SFP port number is provided -if len(sys.argv) < 2: - print("SFP module number or LPM is missed.") - print("Usage: sfpreset.py ") - sys.exit(errno.EINVAL) - -# Init SDK API -rc, handle = sx_api_open(None) -if rc != SX_STATUS_SUCCESS: - print("Failed to open api handle.\nPlease check that SDK is running.") - sys.exit(errno.EACCES) - -# Get SFP module number -sfp_module = int(sys.argv[1]) - 1 - -rc = sx_mgmt_phy_mod_reset(handle, sfp_module) -assert rc == SX_STATUS_SUCCESS, "sx_mgmt_phy_mod_reset failed, rc = %d" % rc - -sx_api_close(handle) +#!/usr/bin/env python3 + +""" +This utility reset the given SFP module. +""" + +import sys +import errno +from python_sdk_api.sx_api import * + +# Check if SFP port number is provided +if len(sys.argv) < 2: + print("SFP module number or LPM is missed.") + print("Usage: sfpreset.py ") + sys.exit(errno.EINVAL) + +# Init SDK API +rc, handle = sx_api_open(None) +if rc != SX_STATUS_SUCCESS: + print("Failed to open api handle.\nPlease check that SDK is running.") + sys.exit(errno.EACCES) + +# Get SFP module number +sfp_module = int(sys.argv[1]) - 1 + +rc = sx_mgmt_phy_mod_reset(handle, sfp_module) +assert rc == SX_STATUS_SUCCESS, "sx_mgmt_phy_mod_reset failed, rc = %d" % rc + +sx_api_close(handle) diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/thermalutil.py b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/thermalutil.py index 73d27a41ac23..c7513711f48f 100644 --- a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/thermalutil.py +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/thermalutil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # Mellanox # diff --git a/device/pegatron/x86_64-pegatron_porsche-r0/plugins/sfputil.py b/device/pegatron/x86_64-pegatron_porsche-r0/plugins/sfputil.py index 0db85c29545f..e28480604265 100755 --- a/device/pegatron/x86_64-pegatron_porsche-r0/plugins/sfputil.py +++ b/device/pegatron/x86_64-pegatron_porsche-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - try: import os import re diff --git a/device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/sfputil.py b/device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/sfputil.py index c967ccfc224a..2bb471970919 100755 --- a/device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/sfputil.py +++ b/device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - try: import time from sonic_sfp.sfputilbase import SfpUtilBase diff --git a/device/quanta/x86_64-quanta_ix8c_bwde-r0/plugins/eeprom.py b/device/quanta/x86_64-quanta_ix8c_bwde-r0/plugins/eeprom.py index 3ac2cc5167f2..d65115b0b6e5 100644 --- a/device/quanta/x86_64-quanta_ix8c_bwde-r0/plugins/eeprom.py +++ b/device/quanta/x86_64-quanta_ix8c_bwde-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - try: import binascii import time diff --git a/device/quanta/x86_64-quanta_ix9_bwde-r0/plugins/eeprom.py b/device/quanta/x86_64-quanta_ix9_bwde-r0/plugins/eeprom.py index 3ac2cc5167f2..d65115b0b6e5 100644 --- a/device/quanta/x86_64-quanta_ix9_bwde-r0/plugins/eeprom.py +++ b/device/quanta/x86_64-quanta_ix9_bwde-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - try: import binascii import time diff --git a/device/quanta/x86_64-quanta_ix9_bwde-r0/plugins/sfputil.py b/device/quanta/x86_64-quanta_ix9_bwde-r0/plugins/sfputil.py index f6afa59ce7c6..2d591d300f50 100644 --- a/device/quanta/x86_64-quanta_ix9_bwde-r0/plugins/sfputil.py +++ b/device/quanta/x86_64-quanta_ix9_bwde-r0/plugins/sfputil.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - try: import time from sonic_sfp.sfputilbase import SfpUtilBase diff --git a/device/virtual/x86_64-kvm_x86_64-r0/plugins/eeprom.py b/device/virtual/x86_64-kvm_x86_64-r0/plugins/eeprom.py index 4fa5d4e91eaa..9e5324acced1 100644 --- a/device/virtual/x86_64-kvm_x86_64-r0/plugins/eeprom.py +++ b/device/virtual/x86_64-kvm_x86_64-r0/plugins/eeprom.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - ############################################################################# # SONiC Virtual switch platform # From 2e4475e94bbd68b5fb9244bf6ca4f54e075e772c Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Tue, 24 Nov 2020 01:17:41 +0000 Subject: [PATCH 20/24] Replace tabs with spaces in Python plugins; fix alignment using autopep8 --- .../plugins/sfputil.py | 154 ++++--- .../plugins/sfputil.py | 56 +-- .../plugins/sfputil.py | 152 ++++--- .../plugins/sfputil.py | 120 +++--- .../sonic_platform/psu.py | 12 +- .../sonic_platform/sfp.py | 3 +- .../plugins/sfputil.py | 92 ++-- .../plugins/sfputil.py | 160 +++---- .../plugins/led_control.py | 250 +++++------ .../plugins/led_control.py | 186 +++++---- .../plugins/eeprom.py | 84 ++-- .../plugins/psuutil.py | 22 +- .../plugins/sfputil.py | 20 +- .../plugins/sfputil.py | 11 +- .../plugins/sfputil.py | 23 +- device/common/pddf/plugins/ledutil.py | 53 +-- .../plugins/sfputil.py | 193 +++++---- .../plugins/sfputil.py | 302 +++++++------- .../plugins/sfputil.py | 154 +++---- .../x86_64-delta_ag5648-r0/plugins/eeprom.py | 7 +- .../x86_64-delta_ag5648-r0/plugins/sfputil.py | 9 +- .../plugins/eeprom.py | 7 +- .../plugins/eeprom.py | 7 +- .../x86_64-delta_ag9064-r0/plugins/eeprom.py | 7 +- .../plugins/eeprom.py | 7 +- .../plugins/eeprom.py | 7 +- .../plugins/psuutil.py | 28 +- .../plugins/sfputil.py | 18 +- .../plugins/sfputil.py | 394 ++++++++++-------- .../plugins/sfputil.py | 293 +++++++------ .../plugins/sfputil.py | 31 +- .../plugins/sfputil.py | 31 +- .../plugins/sfputil.py | 31 +- .../plugins/sfputil.py | 31 +- 34 files changed, 1538 insertions(+), 1417 deletions(-) diff --git a/device/accton/x86_64-accton_as5712_54x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as5712_54x-r0/plugins/sfputil.py index 9ed06a3cb618..5002d842a15f 100755 --- a/device/accton/x86_64-accton_as5712_54x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as5712_54x-r0/plugins/sfputil.py @@ -12,7 +12,7 @@ raise ImportError("%s - required module not found" % str(e)) -#from xcvrd +# from xcvrd SFP_STATUS_INSERTED = '1' SFP_STATUS_REMOVED = '0' @@ -32,7 +32,7 @@ class SfpUtil(SfpUtilBase): BASE_CPLD3_PATH = "/sys/bus/i2c/devices/{0}-0062/" I2C_BUS_ORDER = -1 - #The sidebands of QSFP is different. + # The sidebands of QSFP is different. qsfp_sb_map = [0, 2, 4, 1, 3, 5] _port_to_is_present = {} @@ -40,61 +40,61 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _port_to_i2c_mapping = { - 1: [1, 2], - 2: [2, 3], - 3: [3, 4], - 4: [4, 5], - 5: [5, 6], - 6: [6, 7], - 7: [7, 8], - 8: [8, 9], - 9: [9, 10], - 10: [10, 11], - 11: [11, 12], - 12: [12, 13], - 13: [13, 14], - 14: [14, 15], - 15: [15, 16], - 16: [16, 17], - 17: [17, 18], - 18: [18, 19], - 19: [19, 20], - 20: [20, 21], - 21: [21, 22], - 22: [22, 23], - 23: [23, 24], - 24: [24, 25], - 25: [25, 26], - 26: [26, 27], - 27: [27, 28], - 28: [28, 29], - 29: [29, 30], - 30: [30, 31], - 31: [31, 32], - 32: [32, 33], - 33: [33, 34], - 34: [34, 35], - 35: [35, 36], - 36: [36, 37], - 37: [37, 38], - 38: [38, 39], - 39: [39, 40], - 40: [40, 41], - 41: [41, 42], - 42: [42, 43], - 43: [43, 44], - 44: [44, 45], - 45: [45, 46], - 46: [46, 47], - 47: [47, 48], - 48: [48, 49], - 49: [49, 50],#QSFP49 - 50: [51, 52], - 51: [53, 54], - 52: [50, 51], - 53: [52, 53], - 54: [54, 55],#QSFP54 - } + 1: [1, 2], + 2: [2, 3], + 3: [3, 4], + 4: [4, 5], + 5: [5, 6], + 6: [6, 7], + 7: [7, 8], + 8: [8, 9], + 9: [9, 10], + 10: [10, 11], + 11: [11, 12], + 12: [12, 13], + 13: [13, 14], + 14: [14, 15], + 15: [15, 16], + 16: [16, 17], + 17: [17, 18], + 18: [18, 19], + 19: [19, 20], + 20: [20, 21], + 21: [21, 22], + 22: [22, 23], + 23: [23, 24], + 24: [24, 25], + 25: [25, 26], + 26: [26, 27], + 27: [27, 28], + 28: [28, 29], + 29: [29, 30], + 30: [30, 31], + 31: [31, 32], + 32: [32, 33], + 33: [33, 34], + 34: [34, 35], + 35: [35, 36], + 36: [36, 37], + 37: [37, 38], + 38: [38, 39], + 39: [39, 40], + 40: [40, 41], + 41: [41, 42], + 42: [42, 43], + 43: [43, 44], + 44: [44, 45], + 45: [45, 46], + 46: [46, 47], + 47: [47, 48], + 48: [48, 49], + 49: [49, 50], # QSFP49 + 50: [51, 52], + 51: [53, 54], + 52: [50, 51], + 53: [52, 53], + 54: [54, 55], # QSFP54 + } @property def port_start(self): @@ -120,7 +120,7 @@ def qsfp_ports(self): def port_to_eeprom_mapping(self): return self._port_to_eeprom_mapping - #Two i2c buses might get flipped order, check them both. + # Two i2c buses might get flipped order, check them both. def update_i2c_order(self): if self.I2C_BUS_ORDER < 0: eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom" @@ -144,7 +144,7 @@ def get_presence(self, port_num): present_path = present_path + "module_present_" + str(port_num) self.__port_to_is_present = present_path - content="0" + content = "0" try: val_file = open(self.__port_to_is_present) content = val_file.readline().rstrip() @@ -174,7 +174,7 @@ def get_low_power_mode_cpld(self, port_num): q = self.qsfp_sb_remap(port_num) lp_mode_path = lp_mode_path + str(q) - content="0" + content = "0" try: val_file = open(lp_mode_path) content = val_file.readline().rstrip() @@ -202,13 +202,13 @@ def get_low_power_mode(self, port_num): eeprom.seek(93) lpmode = ord(eeprom.read(1)) - if not (lpmode & 0x1): # 'Power override' bit is 0 + if not (lpmode & 0x1): # 'Power override' bit is 0 return self.get_low_power_mode_cpld(port_num) else: if ((lpmode & 0x2) == 0x2): - return True # Low Power Mode if "Power set" bit is 1 + return True # Low Power Mode if "Power set" bit is 1 else: - return False # High Power Mode if "Power set" bit is 0 + return False # High Power Mode if "Power set" bit is 0 except IOError as err: print("Error: unable to open file: %s" % str(err)) return False @@ -225,10 +225,10 @@ def set_low_power_mode(self, port_num, lpmode): eeprom = None if not self.get_presence(port_num): - return False # Port is not present, unable to set the eeprom + return False # Port is not present, unable to set the eeprom # 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) @@ -260,7 +260,7 @@ def reset(self, port_num): print("Error: unable to open file: %s" % str(e)) return False - #toggle reset + # toggle reset reg_file.seek(0) reg_file.write('0') time.sleep(1) @@ -271,7 +271,7 @@ def reset(self, port_num): @property def _get_presence_bitmap(self): - nodes = [] + nodes = [] order = self.update_i2c_order() present_path = self.BASE_CPLD2_PATH.format(order) @@ -279,8 +279,8 @@ def _get_presence_bitmap(self): present_path = self.BASE_CPLD3_PATH.format(order) nodes.append(present_path + "module_present_all") - bitmap = "" - for node in nodes: + bitmap = "" + for node in nodes: try: reg_file = open(node) @@ -292,10 +292,10 @@ def _get_presence_bitmap(self): rev = bitmap.split(" ") rev = "".join(rev[::-1]) - return int(rev,16) + return int(rev, 16) + data = {'valid': 0, 'last': 0, 'present': 0} - data = {'valid':0, 'last':0, 'present':0} def get_transceiver_change_event(self, timeout=2000): now = time.time() port_dict = {} @@ -303,8 +303,7 @@ def get_transceiver_change_event(self, timeout=2000): if timeout < 1000: timeout = 1000 - timeout = (timeout) / float(1000) # Convert to secs - + timeout = (timeout) / float(1000) # Convert to secs if now < (self.data['last'] + timeout) and self.data['valid']: return True, {} @@ -312,7 +311,7 @@ def get_transceiver_change_event(self, timeout=2000): reg_value = self._get_presence_bitmap changed_ports = self.data['present'] ^ reg_value if changed_ports: - for port in range (self.port_start, self.port_end+1): + for port in range(self.port_start, self.port_end+1): # Mask off the bit corresponding to our port fp_port = self._port_to_i2c_mapping[port][0] mask = (1 << (fp_port - 1)) @@ -333,17 +332,12 @@ def get_transceiver_change_event(self, timeout=2000): return True, {} return False, {} - def __init__(self): eeprom_path = self.BASE_OOM_PATH + "eeprom" for x in range(self.port_start, self.port_end+1): self.port_to_eeprom_mapping[x] = eeprom_path.format( self._port_to_i2c_mapping[x][1] - ) + ) SfpUtilBase.__init__(self) - - - - diff --git a/device/accton/x86_64-accton_as5812_54t-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as5812_54t-r0/plugins/sfputil.py index f932f6a6d49f..38beeaf6ca5e 100755 --- a/device/accton/x86_64-accton_as5812_54t-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as5812_54t-r0/plugins/sfputil.py @@ -10,7 +10,7 @@ except ImportError as e: raise ImportError("%s - required module not found" % str(e)) -#from xcvrd +# from xcvrd SFP_STATUS_INSERTED = '1' SFP_STATUS_REMOVED = '0' @@ -29,9 +29,9 @@ class SfpUtil(SfpUtilBase): BASE_CPLD_PATH = "/sys/bus/i2c/devices/{0}-0060/" I2C_BUS_ORDER = -1 - #The sidebands of QSFP is different. - #present is in-order. - #But lp_mode and reset are not. + # The sidebands of QSFP is different. + # present is in-order. + # But lp_mode and reset are not. qsfp_sb_map = [0, 2, 4, 1, 3, 5] _port_to_is_present = {} @@ -39,13 +39,13 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _port_to_i2c_mapping = { - 49: [1,4],#QSFP_start - 50: [2,6], - 51: [3,3], - 52: [4,5], - 53: [5,7], - 54: [6,2], - } + 49: [1, 4], # QSFP_start + 50: [2, 6], + 51: [3, 3], + 52: [4, 5], + 53: [5, 7], + 54: [6, 2], + } @property def port_start(self): @@ -77,10 +77,10 @@ def __init__(self): for x in range(self.port_start, self.port_end+1): self.port_to_eeprom_mapping[x] = eeprom_path.format( self._port_to_i2c_mapping[x][1] - ) + ) SfpUtilBase.__init__(self) - #Two i2c buses might get flipped order, check them both. + # Two i2c buses might get flipped order, check them both. def update_i2c_order(self): if self.I2C_BUS_ORDER < 0: eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom" @@ -101,7 +101,7 @@ def get_presence(self, port_num): present_path = present_path + "module_present_" + str(port_num) self.__port_to_is_present = present_path - content="0" + content = "0" try: val_file = open(self.__port_to_is_present) content = val_file.readline().rstrip() @@ -124,7 +124,7 @@ def get_low_power_mode_cpld(self, port_num): lp_mode_path = lp_mode_path + "module_lp_mode_" lp_mode_path = lp_mode_path + str(port_num) - content="0" + content = "0" try: val_file = open(lp_mode_path) content = val_file.readline().rstrip() @@ -151,13 +151,13 @@ def get_low_power_mode(self, port_num): eeprom.seek(93) lpmode = ord(eeprom.read(1)) - if not (lpmode & 0x1): # 'Power override' bit is 0 + if not (lpmode & 0x1): # 'Power override' bit is 0 return self.get_low_power_mode_cpld(port_num) else: if ((lpmode & 0x2) == 0x2): - return True # Low Power Mode if "Power set" bit is 1 + return True # Low Power Mode if "Power set" bit is 1 else: - return False # High Power Mode if "Power set" bit is 0 + return False # High Power Mode if "Power set" bit is 0 except IOError as err: print("Error: unable to open file: %s" % str(err)) return False @@ -174,10 +174,10 @@ def set_low_power_mode(self, port_num, lpmode): eeprom = None if not self.get_presence(port_num): - return False # Port is not present, unable to set the eeprom + return False # Port is not present, unable to set the eeprom # 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) @@ -210,7 +210,7 @@ def reset(self, port_num): print("Error: unable to open file: %s" % str(e)) return False - #toggle reset + # toggle reset reg_file.seek(0) reg_file.write('1') time.sleep(1) @@ -221,14 +221,14 @@ def reset(self, port_num): @property def _get_presence_bitmap(self): - nodes = [] + nodes = [] order = self.update_i2c_order() present_path = self.BASE_CPLD_PATH.format(order) nodes.append(present_path + "module_present_all") - bitmap = "" - for node in nodes: + bitmap = "" + for node in nodes: try: reg_file = open(node) @@ -240,10 +240,10 @@ def _get_presence_bitmap(self): rev = bitmap.split(" ") rev = "".join(rev[::-1]) - return int(rev,16) + return int(rev, 16) + data = {'present': 0} - data = {'present':0} def get_transceiver_change_event(self, timeout=2000): port_dict = {} port = 0 @@ -253,7 +253,7 @@ def get_transceiver_change_event(self, timeout=2000): else: cd_ms = timeout - #poll per second + # poll per second while cd_ms > 0: reg_value = self._get_presence_bitmap changed_ports = self.data['present'] ^ reg_value @@ -263,7 +263,7 @@ def get_transceiver_change_event(self, timeout=2000): cd_ms = cd_ms - 1000 if changed_ports: - for port in range (self.port_start, self.port_end+1): + for port in range(self.port_start, self.port_end+1): # Mask off the bit corresponding to our port fp_port = self._port_to_i2c_mapping[port][0] mask = (1 << (fp_port - 1)) diff --git a/device/accton/x86_64-accton_as5812_54x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as5812_54x-r0/plugins/sfputil.py index e4a6d13a84b8..be301aea493b 100755 --- a/device/accton/x86_64-accton_as5812_54x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as5812_54x-r0/plugins/sfputil.py @@ -10,7 +10,7 @@ except ImportError as e: raise ImportError("%s - required module not found" % str(e)) -#from xcvrd +# from xcvrd SFP_STATUS_INSERTED = '1' SFP_STATUS_REMOVED = '0' @@ -30,9 +30,9 @@ class SfpUtil(SfpUtilBase): BASE_CPLD3_PATH = "/sys/bus/i2c/devices/{0}-0062/" I2C_BUS_ORDER = -1 - #The sidebands of QSFP is different. - #present is in-order. - #But lp_mode and reset are not. + # The sidebands of QSFP is different. + # present is in-order. + # But lp_mode and reset are not. qsfp_sb_map = [0, 2, 4, 1, 3, 5] _port_to_is_present = {} @@ -40,61 +40,61 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _port_to_i2c_mapping = { - 1: [1, 2], - 2: [2, 3], - 3: [3, 4], - 4: [4, 5], - 5: [5, 6], - 6: [6, 7], - 7: [7, 8], - 8: [8, 9], - 9: [9, 10], - 10: [10,11], - 11: [11,12], - 12: [12,13], - 13: [13,14], - 14: [14,15], - 15: [15,16], - 16: [16,17], - 17: [17,18], - 18: [18,19], - 19: [19,20], - 20: [20,21], - 21: [21,22], - 22: [22,23], - 23: [23,24], - 24: [24,25], - 25: [25,26], - 26: [26,27], - 27: [27,28], - 28: [28,29], - 29: [29,30], - 30: [30,31], - 31: [31,32], - 32: [32,33], - 33: [33,34], - 34: [34,35], - 35: [35,36], - 36: [36,37], - 37: [37,38], - 38: [38,39], - 39: [39,40], - 40: [40,41], - 41: [41,42], - 42: [42,43], - 43: [43,44], - 44: [44,45], - 45: [45,46], - 46: [46,47], - 47: [47,48], - 48: [48,49], - 49: [49,50],#QSFP_start - 50: [51,52], - 51: [53,54], - 52: [50,51], - 53: [52,53], - 54: [54,55], - } + 1: [1, 2], + 2: [2, 3], + 3: [3, 4], + 4: [4, 5], + 5: [5, 6], + 6: [6, 7], + 7: [7, 8], + 8: [8, 9], + 9: [9, 10], + 10: [10, 11], + 11: [11, 12], + 12: [12, 13], + 13: [13, 14], + 14: [14, 15], + 15: [15, 16], + 16: [16, 17], + 17: [17, 18], + 18: [18, 19], + 19: [19, 20], + 20: [20, 21], + 21: [21, 22], + 22: [22, 23], + 23: [23, 24], + 24: [24, 25], + 25: [25, 26], + 26: [26, 27], + 27: [27, 28], + 28: [28, 29], + 29: [29, 30], + 30: [30, 31], + 31: [31, 32], + 32: [32, 33], + 33: [33, 34], + 34: [34, 35], + 35: [35, 36], + 36: [36, 37], + 37: [37, 38], + 38: [38, 39], + 39: [39, 40], + 40: [40, 41], + 41: [41, 42], + 42: [42, 43], + 43: [43, 44], + 44: [44, 45], + 45: [45, 46], + 46: [46, 47], + 47: [47, 48], + 48: [48, 49], + 49: [49, 50], # QSFP_start + 50: [51, 52], + 51: [53, 54], + 52: [50, 51], + 53: [52, 53], + 54: [54, 55], + } @property def port_start(self): @@ -126,10 +126,10 @@ def __init__(self): for x in range(self.port_start, self.port_end+1): self.port_to_eeprom_mapping[x] = eeprom_path.format( self._port_to_i2c_mapping[x][1] - ) + ) SfpUtilBase.__init__(self) - #Two i2c buses might get flipped order, check them both. + # Two i2c buses might get flipped order, check them both. def update_i2c_order(self): if self.I2C_BUS_ORDER < 0: eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom" @@ -154,7 +154,7 @@ def get_presence(self, port_num): present_path = present_path + "module_present_" + str(port_num) self.__port_to_is_present = present_path - content="0" + content = "0" try: val_file = open(self.__port_to_is_present) content = val_file.readline().rstrip() @@ -212,13 +212,13 @@ def get_low_power_mode(self, port_num): eeprom.seek(93) lpmode = ord(eeprom.read(1)) - if not (lpmode & 0x1): # 'Power override' bit is 0 + if not (lpmode & 0x1): # 'Power override' bit is 0 return self.get_low_power_mode_cpld(port_num) else: if ((lpmode & 0x2) == 0x2): - return True # Low Power Mode if "Power set" bit is 1 + return True # Low Power Mode if "Power set" bit is 1 else: - return False # High Power Mode if "Power set" bit is 0 + return False # High Power Mode if "Power set" bit is 0 except IOError as err: print("Error: unable to open file: %s" % str(err)) return False @@ -235,10 +235,10 @@ def set_low_power_mode(self, port_num, lpmode): eeprom = None if not self.get_presence(port_num): - return False # Port is not present, unable to set the eeprom + return False # Port is not present, unable to set the eeprom # 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) @@ -271,7 +271,7 @@ def reset(self, port_num): print("Error: unable to open file: %s" % str(e)) return False - #toggle reset + # toggle reset reg_file.seek(0) reg_file.write('0') time.sleep(1) @@ -282,7 +282,7 @@ def reset(self, port_num): @property def _get_presence_bitmap(self): - nodes = [] + nodes = [] order = self.update_i2c_order() present_path = self.BASE_CPLD2_PATH.format(order) @@ -290,8 +290,8 @@ def _get_presence_bitmap(self): present_path = self.BASE_CPLD3_PATH.format(order) nodes.append(present_path + "module_present_all") - bitmap = "" - for node in nodes: + bitmap = "" + for node in nodes: try: reg_file = open(node) @@ -303,10 +303,10 @@ def _get_presence_bitmap(self): rev = bitmap.split(" ") rev = "".join(rev[::-1]) - return int(rev,16) + return int(rev, 16) + data = {'valid': 0, 'last': 0, 'present': 0} - data = {'valid':0, 'last':0, 'present':0} def get_transceiver_change_event(self, timeout=2000): now = time.time() port_dict = {} @@ -314,8 +314,7 @@ def get_transceiver_change_event(self, timeout=2000): if timeout < 1000: timeout = 1000 - timeout = (timeout) / float(1000) # Convert to secs - + timeout = (timeout) / float(1000) # Convert to secs if now < (self.data['last'] + timeout) and self.data['valid']: return True, {} @@ -323,7 +322,7 @@ def get_transceiver_change_event(self, timeout=2000): reg_value = self._get_presence_bitmap changed_ports = self.data['present'] ^ reg_value if changed_ports: - for port in range (self.port_start, self.port_end+1): + for port in range(self.port_start, self.port_end+1): # Mask off the bit corresponding to our port fp_port = self._port_to_i2c_mapping[port][0] mask = (1 << (fp_port - 1)) @@ -343,4 +342,3 @@ def get_transceiver_change_event(self, timeout=2000): else: return True, {} return False, {} - diff --git a/device/accton/x86_64-accton_as7116_54x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7116_54x-r0/plugins/sfputil.py index bc904dbc9d46..9f678757f2a8 100644 --- a/device/accton/x86_64-accton_as7116_54x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7116_54x-r0/plugins/sfputil.py @@ -2,11 +2,12 @@ import time from sonic_sfp.sfputilbase import SfpUtilBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") SFP_STATUS_INSERTED = '1' SFP_STATUS_REMOVED = '0' + class SfpUtil(SfpUtilBase): """Platform specific SfpUtill class""" @@ -17,60 +18,60 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _port_to_i2c_mapping = { - 0 : 37, - 1 : 38, - 2 : 39, - 3 : 40, - 4 : 41, - 5 : 42, - 6 : 43, - 7 : 44, - 8 : 45, - 9 : 46, - 10 : 47, - 11 : 48, - 12 : 49, - 13 : 50, - 14 : 51, - 15 : 52, - 16 : 53, - 17 : 54, - 18 : 55, - 19 : 56, - 20 : 57, - 21 : 58, - 22 : 59, - 23 : 60, - 24 : 61, - 25 : 62, - 26 : 63, - 27 : 64, - 28 : 65, - 29 : 66, - 30 : 67, - 31 : 68, - 32 : 69, - 33 : 70, - 34 : 71, - 35 : 72, - 36 : 73, - 37 : 74, - 38 : 75, - 39 : 76, - 40 : 77, - 41 : 78, - 42 : 79, - 43 : 80, - 44 : 81, - 45 : 82, - 46 : 83, - 47 : 84, - 48 : 21, - 49 : 22, - 50 : 23, - 51 : 24, - 52 : 25, - 53 : 26, + 0: 37, + 1: 38, + 2: 39, + 3: 40, + 4: 41, + 5: 42, + 6: 43, + 7: 44, + 8: 45, + 9: 46, + 10: 47, + 11: 48, + 12: 49, + 13: 50, + 14: 51, + 15: 52, + 16: 53, + 17: 54, + 18: 55, + 19: 56, + 20: 57, + 21: 58, + 22: 59, + 23: 60, + 24: 61, + 25: 62, + 26: 63, + 27: 64, + 28: 65, + 29: 66, + 30: 67, + 31: 68, + 32: 69, + 33: 70, + 34: 71, + 35: 72, + 36: 73, + 37: 74, + 38: 75, + 39: 76, + 40: 77, + 41: 78, + 42: 79, + 43: 80, + 44: 81, + 45: 82, + 46: 83, + 47: 84, + 48: 21, + 49: 22, + 50: 23, + 51: 24, + 52: 25, + 53: 26, } _qsfp_ports = list(range(_qsfp_port_start, _ports_in_block + 1)) @@ -101,7 +102,7 @@ def reset(self, port_num): print("Error: unable to open file: %s" % str(e)) return False - #toggle reset + # toggle reset reg_file.seek(0) reg_file.write('1') time.sleep(1) @@ -155,17 +156,16 @@ def qsfp_ports(self): @property def port_to_eeprom_mapping(self): - return self._port_to_eeprom_mapping + return self._port_to_eeprom_mapping def get_transceiver_change_event(self, timeout=0): ret_present = dict() for phy_port in range(self._port_start, self._port_end + 1): last_present_status = SFP_STATUS_INSERTED if self.get_presence(phy_port) else SFP_STATUS_REMOVED if self._present_status[phy_port] != last_present_status: - ret_present[phy_port] = last_present_status - self._present_status[phy_port] = last_present_status + ret_present[phy_port] = last_present_status + self._present_status[phy_port] = last_present_status time.sleep(2) return True, ret_present - diff --git a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/psu.py b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/psu.py index 620d004cc97b..f53b7506bb3e 100644 --- a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/psu.py +++ b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/psu.py @@ -15,6 +15,7 @@ FAN_MAX_RPM = 9600 PSU_NAME_LIST = ["PSU-0", "PSU-1"] + class Psu(PsuBase): """Platform-specific Psu class""" @@ -25,7 +26,6 @@ def __init__(self): self.index = psu_index PsuBase.__init__(self) - def get_fan(self): """ Retrieves object representing the fan module contained in this PSU @@ -71,8 +71,8 @@ def get_presence(self): Returns: bool: True if PSU is present, False if not """ - attr_file ='psu_present' - attr_path = self.SYSFS_PSU_DIR[self.index-1] +'/' + attr_file + attr_file = 'psu_present' + attr_path = self.SYSFS_PSU_DIR[self.index-1] + '/' + attr_file status = 0 try: with open(attr_path, 'r') as psu_prs: @@ -89,11 +89,11 @@ def get_status(self): A boolean value, True if device is operating properly, False if not """ attr_file = 'psu_power_good' - attr_path = self.SYSFS_PSU_DIR[self.index-1] +'/' + attr_file + attr_path = self.SYSFS_PSU_DIR[self.index-1] + '/' + attr_file status = 0 try: - with open(attr_path, 'r') as power_status: - status = int(power_status.read()) + with open(attr_path, 'r') as power_status: + status = int(power_status.read()) except IOError: return False diff --git a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/sfp.py b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/sfp.py index 16f3ee4a77c2..9d85b96be730 100644 --- a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/sfp.py +++ b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/sfp.py @@ -103,6 +103,7 @@ 'Fibre Channel link length/Transmitter Technology', 'Fibre Channel transmission media', 'Fibre Channel Speed') + class Sfp(SfpBase): """Platform-specific Sfp class""" @@ -178,7 +179,7 @@ class Sfp(SfpBase): HWSKU = "Accton-AS7116-54X-R0" def __init__(self, sfp_index, sfp_type): - # Init index + # Init index self.index = sfp_index self.port_num = self.index + 1 self.sfp_type = sfp_type diff --git a/device/accton/x86_64-accton_as7315_27xb-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7315_27xb-r0/plugins/sfputil.py index d10177850216..983acfaea83b 100644 --- a/device/accton/x86_64-accton_as7315_27xb-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7315_27xb-r0/plugins/sfputil.py @@ -12,10 +12,11 @@ except ImportError as e: raise ImportError("%s - required module not found" % str(e)) -#from xcvrd +# from xcvrd SFP_STATUS_REMOVED = '0' SFP_STATUS_INSERTED = '1' + class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" @@ -31,37 +32,37 @@ class SfpUtil(SfpUtilBase): _port_to_lp_mode = {} _port_to_eeprom_mapping = {} - _cpld_mapping = [ "8-0063", "7-0064"] + _cpld_mapping = ["8-0063", "7-0064"] _port_to_i2c_mapping = { - 1: 26, - 2: 27, - 3: 28, - 4: 29, - 5: 30, - 6: 31, - 7: 32, - 8: 33, - 9: 34, - 10: 35, - 11: 36, - 12: 37, - 13: 38, - 14: 39, - 15: 40, - 16: 41, - 17: 42, - 18: 43, - 19: 44, - 20: 45, - 21: 46, - 22: 47, - 23: 48, - 24: 49, - 25: 21, #QSFP - 26: 22, - 27: 23, - } + 1: 26, + 2: 27, + 3: 28, + 4: 29, + 5: 30, + 6: 31, + 7: 32, + 8: 33, + 9: 34, + 10: 35, + 11: 36, + 12: 37, + 13: 38, + 14: 39, + 15: 40, + 16: 41, + 17: 42, + 18: 43, + 19: 44, + 20: 45, + 21: 46, + 22: 47, + 23: 48, + 24: 49, + 25: 21, # QSFP + 26: 22, + 27: 23, + } @property def port_start(self): @@ -111,7 +112,7 @@ def get_presence(self, port_num): cpld_i = self.get_cpld_num(port_num) cpld_ps = self._cpld_mapping[cpld_i] path = "/sys/bus/i2c/devices/{0}/present_{1}" - index = ((port_num-1)%24) +1 + index = ((port_num-1) % 24) + 1 port_ps = path.format(cpld_ps, index) content = "0" @@ -144,11 +145,11 @@ def get_low_power_mode(self, port_num): lpmode = ord(eeprom.read(1)) if ((lpmode & 0x3) == 0x3): - return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 + return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 else: - return 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 + return 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 except IOError as e: print("Error: unable to open file: %s" % str(e)) return False @@ -166,10 +167,10 @@ def set_low_power_mode(self, port_num, lpmode): eeprom = None if not self.get_presence(port_num): - return False # Port is not present, unable to set the eeprom + return False # Port is not present, unable to set the eeprom # 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) @@ -187,14 +188,14 @@ def set_low_power_mode(self, port_num, lpmode): time.sleep(0.01) def reset(self, port_num): - raise NotImplementedError + raise NotImplementedError @property def _get_present_bitmap(self): nodes = [] - port_num = [24,3] + port_num = [24, 3] - path = "/sys/bus/i2c/devices/{0}/" + path = "/sys/bus/i2c/devices/{0}/" cpld_path = path.format(self._cpld_mapping[0]) nodes.append((cpld_path + "module_present_all", port_num[0])) cpld_path = path.format(self._cpld_mapping[1]) @@ -213,9 +214,10 @@ def _get_present_bitmap(self): reg_file.close() rev = "".join(bitmap[::-1]) - return int(rev,16) + return int(rev, 16) + + data = {'valid': 0, 'last': 0, 'present': 0} - data = {'valid':0, 'last':0, 'present':0} def get_transceiver_change_event(self, timeout=2000): now = time.time() port_dict = {} @@ -223,7 +225,7 @@ def get_transceiver_change_event(self, timeout=2000): if timeout < 1000: timeout = 1000 - timeout = (timeout) / float(1000) # Convert to secs + timeout = (timeout) / float(1000) # Convert to secs if now < (self.data['last'] + timeout) and self.data['valid']: return True, {} @@ -231,7 +233,7 @@ def get_transceiver_change_event(self, timeout=2000): reg_value = self._get_present_bitmap changed_ports = self.data['present'] ^ reg_value if changed_ports: - for port in range (self.port_start, self.port_end+1): + for port in range(self.port_start, self.port_end+1): # Mask off the bit corresponding to our port mask = (1 << (port - 1)) if changed_ports & mask: @@ -249,5 +251,3 @@ def get_transceiver_change_event(self, timeout=2000): else: return True, {} return False, {} - - diff --git a/device/accton/x86_64-accton_as7816_64x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7816_64x-r0/plugins/sfputil.py index b6e3400b6c1f..7fea2a476655 100644 --- a/device/accton/x86_64-accton_as7816_64x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7816_64x-r0/plugins/sfputil.py @@ -4,12 +4,13 @@ from ctypes import create_string_buffer from sonic_sfp.sfputilbase import SfpUtilBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") -#from xcvrd +# from xcvrd SFP_STATUS_INSERTED = '1' SFP_STATUS_REMOVED = '0' + class SfpUtil(SfpUtilBase): """Platform specific SfpUtill class""" @@ -19,70 +20,70 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} port_to_i2c_mapping = { - 61 : 25, - 62 : 26, - 63 : 27, - 64 : 28, - 55 : 29, - 56 : 30, - 53 : 31, - 54 : 32, - 9 : 33, - 10 : 34, - 11 : 35, - 12 : 36, - 1 : 37, - 2 : 38, - 3 : 39, - 4 : 40, - 6 : 41, - 5 : 42, - 8 : 43, - 7 : 44, - 13 : 45, - 14 : 46, - 15 : 47, - 16 : 48, - 17 : 49, - 18 : 50, - 19 : 51, - 20 : 52, - 25 : 53, - 26 : 54, - 27 : 55, - 28 : 56, - 29 : 57, - 30 : 58, - 31 : 59, - 32 : 60, - 21 : 61, - 22 : 62, - 23 : 63, - 24 : 64, - 41 : 65, - 42 : 66, - 43 : 67, - 44 : 68, - 33 : 69, - 34 : 70, - 35 : 71, - 36 : 72, - 45 : 73, - 46 : 74, - 47 : 75, - 48 : 76, - 37 : 77, - 38 : 78, - 39 : 79, - 40 : 80, - 57 : 81, - 58 : 82, - 59 : 83, - 60 : 84, - 49 : 85, - 50 : 86, - 51 : 87, - 52 : 88,} + 61: 25, + 62: 26, + 63: 27, + 64: 28, + 55: 29, + 56: 30, + 53: 31, + 54: 32, + 9: 33, + 10: 34, + 11: 35, + 12: 36, + 1: 37, + 2: 38, + 3: 39, + 4: 40, + 6: 41, + 5: 42, + 8: 43, + 7: 44, + 13: 45, + 14: 46, + 15: 47, + 16: 48, + 17: 49, + 18: 50, + 19: 51, + 20: 52, + 25: 53, + 26: 54, + 27: 55, + 28: 56, + 29: 57, + 30: 58, + 31: 59, + 32: 60, + 21: 61, + 22: 62, + 23: 63, + 24: 64, + 41: 65, + 42: 66, + 43: 67, + 44: 68, + 33: 69, + 34: 70, + 35: 71, + 36: 72, + 45: 73, + 46: 74, + 47: 75, + 48: 76, + 37: 77, + 38: 78, + 39: 79, + 40: 80, + 57: 81, + 58: 82, + 59: 83, + 60: 84, + 49: 85, + 50: 86, + 51: 87, + 52: 88, } _qsfp_ports = list(range(0, ports_in_block + 1)) @@ -97,7 +98,7 @@ def reset(self, port_num): # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False - path = "/sys/bus/i2c/devices/19-0060/module_reset_{0}" + path = "/sys/bus/i2c/devices/19-0060/module_reset_{0}" port_ps = path.format(port_num) try: @@ -106,7 +107,7 @@ def reset(self, port_num): print("Error: unable to open file: %s" % str(e)) return False - #HW will clear reset after set. + # HW will clear reset after set. reg_file.seek(0) reg_file.write('1') reg_file.close() @@ -148,7 +149,7 @@ def qsfp_ports(self): @property def port_to_eeprom_mapping(self): - return self._port_to_eeprom_mapping + return self._port_to_eeprom_mapping def get_low_power_mode(self, port_num): # Check for invalid port_num @@ -166,11 +167,11 @@ def get_low_power_mode(self, port_num): lpmode = ord(eeprom.read(1)) if ((lpmode & 0x3) == 0x3): - return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 + return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 else: - return 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 + return 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 except IOError as e: print("Error: unable to open file: %s" % str(e)) return False @@ -188,10 +189,10 @@ def set_low_power_mode(self, port_num, lpmode): eeprom = None if not self.get_presence(port_num): - return False # Port is not present, unable to set the eeprom + return False # Port is not present, unable to set the eeprom # 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) @@ -228,10 +229,10 @@ def _get_present_bitmap(self): rev = bitmap.split(" ") rev = "".join(rev[::-1]) - return int(rev,16) + return int(rev, 16) + data = {'valid': 0, 'last': 0, 'present': 0} - data = {'valid':0, 'last':0, 'present':0} def get_transceiver_change_event(self, timeout=2000): now = time.time() port_dict = {} @@ -239,7 +240,7 @@ def get_transceiver_change_event(self, timeout=2000): if timeout < 1000: timeout = 1000 - timeout = (timeout) / float(1000) # Convert to secs + timeout = (timeout) / float(1000) # Convert to secs if now < (self.data['last'] + timeout) and self.data['valid']: return True, {} @@ -248,7 +249,7 @@ def get_transceiver_change_event(self, timeout=2000): reg_value = ~reg_value changed_ports = self.data['present'] ^ reg_value if changed_ports: - for port in range (self.port_start, self.port_end+1): + for port in range(self.port_start, self.port_end+1): # Mask off the bit corresponding to our port mask = (1 << (port - 1)) if changed_ports & mask: @@ -265,4 +266,3 @@ def get_transceiver_change_event(self, timeout=2000): else: return True, {} return False, {} - diff --git a/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/led_control.py b/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/led_control.py index b46770fbe694..98ac93699ef7 100644 --- a/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/led_control.py +++ b/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/led_control.py @@ -9,10 +9,11 @@ import time + class LedControlBase(object): -# __metaclass__ = abc.ABCMeta + # __metaclass__ = abc.ABCMeta -# @abc.abstractmethod + # @abc.abstractmethod def port_link_state_change(self, port, state): """ Called when port link state changes. Update port link state LED here. @@ -22,6 +23,7 @@ def port_link_state_change(self, port, state): """ return + ### Zion specified ### read_fan_fault = 0 is_fan_all_OK = 0 @@ -31,126 +33,127 @@ def port_link_state_change(self, port, state): is_reset_button_push = 0 ########################## + def sysled_task(): while True: system_led_check() time.sleep(5) - + ### Zion specified ### + + def system_led_check(): - global read_fan_fault, read_power_status, is_fan_all_OK, is_power_all_OK, is_thermal_high, is_reset_button_push - is_fan_all_OK = 1 - is_power_all_OK = 0 - is_thermal_high = 0 - is_reset_button_push = 0 - with open("/sys/bus/i2c/devices/1-005e/fan1_fault", "r") as f1: - read_fan_fault = f1.read() - with open("/sys/bus/i2c/devices/9-005f/fan1_led", "w") as f11: - if str(read_fan_fault) == str("1\n"): - is_fan_all_OK = 0 - f11.write("4") - else: - f11.write("1") - with open("/sys/bus/i2c/devices/1-005e/fan2_fault", "r") as f1: - read_fan_fault = f1.read() - with open("/sys/bus/i2c/devices/9-005f/fan2_led", "w") as f11: - if str(read_fan_fault) == str("1\n"): - is_fan_all_OK = 0 - f11.write("4") - else: - f11.write("1") - with open("/sys/bus/i2c/devices/1-005e/fan3_fault", "r") as f1: - read_fan_fault = f1.read() - with open("/sys/bus/i2c/devices/9-005f/fan3_led", "w") as f11: - if str(read_fan_fault) == str("1\n"): - is_fan_all_OK = 0 - f11.write("4") - else: - f11.write("1") - with open("/sys/bus/i2c/devices/1-005e/fan4_fault", "r") as f1: - read_fan_fault = f1.read() - with open("/sys/bus/i2c/devices/9-005f/fan4_led", "w") as f11: - if str(read_fan_fault) == str("1\n"): - is_fan_all_OK = 0 - f11.write("4") - else: - f11.write("1") - with open("/sys/bus/i2c/devices/1-005e/fan5_fault", "r") as f1: - read_fan_fault = f1.read() - with open("/sys/bus/i2c/devices/9-005f/fan5_led", "w") as f11: - if str(read_fan_fault) == str("1\n"): - is_fan_all_OK = 0 - f11.write("4") - else: - f11.write("1") - with open("/sys/bus/i2c/devices/1-005e/fan6_fault", "r") as f1: - read_fan_fault = f1.read() - with open("/sys/bus/i2c/devices/9-005f/fan6_led", "w") as f11: - if str(read_fan_fault) == str("1\n"): - is_fan_all_OK = 0 - f11.write("4") - else: - f11.write("1") - - - with open("/sys/bus/i2c/devices/1-005e/psu1_power_good", "r") as f1: - read_power_status = f1.read() - with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11: - if str(read_power_status) == str("1\n"): - f11.write("1") - else: - f11.write("4") - with open("/sys/bus/i2c/devices/1-005e/psu1_present", "r") as f1: - read_power_status = f1.read() - with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11: - if str(read_power_status) == str("1\n"): - is_power_all_OK = is_power_all_OK + 1 - f11.write("1") - else: - f11.write("4") - with open("/sys/bus/i2c/devices/1-005e/psu2_power_good", "r") as f1: - read_power_status = f1.read() - with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11: - if str(read_power_status) == str("1\n"): - f11.write("1") - else: - f11.write("4") - with open("/sys/bus/i2c/devices/1-005e/psu2_present", "r") as f1: - read_power_status = f1.read() - with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11: - if str(read_power_status) == str("1\n"): - is_power_all_OK = is_power_all_OK + 1 - f11.write("1") - else: - f11.write("4") - - - with open("/sys/bus/i2c/devices/9-005f/swi_ctrl", "r") as f5: - is_reset_button_push = f5.read() - if str(is_reset_button_push) == "1\n": - is_reset_button_push = 1 - else: - is_reset_button_push = 0 - - with open("/sys/bus/i2c/devices/4-004d/hwmon/hwmon3/temp1_input", "r") as f3: - is_thermal_high = f3.read() - if int(is_thermal_high) >= 70000: - is_thermal_high = 1 - else: - is_thermal_high = 0 - - with open("/sys/bus/i2c/devices/9-005f/sys_status", "w") as f2: - if is_reset_button_push == 1: - f2.write("3") - elif is_fan_all_OK == 0 or is_power_all_OK == 0 or is_thermal_high == 1: - f2.write("4") - else: - f2.write("1") - - return + global read_fan_fault, read_power_status, is_fan_all_OK, is_power_all_OK, is_thermal_high, is_reset_button_push + is_fan_all_OK = 1 + is_power_all_OK = 0 + is_thermal_high = 0 + is_reset_button_push = 0 + with open("/sys/bus/i2c/devices/1-005e/fan1_fault", "r") as f1: + read_fan_fault = f1.read() + with open("/sys/bus/i2c/devices/9-005f/fan1_led", "w") as f11: + if str(read_fan_fault) == str("1\n"): + is_fan_all_OK = 0 + f11.write("4") + else: + f11.write("1") + with open("/sys/bus/i2c/devices/1-005e/fan2_fault", "r") as f1: + read_fan_fault = f1.read() + with open("/sys/bus/i2c/devices/9-005f/fan2_led", "w") as f11: + if str(read_fan_fault) == str("1\n"): + is_fan_all_OK = 0 + f11.write("4") + else: + f11.write("1") + with open("/sys/bus/i2c/devices/1-005e/fan3_fault", "r") as f1: + read_fan_fault = f1.read() + with open("/sys/bus/i2c/devices/9-005f/fan3_led", "w") as f11: + if str(read_fan_fault) == str("1\n"): + is_fan_all_OK = 0 + f11.write("4") + else: + f11.write("1") + with open("/sys/bus/i2c/devices/1-005e/fan4_fault", "r") as f1: + read_fan_fault = f1.read() + with open("/sys/bus/i2c/devices/9-005f/fan4_led", "w") as f11: + if str(read_fan_fault) == str("1\n"): + is_fan_all_OK = 0 + f11.write("4") + else: + f11.write("1") + with open("/sys/bus/i2c/devices/1-005e/fan5_fault", "r") as f1: + read_fan_fault = f1.read() + with open("/sys/bus/i2c/devices/9-005f/fan5_led", "w") as f11: + if str(read_fan_fault) == str("1\n"): + is_fan_all_OK = 0 + f11.write("4") + else: + f11.write("1") + with open("/sys/bus/i2c/devices/1-005e/fan6_fault", "r") as f1: + read_fan_fault = f1.read() + with open("/sys/bus/i2c/devices/9-005f/fan6_led", "w") as f11: + if str(read_fan_fault) == str("1\n"): + is_fan_all_OK = 0 + f11.write("4") + else: + f11.write("1") + + with open("/sys/bus/i2c/devices/1-005e/psu1_power_good", "r") as f1: + read_power_status = f1.read() + with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11: + if str(read_power_status) == str("1\n"): + f11.write("1") + else: + f11.write("4") + with open("/sys/bus/i2c/devices/1-005e/psu1_present", "r") as f1: + read_power_status = f1.read() + with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11: + if str(read_power_status) == str("1\n"): + is_power_all_OK = is_power_all_OK + 1 + f11.write("1") + else: + f11.write("4") + with open("/sys/bus/i2c/devices/1-005e/psu2_power_good", "r") as f1: + read_power_status = f1.read() + with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11: + if str(read_power_status) == str("1\n"): + f11.write("1") + else: + f11.write("4") + with open("/sys/bus/i2c/devices/1-005e/psu2_present", "r") as f1: + read_power_status = f1.read() + with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11: + if str(read_power_status) == str("1\n"): + is_power_all_OK = is_power_all_OK + 1 + f11.write("1") + else: + f11.write("4") + + with open("/sys/bus/i2c/devices/9-005f/swi_ctrl", "r") as f5: + is_reset_button_push = f5.read() + if str(is_reset_button_push) == "1\n": + is_reset_button_push = 1 + else: + is_reset_button_push = 0 + + with open("/sys/bus/i2c/devices/4-004d/hwmon/hwmon3/temp1_input", "r") as f3: + is_thermal_high = f3.read() + if int(is_thermal_high) >= 70000: + is_thermal_high = 1 + else: + is_thermal_high = 0 + + with open("/sys/bus/i2c/devices/9-005f/sys_status", "w") as f2: + if is_reset_button_push == 1: + f2.write("3") + elif is_fan_all_OK == 0 or is_power_all_OK == 0 or is_thermal_high == 1: + f2.write("4") + else: + f2.write("1") + + return ########## - - + + class LedControl(LedControlBase): """Platform specific LED control class""" PORT_TABLE_PREFIX = "PORT_TABLE:" @@ -180,17 +183,18 @@ def _port_name_to_qsfp_index(self, port_name): swss = swsssdk.SonicV2Connector() swss.connect(swss.APPL_DB) - lanes = swss.get(swss.APPL_DB, self.PORT_TABLE_PREFIX + port_name, 'lanes') + lanes = swss.get( + swss.APPL_DB, self.PORT_TABLE_PREFIX + port_name, 'lanes') # SONiC port nums are 0-based and increment by 4 # Arista QSFP indices are 1-based and increment by 1 - return (((sonic_port_num/4) + 1), sonic_port_num%4, len(lanes.split(','))) - + return (((sonic_port_num/4) + 1), sonic_port_num % 4, len(lanes.split(','))) # Concrete implementation of port_link_state_change() method + def port_link_state_change_bk(self, port, state): qsfp_index, lane_index, lanes = self._port_name_to_qsfp_index(port) - + # Ignore invalid QSFP indices if qsfp_index <= 0 or lanes <= 0 or lanes > 4: return @@ -199,9 +203,11 @@ def port_link_state_change_bk(self, port, state): # whereas indices 25-32 are not breakout-capable, and only have one if qsfp_index <= self.QSFP_BREAKOUT_END_IDX: # assuming 40G, then we need to control four lanes - led_sysfs_paths = [ self.LED_SYSFS_PATH_BREAKOUT_CAPABLE.format(qsfp_index, i) for i in range(lane_index + 1, lane_index + 1 + lanes) ] + led_sysfs_paths = [self.LED_SYSFS_PATH_BREAKOUT_CAPABLE.format( + qsfp_index, i) for i in range(lane_index + 1, lane_index + 1 + lanes)] else: - led_sysfs_paths = [ self.LED_SYSFS_PATH_NO_BREAKOUT.format(qsfp_index) ] + led_sysfs_paths = [ + self.LED_SYSFS_PATH_NO_BREAKOUT.format(qsfp_index)] for led_sysfs_path in led_sysfs_paths: led_file = open(led_sysfs_path, "w") @@ -236,7 +242,7 @@ def __init__(self): f.write("1") with open("/sys/bus/i2c/devices/9-005f/fan6_led", "w") as f: f.write("1") - sysled_task() + sysled_task() # Initialize: Turn all front panel QSFP LEDs off # # for qsfp_index in range(self.QSFP_BREAKOUT_START_IDX, self.QSFP_BREAKOUT_END_IDX + 1): diff --git a/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/led_control.py b/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/led_control.py index 7d2c86afb4e5..53cc43c6cce3 100644 --- a/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/led_control.py +++ b/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/led_control.py @@ -1,5 +1,5 @@ # led_control.py -# +# # Platform-specific LED control functionality for SONiC # @@ -11,10 +11,11 @@ import time + class LedControlBase(object): -# __metaclass__ = abc.ABCMeta + # __metaclass__ = abc.ABCMeta -# @abc.abstractmethod + # @abc.abstractmethod def port_link_state_change(self, port, state): """ Called when port link state changes. Update port link state LED here. @@ -24,6 +25,7 @@ def port_link_state_change(self, port, state): """ return + ### Goreme specified ### read_fan_fault = 0 is_fan_all_OK = 0 @@ -33,91 +35,93 @@ def port_link_state_change(self, port, state): is_reset_button_push = 0 ########################## + def sysled_task(): while True: system_led_check() time.sleep(5) - -########## Goreme System LED checking + +# Goreme System LED checking + + def system_led_check(): - global read_fan_fault, read_power_status, is_fan_all_OK, is_power_all_OK, is_thermal_high, is_reset_button_push - is_fan_all_OK = 1 - is_power_all_OK = 0 - is_thermal_high = 0 - is_reset_button_push = 0 - with open("/sys/bus/i2c/devices/0-005e/fan1_fault", "r") as f1: - read_fan_fault = f1.read() - if str(read_fan_fault) == str("1\n"): - is_fan_all_OK = 0 - with open("/sys/bus/i2c/devices/0-005e/fan2_fault", "r") as f1: - read_fan_fault = f1.read() - if str(read_fan_fault) == str("1\n"): - is_fan_all_OK = 0 - with open("/sys/bus/i2c/devices/0-005e/fan3_fault", "r") as f1: - read_fan_fault = f1.read() - if str(read_fan_fault) == str("1\n"): - is_fan_all_OK = 0 - with open("/sys/bus/i2c/devices/0-005e/fan4_fault", "r") as f1: - read_fan_fault = f1.read() - if str(read_fan_fault) == str("1\n"): - is_fan_all_OK = 0 - - with open("/sys/bus/i2c/devices/8-005f/fan1_led", "w") as f11: - if int(is_fan_all_OK) == 1: - f11.write("1") - else: - f11.write("4") - - - with open("/sys/bus/i2c/devices/0-005e/psu1_power_good", "r") as f1: - read_power_status = f1.read() - if str(read_power_status) != str("1\n"): - is_power_all_OK = -10 - with open("/sys/bus/i2c/devices/0-005e/psu1_present", "r") as f1: - read_power_status = f1.read() - if str(read_power_status) == str("1\n"): - is_power_all_OK = is_power_all_OK + 1 - with open("/sys/bus/i2c/devices/0-005e/psu2_power_good", "r") as f1: - read_power_status = f1.read() - if str(read_power_status) != str("1\n"): - is_power_all_OK = -10 - with open("/sys/bus/i2c/devices/0-005e/psu2_present", "r") as f1: - read_power_status = f1.read() - if str(read_power_status) == str("1\n"): - is_power_all_OK = is_power_all_OK + 1 - - with open("/sys/bus/i2c/devices/8-005f/sys_pwr", "w") as f11: - if int(is_power_all_OK) > 0: - f11.write("1") - else: - f11.write("4") - - - with open("/sys/bus/i2c/devices/8-005f/swi_ctrl", "r") as f5: - is_reset_button_push = f5.read() - if str(is_reset_button_push) == "1\n": - is_reset_button_push = 1 - else: - is_reset_button_push = 0 - - with open("/sys/bus/i2c/devices/3-004d/hwmon/hwmon2/temp1_input", "r") as f3: - is_thermal_high = f3.read() - if int(is_thermal_high) >= 70000: - is_thermal_high = 1 - else: - is_thermal_high = 0 - - with open("/sys/bus/i2c/devices/8-005f/sys_status", "w") as f2: - if is_reset_button_push == 1: - f2.write("3") - elif is_fan_all_OK == 0 or is_power_all_OK == 0 or is_thermal_high == 1: - f2.write("4") - else: - f2.write("1") - - return + global read_fan_fault, read_power_status, is_fan_all_OK, is_power_all_OK, is_thermal_high, is_reset_button_push + is_fan_all_OK = 1 + is_power_all_OK = 0 + is_thermal_high = 0 + is_reset_button_push = 0 + with open("/sys/bus/i2c/devices/0-005e/fan1_fault", "r") as f1: + read_fan_fault = f1.read() + if str(read_fan_fault) == str("1\n"): + is_fan_all_OK = 0 + with open("/sys/bus/i2c/devices/0-005e/fan2_fault", "r") as f1: + read_fan_fault = f1.read() + if str(read_fan_fault) == str("1\n"): + is_fan_all_OK = 0 + with open("/sys/bus/i2c/devices/0-005e/fan3_fault", "r") as f1: + read_fan_fault = f1.read() + if str(read_fan_fault) == str("1\n"): + is_fan_all_OK = 0 + with open("/sys/bus/i2c/devices/0-005e/fan4_fault", "r") as f1: + read_fan_fault = f1.read() + if str(read_fan_fault) == str("1\n"): + is_fan_all_OK = 0 + + with open("/sys/bus/i2c/devices/8-005f/fan1_led", "w") as f11: + if int(is_fan_all_OK) == 1: + f11.write("1") + else: + f11.write("4") + + with open("/sys/bus/i2c/devices/0-005e/psu1_power_good", "r") as f1: + read_power_status = f1.read() + if str(read_power_status) != str("1\n"): + is_power_all_OK = -10 + with open("/sys/bus/i2c/devices/0-005e/psu1_present", "r") as f1: + read_power_status = f1.read() + if str(read_power_status) == str("1\n"): + is_power_all_OK = is_power_all_OK + 1 + with open("/sys/bus/i2c/devices/0-005e/psu2_power_good", "r") as f1: + read_power_status = f1.read() + if str(read_power_status) != str("1\n"): + is_power_all_OK = -10 + with open("/sys/bus/i2c/devices/0-005e/psu2_present", "r") as f1: + read_power_status = f1.read() + if str(read_power_status) == str("1\n"): + is_power_all_OK = is_power_all_OK + 1 + + with open("/sys/bus/i2c/devices/8-005f/sys_pwr", "w") as f11: + if int(is_power_all_OK) > 0: + f11.write("1") + else: + f11.write("4") + + with open("/sys/bus/i2c/devices/8-005f/swi_ctrl", "r") as f5: + is_reset_button_push = f5.read() + if str(is_reset_button_push) == "1\n": + is_reset_button_push = 1 + else: + is_reset_button_push = 0 + + with open("/sys/bus/i2c/devices/3-004d/hwmon/hwmon2/temp1_input", "r") as f3: + is_thermal_high = f3.read() + if int(is_thermal_high) >= 70000: + is_thermal_high = 1 + else: + is_thermal_high = 0 + + with open("/sys/bus/i2c/devices/8-005f/sys_status", "w") as f2: + if is_reset_button_push == 1: + f2.write("3") + elif is_fan_all_OK == 0 or is_power_all_OK == 0 or is_thermal_high == 1: + f2.write("4") + else: + f2.write("1") + + return ########## - + + class LedControl(LedControlBase): """Platform specific LED control class""" PORT_TABLE_PREFIX = "PORT_TABLE:" @@ -147,18 +151,18 @@ def _port_name_to_qsfp_index(self, port_name): swss = swsssdk.SonicV2Connector() swss.connect(swss.APPL_DB) - lanes = swss.get(swss.APPL_DB, self.PORT_TABLE_PREFIX + port_name, 'lanes') + lanes = swss.get( + swss.APPL_DB, self.PORT_TABLE_PREFIX + port_name, 'lanes') # SONiC port nums are 0-based and increment by 4 # Arista QSFP indices are 1-based and increment by 1 - return (((sonic_port_num/4) + 1), sonic_port_num%4, len(lanes.split(','))) - - + return (((sonic_port_num/4) + 1), sonic_port_num % 4, len(lanes.split(','))) # Concrete implementation of port_link_state_change() method + def port_link_state_change_bk(self, port, state): qsfp_index, lane_index, lanes = self._port_name_to_qsfp_index(port) - + # Ignore invalid QSFP indices if qsfp_index <= 0 or lanes <= 0 or lanes > 4: return @@ -167,9 +171,11 @@ def port_link_state_change_bk(self, port, state): # whereas indices 25-32 are not breakout-capable, and only have one if qsfp_index <= self.QSFP_BREAKOUT_END_IDX: # assuming 40G, then we need to control four lanes - led_sysfs_paths = [ self.LED_SYSFS_PATH_BREAKOUT_CAPABLE.format(qsfp_index, i) for i in range(lane_index + 1, lane_index + 1 + lanes) ] + led_sysfs_paths = [self.LED_SYSFS_PATH_BREAKOUT_CAPABLE.format( + qsfp_index, i) for i in range(lane_index + 1, lane_index + 1 + lanes)] else: - led_sysfs_paths = [ self.LED_SYSFS_PATH_NO_BREAKOUT.format(qsfp_index) ] + led_sysfs_paths = [ + self.LED_SYSFS_PATH_NO_BREAKOUT.format(qsfp_index)] for led_sysfs_path in led_sysfs_paths: led_file = open(led_sysfs_path, "w") @@ -200,7 +206,7 @@ def __init__(self): f.write("1") with open("/sys/bus/i2c/devices/8-005f/fan4_led", "w") as f: f.write("1") - sysled_task() + sysled_task() # Initialize: Turn all front panel QSFP LEDs off # # for qsfp_index in range(self.QSFP_BREAKOUT_START_IDX, self.QSFP_BREAKOUT_END_IDX + 1): diff --git a/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/eeprom.py b/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/eeprom.py index 3b0ee5fff37e..b94fab471b95 100644 --- a/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/eeprom.py +++ b/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/eeprom.py @@ -29,7 +29,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") if sys.version_info.major == 3: @@ -39,44 +39,44 @@ eeprom_default_dict = { - "prod_name" : ("Product Name", "0x21", 12), - "odm_pcba_part_num" : ("Part Number", "0x22", 13), - "prod_ser_num" : ("Serial Number", "0x23", 12), - "ext_mac_addr" : ("Extended MAC Address Base", "0x24", 12), - "sys_mfg_date" : ("System Manufacturing Date", "0x25", 4), - "prod_ver" : ("Product Version", "0x26", 1), - "ext_mac_addr_size" : ("Extende MAC Address Size", "0x2A", 2), - "sys_mfger" : ("Manufacturer", "0x2B", 8) + "prod_name": ("Product Name", "0x21", 12), + "odm_pcba_part_num": ("Part Number", "0x22", 13), + "prod_ser_num": ("Serial Number", "0x23", 12), + "ext_mac_addr": ("Extended MAC Address Base", "0x24", 12), + "sys_mfg_date": ("System Manufacturing Date", "0x25", 4), + "prod_ver": ("Product Version", "0x26", 1), + "ext_mac_addr_size": ("Extende MAC Address Size", "0x2A", 2), + "sys_mfger": ("Manufacturer", "0x2B", 8) } -eeprom_dict = { "version" : ("Version", None, 0), - "pcb_mfger" : ("PCB Manufacturer", "0x01", 8), - "prod_ser_num" : ("Serial Number", "0x23", 12), - "bfn_pcba_part_num" : ("Switch PCBA Part Number", "0x02", 12), - "odm_pcba_part_num" : ("Part Number", "0x22", 13), - "bfn_pcbb_part_num" : ("Switch PCBB Part Number", "0x04", 12), - "sys_asm_part_num" : ("System Assembly Part Number", "0x05", 12), - "prod_state" : ("Product Production State", "0x06", 1), - "location" : ("EEPROM Location of Fabric", "0x07", 8), - "ext_mac_addr_size" : ("Extende MAC Address Size", "0x08", 2), - "sys_mfg_date" : ("System Manufacturing Date", "0x25", 4), - "prod_name" : ("Product Name", "0x21", 12), - "prod_ver" : ("Product Version", "0x26", 1), - "prod_part_num" : ("Product Part Number", "0x09", 8), - "sys_mfger" : ("Manufacturer", "0x2B", 8), - "assembled_at" : ("Assembled at", "0x08", 8), - "prod_ast_tag" : ("Product Asset Tag", "0x09", 12), - "loc_mac_addr" : ("Local MAC address", "0x0A", 12), - "odm_pcba_ser_num" : ("ODM PBCA Serial Number", "0x0B", 12), - "ext_mac_addr" : ("Extended MAC Address Base", "0x0C", 12), - "prod_sub_ver" : ("Product Sub Version", "0x0D", 1) - } - -product_dict = { "Montara" : "Wedge100BF-32X-O-AC-F-BF", - "Lower MAV" : "Wedge100BF-65X-O-AC-F-BF", - "Upper MAV" : "Wedge100BF-65X-O-AC-F-BF" +eeprom_dict = {"version": ("Version", None, 0), + "pcb_mfger": ("PCB Manufacturer", "0x01", 8), + "prod_ser_num": ("Serial Number", "0x23", 12), + "bfn_pcba_part_num": ("Switch PCBA Part Number", "0x02", 12), + "odm_pcba_part_num": ("Part Number", "0x22", 13), + "bfn_pcbb_part_num": ("Switch PCBB Part Number", "0x04", 12), + "sys_asm_part_num": ("System Assembly Part Number", "0x05", 12), + "prod_state": ("Product Production State", "0x06", 1), + "location": ("EEPROM Location of Fabric", "0x07", 8), + "ext_mac_addr_size": ("Extende MAC Address Size", "0x08", 2), + "sys_mfg_date": ("System Manufacturing Date", "0x25", 4), + "prod_name": ("Product Name", "0x21", 12), + "prod_ver": ("Product Version", "0x26", 1), + "prod_part_num": ("Product Part Number", "0x09", 8), + "sys_mfger": ("Manufacturer", "0x2B", 8), + "assembled_at": ("Assembled at", "0x08", 8), + "prod_ast_tag": ("Product Asset Tag", "0x09", 12), + "loc_mac_addr": ("Local MAC address", "0x0A", 12), + "odm_pcba_ser_num": ("ODM PBCA Serial Number", "0x0B", 12), + "ext_mac_addr": ("Extended MAC Address Base", "0x0C", 12), + "prod_sub_ver": ("Product Sub Version", "0x0D", 1) } +product_dict = {"Montara": "Wedge100BF-32X-O-AC-F-BF", + "Lower MAV": "Wedge100BF-65X-O-AC-F-BF", + "Upper MAV": "Wedge100BF-65X-O-AC-F-BF" + } + thrift_server = 'localhost' transport = None pltfm_mgr = None @@ -84,6 +84,7 @@ EEPROM_SYMLINK = "/var/run/platform/eeprom/syseeprom" EEPROM_STATUS = "/var/run/platform/eeprom/status" + class board(eeprom_tlvinfo.TlvInfoDecoder): RETRIES = 35 @@ -122,8 +123,10 @@ def thrift_setup(self): transport = TTransport.TBufferedTransport(transport) bprotocol = TBinaryProtocol.TBinaryProtocol(transport) - pltfm_mgr_client_module = importlib.import_module(".".join(["pltfm_mgr_rpc", "pltfm_mgr_rpc"])) - pltfm_mgr_protocol = TMultiplexedProtocol.TMultiplexedProtocol(bprotocol, "pltfm_mgr_rpc") + pltfm_mgr_client_module = importlib.import_module( + ".".join(["pltfm_mgr_rpc", "pltfm_mgr_rpc"])) + pltfm_mgr_protocol = TMultiplexedProtocol.TMultiplexedProtocol( + bprotocol, "pltfm_mgr_rpc") pltfm_mgr = pltfm_mgr_client_module.Client(pltfm_mgr_protocol) transport.open() @@ -161,7 +164,8 @@ def eeprom_init(self): value = str(val) if attr == "sys_mfg_date": - value = datetime.datetime.strptime(value, '%m-%d-%y').strftime('%m/%d/%Y 00:00:00') + value = datetime.datetime.strptime( + value, '%m-%d-%y').strftime('%m/%d/%Y 00:00:00') product = product_dict.get(value) if product is not None: @@ -172,9 +176,9 @@ def eeprom_init(self): orig_stdout = sys.stdout sys.stdout = StringIO() - new_e = eeprom_tlvinfo.TlvInfoDecoder.set_eeprom(self, "", [eeprom_params]) + new_e = eeprom_tlvinfo.TlvInfoDecoder.set_eeprom( + self, "", [eeprom_params]) sys.stdout = orig_stdout eeprom_base.EepromDecoder.write_eeprom(self, new_e) return True - diff --git a/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/psuutil.py b/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/psuutil.py index 796b1d0afecb..0ef5162d282c 100644 --- a/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/psuutil.py +++ b/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/psuutil.py @@ -14,12 +14,13 @@ from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") thrift_server = 'localhost' transport = None pltfm_mgr = None + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" @@ -33,8 +34,10 @@ def thrift_setup(self): transport = TTransport.TBufferedTransport(transport) bprotocol = TBinaryProtocol.TBinaryProtocol(transport) - pltfm_mgr_client_module = importlib.import_module(".".join(["pltfm_mgr_rpc", "pltfm_mgr_rpc"])) - pltfm_mgr_protocol = TMultiplexedProtocol.TMultiplexedProtocol(bprotocol, "pltfm_mgr_rpc") + pltfm_mgr_client_module = importlib.import_module( + ".".join(["pltfm_mgr_rpc", "pltfm_mgr_rpc"])) + pltfm_mgr_protocol = TMultiplexedProtocol.TMultiplexedProtocol( + bprotocol, "pltfm_mgr_rpc") pltfm_mgr = pltfm_mgr_client_module.Client(pltfm_mgr_protocol) transport.open() @@ -63,9 +66,9 @@ def get_psu_status(self, index): global pltfm_mgr try: - self.thrift_setup() - psu_info = pltfm_mgr.pltfm_mgr_pwr_supply_info_get(index) - self.thrift_teardown() + self.thrift_setup() + psu_info = pltfm_mgr.pltfm_mgr_pwr_supply_info_get(index) + self.thrift_teardown() except: return False @@ -84,11 +87,10 @@ def get_psu_presence(self, index): global pltfm_mgr try: - self.thrift_setup() - status = pltfm_mgr.pltfm_mgr_pwr_supply_present_get(index) - self.thrift_teardown() + self.thrift_setup() + status = pltfm_mgr.pltfm_mgr_pwr_supply_present_get(index) + self.thrift_teardown() except: return False return status - diff --git a/device/centec/arm64-centec_e530_24x2c-r0/plugins/sfputil.py b/device/centec/arm64-centec_e530_24x2c-r0/plugins/sfputil.py index 920ad0894079..c5c0dc8e16e0 100644 --- a/device/centec/arm64-centec_e530_24x2c-r0/plugins/sfputil.py +++ b/device/centec/arm64-centec_e530_24x2c-r0/plugins/sfputil.py @@ -15,9 +15,11 @@ def DBG_PRINT(str): print(str + "\n") + SFP_STATUS_INSERTED = '1' SFP_STATUS_REMOVED = '0' + class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" @@ -60,30 +62,30 @@ def get_eeprom_data(self, port): return ret # todo - #def _get_port_eeprom_path(self, port_num, devid): + # def _get_port_eeprom_path(self, port_num, devid): # pass def __init__(self): self.SONIC_PORT_NAME_PREFIX = "Ethernet" self.PORT_START = 1 self.PORT_END = 26 - self.SFP_BASE = 1 + self.SFP_BASE = 1 self.PORTS_IN_BLOCK = 26 self.logical = [] self.physical_to_logical = {} self.logical_to_physical = {} - self.eeprom_mapping = {} self.f_sfp_present = "/sys/class/sfp/sfp{}/sfp_presence" self.f_sfp_enable = "/sys/class/sfp/sfp{}/sfp_enable" - for x in range(self.port_start, self.sfp_base): + for x in range(self.port_start, self.sfp_base): self.eeprom_mapping[x] = None for x in range(self.sfp_base, self.port_end + 1): - self.eeprom_mapping[x] = "/sys/class/sfp/sfp{}/sfp_eeprom".format(x - self.sfp_base + 1) + self.eeprom_mapping[x] = "/sys/class/sfp/sfp{}/sfp_eeprom".format( + x - self.sfp_base + 1) self.presence = {} for x in range(self.sfp_base, self.port_end + 1): - self.presence[x] = False; + self.presence[x] = False SfpUtilBase.__init__(self) @@ -125,20 +127,20 @@ def reset(self, port_num): return False - def read_porttab_mappings(self, porttabfile): for x in range(self.sfp_base, self.port_end + 1): self.logical_to_physical['Ethernet' + str(x)] = [x] self.physical_to_logical[x] = ['Ethernet' + str(x)] - data = {'valid':0, 'last':0} + data = {'valid': 0, 'last': 0} + def get_transceiver_change_event(self, timeout=2000): now = time.time() port_dict = {} if timeout < 1000: timeout = 1000 - timeout = (timeout) / float(1000) # Convert to secs + timeout = (timeout) / float(1000) # Convert to secs if now < (self.data['last'] + timeout) and self.data['valid']: return True, {} diff --git a/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/sfputil.py b/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/sfputil.py index de0b32bf2eb2..f7094828eafb 100644 --- a/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/sfputil.py +++ b/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/sfputil.py @@ -66,26 +66,27 @@ def get_eeprom_data(self, port): return ret # todo - #def _get_port_eeprom_path(self, port_num, devid): + # def _get_port_eeprom_path(self, port_num, devid): # pass def __init__(self): self.SONIC_PORT_NAME_PREFIX = "Ethernet" self.PORT_START = 1 self.PORT_END = 52 - self.SFP_BASE = 49 + self.SFP_BASE = 49 self.PORTS_IN_BLOCK = 52 self.eeprom_mapping = {} self.f_sfp_present = "/sys/class/sfp/sfp{}/sfp_presence" self.f_sfp_enable = "/sys/class/sfp/sfp{}/sfp_enable" - for x in range(self.port_start, self.sfp_base): + for x in range(self.port_start, self.sfp_base): self.eeprom_mapping[x] = None for x in range(self.sfp_base, self.port_end + 1): - self.eeprom_mapping[x] = "/sys/class/sfp/sfp{}/sfp_eeprom".format(x - self.sfp_base + 1) + self.eeprom_mapping[x] = "/sys/class/sfp/sfp{}/sfp_eeprom".format( + x - self.sfp_base + 1) self.presence = {} for x in range(self.sfp_base, self.port_end + 1): - self.presence[x] = False; + self.presence[x] = False SfpUtilBase.__init__(self) diff --git a/device/centec/x86_64-ew_es6220_x48q2h4-r0/plugins/sfputil.py b/device/centec/x86_64-ew_es6220_x48q2h4-r0/plugins/sfputil.py index ab476ae648b3..103b3cd5630b 100644 --- a/device/centec/x86_64-ew_es6220_x48q2h4-r0/plugins/sfputil.py +++ b/device/centec/x86_64-ew_es6220_x48q2h4-r0/plugins/sfputil.py @@ -42,24 +42,26 @@ def __init__(self): eeprom_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-0050/eeprom" for x in range(0, self.port_end + 1): - self._port_to_eeprom_mapping[x] = eeprom_path.format(x + self.EEPROM_OFFSET) + self._port_to_eeprom_mapping[x] = eeprom_path.format( + x + self.EEPROM_OFFSET) SfpUtilBase.__init__(self) def get_presence(self, port_name): - #modify by zhw to get sfp presence + # modify by zhw to get sfp presence # Check for invalid port_num port_num = int(port_name[8:]) if port_num < (self.port_start+1) or port_num > (self.port_end+1): return False - #cpld info from "CPLD Register for es5800A2.2(V1.1)" - cpld_map = {0: '0x82', 1: '0x83', 2: '0x84', 3: '0x85', 4: '0x86', 5: '0x87', 6: '0x8E'} + # cpld info from "CPLD Register for es5800A2.2(V1.1)" + cpld_map = {0: '0x82', 1: '0x83', 2: '0x84', + 3: '0x85', 4: '0x86', 5: '0x87', 6: '0x8E'} cpld_key = (port_num - 1)/8 - cpld_mask = (1 << (port_num - 1)%8) + cpld_mask = (1 << (port_num - 1) % 8) - #use i2cget cmd to get cpld data + # use i2cget cmd to get cpld data output = os.popen('i2cdetect -l | grep CP') bus_num = output.read()[4] cmd = "i2cget -y "+bus_num+" 0x5 "+cpld_map[cpld_key] @@ -72,7 +74,7 @@ def get_presence(self, port_name): return False def get_low_power_mode(self, port_num): - ''' + ''' # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False @@ -93,7 +95,7 @@ def get_low_power_mode(self, port_num): # LPMode is active high if reg_value & mask == 0: return False - ''' + ''' return False def set_low_power_mode(self, port_num, lpmode): @@ -102,7 +104,8 @@ def set_low_power_mode(self, port_num, lpmode): return False try: - reg_file = open("/sys/devices/platform/dell-s6000-cpld.0/qsfp_lpmode", "r+") + reg_file = open( + "/sys/devices/platform/dell-s6000-cpld.0/qsfp_lpmode", "r+") except IOError as e: print("Error: unable to open file: %s" % str(e)) return False @@ -183,5 +186,3 @@ def get_transceiver_change_event(self): on this platform. """ raise NotImplementedError - - diff --git a/device/common/pddf/plugins/ledutil.py b/device/common/pddf/plugins/ledutil.py index 74db17744eb7..5f9e2e99dbfa 100755 --- a/device/common/pddf/plugins/ledutil.py +++ b/device/common/pddf/plugins/ledutil.py @@ -2,55 +2,58 @@ sys.path.append('/usr/share/sonic/platform/plugins') import pddfparse + class LedUtil: color_map = { - "STATUS_LED_COLOR_GREEN" : "on", - "STATUS_LED_COLOR_RED" : "faulty", - "STATUS_LED_COLOR_OFF" : "off" + "STATUS_LED_COLOR_GREEN": "on", + "STATUS_LED_COLOR_RED": "faulty", + "STATUS_LED_COLOR_OFF": "off" } def __init__(self): global pddf_obj pddf_obj = pddfparse.PddfParse() - self.path="pddf/devices/led" - self.cur_state_path="pddf/devices/led/cur_state" + self.path = "pddf/devices/led" + self.cur_state_path = "pddf/devices/led/cur_state" def set_status_led(self, led_device_name, color, color_state="SOLID"): if (not led_device_name in list(pddf_obj.data.keys())): - status="ERROR: " + led_device_name + " is not configured" - return (status) + status = "ERROR: " + led_device_name + " is not configured" + return (status) if (not color in list(self.color_map.keys())): - status="ERROR: Invalid color" - return (status) + status = "ERROR: Invalid color" + return (status) - index=pddf_obj.data[led_device_name]['dev_attr']['index'] + index = pddf_obj.data[led_device_name]['dev_attr']['index'] pddf_obj.create_attr('device_name', led_device_name, self.path) pddf_obj.create_attr('index', index, self.path) - pddf_obj.create_attr('color', self.color_map[color], self.cur_state_path) + pddf_obj.create_attr( + 'color', self.color_map[color], self.cur_state_path) pddf_obj.create_attr('color_state', color_state, self.cur_state_path) pddf_obj.create_attr('dev_ops', 'set_status', self.path) - return ("Executed") + return ("Executed") def get_status_led(self, led_device_name): if (not led_device_name in list(pddf_obj.data.keys())): - status="ERROR: " + led_device_name + " is not configured" - return (status) + status = "ERROR: " + led_device_name + " is not configured" + return (status) - index=pddf_obj.data[led_device_name]['dev_attr']['index'] + index = pddf_obj.data[led_device_name]['dev_attr']['index'] pddf_obj.create_attr('device_name', led_device_name, self.path) pddf_obj.create_attr('index', index, self.path) pddf_obj.create_attr('dev_ops', 'get_status', self.path) - color_f="/sys/kernel/" + self.cur_state_path +"/color" - color_state_f="/sys/kernel/" + self.cur_state_path +"/color_state" + color_f = "/sys/kernel/" + self.cur_state_path + "/color" + color_state_f = "/sys/kernel/" + self.cur_state_path + "/color_state" try: - with open(color_f, 'r') as f: - color = f.read().strip("\r\n") - with open(color_state_f, 'r') as f: - color_state = f.read().strip("\r\n") + with open(color_f, 'r') as f: + color = f.read().strip("\r\n") + with open(color_state_f, 'r') as f: + color_state = f.read().strip("\r\n") except IOError: - status="ERROR :" + color_f + " open failed" - return (status) - status = "%s-%s:\t%s %s\n"%(led_device_name, index, color, color_state) - return (status) + status = "ERROR :" + color_f + " open failed" + return (status) + status = "%s-%s:\t%s %s\n" % (led_device_name, + index, color, color_state) + return (status) diff --git a/device/dell/x86_64-dellemc_s5232f_c3538-r0/plugins/sfputil.py b/device/dell/x86_64-dellemc_s5232f_c3538-r0/plugins/sfputil.py index 8d6727bdbd10..f53e8e944d1e 100644 --- a/device/dell/x86_64-dellemc_s5232f_c3538-r0/plugins/sfputil.py +++ b/device/dell/x86_64-dellemc_s5232f_c3538-r0/plugins/sfputil.py @@ -45,6 +45,7 @@ XCVR_DOM_CAPABILITY_OFFSET = 92 XCVR_DOM_CAPABILITY_WIDTH = 1 + class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" @@ -76,8 +77,8 @@ def port_to_eeprom_mapping(self): def pci_mem_read(self, mm, offset): mm.seek(offset) - read_data_stream=mm.read(4) - reg_val=struct.unpack('I',read_data_stream) + read_data_stream = mm.read(4) + reg_val = struct.unpack('I', read_data_stream) mem_val = str(reg_val)[1:-2] # print "reg_val read:%x"%reg_val return mem_val @@ -85,7 +86,7 @@ def pci_mem_read(self, mm, offset): def pci_mem_write(self, mm, offset, data): mm.seek(offset) # print "data to write:%x"%data - mm.write(struct.pack('I',data)) + mm.write(struct.pack('I', data)) def pci_set_value(self, resource, val, offset): fd = open(resource, O_RDWR) @@ -115,9 +116,9 @@ def __init__(self): eeprom_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-0050/eeprom" for x in range(self.port_start, self.port_end + 1): - port_num = x + 1 + port_num = x + 1 self.port_to_eeprom_mapping[x] = eeprom_path.format( - port_num) + port_num) port_num = 0 self.init_global_port_presence() @@ -129,13 +130,13 @@ def get_presence(self, port_num): return False # Port offset starts with 0x4004 - port_offset = 16388 + ((port_num-1) * 16) + port_offset = 16388 + ((port_num-1) * 16) - status = self.pci_get_value(self.BASE_RES_PATH, port_offset) - reg_value = int(status) + status = self.pci_get_value(self.BASE_RES_PATH, port_offset) + reg_value = int(status) # Absence of status throws error - if (reg_value == "" ): + if (reg_value == ""): return False # Mask off 4th bit for presence @@ -143,8 +144,7 @@ def get_presence(self, port_num): # Mask off 1st bit for presence 33,34 if (port_num > 32): - mask = (1 << 0) - + mask = (1 << 0) # ModPrsL is active low if reg_value & mask == 0: @@ -158,14 +158,14 @@ def get_low_power_mode(self, port_num): if port_num < self.port_start or port_num > self.port_end: return False - # Port offset starts with 0x4000 - port_offset = 16384 + ((port_num-1) * 16) + # Port offset starts with 0x4000 + port_offset = 16384 + ((port_num-1) * 16) - status = self.pci_get_value(self.BASE_RES_PATH, port_offset) - reg_value = int(status) + status = self.pci_get_value(self.BASE_RES_PATH, port_offset) + reg_value = int(status) # Absence of status throws error - if (reg_value == "" ): + if (reg_value == ""): return False # Mask off 4th bit for presence @@ -183,44 +183,44 @@ def set_low_power_mode(self, port_num, lpmode): if port_num < self.port_start or port_num > self.port_end: return False - # Port offset starts with 0x4000 - port_offset = 16384 + ((port_num-1) * 16) + # Port offset starts with 0x4000 + port_offset = 16384 + ((port_num-1) * 16) - status = self.pci_get_value(self.BASE_RES_PATH, port_offset) - reg_value = int(status) + status = self.pci_get_value(self.BASE_RES_PATH, port_offset) + reg_value = int(status) # Absence of status throws error - if (reg_value == "" ): + if (reg_value == ""): return False # Mask off 6th bit for lpmode mask = (1 << 6) - # LPMode is active high; set or clear the bit accordingly + # LPMode is active high; set or clear the bit accordingly if lpmode is True: reg_value = reg_value | mask else: reg_value = reg_value & ~mask # Convert our register value back to a hex string and write back - status = self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset) + status = self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset) return True def reset(self, port_num): - # Check for invalid port_num + # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False - # Port offset starts with 0x4000 - port_offset = 16384 + ((port_num-1) * 16) + # Port offset starts with 0x4000 + port_offset = 16384 + ((port_num-1) * 16) - status = self.pci_get_value(self.BASE_RES_PATH, port_offset) - reg_value = int(status) + status = self.pci_get_value(self.BASE_RES_PATH, port_offset) + reg_value = int(status) # Absence of status throws error - if (reg_value == "" ): + if (reg_value == ""): return False # Mask off 4th bit for presence @@ -229,16 +229,16 @@ def reset(self, port_num): # ResetL is active low reg_value = reg_value & ~mask - # Convert our register value back to a hex string and write back - status = self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset) + # Convert our register value back to a hex string and write back + status = self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset) # Sleep 1 second to allow it to settle time.sleep(1) reg_value = reg_value | mask - # Convert our register value back to a hex string and write back - status = self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset) + # Convert our register value back to a hex string and write back + status = self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset) return True @@ -271,7 +271,6 @@ def get_transceiver_change_event(self, timeout=0): return True, port_dict - def get_transceiver_dom_info_dict(self, port_num): transceiver_dom_info_dict = {} @@ -280,13 +279,14 @@ def get_transceiver_dom_info_dict(self, port_num): 'tx1bias', 'tx2bias', 'tx3bias', 'tx4bias', 'tx1power', 'tx2power', 'tx3power', 'tx4power', - ] + ] transceiver_dom_info_dict = dict.fromkeys(dom_info_dict_keys, 'N/A') if port_num in self.qsfp_ports: offset = 0 offset_xcvr = 128 - file_path = self._get_port_eeprom_path(port_num, self.IDENTITY_EEPROM_ADDR) + file_path = self._get_port_eeprom_path( + port_num, self.IDENTITY_EEPROM_ADDR) if not self._sfp_eeprom_present(file_path, 0): return None @@ -308,27 +308,34 @@ def get_transceiver_dom_info_dict(self, port_num): # TODO: in the future when decided to migrate to support SFF-8636 instead of SFF-8436, # need to add more code for determining the capability and version compliance # in SFF-8636 dom capability definitions evolving with the versions. - qsfp_dom_capability_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset_xcvr + XCVR_DOM_CAPABILITY_OFFSET), XCVR_DOM_CAPABILITY_WIDTH) + qsfp_dom_capability_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset_xcvr + XCVR_DOM_CAPABILITY_OFFSET), XCVR_DOM_CAPABILITY_WIDTH) if qsfp_dom_capability_raw is not None: - qspf_dom_capability_data = sfpi_obj.parse_qsfp_dom_capability(qsfp_dom_capability_raw, 0) + qspf_dom_capability_data = sfpi_obj.parse_qsfp_dom_capability( + qsfp_dom_capability_raw, 0) else: return transceiver_dom_info_dict - dom_temperature_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + QSFP_TEMPE_OFFSET), QSFP_TEMPE_WIDTH) + dom_temperature_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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) + dom_temperature_data = sfpd_obj.parse_temperature( + dom_temperature_raw, 0) else: return transceiver_dom_info_dict - dom_voltage_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + QSFP_VOLT_OFFSET), QSFP_VOLT_WIDTH) + dom_voltage_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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 transceiver_dom_info_dict - qsfp_dom_rev_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + QSFP_DOM_REV_OFFSET), QSFP_DOM_REV_WIDTH) + qsfp_dom_rev_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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) + qsfp_dom_rev_data = sfpd_obj.parse_sfp_dom_rev( + qsfp_dom_rev_raw, 0) else: return transceiver_dom_info_dict @@ -341,9 +348,11 @@ def get_transceiver_dom_info_dict(self, port_num): 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(sysfsfile_eeprom, (offset + QSFP_CHANNL_MON_OFFSET), QSFP_CHANNL_MON_WIDTH) + dom_channel_monitor_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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) + dom_channel_monitor_data = sfpd_obj.parse_channel_monitor_params( + dom_channel_monitor_raw, 0) else: return transceiver_dom_info_dict @@ -352,9 +361,11 @@ def get_transceiver_dom_info_dict(self, port_num): transceiver_dom_info_dict['tx3power'] = 'N/A' transceiver_dom_info_dict['tx4power'] = 'N/A' else: - dom_channel_monitor_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + QSFP_CHANNL_MON_OFFSET), QSFP_CHANNL_MON_WITH_TX_POWER_WIDTH) + dom_channel_monitor_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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 @@ -381,47 +392,50 @@ def get_transceiver_dom_info_dict(self, port_num): transceiver_dom_info_dict['tx4bias'] = dom_channel_monitor_data['data']['TX4Bias']['value'] else: - offset = 256 - file_path = self._get_port_eeprom_path(port_num, self.DOM_EEPROM_ADDR) - if not self._sfp_eeprom_present(file_path, 0): - return None + offset = 256 + file_path = self._get_port_eeprom_path( + port_num, self.DOM_EEPROM_ADDR) + if not self._sfp_eeprom_present(file_path, 0): + return None try: - sysfsfile_eeprom = io.open(file_path,"rb",0) + sysfsfile_eeprom = io.open(file_path, "rb", 0) except IOError: - print("Error: reading sysfs file %s" % file_path) - return None + print("Error: reading sysfs file %s" % file_path) + return None - sfpd_obj = sff8472Dom(None,1) + sfpd_obj = sff8472Dom(None, 1) if sfpd_obj is None: return transceiver_dom_info_dict dom_temperature_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_TEMPE_OFFSET), - SFP_TEMPE_WIDTH) + SFP_TEMPE_WIDTH) if dom_temperature_raw is not None: - dom_temperature_data = sfpd_obj.parse_temperature(dom_temperature_raw, 0) + dom_temperature_data = sfpd_obj.parse_temperature( + dom_temperature_raw, 0) else: - return transceiver_dom_info_dict + return transceiver_dom_info_dict dom_voltage_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_VOLT_OFFSET), - SFP_VOLT_WIDTH) + SFP_VOLT_WIDTH) if dom_voltage_raw is not None: - dom_voltage_data = sfpd_obj.parse_voltage(dom_voltage_raw, 0) + dom_voltage_data = sfpd_obj.parse_voltage(dom_voltage_raw, 0) else: - return transceiver_dom_info_dict + return transceiver_dom_info_dict dom_channel_monitor_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_MODULE_THRESHOLD_OFFSET), - SFP_MODULE_THRESHOLD_WIDTH) + SFP_MODULE_THRESHOLD_WIDTH) if dom_channel_monitor_raw is not None: - dom_channel_monitor_data = sfpd_obj.parse_channel_monitor_params(dom_channel_monitor_raw, 0) + dom_channel_monitor_data = sfpd_obj.parse_channel_monitor_params( + dom_channel_monitor_raw, 0) else: - return transceiver_dom_info_dict + return transceiver_dom_info_dict try: - sysfsfile_eeprom.close() + sysfsfile_eeprom.close() except IOError: - print("Error: closing sysfs file %s" % file_path) - return None + print("Error: closing sysfs file %s" % file_path) + return None transceiver_dom_info_dict['temperature'] = dom_temperature_data['data']['Temperature']['value'] transceiver_dom_info_dict['voltage'] = dom_voltage_data['data']['Vcc']['value'] @@ -438,7 +452,7 @@ def get_transceiver_dom_info_dict(self, port_num): transceiver_dom_info_dict['tx3power'] = 'N/A' transceiver_dom_info_dict['tx4power'] = 'N/A' - return transceiver_dom_info_dict + return transceiver_dom_info_dict def get_transceiver_dom_threshold_info_dict(self, port_num): transceiver_dom_threshold_info_dict = {} @@ -452,11 +466,13 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): 'txpowerlowalarm', 'txpowerlowwarning', 'txbiashighalarm', 'txbiashighwarning', 'txbiaslowalarm', 'txbiaslowwarning' - ] - transceiver_dom_threshold_info_dict = dict.fromkeys(dom_info_dict_keys, 'N/A') + ] + transceiver_dom_threshold_info_dict = dict.fromkeys( + dom_info_dict_keys, 'N/A') if port_num in self.qsfp_ports: - file_path = self._get_port_eeprom_path(port_num, self.IDENTITY_EEPROM_ADDR) + file_path = self._get_port_eeprom_path( + port_num, self.IDENTITY_EEPROM_ADDR) if not self._sfp_eeprom_present(file_path, 0): return None @@ -474,20 +490,22 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): # Revert offset back to 0 once data is retrieved offset = 384 dom_module_threshold_raw = self._read_eeprom_specific_bytes( - sysfsfile_eeprom, - (offset + QSFP_MODULE_THRESHOLD_OFFSET), - QSFP_MODULE_THRESHOLD_WIDTH) + sysfsfile_eeprom, + (offset + QSFP_MODULE_THRESHOLD_OFFSET), + QSFP_MODULE_THRESHOLD_WIDTH) if dom_module_threshold_raw is not None: - dom_module_threshold_data = sfpd_obj.parse_module_threshold_values(dom_module_threshold_raw, 0) + dom_module_threshold_data = sfpd_obj.parse_module_threshold_values( + dom_module_threshold_raw, 0) else: return transceiver_dom_threshold_info_dict dom_channel_threshold_raw = self._read_eeprom_specific_bytes( - sysfsfile_eeprom, - (offset + QSFP_CHANNL_THRESHOLD_OFFSET), - QSFP_CHANNL_THRESHOLD_WIDTH) + sysfsfile_eeprom, + (offset + QSFP_CHANNL_THRESHOLD_OFFSET), + QSFP_CHANNL_THRESHOLD_WIDTH) if dom_channel_threshold_raw is not None: - dom_channel_threshold_data = sfpd_obj.parse_channel_threshold_values(dom_channel_threshold_raw, 0) + dom_channel_threshold_data = sfpd_obj.parse_channel_threshold_values( + dom_channel_threshold_raw, 0) else: return transceiver_dom_threshold_info_dict @@ -517,25 +535,27 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): else: offset = 256 - file_path = self._get_port_eeprom_path(port_num, self.DOM_EEPROM_ADDR) + file_path = self._get_port_eeprom_path( + port_num, self.DOM_EEPROM_ADDR) if not self._sfp_eeprom_present(file_path, 0): return None try: - sysfsfile_eeprom = io.open(file_path,"rb",0) + sysfsfile_eeprom = io.open(file_path, "rb", 0) except IOError: print("Error: reading sysfs file %s" % file_path) return None - sfpd_obj = sff8472Dom(None,1) + sfpd_obj = sff8472Dom(None, 1) if sfpd_obj is None: return transceiver_dom_threshold_info_dict dom_module_threshold_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, - (offset + SFP_MODULE_THRESHOLD_OFFSET), SFP_MODULE_THRESHOLD_WIDTH) + (offset + SFP_MODULE_THRESHOLD_OFFSET), SFP_MODULE_THRESHOLD_WIDTH) if dom_module_threshold_raw is not None: - dom_module_threshold_data = sfpd_obj.parse_alarm_warning_threshold(dom_module_threshold_raw, 0) + dom_module_threshold_data = sfpd_obj.parse_alarm_warning_threshold( + dom_module_threshold_raw, 0) else: return transceiver_dom_threshold_info_dict @@ -545,14 +565,15 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): print("Error: closing sysfs file %s" % file_path) return None - #Threshold Data + # Threshold Data transceiver_dom_threshold_info_dict['temphighalarm'] = dom_module_threshold_data['data']['TempHighAlarm']['value'] transceiver_dom_threshold_info_dict['templowalarm'] = dom_module_threshold_data['data']['TempLowAlarm']['value'] transceiver_dom_threshold_info_dict['temphighwarning'] = dom_module_threshold_data['data']['TempHighWarning']['value'] transceiver_dom_threshold_info_dict['templowwarning'] = dom_module_threshold_data['data']['TempLowWarning']['value'] transceiver_dom_threshold_info_dict['vcchighalarm'] = dom_module_threshold_data['data']['VoltageHighAlarm']['value'] transceiver_dom_threshold_info_dict['vcclowalarm'] = dom_module_threshold_data['data']['VoltageLowAlarm']['value'] - transceiver_dom_threshold_info_dict['vcchighwarning'] = dom_module_threshold_data['data']['VoltageHighWarning']['value'] + transceiver_dom_threshold_info_dict['vcchighwarning'] = dom_module_threshold_data[ + 'data']['VoltageHighWarning']['value'] transceiver_dom_threshold_info_dict['vcclowwarning'] = dom_module_threshold_data['data']['VoltageLowWarning']['value'] transceiver_dom_threshold_info_dict['txbiashighalarm'] = dom_module_threshold_data['data']['BiasHighAlarm']['value'] transceiver_dom_threshold_info_dict['txbiaslowalarm'] = dom_module_threshold_data['data']['BiasLowAlarm']['value'] diff --git a/device/dell/x86_64-dellemc_s5248f_c3538-r0/plugins/sfputil.py b/device/dell/x86_64-dellemc_s5248f_c3538-r0/plugins/sfputil.py index 76824d151693..2b941d028968 100644 --- a/device/dell/x86_64-dellemc_s5248f_c3538-r0/plugins/sfputil.py +++ b/device/dell/x86_64-dellemc_s5248f_c3538-r0/plugins/sfputil.py @@ -21,7 +21,7 @@ except ImportError as e: raise ImportError("%s - required module not found" % str(e)) -#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 @@ -48,6 +48,7 @@ XCVR_DOM_CAPABILITY_OFFSET = 92 XCVR_DOM_CAPABILITY_WIDTH = 1 + class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" @@ -58,68 +59,67 @@ class SfpUtil(SfpUtilBase): BASE_RES_PATH = "/sys/bus/pci/devices/0000:04:00.0/resource0" _port_to_i2c_mapping = { - 1: 2, - 2: 3, - 3: 4, - 4: 5, - 5: 6, - 6: 7, - 7: 8, - 8: 9, - 9: 10, - 10: 11, - 11: 12, - 12: 13, - 13: 14, - 14: 15, - 15: 16, - 16: 17, - 17: 18, - 18: 19, - 19: 20, - 20: 21, - 21: 22, - 22: 23, - 23: 24, - 24: 25, - 25: 26, - 26: 27, - 27: 28, - 28: 29, - 29: 30, - 30: 31, - 31: 32, - 32: 33, - 33: 34, - 34: 35, - 35: 36, - 36: 37, - 37: 38, - 38: 39, - 39: 40, - 40: 41, - 41: 42, - 42: 43, - 43: 44, - 44: 45, - 45: 46, - 46: 47, - 47: 48, - 48: 49, - # DD + QSFP28 - 49: 50, - 50: 50, - 51: 51, - 52: 51, - 53: 52, - 54: 53, - 55: 54, - 56: 55, - } + 1: 2, + 2: 3, + 3: 4, + 4: 5, + 5: 6, + 6: 7, + 7: 8, + 8: 9, + 9: 10, + 10: 11, + 11: 12, + 12: 13, + 13: 14, + 14: 15, + 15: 16, + 16: 17, + 17: 18, + 18: 19, + 19: 20, + 20: 21, + 21: 22, + 22: 23, + 23: 24, + 24: 25, + 25: 26, + 26: 27, + 27: 28, + 28: 29, + 29: 30, + 30: 31, + 31: 32, + 32: 33, + 33: 34, + 34: 35, + 35: 36, + 36: 37, + 37: 38, + 38: 39, + 39: 40, + 40: 41, + 41: 42, + 42: 43, + 43: 44, + 44: 45, + 45: 46, + 46: 47, + 47: 48, + 48: 49, + # DD + QSFP28 + 49: 50, + 50: 50, + 51: 51, + 52: 51, + 53: 52, + 54: 53, + 55: 54, + 56: 55, + } _port_to_eeprom_mapping = {} - _global_port_pres_dict = {} @property @@ -140,8 +140,8 @@ def port_to_eeprom_mapping(self): def pci_mem_read(self, mm, offset): mm.seek(offset) - read_data_stream=mm.read(4) - reg_val=struct.unpack('I',read_data_stream) + read_data_stream = mm.read(4) + reg_val = struct.unpack('I', read_data_stream) mem_val = str(reg_val)[1:-2] # print "reg_val read:%x"%reg_val return mem_val @@ -149,7 +149,7 @@ def pci_mem_read(self, mm, offset): def pci_mem_write(self, mm, offset, data): mm.seek(offset) # print "data to write:%x"%data - mm.write(struct.pack('I',data)) + mm.write(struct.pack('I', data)) def pci_set_value(self, resource, val, offset): fd = open(resource, O_RDWR) @@ -180,7 +180,7 @@ def __init__(self): for x in range(self.port_start, self.port_end + 1): self.port_to_eeprom_mapping[x] = eeprom_path.format( - self._port_to_i2c_mapping[x]) + self._port_to_i2c_mapping[x]) self.init_global_port_presence() SfpUtilBase.__init__(self) @@ -190,13 +190,13 @@ def get_presence(self, port_num): return False # Port offset starts with 0x4004 - port_offset = 16388 + ((port_num-1) * 16) + port_offset = 16388 + ((port_num-1) * 16) - status = self.pci_get_value(self.BASE_RES_PATH, port_offset) - reg_value = int(status) + status = self.pci_get_value(self.BASE_RES_PATH, port_offset) + reg_value = int(status) # Absence of status throws error - if (reg_value == "" ): + if (reg_value == ""): return False # Mask off bit for presence @@ -204,7 +204,6 @@ def get_presence(self, port_num): if (port_num > 48): mask = (1 << 4) - # ModPrsL is active low if reg_value & mask == 0: return True @@ -217,14 +216,14 @@ def get_low_power_mode(self, port_num): if port_num < self.port_start or port_num > self.port_end: return False - # Port offset starts with 0x4000 - port_offset = 16384 + ((port_num-1) * 16) + # Port offset starts with 0x4000 + port_offset = 16384 + ((port_num-1) * 16) - status = self.pci_get_value(self.BASE_RES_PATH, port_offset) - reg_value = int(status) + status = self.pci_get_value(self.BASE_RES_PATH, port_offset) + reg_value = int(status) # Absence of status throws error - if (reg_value == "" ): + if (reg_value == ""): return False # Mask off 4th bit for presence @@ -242,44 +241,44 @@ def set_low_power_mode(self, port_num, lpmode): if port_num < self.port_start or port_num > self.port_end: return False - # Port offset starts with 0x4000 - port_offset = 16384 + ((port_num-1) * 16) + # Port offset starts with 0x4000 + port_offset = 16384 + ((port_num-1) * 16) - status = self.pci_get_value(self.BASE_RES_PATH, port_offset) - reg_value = int(status) + status = self.pci_get_value(self.BASE_RES_PATH, port_offset) + reg_value = int(status) # Absence of status throws error - if (reg_value == "" ): + if (reg_value == ""): return False # Mask off 6th bit for lpmode mask = (1 << 6) - # LPMode is active high; set or clear the bit accordingly + # LPMode is active high; set or clear the bit accordingly if lpmode is True: reg_value = reg_value | mask else: reg_value = reg_value & ~mask # Convert our register value back to a hex string and write back - status = self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset) + status = self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset) return True def reset(self, port_num): - # Check for invalid port_num + # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False - # Port offset starts with 0x4000 - port_offset = 16384 + ((port_num-1) * 16) + # Port offset starts with 0x4000 + port_offset = 16384 + ((port_num-1) * 16) - status = self.pci_get_value(self.BASE_RES_PATH, port_offset) - reg_value = int(status) + status = self.pci_get_value(self.BASE_RES_PATH, port_offset) + reg_value = int(status) # Absence of status throws error - if (reg_value == "" ): + if (reg_value == ""): return False # Mask off 4th bit for presence @@ -288,16 +287,16 @@ def reset(self, port_num): # ResetL is active low reg_value = reg_value & ~mask - # Convert our register value back to a hex string and write back - status = self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset) + # Convert our register value back to a hex string and write back + status = self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset) # Sleep 1 second to allow it to settle time.sleep(1) reg_value = reg_value | mask - # Convert our register value back to a hex string and write back - status = self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset) + # Convert our register value back to a hex string and write back + status = self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset) return True @@ -327,13 +326,14 @@ def get_transceiver_dom_info_dict(self, port_num): 'tx1bias', 'tx2bias', 'tx3bias', 'tx4bias', 'tx1power', 'tx2power', 'tx3power', 'tx4power', - ] + ] transceiver_dom_info_dict = dict.fromkeys(dom_info_dict_keys, 'N/A') if port_num in self.qsfp_ports: offset = 0 offset_xcvr = 128 - file_path = self._get_port_eeprom_path(port_num, self.IDENTITY_EEPROM_ADDR) + file_path = self._get_port_eeprom_path( + port_num, self.IDENTITY_EEPROM_ADDR) if not self._sfp_eeprom_present(file_path, 0): return None @@ -355,27 +355,34 @@ def get_transceiver_dom_info_dict(self, port_num): # TODO: in the future when decided to migrate to support SFF-8636 instead of SFF-8436, # need to add more code for determining the capability and version compliance # in SFF-8636 dom capability definitions evolving with the versions. - qsfp_dom_capability_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset_xcvr + XCVR_DOM_CAPABILITY_OFFSET), XCVR_DOM_CAPABILITY_WIDTH) + qsfp_dom_capability_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset_xcvr + XCVR_DOM_CAPABILITY_OFFSET), XCVR_DOM_CAPABILITY_WIDTH) if qsfp_dom_capability_raw is not None: - qspf_dom_capability_data = sfpi_obj.parse_qsfp_dom_capability(qsfp_dom_capability_raw, 0) + qspf_dom_capability_data = sfpi_obj.parse_qsfp_dom_capability( + qsfp_dom_capability_raw, 0) else: return transceiver_dom_info_dict - dom_temperature_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + QSFP_TEMPE_OFFSET), QSFP_TEMPE_WIDTH) + dom_temperature_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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) + dom_temperature_data = sfpd_obj.parse_temperature( + dom_temperature_raw, 0) else: return transceiver_dom_info_dict - dom_voltage_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + QSFP_VOLT_OFFSET), QSFP_VOLT_WIDTH) + dom_voltage_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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 transceiver_dom_info_dict - qsfp_dom_rev_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + QSFP_DOM_REV_OFFSET), QSFP_DOM_REV_WIDTH) + qsfp_dom_rev_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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) + qsfp_dom_rev_data = sfpd_obj.parse_sfp_dom_rev( + qsfp_dom_rev_raw, 0) else: return transceiver_dom_info_dict @@ -388,9 +395,11 @@ def get_transceiver_dom_info_dict(self, port_num): 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(sysfsfile_eeprom, (offset + QSFP_CHANNL_MON_OFFSET), QSFP_CHANNL_MON_WIDTH) + dom_channel_monitor_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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) + dom_channel_monitor_data = sfpd_obj.parse_channel_monitor_params( + dom_channel_monitor_raw, 0) else: return transceiver_dom_info_dict @@ -399,9 +408,11 @@ def get_transceiver_dom_info_dict(self, port_num): transceiver_dom_info_dict['tx3power'] = 'N/A' transceiver_dom_info_dict['tx4power'] = 'N/A' else: - dom_channel_monitor_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + QSFP_CHANNL_MON_OFFSET), QSFP_CHANNL_MON_WITH_TX_POWER_WIDTH) + dom_channel_monitor_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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 @@ -428,48 +439,51 @@ def get_transceiver_dom_info_dict(self, port_num): transceiver_dom_info_dict['tx4bias'] = dom_channel_monitor_data['data']['TX4Bias']['value'] else: - offset = 256 - file_path = self._get_port_eeprom_path(port_num, self.DOM_EEPROM_ADDR) - if not self._sfp_eeprom_present(file_path, 0): - return None + offset = 256 + file_path = self._get_port_eeprom_path( + port_num, self.DOM_EEPROM_ADDR) + if not self._sfp_eeprom_present(file_path, 0): + return None try: - sysfsfile_eeprom = io.open(file_path,"rb",0) + sysfsfile_eeprom = io.open(file_path, "rb", 0) except IOError: - print("Error: reading sysfs file %s" % file_path) - return None + print("Error: reading sysfs file %s" % file_path) + return None - sfpd_obj = sff8472Dom(None,1) + sfpd_obj = sff8472Dom(None, 1) if sfpd_obj is None: return transceiver_dom_info_dict dom_temperature_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_TEMPE_OFFSET), - SFP_TEMPE_WIDTH) + SFP_TEMPE_WIDTH) if dom_temperature_raw is not None: - dom_temperature_data = sfpd_obj.parse_temperature(dom_temperature_raw, 0) + dom_temperature_data = sfpd_obj.parse_temperature( + dom_temperature_raw, 0) else: return transceiver_dom_info_dict dom_voltage_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_VOLT_OFFSET), - SFP_VOLT_WIDTH) + SFP_VOLT_WIDTH) if dom_voltage_raw is not None: - dom_voltage_data = sfpd_obj.parse_voltage(dom_voltage_raw, 0) + dom_voltage_data = sfpd_obj.parse_voltage(dom_voltage_raw, 0) else: - return transceiver_dom_info_dict + return transceiver_dom_info_dict dom_channel_monitor_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_MODULE_THRESHOLD_OFFSET), - SFP_MODULE_THRESHOLD_WIDTH) + SFP_MODULE_THRESHOLD_WIDTH) if dom_channel_monitor_raw is not None: - dom_channel_monitor_data = sfpd_obj.parse_channel_monitor_params(dom_channel_monitor_raw, 0) + dom_channel_monitor_data = sfpd_obj.parse_channel_monitor_params( + dom_channel_monitor_raw, 0) else: - return transceiver_dom_info_dict + return transceiver_dom_info_dict try: - sysfsfile_eeprom.close() + sysfsfile_eeprom.close() except IOError: - print("Error: closing sysfs file %s" % file_path) - return None + print("Error: closing sysfs file %s" % file_path) + return None transceiver_dom_info_dict['temperature'] = dom_temperature_data['data']['Temperature']['value'] transceiver_dom_info_dict['voltage'] = dom_voltage_data['data']['Vcc']['value'] @@ -486,7 +500,7 @@ def get_transceiver_dom_info_dict(self, port_num): transceiver_dom_info_dict['tx3power'] = 'N/A' transceiver_dom_info_dict['tx4power'] = 'N/A' - return transceiver_dom_info_dict + return transceiver_dom_info_dict def get_transceiver_dom_threshold_info_dict(self, port_num): transceiver_dom_threshold_info_dict = {} @@ -500,11 +514,13 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): 'txpowerlowalarm', 'txpowerlowwarning', 'txbiashighalarm', 'txbiashighwarning', 'txbiaslowalarm', 'txbiaslowwarning' - ] - transceiver_dom_threshold_info_dict = dict.fromkeys(dom_info_dict_keys, 'N/A') + ] + transceiver_dom_threshold_info_dict = dict.fromkeys( + dom_info_dict_keys, 'N/A') if port_num in self.qsfp_ports: - file_path = self._get_port_eeprom_path(port_num, self.IDENTITY_EEPROM_ADDR) + file_path = self._get_port_eeprom_path( + port_num, self.IDENTITY_EEPROM_ADDR) if not self._sfp_eeprom_present(file_path, 0): return None @@ -522,20 +538,22 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): # Revert offset back to 0 once data is retrieved offset = 384 dom_module_threshold_raw = self._read_eeprom_specific_bytes( - sysfsfile_eeprom, - (offset + QSFP_MODULE_THRESHOLD_OFFSET), - QSFP_MODULE_THRESHOLD_WIDTH) + sysfsfile_eeprom, + (offset + QSFP_MODULE_THRESHOLD_OFFSET), + QSFP_MODULE_THRESHOLD_WIDTH) if dom_module_threshold_raw is not None: - dom_module_threshold_data = sfpd_obj.parse_module_threshold_values(dom_module_threshold_raw, 0) + dom_module_threshold_data = sfpd_obj.parse_module_threshold_values( + dom_module_threshold_raw, 0) else: return transceiver_dom_threshold_info_dict dom_channel_threshold_raw = self._read_eeprom_specific_bytes( - sysfsfile_eeprom, - (offset + QSFP_CHANNL_THRESHOLD_OFFSET), - QSFP_CHANNL_THRESHOLD_WIDTH) + sysfsfile_eeprom, + (offset + QSFP_CHANNL_THRESHOLD_OFFSET), + QSFP_CHANNL_THRESHOLD_WIDTH) if dom_channel_threshold_raw is not None: - dom_channel_threshold_data = sfpd_obj.parse_channel_threshold_values(dom_channel_threshold_raw, 0) + dom_channel_threshold_data = sfpd_obj.parse_channel_threshold_values( + dom_channel_threshold_raw, 0) else: return transceiver_dom_threshold_info_dict @@ -565,25 +583,27 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): else: offset = 256 - file_path = self._get_port_eeprom_path(port_num, self.DOM_EEPROM_ADDR) + file_path = self._get_port_eeprom_path( + port_num, self.DOM_EEPROM_ADDR) if not self._sfp_eeprom_present(file_path, 0): return None try: - sysfsfile_eeprom = io.open(file_path,"rb",0) + sysfsfile_eeprom = io.open(file_path, "rb", 0) except IOError: print("Error: reading sysfs file %s" % file_path) return None - sfpd_obj = sff8472Dom(None,1) + sfpd_obj = sff8472Dom(None, 1) if sfpd_obj is None: return transceiver_dom_threshold_info_dict dom_module_threshold_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, - (offset + SFP_MODULE_THRESHOLD_OFFSET), SFP_MODULE_THRESHOLD_WIDTH) + (offset + SFP_MODULE_THRESHOLD_OFFSET), SFP_MODULE_THRESHOLD_WIDTH) if dom_module_threshold_raw is not None: - dom_module_threshold_data = sfpd_obj.parse_alarm_warning_threshold(dom_module_threshold_raw, 0) + dom_module_threshold_data = sfpd_obj.parse_alarm_warning_threshold( + dom_module_threshold_raw, 0) else: return transceiver_dom_threshold_info_dict @@ -593,7 +613,7 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): print("Error: closing sysfs file %s" % file_path) return None - #Threshold Data + # Threshold Data transceiver_dom_threshold_info_dict['temphighalarm'] = dom_module_threshold_data['data']['TempHighAlarm']['value'] transceiver_dom_threshold_info_dict['templowalarm'] = dom_module_threshold_data['data']['TempLowAlarm']['value'] transceiver_dom_threshold_info_dict['temphighwarning'] = dom_module_threshold_data['data']['TempHighWarning']['value'] diff --git a/device/dell/x86_64-dellemc_s5296f_c3538-r0/plugins/sfputil.py b/device/dell/x86_64-dellemc_s5296f_c3538-r0/plugins/sfputil.py index 85ce9551e033..8b4ab0dcae1a 100644 --- a/device/dell/x86_64-dellemc_s5296f_c3538-r0/plugins/sfputil.py +++ b/device/dell/x86_64-dellemc_s5296f_c3538-r0/plugins/sfputil.py @@ -19,7 +19,7 @@ raise ImportError("%s - required module not found" % str(e)) -#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 @@ -58,7 +58,6 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} - _global_port_pres_dict = {} @property @@ -79,8 +78,8 @@ def port_to_eeprom_mapping(self): def pci_mem_read(self, mm, offset): mm.seek(offset) - read_data_stream=mm.read(4) - reg_val=struct.unpack('I',read_data_stream) + read_data_stream = mm.read(4) + reg_val = struct.unpack('I', read_data_stream) mem_val = str(reg_val)[1:-2] # print "reg_val read:%x"%reg_val return mem_val @@ -88,7 +87,7 @@ def pci_mem_read(self, mm, offset): def pci_mem_write(self, mm, offset, data): mm.seek(offset) # print "data to write:%x"%data - mm.write(struct.pack('I',data)) + mm.write(struct.pack('I', data)) def pci_set_value(self, resource, val, offset): fd = open(resource, O_RDWR) @@ -128,13 +127,13 @@ def get_presence(self, port_num): return False # Port offset starts with 0x4004 - port_offset = 16388 + ((port_num-1) * 16) + port_offset = 16388 + ((port_num-1) * 16) - status = self.pci_get_value(self.BASE_RES_PATH, port_offset) - reg_value = int(status) + status = self.pci_get_value(self.BASE_RES_PATH, port_offset) + reg_value = int(status) # Absence of status throws error - if (reg_value == "" ): + if (reg_value == ""): return False # Mask off bit for presence @@ -154,14 +153,14 @@ def get_low_power_mode(self, port_num): if port_num < self.port_start or port_num > self.port_end: return False - # Port offset starts with 0x4000 - port_offset = 16384 + ((port_num-1) * 16) + # Port offset starts with 0x4000 + port_offset = 16384 + ((port_num-1) * 16) - status = self.pci_get_value(self.BASE_RES_PATH, port_offset) - reg_value = int(status) + status = self.pci_get_value(self.BASE_RES_PATH, port_offset) + reg_value = int(status) # Absence of status throws error - if (reg_value == "" ): + if (reg_value == ""): return False # Mask off 4th bit for presence @@ -179,44 +178,44 @@ def set_low_power_mode(self, port_num, lpmode): if port_num < self.port_start or port_num > self.port_end: return False - # Port offset starts with 0x4000 - port_offset = 16384 + ((port_num-1) * 16) + # Port offset starts with 0x4000 + port_offset = 16384 + ((port_num-1) * 16) - status = self.pci_get_value(self.BASE_RES_PATH, port_offset) - reg_value = int(status) + status = self.pci_get_value(self.BASE_RES_PATH, port_offset) + reg_value = int(status) # Absence of status throws error - if (reg_value == "" ): + if (reg_value == ""): return False # Mask off 4th bit for presence mask = (1 << 6) - # LPMode is active high; set or clear the bit accordingly + # LPMode is active high; set or clear the bit accordingly if lpmode is True: reg_value = reg_value | mask else: reg_value = reg_value & ~mask # Convert our register value back to a hex string and write back - self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset) + self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset) return True def reset(self, port_num): - # Check for invalid port_num + # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False - # Port offset starts with 0x4000 - port_offset = 16384 + ((port_num-1) * 16) + # Port offset starts with 0x4000 + port_offset = 16384 + ((port_num-1) * 16) - status = self.pci_get_value(self.BASE_RES_PATH, port_offset) - reg_value = int(status) + status = self.pci_get_value(self.BASE_RES_PATH, port_offset) + reg_value = int(status) # Absence of status throws error - if (reg_value == "" ): + if (reg_value == ""): return False # Mask off 4th bit for presence @@ -225,16 +224,16 @@ def reset(self, port_num): # ResetL is active low reg_value = reg_value & ~mask - # Convert our register value back to a hex string and write back - self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset) + # Convert our register value back to a hex string and write back + self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset) # Sleep 1 second to allow it to settle time.sleep(1) reg_value = reg_value | mask - # Convert our register value back to a hex string and write back - self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset) + # Convert our register value back to a hex string and write back + self.pci_set_value(self.BASE_RES_PATH, reg_value, port_offset) return True @@ -267,7 +266,6 @@ def get_transceiver_change_event(self, timeout=0): return True, port_dict - def get_transceiver_dom_info_dict(self, port_num): transceiver_dom_info_dict = {} @@ -276,11 +274,11 @@ def get_transceiver_dom_info_dict(self, port_num): 'tx1bias', 'tx2bias', 'tx3bias', 'tx4bias', 'tx1power', 'tx2power', 'tx3power', 'tx4power', - ] + ] transceiver_dom_info_dict = dict.fromkeys(dom_info_dict_keys, 'N/A') - if port_num in self.qsfp_ports: - offset = 0 + if port_num in self.qsfp_ports: + offset = 0 offset_xcvr = 128 file_path = self._get_port_eeprom_path(port_num, self.IDENTITY_EEPROM_ADDR) if not self._sfp_eeprom_present(file_path, 0): @@ -304,25 +302,29 @@ def get_transceiver_dom_info_dict(self, port_num): # TODO: in the future when decided to migrate to support SFF-8636 instead of SFF-8436, # need to add more code for determining the capability and version compliance # in SFF-8636 dom capability definitions evolving with the versions. - qsfp_dom_capability_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset_xcvr + XCVR_DOM_CAPABILITY_OFFSET), XCVR_DOM_CAPABILITY_WIDTH) + qsfp_dom_capability_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset_xcvr + XCVR_DOM_CAPABILITY_OFFSET), XCVR_DOM_CAPABILITY_WIDTH) if qsfp_dom_capability_raw is not None: qspf_dom_capability_data = sfpi_obj.parse_qsfp_dom_capability(qsfp_dom_capability_raw, 0) else: return transceiver_dom_info_dict - dom_temperature_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + QSFP_TEMPE_OFFSET), QSFP_TEMPE_WIDTH) - if dom_temperature_raw is not None: + dom_temperature_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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 transceiver_dom_info_dict - dom_voltage_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + QSFP_VOLT_OFFSET), QSFP_VOLT_WIDTH) + dom_voltage_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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 transceiver_dom_info_dict - qsfp_dom_rev_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + QSFP_DOM_REV_OFFSET), QSFP_DOM_REV_WIDTH) + qsfp_dom_rev_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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: @@ -337,17 +339,18 @@ def get_transceiver_dom_info_dict(self, port_num): 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(sysfsfile_eeprom, (offset + QSFP_CHANNL_MON_OFFSET), QSFP_CHANNL_MON_WIDTH) + dom_channel_monitor_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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: return transceiver_dom_info_dict - transceiver_dom_info_dict['tx1power'] = 'N/A' + transceiver_dom_info_dict['tx1power'] = 'N/A' transceiver_dom_info_dict['tx2power'] = 'N/A' transceiver_dom_info_dict['tx3power'] = 'N/A' transceiver_dom_info_dict['tx4power'] = 'N/A' - try: + try: sysfsfile_eeprom.close() except IOError: print("Error: closing sysfs file %s" % file_path) @@ -365,46 +368,46 @@ def get_transceiver_dom_info_dict(self, port_num): transceiver_dom_info_dict['tx4bias'] = dom_channel_monitor_data['data']['TX4Bias']['value'] else: - offset = 256 - file_path = self._get_port_eeprom_path(port_num, self.DOM_EEPROM_ADDR) - if not self._sfp_eeprom_present(file_path, 0): - return None + offset = 256 + file_path = self._get_port_eeprom_path(port_num, self.DOM_EEPROM_ADDR) + if not self._sfp_eeprom_present(file_path, 0): + return None try: - sysfsfile_eeprom = io.open(file_path,"rb",0) + sysfsfile_eeprom = io.open(file_path, "rb", 0) except IOError: - print("Error: reading sysfs file %s" % file_path) - return None + print("Error: reading sysfs file %s" % file_path) + return None - sfpd_obj = sff8472Dom(None,1) + sfpd_obj = sff8472Dom(None, 1) if sfpd_obj is None: return None dom_temperature_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_TEMPE_OFFSET), - SFP_TEMPE_WIDTH) + SFP_TEMPE_WIDTH) if dom_temperature_raw is not None: dom_temperature_data = sfpd_obj.parse_temperature(dom_temperature_raw, 0) else: - return transceiver_dom_info_dict + return transceiver_dom_info_dict dom_voltage_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_VOLT_OFFSET), - SFP_VOLT_WIDTH) + SFP_VOLT_WIDTH) if dom_voltage_raw is not None: - dom_voltage_data = sfpd_obj.parse_voltage(dom_voltage_raw, 0) + dom_voltage_data = sfpd_obj.parse_voltage(dom_voltage_raw, 0) else: - return transceiver_dom_info_dict + return transceiver_dom_info_dict dom_channel_monitor_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_MODULE_THRESHOLD_OFFSET), - SFP_MODULE_THRESHOLD_WIDTH) + SFP_MODULE_THRESHOLD_WIDTH) if dom_channel_monitor_raw is not None: - dom_channel_monitor_data = sfpd_obj.parse_channel_monitor_params(dom_channel_monitor_raw, 0) + dom_channel_monitor_data = sfpd_obj.parse_channel_monitor_params(dom_channel_monitor_raw, 0) else: - return transceiver_dom_info_dict + return transceiver_dom_info_dict try: - sysfsfile_eeprom.close() + sysfsfile_eeprom.close() except IOError: - print("Error: closing sysfs file %s" % file_path) - return None + print("Error: closing sysfs file %s" % file_path) + return None transceiver_dom_info_dict['temperature'] = dom_temperature_data['data']['Temperature']['value'] transceiver_dom_info_dict['voltage'] = dom_voltage_data['data']['Vcc']['value'] @@ -421,7 +424,7 @@ def get_transceiver_dom_info_dict(self, port_num): transceiver_dom_info_dict['tx3power'] = 'N/A' transceiver_dom_info_dict['tx4power'] = 'N/A' - return transceiver_dom_info_dict + return transceiver_dom_info_dict def get_transceiver_dom_threshold_info_dict(self, port_num): transceiver_dom_threshold_info_dict = {} @@ -435,11 +438,11 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): 'txpowerlowalarm', 'txpowerlowwarning', 'txbiashighalarm', 'txbiashighwarning', 'txbiaslowalarm', 'txbiaslowwarning' - ] + ] transceiver_dom_threshold_info_dict = dict.fromkeys(dom_info_dict_keys, 'N/A') if port_num in self.qsfp_ports: - file_path = self._get_port_eeprom_path(port_num, self.IDENTITY_EEPROM_ADDR) + file_path = self._get_port_eeprom_path(port_num, self.IDENTITY_EEPROM_ADDR) if not self._sfp_eeprom_present(file_path, 0): return None @@ -457,18 +460,18 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): # Revert offset back to 0 once data is retrieved offset = 384 dom_module_threshold_raw = self._read_eeprom_specific_bytes( - sysfsfile_eeprom, - (offset + QSFP_MODULE_THRESHOLD_OFFSET), - QSFP_MODULE_THRESHOLD_WIDTH) + sysfsfile_eeprom, + (offset + QSFP_MODULE_THRESHOLD_OFFSET), + QSFP_MODULE_THRESHOLD_WIDTH) if dom_module_threshold_raw is not None: dom_module_threshold_data = sfpd_obj.parse_module_threshold_values(dom_module_threshold_raw, 0) else: return transceiver_dom_threshold_info_dict dom_channel_threshold_raw = self._read_eeprom_specific_bytes( - sysfsfile_eeprom, - (offset + QSFP_CHANNL_THRESHOLD_OFFSET), - QSFP_CHANNL_THRESHOLD_WIDTH) + sysfsfile_eeprom, + (offset + QSFP_CHANNL_THRESHOLD_OFFSET), + QSFP_CHANNL_THRESHOLD_WIDTH) if dom_channel_threshold_raw is not None: dom_channel_threshold_data = sfpd_obj.parse_channel_threshold_values(dom_channel_threshold_raw, 0) else: @@ -505,17 +508,17 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): return None try: - sysfsfile_eeprom = io.open(file_path,"rb",0) + sysfsfile_eeprom = io.open(file_path, "rb", 0) except IOError: print("Error: reading sysfs file %s" % file_path) return None - sfpd_obj = sff8472Dom(None,1) + sfpd_obj = sff8472Dom(None, 1) if sfpd_obj is None: return transceiver_dom_threshold_info_dict dom_module_threshold_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, - (offset + SFP_MODULE_THRESHOLD_OFFSET), SFP_MODULE_THRESHOLD_WIDTH) + (offset + SFP_MODULE_THRESHOLD_OFFSET), SFP_MODULE_THRESHOLD_WIDTH) if dom_module_threshold_raw is not None: dom_module_threshold_data = sfpd_obj.parse_alarm_warning_threshold(dom_module_threshold_raw, 0) @@ -528,7 +531,7 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): print("Error: closing sysfs file %s" % file_path) return None - #Threshold Data + # Threshold Data transceiver_dom_threshold_info_dict['temphighalarm'] = dom_module_threshold_data['data']['TempHighAlarm']['value'] transceiver_dom_threshold_info_dict['templowalarm'] = dom_module_threshold_data['data']['TempLowAlarm']['value'] transceiver_dom_threshold_info_dict['temphighwarning'] = dom_module_threshold_data['data']['TempHighWarning']['value'] @@ -551,4 +554,3 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): transceiver_dom_threshold_info_dict['rxpowerlowwarning'] = dom_module_threshold_data['data']['RXPowerLowWarning']['value'] return transceiver_dom_threshold_info_dict - diff --git a/device/delta/x86_64-delta_ag5648-r0/plugins/eeprom.py b/device/delta/x86_64-delta_ag5648-r0/plugins/eeprom.py index 9112318a7915..bd9bbb755f39 100644 --- a/device/delta/x86_64-delta_ag5648-r0/plugins/eeprom.py +++ b/device/delta/x86_64-delta_ag5648-r0/plugins/eeprom.py @@ -18,12 +18,13 @@ from sonic_eeprom import eeprom_tlvinfo import subprocess except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 def __init__(self, name, path, cpld_root, ro): - self.eeprom_path = "/sys/devices/pci0000:00/0000:00:13.0/i2c-1/i2c-2/2-0053/eeprom" - super(board, self).__init__(self.eeprom_path, 0, '', True) + self.eeprom_path = "/sys/devices/pci0000:00/0000:00:13.0/i2c-1/i2c-2/2-0053/eeprom" + super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/delta/x86_64-delta_ag5648-r0/plugins/sfputil.py b/device/delta/x86_64-delta_ag5648-r0/plugins/sfputil.py index b4c5706b2d32..5fc426340818 100644 --- a/device/delta/x86_64-delta_ag5648-r0/plugins/sfputil.py +++ b/device/delta/x86_64-delta_ag5648-r0/plugins/sfputil.py @@ -25,6 +25,7 @@ class SfpUtil(SfpUtilBase): @property def port_start(self): return self.PORT_START + @property def port_start_qsfp(self): return self.PORT_START_QSFP @@ -45,7 +46,7 @@ def __init__(self): eeprom_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-0050/eeprom" for x in range(0, self.port_end + 1): - if x > self.port_start_qsfp -1 and x < self.port_end + 1: + if x > self.port_start_qsfp - 1 and x < self.port_end + 1: self.get_response(x) self._port_to_eeprom_mapping[x] = eeprom_path.format(x + self.EEPROM_OFFSET) SfpUtilBase.__init__(self) @@ -61,9 +62,9 @@ def get_response(self, port_num): print("Error: unable to open file: %s" % str(e)) return False - # set the bit corresponding to our port - mask = (port_num + 1) % 8 - 1 - mask = 1 << mask + # set the bit corresponding to our port + mask = (port_num + 1) % 8 - 1 + mask = 1 << mask # Convert our register value back to a hex string and write back content = hex(mask) diff --git a/device/delta/x86_64-delta_ag9032v1-r0/plugins/eeprom.py b/device/delta/x86_64-delta_ag9032v1-r0/plugins/eeprom.py index 9112318a7915..bd9bbb755f39 100644 --- a/device/delta/x86_64-delta_ag9032v1-r0/plugins/eeprom.py +++ b/device/delta/x86_64-delta_ag9032v1-r0/plugins/eeprom.py @@ -18,12 +18,13 @@ from sonic_eeprom import eeprom_tlvinfo import subprocess except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 def __init__(self, name, path, cpld_root, ro): - self.eeprom_path = "/sys/devices/pci0000:00/0000:00:13.0/i2c-1/i2c-2/2-0053/eeprom" - super(board, self).__init__(self.eeprom_path, 0, '', True) + self.eeprom_path = "/sys/devices/pci0000:00/0000:00:13.0/i2c-1/i2c-2/2-0053/eeprom" + super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/delta/x86_64-delta_ag9032v2a-r0/plugins/eeprom.py b/device/delta/x86_64-delta_ag9032v2a-r0/plugins/eeprom.py index c023b80c6501..9d55c090d57b 100644 --- a/device/delta/x86_64-delta_ag9032v2a-r0/plugins/eeprom.py +++ b/device/delta/x86_64-delta_ag9032v2a-r0/plugins/eeprom.py @@ -18,12 +18,13 @@ from sonic_eeprom import eeprom_tlvinfo import subprocess except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 def __init__(self, name, path, cpld_root, ro): - self.eeprom_path = "/sys/devices/pci0000:00/0000:00:1f.3/i2c-0/i2c-1/1-0053/eeprom" - super(board, self).__init__(self.eeprom_path, 0, '', True) + self.eeprom_path = "/sys/devices/pci0000:00/0000:00:1f.3/i2c-0/i2c-1/1-0053/eeprom" + super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/delta/x86_64-delta_ag9064-r0/plugins/eeprom.py b/device/delta/x86_64-delta_ag9064-r0/plugins/eeprom.py index 37a4dfd71be2..9a3ea5737684 100644 --- a/device/delta/x86_64-delta_ag9064-r0/plugins/eeprom.py +++ b/device/delta/x86_64-delta_ag9064-r0/plugins/eeprom.py @@ -18,12 +18,13 @@ from sonic_eeprom import eeprom_tlvinfo import subprocess except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 def __init__(self, name, path, cpld_root, ro): - self.eeprom_path = "/sys/devices/pci0000:00/0000:00:1f.3/i2c-0/0-0056/eeprom" - super(board, self).__init__(self.eeprom_path, 0, '', True) + self.eeprom_path = "/sys/devices/pci0000:00/0000:00:1f.3/i2c-0/0-0056/eeprom" + super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/delta/x86_64-delta_et-6248brb-r0/plugins/eeprom.py b/device/delta/x86_64-delta_et-6248brb-r0/plugins/eeprom.py index 5029ffc8d554..3b4b15ee543b 100644 --- a/device/delta/x86_64-delta_et-6248brb-r0/plugins/eeprom.py +++ b/device/delta/x86_64-delta_et-6248brb-r0/plugins/eeprom.py @@ -18,12 +18,13 @@ from sonic_eeprom import eeprom_tlvinfo import subprocess except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 def __init__(self, name, path, cpld_root, ro): - self.eeprom_path = "/sys/devices/pci0000:00/0000:00:13.0/i2c-1/1-0054/eeprom" - super(board, self).__init__(self.eeprom_path, 0, '', True) + self.eeprom_path = "/sys/devices/pci0000:00/0000:00:13.0/i2c-1/1-0054/eeprom" + super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/delta/x86_64-delta_et-c032if-r0/plugins/eeprom.py b/device/delta/x86_64-delta_et-c032if-r0/plugins/eeprom.py index 5254f3da2e3f..23376fcd7236 100644 --- a/device/delta/x86_64-delta_et-c032if-r0/plugins/eeprom.py +++ b/device/delta/x86_64-delta_et-c032if-r0/plugins/eeprom.py @@ -18,12 +18,13 @@ from sonic_eeprom import eeprom_tlvinfo import subprocess except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 def __init__(self, name, path, cpld_root, ro): - self.eeprom_path = "/sys/devices/pci0000:00/0000:00:1f.3/i2c-0/i2c-10/10-0053/eeprom" - super(board, self).__init__(self.eeprom_path, 0, '', True) + self.eeprom_path = "/sys/devices/pci0000:00/0000:00:1f.3/i2c-0/i2c-10/10-0053/eeprom" + super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/inventec/x86_64-inventec_d7264q28b-r0/plugins/psuutil.py b/device/inventec/x86_64-inventec_d7264q28b-r0/plugins/psuutil.py index c2337a97f4ea..8e100d36405d 100755 --- a/device/inventec/x86_64-inventec_d7264q28b-r0/plugins/psuutil.py +++ b/device/inventec/x86_64-inventec_d7264q28b-r0/plugins/psuutil.py @@ -23,8 +23,8 @@ def __init__(self): # Get sysfs attribute def get_attr_value(self, attr_path): - - retval = 'ERR' + + retval = 'ERR' if (not os.path.isfile(attr_path)): return retval @@ -36,7 +36,7 @@ def get_attr_value(self, attr_path): retval = retval.rstrip(' \t\n\r') return retval - + def get_num_psus(self): """ Retrieves the number of PSUs available on the device @@ -54,18 +54,18 @@ def get_psu_status(self, index): faulty """ status = 0 - attr_file = 'psoc_psu'+ str(index) + '_iout' - attr_path = self.PSU_DIR1 +'/' + attr_file - + attr_file = 'psoc_psu' + str(index) + '_iout' + attr_path = self.PSU_DIR1 + '/' + attr_file + attr_value = self.get_attr_value(attr_path) if (attr_value == 'ERR'): - attr_path = self.PSU_DIR2 +'/' + attr_file + attr_path = self.PSU_DIR2 + '/' + attr_file attr_value = self.get_attr_value(attr_path) # Check for PSU status if (attr_value != 0): - status = 1 + status = 1 if (attr_value != 0): - status = 1 + status = 1 return status def get_psu_presence(self, index): @@ -78,16 +78,16 @@ def get_psu_presence(self, index): status = 0 psu_absent = 0 ind = index-1 - attr_file ='psu'+ str(ind) + attr_file = 'psu' + str(ind) normal_attr_value = '0 : normal' - attr_path = self.PSU_DIR1 +'/' + attr_file + attr_path = self.PSU_DIR1 + '/' + attr_file attr_value = self.get_attr_value(attr_path) if (attr_value == 'ERR'): - attr_path = self.PSU_DIR2 +'/' + attr_file + attr_path = self.PSU_DIR2 + '/' + attr_file attr_value = self.get_attr_value(attr_path) # Check for PSU presence if (attr_value == normal_attr_value): - status = 1 + status = 1 if (attr_value == normal_attr_value): - status = 1 + status = 1 return status diff --git a/device/inventec/x86_64-inventec_d7264q28b-r0/plugins/sfputil.py b/device/inventec/x86_64-inventec_d7264q28b-r0/plugins/sfputil.py index 3f9880512f88..6591809194af 100755 --- a/device/inventec/x86_64-inventec_d7264q28b-r0/plugins/sfputil.py +++ b/device/inventec/x86_64-inventec_d7264q28b-r0/plugins/sfputil.py @@ -76,15 +76,15 @@ class SfpUtil(SfpUtilBase): 52: 65, 53: 64, 54: 63, - 55: 62, - 56: 69, - 57: 68, - 58: 67, - 59: 66, - 60: 73, - 61: 72, - 62: 71, - 63: 70 + 55: 62, + 56: 69, + 57: 68, + 58: 67, + 59: 66, + 60: 73, + 61: 72, + 62: 71, + 63: 70 } @property diff --git a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/sfputil.py b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/sfputil.py index 3a676430721c..54dbdacc1c21 100644 --- a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/sfputil.py +++ b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/sfputil.py @@ -52,23 +52,23 @@ logger = Logger(SYSLOG_IDENTIFIER) qfx5200_qsfp_cable_length_tup = ('Length(km)', 'Length OM3(2m)', - 'Length OM2(m)', 'Length OM1(m)', - 'Length Cable Assembly(m)') + 'Length OM2(m)', 'Length OM1(m)', + 'Length Cable Assembly(m)') qfx5200_sfp_cable_length_tup = ('LengthSMFkm-UnitsOfKm', 'LengthSMF(UnitsOf100m)', - 'Length50um(UnitsOf10m)', 'Length62.5um(UnitsOfm)', - 'LengthCable(UnitsOfm)', 'LengthOM3(UnitsOf10m)') + 'Length50um(UnitsOf10m)', 'Length62.5um(UnitsOfm)', + 'LengthCable(UnitsOfm)', 'LengthOM3(UnitsOf10m)') qfx5200_sfp_compliance_code_tup = ('10GEthernetComplianceCode', 'InfinibandComplianceCode', - 'ESCONComplianceCodes', 'SONETComplianceCodes', - 'EthernetComplianceCodes','FibreChannelLinkLength', - 'FibreChannelTechnology', 'SFP+CableTechnology', - 'FibreChannelTransmissionMedia','FibreChannelSpeed') + 'ESCONComplianceCodes', 'SONETComplianceCodes', + 'EthernetComplianceCodes', 'FibreChannelLinkLength', + 'FibreChannelTechnology', 'SFP+CableTechnology', + 'FibreChannelTransmissionMedia', 'FibreChannelSpeed') qfx5200_qsfp_compliance_code_tup = ('10/40G Ethernet Compliance Code', 'SONET Compliance codes', - 'SAS/SATA compliance codes', 'Gigabit Ethernet Compliant codes', - 'Fibre Channel link length/Transmitter Technology', - 'Fibre Channel transmission media', 'Fibre Channel Speed') + 'SAS/SATA compliance codes', 'Gigabit Ethernet Compliant codes', + 'Fibre Channel link length/Transmitter Technology', + 'Fibre Channel transmission media', 'Fibre Channel Speed') GPIO_SLAVE0_PORT_START = 0 @@ -120,7 +120,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 @@ -158,16 +158,17 @@ def gpio_create_file(gpio_pin): return True + def gpio_sfp_port_init(gpio_base, port): - presence_pin = gpio_base + GPIO_PRESENCE_OFFSET + (port % 16) - if gpio_create_file(presence_pin): - gpio_sfp_presence[port] = presence_pin - reset_pin = gpio_base + GPIO_RESET_OFFSET + (port % 16) - if gpio_create_file(reset_pin): - gpio_sfp_reset[port] = reset_pin - lpmode_pin = gpio_base + GPIO_LPMODE_OFFSET + (port % 16) - if gpio_create_file(lpmode_pin): - gpio_sfp_lpmode[port] = lpmode_pin + presence_pin = gpio_base + GPIO_PRESENCE_OFFSET + (port % 16) + if gpio_create_file(presence_pin): + gpio_sfp_presence[port] = presence_pin + reset_pin = gpio_base + GPIO_RESET_OFFSET + (port % 16) + if gpio_create_file(reset_pin): + gpio_sfp_reset[port] = reset_pin + lpmode_pin = gpio_base + GPIO_LPMODE_OFFSET + (port % 16) + if gpio_create_file(lpmode_pin): + gpio_sfp_lpmode[port] = lpmode_pin def gpio_sfp_slave_init(gpio_base_path, gpio_port_start, gpio_port_end): @@ -180,48 +181,53 @@ def gpio_sfp_slave_init(gpio_base_path, gpio_port_start, gpio_port_end): print("Error: unable to open file: %s" % str(e)) return - for port in range(gpio_port_start, gpio_port_end + 1): + for port in range(gpio_port_start, gpio_port_end + 1): gpio_sfp_port_init(gpio_base, port) + def gpio_sfp_base_init(): gpio_sfp_slave_init("/sys/bus/platform/drivers/gpioslave-tmc/gpioslave-tmc.21/gpio/gpio*", - GPIO_SLAVE0_PORT_START, GPIO_SLAVE0_PORT_END) + GPIO_SLAVE0_PORT_START, GPIO_SLAVE0_PORT_END) gpio_sfp_slave_init("/sys/bus/platform/drivers/gpioslave-tmc/gpioslave-tmc.22/gpio/gpio*", - GPIO_SLAVE1_PORT_START, GPIO_SLAVE1_PORT_END) + GPIO_SLAVE1_PORT_START, GPIO_SLAVE1_PORT_END) + def gpio_sfp_read(gpio_pin): gpio_pin_path = "/sys/class/gpio/gpio" + str(gpio_pin) value = 0 try: - reg_file = open(gpio_pin_path +"/value") + reg_file = open(gpio_pin_path + "/value") value = int(reg_file.readline().rstrip()) except IOError as e: - print("error: unable to open file: %s" % str(e)) + print("error: unable to open file: %s" % str(e)) return value + def gpio_sfp_write(gpio_pin, value): success = False gpio_pin_path = "/sys/class/gpio/gpio" + str(gpio_pin) try: - gpio_file = open(gpio_pin_path +"/value", 'w') + gpio_file = open(gpio_pin_path + "/value", 'w') gpio_file.write(str(value)) success = True except IOError as e: - print("error: unable to open file: %s" % str(e)) + print("error: unable to open file: %s" % str(e)) return success + def gpio_sfp_presence_get(port): if port not in list(gpio_sfp_presence.keys()): - print("Port:" + str(port) + " not in sfp dict") + print("Port:" + str(port) + " not in sfp dict") return 0 gpio_pin = gpio_sfp_presence[port] return gpio_sfp_read(gpio_pin) + def gpio_sfp_lpmode_get(port): if port not in list(gpio_sfp_lpmode.keys()): return 0 @@ -229,6 +235,7 @@ def gpio_sfp_lpmode_get(port): gpio_pin = gpio_sfp_lpmode[port] return gpio_sfp_read(gpio_pin) + def gpio_sfp_lpmode_set(port, value): if port not in list(gpio_sfp_lpmode.keys()): return False @@ -236,6 +243,7 @@ def gpio_sfp_lpmode_set(port, value): gpio_pin = gpio_sfp_lpmode[port] return gpio_sfp_write(gpio_pin, value) + def gpio_sfp_reset_set(port, value): if port not in list(gpio_sfp_reset.keys()): return False @@ -243,6 +251,7 @@ def gpio_sfp_reset_set(port, value): gpio_pin = gpio_sfp_reset[port] return gpio_sfp_write(gpio_pin, value) + class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" @@ -291,55 +300,55 @@ class SfpUtil(SfpUtilBase): } port_ctle_settings = { - 0: 119, # 0x77 - 1: 102, # 0x66 - 2: 102, # 0x66 - 3: 102, # 0x66 - 4: 102, # 0x66 - 5: 85, # 0x55 - 6: 102, # 0x66 - 7: 85, # 0x55 - 8: 85, # 0x55 - 9: 85, # 0x55 - 10: 119, # 0x77 - 11: 119, # 0x77 - 12: 102, # 0x66 - 13: 85, # 0x55 - 14: 68, # 0x44 - 15: 51, # 0x33 - 16: 68, # 0x44 - 17: 85, # 0x55 - 18: 102, # 0x66 - 19: 102, # 0x66 - 20: 119, # 0X77 - 21: 102, # 0x66 - 22: 85, # 0X55 - 23: 85, # 0X55 - 24: 85, # 0x55 - 25: 85, # 0x55 - 26: 102, # 0x66 - 27: 85, # 0x55 - 28: 102, # 0x66 - 29: 102, # 0x66 - 30: 119, # 0x77 - 31: 119 # 0x77 + 0: 119, # 0x77 + 1: 102, # 0x66 + 2: 102, # 0x66 + 3: 102, # 0x66 + 4: 102, # 0x66 + 5: 85, # 0x55 + 6: 102, # 0x66 + 7: 85, # 0x55 + 8: 85, # 0x55 + 9: 85, # 0x55 + 10: 119, # 0x77 + 11: 119, # 0x77 + 12: 102, # 0x66 + 13: 85, # 0x55 + 14: 68, # 0x44 + 15: 51, # 0x33 + 16: 68, # 0x44 + 17: 85, # 0x55 + 18: 102, # 0x66 + 19: 102, # 0x66 + 20: 119, # 0X77 + 21: 102, # 0x66 + 22: 85, # 0X55 + 23: 85, # 0X55 + 24: 85, # 0x55 + 25: 85, # 0x55 + 26: 102, # 0x66 + 27: 85, # 0x55 + 28: 102, # 0x66 + 29: 102, # 0x66 + 30: 119, # 0x77 + 31: 119 # 0x77 } optics_list_100g = { - "AFBR-89CDDZ-JU1", + "AFBR-89CDDZ-JU1", "AFBR-89CDDZ-JU2", - "FTLC9551REPM-J1", - "FCBN425QE1C30-J1", - "FCBN425QE1C10-J1", + "FTLC9551REPM-J1", + "FCBN425QE1C30-J1", + "FCBN425QE1C10-J1", "FTLC9551REPM-J3", - "LUX42604CO", - "LUX42604BO", - "EOLQ-161HG-10-LJ1", - "FTLC1151RDPL-J1", - "TR-FC13R-NJC", + "LUX42604CO", + "LUX42604BO", + "EOLQ-161HG-10-LJ1", + "FTLC1151RDPL-J1", + "TR-FC13R-NJC", "TR-FC13L-NJC", - "TR-FC13R-NJ3", - "SPQ-CE-LR-CDFB-J2", + "TR-FC13R-NJ3", + "SPQ-CE-LR-CDFB-J2", "1K1QAC", "SPQCELRCDFAJ2" } @@ -359,11 +368,11 @@ def set_bit(self, data, pos): def is_100g_optics(self, part_num): ret = part_num in self.optics_list_100g - return ret + return ret def is_40g_optics(self, part_num): ret = part_num in self.optics_list_40g - return ret + return ret def is_optics(self, part_num): if self.is_100g_optics(part_num): @@ -375,27 +384,27 @@ def is_optics(self, part_num): def process_TxCTLE(self, eeprom, port_num, part_num): if self.is_100g_optics(part_num): - logger.log_debug(" QFX5200: TxCTLE port {} and SFP PN NUM {} ".format(port_num,part_num)) - # Accessing page 3 of optics - regval = 3 - buffer = create_string_buffer(1) - buffer[0] = chr(regval) - eeprom.seek(127) - eeprom.write(buffer[0]) + logger.log_debug(" QFX5200: TxCTLE port {} and SFP PN NUM {} ".format(port_num, part_num)) + # Accessing page 3 of optics + regval = 3 + buffer = create_string_buffer(1) + buffer[0] = chr(regval) + eeprom.seek(127) + eeprom.write(buffer[0]) regval = self.port_ctle_settings[port_num] - logger.log_debug("QFX5200: TxCTLE port {}, SFP PN NUM {}, regval {} ".format(port_num,part_num,regval)) + logger.log_debug("QFX5200: TxCTLE port {}, SFP PN NUM {}, regval {} ".format(port_num, part_num, regval)) eeprom.seek(234) - buffer[0] = chr(regval) + buffer[0] = chr(regval) eeprom.write(buffer[0]) eeprom.seek(235) - eeprom.write(buffer[0]) - # Moving back the optics page to 0 - regval = 0x0 - buffer[0] = chr(regval) - eeprom.seek(127) - eeprom.write(buffer[0]) + eeprom.write(buffer[0]) + # Moving back the optics page to 0 + regval = 0x0 + buffer[0] = chr(regval) + eeprom.seek(127) + eeprom.write(buffer[0]) else: pass @@ -486,8 +495,8 @@ def write_to_file(self, file_name, from_list): fp1.close() return True - # Reading from a file to a list + def read_from_file(self, file_name): try: fp = open(file_name, 'r') @@ -495,10 +504,10 @@ def read_from_file(self, file_name): print("Error: unable to open file: %s" % str(e)) return False - to_list = fp.readlines() - to_list = [x.rstrip() for x in to_list] - fp.close() - return to_list + to_list = fp.readlines() + to_list = [x.rstrip() for x in to_list] + fp.close() + return to_list def sfp_detect(self): port = 0 @@ -520,56 +529,57 @@ def sfp_detect(self): # Read the current values from sysfs for port in range(GPIO_PORT_START, GPIO_PORT_END + 1): - sfp_present = gpio_sfp_presence_get(port) - current_sfp_values[port] = str(sfp_present) - ret_dict.update({port:current_sfp_values[port]}) - - prev_value = str(previous_sfp_values[port]) - - current_value = current_sfp_values[port] - if (prev_value != current_value): - ret_dict.update({port:current_sfp_values[port]}) - value = str(current_sfp_values[port]) - if (value): - offset = 128 - sfpi_obj = sff8436InterfaceId() - if sfpi_obj is None: - return None - - file_path = self._get_port_eeprom_path(port, self.IDENTITY_EEPROM_ADDR) - if not self._sfp_eeprom_present(file_path, 0): - print("Error, file not exist %s" % file_path) - return None - - try: - sysfsfile_eeprom = open(file_path, mode="rb", buffering=0) - except IOError: - print("Error: reading sysfs file %s" % file_path) - return None - - sfp_vendor_pn_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + XCVR_VENDOR_PN_OFFSET), XCVR_VENDOR_PN_WIDTH) - if sfp_vendor_pn_raw is not None: - sfp_vendor_pn_data = sfpi_obj.parse_vendor_pn(sfp_vendor_pn_raw, 0) - else: - return None - - try: - sysfsfile_eeprom.close() - except IOError: - print("Error: closing sysfs file %s" % file_path) - return None - - sfp_pn_num = str(sfp_vendor_pn_data['data']['Vendor PN']['value']) - if self.is_optics(sfp_pn_num): - logger.log_debug("QFX5200: Port {} is connected with Optics with Part Number {}".format(port,sfp_pn_num)) - eeprom1 = open(self._port_to_eeprom_mapping[port], "r+b") - self.process_TxCTLE(eeprom1, port, sfp_pn_num) - eeprom1.close - # End of if(value) - # End of current_sfp_values != previous_sfp_vlalues + sfp_present = gpio_sfp_presence_get(port) + current_sfp_values[port] = str(sfp_present) + ret_dict.update({port: current_sfp_values[port]}) + + prev_value = str(previous_sfp_values[port]) + + current_value = current_sfp_values[port] + if (prev_value != current_value): + ret_dict.update({port: current_sfp_values[port]}) + value = str(current_sfp_values[port]) + if (value): + offset = 128 + sfpi_obj = sff8436InterfaceId() + if sfpi_obj is None: + return None + + file_path = self._get_port_eeprom_path(port, self.IDENTITY_EEPROM_ADDR) + if not self._sfp_eeprom_present(file_path, 0): + print("Error, file not exist %s" % file_path) + return None + + try: + sysfsfile_eeprom = open(file_path, mode="rb", buffering=0) + except IOError: + print("Error: reading sysfs file %s" % file_path) + return None + + sfp_vendor_pn_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + XCVR_VENDOR_PN_OFFSET), XCVR_VENDOR_PN_WIDTH) + if sfp_vendor_pn_raw is not None: + sfp_vendor_pn_data = sfpi_obj.parse_vendor_pn(sfp_vendor_pn_raw, 0) + else: + return None + + try: + sysfsfile_eeprom.close() + except IOError: + print("Error: closing sysfs file %s" % file_path) + return None + + sfp_pn_num = str(sfp_vendor_pn_data['data']['Vendor PN']['value']) + if self.is_optics(sfp_pn_num): + logger.log_debug( + "QFX5200: Port {} is connected with Optics with Part Number {}".format(port, sfp_pn_num)) + eeprom1 = open(self._port_to_eeprom_mapping[port], "r+b") + self.process_TxCTLE(eeprom1, port, sfp_pn_num) + eeprom1.close + # End of if(value) + # End of current_sfp_values != previous_sfp_vlalues # End of for loop - if(self.write_to_file(self.cmd, current_sfp_values) == True): logger.log_debug("QFX5200: sfp_detect, current sfp values written successfully to sfppresence file") logger.log_debug("QFX5200: sfp_detect ret_dict is {}".format(ret_dict)) @@ -607,31 +617,36 @@ def get_transceiver_info_dict(self, port_num): print("Error: reading sysfs file %s" % file_path) return None - sfp_type_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + OSFP_TYPE_OFFSET), XCVR_TYPE_WIDTH) + sfp_type_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + OSFP_TYPE_OFFSET), XCVR_TYPE_WIDTH) if sfp_type_raw is not None: sfp_type_data = sfpi_obj.parse_sfp_type(sfp_type_raw, 0) else: return None - sfp_vendor_name_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + OSFP_VENDOR_NAME_OFFSET), XCVR_VENDOR_NAME_WIDTH) + sfp_vendor_name_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + OSFP_VENDOR_NAME_OFFSET), XCVR_VENDOR_NAME_WIDTH) if sfp_vendor_name_raw is not None: sfp_vendor_name_data = sfpi_obj.parse_vendor_name(sfp_vendor_name_raw, 0) else: return None - sfp_vendor_pn_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + OSFP_VENDOR_PN_OFFSET), XCVR_VENDOR_PN_WIDTH) + sfp_vendor_pn_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + OSFP_VENDOR_PN_OFFSET), XCVR_VENDOR_PN_WIDTH) if sfp_vendor_pn_raw is not None: sfp_vendor_pn_data = sfpi_obj.parse_vendor_pn(sfp_vendor_pn_raw, 0) else: return None - sfp_vendor_rev_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + OSFP_HW_REV_OFFSET), vendor_rev_width) + sfp_vendor_rev_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + OSFP_HW_REV_OFFSET), vendor_rev_width) if sfp_vendor_rev_raw is not None: sfp_vendor_rev_data = sfpi_obj.parse_vendor_rev(sfp_vendor_rev_raw, 0) else: return None - sfp_vendor_sn_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + OSFP_VENDOR_SN_OFFSET), XCVR_VENDOR_SN_WIDTH) + sfp_vendor_sn_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + OSFP_VENDOR_SN_OFFSET), XCVR_VENDOR_SN_WIDTH) if sfp_vendor_sn_raw is not None: sfp_vendor_sn_data = sfpi_obj.parse_vendor_sn(sfp_vendor_sn_raw, 0) else: @@ -695,43 +710,50 @@ def get_transceiver_info_dict(self, port_num): print("Error: reading sysfs file %s" % file_path) return None - sfp_interface_bulk_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + XCVR_INTFACE_BULK_OFFSET), interface_info_bulk_width) + sfp_interface_bulk_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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) else: return None - sfp_vendor_name_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + XCVR_VENDOR_NAME_OFFSET), XCVR_VENDOR_NAME_WIDTH) + sfp_vendor_name_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + XCVR_VENDOR_NAME_OFFSET), XCVR_VENDOR_NAME_WIDTH) if sfp_vendor_name_raw is not None: sfp_vendor_name_data = sfpi_obj.parse_vendor_name(sfp_vendor_name_raw, 0) else: return None - sfp_vendor_pn_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + XCVR_VENDOR_PN_OFFSET), XCVR_VENDOR_PN_WIDTH) + sfp_vendor_pn_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + XCVR_VENDOR_PN_OFFSET), XCVR_VENDOR_PN_WIDTH) if sfp_vendor_pn_raw is not None: sfp_vendor_pn_data = sfpi_obj.parse_vendor_pn(sfp_vendor_pn_raw, 0) else: return None - sfp_vendor_rev_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + XCVR_HW_REV_OFFSET), vendor_rev_width) + sfp_vendor_rev_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + XCVR_HW_REV_OFFSET), vendor_rev_width) if sfp_vendor_rev_raw is not None: sfp_vendor_rev_data = sfpi_obj.parse_vendor_rev(sfp_vendor_rev_raw, 0) else: return None - sfp_vendor_sn_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + XCVR_VENDOR_SN_OFFSET), XCVR_VENDOR_SN_WIDTH) + sfp_vendor_sn_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + XCVR_VENDOR_SN_OFFSET), XCVR_VENDOR_SN_WIDTH) if sfp_vendor_sn_raw is not None: sfp_vendor_sn_data = sfpi_obj.parse_vendor_sn(sfp_vendor_sn_raw, 0) else: return None - sfp_vendor_oui_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + XCVR_VENDOR_OUI_OFFSET), XCVR_VENDOR_OUI_WIDTH) + sfp_vendor_oui_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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) else: return None - sfp_vendor_date_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + XCVR_VENDOR_DATE_OFFSET), XCVR_VENDOR_DATE_WIDTH) + sfp_vendor_date_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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) else: @@ -750,7 +772,8 @@ def get_transceiver_info_dict(self, port_num): transceiver_info_dict['hardware_rev'] = sfp_vendor_rev_data['data']['Vendor Rev']['value'] transceiver_info_dict['serial'] = sfp_vendor_sn_data['data']['Vendor SN']['value'] transceiver_info_dict['vendor_oui'] = sfp_vendor_oui_data['data']['Vendor OUI']['value'] - transceiver_info_dict['vendor_date'] = sfp_vendor_date_data['data']['VendorDataCode(YYYY-MM-DD Lot)']['value'] + transceiver_info_dict['vendor_date'] = sfp_vendor_date_data[ + 'data']['VendorDataCode(YYYY-MM-DD Lot)']['value'] transceiver_info_dict['connector'] = sfp_interface_bulk_data['data']['Connector']['value'] transceiver_info_dict['encoding'] = sfp_interface_bulk_data['data']['EncodingCodes']['value'] transceiver_info_dict['ext_identifier'] = sfp_interface_bulk_data['data']['Extended Identifier']['value'] @@ -771,7 +794,8 @@ def get_transceiver_info_dict(self, port_num): transceiver_info_dict['specification_compliance'] = str(compliance_code_dict) if 'Nominal Bit Rate(100Mbs)' in sfp_interface_bulk_data['data']: - transceiver_info_dict['nominal_bit_rate'] = str(sfp_interface_bulk_data['data']['Nominal Bit Rate(100Mbs)']['value']) + transceiver_info_dict['nominal_bit_rate'] = str( + sfp_interface_bulk_data['data']['Nominal Bit Rate(100Mbs)']['value']) else: transceiver_info_dict['nominal_bit_rate'] = 'N/A' else: @@ -789,7 +813,8 @@ def get_transceiver_info_dict(self, port_num): transceiver_info_dict['specification_compliance'] = str(compliance_code_dict) if 'NominalSignallingRate(UnitsOf100Mbd)' in sfp_interface_bulk_data['data']: - transceiver_info_dict['nominal_bit_rate'] = str(sfp_interface_bulk_data['data']['NominalSignallingRate(UnitsOf100Mbd)']['value']) + transceiver_info_dict['nominal_bit_rate'] = str( + sfp_interface_bulk_data['data']['NominalSignallingRate(UnitsOf100Mbd)']['value']) else: transceiver_info_dict['nominal_bit_rate'] = 'N/A' @@ -842,25 +867,29 @@ def get_transceiver_dom_info_dict(self, port_num): # TODO: in the future when decided to migrate to support SFF-8636 instead of SFF-8436, # need to add more code for determining the capability and version compliance # in SFF-8636 dom capability definitions evolving with the versions. - qsfp_dom_capability_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset_xcvr + XCVR_DOM_CAPABILITY_OFFSET), XCVR_DOM_CAPABILITY_WIDTH) + qsfp_dom_capability_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset_xcvr + XCVR_DOM_CAPABILITY_OFFSET), XCVR_DOM_CAPABILITY_WIDTH) if qsfp_dom_capability_raw is not None: qspf_dom_capability_data = sfpi_obj.parse_qsfp_dom_capability(qsfp_dom_capability_raw, 0) else: return None - dom_temperature_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + QSFP_TEMPE_OFFSET), QSFP_TEMPE_WIDTH) + dom_temperature_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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(sysfsfile_eeprom, (offset + QSFP_VOLT_OFFSET), QSFP_VOLT_WIDTH) + dom_voltage_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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(sysfsfile_eeprom, (offset + QSFP_DOM_REV_OFFSET), QSFP_DOM_REV_WIDTH) + qsfp_dom_rev_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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: @@ -875,7 +904,8 @@ def get_transceiver_dom_info_dict(self, port_num): 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(sysfsfile_eeprom, (offset + QSFP_CHANNL_MON_OFFSET), QSFP_CHANNL_MON_WIDTH) + dom_channel_monitor_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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: @@ -886,9 +916,11 @@ def get_transceiver_dom_info_dict(self, port_num): transceiver_dom_info_dict['tx3power'] = 'N/A' transceiver_dom_info_dict['tx4power'] = 'N/A' else: - dom_channel_monitor_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + QSFP_CHANNL_MON_OFFSET), QSFP_CHANNL_MON_WITH_TX_POWER_WIDTH) + dom_channel_monitor_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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 @@ -930,19 +962,22 @@ def get_transceiver_dom_info_dict(self, port_num): if sfpd_obj is None: return None - dom_temperature_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_TEMPE_OFFSET), SFP_TEMPE_WIDTH) + dom_temperature_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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(sysfsfile_eeprom, (offset + SFP_VOLT_OFFSET), SFP_VOLT_WIDTH) + dom_voltage_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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(sysfsfile_eeprom, (offset + SFP_CHANNL_MON_OFFSET), SFP_CHANNL_MON_WIDTH) + dom_channel_monitor_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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: @@ -984,7 +1019,7 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): 'txpowerlowalarm', 'txpowerlowwarning', 'txbiashighalarm', 'txbiashighwarning', 'txbiaslowalarm', 'txbiaslowwarning' - ] + ] transceiver_dom_threshold_info_dict = dict.fromkeys(dom_info_dict_keys, 'N/A') logger.log_debug("QFX5200: get_transceiver_dom_threshold_info_dict Start") @@ -1007,18 +1042,18 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): # Revert offset back to 0 once data is retrieved offset = 384 dom_module_threshold_raw = self._read_eeprom_specific_bytes( - sysfsfile_eeprom, - (offset + QSFP_MODULE_THRESHOLD_OFFSET), - QSFP_MODULE_THRESHOLD_WIDTH) + sysfsfile_eeprom, + (offset + QSFP_MODULE_THRESHOLD_OFFSET), + QSFP_MODULE_THRESHOLD_WIDTH) if dom_module_threshold_raw is not None: dom_module_threshold_data = sfpd_obj.parse_module_threshold_values(dom_module_threshold_raw, 0) else: return transceiver_dom_threshold_info_dict dom_channel_threshold_raw = self._read_eeprom_specific_bytes( - sysfsfile_eeprom, - (offset + QSFP_CHANNL_THRESHOLD_OFFSET), - QSFP_CHANNL_THRESHOLD_WIDTH) + sysfsfile_eeprom, + (offset + QSFP_CHANNL_THRESHOLD_OFFSET), + QSFP_CHANNL_THRESHOLD_WIDTH) if dom_channel_threshold_raw is not None: dom_channel_threshold_data = sfpd_obj.parse_channel_threshold_values(dom_channel_threshold_raw, 0) else: @@ -1055,17 +1090,17 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): return None try: - sysfsfile_eeprom = io.open(file_path,"rb",0) + sysfsfile_eeprom = io.open(file_path, "rb", 0) except IOError: print("Error: reading sysfs file %s" % file_path) return None - sfpd_obj = sff8472Dom(None,1) + sfpd_obj = sff8472Dom(None, 1) if sfpd_obj is None: return transceiver_dom_threshold_info_dict dom_module_threshold_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, - (offset + SFP_MODULE_THRESHOLD_OFFSET), SFP_MODULE_THRESHOLD_WIDTH) + (offset + SFP_MODULE_THRESHOLD_OFFSET), SFP_MODULE_THRESHOLD_WIDTH) if dom_module_threshold_raw is not None: dom_module_threshold_data = sfpd_obj.parse_alarm_warning_threshold(dom_module_threshold_raw, 0) @@ -1078,7 +1113,7 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): print("Error: closing sysfs file %s" % file_path) return None - #Threshold Data + # Threshold Data transceiver_dom_threshold_info_dict['temphighalarm'] = dom_module_threshold_data['data']['TempHighAlarm']['value'] transceiver_dom_threshold_info_dict['templowalarm'] = dom_module_threshold_data['data']['TempLowAlarm']['value'] transceiver_dom_threshold_info_dict['temphighwarning'] = dom_module_threshold_data['data']['TempHighWarning']['value'] @@ -1104,6 +1139,5 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): return transceiver_dom_threshold_info_dict def get_transceiver_change_event(self, timeout=2000): - time.sleep(3) + time.sleep(3) return self.sfp_detect() - diff --git a/device/juniper/x86_64-juniper_qfx5210-r0/plugins/sfputil.py b/device/juniper/x86_64-juniper_qfx5210-r0/plugins/sfputil.py index 9fd51a6b1c84..8f3365f5eb23 100644 --- a/device/juniper/x86_64-juniper_qfx5210-r0/plugins/sfputil.py +++ b/device/juniper/x86_64-juniper_qfx5210-r0/plugins/sfputil.py @@ -8,30 +8,29 @@ from ctypes import create_string_buffer from sonic_py_common.logger import Logger except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") SYSLOG_IDENTIFIER = "sfputil" logger = Logger(SYSLOG_IDENTIFIER) qfx5210_qsfp_cable_length_tup = ('Length(km)', 'Length OM3(2m)', - 'Length OM2(m)', 'Length OM1(m)', - 'Length Cable Assembly(m)') + 'Length OM2(m)', 'Length OM1(m)', + 'Length Cable Assembly(m)') qfx5210_sfp_cable_length_tup = ('LengthSMFkm-UnitsOfKm', 'LengthSMF(UnitsOf100m)', - 'Length50um(UnitsOf10m)', 'Length62.5um(UnitsOfm)', - 'LengthCable(UnitsOfm)', 'LengthOM3(UnitsOf10m)') + 'Length50um(UnitsOf10m)', 'Length62.5um(UnitsOfm)', + 'LengthCable(UnitsOfm)', 'LengthOM3(UnitsOf10m)') qfx5210_sfp_compliance_code_tup = ('10GEthernetComplianceCode', 'InfinibandComplianceCode', - 'ESCONComplianceCodes', 'SONETComplianceCodes', - 'EthernetComplianceCodes','FibreChannelLinkLength', - 'FibreChannelTechnology', 'SFP+CableTechnology', - 'FibreChannelTransmissionMedia','FibreChannelSpeed') + 'ESCONComplianceCodes', 'SONETComplianceCodes', + 'EthernetComplianceCodes', 'FibreChannelLinkLength', + 'FibreChannelTechnology', 'SFP+CableTechnology', + 'FibreChannelTransmissionMedia', 'FibreChannelSpeed') qfx5210_qsfp_compliance_code_tup = ('10/40G Ethernet Compliance Code', 'SONET Compliance codes', - 'SAS/SATA compliance codes', 'Gigabit Ethernet Compliant codes', - 'Fibre Channel link length/Transmitter Technology', - 'Fibre Channel transmission media', 'Fibre Channel Speed') - + 'SAS/SATA compliance codes', 'Gigabit Ethernet Compliant codes', + 'Fibre Channel link length/Transmitter Technology', + 'Fibre Channel transmission media', 'Fibre Channel Speed') class SfpUtil(SfpUtilBase): @@ -43,75 +42,74 @@ class SfpUtil(SfpUtilBase): cmd = '/var/run/sfppresence' _port_to_eeprom_mapping = {} port_to_i2c_mapping = { - 60 : 25, - 61 : 26, - 62 : 27, - 63 : 28, - 54 : 29, - 55 : 30, - 52 : 31, - 53 : 32, - 8 : 33, - 9 : 34, - 10 : 35, - 11 : 36, - 0 : 37, - 1 : 38, - 2 : 39, - 3 : 40, - 5 : 41, - 4 : 42, - 7 : 43, - 6 : 44, - 12 : 45, - 13 : 46, - 14 : 47, - 15 : 48, - 16 : 49, - 17 : 50, - 18 : 51, - 19 : 52, - 24 : 53, - 25 : 54, - 26 : 55, - 27 : 56, - 28 : 57, - 29 : 58, - 30 : 59, - 31 : 60, - 20 : 61, - 21 : 62, - 22 : 63, - 23 : 64, - 40 : 65, - 41 : 66, - 42 : 67, - 43 : 68, - 32 : 69, - 33 : 70, - 34 : 71, - 35 : 72, - 44 : 73, - 45 : 74, - 46 : 75, - 47 : 76, - 36 : 77, - 37 : 78, - 38 : 79, - 39 : 80, - 56 : 81, - 57 : 82, - 58 : 83, - 59 : 84, - 48 : 85, - 49 : 86, - 50 : 87, - 51 : 88,} - - # sys.path.append('/usr/local/bin') + 60: 25, + 61: 26, + 62: 27, + 63: 28, + 54: 29, + 55: 30, + 52: 31, + 53: 32, + 8: 33, + 9: 34, + 10: 35, + 11: 36, + 0: 37, + 1: 38, + 2: 39, + 3: 40, + 5: 41, + 4: 42, + 7: 43, + 6: 44, + 12: 45, + 13: 46, + 14: 47, + 15: 48, + 16: 49, + 17: 50, + 18: 51, + 19: 52, + 24: 53, + 25: 54, + 26: 55, + 27: 56, + 28: 57, + 29: 58, + 30: 59, + 31: 60, + 20: 61, + 21: 62, + 22: 63, + 23: 64, + 40: 65, + 41: 66, + 42: 67, + 43: 68, + 32: 69, + 33: 70, + 34: 71, + 35: 72, + 44: 73, + 45: 74, + 46: 75, + 47: 76, + 36: 77, + 37: 78, + 38: 79, + 39: 80, + 56: 81, + 57: 82, + 58: 83, + 59: 84, + 48: 85, + 49: 86, + 50: 87, + 51: 88, } + + # sys.path.append('/usr/local/bin') _qsfp_ports = list(range(0, ports_in_block + 1)) - def __init__(self): eeprom_path = '/sys/bus/i2c/devices/{0}-0050/eeprom' for x in range(self._port_start, self._port_end + 1): @@ -123,7 +121,7 @@ def reset(self, port_num): # Check for invalid port_num if port_num < self._port_start or port_num > self._port_end: return False - path = "/sys/bus/i2c/devices/19-0060/module_reset_{0}" + path = "/sys/bus/i2c/devices/19-0060/module_reset_{0}" port_ps = path.format(port_num+1) try: @@ -132,7 +130,7 @@ def reset(self, port_num): print("Error: unable to open file: %s" % str(e)) return False - #HW will clear reset after set. + # HW will clear reset after set. reg_file.seek(0) reg_file.write('1') reg_file.close() @@ -172,7 +170,7 @@ def qsfp_ports(self): @property def port_to_eeprom_mapping(self): - return self._port_to_eeprom_mapping + return self._port_to_eeprom_mapping # Writing to a file from a list def write_to_file(self, file_name, from_list): @@ -189,8 +187,8 @@ def write_to_file(self, file_name, from_list): fp1.close() return True - # Reading from a file to a list + def read_from_file(self, file_name): try: fp = open(file_name, 'r') @@ -198,10 +196,10 @@ def read_from_file(self, file_name): print("Error: unable to open file: %s" % str(e)) return False - to_list = fp.readlines() - to_list = [x.rstrip() for x in to_list] - fp.close() - return to_list + to_list = fp.readlines() + to_list = [x.rstrip() for x in to_list] + fp.close() + return to_list def sfp_detect(self): x = 0 @@ -220,8 +218,8 @@ def sfp_detect(self): else: previous_sfp_values = self.read_from_file(self.cmd) - # Read the current values from sysfs - for x in range(self._port_start , self._port_end + 1): + # Read the current values from sysfs + for x in range(self._port_start, self._port_end + 1): try: new_path = path.format(x + 1) reg_file = open(new_path, 'r') @@ -229,11 +227,11 @@ def sfp_detect(self): print("Error: unable to open file: %s" % str(e)) return False, defl_dict - sfp_present = reg_file.readline().rstrip() + sfp_present = reg_file.readline().rstrip() reg_file.close() current_sfp_values[x] = sfp_present - if (current_sfp_values[x] != previous_sfp_values[x]): - ret_dict.update({x:current_sfp_values[x]}) + if (current_sfp_values[x] != previous_sfp_values[x]): + ret_dict.update({x: current_sfp_values[x]}) if(self.write_to_file(self.cmd, current_sfp_values) == True): return True, ret_dict @@ -260,11 +258,11 @@ def get_low_power_mode(self, port_num): lpmode = ord(eeprom.read(1)) if ((lpmode & 0x3) == 0x3): - return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 + return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 else: - return 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 + return 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 except IOError as e: print("Error: unable to open file: %s" % str(e)) return False @@ -282,10 +280,10 @@ def set_low_power_mode(self, port_num, lpmode): eeprom = None if not self.get_presence(port_num): - return False # Port is not present, unable to set the eeprom + return False # Port is not present, unable to set the eeprom # 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) @@ -330,31 +328,36 @@ def get_transceiver_info_dict(self, port_num): print("Error: reading sysfs file %s" % file_path) return None - sfp_type_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + OSFP_TYPE_OFFSET), XCVR_TYPE_WIDTH) + sfp_type_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + OSFP_TYPE_OFFSET), XCVR_TYPE_WIDTH) if sfp_type_raw is not None: sfp_type_data = sfpi_obj.parse_sfp_type(sfp_type_raw, 0) else: return None - sfp_vendor_name_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + OSFP_VENDOR_NAME_OFFSET), XCVR_VENDOR_NAME_WIDTH) + sfp_vendor_name_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + OSFP_VENDOR_NAME_OFFSET), XCVR_VENDOR_NAME_WIDTH) if sfp_vendor_name_raw is not None: sfp_vendor_name_data = sfpi_obj.parse_vendor_name(sfp_vendor_name_raw, 0) else: return None - sfp_vendor_pn_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + OSFP_VENDOR_PN_OFFSET), XCVR_VENDOR_PN_WIDTH) + sfp_vendor_pn_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + OSFP_VENDOR_PN_OFFSET), XCVR_VENDOR_PN_WIDTH) if sfp_vendor_pn_raw is not None: sfp_vendor_pn_data = sfpi_obj.parse_vendor_pn(sfp_vendor_pn_raw, 0) else: return None - sfp_vendor_rev_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + OSFP_HW_REV_OFFSET), vendor_rev_width) + sfp_vendor_rev_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + OSFP_HW_REV_OFFSET), vendor_rev_width) if sfp_vendor_rev_raw is not None: sfp_vendor_rev_data = sfpi_obj.parse_vendor_rev(sfp_vendor_rev_raw, 0) else: return None - sfp_vendor_sn_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + OSFP_VENDOR_SN_OFFSET), XCVR_VENDOR_SN_WIDTH) + sfp_vendor_sn_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + OSFP_VENDOR_SN_OFFSET), XCVR_VENDOR_SN_WIDTH) if sfp_vendor_sn_raw is not None: sfp_vendor_sn_data = sfpi_obj.parse_vendor_sn(sfp_vendor_sn_raw, 0) else: @@ -420,43 +423,50 @@ def get_transceiver_info_dict(self, port_num): print("Error: reading sysfs file %s" % file_path) return None - sfp_interface_bulk_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + XCVR_INTFACE_BULK_OFFSET), interface_info_bulk_width) + sfp_interface_bulk_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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) else: return None - sfp_vendor_name_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + XCVR_VENDOR_NAME_OFFSET), XCVR_VENDOR_NAME_WIDTH) + sfp_vendor_name_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + XCVR_VENDOR_NAME_OFFSET), XCVR_VENDOR_NAME_WIDTH) if sfp_vendor_name_raw is not None: sfp_vendor_name_data = sfpi_obj.parse_vendor_name(sfp_vendor_name_raw, 0) else: return None - sfp_vendor_pn_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + XCVR_VENDOR_PN_OFFSET), XCVR_VENDOR_PN_WIDTH) + sfp_vendor_pn_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + XCVR_VENDOR_PN_OFFSET), XCVR_VENDOR_PN_WIDTH) if sfp_vendor_pn_raw is not None: sfp_vendor_pn_data = sfpi_obj.parse_vendor_pn(sfp_vendor_pn_raw, 0) else: return None - sfp_vendor_rev_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + XCVR_HW_REV_OFFSET), vendor_rev_width) + sfp_vendor_rev_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + XCVR_HW_REV_OFFSET), vendor_rev_width) if sfp_vendor_rev_raw is not None: sfp_vendor_rev_data = sfpi_obj.parse_vendor_rev(sfp_vendor_rev_raw, 0) else: return None - sfp_vendor_sn_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + XCVR_VENDOR_SN_OFFSET), XCVR_VENDOR_SN_WIDTH) + sfp_vendor_sn_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + XCVR_VENDOR_SN_OFFSET), XCVR_VENDOR_SN_WIDTH) if sfp_vendor_sn_raw is not None: sfp_vendor_sn_data = sfpi_obj.parse_vendor_sn(sfp_vendor_sn_raw, 0) else: return None - sfp_vendor_oui_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + XCVR_VENDOR_OUI_OFFSET), XCVR_VENDOR_OUI_WIDTH) + sfp_vendor_oui_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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) else: return None - sfp_vendor_date_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + XCVR_VENDOR_DATE_OFFSET), XCVR_VENDOR_DATE_WIDTH) + sfp_vendor_date_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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) else: @@ -475,7 +485,8 @@ def get_transceiver_info_dict(self, port_num): transceiver_info_dict['hardware_rev'] = sfp_vendor_rev_data['data']['Vendor Rev']['value'] transceiver_info_dict['serial'] = sfp_vendor_sn_data['data']['Vendor SN']['value'] transceiver_info_dict['vendor_oui'] = sfp_vendor_oui_data['data']['Vendor OUI']['value'] - transceiver_info_dict['vendor_date'] = sfp_vendor_date_data['data']['VendorDataCode(YYYY-MM-DD Lot)']['value'] + transceiver_info_dict['vendor_date'] = sfp_vendor_date_data[ + 'data']['VendorDataCode(YYYY-MM-DD Lot)']['value'] transceiver_info_dict['connector'] = sfp_interface_bulk_data['data']['Connector']['value'] transceiver_info_dict['encoding'] = sfp_interface_bulk_data['data']['EncodingCodes']['value'] transceiver_info_dict['ext_identifier'] = sfp_interface_bulk_data['data']['Extended Identifier']['value'] @@ -496,7 +507,8 @@ def get_transceiver_info_dict(self, port_num): transceiver_info_dict['specification_compliance'] = str(compliance_code_dict) if 'Nominal Bit Rate(100Mbs)' in sfp_interface_bulk_data['data']: - transceiver_info_dict['nominal_bit_rate'] = str(sfp_interface_bulk_data['data']['Nominal Bit Rate(100Mbs)']['value']) + transceiver_info_dict['nominal_bit_rate'] = str( + sfp_interface_bulk_data['data']['Nominal Bit Rate(100Mbs)']['value']) else: transceiver_info_dict['nominal_bit_rate'] = 'N/A' else: @@ -514,7 +526,8 @@ def get_transceiver_info_dict(self, port_num): transceiver_info_dict['specification_compliance'] = str(compliance_code_dict) if 'NominalSignallingRate(UnitsOf100Mbd)' in sfp_interface_bulk_data['data']: - transceiver_info_dict['nominal_bit_rate'] = str(sfp_interface_bulk_data['data']['NominalSignallingRate(UnitsOf100Mbd)']['value']) + transceiver_info_dict['nominal_bit_rate'] = str( + sfp_interface_bulk_data['data']['NominalSignallingRate(UnitsOf100Mbd)']['value']) else: transceiver_info_dict['nominal_bit_rate'] = 'N/A' #transceiver_info_dict['nominal_bit_rate'] = str(sfp_interface_bulk_data['data']['NominalSignallingRate(UnitsOf100Mbd)']['value']) @@ -566,25 +579,29 @@ def get_transceiver_dom_info_dict(self, port_num): # TODO: in the future when decided to migrate to support SFF-8636 instead of SFF-8436, # need to add more code for determining the capability and version compliance # in SFF-8636 dom capability definitions evolving with the versions. - qsfp_dom_capability_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset_xcvr + XCVR_DOM_CAPABILITY_OFFSET), XCVR_DOM_CAPABILITY_WIDTH) + qsfp_dom_capability_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset_xcvr + XCVR_DOM_CAPABILITY_OFFSET), XCVR_DOM_CAPABILITY_WIDTH) if qsfp_dom_capability_raw is not None: qspf_dom_capability_data = sfpi_obj.parse_qsfp_dom_capability(qsfp_dom_capability_raw, 0) else: return None - dom_temperature_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + QSFP_TEMPE_OFFSET), QSFP_TEMPE_WIDTH) + dom_temperature_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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(sysfsfile_eeprom, (offset + QSFP_VOLT_OFFSET), QSFP_VOLT_WIDTH) + dom_voltage_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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(sysfsfile_eeprom, (offset + QSFP_DOM_REV_OFFSET), QSFP_DOM_REV_WIDTH) + qsfp_dom_rev_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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: @@ -599,7 +616,8 @@ def get_transceiver_dom_info_dict(self, port_num): 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(sysfsfile_eeprom, (offset + QSFP_CHANNL_MON_OFFSET), QSFP_CHANNL_MON_WIDTH) + dom_channel_monitor_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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: @@ -610,9 +628,11 @@ def get_transceiver_dom_info_dict(self, port_num): transceiver_dom_info_dict['tx3power'] = 'N/A' transceiver_dom_info_dict['tx4power'] = 'N/A' else: - dom_channel_monitor_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + QSFP_CHANNL_MON_OFFSET), QSFP_CHANNL_MON_WITH_TX_POWER_WIDTH) + dom_channel_monitor_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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 @@ -654,19 +674,22 @@ def get_transceiver_dom_info_dict(self, port_num): if sfpd_obj is None: return None - dom_temperature_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_TEMPE_OFFSET), SFP_TEMPE_WIDTH) + dom_temperature_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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(sysfsfile_eeprom, (offset + SFP_VOLT_OFFSET), SFP_VOLT_WIDTH) + dom_voltage_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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(sysfsfile_eeprom, (offset + SFP_CHANNL_MON_OFFSET), SFP_CHANNL_MON_WIDTH) + dom_channel_monitor_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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: @@ -707,7 +730,7 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): 'txpowerlowalarm', 'txpowerlowwarning', 'txbiashighalarm', 'txbiashighwarning', 'txbiaslowalarm', 'txbiaslowwarning' - ] + ] transceiver_dom_threshold_info_dict = dict.fromkeys(dom_info_dict_keys, 'N/A') logger.log_debug("QFX5210: get_transceiver_dom_threshold_info_dict Start") @@ -730,18 +753,18 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): # Revert offset back to 0 once data is retrieved offset = 384 dom_module_threshold_raw = self._read_eeprom_specific_bytes( - sysfsfile_eeprom, - (offset + QSFP_MODULE_THRESHOLD_OFFSET), - QSFP_MODULE_THRESHOLD_WIDTH) + sysfsfile_eeprom, + (offset + QSFP_MODULE_THRESHOLD_OFFSET), + QSFP_MODULE_THRESHOLD_WIDTH) if dom_module_threshold_raw is not None: dom_module_threshold_data = sfpd_obj.parse_module_threshold_values(dom_module_threshold_raw, 0) else: return transceiver_dom_threshold_info_dict dom_channel_threshold_raw = self._read_eeprom_specific_bytes( - sysfsfile_eeprom, - (offset + QSFP_CHANNL_THRESHOLD_OFFSET), - QSFP_CHANNL_THRESHOLD_WIDTH) + sysfsfile_eeprom, + (offset + QSFP_CHANNL_THRESHOLD_OFFSET), + QSFP_CHANNL_THRESHOLD_WIDTH) if dom_channel_threshold_raw is not None: dom_channel_threshold_data = sfpd_obj.parse_channel_threshold_values(dom_channel_threshold_raw, 0) else: @@ -778,17 +801,17 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): return None try: - sysfsfile_eeprom = io.open(file_path,"rb",0) + sysfsfile_eeprom = io.open(file_path, "rb", 0) except IOError: print("Error: reading sysfs file %s" % file_path) return None - sfpd_obj = sff8472Dom(None,1) + sfpd_obj = sff8472Dom(None, 1) if sfpd_obj is None: return transceiver_dom_threshold_info_dict dom_module_threshold_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, - (offset + SFP_MODULE_THRESHOLD_OFFSET), SFP_MODULE_THRESHOLD_WIDTH) + (offset + SFP_MODULE_THRESHOLD_OFFSET), SFP_MODULE_THRESHOLD_WIDTH) if dom_module_threshold_raw is not None: dom_module_threshold_data = sfpd_obj.parse_alarm_warning_threshold(dom_module_threshold_raw, 0) @@ -801,7 +824,7 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): print("Error: closing sysfs file %s" % file_path) return None - #Threshold Data + # Threshold Data transceiver_dom_threshold_info_dict['temphighalarm'] = dom_module_threshold_data['data']['TempHighAlarm']['value'] transceiver_dom_threshold_info_dict['templowalarm'] = dom_module_threshold_data['data']['TempLowAlarm']['value'] transceiver_dom_threshold_info_dict['temphighwarning'] = dom_module_threshold_data['data']['TempHighWarning']['value'] diff --git a/device/marvell/arm64-marvell_db98cx8580_16cd-r0/plugins/sfputil.py b/device/marvell/arm64-marvell_db98cx8580_16cd-r0/plugins/sfputil.py index 193adf148ffc..4463e687e695 100644 --- a/device/marvell/arm64-marvell_db98cx8580_16cd-r0/plugins/sfputil.py +++ b/device/marvell/arm64-marvell_db98cx8580_16cd-r0/plugins/sfputil.py @@ -5,7 +5,7 @@ import re from sonic_sfp.sfputilbase import SfpUtilBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") if sys.version_info[0] < 3: import commands @@ -19,6 +19,7 @@ except ImportError as e: smbus_present = 0 + class SfpUtil(SfpUtilBase): """Platform specific sfputil class""" _port_start = 1 @@ -31,13 +32,13 @@ class SfpUtil(SfpUtilBase): def __init__(self): os.system("modprobe i2c-dev") - if not os.path.exists("/sys/bus/i2c/devices/0-0050") : + if not os.path.exists("/sys/bus/i2c/devices/0-0050"): os.system("echo optoe2 0x50 > /sys/bus/i2c/devices/i2c-0/new_device") eeprom_path = '/sys/bus/i2c/devices/0-0050/eeprom' - #for x in range(self.port _start, self.port_end +1): + # for x in range(self.port _start, self.port_end +1): x = self.port_start - while(x=4: - offset=offset-4 - elif offset<4: - offset=offset+4 - bin_offset = 1<= 4: + offset = offset-4 + elif offset < 4: + offset = offset+4 + bin_offset = 1 << offset if port_num >= 0 and port_num <= 63: device_reg = 0x70 @@ -168,11 +169,10 @@ def read_porttab_mappings(self, porttabfile): bcm_port = str(port_pos_in_file) - if "index" in title: fp_port_index = int(line.split()[title.index("index")]) # Leave the old code for backward compatibility - #if len(line.split()) >= 4: + # if len(line.split()) >= 4: # fp_port_index = (line.split()[3]) # print(fp_port_index) else: @@ -223,9 +223,8 @@ def read_porttab_mappings(self, porttabfile): self.logical_to_physical = logical_to_physical self.physical_to_logical = physical_to_logical - - #print(self.logical_to_physical) - '''print("logical: " + self.logical) + # print(self.logical_to_physical) + '''print("logical: " + self.logical) print("logical to bcm: " + self.logical_to_bcm) print("logical to physical: " + self.logical_to_physical) print("physical to logical: " + self.physical_to_logical)''' @@ -245,7 +244,7 @@ def qsfp_ports(self): @property def port_to_eeprom_mapping(self): - return self._port_to_eeprom_mapping + return self._port_to_eeprom_mapping @property def get_transceiver_change_event(self): diff --git a/device/marvell/arm64-marvell_db98cx8580_32cd-r0/plugins/sfputil.py b/device/marvell/arm64-marvell_db98cx8580_32cd-r0/plugins/sfputil.py index 6dc6a0a8c897..b3d1ea371454 100644 --- a/device/marvell/arm64-marvell_db98cx8580_32cd-r0/plugins/sfputil.py +++ b/device/marvell/arm64-marvell_db98cx8580_32cd-r0/plugins/sfputil.py @@ -5,7 +5,7 @@ import re from sonic_sfp.sfputilbase import SfpUtilBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") if sys.version_info[0] < 3: import commands @@ -19,6 +19,7 @@ except ImportError as e: smbus_present = 0 + class SfpUtil(SfpUtilBase): """Platform specific sfputil class""" _port_start = 1 @@ -31,13 +32,13 @@ class SfpUtil(SfpUtilBase): def __init__(self): os.system("modprobe i2c-dev") - if not os.path.exists("/sys/bus/i2c/devices/0-0050") : + if not os.path.exists("/sys/bus/i2c/devices/0-0050"): os.system("echo optoe2 0x50 > /sys/bus/i2c/devices/i2c-0/new_device") eeprom_path = '/sys/bus/i2c/devices/0-0050/eeprom' - #for x in range(self.port _start, self.port_end +1): + # for x in range(self.port _start, self.port_end +1): x = self.port_start - while(x=4: - offset=offset-4 - elif offset<4: - offset=offset+4 - bin_offset = 1<= 4: + offset = offset-4 + elif offset < 4: + offset = offset+4 + bin_offset = 1 << offset if port_num >= 0 and port_num <= 63: device_reg = 0x70 @@ -174,11 +175,10 @@ def read_porttab_mappings(self, porttabfile): bcm_port = str(port_pos_in_file) - if "index" in title: fp_port_index = int(line.split()[title.index("index")]) # Leave the old code for backward compatibility - #if len(line.split()) >= 4: + # if len(line.split()) >= 4: # fp_port_index = (line.split()[3]) # print(fp_port_index) else: @@ -229,9 +229,8 @@ def read_porttab_mappings(self, porttabfile): self.logical_to_physical = logical_to_physical self.physical_to_logical = physical_to_logical - - #print(self.logical_to_physical) - '''print("logical: " + self.logical) + # print(self.logical_to_physical) + '''print("logical: " + self.logical) print("logical to bcm: " + self.logical_to_bcm) print("logical to physical: " + self.logical_to_physical) print("physical to logical: " + self.physical_to_logical)''' @@ -251,7 +250,7 @@ def qsfp_ports(self): @property def port_to_eeprom_mapping(self): - return self._port_to_eeprom_mapping + return self._port_to_eeprom_mapping @property def get_transceiver_change_event(self): diff --git a/device/marvell/x86_64-marvell_db98cx8580_16cd-r0/plugins/sfputil.py b/device/marvell/x86_64-marvell_db98cx8580_16cd-r0/plugins/sfputil.py index 193adf148ffc..4463e687e695 100644 --- a/device/marvell/x86_64-marvell_db98cx8580_16cd-r0/plugins/sfputil.py +++ b/device/marvell/x86_64-marvell_db98cx8580_16cd-r0/plugins/sfputil.py @@ -5,7 +5,7 @@ import re from sonic_sfp.sfputilbase import SfpUtilBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") if sys.version_info[0] < 3: import commands @@ -19,6 +19,7 @@ except ImportError as e: smbus_present = 0 + class SfpUtil(SfpUtilBase): """Platform specific sfputil class""" _port_start = 1 @@ -31,13 +32,13 @@ class SfpUtil(SfpUtilBase): def __init__(self): os.system("modprobe i2c-dev") - if not os.path.exists("/sys/bus/i2c/devices/0-0050") : + if not os.path.exists("/sys/bus/i2c/devices/0-0050"): os.system("echo optoe2 0x50 > /sys/bus/i2c/devices/i2c-0/new_device") eeprom_path = '/sys/bus/i2c/devices/0-0050/eeprom' - #for x in range(self.port _start, self.port_end +1): + # for x in range(self.port _start, self.port_end +1): x = self.port_start - while(x=4: - offset=offset-4 - elif offset<4: - offset=offset+4 - bin_offset = 1<= 4: + offset = offset-4 + elif offset < 4: + offset = offset+4 + bin_offset = 1 << offset if port_num >= 0 and port_num <= 63: device_reg = 0x70 @@ -168,11 +169,10 @@ def read_porttab_mappings(self, porttabfile): bcm_port = str(port_pos_in_file) - if "index" in title: fp_port_index = int(line.split()[title.index("index")]) # Leave the old code for backward compatibility - #if len(line.split()) >= 4: + # if len(line.split()) >= 4: # fp_port_index = (line.split()[3]) # print(fp_port_index) else: @@ -223,9 +223,8 @@ def read_porttab_mappings(self, porttabfile): self.logical_to_physical = logical_to_physical self.physical_to_logical = physical_to_logical - - #print(self.logical_to_physical) - '''print("logical: " + self.logical) + # print(self.logical_to_physical) + '''print("logical: " + self.logical) print("logical to bcm: " + self.logical_to_bcm) print("logical to physical: " + self.logical_to_physical) print("physical to logical: " + self.physical_to_logical)''' @@ -245,7 +244,7 @@ def qsfp_ports(self): @property def port_to_eeprom_mapping(self): - return self._port_to_eeprom_mapping + return self._port_to_eeprom_mapping @property def get_transceiver_change_event(self): diff --git a/device/marvell/x86_64-marvell_db98cx8580_32cd-r0/plugins/sfputil.py b/device/marvell/x86_64-marvell_db98cx8580_32cd-r0/plugins/sfputil.py index 6dc6a0a8c897..b3d1ea371454 100644 --- a/device/marvell/x86_64-marvell_db98cx8580_32cd-r0/plugins/sfputil.py +++ b/device/marvell/x86_64-marvell_db98cx8580_32cd-r0/plugins/sfputil.py @@ -5,7 +5,7 @@ import re from sonic_sfp.sfputilbase import SfpUtilBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") if sys.version_info[0] < 3: import commands @@ -19,6 +19,7 @@ except ImportError as e: smbus_present = 0 + class SfpUtil(SfpUtilBase): """Platform specific sfputil class""" _port_start = 1 @@ -31,13 +32,13 @@ class SfpUtil(SfpUtilBase): def __init__(self): os.system("modprobe i2c-dev") - if not os.path.exists("/sys/bus/i2c/devices/0-0050") : + if not os.path.exists("/sys/bus/i2c/devices/0-0050"): os.system("echo optoe2 0x50 > /sys/bus/i2c/devices/i2c-0/new_device") eeprom_path = '/sys/bus/i2c/devices/0-0050/eeprom' - #for x in range(self.port _start, self.port_end +1): + # for x in range(self.port _start, self.port_end +1): x = self.port_start - while(x=4: - offset=offset-4 - elif offset<4: - offset=offset+4 - bin_offset = 1<= 4: + offset = offset-4 + elif offset < 4: + offset = offset+4 + bin_offset = 1 << offset if port_num >= 0 and port_num <= 63: device_reg = 0x70 @@ -174,11 +175,10 @@ def read_porttab_mappings(self, porttabfile): bcm_port = str(port_pos_in_file) - if "index" in title: fp_port_index = int(line.split()[title.index("index")]) # Leave the old code for backward compatibility - #if len(line.split()) >= 4: + # if len(line.split()) >= 4: # fp_port_index = (line.split()[3]) # print(fp_port_index) else: @@ -229,9 +229,8 @@ def read_porttab_mappings(self, porttabfile): self.logical_to_physical = logical_to_physical self.physical_to_logical = physical_to_logical - - #print(self.logical_to_physical) - '''print("logical: " + self.logical) + # print(self.logical_to_physical) + '''print("logical: " + self.logical) print("logical to bcm: " + self.logical_to_bcm) print("logical to physical: " + self.logical_to_physical) print("physical to logical: " + self.physical_to_logical)''' @@ -251,7 +250,7 @@ def qsfp_ports(self): @property def port_to_eeprom_mapping(self): - return self._port_to_eeprom_mapping + return self._port_to_eeprom_mapping @property def get_transceiver_change_event(self): From 981c5af4a1c34ef8120d6a0e767b918c470b4880 Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Tue, 24 Nov 2020 01:22:32 +0000 Subject: [PATCH 21/24] Format remaining Python files wil autopep8 for consistency --- .../plugins/eeprom.py | 4 +- .../plugins/psuutil.py | 3 +- .../plugins/sfputil.py | 33 +- .../plugins/eeprom.py | 6 +- .../plugins/psuutil.py | 3 +- .../plugins/eeprom.py | 6 +- .../plugins/psuutil.py | 3 +- .../plugins/eeprom.py | 6 +- .../plugins/psuutil.py | 3 +- .../plugins/eeprom.py | 6 +- .../plugins/psuutil.py | 3 +- .../plugins/sfputil.py | 92 +-- .../plugins/eeprom.py | 6 +- .../plugins/psuutil.py | 3 +- .../plugins/sfputil.py | 200 +++---- .../plugins/eeprom.py | 6 +- .../plugins/psuutil.py | 3 +- .../plugins/sfputil.py | 98 ++-- .../plugins/eeprom.py | 4 +- .../plugins/psuutil.py | 27 +- .../sonic_platform/chassis.py | 2 +- .../sonic_platform/component.py | 1 + .../sonic_platform/fan.py | 11 +- .../sonic_platform/platform.py | 1 + .../plugins/eeprom.py | 6 +- .../plugins/sfputil.py | 70 +-- .../plugins/eeprom.py | 6 +- .../plugins/psuutil.py | 3 +- .../plugins/sfputil.py | 130 ++-- .../plugins/eeprom.py | 6 +- .../plugins/psuutil.py | 3 +- .../plugins/sfputil.py | 130 ++-- .../plugins/eeprom.py | 4 +- .../plugins/psuutil.py | 3 +- .../plugins/eeprom.py | 4 +- .../plugins/psuutil.py | 3 +- .../plugins/sfputil.py | 151 ++--- .../plugins/eeprom.py | 3 +- .../plugins/sfputil.py | 15 +- .../plugins/eeprom.py | 6 +- .../plugins/psuutil.py | 3 +- .../plugins/sfputil.py | 94 +-- .../plugins/eeprom.py | 6 +- .../plugins/psuutil.py | 3 +- .../plugins/sfputil.py | 92 +-- .../plugins/eeprom.py | 6 +- .../plugins/psuutil.py | 3 +- .../plugins/sfputil.py | 82 ++- .../plugins/eeprom.py | 6 +- .../plugins/psuutil.py | 3 +- .../plugins/sfputil.py | 103 ++-- .../plugins/eeprom.py | 4 +- .../plugins/psuutil.py | 3 +- .../plugins/eeprom.py | 18 +- .../plugins/psuutil.py | 3 +- .../plugins/sfputil.py | 150 ++--- .../plugins/eeprom.py | 4 +- .../plugins/led_control.py | 20 +- .../plugins/psuutil.py | 3 +- .../plugins/sfputil.py | 51 +- .../plugins/eeprom.py | 6 +- .../plugins/led_control.py | 193 +++--- .../plugins/psuutil.py | 3 +- .../plugins/sfputil.py | 15 +- .../plugins/eeprom.py | 6 +- .../plugins/psuutil.py | 3 +- .../plugins/sfputil.py | 16 +- .../x86_64-arista_common/platform_reboot | 8 +- .../plugins/pltfm_mgr_rpc/pltfm_mgr_rpc.py | 48 +- .../plugins/pltfm_mgr_rpc/ttypes.py | 63 +- .../plugins/sfputil.py | 8 +- .../x86_64-bcm_xlr-r0/plugins/eeprom.py | 4 +- .../x86_64-cel_e1031-r0/plugins/eeprom.py | 3 +- .../x86_64-cel_e1031-r0/plugins/sfputil.py | 21 +- .../x86_64-cel_midstone-r0/plugins/eeprom.py | 2 +- .../x86_64-cel_midstone-r0/plugins/psuutil.py | 5 +- .../x86_64-cel_seastone-r0/plugins/eeprom.py | 3 +- .../sonic_platform/sfp.py | 1 - .../plugins/eeprom.py | 3 +- .../plugins/psuutil.py | 21 +- .../plugins/sfputil.py | 1 - .../plugins/eeprom.py | 3 +- .../plugins/psuutil.py | 16 +- .../sonic_platform/chassis.py | 1 - .../sonic_platform/eeprom.py | 4 +- .../sonic_platform/fan.py | 2 +- .../sonic_platform/psu.py | 2 +- .../sonic_platform/thermal.py | 1 + .../plugins/eeprom.py | 2 +- .../plugins/led_control.py | 5 +- .../plugins/psuutil.py | 3 +- .../plugins/eeprom.py | 2 +- .../plugins/led_control.py | 5 +- .../plugins/psuutil.py | 3 +- .../plugins/eeprom.py | 2 +- .../plugins/led_control.py | 28 +- .../plugins/psuutil.py | 3 +- .../plugins/sfputil.py | 44 +- .../plugins/eeprom.py | 2 +- .../plugins/led_control.py | 25 +- .../plugins/psuutil.py | 3 +- .../plugins/sfputil.py | 44 +- .../plugins/eeprom.py | 9 +- .../plugins/psuutil.py | 16 +- .../plugins/eeprom.py | 4 +- .../plugins/psuutil.py | 13 +- .../plugins/sfputil.py | 120 ++-- .../plugins/eeprom.py | 4 +- .../plugins/psuutil.py | 13 +- .../plugins/sfputil.py | 120 ++-- .../plugins/eeprom.py | 4 +- .../plugins/psuutil.py | 13 +- .../plugins/sfputil.py | 124 ++-- device/common/pddf/plugins/eeprom.py | 4 +- device/common/pddf/plugins/fanutil.py | 38 +- device/common/pddf/plugins/psuutil.py | 67 ++- device/common/pddf/plugins/sfputil.py | 40 +- device/common/pddf/plugins/sysstatutil.py | 73 ++- device/common/pddf/plugins/thermalutil.py | 33 +- .../platform_reboot | 20 +- .../plugins/psuutil.py | 2 +- .../plugins/sfputil.py | 11 +- .../plugins/eeprom.py | 2 +- .../plugins/psuutil.py | 5 +- .../plugins/sfputil.py | 555 +++++++++--------- .../plugins/psuutil.py | 5 +- .../plugins/sfputil.py | 321 +++++----- .../plugins/psuutil.py | 48 +- .../plugins/psuutil.py | 3 +- .../plugins/eeprom.py | 2 +- .../plugins/psuutil.py | 4 +- .../plugins/eeprom.py | 2 +- .../plugins/psuutil.py | 3 +- .../plugins/sfputil.py | 216 +++---- .../plugins/psuutil.py | 43 +- .../plugins/sfputil.py | 114 ++-- .../x86_64-delta_ag5648-r0/plugins/psuutil.py | 10 +- .../plugins/psuutil.py | 12 +- .../plugins/psuutil.py | 9 +- .../x86_64-delta_ag9064-r0/plugins/psuutil.py | 8 +- .../x86_64-delta_agc032-r0/plugins/eeprom.py | 4 +- .../x86_64-delta_agc032-r0/plugins/psuutil.py | 14 +- .../x86_64-delta_agc032-r0/plugins/sfputil.py | 3 +- .../plugins/psuutil.py | 4 +- .../plugins/psuutil.py | 8 +- .../plugins/sfputil.py | 11 +- .../plugins/eeprom.py | 2 +- .../plugins/psuutil.py | 27 +- .../plugins/sfputil.py | 14 +- .../plugins/eeprom.py | 2 +- .../plugins/psuutil.py | 31 +- .../plugins/sfputil.py | 14 +- .../plugins/eeprom.py | 2 +- .../plugins/psuutil.py | 31 +- .../plugins/sfputil.py | 133 ++--- .../plugins/eeprom.py | 2 +- .../plugins/psuutil.py | 31 +- .../plugins/sfputil.py | 14 +- .../plugins/eeprom.py | 2 +- .../plugins/psuutil.py | 27 +- .../plugins/sfputil.py | 18 +- .../plugins/eeprom.py | 2 +- .../plugins/psuutil.py | 15 +- .../plugins/sfputil.py | 21 +- .../plugins/eeprom.py | 2 +- .../plugins/psuutil.py | 27 +- .../plugins/sfputil.py | 129 ++-- .../plugins/eeprom.py | 2 +- .../plugins/psuutil.py | 27 +- .../plugins/sfputil.py | 153 +++-- .../plugins/eeprom.py | 2 +- .../plugins/psuutil.py | 27 +- .../plugins/sfputil.py | 156 +++-- .../plugins/eeprom.py | 2 +- .../plugins/psuutil.py | 22 +- .../plugins/eeprom.py | 2 +- .../plugins/psuutil.py | 22 +- .../plugins/sfputil.py | 84 +-- .../plugins/eeprom.py | 2 +- .../plugins/psuutil.py | 23 +- .../plugins/sfputil.py | 131 +++-- .../plugins/eeprom.py | 2 +- .../plugins/psuutil.py | 22 +- .../plugins/eeprom.py | 2 +- .../plugins/psuutil.py | 26 +- .../plugins/eeprom.py | 2 +- .../plugins/psuutil.py | 22 +- .../plugins/eeprom.py | 2 +- .../plugins/eeprom.py | 19 +- .../plugins/led_control.py | 30 +- .../plugins/psuutil.py | 30 +- .../plugins/qfx5200_eeprom_data.py | 59 +- .../plugins/qfx5200_sfp_init.py | 6 +- .../plugins/eeprom.py | 5 +- .../plugins/psuutil.py | 3 +- .../plugins/qfx5210_eeprom_data.py | 57 +- .../plugins/eeprom.py | 2 +- .../plugins/eeprom.py | 2 +- .../plugins/eeprom.py | 2 +- .../plugins/psuutil.py | 66 ++- .../plugins/sfputil.py | 87 ++- .../plugins/eeprom.py | 2 +- .../plugins/eeprom.py | 2 +- .../plugins/eeprom.py | 6 +- .../plugins/sfputil.py | 71 ++- .../x86_64-mlnx_msn2010-r0/plugins/psuutil.py | 3 +- .../x86_64-mlnx_msn2100-r0/plugins/psuutil.py | 3 +- .../x86_64-mlnx_msn2700-r0/plugins/eeprom.py | 7 +- .../x86_64-mlnx_msn2700-r0/plugins/fanutil.py | 17 +- .../x86_64-mlnx_msn2700-r0/plugins/psuutil.py | 6 +- .../plugins/sfplpmget.py | 2 + .../plugins/sfplpmset.py | 16 +- .../x86_64-mlnx_msn2700-r0/plugins/sfputil.py | 96 +-- .../plugins/thermalutil.py | 274 ++++----- .../plugins/eeprom.py | 6 +- .../plugins/sfputil.py | 30 +- .../plugins/eeprom.py | 2 +- .../plugins/eeprom.py | 4 +- .../plugins/psuutil.py | 25 +- .../plugins/sfputil.py | 13 +- .../plugins/eeprom.py | 4 +- .../plugins/psuutil.py | 41 +- .../plugins/sfputil.py | 74 ++- .../plugins/eeprom.py | 4 +- .../plugins/psuutil.py | 3 +- .../plugins/sfputil.py | 66 +-- .../plugins/eeprom.py | 4 +- .../plugins/psuutil.py | 3 +- .../plugins/sfputil.py | 114 ++-- .../plugins/eeprom.py | 4 +- .../plugins/psuutil.py | 3 +- .../plugins/sfputil.py | 114 ++-- .../plugins/eeprom.py | 4 +- .../plugins/psuutil.py | 3 +- .../plugins/sfputil.py | 74 ++- .../x86_64-kvm_x86_64-r0/plugins/eeprom.py | 2 +- .../x86_64-wnc_osw1800-r0/plugins/eeprom.py | 3 +- 237 files changed, 3715 insertions(+), 3534 deletions(-) diff --git a/device/accton/x86_64-accton_as4630_54pe-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as4630_54pe-r0/plugins/eeprom.py index 5f7cee8d0b3e..3d0ff81ca574 100755 --- a/device/accton/x86_64-accton_as4630_54pe-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as4630_54pe-r0/plugins/eeprom.py @@ -9,10 +9,12 @@ from sonic_eeprom import eeprom_tlvinfo import subprocess except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/accton/x86_64-accton_as4630_54pe-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as4630_54pe-r0/plugins/psuutil.py index 3e0d2cea5f1e..92e08e23afd6 100755 --- a/device/accton/x86_64-accton_as4630_54pe-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as4630_54pe-r0/plugins/psuutil.py @@ -11,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/accton/x86_64-accton_as4630_54pe-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as4630_54pe-r0/plugins/sfputil.py index bd16ac366f14..fd660ccdc245 100755 --- a/device/accton/x86_64-accton_as4630_54pe-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as4630_54pe-r0/plugins/sfputil.py @@ -15,6 +15,7 @@ SFP_STATUS_INSERTED = '1' SFP_STATUS_REMOVED = '0' + class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" @@ -31,13 +32,13 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _port_to_i2c_mapping = { - 49: [18], - 50: [19], - 51: [20], - 52: [21], - 53: [22], - 54: [23], - } + 49: [18], + 50: [19], + 51: [20], + 52: [21], + 53: [22], + 54: [23], + } @property def port_start(self): @@ -70,7 +71,7 @@ def get_presence(self, port_num): present_path = self.BASE_CPLD_PATH + "module_present_" + str(port_num) self.__port_to_is_present = present_path - content="0" + content = "0" try: val_file = open(self.__port_to_is_present) content = val_file.readline().rstrip() @@ -78,7 +79,7 @@ def get_presence(self, port_num): except IOError as e: print("Error: unable to access file: %s" % str(e)) return False - + if content == "1": return True @@ -123,7 +124,7 @@ def set_low_power_mode(self, port_num, lpmode): try: eeprom = None if not self.get_presence(port_num): - return False # Port is not present, unable to set the eeprom + return False # Port is not present, unable to set the eeprom # Fill in write buffer # 0x3:Low Power Mode, 0x1:High Power Mode @@ -153,12 +154,13 @@ def _get_presence_bitmap(self): bits = [] for x in range(self.port_start, self.port_end+1): - bits.append(str(int(self.get_presence(x)))) + bits.append(str(int(self.get_presence(x)))) rev = "".join(bits[::-1]) - return int(rev,2) + return int(rev, 2) + + data = {'present': 0} - data = {'present':0} def get_transceiver_change_event(self, timeout=0): port_dict = {} @@ -167,7 +169,7 @@ def get_transceiver_change_event(self, timeout=0): else: cd_ms = timeout - #poll per second + # poll per second while cd_ms > 0: reg_value = self._get_presence_bitmap changed_ports = self.data['present'] ^ reg_value @@ -177,7 +179,7 @@ def get_transceiver_change_event(self, timeout=0): cd_ms = cd_ms - 1000 if changed_ports != 0: - for port in range (self.port_start, self.port_end+1): + for port in range(self.port_start, self.port_end+1): # Mask off the bit corresponding to our port mask = (1 << (port - self.port_start)) if changed_ports & mask: @@ -192,4 +194,3 @@ def get_transceiver_change_event(self, timeout=0): else: return True, {} return False, {} - diff --git a/device/accton/x86_64-accton_as5712_54x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as5712_54x-r0/plugins/eeprom.py index e7f6a39411d5..951384d5e37d 100644 --- a/device/accton/x86_64-accton_as5712_54x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as5712_54x-r0/plugins/eeprom.py @@ -9,13 +9,15 @@ from sonic_eeprom import eeprom_tlvinfo import subprocess except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom" - #Two i2c buses might get flipped order, check them both. + # Two i2c buses might get flipped order, check them both. if not os.path.exists(self.eeprom_path): self.eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/accton/x86_64-accton_as5712_54x-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as5712_54x-r0/plugins/psuutil.py index 33a27c378823..a07aebc96312 100755 --- a/device/accton/x86_64-accton_as5712_54x-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as5712_54x-r0/plugins/psuutil.py @@ -11,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/accton/x86_64-accton_as5812_54t-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as5812_54t-r0/plugins/eeprom.py index e7f6a39411d5..951384d5e37d 100644 --- a/device/accton/x86_64-accton_as5812_54t-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as5812_54t-r0/plugins/eeprom.py @@ -9,13 +9,15 @@ from sonic_eeprom import eeprom_tlvinfo import subprocess except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom" - #Two i2c buses might get flipped order, check them both. + # Two i2c buses might get flipped order, check them both. if not os.path.exists(self.eeprom_path): self.eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/accton/x86_64-accton_as5812_54t-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as5812_54t-r0/plugins/psuutil.py index 6193c5e900ea..b7a0a2fd66e3 100755 --- a/device/accton/x86_64-accton_as5812_54t-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as5812_54t-r0/plugins/psuutil.py @@ -11,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/accton/x86_64-accton_as5812_54x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as5812_54x-r0/plugins/eeprom.py index e7f6a39411d5..951384d5e37d 100644 --- a/device/accton/x86_64-accton_as5812_54x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as5812_54x-r0/plugins/eeprom.py @@ -9,13 +9,15 @@ from sonic_eeprom import eeprom_tlvinfo import subprocess except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom" - #Two i2c buses might get flipped order, check them both. + # Two i2c buses might get flipped order, check them both. if not os.path.exists(self.eeprom_path): self.eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/accton/x86_64-accton_as5812_54x-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as5812_54x-r0/plugins/psuutil.py index 33a27c378823..a07aebc96312 100755 --- a/device/accton/x86_64-accton_as5812_54x-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as5812_54x-r0/plugins/psuutil.py @@ -11,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/accton/x86_64-accton_as5835_54t-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as5835_54t-r0/plugins/eeprom.py index e7f6a39411d5..951384d5e37d 100644 --- a/device/accton/x86_64-accton_as5835_54t-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as5835_54t-r0/plugins/eeprom.py @@ -9,13 +9,15 @@ from sonic_eeprom import eeprom_tlvinfo import subprocess except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom" - #Two i2c buses might get flipped order, check them both. + # Two i2c buses might get flipped order, check them both. if not os.path.exists(self.eeprom_path): self.eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/accton/x86_64-accton_as5835_54t-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as5835_54t-r0/plugins/psuutil.py index 10303e4b9ad0..b22e01f5e9fc 100644 --- a/device/accton/x86_64-accton_as5835_54t-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as5835_54t-r0/plugins/psuutil.py @@ -11,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/accton/x86_64-accton_as5835_54t-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as5835_54t-r0/plugins/sfputil.py index 696442f9bd66..7c7e7f941a1f 100644 --- a/device/accton/x86_64-accton_as5835_54t-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as5835_54t-r0/plugins/sfputil.py @@ -14,6 +14,7 @@ SFP_STATUS_INSERTED = '1' SFP_STATUS_REMOVED = '0' + class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" @@ -23,31 +24,31 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _port_to_i2c_mapping = { - 49: 28, #QSFP49 - 50: 28, - 51: 28, - 52: 28, - 53: 29, #QSFP50 - 54: 29, - 55: 29, - 56: 29, - 57: 26, #QSFP51 - 58: 26, - 59: 26, - 60: 26, - 61: 30, #QSFP52 - 62: 30, - 63: 30, - 64: 30, - 65: 31, #QSFP53 - 66: 31, - 67: 31, - 68: 31, - 69: 27, #QSFP54 - 70: 27, - 71: 27, - 72: 27, - } + 49: 28, # QSFP49 + 50: 28, + 51: 28, + 52: 28, + 53: 29, # QSFP50 + 54: 29, + 55: 29, + 56: 29, + 57: 26, # QSFP51 + 58: 26, + 59: 26, + 60: 26, + 61: 30, # QSFP52 + 62: 30, + 63: 30, + 64: 30, + 65: 31, # QSFP53 + 66: 31, + 67: 31, + 68: 31, + 69: 27, # QSFP54 + 70: 27, + 71: 27, + 72: 27, + } @property def port_start(self): @@ -81,8 +82,8 @@ def __init__(self): SfpUtilBase.__init__(self) - # For port 49~54 are QSFP, here presumed they're all split to 4 lanes. + def get_cage_num(self, port_num): cage_num = port_num if (port_num >= self.PORT_START): @@ -100,7 +101,7 @@ def get_presence(self, port_num): path = "/sys/bus/i2c/devices/3-0062/module_present_{0}" port_ps = path.format(cage_num) - content="0" + content = "0" try: val_file = open(port_ps) content = val_file.readline().rstrip() @@ -150,13 +151,13 @@ def get_low_power_mode(self, port_num): eeprom.seek(93) lpmode = ord(eeprom.read(1)) - if not (lpmode & 0x1): # 'Power override' bit is 0 + if not (lpmode & 0x1): # 'Power override' bit is 0 return self.get_low_power_mode_cpld(port_num) else: if ((lpmode & 0x2) == 0x2): - return True # Low Power Mode if "Power set" bit is 1 + return True # Low Power Mode if "Power set" bit is 1 else: - return False # High Power Mode if "Power set" bit is 0 + return False # High Power Mode if "Power set" bit is 0 except IOError as e: print("Error: unable to open file: %s" % str(e)) return False @@ -173,10 +174,10 @@ def set_low_power_mode(self, port_num, lpmode): eeprom = None if not self.get_presence(port_num): - return False # Port is not present, unable to set the eeprom + return False # Port is not present, unable to set the eeprom # 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) @@ -206,7 +207,7 @@ def reset(self, port_num): print("Error: unable to open file: %s" % str(e)) return False - #toggle reset + # toggle reset reg_file.seek(0) reg_file.write('0') time.sleep(1) @@ -229,25 +230,26 @@ def _get_presence_bitmap(self): reg_file.close() rev = bitmap.split(" ") - rev.pop() # Remove the last useless character + rev.pop() # Remove the last useless character # Save port 49-54 into buffer tmp = rev.pop() # Insert port 1-48 - for i in range (0, 6): + for i in range(0, 6): rev.append(hex(0)[2:]) rev[i] = rev[i].zfill(2) # Expand port 49-54 - for i in range (0, 6): - val = (int(tmp,16) >> i) & 0x1 + for i in range(0, 6): + val = (int(tmp, 16) >> i) & 0x1 rev.append(hex(val)[2:]) rev = "".join(rev[::-1]) - return int(rev,16) + return int(rev, 16) + + data = {'valid': 0, 'present': 0} - data = {'valid':0, 'present':0} def get_transceiver_change_event(self, timeout=0): start_time = time.time() @@ -258,17 +260,17 @@ def get_transceiver_change_event(self, timeout=0): if timeout == 0: blocking = True elif timeout > 0: - timeout = timeout / float(1000) # Convert to secs + timeout = timeout / float(1000) # Convert to secs else: print("get_transceiver_change_event:Invalid timeout value", timeout) return False, {} end_time = start_time + timeout if start_time > end_time: - print('get_transceiver_change_event:' \ - 'time wrap / invalid timeout value', timeout) + print('get_transceiver_change_event:' + 'time wrap / invalid timeout value', timeout) - return False, {} # Time wrap or possibly incorrect timeout + return False, {} # Time wrap or possibly incorrect timeout while timeout >= 0: # Check for OIR events and return updated port_dict @@ -276,7 +278,7 @@ def get_transceiver_change_event(self, timeout=0): reg_value = self._get_presence_bitmap changed_ports = self.data['present'] ^ reg_value if changed_ports: - for port in range (self.port_start, self.port_end+1): + for port in range(self.port_start, self.port_end+1): # Mask off the bit corresponding to our port mask = (1 << (port - 1)) if changed_ports & mask: @@ -296,7 +298,7 @@ def get_transceiver_change_event(self, timeout=0): else: timeout = end_time - time.time() if timeout >= 1: - time.sleep(1) # We poll at 1 second granularity + time.sleep(1) # We poll at 1 second granularity else: if timeout > 0: time.sleep(timeout) diff --git a/device/accton/x86_64-accton_as5835_54x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as5835_54x-r0/plugins/eeprom.py index e7f6a39411d5..951384d5e37d 100644 --- a/device/accton/x86_64-accton_as5835_54x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as5835_54x-r0/plugins/eeprom.py @@ -9,13 +9,15 @@ from sonic_eeprom import eeprom_tlvinfo import subprocess except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom" - #Two i2c buses might get flipped order, check them both. + # Two i2c buses might get flipped order, check them both. if not os.path.exists(self.eeprom_path): self.eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/accton/x86_64-accton_as5835_54x-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as5835_54x-r0/plugins/psuutil.py index 10303e4b9ad0..b22e01f5e9fc 100644 --- a/device/accton/x86_64-accton_as5835_54x-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as5835_54x-r0/plugins/psuutil.py @@ -11,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/accton/x86_64-accton_as5835_54x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as5835_54x-r0/plugins/sfputil.py index 6fe4c2b21a11..b18b15f3e68c 100644 --- a/device/accton/x86_64-accton_as5835_54x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as5835_54x-r0/plugins/sfputil.py @@ -14,6 +14,7 @@ SFP_STATUS_INSERTED = '1' SFP_STATUS_REMOVED = '0' + class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" @@ -30,84 +31,84 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _cpld_mapping = { - 0: "3-0060", - 1: "3-0061", - 2: "3-0062", - } + 0: "3-0060", + 1: "3-0061", + 2: "3-0062", + } _port_to_i2c_mapping = { - 1: 42, - 2: 43, - 3: 44, - 4: 45, - 5: 46, - 6: 47, - 7: 48, - 8: 49, - 9: 50, - 10: 51, - 11: 52, - 12: 53, - 13: 54, - 14: 55, - 15: 56, - 16: 57, - 17: 58, - 18: 59, - 19: 60, - 20: 61, - 21: 62, - 22: 63, - 23: 64, - 24: 65, - 25: 66, - 26: 67, - 27: 68, - 28: 69, - 29: 70, - 30: 71, - 31: 72, - 32: 73, - 33: 74, - 34: 75, - 35: 76, - 36: 77, - 37: 78, - 38: 79, - 39: 80, - 40: 81, - 41: 82, - 42: 83, - 43: 84, - 44: 85, - 45: 86, - 46: 87, - 47: 88, - 48: 89, - 49: 28, #QSFP49 - 50: 28, - 51: 28, - 52: 28, - 53: 29, #QSFP50 - 54: 29, - 55: 29, - 56: 29, - 57: 26, #QSFP51 - 58: 26, - 59: 26, - 60: 26, - 61: 30, #QSFP52 - 62: 30, - 63: 30, - 64: 30, - 65: 31, #QSFP53 - 66: 31, - 67: 31, - 68: 31, - 69: 27, #QSFP54 - 70: 27, - 71: 27, - 72: 27, - } + 1: 42, + 2: 43, + 3: 44, + 4: 45, + 5: 46, + 6: 47, + 7: 48, + 8: 49, + 9: 50, + 10: 51, + 11: 52, + 12: 53, + 13: 54, + 14: 55, + 15: 56, + 16: 57, + 17: 58, + 18: 59, + 19: 60, + 20: 61, + 21: 62, + 22: 63, + 23: 64, + 24: 65, + 25: 66, + 26: 67, + 27: 68, + 28: 69, + 29: 70, + 30: 71, + 31: 72, + 32: 73, + 33: 74, + 34: 75, + 35: 76, + 36: 77, + 37: 78, + 38: 79, + 39: 80, + 40: 81, + 41: 82, + 42: 83, + 43: 84, + 44: 85, + 45: 86, + 46: 87, + 47: 88, + 48: 89, + 49: 28, # QSFP49 + 50: 28, + 51: 28, + 52: 28, + 53: 29, # QSFP50 + 54: 29, + 55: 29, + 56: 29, + 57: 26, # QSFP51 + 58: 26, + 59: 26, + 60: 26, + 61: 30, # QSFP52 + 62: 30, + 63: 30, + 64: 30, + 65: 31, # QSFP53 + 66: 31, + 67: 31, + 68: 31, + 69: 27, # QSFP54 + 70: 27, + 71: 27, + 72: 27, + } @property def port_start(self): @@ -141,8 +142,8 @@ def __init__(self): SfpUtilBase.__init__(self) - # For port 49~54 are QSFP, here presumed they're all split to 4 lanes. + def get_cage_num(self, port_num): cage_num = port_num if (port_num >= self.QSFP_PORT_START): @@ -220,13 +221,13 @@ def get_low_power_mode(self, port_num): eeprom.seek(93) lpmode = ord(eeprom.read(1)) - if not (lpmode & 0x1): # 'Power override' bit is 0 + if not (lpmode & 0x1): # 'Power override' bit is 0 return self.get_low_power_mode_cpld(port_num) else: if ((lpmode & 0x2) == 0x2): - return True # Low Power Mode if "Power set" bit is 1 + return True # Low Power Mode if "Power set" bit is 1 else: - return False # High Power Mode if "Power set" bit is 0 + return False # High Power Mode if "Power set" bit is 0 except IOError as e: print("Error: unable to open file: %s" % str(e)) return False @@ -243,10 +244,10 @@ def set_low_power_mode(self, port_num, lpmode): eeprom = None if not self.get_presence(port_num): - return False # Port is not present, unable to set the eeprom + return False # Port is not present, unable to set the eeprom # 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) @@ -278,7 +279,7 @@ def reset(self, port_num): print("Error: unable to open file: %s" % str(e)) return False - #toggle reset + # toggle reset reg_file.seek(0) reg_file.write('0') time.sleep(1) @@ -306,25 +307,26 @@ def _get_presence_bitmap(self): reg_file.close() rev = bitmap.split(" ") - rev.pop() # Remove the last useless character + rev.pop() # Remove the last useless character # Convert bitmap into continuously port order - rev[4] = hex((int(rev[4],16) | ((int(rev[5],16) & 0x3) << 6)))[2:] # Port 33-40 - rev[5] = hex((int(rev[5],16) >> 2) | ((int(rev[6],16) & 0x3) << 6))[2:] # Port 41-48 + rev[4] = hex((int(rev[4], 16) | ((int(rev[5], 16) & 0x3) << 6)))[2:] # Port 33-40 + rev[5] = hex((int(rev[5], 16) >> 2) | ((int(rev[6], 16) & 0x3) << 6))[2:] # Port 41-48 # Expand port 49-54 tmp = rev.pop() - for i in range (2, 8): - val = (int(tmp,16) >> i) & 0x1 + for i in range(2, 8): + val = (int(tmp, 16) >> i) & 0x1 rev.append(hex(val)[2:]) - for i in range (0,6): + for i in range(0, 6): rev[i] = rev[i].zfill(2) rev = "".join(rev[::-1]) - return int(rev,16) + return int(rev, 16) + + data = {'valid': 0, 'present': 0} - data = {'valid':0, 'present':0} def get_transceiver_change_event(self, timeout=0): start_time = time.time() @@ -335,17 +337,17 @@ def get_transceiver_change_event(self, timeout=0): if timeout == 0: blocking = True elif timeout > 0: - timeout = timeout / float(1000) # Convert to secs + timeout = timeout / float(1000) # Convert to secs else: print("get_transceiver_change_event:Invalid timeout value", timeout) return False, {} end_time = start_time + timeout if start_time > end_time: - print('get_transceiver_change_event:' \ - 'time wrap / invalid timeout value', timeout) + print('get_transceiver_change_event:' + 'time wrap / invalid timeout value', timeout) - return False, {} # Time wrap or possibly incorrect timeout + return False, {} # Time wrap or possibly incorrect timeout while timeout >= 0: # Check for OIR events and return updated port_dict @@ -353,7 +355,7 @@ def get_transceiver_change_event(self, timeout=0): reg_value = self._get_presence_bitmap changed_ports = self.data['present'] ^ reg_value if changed_ports: - for port in range (self.port_start, self.port_end+1): + for port in range(self.port_start, self.port_end+1): # Mask off the bit corresponding to our port mask = (1 << (port - 1)) if changed_ports & mask: @@ -373,12 +375,10 @@ def get_transceiver_change_event(self, timeout=0): else: timeout = end_time - time.time() if timeout >= 1: - time.sleep(1) # We poll at 1 second granularity + time.sleep(1) # We poll at 1 second granularity else: if timeout > 0: time.sleep(timeout) return True, {} print("get_transceiver_change_event: Should not reach here.") return False, {} - - diff --git a/device/accton/x86_64-accton_as6712_32x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as6712_32x-r0/plugins/eeprom.py index 5c409f60faf0..bf7f2e1f3aec 100644 --- a/device/accton/x86_64-accton_as6712_32x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as6712_32x-r0/plugins/eeprom.py @@ -8,13 +8,15 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom" - #Two i2c buses might get flipped order, check them both. + # Two i2c buses might get flipped order, check them both. if not os.path.exists(self.eeprom_path): self.eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/accton/x86_64-accton_as6712_32x-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as6712_32x-r0/plugins/psuutil.py index d72809288e5c..110c836004c8 100644 --- a/device/accton/x86_64-accton_as6712_32x-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as6712_32x-r0/plugins/psuutil.py @@ -11,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/accton/x86_64-accton_as6712_32x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as6712_32x-r0/plugins/sfputil.py index 744fc13b1b74..28c9010abf56 100644 --- a/device/accton/x86_64-accton_as6712_32x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as6712_32x-r0/plugins/sfputil.py @@ -12,7 +12,7 @@ except ImportError as e: raise ImportError("%s - required module not found" % str(e)) -#from xcvrd +# from xcvrd SFP_STATUS_INSERTED = '1' SFP_STATUS_REMOVED = '0' @@ -36,39 +36,39 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _port_to_i2c_mapping = { - 1: [1, 2], - 2: [2, 3], - 3: [3, 4], - 4: [4, 5], - 5: [5, 6], - 6: [6, 7], - 7: [7, 8], - 8: [8, 9], - 9: [9, 10], - 10: [10, 11], - 11: [11, 12], - 12: [12, 13], - 13: [13, 14], - 14: [14, 15], - 15: [15, 16], - 16: [16, 17], - 17: [17, 18], - 18: [18, 19], - 19: [19, 20], - 20: [20, 21], - 21: [21, 22], - 22: [22, 23], - 23: [23, 24], - 24: [24, 25], - 25: [25, 26], - 26: [26, 27], - 27: [27, 28], - 28: [28, 29], - 29: [29, 30], - 30: [30, 31], - 31: [31, 32], - 32: [32, 33], - } + 1: [1, 2], + 2: [2, 3], + 3: [3, 4], + 4: [4, 5], + 5: [5, 6], + 6: [6, 7], + 7: [7, 8], + 8: [8, 9], + 9: [9, 10], + 10: [10, 11], + 11: [11, 12], + 12: [12, 13], + 13: [13, 14], + 14: [14, 15], + 15: [15, 16], + 16: [16, 17], + 17: [17, 18], + 18: [18, 19], + 19: [19, 20], + 20: [20, 21], + 21: [21, 22], + 22: [22, 23], + 23: [23, 24], + 24: [24, 25], + 25: [25, 26], + 26: [26, 27], + 27: [27, 28], + 28: [28, 29], + 29: [29, 30], + 30: [30, 31], + 31: [31, 32], + 32: [32, 33], + } @property def port_start(self): @@ -100,7 +100,7 @@ def __init__(self): for x in range(self.port_start, self.port_end+1): self.port_to_eeprom_mapping[x] = eeprom_path.format( self._port_to_i2c_mapping[x][1] - ) + ) SfpUtilBase.__init__(self) def get_cpld_dev_path(self, port_num): @@ -109,7 +109,7 @@ def get_cpld_dev_path(self, port_num): else: cpld_num = 1 - #cpld can be at either bus 0 or bus 1. + # cpld can be at either bus 0 or bus 1. cpld_path = self.I2C_DEV_PATH + str(0) + self.CPLD_ADDRESS[cpld_num] if not os.path.exists(cpld_path): cpld_path = self.I2C_DEV_PATH + str(1) + self.CPLD_ADDRESS[cpld_num] @@ -120,14 +120,13 @@ def get_presence(self, port_num): if port_num < self.port_start or port_num > self.port_end: return False - cpld_path = self.get_cpld_dev_path(port_num) present_path = cpld_path + "/module_present_" present_path += str(self._port_to_i2c_mapping[port_num][0]) self.__port_to_is_present = present_path - content="0" + content = "0" try: val_file = open(self.__port_to_is_present) content = val_file.readline().rstrip() @@ -149,7 +148,7 @@ def get_low_power_mode_cpld(self, port_num): _path = cpld_path + "/module_lp_mode_" _path += str(self._port_to_i2c_mapping[port_num][0]) - content="0" + content = "0" try: reg_file = open(_path) content = reg_file.readline().rstrip() @@ -177,13 +176,13 @@ def get_low_power_mode(self, port_num): eeprom.seek(93) lpmode = ord(eeprom.read(1)) - if not (lpmode & 0x1): # 'Power override' bit is 0 + if not (lpmode & 0x1): # 'Power override' bit is 0 return self.get_low_power_mode_cpld(port_num) else: if ((lpmode & 0x2) == 0x2): - return True # Low Power Mode if "Power set" bit is 1 + return True # Low Power Mode if "Power set" bit is 1 else: - return False # High Power Mode if "Power set" bit is 0 + return False # High Power Mode if "Power set" bit is 0 except IOError as e: print("Error: unable to open file: %s" % str(e)) return False @@ -200,10 +199,10 @@ def set_low_power_mode(self, port_num, lpmode): eeprom = None if not self.get_presence(port_num): - return False # Port is not present, unable to set the eeprom + return False # Port is not present, unable to set the eeprom # 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) @@ -265,10 +264,10 @@ def get_transceiver_status(self): rev = bitmap.split(" ") rev = "".join(rev[::-1]) - return int(rev,16) + return int(rev, 16) + data = {'valid': 0, 'last': 0, 'present': 0} - data = {'valid':0, 'last':0, 'present':0} def get_transceiver_change_event(self, timeout=2000): now = time.time() port_dict = {} @@ -276,8 +275,7 @@ def get_transceiver_change_event(self, timeout=2000): if timeout < 1000: timeout = 1000 - timeout = (timeout) / float(1000) # Convert to secs - + timeout = (timeout) / float(1000) # Convert to secs if now < (self.data['last'] + timeout) and self.data['valid']: return True, {} @@ -285,7 +283,7 @@ def get_transceiver_change_event(self, timeout=2000): reg_value = self.get_transceiver_status changed_ports = self.data['present'] ^ reg_value if changed_ports: - for port in range (self.port_start, self.port_end+1): + for port in range(self.port_start, self.port_end+1): # Mask off the bit corresponding to our port fp_port = self._port_to_i2c_mapping[port][0] mask = (1 << (fp_port - 1)) @@ -305,5 +303,3 @@ def get_transceiver_change_event(self, timeout=2000): else: return True, {} return False, {} - - diff --git a/device/accton/x86_64-accton_as7116_54x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as7116_54x-r0/plugins/eeprom.py index 1183e929ea01..4241483d68eb 100644 --- a/device/accton/x86_64-accton_as7116_54x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as7116_54x-r0/plugins/eeprom.py @@ -9,10 +9,12 @@ from sonic_eeprom import eeprom_tlvinfo import subprocess except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/0-0056/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/accton/x86_64-accton_as7116_54x-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as7116_54x-r0/plugins/psuutil.py index 08fd2648f314..40e7257a6f02 100644 --- a/device/accton/x86_64-accton_as7116_54x-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as7116_54x-r0/plugins/psuutil.py @@ -20,12 +20,12 @@ class PsuUtil(PsuBase): def __init__(self): PsuBase.__init__(self) - - + # Get sysfs attribute + def get_attr_value(self, attr_path): - - retval = 'ERR' + + retval = 'ERR' if (not os.path.isfile(attr_path)): return retval @@ -55,16 +55,16 @@ def get_psu_status(self, index): faulty """ status = 0 - attr_file = 'psu_power_good' - attr_path = self.SYSFS_PSU_DIR[index-1] +'/' + attr_file - + attr_file = 'psu_power_good' + attr_path = self.SYSFS_PSU_DIR[index-1] + '/' + attr_file + attr_value = self.get_attr_value(attr_path) - + if (attr_value != 'ERR'): attr_value = int(attr_value, 16) # Check for PSU status if (attr_value == 1): - status = 1 + status = 1 return status @@ -77,16 +77,15 @@ def get_psu_presence(self, index): """ status = 0 psu_absent = 0 - attr_file ='psu_present' - attr_path = self.SYSFS_PSU_DIR[index-1] +'/' + attr_file - + attr_file = 'psu_present' + attr_path = self.SYSFS_PSU_DIR[index-1] + '/' + attr_file + attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): attr_value = int(attr_value, 16) # Check for PSU presence if (attr_value == 1): - status = 1 + status = 1 return status - diff --git a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/chassis.py b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/chassis.py index 38dcaf489f8b..86ae121c6c82 100644 --- a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/chassis.py +++ b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/chassis.py @@ -30,7 +30,7 @@ SFP_PORT_START = 0 QSFP_PORT_START = 48 SFP_PORT_END = 47 -QSFP_PORT_END=53 +QSFP_PORT_END = 53 HOST_REBOOT_CAUSE_PATH = "/host/reboot-cause/" PMON_REBOOT_CAUSE_PATH = "/usr/share/sonic/platform/api_files/reboot-cause/" REBOOT_CAUSE_FILE = "reboot-cause.txt" diff --git a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/component.py b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/component.py index 4371d9efb62b..59fe7898cfe3 100644 --- a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/component.py +++ b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/component.py @@ -16,6 +16,7 @@ BIOS_VERSION_PATH = "/sys/class/dmi/id/bios_version" + class Component(DeviceBase): """Platform-specific Component class""" diff --git a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/fan.py b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/fan.py index 4b49fb4910c6..421e7727ceeb 100644 --- a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/fan.py +++ b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/fan.py @@ -19,6 +19,7 @@ "FANTRAY-3", "FANTRAY-4", "FANTRAY-5"] FAN_NAME_LIST = ["front", "rear"] + class Fan(FanBase): """Platform-specific Fan class""" @@ -65,7 +66,7 @@ def get_direction(self): """ direction = self.FAN_DIRECTION_EXHAUST fan_direction_file = (FAN_PATH + - self.fan_direction.format(self.fan_tray_index+1)) + self.fan_direction.format(self.fan_tray_index+1)) raw = self.__read_txt_file(fan_direction_file).strip('\r\n') direction = self.FAN_DIRECTION_INTAKE if str( raw).upper() == "1" else self.FAN_DIRECTION_EXHAUST @@ -82,7 +83,7 @@ def get_speed(self): speed = 0 if self.get_presence(): fan_speed_file = (FAN_PATH + - self.fan_speed_rpm.format(self.fan_tray_index+1,FAN_NAME_LIST[self.fan_index])) + self.fan_speed_rpm.format(self.fan_tray_index+1, FAN_NAME_LIST[self.fan_index])) speed = self.__read_txt_file(fan_speed_file).strip('\r\n') return int(speed) @@ -96,9 +97,9 @@ def get_target_speed(self): """ target = 0 if self.get_presence(): - fan_speed_file=(FAN_PATH + - self.fan_speed_rpm.format(self.fan_tray_index+1, FAN_NAME_LIST[self.fan_index])) - target=self.__read_txt_file(fan_speed_file).strip('\r\n') + fan_speed_file = (FAN_PATH + + self.fan_speed_rpm.format(self.fan_tray_index+1, FAN_NAME_LIST[self.fan_index])) + target = self.__read_txt_file(fan_speed_file).strip('\r\n') return target diff --git a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/platform.py b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/platform.py index 768a9ebad5e6..6e1a90132acc 100644 --- a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/platform.py +++ b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/platform.py @@ -10,6 +10,7 @@ except ImportError as e: raise ImportError(str(e) + "- required module not found") + class Platform(PlatformBase): """Platform-specific Platform class""" diff --git a/device/accton/x86_64-accton_as7212_54x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as7212_54x-r0/plugins/eeprom.py index e7f6a39411d5..951384d5e37d 100755 --- a/device/accton/x86_64-accton_as7212_54x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as7212_54x-r0/plugins/eeprom.py @@ -9,13 +9,15 @@ from sonic_eeprom import eeprom_tlvinfo import subprocess except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom" - #Two i2c buses might get flipped order, check them both. + # Two i2c buses might get flipped order, check them both. if not os.path.exists(self.eeprom_path): self.eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/accton/x86_64-accton_as7212_54x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7212_54x-r0/plugins/sfputil.py index fc0765f7ffcc..47e1f9350aff 100755 --- a/device/accton/x86_64-accton_as7212_54x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7212_54x-r0/plugins/sfputil.py @@ -2,7 +2,7 @@ import time from sonic_sfp.sfputilbase import SfpUtilBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class sfputil(SfpUtilBase): @@ -14,38 +14,38 @@ class sfputil(SfpUtilBase): port_to_eeprom_mapping = {} port_to_i2c_mapping = { - 9 : 18, - 10 : 19, - 11 : 20, - 12 : 21, - 1 : 22, - 2 : 23, - 3 : 24, - 4 : 25, - 6 : 26, - 5 : 27, - 8 : 28, - 7 : 29, - 13 : 30, - 14 : 31, - 15 : 32, - 16 : 33, - 17 : 34, - 18 : 35, - 19 : 36, - 20 : 37, - 25 : 38, - 26 : 39, - 27 : 40, - 28 : 41, - 29 : 42, - 30 : 43, - 31 : 44, - 32 : 45, - 21 : 46, - 22 : 47, - 23 : 48, - 24 : 49, + 9: 18, + 10: 19, + 11: 20, + 12: 21, + 1: 22, + 2: 23, + 3: 24, + 4: 25, + 6: 26, + 5: 27, + 8: 28, + 7: 29, + 13: 30, + 14: 31, + 15: 32, + 16: 33, + 17: 34, + 18: 35, + 19: 36, + 20: 37, + 25: 38, + 26: 39, + 27: 40, + 28: 41, + 29: 42, + 30: 43, + 31: 44, + 32: 45, + 21: 46, + 22: 47, + 23: 48, + 24: 49, } _qsfp_ports = list(range(0, ports_in_block + 1)) @@ -72,7 +72,7 @@ def reset(self, port_num): print("Error: unable to open file: %s" % str(e)) return False - #toggle reset + # toggle reset reg_file.seek(0) reg_file.write('1') time.sleep(1) @@ -123,7 +123,7 @@ def qsfp_ports(self): @property def port_to_eeprom_mapping(self): - return self._port_to_eeprom_mapping + return self._port_to_eeprom_mapping def get_transceiver_change_event(self): """ diff --git a/device/accton/x86_64-accton_as7312_54x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as7312_54x-r0/plugins/eeprom.py index e7f6a39411d5..951384d5e37d 100644 --- a/device/accton/x86_64-accton_as7312_54x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as7312_54x-r0/plugins/eeprom.py @@ -9,13 +9,15 @@ from sonic_eeprom import eeprom_tlvinfo import subprocess except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom" - #Two i2c buses might get flipped order, check them both. + # Two i2c buses might get flipped order, check them both. if not os.path.exists(self.eeprom_path): self.eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/accton/x86_64-accton_as7312_54x-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as7312_54x-r0/plugins/psuutil.py index de0ae8504e6e..a47dfcab7e94 100644 --- a/device/accton/x86_64-accton_as7312_54x-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as7312_54x-r0/plugins/psuutil.py @@ -11,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/accton/x86_64-accton_as7312_54x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7312_54x-r0/plugins/sfputil.py index 69d3d25b061e..8f0818305f7f 100644 --- a/device/accton/x86_64-accton_as7312_54x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7312_54x-r0/plugins/sfputil.py @@ -28,66 +28,66 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _cpld_mapping = { - 0: "4-0060", - 1: "5-0062", - 2: "6-0064", - } + 0: "4-0060", + 1: "5-0062", + 2: "6-0064", + } _port_to_i2c_mapping = { - 1: 18, - 2: 19, - 3: 20, - 4: 21, - 5: 22, - 6: 23, - 7: 24, - 8: 25, - 9: 26, - 10: 27, - 11: 28, - 12: 29, - 13: 30, - 14: 31, - 15: 32, - 16: 33, - 17: 34, - 18: 35, - 19: 36, - 20: 37, - 21: 38, - 22: 39, - 23: 40, - 24: 41, - 25: 42, - 26: 43, - 27: 44, - 28: 45, - 29: 46, - 30: 47, - 31: 48, - 32: 49, - 33: 50, - 34: 51, - 35: 52, - 36: 53, - 37: 54, - 38: 55, - 39: 56, - 40: 57, - 41: 58, - 42: 59, - 43: 60, - 44: 61, - 45: 62, - 46: 63, - 47: 64, - 48: 65, - 49: 66, #QSFP49 - 50: 67, - 51: 68, - 52: 69, - 53: 70, - 54: 71, #QSFP54 - } + 1: 18, + 2: 19, + 3: 20, + 4: 21, + 5: 22, + 6: 23, + 7: 24, + 8: 25, + 9: 26, + 10: 27, + 11: 28, + 12: 29, + 13: 30, + 14: 31, + 15: 32, + 16: 33, + 17: 34, + 18: 35, + 19: 36, + 20: 37, + 21: 38, + 22: 39, + 23: 40, + 24: 41, + 25: 42, + 26: 43, + 27: 44, + 28: 45, + 29: 46, + 30: 47, + 31: 48, + 32: 49, + 33: 50, + 34: 51, + 35: 52, + 36: 53, + 37: 54, + 38: 55, + 39: 56, + 40: 57, + 41: 58, + 42: 59, + 43: 60, + 44: 61, + 45: 62, + 46: 63, + 47: 64, + 48: 65, + 49: 66, # QSFP49 + 50: 67, + 51: 68, + 52: 69, + 53: 70, + 54: 71, # QSFP54 + } @property def port_start(self): @@ -172,11 +172,11 @@ def get_low_power_mode(self, port_num): lpmode = ord(eeprom.read(1)) if ((lpmode & 0x3) == 0x3): - return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 + return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 else: - return 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 + return 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 except IOError as e: print("Error: unable to open file: %s" % str(e)) return False @@ -194,10 +194,10 @@ def set_low_power_mode(self, port_num, lpmode): eeprom = None if not self.get_presence(port_num): - return False # Port is not present, unable to set the eeprom + return False # Port is not present, unable to set the eeprom # 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) diff --git a/device/accton/x86_64-accton_as7312_54xs-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as7312_54xs-r0/plugins/eeprom.py index e7f6a39411d5..951384d5e37d 100644 --- a/device/accton/x86_64-accton_as7312_54xs-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as7312_54xs-r0/plugins/eeprom.py @@ -9,13 +9,15 @@ from sonic_eeprom import eeprom_tlvinfo import subprocess except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom" - #Two i2c buses might get flipped order, check them both. + # Two i2c buses might get flipped order, check them both. if not os.path.exists(self.eeprom_path): self.eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/accton/x86_64-accton_as7312_54xs-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as7312_54xs-r0/plugins/psuutil.py index de0ae8504e6e..a47dfcab7e94 100644 --- a/device/accton/x86_64-accton_as7312_54xs-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as7312_54xs-r0/plugins/psuutil.py @@ -11,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/accton/x86_64-accton_as7312_54xs-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7312_54xs-r0/plugins/sfputil.py index e5dac3001f5e..2cc51982fdc9 100644 --- a/device/accton/x86_64-accton_as7312_54xs-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7312_54xs-r0/plugins/sfputil.py @@ -28,66 +28,66 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _cpld_mapping = { - 0: "4-0060", - 1: "5-0062", - 2: "6-0064", - } + 0: "4-0060", + 1: "5-0062", + 2: "6-0064", + } _port_to_i2c_mapping = { - 1: 18, - 2: 19, - 3: 20, - 4: 21, - 5: 22, - 6: 23, - 7: 24, - 8: 25, - 9: 26, - 10: 27, - 11: 28, - 12: 29, - 13: 30, - 14: 31, - 15: 32, - 16: 33, - 17: 34, - 18: 35, - 19: 36, - 20: 37, - 21: 38, - 22: 39, - 23: 40, - 24: 41, - 25: 42, - 26: 43, - 27: 44, - 28: 45, - 29: 46, - 30: 47, - 31: 48, - 32: 49, - 33: 50, - 34: 51, - 35: 52, - 36: 53, - 37: 54, - 38: 55, - 39: 56, - 40: 57, - 41: 58, - 42: 59, - 43: 60, - 44: 61, - 45: 62, - 46: 63, - 47: 64, - 48: 65, - 49: 66, #QSFP49 - 50: 67, - 51: 68, - 52: 69, - 53: 70, - 54: 71, #QSFP54 - } + 1: 18, + 2: 19, + 3: 20, + 4: 21, + 5: 22, + 6: 23, + 7: 24, + 8: 25, + 9: 26, + 10: 27, + 11: 28, + 12: 29, + 13: 30, + 14: 31, + 15: 32, + 16: 33, + 17: 34, + 18: 35, + 19: 36, + 20: 37, + 21: 38, + 22: 39, + 23: 40, + 24: 41, + 25: 42, + 26: 43, + 27: 44, + 28: 45, + 29: 46, + 30: 47, + 31: 48, + 32: 49, + 33: 50, + 34: 51, + 35: 52, + 36: 53, + 37: 54, + 38: 55, + 39: 56, + 40: 57, + 41: 58, + 42: 59, + 43: 60, + 44: 61, + 45: 62, + 46: 63, + 47: 64, + 48: 65, + 49: 66, # QSFP49 + 50: 67, + 51: 68, + 52: 69, + 53: 70, + 54: 71, # QSFP54 + } @property def port_start(self): @@ -173,11 +173,11 @@ def get_low_power_mode(self, port_num): lpmode = ord(eeprom.read(1)) if ((lpmode & 0x3) == 0x3): - return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 + return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 else: - return 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 + return 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 except IOError as e: print("Error: unable to open file: %s" % str(e)) return False @@ -195,10 +195,10 @@ def set_low_power_mode(self, port_num, lpmode): eeprom = None if not self.get_presence(port_num): - return False # Port is not present, unable to set the eeprom + return False # Port is not present, unable to set the eeprom # 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) diff --git a/device/accton/x86_64-accton_as7315_27xb-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as7315_27xb-r0/plugins/eeprom.py index 414249503088..6f7ad9ef091d 100644 --- a/device/accton/x86_64-accton_as7315_27xb-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as7315_27xb-r0/plugins/eeprom.py @@ -9,10 +9,12 @@ from sonic_eeprom import eeprom_tlvinfo import subprocess except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/4-0057/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/accton/x86_64-accton_as7315_27xb-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as7315_27xb-r0/plugins/psuutil.py index 171a181ec092..dbc0a1170251 100644 --- a/device/accton/x86_64-accton_as7315_27xb-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as7315_27xb-r0/plugins/psuutil.py @@ -11,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/accton/x86_64-accton_as7326_56x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as7326_56x-r0/plugins/eeprom.py index 1183e929ea01..4241483d68eb 100644 --- a/device/accton/x86_64-accton_as7326_56x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as7326_56x-r0/plugins/eeprom.py @@ -9,10 +9,12 @@ from sonic_eeprom import eeprom_tlvinfo import subprocess except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/0-0056/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/accton/x86_64-accton_as7326_56x-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as7326_56x-r0/plugins/psuutil.py index a682bfde3b01..c215bb896772 100644 --- a/device/accton/x86_64-accton_as7326_56x-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as7326_56x-r0/plugins/psuutil.py @@ -11,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/accton/x86_64-accton_as7326_56x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7326_56x-r0/plugins/sfputil.py index 32fd1354fe7c..4777bb0cda2f 100644 --- a/device/accton/x86_64-accton_as7326_56x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7326_56x-r0/plugins/sfputil.py @@ -11,10 +11,11 @@ except ImportError as e: raise ImportError("%s - required module not found" % str(e)) -#from xcvrd +# from xcvrd SFP_STATUS_REMOVED = '0' SFP_STATUS_INSERTED = '1' + class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" @@ -31,69 +32,69 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _cpld_mapping = { - 1: "12-0062", - 2: "18-0060", - 3: "19-0064", - } + 1: "12-0062", + 2: "18-0060", + 3: "19-0064", + } _port_to_i2c_mapping = { - 1: 42, - 2: 41, - 3: 44, - 4: 43, - 5: 47, - 6: 45, - 7: 46, - 8: 50, - 9: 48, - 10: 49, - 11: 52, - 12: 51, - 13: 53, - 14: 56, - 15: 55, - 16: 54, - 17: 58, - 18: 57, - 19: 60, - 20: 59, - 21: 61, - 22: 63, - 23: 62, - 24: 64, - 25: 66, - 26: 68, - 27: 65, - 28: 67, - 29: 69, - 30: 71, - 31: 72, - 32: 70, - 33: 74, - 34: 73, - 35: 76, - 36: 75, - 37: 77, - 38: 79, - 39: 78, - 40: 80, - 41: 81, - 42: 82, - 43: 84, - 44: 85, - 45: 83, - 46: 87, - 47: 88, - 48: 86, - 49: 25,#QSFP49 - 50: 26, - 51: 27, - 52: 28, - 53: 29, - 54: 30, - 55: 31, - 56: 32,#QSFP56 - } + 1: 42, + 2: 41, + 3: 44, + 4: 43, + 5: 47, + 6: 45, + 7: 46, + 8: 50, + 9: 48, + 10: 49, + 11: 52, + 12: 51, + 13: 53, + 14: 56, + 15: 55, + 16: 54, + 17: 58, + 18: 57, + 19: 60, + 20: 59, + 21: 61, + 22: 63, + 23: 62, + 24: 64, + 25: 66, + 26: 68, + 27: 65, + 28: 67, + 29: 69, + 30: 71, + 31: 72, + 32: 70, + 33: 74, + 34: 73, + 35: 76, + 36: 75, + 37: 77, + 38: 79, + 39: 78, + 40: 80, + 41: 81, + 42: 82, + 43: 84, + 44: 85, + 45: 83, + 46: 87, + 47: 88, + 48: 86, + 49: 25, # QSFP49 + 50: 26, + 51: 27, + 52: 28, + 53: 29, + 54: 30, + 55: 31, + 56: 32, # QSFP56 + } @property def port_start(self): @@ -145,7 +146,7 @@ def get_presence(self, port_num): path = "/sys/bus/i2c/devices/{0}/module_present_{1}" port_ps = path.format(cpld_ps, port_num) - content="0" + content = "0" try: val_file = open(port_ps) content = val_file.readline().rstrip() @@ -175,11 +176,11 @@ def get_low_power_mode(self, port_num): lpmode = ord(eeprom.read(1)) if ((lpmode & 0x3) == 0x3): - return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 + return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 else: - return 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 + return 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 except IOError as e: print("Error: unable to open file: %s" % str(e)) @@ -198,10 +199,10 @@ def set_low_power_mode(self, port_num, lpmode): eeprom = None if not self.get_presence(port_num): - return False # Port is not present, unable to set the eeprom + return False # Port is not present, unable to set the eeprom # 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) @@ -234,7 +235,7 @@ def reset(self, port_num): print("Error: unable to open file: %s" % str(e)) return False - #toggle reset + # toggle reset reg_file.seek(0) reg_file.write('1') time.sleep(1) @@ -243,11 +244,12 @@ def reset(self, port_num): reg_file.close() return True + @property def _get_present_bitmap(self): nodes = [] rev = [] - port_num = [30,26] + port_num = [30, 26] path = "/sys/bus/i2c/devices/{0}/module_present_all" cpld_i = self.get_cpld_num(self.port_start) @@ -273,7 +275,8 @@ def _get_present_bitmap(self): bitmaps = hex(int(bitmaps, 2)) return int(bitmaps, 0) - data = {'valid':0, 'last':0, 'present':0} + data = {'valid': 0, 'last': 0, 'present': 0} + def get_transceiver_change_event(self, timeout=2000): now = time.time() port_dict = {} @@ -281,7 +284,7 @@ def get_transceiver_change_event(self, timeout=2000): if timeout < 1000: timeout = 1000 - timeout = (timeout) / float(1000) # Convert to secs + timeout = (timeout) / float(1000) # Convert to secs if now < (self.data['last'] + timeout) and self.data['valid']: return True, {} @@ -289,7 +292,7 @@ def get_transceiver_change_event(self, timeout=2000): reg_value = self._get_present_bitmap changed_ports = self.data['present'] ^ reg_value if changed_ports: - for port in range (self.port_start, self.port_end+1): + for port in range(self.port_start, self.port_end+1): # Mask off the bit corresponding to our port mask = (1 << (port - 1)) if changed_ports & mask: diff --git a/device/accton/x86_64-accton_as7512_32x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as7512_32x-r0/plugins/eeprom.py index 6c4d1915337d..f2f0703f0a11 100644 --- a/device/accton/x86_64-accton_as7512_32x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as7512_32x-r0/plugins/eeprom.py @@ -18,7 +18,8 @@ from sonic_eeprom import eeprom_tlvinfo import subprocess except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/accton/x86_64-accton_as7512_32x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7512_32x-r0/plugins/sfputil.py index d5bfae40bdbf..d47d7073e674 100644 --- a/device/accton/x86_64-accton_as7512_32x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7512_32x-r0/plugins/sfputil.py @@ -6,7 +6,7 @@ from ctypes import create_string_buffer from sonic_sfp.sfputilbase import SfpUtilBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class SfpUtil(SfpUtilBase): @@ -16,7 +16,6 @@ class SfpUtil(SfpUtilBase): _port_end = 31 ports_in_block = 32 - _port_to_eeprom_mapping = {} _qsfp_ports = list(range(0, ports_in_block + 1)) @@ -93,11 +92,11 @@ def get_low_power_mode(self, port_num): lpmode = ord(eeprom.read(1)) if ((lpmode & 0x3) == 0x3): - return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 + return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 else: - return 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 + return 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 except IOError as e: print("Error: unable to open file: %s" % str(e)) return False @@ -115,10 +114,10 @@ def set_low_power_mode(self, port_num, lpmode): eeprom = None if not self.get_presence(port_num): - return False # Port is not present, unable to set the eeprom + return False # Port is not present, unable to set the eeprom # 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) diff --git a/device/accton/x86_64-accton_as7712_32x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as7712_32x-r0/plugins/eeprom.py index e7f6a39411d5..951384d5e37d 100644 --- a/device/accton/x86_64-accton_as7712_32x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as7712_32x-r0/plugins/eeprom.py @@ -9,13 +9,15 @@ from sonic_eeprom import eeprom_tlvinfo import subprocess except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom" - #Two i2c buses might get flipped order, check them both. + # Two i2c buses might get flipped order, check them both. if not os.path.exists(self.eeprom_path): self.eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/accton/x86_64-accton_as7712_32x-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as7712_32x-r0/plugins/psuutil.py index e5c8aab97ce0..a9133f8adccb 100644 --- a/device/accton/x86_64-accton_as7712_32x-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as7712_32x-r0/plugins/psuutil.py @@ -11,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/accton/x86_64-accton_as7712_32x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7712_32x-r0/plugins/sfputil.py index 93160d9ad249..c3d0306929ef 100644 --- a/device/accton/x86_64-accton_as7712_32x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7712_32x-r0/plugins/sfputil.py @@ -4,9 +4,9 @@ from ctypes import create_string_buffer from sonic_sfp.sfputilbase import SfpUtilBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") -#from xcvrd +# from xcvrd SFP_STATUS_INSERTED = '1' SFP_STATUS_REMOVED = '0' @@ -20,38 +20,38 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} port_to_i2c_mapping = { - 9 : 18, - 10 : 19, - 11 : 20, - 12 : 21, - 1 : 22, - 2 : 23, - 3 : 24, - 4 : 25, - 6 : 26, - 5 : 27, - 8 : 28, - 7 : 29, - 13 : 30, - 14 : 31, - 15 : 32, - 16 : 33, - 17 : 34, - 18 : 35, - 19 : 36, - 20 : 37, - 25 : 38, - 26 : 39, - 27 : 40, - 28 : 41, - 29 : 42, - 30 : 43, - 31 : 44, - 32 : 45, - 21 : 46, - 22 : 47, - 23 : 48, - 24 : 49, + 9: 18, + 10: 19, + 11: 20, + 12: 21, + 1: 22, + 2: 23, + 3: 24, + 4: 25, + 6: 26, + 5: 27, + 8: 28, + 7: 29, + 13: 30, + 14: 31, + 15: 32, + 16: 33, + 17: 34, + 18: 35, + 19: 36, + 20: 37, + 25: 38, + 26: 39, + 27: 40, + 28: 41, + 29: 42, + 30: 43, + 31: 44, + 32: 45, + 21: 46, + 22: 47, + 23: 48, + 24: 49, } _qsfp_ports = list(range(0, ports_in_block + 1)) @@ -77,7 +77,7 @@ def reset(self, port_num): print("Error: unable to open file: %s" % str(e)) return False - #toggle reset + # toggle reset reg_file.seek(0) reg_file.write('1') time.sleep(1) @@ -122,7 +122,7 @@ def qsfp_ports(self): @property def port_to_eeprom_mapping(self): - return self._port_to_eeprom_mapping + return self._port_to_eeprom_mapping def get_low_power_mode(self, port_num): # Check for invalid port_num @@ -140,11 +140,11 @@ def get_low_power_mode(self, port_num): lpmode = ord(eeprom.read(1)) if ((lpmode & 0x3) == 0x3): - return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 + return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 else: - return 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 + return 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 except IOError as e: print("Error: unable to open file: %s" % str(e)) return False @@ -162,10 +162,10 @@ def set_low_power_mode(self, port_num, lpmode): eeprom = None if not self.get_presence(port_num): - return False # Port is not present, unable to set the eeprom + return False # Port is not present, unable to set the eeprom # 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) @@ -202,9 +202,10 @@ def _get_all_presence(self): rev = bitmap.split(" ") rev = "".join(rev[::-1]) - return int(rev,16) + return int(rev, 16) + + data = {'valid': 0, 'last': 0, 'present': 0} - data = {'valid':0, 'last':0, 'present':0} def get_transceiver_change_event(self, timeout=2000): now = time.time() port_dict = {} @@ -212,7 +213,7 @@ def get_transceiver_change_event(self, timeout=2000): if timeout < 1000: timeout = 1000 - timeout = (timeout) / float(1000) # Convert to secs + timeout = (timeout) / float(1000) # Convert to secs if now < (self.data['last'] + timeout) and self.data['valid']: return True, {} @@ -220,7 +221,7 @@ def get_transceiver_change_event(self, timeout=2000): reg_value = self._get_all_presence changed_ports = self.data['present'] ^ reg_value if changed_ports: - for port in range (self.port_start, self.port_end+1): + for port in range(self.port_start, self.port_end+1): # Mask off the bit corresponding to our port mask = (1 << (port - 1)) if changed_ports & mask: @@ -237,4 +238,3 @@ def get_transceiver_change_event(self, timeout=2000): else: return True, {} return False, {} - diff --git a/device/accton/x86_64-accton_as7716_32x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as7716_32x-r0/plugins/eeprom.py index abb1cf9eb8bf..9e4e9970e9f5 100755 --- a/device/accton/x86_64-accton_as7716_32x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as7716_32x-r0/plugins/eeprom.py @@ -9,13 +9,15 @@ from sonic_eeprom import eeprom_tlvinfo import subprocess except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/1-0056/eeprom" - #Two i2c buses might get flipped order, check them both. + # Two i2c buses might get flipped order, check them both. if not os.path.exists(self.eeprom_path): self.eeprom_path = "/sys/bus/i2c/devices/0-0056/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/accton/x86_64-accton_as7716_32x-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as7716_32x-r0/plugins/psuutil.py index f34753f549a0..5c18e6f51b8e 100755 --- a/device/accton/x86_64-accton_as7716_32x-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as7716_32x-r0/plugins/psuutil.py @@ -11,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/accton/x86_64-accton_as7716_32x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7716_32x-r0/plugins/sfputil.py index 7944c623760d..79660136b33a 100755 --- a/device/accton/x86_64-accton_as7716_32x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7716_32x-r0/plugins/sfputil.py @@ -10,7 +10,7 @@ from sonic_sfp.sfputilbase import SfpUtilBase except ImportError as e: raise ImportError("%s - required module not found" % str(e)) -#from xcvrd +# from xcvrd SFP_STATUS_REMOVED = '0' SFP_STATUS_INSERTED = '1' @@ -30,39 +30,39 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _port_to_i2c_mapping = { - 1: 29, - 2: 30, - 3: 31, - 4: 32, - 5: 34, - 6: 33, - 7: 36, - 8: 35, - 9: 25, - 10: 26, - 11: 27, - 12: 28, - 13: 37, - 14: 38, - 15: 39, - 16: 40, - 17: 41, - 18: 42, - 19: 43, - 20: 44, - 21: 53, - 22: 54, - 23: 55, - 24: 56, - 25: 45, - 26: 46, - 27: 47, - 28: 48, - 29: 49, - 30: 50, - 31: 51, - 32: 52, - } + 1: 29, + 2: 30, + 3: 31, + 4: 32, + 5: 34, + 6: 33, + 7: 36, + 8: 35, + 9: 25, + 10: 26, + 11: 27, + 12: 28, + 13: 37, + 14: 38, + 15: 39, + 16: 40, + 17: 41, + 18: 42, + 19: 43, + 20: 44, + 21: 53, + 22: 54, + 23: 55, + 24: 56, + 25: 45, + 26: 46, + 27: 47, + 28: 48, + 29: 49, + 30: 50, + 31: 51, + 32: 52, + } @property def port_start(self): @@ -86,7 +86,7 @@ def __init__(self): for x in range(self.port_start, self.port_end+1): self.port_to_eeprom_mapping[x] = eeprom_path.format( self._port_to_i2c_mapping[x] - ) + ) SfpUtilBase.__init__(self) def get_presence(self, port_num): @@ -127,11 +127,11 @@ def get_low_power_mode(self, port_num): lpmode = ord(eeprom.read(1)) if ((lpmode & 0x3) == 0x3): - return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 + return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 else: - return 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 + return 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 except IOError as e: print("Error: unable to open file: %s" % str(e)) return False @@ -149,10 +149,10 @@ def set_low_power_mode(self, port_num, lpmode): eeprom = None if not self.get_presence(port_num): - return False # Port is not present, unable to set the eeprom + return False # Port is not present, unable to set the eeprom # 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) @@ -206,9 +206,10 @@ def _get_present_bitmap(self): rev = bitmap.split(" ") rev = "".join(rev[::-1]) - return int(rev,16) + return int(rev, 16) + + data = {'valid': 0, 'last': 0, 'present': 0} - data = {'valid':0, 'last':0, 'present':0} def get_transceiver_change_event(self, timeout=2000): now = time.time() port_dict = {} @@ -216,7 +217,7 @@ def get_transceiver_change_event(self, timeout=2000): if timeout < 1000: timeout = 1000 - timeout = (timeout) / float(1000) # Convert to secs + timeout = (timeout) / float(1000) # Convert to secs if now < (self.data['last'] + timeout) and self.data['valid']: return True, {} @@ -224,7 +225,7 @@ def get_transceiver_change_event(self, timeout=2000): reg_value = self._get_present_bitmap changed_ports = self.data['present'] ^ reg_value if changed_ports: - for port in range (self.port_start, self.port_end+1): + for port in range(self.port_start, self.port_end+1): # Mask off the bit corresponding to our port mask = (1 << (port - 1)) if changed_ports & mask: @@ -241,4 +242,3 @@ def get_transceiver_change_event(self, timeout=2000): else: return True, {} return False, {} - diff --git a/device/accton/x86_64-accton_as7716_32xb-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as7716_32xb-r0/plugins/eeprom.py index 34924aaed973..0982e699367a 100755 --- a/device/accton/x86_64-accton_as7716_32xb-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as7716_32xb-r0/plugins/eeprom.py @@ -9,13 +9,15 @@ from sonic_eeprom import eeprom_tlvinfo import subprocess except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/0-0056/eeprom" - #Two i2c buses might get flipped order, check them both. + # Two i2c buses might get flipped order, check them both. if not os.path.exists(self.eeprom_path): self.eeprom_path = "/sys/bus/i2c/devices/0-0056/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/accton/x86_64-accton_as7716_32xb-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as7716_32xb-r0/plugins/psuutil.py index e803a060e134..d4815ac85cec 100755 --- a/device/accton/x86_64-accton_as7716_32xb-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as7716_32xb-r0/plugins/psuutil.py @@ -11,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/accton/x86_64-accton_as7716_32xb-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7716_32xb-r0/plugins/sfputil.py index 18c04888630d..bedf33685e08 100755 --- a/device/accton/x86_64-accton_as7716_32xb-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7716_32xb-r0/plugins/sfputil.py @@ -6,7 +6,7 @@ try: import time import os - import sys, getopt + import sys import subprocess from sonic_sfp.sfputilbase import SfpUtilBase except ImportError as e: @@ -29,39 +29,39 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _port_to_i2c_mapping = { - 0: [1, 29], - 1: [2, 30], - 2: [3, 31], - 3: [4, 32], - 4: [5, 34], - 5: [6, 33], - 6: [7, 36], - 7: [8, 35], - 8: [9, 25], - 9: [10, 26], - 10: [11, 27], - 11: [12, 28], - 12: [14, 37], - 13: [15, 38], - 14: [16, 39], - 15: [17, 40], - 16: [18, 41], - 17: [19, 42], - 18: [20, 43], - 19: [21, 44], - 20: [22, 53], - 21: [23, 54], - 22: [24, 55], - 23: [25, 56], - 24: [26, 45], - 25: [27, 46], - 26: [28, 47], - 27: [29, 48], - 28: [30, 49], - 29: [31, 50], - 30: [32, 51], - 31: [33, 52], - } + 0: [1, 29], + 1: [2, 30], + 2: [3, 31], + 3: [4, 32], + 4: [5, 34], + 5: [6, 33], + 6: [7, 36], + 7: [8, 35], + 8: [9, 25], + 9: [10, 26], + 10: [11, 27], + 11: [12, 28], + 12: [14, 37], + 13: [15, 38], + 14: [16, 39], + 15: [17, 40], + 16: [18, 41], + 17: [19, 42], + 18: [20, 43], + 19: [21, 44], + 20: [22, 53], + 21: [23, 54], + 22: [24, 55], + 23: [25, 56], + 24: [26, 45], + 25: [27, 46], + 26: [28, 47], + 27: [29, 48], + 28: [30, 49], + 29: [31, 50], + 30: [32, 51], + 31: [33, 52], + } @property def port_start(self): @@ -107,21 +107,19 @@ def __init__(self): for x in range(0, self.port_end+1): self.port_to_eeprom_mapping[x] = eeprom_path.format( self._port_to_i2c_mapping[x][1] - ) + ) if(x < 9): - if(self.get_presence(x)==1): - self.port_to_eeprom_mapping[x] = self.BASE_I2C_PATH + "0-000" +str(x+1) + "/eeprom" + if(self.get_presence(x) == 1): + self.port_to_eeprom_mapping[x] = self.BASE_I2C_PATH + "0-000" + str(x+1) + "/eeprom" else: - if(self.get_presence(x)==1): - self.port_to_eeprom_mapping[x] = self.BASE_I2C_PATH + "0-00" +str(x+1)+ "/eeprom" + if(self.get_presence(x) == 1): + self.port_to_eeprom_mapping[x] = self.BASE_I2C_PATH + "0-00" + str(x+1) + "/eeprom" SfpUtilBase.__init__(self) - - def get_low_power_mode(self, port_num): - raise NotImplementedError + raise NotImplementedError def set_low_power_mode(self, port_num, lpmode): raise NotImplementedError diff --git a/device/accton/x86_64-accton_as7726_32x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as7726_32x-r0/plugins/eeprom.py index 1a411807e3ed..5ff41c3bac24 100755 --- a/device/accton/x86_64-accton_as7726_32x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as7726_32x-r0/plugins/eeprom.py @@ -9,13 +9,15 @@ from sonic_eeprom import eeprom_tlvinfo import subprocess except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/0-0056/eeprom" - #Two i2c buses might get flipped order, check them both. + # Two i2c buses might get flipped order, check them both. if not os.path.exists(self.eeprom_path): self.eeprom_path = "/sys/bus/i2c/devices/1-0056/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/accton/x86_64-accton_as7726_32x-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as7726_32x-r0/plugins/psuutil.py index 169feecc9adb..92b453784721 100755 --- a/device/accton/x86_64-accton_as7726_32x-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as7726_32x-r0/plugins/psuutil.py @@ -11,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/accton/x86_64-accton_as7726_32x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7726_32x-r0/plugins/sfputil.py index 64da760ad821..b3cf8a495184 100755 --- a/device/accton/x86_64-accton_as7726_32x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7726_32x-r0/plugins/sfputil.py @@ -11,7 +11,7 @@ except ImportError as e: raise ImportError("%s - required module not found" % str(e)) -#from xcvrd +# from xcvrd SFP_STATUS_INSERTED = '1' SFP_STATUS_REMOVED = '0' @@ -20,7 +20,7 @@ class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" PORT_START = 1 - PORT_END = 32 #34 cages actually, but last 2 are not at port_config.ini. + PORT_END = 32 # 34 cages actually, but last 2 are not at port_config.ini. PORTS_IN_BLOCK = 32 BASE_OOM_PATH = "/sys/bus/i2c/devices/{0}-0050/" @@ -31,41 +31,41 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _port_to_i2c_mapping = { - 1: 21, - 2: 22, - 3: 23, - 4: 24, - 5: 26, - 6: 25, - 7: 28, - 8: 27, - 9: 17, - 10: 18, - 11: 19, - 12: 20, - 13: 29, - 14: 30, - 15: 31, - 16: 32, - 17: 33, - 18: 34, - 19: 35, - 20: 36, - 21: 45, - 22: 46, - 23: 47, - 24: 48, - 25: 37, - 26: 38, - 27: 39, - 28: 40, - 29: 41, - 30: 42, - 31: 43, - 32: 44, - 33: 15, - 34: 16, - } + 1: 21, + 2: 22, + 3: 23, + 4: 24, + 5: 26, + 6: 25, + 7: 28, + 8: 27, + 9: 17, + 10: 18, + 11: 19, + 12: 20, + 13: 29, + 14: 30, + 15: 31, + 16: 32, + 17: 33, + 18: 34, + 19: 35, + 20: 36, + 21: 45, + 22: 46, + 23: 47, + 24: 48, + 25: 37, + 26: 38, + 27: 39, + 28: 40, + 29: 41, + 30: 42, + 31: 43, + 32: 44, + 33: 15, + 34: 16, + } @property def port_start(self): @@ -89,7 +89,7 @@ def __init__(self): for x in range(self.port_start, self.port_end+1): self.port_to_eeprom_mapping[x] = eeprom_path.format( self._port_to_i2c_mapping[x] - ) + ) SfpUtilBase.__init__(self) def get_presence(self, port_num): @@ -100,7 +100,7 @@ def get_presence(self, port_num): present_path = self.BASE_CPLD_PATH + "module_present_" + str(port_num) self.__port_to_is_present = present_path - content="0" + content = "0" try: val_file = open(self.__port_to_is_present) content = val_file.readline().rstrip() @@ -130,11 +130,11 @@ def get_low_power_mode(self, port_num): lpmode = ord(eeprom.read(1)) if ((lpmode & 0x3) == 0x3): - return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 + return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 else: - return 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 + return 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 except IOError as e: print("Error: unable to open file: %s" % str(e)) return False @@ -152,10 +152,10 @@ def set_low_power_mode(self, port_num, lpmode): eeprom = None if not self.get_presence(port_num): - return False # Port is not present, unable to set the eeprom + return False # Port is not present, unable to set the eeprom # 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) @@ -185,7 +185,7 @@ def reset(self, port_num): print("Error: unable to open file: %s" % str(e)) return False - #toggle reset + # toggle reset reg_file.seek(0) reg_file.write('1') time.sleep(1) @@ -215,9 +215,10 @@ def get_transceiver_status(self): rev = bitmap.split(" ") rev = "".join(rev[::-1]) - return int(rev,16) + return int(rev, 16) + + data = {'valid': 0, 'last': 0, 'present': 0} - data = {'valid':0, 'last':0, 'present':0} def get_transceiver_change_event(self, timeout=2000): now = time.time() port_dict = {} @@ -225,8 +226,7 @@ def get_transceiver_change_event(self, timeout=2000): if timeout < 1000: timeout = 1000 - timeout = (timeout) / float(1000) # Convert to secs - + timeout = (timeout) / float(1000) # Convert to secs if now < (self.data['last'] + timeout) and self.data['valid']: return True, {} @@ -234,7 +234,7 @@ def get_transceiver_change_event(self, timeout=2000): reg_value = self.get_transceiver_status changed_ports = self.data['present'] ^ reg_value if changed_ports: - for port in range (self.port_start, self.port_end+1): + for port in range(self.port_start, self.port_end+1): # Mask off the bit corresponding to our port fp_port = port mask = (1 << (fp_port - 1)) @@ -253,4 +253,3 @@ def get_transceiver_change_event(self, timeout=2000): else: return True, {} return False, {} - diff --git a/device/accton/x86_64-accton_as7816_64x-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as7816_64x-r0/plugins/eeprom.py index 1183e929ea01..4241483d68eb 100644 --- a/device/accton/x86_64-accton_as7816_64x-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as7816_64x-r0/plugins/eeprom.py @@ -9,10 +9,12 @@ from sonic_eeprom import eeprom_tlvinfo import subprocess except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/0-0056/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/accton/x86_64-accton_as7816_64x-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as7816_64x-r0/plugins/psuutil.py index 512127fa18fb..b05cf3e477ac 100755 --- a/device/accton/x86_64-accton_as7816_64x-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as7816_64x-r0/plugins/psuutil.py @@ -11,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/accton/x86_64-accton_as9716_32d-r0/plugins/eeprom.py b/device/accton/x86_64-accton_as9716_32d-r0/plugins/eeprom.py index 6cf20f4046d3..9031f2c60ece 100644 --- a/device/accton/x86_64-accton_as9716_32d-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_as9716_32d-r0/plugins/eeprom.py @@ -9,23 +9,25 @@ from sonic_eeprom import eeprom_tlvinfo import subprocess except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + def eeprom_check(): - filepath="/sys/bus/i2c/devices/0-0057/eeprom" + filepath = "/sys/bus/i2c/devices/0-0057/eeprom" if os.path.isfile(filepath): - return 1 #now board, 0x57 + return 1 # now board, 0x57 else: - return 0 #now board, 0x56 - + return 0 # now board, 0x56 + + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): - ret=eeprom_check() - if ret==1: + ret = eeprom_check() + if ret == 1: self.eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom" else: self.eeprom_path = "/sys/bus/i2c/devices/0-0056/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) - diff --git a/device/accton/x86_64-accton_as9716_32d-r0/plugins/psuutil.py b/device/accton/x86_64-accton_as9716_32d-r0/plugins/psuutil.py index 63ea48e2424b..ef49f262dca9 100644 --- a/device/accton/x86_64-accton_as9716_32d-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_as9716_32d-r0/plugins/psuutil.py @@ -11,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/accton/x86_64-accton_as9716_32d-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as9716_32d-r0/plugins/sfputil.py index 8a41a2bb576e..e75f849a7a41 100755 --- a/device/accton/x86_64-accton_as9716_32d-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as9716_32d-r0/plugins/sfputil.py @@ -6,7 +6,7 @@ try: import time import os - import sys, getopt + import sys from ctypes import create_string_buffer from sonic_sfp.sfputilbase import SfpUtilBase except ImportError as e: @@ -29,41 +29,41 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _port_to_i2c_mapping = { - 0: [1, 25], - 1: [2, 26], - 2: [3, 27], - 3: [4, 28], - 4: [5, 29], - 5: [6, 30], - 6: [7, 31], - 7: [8, 32], - 8: [9, 33], - 9: [10, 34], - 10: [11, 35], - 11: [12, 36], - 12: [13, 37], - 13: [14, 38], - 14: [15, 39], - 15: [16, 40], - 16: [17, 41], - 17: [18, 42], - 18: [19, 43], - 19: [20, 44], - 20: [21, 45], - 21: [22, 46], - 22: [23, 47], - 23: [24, 48], - 24: [25, 49], - 25: [26, 50], - 26: [27, 51], - 27: [28, 52], - 28: [29, 53], - 29: [30, 54], - 30: [31, 55], - 31: [32, 56], - 32: [33, 57], - 33: [34, 58], - } + 0: [1, 25], + 1: [2, 26], + 2: [3, 27], + 3: [4, 28], + 4: [5, 29], + 5: [6, 30], + 6: [7, 31], + 7: [8, 32], + 8: [9, 33], + 9: [10, 34], + 10: [11, 35], + 11: [12, 36], + 12: [13, 37], + 13: [14, 38], + 14: [15, 39], + 15: [16, 40], + 16: [17, 41], + 17: [18, 42], + 18: [19, 43], + 19: [20, 44], + 20: [21, 45], + 21: [22, 46], + 22: [23, 47], + 23: [24, 48], + 24: [25, 49], + 25: [26, 50], + 26: [27, 51], + 27: [28, 52], + 28: [29, 53], + 29: [30, 54], + 30: [31, 55], + 31: [32, 56], + 32: [33, 57], + 33: [34, 58], + } @property def port_start(self): @@ -87,7 +87,7 @@ def __init__(self): for x in range(0, self.port_end+1): self.port_to_eeprom_mapping[x] = eeprom_path.format( self._port_to_i2c_mapping[x][1] - ) + ) SfpUtilBase.__init__(self) @@ -95,13 +95,13 @@ def get_presence(self, port_num): # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False - if port_num < 16 : + if port_num < 16: present_path = self.BASE_CPLD1_PATH + "module_present_" + str(port_num+1) else: present_path = self.BASE_CPLD2_PATH + "module_present_" + str(port_num+1) self.__port_to_is_present = present_path - content="0" + content = "0" try: val_file = open(self.__port_to_is_present) content = val_file.readline().rstrip() @@ -131,11 +131,11 @@ def get_low_power_mode(self, port_num): lpmode = ord(eeprom.read(1)) if ((lpmode & 0x3) == 0x3): - return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 + return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 else: - return 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 + return 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 except IOError as e: print("Error: unable to open file: %s" % str(e)) return False @@ -153,7 +153,7 @@ def set_low_power_mode(self, port_num, lpmode): eeprom = None if not self.get_presence(port_num): - return False # Port is not present, unable to set the eeprom + return False # Port is not present, unable to set the eeprom # Fill in write buffer # 0x3:Low Power Mode. "Power override" bit is 1 and "Power set" bit is 1 @@ -180,7 +180,7 @@ def reset(self, port_num): if port_num < self.port_start or port_num > self.port_end: return False - if port_num < 16 : + if port_num < 16: mod_rst_path = self.BASE_CPLD1_PATH + "module_reset_" + str(port_num+1) else: mod_rst_path = self.BASE_CPLD2_PATH + "module_reset_" + str(port_num+1) @@ -200,78 +200,78 @@ def reset(self, port_num): return True def get_cpld_interrupt(self): - port_dict={} - for i in range(0,4): - if i==0 or i==1: + port_dict = {} + for i in range(0, 4): + if i == 0 or i == 1: cpld_i2c_path = self.BASE_CPLD1_PATH + "cpld_intr_" + str(i+1) else: - cpld_i2c_path = self.BASE_CPLD2_PATH + "cpld_intr_" +str(i+1) + cpld_i2c_path = self.BASE_CPLD2_PATH + "cpld_intr_" + str(i+1) - start_i=(i*8) - end_i=(i*8+8) + start_i = (i*8) + end_i = (i*8+8) try: val_file = open(cpld_i2c_path) except IOError as e: print("Error: unable to open file: %s" % str(e)) - for k in range (start_i, end_i): - port_dict[k]=0 + for k in range(start_i, end_i): + port_dict[k] = 0 return port_dict status = val_file.readline().rstrip() val_file.close() - status=status.strip() - status= int(status, 16) + status = status.strip() + status = int(status, 16) interrupt_status = ~(status & 0xff) if interrupt_status: - port_shift=0 - for k in range (start_i, end_i): - if interrupt_status & (0x1< 0: - timeout = timeout / float(1000) # Convert to secs + timeout = timeout / float(1000) # Convert to secs else: print("get_transceiver_change_event:Invalid timeout value", timeout) return False, {} end_time = start_time + timeout if start_time > end_time: - print('get_transceiver_change_event:' \ - 'time wrap / invalid timeout value', timeout) + print('get_transceiver_change_event:' + 'time wrap / invalid timeout value', timeout) - return False, {} # Time wrap or possibly incorrect timeout + return False, {} # Time wrap or possibly incorrect timeout - #for i in range(self.port_start, self.port_end+1): + # for i in range(self.port_start, self.port_end+1): # ori_present[i]=self.get_presence(i) while timeout >= 0: - change_status=0 + change_status = 0 port_dict = self.get_cpld_interrupt() - present=0 + present = 0 for key, value in port_dict.items(): - if value==1: - present=self.get_presence(key) - change_status=1 + if value == 1: + present = self.get_presence(key) + change_status = 1 if present: - port_dict[key]='1' + port_dict[key] = '1' else: - port_dict[key]='0' + port_dict[key] = '0' if change_status: return True, port_dict @@ -280,7 +280,7 @@ def get_transceiver_change_event(self, timeout=0): else: timeout = end_time - time.time() if timeout >= 1: - time.sleep(1) # We poll at 1 second granularity + time.sleep(1) # We poll at 1 second granularity else: if timeout > 0: time.sleep(timeout) diff --git a/device/accton/x86_64-accton_minipack-r0/plugins/eeprom.py b/device/accton/x86_64-accton_minipack-r0/plugins/eeprom.py index a3bd41b12d31..3912194484db 100644 --- a/device/accton/x86_64-accton_minipack-r0/plugins/eeprom.py +++ b/device/accton/x86_64-accton_minipack-r0/plugins/eeprom.py @@ -9,10 +9,12 @@ from sonic_eeprom import eeprom_tlvinfo import subprocess except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom" super(board, self).__init__(self.eeprom_path, 0x200, '', True) diff --git a/device/accton/x86_64-accton_minipack-r0/plugins/led_control.py b/device/accton/x86_64-accton_minipack-r0/plugins/led_control.py index c452552a3dc7..a11a31062367 100755 --- a/device/accton/x86_64-accton_minipack-r0/plugins/led_control.py +++ b/device/accton/x86_64-accton_minipack-r0/plugins/led_control.py @@ -23,9 +23,8 @@ class LedControl(LedControlBase): """Platform specific LED control class""" SONIC_PORT_NAME_PREFIX = "Ethernet" - def __init__(self): - pim=PimUtil() + pim = PimUtil() pim.init_pim_fpga() def _port_name_to_index(self, port_name): @@ -38,20 +37,19 @@ def _port_name_to_index(self, port_name): def _port_state_to_mode(self, port_idx, state): if state == "up": - return 1, 4 #port linkup, led is green + return 1, 4 # port linkup, led is green else: - return 0, 0 #port linkdown, led is off + return 0, 0 # port linkdown, led is off def port_link_state_change(self, portname, state): - pim=PimUtil() + pim = PimUtil() port_idx = self._port_name_to_index(portname) new_control, led_mode = self._port_state_to_mode(port_idx, state) - color, control=pim.get_port_led(port_idx) + color, control = pim.get_port_led(port_idx) - if color==led_mode: - if control==new_control: + if color == led_mode: + if control == new_control: return - pim.set_port_led(port_idx, led_mode, new_control)#port linkup, led is green - #port linkdown, led is off - + pim.set_port_led(port_idx, led_mode, new_control) # port linkup, led is green + # port linkdown, led is off diff --git a/device/accton/x86_64-accton_minipack-r0/plugins/psuutil.py b/device/accton/x86_64-accton_minipack-r0/plugins/psuutil.py index 53a172c771b9..2a8bd232db44 100644 --- a/device/accton/x86_64-accton_minipack-r0/plugins/psuutil.py +++ b/device/accton/x86_64-accton_minipack-r0/plugins/psuutil.py @@ -11,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/accton/x86_64-accton_minipack-r0/plugins/sfputil.py b/device/accton/x86_64-accton_minipack-r0/plugins/sfputil.py index cdbac3096bce..85dc5f81f5ac 100755 --- a/device/accton/x86_64-accton_minipack-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_minipack-r0/plugins/sfputil.py @@ -7,7 +7,7 @@ import time from sonic_sfp.sfputilbase import SfpUtilBase import os - import sys, getopt + import sys from minipack.pimutil import PimUtil except ImportError as e: raise ImportError("%s - required module not found" % str(e)) @@ -47,57 +47,56 @@ def sfp_map(self, index): base = ((port-1)/8*8) + 10 index = (port - 1) % 8 index = 7 - index - if (index%2): - index = index -1 + if (index % 2): + index = index - 1 else: - index = index +1 + index = index + 1 bus = base + index return bus - def __init__(self): for x in range(0, self.port_end): - self.port_to_eeprom_mapping[x] = self.LOCAL_OOM_PATH %x + self.port_to_eeprom_mapping[x] = self.LOCAL_OOM_PATH % x SfpUtilBase.__init__(self) - pim=PimUtil() + pim = PimUtil() pim.init_pim_fpga() def __del__(self): - self.value=0 + self.value = 0 def get_presence(self, port_num): # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False - pim=PimUtil() - status=pim.get_qsfp_presence(port_num) + pim = PimUtil() + status = pim.get_qsfp_presence(port_num) return status def get_low_power_mode(self, port_num): if port_num < self.port_start or port_num > self.port_end: return False - pim=PimUtil() + pim = PimUtil() return pim.get_low_power_mode(port_num) def set_low_power_mode(self, port_num, lpmode): if port_num < self.port_start or port_num > self.port_end: return False - pim=PimUtil() + pim = PimUtil() pim.set_low_power_mode(port_num, lpmode) return True def reset(self, port_num): if port_num < self.port_start or port_num > self.port_end: return False - pim=PimUtil() + pim = PimUtil() pim.reset(port_num) return True def get_transceiver_change_event(self, timeout=0): - pim=PimUtil() + pim = PimUtil() start_time = time.time() port_dict = {} forever = False @@ -105,30 +104,30 @@ def get_transceiver_change_event(self, timeout=0): if timeout == 0: forever = True elif timeout > 0: - timeout = timeout / float(1000) # Convert to secs + timeout = timeout / float(1000) # Convert to secs else: print("get_transceiver_change_event:Invalid timeout value", timeout) return False, {} end_time = start_time + timeout if start_time > end_time: - print('get_transceiver_change_event:' \ - 'time wrap / invalid timeout value', timeout) + print('get_transceiver_change_event:' + 'time wrap / invalid timeout value', timeout) - return False, {} # Time wrap or possibly incorrect timeout + return False, {} # Time wrap or possibly incorrect timeout while timeout >= 0: - change_status=0 + change_status = 0 port_dict = pim.get_qsfp_interrupt() - present=0 + present = 0 for key, value in port_dict.items(): - if value==1: - present=self.get_presence(key) - change_status=1 + if value == 1: + present = self.get_presence(key) + change_status = 1 if present: - port_dict[key]='1' + port_dict[key] = '1' else: - port_dict[key]='0' + port_dict[key] = '0' if change_status: return True, port_dict @@ -137,7 +136,7 @@ def get_transceiver_change_event(self, timeout=0): else: timeout = end_time - time.time() if timeout >= 1: - time.sleep(1) # We poll at 1 second granularity + time.sleep(1) # We poll at 1 second granularity else: if timeout > 0: time.sleep(timeout) diff --git a/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/eeprom.py b/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/eeprom.py index abb1cf9eb8bf..9e4e9970e9f5 100644 --- a/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/eeprom.py +++ b/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/eeprom.py @@ -9,13 +9,15 @@ from sonic_eeprom import eeprom_tlvinfo import subprocess except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/1-0056/eeprom" - #Two i2c buses might get flipped order, check them both. + # Two i2c buses might get flipped order, check them both. if not os.path.exists(self.eeprom_path): self.eeprom_path = "/sys/bus/i2c/devices/0-0056/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/led_control.py b/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/led_control.py index 98ac93699ef7..926245e8a069 100644 --- a/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/led_control.py +++ b/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/led_control.py @@ -44,113 +44,114 @@ def sysled_task(): def system_led_check(): global read_fan_fault, read_power_status, is_fan_all_OK, is_power_all_OK, is_thermal_high, is_reset_button_push - is_fan_all_OK = 1 - is_power_all_OK = 0 - is_thermal_high = 0 - is_reset_button_push = 0 - with open("/sys/bus/i2c/devices/1-005e/fan1_fault", "r") as f1: - read_fan_fault = f1.read() - with open("/sys/bus/i2c/devices/9-005f/fan1_led", "w") as f11: - if str(read_fan_fault) == str("1\n"): - is_fan_all_OK = 0 - f11.write("4") - else: - f11.write("1") - with open("/sys/bus/i2c/devices/1-005e/fan2_fault", "r") as f1: - read_fan_fault = f1.read() - with open("/sys/bus/i2c/devices/9-005f/fan2_led", "w") as f11: - if str(read_fan_fault) == str("1\n"): - is_fan_all_OK = 0 - f11.write("4") - else: - f11.write("1") - with open("/sys/bus/i2c/devices/1-005e/fan3_fault", "r") as f1: - read_fan_fault = f1.read() - with open("/sys/bus/i2c/devices/9-005f/fan3_led", "w") as f11: - if str(read_fan_fault) == str("1\n"): - is_fan_all_OK = 0 - f11.write("4") - else: - f11.write("1") - with open("/sys/bus/i2c/devices/1-005e/fan4_fault", "r") as f1: - read_fan_fault = f1.read() - with open("/sys/bus/i2c/devices/9-005f/fan4_led", "w") as f11: - if str(read_fan_fault) == str("1\n"): - is_fan_all_OK = 0 - f11.write("4") - else: - f11.write("1") - with open("/sys/bus/i2c/devices/1-005e/fan5_fault", "r") as f1: - read_fan_fault = f1.read() - with open("/sys/bus/i2c/devices/9-005f/fan5_led", "w") as f11: - if str(read_fan_fault) == str("1\n"): - is_fan_all_OK = 0 - f11.write("4") - else: - f11.write("1") - with open("/sys/bus/i2c/devices/1-005e/fan6_fault", "r") as f1: - read_fan_fault = f1.read() - with open("/sys/bus/i2c/devices/9-005f/fan6_led", "w") as f11: - if str(read_fan_fault) == str("1\n"): - is_fan_all_OK = 0 - f11.write("4") - else: - f11.write("1") - - with open("/sys/bus/i2c/devices/1-005e/psu1_power_good", "r") as f1: - read_power_status = f1.read() - with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11: - if str(read_power_status) == str("1\n"): + + is_fan_all_OK = 1 + is_power_all_OK = 0 + is_thermal_high = 0 + is_reset_button_push = 0 + with open("/sys/bus/i2c/devices/1-005e/fan1_fault", "r") as f1: + read_fan_fault = f1.read() + with open("/sys/bus/i2c/devices/9-005f/fan1_led", "w") as f11: + if str(read_fan_fault) == str("1\n"): + is_fan_all_OK = 0 + f11.write("4") + else: f11.write("1") + with open("/sys/bus/i2c/devices/1-005e/fan2_fault", "r") as f1: + read_fan_fault = f1.read() + with open("/sys/bus/i2c/devices/9-005f/fan2_led", "w") as f11: + if str(read_fan_fault) == str("1\n"): + is_fan_all_OK = 0 + f11.write("4") else: + f11.write("1") + with open("/sys/bus/i2c/devices/1-005e/fan3_fault", "r") as f1: + read_fan_fault = f1.read() + with open("/sys/bus/i2c/devices/9-005f/fan3_led", "w") as f11: + if str(read_fan_fault) == str("1\n"): + is_fan_all_OK = 0 f11.write("4") - with open("/sys/bus/i2c/devices/1-005e/psu1_present", "r") as f1: - read_power_status = f1.read() - with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11: - if str(read_power_status) == str("1\n"): - is_power_all_OK = is_power_all_OK + 1 - f11.write("1") - else: - f11.write("4") - with open("/sys/bus/i2c/devices/1-005e/psu2_power_good", "r") as f1: - read_power_status = f1.read() - with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11: - if str(read_power_status) == str("1\n"): + else: f11.write("1") + with open("/sys/bus/i2c/devices/1-005e/fan4_fault", "r") as f1: + read_fan_fault = f1.read() + with open("/sys/bus/i2c/devices/9-005f/fan4_led", "w") as f11: + if str(read_fan_fault) == str("1\n"): + is_fan_all_OK = 0 + f11.write("4") else: + f11.write("1") + with open("/sys/bus/i2c/devices/1-005e/fan5_fault", "r") as f1: + read_fan_fault = f1.read() + with open("/sys/bus/i2c/devices/9-005f/fan5_led", "w") as f11: + if str(read_fan_fault) == str("1\n"): + is_fan_all_OK = 0 f11.write("4") - with open("/sys/bus/i2c/devices/1-005e/psu2_present", "r") as f1: - read_power_status = f1.read() - with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11: - if str(read_power_status) == str("1\n"): - is_power_all_OK = is_power_all_OK + 1 - f11.write("1") - else: - f11.write("4") - - with open("/sys/bus/i2c/devices/9-005f/swi_ctrl", "r") as f5: - is_reset_button_push = f5.read() - if str(is_reset_button_push) == "1\n": - is_reset_button_push = 1 - else: - is_reset_button_push = 0 + else: + f11.write("1") + with open("/sys/bus/i2c/devices/1-005e/fan6_fault", "r") as f1: + read_fan_fault = f1.read() + with open("/sys/bus/i2c/devices/9-005f/fan6_led", "w") as f11: + if str(read_fan_fault) == str("1\n"): + is_fan_all_OK = 0 + f11.write("4") + else: + f11.write("1") - with open("/sys/bus/i2c/devices/4-004d/hwmon/hwmon3/temp1_input", "r") as f3: - is_thermal_high = f3.read() - if int(is_thermal_high) >= 70000: - is_thermal_high = 1 + with open("/sys/bus/i2c/devices/1-005e/psu1_power_good", "r") as f1: + read_power_status = f1.read() + with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11: + if str(read_power_status) == str("1\n"): + f11.write("1") else: - is_thermal_high = 0 + f11.write("4") + with open("/sys/bus/i2c/devices/1-005e/psu1_present", "r") as f1: + read_power_status = f1.read() + with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11: + if str(read_power_status) == str("1\n"): + is_power_all_OK = is_power_all_OK + 1 + f11.write("1") + else: + f11.write("4") + with open("/sys/bus/i2c/devices/1-005e/psu2_power_good", "r") as f1: + read_power_status = f1.read() + with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11: + if str(read_power_status) == str("1\n"): + f11.write("1") + else: + f11.write("4") + with open("/sys/bus/i2c/devices/1-005e/psu2_present", "r") as f1: + read_power_status = f1.read() + with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11: + if str(read_power_status) == str("1\n"): + is_power_all_OK = is_power_all_OK + 1 + f11.write("1") + else: + f11.write("4") - with open("/sys/bus/i2c/devices/9-005f/sys_status", "w") as f2: - if is_reset_button_push == 1: - f2.write("3") - elif is_fan_all_OK == 0 or is_power_all_OK == 0 or is_thermal_high == 1: - f2.write("4") + with open("/sys/bus/i2c/devices/9-005f/swi_ctrl", "r") as f5: + is_reset_button_push = f5.read() + if str(is_reset_button_push) == "1\n": + is_reset_button_push = 1 else: - f2.write("1") + is_reset_button_push = 0 - return + with open("/sys/bus/i2c/devices/4-004d/hwmon/hwmon3/temp1_input", "r") as f3: + is_thermal_high = f3.read() + if int(is_thermal_high) >= 70000: + is_thermal_high = 1 + else: + is_thermal_high = 0 + + with open("/sys/bus/i2c/devices/9-005f/sys_status", "w") as f2: + if is_reset_button_push == 1: + f2.write("3") + elif is_fan_all_OK == 0 or is_power_all_OK == 0 or is_thermal_high == 1: + f2.write("4") + else: + f2.write("1") + + return ########## diff --git a/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/psuutil.py b/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/psuutil.py index 376a51f037bb..d189349b5d0e 100644 --- a/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/psuutil.py +++ b/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/psuutil.py @@ -11,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/sfputil.py b/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/sfputil.py index 59be952ebb50..09679eed8c3b 100644 --- a/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/sfputil.py +++ b/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/sfputil.py @@ -2,7 +2,7 @@ import time from sonic_sfp.sfputilbase import SfpUtilBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class SfpUtil(SfpUtilBase): @@ -14,10 +14,10 @@ class SfpUtil(SfpUtilBase): port_to_eeprom = {} port_to_i2cbus_mapping = { - 1 : 14, - 2 : 15, - 3 : 16, - 4 : 17, + 1: 14, + 2: 15, + 3: 16, + 4: 17, } eeprom_path = "/sys/bus/i2c/devices/{0}-005f/sfp{1}_eeprom" @@ -25,6 +25,7 @@ class SfpUtil(SfpUtilBase): present_path = "/sys/bus/i2c/devices/{0}-005f/sfp{1}_is_present" _qsfp_ports = list(range(first_port, port_num + 1)) + @property def port_start(self): return self.first_port @@ -39,7 +40,7 @@ def qsfp_ports(self): @property def port_to_eeprom_mapping(self): - return self.port_to_eeprom + return self.port_to_eeprom def get_transceiver_change_event(self): """ @@ -99,7 +100,6 @@ def get_presence(self, port_num): path = self.present_path port_path = path.format(self.port_to_i2cbus_mapping[i2c_index], (index + 1)) - try: reg_file = open(port_path) except IOError as e: @@ -111,4 +111,3 @@ def get_presence(self, port_num): return True return False - diff --git a/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/eeprom.py b/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/eeprom.py index abb1cf9eb8bf..9e4e9970e9f5 100644 --- a/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/eeprom.py +++ b/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/eeprom.py @@ -9,13 +9,15 @@ from sonic_eeprom import eeprom_tlvinfo import subprocess except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/1-0056/eeprom" - #Two i2c buses might get flipped order, check them both. + # Two i2c buses might get flipped order, check them both. if not os.path.exists(self.eeprom_path): self.eeprom_path = "/sys/bus/i2c/devices/0-0056/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/psuutil.py b/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/psuutil.py index 376a51f037bb..d189349b5d0e 100644 --- a/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/psuutil.py +++ b/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/psuutil.py @@ -11,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/sfputil.py b/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/sfputil.py index a5c7830c2a2c..e2c2aae496cc 100644 --- a/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/sfputil.py +++ b/device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/sfputil.py @@ -2,7 +2,7 @@ import time from sonic_sfp.sfputilbase import SfpUtilBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class SfpUtil(SfpUtilBase): @@ -14,11 +14,11 @@ class SfpUtil(SfpUtilBase): port_to_eeprom = {} port_to_i2cbus_mapping = { - 1 : 13, - 2 : 14, - 3 : 15, - 4 : 16, - 5 : 23, + 1: 13, + 2: 14, + 3: 15, + 4: 16, + 5: 23, } eeprom_path_1 = "/sys/bus/i2c/devices/{0}-0020/sfp{1}_eeprom" @@ -44,7 +44,7 @@ def qsfp_ports(self): @property def port_to_eeprom_mapping(self): - return self.port_to_eeprom + return self.port_to_eeprom def get_transceiver_change_event(self): """ @@ -114,7 +114,6 @@ def get_presence(self, port_num): path = self.present_path port_path = path.format(self.port_to_i2cbus_mapping[cpld_index], index) - try: reg_file = open(port_path) except IOError as e: @@ -127,4 +126,3 @@ def get_presence(self, port_num): return True return False - diff --git a/device/arista/x86_64-arista_common/platform_reboot b/device/arista/x86_64-arista_common/platform_reboot index 76cc3c5a2b34..1c3f954c03cc 100755 --- a/device/arista/x86_64-arista_common/platform_reboot +++ b/device/arista/x86_64-arista_common/platform_reboot @@ -3,9 +3,11 @@ import arista.platforms from arista.utils.sonic_reboot import reboot + def main(): - # reboot the system - reboot() + # reboot the system + reboot() + if __name__ == "__main__": - main() + main() diff --git a/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/pltfm_mgr_rpc/pltfm_mgr_rpc.py b/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/pltfm_mgr_rpc/pltfm_mgr_rpc.py index 16608e977d24..8f5b89e4312a 100644 --- a/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/pltfm_mgr_rpc/pltfm_mgr_rpc.py +++ b/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/pltfm_mgr_rpc/pltfm_mgr_rpc.py @@ -177,7 +177,8 @@ def recv_pltfm_mgr_sys_tmp_get(self): return result.success if result.ouch is not None: raise result.ouch - raise TApplicationException(TApplicationException.MISSING_RESULT, "pltfm_mgr_sys_tmp_get failed: unknown result") + raise TApplicationException(TApplicationException.MISSING_RESULT, + "pltfm_mgr_sys_tmp_get failed: unknown result") def pltfm_mgr_sys_eeprom_get(self): self.send_pltfm_mgr_sys_eeprom_get() @@ -205,7 +206,8 @@ def recv_pltfm_mgr_sys_eeprom_get(self): return result.success if result.ouch is not None: raise result.ouch - raise TApplicationException(TApplicationException.MISSING_RESULT, "pltfm_mgr_sys_eeprom_get failed: unknown result") + raise TApplicationException(TApplicationException.MISSING_RESULT, + "pltfm_mgr_sys_eeprom_get failed: unknown result") def pltfm_mgr_pwr_supply_present_get(self, ps_num): """ @@ -238,7 +240,8 @@ def recv_pltfm_mgr_pwr_supply_present_get(self): return result.success if result.ouch is not None: raise result.ouch - raise TApplicationException(TApplicationException.MISSING_RESULT, "pltfm_mgr_pwr_supply_present_get failed: unknown result") + raise TApplicationException(TApplicationException.MISSING_RESULT, + "pltfm_mgr_pwr_supply_present_get failed: unknown result") def pltfm_mgr_pwr_supply_info_get(self, ps_num): """ @@ -271,7 +274,8 @@ def recv_pltfm_mgr_pwr_supply_info_get(self): return result.success if result.ouch is not None: raise result.ouch - raise TApplicationException(TApplicationException.MISSING_RESULT, "pltfm_mgr_pwr_supply_info_get failed: unknown result") + raise TApplicationException(TApplicationException.MISSING_RESULT, + "pltfm_mgr_pwr_supply_info_get failed: unknown result") def pltfm_mgr_pwr_rail_info_get(self, ps_num): """ @@ -304,7 +308,8 @@ def recv_pltfm_mgr_pwr_rail_info_get(self): return result.success if result.ouch is not None: raise result.ouch - raise TApplicationException(TApplicationException.MISSING_RESULT, "pltfm_mgr_pwr_rail_info_get failed: unknown result") + raise TApplicationException(TApplicationException.MISSING_RESULT, + "pltfm_mgr_pwr_rail_info_get failed: unknown result") def pltfm_mgr_fan_speed_set(self, fan_num, percent): """ @@ -339,7 +344,8 @@ def recv_pltfm_mgr_fan_speed_set(self): return result.success if result.ouch is not None: raise result.ouch - raise TApplicationException(TApplicationException.MISSING_RESULT, "pltfm_mgr_fan_speed_set failed: unknown result") + raise TApplicationException(TApplicationException.MISSING_RESULT, + "pltfm_mgr_fan_speed_set failed: unknown result") def pltfm_mgr_fan_info_get(self, fan_num): """ @@ -372,7 +378,8 @@ def recv_pltfm_mgr_fan_info_get(self): return result.success if result.ouch is not None: raise result.ouch - raise TApplicationException(TApplicationException.MISSING_RESULT, "pltfm_mgr_fan_info_get failed: unknown result") + raise TApplicationException(TApplicationException.MISSING_RESULT, + "pltfm_mgr_fan_info_get failed: unknown result") def pltfm_mgr_qsfp_presence_get(self, port_num): """ @@ -405,7 +412,8 @@ def recv_pltfm_mgr_qsfp_presence_get(self): return result.success if result.ouch is not None: raise result.ouch - raise TApplicationException(TApplicationException.MISSING_RESULT, "pltfm_mgr_qsfp_presence_get failed: unknown result") + raise TApplicationException(TApplicationException.MISSING_RESULT, + "pltfm_mgr_qsfp_presence_get failed: unknown result") def pltfm_mgr_qsfp_info_get(self, port_num): """ @@ -438,7 +446,8 @@ def recv_pltfm_mgr_qsfp_info_get(self): return result.success if result.ouch is not None: raise result.ouch - raise TApplicationException(TApplicationException.MISSING_RESULT, "pltfm_mgr_qsfp_info_get failed: unknown result") + raise TApplicationException(TApplicationException.MISSING_RESULT, + "pltfm_mgr_qsfp_info_get failed: unknown result") def pltfm_mgr_qsfp_get_max_port(self): self.send_pltfm_mgr_qsfp_get_max_port() @@ -466,7 +475,8 @@ def recv_pltfm_mgr_qsfp_get_max_port(self): return result.success if result.ouch is not None: raise result.ouch - raise TApplicationException(TApplicationException.MISSING_RESULT, "pltfm_mgr_qsfp_get_max_port failed: unknown result") + raise TApplicationException(TApplicationException.MISSING_RESULT, + "pltfm_mgr_qsfp_get_max_port failed: unknown result") def pltfm_mgr_qsfp_reset(self, port_num, reset): """ @@ -534,7 +544,8 @@ def recv_pltfm_mgr_qsfp_lpmode_get(self): return result.success if result.ouch is not None: raise result.ouch - raise TApplicationException(TApplicationException.MISSING_RESULT, "pltfm_mgr_qsfp_lpmode_get failed: unknown result") + raise TApplicationException(TApplicationException.MISSING_RESULT, + "pltfm_mgr_qsfp_lpmode_get failed: unknown result") def pltfm_mgr_qsfp_lpmode_set(self, port_num, lpmode): """ @@ -569,7 +580,8 @@ def recv_pltfm_mgr_qsfp_lpmode_set(self): return result.success if result.ouch is not None: raise result.ouch - raise TApplicationException(TApplicationException.MISSING_RESULT, "pltfm_mgr_qsfp_lpmode_set failed: unknown result") + raise TApplicationException(TApplicationException.MISSING_RESULT, + "pltfm_mgr_qsfp_lpmode_set failed: unknown result") def pltfm_mgr_sensor_info_get(self, options): """ @@ -602,7 +614,8 @@ def recv_pltfm_mgr_sensor_info_get(self): return result.success if result.ouch is not None: raise result.ouch - raise TApplicationException(TApplicationException.MISSING_RESULT, "pltfm_mgr_sensor_info_get failed: unknown result") + raise TApplicationException(TApplicationException.MISSING_RESULT, + "pltfm_mgr_sensor_info_get failed: unknown result") class Processor(Iface, TProcessor): @@ -2213,7 +2226,8 @@ def read(self, iprot): break if fid == 0: if ftype == TType.STRING: - self.success = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.success = iprot.readString().decode( + 'utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) elif fid == 1: @@ -2817,7 +2831,8 @@ def read(self, iprot): break if fid == 1: if ftype == TType.STRING: - self.options = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.options = iprot.readString().decode( + 'utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) else: @@ -2879,7 +2894,8 @@ def read(self, iprot): break if fid == 0: if ftype == TType.STRING: - self.success = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.success = iprot.readString().decode( + 'utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) elif fid == 1: diff --git a/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/pltfm_mgr_rpc/ttypes.py b/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/pltfm_mgr_rpc/ttypes.py index 22b59d885bb7..1f88c3c1f94f 100644 --- a/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/pltfm_mgr_rpc/ttypes.py +++ b/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/pltfm_mgr_rpc/ttypes.py @@ -274,37 +274,44 @@ def read(self, iprot): iprot.skip(ftype) elif fid == 2: if ftype == TType.STRING: - self.prod_name = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.prod_name = iprot.readString().decode( + 'utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) elif fid == 3: if ftype == TType.STRING: - self.prod_part_num = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.prod_part_num = iprot.readString().decode( + 'utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) elif fid == 4: if ftype == TType.STRING: - self.sys_asm_part_num = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.sys_asm_part_num = iprot.readString().decode( + 'utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) elif fid == 5: if ftype == TType.STRING: - self.bfn_pcba_part_num = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.bfn_pcba_part_num = iprot.readString().decode( + 'utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) elif fid == 6: if ftype == TType.STRING: - self.bfn_pcbb_part_num = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.bfn_pcbb_part_num = iprot.readString().decode( + 'utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) elif fid == 7: if ftype == TType.STRING: - self.odm_pcba_part_num = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.odm_pcba_part_num = iprot.readString().decode( + 'utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) elif fid == 8: if ftype == TType.STRING: - self.odm_pcba_ser_num = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.odm_pcba_ser_num = iprot.readString().decode( + 'utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) elif fid == 9: @@ -324,42 +331,50 @@ def read(self, iprot): iprot.skip(ftype) elif fid == 12: if ftype == TType.STRING: - self.prod_ser_num = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.prod_ser_num = iprot.readString().decode( + 'utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) elif fid == 13: if ftype == TType.STRING: - self.prod_ast_tag = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.prod_ast_tag = iprot.readString().decode( + 'utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) elif fid == 14: if ftype == TType.STRING: - self.sys_mfger = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.sys_mfger = iprot.readString().decode( + 'utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) elif fid == 15: if ftype == TType.STRING: - self.sys_mfg_date = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.sys_mfg_date = iprot.readString().decode( + 'utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) elif fid == 16: if ftype == TType.STRING: - self.pcb_mfger = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.pcb_mfger = iprot.readString().decode( + 'utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) elif fid == 17: if ftype == TType.STRING: - self.assembled_at = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.assembled_at = iprot.readString().decode( + 'utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) elif fid == 18: if ftype == TType.STRING: - self.loc_mac_addr = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.loc_mac_addr = iprot.readString().decode( + 'utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) elif fid == 19: if ftype == TType.STRING: - self.ext_mac_addr = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.ext_mac_addr = iprot.readString().decode( + 'utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) elif fid == 20: @@ -369,7 +384,8 @@ def read(self, iprot): iprot.skip(ftype) elif fid == 21: if ftype == TType.STRING: - self.location = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() + self.location = iprot.readString().decode( + 'utf-8') if sys.version_info[0] == 2 else iprot.readString() else: iprot.skip(ftype) elif fid == 22: @@ -401,23 +417,28 @@ def write(self, oprot): oprot.writeFieldEnd() if self.sys_asm_part_num is not None: oprot.writeFieldBegin('sys_asm_part_num', TType.STRING, 4) - oprot.writeString(self.sys_asm_part_num.encode('utf-8') if sys.version_info[0] == 2 else self.sys_asm_part_num) + oprot.writeString(self.sys_asm_part_num.encode('utf-8') + if sys.version_info[0] == 2 else self.sys_asm_part_num) oprot.writeFieldEnd() if self.bfn_pcba_part_num is not None: oprot.writeFieldBegin('bfn_pcba_part_num', TType.STRING, 5) - oprot.writeString(self.bfn_pcba_part_num.encode('utf-8') if sys.version_info[0] == 2 else self.bfn_pcba_part_num) + oprot.writeString(self.bfn_pcba_part_num.encode('utf-8') + if sys.version_info[0] == 2 else self.bfn_pcba_part_num) oprot.writeFieldEnd() if self.bfn_pcbb_part_num is not None: oprot.writeFieldBegin('bfn_pcbb_part_num', TType.STRING, 6) - oprot.writeString(self.bfn_pcbb_part_num.encode('utf-8') if sys.version_info[0] == 2 else self.bfn_pcbb_part_num) + oprot.writeString(self.bfn_pcbb_part_num.encode('utf-8') + if sys.version_info[0] == 2 else self.bfn_pcbb_part_num) oprot.writeFieldEnd() if self.odm_pcba_part_num is not None: oprot.writeFieldBegin('odm_pcba_part_num', TType.STRING, 7) - oprot.writeString(self.odm_pcba_part_num.encode('utf-8') if sys.version_info[0] == 2 else self.odm_pcba_part_num) + oprot.writeString(self.odm_pcba_part_num.encode('utf-8') + if sys.version_info[0] == 2 else self.odm_pcba_part_num) oprot.writeFieldEnd() if self.odm_pcba_ser_num is not None: oprot.writeFieldBegin('odm_pcba_ser_num', TType.STRING, 8) - oprot.writeString(self.odm_pcba_ser_num.encode('utf-8') if sys.version_info[0] == 2 else self.odm_pcba_ser_num) + oprot.writeString(self.odm_pcba_ser_num.encode('utf-8') + if sys.version_info[0] == 2 else self.odm_pcba_ser_num) oprot.writeFieldEnd() if self.prod_state is not None: oprot.writeFieldBegin('prod_state', TType.I16, 9) diff --git a/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/sfputil.py b/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/sfputil.py index b120179b1e34..47d875432cc5 100644 --- a/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/sfputil.py +++ b/device/barefoot/x86_64-accton_wedge100bf_32x-r0/plugins/sfputil.py @@ -15,7 +15,7 @@ from sonic_sfp.sfputilbase import SfpUtilBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") thrift_server = 'localhost' transport = None @@ -23,6 +23,7 @@ SFP_EEPROM_CACHE = "/var/run/platform/sfp/cache" + class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" @@ -78,7 +79,7 @@ def update_port_info(self): if self.QSFP_PORT_END == 0: self.thrift_setup() - self.QSFP_PORT_END = pltfm_mgr.pltfm_mgr_qsfp_get_max_port(); + self.QSFP_PORT_END = pltfm_mgr.pltfm_mgr_qsfp_get_max_port() self.PORT_END = self.QSFP_PORT_END self.PORTS_IN_BLOCK = self.QSFP_PORT_END self.thrift_teardown() @@ -196,7 +197,7 @@ def get_transceiver_change_event(self, timeout=0): if timeout == 0: forever = True elif timeout > 0: - timeout = timeout / float(1000) # Convert to secs + timeout = timeout / float(1000) # Convert to secs else: print("get_transceiver_change_event:Invalid timeout value", timeout) return False, {} @@ -247,4 +248,3 @@ def _get_port_eeprom_path(self, port_num, devid): self.thrift_teardown() return eeprom_path - diff --git a/device/broadcom/x86_64-bcm_xlr-r0/plugins/eeprom.py b/device/broadcom/x86_64-bcm_xlr-r0/plugins/eeprom.py index dc74870344d8..0a4e11155711 100644 --- a/device/broadcom/x86_64-bcm_xlr-r0/plugins/eeprom.py +++ b/device/broadcom/x86_64-bcm_xlr-r0/plugins/eeprom.py @@ -15,7 +15,7 @@ try: from sonic_eeprom import eeprom_tlvinfo except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): @@ -23,7 +23,7 @@ class board(eeprom_tlvinfo.TlvInfoDecoder): def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/usr/share/sonic/platform/sys_eeprom.bin" if os.path.isfile(self.eeprom_path) is False: - self.eeprom_path = "/usr/share/sonic/device/x86_64-bcm_xlr-r0/sys_eeprom.bin" + self.eeprom_path = "/usr/share/sonic/device/x86_64-bcm_xlr-r0/sys_eeprom.bin" super(board, self).__init__(self.eeprom_path, 0, '', False, True) def serial_number_str(self, e): diff --git a/device/celestica/x86_64-cel_e1031-r0/plugins/eeprom.py b/device/celestica/x86_64-cel_e1031-r0/plugins/eeprom.py index 43a40dec8539..4728d562cc7a 100644 --- a/device/celestica/x86_64-cel_e1031-r0/plugins/eeprom.py +++ b/device/celestica/x86_64-cel_e1031-r0/plugins/eeprom.py @@ -10,7 +10,7 @@ try: from sonic_eeprom import eeprom_tlvinfo except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): @@ -18,4 +18,3 @@ class board(eeprom_tlvinfo.TlvInfoDecoder): def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/class/i2c-adapter/i2c-2/2-0050/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) - diff --git a/device/celestica/x86_64-cel_e1031-r0/plugins/sfputil.py b/device/celestica/x86_64-cel_e1031-r0/plugins/sfputil.py index b9580b065cf0..d65f2cf3f54f 100644 --- a/device/celestica/x86_64-cel_e1031-r0/plugins/sfputil.py +++ b/device/celestica/x86_64-cel_e1031-r0/plugins/sfputil.py @@ -13,15 +13,15 @@ class SfpUtil(SfpUtilBase): PORT_START = 1 PORT_END = 52 port_to_i2c_mapping = { - 1: None, - 2: None, - 3: None, - 4: None, - 5: None, - 6: None, - 7: None, - 8: None, - 9: None, + 1: None, + 2: None, + 3: None, + 4: None, + 5: None, + 6: None, + 7: None, + 8: None, + 9: None, 10: None, 11: None, 12: None, @@ -93,7 +93,6 @@ def __init__(self): self.port_to_eeprom_mapping[x] = port_eeprom_path SfpUtilBase.__init__(self) - def get_presence(self, port_num): sfp_modabs_path = '/sys/devices/platform/e1031.smc/SFP/sfp_modabs' @@ -137,7 +136,7 @@ def get_transceiver_change_event(self, timeout=0): with open(modabs_interrupt_path, 'r') as port_changes: changes = int(port_changes.read(), 16) for port_num in self._sfp_port: - change = (changes >> ( port_num - 49)) & 1 + change = (changes >> (port_num - 49)) & 1 if change == 1: port_dict[str(port_num)] = str(int(self.get_presence(port_num))) found_flag = 1 diff --git a/device/celestica/x86_64-cel_midstone-r0/plugins/eeprom.py b/device/celestica/x86_64-cel_midstone-r0/plugins/eeprom.py index 08e42ad1c40f..c8b593a15003 100755 --- a/device/celestica/x86_64-cel_midstone-r0/plugins/eeprom.py +++ b/device/celestica/x86_64-cel_midstone-r0/plugins/eeprom.py @@ -10,7 +10,7 @@ try: from sonic_eeprom import eeprom_tlvinfo except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/celestica/x86_64-cel_midstone-r0/plugins/psuutil.py b/device/celestica/x86_64-cel_midstone-r0/plugins/psuutil.py index d8455b816f9a..0c93576e1fba 100644 --- a/device/celestica/x86_64-cel_midstone-r0/plugins/psuutil.py +++ b/device/celestica/x86_64-cel_midstone-r0/plugins/psuutil.py @@ -12,7 +12,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" @@ -42,7 +43,6 @@ def get_psu_status(self, index): status = 1 return status == 1 - def get_psu_presence(self, index): """ Retrieves the presence status of power supply unit (PSU) defined @@ -56,4 +56,3 @@ def get_psu_presence(self, index): status = 1 return status == 1 - diff --git a/device/celestica/x86_64-cel_seastone-r0/plugins/eeprom.py b/device/celestica/x86_64-cel_seastone-r0/plugins/eeprom.py index da2c87ce9cec..bba16943966a 100644 --- a/device/celestica/x86_64-cel_seastone-r0/plugins/eeprom.py +++ b/device/celestica/x86_64-cel_seastone-r0/plugins/eeprom.py @@ -10,7 +10,7 @@ try: from sonic_eeprom import eeprom_tlvinfo except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): @@ -18,4 +18,3 @@ class board(eeprom_tlvinfo.TlvInfoDecoder): def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/class/i2c-adapter/i2c-12/12-0050/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) - diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/sfp.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/sfp.py index bf650ab792d5..4c0a645714af 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/sfp.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/sfp.py @@ -530,7 +530,6 @@ def get_transceiver_info(self): transceiver_info_dict['ext_identifier'] = sfp_interface_bulk_data['data']['Extended Identifier']['value'] transceiver_info_dict['ext_rateselect_compliance'] = sfp_interface_bulk_data['data']['RateIdentifier']['value'] - if self.sfp_type == QSFP_TYPE: for key in qsfp_cable_length_tup: if key in sfp_interface_bulk_data['data']: diff --git a/device/celestica/x86_64-cel_seastone_2-r0/plugins/eeprom.py b/device/celestica/x86_64-cel_seastone_2-r0/plugins/eeprom.py index ff7beb84805d..93290ebf82bf 100644 --- a/device/celestica/x86_64-cel_seastone_2-r0/plugins/eeprom.py +++ b/device/celestica/x86_64-cel_seastone_2-r0/plugins/eeprom.py @@ -10,7 +10,7 @@ try: from sonic_eeprom import eeprom_tlvinfo except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): @@ -18,4 +18,3 @@ class board(eeprom_tlvinfo.TlvInfoDecoder): def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/class/i2c-adapter/i2c-0/0-0056/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) - diff --git a/device/celestica/x86_64-cel_seastone_2-r0/plugins/psuutil.py b/device/celestica/x86_64-cel_seastone_2-r0/plugins/psuutil.py index 5b407e017f43..35fcc0cc678c 100644 --- a/device/celestica/x86_64-cel_seastone_2-r0/plugins/psuutil.py +++ b/device/celestica/x86_64-cel_seastone_2-r0/plugins/psuutil.py @@ -6,7 +6,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" @@ -21,16 +22,16 @@ def run_command(self, command): if proc.returncode != 0: sys.exit(proc.returncode) - + return out - + def find_value(self, grep_string): result = re.search(".+\| (0x\d{2})\d{2}\|.+", grep_string) if result: return result.group(1) else: return result - + def get_num_psus(self): """ Retrieves the number of PSUs available on the device @@ -49,9 +50,9 @@ def get_psu_status(self, index): return False grep_key = "PSUL_Status" if index == 1 else "PSUR_Status" - grep_string = self.run_command(self.ipmi_sensor + ' | grep '+ grep_key) + grep_string = self.run_command(self.ipmi_sensor + ' | grep ' + grep_key) status_byte = self.find_value(grep_string) - + if status_byte is None: return False @@ -73,13 +74,13 @@ def get_psu_presence(self, index): return False grep_key = "PSUL_Status" if index == 1 else "PSUR_Status" - grep_string = self.run_command(self.ipmi_sensor + ' | grep '+ grep_key) + grep_string = self.run_command(self.ipmi_sensor + ' | grep ' + grep_key) status_byte = self.find_value(grep_string) - + if status_byte is None: return False - - presence = ( int(status_byte, 16) >> 0 ) & 1 + + presence = (int(status_byte, 16) >> 0) & 1 if presence: return True else: diff --git a/device/celestica/x86_64-cel_seastone_2-r0/plugins/sfputil.py b/device/celestica/x86_64-cel_seastone_2-r0/plugins/sfputil.py index cd14023f9f18..6f05527621fe 100755 --- a/device/celestica/x86_64-cel_seastone_2-r0/plugins/sfputil.py +++ b/device/celestica/x86_64-cel_seastone_2-r0/plugins/sfputil.py @@ -177,4 +177,3 @@ def get_transceiver_change_event(self, timeout=0): TBD: When the feature request. """ raise NotImplementedError - diff --git a/device/celestica/x86_64-cel_silverstone-r0/plugins/eeprom.py b/device/celestica/x86_64-cel_silverstone-r0/plugins/eeprom.py index fab05edf9e15..012196b0dd4c 100644 --- a/device/celestica/x86_64-cel_silverstone-r0/plugins/eeprom.py +++ b/device/celestica/x86_64-cel_silverstone-r0/plugins/eeprom.py @@ -10,7 +10,7 @@ try: from sonic_eeprom import eeprom_tlvinfo except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): @@ -18,4 +18,3 @@ class board(eeprom_tlvinfo.TlvInfoDecoder): def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/class/i2c-adapter/i2c-0/0-0056/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) - diff --git a/device/celestica/x86_64-cel_silverstone-r0/plugins/psuutil.py b/device/celestica/x86_64-cel_silverstone-r0/plugins/psuutil.py index 109e23b1e653..8051863dc779 100644 --- a/device/celestica/x86_64-cel_silverstone-r0/plugins/psuutil.py +++ b/device/celestica/x86_64-cel_silverstone-r0/plugins/psuutil.py @@ -6,7 +6,7 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class PsuUtil(PsuBase): @@ -24,16 +24,16 @@ def run_command(self, command): if proc.returncode != 0: sys.exit(proc.returncode) - + return out - + def find_value(self, in_string): result = re.search("^.+ ([0-9a-f]{2}) .+$", in_string) if result: return result.group(1) else: return result - + def get_num_psus(self): """ Retrieves the number of PSUs available on the device @@ -54,7 +54,7 @@ def get_psu_status(self, index): psu_id = self.psu1_id if index == 1 else self.psu2_id res_string = self.run_command(self.ipmi_raw + ' ' + psu_id) status_byte = self.find_value(res_string) - + if status_byte is None: return False @@ -78,11 +78,11 @@ def get_psu_presence(self, index): psu_id = self.psu1_id if index == 1 else self.psu2_id res_string = self.run_command(self.ipmi_raw + ' ' + psu_id) status_byte = self.find_value(res_string) - + if status_byte is None: return False - - presence = ( int(status_byte, 16) >> 0 ) & 1 + + presence = (int(status_byte, 16) >> 0) & 1 if presence: return True else: diff --git a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/chassis.py b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/chassis.py index a599bdf7c5d0..b6f77cbd3dc9 100644 --- a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/chassis.py +++ b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/chassis.py @@ -63,7 +63,6 @@ def __init__(self): thermal = Thermal(index) self._thermal_list.append(thermal) - def get_base_mac(self): """ Retrieves the base MAC address for the chassis diff --git a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/eeprom.py b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/eeprom.py index a2e3d946f656..cf3f1a98de20 100644 --- a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/eeprom.py +++ b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/eeprom.py @@ -29,12 +29,14 @@ TLV_EEPROM_I2C_BUS = 0 TLV_EEPROM_I2C_ADDR = 56 + class Tlv(eeprom_tlvinfo.TlvInfoDecoder): EEPROM_DECODE_HEADLINES = 6 def __init__(self): - self._eeprom_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-00{1}/eeprom".format(TLV_EEPROM_I2C_BUS, TLV_EEPROM_I2C_ADDR) + self._eeprom_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-00{1}/eeprom".format( + TLV_EEPROM_I2C_BUS, TLV_EEPROM_I2C_ADDR) super(Tlv, self).__init__(self._eeprom_path, 0, '', True) self._eeprom = self._load_eeprom() diff --git a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/fan.py b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/fan.py index a2cb9c094b1f..1055aee68fc7 100644 --- a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/fan.py +++ b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/fan.py @@ -148,7 +148,7 @@ def set_speed(self, speed): # register = 22 32 42 52 62 72 82 if self.is_psu_fan: - ## TODO + # TODO return False speed_hex = hex(int(float(speed)/100 * 255)) diff --git a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/psu.py b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/psu.py index a70b1e28a7dd..9ad0f1dc9392 100644 --- a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/psu.py +++ b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/psu.py @@ -236,6 +236,6 @@ def get_status(self): if status: failure_detected = (int(status_byte, 16) >> 1) & 1 input_lost = (int(status_byte, 16) >> 3) & 1 - psu_status = False if (input_lost or failure_detected) else True + psu_status = False if (input_lost or failure_detected) else True return psu_status diff --git a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/thermal.py b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/thermal.py index bd87ab77bff7..9ecf12218d50 100644 --- a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/thermal.py +++ b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/thermal.py @@ -45,6 +45,7 @@ def __init__(self, thermal_index): self.sensor_id = self.THERMAL_LIST[self.index][0] self.sensor_des = self.THERMAL_LIST[self.index][1] self.sensor_reading_addr = self.THERMAL_LIST[self.index][2] + def __set_threshold(self, key, value): print('{} {}'.format(key, value)) diff --git a/device/centec/arm64-centec_e530_24x2c-r0/plugins/eeprom.py b/device/centec/arm64-centec_e530_24x2c-r0/plugins/eeprom.py index cf57d35d99ef..afea818be079 100644 --- a/device/centec/arm64-centec_e530_24x2c-r0/plugins/eeprom.py +++ b/device/centec/arm64-centec_e530_24x2c-r0/plugins/eeprom.py @@ -10,7 +10,7 @@ try: from sonic_eeprom import eeprom_tlvinfo except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/centec/arm64-centec_e530_24x2c-r0/plugins/led_control.py b/device/centec/arm64-centec_e530_24x2c-r0/plugins/led_control.py index d9fc2c14f684..627cf03ddad4 100644 --- a/device/centec/arm64-centec_e530_24x2c-r0/plugins/led_control.py +++ b/device/centec/arm64-centec_e530_24x2c-r0/plugins/led_control.py @@ -22,7 +22,6 @@ def DBG_PRINT(str): class LedControl(LedControlBase): """Platform specific LED control class""" - # Helper method to map SONiC port name to index def _port_name_to_index(self, port_name): # Strip "Ethernet" off port name @@ -72,8 +71,8 @@ def _initDefaultConfig(self): DBG_PRINT("init led done") - # Concrete implementation of port_link_state_change() method + def port_link_state_change(self, portname, state): port_idx = self._port_name_to_index(portname) ledMode = self._port_state_to_mode(port_idx, state) @@ -86,8 +85,8 @@ def port_link_state_change(self, portname, state): self._port_led_mode_update(port_idx, ledMode) DBG_PRINT("update {} led mode from {} to {}".format(portname, saveMode, ledMode)) - # Constructor + def __init__(self): self.SONIC_PORT_NAME_PREFIX = "Ethernet" self.LED_MODE_UP = [11, 11] diff --git a/device/centec/arm64-centec_e530_24x2c-r0/plugins/psuutil.py b/device/centec/arm64-centec_e530_24x2c-r0/plugins/psuutil.py index c18fe699c37a..3a83f406d990 100644 --- a/device/centec/arm64-centec_e530_24x2c-r0/plugins/psuutil.py +++ b/device/centec/arm64-centec_e530_24x2c-r0/plugins/psuutil.py @@ -9,7 +9,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/eeprom.py b/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/eeprom.py index cf57d35d99ef..afea818be079 100644 --- a/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/eeprom.py +++ b/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/eeprom.py @@ -10,7 +10,7 @@ try: from sonic_eeprom import eeprom_tlvinfo except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/led_control.py b/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/led_control.py index 3768e099baf5..eb567de89c22 100644 --- a/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/led_control.py +++ b/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/led_control.py @@ -21,7 +21,6 @@ def DBG_PRINT(str): class LedControl(LedControlBase): """Platform specific LED control class""" - # Helper method to map SONiC port name to index def _port_name_to_index(self, port_name): # Strip "Ethernet" off port name @@ -71,8 +70,8 @@ def _initDefaultConfig(self): DBG_PRINT("init led done") - # Concrete implementation of port_link_state_change() method + def port_link_state_change(self, portname, state): port_idx = self._port_name_to_index(portname) ledMode = self._port_state_to_mode(port_idx, state) @@ -85,8 +84,8 @@ def port_link_state_change(self, portname, state): self._port_led_mode_update(port_idx, ledMode) DBG_PRINT("update {} led mode from {} to {}".format(portname, saveMode, ledMode)) - # Constructor + def __init__(self): self.SONIC_PORT_NAME_PREFIX = "Ethernet" self.LED_MODE_UP = [2, 11] diff --git a/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/psuutil.py b/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/psuutil.py index c18fe699c37a..3a83f406d990 100644 --- a/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/psuutil.py +++ b/device/centec/arm64-centec_e530_48t4x_p-r0/plugins/psuutil.py @@ -9,7 +9,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/eeprom.py b/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/eeprom.py index ed2448c7d290..63854d994cf1 100644 --- a/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/eeprom.py +++ b/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/eeprom.py @@ -18,7 +18,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/led_control.py b/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/led_control.py index da593262789a..48a4d8d04eae 100644 --- a/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/led_control.py +++ b/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/led_control.py @@ -23,6 +23,7 @@ def DBG_PRINT(str): syslog.syslog(syslog.LOG_INFO, str) syslog.closelog() + class LedControl(LedControlBase): """Platform specific LED control class""" SONIC_PORT_NAME_PREFIX = "Ethernet" @@ -51,7 +52,8 @@ def _initPanelLed(self): data = struct.pack('=HHHBB30B', 0, 3, 32, 30, 0, *[x[0] for x in self.led_mapping[21:51]]) self.udpClient.sendto(data, ('localhost', 8101)) - data = struct.pack('=HHHBB28B', 0, 3, 30, 28, 1, *[x[0] for x in (self.led_mapping[1:21]+self.led_mapping[51:59])]) + data = struct.pack('=HHHBB28B', 0, 3, 30, 28, 1, *[x[0] + for x in (self.led_mapping[1:21]+self.led_mapping[51:59])]) self.udpClient.sendto(data, ('localhost', 8101)) data = struct.pack('=HHHB', 0, 5, 1, 1) @@ -94,8 +96,8 @@ def _initDefaultConfig(self): DBG_PRINT("init led done") - # Helper method to map SONiC port name to index + def _port_name_to_index(self, port_name): # Strip "Ethernet" off port name if not port_name.startswith(self.SONIC_PORT_NAME_PREFIX): @@ -134,13 +136,20 @@ def port_link_state_change(self, portname, state): def __init__(self): # [macid, ctlid, defaultmode] self.led_mapping = [(0, 0, 0)] # resv - self.led_mapping.extend([(27, 1, 7), (25, 1, 7), (24, 1, 7), (22, 1, 7), (21, 1, 7), (19, 1, 7), (18, 1, 7), (16, 1, 7)]) # panel port 1~8 - self.led_mapping.extend([(15, 1, 7), (13, 1, 7), (12, 1, 7), (10, 1, 7), (9, 1, 7), (8, 1, 7), (7, 1, 7), (5, 1, 7)]) # panel port 9~16 - self.led_mapping.extend([(4, 1, 7), (2, 1, 7), (1, 1, 7), (0, 1, 7), (0, 0, 7), (1, 0, 7), (3, 0, 7), (2, 0, 7)]) # panel port 17~24 - self.led_mapping.extend([(4, 0, 7), (5, 0, 7), (6, 0, 7), (7, 0, 7), (8, 0, 7), (9, 0, 7), (10, 0, 7), (12, 0, 7)]) # panel port 25~32 - self.led_mapping.extend([(13, 0, 7), (15, 0, 7), (16, 0, 7), (18, 0, 7), (19, 0, 7), (21, 0, 7), (22, 0, 7), (24, 0, 7)]) # panel port 33~40 - self.led_mapping.extend([(25, 0, 7), (27, 0, 7), (28, 0, 7), (30, 0, 7), (31, 0, 7), (33, 0, 7), (34, 0, 7), (48, 0, 7)]) # panel port 41~48 - self.led_mapping.extend([(36, 0, 2), (52, 0, 2), (52, 1, 2), (36, 1, 2), (48, 1, 2), (32, 1, 2)]) # panel port 49~54 + self.led_mapping.extend([(27, 1, 7), (25, 1, 7), (24, 1, 7), (22, 1, 7), (21, 1, 7), + (19, 1, 7), (18, 1, 7), (16, 1, 7)]) # panel port 1~8 + self.led_mapping.extend([(15, 1, 7), (13, 1, 7), (12, 1, 7), (10, 1, 7), (9, 1, 7), + (8, 1, 7), (7, 1, 7), (5, 1, 7)]) # panel port 9~16 + self.led_mapping.extend([(4, 1, 7), (2, 1, 7), (1, 1, 7), (0, 1, 7), (0, 0, 7), + (1, 0, 7), (3, 0, 7), (2, 0, 7)]) # panel port 17~24 + self.led_mapping.extend([(4, 0, 7), (5, 0, 7), (6, 0, 7), (7, 0, 7), (8, 0, 7), + (9, 0, 7), (10, 0, 7), (12, 0, 7)]) # panel port 25~32 + self.led_mapping.extend([(13, 0, 7), (15, 0, 7), (16, 0, 7), (18, 0, 7), (19, 0, 7), + (21, 0, 7), (22, 0, 7), (24, 0, 7)]) # panel port 33~40 + self.led_mapping.extend([(25, 0, 7), (27, 0, 7), (28, 0, 7), (30, 0, 7), (31, 0, 7), + (33, 0, 7), (34, 0, 7), (48, 0, 7)]) # panel port 41~48 + self.led_mapping.extend([(36, 0, 2), (52, 0, 2), (52, 1, 2), (36, 1, 2), (48, 1, 2), + (32, 1, 2)]) # panel port 49~54 self.led_mapping.extend([(11, 1, 2), (11, 1, 2), (11, 1, 2), (11, 1, 2), (11, 1, 2), (11, 1, 2)]) self.f_led = "/sys/class/leds/{}/brightness" @@ -148,4 +157,3 @@ def __init__(self): self.udpClient = socket(AF_INET, SOCK_DGRAM) self._initDefaultConfig() - diff --git a/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/psuutil.py b/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/psuutil.py index 146d390d2ef0..f38f0cdd0a2e 100644 --- a/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/psuutil.py +++ b/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/psuutil.py @@ -11,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/sfputil.py b/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/sfputil.py index 92f76ce3217a..4e94646db772 100644 --- a/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/sfputil.py +++ b/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/sfputil.py @@ -16,7 +16,6 @@ raise ImportError("%s - required module not found" % str(e)) - def DBG_PRINT(str): print(str + "\n") @@ -60,17 +59,17 @@ def get_eeprom_data(self, port): offset = (128 if port in self.qsfp_ports else 0) r_sel = [self.udpClient] req = struct.pack('=HHHBBHIBBBBI', - 0, 9, 16, # lchip/msgtype/msglen - ctlid, # uint8 ctl_id - devid, # uint8 slave_dev_id - 0x50, # uint16 dev_addr - (1< /dev/null 2>&1") + p = os.popen(self.psu_presence.format(index + Base_bus_number) + "> /dev/null 2>&1") if p.readline() != None: status = 1 p.close() except IOError: return False return status == 1 - - diff --git a/device/cig/x86_64-cig_cs5435_54p-r0/plugins/eeprom.py b/device/cig/x86_64-cig_cs5435_54p-r0/plugins/eeprom.py index e22124e5fc89..ae5a8385d96c 100755 --- a/device/cig/x86_64-cig_cs5435_54p-r0/plugins/eeprom.py +++ b/device/cig/x86_64-cig_cs5435_54p-r0/plugins/eeprom.py @@ -9,10 +9,12 @@ from sonic_eeprom import eeprom_tlvinfo import subprocess except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/7-0057/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/cig/x86_64-cig_cs5435_54p-r0/plugins/psuutil.py b/device/cig/x86_64-cig_cs5435_54p-r0/plugins/psuutil.py index 70d50e6c3458..442026775a5e 100755 --- a/device/cig/x86_64-cig_cs5435_54p-r0/plugins/psuutil.py +++ b/device/cig/x86_64-cig_cs5435_54p-r0/plugins/psuutil.py @@ -22,8 +22,8 @@ class PsuUtil(PsuBase): def __init__(self): PsuBase.__init__(self) - # Get sysfs attribute + def get_attr_value(self, attr_path): retval = 'ERR' @@ -57,7 +57,7 @@ def get_psu_status(self, index): """ status = 0 attr_file = 'psu_power_good' - attr_path = self.SYSFS_PSU_DIR[index-1] +'/' + attr_file + attr_path = self.SYSFS_PSU_DIR[index-1] + '/' + attr_file attr_value = self.get_attr_value(attr_path) @@ -65,7 +65,7 @@ def get_psu_status(self, index): attr_value = int(attr_value, 16) # Check for PSU status if (attr_value == 1): - status = 1 + status = 1 return status @@ -78,8 +78,8 @@ def get_psu_presence(self, index): """ status = 0 psu_absent = 0 - attr_file ='psu_present' - attr_path = self.SYSFS_PSU_DIR[index-1] +'/' + attr_file + attr_file = 'psu_present' + attr_path = self.SYSFS_PSU_DIR[index-1] + '/' + attr_file attr_value = self.get_attr_value(attr_path) @@ -87,7 +87,6 @@ def get_psu_presence(self, index): attr_value = int(attr_value, 16) # Check for PSU presence if (attr_value == 1): - status = 1 + status = 1 return status - diff --git a/device/cig/x86_64-cig_cs5435_54p-r0/plugins/sfputil.py b/device/cig/x86_64-cig_cs5435_54p-r0/plugins/sfputil.py index 1e5f95a32a90..2d6827300457 100755 --- a/device/cig/x86_64-cig_cs5435_54p-r0/plugins/sfputil.py +++ b/device/cig/x86_64-cig_cs5435_54p-r0/plugins/sfputil.py @@ -2,7 +2,7 @@ import time from sonic_sfp.sfputilbase import SfpUtilBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class SfpUtil(SfpUtilBase): @@ -17,60 +17,60 @@ class SfpUtil(SfpUtilBase): _global_port_pres_dict = {} _port_to_i2c_mapping = { - 1 : 8, - 2 : 9, - 3 : 10, - 4 : 11, - 5 : 12, - 6 : 13, - 7 : 14, - 8 : 15, - 9 : 16, + 1: 8, + 2: 9, + 3: 10, + 4: 11, + 5: 12, + 6: 13, + 7: 14, + 8: 15, + 9: 16, 10: 17, - 11 : 18, - 12 : 19, - 13 : 20, - 14 : 21, - 15 : 22, - 16 : 23, - 17 : 24, - 18 : 25, - 19 : 26, - 20 : 27, - 21 : 28, - 22 : 29, - 23 : 30, - 24 : 31, - 25 : 32, - 26 : 33, - 27 : 34, - 28 : 35, - 29 : 36, - 30 : 37, - 31 : 38, - 32 : 39, - 33 : 40, - 34 : 41, - 35 : 42, - 36 : 43, - 37 : 44, - 38 : 45, - 39 : 46, - 40 : 47, - 41 : 48, - 42 : 49, - 43 : 50, - 44 : 51, - 45 : 52, - 46 : 53, - 47 : 54, - 48 : 55, - 49 : 56, - 50 : 57, - 51 : 60, - 52 : 61, - 53 : 62, - 54 : 63, + 11: 18, + 12: 19, + 13: 20, + 14: 21, + 15: 22, + 16: 23, + 17: 24, + 18: 25, + 19: 26, + 20: 27, + 21: 28, + 22: 29, + 23: 30, + 24: 31, + 25: 32, + 26: 33, + 27: 34, + 28: 35, + 29: 36, + 30: 37, + 31: 38, + 32: 39, + 33: 40, + 34: 41, + 35: 42, + 36: 43, + 37: 44, + 38: 45, + 39: 46, + 40: 47, + 41: 48, + 42: 49, + 43: 50, + 44: 51, + 45: 52, + 46: 53, + 47: 54, + 48: 55, + 49: 56, + 50: 57, + 51: 60, + 52: 61, + 53: 62, + 54: 63, } _qsfp_ports = list(range(_qsfp_port_start, _ports_in_block + 1)) @@ -83,7 +83,6 @@ def get_presence(self, port_num): path = "/sys/bus/i2c/devices/{0}-0050/sfp_is_present" port_ps = path.format(self._port_to_i2c_mapping[port_num]) - try: reg_file = open(port_ps) except IOError as e: @@ -116,7 +115,6 @@ def init_global_port_presence(self): for port_num in range(self.port_start, (self.port_end + 1)): self._global_port_pres_dict[port_num] = '0' - def __init__(self): eeprom_path = '/sys/bus/i2c/devices/{0}-0050/sfp_eeprom' for x in range(self._port_start, self._port_end + 1): @@ -140,7 +138,7 @@ def reset(self, port_num): print("Error: unable to open file: %s" % str(e)) return False - #toggle reset + # toggle reset reg_file.seek(0) reg_file.write('1') time.sleep(1) @@ -156,13 +154,13 @@ def set_low_power_mode(self, port_num, lpmode): pre_value = self.get_presence(port_num) if pre_value == False: - return False + return False path = "/sys/bus/i2c/devices/{0}-0050/sfp_lpmode" port_ps = path.format(self._port_to_i2c_mapping[port_num]) try: - reg_file = open(port_ps,'w') + reg_file = open(port_ps, 'w') except IOError as e: print("Error: unable to open file: %s" % str(e)) return False @@ -177,7 +175,6 @@ def set_low_power_mode(self, port_num, lpmode): return True - def get_low_power_mode(self, port_num): # Check for invalid port_num @@ -230,7 +227,6 @@ def get_transceiver_change_event(self): time.sleep(0.5) - @property def port_start(self): return self._port_start @@ -245,4 +241,4 @@ def qsfp_ports(self): @property def port_to_eeprom_mapping(self): - return self._port_to_eeprom_mapping + return self._port_to_eeprom_mapping diff --git a/device/cig/x86_64-cig_cs6436_54p-r0/plugins/eeprom.py b/device/cig/x86_64-cig_cs6436_54p-r0/plugins/eeprom.py index ce0e273f2203..c068c04dac6d 100755 --- a/device/cig/x86_64-cig_cs6436_54p-r0/plugins/eeprom.py +++ b/device/cig/x86_64-cig_cs6436_54p-r0/plugins/eeprom.py @@ -8,10 +8,12 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/7-0057/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/cig/x86_64-cig_cs6436_54p-r0/plugins/psuutil.py b/device/cig/x86_64-cig_cs6436_54p-r0/plugins/psuutil.py index 70d50e6c3458..442026775a5e 100755 --- a/device/cig/x86_64-cig_cs6436_54p-r0/plugins/psuutil.py +++ b/device/cig/x86_64-cig_cs6436_54p-r0/plugins/psuutil.py @@ -22,8 +22,8 @@ class PsuUtil(PsuBase): def __init__(self): PsuBase.__init__(self) - # Get sysfs attribute + def get_attr_value(self, attr_path): retval = 'ERR' @@ -57,7 +57,7 @@ def get_psu_status(self, index): """ status = 0 attr_file = 'psu_power_good' - attr_path = self.SYSFS_PSU_DIR[index-1] +'/' + attr_file + attr_path = self.SYSFS_PSU_DIR[index-1] + '/' + attr_file attr_value = self.get_attr_value(attr_path) @@ -65,7 +65,7 @@ def get_psu_status(self, index): attr_value = int(attr_value, 16) # Check for PSU status if (attr_value == 1): - status = 1 + status = 1 return status @@ -78,8 +78,8 @@ def get_psu_presence(self, index): """ status = 0 psu_absent = 0 - attr_file ='psu_present' - attr_path = self.SYSFS_PSU_DIR[index-1] +'/' + attr_file + attr_file = 'psu_present' + attr_path = self.SYSFS_PSU_DIR[index-1] + '/' + attr_file attr_value = self.get_attr_value(attr_path) @@ -87,7 +87,6 @@ def get_psu_presence(self, index): attr_value = int(attr_value, 16) # Check for PSU presence if (attr_value == 1): - status = 1 + status = 1 return status - diff --git a/device/cig/x86_64-cig_cs6436_54p-r0/plugins/sfputil.py b/device/cig/x86_64-cig_cs6436_54p-r0/plugins/sfputil.py index 1e5f95a32a90..2d6827300457 100755 --- a/device/cig/x86_64-cig_cs6436_54p-r0/plugins/sfputil.py +++ b/device/cig/x86_64-cig_cs6436_54p-r0/plugins/sfputil.py @@ -2,7 +2,7 @@ import time from sonic_sfp.sfputilbase import SfpUtilBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class SfpUtil(SfpUtilBase): @@ -17,60 +17,60 @@ class SfpUtil(SfpUtilBase): _global_port_pres_dict = {} _port_to_i2c_mapping = { - 1 : 8, - 2 : 9, - 3 : 10, - 4 : 11, - 5 : 12, - 6 : 13, - 7 : 14, - 8 : 15, - 9 : 16, + 1: 8, + 2: 9, + 3: 10, + 4: 11, + 5: 12, + 6: 13, + 7: 14, + 8: 15, + 9: 16, 10: 17, - 11 : 18, - 12 : 19, - 13 : 20, - 14 : 21, - 15 : 22, - 16 : 23, - 17 : 24, - 18 : 25, - 19 : 26, - 20 : 27, - 21 : 28, - 22 : 29, - 23 : 30, - 24 : 31, - 25 : 32, - 26 : 33, - 27 : 34, - 28 : 35, - 29 : 36, - 30 : 37, - 31 : 38, - 32 : 39, - 33 : 40, - 34 : 41, - 35 : 42, - 36 : 43, - 37 : 44, - 38 : 45, - 39 : 46, - 40 : 47, - 41 : 48, - 42 : 49, - 43 : 50, - 44 : 51, - 45 : 52, - 46 : 53, - 47 : 54, - 48 : 55, - 49 : 56, - 50 : 57, - 51 : 60, - 52 : 61, - 53 : 62, - 54 : 63, + 11: 18, + 12: 19, + 13: 20, + 14: 21, + 15: 22, + 16: 23, + 17: 24, + 18: 25, + 19: 26, + 20: 27, + 21: 28, + 22: 29, + 23: 30, + 24: 31, + 25: 32, + 26: 33, + 27: 34, + 28: 35, + 29: 36, + 30: 37, + 31: 38, + 32: 39, + 33: 40, + 34: 41, + 35: 42, + 36: 43, + 37: 44, + 38: 45, + 39: 46, + 40: 47, + 41: 48, + 42: 49, + 43: 50, + 44: 51, + 45: 52, + 46: 53, + 47: 54, + 48: 55, + 49: 56, + 50: 57, + 51: 60, + 52: 61, + 53: 62, + 54: 63, } _qsfp_ports = list(range(_qsfp_port_start, _ports_in_block + 1)) @@ -83,7 +83,6 @@ def get_presence(self, port_num): path = "/sys/bus/i2c/devices/{0}-0050/sfp_is_present" port_ps = path.format(self._port_to_i2c_mapping[port_num]) - try: reg_file = open(port_ps) except IOError as e: @@ -116,7 +115,6 @@ def init_global_port_presence(self): for port_num in range(self.port_start, (self.port_end + 1)): self._global_port_pres_dict[port_num] = '0' - def __init__(self): eeprom_path = '/sys/bus/i2c/devices/{0}-0050/sfp_eeprom' for x in range(self._port_start, self._port_end + 1): @@ -140,7 +138,7 @@ def reset(self, port_num): print("Error: unable to open file: %s" % str(e)) return False - #toggle reset + # toggle reset reg_file.seek(0) reg_file.write('1') time.sleep(1) @@ -156,13 +154,13 @@ def set_low_power_mode(self, port_num, lpmode): pre_value = self.get_presence(port_num) if pre_value == False: - return False + return False path = "/sys/bus/i2c/devices/{0}-0050/sfp_lpmode" port_ps = path.format(self._port_to_i2c_mapping[port_num]) try: - reg_file = open(port_ps,'w') + reg_file = open(port_ps, 'w') except IOError as e: print("Error: unable to open file: %s" % str(e)) return False @@ -177,7 +175,6 @@ def set_low_power_mode(self, port_num, lpmode): return True - def get_low_power_mode(self, port_num): # Check for invalid port_num @@ -230,7 +227,6 @@ def get_transceiver_change_event(self): time.sleep(0.5) - @property def port_start(self): return self._port_start @@ -245,4 +241,4 @@ def qsfp_ports(self): @property def port_to_eeprom_mapping(self): - return self._port_to_eeprom_mapping + return self._port_to_eeprom_mapping diff --git a/device/cig/x86_64-cig_cs6436_56p-r0/plugins/eeprom.py b/device/cig/x86_64-cig_cs6436_56p-r0/plugins/eeprom.py index e22124e5fc89..ae5a8385d96c 100755 --- a/device/cig/x86_64-cig_cs6436_56p-r0/plugins/eeprom.py +++ b/device/cig/x86_64-cig_cs6436_56p-r0/plugins/eeprom.py @@ -9,10 +9,12 @@ from sonic_eeprom import eeprom_tlvinfo import subprocess except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/7-0057/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/cig/x86_64-cig_cs6436_56p-r0/plugins/psuutil.py b/device/cig/x86_64-cig_cs6436_56p-r0/plugins/psuutil.py index 70d50e6c3458..442026775a5e 100755 --- a/device/cig/x86_64-cig_cs6436_56p-r0/plugins/psuutil.py +++ b/device/cig/x86_64-cig_cs6436_56p-r0/plugins/psuutil.py @@ -22,8 +22,8 @@ class PsuUtil(PsuBase): def __init__(self): PsuBase.__init__(self) - # Get sysfs attribute + def get_attr_value(self, attr_path): retval = 'ERR' @@ -57,7 +57,7 @@ def get_psu_status(self, index): """ status = 0 attr_file = 'psu_power_good' - attr_path = self.SYSFS_PSU_DIR[index-1] +'/' + attr_file + attr_path = self.SYSFS_PSU_DIR[index-1] + '/' + attr_file attr_value = self.get_attr_value(attr_path) @@ -65,7 +65,7 @@ def get_psu_status(self, index): attr_value = int(attr_value, 16) # Check for PSU status if (attr_value == 1): - status = 1 + status = 1 return status @@ -78,8 +78,8 @@ def get_psu_presence(self, index): """ status = 0 psu_absent = 0 - attr_file ='psu_present' - attr_path = self.SYSFS_PSU_DIR[index-1] +'/' + attr_file + attr_file = 'psu_present' + attr_path = self.SYSFS_PSU_DIR[index-1] + '/' + attr_file attr_value = self.get_attr_value(attr_path) @@ -87,7 +87,6 @@ def get_psu_presence(self, index): attr_value = int(attr_value, 16) # Check for PSU presence if (attr_value == 1): - status = 1 + status = 1 return status - diff --git a/device/cig/x86_64-cig_cs6436_56p-r0/plugins/sfputil.py b/device/cig/x86_64-cig_cs6436_56p-r0/plugins/sfputil.py index 019592b83454..9c31083f5c23 100755 --- a/device/cig/x86_64-cig_cs6436_56p-r0/plugins/sfputil.py +++ b/device/cig/x86_64-cig_cs6436_56p-r0/plugins/sfputil.py @@ -2,7 +2,7 @@ import time from sonic_sfp.sfputilbase import SfpUtilBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class SfpUtil(SfpUtilBase): @@ -17,62 +17,62 @@ class SfpUtil(SfpUtilBase): _global_port_pres_dict = {} _port_to_i2c_mapping = { - 1 : 8, - 2 : 9, - 3 : 10, - 4 : 11, - 5 : 12, - 6 : 13, - 7 : 14, - 8 : 15, - 9 : 16, + 1: 8, + 2: 9, + 3: 10, + 4: 11, + 5: 12, + 6: 13, + 7: 14, + 8: 15, + 9: 16, 10: 17, - 11 : 18, - 12 : 19, - 13 : 20, - 14 : 21, - 15 : 22, - 16 : 23, - 17 : 24, - 18 : 25, - 19 : 26, - 20 : 27, - 21 : 28, - 22 : 29, - 23 : 30, - 24 : 31, - 25 : 32, - 26 : 33, - 27 : 34, - 28 : 35, - 29 : 36, - 30 : 37, - 31 : 38, - 32 : 39, - 33 : 40, - 34 : 41, - 35 : 42, - 36 : 43, - 37 : 44, - 38 : 45, - 39 : 46, - 40 : 47, - 41 : 48, - 42 : 49, - 43 : 50, - 44 : 51, - 45 : 52, - 46 : 53, - 47 : 54, - 48 : 55, - 49 : 56, - 50 : 57, - 51 : 58, - 52 : 59, - 53 : 60, - 54 : 61, - 55 : 62, - 56 : 63, + 11: 18, + 12: 19, + 13: 20, + 14: 21, + 15: 22, + 16: 23, + 17: 24, + 18: 25, + 19: 26, + 20: 27, + 21: 28, + 22: 29, + 23: 30, + 24: 31, + 25: 32, + 26: 33, + 27: 34, + 28: 35, + 29: 36, + 30: 37, + 31: 38, + 32: 39, + 33: 40, + 34: 41, + 35: 42, + 36: 43, + 37: 44, + 38: 45, + 39: 46, + 40: 47, + 41: 48, + 42: 49, + 43: 50, + 44: 51, + 45: 52, + 46: 53, + 47: 54, + 48: 55, + 49: 56, + 50: 57, + 51: 58, + 52: 59, + 53: 60, + 54: 61, + 55: 62, + 56: 63, } _qsfp_ports = list(range(_qsfp_port_start, _ports_in_block + 1)) @@ -85,7 +85,6 @@ def get_presence(self, port_num): path = "/sys/bus/i2c/devices/{0}-0050/sfp_is_present" port_ps = path.format(self._port_to_i2c_mapping[port_num]) - try: reg_file = open(port_ps) except IOError as e: @@ -118,7 +117,6 @@ def init_global_port_presence(self): for port_num in range(self.port_start, (self.port_end + 1)): self._global_port_pres_dict[port_num] = '0' - def __init__(self): eeprom_path = '/sys/bus/i2c/devices/{0}-0050/sfp_eeprom' for x in range(self._port_start, self._port_end + 1): @@ -142,7 +140,7 @@ def reset(self, port_num): print("Error: unable to open file: %s" % str(e)) return False - #toggle reset + # toggle reset reg_file.seek(0) reg_file.write('1') time.sleep(1) @@ -158,13 +156,13 @@ def set_low_power_mode(self, port_num, lpmode): pre_value = self.get_presence(port_num) if pre_value == False: - return False + return False path = "/sys/bus/i2c/devices/{0}-0050/sfp_lpmode" port_ps = path.format(self._port_to_i2c_mapping[port_num]) try: - reg_file = open(port_ps,'w') + reg_file = open(port_ps, 'w') except IOError as e: print("Error: unable to open file: %s" % str(e)) return False @@ -179,7 +177,6 @@ def set_low_power_mode(self, port_num, lpmode): return True - def get_low_power_mode(self, port_num): # Check for invalid port_num @@ -232,7 +229,6 @@ def get_transceiver_change_event(self): time.sleep(0.5) - @property def port_start(self): return self._port_start @@ -247,4 +243,4 @@ def qsfp_ports(self): @property def port_to_eeprom_mapping(self): - return self._port_to_eeprom_mapping + return self._port_to_eeprom_mapping diff --git a/device/common/pddf/plugins/eeprom.py b/device/common/pddf/plugins/eeprom.py index c645cbd8bc04..cf7215e0c9ac 100755 --- a/device/common/pddf/plugins/eeprom.py +++ b/device/common/pddf/plugins/eeprom.py @@ -7,11 +7,12 @@ #from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): global pddf_obj global plugin_data @@ -22,4 +23,3 @@ def __init__(self, name, path, cpld_root, ro): # system EEPROM always has device name EEPROM1 self.eeprom_path = pddf_obj.get_path("EEPROM1", "eeprom") super(board, self).__init__(self.eeprom_path, 0, '', True) - diff --git a/device/common/pddf/plugins/fanutil.py b/device/common/pddf/plugins/fanutil.py index 5020586130b6..f34c260035e8 100755 --- a/device/common/pddf/plugins/fanutil.py +++ b/device/common/pddf/plugins/fanutil.py @@ -18,7 +18,8 @@ try: from sonic_fan.fan_base import FanBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class FanUtil(FanBase): """PDDF generic FAN util class""" @@ -33,18 +34,18 @@ def __init__(self): pddf_obj = pddfparse.PddfParse() self.platform = pddf_obj.get_platform() - self.num_fans = (self.platform['num_fantrays'] * self.platform['num_fans_pertray'] ) + self.num_fans = (self.platform['num_fantrays'] * self.platform['num_fans_pertray']) def get_num_fans(self): return self.num_fans def get_presence(self, idx): # 1 based fan index - if idx<1 or idx>self.num_fans: - print("Invalid fan index %d\n"%idx) + if idx < 1 or idx > self.num_fans: + print("Invalid fan index %d\n" % idx) return False - attr_name = "fan"+ str(idx) +"_present" + attr_name = "fan" + str(idx) + "_present" output = pddf_obj.get_attr_name_output("FAN-CTRL", attr_name) if not output: return False @@ -63,8 +64,8 @@ def get_presence(self, idx): def get_status(self, idx): # 1 based fan index - if idx<1 or idx>self.num_fans: - print("Invalid fan index %d\n"%idx) + if idx < 1 or idx > self.num_fans: + print("Invalid fan index %d\n" % idx) return False speed = self.get_speed(idx) @@ -73,8 +74,8 @@ def get_status(self, idx): def get_direction(self, idx): # 1 based fan index - if idx<1 or idx>self.num_fans: - print("Invalid fan index %d\n"%idx) + if idx < 1 or idx > self.num_fans: + print("Invalid fan index %d\n" % idx) return None attr = "fan" + str(idx) + "_direction" @@ -88,7 +89,6 @@ def get_direction(self, idx): val = val.rstrip() vmap = plugin_data['FAN']['direction'][mode]['valmap'] - if val in vmap: direction = vmap[val] else: @@ -97,7 +97,7 @@ def get_direction(self, idx): return direction def get_directions(self): - num_fan = self.get_num_fan(); + num_fan = self.get_num_fan() for i in range(1, num_fan+1): attr = "fan" + str(i) + "_direction" @@ -113,14 +113,14 @@ def get_directions(self): direction = vmap[str(val)] - print("FAN-%d direction is %s"%(i, direction)) + print("FAN-%d direction is %s" % (i, direction)) return 0 def get_speed(self, idx): # 1 based fan index - if idx<1 or idx>self.num_fans: - print("Invalid fan index %d\n"%idx) + if idx < 1 or idx > self.num_fans: + print("Invalid fan index %d\n" % idx) return 0 attr = "fan" + str(idx) + "_input" @@ -139,7 +139,7 @@ def get_speed(self, idx): return rpm_speed def get_speeds(self): - num_fan = self.get_num_fan(); + num_fan = self.get_num_fan() ret = "FAN_INDEX\t\tRPM\n" for i in range(1, num_fan+1): @@ -156,13 +156,13 @@ def get_speeds(self): else: frpm = int(val) - ret += "FAN-%d\t\t\t%d\n"%(i, frpm) + ret += "FAN-%d\t\t\t%d\n" % (i, frpm) return ret def set_speed(self, val): - if val<0 or val>100: - print("Error: Invalid speed %d. Please provide a valid speed percentage"%val) + if val < 0 or val > 100: + print("Error: Invalid speed %d. Please provide a valid speed percentage" % val) return False num_fan = self.num_fans @@ -172,7 +172,7 @@ def set_speed(self, val): else: duty_cycle_to_pwm = eval(plugin_data['FAN']['duty_cycle_to_pwm']) pwm = duty_cycle_to_pwm(val) - print("New Speed: %d%% - PWM value to be set is %d\n"%(val,pwm)) + print("New Speed: %d%% - PWM value to be set is %d\n" % (val, pwm)) for i in range(1, num_fan+1): attr = "fan" + str(i) + "_pwm" diff --git a/device/common/pddf/plugins/psuutil.py b/device/common/pddf/plugins/psuutil.py index a869b33440f3..dccb1ac1a155 100755 --- a/device/common/pddf/plugins/psuutil.py +++ b/device/common/pddf/plugins/psuutil.py @@ -23,7 +23,7 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class PsuUtil(PsuBase): @@ -46,7 +46,7 @@ def get_psu_status(self, index): if index is None: return False - device = "PSU" + "%d"%index + device = "PSU" + "%d" % index output = pddf_obj.get_attr_name_output(device, "psu_power_good") if not output: return False @@ -67,7 +67,7 @@ def get_psu_presence(self, index): return False status = 0 - device = "PSU" + "%d"%index + device = "PSU" + "%d" % index output = pddf_obj.get_attr_name_output(device, "psu_present") if not output: return False @@ -86,17 +86,17 @@ def get_powergood_status(self, idx): if idx is None: return False - if idx<1 or idx>self.platform['num_psus']: - print("Invalid index %d\n"%idx) + if idx < 1 or idx > self.platform['num_psus']: + print("Invalid index %d\n" % idx) return False - device = "PSU"+"%d"%(idx) + device = "PSU"+"%d" % (idx) output = pddf_obj.get_attr_name_output(device, "psu_power_good") if not output: return False mode = output['mode'] - status = output ['status'] + status = output['status'] vmap = plugin_data['PSU']['psu_power_good'][mode]['valmap'] @@ -109,11 +109,11 @@ def get_model(self, idx): if idx is None: return None - if idx<1 or idx>self.platform['num_psus']: - print("Invalid index %d\n"%idx) + if idx < 1 or idx > self.platform['num_psus']: + print("Invalid index %d\n" % idx) return None - device = "PSU"+"%d"%(idx) + device = "PSU"+"%d" % (idx) output = pddf_obj.get_attr_name_output(device, "psu_model_name") if not output: return None @@ -130,11 +130,11 @@ def get_mfr_id(self, idx): if idx is None: return None - if idx<1 or idx>self.platform['num_psus']: - print("Invalid index %d\n"%idx) + if idx < 1 or idx > self.platform['num_psus']: + print("Invalid index %d\n" % idx) return None - device = "PSU"+"%d"%(idx) + device = "PSU"+"%d" % (idx) output = pddf_obj.get_attr_name_output(device, "psu_mfr_id") if not output: return None @@ -147,11 +147,11 @@ def get_serial(self, idx): if idx is None: return None - if idx<1 or idx>self.platform['num_psus']: - print("Invalid index %d\n"%idx) + if idx < 1 or idx > self.platform['num_psus']: + print("Invalid index %d\n" % idx) return None - device = "PSU"+"%d"%(idx) + device = "PSU"+"%d" % (idx) output = pddf_obj.get_attr_name_output(device, "psu_serial_num") if not output: return None @@ -164,11 +164,11 @@ def get_direction(self, idx): if idx is None: return None - if idx<1 or idx>self.platform['num_psus']: - print("Invalid index %d\n"%idx) + if idx < 1 or idx > self.platform['num_psus']: + print("Invalid index %d\n" % idx) return None - device = "PSU"+"%d"%(idx) + device = "PSU"+"%d" % (idx) output = pddf_obj.get_attr_name_output(device, "psu_fan_dir") if not output: return None @@ -188,11 +188,11 @@ def get_output_voltage(self, idx): if idx is None: return 0.0 - if idx<1 or idx>self.platform['num_psus']: - print("Invalid index %d\n"%idx) + if idx < 1 or idx > self.platform['num_psus']: + print("Invalid index %d\n" % idx) return 0.0 - device = "PSU"+"%d"%(idx) + device = "PSU"+"%d" % (idx) output = pddf_obj.get_attr_name_output(device, "psu_v_out") if not output: return 0.0 @@ -206,11 +206,11 @@ def get_output_current(self, idx): if idx is None: return 0.0 - if idx<1 or idx>self.platform['num_psus']: - print("Invalid index %d\n"%idx) + if idx < 1 or idx > self.platform['num_psus']: + print("Invalid index %d\n" % idx) return 0.0 - device = "PSU"+"%d"%(idx) + device = "PSU"+"%d" % (idx) output = pddf_obj.get_attr_name_output(device, "psu_i_out") if not output: return 0.0 @@ -224,11 +224,11 @@ def get_output_power(self, idx): if idx is None: return 0.0 - if idx<1 or idx>self.platform['num_psus']: - print("Invalid index %d\n"%idx) + if idx < 1 or idx > self.platform['num_psus']: + print("Invalid index %d\n" % idx) return 0.0 - device = "PSU"+"%d"%(idx) + device = "PSU"+"%d" % (idx) output = pddf_obj.get_attr_name_output(device, "psu_p_out") if not output: return 0.0 @@ -242,16 +242,15 @@ def get_fan_rpm(self, idx, fan_idx): if idx is None or fan_idx is None: return 0 - if idx<1 or idx>self.platform['num_psus']: - print("Invalid index %d\n"%idx) + if idx < 1 or idx > self.platform['num_psus']: + print("Invalid index %d\n" % idx) return 0 - - device = "PSU"+"%d"%(idx) + device = "PSU"+"%d" % (idx) num_fans = pddf_obj.get_num_psu_fans(device) - if fan_idx<1 or fan_idx>num_fans: - print("Invalid PSU-fan index %d\n"%fan_idx) + if fan_idx < 1 or fan_idx > num_fans: + print("Invalid PSU-fan index %d\n" % fan_idx) return 0 output = pddf_obj.get_attr_name_output(device, "psu_fan"+str(fan_idx)+"_speed_rpm") diff --git a/device/common/pddf/plugins/sfputil.py b/device/common/pddf/plugins/sfputil.py index 0b058e5df57a..35e1d19b15f3 100755 --- a/device/common/pddf/plugins/sfputil.py +++ b/device/common/pddf/plugins/sfputil.py @@ -9,7 +9,8 @@ from ctypes import create_string_buffer from sonic_sfp.sfputilbase import SfpUtilBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class SfpUtil(SfpUtilBase): """Platform generic PDDF SfpUtil class""" @@ -34,8 +35,8 @@ def __init__(self): self._port_end = self.get_num_ports() for port_num in range(self._port_start, self._port_end): - device = "PORT" + "%d"%(port_num+1) - port_eeprom_path = pddf_obj.get_path(device,"eeprom") + device = "PORT" + "%d" % (port_num+1) + port_eeprom_path = pddf_obj.get_path(device, "eeprom") self._port_to_eeprom_mapping[port_num] = port_eeprom_path port_type = pddf_obj.get_device_type(device) self._port_to_type_mapping[port_num] = port_type @@ -54,7 +55,7 @@ def get_presence(self, port_num): if port_num < self._port_start or port_num > self._port_end: return False - device = "PORT" + "%d"%(port_num+1) + device = "PORT" + "%d" % (port_num+1) output = pddf_obj.get_attr_name_output(device, 'xcvr_present') if not output: return False @@ -103,8 +104,8 @@ def reset(self, port_num): if port_num < self._port_start or port_num > self._port_end: return False - device = "PORT" + "%d"%(port_num+1) - port_ps = pddf_obj.get_path(device,"xcvr_reset") + device = "PORT" + "%d" % (port_num+1) + port_ps = pddf_obj.get_path(device, "xcvr_reset") if port_ps is None: return False @@ -133,29 +134,29 @@ def get_low_power_mode(self, port_num): if not self.get_presence(port_num): return False - device = "PORT" + "%d"%(port_num+1) + device = "PORT" + "%d" % (port_num+1) output = pddf_obj.get_attr_name_output(device, 'xcvr_lpmode') if not output: if port_num not in self.qsfp_ports: - return False # Read from eeprom only for QSFP ports + return False # Read from eeprom only for QSFP ports try: eeprom = None eeprom = open(self.port_to_eeprom_mapping[port_num], "rb") # check for valid connector type eeprom.seek(2) ctype = eeprom.read(1) - if ctype in ['21','23']: + if ctype in ['21', '23']: return False eeprom.seek(93) lpmode = ord(eeprom.read(1)) if ((lpmode & 0x3) == 0x3): - return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 + return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 else: - return 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 + return 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 except IOError as e: print("Error: unable to open file: %s" % str(e)) return False @@ -178,24 +179,24 @@ def set_low_power_mode(self, port_num, lpmode): return False if not self.get_presence(port_num): - return False # Port is not present, unable to set the eeprom + return False # Port is not present, unable to set the eeprom - device = "PORT" + "%d"%(port_num+1) - port_ps = pddf_obj.get_path(device,"xcvr_lpmode") + device = "PORT" + "%d" % (port_num+1) + port_ps = pddf_obj.get_path(device, "xcvr_lpmode") if port_ps is None: if port_num not in self.qsfp_ports: - return False # Write to eeprom only for QSFP ports + return False # Write to eeprom only for QSFP ports try: eeprom = None eeprom = open(self.port_to_eeprom_mapping[port_num], "r+b") # check for valid connector type eeprom.seek(2) ctype = eeprom.read(1) - if ctype in ['21','23']: + if ctype in ['21', '23']: 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) @@ -230,6 +231,5 @@ def get_transceiver_change_event(self): """ raise NotImplementedError - def dump_sysfs(self): return pddf_obj.cli_dump_dsysfs('xcvr') diff --git a/device/common/pddf/plugins/sysstatutil.py b/device/common/pddf/plugins/sysstatutil.py index f746f8ff3723..af4dd5915361 100755 --- a/device/common/pddf/plugins/sysstatutil.py +++ b/device/common/pddf/plugins/sysstatutil.py @@ -4,8 +4,10 @@ import pddfparse import json + class SYSStatusUtil(): """Platform-specific SYSStatus class""" + def __init__(self): global pddf_obj global plugin_data @@ -16,68 +18,65 @@ def __init__(self): def get_board_info(self): device = "SYSSTATUS" - node = pddf_obj.get_path(device,"board_info") + node = pddf_obj.get_path(device, "board_info") if node is None: return False try: with open(node, 'r') as f: status = f.read() - print("board_info : %s" %status) + print("board_info : %s" % status) except IOError: return False def get_cpld_versio(self): device = "SYSSTATUS" - node = pddf_obj.get_path(device,"cpld1_version") + node = pddf_obj.get_path(device, "cpld1_version") if node is None: return False try: with open(node, 'r') as f: status = f.read() - print("cpld1_version : %s" %status) + print("cpld1_version : %s" % status) except IOError: return False def get_power_module_status(self): - device = "SYSSTATUS" - node = pddf_obj.get_path(device,"power_module_status") - if node is None: - return False - try: - with open(node, 'r') as f: - status = f.read() - print("power_module_status : %s" %status) - except IOError: - return False - + device = "SYSSTATUS" + node = pddf_obj.get_path(device, "power_module_status") + if node is None: + return False + try: + with open(node, 'r') as f: + status = f.read() + print("power_module_status : %s" % status) + except IOError: + return False def get_system_reset_status(self): device = "SYSSTATUS" - for i in range(1,8): - node = pddf_obj.get_path(device,"system_reset"+str(i)) - if node is None: - return False - try: - with open(node, 'r') as f: - status = f.read() - print("system_reset%s : %s" %(i, status)) - except IOError: - print("system_reset%s not supported" %i) - + for i in range(1, 8): + node = pddf_obj.get_path(device, "system_reset"+str(i)) + if node is None: + return False + try: + with open(node, 'r') as f: + status = f.read() + print("system_reset%s : %s" % (i, status)) + except IOError: + print("system_reset%s not supported" % i) def get_misc_status(self): device = "SYSSTATUS" - for i in range(1,3): - node = pddf_obj.get_path(device,"misc"+str(i)) - if node is None: - return False - try: - with open(node, 'r') as f: - status = f.read() - print("misc%s : %s" %(i, status)) - except IOError: - print("system_reset%s not supported" %i) - + for i in range(1, 3): + node = pddf_obj.get_path(device, "misc"+str(i)) + if node is None: + return False + try: + with open(node, 'r') as f: + status = f.read() + print("misc%s : %s" % (i, status)) + except IOError: + print("system_reset%s not supported" % i) def dump_sysfs(self): return pddf_obj.cli_dump_dsysfs('sys-status') diff --git a/device/common/pddf/plugins/thermalutil.py b/device/common/pddf/plugins/thermalutil.py index 5e6ecf9da2ee..6aef47b7e924 100755 --- a/device/common/pddf/plugins/thermalutil.py +++ b/device/common/pddf/plugins/thermalutil.py @@ -4,6 +4,7 @@ sys.path.append('/usr/share/sonic/platform/plugins') import pddfparse + class ThermalUtil: def __init__(self): global pddf_obj @@ -14,23 +15,24 @@ def __init__(self): pddf_obj = pddfparse.PddfParse() self.platform = pddf_obj.get_platform() self.num_thermals = self.platform['num_temps'] - self.info=[] + self.info = [] def get_num_thermals(self): return (self.num_thermals) def get_thermal_info(self): - list=[] + list = [] pddf_obj.get_device_list(list, "TEMP_SENSOR") list.sort() for dev in list: - data={} + data = {} device_name = dev['dev_info']['device_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)) + label = "%s-i2c-%d-%x" % (topo_info['dev_type'], + int(topo_info['parent_bus'], 0), int(topo_info['dev_addr'], 0)) attr_list = dev['i2c']['attr_list'] - data['device_name']=device_name - data['label']=label + data['device_name'] = device_name + data['label'] = label for attr in attr_list: attr_name = attr['attr_name'] node = pddf_obj.get_path(device_name, attr_name) @@ -45,17 +47,18 @@ def get_thermal_info(self): self.info.append(data) def show_thermal_temp_values(self, idx): - if idx<1 or idx>self.num_thermals: - print("Invalid temperature sensor idx %d"%idx) + if idx < 1 or idx > self.num_thermals: + print("Invalid temperature sensor idx %d" % idx) return None self.get_thermal_info() - thermal_name = "TEMP"+"%d"%idx - label="" - value="" + thermal_name = "TEMP"+"%d" % idx + label = "" + value = "" for temp in self.info: - if thermal_name==temp['device_name']: + if thermal_name == temp['device_name']: label = temp['label'] - value = "temp1\t %+.1f C (high = %+.1f C, hyst = %+.1f C)" % (temp['temp1_input'], temp['temp1_max'], temp['temp1_max_hyst']) + value = "temp1\t %+.1f C (high = %+.1f C, hyst = %+.1f C)" % ( + temp['temp1_input'], temp['temp1_max'], temp['temp1_max_hyst']) else: continue @@ -65,8 +68,8 @@ def show_temp_values(self): self.get_thermal_info() for temp in self.info: print(temp['label']) - print("temp1\t %+.1f C (high = %+.1f C, hyst = %+.1f C)" % (temp['temp1_input'], temp['temp1_max'], temp['temp1_max_hyst'])) - + print("temp1\t %+.1f C (high = %+.1f C, hyst = %+.1f C)" % + (temp['temp1_input'], temp['temp1_max'], temp['temp1_max_hyst'])) def dump_sysfs(self): return pddf_obj.cli_dump_dsysfs('temp-sensors') diff --git a/device/dell/x86_64-dell_s6000_s1220-r0/platform_reboot b/device/dell/x86_64-dell_s6000_s1220-r0/platform_reboot index 449a45bc57e9..d973f4f810e1 100755 --- a/device/dell/x86_64-dell_s6000_s1220-r0/platform_reboot +++ b/device/dell/x86_64-dell_s6000_s1220-r0/platform_reboot @@ -5,8 +5,9 @@ import os import struct NVRAM_RES = '/dev/nvram' -COLD_RESET = 0xE # Cold Reset -WARM_RESET = 0x6 # Warm Reset +COLD_RESET = 0xE # Cold Reset +WARM_RESET = 0x6 # Warm Reset + def io_reg_write(resource, offset, val): fd = os.open(resource, os.O_RDWR) @@ -28,18 +29,21 @@ def power_reset(val): p.write(str(int(val)) + '\n') p.flush() -def gpio_direction(pin,direction): + +def gpio_direction(pin, direction): kernpath = '/sys/class/gpio/gpio'+str(pin)+'/direction' with open(('kernpath'), 'w') as p: p.write(str(direction) + '\n') p.flush() -def gpio_set(pin,value): + +def gpio_set(pin, value): kernpath = '/sys/class/gpio/gpio'+str(pin)+'/value' with open(('kernpath'), 'w') as p: p.write(str(int(value)) + '\n') p.flush() + def gpio_export(value): with open('/sys/class/gpio/export', 'w') as p: p.write(str(int(value)) + '\n') @@ -50,8 +54,8 @@ if __name__ == "__main__": io_reg_write(NVRAM_RES, 0x49, COLD_RESET) if not os.path.isdir("/sys/class/gpio/gpio10"): gpio_export(10) - gpio_direction("10","out") - #Toggle GPIO10 pin (to reset MUX) - gpio_set("10",1) - gpio_set("10",0) + gpio_direction("10", "out") + # Toggle GPIO10 pin (to reset MUX) + gpio_set("10", 1) + gpio_set("10", 0) power_reset(1) diff --git a/device/dell/x86_64-dell_s6000_s1220-r0/plugins/psuutil.py b/device/dell/x86_64-dell_s6000_s1220-r0/plugins/psuutil.py index 537605f3975b..16318bca8162 100644 --- a/device/dell/x86_64-dell_s6000_s1220-r0/plugins/psuutil.py +++ b/device/dell/x86_64-dell_s6000_s1220-r0/plugins/psuutil.py @@ -21,7 +21,7 @@ def __init__(self): def get_cpld_register(self, reg_name): cpld_dir = "/sys/devices/platform/dell-s6000-cpld.0" retval = 'ERR' - reg_file = cpld_dir +'/' + reg_name + reg_file = cpld_dir + '/' + reg_name if (not os.path.isfile(reg_file)): return retval diff --git a/device/dell/x86_64-dell_s6000_s1220-r0/plugins/sfputil.py b/device/dell/x86_64-dell_s6000_s1220-r0/plugins/sfputil.py index 3f89d30ad630..f03415cbc7ea 100644 --- a/device/dell/x86_64-dell_s6000_s1220-r0/plugins/sfputil.py +++ b/device/dell/x86_64-dell_s6000_s1220-r0/plugins/sfputil.py @@ -55,7 +55,6 @@ def get_transceiver_status(self): return int(content, 16) - def __init__(self): eeprom_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-0050/eeprom" @@ -207,17 +206,17 @@ def get_transceiver_change_event(self, timeout=0): if timeout == 0: forever = True elif timeout > 0: - timeout = timeout / float(1000) # Convert to secs + timeout = timeout / float(1000) # Convert to secs else: print("get_transceiver_change_event:Invalid timeout value", timeout) return False, {} end_time = start_time + timeout if start_time > end_time: - print('get_transceiver_change_event:' \ - 'time wrap / invalid timeout value', timeout) + print('get_transceiver_change_event:' + 'time wrap / invalid timeout value', timeout) - return False, {} # Time wrap or possibly incorrect timeout + return False, {} # Time wrap or possibly incorrect timeout while timeout >= 0: # Check for OIR events and return updated port_dict @@ -247,7 +246,7 @@ def get_transceiver_change_event(self, timeout=0): else: timeout = end_time - time.time() if timeout >= 1: - time.sleep(1) # We poll at 1 second granularity + time.sleep(1) # We poll at 1 second granularity else: if timeout > 0: time.sleep(timeout) diff --git a/device/dell/x86_64-dell_s6100_c2538-r0/plugins/eeprom.py b/device/dell/x86_64-dell_s6100_c2538-r0/plugins/eeprom.py index 664833deed39..e77f08fe873d 100644 --- a/device/dell/x86_64-dell_s6100_c2538-r0/plugins/eeprom.py +++ b/device/dell/x86_64-dell_s6100_c2538-r0/plugins/eeprom.py @@ -28,4 +28,4 @@ def serial_number_str(self, e): # 'results' is a list containing 3 elements, type (int), length (int), # and value (string) of the requested TLV - return results[2] + return results[2] diff --git a/device/dell/x86_64-dell_s6100_c2538-r0/plugins/psuutil.py b/device/dell/x86_64-dell_s6100_c2538-r0/plugins/psuutil.py index 0d2717331111..a29d45f939bf 100644 --- a/device/dell/x86_64-dell_s6100_c2538-r0/plugins/psuutil.py +++ b/device/dell/x86_64-dell_s6100_c2538-r0/plugins/psuutil.py @@ -14,6 +14,7 @@ HWMON_DIR = "/sys/devices/platform/SMF.512/hwmon/" HWMON_NODE = os.listdir(HWMON_DIR)[0] + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" @@ -60,7 +61,7 @@ def get_psu_status(self, index): psu_status = int(psu_status, 16) # Check for PSU statuse if (~psu_status & 0b1000) or (psu_status & 0b0100): - status = 1 + status = 1 return status @@ -77,6 +78,6 @@ def get_psu_presence(self, index): psu_presence = int(psu_presence, 16) # Check for PSU presence if (~psu_presence & 0b1): - status = 1 + status = 1 return status diff --git a/device/dell/x86_64-dell_s6100_c2538-r0/plugins/sfputil.py b/device/dell/x86_64-dell_s6100_c2538-r0/plugins/sfputil.py index efd77416ea19..a6a7cce72f56 100644 --- a/device/dell/x86_64-dell_s6100_c2538-r0/plugins/sfputil.py +++ b/device/dell/x86_64-dell_s6100_c2538-r0/plugins/sfputil.py @@ -31,70 +31,70 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _port_to_i2c_mapping = { - 0: [6, 18, 34, 50, 66], - 1: [6, 19, 35, 51, 67], - 2: [6, 20, 36, 52, 68], - 3: [6, 21, 37, 53, 69], - 4: [6, 22, 38, 54, 70], - 5: [6, 23, 39, 55, 71], - 6: [6, 24, 40, 56, 72], - 7: [6, 25, 41, 57, 73], - 8: [6, 26, 42, 58, 74], - 9: [6, 27, 43, 59, 75], - 10: [6, 28, 44, 60, 76], - 11: [6, 29, 45, 61, 77], - 12: [6, 30, 46, 62, 78], - 13: [6, 31, 47, 63, 79], - 14: [6, 32, 48, 64, 80], - 15: [6, 33, 49, 65, 81], - 16: [8, 18, 34, 50, 66], - 17: [8, 19, 35, 51, 67], - 18: [8, 20, 36, 52, 68], - 19: [8, 21, 37, 53, 69], - 20: [8, 22, 38, 54, 70], - 21: [8, 23, 39, 55, 71], - 22: [8, 24, 40, 56, 72], - 23: [8, 25, 41, 57, 73], - 24: [8, 26, 42, 58, 74], - 25: [8, 27, 43, 59, 75], - 26: [8, 28, 44, 60, 76], - 27: [8, 29, 45, 61, 77], - 28: [8, 30, 46, 62, 78], - 29: [8, 31, 47, 63, 79], - 30: [8, 32, 48, 64, 80], - 31: [8, 33, 49, 65, 81], - 32: [7, 18, 34, 50, 66], - 33: [7, 19, 35, 51, 67], - 34: [7, 20, 36, 52, 68], - 35: [7, 21, 37, 53, 69], - 36: [7, 22, 38, 54, 70], - 37: [7, 23, 39, 55, 71], - 38: [7, 24, 40, 56, 72], - 39: [7, 25, 41, 57, 73], - 40: [7, 26, 42, 58, 74], - 41: [7, 27, 43, 59, 75], - 42: [7, 28, 44, 60, 76], - 43: [7, 29, 45, 61, 77], - 44: [7, 30, 46, 62, 78], - 45: [7, 31, 47, 63, 79], - 46: [7, 32, 48, 64, 80], - 47: [7, 33, 49, 65, 81], - 48: [9, 18, 34, 50, 66], - 49: [9, 19, 35, 51, 67], - 50: [9, 20, 36, 52, 68], - 51: [9, 21, 37, 53, 69], - 52: [9, 22, 38, 54, 70], - 53: [9, 23, 39, 55, 71], - 54: [9, 24, 40, 56, 72], - 55: [9, 25, 41, 57, 73], - 56: [9, 26, 42, 58, 74], - 57: [9, 27, 43, 59, 75], - 58: [9, 28, 44, 60, 76], - 59: [9, 29, 45, 61, 77], - 60: [9, 30, 46, 62, 78], - 61: [9, 31, 47, 63, 79], - 62: [9, 32, 48, 64, 80], - 63: [9, 33, 49, 65, 81] + 0: [6, 18, 34, 50, 66], + 1: [6, 19, 35, 51, 67], + 2: [6, 20, 36, 52, 68], + 3: [6, 21, 37, 53, 69], + 4: [6, 22, 38, 54, 70], + 5: [6, 23, 39, 55, 71], + 6: [6, 24, 40, 56, 72], + 7: [6, 25, 41, 57, 73], + 8: [6, 26, 42, 58, 74], + 9: [6, 27, 43, 59, 75], + 10: [6, 28, 44, 60, 76], + 11: [6, 29, 45, 61, 77], + 12: [6, 30, 46, 62, 78], + 13: [6, 31, 47, 63, 79], + 14: [6, 32, 48, 64, 80], + 15: [6, 33, 49, 65, 81], + 16: [8, 18, 34, 50, 66], + 17: [8, 19, 35, 51, 67], + 18: [8, 20, 36, 52, 68], + 19: [8, 21, 37, 53, 69], + 20: [8, 22, 38, 54, 70], + 21: [8, 23, 39, 55, 71], + 22: [8, 24, 40, 56, 72], + 23: [8, 25, 41, 57, 73], + 24: [8, 26, 42, 58, 74], + 25: [8, 27, 43, 59, 75], + 26: [8, 28, 44, 60, 76], + 27: [8, 29, 45, 61, 77], + 28: [8, 30, 46, 62, 78], + 29: [8, 31, 47, 63, 79], + 30: [8, 32, 48, 64, 80], + 31: [8, 33, 49, 65, 81], + 32: [7, 18, 34, 50, 66], + 33: [7, 19, 35, 51, 67], + 34: [7, 20, 36, 52, 68], + 35: [7, 21, 37, 53, 69], + 36: [7, 22, 38, 54, 70], + 37: [7, 23, 39, 55, 71], + 38: [7, 24, 40, 56, 72], + 39: [7, 25, 41, 57, 73], + 40: [7, 26, 42, 58, 74], + 41: [7, 27, 43, 59, 75], + 42: [7, 28, 44, 60, 76], + 43: [7, 29, 45, 61, 77], + 44: [7, 30, 46, 62, 78], + 45: [7, 31, 47, 63, 79], + 46: [7, 32, 48, 64, 80], + 47: [7, 33, 49, 65, 81], + 48: [9, 18, 34, 50, 66], + 49: [9, 19, 35, 51, 67], + 50: [9, 20, 36, 52, 68], + 51: [9, 21, 37, 53, 69], + 52: [9, 22, 38, 54, 70], + 53: [9, 23, 39, 55, 71], + 54: [9, 24, 40, 56, 72], + 55: [9, 25, 41, 57, 73], + 56: [9, 26, 42, 58, 74], + 57: [9, 27, 43, 59, 75], + 58: [9, 28, 44, 60, 76], + 59: [9, 29, 45, 61, 77], + 60: [9, 30, 46, 62, 78], + 61: [9, 31, 47, 63, 79], + 62: [9, 32, 48, 64, 80], + 63: [9, 33, 49, 65, 81] } IOM_1_PORT_START = 0 @@ -172,69 +172,69 @@ def __init__(self): global port_to_eeprom_path for port_num in range(0, self.port_end + 1): - if port_num >= self.iom1_port_start and port_num <=\ - self.iom1_port_end: - assigned = 0 - # i2c-6 - for x in range(1, 5): - port_to_eeprom_path = eeprom_path.format( - self.port_to_i2c_mapping[port_num][0], - self.port_to_i2c_mapping[port_num][x]) - if (os.path.isfile(port_to_eeprom_path)): - self.port_to_eeprom_mapping[port_num] =\ - port_to_eeprom_path - assigned = 1 - elif (not assigned): - self.port_to_eeprom_mapping[port_num] =\ - "No IOM" - - elif(port_num >= self.iom2_port_start and - port_num <= self.iom2_port_end): - assigned = 0 - # i2c-8 - for x in range(1, 5): - port_to_eeprom_path = eeprom_path.format( - self.port_to_i2c_mapping[port_num][0], - self.port_to_i2c_mapping[port_num][x]) - if (os.path.isfile(port_to_eeprom_path)): - self.port_to_eeprom_mapping[port_num] =\ - port_to_eeprom_path - assigned = 1 - elif (not assigned): - self.port_to_eeprom_mapping[port_num] =\ - "No IOM" - - elif(port_num >= self.iom3_port_start and port_num <= - self.iom3_port_end): - assigned = 0 - # i2c-7 - for x in range(1, 5): - port_to_eeprom_path = eeprom_path.format( - self.port_to_i2c_mapping[port_num][0], - self.port_to_i2c_mapping[port_num][x]) - if (os.path.isfile(port_to_eeprom_path)): - self.port_to_eeprom_mapping[port_num] =\ - port_to_eeprom_path - assigned = 1 - elif (not assigned): - self.port_to_eeprom_mapping[port_num] =\ - "No IOM" - - elif(port_num >= self.iom4_port_start and port_num <= - self.iom4_port_end): - assigned = 0 - # i2c-9 - for x in range(1, 5): - port_to_eeprom_path = eeprom_path.format( - self.port_to_i2c_mapping[port_num][0], - self.port_to_i2c_mapping[port_num][x]) - if (os.path.isfile(port_to_eeprom_path)): - self.port_to_eeprom_mapping[port_num] =\ - port_to_eeprom_path - assigned = 1 - elif (not assigned): - self.port_to_eeprom_mapping[port_num] =\ - "No IOM" + if port_num >= self.iom1_port_start and port_num <=\ + self.iom1_port_end: + assigned = 0 + # i2c-6 + for x in range(1, 5): + port_to_eeprom_path = eeprom_path.format( + self.port_to_i2c_mapping[port_num][0], + self.port_to_i2c_mapping[port_num][x]) + if (os.path.isfile(port_to_eeprom_path)): + self.port_to_eeprom_mapping[port_num] =\ + port_to_eeprom_path + assigned = 1 + elif (not assigned): + self.port_to_eeprom_mapping[port_num] =\ + "No IOM" + + elif(port_num >= self.iom2_port_start and + port_num <= self.iom2_port_end): + assigned = 0 + # i2c-8 + for x in range(1, 5): + port_to_eeprom_path = eeprom_path.format( + self.port_to_i2c_mapping[port_num][0], + self.port_to_i2c_mapping[port_num][x]) + if (os.path.isfile(port_to_eeprom_path)): + self.port_to_eeprom_mapping[port_num] =\ + port_to_eeprom_path + assigned = 1 + elif (not assigned): + self.port_to_eeprom_mapping[port_num] =\ + "No IOM" + + elif(port_num >= self.iom3_port_start and port_num <= + self.iom3_port_end): + assigned = 0 + # i2c-7 + for x in range(1, 5): + port_to_eeprom_path = eeprom_path.format( + self.port_to_i2c_mapping[port_num][0], + self.port_to_i2c_mapping[port_num][x]) + if (os.path.isfile(port_to_eeprom_path)): + self.port_to_eeprom_mapping[port_num] =\ + port_to_eeprom_path + assigned = 1 + elif (not assigned): + self.port_to_eeprom_mapping[port_num] =\ + "No IOM" + + elif(port_num >= self.iom4_port_start and port_num <= + self.iom4_port_end): + assigned = 0 + # i2c-9 + for x in range(1, 5): + port_to_eeprom_path = eeprom_path.format( + self.port_to_i2c_mapping[port_num][0], + self.port_to_i2c_mapping[port_num][x]) + if (os.path.isfile(port_to_eeprom_path)): + self.port_to_eeprom_mapping[port_num] =\ + port_to_eeprom_path + assigned = 1 + elif (not assigned): + self.port_to_eeprom_mapping[port_num] =\ + "No IOM" SfpUtilBase.__init__(self) @@ -267,8 +267,8 @@ def get_presence(self, port_num): i2c_line = 17 try: - qsfp_path = self.BASE_VAL_PATH.format(i2c_line)+"qsfp_modprs" - reg_file = open(qsfp_path, "r") + qsfp_path = self.BASE_VAL_PATH.format(i2c_line)+"qsfp_modprs" + reg_file = open(qsfp_path, "r") except IOError as e: print("Error: unable to open file: %s" % str(e)) @@ -316,8 +316,8 @@ def get_low_power_mode(self, port_num): i2c_line = 17 try: - qsfp_path = self.BASE_VAL_PATH.format(i2c_line)+"qsfp_lpmode" - reg_file = open(qsfp_path, "r") + qsfp_path = self.BASE_VAL_PATH.format(i2c_line)+"qsfp_lpmode" + reg_file = open(qsfp_path, "r") except IOError as e: print("Error: unable to open file: %s" % str(e)) @@ -365,8 +365,8 @@ def set_low_power_mode(self, port_num, lpmode): i2c_line = 17 try: - qsfp_path = self.BASE_VAL_PATH.format(i2c_line)+"qsfp_lpmode" - reg_file = open(qsfp_path, "r+") + qsfp_path = self.BASE_VAL_PATH.format(i2c_line)+"qsfp_lpmode" + reg_file = open(qsfp_path, "r+") except IOError as e: print("Error: unable to open file: %s" % str(e)) @@ -426,8 +426,8 @@ def reset(self, port_num): i2c_line = 17 try: - qsfp_path = self.BASE_VAL_PATH.format(i2c_line)+"qsfp_lpmode" - reg_file = open(qsfp_path, "r+") + qsfp_path = self.BASE_VAL_PATH.format(i2c_line)+"qsfp_lpmode" + reg_file = open(qsfp_path, "r+") except IOError as e: print("Error: unable to open file: %s" % str(e)) @@ -465,8 +465,8 @@ def reset(self, port_num): # Flip the bit back high and write back to the register to take port # out of reset try: - qsfp_path = self.BASE_VAL_PATH.format(i2c_line)+"qsfp_lpmode" - reg_file = open(qsfp_path, "w") + qsfp_path = self.BASE_VAL_PATH.format(i2c_line)+"qsfp_lpmode" + reg_file = open(qsfp_path, "w") except IOError as e: print("Error: unable to open file: %s" % str(e)) @@ -480,158 +480,157 @@ def reset(self, port_num): return True def get_register(self, reg_file): - retval = 'ERR' + retval = 'ERR' - if (not os.path.isfile(reg_file)): - print(reg_file + ' not found !') - return retval + if (not os.path.isfile(reg_file)): + print(reg_file + ' not found !') + return retval - try: - with open(reg_file, 'r') as fd: - retval = fd.read() - except Exception as error: - logging.error("Unable to open ", reg_file, "file !") + try: + with open(reg_file, 'r') as fd: + retval = fd.read() + except Exception as error: + logging.error("Unable to open ", reg_file, "file !") - retval = retval.rstrip('\r\n') - retval = retval.lstrip(" ") - return retval + retval = retval.rstrip('\r\n') + retval = retval.lstrip(" ") + return retval def check_interrupts(self, port_dict): - retval = 0 - is_port_dict_updated = False - - # Read the QSFP ABS interrupt & status registers - cpld2_abs_int = self.get_register( - "/sys/class/i2c-adapter/i2c-14/14-003e/qsfp_abs_int") - cpld2_abs_sta = self.get_register( - "/sys/class/i2c-adapter/i2c-14/14-003e/qsfp_abs_sta") - cpld3_abs_int = self.get_register( - "/sys/class/i2c-adapter/i2c-15/15-003e/qsfp_abs_int") - cpld3_abs_sta = self.get_register( - "/sys/class/i2c-adapter/i2c-15/15-003e/qsfp_abs_sta") - cpld4_abs_int = self.get_register( - "/sys/class/i2c-adapter/i2c-16/16-003e/qsfp_abs_int") - cpld4_abs_sta = self.get_register( - "/sys/class/i2c-adapter/i2c-16/16-003e/qsfp_abs_sta") - cpld5_abs_int = self.get_register( - "/sys/class/i2c-adapter/i2c-17/17-003e/qsfp_abs_int") - cpld5_abs_sta = self.get_register( - "/sys/class/i2c-adapter/i2c-17/17-003e/qsfp_abs_sta") - - if (cpld2_abs_int == 'ERR' or cpld2_abs_sta == 'ERR' or - cpld3_abs_int == 'ERR' or cpld3_abs_sta == 'ERR' or - cpld4_abs_int == 'ERR' or cpld4_abs_sta == 'ERR' or - cpld5_abs_int == 'ERR' or cpld5_abs_sta == 'ERR'): - return -1 - - # If IOM is not present, interrupt will return 'read error' - # Handle the scenario gracefully - if (cpld2_abs_int == 'read error'): - cpld2_abs_int = "0x0" - cpld2_abs_sta = "0x0" - if (cpld3_abs_int == 'read error'): - cpld3_abs_int = "0x0" - cpld3_abs_sta = "0x0" - if (cpld4_abs_int == 'read error'): - cpld4_abs_int = "0x0" - cpld4_abs_sta = "0x0" - if (cpld5_abs_int == 'read error'): - cpld5_abs_int = "0x0" - cpld5_abs_sta = "0x0" - - cpld2_abs_int = int(cpld2_abs_int, 16) - cpld2_abs_sta = int(cpld2_abs_sta, 16) - cpld3_abs_int = int(cpld3_abs_int, 16) - cpld3_abs_sta = int(cpld3_abs_sta, 16) - cpld4_abs_int = int(cpld4_abs_int, 16) - cpld4_abs_sta = int(cpld4_abs_sta, 16) - cpld5_abs_int = int(cpld5_abs_int, 16) - cpld5_abs_sta = int(cpld5_abs_sta, 16) - - # Make it contiguous - interrupt_reg = (cpld2_abs_int & 0xffff) | \ - ((cpld4_abs_int & 0xffff) << 16) | \ - ((cpld3_abs_int & 0xffff) << 32) | \ - ((cpld5_abs_int & 0xffff) << 48) - status_reg = (cpld2_abs_sta & 0xffff) | \ - ((cpld4_abs_sta & 0xffff) << 16) | \ - ((cpld3_abs_sta & 0xffff) << 32) | \ - ((cpld5_abs_sta & 0xffff) << 48) - - port = self.port_start - while port <= self.port_end: - if interrupt_reg & (1 << port): - # update only if atleast one port has generated - # interrupt - is_port_dict_updated = True - if status_reg & (1 << port): - # status reg 1 => optics is removed - port_dict[port] = '0' - else: - # status reg 0 => optics is inserted - port_dict[port] = '1' - port += 1 - return retval, is_port_dict_updated + retval = 0 + is_port_dict_updated = False + + # Read the QSFP ABS interrupt & status registers + cpld2_abs_int = self.get_register( + "/sys/class/i2c-adapter/i2c-14/14-003e/qsfp_abs_int") + cpld2_abs_sta = self.get_register( + "/sys/class/i2c-adapter/i2c-14/14-003e/qsfp_abs_sta") + cpld3_abs_int = self.get_register( + "/sys/class/i2c-adapter/i2c-15/15-003e/qsfp_abs_int") + cpld3_abs_sta = self.get_register( + "/sys/class/i2c-adapter/i2c-15/15-003e/qsfp_abs_sta") + cpld4_abs_int = self.get_register( + "/sys/class/i2c-adapter/i2c-16/16-003e/qsfp_abs_int") + cpld4_abs_sta = self.get_register( + "/sys/class/i2c-adapter/i2c-16/16-003e/qsfp_abs_sta") + cpld5_abs_int = self.get_register( + "/sys/class/i2c-adapter/i2c-17/17-003e/qsfp_abs_int") + cpld5_abs_sta = self.get_register( + "/sys/class/i2c-adapter/i2c-17/17-003e/qsfp_abs_sta") + + if (cpld2_abs_int == 'ERR' or cpld2_abs_sta == 'ERR' or + cpld3_abs_int == 'ERR' or cpld3_abs_sta == 'ERR' or + cpld4_abs_int == 'ERR' or cpld4_abs_sta == 'ERR' or + cpld5_abs_int == 'ERR' or cpld5_abs_sta == 'ERR'): + return -1 + + # If IOM is not present, interrupt will return 'read error' + # Handle the scenario gracefully + if (cpld2_abs_int == 'read error'): + cpld2_abs_int = "0x0" + cpld2_abs_sta = "0x0" + if (cpld3_abs_int == 'read error'): + cpld3_abs_int = "0x0" + cpld3_abs_sta = "0x0" + if (cpld4_abs_int == 'read error'): + cpld4_abs_int = "0x0" + cpld4_abs_sta = "0x0" + if (cpld5_abs_int == 'read error'): + cpld5_abs_int = "0x0" + cpld5_abs_sta = "0x0" + + cpld2_abs_int = int(cpld2_abs_int, 16) + cpld2_abs_sta = int(cpld2_abs_sta, 16) + cpld3_abs_int = int(cpld3_abs_int, 16) + cpld3_abs_sta = int(cpld3_abs_sta, 16) + cpld4_abs_int = int(cpld4_abs_int, 16) + cpld4_abs_sta = int(cpld4_abs_sta, 16) + cpld5_abs_int = int(cpld5_abs_int, 16) + cpld5_abs_sta = int(cpld5_abs_sta, 16) + + # Make it contiguous + interrupt_reg = (cpld2_abs_int & 0xffff) | \ + ((cpld4_abs_int & 0xffff) << 16) | \ + ((cpld3_abs_int & 0xffff) << 32) | \ + ((cpld5_abs_int & 0xffff) << 48) + status_reg = (cpld2_abs_sta & 0xffff) | \ + ((cpld4_abs_sta & 0xffff) << 16) | \ + ((cpld3_abs_sta & 0xffff) << 32) | \ + ((cpld5_abs_sta & 0xffff) << 48) + + port = self.port_start + while port <= self.port_end: + if interrupt_reg & (1 << port): + # update only if atleast one port has generated + # interrupt + is_port_dict_updated = True + if status_reg & (1 << port): + # status reg 1 => optics is removed + port_dict[port] = '0' + else: + # status reg 0 => optics is inserted + port_dict[port] = '1' + port += 1 + return retval, is_port_dict_updated def get_transceiver_change_event(self, timeout=0): - port_dict = {} - try: - # We get notified when there is an SCI interrupt from GPIO SUS6 - # Open the sysfs file and register the epoll object - self.oir_fd = open(self.OIR_FD_PATH, "r") - if self.oir_fd != -1: - # Do a dummy read before epoll register - self.oir_fd.read() - self.epoll = select.epoll() - self.epoll.register(self.oir_fd.fileno(), - select.EPOLLIN & select.EPOLLET) - else: - print("get_transceiver_change_event : unable to create fd") - return False, {} + port_dict = {} + try: + # We get notified when there is an SCI interrupt from GPIO SUS6 + # Open the sysfs file and register the epoll object + self.oir_fd = open(self.OIR_FD_PATH, "r") + if self.oir_fd != -1: + # Do a dummy read before epoll register + self.oir_fd.read() + self.epoll = select.epoll() + self.epoll.register(self.oir_fd.fileno(), + select.EPOLLIN & select.EPOLLET) + else: + print("get_transceiver_change_event : unable to create fd") + return False, {} - # Check for missed interrupts by invoking self.check_interrupts - # which will update the port_dict. - while True: - interrupt_count_start = self.get_register(self.OIR_FD_PATH) + # Check for missed interrupts by invoking self.check_interrupts + # which will update the port_dict. + while True: + interrupt_count_start = self.get_register(self.OIR_FD_PATH) - retval, is_port_dict_updated = \ - self.check_interrupts(port_dict) - if ((retval == 0) and (is_port_dict_updated is True)): - return True, port_dict + retval, is_port_dict_updated = \ + self.check_interrupts(port_dict) + if ((retval == 0) and (is_port_dict_updated is True)): + return True, port_dict - interrupt_count_end = self.get_register(self.OIR_FD_PATH) + interrupt_count_end = self.get_register(self.OIR_FD_PATH) - if (interrupt_count_start == 'ERR' or - interrupt_count_end == 'ERR'): - print("get_transceiver_change_event : \ + if (interrupt_count_start == 'ERR' or + interrupt_count_end == 'ERR'): + print("get_transceiver_change_event : \ unable to retrive interrupt count") - break - - # check_interrupts() itself may take upto 100s of msecs. - # We detect a missed interrupt based on the count - if interrupt_count_start == interrupt_count_end: - break - - # Block until an xcvr is inserted or removed with timeout = -1 - events = self.epoll.poll( - timeout=timeout if timeout != 0 else -1) - if events: - # check interrupts and return the port_dict - retval, is_port_dict_updated = \ - self.check_interrupts(port_dict) - if (retval != 0): - return False, {} - - return True, port_dict - except: - return False, {} - finally: - if self.oir_fd != -1: - self.epoll.unregister(self.oir_fd.fileno()) - self.epoll.close() - self.oir_fd.close() - self.oir_fd = -1 - self.epoll = -1 + break + + # check_interrupts() itself may take upto 100s of msecs. + # We detect a missed interrupt based on the count + if interrupt_count_start == interrupt_count_end: + break + + # Block until an xcvr is inserted or removed with timeout = -1 + events = self.epoll.poll( + timeout=timeout if timeout != 0 else -1) + if events: + # check interrupts and return the port_dict + retval, is_port_dict_updated = \ + self.check_interrupts(port_dict) + if (retval != 0): + return False, {} + return True, port_dict + except: return False, {} - + finally: + if self.oir_fd != -1: + self.epoll.unregister(self.oir_fd.fileno()) + self.epoll.close() + self.oir_fd.close() + self.oir_fd = -1 + self.epoll = -1 + + return False, {} diff --git a/device/dell/x86_64-dell_z9100_c2538-r0/plugins/psuutil.py b/device/dell/x86_64-dell_z9100_c2538-r0/plugins/psuutil.py index e2dfd30bf6bb..d6eed4a5a7c1 100644 --- a/device/dell/x86_64-dell_z9100_c2538-r0/plugins/psuutil.py +++ b/device/dell/x86_64-dell_z9100_c2538-r0/plugins/psuutil.py @@ -14,6 +14,7 @@ HWMON_DIR = "/sys/devices/platform/SMF.512/hwmon/" HWMON_NODE = os.listdir(HWMON_DIR)[0] + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" @@ -60,7 +61,7 @@ def get_psu_status(self, index): psu_status = int(psu_status, 16) # Check for PSU statuse if (~psu_status & 0b1000) or (psu_status & 0b0100): - status = 1 + status = 1 return status @@ -77,6 +78,6 @@ def get_psu_presence(self, index): psu_presence = int(psu_presence, 16) # Check for PSU presence if (~psu_presence & 0b1): - status = 1 + status = 1 return status diff --git a/device/dell/x86_64-dell_z9100_c2538-r0/plugins/sfputil.py b/device/dell/x86_64-dell_z9100_c2538-r0/plugins/sfputil.py index 1e2aa1084dc7..16b5192522e3 100644 --- a/device/dell/x86_64-dell_z9100_c2538-r0/plugins/sfputil.py +++ b/device/dell/x86_64-dell_z9100_c2538-r0/plugins/sfputil.py @@ -33,40 +33,40 @@ class SfpUtil(SfpUtilBase): epoll = -1 _port_to_eeprom_mapping = {} _port_to_i2c_mapping = { - 0: [0, 00], # Dummy Entry - 1: [9, 18], - 2: [9, 19], - 3: [9, 20], - 4: [9, 21], - 5: [9, 22], - 6: [9, 23], - 7: [9, 24], - 8: [9, 25], - 9: [8, 26], - 10: [8, 27], - 11: [8, 28], - 12: [8, 29], - 13: [8, 31], # reordered - 14: [8, 30], - 15: [8, 33], # reordered - 16: [8, 32], - 17: [7, 34], - 18: [7, 35], - 19: [7, 36], - 20: [7, 37], - 21: [7, 38], - 22: [7, 39], - 23: [7, 40], - 24: [7, 41], - 25: [6, 42], - 26: [6, 43], - 27: [6, 44], - 28: [6, 45], - 29: [6, 46], - 30: [6, 47], - 31: [6, 48], - 32: [6, 49] - } + 0: [0, 00], # Dummy Entry + 1: [9, 18], + 2: [9, 19], + 3: [9, 20], + 4: [9, 21], + 5: [9, 22], + 6: [9, 23], + 7: [9, 24], + 8: [9, 25], + 9: [8, 26], + 10: [8, 27], + 11: [8, 28], + 12: [8, 29], + 13: [8, 31], # reordered + 14: [8, 30], + 15: [8, 33], # reordered + 16: [8, 32], + 17: [7, 34], + 18: [7, 35], + 19: [7, 36], + 20: [7, 37], + 21: [7, 38], + 22: [7, 39], + 23: [7, 40], + 24: [7, 41], + 25: [6, 42], + 26: [6, 43], + 27: [6, 44], + 28: [6, 45], + 29: [6, 46], + 30: [6, 47], + 31: [6, 48], + 32: [6, 49] + } @property def port_start(self): @@ -124,9 +124,9 @@ def __init__(self): def __del__(self): if self.oir_fd != -1: - self.epoll.unregister(self.oir_fd.fileno()) - self.epoll.close() - self.oir_fd.close() + self.epoll.unregister(self.oir_fd.fileno()) + self.epoll.close() + self.oir_fd.close() def normalize_port(self, port_num): # Check for invalid port_num @@ -153,7 +153,6 @@ def normalize_port(self, port_num): return i2c_line, port_num - def get_presence(self, port_num): i2c_line, port_num = self.normalize_port(port_num) @@ -193,8 +192,8 @@ def get_low_power_mode(self, port_num): return False try: - qsfp_path = self.BASE_VAL_PATH.format(i2c_line)+"qsfp_lpmode" - reg_file = open(qsfp_path, "r") + qsfp_path = self.BASE_VAL_PATH.format(i2c_line)+"qsfp_lpmode" + reg_file = open(qsfp_path, "r") except IOError as e: print("Error: unable to open file: %s" % str(e)) @@ -225,9 +224,8 @@ def set_low_power_mode(self, port_num, lpmode): return False try: - qsfp_path = self.BASE_VAL_PATH.format(i2c_line)+"qsfp_lpmode" - reg_file = open(qsfp_path, "r+") - + qsfp_path = self.BASE_VAL_PATH.format(i2c_line)+"qsfp_lpmode" + reg_file = open(qsfp_path, "r+") except IOError as e: print("Error: unable to open file: %s" % str(e)) @@ -266,8 +264,8 @@ def reset(self, port_num): return False try: - qsfp_path = self.BASE_VAL_PATH.format(i2c_line)+"qsfp_lpmode" - reg_file = open(qsfp_path, "r+") + qsfp_path = self.BASE_VAL_PATH.format(i2c_line)+"qsfp_lpmode" + reg_file = open(qsfp_path, "r+") except IOError as e: print("Error: unable to open file: %s" % str(e)) @@ -295,8 +293,8 @@ def reset(self, port_num): # Flip the bit back high and write back to the register to take # port out of reset try: - qsfp_path = self.BASE_VAL_PATH.format(i2c_line)+"qsfp_lpmode" - reg_file = open(qsfp_path, "w+") + qsfp_path = self.BASE_VAL_PATH.format(i2c_line)+"qsfp_lpmode" + reg_file = open(qsfp_path, "w+") except IOError as e: print("Error: unable to open file: %s" % str(e)) @@ -310,133 +308,132 @@ def reset(self, port_num): return True def get_register(self, reg_file): - retval = 'ERR' + retval = 'ERR' - if (not os.path.isfile(reg_file)): - print(reg_file + ' not found !') - return retval + if (not os.path.isfile(reg_file)): + print(reg_file + ' not found !') + return retval - try: - with open(reg_file, 'r') as fd: - retval = fd.read() - except Exception as error: - logging.error("Unable to open ", reg_file, "file !") + try: + with open(reg_file, 'r') as fd: + retval = fd.read() + except Exception as error: + logging.error("Unable to open ", reg_file, "file !") - retval = retval.rstrip('\r\n') - retval = retval.lstrip(" ") - return retval + retval = retval.rstrip('\r\n') + retval = retval.lstrip(" ") + return retval def check_interrupts(self, port_dict): - retval = 0 - is_port_dict_updated = False - # Read the QSFP ABS interrupt & status registers - cpld2_abs_int = self.get_register( - "/sys/class/i2c-adapter/i2c-14/14-003e/qsfp_abs_int") - cpld2_abs_sta = self.get_register( - "/sys/class/i2c-adapter/i2c-14/14-003e/qsfp_abs_sta") - cpld3_abs_int = self.get_register( - "/sys/class/i2c-adapter/i2c-15/15-003e/qsfp_abs_int") - cpld3_abs_sta = self.get_register( - "/sys/class/i2c-adapter/i2c-15/15-003e/qsfp_abs_sta") - cpld4_abs_int = self.get_register( - "/sys/class/i2c-adapter/i2c-16/16-003e/qsfp_abs_int") - cpld4_abs_sta = self.get_register( - "/sys/class/i2c-adapter/i2c-16/16-003e/qsfp_abs_sta") - - if (cpld2_abs_int == 'ERR' or cpld2_abs_sta == 'ERR' or - cpld3_abs_int == 'ERR' or cpld3_abs_sta == 'ERR' or - cpld4_abs_int == 'ERR' or cpld4_abs_sta == 'ERR'): - return -1 - - cpld2_abs_int = int(cpld2_abs_int, 16) - cpld2_abs_sta = int(cpld2_abs_sta, 16) - cpld3_abs_int = int(cpld3_abs_int, 16) - cpld3_abs_sta = int(cpld3_abs_sta, 16) - cpld4_abs_int = int(cpld4_abs_int, 16) - cpld4_abs_sta = int(cpld4_abs_sta, 16) - - # Make it contiguous (discard reserved bits) - interrupt_reg = (cpld2_abs_int & 0xfff) |\ - ((cpld3_abs_int & 0x3ff) << 12) |\ - ((cpld4_abs_int & 0x3ff) << 22) - status_reg = (cpld2_abs_sta & 0xfff) |\ - ((cpld3_abs_sta & 0x3ff) << 12) |\ - ((cpld4_abs_sta & 0x3ff) << 22) - - port = self.port_start - while port <= self.port_end: - if interrupt_reg & (1 << (port-1)): - # update only if atleast one port has generated - # interrupt - is_port_dict_updated = True - if status_reg & (1 << (port-1)): - # status reg 1 => optics is removed - port_dict[port] = '0' - else: - # status reg 0 => optics is inserted - port_dict[port] = '1' - port += 1 - return retval, is_port_dict_updated + retval = 0 + is_port_dict_updated = False + # Read the QSFP ABS interrupt & status registers + cpld2_abs_int = self.get_register( + "/sys/class/i2c-adapter/i2c-14/14-003e/qsfp_abs_int") + cpld2_abs_sta = self.get_register( + "/sys/class/i2c-adapter/i2c-14/14-003e/qsfp_abs_sta") + cpld3_abs_int = self.get_register( + "/sys/class/i2c-adapter/i2c-15/15-003e/qsfp_abs_int") + cpld3_abs_sta = self.get_register( + "/sys/class/i2c-adapter/i2c-15/15-003e/qsfp_abs_sta") + cpld4_abs_int = self.get_register( + "/sys/class/i2c-adapter/i2c-16/16-003e/qsfp_abs_int") + cpld4_abs_sta = self.get_register( + "/sys/class/i2c-adapter/i2c-16/16-003e/qsfp_abs_sta") + + if (cpld2_abs_int == 'ERR' or cpld2_abs_sta == 'ERR' or + cpld3_abs_int == 'ERR' or cpld3_abs_sta == 'ERR' or + cpld4_abs_int == 'ERR' or cpld4_abs_sta == 'ERR'): + return -1 + + cpld2_abs_int = int(cpld2_abs_int, 16) + cpld2_abs_sta = int(cpld2_abs_sta, 16) + cpld3_abs_int = int(cpld3_abs_int, 16) + cpld3_abs_sta = int(cpld3_abs_sta, 16) + cpld4_abs_int = int(cpld4_abs_int, 16) + cpld4_abs_sta = int(cpld4_abs_sta, 16) + + # Make it contiguous (discard reserved bits) + interrupt_reg = (cpld2_abs_int & 0xfff) |\ + ((cpld3_abs_int & 0x3ff) << 12) |\ + ((cpld4_abs_int & 0x3ff) << 22) + status_reg = (cpld2_abs_sta & 0xfff) |\ + ((cpld3_abs_sta & 0x3ff) << 12) |\ + ((cpld4_abs_sta & 0x3ff) << 22) + + port = self.port_start + while port <= self.port_end: + if interrupt_reg & (1 << (port-1)): + # update only if atleast one port has generated + # interrupt + is_port_dict_updated = True + if status_reg & (1 << (port-1)): + # status reg 1 => optics is removed + port_dict[port] = '0' + else: + # status reg 0 => optics is inserted + port_dict[port] = '1' + port += 1 + return retval, is_port_dict_updated def get_transceiver_change_event(self, timeout=0): - port_dict = {} - try: - # We get notified when there is an SCI interrupt from GPIO SUS6 - # Open the sysfs file and register the epoll object - self.oir_fd = open(self.OIR_FD_PATH, "r") - if self.oir_fd != -1: - # Do a dummy read before epoll register - self.oir_fd.read() - self.epoll = select.epoll() - self.epoll.register(self.oir_fd.fileno(), - select.EPOLLIN & select.EPOLLET) - else: - print("get_transceiver_change_event : unable to create fd") - return False, {} + port_dict = {} + try: + # We get notified when there is an SCI interrupt from GPIO SUS6 + # Open the sysfs file and register the epoll object + self.oir_fd = open(self.OIR_FD_PATH, "r") + if self.oir_fd != -1: + # Do a dummy read before epoll register + self.oir_fd.read() + self.epoll = select.epoll() + self.epoll.register(self.oir_fd.fileno(), + select.EPOLLIN & select.EPOLLET) + else: + print("get_transceiver_change_event : unable to create fd") + return False, {} - # Check for missed interrupts by invoking self.check_interrupts - # which will update the port_dict. - while True: - interrupt_count_start = self.get_register(self.OIR_FD_PATH) + # Check for missed interrupts by invoking self.check_interrupts + # which will update the port_dict. + while True: + interrupt_count_start = self.get_register(self.OIR_FD_PATH) - retval, is_port_dict_updated = \ - self.check_interrupts(port_dict) - if ((retval == 0) and (is_port_dict_updated is True)): - return True, port_dict + retval, is_port_dict_updated = \ + self.check_interrupts(port_dict) + if ((retval == 0) and (is_port_dict_updated is True)): + return True, port_dict - interrupt_count_end = self.get_register(self.OIR_FD_PATH) + interrupt_count_end = self.get_register(self.OIR_FD_PATH) - if (interrupt_count_start == 'ERR' or - interrupt_count_end == 'ERR'): - print("get_transceiver_change_event : \ + if (interrupt_count_start == 'ERR' or + interrupt_count_end == 'ERR'): + print("get_transceiver_change_event : \ unable to retrive interrupt count") - break - - # check_interrupts() itself may take upto 100s of msecs. - # We detect a missed interrupt based on the count - if interrupt_count_start == interrupt_count_end: - break - - # Block until an xcvr is inserted or removed with timeout = -1 - events = self.epoll.poll( - timeout=timeout if timeout != 0 else -1) - if events: - # check interrupts and return the port_dict - retval, is_port_dict_updated = \ - self.check_interrupts(port_dict) - if (retval != 0): - return False, {} - - return True, port_dict - except: - return False, {} - finally: - if self.oir_fd != -1: - self.epoll.unregister(self.oir_fd.fileno()) - self.epoll.close() - self.oir_fd.close() - self.oir_fd = -1 - self.epoll = -1 + break + + # check_interrupts() itself may take upto 100s of msecs. + # We detect a missed interrupt based on the count + if interrupt_count_start == interrupt_count_end: + break + + # Block until an xcvr is inserted or removed with timeout = -1 + events = self.epoll.poll( + timeout=timeout if timeout != 0 else -1) + if events: + # check interrupts and return the port_dict + retval, is_port_dict_updated = \ + self.check_interrupts(port_dict) + if (retval != 0): + return False, {} + return True, port_dict + except: return False, {} + finally: + if self.oir_fd != -1: + self.epoll.unregister(self.oir_fd.fileno()) + self.epoll.close() + self.oir_fd.close() + self.oir_fd = -1 + self.epoll = -1 + return False, {} diff --git a/device/dell/x86_64-dellemc_s5232f_c3538-r0/plugins/psuutil.py b/device/dell/x86_64-dellemc_s5232f_c3538-r0/plugins/psuutil.py index 842b8f710143..27042e3122b4 100644 --- a/device/dell/x86_64-dellemc_s5232f_c3538-r0/plugins/psuutil.py +++ b/device/dell/x86_64-dellemc_s5232f_c3538-r0/plugins/psuutil.py @@ -51,15 +51,15 @@ def get_pmc_register(self, reg_name): ipmi_cmd_2 = IPMI_PSU1_DATA dockerenv = self.isDockerEnv() if dockerenv == True: - if index == 1: - status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA_DOCKER) - elif index == 2: - status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA_DOCKER) + if index == 1: + status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA_DOCKER) + elif index == 2: + status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA_DOCKER) else: - if index == 1: - status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA) - elif index == 2: - status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA) + if index == 1: + status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA) + elif index == 2: + status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA) if status: logging.error('Failed to execute ipmitool') @@ -91,15 +91,15 @@ def get_psu_status(self, index): ret_status = 1 dockerenv = self.isDockerEnv() if dockerenv == True: - if index == 1: - ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA_DOCKER) - elif index == 2: - ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA_DOCKER) + if index == 1: + ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA_DOCKER) + elif index == 2: + ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA_DOCKER) else: - if index == 1: - ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA) - elif index == 2: - ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA) + if index == 1: + ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA) + elif index == 2: + ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA) if ret_status: logging.error('Failed to execute ipmitool : ') @@ -119,15 +119,15 @@ def get_psu_presence(self, index): ret_status = 1 dockerenv = self.isDockerEnv() if dockerenv == True: - if index == 1: - ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA_DOCKER) - elif index == 2: - ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA_DOCKER) + if index == 1: + ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA_DOCKER) + elif index == 2: + ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA_DOCKER) else: - if index == 1: - ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA) - elif index == 2: - ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA) + if index == 1: + ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA) + elif index == 2: + ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA) if ret_status: logging.error('Failed to execute ipmitool : ') diff --git a/device/dell/x86_64-dellemc_s5248f_c3538-r0/plugins/psuutil.py b/device/dell/x86_64-dellemc_s5248f_c3538-r0/plugins/psuutil.py index 746eecaaf403..9cd186611486 100644 --- a/device/dell/x86_64-dellemc_s5248f_c3538-r0/plugins/psuutil.py +++ b/device/dell/x86_64-dellemc_s5248f_c3538-r0/plugins/psuutil.py @@ -106,6 +106,5 @@ def get_psu_presence(self, index): if (psu_status != 'ERR'): # Check for PSU presence if (psu_status == 0x00): - status = 1 + status = 1 return status - diff --git a/device/dell/x86_64-dellemc_s5296f_c3538-r0/plugins/eeprom.py b/device/dell/x86_64-dellemc_s5296f_c3538-r0/plugins/eeprom.py index a1cc6a5864fc..e4ee56138a77 100644 --- a/device/dell/x86_64-dellemc_s5296f_c3538-r0/plugins/eeprom.py +++ b/device/dell/x86_64-dellemc_s5296f_c3538-r0/plugins/eeprom.py @@ -12,7 +12,7 @@ try: from sonic_eeprom import eeprom_tlvinfo except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/dell/x86_64-dellemc_s5296f_c3538-r0/plugins/psuutil.py b/device/dell/x86_64-dellemc_s5296f_c3538-r0/plugins/psuutil.py index e318325febf4..8a7b53a626bf 100644 --- a/device/dell/x86_64-dellemc_s5296f_c3538-r0/plugins/psuutil.py +++ b/device/dell/x86_64-dellemc_s5296f_c3538-r0/plugins/psuutil.py @@ -97,6 +97,6 @@ def get_psu_presence(self, index): :param index: An integer, index of the PSU of which to query status :return: Boolean, True if PSU is plugged, False if not """ - cmd_status, psu_status = commands.getstatusoutput('ipmitool raw 0x04 0x2d ' + hex(0x30 + index) + " | awk '{print substr($0,9,1)}'") + cmd_status, psu_status = commands.getstatusoutput( + 'ipmitool raw 0x04 0x2d ' + hex(0x30 + index) + " | awk '{print substr($0,9,1)}'") return 1 if psu_status == '1' else 0 - diff --git a/device/dell/x86_64-dellemc_z9264f_c3538-r0/plugins/eeprom.py b/device/dell/x86_64-dellemc_z9264f_c3538-r0/plugins/eeprom.py index e4dcfbd3cf08..a38a0395d5b3 100644 --- a/device/dell/x86_64-dellemc_z9264f_c3538-r0/plugins/eeprom.py +++ b/device/dell/x86_64-dellemc_z9264f_c3538-r0/plugins/eeprom.py @@ -18,7 +18,7 @@ class board(eeprom_tlvinfo.TlvInfoDecoder): def __init__(self, name, path, cpld_root, ro): self.eeprom_path = None - for b in (0,1): + for b in (0, 1): f = '/sys/class/i2c-adapter/i2c-{0}/{0}-0050/eeprom'.format(b) if os.path.exists(f): self.eeprom_path = f diff --git a/device/dell/x86_64-dellemc_z9264f_c3538-r0/plugins/psuutil.py b/device/dell/x86_64-dellemc_z9264f_c3538-r0/plugins/psuutil.py index 58546d4028f8..3a58afda8df4 100644 --- a/device/dell/x86_64-dellemc_z9264f_c3538-r0/plugins/psuutil.py +++ b/device/dell/x86_64-dellemc_z9264f_c3538-r0/plugins/psuutil.py @@ -106,6 +106,5 @@ def get_psu_presence(self, index): if (psu_status != 'ERR'): # Check for PSU presence if (psu_status): - status = 1 + status = 1 return status - diff --git a/device/dell/x86_64-dellemc_z9264f_c3538-r0/plugins/sfputil.py b/device/dell/x86_64-dellemc_z9264f_c3538-r0/plugins/sfputil.py index 60c2f4724308..5b01882762af 100644 --- a/device/dell/x86_64-dellemc_z9264f_c3538-r0/plugins/sfputil.py +++ b/device/dell/x86_64-dellemc_z9264f_c3538-r0/plugins/sfputil.py @@ -21,7 +21,7 @@ except ImportError as e: raise ImportError("%s - required module not found" % str(e)) -#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 @@ -50,6 +50,7 @@ XCVR_DOM_CAPABILITY_OFFSET = 92 XCVR_DOM_CAPABILITY_WIDTH = 1 + class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" @@ -150,7 +151,7 @@ def get_presence(self, port_num): # Mask off 1st bit for presence 65,66 if (port_num > 64): - mask = (1 << 0) + mask = (1 << 0) # ModPrsL is active low if reg_value & mask == 0: return True @@ -248,95 +249,95 @@ def reset(self, port_num): return True def get_register(self, reg_file): - retval = 'ERR' - if (not path.isfile(reg_file)): - print(reg_file + ' not found !') - return retval + retval = 'ERR' + if (not path.isfile(reg_file)): + print(reg_file + ' not found !') + return retval - try: - with fdopen(open(reg_file, O_RDONLY)) as fd: - retval = fd.read() - except Exception as error: - logging.error("Unable to open ", reg_file, "file !") + try: + with fdopen(open(reg_file, O_RDONLY)) as fd: + retval = fd.read() + except Exception as error: + logging.error("Unable to open ", reg_file, "file !") - retval = retval.rstrip('\r\n') - retval = retval.lstrip(" ") - return retval + retval = retval.rstrip('\r\n') + retval = retval.lstrip(" ") + return retval def check_interrupts(self, port_dict): - retval = 0 - is_port_dict_updated = False - for port_num in range(self.port_start, (self.port_end + 1)): - presence = self.get_presence(port_num) - if(presence and self._global_port_pres_dict[port_num] == '0'): - is_port_dict_updated = True - self._global_port_pres_dict[port_num] = '1' - port_dict[port_num] = '1' - elif(not presence and - self._global_port_pres_dict[port_num] == '1'): - is_port_dict_updated = True - self._global_port_pres_dict[port_num] = '0' - port_dict[port_num] = '0' - return retval, is_port_dict_updated + retval = 0 + is_port_dict_updated = False + for port_num in range(self.port_start, (self.port_end + 1)): + presence = self.get_presence(port_num) + if(presence and self._global_port_pres_dict[port_num] == '0'): + is_port_dict_updated = True + self._global_port_pres_dict[port_num] = '1' + port_dict[port_num] = '1' + elif(not presence and + self._global_port_pres_dict[port_num] == '1'): + is_port_dict_updated = True + self._global_port_pres_dict[port_num] = '0' + port_dict[port_num] = '0' + return retval, is_port_dict_updated def get_transceiver_change_event(self, timeout=0): - port_dict = {} - try: - # We get notified when there is a MSI interrupt (vector 4/5)CVR - # Open the sysfs file and register the epoll object - self.oir_fd = fdopen(open(self.OIR_FD_PATH, O_RDONLY)) - if self.oir_fd != -1: - # Do a dummy read before epoll register - self.oir_fd.read() - self.epoll = select.epoll() - self.epoll.register( - self.oir_fd.fileno(), select.EPOLLIN & select.EPOLLET) - else: - print("get_transceiver_change_event : unable to create fd") - return False, {} + port_dict = {} + try: + # We get notified when there is a MSI interrupt (vector 4/5)CVR + # Open the sysfs file and register the epoll object + self.oir_fd = fdopen(open(self.OIR_FD_PATH, O_RDONLY)) + if self.oir_fd != -1: + # Do a dummy read before epoll register + self.oir_fd.read() + self.epoll = select.epoll() + self.epoll.register( + self.oir_fd.fileno(), select.EPOLLIN & select.EPOLLET) + else: + print("get_transceiver_change_event : unable to create fd") + return False, {} - # Check for missed interrupts by invoking self.check_interrupts - # which will update the port_dict. - while True: - interrupt_count_start = self.get_register(self.OIR_FD_PATH) - retval, is_port_dict_updated = \ - self.check_interrupts(port_dict) - if ((retval == 0) and (is_port_dict_updated is True)): - return True, port_dict - interrupt_count_end = self.get_register(self.OIR_FD_PATH) - if (interrupt_count_start == 'ERR' or - interrupt_count_end == 'ERR'): - print("get_transceiver_change_event : \ + # Check for missed interrupts by invoking self.check_interrupts + # which will update the port_dict. + while True: + interrupt_count_start = self.get_register(self.OIR_FD_PATH) + retval, is_port_dict_updated = \ + self.check_interrupts(port_dict) + if ((retval == 0) and (is_port_dict_updated is True)): + return True, port_dict + interrupt_count_end = self.get_register(self.OIR_FD_PATH) + if (interrupt_count_start == 'ERR' or + interrupt_count_end == 'ERR'): + print("get_transceiver_change_event : \ unable to retrive interrupt count") - break - - # check_interrupts() itself may take upto 100s of msecs. - # We detect a missed interrupt based on the count - if interrupt_count_start == interrupt_count_end: - break - - # Block until an xcvr is inserted or removed with timeout = -1 - events = self.epoll.poll( - timeout=timeout if timeout != 0 else -1) - if events: - # check interrupts and return the port_dict - retval, is_port_dict_updated = \ - self.check_interrupts(port_dict) - if (retval != 0): - return False, {} - - return True, port_dict - except: - return False, {} - finally: - if self.oir_fd != -1: - self.epoll.unregister(self.oir_fd.fileno()) - self.epoll.close() - self.oir_fd.close() - self.oir_fd = -1 - self.epoll = -1 + break + + # check_interrupts() itself may take upto 100s of msecs. + # We detect a missed interrupt based on the count + if interrupt_count_start == interrupt_count_end: + break + + # Block until an xcvr is inserted or removed with timeout = -1 + events = self.epoll.poll( + timeout=timeout if timeout != 0 else -1) + if events: + # check interrupts and return the port_dict + retval, is_port_dict_updated = \ + self.check_interrupts(port_dict) + if (retval != 0): + return False, {} + return True, port_dict + except: return False, {} + finally: + if self.oir_fd != -1: + self.epoll.unregister(self.oir_fd.fileno()) + self.epoll.close() + self.oir_fd.close() + self.oir_fd = -1 + self.epoll = -1 + + return False, {} def get_transceiver_dom_info_dict(self, port_num): transceiver_dom_info_dict = {} @@ -346,7 +347,7 @@ def get_transceiver_dom_info_dict(self, port_num): 'tx1bias', 'tx2bias', 'tx3bias', 'tx4bias', 'tx1power', 'tx2power', 'tx3power', 'tx4power', - ] + ] transceiver_dom_info_dict = dict.fromkeys(dom_info_dict_keys, 'N/A') if port_num in self.qsfp_ports: @@ -374,25 +375,29 @@ def get_transceiver_dom_info_dict(self, port_num): # TODO: in the future when decided to migrate to support SFF-8636 instead of SFF-8436, # need to add more code for determining the capability and version compliance # in SFF-8636 dom capability definitions evolving with the versions. - qsfp_dom_capability_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset_xcvr + XCVR_DOM_CAPABILITY_OFFSET), XCVR_DOM_CAPABILITY_WIDTH) + qsfp_dom_capability_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset_xcvr + XCVR_DOM_CAPABILITY_OFFSET), XCVR_DOM_CAPABILITY_WIDTH) if qsfp_dom_capability_raw is not None: qspf_dom_capability_data = sfpi_obj.parse_qsfp_dom_capability(qsfp_dom_capability_raw, 0) else: return transceiver_dom_info_dict - dom_temperature_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + QSFP_TEMPE_OFFSET), QSFP_TEMPE_WIDTH) + dom_temperature_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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 transceiver_dom_info_dict - dom_voltage_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + QSFP_VOLT_OFFSET), QSFP_VOLT_WIDTH) + dom_voltage_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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 transceiver_dom_info_dict - qsfp_dom_rev_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + QSFP_DOM_REV_OFFSET), QSFP_DOM_REV_WIDTH) + qsfp_dom_rev_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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: @@ -407,7 +412,8 @@ def get_transceiver_dom_info_dict(self, port_num): 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(sysfsfile_eeprom, (offset + QSFP_CHANNL_MON_OFFSET), QSFP_CHANNL_MON_WIDTH) + dom_channel_monitor_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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: @@ -418,9 +424,11 @@ def get_transceiver_dom_info_dict(self, port_num): transceiver_dom_info_dict['tx3power'] = 'N/A' transceiver_dom_info_dict['tx4power'] = 'N/A' else: - dom_channel_monitor_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + QSFP_CHANNL_MON_OFFSET), QSFP_CHANNL_MON_WITH_TX_POWER_WIDTH) + dom_channel_monitor_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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 @@ -453,16 +461,16 @@ def get_transceiver_dom_info_dict(self, port_num): return None try: - sysfsfile_eeprom = io.open(file_path,"rb",0) + sysfsfile_eeprom = io.open(file_path, "rb", 0) except IOError: print("Error: reading sysfs file %s" % file_path) return None - sfpd_obj = sff8472Dom(None,1) + sfpd_obj = sff8472Dom(None, 1) if sfpd_obj is None: return None dom_temperature_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_TEMPE_OFFSET), - SFP_TEMPE_WIDTH) + SFP_TEMPE_WIDTH) if dom_temperature_raw is not None: dom_temperature_data = sfpd_obj.parse_temperature(dom_temperature_raw, 0) @@ -470,7 +478,7 @@ def get_transceiver_dom_info_dict(self, port_num): return transceiver_dom_info_dict dom_voltage_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_VOLT_OFFSET), - SFP_VOLT_WIDTH) + SFP_VOLT_WIDTH) if dom_voltage_raw is not None: dom_voltage_data = sfpd_obj.parse_voltage(dom_voltage_raw, 0) @@ -519,7 +527,7 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): 'txpowerlowalarm', 'txpowerlowwarning', 'txbiashighalarm', 'txbiashighwarning', 'txbiaslowalarm', 'txbiaslowwarning' - ] + ] transceiver_dom_threshold_info_dict = dict.fromkeys(dom_info_dict_keys, 'N/A') if port_num in self.qsfp_ports: @@ -541,18 +549,18 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): # Revert offset back to 0 once data is retrieved offset = 384 dom_module_threshold_raw = self._read_eeprom_specific_bytes( - sysfsfile_eeprom, - (offset + QSFP_MODULE_THRESHOLD_OFFSET), - QSFP_MODULE_THRESHOLD_WIDTH) + sysfsfile_eeprom, + (offset + QSFP_MODULE_THRESHOLD_OFFSET), + QSFP_MODULE_THRESHOLD_WIDTH) if dom_module_threshold_raw is not None: dom_module_threshold_data = sfpd_obj.parse_module_threshold_values(dom_module_threshold_raw, 0) else: return transceiver_dom_threshold_info_dict dom_channel_threshold_raw = self._read_eeprom_specific_bytes( - sysfsfile_eeprom, - (offset + QSFP_CHANNL_THRESHOLD_OFFSET), - QSFP_CHANNL_THRESHOLD_WIDTH) + sysfsfile_eeprom, + (offset + QSFP_CHANNL_THRESHOLD_OFFSET), + QSFP_CHANNL_THRESHOLD_WIDTH) if dom_channel_threshold_raw is not None: dom_channel_threshold_data = sfpd_obj.parse_channel_threshold_values(dom_channel_threshold_raw, 0) else: @@ -589,17 +597,17 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): return None try: - sysfsfile_eeprom = io.open(file_path,"rb",0) + sysfsfile_eeprom = io.open(file_path, "rb", 0) except IOError: print("Error: reading sysfs file %s" % file_path) return None - sfpd_obj = sff8472Dom(None,1) + sfpd_obj = sff8472Dom(None, 1) if sfpd_obj is None: return transceiver_dom_threshold_info_dict dom_module_threshold_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, - (offset + SFP_MODULE_THRESHOLD_OFFSET), SFP_MODULE_THRESHOLD_WIDTH) + (offset + SFP_MODULE_THRESHOLD_OFFSET), SFP_MODULE_THRESHOLD_WIDTH) if dom_module_threshold_raw is not None: dom_module_threshold_data = sfpd_obj.parse_alarm_warning_threshold(dom_module_threshold_raw, 0) @@ -612,7 +620,7 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): print("Error: closing sysfs file %s" % file_path) return None - #Threshold Data + # Threshold Data transceiver_dom_threshold_info_dict['temphighalarm'] = dom_module_threshold_data['data']['TempHighAlarm']['value'] transceiver_dom_threshold_info_dict['templowalarm'] = dom_module_threshold_data['data']['TempLowAlarm']['value'] transceiver_dom_threshold_info_dict['temphighwarning'] = dom_module_threshold_data['data']['TempHighWarning']['value'] diff --git a/device/dell/x86_64-dellemc_z9332f_d1508-r0/plugins/psuutil.py b/device/dell/x86_64-dellemc_z9332f_d1508-r0/plugins/psuutil.py index d098693217d0..435f9b2929ec 100644 --- a/device/dell/x86_64-dellemc_z9332f_d1508-r0/plugins/psuutil.py +++ b/device/dell/x86_64-dellemc_z9332f_d1508-r0/plugins/psuutil.py @@ -54,15 +54,15 @@ def get_pmc_register(self, reg_name): ipmi_cmd_2 = IPMI_PSU1_DATA dockerenv = self.isDockerEnv() if dockerenv == True: - if index == 1: - status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA_DOCKER) - elif index == 2: - status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA_DOCKER) + if index == 1: + status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA_DOCKER) + elif index == 2: + status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA_DOCKER) else: - if index == 1: - status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA) - elif index == 2: - status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA) + if index == 1: + status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA) + elif index == 2: + status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA) if status: logging.error('Failed to execute ipmitool') @@ -106,25 +106,24 @@ def get_psu_presence(self, index): ipmi_dev_node = "/dev/pmi0" dockerenv = self.isDockerEnv() if dockerenv == True: - if index == 1: - status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA_DOCKER) - elif index == 2: - status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA_DOCKER) + if index == 1: + status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA_DOCKER) + elif index == 2: + status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA_DOCKER) else: - if index == 1: - status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA) - elif index == 2: - ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA) + if index == 1: + status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU1_DATA) + elif index == 2: + ret_status, ipmi_sdr_list = commands.getstatusoutput(IPMI_PSU2_DATA) - #if ret_status: - # print ipmi_sdr_list - # logging.error('Failed to execute ipmitool') - # sys.exit(0) + # if ret_status: + # print ipmi_sdr_list + # logging.error('Failed to execute ipmitool') + # sys.exit(0) psu_status = ipmi_sdr_list if psu_status == '1': - status = 1 + status = 1 return status - diff --git a/device/dell/x86_64-dellemc_z9332f_d1508-r0/plugins/sfputil.py b/device/dell/x86_64-dellemc_z9332f_d1508-r0/plugins/sfputil.py index b9c9acf34ede..d037fd9273dd 100644 --- a/device/dell/x86_64-dellemc_z9332f_d1508-r0/plugins/sfputil.py +++ b/device/dell/x86_64-dellemc_z9332f_d1508-r0/plugins/sfputil.py @@ -16,14 +16,11 @@ except ImportError as e: raise ImportError("%s - required module not found" % str(e)) -#from xcvrd +# from xcvrd SFP_STATUS_REMOVED = '0' SFP_STATUS_INSERTED = '1' - - - class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" @@ -34,41 +31,41 @@ class SfpUtil(SfpUtilBase): BASE_RES_PATH = "/sys/bus/pci/devices/0000:09:00.0/resource0" _port_to_i2c_mapping = { - 1: 10, - 2: 11, - 3: 12, - 4: 13, - 5: 14, - 6: 15, - 7: 16, - 8: 17, - 9: 18, - 10: 19, - 11: 20, - 12: 21, - 13: 22, - 14: 23, - 15: 24, - 16: 25, - 17: 26, - 18: 27, - 19: 28, - 20: 29, - 21: 30, - 22: 31, - 23: 32, - 24: 33, - 25: 34, - 26: 35, - 27: 36, - 28: 37, - 29: 38, - 30: 39, - 31: 40, - 32: 41, - 33: 1, - 34: 2, - } + 1: 10, + 2: 11, + 3: 12, + 4: 13, + 5: 14, + 6: 15, + 7: 16, + 8: 17, + 9: 18, + 10: 19, + 11: 20, + 12: 21, + 13: 22, + 14: 23, + 15: 24, + 16: 25, + 17: 26, + 18: 27, + 19: 28, + 20: 29, + 21: 30, + 22: 31, + 23: 32, + 24: 33, + 25: 34, + 26: 35, + 27: 36, + 28: 37, + 29: 38, + 30: 39, + 31: 40, + 32: 41, + 33: 1, + 34: 2, + } _port_to_eeprom_mapping = {} @@ -128,27 +125,26 @@ def init_global_port_presence(self): self._global_port_pres_dict[port_num] = '0' def mod_pres(self): - port_pres_mask =0 + port_pres_mask = 0 for port_num in range(self.port_start, (self.port_end + 1)): presence = self.get_presence(port_num) if(presence): self._global_port_pres_dict[port_num] = '1' - port_val = (1 << (port_num -1)) + port_val = (1 << (port_num - 1)) port_pres_mask = (port_pres_mask | port_val) else: self._global_port_pres_dict[port_num] = '0' - port_val = ~(1 << (port_num -1)) + port_val = ~(1 << (port_num - 1)) port_pres_mask = (port_pres_mask & port_val) return port_pres_mask - def __init__(self): eeprom_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-0050/eeprom" for x in range(self.port_start, self.port_end + 1): self.port_to_eeprom_mapping[x] = eeprom_path.format( - self._port_to_i2c_mapping[x]) + self._port_to_i2c_mapping[x]) self.init_global_port_presence() SfpUtilBase.__init__(self) @@ -172,7 +168,7 @@ def get_presence(self, port_num): # Mask off 1st bit for presence 33,34 if (port_num > 32): - mask = (1 << 0) + mask = (1 << 0) # ModPrsL is active low if reg_value & mask == 0: @@ -271,21 +267,21 @@ def reset(self, port_num): return True def get_register(self, reg_file): - retval = 'ERR' - if (not path.isfile(reg_file)): - print(reg_file + ' not found !') - return retval - - try: - with fdopen(open(reg_file, O_RDONLY)) as fd: - retval = fd.read() - except Exception as error: - logging.error("Unable to open ", reg_file, "file !") - - retval = retval.rstrip('\r\n') - retval = retval.lstrip(" ") + retval = 'ERR' + if (not path.isfile(reg_file)): + print(reg_file + ' not found !') return retval + try: + with fdopen(open(reg_file, O_RDONLY)) as fd: + retval = fd.read() + except Exception as error: + logging.error("Unable to open ", reg_file, "file !") + + retval = retval.rstrip('\r\n') + retval = retval.lstrip(" ") + return retval + def get_transceiver_change_event(self): port_dict = {} while True: @@ -303,5 +299,3 @@ def get_transceiver_change_event(self): return True, port_dict time.sleep(0.5) - - diff --git a/device/delta/x86_64-delta_ag5648-r0/plugins/psuutil.py b/device/delta/x86_64-delta_ag5648-r0/plugins/psuutil.py index 0d17ff05681a..8aa080166f8a 100644 --- a/device/delta/x86_64-delta_ag5648-r0/plugins/psuutil.py +++ b/device/delta/x86_64-delta_ag5648-r0/plugins/psuutil.py @@ -3,7 +3,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" @@ -15,7 +16,6 @@ def __init__(self): self.psu_oper_status = "in1_input" self.psu_presence = "i2cget -y 6 0x{} 0x00" - def get_num_psus(self): """ Retrieves the number of PSUs available on the device @@ -31,7 +31,7 @@ def get_psu_status(self, index): status = 0 try: with open(self.psu_path.format(index + Base_bus_number) + self.psu_oper_status, 'r') as power_status: - if int(power_status.read()) == 0 : + if int(power_status.read()) == 0: return False else: status = 1 @@ -45,12 +45,10 @@ def get_psu_presence(self, index): Base_bus_number = 49 status = 0 try: - p = os.popen(self.psu_presence.format(index + Base_bus_number)+ "> /dev/null 2>&1") + p = os.popen(self.psu_presence.format(index + Base_bus_number) + "> /dev/null 2>&1") if p.readline() != None: status = 1 p.close() except IOError: return False return status == 1 - - diff --git a/device/delta/x86_64-delta_ag9032v1-r0/plugins/psuutil.py b/device/delta/x86_64-delta_ag9032v1-r0/plugins/psuutil.py index 4b370d9a7443..391efbd2401f 100644 --- a/device/delta/x86_64-delta_ag9032v1-r0/plugins/psuutil.py +++ b/device/delta/x86_64-delta_ag9032v1-r0/plugins/psuutil.py @@ -3,7 +3,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" @@ -15,7 +16,6 @@ def __init__(self): self.psu_oper_status = "in1_input" self.psu_presence = "i2cget -y {} 0x50 0x00" - def get_num_psus(self): """ Retrieves the number of PSUs available on the device @@ -29,10 +29,10 @@ def get_psu_status(self, index): return False Base_bus_number = 39 status = 0 - #index from 1, psu attribute bus from 40 + # index from 1, psu attribute bus from 40 try: with open(self.psu_path.format(index + Base_bus_number) + self.psu_oper_status, 'r') as power_status: - if int(power_status.read()) == 0 : + if int(power_status.read()) == 0: return False else: status = 1 @@ -46,12 +46,10 @@ def get_psu_presence(self, index): Base_bus_number = 39 status = 0 try: - p = os.popen(self.psu_presence.format(index + Base_bus_number)+ "> /dev/null 2>&1") + p = os.popen(self.psu_presence.format(index + Base_bus_number) + "> /dev/null 2>&1") if p.readline() != None: status = 1 p.close() except IOError: return False return status == 1 - - diff --git a/device/delta/x86_64-delta_ag9032v2a-r0/plugins/psuutil.py b/device/delta/x86_64-delta_ag9032v2a-r0/plugins/psuutil.py index 93936664c1c5..06655c07a416 100644 --- a/device/delta/x86_64-delta_ag9032v2a-r0/plugins/psuutil.py +++ b/device/delta/x86_64-delta_ag9032v2a-r0/plugins/psuutil.py @@ -9,7 +9,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" @@ -52,7 +53,6 @@ def get_psu_status(self, index): return False return status == 1 - def get_psu_presence(self, index): """ Retrieves the presence status of power supply unit (PSU) defined @@ -72,14 +72,13 @@ def get_psu_presence(self, index): if index == 1: mask = (1 << 7) if reg_value & mask == 0x80: - return False + return False else: mask = (1 << 3) if reg_value & mask == 0x08: - return False + return False status = 1 p.close() except IOError: return False return status == 1 - diff --git a/device/delta/x86_64-delta_ag9064-r0/plugins/psuutil.py b/device/delta/x86_64-delta_ag9064-r0/plugins/psuutil.py index 2a2bd1eea6a2..43f7bb6acb3c 100644 --- a/device/delta/x86_64-delta_ag9064-r0/plugins/psuutil.py +++ b/device/delta/x86_64-delta_ag9064-r0/plugins/psuutil.py @@ -9,7 +9,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" @@ -44,15 +45,13 @@ def get_psu_status(self, index): content = p.readline().rstrip() reg_value = int(content) if reg_value != 0: - return False + return False status = 1 p.close() except IOError: return False return status == 1 - - def get_psu_presence(self, index): """ Retrieves the presence status of power supply unit (PSU) defined @@ -75,4 +74,3 @@ def get_psu_presence(self, index): except IOError: return False return status == 1 - diff --git a/device/delta/x86_64-delta_agc032-r0/plugins/eeprom.py b/device/delta/x86_64-delta_agc032-r0/plugins/eeprom.py index a57cd91c0ca0..c252fd69f678 100644 --- a/device/delta/x86_64-delta_agc032-r0/plugins/eeprom.py +++ b/device/delta/x86_64-delta_agc032-r0/plugins/eeprom.py @@ -1,10 +1,12 @@ try: from sonic_eeprom import eeprom_tlvinfo except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/devices/pci0000:00/0000:00:1f.3/i2c-0/0-0053/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/delta/x86_64-delta_agc032-r0/plugins/psuutil.py b/device/delta/x86_64-delta_agc032-r0/plugins/psuutil.py index 0636417def1f..0cb47cad1bf9 100644 --- a/device/delta/x86_64-delta_agc032-r0/plugins/psuutil.py +++ b/device/delta/x86_64-delta_agc032-r0/plugins/psuutil.py @@ -3,7 +3,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" @@ -16,7 +17,6 @@ def __init__(self): self.psu_oper_status2 = "in2_input" self.psu_presence = "i2cget -y {} 0x50 0x00" - def get_num_psus(self): """ Retrieves the number of PSUs available on the device @@ -30,14 +30,14 @@ def get_psu_status(self, index): return False Base_bus_number = 0 status = 0 - #index from 1, psu attribute bus from 40 + # index from 1, psu attribute bus from 40 try: with open(self.psu_path.format(index + Base_bus_number) + self.psu_oper_status, 'r') as power_status: - if int(power_status.read()) == 0 : + if int(power_status.read()) == 0: return False else: with open(self.psu_path.format(index + Base_bus_number) + self.psu_oper_status2, 'r') as power_status2: - if int(power_status2.read()) == 0 : + if int(power_status2.read()) == 0: return False else: status = 1 @@ -51,12 +51,10 @@ def get_psu_presence(self, index): Base_bus_number = 0 status = 0 try: - p = os.popen(self.psu_presence.format(index + Base_bus_number)+ "> /dev/null 2>&1") + p = os.popen(self.psu_presence.format(index + Base_bus_number) + "> /dev/null 2>&1") if p.readline() != None: status = 1 p.close() except IOError: return False return status == 1 - - diff --git a/device/delta/x86_64-delta_agc032-r0/plugins/sfputil.py b/device/delta/x86_64-delta_agc032-r0/plugins/sfputil.py index b6a2601e42ac..e9b02c6c77c6 100644 --- a/device/delta/x86_64-delta_agc032-r0/plugins/sfputil.py +++ b/device/delta/x86_64-delta_agc032-r0/plugins/sfputil.py @@ -13,6 +13,7 @@ except ImportError as e: raise ImportError("%s - required module not found" % str(e)) + class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" @@ -58,7 +59,7 @@ def get_presence(self, port_num): port = (str(port_num + 1)).zfill(2) # SWPLD2 for port 1~16, SWPLD3 for port 17~34 - if port_num < 16: + if port_num < 16: present_path = "SWPLD2/qsfp_p{}_modprs".format(port) elif port_num < self.PORTS_IN_BLOCK: present_path = "SWPLD3/qsfp_p{}_modprs".format(port) diff --git a/device/delta/x86_64-delta_et-6248brb-r0/plugins/psuutil.py b/device/delta/x86_64-delta_et-6248brb-r0/plugins/psuutil.py index 35dac38245d6..c6ec180bfc06 100644 --- a/device/delta/x86_64-delta_et-6248brb-r0/plugins/psuutil.py +++ b/device/delta/x86_64-delta_et-6248brb-r0/plugins/psuutil.py @@ -3,7 +3,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" @@ -15,7 +16,6 @@ def __init__(self): self.psu_oper_status = "in1_input" self.psu_presence = "/sys/devices/platform/delta-et6248brb-gpio.0/PSU/psu{}_pres" - def get_num_psus(self): """ Retrieves the number of PSUs available on the device diff --git a/device/delta/x86_64-delta_et-c032if-r0/plugins/psuutil.py b/device/delta/x86_64-delta_et-c032if-r0/plugins/psuutil.py index 80383aaffddf..4eb3bb87db80 100644 --- a/device/delta/x86_64-delta_et-c032if-r0/plugins/psuutil.py +++ b/device/delta/x86_64-delta_et-c032if-r0/plugins/psuutil.py @@ -9,7 +9,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" @@ -44,15 +45,13 @@ def get_psu_status(self, index): reg_value = int(content, 16) mask = (1 << (8 - index)) if reg_value & mask == 0: - return False + return False status = 1 p.close() except IOError: return False return status == 1 - - def get_psu_presence(self, index): """ Retrieves the presence status of power supply unit (PSU) defined @@ -75,4 +74,3 @@ def get_psu_presence(self, index): except IOError: return False return status == 1 - diff --git a/device/delta/x86_64-delta_et-c032if-r0/plugins/sfputil.py b/device/delta/x86_64-delta_et-c032if-r0/plugins/sfputil.py index fc607c8b84f4..25b1ba3abdeb 100644 --- a/device/delta/x86_64-delta_et-c032if-r0/plugins/sfputil.py +++ b/device/delta/x86_64-delta_et-c032if-r0/plugins/sfputil.py @@ -60,7 +60,6 @@ def get_transceiver_status(self): return int(content, 16) - def __init__(self): eeprom_path = "/sys/kernel/sfp/eeprom_sfp_{0}" @@ -207,17 +206,17 @@ def get_transceiver_change_event(self, timeout=0): if timeout == 0: forever = True elif timeout > 0: - timeout = timeout / float(1000) # Convert to secs + timeout = timeout / float(1000) # Convert to secs else: print("get_transceiver_change_event:Invalid timeout value", timeout) return False, {} end_time = start_time + timeout if start_time > end_time: - print('get_transceiver_change_event:' \ - 'time wrap / invalid timeout value', timeout) + print('get_transceiver_change_event:' + 'time wrap / invalid timeout value', timeout) - return False, {} # Time wrap or possibly incorrect timeout + return False, {} # Time wrap or possibly incorrect timeout while timeout >= 0: # Check for OIR events and return updated port_dict reg_value = self.get_transceiver_status @@ -246,7 +245,7 @@ def get_transceiver_change_event(self, timeout=0): else: timeout = end_time - time.time() if timeout >= 1: - time.sleep(1) # We poll at 1 second granularity + time.sleep(1) # We poll at 1 second granularity else: if timeout > 0: time.sleep(timeout) diff --git a/device/ingrasys/x86_64-ingrasys_s8810_32q-r0/plugins/eeprom.py b/device/ingrasys/x86_64-ingrasys_s8810_32q-r0/plugins/eeprom.py index f669e3d14692..8f9ee7d9989b 100644 --- a/device/ingrasys/x86_64-ingrasys_s8810_32q-r0/plugins/eeprom.py +++ b/device/ingrasys/x86_64-ingrasys_s8810_32q-r0/plugins/eeprom.py @@ -10,7 +10,7 @@ try: from sonic_eeprom import eeprom_tlvinfo except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/ingrasys/x86_64-ingrasys_s8810_32q-r0/plugins/psuutil.py b/device/ingrasys/x86_64-ingrasys_s8810_32q-r0/plugins/psuutil.py index 7e69360b0402..fcf9136d25db 100644 --- a/device/ingrasys/x86_64-ingrasys_s8810_32q-r0/plugins/psuutil.py +++ b/device/ingrasys/x86_64-ingrasys_s8810_32q-r0/plugins/psuutil.py @@ -20,12 +20,12 @@ class PsuUtil(PsuBase): def __init__(self): PsuBase.__init__(self) - - + # Get sysfs attribute + def get_attr_value(self, attr_path): - - retval = 'ERR' + + retval = 'ERR' if (not os.path.isfile(attr_path)): return retval @@ -55,16 +55,16 @@ def get_psu_status(self, index): faulty """ status = 0 - attr_file = 'psu_pg' - attr_path = self.SYSFS_PSU_DIR[index-1] +'/' + attr_file - + attr_file = 'psu_pg' + attr_path = self.SYSFS_PSU_DIR[index-1] + '/' + attr_file + attr_value = self.get_attr_value(attr_path) - + if (attr_value != 'ERR'): attr_value = int(attr_value, 16) # Check for PSU status if (attr_value == 1): - status = 1 + status = 1 return status @@ -77,16 +77,15 @@ def get_psu_presence(self, index): """ status = 0 psu_absent = 0 - attr_file ='psu_abs' - attr_path = self.SYSFS_PSU_DIR[index-1] +'/' + attr_file - + attr_file = 'psu_abs' + attr_path = self.SYSFS_PSU_DIR[index-1] + '/' + attr_file + attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): attr_value = int(attr_value, 16) # Check for PSU presence if (attr_value == 0): - status = 1 + status = 1 return status - diff --git a/device/ingrasys/x86_64-ingrasys_s8810_32q-r0/plugins/sfputil.py b/device/ingrasys/x86_64-ingrasys_s8810_32q-r0/plugins/sfputil.py index 9bdc732c7ed5..c1afbdf0738d 100644 --- a/device/ingrasys/x86_64-ingrasys_s8810_32q-r0/plugins/sfputil.py +++ b/device/ingrasys/x86_64-ingrasys_s8810_32q-r0/plugins/sfputil.py @@ -55,11 +55,11 @@ def set_gpio_offset(self): for d in os.listdir(sys_gpio_dir): if "gpiochip" in d: try: - gpiochip_no = int(d[8:],10) + gpiochip_no = int(d[8:], 10) except ValueError as e: print("Error: %s" % str(e)) if gpiochip_no > 255: - self.GPIO_OFFSET=256 + self.GPIO_OFFSET = 256 return True return True @@ -89,7 +89,7 @@ def get_presence(self, port_num): try: abs_device_file = self.BASE_VAL_PATH.format( - port_num + self.ABS_GPIO_BASE) + port_num + self.ABS_GPIO_BASE) val_file = open(abs_device_file) except IOError as e: print("Error: unable to open file: %s" % str(e)) @@ -110,7 +110,7 @@ def get_low_power_mode(self, port_num): try: lpmode_val_device_file = self.BASE_VAL_PATH.format( - port_num + self.LP_GPIO_BASE) + port_num + self.LP_GPIO_BASE) val_file = open(lpmode_val_device_file) except IOError as e: print("Error: unable to open file: %s" % str(e)) @@ -131,7 +131,7 @@ def set_low_power_mode(self, port_num, lpmode): try: lpmode_val_device_file = self.BASE_VAL_PATH.format( - port_num + self.LP_GPIO_BASE) + port_num + self.LP_GPIO_BASE) val_file = open(lpmode_val_device_file, "w") except IOError as e: print("Error: unable to open file: %s" % str(e)) @@ -149,7 +149,7 @@ def reset(self, port_num): try: reset_val_device_file = self.BASE_VAL_PATH.format( - port_num + self.RST_GPIO_BASE) + port_num + self.RST_GPIO_BASE) val_file = open(reset_val_device_file, "w") except IOError as e: print("Error: unable to open file: %s" % str(e)) @@ -163,7 +163,7 @@ def reset(self, port_num): try: reset_val_device_file = self.BASE_VAL_PATH.format( - port_num + self.RST_GPIO_BASE) + port_num + self.RST_GPIO_BASE) val_file = open(reset_val_device_file, "w") except IOError as e: print("Error: unable to open file: %s" % str(e)) diff --git a/device/ingrasys/x86_64-ingrasys_s8900_54xc-r0/plugins/eeprom.py b/device/ingrasys/x86_64-ingrasys_s8900_54xc-r0/plugins/eeprom.py index 200b59c55c90..fcfaf8a27947 100644 --- a/device/ingrasys/x86_64-ingrasys_s8900_54xc-r0/plugins/eeprom.py +++ b/device/ingrasys/x86_64-ingrasys_s8900_54xc-r0/plugins/eeprom.py @@ -10,7 +10,7 @@ try: from sonic_eeprom import eeprom_tlvinfo except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/ingrasys/x86_64-ingrasys_s8900_54xc-r0/plugins/psuutil.py b/device/ingrasys/x86_64-ingrasys_s8900_54xc-r0/plugins/psuutil.py index 4f226c69fff3..ef45a0c91727 100644 --- a/device/ingrasys/x86_64-ingrasys_s8900_54xc-r0/plugins/psuutil.py +++ b/device/ingrasys/x86_64-ingrasys_s8900_54xc-r0/plugins/psuutil.py @@ -19,12 +19,12 @@ class PsuUtil(PsuBase): def __init__(self): PsuBase.__init__(self) - - + # Get sysfs attribute + def get_attr_value(self, attr_path): - - retval = 'ERR' + + retval = 'ERR' if (not os.path.isfile(attr_path)): return retval @@ -54,17 +54,17 @@ def get_psu_status(self, index): faulty """ status = 0 - mask = [ 0x08, 0x10 ] - attr_file = 'cpld_pw_good' - attr_path = self.PSU_CPLD_DIR +'/'+ attr_file - + mask = [0x08, 0x10] + attr_file = 'cpld_pw_good' + attr_path = self.PSU_CPLD_DIR + '/' + attr_file + attr_value = self.get_attr_value(attr_path) - + if (attr_value != 'ERR'): attr_value = int(attr_value, 16) # Check for PSU status if (attr_value & mask[index-1]): - status = 1 + status = 1 return status @@ -76,17 +76,16 @@ def get_psu_presence(self, index): :return: Boolean, True if PSU is plugged, False if not """ status = 0 - mask = [ 0x01, 0x02 ] - attr_file ='cpld_pw_abs' - attr_path = self.PSU_CPLD_DIR +'/'+ attr_file - + mask = [0x01, 0x02] + attr_file = 'cpld_pw_abs' + attr_path = self.PSU_CPLD_DIR + '/' + attr_file + attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): attr_value = int(attr_value, 16) # Check for PSU presence if (~attr_value & mask[index-1]): - status = 1 + status = 1 return status - diff --git a/device/ingrasys/x86_64-ingrasys_s8900_54xc-r0/plugins/sfputil.py b/device/ingrasys/x86_64-ingrasys_s8900_54xc-r0/plugins/sfputil.py index 8fdea71c64f3..c7a4dfa471b6 100644 --- a/device/ingrasys/x86_64-ingrasys_s8900_54xc-r0/plugins/sfputil.py +++ b/device/ingrasys/x86_64-ingrasys_s8900_54xc-r0/plugins/sfputil.py @@ -113,11 +113,11 @@ def set_gpio_offset(self): for d in os.listdir(sys_gpio_dir): if "gpiochip" in d: try: - gpiochip_no = int(d[8:],10) + gpiochip_no = int(d[8:], 10) except ValueError as e: print("Error: %s" % str(e)) if gpiochip_no > 255: - self.GPIO_OFFSET=256 + self.GPIO_OFFSET = 256 return True return True @@ -225,7 +225,7 @@ def get_presence(self, port_num): try: abs_device_file = self.BASE_VAL_PATH.format( - self.abs_to_gpio_mapping[port_num]) + self.abs_to_gpio_mapping[port_num]) val_file = open(abs_device_file) except IOError as e: print("Error: unable to open file: %s" % str(e)) @@ -246,7 +246,7 @@ def get_low_power_mode(self, port_num): try: lpmode_val_device_file = self.BASE_VAL_PATH.format( - self.lpmode_to_gpio_mapping[port_num]) + self.lpmode_to_gpio_mapping[port_num]) val_file = open(lpmode_val_device_file) except IOError as e: print("Error: unable to open file: %s" % str(e)) @@ -267,7 +267,7 @@ def set_low_power_mode(self, port_num, lpmode): try: lpmode_val_device_file = self.BASE_VAL_PATH.format( - self.lpmode_to_gpio_mapping[port_num]) + self.lpmode_to_gpio_mapping[port_num]) val_file = open(lpmode_val_device_file, "w") except IOError as e: print("Error: unable to open file: %s" % str(e)) @@ -287,7 +287,7 @@ def reset(self, port_num): try: print("port %s" % str(port_num)) reset_val_device_file = self.BASE_VAL_PATH.format( - self.reset_to_gpio_mapping[port_num]) + self.reset_to_gpio_mapping[port_num]) val_file = open(reset_val_device_file, "w") except IOError as e: print("Error: unable to open file: %s" % str(e)) @@ -301,7 +301,7 @@ def reset(self, port_num): try: reset_val_device_file = self.BASE_VAL_PATH.format( - self.reset_to_gpio_mapping[port_num]) + self.reset_to_gpio_mapping[port_num]) val_file = open(reset_val_device_file, "w") except IOError as e: print("Error: unable to open file: %s" % str(e)) diff --git a/device/ingrasys/x86_64-ingrasys_s8900_64xc-r0/plugins/eeprom.py b/device/ingrasys/x86_64-ingrasys_s8900_64xc-r0/plugins/eeprom.py index 574e6ac06b2f..1737549081a6 100644 --- a/device/ingrasys/x86_64-ingrasys_s8900_64xc-r0/plugins/eeprom.py +++ b/device/ingrasys/x86_64-ingrasys_s8900_64xc-r0/plugins/eeprom.py @@ -10,7 +10,7 @@ try: from sonic_eeprom import eeprom_tlvinfo except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/ingrasys/x86_64-ingrasys_s8900_64xc-r0/plugins/psuutil.py b/device/ingrasys/x86_64-ingrasys_s8900_64xc-r0/plugins/psuutil.py index 3af5423daebd..e97e3193fd64 100644 --- a/device/ingrasys/x86_64-ingrasys_s8900_64xc-r0/plugins/psuutil.py +++ b/device/ingrasys/x86_64-ingrasys_s8900_64xc-r0/plugins/psuutil.py @@ -19,12 +19,12 @@ class PsuUtil(PsuBase): def __init__(self): PsuBase.__init__(self) - - + # Get sysfs attribute + def get_attr_value(self, attr_path): - - retval = 'ERR' + + retval = 'ERR' if (not os.path.isfile(attr_path)): return retval @@ -54,17 +54,17 @@ def get_psu_status(self, index): faulty """ status = 0 - mask = [ 0x04, 0x08 ] - attr_file = 'cpld_pw_good' - attr_path = self.PSU_CPLD_DIR +'/'+ attr_file - + mask = [0x04, 0x08] + attr_file = 'cpld_pw_good' + attr_path = self.PSU_CPLD_DIR + '/' + attr_file + attr_value = self.get_attr_value(attr_path) - + if (attr_value != 'ERR'): attr_value = int(attr_value, 16) # Check for PSU status if (attr_value & mask[index-1]): - status = 1 + status = 1 return status @@ -76,17 +76,16 @@ def get_psu_presence(self, index): :return: Boolean, True if PSU is plugged, False if not """ status = 0 - mask = [ 0x01, 0x02 ] - attr_file ='cpld_pw_abs' - attr_path = self.PSU_CPLD_DIR +'/'+ attr_file - + mask = [0x01, 0x02] + attr_file = 'cpld_pw_abs' + attr_path = self.PSU_CPLD_DIR + '/' + attr_file + attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): attr_value = int(attr_value, 16) # Check for PSU presence if (~attr_value & mask[index-1]): - status = 1 + status = 1 return status - diff --git a/device/ingrasys/x86_64-ingrasys_s8900_64xc-r0/plugins/sfputil.py b/device/ingrasys/x86_64-ingrasys_s8900_64xc-r0/plugins/sfputil.py index 7931cb5f1bb9..cc2c01d3bd33 100644 --- a/device/ingrasys/x86_64-ingrasys_s8900_64xc-r0/plugins/sfputil.py +++ b/device/ingrasys/x86_64-ingrasys_s8900_64xc-r0/plugins/sfputil.py @@ -16,6 +16,7 @@ cpld_addr = '0x33' mux_reg = '0x4A' + class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" @@ -26,70 +27,70 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} port_to_i2c_mapping = { - 0: [2,1], - 1: [2,2], - 2: [2,3], - 3: [2,4], - 4: [2,5], - 5: [2,6], - 6: [2,7], - 7: [2,8], - 8: [2,9], - 9: [2,10], - 10: [2,11], - 11: [2,12], - 12: [2,13], - 13: [2,14], - 14: [2,15], - 15: [2,16], - 16: [2,17], - 17: [2,18], - 18: [2,19], - 19: [2,20], - 20: [2,21], - 21: [2,22], - 22: [2,23], - 23: [2,24], - 24: [3,25], - 25: [3,26], - 26: [3,27], - 27: [3,28], - 28: [3,29], - 29: [3,30], - 30: [3,31], - 31: [3,32], - 32: [3,33], - 33: [3,34], - 34: [3,35], - 35: [3,36], - 36: [3,37], - 37: [3,38], - 38: [3,39], - 39: [3,40], - 40: [3,41], - 41: [3,42], - 42: [3,43], - 43: [3,44], - 44: [3,45], - 45: [3,46], - 46: [3,47], - 47: [3,48], - 48: [4,49], - 49: [4,50], - 50: [4,51], - 51: [4,52], - 52: [4,53], - 53: [4,54], - 54: [4,55], - 55: [4,56], - 56: [4,57], - 57: [4,58], - 58: [4,59], - 59: [4,60], - 60: [4,61], - 61: [4,62], - 62: [4,63], - 63: [4,64] + 0: [2, 1], + 1: [2, 2], + 2: [2, 3], + 3: [2, 4], + 4: [2, 5], + 5: [2, 6], + 6: [2, 7], + 7: [2, 8], + 8: [2, 9], + 9: [2, 10], + 10: [2, 11], + 11: [2, 12], + 12: [2, 13], + 13: [2, 14], + 14: [2, 15], + 15: [2, 16], + 16: [2, 17], + 17: [2, 18], + 18: [2, 19], + 19: [2, 20], + 20: [2, 21], + 21: [2, 22], + 22: [2, 23], + 23: [2, 24], + 24: [3, 25], + 25: [3, 26], + 26: [3, 27], + 27: [3, 28], + 28: [3, 29], + 29: [3, 30], + 30: [3, 31], + 31: [3, 32], + 32: [3, 33], + 33: [3, 34], + 34: [3, 35], + 35: [3, 36], + 36: [3, 37], + 37: [3, 38], + 38: [3, 39], + 39: [3, 40], + 40: [3, 41], + 41: [3, 42], + 42: [3, 43], + 43: [3, 44], + 44: [3, 45], + 45: [3, 46], + 46: [3, 47], + 47: [3, 48], + 48: [4, 49], + 49: [4, 50], + 50: [4, 51], + 51: [4, 52], + 52: [4, 53], + 53: [4, 54], + 54: [4, 55], + 55: [4, 56], + 56: [4, 57], + 57: [4, 58], + 58: [4, 59], + 59: [4, 60], + 60: [4, 61], + 61: [4, 62], + 62: [4, 63], + 63: [4, 64] } @property @@ -167,7 +168,7 @@ def get_low_power_mode(self, port_num): reg_value = int(content, 16) # Mask off the bit corresponding to our port - mask = (1 << (port_num - self.qsfp_port_start) ) + mask = (1 << (port_num - self.qsfp_port_start)) # LPMode is active high if reg_value & mask == 0: @@ -192,7 +193,7 @@ def set_low_power_mode(self, port_num, lpmode): reg_value = int(content, 16) # Mask off the bit corresponding to our port - mask = (1 << (port_num - self.qsfp_port_start) ) + mask = (1 << (port_num - self.qsfp_port_start)) # LPMode is active high; set or clear the bit accordingly if lpmode is True: diff --git a/device/ingrasys/x86_64-ingrasys_s9100-r0/plugins/eeprom.py b/device/ingrasys/x86_64-ingrasys_s9100-r0/plugins/eeprom.py index 198aab9035b4..1c23602fcb5a 100644 --- a/device/ingrasys/x86_64-ingrasys_s9100-r0/plugins/eeprom.py +++ b/device/ingrasys/x86_64-ingrasys_s9100-r0/plugins/eeprom.py @@ -10,7 +10,7 @@ try: from sonic_eeprom import eeprom_tlvinfo except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/ingrasys/x86_64-ingrasys_s9100-r0/plugins/psuutil.py b/device/ingrasys/x86_64-ingrasys_s9100-r0/plugins/psuutil.py index 4f226c69fff3..ef45a0c91727 100644 --- a/device/ingrasys/x86_64-ingrasys_s9100-r0/plugins/psuutil.py +++ b/device/ingrasys/x86_64-ingrasys_s9100-r0/plugins/psuutil.py @@ -19,12 +19,12 @@ class PsuUtil(PsuBase): def __init__(self): PsuBase.__init__(self) - - + # Get sysfs attribute + def get_attr_value(self, attr_path): - - retval = 'ERR' + + retval = 'ERR' if (not os.path.isfile(attr_path)): return retval @@ -54,17 +54,17 @@ def get_psu_status(self, index): faulty """ status = 0 - mask = [ 0x08, 0x10 ] - attr_file = 'cpld_pw_good' - attr_path = self.PSU_CPLD_DIR +'/'+ attr_file - + mask = [0x08, 0x10] + attr_file = 'cpld_pw_good' + attr_path = self.PSU_CPLD_DIR + '/' + attr_file + attr_value = self.get_attr_value(attr_path) - + if (attr_value != 'ERR'): attr_value = int(attr_value, 16) # Check for PSU status if (attr_value & mask[index-1]): - status = 1 + status = 1 return status @@ -76,17 +76,16 @@ def get_psu_presence(self, index): :return: Boolean, True if PSU is plugged, False if not """ status = 0 - mask = [ 0x01, 0x02 ] - attr_file ='cpld_pw_abs' - attr_path = self.PSU_CPLD_DIR +'/'+ attr_file - + mask = [0x01, 0x02] + attr_file = 'cpld_pw_abs' + attr_path = self.PSU_CPLD_DIR + '/' + attr_file + attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): attr_value = int(attr_value, 16) # Check for PSU presence if (~attr_value & mask[index-1]): - status = 1 + status = 1 return status - diff --git a/device/ingrasys/x86_64-ingrasys_s9100-r0/plugins/sfputil.py b/device/ingrasys/x86_64-ingrasys_s9100-r0/plugins/sfputil.py index 593f287a14f1..f2da8544202c 100644 --- a/device/ingrasys/x86_64-ingrasys_s9100-r0/plugins/sfputil.py +++ b/device/ingrasys/x86_64-ingrasys_s9100-r0/plugins/sfputil.py @@ -86,11 +86,11 @@ def set_gpio_offset(self): for d in os.listdir(sys_gpio_dir): if "gpiochip" in d: try: - gpiochip_no = int(d[8:],10) + gpiochip_no = int(d[8:], 10) except ValueError as e: print("Error: %s" % str(e)) if gpiochip_no > 255: - self.GPIO_OFFSET=256 + self.GPIO_OFFSET = 256 return True return True @@ -228,7 +228,7 @@ def get_presence(self, port_num): try: abs_device_file = self.BASE_VAL_PATH.format( - self.abs_to_gpio_mapping[port_num]) + self.abs_to_gpio_mapping[port_num]) val_file = open(abs_device_file) except IOError as e: print("Error: unable to open file: %s" % str(e)) @@ -250,7 +250,7 @@ def get_low_power_mode(self, port_num): try: lpmode_val_device_file = self.BASE_VAL_PATH.format( - self.lpmode_to_gpio_mapping[port_num]) + self.lpmode_to_gpio_mapping[port_num]) val_file = open(lpmode_val_device_file) except IOError as e: print("Error: unable to open file: %s" % str(e)) @@ -272,7 +272,7 @@ def set_low_power_mode(self, port_num, lpmode): try: lpmode_val_device_file = self.BASE_VAL_PATH.format( - self.lpmode_to_gpio_mapping[port_num]) + self.lpmode_to_gpio_mapping[port_num]) val_file = open(lpmode_val_device_file, "w") except IOError as e: print("Error: unable to open file: %s" % str(e)) @@ -290,7 +290,7 @@ def reset(self, port_num): try: reset_val_device_file = self.BASE_VAL_PATH.format( - self.reset_to_gpio_mapping[port_num]) + self.reset_to_gpio_mapping[port_num]) val_file = open(reset_val_device_file, "w") except IOError as e: print("Error: unable to open file: %s" % str(e)) @@ -304,7 +304,7 @@ def reset(self, port_num): try: reset_val_device_file = self.BASE_VAL_PATH.format( - self.reset_to_gpio_mapping[port_num]) + self.reset_to_gpio_mapping[port_num]) val_file = open(reset_val_device_file, "w") except IOError as e: print("Error: unable to open file: %s" % str(e)) diff --git a/device/ingrasys/x86_64-ingrasys_s9130_32x-r0/plugins/eeprom.py b/device/ingrasys/x86_64-ingrasys_s9130_32x-r0/plugins/eeprom.py index a7faf85f5ca8..7496ebe21ada 100644 --- a/device/ingrasys/x86_64-ingrasys_s9130_32x-r0/plugins/eeprom.py +++ b/device/ingrasys/x86_64-ingrasys_s9130_32x-r0/plugins/eeprom.py @@ -10,7 +10,7 @@ try: from sonic_eeprom import eeprom_tlvinfo except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/ingrasys/x86_64-ingrasys_s9130_32x-r0/plugins/psuutil.py b/device/ingrasys/x86_64-ingrasys_s9130_32x-r0/plugins/psuutil.py index 4a029c15b1a6..37e2173aa9d2 100644 --- a/device/ingrasys/x86_64-ingrasys_s9130_32x-r0/plugins/psuutil.py +++ b/device/ingrasys/x86_64-ingrasys_s9130_32x-r0/plugins/psuutil.py @@ -20,12 +20,12 @@ class PsuUtil(PsuBase): def __init__(self): PsuBase.__init__(self) - - + # Get sysfs attribute + def get_attr_value(self, attr_path): - - retval = 'ERR' + + retval = 'ERR' if (not os.path.isfile(attr_path)): return retval @@ -55,16 +55,16 @@ def get_psu_status(self, index): faulty """ status = 0 - attr_file = 'psu_pg' - attr_path = self.SYSFS_PSU_DIR[index-1] +'/' + attr_file - + attr_file = 'psu_pg' + attr_path = self.SYSFS_PSU_DIR[index-1] + '/' + attr_file + attr_value = self.get_attr_value(attr_path) - + if (attr_value != 'ERR'): attr_value = int(attr_value, 16) # Check for PSU status if (attr_value == 1): - status = 1 + status = 1 return status @@ -77,16 +77,15 @@ def get_psu_presence(self, index): """ status = 0 psu_absent = 0 - attr_file ='psu_abs' - attr_path = self.SYSFS_PSU_DIR[index-1] +'/' + attr_file - + attr_file = 'psu_abs' + attr_path = self.SYSFS_PSU_DIR[index-1] + '/' + attr_file + attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): attr_value = int(attr_value, 16) # Check for PSU presence if (attr_value == 0): - status = 1 + status = 1 return status - diff --git a/device/ingrasys/x86_64-ingrasys_s9130_32x-r0/plugins/sfputil.py b/device/ingrasys/x86_64-ingrasys_s9130_32x-r0/plugins/sfputil.py index 06603aef6a0a..260c759c7993 100644 --- a/device/ingrasys/x86_64-ingrasys_s9130_32x-r0/plugins/sfputil.py +++ b/device/ingrasys/x86_64-ingrasys_s9130_32x-r0/plugins/sfputil.py @@ -54,11 +54,11 @@ def set_gpio_offset(self): for d in os.listdir(sys_gpio_dir): if "gpiochip" in d: try: - gpiochip_no = int(d[8:],10) + gpiochip_no = int(d[8:], 10) except ValueError as e: print("Error: %s" % str(e)) if gpiochip_no > 255: - self.GPIO_OFFSET=256 + self.GPIO_OFFSET = 256 return True return True @@ -92,9 +92,9 @@ def get_presence(self, port_num): # open corrsponding gpio file try: if port_num <= 15: - gpio_base = self.ABS_GPIO_BASE_0_15 - else : - gpio_base = self.ABS_GPIO_BASE_16_31 + gpio_base = self.ABS_GPIO_BASE_0_15 + else: + gpio_base = self.ABS_GPIO_BASE_16_31 gpio_index = gpio_base + (port_num % 16) gpio_file_path = self.GPIO_VAL_PATH.format(gpio_index) gpio_file = open(gpio_file_path) @@ -121,7 +121,7 @@ def get_low_power_mode(self, port_num): try: if port_num <= 15: gpio_base = self.LP_MODE_GPIO_BASE_0_15 - else : + else: gpio_base = self.LP_MODE_GPIO_BASE_16_31 gpio_index = gpio_base + (port_num % 16) gpio_file_path = self.GPIO_VAL_PATH.format(gpio_index) @@ -148,7 +148,7 @@ def set_low_power_mode(self, port_num, lpmode): try: if port_num <= 15: gpio_base = self.LP_MODE_GPIO_BASE_0_15 - else : + else: gpio_base = self.LP_MODE_GPIO_BASE_16_31 gpio_index = gpio_base + (port_num % 16) gpio_file_path = self.GPIO_VAL_PATH.format(gpio_index) @@ -179,7 +179,7 @@ def reset(self, port_num): try: if port_num <= 15: gpio_base = self.RST_GPIO_BASE_0_15 - else : + else: gpio_base = self.RST_GPIO_BASE_16_31 gpio_index = gpio_base + (port_num % 16) gpio_file_path = self.GPIO_VAL_PATH.format(gpio_index) @@ -209,7 +209,7 @@ def reset(self, port_num): # set gpio back low to take port out of reset # the gpio pin is ACTIVE_LOW but reversed gpio_val = "0" - # write value to gpio + # write value to gpio gpio_file.seek(0) gpio_file.write(gpio_val) gpio_file.close() diff --git a/device/ingrasys/x86_64-ingrasys_s9180_32x-r0/plugins/eeprom.py b/device/ingrasys/x86_64-ingrasys_s9180_32x-r0/plugins/eeprom.py index b5f65c52b696..f3fb959c2d01 100644 --- a/device/ingrasys/x86_64-ingrasys_s9180_32x-r0/plugins/eeprom.py +++ b/device/ingrasys/x86_64-ingrasys_s9180_32x-r0/plugins/eeprom.py @@ -10,7 +10,7 @@ try: from sonic_eeprom import eeprom_tlvinfo except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/ingrasys/x86_64-ingrasys_s9180_32x-r0/plugins/psuutil.py b/device/ingrasys/x86_64-ingrasys_s9180_32x-r0/plugins/psuutil.py index ec35a487eead..3ac4fa48afd0 100644 --- a/device/ingrasys/x86_64-ingrasys_s9180_32x-r0/plugins/psuutil.py +++ b/device/ingrasys/x86_64-ingrasys_s9180_32x-r0/plugins/psuutil.py @@ -25,11 +25,11 @@ def set_gpio_offset(self): for d in os.listdir(sys_gpio_dir): if "gpiochip" in d: try: - gpiochip_no = int(d[8:],10) + gpiochip_no = int(d[8:], 10) except ValueError as e: print("Error: %s" % str(e)) if gpiochip_no > 255: - self.GPIO_OFFSET=256 + self.GPIO_OFFSET = 256 return True return True @@ -37,8 +37,8 @@ def __init__(self): self.set_gpio_offset() PsuBase.__init__(self) - # Get sysfs attribute + def get_attr_value(self, attr_path): retval = 'ERR' @@ -71,7 +71,7 @@ def get_psu_status(self, index): faulty """ status = 0 - gpio_path = [ 'gpio'+str(99+self.GPIO_OFFSET)+'/value', 'gpio'+str(96+self.GPIO_OFFSET)+'/value' ] + gpio_path = ['gpio'+str(99+self.GPIO_OFFSET)+'/value', 'gpio'+str(96+self.GPIO_OFFSET)+'/value'] attr_path = self.SYS_GPIO_DIR + gpio_path[index-1] attr_value = self.get_attr_value(attr_path) @@ -80,7 +80,7 @@ def get_psu_status(self, index): attr_value = int(attr_value, 10) # Check for PSU status if (attr_value == 1): - status = 1 + status = 1 return status @@ -92,7 +92,7 @@ def get_psu_presence(self, index): :return: Boolean, True if PSU is plugged, False if not """ status = 0 - gpio_path = [ 'gpio'+str(100+self.GPIO_OFFSET)+'/value', 'gpio'+str(97+self.GPIO_OFFSET)+'/value' ] + gpio_path = ['gpio'+str(100+self.GPIO_OFFSET)+'/value', 'gpio'+str(97+self.GPIO_OFFSET)+'/value'] attr_path = self.SYS_GPIO_DIR + gpio_path[index-1] attr_value = self.get_attr_value(attr_path) @@ -101,7 +101,6 @@ def get_psu_presence(self, index): attr_value = int(attr_value, 10) # Check for PSU status if (attr_value == 1): - status = 1 + status = 1 return status - diff --git a/device/ingrasys/x86_64-ingrasys_s9180_32x-r0/plugins/sfputil.py b/device/ingrasys/x86_64-ingrasys_s9180_32x-r0/plugins/sfputil.py index 530554ed9fb6..c061fcabd23a 100644 --- a/device/ingrasys/x86_64-ingrasys_s9180_32x-r0/plugins/sfputil.py +++ b/device/ingrasys/x86_64-ingrasys_s9180_32x-r0/plugins/sfputil.py @@ -81,6 +81,7 @@ def qsfp_ports(self): @property def port_to_eeprom_mapping(self): return self._port_to_eeprom_mapping + @property def sfp_port_start(self): return self.SFP_PORT_START @@ -92,11 +93,11 @@ def set_gpio_offset(self): for d in os.listdir(sys_gpio_dir): if "gpiochip" in d: try: - gpiochip_no = int(d[8:],10) + gpiochip_no = int(d[8:], 10) except ValueError as e: print("Error: %s" % str(e)) if gpiochip_no > 255: - self.GPIO_OFFSET=256 + self.GPIO_OFFSET = 256 return True return True @@ -236,7 +237,7 @@ def get_presence(self, port_num): try: abs_device_file = self.BASE_VAL_PATH.format( - self.abs_to_gpio_mapping[port_num]) + self.abs_to_gpio_mapping[port_num]) val_file = open(abs_device_file) except IOError as e: print("Error: unable to open file: %s" % str(e)) @@ -253,12 +254,12 @@ def get_presence(self, port_num): def get_low_power_mode(self, port_num): # Check for invalid port_num - if port_num < self.port_start or port_num > self.sfp_port_start: # TBD + if port_num < self.port_start or port_num > self.sfp_port_start: # TBD return False try: lpmode_val_device_file = self.BASE_VAL_PATH.format( - self.lpmode_to_gpio_mapping[port_num]) + self.lpmode_to_gpio_mapping[port_num]) val_file = open(lpmode_val_device_file) except IOError as e: print("Error: unable to open file: %s" % str(e)) @@ -275,12 +276,12 @@ def get_low_power_mode(self, port_num): def set_low_power_mode(self, port_num, lpmode): # Check for invalid port_num - if port_num < self.port_start or port_num > self.sfp_port_start: # TBD + if port_num < self.port_start or port_num > self.sfp_port_start: # TBD return False try: lpmode_val_device_file = self.BASE_VAL_PATH.format( - self.lpmode_to_gpio_mapping[port_num]) + self.lpmode_to_gpio_mapping[port_num]) val_file = open(lpmode_val_device_file, "w") except IOError as e: print("Error: unable to open file: %s" % str(e)) @@ -293,12 +294,12 @@ def set_low_power_mode(self, port_num, lpmode): def reset(self, port_num): # Check for invalid port_num - if port_num < self.port_start or port_num > self.sfp_port_start: # TBD + if port_num < self.port_start or port_num > self.sfp_port_start: # TBD return False try: reset_val_device_file = self.BASE_VAL_PATH.format( - self.reset_to_gpio_mapping[port_num]) + self.reset_to_gpio_mapping[port_num]) val_file = open(reset_val_device_file, "w") except IOError as e: print("Error: unable to open file: %s" % str(e)) @@ -312,7 +313,7 @@ def reset(self, port_num): try: reset_val_device_file = self.BASE_VAL_PATH.format( - self.reset_to_gpio_mapping[port_num]) + self.reset_to_gpio_mapping[port_num]) val_file = open(reset_val_device_file, "w") except IOError as e: print("Error: unable to open file: %s" % str(e)) diff --git a/device/ingrasys/x86_64-ingrasys_s9200_64x-r0/plugins/eeprom.py b/device/ingrasys/x86_64-ingrasys_s9200_64x-r0/plugins/eeprom.py index 3152c7297936..034c592c411e 100644 --- a/device/ingrasys/x86_64-ingrasys_s9200_64x-r0/plugins/eeprom.py +++ b/device/ingrasys/x86_64-ingrasys_s9200_64x-r0/plugins/eeprom.py @@ -10,7 +10,7 @@ try: from sonic_eeprom import eeprom_tlvinfo except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/ingrasys/x86_64-ingrasys_s9200_64x-r0/plugins/psuutil.py b/device/ingrasys/x86_64-ingrasys_s9200_64x-r0/plugins/psuutil.py index cc996057e09e..b2cdb9dca023 100644 --- a/device/ingrasys/x86_64-ingrasys_s9200_64x-r0/plugins/psuutil.py +++ b/device/ingrasys/x86_64-ingrasys_s9200_64x-r0/plugins/psuutil.py @@ -20,12 +20,12 @@ class PsuUtil(PsuBase): def __init__(self): PsuBase.__init__(self) - - + # Get sysfs attribute + def get_attr_value(self, attr_path): - - retval = 'ERR' + + retval = 'ERR' if (not os.path.isfile(attr_path)): return retval @@ -55,16 +55,16 @@ def get_psu_status(self, index): faulty """ status = 0 - attr_file = 'psu_pg' - attr_path = self.SYSFS_PSU_DIR[index-1] +'/' + attr_file - + attr_file = 'psu_pg' + attr_path = self.SYSFS_PSU_DIR[index-1] + '/' + attr_file + attr_value = self.get_attr_value(attr_path) - + if (attr_value != 'ERR'): attr_value = int(attr_value, 16) # Check for PSU status if (attr_value == 1): - status = 1 + status = 1 return status @@ -77,16 +77,15 @@ def get_psu_presence(self, index): """ status = 0 psu_absent = 0 - attr_file ='psu_abs' - attr_path = self.SYSFS_PSU_DIR[index-1] +'/' + attr_file - + attr_file = 'psu_abs' + attr_path = self.SYSFS_PSU_DIR[index-1] + '/' + attr_file + attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): attr_value = int(attr_value, 16) # Check for PSU presence if (attr_value == 0): - status = 1 + status = 1 return status - diff --git a/device/ingrasys/x86_64-ingrasys_s9200_64x-r0/plugins/sfputil.py b/device/ingrasys/x86_64-ingrasys_s9200_64x-r0/plugins/sfputil.py index a1e71ec610e0..1066c78ba826 100644 --- a/device/ingrasys/x86_64-ingrasys_s9200_64x-r0/plugins/sfputil.py +++ b/device/ingrasys/x86_64-ingrasys_s9200_64x-r0/plugins/sfputil.py @@ -22,70 +22,70 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _logic_to_phy_port_mapping = { - 0: 0, - 1: 1, - 2: 4, - 3: 5, - 4: 8, - 5: 9, - 6: 12, - 7: 13, - 8: 16, - 9: 17, - 10: 20, - 11: 21, - 12: 24, - 13: 25, - 14: 28, - 15: 29, - 16: 32, - 17: 33, - 18: 36, - 19: 37, - 20: 40, - 21: 41, - 22: 44, - 23: 45, - 24: 48, - 25: 49, - 26: 52, - 27: 53, - 28: 56, - 29: 57, - 30: 60, - 31: 61, - 32: 2, - 33: 3, - 34: 6, - 35: 7, - 36: 10, - 37: 11, - 38: 14, - 39: 15, - 40: 18, - 41: 19, - 42: 22, - 43: 23, - 44: 26, - 45: 27, - 46: 30, - 47: 31, - 48: 34, - 49: 35, - 50: 38, - 51: 39, - 52: 42, - 53: 43, - 54: 46, - 55: 47, - 56: 50, - 57: 51, - 58: 54, - 59: 55, - 60: 58, - 61: 59, - 62: 62, - 63: 63 + 0: 0, + 1: 1, + 2: 4, + 3: 5, + 4: 8, + 5: 9, + 6: 12, + 7: 13, + 8: 16, + 9: 17, + 10: 20, + 11: 21, + 12: 24, + 13: 25, + 14: 28, + 15: 29, + 16: 32, + 17: 33, + 18: 36, + 19: 37, + 20: 40, + 21: 41, + 22: 44, + 23: 45, + 24: 48, + 25: 49, + 26: 52, + 27: 53, + 28: 56, + 29: 57, + 30: 60, + 31: 61, + 32: 2, + 33: 3, + 34: 6, + 35: 7, + 36: 10, + 37: 11, + 38: 14, + 39: 15, + 40: 18, + 41: 19, + 42: 22, + 43: 23, + 44: 26, + 45: 27, + 46: 30, + 47: 31, + 48: 34, + 49: 35, + 50: 38, + 51: 39, + 52: 42, + 53: 43, + 54: 46, + 55: 47, + 56: 50, + 57: 51, + 58: 54, + 59: 55, + 60: 58, + 61: 59, + 62: 62, + 63: 63 } @property @@ -184,7 +184,6 @@ def set_low_power_mode(self, port_num, lpmode): content = reg_file.readline().rstrip() - # content is a string containing the hex representation of the register reg_value = int(content, 16) diff --git a/device/ingrasys/x86_64-ingrasys_s9230_64x-r0/plugins/eeprom.py b/device/ingrasys/x86_64-ingrasys_s9230_64x-r0/plugins/eeprom.py index cc3b5e668f5e..159e12d98f64 100644 --- a/device/ingrasys/x86_64-ingrasys_s9230_64x-r0/plugins/eeprom.py +++ b/device/ingrasys/x86_64-ingrasys_s9230_64x-r0/plugins/eeprom.py @@ -10,7 +10,7 @@ try: from sonic_eeprom import eeprom_tlvinfo except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/ingrasys/x86_64-ingrasys_s9230_64x-r0/plugins/psuutil.py b/device/ingrasys/x86_64-ingrasys_s9230_64x-r0/plugins/psuutil.py index cc996057e09e..b2cdb9dca023 100644 --- a/device/ingrasys/x86_64-ingrasys_s9230_64x-r0/plugins/psuutil.py +++ b/device/ingrasys/x86_64-ingrasys_s9230_64x-r0/plugins/psuutil.py @@ -20,12 +20,12 @@ class PsuUtil(PsuBase): def __init__(self): PsuBase.__init__(self) - - + # Get sysfs attribute + def get_attr_value(self, attr_path): - - retval = 'ERR' + + retval = 'ERR' if (not os.path.isfile(attr_path)): return retval @@ -55,16 +55,16 @@ def get_psu_status(self, index): faulty """ status = 0 - attr_file = 'psu_pg' - attr_path = self.SYSFS_PSU_DIR[index-1] +'/' + attr_file - + attr_file = 'psu_pg' + attr_path = self.SYSFS_PSU_DIR[index-1] + '/' + attr_file + attr_value = self.get_attr_value(attr_path) - + if (attr_value != 'ERR'): attr_value = int(attr_value, 16) # Check for PSU status if (attr_value == 1): - status = 1 + status = 1 return status @@ -77,16 +77,15 @@ def get_psu_presence(self, index): """ status = 0 psu_absent = 0 - attr_file ='psu_abs' - attr_path = self.SYSFS_PSU_DIR[index-1] +'/' + attr_file - + attr_file = 'psu_abs' + attr_path = self.SYSFS_PSU_DIR[index-1] + '/' + attr_file + attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): attr_value = int(attr_value, 16) # Check for PSU presence if (attr_value == 0): - status = 1 + status = 1 return status - diff --git a/device/ingrasys/x86_64-ingrasys_s9230_64x-r0/plugins/sfputil.py b/device/ingrasys/x86_64-ingrasys_s9230_64x-r0/plugins/sfputil.py index b962a424c9e2..f3e1d49cd86b 100644 --- a/device/ingrasys/x86_64-ingrasys_s9230_64x-r0/plugins/sfputil.py +++ b/device/ingrasys/x86_64-ingrasys_s9230_64x-r0/plugins/sfputil.py @@ -16,7 +16,7 @@ class SfpUtil(SfpUtilBase): PORT_START = 0 PORT_END = 63 PORTS_IN_BLOCK = 64 - #TODO: modify according to port map + # TODO: modify according to port map EEPROM_OFFSET = 33 CPLD1_PORTS = 12 CPLDx_PORTS = 13 @@ -32,70 +32,70 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _logic_to_phy_port_mapping = { - 0: 0, - 1: 1, - 2: 4, - 3: 5, - 4: 8, - 5: 9, - 6: 12, - 7: 13, - 8: 16, - 9: 17, - 10: 20, - 11: 21, - 12: 24, - 13: 25, - 14: 28, - 15: 29, - 16: 32, - 17: 33, - 18: 36, - 19: 37, - 20: 40, - 21: 41, - 22: 44, - 23: 45, - 24: 48, - 25: 49, - 26: 52, - 27: 53, - 28: 56, - 29: 57, - 30: 60, - 31: 61, - 32: 2, - 33: 3, - 34: 6, - 35: 7, - 36: 10, - 37: 11, - 38: 14, - 39: 15, - 40: 18, - 41: 19, - 42: 22, - 43: 23, - 44: 26, - 45: 27, - 46: 30, - 47: 31, - 48: 34, - 49: 35, - 50: 38, - 51: 39, - 52: 42, - 53: 43, - 54: 46, - 55: 47, - 56: 50, - 57: 51, - 58: 54, - 59: 55, - 60: 58, - 61: 59, - 62: 62, - 63: 63 + 0: 0, + 1: 1, + 2: 4, + 3: 5, + 4: 8, + 5: 9, + 6: 12, + 7: 13, + 8: 16, + 9: 17, + 10: 20, + 11: 21, + 12: 24, + 13: 25, + 14: 28, + 15: 29, + 16: 32, + 17: 33, + 18: 36, + 19: 37, + 20: 40, + 21: 41, + 22: 44, + 23: 45, + 24: 48, + 25: 49, + 26: 52, + 27: 53, + 28: 56, + 29: 57, + 30: 60, + 31: 61, + 32: 2, + 33: 3, + 34: 6, + 35: 7, + 36: 10, + 37: 11, + 38: 14, + 39: 15, + 40: 18, + 41: 19, + 42: 22, + 43: 23, + 44: 26, + 45: 27, + 46: 30, + 47: 31, + 48: 34, + 49: 35, + 50: 38, + 51: 39, + 52: 42, + 53: 43, + 54: 46, + 55: 47, + 56: 50, + 57: 51, + 58: 54, + 59: 55, + 60: 58, + 61: 59, + 62: 62, + 63: 63 } @property @@ -114,7 +114,6 @@ def qsfp_ports(self): def port_to_eeprom_mapping(self): return self._port_to_eeprom_mapping - def __init__(self): # Override port_to_eeprom_mapping for class initialization eeprom_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-0050/eeprom" @@ -132,7 +131,7 @@ def qsfp_to_cpld_index(self, port_num): else: cpld_id = 1 + (port_num - self.CPLD1_PORTS) / self.CPLDx_PORTS cpld_port_index = ((port_num - self.CPLD1_PORTS) % self.CPLDx_PORTS) + 1 - return cpld_id, cpld_port_index + return cpld_id, cpld_port_index def get_presence(self, port_num): # Check for invalid port_num @@ -144,8 +143,8 @@ def get_presence(self, port_num): cpld_id, cpld_port_index = self.qsfp_to_cpld_index(port_num) i2c_id = self.CPLD_OFFSET + cpld_id - reg_path = self.CPLD_REG_PATH.format(i2c_id, self.CPLDx_I2C_ADDR, \ - self.CPLD_PORT_STATUS_KEY, cpld_port_index) + reg_path = self.CPLD_REG_PATH.format(i2c_id, self.CPLDx_I2C_ADDR, + self.CPLD_PORT_STATUS_KEY, cpld_port_index) try: reg_file = open(reg_path) @@ -162,7 +161,7 @@ def get_presence(self, port_num): mask = (1 << self.CPLD_PRES_BIT) # 0 - presence, 1 - absence - if reg_value & mask == 0: + if reg_value & mask == 0: return True return False @@ -177,8 +176,8 @@ def get_low_power_mode(self, port_num): cpld_id, cpld_port_index = self.qsfp_to_cpld_index(port_num) i2c_id = self.CPLD_OFFSET + cpld_id - reg_path = self.CPLD_REG_PATH.format(i2c_id, self.CPLDx_I2C_ADDR, \ - self.CPLD_PORT_CONFIG_KEY, cpld_port_index) + reg_path = self.CPLD_REG_PATH.format(i2c_id, self.CPLDx_I2C_ADDR, + self.CPLD_PORT_CONFIG_KEY, cpld_port_index) try: reg_file = open(reg_path) @@ -195,7 +194,7 @@ def get_low_power_mode(self, port_num): mask = (1 << self.CPLD_LPMOD_BIT) # 0 - disable, 1 - low power mode - if reg_value & mask == 0: + if reg_value & mask == 0: return False return True @@ -210,8 +209,8 @@ def set_low_power_mode(self, port_num, lpmode): cpld_id, cpld_port_index = self.qsfp_to_cpld_index(port_num) i2c_id = self.CPLD_OFFSET + cpld_id - reg_path = self.CPLD_REG_PATH.format(i2c_id, self.CPLDx_I2C_ADDR, \ - self.CPLD_PORT_CONFIG_KEY, cpld_port_index) + reg_path = self.CPLD_REG_PATH.format(i2c_id, self.CPLDx_I2C_ADDR, + self.CPLD_PORT_CONFIG_KEY, cpld_port_index) try: reg_file = open(reg_path, "r+") @@ -250,8 +249,8 @@ def reset(self, port_num): cpld_id, cpld_port_index = self.qsfp_to_cpld_index(port_num) i2c_id = self.CPLD_OFFSET + cpld_id - reg_path = self.CPLD_REG_PATH.format(i2c_id, self.CPLDx_I2C_ADDR, \ - self.CPLD_PORT_CONFIG_KEY, cpld_port_index) + reg_path = self.CPLD_REG_PATH.format(i2c_id, self.CPLDx_I2C_ADDR, + self.CPLD_PORT_CONFIG_KEY, cpld_port_index) # reset the port try: diff --git a/device/ingrasys/x86_64-ingrasys_s9280_64x-r0/plugins/eeprom.py b/device/ingrasys/x86_64-ingrasys_s9280_64x-r0/plugins/eeprom.py index 5f4485434068..3fc614fc2632 100644 --- a/device/ingrasys/x86_64-ingrasys_s9280_64x-r0/plugins/eeprom.py +++ b/device/ingrasys/x86_64-ingrasys_s9280_64x-r0/plugins/eeprom.py @@ -10,7 +10,7 @@ try: from sonic_eeprom import eeprom_tlvinfo except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/ingrasys/x86_64-ingrasys_s9280_64x-r0/plugins/psuutil.py b/device/ingrasys/x86_64-ingrasys_s9280_64x-r0/plugins/psuutil.py index c4b78c943e81..8c7d5cfa4174 100644 --- a/device/ingrasys/x86_64-ingrasys_s9280_64x-r0/plugins/psuutil.py +++ b/device/ingrasys/x86_64-ingrasys_s9280_64x-r0/plugins/psuutil.py @@ -21,12 +21,12 @@ class PsuUtil(PsuBase): def __init__(self): PsuBase.__init__(self) - - + # Get sysfs attribute + def get_attr_value(self, attr_path): - - retval = 'ERR' + + retval = 'ERR' if (not os.path.isfile(attr_path)): return retval @@ -56,16 +56,16 @@ def get_psu_status(self, index): faulty """ status = 0 - attr_file = 'psu_pg' - attr_path = self.SYSFS_PSU_DIR[index-1] +'/' + attr_file - + attr_file = 'psu_pg' + attr_path = self.SYSFS_PSU_DIR[index-1] + '/' + attr_file + attr_value = self.get_attr_value(attr_path) - + if (attr_value != 'ERR'): attr_value = int(attr_value, 16) # Check for PSU status if (attr_value == 1): - status = 1 + status = 1 return status @@ -78,16 +78,15 @@ def get_psu_presence(self, index): """ status = 0 psu_absent = 0 - attr_file ='psu_abs' - attr_path = self.SYSFS_PSU_DIR[index-1] +'/' + attr_file - + attr_file = 'psu_abs' + attr_path = self.SYSFS_PSU_DIR[index-1] + '/' + attr_file + attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): attr_value = int(attr_value, 16) # Check for PSU presence if (attr_value == 0): - status = 1 + status = 1 return status - diff --git a/device/ingrasys/x86_64-ingrasys_s9280_64x-r0/plugins/sfputil.py b/device/ingrasys/x86_64-ingrasys_s9280_64x-r0/plugins/sfputil.py index 9e1ec0f60cb0..689710cf3f4d 100644 --- a/device/ingrasys/x86_64-ingrasys_s9280_64x-r0/plugins/sfputil.py +++ b/device/ingrasys/x86_64-ingrasys_s9280_64x-r0/plugins/sfputil.py @@ -19,7 +19,7 @@ class SfpUtil(SfpUtilBase): EEPROM_OFFSET = 41 CPLD1_PORTS = 12 CPLDx_PORTS = 13 - #TODO: check init sequence for CPLD i2c bus + # TODO: check init sequence for CPLD i2c bus CPLD_OFFSET = 1 CPLD_PRES_BIT = 1 CPLD_RESET_BIT = 0 @@ -32,72 +32,72 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} - #TODO: check the fp port to phy port mapping + # TODO: check the fp port to phy port mapping _fp2phy_port_mapping = { - 0: 0, - 1: 1, - 2: 4, - 3: 5, - 4: 8, - 5: 9, - 6: 12, - 7: 13, - 8: 16, - 9: 17, - 10: 20, - 11: 21, - 12: 24, - 13: 25, - 14: 28, - 15: 29, - 16: 32, - 17: 33, - 18: 36, - 19: 37, - 20: 40, - 21: 41, - 22: 44, - 23: 45, - 24: 48, - 25: 49, - 26: 52, - 27: 53, - 28: 56, - 29: 57, - 30: 60, - 31: 61, - 32: 2, - 33: 3, - 34: 6, - 35: 7, - 36: 10, - 37: 11, - 38: 14, - 39: 15, - 40: 18, - 41: 19, - 42: 22, - 43: 23, - 44: 26, - 45: 27, - 46: 30, - 47: 31, - 48: 34, - 49: 35, - 50: 38, - 51: 39, - 52: 42, - 53: 43, - 54: 46, - 55: 47, - 56: 50, - 57: 51, - 58: 54, - 59: 55, - 60: 58, - 61: 59, - 62: 62, - 63: 63 + 0: 0, + 1: 1, + 2: 4, + 3: 5, + 4: 8, + 5: 9, + 6: 12, + 7: 13, + 8: 16, + 9: 17, + 10: 20, + 11: 21, + 12: 24, + 13: 25, + 14: 28, + 15: 29, + 16: 32, + 17: 33, + 18: 36, + 19: 37, + 20: 40, + 21: 41, + 22: 44, + 23: 45, + 24: 48, + 25: 49, + 26: 52, + 27: 53, + 28: 56, + 29: 57, + 30: 60, + 31: 61, + 32: 2, + 33: 3, + 34: 6, + 35: 7, + 36: 10, + 37: 11, + 38: 14, + 39: 15, + 40: 18, + 41: 19, + 42: 22, + 43: 23, + 44: 26, + 45: 27, + 46: 30, + 47: 31, + 48: 34, + 49: 35, + 50: 38, + 51: 39, + 52: 42, + 53: 43, + 54: 46, + 55: 47, + 56: 50, + 57: 51, + 58: 54, + 59: 55, + 60: 58, + 61: 59, + 62: 62, + 63: 63 } @property @@ -116,7 +116,6 @@ def qsfp_ports(self): def port_to_eeprom_mapping(self): return self._port_to_eeprom_mapping - def __init__(self): # Override port_to_eeprom_mapping for class initialization eeprom_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-00{1}/eeprom" @@ -134,7 +133,7 @@ def qsfp_to_cpld_index(self, port_num): else: cpld_id = 1 + (port_num - self.CPLD1_PORTS) / self.CPLDx_PORTS cpld_port_index = ((port_num - self.CPLD1_PORTS) % self.CPLDx_PORTS) + 1 - return cpld_id, cpld_port_index + return cpld_id, cpld_port_index def fp2phy_port_num(self, fp_port_num): @@ -151,8 +150,8 @@ def get_presence(self, port_num): cpld_id, cpld_port_index = self.qsfp_to_cpld_index(port_num) i2c_id = self.CPLD_OFFSET + cpld_id - reg_path = self.CPLD_REG_PATH.format(i2c_id, self.CPLDx_I2C_ADDR, \ - self.CPLD_PORT_STATUS_KEY, cpld_port_index) + reg_path = self.CPLD_REG_PATH.format(i2c_id, self.CPLDx_I2C_ADDR, + self.CPLD_PORT_STATUS_KEY, cpld_port_index) try: reg_file = open(reg_path) @@ -169,7 +168,7 @@ def get_presence(self, port_num): mask = (1 << self.CPLD_PRES_BIT) # 0 - presence, 1 - absence - if reg_value & mask == 0: + if reg_value & mask == 0: return True return False @@ -184,8 +183,8 @@ def get_low_power_mode(self, port_num): cpld_id, cpld_port_index = self.qsfp_to_cpld_index(port_num) i2c_id = self.CPLD_OFFSET + cpld_id - reg_path = self.CPLD_REG_PATH.format(i2c_id, self.CPLDx_I2C_ADDR, \ - self.CPLD_PORT_CONFIG_KEY, cpld_port_index) + reg_path = self.CPLD_REG_PATH.format(i2c_id, self.CPLDx_I2C_ADDR, + self.CPLD_PORT_CONFIG_KEY, cpld_port_index) try: reg_file = open(reg_path) @@ -202,7 +201,7 @@ def get_low_power_mode(self, port_num): mask = (1 << self.CPLD_LPMOD_BIT) # 0 - disable, 1 - low power mode - if reg_value & mask == 0: + if reg_value & mask == 0: return False return True @@ -217,8 +216,8 @@ def set_low_power_mode(self, port_num, lpmode): cpld_id, cpld_port_index = self.qsfp_to_cpld_index(port_num) i2c_id = self.CPLD_OFFSET + cpld_id - reg_path = self.CPLD_REG_PATH.format(i2c_id, self.CPLDx_I2C_ADDR, \ - self.CPLD_PORT_CONFIG_KEY, cpld_port_index) + reg_path = self.CPLD_REG_PATH.format(i2c_id, self.CPLDx_I2C_ADDR, + self.CPLD_PORT_CONFIG_KEY, cpld_port_index) try: reg_file = open(reg_path, "r+") @@ -257,8 +256,8 @@ def reset(self, port_num): cpld_id, cpld_port_index = self.qsfp_to_cpld_index(port_num) i2c_id = self.CPLD_OFFSET + cpld_id - reg_path = self.CPLD_REG_PATH.format(i2c_id, self.CPLDx_I2C_ADDR, \ - self.CPLD_PORT_CONFIG_KEY, cpld_port_index) + reg_path = self.CPLD_REG_PATH.format(i2c_id, self.CPLDx_I2C_ADDR, + self.CPLD_PORT_CONFIG_KEY, cpld_port_index) # reset the port try: @@ -305,4 +304,3 @@ def get_transceiver_change_event(self): on this platform. """ raise NotImplementedError - diff --git a/device/inventec/x86_64-inventec_d6254qs-r0/plugins/eeprom.py b/device/inventec/x86_64-inventec_d6254qs-r0/plugins/eeprom.py index c94ecca1200f..31f847614fb0 100644 --- a/device/inventec/x86_64-inventec_d6254qs-r0/plugins/eeprom.py +++ b/device/inventec/x86_64-inventec_d6254qs-r0/plugins/eeprom.py @@ -10,7 +10,7 @@ try: from sonic_eeprom import eeprom_tlvinfo except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/inventec/x86_64-inventec_d6254qs-r0/plugins/psuutil.py b/device/inventec/x86_64-inventec_d6254qs-r0/plugins/psuutil.py index 4bd3f7a27052..162e240bae35 100644 --- a/device/inventec/x86_64-inventec_d6254qs-r0/plugins/psuutil.py +++ b/device/inventec/x86_64-inventec_d6254qs-r0/plugins/psuutil.py @@ -22,8 +22,8 @@ def __init__(self): # Get sysfs attribute def get_attr_value(self, attr_path): - - retval = 'ERR' + + retval = 'ERR' if (not os.path.isfile(attr_path)): return retval @@ -35,7 +35,7 @@ def get_attr_value(self, attr_path): retval = retval.rstrip(' \t\n\r') return retval - + def get_num_psus(self): """ Retrieves the number of PSUs available on the device @@ -53,14 +53,14 @@ def get_psu_status(self, index): faulty """ status = 0 - attr_file = 'psoc_psu'+ str(index) + '_iout' - attr_path = self.PSU_DIR +'/' + attr_file - + attr_file = 'psoc_psu' + str(index) + '_iout' + attr_path = self.PSU_DIR + '/' + attr_file + attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): # Check for PSU status if (attr_value != 0): - status = 1 + status = 1 return status def get_psu_presence(self, index): @@ -73,12 +73,12 @@ def get_psu_presence(self, index): status = 0 psu_absent = 0 ind = index-1 - attr_file ='psu'+ str(ind) - attr_path = self.PSU_DIR +'/' + attr_file - normal_attr_value = '0 : normal' + attr_file = 'psu' + str(ind) + attr_path = self.PSU_DIR + '/' + attr_file + normal_attr_value = '0 : normal' attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): # Check for PSU presence if (attr_value == normal_attr_value): - status = 1 + status = 1 return status diff --git a/device/inventec/x86_64-inventec_d6332-r0/plugins/eeprom.py b/device/inventec/x86_64-inventec_d6332-r0/plugins/eeprom.py index 78a82a32ac36..96e27323aa44 100644 --- a/device/inventec/x86_64-inventec_d6332-r0/plugins/eeprom.py +++ b/device/inventec/x86_64-inventec_d6332-r0/plugins/eeprom.py @@ -10,7 +10,7 @@ try: from sonic_eeprom import eeprom_tlvinfo except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/inventec/x86_64-inventec_d6332-r0/plugins/psuutil.py b/device/inventec/x86_64-inventec_d6332-r0/plugins/psuutil.py index b2033963872d..3ae6d5ddb355 100755 --- a/device/inventec/x86_64-inventec_d6332-r0/plugins/psuutil.py +++ b/device/inventec/x86_64-inventec_d6332-r0/plugins/psuutil.py @@ -23,8 +23,8 @@ def __init__(self): # Get sysfs attribute def get_attr_value(self, attr_path): - - retval = 'ERR' + + retval = 'ERR' if (not os.path.isfile(attr_path)): return retval @@ -36,7 +36,7 @@ def get_attr_value(self, attr_path): retval = retval.rstrip(' \t\n\r') return retval - + def get_num_psus(self): """ Retrieves the number of PSUs available on the device @@ -54,17 +54,17 @@ def get_psu_status(self, index): faulty """ status = 0 - attr_file ='psu'+ str(index) - attr_path = self.PSU_DIR +'/' + attr_file + attr_file = 'psu' + str(index) + attr_path = self.PSU_DIR + '/' + attr_file normal_attr_value = '1:normal' unpower_attr_value = '0:unpowered' attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): # Check for PSU presence if (attr_value == normal_attr_value): - status = 1 + status = 1 elif (attr_value == unpower_attr_value): - status = 0 + status = 0 return status def get_psu_presence(self, index): @@ -75,15 +75,15 @@ def get_psu_presence(self, index): :return: Boolean, True if PSU is plugged, False if not """ status = 0 - attr_file ='psu'+ str(index) - attr_path = self.PSU_DIR +'/' + attr_file + attr_file = 'psu' + str(index) + attr_path = self.PSU_DIR + '/' + attr_file normal_attr_value = '1:normal' unpower_attr_value = '0:unpowered' attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): # Check for PSU presence if (attr_value == normal_attr_value): - status = 1 + status = 1 if (attr_value == unpower_attr_value): - status = 1 + status = 1 return status diff --git a/device/inventec/x86_64-inventec_d6332-r0/plugins/sfputil.py b/device/inventec/x86_64-inventec_d6332-r0/plugins/sfputil.py index 46c2f22378dd..7c3b78c1bc22 100755 --- a/device/inventec/x86_64-inventec_d6332-r0/plugins/sfputil.py +++ b/device/inventec/x86_64-inventec_d6332-r0/plugins/sfputil.py @@ -5,7 +5,9 @@ try: import time - import os, re, socket + import os + import re + import socket from sonic_sfp.sfputilbase import SfpUtilBase from collections import OrderedDict from sonic_sfp.sff8472 import sff8472Dom @@ -22,6 +24,7 @@ NETLINK_KOBJECT_UEVENT = 15 monitor = None + class SWPSEventMonitor(object): def __init__(self): @@ -76,38 +79,38 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} port_to_i2cbus_mapping = { - 0:12, - 1:13, - 2:14, - 3:15, - 4:16, - 5:17, - 6:18, - 7:19, - 8:20, - 9:21, - 10:22, - 11:23, - 12:24, - 13:25, - 14:26, - 15:27, - 16:28, - 17:29, - 18:30, - 19:31, - 20:32, - 21:33, - 22:34, - 23:35, - 24:36, - 25:37, - 26:38, - 27:39, - 28:40, - 29:41, - 30:42, - 31:43 + 0: 12, + 1: 13, + 2: 14, + 3: 15, + 4: 16, + 5: 17, + 6: 18, + 7: 19, + 8: 20, + 9: 21, + 10: 22, + 11: 23, + 12: 24, + 13: 25, + 14: 26, + 15: 27, + 16: 28, + 17: 29, + 18: 30, + 19: 31, + 20: 32, + 21: 33, + 22: 34, + 23: 35, + 24: 36, + 25: 37, + 26: 38, + 27: 39, + 28: 40, + 29: 41, + 30: 42, + 31: 43 } @property @@ -228,7 +231,7 @@ def reset(self, port_num): def _get_port_eeprom_path(self, port_num, devid): sysfs_i2c_adapter_base_path = "/sys/class/i2c-adapter" - if devid == self.IDENTITY_EEPROM_ADDR : + if devid == self.IDENTITY_EEPROM_ADDR: return SfpUtilBase._get_port_eeprom_path(self, port_num, devid) else: i2c_adapter_id = self._get_port_i2c_adapter_id(port_num) @@ -252,7 +255,7 @@ def _get_port_eeprom_path(self, port_num, devid): # If sfp device is not present on bus, Add it if not os.path.exists(sysfs_sfp_i2c_client_path): ret = self._add_new_sfp_device( - sysfs_sfp_i2c_adapter_path, devid) + sysfs_sfp_i2c_adapter_path, devid) if ret != 0: print("Error adding sfp device") return None @@ -282,7 +285,8 @@ def get_transceiver_dom_info_dict(self, port_num): if sfpd_obj is None: return None - dom_temperature_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_TEMPE_OFFSET), SFP_TEMPE_WIDTH) + dom_temperature_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + SFP_TEMPE_OFFSET), SFP_TEMPE_WIDTH) if dom_temperature_raw is not None: print(dom_temperature_raw) dom_temperature_data = sfpd_obj.parse_temperature(dom_temperature_raw, 0) @@ -290,14 +294,16 @@ def get_transceiver_dom_info_dict(self, port_num): else: return None - dom_voltage_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_VLOT_OFFSET), SFP_VOLT_WIDTH) + dom_voltage_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + SFP_VLOT_OFFSET), SFP_VOLT_WIDTH) if dom_voltage_raw is not None: print(dom_voltage_raw) dom_voltage_data = sfpd_obj.parse_voltage(dom_voltage_raw, 0) else: return None - dom_channel_monitor_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_CHANNL_MON_OFFSET), SFP_CHANNL_MON_WIDTH) + dom_channel_monitor_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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: @@ -334,7 +340,7 @@ def get_transceiver_change_event(self, timeout=0): if event['SUBSYSTEM'] == 'swps': #print('SWPS event. From %s, ACTION %s, IF_TYPE %s, IF_LANE %s' % (event['DEVPATH'], event['ACTION'], event['IF_TYPE'], event['IF_LANE'])) portname = event['DEVPATH'].split("/")[-1] - rc = re.match(r"port(?P\d+)",portname) + rc = re.match(r"port(?P\d+)", portname) if rc is not None: if event['ACTION'] == "remove": remove_num = int(rc.group("num")) diff --git a/device/inventec/x86_64-inventec_d6356-r0/plugins/eeprom.py b/device/inventec/x86_64-inventec_d6356-r0/plugins/eeprom.py index d3db6ca00d24..4c75d0918add 100644 --- a/device/inventec/x86_64-inventec_d6356-r0/plugins/eeprom.py +++ b/device/inventec/x86_64-inventec_d6356-r0/plugins/eeprom.py @@ -10,7 +10,7 @@ try: from sonic_eeprom import eeprom_tlvinfo except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/inventec/x86_64-inventec_d6356-r0/plugins/psuutil.py b/device/inventec/x86_64-inventec_d6356-r0/plugins/psuutil.py index 732650ffe638..ce8d0b321928 100755 --- a/device/inventec/x86_64-inventec_d6356-r0/plugins/psuutil.py +++ b/device/inventec/x86_64-inventec_d6356-r0/plugins/psuutil.py @@ -22,8 +22,8 @@ def __init__(self): # Get sysfs attribute def get_attr_value(self, attr_path): - - retval = 'ERR' + + retval = 'ERR' if (not os.path.isfile(attr_path)): return retval @@ -35,7 +35,7 @@ def get_attr_value(self, attr_path): retval = retval.rstrip(' \t\n\r') return retval - + def get_num_psus(self): """ Retrieves the number of PSUs available on the device @@ -53,17 +53,17 @@ def get_psu_status(self, index): faulty """ status = 0 - - if index == 1 : + + if index == 1: attr_path = "/sys/class/hwmon/hwmon7/in1_input" - else : + else: attr_path = "/sys/class/hwmon/hwmon8/in1_input" attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): # Check for PSU status if (attr_value != 0): - status = 1 + status = 1 return status def get_psu_presence(self, index): @@ -76,13 +76,12 @@ def get_psu_presence(self, index): status = 0 psu_absent = 0 ind = index - attr_file ='psu'+ str(ind) - attr_path = self.PSU_DIR +'/' + attr_file - normal_attr_value = '1:normal' + attr_file = 'psu' + str(ind) + attr_path = self.PSU_DIR + '/' + attr_file + normal_attr_value = '1:normal' attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): # Check for PSU presence if (attr_value == normal_attr_value): - status = 1 + status = 1 return status - diff --git a/device/inventec/x86_64-inventec_d6356-r0/plugins/sfputil.py b/device/inventec/x86_64-inventec_d6356-r0/plugins/sfputil.py index ba1b93ea6531..d58d1e96b766 100755 --- a/device/inventec/x86_64-inventec_d6356-r0/plugins/sfputil.py +++ b/device/inventec/x86_64-inventec_d6356-r0/plugins/sfputil.py @@ -14,7 +14,9 @@ # try: import time - import socket, re,os + import socket + import re + import os from collections import OrderedDict from sonic_sfp.sfputilbase import SfpUtilBase from sonic_sfp.sff8472 import sff8472Dom @@ -31,6 +33,7 @@ NETLINK_KOBJECT_UEVENT = 15 monitor = None + class SWPSEventMonitor(object): def __init__(self): @@ -76,6 +79,7 @@ def next_events(self): except ValueError: pass + class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" @@ -87,62 +91,62 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} port_to_i2c_mapping = { - 0:22, - 1:23, - 2:24, - 3:25, - 4:26, - 5:27, - 6:28, - 7:29, - 8:30, - 9:31, - 10:32, - 11:33, - 12:34, - 13:35, - 14:36, - 15:37, - 16:38, - 17:39, - 18:40, - 19:41, - 20:42, - 21:43, - 22:44, - 23:45, - 24:46, - 25:47, - 26:48, - 27:49, - 28:50, - 29:51, - 30:52, - 31:53, - 32:54, - 33:55, - 34:56, - 35:57, - 36:58, - 37:59, - 38:60, - 39:61, - 40:62, - 41:63, - 42:64, - 43:65, - 44:66, - 45:67, - 46:68, - 47:69, - 48:14, - 49:15, - 50:16, - 51:17, - 52:18, - 53:19, - 54:20, - 55:21 + 0: 22, + 1: 23, + 2: 24, + 3: 25, + 4: 26, + 5: 27, + 6: 28, + 7: 29, + 8: 30, + 9: 31, + 10: 32, + 11: 33, + 12: 34, + 13: 35, + 14: 36, + 15: 37, + 16: 38, + 17: 39, + 18: 40, + 19: 41, + 20: 42, + 21: 43, + 22: 44, + 23: 45, + 24: 46, + 25: 47, + 26: 48, + 27: 49, + 28: 50, + 29: 51, + 30: 52, + 31: 53, + 32: 54, + 33: 55, + 34: 56, + 35: 57, + 36: 58, + 37: 59, + 38: 60, + 39: 61, + 40: 62, + 41: 63, + 42: 64, + 43: 65, + 44: 66, + 45: 67, + 46: 68, + 47: 69, + 48: 14, + 49: 15, + 50: 16, + 51: 17, + 52: 18, + 53: 19, + 54: 20, + 55: 21 } @property @@ -293,7 +297,7 @@ def get_transceiver_change_event(self): if event['SUBSYSTEM'] == 'swps': #print('SWPS event. From %s, ACTION %s, IF_TYPE %s, IF_LANE %s' % (event['DEVPATH'], event['ACTION'], event['IF_TYPE'], event['IF_LANE'])) portname = event['DEVPATH'].split("/")[-1] - rc = re.match(r"port(?P\d+)",portname) + rc = re.match(r"port(?P\d+)", portname) if rc is not None: if event['ACTION'] == "remove": remove_num = int(rc.group("num")) @@ -335,19 +339,22 @@ def get_transceiver_dom_info_dict(self, port_num): if sfpd_obj is None: return None - dom_temperature_raw = self._read_eeprom_specific_bytes(sysfsfile_eeprom, (offset + SFP_TEMPE_OFFSET), SFP_TEMPE_WIDTH) + dom_temperature_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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(sysfsfile_eeprom, (offset + SFP_VLOT_OFFSET), SFP_VOLT_WIDTH) + dom_voltage_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (offset + SFP_VLOT_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(sysfsfile_eeprom, (offset + SFP_CHANNL_MON_OFFSET), SFP_CHANNL_MON_WIDTH) + dom_channel_monitor_raw = self._read_eeprom_specific_bytes( + sysfsfile_eeprom, (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: @@ -375,5 +382,3 @@ def get_transceiver_dom_info_dict(self, port_num): transceiver_dom_info_dict['tx4power'] = 'N/A' return transceiver_dom_info_dict - - diff --git a/device/inventec/x86_64-inventec_d6556-r0/plugins/eeprom.py b/device/inventec/x86_64-inventec_d6556-r0/plugins/eeprom.py index c94ecca1200f..31f847614fb0 100644 --- a/device/inventec/x86_64-inventec_d6556-r0/plugins/eeprom.py +++ b/device/inventec/x86_64-inventec_d6556-r0/plugins/eeprom.py @@ -10,7 +10,7 @@ try: from sonic_eeprom import eeprom_tlvinfo except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/inventec/x86_64-inventec_d6556-r0/plugins/psuutil.py b/device/inventec/x86_64-inventec_d6556-r0/plugins/psuutil.py index 855162f63b98..ced851d6c82a 100644 --- a/device/inventec/x86_64-inventec_d6556-r0/plugins/psuutil.py +++ b/device/inventec/x86_64-inventec_d6556-r0/plugins/psuutil.py @@ -22,8 +22,8 @@ def __init__(self): # Get sysfs attribute def get_attr_value(self, attr_path): - - retval = 'ERR' + + retval = 'ERR' if (not os.path.isfile(attr_path)): return retval @@ -35,7 +35,7 @@ def get_attr_value(self, attr_path): retval = retval.rstrip(' \t\n\r') return retval - + def get_num_psus(self): """ Retrieves the number of PSUs available on the device @@ -53,14 +53,14 @@ def get_psu_status(self, index): faulty """ status = 0 - attr_file = 'psoc_psu'+ str(index) + '_iout' - attr_path = self.PSU_DIR +'/' + attr_file - + attr_file = 'psoc_psu' + str(index) + '_iout' + attr_path = self.PSU_DIR + '/' + attr_file + attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): # Check for PSU status if (attr_value != 0): - status = 1 + status = 1 return status def get_psu_presence(self, index): @@ -73,12 +73,12 @@ def get_psu_presence(self, index): status = 0 psu_absent = 0 ind = index-1 - attr_file ='psu'+ str(ind) - attr_path = self.PSU_DIR +'/' + attr_file - normal_attr_value = '0 : normal' + attr_file = 'psu' + str(ind) + attr_path = self.PSU_DIR + '/' + attr_file + normal_attr_value = '0 : normal' attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): # Check for PSU presence if (attr_value == normal_attr_value): - status = 1 + status = 1 return status diff --git a/device/inventec/x86_64-inventec_d7032q28b-r0/plugins/eeprom.py b/device/inventec/x86_64-inventec_d7032q28b-r0/plugins/eeprom.py index c94ecca1200f..31f847614fb0 100644 --- a/device/inventec/x86_64-inventec_d7032q28b-r0/plugins/eeprom.py +++ b/device/inventec/x86_64-inventec_d7032q28b-r0/plugins/eeprom.py @@ -10,7 +10,7 @@ try: from sonic_eeprom import eeprom_tlvinfo except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/inventec/x86_64-inventec_d7032q28b-r0/plugins/psuutil.py b/device/inventec/x86_64-inventec_d7032q28b-r0/plugins/psuutil.py index cc5ca004dadf..2e058a9e410e 100644 --- a/device/inventec/x86_64-inventec_d7032q28b-r0/plugins/psuutil.py +++ b/device/inventec/x86_64-inventec_d7032q28b-r0/plugins/psuutil.py @@ -22,8 +22,8 @@ def __init__(self): # Get sysfs attribute def get_attr_value(self, attr_path): - - retval = 'ERR' + + retval = 'ERR' if (not os.path.isfile(attr_path)): return retval @@ -35,7 +35,7 @@ def get_attr_value(self, attr_path): retval = retval.rstrip(' \t\n\r') return retval - + def get_num_psus(self): """ Retrieves the number of PSUs available on the device @@ -54,17 +54,17 @@ def get_psu_status(self, index): """ status = 0 if (index == 1): - ind = 2 + ind = 2 if (index == 2): - ind = 1 - attr_file = 'psu'+ str(ind) + '_iout' - attr_path = self.PSU_DIR +'/' + attr_file - + ind = 1 + attr_file = 'psu' + str(ind) + '_iout' + attr_path = self.PSU_DIR + '/' + attr_file + attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): # Check for PSU status if (attr_value != 0): - status = 1 + status = 1 return status def get_psu_presence(self, index): @@ -77,12 +77,12 @@ def get_psu_presence(self, index): status = 0 psu_absent = 0 ind = index-1 - attr_file ='psu'+ str(ind) - attr_path = self.PSU_DIR +'/' + attr_file - normal_attr_value = '0 : normal' + attr_file = 'psu' + str(ind) + attr_path = self.PSU_DIR + '/' + attr_file + normal_attr_value = '0 : normal' attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): # Check for PSU presence if (attr_value == normal_attr_value): - status = 1 + status = 1 return status diff --git a/device/inventec/x86_64-inventec_d7054q28b-r0/plugins/eeprom.py b/device/inventec/x86_64-inventec_d7054q28b-r0/plugins/eeprom.py index c94ecca1200f..31f847614fb0 100644 --- a/device/inventec/x86_64-inventec_d7054q28b-r0/plugins/eeprom.py +++ b/device/inventec/x86_64-inventec_d7054q28b-r0/plugins/eeprom.py @@ -10,7 +10,7 @@ try: from sonic_eeprom import eeprom_tlvinfo except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/inventec/x86_64-inventec_d7054q28b-r0/plugins/psuutil.py b/device/inventec/x86_64-inventec_d7054q28b-r0/plugins/psuutil.py index 4bd3f7a27052..162e240bae35 100644 --- a/device/inventec/x86_64-inventec_d7054q28b-r0/plugins/psuutil.py +++ b/device/inventec/x86_64-inventec_d7054q28b-r0/plugins/psuutil.py @@ -22,8 +22,8 @@ def __init__(self): # Get sysfs attribute def get_attr_value(self, attr_path): - - retval = 'ERR' + + retval = 'ERR' if (not os.path.isfile(attr_path)): return retval @@ -35,7 +35,7 @@ def get_attr_value(self, attr_path): retval = retval.rstrip(' \t\n\r') return retval - + def get_num_psus(self): """ Retrieves the number of PSUs available on the device @@ -53,14 +53,14 @@ def get_psu_status(self, index): faulty """ status = 0 - attr_file = 'psoc_psu'+ str(index) + '_iout' - attr_path = self.PSU_DIR +'/' + attr_file - + attr_file = 'psoc_psu' + str(index) + '_iout' + attr_path = self.PSU_DIR + '/' + attr_file + attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): # Check for PSU status if (attr_value != 0): - status = 1 + status = 1 return status def get_psu_presence(self, index): @@ -73,12 +73,12 @@ def get_psu_presence(self, index): status = 0 psu_absent = 0 ind = index-1 - attr_file ='psu'+ str(ind) - attr_path = self.PSU_DIR +'/' + attr_file - normal_attr_value = '0 : normal' + attr_file = 'psu' + str(ind) + attr_path = self.PSU_DIR + '/' + attr_file + normal_attr_value = '0 : normal' attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): # Check for PSU presence if (attr_value == normal_attr_value): - status = 1 + status = 1 return status diff --git a/device/inventec/x86_64-inventec_d7264q28b-r0/plugins/eeprom.py b/device/inventec/x86_64-inventec_d7264q28b-r0/plugins/eeprom.py index c94ecca1200f..31f847614fb0 100644 --- a/device/inventec/x86_64-inventec_d7264q28b-r0/plugins/eeprom.py +++ b/device/inventec/x86_64-inventec_d7264q28b-r0/plugins/eeprom.py @@ -10,7 +10,7 @@ try: from sonic_eeprom import eeprom_tlvinfo except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/eeprom.py b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/eeprom.py index b39974726354..33898d83a0e9 100644 --- a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/eeprom.py +++ b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/eeprom.py @@ -1,14 +1,14 @@ # # Name: eeprom.py version: 1.0 # -# Description: Platform-specific EEPROM interface for Juniper QFX5200 +# Description: Platform-specific EEPROM interface for Juniper QFX5200 # # Copyright (c) 2020, Juniper Networks, Inc. # All rights reserved. # -# Notice and Disclaimer: This code is licensed to you under the GNU General -# Public License as published by the Free Software Foundation, version 3 or -# any later version. This code is not an official Juniper product. You can +# Notice and Disclaimer: This code is licensed to you under the GNU General +# Public License as published by the Free Software Foundation, version 3 or +# any later version. This code is not an official Juniper product. You can # obtain a copy of the License at # # OSS License: @@ -26,9 +26,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . # -# Third-Party Code: This code may depend on other components under separate -# copyright notice and license terms. Your use of the source code for those -# components is subject to the terms and conditions of the respective license +# Third-Party Code: This code may depend on other components under separate +# copyright notice and license terms. Your use of the source code for those +# components is subject to the terms and conditions of the respective license # as noted in the Third-Party source code file. try: @@ -37,16 +37,18 @@ import syslog from array import * except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") SYSLOG_IDENTIFIER = "eeprom.py" EEPROM_PATH = "/sys/bus/i2c/devices/0-0051/eeprom" + def log_error(msg): syslog.openlog(SYSLOG_IDENTIFIER) syslog.syslog(syslog.LOG_ERR, msg) syslog.closelog() + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 @@ -58,4 +60,3 @@ def __init__(self, name, path, cpld_root, ro): self.eeprom_path = EEPROM_PATH super(board, self).__init__(self.eeprom_path, 0, '', True) - diff --git a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/led_control.py b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/led_control.py index 6078177d8bc5..223c6dc8a289 100644 --- a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/led_control.py +++ b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/led_control.py @@ -42,7 +42,6 @@ raise ImportError(str(e) + " - required module not found") - def DBG_PRINT(str): syslog.openlog("ledi_control") syslog.syslog(syslog.LOG_INFO, str) @@ -52,7 +51,7 @@ def DBG_PRINT(str): class LedControl(LedControlBase): """Platform specific LED control class""" SONIC_PORT_NAME_PREFIX = "Ethernet" - LED_MODE_OFF = 0 + LED_MODE_OFF = 0 LED_MODE_GREEN = 1 PORT_START = 0 PORT_END = 127 @@ -68,7 +67,7 @@ class LedControl(LedControlBase): GPIO_LANE3_PORT_LED_OFFSET = 112 # Turn OFF all port leds during init - def gpio_create_file(self,gpio_pin): + def gpio_create_file(self, gpio_pin): gpio_export_path = "/sys/class/gpio/export" gpio_pin_path = "/sys/class/gpio/gpio" + str(gpio_pin) if not os.path.exists(gpio_pin_path): @@ -82,13 +81,12 @@ def gpio_create_file(self,gpio_pin): return True - def gpio_port_led_init(self,gpio_base, port): - port_led_pin = gpio_base + self.GPIO_LANE0_PORT_LED_OFFSET + 16*(port%4) + ((port % 64)/4) + def gpio_port_led_init(self, gpio_base, port): + port_led_pin = gpio_base + self.GPIO_LANE0_PORT_LED_OFFSET + 16*(port % 4) + ((port % 64)/4) if self.gpio_create_file(port_led_pin): self.port_to_gpio_pin_mapping[port] = port_led_pin - - def gpio_port_led_slave_init(self,gpio_base_path, gpio_port_start, gpio_port_end): + def gpio_port_led_slave_init(self, gpio_base_path, gpio_port_start, gpio_port_end): flist = glob.glob(gpio_base_path) if len(flist) == 1: try: @@ -100,21 +98,19 @@ def gpio_port_led_slave_init(self,gpio_base_path, gpio_port_start, gpio_port_end for port in range(gpio_port_start, gpio_port_end + 1): self.gpio_port_led_init(gpio_base, port) - def gpio_port_led_base_init(self): self.gpio_port_led_slave_init("/sys/bus/platform/drivers/gpioslave-tmc/gpioslave-tmc.22/gpio/gpio*", - self.GPIO_SLAVE0_PORT_START, self.GPIO_SLAVE0_PORT_END) + self.GPIO_SLAVE0_PORT_START, self.GPIO_SLAVE0_PORT_END) self.gpio_port_led_slave_init("/sys/bus/platform/drivers/gpioslave-tmc/gpioslave-tmc.21/gpio/gpio*", - self.GPIO_SLAVE1_PORT_START, self.GPIO_SLAVE1_PORT_END) - + self.GPIO_SLAVE1_PORT_START, self.GPIO_SLAVE1_PORT_END) # Write driver for port led - def gpio_led_write(self,gpio_pin, value): + def gpio_led_write(self, gpio_pin, value): success = False gpio_pin_path = "/sys/class/gpio/gpio" + str(gpio_pin) try: - gpio_file = open(gpio_pin_path +"/value", 'w') + gpio_file = open(gpio_pin_path + "/value", 'w') gpio_file.write(str(value)) success = True except IOError as e: @@ -123,12 +119,12 @@ def gpio_led_write(self,gpio_pin, value): return success # Read driver for port led - def gpio_led_read(self,gpio_pin): + def gpio_led_read(self, gpio_pin): gpio_pin_path = "/sys/class/gpio/gpio" + str(gpio_pin) value = 0 try: - reg_file = open(gpio_pin_path +"/value") + reg_file = open(gpio_pin_path + "/value") value = int(reg_file.readline().rstrip()) except IOError as e: print("error: unable to open file: %s" % str(e)) @@ -159,16 +155,16 @@ def _port_state_to_mode(self, state): else: return self.LED_MODE_OFF - # Set the port led mode to Green/OFF + def _port_led_mode_update(self, gpio_pin, ledMode): if ledMode == self.LED_MODE_GREEN: self.gpio_led_write(gpio_pin, 1) else: self.gpio_led_write(gpio_pin, 0) - # Concrete implementation of port_link_state_change() method + def port_link_state_change(self, portname, state): port_idx = self._port_name_to_index(portname) gpio_pin = self.port_to_gpio_pin_mapping[port_idx] diff --git a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/psuutil.py b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/psuutil.py index 2038f8e50ee7..7ee1d3c38a3d 100644 --- a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/psuutil.py +++ b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/psuutil.py @@ -1,14 +1,14 @@ # # Name: psuutil.py version: 1.0 # -# Description: Platform-specific PSU status interface for Juniper QFX5200 +# Description: Platform-specific PSU status interface for Juniper QFX5200 # # Copyright (c) 2020, Juniper Networks, Inc. # All rights reserved. # -# Notice and Disclaimer: This code is licensed to you under the GNU General -# Public License as published by the Free Software Foundation, version 3 or -# any later version. This code is not an official Juniper product. You can +# Notice and Disclaimer: This code is licensed to you under the GNU General +# Public License as published by the Free Software Foundation, version 3 or +# any later version. This code is not an official Juniper product. You can # obtain a copy of the License at # # OSS License: @@ -26,9 +26,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . # -# Third-Party Code: This code may depend on other components under separate -# copyright notice and license terms. Your use of the source code for those -# components is subject to the terms and conditions of the respective license +# Third-Party Code: This code may depend on other components under separate +# copyright notice and license terms. Your use of the source code for those +# components is subject to the terms and conditions of the respective license # as noted in the Third-Party source code file. @@ -50,9 +50,11 @@ def __init__(self): # Get sysfs attribute + + def get_attr_value(self, attr_path): - - retval = 'ERR' + + retval = 'ERR' if (not os.path.isfile(attr_path)): return retval @@ -64,7 +66,7 @@ def get_attr_value(self, attr_path): retval = retval.rstrip(' \t\n\r') return int(retval) - + def get_num_psus(self): """ Retrieves the number of PSUs available on the device @@ -81,8 +83,8 @@ def get_psu_status(self, index): :return: Boolean, True if PSU is operating properly, False if PSU is\ faulty """ - attr_file = 'psu'+ str(index-1) +'_' + 'present' - attr_path = self.PSU_DIR +'/' + attr_file + attr_file = 'psu' + str(index-1) + '_' + 'present' + attr_path = self.PSU_DIR + '/' + attr_file attr_value = self.get_attr_value(attr_path) return attr_value == 1 @@ -94,7 +96,7 @@ def get_psu_presence(self, index): :param index: An integer, index of the PSU of which to query status :return: Boolean, True if PSU is plugged, False if not """ - attr_file ='psu'+ str(index-1) +'_' + 'present' - attr_path = self.PSU_DIR +'/' + attr_file + attr_file = 'psu' + str(index-1) + '_' + 'present' + attr_path = self.PSU_DIR + '/' + attr_file attr_value = self.get_attr_value(attr_path) return attr_value == 1 diff --git a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/qfx5200_eeprom_data.py b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/qfx5200_eeprom_data.py index e257aae91e93..ea53f11e698d 100644 --- a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/qfx5200_eeprom_data.py +++ b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/qfx5200_eeprom_data.py @@ -42,6 +42,7 @@ else: import subprocess as commands + def fantype_detect(): refpgaTMC_path = "/sys/devices/pci0000:00/0000:00:1c.0/0000:0f:00.0/refpga-tmc.15" @@ -49,7 +50,7 @@ def fantype_detect(): AFO = "1" AFI = "0" - #default fan type is AFO + # default fan type is AFO default_fantype = "0" for filename in os.listdir(refpgaTMC_path): @@ -57,7 +58,7 @@ def fantype_detect(): fantype_path = os.path.join(refpgaTMC_path, filename) cat_string = "cat " fantype_string = cat_string + fantype_path - status,fan_type = commands.getstatusoutput(fantype_string) + status, fan_type = commands.getstatusoutput(fantype_string) if ((fan_type == AFO) or (fan_type == AFI)): return fan_type else: @@ -66,7 +67,6 @@ def fantype_detect(): return default_fantype - def main(): AFO_value = "1" @@ -75,7 +75,7 @@ def main(): fan_type = fantype_detect() # creating the "/var/run/eeprom" file and storing values of CPU board EEPROM and MAIN Board EEPROM in this file. - eeprom_file = open ("/var/run/eeprom", "a+") + eeprom_file = open("/var/run/eeprom", "a+") eeprom_file.write("\n") if fan_type == AFO_value: eeprom_file.write("Fan Type=AFO\r\n") @@ -119,9 +119,9 @@ def main(): AsmID_Hexfile.write(ASMID_str) AsmID_Hexfile.seek(0, 0) vendorext_read = AsmID_Hexfile.read(58) - vendorext="" + vendorext = "" vendorext += "0x" + vendorext_read[0:2] - for i in range(2,58,2): + for i in range(2, 58, 2): vendorext += " 0x" + vendorext_read[i:i+2] eeprom_file.write("Vendor Extension=%s\r\n" % str(vendorext)) @@ -143,31 +143,26 @@ def main(): eeprom_file.write("\t") eeprom_file.write("Assembly ID=0x%s\r\n" % AssemblyID_write) - eeprom_hexfile.seek(28, 0) HWMajorRev_write = eeprom_hexfile.read(2) eeprom_file.write("\t") eeprom_file.write("HW Major Revision=0x%s\r\n" % HWMajorRev_write) - eeprom_hexfile.seek(30, 0) HWMinorRev_write = eeprom_hexfile.read(2) eeprom_file.write("\t") eeprom_file.write("HW Minor Revision=0x%s\r\n" % HWMinorRev_write) - eeprom_hexfile.seek(32, 0) Deviation_write = eeprom_hexfile.read(10) eeprom_file.write("\t") eeprom_file.write("Deviation=0x%s\r\n" % Deviation_write) - eeprom_hexfile.seek(52, 0) JEDC_write = eeprom_hexfile.read(4) eeprom_file.write("\t") eeprom_file.write("JEDC=0x%s\r\n" % JEDC_write) - eeprom_hexfile.seek(56, 0) EEPROM_version_write = eeprom_hexfile.read(2) eeprom_file.write("\t") @@ -204,7 +199,7 @@ def main(): Hexformatoutput = binascii.hexlify(content) eeprom_hex = '/etc/init.d/MainEeprom_qfx5200_hex' - #Write contents of CPU EEPROM to new file in hexa format + # Write contents of CPU EEPROM to new file in hexa format with open(eeprom_hex, 'wb+') as Hexfile: Hexfile.write(Hexformatoutput) @@ -269,6 +264,7 @@ def main(): eeprom_file.close() return True + class Eeprom(eeprom_tlvinfo.TlvInfoDecoder): def __init__(self): self.__eeprom_path = "/sys/class/i2c-adapter/i2c-0/0-0051/eeprom" @@ -312,14 +308,14 @@ def __init__(self): def serial_number_str(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_SERIAL_NUMBER) + self.__eeprom_data, self._TLV_CODE_SERIAL_NUMBER) if not is_valid: return "N/A" return results[2] def base_mac_address(self): (is_valid, t) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_MAC_BASE) + self.__eeprom_data, self._TLV_CODE_MAC_BASE) if not is_valid or t[1] != 6: return super(eeprom_tlvinfo.TlvInfoDecoder, self).switchaddrstr(self.__eeprom_data) @@ -327,7 +323,7 @@ def base_mac_address(self): def modelstr(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_PRODUCT_NAME) + self.__eeprom_data, self._TLV_CODE_PRODUCT_NAME) if not is_valid: return "N/A" @@ -335,7 +331,7 @@ def modelstr(self): def part_number_str(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_PART_NUMBER) + self.__eeprom_data, self._TLV_CODE_PART_NUMBER) if not is_valid: return "N/A" @@ -343,7 +339,7 @@ def part_number_str(self): def serial_tag_str(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_SERVICE_TAG) + self.__eeprom_data, self._TLV_CODE_SERVICE_TAG) if not is_valid: return "N/A" @@ -351,7 +347,7 @@ def serial_tag_str(self): def revision_str(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_DEVICE_VERSION) + self.__eeprom_data, self._TLV_CODE_DEVICE_VERSION) if not is_valid: return "N/A" @@ -359,7 +355,7 @@ def revision_str(self): def manuDate_str(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_MANUF_DATE) + self.__eeprom_data, self._TLV_CODE_MANUF_DATE) if not is_valid: return "N/A" @@ -367,23 +363,23 @@ def manuDate_str(self): def platform_str(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_PLATFORM_NAME) + self.__eeprom_data, self._TLV_CODE_PLATFORM_NAME) if not is_valid: return "N/A" return results[2] def MACsize_str(self): - (is_valid, t) = self.get_tlv_field(self.__eeprom_data, self._TLV_CODE_MAC_SIZE) + (is_valid, t) = self.get_tlv_field(self.__eeprom_data, self._TLV_CODE_MAC_SIZE) - if not is_valid: - return "N/A" + if not is_valid: + return "N/A" - return str((ord(t[2][0]) << 8) | ord(t[2][1])) + return str((ord(t[2][0]) << 8) | ord(t[2][1])) def vendor_name_str(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_VENDOR_NAME) + self.__eeprom_data, self._TLV_CODE_VENDOR_NAME) if not is_valid: return "N/A" @@ -391,7 +387,7 @@ def vendor_name_str(self): def manufacture_name_str(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_MANUF_NAME) + self.__eeprom_data, self._TLV_CODE_MANUF_NAME) if not is_valid: return "N/A" @@ -400,7 +396,7 @@ def manufacture_name_str(self): def onie_version_str(self): value = "" (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_ONIE_VERSION) + self.__eeprom_data, self._TLV_CODE_ONIE_VERSION) if not is_valid: return "N/A" @@ -412,19 +408,19 @@ def onie_version_str(self): def vendor_ext_str(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_VENDOR_EXT) + self.__eeprom_data, self._TLV_CODE_VENDOR_EXT) if not is_valid: return "N/A" - vendor_value_formatted = ''.join( [ " 0x" + "%02X " % ord( x ) for x in results[2] ] ).strip() - vendor_value_hexvalue = ''.join( ["%02X" % ord( x ) for x in results[2] ] ).strip() + vendor_value_formatted = ''.join([" 0x" + "%02X " % ord(x) for x in results[2]]).strip() + vendor_value_hexvalue = ''.join(["%02X" % ord(x) for x in results[2]]).strip() return vendor_value_formatted, vendor_value_hexvalue def crc_str(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_CRC_32) + self.__eeprom_data, self._TLV_CODE_CRC_32) if not is_valid: return "N/A" @@ -436,5 +432,6 @@ def system_eeprom_info(self): """ return self.__eeprom_tlv_dict + if __name__ == "__main__": main() diff --git a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/qfx5200_sfp_init.py b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/qfx5200_sfp_init.py index 4a133d3de912..723a4073687e 100644 --- a/device/juniper/x86_64-juniper_qfx5200-r0/plugins/qfx5200_sfp_init.py +++ b/device/juniper/x86_64-juniper_qfx5200-r0/plugins/qfx5200_sfp_init.py @@ -45,6 +45,7 @@ DEBUG = False + def i2c_eeprom_dev_update(port, create_eeprom): eeprom_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-0050/eeprom" i2c_path = "/sys/class/i2c-adapter/i2c-{0}" @@ -68,12 +69,13 @@ def i2c_eeprom_dev_update(port, create_eeprom): print("Error: unable to write to i2c file: %s" % str(e)) return + def gpio_sfp_init(): jnpr_sfp.gpio_sfp_base_init() time.sleep(2) - #Reset all ports + # Reset all ports for port in range(jnpr_sfp.GPIO_PORT_START, jnpr_sfp.GPIO_PORT_END + 1): logger.log_debug("GPIO SFP port {}".format(port)) @@ -82,7 +84,7 @@ def gpio_sfp_init(): time.sleep(1) - #Enable optics for all ports which have XCVRs present + # Enable optics for all ports which have XCVRs present for port in range(jnpr_sfp.GPIO_PORT_START, jnpr_sfp.GPIO_PORT_END + 1): jnpr_sfp.gpio_sfp_lpmode_set(port, 1) diff --git a/device/juniper/x86_64-juniper_qfx5210-r0/plugins/eeprom.py b/device/juniper/x86_64-juniper_qfx5210-r0/plugins/eeprom.py index b5dd80463551..4f087afc6eb0 100644 --- a/device/juniper/x86_64-juniper_qfx5210-r0/plugins/eeprom.py +++ b/device/juniper/x86_64-juniper_qfx5210-r0/plugins/eeprom.py @@ -12,16 +12,18 @@ from struct import * from array import * except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") SYSLOG_IDENTIFIER = "eeprom.py" EEPROM_PATH = "/sys/bus/i2c/devices/0-0056/eeprom" + def log_error(msg): syslog.openlog(SYSLOG_IDENTIFIER) syslog.syslog(syslog.LOG_ERR, msg) syslog.closelog() + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 @@ -33,4 +35,3 @@ def __init__(self, name, path, cpld_root, ro): self.eeprom_path = EEPROM_PATH super(board, self).__init__(self.eeprom_path, 0, '', True) - diff --git a/device/juniper/x86_64-juniper_qfx5210-r0/plugins/psuutil.py b/device/juniper/x86_64-juniper_qfx5210-r0/plugins/psuutil.py index 512127fa18fb..b05cf3e477ac 100644 --- a/device/juniper/x86_64-juniper_qfx5210-r0/plugins/psuutil.py +++ b/device/juniper/x86_64-juniper_qfx5210-r0/plugins/psuutil.py @@ -11,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/juniper/x86_64-juniper_qfx5210-r0/plugins/qfx5210_eeprom_data.py b/device/juniper/x86_64-juniper_qfx5210-r0/plugins/qfx5210_eeprom_data.py index c80322406f5e..b0aef43ba273 100644 --- a/device/juniper/x86_64-juniper_qfx5210-r0/plugins/qfx5210_eeprom_data.py +++ b/device/juniper/x86_64-juniper_qfx5210-r0/plugins/qfx5210_eeprom_data.py @@ -36,6 +36,7 @@ import binascii from sonic_eeprom import eeprom_tlvinfo + def main(): eeprom_qfx5210 = Eeprom() @@ -51,15 +52,15 @@ def main(): fan_type_file.close() if (int(fan_type) == -1 or int(fan_type) == 0): - if (int(fan_type) == -1): - print("unable to open sys file for fan handling, defaulting it to AFO") + if (int(fan_type) == -1): + print("unable to open sys file for fan handling, defaulting it to AFO") - isPlatformAFO = True + isPlatformAFO = True else: - isPlatformAFO = False + isPlatformAFO = False # creating the "/var/run/eeprom" file and storing values of CPU board EEPROM in this file. - eeprom_file = open ("/var/run/eeprom", "a+") + eeprom_file = open("/var/run/eeprom", "a+") eeprom_file.write("\n") if isPlatformAFO == True: eeprom_file.write("Fan Type=AFO\r\n") @@ -98,13 +99,13 @@ def main(): with open(eeprom_hex, 'wb+') as Hexfile: Hexfile.write(Hexformatoutput) - #Write contents of CPU EEPROM to new file in hexa format + # Write contents of CPU EEPROM to new file in hexa format with open(eeprom_hex, 'rb') as eeprom_hexfile: eeprom_hexfile.seek(350, 0) vendorext_read = eeprom_hexfile.read(124) - vendorext="" + vendorext = "" vendorext += "0x" + vendorext_read[0:2] - for i in range(2,124,2): + for i in range(2, 124, 2): vendorext += " 0x" + vendorext_read[i:i+2] eeprom_file.write("Vendor Extension=%s\r\n" % str(vendorext)) @@ -159,6 +160,7 @@ def main(): eeprom_file.close() return True + class Eeprom(eeprom_tlvinfo.TlvInfoDecoder): def __init__(self): self.__eeprom_path = "/sys/class/i2c-adapter/i2c-0/0-0056/eeprom" @@ -202,14 +204,14 @@ def __init__(self): def serial_number_str(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_SERIAL_NUMBER) + self.__eeprom_data, self._TLV_CODE_SERIAL_NUMBER) if not is_valid: return "N/A" return results[2] def base_mac_address(self): (is_valid, t) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_MAC_BASE) + self.__eeprom_data, self._TLV_CODE_MAC_BASE) if not is_valid or t[1] != 6: return super(eeprom_tlvinfo.TlvInfoDecoder, self).switchaddrstr(self.__eeprom_data) @@ -217,7 +219,7 @@ def base_mac_address(self): def modelstr(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_PRODUCT_NAME) + self.__eeprom_data, self._TLV_CODE_PRODUCT_NAME) if not is_valid: return "N/A" @@ -225,7 +227,7 @@ def modelstr(self): def part_number_str(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_PART_NUMBER) + self.__eeprom_data, self._TLV_CODE_PART_NUMBER) if not is_valid: return "N/A" @@ -233,7 +235,7 @@ def part_number_str(self): def serial_tag_str(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_SERVICE_TAG) + self.__eeprom_data, self._TLV_CODE_SERVICE_TAG) if not is_valid: return "N/A" @@ -241,7 +243,7 @@ def serial_tag_str(self): def revision_str(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_DEVICE_VERSION) + self.__eeprom_data, self._TLV_CODE_DEVICE_VERSION) if not is_valid: return "N/A" @@ -249,7 +251,7 @@ def revision_str(self): def manuDate_str(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_MANUF_DATE) + self.__eeprom_data, self._TLV_CODE_MANUF_DATE) if not is_valid: return "N/A" @@ -257,23 +259,23 @@ def manuDate_str(self): def platform_str(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_PLATFORM_NAME) + self.__eeprom_data, self._TLV_CODE_PLATFORM_NAME) if not is_valid: return "N/A" return results[2] def MACsize_str(self): - (is_valid, t) = self.get_tlv_field(self.__eeprom_data, self._TLV_CODE_MAC_SIZE) + (is_valid, t) = self.get_tlv_field(self.__eeprom_data, self._TLV_CODE_MAC_SIZE) - if not is_valid: - return "N/A" + if not is_valid: + return "N/A" - return str((ord(t[2][0]) << 8) | ord(t[2][1])) + return str((ord(t[2][0]) << 8) | ord(t[2][1])) def vendor_name_str(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_VENDOR_NAME) + self.__eeprom_data, self._TLV_CODE_VENDOR_NAME) if not is_valid: return "N/A" @@ -281,7 +283,7 @@ def vendor_name_str(self): def manufacture_name_str(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_MANUF_NAME) + self.__eeprom_data, self._TLV_CODE_MANUF_NAME) if not is_valid: return "N/A" @@ -290,7 +292,7 @@ def manufacture_name_str(self): def onie_version_str(self): value = "" (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_ONIE_VERSION) + self.__eeprom_data, self._TLV_CODE_ONIE_VERSION) if not is_valid: return "N/A" @@ -302,19 +304,19 @@ def onie_version_str(self): def vendor_ext_str(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_VENDOR_EXT) + self.__eeprom_data, self._TLV_CODE_VENDOR_EXT) if not is_valid: return "N/A" - vendor_value_formatted = ''.join( [ " 0x" + "%02X " % ord( x ) for x in results[2] ] ).strip() - vendor_value_hexvalue = ''.join( ["%02X" % ord( x ) for x in results[2] ] ).strip() + vendor_value_formatted = ''.join([" 0x" + "%02X " % ord(x) for x in results[2]]).strip() + vendor_value_hexvalue = ''.join(["%02X" % ord(x) for x in results[2]]).strip() return vendor_value_formatted, vendor_value_hexvalue def crc_str(self): (is_valid, results) = self.get_tlv_field( - self.__eeprom_data, self._TLV_CODE_CRC_32) + self.__eeprom_data, self._TLV_CODE_CRC_32) if not is_valid: return "N/A" @@ -326,5 +328,6 @@ def system_eeprom_info(self): """ return self.__eeprom_tlv_dict + if __name__ == "__main__": main() diff --git a/device/marvell/arm64-marvell_db98cx8580_16cd-r0/plugins/eeprom.py b/device/marvell/arm64-marvell_db98cx8580_16cd-r0/plugins/eeprom.py index 3463ca3e89e0..71f05c5b70f5 100644 --- a/device/marvell/arm64-marvell_db98cx8580_16cd-r0/plugins/eeprom.py +++ b/device/marvell/arm64-marvell_db98cx8580_16cd-r0/plugins/eeprom.py @@ -1,7 +1,7 @@ try: from sonic_eeprom import eeprom_tlvinfo except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/marvell/arm64-marvell_db98cx8580_32cd-r0/plugins/eeprom.py b/device/marvell/arm64-marvell_db98cx8580_32cd-r0/plugins/eeprom.py index 3463ca3e89e0..71f05c5b70f5 100644 --- a/device/marvell/arm64-marvell_db98cx8580_32cd-r0/plugins/eeprom.py +++ b/device/marvell/arm64-marvell_db98cx8580_32cd-r0/plugins/eeprom.py @@ -1,7 +1,7 @@ try: from sonic_eeprom import eeprom_tlvinfo except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/eeprom.py b/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/eeprom.py index 3463ca3e89e0..71f05c5b70f5 100644 --- a/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/eeprom.py +++ b/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/eeprom.py @@ -1,7 +1,7 @@ try: from sonic_eeprom import eeprom_tlvinfo except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/psuutil.py b/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/psuutil.py index 65f339e6647d..ab6aeff2b20b 100755 --- a/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/psuutil.py +++ b/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/psuutil.py @@ -7,21 +7,22 @@ smbus_present = 1 try: - import smbus + import smbus except ImportError as e: - smbus_present = 0 + smbus_present = 0 try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" def __init__(self): - PsuBase.__init__(self) - MAX_PSUS = 2 + PsuBase.__init__(self) + MAX_PSUS = 2 def get_num_psus(self): MAX_PSUS = 2 @@ -29,23 +30,24 @@ def get_num_psus(self): def get_psu_status(self, index): if index is None: - return False + return False if smbus_present == 0: - cmdstatus, psustatus = commands.getstatusoutput('i2cget -y 0 0x41 0xa') #need to verify the cpld register logic - psustatus = int(psustatus, 16) - else : - bus = smbus.SMBus(0) - DEVICE_ADDRESS = 0x41 - DEVICE_REG = 0xa - psustatus = bus.read_byte_data(DEVICE_ADDRESS, DEVICE_REG) + cmdstatus, psustatus = commands.getstatusoutput( + 'i2cget -y 0 0x41 0xa') # need to verify the cpld register logic + psustatus = int(psustatus, 16) + else: + bus = smbus.SMBus(0) + DEVICE_ADDRESS = 0x41 + DEVICE_REG = 0xa + psustatus = bus.read_byte_data(DEVICE_ADDRESS, DEVICE_REG) if index == 1: - psustatus = psustatus&4 - if psustatus == 4 : - return True + psustatus = psustatus & 4 + if psustatus == 4: + return True if index == 2: - psustatus = psustatus&8 - if psustatus == 8 : - return True + psustatus = psustatus & 8 + if psustatus == 8: + return True return False @@ -54,21 +56,21 @@ def get_psu_presence(self, index): return False if smbus_present == 0: - cmdstatus, psustatus = commands.getstatusoutput('i2cget -y 0 0x41 0xa') #need to verify the cpld register logic - psustatus = int(psustatus, 16) - else : - bus = smbus.SMBus(0) - DEVICE_ADDRESS = 0x41 - DEVICE_REG = 0xa - psustatus = bus.read_byte_data(DEVICE_ADDRESS, DEVICE_REG) + cmdstatus, psustatus = commands.getstatusoutput( + 'i2cget -y 0 0x41 0xa') # need to verify the cpld register logic + psustatus = int(psustatus, 16) + else: + bus = smbus.SMBus(0) + DEVICE_ADDRESS = 0x41 + DEVICE_REG = 0xa + psustatus = bus.read_byte_data(DEVICE_ADDRESS, DEVICE_REG) if index == 1: - psustatus = psustatus&1 - if psustatus == 1 : - return True + psustatus = psustatus & 1 + if psustatus == 1: + return True if index == 2: - psustatus = psustatus&2 - if psustatus == 2 : + psustatus = psustatus & 2 + if psustatus == 2: return True return False - diff --git a/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/sfputil.py b/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/sfputil.py index 74cf86ed1034..39d5db4ce7f4 100755 --- a/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/sfputil.py +++ b/device/marvell/armhf-marvell_et6448m_52x-r0/plugins/sfputil.py @@ -6,7 +6,7 @@ import glob from sonic_sfp.sfputilbase import SfpUtilBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") if sys.version_info[0] < 3: import commands @@ -20,6 +20,7 @@ except ImportError as e: smbus_present = 0 + class SfpUtil(SfpUtilBase): """Platform specific sfputil class""" @@ -29,24 +30,25 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} port_to_i2c_mapping = { - 49 : 2, - 50 : 3, - 51 : 4, - 52 : 5 + 49: 2, + 50: 3, + 51: 4, + 52: 5 } _qsfp_ports = list(range(_port_start, ports_in_block + 1)) - _changed_ports = [0,0,0,0] + _changed_ports = [0, 0, 0, 0] + def __init__(self): # Enable optical SFP Tx - if smbus_present == 0 : + if smbus_present == 0: os.system("i2cset -y -m 0x0f 0 0x41 0x5 0x00") - else : + else: bus = smbus.SMBus(0) DEVICE_ADDRESS = 0x41 DEVICEREG = 0x5 - OPTIC_E = bus.read_byte_data(DEVICE_ADDRESS, DEVICEREG) + OPTIC_E = bus.read_byte_data(DEVICE_ADDRESS, DEVICEREG) OPTIC_E = OPTIC_E & 0xf0 bus.write_byte_data(DEVICE_ADDRESS, DEVICEREG, OPTIC_E) @@ -84,7 +86,7 @@ def reset(self, port_num): print("Error: unable to open file: %s" % str(e)) return False - #toggle reset + # toggle reset reg_file.seek(0) reg_file.write('1') time.sleep(1) @@ -108,17 +110,18 @@ def get_presence(self, port_num): p = sel[0] q = sel[1] - pos = [1,2,4,8] + pos = [1, 2, 4, 8] bit_pos = pos[prt] if smbus_present == 0: - cmdstatus, sfpstatus = commands.getstatusoutput('i2cget -y 0 0x41 0x3') #need to verify the cpld register logic - sfpstatus = int(sfpstatus, 16) + cmdstatus, sfpstatus = commands.getstatusoutput( + 'i2cget -y 0 0x41 0x3') # need to verify the cpld register logic + sfpstatus = int(sfpstatus, 16) else: - bus = smbus.SMBus(0) - DEVICE_ADDRESS = 0x41 - DEVICE_REG = 0x3 - sfpstatus = bus.read_byte_data(DEVICE_ADDRESS, DEVICE_REG) - sfpstatus = sfpstatus&(bit_pos) + bus = smbus.SMBus(0) + DEVICE_ADDRESS = 0x41 + DEVICE_REG = 0x3 + sfpstatus = bus.read_byte_data(DEVICE_ADDRESS, DEVICE_REG) + sfpstatus = sfpstatus & (bit_pos) if sfpstatus == 0: #print("Port " + str(port_num) + "present") return True @@ -168,7 +171,7 @@ def read_porttab_mappings(self, porttabfile): else: fp_port_index = portname.split("Ethernet").pop() fp_port_index = int(fp_port_index.split("s").pop(0))+1 - #print(fp_port_index) + # print(fp_port_index) else: # Parsing logic for older 'portmap.ini' file fp_port_index = portname.split("Ethernet").pop() fp_port_index = int(fp_port_index.split("s").pop(0))+1 @@ -209,8 +212,7 @@ def read_porttab_mappings(self, porttabfile): self.logical = logical self.logical_to_physical = logical_to_physical self.physical_to_logical = physical_to_logical - #print(self.logical_to_physical) - + # print(self.logical_to_physical) @property def port_start(self): @@ -226,7 +228,7 @@ def qsfp_ports(self): @property def port_to_eeprom_mapping(self): - return self._port_to_eeprom_mapping + return self._port_to_eeprom_mapping def get_transceiver_change_event(self, timeout): port_dict = {} @@ -237,32 +239,29 @@ def get_transceiver_change_event(self, timeout): else: cd_ms = timeout changed_port = 0 - #poll per second + # poll per second while cd_ms > 0: - for port_num in range(49,53): - prt = port_num % 49 - sfpstatus = self.get_presence(port_num) - if sfpstatus : - port_dict[str(port_num)]= '1' - if self._changed_ports[prt] == 0: - changed_port = 1 - self._changed_ports[prt] = 1 - else : - port_dict[str(port_num)] = '0' - if self._changed_ports[prt] == 1: - changed_port = 1 - self._changed_ports[prt] = 0 - - if changed_port != 0: - break - time.sleep(1) - cd_ms = cd_ms - 1000 + for port_num in range(49, 53): + prt = port_num % 49 + sfpstatus = self.get_presence(port_num) + if sfpstatus: + port_dict[str(port_num)] = '1' + if self._changed_ports[prt] == 0: + changed_port = 1 + self._changed_ports[prt] = 1 + else: + port_dict[str(port_num)] = '0' + if self._changed_ports[prt] == 1: + changed_port = 1 + self._changed_ports[prt] = 0 + + if changed_port != 0: + break + time.sleep(1) + cd_ms = cd_ms - 1000 if changed_port: return True, port_dict else: return True, {} return False, {} - - - diff --git a/device/marvell/x86_64-marvell_db98cx8580_16cd-r0/plugins/eeprom.py b/device/marvell/x86_64-marvell_db98cx8580_16cd-r0/plugins/eeprom.py index 3463ca3e89e0..71f05c5b70f5 100644 --- a/device/marvell/x86_64-marvell_db98cx8580_16cd-r0/plugins/eeprom.py +++ b/device/marvell/x86_64-marvell_db98cx8580_16cd-r0/plugins/eeprom.py @@ -1,7 +1,7 @@ try: from sonic_eeprom import eeprom_tlvinfo except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/marvell/x86_64-marvell_db98cx8580_32cd-r0/plugins/eeprom.py b/device/marvell/x86_64-marvell_db98cx8580_32cd-r0/plugins/eeprom.py index 3463ca3e89e0..71f05c5b70f5 100644 --- a/device/marvell/x86_64-marvell_db98cx8580_32cd-r0/plugins/eeprom.py +++ b/device/marvell/x86_64-marvell_db98cx8580_32cd-r0/plugins/eeprom.py @@ -1,7 +1,7 @@ try: from sonic_eeprom import eeprom_tlvinfo except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): diff --git a/device/marvell/x86_64-marvell_slm5401_54x-r0/plugins/eeprom.py b/device/marvell/x86_64-marvell_slm5401_54x-r0/plugins/eeprom.py index e7f6a39411d5..951384d5e37d 100755 --- a/device/marvell/x86_64-marvell_slm5401_54x-r0/plugins/eeprom.py +++ b/device/marvell/x86_64-marvell_slm5401_54x-r0/plugins/eeprom.py @@ -9,13 +9,15 @@ from sonic_eeprom import eeprom_tlvinfo import subprocess except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom" - #Two i2c buses might get flipped order, check them both. + # Two i2c buses might get flipped order, check them both. if not os.path.exists(self.eeprom_path): self.eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/marvell/x86_64-marvell_slm5401_54x-r0/plugins/sfputil.py b/device/marvell/x86_64-marvell_slm5401_54x-r0/plugins/sfputil.py index aeb3a0d512f9..b1d356e393ee 100755 --- a/device/marvell/x86_64-marvell_slm5401_54x-r0/plugins/sfputil.py +++ b/device/marvell/x86_64-marvell_slm5401_54x-r0/plugins/sfputil.py @@ -2,7 +2,7 @@ import time from sonic_sfp.sfputilbase import SfpUtilBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class sfputil(SfpUtilBase): @@ -14,38 +14,38 @@ class sfputil(SfpUtilBase): port_to_eeprom_mapping = {} port_to_i2c_mapping = { - 9 : 18, - 10 : 19, - 11 : 20, - 12 : 21, - 1 : 22, - 2 : 23, - 3 : 24, - 4 : 25, - 6 : 26, - 5 : 27, - 8 : 28, - 7 : 29, - 13 : 30, - 14 : 31, - 15 : 32, - 16 : 33, - 17 : 34, - 18 : 35, - 19 : 36, - 20 : 37, - 25 : 38, - 26 : 39, - 27 : 40, - 28 : 41, - 29 : 42, - 30 : 43, - 31 : 44, - 32 : 45, - 21 : 46, - 22 : 47, - 23 : 48, - 24 : 49, + 9: 18, + 10: 19, + 11: 20, + 12: 21, + 1: 22, + 2: 23, + 3: 24, + 4: 25, + 6: 26, + 5: 27, + 8: 28, + 7: 29, + 13: 30, + 14: 31, + 15: 32, + 16: 33, + 17: 34, + 18: 35, + 19: 36, + 20: 37, + 25: 38, + 26: 39, + 27: 40, + 28: 41, + 29: 42, + 30: 43, + 31: 44, + 32: 45, + 21: 46, + 22: 47, + 23: 48, + 24: 49, } _qsfp_ports = list(range(0, ports_in_block + 1)) @@ -72,7 +72,7 @@ def reset(self, port_num): print("Error: unable to open file: %s" % str(e)) return False - #toggle reset + # toggle reset reg_file.seek(0) reg_file.write('1') time.sleep(1) @@ -95,7 +95,6 @@ def get_presence(self, port_num): path = "/sys/bus/i2c/devices/{0}-0050/sfp_is_present" port_ps = path.format(self.port_to_i2c_mapping[port_num+1]) - try: reg_file = open(port_ps) except IOError as e: @@ -122,7 +121,7 @@ def qsfp_ports(self): @property def port_to_eeprom_mapping(self): - return self._port_to_eeprom_mapping + return self._port_to_eeprom_mapping def get_transceiver_change_event(self): """ diff --git a/device/mellanox/x86_64-mlnx_msn2010-r0/plugins/psuutil.py b/device/mellanox/x86_64-mlnx_msn2010-r0/plugins/psuutil.py index 051e6bfe1044..0d864849dc48 100644 --- a/device/mellanox/x86_64-mlnx_msn2010-r0/plugins/psuutil.py +++ b/device/mellanox/x86_64-mlnx_msn2010-r0/plugins/psuutil.py @@ -11,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/mellanox/x86_64-mlnx_msn2100-r0/plugins/psuutil.py b/device/mellanox/x86_64-mlnx_msn2100-r0/plugins/psuutil.py index 8498b0ce906c..2b4f87397bc4 100644 --- a/device/mellanox/x86_64-mlnx_msn2100-r0/plugins/psuutil.py +++ b/device/mellanox/x86_64-mlnx_msn2100-r0/plugins/psuutil.py @@ -11,7 +11,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/eeprom.py b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/eeprom.py index e191f47d826a..0f20ffff3b53 100644 --- a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/eeprom.py +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/eeprom.py @@ -26,12 +26,13 @@ from sonic_py_common.device_info import get_machine_info import subprocess except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") SYSLOG_IDENTIFIER = "eeprom.py" EEPROM_SYMLINK = "/var/run/hw-management/eeprom/vpd_info" CACHE_FILE = "/var/cache/sonic/decode-syseeprom/syseeprom_cache" + def log_error(msg): syslog.openlog(SYSLOG_IDENTIFIER) syslog.syslog(syslog.LOG_ERR, msg) @@ -45,6 +46,7 @@ def log_error(msg): subprocess.check_call(['/usr/bin/xxd', '-r', '-p', 'syseeprom.hex', 'syseeprom.bin'], cwd=platform_path) CACHE_FILE = os.path.join(platform_path, 'syseeprom.bin') + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 @@ -55,7 +57,7 @@ def __init__(self, name, path, cpld_root, ro): if not os.path.islink(EEPROM_SYMLINK): time.sleep(1) else: - break + break if not (os.path.exists(EEPROM_SYMLINK) or os.path.isfile(CACHE_FILE)): log_error("Nowhere to read syseeprom from! No symlink or cache file found") @@ -71,4 +73,3 @@ def decode_eeprom(self, e): decode_output = sys.stdout.getvalue() sys.stdout = original_stdout print(decode_output.replace('\0', '')) - diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/fanutil.py b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/fanutil.py index 0a5559c34b06..5881e595c26e 100644 --- a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/fanutil.py +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/fanutil.py @@ -14,20 +14,23 @@ from glob import glob from sonic_fan.fan_base import FanBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + def log_err(msg): syslog.openlog("fanutil") syslog.syslog(syslog.LOG_ERR, msg) syslog.closelog() + class FanUtil(FanBase): """Platform-specific FanUtil class""" PWM_MAX = 255 MAX_FAN_PER_DRAWER = 2 GET_HWSKU_CMD = "sonic-cfggen -d -v DEVICE_METADATA.localhost.hwsku" - sku_without_fan_direction = ['ACS-MSN2010', 'ACS-MSN2100', 'ACS-MSN2410', 'ACS-MSN2700', 'Mellanox-SN2700', 'Mellanox-SN2700-D48C8', 'LS-SN2700', 'ACS-MSN2740'] + sku_without_fan_direction = ['ACS-MSN2010', 'ACS-MSN2100', 'ACS-MSN2410', + 'ACS-MSN2700', 'Mellanox-SN2700', 'Mellanox-SN2700-D48C8', 'LS-SN2700', 'ACS-MSN2740'] sku_with_unpluggable_fan = ['ACS-MSN2010', 'ACS-MSN2100'] def __init__(self): @@ -48,7 +51,7 @@ def __init__(self): self.fan_direction = None else: self.fan_direction = "system/fan_dir" - + self.fan_led_green = "led/led_fan*_green" self.num_of_fan, self.num_of_drawer = self._extract_num_of_fans_and_fan_drawers() @@ -72,7 +75,7 @@ def _extract_num_of_fans_and_fan_drawers(self): def _convert_fan_index_to_drawer_index(self, index): return (index + self.MAX_FAN_PER_DRAWER - 1) / self.MAX_FAN_PER_DRAWER - def _read_file(self, file_pattern, index = 0): + def _read_file(self, file_pattern, index=0): """ Reads the file of the fan @@ -122,7 +125,8 @@ def get_presence(self, index): :return: Boolean, True if FAN is plugged, False if not """ if index > self.num_of_fan: - raise RuntimeError("index ({}) shouldn't be greater than number of fans ({})".format(index, self.num_of_fan)) + raise RuntimeError( + "index ({}) shouldn't be greater than number of fans ({})".format(index, self.num_of_fan)) if self.unpluggable_fan: return True @@ -154,7 +158,8 @@ def get_direction(self, index): return self.FAN_DIRECTION_NOT_APPLICABLE if index > self.num_of_fan: - raise RuntimeError("index ({}) shouldn't be greater than number of fans ({})".format(index, self.num_of_fan)) + raise RuntimeError( + "index ({}) shouldn't be greater than number of fans ({})".format(index, self.num_of_fan)) drawer_index = self._convert_fan_index_to_drawer_index(index) diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/psuutil.py b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/psuutil.py index 64f1ab9a080d..0303ab8f8193 100644 --- a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/psuutil.py +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/psuutil.py @@ -12,7 +12,8 @@ import subprocess from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + def log_err(msg): syslog.openlog("psuutil") @@ -28,7 +29,8 @@ class PsuUtil(PsuBase): GET_HWSKU_CMD = "sonic-cfggen -d -v DEVICE_METADATA.localhost.hwsku" # for spectrum1 switches with plugable PSUs, the output voltage file is psuX_volt # for spectrum2 switches the output voltage file is psuX_volt_out2 - sku_spectrum1_with_plugable_psu = ['ACS-MSN2410', 'ACS-MSN2700', 'Mellanox-SN2700', 'Mellanox-SN2700-D48C8', 'LS-SN2700', 'ACS-MSN2740'] + sku_spectrum1_with_plugable_psu = ['ACS-MSN2410', 'ACS-MSN2700', + 'Mellanox-SN2700', 'Mellanox-SN2700-D48C8', 'LS-SN2700', 'ACS-MSN2740'] def __init__(self): PsuBase.__init__(self) diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfplpmget.py b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfplpmget.py index 5964736dbb53..ca16c3573d06 100644 --- a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfplpmget.py +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfplpmget.py @@ -8,6 +8,7 @@ import errno from python_sdk_api.sx_api import * + def mgmt_phy_mod_pwr_attr_get(handle, module_id, power_attr_type): sx_mgmt_phy_mod_pwr_attr_p = new_sx_mgmt_phy_mod_pwr_attr_t_p() sx_mgmt_phy_mod_pwr_attr = sx_mgmt_phy_mod_pwr_attr_t() @@ -22,6 +23,7 @@ def mgmt_phy_mod_pwr_attr_get(handle, module_id, power_attr_type): finally: delete_sx_mgmt_phy_mod_pwr_attr_t_p(sx_mgmt_phy_mod_pwr_attr_p) + # Check if SFP port number is provided if len(sys.argv) < 2: print("SFP module number is missed.") diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfplpmset.py b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfplpmset.py index 8fbc87daf720..61423880ac71 100644 --- a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfplpmset.py +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfplpmset.py @@ -20,12 +20,15 @@ NVE_MASK = PORT_TYPE_MASK & (PORT_TYPE_NVE << PORT_TYPE_OFFSET) CPU_MASK = PORT_TYPE_MASK & (PORT_TYPE_CPU << PORT_TYPE_OFFSET) + def is_nve(port): return (port & NVE_MASK) != 0 + def is_cpu(port): return (port & CPU_MASK) != 0 + def is_port_admin_status_up(log_port): oper_state_p = new_sx_port_oper_state_t_p() admin_state_p = new_sx_port_admin_state_t_p() @@ -39,11 +42,14 @@ def is_port_admin_status_up(log_port): else: return False + def set_port_admin_status_by_log_port(handle, log_port, admin_status): rc = sx_api_port_state_set(handle, log_port, admin_status) assert rc == SX_STATUS_SUCCESS, "sx_api_port_state_set failed, rc = %d" % rc # Get all the ports related to the sfp, if port admin status is up, put it to list + + def get_log_ports(handle, sfp_module): port_attributes_list = new_sx_port_attributes_t_arr(SX_PORT_ATTR_ARR_SIZE) port_cnt_p = new_uint32_t_p() @@ -64,6 +70,7 @@ def get_log_ports(handle, sfp_module): return log_port_list + def mgmt_phy_mod_pwr_attr_set(handle, module_id, power_attr_type, admin_pwr_mode): sx_mgmt_phy_mod_pwr_attr = sx_mgmt_phy_mod_pwr_attr_t() sx_mgmt_phy_mod_pwr_mode_attr = sx_mgmt_phy_mod_pwr_mode_attr_t() @@ -78,6 +85,7 @@ def mgmt_phy_mod_pwr_attr_set(handle, module_id, power_attr_type, admin_pwr_mode finally: delete_sx_mgmt_phy_mod_pwr_attr_t_p(sx_mgmt_phy_mod_pwr_attr_p) + def mgmt_phy_mod_pwr_attr_get(handle, module_id, power_attr_type): sx_mgmt_phy_mod_pwr_attr_p = new_sx_mgmt_phy_mod_pwr_attr_t_p() sx_mgmt_phy_mod_pwr_attr = sx_mgmt_phy_mod_pwr_attr_t() @@ -110,20 +118,24 @@ def pwr_attr_set(handle, module_id, ports, attr_type, power_mode): for port in ports: set_port_admin_status_by_log_port(handle, port, SX_PORT_ADMIN_STATUS_UP) + def set_lpmode(handle, cmd, module_id): # Construct the port module map. log_port_list = get_log_ports(handle, module_id) if cmd == "enable": - pwr_attr_set(handle, module_id, log_port_list, SX_MGMT_PHY_MOD_PWR_ATTR_PWR_MODE_E, SX_MGMT_PHY_MOD_PWR_MODE_LOW_E) + pwr_attr_set(handle, module_id, log_port_list, + SX_MGMT_PHY_MOD_PWR_ATTR_PWR_MODE_E, SX_MGMT_PHY_MOD_PWR_MODE_LOW_E) print("Enabled low power mode for module [%d]" % module_id) elif cmd == "disable": - pwr_attr_set(handle, module_id, log_port_list, SX_MGMT_PHY_MOD_PWR_ATTR_PWR_MODE_E, SX_MGMT_PHY_MOD_PWR_MODE_AUTO_E) + pwr_attr_set(handle, module_id, log_port_list, + SX_MGMT_PHY_MOD_PWR_ATTR_PWR_MODE_E, SX_MGMT_PHY_MOD_PWR_MODE_AUTO_E) print("Disabled low power mode for module [%d]" % module_id) else: print("Error: Invalid command") sys.exit(0) + if len(sys.argv) < 3: print("SFP module number or LPM is missed.") print("Usage: sfplpmset.py ") diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfputil.py b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfputil.py index 3462ac782fa8..5c30fb5cd069 100644 --- a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfputil.py +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfputil.py @@ -41,19 +41,24 @@ # magic code defnition for port number, qsfp port position of each platform # port_position_tuple = (PORT_START, QSFP_PORT_START, PORT_END, PORT_IN_BLOCK, EEPROM_OFFSET) -platform_dict = {'x86_64-mlnx_msn2700-r0': 0, 'x86_64-mlnx_msn2740-r0': 0, 'x86_64-mlnx_msn2100-r0': 1, 'x86_64-mlnx_msn2410-r0': 2, 'x86_64-mlnx_msn2010-r0': 3, 'x86_64-mlnx_msn3420-r0':5, 'x86_64-mlnx_msn3700-r0': 0, 'x86_64-mlnx_msn3700c-r0': 0, 'x86_64-mlnx_msn3800-r0': 4, 'x86_64-mlnx_msn4600c':4, 'x86_64-mlnx_msn4700-r0': 0} -port_position_tuple_list = [(0, 0, 31, 32, 1), (0, 0, 15, 16, 1), (0, 48, 55, 56, 1), (0, 18, 21, 22, 1), (0, 0, 63, 64, 1), (0, 48, 59, 60, 1)] +platform_dict = {'x86_64-mlnx_msn2700-r0': 0, 'x86_64-mlnx_msn2740-r0': 0, 'x86_64-mlnx_msn2100-r0': 1, 'x86_64-mlnx_msn2410-r0': 2, 'x86_64-mlnx_msn2010-r0': 3, + 'x86_64-mlnx_msn3420-r0': 5, 'x86_64-mlnx_msn3700-r0': 0, 'x86_64-mlnx_msn3700c-r0': 0, 'x86_64-mlnx_msn3800-r0': 4, 'x86_64-mlnx_msn4600c': 4, 'x86_64-mlnx_msn4700-r0': 0} +port_position_tuple_list = [(0, 0, 31, 32, 1), (0, 0, 15, 16, 1), (0, 48, 55, 56, 1), + (0, 18, 21, 22, 1), (0, 0, 63, 64, 1), (0, 48, 59, 60, 1)] + def log_info(msg, also_print_to_console=False): syslog.openlog("sfputil") syslog.syslog(syslog.LOG_INFO, msg) syslog.closelog() + def log_err(msg, also_print_to_console=False): syslog.openlog("sfputil") syslog.syslog(syslog.LOG_ERR, msg) syslog.closelog() + class SfpUtil(SfpUtilBase): """Platform-specific SfpUtil class""" PORT_START = 0 @@ -260,13 +265,13 @@ def _read_eeprom_specific_bytes_via_ethtool(self, port_num, offset, num_bytes): return eeprom_raw # Read eeprom - def _read_eeprom_devid(self, port_num, devid, offset, num_bytes = 512): + def _read_eeprom_devid(self, port_num, devid, offset, num_bytes=512): if port_num in self.osfp_ports: pass elif port_num in self.qsfp_ports: pass elif (self.DOM_EEPROM_ADDR == devid): - offset += 256 + offset += 256 eeprom_raw = self._read_eeprom_specific_bytes_via_ethtool(port_num, offset, num_bytes) @@ -289,31 +294,36 @@ def get_transceiver_info_dict(self, port_num): print("Error: sfp_object open failed") return None - sfp_type_raw = self._read_eeprom_specific_bytes_via_ethtool(port_num, (offset + OSFP_TYPE_OFFSET), XCVR_TYPE_WIDTH) + sfp_type_raw = self._read_eeprom_specific_bytes_via_ethtool( + port_num, (offset + OSFP_TYPE_OFFSET), XCVR_TYPE_WIDTH) if sfp_type_raw is not None: sfp_type_data = sfpi_obj.parse_sfp_type(sfp_type_raw, 0) else: return None - sfp_vendor_name_raw = self._read_eeprom_specific_bytes_via_ethtool(port_num, (offset + OSFP_VENDOR_NAME_OFFSET), XCVR_VENDOR_NAME_WIDTH) + sfp_vendor_name_raw = self._read_eeprom_specific_bytes_via_ethtool( + port_num, (offset + OSFP_VENDOR_NAME_OFFSET), XCVR_VENDOR_NAME_WIDTH) if sfp_vendor_name_raw is not None: sfp_vendor_name_data = sfpi_obj.parse_vendor_name(sfp_vendor_name_raw, 0) else: return None - sfp_vendor_pn_raw = self._read_eeprom_specific_bytes_via_ethtool(port_num, (offset + OSFP_VENDOR_PN_OFFSET), XCVR_VENDOR_PN_WIDTH) + sfp_vendor_pn_raw = self._read_eeprom_specific_bytes_via_ethtool( + port_num, (offset + OSFP_VENDOR_PN_OFFSET), XCVR_VENDOR_PN_WIDTH) if sfp_vendor_pn_raw is not None: sfp_vendor_pn_data = sfpi_obj.parse_vendor_pn(sfp_vendor_pn_raw, 0) else: return None - sfp_vendor_rev_raw = self._read_eeprom_specific_bytes_via_ethtool(port_num, (offset + OSFP_HW_REV_OFFSET), vendor_rev_width) + sfp_vendor_rev_raw = self._read_eeprom_specific_bytes_via_ethtool( + port_num, (offset + OSFP_HW_REV_OFFSET), vendor_rev_width) if sfp_vendor_rev_raw is not None: sfp_vendor_rev_data = sfpi_obj.parse_vendor_rev(sfp_vendor_rev_raw, 0) else: return None - sfp_vendor_sn_raw = self._read_eeprom_specific_bytes_via_ethtool(port_num, (offset + OSFP_VENDOR_SN_OFFSET), XCVR_VENDOR_SN_WIDTH) + sfp_vendor_sn_raw = self._read_eeprom_specific_bytes_via_ethtool( + port_num, (offset + OSFP_VENDOR_SN_OFFSET), XCVR_VENDOR_SN_WIDTH) if sfp_vendor_sn_raw is not None: sfp_vendor_sn_data = sfpi_obj.parse_vendor_sn(sfp_vendor_sn_raw, 0) else: @@ -361,43 +371,50 @@ def get_transceiver_info_dict(self, port_num): print("Error: sfp_object open failed") return None - sfp_interface_bulk_raw = self._read_eeprom_specific_bytes_via_ethtool(port_num, (offset + XCVR_INTFACE_BULK_OFFSET), interface_info_bulk_width) + sfp_interface_bulk_raw = self._read_eeprom_specific_bytes_via_ethtool( + port_num, (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) else: return None - sfp_vendor_name_raw = self._read_eeprom_specific_bytes_via_ethtool(port_num, (offset + XCVR_VENDOR_NAME_OFFSET), XCVR_VENDOR_NAME_WIDTH) + sfp_vendor_name_raw = self._read_eeprom_specific_bytes_via_ethtool( + port_num, (offset + XCVR_VENDOR_NAME_OFFSET), XCVR_VENDOR_NAME_WIDTH) if sfp_vendor_name_raw is not None: sfp_vendor_name_data = sfpi_obj.parse_vendor_name(sfp_vendor_name_raw, 0) else: return None - sfp_vendor_pn_raw = self._read_eeprom_specific_bytes_via_ethtool(port_num, (offset + XCVR_VENDOR_PN_OFFSET), XCVR_VENDOR_PN_WIDTH) + sfp_vendor_pn_raw = self._read_eeprom_specific_bytes_via_ethtool( + port_num, (offset + XCVR_VENDOR_PN_OFFSET), XCVR_VENDOR_PN_WIDTH) if sfp_vendor_pn_raw is not None: sfp_vendor_pn_data = sfpi_obj.parse_vendor_pn(sfp_vendor_pn_raw, 0) else: return None - sfp_vendor_rev_raw = self._read_eeprom_specific_bytes_via_ethtool(port_num, (offset + XCVR_HW_REV_OFFSET), vendor_rev_width) + sfp_vendor_rev_raw = self._read_eeprom_specific_bytes_via_ethtool( + port_num, (offset + XCVR_HW_REV_OFFSET), vendor_rev_width) if sfp_vendor_rev_raw is not None: sfp_vendor_rev_data = sfpi_obj.parse_vendor_rev(sfp_vendor_rev_raw, 0) else: return None - sfp_vendor_sn_raw = self._read_eeprom_specific_bytes_via_ethtool(port_num, (offset + XCVR_VENDOR_SN_OFFSET), XCVR_VENDOR_SN_WIDTH) + sfp_vendor_sn_raw = self._read_eeprom_specific_bytes_via_ethtool( + port_num, (offset + XCVR_VENDOR_SN_OFFSET), XCVR_VENDOR_SN_WIDTH) if sfp_vendor_sn_raw is not None: sfp_vendor_sn_data = sfpi_obj.parse_vendor_sn(sfp_vendor_sn_raw, 0) else: return None - sfp_vendor_oui_raw = self._read_eeprom_specific_bytes_via_ethtool(port_num, (offset + XCVR_VENDOR_OUI_OFFSET), XCVR_VENDOR_OUI_WIDTH) + sfp_vendor_oui_raw = self._read_eeprom_specific_bytes_via_ethtool( + port_num, (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) else: return None - sfp_vendor_date_raw = self._read_eeprom_specific_bytes_via_ethtool(port_num, (offset + XCVR_VENDOR_DATE_OFFSET), XCVR_VENDOR_DATE_WIDTH) + sfp_vendor_date_raw = self._read_eeprom_specific_bytes_via_ethtool( + port_num, (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) else: @@ -409,7 +426,8 @@ def get_transceiver_info_dict(self, port_num): transceiver_info_dict['hardware_rev'] = sfp_vendor_rev_data['data']['Vendor Rev']['value'] transceiver_info_dict['serial'] = sfp_vendor_sn_data['data']['Vendor SN']['value'] transceiver_info_dict['vendor_oui'] = sfp_vendor_oui_data['data']['Vendor OUI']['value'] - transceiver_info_dict['vendor_date'] = sfp_vendor_date_data['data']['VendorDataCode(YYYY-MM-DD Lot)']['value'] + transceiver_info_dict['vendor_date'] = sfp_vendor_date_data[ + 'data']['VendorDataCode(YYYY-MM-DD Lot)']['value'] transceiver_info_dict['connector'] = sfp_interface_bulk_data['data']['Connector']['value'] transceiver_info_dict['encoding'] = sfp_interface_bulk_data['data']['EncodingCodes']['value'] transceiver_info_dict['ext_identifier'] = sfp_interface_bulk_data['data']['Extended Identifier']['value'] @@ -425,7 +443,8 @@ def get_transceiver_info_dict(self, port_num): compliance_code_dict[key] = sfp_interface_bulk_data['data']['Specification compliance']['value'][key]['value'] transceiver_info_dict['specification_compliance'] = str(compliance_code_dict) - transceiver_info_dict['nominal_bit_rate'] = str(sfp_interface_bulk_data['data']['Nominal Bit Rate(100Mbs)']['value']) + transceiver_info_dict['nominal_bit_rate'] = str( + sfp_interface_bulk_data['data']['Nominal Bit Rate(100Mbs)']['value']) else: for key in sfp_cable_length_tup: if key in sfp_interface_bulk_data['data']: @@ -437,7 +456,8 @@ def get_transceiver_info_dict(self, port_num): compliance_code_dict[key] = sfp_interface_bulk_data['data']['Specification compliance']['value'][key]['value'] transceiver_info_dict['specification_compliance'] = str(compliance_code_dict) - transceiver_info_dict['nominal_bit_rate'] = str(sfp_interface_bulk_data['data']['NominalSignallingRate(UnitsOf100Mbd)']['value']) + transceiver_info_dict['nominal_bit_rate'] = str( + sfp_interface_bulk_data['data']['NominalSignallingRate(UnitsOf100Mbd)']['value']) return transceiver_info_dict @@ -486,30 +506,33 @@ def get_transceiver_dom_info_dict(self, port_num): if sfpi_obj is None: return None - # QSFP capability byte parse, through this byte can know whether it support tx_power or not. # TODO: in the future when decided to migrate to support SFF-8636 instead of SFF-8436, # need to add more code for determining the capability and version compliance # in SFF-8636 dom capability definitions evolving with the versions. - qsfp_dom_capability_raw = self._read_eeprom_specific_bytes_via_ethtool(port_num, (offset_xcvr + XCVR_DOM_CAPABILITY_OFFSET), XCVR_DOM_CAPABILITY_WIDTH) + qsfp_dom_capability_raw = self._read_eeprom_specific_bytes_via_ethtool( + port_num, (offset_xcvr + XCVR_DOM_CAPABILITY_OFFSET), XCVR_DOM_CAPABILITY_WIDTH) if qsfp_dom_capability_raw is not None: qspf_dom_capability_data = sfpi_obj.parse_qsfp_dom_capability(qsfp_dom_capability_raw, 0) else: return transceiver_dom_info_dict - dom_temperature_raw = self._read_eeprom_specific_bytes_via_ethtool(port_num, (offset + QSFP_TEMPE_OFFSET), QSFP_TEMPE_WIDTH) + dom_temperature_raw = self._read_eeprom_specific_bytes_via_ethtool( + port_num, (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 transceiver_dom_info_dict - dom_voltage_raw = self._read_eeprom_specific_bytes_via_ethtool(port_num, (offset + QSFP_VOLT_OFFSET), QSFP_VOLT_WIDTH) + dom_voltage_raw = self._read_eeprom_specific_bytes_via_ethtool( + port_num, (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 transceiver_dom_info_dict - qsfp_dom_rev_raw = self._read_eeprom_specific_bytes_via_ethtool(port_num, (offset + QSFP_DOM_REV_OFFSET), QSFP_DOM_REV_WIDTH) + qsfp_dom_rev_raw = self._read_eeprom_specific_bytes_via_ethtool( + port_num, (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: @@ -524,15 +547,18 @@ def get_transceiver_dom_info_dict(self, port_num): 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_via_ethtool(port_num, (offset + QSFP_CHANNL_MON_OFFSET), QSFP_CHANNL_MON_WIDTH) + dom_channel_monitor_raw = self._read_eeprom_specific_bytes_via_ethtool( + port_num, (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: return transceiver_dom_info_dict else: - dom_channel_monitor_raw = self._read_eeprom_specific_bytes_via_ethtool(port_num, (offset + QSFP_CHANNL_MON_OFFSET), QSFP_CHANNL_MON_WITH_TX_POWER_WIDTH) + dom_channel_monitor_raw = self._read_eeprom_specific_bytes_via_ethtool( + port_num, (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 transceiver_dom_info_dict @@ -556,8 +582,9 @@ def get_transceiver_dom_info_dict(self, port_num): offset = SFP_I2C_PAGE_SIZE eeprom_raw = ['0'] * SFP_I2C_PAGE_SIZE - eeprom_raw[XCVR_DOM_CAPABILITY_OFFSET : XCVR_DOM_CAPABILITY_OFFSET + XCVR_DOM_CAPABILITY_WIDTH] = \ - self._read_eeprom_specific_bytes_via_ethtool(port_num, XCVR_DOM_CAPABILITY_OFFSET, XCVR_DOM_CAPABILITY_WIDTH) + eeprom_raw[XCVR_DOM_CAPABILITY_OFFSET: XCVR_DOM_CAPABILITY_OFFSET + XCVR_DOM_CAPABILITY_WIDTH] = \ + self._read_eeprom_specific_bytes_via_ethtool( + port_num, XCVR_DOM_CAPABILITY_OFFSET, XCVR_DOM_CAPABILITY_WIDTH) sfp_obj = sff8472InterfaceId() calibration_type = sfp_obj._get_calibration_type(eeprom_raw) @@ -604,7 +631,7 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): 'txpowerlowalarm', 'txpowerlowwarning', 'txbiashighalarm', 'txbiashighwarning', 'txbiaslowalarm', 'txbiaslowwarning' - ] + ] transceiver_dom_threshold_info_dict = dict.fromkeys(dom_info_dict_keys, 'N/A') if port_num in self.qsfp_ports: @@ -614,8 +641,9 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): offset = SFP_I2C_PAGE_SIZE eeprom_raw = ['0'] * SFP_I2C_PAGE_SIZE - eeprom_raw[XCVR_DOM_CAPABILITY_OFFSET : XCVR_DOM_CAPABILITY_OFFSET + XCVR_DOM_CAPABILITY_WIDTH] = \ - self._read_eeprom_specific_bytes_via_ethtool(port_num, XCVR_DOM_CAPABILITY_OFFSET, XCVR_DOM_CAPABILITY_WIDTH) + eeprom_raw[XCVR_DOM_CAPABILITY_OFFSET: XCVR_DOM_CAPABILITY_OFFSET + XCVR_DOM_CAPABILITY_WIDTH] = \ + self._read_eeprom_specific_bytes_via_ethtool( + port_num, XCVR_DOM_CAPABILITY_OFFSET, XCVR_DOM_CAPABILITY_WIDTH) sfp_obj = sff8472InterfaceId() calibration_type = sfp_obj._get_calibration_type(eeprom_raw) @@ -628,8 +656,8 @@ def get_transceiver_dom_threshold_info_dict(self, port_num): return transceiver_dom_threshold_info_dict dom_module_threshold_raw = self._read_eeprom_specific_bytes_via_ethtool(port_num, - (offset + SFP_MODULE_THRESHOLD_OFFSET), - SFP_MODULE_THRESHOLD_WIDTH) + (offset + SFP_MODULE_THRESHOLD_OFFSET), + SFP_MODULE_THRESHOLD_WIDTH) if dom_module_threshold_raw is not None: dom_module_threshold_data = sfpd_obj.parse_alarm_warning_threshold(dom_module_threshold_raw, 0) else: diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/thermalutil.py b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/thermalutil.py index c7513711f48f..10516b7077dc 100644 --- a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/thermalutil.py +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/thermalutil.py @@ -12,7 +12,8 @@ import subprocess from sonic_thermal.thermal_base import ThermalBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + def log_info(msg): syslog.openlog("thermalutil") @@ -42,57 +43,57 @@ def log_info(msg): HW_MGMT_THERMAL_ROOT = "/var/run/hw-management/thermal/" thermal_api_handler_cpu_core = { - THERMAL_API_GET_TEMPERATURE:"cpu_core{}", - THERMAL_API_GET_HIGH_THRESHOLD:"cpu_core{}_max", - THERMAL_API_GET_HIGH_CRITICAL_THRESHOLD:"cpu_core{}_crit" + THERMAL_API_GET_TEMPERATURE: "cpu_core{}", + THERMAL_API_GET_HIGH_THRESHOLD: "cpu_core{}_max", + THERMAL_API_GET_HIGH_CRITICAL_THRESHOLD: "cpu_core{}_crit" } thermal_api_handler_cpu_pack = { - THERMAL_API_GET_TEMPERATURE:"cpu_pack", - THERMAL_API_GET_HIGH_THRESHOLD:"cpu_pack_max", - THERMAL_API_GET_HIGH_CRITICAL_THRESHOLD:"cpu_pack_crit" + THERMAL_API_GET_TEMPERATURE: "cpu_pack", + THERMAL_API_GET_HIGH_THRESHOLD: "cpu_pack_max", + THERMAL_API_GET_HIGH_CRITICAL_THRESHOLD: "cpu_pack_crit" } thermal_api_handler_module = { - THERMAL_API_GET_TEMPERATURE:"module{}_temp_input", - THERMAL_API_GET_HIGH_THRESHOLD:"module{}_temp_crit", - THERMAL_API_GET_HIGH_CRITICAL_THRESHOLD:"module{}_temp_emergency" + THERMAL_API_GET_TEMPERATURE: "module{}_temp_input", + THERMAL_API_GET_HIGH_THRESHOLD: "module{}_temp_crit", + THERMAL_API_GET_HIGH_CRITICAL_THRESHOLD: "module{}_temp_emergency" } thermal_api_handler_psu = { - THERMAL_API_GET_TEMPERATURE:"psu{}_temp", - THERMAL_API_GET_HIGH_THRESHOLD:"psu{}_temp_max", - THERMAL_API_GET_HIGH_CRITICAL_THRESHOLD:None + THERMAL_API_GET_TEMPERATURE: "psu{}_temp", + THERMAL_API_GET_HIGH_THRESHOLD: "psu{}_temp_max", + THERMAL_API_GET_HIGH_CRITICAL_THRESHOLD: None } thermal_api_handler_gearbox = { - THERMAL_API_GET_TEMPERATURE:"gearbox{}_temp_input", - THERMAL_API_GET_HIGH_THRESHOLD:None, - THERMAL_API_GET_HIGH_CRITICAL_THRESHOLD:None + THERMAL_API_GET_TEMPERATURE: "gearbox{}_temp_input", + THERMAL_API_GET_HIGH_THRESHOLD: None, + THERMAL_API_GET_HIGH_CRITICAL_THRESHOLD: None } thermal_ambient_apis = { - THERMAL_DEV_ASIC_AMBIENT : "asic", - THERMAL_DEV_PORT_AMBIENT : "port_amb", - THERMAL_DEV_FAN_AMBIENT : "fan_amb", - THERMAL_DEV_COMEX_AMBIENT : "comex_amb", - THERMAL_DEV_BOARD_AMBIENT : "board_amb" + THERMAL_DEV_ASIC_AMBIENT: "asic", + THERMAL_DEV_PORT_AMBIENT: "port_amb", + THERMAL_DEV_FAN_AMBIENT: "fan_amb", + THERMAL_DEV_COMEX_AMBIENT: "comex_amb", + THERMAL_DEV_BOARD_AMBIENT: "board_amb" } thermal_ambient_name = { - THERMAL_DEV_ASIC_AMBIENT : "Ambient ASIC Temp", - THERMAL_DEV_PORT_AMBIENT : "Ambient Port Side Temp", - THERMAL_DEV_FAN_AMBIENT : "Ambient Fan Side Temp", - THERMAL_DEV_COMEX_AMBIENT : "Ambient COMEX Temp", - THERMAL_DEV_BOARD_AMBIENT : "Ambient Board Temp" + THERMAL_DEV_ASIC_AMBIENT: "Ambient ASIC Temp", + THERMAL_DEV_PORT_AMBIENT: "Ambient Port Side Temp", + THERMAL_DEV_FAN_AMBIENT: "Ambient Fan Side Temp", + THERMAL_DEV_COMEX_AMBIENT: "Ambient COMEX Temp", + THERMAL_DEV_BOARD_AMBIENT: "Ambient Board Temp" } thermal_api_handlers = { - THERMAL_DEV_CATEGORY_CPU_CORE : thermal_api_handler_cpu_core, - THERMAL_DEV_CATEGORY_CPU_PACK : thermal_api_handler_cpu_pack, - THERMAL_DEV_CATEGORY_MODULE : thermal_api_handler_module, - THERMAL_DEV_CATEGORY_PSU : thermal_api_handler_psu, - THERMAL_DEV_CATEGORY_GEARBOX : thermal_api_handler_gearbox + THERMAL_DEV_CATEGORY_CPU_CORE: thermal_api_handler_cpu_core, + THERMAL_DEV_CATEGORY_CPU_PACK: thermal_api_handler_cpu_pack, + THERMAL_DEV_CATEGORY_MODULE: thermal_api_handler_module, + THERMAL_DEV_CATEGORY_PSU: thermal_api_handler_psu, + THERMAL_DEV_CATEGORY_GEARBOX: thermal_api_handler_gearbox } thermal_name = { - THERMAL_DEV_CATEGORY_CPU_CORE : "CPU Core {} Temp", - THERMAL_DEV_CATEGORY_CPU_PACK : "CPU Pack Temp", - THERMAL_DEV_CATEGORY_MODULE : "xSFP module {} Temp", - THERMAL_DEV_CATEGORY_PSU : "PSU-{} Temp", - THERMAL_DEV_CATEGORY_GEARBOX : "Gearbox {} Temp" + THERMAL_DEV_CATEGORY_CPU_CORE: "CPU Core {} Temp", + THERMAL_DEV_CATEGORY_CPU_PACK: "CPU Pack Temp", + THERMAL_DEV_CATEGORY_MODULE: "xSFP module {} Temp", + THERMAL_DEV_CATEGORY_PSU: "PSU-{} Temp", + THERMAL_DEV_CATEGORY_GEARBOX: "Gearbox {} Temp" } thermal_device_categories_all = [ @@ -113,130 +114,131 @@ def log_info(msg): THERMAL_API_GET_HIGH_THRESHOLD ] -hwsku_dict_thermal = {'ACS-MSN2700': 0, 'LS-SN2700':0, 'ACS-MSN2740': 3, 'ACS-MSN2100': 1, 'ACS-MSN2410': 2, 'ACS-MSN2010': 4, 'ACS-MSN3700': 5, 'ACS-MSN3700C': 6, 'Mellanox-SN2700': 0, 'Mellanox-SN2700-D48C8': 0, 'ACS-MSN3800': 7, 'Mellanox-SN3800-D112C8': 7} +hwsku_dict_thermal = {'ACS-MSN2700': 0, 'LS-SN2700': 0, 'ACS-MSN2740': 3, 'ACS-MSN2100': 1, 'ACS-MSN2410': 2, 'ACS-MSN2010': 4, + 'ACS-MSN3700': 5, 'ACS-MSN3700C': 6, 'Mellanox-SN2700': 0, 'Mellanox-SN2700-D48C8': 0, 'ACS-MSN3800': 7, 'Mellanox-SN3800-D112C8': 7} thermal_profile_list = [ # 2700 { - THERMAL_DEV_CATEGORY_CPU_CORE:(0, 2), - THERMAL_DEV_CATEGORY_MODULE:(1, 32), - THERMAL_DEV_CATEGORY_PSU:(1, 2), - THERMAL_DEV_CATEGORY_CPU_PACK:(0,1), - THERMAL_DEV_CATEGORY_GEARBOX:(0,0), - THERMAL_DEV_CATEGORY_AMBIENT:(0, - [ - THERMAL_DEV_ASIC_AMBIENT, - THERMAL_DEV_PORT_AMBIENT, - THERMAL_DEV_FAN_AMBIENT - ] - ) + THERMAL_DEV_CATEGORY_CPU_CORE: (0, 2), + THERMAL_DEV_CATEGORY_MODULE: (1, 32), + THERMAL_DEV_CATEGORY_PSU: (1, 2), + THERMAL_DEV_CATEGORY_CPU_PACK: (0, 1), + THERMAL_DEV_CATEGORY_GEARBOX: (0, 0), + THERMAL_DEV_CATEGORY_AMBIENT: (0, + [ + THERMAL_DEV_ASIC_AMBIENT, + THERMAL_DEV_PORT_AMBIENT, + THERMAL_DEV_FAN_AMBIENT + ] + ) }, # 2100 { - THERMAL_DEV_CATEGORY_CPU_CORE:(0, 4), - THERMAL_DEV_CATEGORY_MODULE:(1, 16), - THERMAL_DEV_CATEGORY_PSU:(0, 0), - THERMAL_DEV_CATEGORY_CPU_PACK:(0,0), - THERMAL_DEV_CATEGORY_GEARBOX:(0,0), - THERMAL_DEV_CATEGORY_AMBIENT:(0, - [ - THERMAL_DEV_ASIC_AMBIENT, - THERMAL_DEV_PORT_AMBIENT, - THERMAL_DEV_FAN_AMBIENT, - ] - ) + THERMAL_DEV_CATEGORY_CPU_CORE: (0, 4), + THERMAL_DEV_CATEGORY_MODULE: (1, 16), + THERMAL_DEV_CATEGORY_PSU: (0, 0), + THERMAL_DEV_CATEGORY_CPU_PACK: (0, 0), + THERMAL_DEV_CATEGORY_GEARBOX: (0, 0), + THERMAL_DEV_CATEGORY_AMBIENT: (0, + [ + THERMAL_DEV_ASIC_AMBIENT, + THERMAL_DEV_PORT_AMBIENT, + THERMAL_DEV_FAN_AMBIENT, + ] + ) }, # 2410 { - THERMAL_DEV_CATEGORY_CPU_CORE:(0, 2), - THERMAL_DEV_CATEGORY_MODULE:(1, 56), - THERMAL_DEV_CATEGORY_PSU:(1, 2), - THERMAL_DEV_CATEGORY_CPU_PACK:(0,1), - THERMAL_DEV_CATEGORY_GEARBOX:(0,0), - THERMAL_DEV_CATEGORY_AMBIENT:(0, - [ - THERMAL_DEV_ASIC_AMBIENT, - THERMAL_DEV_PORT_AMBIENT, - THERMAL_DEV_FAN_AMBIENT, - ] - ) + THERMAL_DEV_CATEGORY_CPU_CORE: (0, 2), + THERMAL_DEV_CATEGORY_MODULE: (1, 56), + THERMAL_DEV_CATEGORY_PSU: (1, 2), + THERMAL_DEV_CATEGORY_CPU_PACK: (0, 1), + THERMAL_DEV_CATEGORY_GEARBOX: (0, 0), + THERMAL_DEV_CATEGORY_AMBIENT: (0, + [ + THERMAL_DEV_ASIC_AMBIENT, + THERMAL_DEV_PORT_AMBIENT, + THERMAL_DEV_FAN_AMBIENT, + ] + ) }, # 2740 { - THERMAL_DEV_CATEGORY_CPU_CORE:(0, 4), - THERMAL_DEV_CATEGORY_MODULE:(1, 32), - THERMAL_DEV_CATEGORY_PSU:(1, 2), - THERMAL_DEV_CATEGORY_CPU_PACK:(0,0), - THERMAL_DEV_CATEGORY_GEARBOX:(0,0), - THERMAL_DEV_CATEGORY_AMBIENT:(0, - [ - THERMAL_DEV_ASIC_AMBIENT, - THERMAL_DEV_PORT_AMBIENT, - THERMAL_DEV_FAN_AMBIENT, - ] - ) + THERMAL_DEV_CATEGORY_CPU_CORE: (0, 4), + THERMAL_DEV_CATEGORY_MODULE: (1, 32), + THERMAL_DEV_CATEGORY_PSU: (1, 2), + THERMAL_DEV_CATEGORY_CPU_PACK: (0, 0), + THERMAL_DEV_CATEGORY_GEARBOX: (0, 0), + THERMAL_DEV_CATEGORY_AMBIENT: (0, + [ + THERMAL_DEV_ASIC_AMBIENT, + THERMAL_DEV_PORT_AMBIENT, + THERMAL_DEV_FAN_AMBIENT, + ] + ) }, # 2010 { - THERMAL_DEV_CATEGORY_CPU_CORE:(0, 4), - THERMAL_DEV_CATEGORY_MODULE:(1, 22), - THERMAL_DEV_CATEGORY_PSU:(0, 0), - THERMAL_DEV_CATEGORY_CPU_PACK:(0,0), - THERMAL_DEV_CATEGORY_GEARBOX:(0,0), - THERMAL_DEV_CATEGORY_AMBIENT:(0, - [ - THERMAL_DEV_ASIC_AMBIENT, - THERMAL_DEV_PORT_AMBIENT, - THERMAL_DEV_FAN_AMBIENT, - ] - ) + THERMAL_DEV_CATEGORY_CPU_CORE: (0, 4), + THERMAL_DEV_CATEGORY_MODULE: (1, 22), + THERMAL_DEV_CATEGORY_PSU: (0, 0), + THERMAL_DEV_CATEGORY_CPU_PACK: (0, 0), + THERMAL_DEV_CATEGORY_GEARBOX: (0, 0), + THERMAL_DEV_CATEGORY_AMBIENT: (0, + [ + THERMAL_DEV_ASIC_AMBIENT, + THERMAL_DEV_PORT_AMBIENT, + THERMAL_DEV_FAN_AMBIENT, + ] + ) }, # 3700 { - THERMAL_DEV_CATEGORY_CPU_CORE:(0, 4), - THERMAL_DEV_CATEGORY_MODULE:(1, 32), - THERMAL_DEV_CATEGORY_PSU:(1, 2), - THERMAL_DEV_CATEGORY_CPU_PACK:(0,1), - THERMAL_DEV_CATEGORY_GEARBOX:(0,0), - THERMAL_DEV_CATEGORY_AMBIENT:(0, - [ - THERMAL_DEV_ASIC_AMBIENT, - THERMAL_DEV_COMEX_AMBIENT, - THERMAL_DEV_PORT_AMBIENT, - THERMAL_DEV_FAN_AMBIENT - ] - ) + THERMAL_DEV_CATEGORY_CPU_CORE: (0, 4), + THERMAL_DEV_CATEGORY_MODULE: (1, 32), + THERMAL_DEV_CATEGORY_PSU: (1, 2), + THERMAL_DEV_CATEGORY_CPU_PACK: (0, 1), + THERMAL_DEV_CATEGORY_GEARBOX: (0, 0), + THERMAL_DEV_CATEGORY_AMBIENT: (0, + [ + THERMAL_DEV_ASIC_AMBIENT, + THERMAL_DEV_COMEX_AMBIENT, + THERMAL_DEV_PORT_AMBIENT, + THERMAL_DEV_FAN_AMBIENT + ] + ) }, # 3700c { - THERMAL_DEV_CATEGORY_CPU_CORE:(0, 2), - THERMAL_DEV_CATEGORY_MODULE:(1, 32), - THERMAL_DEV_CATEGORY_PSU:(1, 2), - THERMAL_DEV_CATEGORY_CPU_PACK:(0,1), - THERMAL_DEV_CATEGORY_GEARBOX:(0,0), - THERMAL_DEV_CATEGORY_AMBIENT:(0, - [ - THERMAL_DEV_ASIC_AMBIENT, - THERMAL_DEV_COMEX_AMBIENT, - THERMAL_DEV_PORT_AMBIENT, - THERMAL_DEV_FAN_AMBIENT - ] - ) + THERMAL_DEV_CATEGORY_CPU_CORE: (0, 2), + THERMAL_DEV_CATEGORY_MODULE: (1, 32), + THERMAL_DEV_CATEGORY_PSU: (1, 2), + THERMAL_DEV_CATEGORY_CPU_PACK: (0, 1), + THERMAL_DEV_CATEGORY_GEARBOX: (0, 0), + THERMAL_DEV_CATEGORY_AMBIENT: (0, + [ + THERMAL_DEV_ASIC_AMBIENT, + THERMAL_DEV_COMEX_AMBIENT, + THERMAL_DEV_PORT_AMBIENT, + THERMAL_DEV_FAN_AMBIENT + ] + ) }, # 3800 { - THERMAL_DEV_CATEGORY_CPU_CORE:(0, 4), - THERMAL_DEV_CATEGORY_MODULE:(1, 64), - THERMAL_DEV_CATEGORY_PSU:(1, 2), - THERMAL_DEV_CATEGORY_CPU_PACK:(0,1), - THERMAL_DEV_CATEGORY_GEARBOX:(1,32), - THERMAL_DEV_CATEGORY_AMBIENT:(0, - [ - THERMAL_DEV_ASIC_AMBIENT, - THERMAL_DEV_COMEX_AMBIENT, - THERMAL_DEV_PORT_AMBIENT, - THERMAL_DEV_FAN_AMBIENT - ] - ) + THERMAL_DEV_CATEGORY_CPU_CORE: (0, 4), + THERMAL_DEV_CATEGORY_MODULE: (1, 64), + THERMAL_DEV_CATEGORY_PSU: (1, 2), + THERMAL_DEV_CATEGORY_CPU_PACK: (0, 1), + THERMAL_DEV_CATEGORY_GEARBOX: (1, 32), + THERMAL_DEV_CATEGORY_AMBIENT: (0, + [ + THERMAL_DEV_ASIC_AMBIENT, + THERMAL_DEV_COMEX_AMBIENT, + THERMAL_DEV_PORT_AMBIENT, + THERMAL_DEV_FAN_AMBIENT + ] + ) }, ] diff --git a/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/plugins/eeprom.py b/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/plugins/eeprom.py index 51caf72ac6d0..96dc19ad5b36 100644 --- a/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/plugins/eeprom.py +++ b/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/plugins/eeprom.py @@ -9,13 +9,15 @@ from sonic_eeprom import eeprom_tlvinfo import subprocess except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/2-0050/eeprom" - #Two i2c buses might get flipped order, check them both. + # Two i2c buses might get flipped order, check them both. if not os.path.exists(self.eeprom_path): self.eeprom_path = "/sys/bus/i2c/devices/2-0050/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/plugins/sfputil.py b/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/plugins/sfputil.py index db85cd0d595b..97c04f6d0d43 100644 --- a/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/plugins/sfputil.py +++ b/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/plugins/sfputil.py @@ -51,11 +51,12 @@ def get_presence(self, port_num): return False if port_num > 16: - cpld_addr=33 + cpld_addr = 33 else: - cpld_addr=32 + cpld_addr = 32 - file_path="/sys/bus/i2c/devices/1-00" + str(cpld_addr) + "/port" + str(port_num) + "/port" + str(port_num) + "_present" + file_path = "/sys/bus/i2c/devices/1-00" + \ + str(cpld_addr) + "/port" + str(port_num) + "/port" + str(port_num) + "_present" try: reg_file = open("file_path") @@ -68,7 +69,6 @@ def get_presence(self, port_num): # content is a string containing the hex representation of the register reg_value = int(content, 16) - # ModPrsL is active low if reg_value == 0: return True @@ -81,12 +81,12 @@ def get_low_power_mode(self, port_num): return False if port_num > 16: - cpld_addr=33 + cpld_addr = 33 else: - cpld_addr=32 - + cpld_addr = 32 - file_path="/sys/bus/i2c/devices/1-00" + str(cpld_addr) + "/port" + str(port_num) + "/port" + str(port_num) + "_lpmode" + file_path = "/sys/bus/i2c/devices/1-00" + \ + str(cpld_addr) + "/port" + str(port_num) + "/port" + str(port_num) + "_lpmode" try: reg_file = open(file_path) @@ -110,11 +110,12 @@ def set_low_power_mode(self, port_num, lpmode): return False if port_num > 16: - cpld_addr=33 + cpld_addr = 33 else: - cpld_addr=32 + cpld_addr = 32 - file_path="/sys/bus/i2c/devices/1-00" + str(cpld_num) + "/port" + str(port_num) + "/port" + str(port_num) + "_lpmode" + file_path = "/sys/bus/i2c/devices/1-00" + \ + str(cpld_num) + "/port" + str(port_num) + "/port" + str(port_num) + "_lpmode" try: reg_file = open(file_path, "r+") @@ -144,11 +145,12 @@ def reset(self, port_num): return False if port_num > 16: - cpld_addr=33 + cpld_addr = 33 else: - cpld_addr=32 + cpld_addr = 32 - file_path="/sys/bus/i2c/devices/1-00" + str(cpld_num) + "/port" + str(port_num) + "/port" + str(port_num) + "_rst" + file_path = "/sys/bus/i2c/devices/1-00" + \ + str(cpld_num) + "/port" + str(port_num) + "/port" + str(port_num) + "_rst" try: reg_file = open(file_path, "r+") diff --git a/device/nokia/armhf-nokia_ixs7215_52x-r0/plugins/eeprom.py b/device/nokia/armhf-nokia_ixs7215_52x-r0/plugins/eeprom.py index be538d1c0e89..cbd48237cc10 100644 --- a/device/nokia/armhf-nokia_ixs7215_52x-r0/plugins/eeprom.py +++ b/device/nokia/armhf-nokia_ixs7215_52x-r0/plugins/eeprom.py @@ -10,5 +10,5 @@ class board(eeprom_tlvinfo.TlvInfoDecoder): def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/class/i2c-adapter/i2c-0/0-0053/eeprom" if not os.path.exists(self.eeprom_path): - os.system("echo 24c02 0x53 > /sys/class/i2c-adapter/i2c-0/new_device") + os.system("echo 24c02 0x53 > /sys/class/i2c-adapter/i2c-0/new_device") super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/pegatron/x86_64-pegatron_porsche-r0/plugins/eeprom.py b/device/pegatron/x86_64-pegatron_porsche-r0/plugins/eeprom.py index 68dbc88ce842..5c2a90e81c2f 100755 --- a/device/pegatron/x86_64-pegatron_porsche-r0/plugins/eeprom.py +++ b/device/pegatron/x86_64-pegatron_porsche-r0/plugins/eeprom.py @@ -9,10 +9,12 @@ from sonic_eeprom import eeprom_tlvinfo import subprocess except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/4-0054/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/pegatron/x86_64-pegatron_porsche-r0/plugins/psuutil.py b/device/pegatron/x86_64-pegatron_porsche-r0/plugins/psuutil.py index a23a7b7fe73e..ce859cb70c77 100755 --- a/device/pegatron/x86_64-pegatron_porsche-r0/plugins/psuutil.py +++ b/device/pegatron/x86_64-pegatron_porsche-r0/plugins/psuutil.py @@ -19,12 +19,12 @@ class PsuUtil(PsuBase): def __init__(self): PsuBase.__init__(self) - - + # Get sysfs attribute + def get_attr_value(self, attr_path): - - retval = 'ERR' + + retval = 'ERR' if (not os.path.isfile(attr_path)): return retval @@ -56,16 +56,16 @@ def get_psu_status(self, index): faulty """ status = 0 - attr_file = 'psu_'+str(index)+'_status' - attr_path = self.SYSFS_PSU_DIR +'/' + attr_file - + attr_file = 'psu_'+str(index)+'_status' + attr_path = self.SYSFS_PSU_DIR + '/' + attr_file + attr_value = self.get_attr_value(attr_path) - + if (attr_value != 'ERR'): attr_value = int(attr_value, 16) # Check for PSU status if (attr_value == 1): - status = 1 + status = 1 return status @@ -78,15 +78,14 @@ def get_psu_presence(self, index): """ status = 0 attr_file = 'psu_'+str(index)+'_present' - attr_path = self.SYSFS_PSU_DIR +'/' + attr_file - + attr_path = self.SYSFS_PSU_DIR + '/' + attr_file + attr_value = self.get_attr_value(attr_path) if (attr_value != 'ERR'): attr_value = int(attr_value, 16) # Check for PSU presence if (attr_value == 0): - status = 1 + status = 1 return status - diff --git a/device/pegatron/x86_64-pegatron_porsche-r0/plugins/sfputil.py b/device/pegatron/x86_64-pegatron_porsche-r0/plugins/sfputil.py index e28480604265..3a757333cd2f 100755 --- a/device/pegatron/x86_64-pegatron_porsche-r0/plugins/sfputil.py +++ b/device/pegatron/x86_64-pegatron_porsche-r0/plugins/sfputil.py @@ -4,7 +4,7 @@ import time from sonic_sfp.sfputilbase import SfpUtilBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class SfpUtil(SfpUtilBase): @@ -22,15 +22,14 @@ class SfpUtil(SfpUtilBase): sfp_ports = list(range(0, ports_in_block)) qsfp_ports = list(range(ports_in_block - 6, ports_in_block)) - def __init__(self): for x in range(self.port_start, self.port_end + 1): if x < self.cpldb_sfp_num: - self.port_to_i2c_mapping.update({x:7}) + self.port_to_i2c_mapping.update({x: 7}) elif x < self.cplda_sfp_num + self.cpldb_sfp_num: - self.port_to_i2c_mapping.update({x:6}) + self.port_to_i2c_mapping.update({x: 6}) else: - self.port_to_i2c_mapping.update({x:8}) + self.port_to_i2c_mapping.update({x: 8}) for x in range(self.port_start, self.port_end+1): eeprom_path = '/sys/bus/i2c/devices/{0}-0050/sfp'+str(x+1)+'_eeprom' @@ -38,7 +37,6 @@ def __init__(self): self.port_to_eeprom_mapping[x] = port_eeprom_path SfpUtilBase.__init__(self) - def get_presence(self, port_num): if port_num < self.port_start or port_num > self.port_end: return False @@ -231,6 +229,3 @@ def read_porttab_mappings(self, porttabfile): print "logical to physical: " + self.logical_to_physical print "physical to logical: " + self.physical_to_logical """ - - - diff --git a/device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/eeprom.py b/device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/eeprom.py index 2f0b219a73bb..ddefcf8877fb 100755 --- a/device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/eeprom.py +++ b/device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/eeprom.py @@ -9,10 +9,12 @@ from sonic_eeprom import eeprom_tlvinfo import subprocess except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/22-0054/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/psuutil.py b/device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/psuutil.py index 1986aa846c5e..e78148e30f40 100755 --- a/device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/psuutil.py +++ b/device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/psuutil.py @@ -15,64 +15,73 @@ DEBUG = False + def show_log(txt): if DEBUG == True: print("[IX2]"+txt) return + def exec_cmd(cmd, show): logging.info('Run :'+cmd) try: output = subprocess.check_output(cmd, shell=True) - show_log (cmd +"output:"+str(output)) + show_log(cmd + "output:"+str(output)) except subprocess.CalledProcessError as e: logging.info("Failed :"+cmd) if show: - print("Failed :"+cmd +"returncode = {}, err msg: {}".format(e.returncode, e.output)) - return output + print("Failed :"+cmd + "returncode = {}, err msg: {}".format(e.returncode, e.output)) + return output + def my_log(txt): if DEBUG == True: print("[QUANTA DBG]: "+txt) return + def log_os_system(cmd, show): logging.info('Run :'+cmd) status = 1 output = "" try: output = subprocess.check_output(cmd, shell=True) - my_log (cmd +"output:"+str(output)) + my_log(cmd + "output:"+str(output)) except subprocess.CalledProcessError as e: logging.info('Failed :'+cmd) if show: - print("Failed :"+cmd +"returncode = {}, err msg: {}".format(e.returncode, e.output)) - return output + print("Failed :"+cmd + "returncode = {}, err msg: {}".format(e.returncode, e.output)) + return output + def gpio16_exist(): ls = log_os_system("ls /sys/class/gpio/ | grep gpio16", 0) logging.info('mods:'+ls) - if len(ls) ==0: + if len(ls) == 0: return False + def gpio17_exist(): ls = log_os_system("ls /sys/class/gpio/ | grep gpio17", 0) logging.info('mods:'+ls) - if len(ls) ==0: + if len(ls) == 0: return False + def gpio19_exist(): ls = log_os_system("ls /sys/class/gpio/ | grep gpio19", 0) logging.info('mods:'+ls) - if len(ls) ==0: + if len(ls) == 0: return False + def gpio20_exist(): ls = log_os_system("ls /sys/class/gpio/ | grep gpio20", 0) logging.info('mods:'+ls) - if len(ls) ==0: + if len(ls) == 0: return False + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" @@ -81,6 +90,7 @@ class PsuUtil(PsuBase): SYSFS_PSU_POWERGOOD_DIR = ["/sys/class/gpio/gpio17", "/sys/class/gpio/gpio20"] + def __init__(self): PsuBase.__init__(self) @@ -134,7 +144,7 @@ def get_psu_status(self, index): """ status = 0 attr_file = 'value' - attr_path = self.SYSFS_PSU_POWERGOOD_DIR[index-1] +'/' + attr_file + attr_path = self.SYSFS_PSU_POWERGOOD_DIR[index-1] + '/' + attr_file attr_value = self.get_attr_value(attr_path) @@ -142,7 +152,7 @@ def get_psu_status(self, index): attr_value = int(attr_value, 16) # Check for PSU status if (attr_value == 1): - status = 1 + status = 1 return status @@ -155,8 +165,8 @@ def get_psu_presence(self, index): """ status = 0 psu_absent = 0 - attr_file ='value' - attr_path = self.SYSFS_PSU_PRESENT_DIR[index-1] +'/' + attr_file + attr_file = 'value' + attr_path = self.SYSFS_PSU_PRESENT_DIR[index-1] + '/' + attr_file attr_value = self.get_attr_value(attr_path) @@ -164,7 +174,6 @@ def get_psu_presence(self, index): attr_value = int(attr_value, 16) # Check for PSU presence if (attr_value == 0): - status = 1 + status = 1 return status - diff --git a/device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/sfputil.py b/device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/sfputil.py index 2bb471970919..cbaf8b71832f 100755 --- a/device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/sfputil.py +++ b/device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/sfputil.py @@ -2,7 +2,7 @@ import time from sonic_sfp.sfputilbase import SfpUtilBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class SfpUtil(SfpUtilBase): @@ -14,38 +14,38 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} port_to_i2c_mapping = { - 1 : 32, - 2 : 33, - 3 : 34, - 4 : 35, - 5 : 36, - 6 : 37, - 7 : 38, - 8 : 39, - 9 : 40, - 10 : 41, - 11 : 42, - 12 : 43, - 13 : 44, - 14 : 45, - 15 : 46, - 16 : 47, - 17 : 48, - 18 : 49, - 19 : 50, - 20 : 51, - 21 : 52, - 22 : 53, - 23 : 54, - 24 : 55, - 25 : 56, - 26 : 57, - 27 : 58, - 28 : 59, - 29 : 60, - 30 : 61, - 31 : 62, - 32 : 63, + 1: 32, + 2: 33, + 3: 34, + 4: 35, + 5: 36, + 6: 37, + 7: 38, + 8: 39, + 9: 40, + 10: 41, + 11: 42, + 12: 43, + 13: 44, + 14: 45, + 15: 46, + 16: 47, + 17: 48, + 18: 49, + 19: 50, + 20: 51, + 21: 52, + 22: 53, + 23: 54, + 24: 55, + 25: 56, + 26: 57, + 27: 58, + 28: 59, + 29: 60, + 30: 61, + 31: 62, + 32: 63, } _qsfp_ports = list(range(0, ports_in_block + 1)) @@ -89,7 +89,7 @@ def reset(self, port_num): return True def set_low_power_mode(self, port_num, lpmode): - # Check for invalid port_num + # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False @@ -113,7 +113,7 @@ def set_low_power_mode(self, port_num, lpmode): return True def get_low_power_mode(self, port_num): - # Check for invalid port_num + # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False @@ -164,7 +164,7 @@ def qsfp_ports(self): @property def port_to_eeprom_mapping(self): - return self._port_to_eeprom_mapping + return self._port_to_eeprom_mapping def get_transceiver_change_event(self): """ @@ -173,5 +173,3 @@ def get_transceiver_change_event(self): on this platform. """ raise NotImplementedError - - diff --git a/device/quanta/x86_64-quanta_ix7_rglbmc-r0/plugins/eeprom.py b/device/quanta/x86_64-quanta_ix7_rglbmc-r0/plugins/eeprom.py index d65115b0b6e5..fa34110c04ea 100644 --- a/device/quanta/x86_64-quanta_ix7_rglbmc-r0/plugins/eeprom.py +++ b/device/quanta/x86_64-quanta_ix7_rglbmc-r0/plugins/eeprom.py @@ -9,10 +9,12 @@ from sonic_eeprom import eeprom_tlvinfo import subprocess except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/18-0054/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/quanta/x86_64-quanta_ix7_rglbmc-r0/plugins/psuutil.py b/device/quanta/x86_64-quanta_ix7_rglbmc-r0/plugins/psuutil.py index 885842bbda5a..5cf06fb5d66a 100644 --- a/device/quanta/x86_64-quanta_ix7_rglbmc-r0/plugins/psuutil.py +++ b/device/quanta/x86_64-quanta_ix7_rglbmc-r0/plugins/psuutil.py @@ -8,7 +8,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/quanta/x86_64-quanta_ix7_rglbmc-r0/plugins/sfputil.py b/device/quanta/x86_64-quanta_ix7_rglbmc-r0/plugins/sfputil.py index 8fed7617c942..14b0ef6674be 100644 --- a/device/quanta/x86_64-quanta_ix7_rglbmc-r0/plugins/sfputil.py +++ b/device/quanta/x86_64-quanta_ix7_rglbmc-r0/plugins/sfputil.py @@ -21,38 +21,38 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _port_to_i2c_mapping = { - 1 : 32, - 2 : 33, - 3 : 34, - 4 : 35, - 5 : 36, - 6 : 37, - 7 : 38, - 8 : 39, - 9 : 40, - 10 : 41, - 11 : 42, - 12 : 43, - 13 : 44, - 14 : 45, - 15 : 46, - 16 : 47, - 17 : 48, - 18 : 49, - 19 : 50, - 20 : 51, - 21 : 52, - 22 : 53, - 23 : 54, - 24 : 55, - 25 : 56, - 26 : 57, - 27 : 58, - 28 : 59, - 29 : 60, - 30 : 61, - 31 : 62, - 32 : 63, + 1: 32, + 2: 33, + 3: 34, + 4: 35, + 5: 36, + 6: 37, + 7: 38, + 8: 39, + 9: 40, + 10: 41, + 11: 42, + 12: 43, + 13: 44, + 14: 45, + 15: 46, + 16: 47, + 17: 48, + 18: 49, + 19: 50, + 20: 51, + 21: 52, + 22: 53, + 23: 54, + 24: 55, + 25: 56, + 26: 57, + 27: 58, + 28: 59, + 29: 60, + 30: 61, + 31: 62, + 32: 63, } @property @@ -69,7 +69,7 @@ def qsfp_ports(self): @property def port_to_eeprom_mapping(self): - return self._port_to_eeprom_mapping + return self._port_to_eeprom_mapping def __init__(self): eeprom_path = '/sys/bus/i2c/devices/{0}-0050/eeprom' diff --git a/device/quanta/x86_64-quanta_ix8_rglbmc-r0/plugins/eeprom.py b/device/quanta/x86_64-quanta_ix8_rglbmc-r0/plugins/eeprom.py index d65115b0b6e5..fa34110c04ea 100644 --- a/device/quanta/x86_64-quanta_ix8_rglbmc-r0/plugins/eeprom.py +++ b/device/quanta/x86_64-quanta_ix8_rglbmc-r0/plugins/eeprom.py @@ -9,10 +9,12 @@ from sonic_eeprom import eeprom_tlvinfo import subprocess except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/18-0054/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/quanta/x86_64-quanta_ix8_rglbmc-r0/plugins/psuutil.py b/device/quanta/x86_64-quanta_ix8_rglbmc-r0/plugins/psuutil.py index 885842bbda5a..5cf06fb5d66a 100644 --- a/device/quanta/x86_64-quanta_ix8_rglbmc-r0/plugins/psuutil.py +++ b/device/quanta/x86_64-quanta_ix8_rglbmc-r0/plugins/psuutil.py @@ -8,7 +8,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/quanta/x86_64-quanta_ix8_rglbmc-r0/plugins/sfputil.py b/device/quanta/x86_64-quanta_ix8_rglbmc-r0/plugins/sfputil.py index ab84d5994a22..3067919795d5 100644 --- a/device/quanta/x86_64-quanta_ix8_rglbmc-r0/plugins/sfputil.py +++ b/device/quanta/x86_64-quanta_ix8_rglbmc-r0/plugins/sfputil.py @@ -23,62 +23,62 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _port_to_i2c_mapping = { - 1 : 32, - 2 : 33, - 3 : 34, - 4 : 35, - 5 : 36, - 6 : 37, - 7 : 38, - 8 : 39, - 9 : 40, - 10 : 41, - 11 : 42, - 12 : 43, - 13 : 44, - 14 : 45, - 15 : 46, - 16 : 47, - 17 : 48, - 18 : 49, - 19 : 50, - 20 : 51, - 21 : 52, - 22 : 53, - 23 : 54, - 24 : 55, - 25 : 56, - 26 : 57, - 27 : 58, - 28 : 59, - 29 : 60, - 30 : 61, - 31 : 62, - 32 : 63, - 33 : 64, - 34 : 65, - 35 : 66, - 36 : 67, - 37 : 68, - 38 : 69, - 39 : 70, - 40 : 71, - 41 : 72, - 42 : 73, - 43 : 74, - 44 : 75, - 45 : 76, - 46 : 77, - 47 : 78, - 48 : 79, - 49 : 80,#QSFP49 - 50 : 81,#QSFP50 - 51 : 82,#QSFP51 - 52 : 83,#QSFP52 - 53 : 84,#QSFP53 - 54 : 85,#QSFP54 - 55 : 86,#QSFP55 - 56 : 87,#QSFP56 + 1: 32, + 2: 33, + 3: 34, + 4: 35, + 5: 36, + 6: 37, + 7: 38, + 8: 39, + 9: 40, + 10: 41, + 11: 42, + 12: 43, + 13: 44, + 14: 45, + 15: 46, + 16: 47, + 17: 48, + 18: 49, + 19: 50, + 20: 51, + 21: 52, + 22: 53, + 23: 54, + 24: 55, + 25: 56, + 26: 57, + 27: 58, + 28: 59, + 29: 60, + 30: 61, + 31: 62, + 32: 63, + 33: 64, + 34: 65, + 35: 66, + 36: 67, + 37: 68, + 38: 69, + 39: 70, + 40: 71, + 41: 72, + 42: 73, + 43: 74, + 44: 75, + 45: 76, + 46: 77, + 47: 78, + 48: 79, + 49: 80, # QSFP49 + 50: 81, # QSFP50 + 51: 82, # QSFP51 + 52: 83, # QSFP52 + 53: 84, # QSFP53 + 54: 85, # QSFP54 + 55: 86, # QSFP55 + 56: 87, # QSFP56 } @property @@ -103,7 +103,7 @@ def qsfp_ports(self): @property def port_to_eeprom_mapping(self): - return self._port_to_eeprom_mapping + return self._port_to_eeprom_mapping def __init__(self): eeprom_path = '/sys/bus/i2c/devices/{0}-0050/eeprom' diff --git a/device/quanta/x86_64-quanta_ix8c_bwde-r0/plugins/eeprom.py b/device/quanta/x86_64-quanta_ix8c_bwde-r0/plugins/eeprom.py index d65115b0b6e5..fa34110c04ea 100644 --- a/device/quanta/x86_64-quanta_ix8c_bwde-r0/plugins/eeprom.py +++ b/device/quanta/x86_64-quanta_ix8c_bwde-r0/plugins/eeprom.py @@ -9,10 +9,12 @@ from sonic_eeprom import eeprom_tlvinfo import subprocess except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/18-0054/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/quanta/x86_64-quanta_ix8c_bwde-r0/plugins/psuutil.py b/device/quanta/x86_64-quanta_ix8c_bwde-r0/plugins/psuutil.py index cc9be248aa1b..319c35d490e4 100644 --- a/device/quanta/x86_64-quanta_ix8c_bwde-r0/plugins/psuutil.py +++ b/device/quanta/x86_64-quanta_ix8c_bwde-r0/plugins/psuutil.py @@ -8,7 +8,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/quanta/x86_64-quanta_ix8c_bwde-r0/plugins/sfputil.py b/device/quanta/x86_64-quanta_ix8c_bwde-r0/plugins/sfputil.py index ab84d5994a22..3067919795d5 100644 --- a/device/quanta/x86_64-quanta_ix8c_bwde-r0/plugins/sfputil.py +++ b/device/quanta/x86_64-quanta_ix8c_bwde-r0/plugins/sfputil.py @@ -23,62 +23,62 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} _port_to_i2c_mapping = { - 1 : 32, - 2 : 33, - 3 : 34, - 4 : 35, - 5 : 36, - 6 : 37, - 7 : 38, - 8 : 39, - 9 : 40, - 10 : 41, - 11 : 42, - 12 : 43, - 13 : 44, - 14 : 45, - 15 : 46, - 16 : 47, - 17 : 48, - 18 : 49, - 19 : 50, - 20 : 51, - 21 : 52, - 22 : 53, - 23 : 54, - 24 : 55, - 25 : 56, - 26 : 57, - 27 : 58, - 28 : 59, - 29 : 60, - 30 : 61, - 31 : 62, - 32 : 63, - 33 : 64, - 34 : 65, - 35 : 66, - 36 : 67, - 37 : 68, - 38 : 69, - 39 : 70, - 40 : 71, - 41 : 72, - 42 : 73, - 43 : 74, - 44 : 75, - 45 : 76, - 46 : 77, - 47 : 78, - 48 : 79, - 49 : 80,#QSFP49 - 50 : 81,#QSFP50 - 51 : 82,#QSFP51 - 52 : 83,#QSFP52 - 53 : 84,#QSFP53 - 54 : 85,#QSFP54 - 55 : 86,#QSFP55 - 56 : 87,#QSFP56 + 1: 32, + 2: 33, + 3: 34, + 4: 35, + 5: 36, + 6: 37, + 7: 38, + 8: 39, + 9: 40, + 10: 41, + 11: 42, + 12: 43, + 13: 44, + 14: 45, + 15: 46, + 16: 47, + 17: 48, + 18: 49, + 19: 50, + 20: 51, + 21: 52, + 22: 53, + 23: 54, + 24: 55, + 25: 56, + 26: 57, + 27: 58, + 28: 59, + 29: 60, + 30: 61, + 31: 62, + 32: 63, + 33: 64, + 34: 65, + 35: 66, + 36: 67, + 37: 68, + 38: 69, + 39: 70, + 40: 71, + 41: 72, + 42: 73, + 43: 74, + 44: 75, + 45: 76, + 46: 77, + 47: 78, + 48: 79, + 49: 80, # QSFP49 + 50: 81, # QSFP50 + 51: 82, # QSFP51 + 52: 83, # QSFP52 + 53: 84, # QSFP53 + 54: 85, # QSFP54 + 55: 86, # QSFP55 + 56: 87, # QSFP56 } @property @@ -103,7 +103,7 @@ def qsfp_ports(self): @property def port_to_eeprom_mapping(self): - return self._port_to_eeprom_mapping + return self._port_to_eeprom_mapping def __init__(self): eeprom_path = '/sys/bus/i2c/devices/{0}-0050/eeprom' diff --git a/device/quanta/x86_64-quanta_ix9_bwde-r0/plugins/eeprom.py b/device/quanta/x86_64-quanta_ix9_bwde-r0/plugins/eeprom.py index d65115b0b6e5..fa34110c04ea 100644 --- a/device/quanta/x86_64-quanta_ix9_bwde-r0/plugins/eeprom.py +++ b/device/quanta/x86_64-quanta_ix9_bwde-r0/plugins/eeprom.py @@ -9,10 +9,12 @@ from sonic_eeprom import eeprom_tlvinfo import subprocess except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/bus/i2c/devices/18-0054/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/quanta/x86_64-quanta_ix9_bwde-r0/plugins/psuutil.py b/device/quanta/x86_64-quanta_ix9_bwde-r0/plugins/psuutil.py index 885842bbda5a..5cf06fb5d66a 100644 --- a/device/quanta/x86_64-quanta_ix9_bwde-r0/plugins/psuutil.py +++ b/device/quanta/x86_64-quanta_ix9_bwde-r0/plugins/psuutil.py @@ -8,7 +8,8 @@ try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" diff --git a/device/quanta/x86_64-quanta_ix9_bwde-r0/plugins/sfputil.py b/device/quanta/x86_64-quanta_ix9_bwde-r0/plugins/sfputil.py index 2d591d300f50..832dac4e0570 100644 --- a/device/quanta/x86_64-quanta_ix9_bwde-r0/plugins/sfputil.py +++ b/device/quanta/x86_64-quanta_ix9_bwde-r0/plugins/sfputil.py @@ -2,7 +2,7 @@ import time from sonic_sfp.sfputilbase import SfpUtilBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class SfpUtil(SfpUtilBase): @@ -14,38 +14,38 @@ class SfpUtil(SfpUtilBase): _port_to_eeprom_mapping = {} port_to_i2c_mapping = { - 1 : 32, - 2 : 33, - 3 : 34, - 4 : 35, - 5 : 36, - 6 : 37, - 7 : 38, - 8 : 39, - 9 : 40, - 10 : 41, - 11 : 42, - 12 : 43, - 13 : 44, - 14 : 45, - 15 : 46, - 16 : 47, - 17 : 48, - 18 : 49, - 19 : 50, - 20 : 51, - 21 : 52, - 22 : 53, - 23 : 54, - 24 : 55, - 25 : 56, - 26 : 57, - 27 : 58, - 28 : 59, - 29 : 60, - 30 : 61, - 31 : 62, - 32 : 63, + 1: 32, + 2: 33, + 3: 34, + 4: 35, + 5: 36, + 6: 37, + 7: 38, + 8: 39, + 9: 40, + 10: 41, + 11: 42, + 12: 43, + 13: 44, + 14: 45, + 15: 46, + 16: 47, + 17: 48, + 18: 49, + 19: 50, + 20: 51, + 21: 52, + 22: 53, + 23: 54, + 24: 55, + 25: 56, + 26: 57, + 27: 58, + 28: 59, + 29: 60, + 30: 61, + 31: 62, + 32: 63, } _qsfp_ports = list(range(0, ports_in_block + 1)) @@ -89,7 +89,7 @@ def reset(self, port_num): return True def set_low_power_mode(self, port_num, lpmode): - # Check for invalid port_num + # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False @@ -113,7 +113,7 @@ def set_low_power_mode(self, port_num, lpmode): return True def get_low_power_mode(self, port_num): - # Check for invalid port_num + # Check for invalid port_num if port_num < self.port_start or port_num > self.port_end: return False @@ -161,7 +161,7 @@ def qsfp_ports(self): @property def port_to_eeprom_mapping(self): - return self._port_to_eeprom_mapping + return self._port_to_eeprom_mapping def get_transceiver_change_event(self): """ @@ -170,5 +170,3 @@ def get_transceiver_change_event(self): on this platform. """ raise NotImplementedError - - diff --git a/device/virtual/x86_64-kvm_x86_64-r0/plugins/eeprom.py b/device/virtual/x86_64-kvm_x86_64-r0/plugins/eeprom.py index 9e5324acced1..163c31ba20fc 100644 --- a/device/virtual/x86_64-kvm_x86_64-r0/plugins/eeprom.py +++ b/device/virtual/x86_64-kvm_x86_64-r0/plugins/eeprom.py @@ -16,7 +16,7 @@ def is_checksum_valid(self, e): def read_eeprom(self): return \ -""" + """ TLV Name Code Len Value -------------------- ---- --- ----- Product Name 0x21 5 SONiC diff --git a/device/wnc/x86_64-wnc_osw1800-r0/plugins/eeprom.py b/device/wnc/x86_64-wnc_osw1800-r0/plugins/eeprom.py index 7cb133ba5123..7c36371812ae 100644 --- a/device/wnc/x86_64-wnc_osw1800-r0/plugins/eeprom.py +++ b/device/wnc/x86_64-wnc_osw1800-r0/plugins/eeprom.py @@ -8,7 +8,7 @@ from sonic_eeprom import eeprom_base from sonic_eeprom import eeprom_tlvinfo except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") class board(eeprom_tlvinfo.TlvInfoDecoder): @@ -16,4 +16,3 @@ class board(eeprom_tlvinfo.TlvInfoDecoder): def __init__(self, name, path, cpld_root, ro): self.eeprom_path = "/sys/class/i2c-adapter/i2c-8/8-0052/eeprom" super(board, self).__init__(self.eeprom_path, 0, '', True) - From 9529029f4d671e43ba2f963622c187b47eb7614b Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Tue, 24 Nov 2020 02:03:06 +0000 Subject: [PATCH 22/24] Fix comment placement --- device/accton/x86_64-accton_as7312_54x-r0/plugins/sfputil.py | 3 ++- device/accton/x86_64-accton_as7312_54xs-r0/plugins/sfputil.py | 3 ++- device/accton/x86_64-accton_as7315_27xb-r0/plugins/sfputil.py | 3 ++- device/accton/x86_64-accton_as7326_56x-r0/plugins/sfputil.py | 3 ++- device/accton/x86_64-accton_as7512_32x-r0/plugins/sfputil.py | 3 ++- device/accton/x86_64-accton_as7712_32x-r0/plugins/sfputil.py | 3 ++- device/accton/x86_64-accton_as7716_32x-r0/plugins/sfputil.py | 3 ++- device/accton/x86_64-accton_as7726_32x-r0/plugins/sfputil.py | 3 ++- device/accton/x86_64-accton_as7816_64x-r0/plugins/sfputil.py | 3 ++- device/accton/x86_64-accton_as9716_32d-r0/plugins/sfputil.py | 3 ++- device/common/pddf/plugins/sfputil.py | 3 ++- device/juniper/x86_64-juniper_qfx5210-r0/plugins/sfputil.py | 3 ++- 12 files changed, 24 insertions(+), 12 deletions(-) diff --git a/device/accton/x86_64-accton_as7312_54x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7312_54x-r0/plugins/sfputil.py index 8f0818305f7f..7255b2d784e1 100644 --- a/device/accton/x86_64-accton_as7312_54x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7312_54x-r0/plugins/sfputil.py @@ -174,9 +174,10 @@ def get_low_power_mode(self, port_num): if ((lpmode & 0x3) == 0x3): return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 else: - return False # High Power Mode if one of the following conditions is matched: + # 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 + return False except IOError as e: print("Error: unable to open file: %s" % str(e)) return False diff --git a/device/accton/x86_64-accton_as7312_54xs-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7312_54xs-r0/plugins/sfputil.py index 2cc51982fdc9..7d700fdaf90e 100644 --- a/device/accton/x86_64-accton_as7312_54xs-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7312_54xs-r0/plugins/sfputil.py @@ -175,9 +175,10 @@ def get_low_power_mode(self, port_num): if ((lpmode & 0x3) == 0x3): return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 else: - return False # High Power Mode if one of the following conditions is matched: + # 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 + return False except IOError as e: print("Error: unable to open file: %s" % str(e)) return False diff --git a/device/accton/x86_64-accton_as7315_27xb-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7315_27xb-r0/plugins/sfputil.py index 983acfaea83b..1a1b61d1e659 100644 --- a/device/accton/x86_64-accton_as7315_27xb-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7315_27xb-r0/plugins/sfputil.py @@ -147,9 +147,10 @@ def get_low_power_mode(self, port_num): if ((lpmode & 0x3) == 0x3): return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 else: - return False # High Power Mode if one of the following conditions is matched: + # 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 + return False except IOError as e: print("Error: unable to open file: %s" % str(e)) return False diff --git a/device/accton/x86_64-accton_as7326_56x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7326_56x-r0/plugins/sfputil.py index 4777bb0cda2f..965e876691c8 100644 --- a/device/accton/x86_64-accton_as7326_56x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7326_56x-r0/plugins/sfputil.py @@ -178,9 +178,10 @@ def get_low_power_mode(self, port_num): if ((lpmode & 0x3) == 0x3): return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 else: - return False # High Power Mode if one of the following conditions is matched: + # 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 + return False except IOError as e: print("Error: unable to open file: %s" % str(e)) diff --git a/device/accton/x86_64-accton_as7512_32x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7512_32x-r0/plugins/sfputil.py index d47d7073e674..a999ecc24092 100644 --- a/device/accton/x86_64-accton_as7512_32x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7512_32x-r0/plugins/sfputil.py @@ -94,9 +94,10 @@ def get_low_power_mode(self, port_num): if ((lpmode & 0x3) == 0x3): return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 else: - return False # High Power Mode if one of the following conditions is matched: + # 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 + return False except IOError as e: print("Error: unable to open file: %s" % str(e)) return False diff --git a/device/accton/x86_64-accton_as7712_32x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7712_32x-r0/plugins/sfputil.py index c3d0306929ef..079a533e4e7d 100644 --- a/device/accton/x86_64-accton_as7712_32x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7712_32x-r0/plugins/sfputil.py @@ -142,9 +142,10 @@ def get_low_power_mode(self, port_num): if ((lpmode & 0x3) == 0x3): return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 else: - return False # High Power Mode if one of the following conditions is matched: + # 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 + return False except IOError as e: print("Error: unable to open file: %s" % str(e)) return False diff --git a/device/accton/x86_64-accton_as7716_32x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7716_32x-r0/plugins/sfputil.py index 79660136b33a..7af5098d52f0 100755 --- a/device/accton/x86_64-accton_as7716_32x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7716_32x-r0/plugins/sfputil.py @@ -129,9 +129,10 @@ def get_low_power_mode(self, port_num): if ((lpmode & 0x3) == 0x3): return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 else: - return False # High Power Mode if one of the following conditions is matched: + # 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 + return False except IOError as e: print("Error: unable to open file: %s" % str(e)) return False diff --git a/device/accton/x86_64-accton_as7726_32x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7726_32x-r0/plugins/sfputil.py index b3cf8a495184..350c2245fe3b 100755 --- a/device/accton/x86_64-accton_as7726_32x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7726_32x-r0/plugins/sfputil.py @@ -132,9 +132,10 @@ def get_low_power_mode(self, port_num): if ((lpmode & 0x3) == 0x3): return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 else: - return False # High Power Mode if one of the following conditions is matched: + # 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 + return False except IOError as e: print("Error: unable to open file: %s" % str(e)) return False diff --git a/device/accton/x86_64-accton_as7816_64x-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7816_64x-r0/plugins/sfputil.py index 7fea2a476655..0520799d385a 100644 --- a/device/accton/x86_64-accton_as7816_64x-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7816_64x-r0/plugins/sfputil.py @@ -169,9 +169,10 @@ def get_low_power_mode(self, port_num): if ((lpmode & 0x3) == 0x3): return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 else: - return False # High Power Mode if one of the following conditions is matched: + # 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 + return False except IOError as e: print("Error: unable to open file: %s" % str(e)) return False diff --git a/device/accton/x86_64-accton_as9716_32d-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as9716_32d-r0/plugins/sfputil.py index e75f849a7a41..7b3ca53d4ed4 100755 --- a/device/accton/x86_64-accton_as9716_32d-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as9716_32d-r0/plugins/sfputil.py @@ -133,9 +133,10 @@ def get_low_power_mode(self, port_num): if ((lpmode & 0x3) == 0x3): return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 else: - return False # High Power Mode if one of the following conditions is matched: + # 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 + return False except IOError as e: print("Error: unable to open file: %s" % str(e)) return False diff --git a/device/common/pddf/plugins/sfputil.py b/device/common/pddf/plugins/sfputil.py index 35e1d19b15f3..1ca925610822 100755 --- a/device/common/pddf/plugins/sfputil.py +++ b/device/common/pddf/plugins/sfputil.py @@ -154,9 +154,10 @@ def get_low_power_mode(self, port_num): if ((lpmode & 0x3) == 0x3): return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 else: - return False # High Power Mode if one of the following conditions is matched: + # 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 + return False except IOError as e: print("Error: unable to open file: %s" % str(e)) return False diff --git a/device/juniper/x86_64-juniper_qfx5210-r0/plugins/sfputil.py b/device/juniper/x86_64-juniper_qfx5210-r0/plugins/sfputil.py index 8f3365f5eb23..a854f8fa2915 100644 --- a/device/juniper/x86_64-juniper_qfx5210-r0/plugins/sfputil.py +++ b/device/juniper/x86_64-juniper_qfx5210-r0/plugins/sfputil.py @@ -260,9 +260,10 @@ def get_low_power_mode(self, port_num): if ((lpmode & 0x3) == 0x3): return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1 else: - return False # High Power Mode if one of the following conditions is matched: + # 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 + return False except IOError as e: print("Error: unable to open file: %s" % str(e)) return False From c313fa698d6d99eb9cdbea1e11a4d2effebc6f76 Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Tue, 24 Nov 2020 02:06:47 +0000 Subject: [PATCH 23/24] Fix alignment --- .../plugins/led_control.py | 132 +++++++++--------- 1 file changed, 66 insertions(+), 66 deletions(-) diff --git a/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/led_control.py b/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/led_control.py index 926245e8a069..4da72e7f7a04 100644 --- a/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/led_control.py +++ b/device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/led_control.py @@ -51,97 +51,97 @@ def system_led_check(): is_reset_button_push = 0 with open("/sys/bus/i2c/devices/1-005e/fan1_fault", "r") as f1: read_fan_fault = f1.read() - with open("/sys/bus/i2c/devices/9-005f/fan1_led", "w") as f11: - if str(read_fan_fault) == str("1\n"): - is_fan_all_OK = 0 - f11.write("4") - else: - f11.write("1") + with open("/sys/bus/i2c/devices/9-005f/fan1_led", "w") as f11: + if str(read_fan_fault) == str("1\n"): + is_fan_all_OK = 0 + f11.write("4") + else: + f11.write("1") with open("/sys/bus/i2c/devices/1-005e/fan2_fault", "r") as f1: read_fan_fault = f1.read() - with open("/sys/bus/i2c/devices/9-005f/fan2_led", "w") as f11: - if str(read_fan_fault) == str("1\n"): - is_fan_all_OK = 0 - f11.write("4") - else: - f11.write("1") + with open("/sys/bus/i2c/devices/9-005f/fan2_led", "w") as f11: + if str(read_fan_fault) == str("1\n"): + is_fan_all_OK = 0 + f11.write("4") + else: + f11.write("1") with open("/sys/bus/i2c/devices/1-005e/fan3_fault", "r") as f1: read_fan_fault = f1.read() - with open("/sys/bus/i2c/devices/9-005f/fan3_led", "w") as f11: - if str(read_fan_fault) == str("1\n"): - is_fan_all_OK = 0 - f11.write("4") - else: - f11.write("1") + with open("/sys/bus/i2c/devices/9-005f/fan3_led", "w") as f11: + if str(read_fan_fault) == str("1\n"): + is_fan_all_OK = 0 + f11.write("4") + else: + f11.write("1") with open("/sys/bus/i2c/devices/1-005e/fan4_fault", "r") as f1: read_fan_fault = f1.read() - with open("/sys/bus/i2c/devices/9-005f/fan4_led", "w") as f11: - if str(read_fan_fault) == str("1\n"): - is_fan_all_OK = 0 - f11.write("4") - else: - f11.write("1") + with open("/sys/bus/i2c/devices/9-005f/fan4_led", "w") as f11: + if str(read_fan_fault) == str("1\n"): + is_fan_all_OK = 0 + f11.write("4") + else: + f11.write("1") with open("/sys/bus/i2c/devices/1-005e/fan5_fault", "r") as f1: read_fan_fault = f1.read() - with open("/sys/bus/i2c/devices/9-005f/fan5_led", "w") as f11: - if str(read_fan_fault) == str("1\n"): - is_fan_all_OK = 0 - f11.write("4") - else: - f11.write("1") + with open("/sys/bus/i2c/devices/9-005f/fan5_led", "w") as f11: + if str(read_fan_fault) == str("1\n"): + is_fan_all_OK = 0 + f11.write("4") + else: + f11.write("1") with open("/sys/bus/i2c/devices/1-005e/fan6_fault", "r") as f1: read_fan_fault = f1.read() - with open("/sys/bus/i2c/devices/9-005f/fan6_led", "w") as f11: - if str(read_fan_fault) == str("1\n"): - is_fan_all_OK = 0 - f11.write("4") - else: - f11.write("1") + with open("/sys/bus/i2c/devices/9-005f/fan6_led", "w") as f11: + if str(read_fan_fault) == str("1\n"): + is_fan_all_OK = 0 + f11.write("4") + else: + f11.write("1") with open("/sys/bus/i2c/devices/1-005e/psu1_power_good", "r") as f1: read_power_status = f1.read() - with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11: - if str(read_power_status) == str("1\n"): - f11.write("1") - else: - f11.write("4") + with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11: + if str(read_power_status) == str("1\n"): + f11.write("1") + else: + f11.write("4") with open("/sys/bus/i2c/devices/1-005e/psu1_present", "r") as f1: read_power_status = f1.read() - with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11: - if str(read_power_status) == str("1\n"): - is_power_all_OK = is_power_all_OK + 1 - f11.write("1") - else: - f11.write("4") + with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11: + if str(read_power_status) == str("1\n"): + is_power_all_OK = is_power_all_OK + 1 + f11.write("1") + else: + f11.write("4") with open("/sys/bus/i2c/devices/1-005e/psu2_power_good", "r") as f1: read_power_status = f1.read() - with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11: - if str(read_power_status) == str("1\n"): - f11.write("1") - else: - f11.write("4") + with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11: + if str(read_power_status) == str("1\n"): + f11.write("1") + else: + f11.write("4") with open("/sys/bus/i2c/devices/1-005e/psu2_present", "r") as f1: read_power_status = f1.read() - with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11: - if str(read_power_status) == str("1\n"): - is_power_all_OK = is_power_all_OK + 1 - f11.write("1") - else: - f11.write("4") + with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11: + if str(read_power_status) == str("1\n"): + is_power_all_OK = is_power_all_OK + 1 + f11.write("1") + else: + f11.write("4") with open("/sys/bus/i2c/devices/9-005f/swi_ctrl", "r") as f5: is_reset_button_push = f5.read() - if str(is_reset_button_push) == "1\n": - is_reset_button_push = 1 - else: - is_reset_button_push = 0 + if str(is_reset_button_push) == "1\n": + is_reset_button_push = 1 + else: + is_reset_button_push = 0 with open("/sys/bus/i2c/devices/4-004d/hwmon/hwmon3/temp1_input", "r") as f3: is_thermal_high = f3.read() - if int(is_thermal_high) >= 70000: - is_thermal_high = 1 - else: - is_thermal_high = 0 + if int(is_thermal_high) >= 70000: + is_thermal_high = 1 + else: + is_thermal_high = 0 with open("/sys/bus/i2c/devices/9-005f/sys_status", "w") as f2: if is_reset_button_push == 1: From 3fab9f4eb047a36362a5577391186490cbb92b2c Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Wed, 25 Nov 2020 05:16:39 +0000 Subject: [PATCH 24/24] Pass 'universal_newlines=True' arg to all relevant subprocess functions --- .../sonic_platform/component.py | 2 +- .../x86_64-accton_as7716_32xb-r0/plugins/sfputil.py | 2 +- .../x86_64-cel_e1031-r0/sonic_platform/component.py | 4 ++-- .../sonic_platform/component.py | 2 +- .../x86_64-cel_seastone-r0/sonic_platform/helper.py | 8 ++++---- .../x86_64-cel_seastone_2-r0/plugins/psuutil.py | 2 +- .../x86_64-cel_silverstone-r0/plugins/psuutil.py | 2 +- .../sonic_platform/helper.py | 8 ++++---- .../x86_64-mlnx_msn2700-r0/plugins/fanutil.py | 2 +- .../x86_64-mlnx_msn2700-r0/plugins/psuutil.py | 2 +- .../x86_64-mlnx_msn2700-r0/plugins/sfputil.py | 12 ++++++------ .../x86_64-mlnx_msn2700-r0/plugins/thermalutil.py | 2 +- .../x86_64-quanta_ix1b_rglbmc-r0/plugins/psuutil.py | 4 ++-- 13 files changed, 26 insertions(+), 26 deletions(-) diff --git a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/component.py b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/component.py index 59fe7898cfe3..15d8e9e15e9d 100644 --- a/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/component.py +++ b/device/accton/x86_64-accton_as7116_54x-r0/sonic_platform/component.py @@ -30,7 +30,7 @@ def __run_command(self, command): # Run bash command and print output to stdout try: process = subprocess.Popen( - shlex.split(command), stdout=subprocess.PIPE) + shlex.split(command), universal_newlines=True, stdout=subprocess.PIPE) while True: output = process.stdout.readline() if output == '' and process.poll() is not None: diff --git a/device/accton/x86_64-accton_as7716_32xb-r0/plugins/sfputil.py b/device/accton/x86_64-accton_as7716_32xb-r0/plugins/sfputil.py index bedf33685e08..af8b9dd2fa02 100755 --- a/device/accton/x86_64-accton_as7716_32xb-r0/plugins/sfputil.py +++ b/device/accton/x86_64-accton_as7716_32xb-r0/plugins/sfputil.py @@ -129,7 +129,7 @@ def reset(self, port_num): return False mod_rst_cmd = "ipmitool raw 0x34 0x11 " + str(port_num+1) + " 0x11 0x1" - subprocess.check_output(mod_rst_cmd) + subprocess.check_output(mod_rst_cmd, universal_newlines=True) return True def get_transceiver_change_event(self): diff --git a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/component.py b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/component.py index a621da45ad3f..7fdfc8756a4d 100644 --- a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/component.py +++ b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/component.py @@ -41,7 +41,7 @@ def __run_command(self, command): # Run bash command and print output to stdout try: process = subprocess.Popen( - shlex.split(command), stdout=subprocess.PIPE) + shlex.split(command), universal_newlines=True, stdout=subprocess.PIPE) while True: output = process.stdout.readline() if output == '' and process.poll() is not None: @@ -66,7 +66,7 @@ def get_register_value(self, register): # Retrieves the cpld register value cmd = "echo {1} > {0}; cat {0}".format(GETREG_PATH, register) p = subprocess.Popen( - cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) raw_data, err = p.communicate() if err is not '': return None diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/component.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/component.py index 291b5bd3e384..2833bf4d1cc5 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/component.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/component.py @@ -54,7 +54,7 @@ def get_register_value(self, register): # Retrieves the cpld register value cmd = "echo {1} > {0}; cat {0}".format(GETREG_PATH, register) p = subprocess.Popen( - cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) raw_data, err = p.communicate() if err is not '': return None diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/helper.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/helper.py index 376110e6acc9..140c62c08666 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/helper.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/helper.py @@ -35,7 +35,7 @@ def run_command(self, cmd): result = "" try: p = subprocess.Popen( - cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) raw_data, err = p.communicate() if err == '': result = raw_data.strip() @@ -87,7 +87,7 @@ def ipmi_raw(self, netfn, cmd): try: cmd = "ipmitool raw {} {}".format(str(netfn), str(cmd)) p = subprocess.Popen( - cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) raw_data, err = p.communicate() if err == '': result = raw_data.strip() @@ -105,7 +105,7 @@ def ipmi_fru_id(self, id, key=None): id)) if not key else "ipmitool fru print {0} | grep '{1}' ".format(str(id), str(key)) p = subprocess.Popen( - cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) raw_data, err = p.communicate() if err == '': result = raw_data.strip() @@ -122,7 +122,7 @@ def ipmi_set_ss_thres(self, id, threshold_key, value): cmd = "ipmitool sensor thresh '{}' {} {}".format( str(id), str(threshold_key), str(value)) p = subprocess.Popen( - cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) raw_data, err = p.communicate() if err == '': result = raw_data.strip() diff --git a/device/celestica/x86_64-cel_seastone_2-r0/plugins/psuutil.py b/device/celestica/x86_64-cel_seastone_2-r0/plugins/psuutil.py index 35fcc0cc678c..cc5461ccb5d4 100644 --- a/device/celestica/x86_64-cel_seastone_2-r0/plugins/psuutil.py +++ b/device/celestica/x86_64-cel_seastone_2-r0/plugins/psuutil.py @@ -17,7 +17,7 @@ def __init__(self): PsuBase.__init__(self) def run_command(self, command): - proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) + proc = subprocess.Popen(command, shell=True, universal_newlines=True, stdout=subprocess.PIPE) (out, err) = proc.communicate() if proc.returncode != 0: diff --git a/device/celestica/x86_64-cel_silverstone-r0/plugins/psuutil.py b/device/celestica/x86_64-cel_silverstone-r0/plugins/psuutil.py index 8051863dc779..ca75ad98334c 100644 --- a/device/celestica/x86_64-cel_silverstone-r0/plugins/psuutil.py +++ b/device/celestica/x86_64-cel_silverstone-r0/plugins/psuutil.py @@ -19,7 +19,7 @@ def __init__(self): PsuBase.__init__(self) def run_command(self, command): - proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) + proc = subprocess.Popen(command, shell=True, universal_newlines=True, stdout=subprocess.PIPE) (out, err) = proc.communicate() if proc.returncode != 0: diff --git a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/helper.py b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/helper.py index 42fa127b6073..144d9e154348 100644 --- a/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/helper.py +++ b/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/helper.py @@ -33,7 +33,7 @@ def run_command(self, cmd): result = "" try: p = subprocess.Popen( - cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) raw_data, err = p.communicate() if err == '': result = raw_data.strip() @@ -63,7 +63,7 @@ def ipmi_raw(self, netfn, cmd): try: cmd = "ipmitool raw {} {}".format(str(netfn), str(cmd)) p = subprocess.Popen( - cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) raw_data, err = p.communicate() if err == '': result = raw_data.strip() @@ -81,7 +81,7 @@ def ipmi_fru_id(self, id, key=None): id)) if not key else "ipmitool fru print {0} | grep '{1}' ".format(str(id), str(key)) p = subprocess.Popen( - cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) raw_data, err = p.communicate() if err == '': result = raw_data.strip() @@ -97,7 +97,7 @@ def ipmi_set_ss_thres(self, id, threshold_key, value): try: cmd = "ipmitool sensor thresh '{}' {} {}".format(str(id), str(threshold_key), str(value)) p = subprocess.Popen( - cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) raw_data, err = p.communicate() if err == '': result = raw_data.strip() diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/fanutil.py b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/fanutil.py index 5881e595c26e..ee6446e7c053 100644 --- a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/fanutil.py +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/fanutil.py @@ -56,7 +56,7 @@ def __init__(self): self.num_of_fan, self.num_of_drawer = self._extract_num_of_fans_and_fan_drawers() def _get_sku_name(self): - p = subprocess.Popen(self.GET_HWSKU_CMD, shell=True, stdout=subprocess.PIPE) + p = subprocess.Popen(self.GET_HWSKU_CMD, shell=True, universal_newlines=True, stdout=subprocess.PIPE) out, err = p.communicate() return out.rstrip('\n') diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/psuutil.py b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/psuutil.py index 0303ab8f8193..6da5770c294f 100644 --- a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/psuutil.py +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/psuutil.py @@ -49,7 +49,7 @@ def __init__(self): self.fan_speed = "thermal/psu{}_fan1_speed_get" def _get_sku_name(self): - p = subprocess.Popen(self.GET_HWSKU_CMD, shell=True, stdout=subprocess.PIPE) + p = subprocess.Popen(self.GET_HWSKU_CMD, shell=True, universal_newlines=True, stdout=subprocess.PIPE) out, err = p.communicate() return out.rstrip('\n') diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfputil.py b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfputil.py index 5c30fb5cd069..954ed23d8eac 100644 --- a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfputil.py +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfputil.py @@ -92,7 +92,7 @@ def port_to_eeprom_mapping(self): raise Exception() def get_port_position_tuple_by_platform_name(self): - p = subprocess.Popen(GET_PLATFORM_CMD, shell=True, stdout=subprocess.PIPE) + p = subprocess.Popen(GET_PLATFORM_CMD, shell=True, universal_newlines=True, stdout=subprocess.PIPE) out, err = p.communicate() position_tuple = port_position_tuple_list[platform_dict[out.rstrip('\n')]] return position_tuple @@ -120,7 +120,7 @@ def get_presence(self, port_num): ethtool_cmd = "ethtool -m {} 2>/dev/null".format(sfpname) try: - proc = subprocess.Popen(ethtool_cmd, stdout=subprocess.PIPE, shell=True, stderr=subprocess.STDOUT) + proc = subprocess.Popen(ethtool_cmd, stdout=subprocess.PIPE, shell=True, universal_newlines=True, stderr=subprocess.STDOUT) stdout = proc.communicate()[0] proc.wait() result = stdout.rstrip('\n') @@ -140,7 +140,7 @@ def get_low_power_mode(self, port_num): lpm_cmd = "docker exec syncd python /usr/share/sonic/platform/plugins/sfplpmget.py {}".format(port_num) try: - output = subprocess.check_output(lpm_cmd, shell=True) + output = subprocess.check_output(lpm_cmd, shell=True, universal_newlines=True) if 'LPM ON' in output: return True except subprocess.CalledProcessError as e: @@ -164,7 +164,7 @@ def set_low_power_mode(self, port_num, lpmode): # Set LPM try: - subprocess.check_output(lpm_cmd, shell=True) + subprocess.check_output(lpm_cmd, shell=True, universal_newlines=True) except subprocess.CalledProcessError as e: print("Error! Unable to set LPM for {}, rc = {}, err msg: {}".format(port_num, e.returncode, e.output)) return False @@ -179,7 +179,7 @@ def reset(self, port_num): lpm_cmd = "docker exec syncd python /usr/share/sonic/platform/plugins/sfpreset.py {}".format(port_num) try: - subprocess.check_output(lpm_cmd, shell=True) + subprocess.check_output(lpm_cmd, shell=True, universal_newlines=True) return True except subprocess.CalledProcessError as e: print("Error! Unable to set LPM for {}, rc = {}, err msg: {}".format(port_num, e.returncode, e.output)) @@ -252,7 +252,7 @@ def _read_eeprom_specific_bytes_via_ethtool(self, port_num, offset, num_bytes): eeprom_raw = [] ethtool_cmd = "ethtool -m {} hex on offset {} length {}".format(sfpname, offset, num_bytes) try: - output = subprocess.check_output(ethtool_cmd, shell=True) + output = subprocess.check_output(ethtool_cmd, shell=True, universal_newlines=True) output_lines = output.splitlines() first_line_raw = output_lines[0] if "Offset" in first_line_raw: diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/thermalutil.py b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/thermalutil.py index 10516b7077dc..980ef8a9fc38 100644 --- a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/thermalutil.py +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/thermalutil.py @@ -364,7 +364,7 @@ class ThermalUtil(ThermalBase): thermal_list = [] def _get_sku_name(self): - p = subprocess.Popen(self.GET_HWSKU_CMD, shell=True, stdout=subprocess.PIPE) + p = subprocess.Popen(self.GET_HWSKU_CMD, shell=True, universal_newlines=True, stdout=subprocess.PIPE) out, err = p.communicate() return out.rstrip('\n') diff --git a/device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/psuutil.py b/device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/psuutil.py index e78148e30f40..0b2027afdda4 100755 --- a/device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/psuutil.py +++ b/device/quanta/x86_64-quanta_ix1b_rglbmc-r0/plugins/psuutil.py @@ -25,7 +25,7 @@ def show_log(txt): def exec_cmd(cmd, show): logging.info('Run :'+cmd) try: - output = subprocess.check_output(cmd, shell=True) + output = subprocess.check_output(cmd, shell=True, universal_newlines=True) show_log(cmd + "output:"+str(output)) except subprocess.CalledProcessError as e: logging.info("Failed :"+cmd) @@ -45,7 +45,7 @@ def log_os_system(cmd, show): status = 1 output = "" try: - output = subprocess.check_output(cmd, shell=True) + output = subprocess.check_output(cmd, shell=True, universal_newlines=True) my_log(cmd + "output:"+str(output)) except subprocess.CalledProcessError as e: logging.info('Failed :'+cmd)