Skip to content

Commit

Permalink
Support python3 for xcvrd, psud, thermalctld and syseepromd (#132)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Junchao-Mellanox authored Dec 8, 2020
1 parent 4d619b9 commit 5e1c67e
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions sonic-psud/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
'Natural Language :: English',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.7',
'Topic :: System :: Hardware',
],
keywords='sonic SONiC psu PSU daemon psud PSUD',
Expand Down
1 change: 1 addition & 0 deletions sonic-syseepromd/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
'Natural Language :: English',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.7',
'Topic :: System :: Hardware',
],
keywords='sonic SONiC SYSEEPROM syseeprom SYSEEPROMD syseepromd',
Expand Down
2 changes: 1 addition & 1 deletion sonic-thermalctld/scripts/thermalctld
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class FanStatus(logger.Logger):

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

Expand Down
1 change: 1 addition & 0 deletions sonic-thermalctld/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
'Natural Language :: English',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.7',
'Topic :: System :: Hardware',
],
keywords='sonic SONiC THERMALCONTROL thermalcontrol THERMALCTL thermalctl thermalctld',
Expand Down
1 change: 1 addition & 0 deletions sonic-xcvrd/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
'Natural Language :: English',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.7',
'Topic :: System :: Hardware',
],
keywords = 'sonic SONiC TRANSCEIVER transceiver daemon XCVRD xcvrd',
Expand Down
6 changes: 3 additions & 3 deletions sonic-xcvrd/xcvrd/xcvrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from swsscommon import swsscommon

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

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

Expand Down
4 changes: 2 additions & 2 deletions sonic-xcvrd/xcvrd/xcvrd_utilities/y_cable_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from sonic_py_common import multi_asic
from sonic_y_cable import y_cable
from swsscommon import swsscommon
except ImportError, e:
except ImportError as e:
raise ImportError(str(e) + " - required module not found")


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

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

0 comments on commit 5e1c67e

Please sign in to comment.