diff --git a/platform/broadcom/sonic-platform-modules-dell/s5232f/sonic_platform/eeprom.py b/platform/broadcom/sonic-platform-modules-dell/s5232f/sonic_platform/eeprom.py index 4a567380f477..bf3434733f36 100644 --- a/platform/broadcom/sonic-platform-modules-dell/s5232f/sonic_platform/eeprom.py +++ b/platform/broadcom/sonic-platform-modules-dell/s5232f/sonic_platform/eeprom.py @@ -11,7 +11,6 @@ try: import os.path from sonic_eeprom import eeprom_tlvinfo - import binascii except ImportError as e: raise ImportError(str(e) + "- required module not found") @@ -40,7 +39,7 @@ def __init__(self): if not self.is_valid_tlvinfo_header(eeprom): return - total_length = (ord(eeprom[9]) << 8) | ord(eeprom[10]) + total_length = (eeprom[9] << 8) | eeprom[10] tlv_index = self._TLV_INFO_HDR_LEN tlv_end = self._TLV_INFO_HDR_LEN + total_length @@ -49,16 +48,16 @@ def __init__(self): break tlv = eeprom[tlv_index:tlv_index + 2 - + ord(eeprom[tlv_index + 1])] - code = "0x%02X" % (ord(tlv[0])) + + eeprom[tlv_index + 1]] + code = "0x%02X" % tlv[0] name, value = self.decoder(None, tlv) self.eeprom_tlv_dict[code] = value - if ord(eeprom[tlv_index]) == self._TLV_CODE_CRC_32: + if eeprom[tlv_index] == self._TLV_CODE_CRC_32: break - tlv_index += ord(eeprom[tlv_index+1]) + 2 + tlv_index += eeprom[tlv_index+1] + 2 def serial_number_str(self): """ @@ -68,7 +67,7 @@ def serial_number_str(self): self.eeprom_data, self._TLV_CODE_SERIAL_NUMBER) if not is_valid: return "N/A" - return results[2] + return results[2].decode('ascii') def base_mac_addr(self, e): """ @@ -79,7 +78,7 @@ def base_mac_addr(self, e): if not is_valid or t[1] != 6: return super(eeprom_tlvinfo.TlvInfoDecoder, self).switchaddrstr(t) - return ":".join([binascii.b2a_hex(T) for T in t[2]]) + return ":".join(["{:02x}".format(T) for T in t[2]]).upper() def modelstr(self): """ @@ -90,7 +89,7 @@ def modelstr(self): if not is_valid: return "N/A" - return results[2] + return results[2].decode('ascii') def part_number_str(self): """ @@ -101,7 +100,7 @@ def part_number_str(self): if not is_valid: return "N/A" - return results[2] + return results[2].decode('ascii') def serial_str(self): """ @@ -112,7 +111,7 @@ def serial_str(self): if not is_valid: return "N/A" - return results[2] + return results[2].decode('ascii') def revision_str(self): """ @@ -123,7 +122,7 @@ def revision_str(self): if not is_valid: return "N/A" - return results[2] + return results[2].decode('ascii') def system_eeprom_info(self): """ @@ -132,5 +131,3 @@ def system_eeprom_info(self): found in the system EEPROM. """ return self.eeprom_tlv_dict - - diff --git a/platform/broadcom/sonic-platform-modules-dell/s6000/sonic_platform/eeprom.py b/platform/broadcom/sonic-platform-modules-dell/s6000/sonic_platform/eeprom.py index 45f2a63598e7..ef736089c44b 100644 --- a/platform/broadcom/sonic-platform-modules-dell/s6000/sonic_platform/eeprom.py +++ b/platform/broadcom/sonic-platform-modules-dell/s6000/sonic_platform/eeprom.py @@ -18,7 +18,6 @@ try: import binascii - import os import redis import struct from collections import OrderedDict @@ -108,7 +107,7 @@ def _load_system_eeprom(self): self.serial = 'NA' return - total_length = (ord(eeprom[9]) << 8) | ord(eeprom[10]) + total_length = (eeprom[9] << 8) | (eeprom[10]) tlv_index = self._TLV_INFO_HDR_LEN tlv_end = self._TLV_INFO_HDR_LEN + total_length @@ -117,21 +116,21 @@ def _load_system_eeprom(self): break tlv = eeprom[tlv_index:tlv_index + 2 - + ord(eeprom[tlv_index + 1])] - code = "0x%02X" % (ord(tlv[0])) + + eeprom[tlv_index + 1]] + code = "0x%02X" % (tlv[0]) - if ord(tlv[0]) == self._TLV_CODE_VENDOR_EXT: - value = str((ord(tlv[2]) << 24) | (ord(tlv[3]) << 16) | - (ord(tlv[4]) << 8) | ord(tlv[5])) - value += str(tlv[6:6 + ord(tlv[1])]) + if tlv[0] == self._TLV_CODE_VENDOR_EXT: + value = str((tlv[2] << 24) | (tlv[3] << 16) | + (tlv[4] << 8) | tlv[5]) + value += tlv[6:6 + tlv[1]].decode('ascii') else: name, value = self.decoder(None, tlv) self.eeprom_tlv_dict[code] = value - if ord(eeprom[tlv_index]) == self._TLV_CODE_CRC_32: + if eeprom[tlv_index] == self._TLV_CODE_CRC_32: break - tlv_index += ord(eeprom[tlv_index+1]) + 2 + tlv_index += eeprom[tlv_index+1] + 2 self.base_mac = self.eeprom_tlv_dict.get( "0x%X" % (self._TLV_CODE_MAC_BASE), 'NA') @@ -191,7 +190,7 @@ def _load_device_eeprom(self): else: self.fan_type = 'NA' - def _get_eeprom_field(self, field_name): + def _get_eeprom_field(self, field_name, decode=True): """ For a field name specified in the EEPROM format, returns the presence of the field and the value for the same. @@ -200,7 +199,10 @@ def _get_eeprom_field(self, field_name): for field in self.format: field_end = field_start + field[2] if field[0] == field_name: - return (True, self.eeprom_data[field_start:field_end].decode('utf-8')) + if decode: + return (True, self.eeprom_data[field_start:field_end].decode('ascii')) + else: + return (True, self.eeprom_data[field_start:field_end]) field_start = field_end return (False, None) @@ -259,7 +261,7 @@ class EepromS6000(EepromDecoder): _EEPROM_MAX_LEN = 128 _BLK_HDR_LEN = 6 - _BLK_HDR_MAGIC = '\x3a\x29' + _BLK_HDR_MAGIC = b'\x3a\x29' _BLK_HDR_REVID = 1 _BLK_CODE_MFG = 0x20 @@ -297,10 +299,10 @@ def _is_valid_block_checksum(self, e): def _is_valid_block(self, e, blk_code): return (e[:2] == self._BLK_HDR_MAGIC and struct.unpack('3d} {: