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

[eeprom_tlv_info] Optimize EEPROM data process by using visitor pattern #12

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ sonic_platform_common.egg-info/
# Unit test / coverage reports
.coverage
htmlcov/
coverage.xml
test-results.xml
17 changes: 17 additions & 0 deletions sonic_platform_base/sonic_eeprom/eeprom_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def __init__(self, path, format, start, status, readonly):
self.s = start
self.u = status
self.r = readonly
# Warning: the following members are deprecated, the parsed EEPROM data is stored in the
# Redis STATE_DB, cached data should be fetched from STATE_DB.EEPROM_INFO.
self.cache_name = None
self.cache_update_needed = False
self.lock_file = None
Expand All @@ -47,6 +49,9 @@ def check_status(self):
return 'ok'

def set_cache_name(self, name):
# Warning: this method is deprecated, the parsed EEPROM data is stored in the
# Redis STATE_DB, cached data should be fetched from STATE_DB.EEPROM_INFO.

# before accessing the eeprom we acquire an exclusive lock on the eeprom file.
# this will prevent a race condition where multiple instances of this app
# could try to update the cache at the same time
Expand Down Expand Up @@ -214,6 +219,9 @@ def open_eeprom(self):
using_eeprom = True
eeprom_file = self.p
try:
# Warning: cache file is deprecated, the parsed EEPROM data is stored in the
# Redis STATE_DB, cached data should be fetched from STATE_DB.EEPROM_INFO. This
# code need to be adjusted once cache file is completely removing from the system.
if os.path.isfile(self.cache_name):
eeprom_file = self.cache_name
using_eeprom = False
Expand All @@ -240,6 +248,9 @@ def read_eeprom_bytes(self, byteCount, offset=0):
# 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:
# Warning: cache file is deprecated, the parsed EEPROM data is stored in the
# Redis STATE_DB, cached data should be fetched from STATE_DB.EEPROM_INFO. This
# code needs to be adjusted once cache file is completely removed from the system.
os.remove(self.cache_name)
self.cache_update_needed = True
F.close()
Expand Down Expand Up @@ -277,6 +288,9 @@ def write_eeprom(self, e):
self.write_cache(e)

def write_cache(self, e):
# Warning: this method is deprecated, the parsed EEPROM data is stored in the
# Redis STATE_DB, cached data should be fetched from STATE_DB.EEPROM_INFO.

if self.cache_name:
F = None
try:
Expand All @@ -290,6 +304,9 @@ def write_cache(self, e):
F.close()

def update_cache(self, e):
# Warning: this method is deprecated, the parsed EEPROM data is stored in the
# Redis STATE_DB, cached data should be fetched from STATE_DB.EEPROM_INFO.

if self.cache_update_needed:
self.write_cache(e)
fcntl.flock(self.lock_file, fcntl.LOCK_UN)
Expand Down
Loading