diff --git a/sonic_eeprom/eeprom_base.py b/sonic_eeprom/eeprom_base.py index 27d7b5dfe8..faa9c071b5 100644 --- a/sonic_eeprom/eeprom_base.py +++ b/sonic_eeprom/eeprom_base.py @@ -232,10 +232,22 @@ def read_eeprom_bytes(self, byteCount, offset=0): F = self.open_eeprom() F.seek(self.s + offset) o = F.read(byteCount) + + # If we read from the cache file and the byte count isn't what we + # expect, the file may be corrupt. Delete it and try again, this + # time reading from the actual EEPROM. + if len(o) != byteCount and not self.cache_update_needed: + os.remove(self.cache_name) + self.cache_update_needed = True + F.close() + F = self.open_eeprom() + F.seek(self.s + offset) + o = F.read(byteCount) + if len(o) != byteCount: - raise RuntimeError("expected to read %d bytes from %s, " \ - %(byteCount, self.p) + - "but only read %d" %(len(o))) + raise RuntimeError("Expected to read %d bytes from %s, " + % (byteCount, self.p) + + "but only read %d" % (len(o))) F.close() return o