Skip to content

Commit 5e1c67e

Browse files
Support python3 for xcvrd, psud, thermalctld and syseepromd (sonic-net#132)
python2 is end of life and SONiC is going to support python3. This PR is to change code in xcvrd, psud, thermalctld and syseeprom to make it compatible with both python3 and python2.
1 parent 4d619b9 commit 5e1c67e

File tree

7 files changed

+10
-6
lines changed

7 files changed

+10
-6
lines changed

sonic-psud/setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
'Natural Language :: English',
3636
'Operating System :: POSIX :: Linux',
3737
'Programming Language :: Python :: 2.7',
38+
'Programming Language :: Python :: 3.7',
3839
'Topic :: System :: Hardware',
3940
],
4041
keywords='sonic SONiC psu PSU daemon psud PSUD',

sonic-syseepromd/setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
'Natural Language :: English',
2727
'Operating System :: POSIX :: Linux',
2828
'Programming Language :: Python :: 2.7',
29+
'Programming Language :: Python :: 3.7',
2930
'Topic :: System :: Hardware',
3031
],
3132
keywords='sonic SONiC SYSEEPROM syseeprom SYSEEPROMD syseepromd',

sonic-thermalctld/scripts/thermalctld

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class FanStatus(logger.Logger):
116116

117117
def _check_speed_value_available(self, speed, target_speed, tolerance, current_status):
118118
if speed == NOT_AVAILABLE or target_speed == NOT_AVAILABLE or tolerance == NOT_AVAILABLE:
119-
if tolerance > 100 or tolerance < 0:
119+
if isinstance(tolerance, int) and (tolerance > 100 or tolerance < 0):
120120
self.log_warning('Invalid tolerance value: {}'.format(tolerance))
121121
return False
122122

sonic-thermalctld/setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
'Natural Language :: English',
3535
'Operating System :: POSIX :: Linux',
3636
'Programming Language :: Python :: 2.7',
37+
'Programming Language :: Python :: 3.7',
3738
'Topic :: System :: Hardware',
3839
],
3940
keywords='sonic SONiC THERMALCONTROL thermalcontrol THERMALCTL thermalctl thermalctld',

sonic-xcvrd/setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
'Natural Language :: English',
3535
'Operating System :: POSIX :: Linux',
3636
'Programming Language :: Python :: 2.7',
37+
'Programming Language :: Python :: 3.7',
3738
'Topic :: System :: Hardware',
3839
],
3940
keywords = 'sonic SONiC TRANSCEIVER transceiver daemon XCVRD xcvrd',

sonic-xcvrd/xcvrd/xcvrd.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from swsscommon import swsscommon
2323

2424
from .xcvrd_utilities import y_cable_helper
25-
except ImportError, e:
25+
except ImportError as e:
2626
raise ImportError (str(e) + " - required module not found")
2727

2828
#
@@ -1003,7 +1003,7 @@ def task_worker(self, stopping_event, sfp_error_event, y_cable_presence):
10031003
# 1. the state has been normal before got the event
10041004
# 2. the state was init and transition to normal after got the event.
10051005
# this is for the vendors who don't implement "system_not_ready/system_becom_ready" logic
1006-
for key, value in port_dict.iteritems():
1006+
for key, value in port_dict.items():
10071007
logical_port_list = platform_sfputil.get_physical_to_logical(int(key))
10081008
if logical_port_list is None:
10091009
helper_logger.log_warning("Got unknown FP port index {}, ignored".format(key))
@@ -1210,7 +1210,7 @@ def init(self):
12101210
# For single ASIC platforms we pass port_config_file_path and the asic_inst as 0
12111211
port_config_file_path = device_info.get_path_to_port_config_file()
12121212
platform_sfputil.read_porttab_mappings(port_config_file_path, 0)
1213-
except Exception, e:
1213+
except Exception as e:
12141214
self.log_error("Failed to read port info: %s" % (str(e)), True)
12151215
sys.exit(PORT_CONFIG_LOAD_ERROR)
12161216

sonic-xcvrd/xcvrd/xcvrd_utilities/y_cable_helper.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from sonic_py_common import multi_asic
1111
from sonic_y_cable import y_cable
1212
from swsscommon import swsscommon
13-
except ImportError, e:
13+
except ImportError as e:
1414
raise ImportError(str(e) + " - required module not found")
1515

1616

@@ -403,7 +403,7 @@ def change_ports_status_for_y_cable_change_event(port_dict, y_cable_presence, st
403403
port_table_keys[asic_id] = port_tbl[asic_id].getKeys()
404404

405405
# Init PORT_STATUS table if ports are on Y cable and an event is received
406-
for key, value in port_dict.iteritems():
406+
for key, value in port_dict.items():
407407
logical_port_list = y_cable_platform_sfputil.get_physical_to_logical(int(key))
408408
if logical_port_list is None:
409409
helper_logger.log_warning("Got unknown FP port index {}, ignored".format(key))

0 commit comments

Comments
 (0)