Skip to content

Commit 600d043

Browse files
authored
[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 sonic-net/sonic-platform-daemons#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.
1 parent af79326 commit 600d043

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

sonic-xcvrd/scripts/xcvrd

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ try:
1616
import threading
1717
import time
1818

19+
from enum import Enum
1920
from sonic_py_common import daemon_base, device_info, logger
2021
from sonic_py_common import multi_asic
2122
from swsscommon import swsscommon
@@ -45,21 +46,13 @@ XCVRD_MAIN_THREAD_SLEEP_SECS = 60
4546
SFP_STATUS_REMOVED = '0'
4647
SFP_STATUS_INSERTED = '1'
4748

48-
# SFP error codes, stored as strings. Can add more as needed.
49-
SFP_STATUS_ERR_I2C_STUCK = '2'
50-
SFP_STATUS_ERR_BAD_EEPROM = '3'
51-
SFP_STATUS_ERR_UNSUPPORTED_CABLE = '4'
52-
SFP_STATUS_ERR_HIGH_TEMP = '5'
53-
SFP_STATUS_ERR_BAD_CABLE = '6'
54-
55-
# Store the error codes in a set for convenience
56-
errors_block_eeprom_reading = {
57-
SFP_STATUS_ERR_I2C_STUCK,
58-
SFP_STATUS_ERR_BAD_EEPROM,
59-
SFP_STATUS_ERR_UNSUPPORTED_CABLE,
60-
SFP_STATUS_ERR_HIGH_TEMP,
61-
SFP_STATUS_ERR_BAD_CABLE
62-
}
49+
# SFP error code enum, new elements can be added to the enum if new errors need to be supported.
50+
SFP_STATUS_ERR_ENUM = Enum('SFP_STATUS_ERR_ENUM', ['SFP_STATUS_ERR_I2C_STUCK', 'SFP_STATUS_ERR_BAD_EEPROM',
51+
'SFP_STATUS_ERR_UNSUPPORTED_CABLE', 'SFP_STATUS_ERR_HIGH_TEMP',
52+
'SFP_STATUS_ERR_BAD_CABLE'], start=2)
53+
54+
# Convert the error code to string and store them in a set for convenience
55+
errors_block_eeprom_reading = set(str(error_code.value) for error_code in SFP_STATUS_ERR_ENUM)
6356

6457
EVENT_ON_ALL_SFP = '-1'
6558
# events definition

sonic-xcvrd/setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
],
1616
install_requires = [
1717
# NOTE: This package also requires swsscommon, but it is not currently installed as a wheel
18+
'enum34; python_version < "3.4"',
1819
'sonic-py-common',
1920
],
2021
setup_requires = [

0 commit comments

Comments
 (0)