Skip to content

Commit fa02416

Browse files
vpsubramaniamV P Subramaniam
andauthored
Change import order in Ycable helper and EEPROM read bytearray change 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 <[email protected]>
1 parent 0b60982 commit fa02416

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

sonic_platform_base/sonic_sfp/sfputilbase.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -344,16 +344,10 @@ def _read_eeprom_specific_bytes(self, sysfsfile_eeprom, offset, num_bytes):
344344
return None
345345

346346
try:
347-
# in case raw is bytes (python3 is used) raw[n] will return int,
348-
# and in case raw is str(python2 is used) raw[n] will return str,
349-
# so for python3 the are no need to call ord to convert str to int.
350-
# TODO: Remove this check once we no longer support Python 2
351-
if type(raw) == bytes:
352-
for n in range(0, num_bytes):
353-
eeprom_raw[n] = hex(raw[n])[2:].zfill(2)
354-
else:
355-
for n in range(0, num_bytes):
356-
eeprom_raw[n] = hex(ord(raw[n]))[2:].zfill(2)
347+
# raw is changed to bytearray to support both python 2 and 3.
348+
raw = bytearray(raw)
349+
for n in range(0, num_bytes):
350+
eeprom_raw[n] = hex(raw[n])[2:].zfill(2)
357351
except Exception:
358352
return None
359353

sonic_y_cable/y_cable.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
import struct
1111
from ctypes import c_int8
1212

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

0 commit comments

Comments
 (0)