Skip to content

Commit

Permalink
Change import order in Ycable helper and EEPROM read bytearray change…
Browse files Browse the repository at this point in the history
… in SFP plugin (#177)

- Import of sonic_platform before logger when platform API is not available leads to non import of logger resulting in xcvrd crash
- Since string and byte comparison returns true in python2 current check for differentiating python2 and 3 in EEPROM read fails.

Co-authored-by: V P Subramaniam <Subramaniam_Vellalap@dell.com>
  • Loading branch information
vpsubramaniam and V P Subramaniam authored Mar 23, 2021
1 parent 0b60982 commit fa02416
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
14 changes: 4 additions & 10 deletions sonic_platform_base/sonic_sfp/sfputilbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,16 +344,10 @@ def _read_eeprom_specific_bytes(self, sysfsfile_eeprom, offset, num_bytes):
return None

try:
# in case raw is bytes (python3 is used) raw[n] will return int,
# and in case raw is str(python2 is used) raw[n] will return str,
# so for python3 the are no need to call ord to convert str to int.
# TODO: Remove this check once we no longer support Python 2
if type(raw) == bytes:
for n in range(0, num_bytes):
eeprom_raw[n] = hex(raw[n])[2:].zfill(2)
else:
for n in range(0, num_bytes):
eeprom_raw[n] = hex(ord(raw[n]))[2:].zfill(2)
# raw is changed to bytearray to support both python 2 and 3.
raw = bytearray(raw)
for n in range(0, num_bytes):
eeprom_raw[n] = hex(raw[n])[2:].zfill(2)
except Exception:
return None

Expand Down
2 changes: 1 addition & 1 deletion sonic_y_cable/y_cable.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import struct
from ctypes import c_int8

import sonic_platform.platform
from sonic_py_common import logger
import sonic_platform.platform
except ImportError as e:
# When build python3 xcvrd, it tries to do basic check which will import this file. However,
# not all platform supports python3 API now, so it could cause an issue when importing
Expand Down

0 comments on commit fa02416

Please sign in to comment.