Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sonic_eeprom] If reading from what appears to be a corrupt cache file, delete file and read directly from EEPROM #10

Merged
merged 2 commits into from
Aug 10, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions sonic_eeprom/eeprom_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down