From 600d043afc4756f5965479a333bfcf91c31d655d Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Tue, 3 Nov 2020 09:27:48 -0800 Subject: [PATCH] [xcvrd] Add enum dependence back; Install 'enum34' conditionally based on Python version (#107) Add dependence on 'enum' package back to xcvrd (basically reverting most of https://github.com/Azure/sonic-platform-daemons/pull/106). However, in setup.py, we only install the enum34 package if the version of Python we are installing for is < 3.4. Thus, when installing the Python 3 xcvrd package in Python 2.7, the Python 2 version of enum34 will be installed. However, if installing the Python 3 xcvrd package on Python 3.7, enum34 will not be installed, causing xcrvd to import the 'enum' module from the standard library. This should prevent any conflicts which arise when 'enum34' is ever installed on Python versions >= 3.4 by preventing this situation. --- sonic-xcvrd/scripts/xcvrd | 23 ++++++++--------------- sonic-xcvrd/setup.py | 1 + 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/sonic-xcvrd/scripts/xcvrd b/sonic-xcvrd/scripts/xcvrd index 2ad3b198610b..5cdf6e1b01f0 100644 --- a/sonic-xcvrd/scripts/xcvrd +++ b/sonic-xcvrd/scripts/xcvrd @@ -16,6 +16,7 @@ try: import threading import time + from enum import Enum from sonic_py_common import daemon_base, device_info, logger from sonic_py_common import multi_asic from swsscommon import swsscommon @@ -45,21 +46,13 @@ XCVRD_MAIN_THREAD_SLEEP_SECS = 60 SFP_STATUS_REMOVED = '0' SFP_STATUS_INSERTED = '1' -# SFP error codes, stored as strings. Can add more as needed. -SFP_STATUS_ERR_I2C_STUCK = '2' -SFP_STATUS_ERR_BAD_EEPROM = '3' -SFP_STATUS_ERR_UNSUPPORTED_CABLE = '4' -SFP_STATUS_ERR_HIGH_TEMP = '5' -SFP_STATUS_ERR_BAD_CABLE = '6' - -# Store the error codes in a set for convenience -errors_block_eeprom_reading = { - SFP_STATUS_ERR_I2C_STUCK, - SFP_STATUS_ERR_BAD_EEPROM, - SFP_STATUS_ERR_UNSUPPORTED_CABLE, - SFP_STATUS_ERR_HIGH_TEMP, - SFP_STATUS_ERR_BAD_CABLE -} +# SFP error code enum, new elements can be added to the enum if new errors need to be supported. +SFP_STATUS_ERR_ENUM = Enum('SFP_STATUS_ERR_ENUM', ['SFP_STATUS_ERR_I2C_STUCK', 'SFP_STATUS_ERR_BAD_EEPROM', + 'SFP_STATUS_ERR_UNSUPPORTED_CABLE', 'SFP_STATUS_ERR_HIGH_TEMP', + 'SFP_STATUS_ERR_BAD_CABLE'], start=2) + +# Convert the error code to string and store them in a set for convenience +errors_block_eeprom_reading = set(str(error_code.value) for error_code in SFP_STATUS_ERR_ENUM) EVENT_ON_ALL_SFP = '-1' # events definition diff --git a/sonic-xcvrd/setup.py b/sonic-xcvrd/setup.py index ad5148d8c975..1171ecdfc681 100644 --- a/sonic-xcvrd/setup.py +++ b/sonic-xcvrd/setup.py @@ -15,6 +15,7 @@ ], install_requires = [ # NOTE: This package also requires swsscommon, but it is not currently installed as a wheel + 'enum34; python_version < "3.4"', 'sonic-py-common', ], setup_requires = [