Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Celestica] Fix platform module to be compatible with Python3 #10051

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import chassis
import platform
from . import chassis
from . import platform
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
try:
import sys
from sonic_platform_base.chassis_base import ChassisBase
from common import Common
from sonic_platform.common import Common
except ImportError as e:
raise ImportError(str(e) + "- required module not found")

Expand Down Expand Up @@ -106,7 +106,7 @@ def __initialize_eeprom(self):
self._eeprom = Tlv(self._config)

def __initialize_components(self):
from component import Component
from sonic_platform.component import Component

component_config_path = self._api_common.get_config_path(
self.COMPONENT_CONFIG)
Expand Down Expand Up @@ -298,7 +298,7 @@ def get_model(self):
Returns:
string: Model/part number of device
"""
return self._eeprom.get_pn()
return self._eeprom.get_part_number()

def get_serial(self):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _run_command(self, command):
output = ""
try:
p = subprocess.Popen(
command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
command, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
raw_data, err = p.communicate()
if err == '':
status, output = True, raw_data.strip()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

try:
from sonic_platform_base.component_base import ComponentBase
from common import Common
from sonic_platform.common import Common
except ImportError as e:
raise ImportError(str(e) + "- required module not found")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ def _load_eeprom(self):
def get_eeprom(self):
return self._eeprom

def get_part_number(self):
return self._eeprom.get('0x22', "Undefined.")

def get_serial(self):
return self._eeprom.get('0x23', "Undefined.")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

try:
from sonic_platform_base.fan_base import FanBase
from common import Common
from sonic_platform.common import Common
except ImportError as e:
raise ImportError(str(e) + "- required module not found")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

try:
from sonic_platform_base.psu_base import PsuBase
from common import Common
from sonic_platform.common import Common
except ImportError as e:
raise ImportError(str(e) + "- required module not found")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from sonic_platform_base.sonic_sfp.qsfp_dd import qsfp_dd_InterfaceId
from sonic_platform_base.sonic_sfp.qsfp_dd import qsfp_dd_Dom
from sonic_platform_base.sonic_sfp.sfputilhelper import SfpUtilHelper
from common import Common
from sonic_platform.common import Common
except ImportError as e:
raise ImportError(str(e) + "- required module not found")

Expand Down Expand Up @@ -197,7 +197,7 @@
'Fibre Channel link length/Transmitter Technology',
'Fibre Channel transmission media', 'Fibre Channel Speed')

info_dict_keys = ['type', 'hardwarerev', 'serial', 'manufacturer', 'model', 'connector', 'encoding', 'ext_identifier',
info_dict_keys = ['type', 'vendor_rev', 'serial', 'manufacturer', 'model', 'connector', 'encoding', 'ext_identifier',
'ext_rateselect_compliance', 'cable_type', 'cable_length', 'nominal_bit_rate', 'specification_compliance',
'vendor_date', 'vendor_oui', 'application_advertisement']

Expand Down Expand Up @@ -285,7 +285,7 @@ def _read_eeprom_specific_bytes(self, offset, num_bytes):
sysfsfile_eeprom = None
eeprom_raw = []
for i in range(0, num_bytes):
eeprom_raw.append("0x00")
eeprom_raw.append("00")

sysfs_sfp_i2c_client_eeprom_path = self._get_eeprom_path()
try:
Expand All @@ -294,7 +294,7 @@ def _read_eeprom_specific_bytes(self, offset, num_bytes):
sysfsfile_eeprom.seek(offset)
raw = sysfsfile_eeprom.read(num_bytes)
for n in range(0, num_bytes):
eeprom_raw[n] = hex(ord(raw[n]))[2:].zfill(2)
eeprom_raw[n] = raw[n:n+1].hex()
except Exception:
pass
finally:
Expand Down Expand Up @@ -545,6 +545,9 @@ def get_transceiver_info(self):
================================================================================
"""

if not self.get_presence():
return {}

transceiver_info_dict = {}
compliance_code_dict = {}
transceiver_info_dict = dict.fromkeys(
Expand Down Expand Up @@ -896,6 +899,10 @@ def get_transceiver_bulk_status(self):
| |for example, tx2power stands for tx power of channel 2.
========================================================================
"""

if not self.get_presence():
return {}

transceiver_dom_info_dict = dict.fromkeys(
dom_info_dict_keys, Common.NULL_VAL)

Expand Down Expand Up @@ -1129,6 +1136,10 @@ def get_transceiver_threshold_info(self):
txbiaslowwarning |FLOAT |Low Warning Threshold value of tx Bias Current in mA.
========================================================================
"""

if not self.get_presence():
return {}

transceiver_dom_threshold_info_dict = dict.fromkeys(
threshold_dict_keys, Common.NULL_VAL)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

try:
from sonic_platform_base.thermal_base import ThermalBase
from common import Common
from sonic_platform.common import Common
except ImportError as e:
raise ImportError(str(e) + "- required module not found")

Expand Down