Skip to content

Commit fb05b3c

Browse files
authored
Make eeprom_tlvinfo.py Python3 compatible (sonic-net#152)
Fix errors like below: ``` admin@sonic:~$ show version SONiC Software Version: SONiC.master.0-dirty-20201204.005739 Distribution: Debian 10.6 Kernel: 4.19.0-9-2-amd64 Build commit: 873fb969 Build date: Fri Dec 4 09:02:43 UTC 2020 Built by: user@sonic-build Platform: x86_64-accton_wedge100bf_32x-r0 HwSKU: montara ASIC: barefoot Traceback (most recent call last): File "/usr/local/bin/decode-syseeprom", line 171, in <module> exit(main()) File "/usr/local/bin/decode-syseeprom", line 47, in main t = class_('board', '','','') File "/usr/share/sonic/device/x86_64-accton_wedge100bf_32x-r0/plugins/eeprom.py", line 113, in __init__ if self.eeprom_init(): File "/usr/share/sonic/device/x86_64-accton_wedge100bf_32x-r0/plugins/eeprom.py", line 180, in eeprom_init self, "", [eeprom_params]) File "/usr/local/lib/python3.7/dist-packages/sonic_eeprom/eeprom_tlvinfo.py", line 178, in set_eeprom new_tlvs += new_tlv TypeError: can't concat str to bytearray ```
1 parent a8823a3 commit fb05b3c

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

sonic_platform_base/sonic_eeprom/eeprom_tlvinfo.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -202,16 +202,16 @@ def set_eeprom(self, e, cmd_args):
202202

203203
if self._TLV_HDR_ENABLED:
204204
new_tlvs_len = len(new_tlvs) + 6
205-
new_e = self._TLV_INFO_ID_STRING + chr(self._TLV_INFO_VERSION) + \
206-
chr((new_tlvs_len >> 8) & 0xFF) + \
207-
chr(new_tlvs_len & 0xFF) + new_tlvs
205+
new_e = self._TLV_INFO_ID_STRING + bytes([self._TLV_INFO_VERSION]) + \
206+
bytes([(new_tlvs_len >> 8) & 0xFF]) + \
207+
bytes([new_tlvs_len & 0xFF]) + new_tlvs
208208
else:
209209
new_e = new_tlvs
210210

211211
if self._TLV_CODE_CRC_32 != self._TLV_CODE_UNDEFINED:
212-
new_e = new_e + chr(self._TLV_CODE_CRC_32) + chr(4)
212+
new_e = new_e + bytes([self._TLV_CODE_CRC_32]) + bytes([4])
213213
elif self._TLV_CODE_QUANTA_CRC != self._TLV_CODE_UNDEFINED:
214-
new_e = new_e + chr(self._TLV_CODE_QUANTA_CRC) + chr(2)
214+
new_e = new_e + bytes([self._TLV_CODE_QUANTA_CRC]) + bytes([2])
215215
else:
216216
print("\nFailed to formulate new eeprom\n")
217217
exit
@@ -682,7 +682,7 @@ def encoder(self, I, v):
682682
sys.stderr.write("Error: '" + "0x%02X" % (I[0],) + "' correct format is " + errstr + "\n")
683683
exit(0)
684684

685-
return chr(I[0]) + chr(len(value)) + value
685+
return (chr(I[0]) + chr(len(value)) + value).encode()
686686

687687

688688
def is_checksum_field(self, I):

0 commit comments

Comments
 (0)