Skip to content

Commit fc2e9e2

Browse files
[eeprom_tlv_info] Optimize EEPROM data process by using visitor pattern (sonic-net#193)
Remove EEPROM cache file and use DB instead 1. Use visitor pattern accessing EEPROM data 2. Provide utility functions to access redis data base
1 parent 295b68c commit fc2e9e2

3 files changed

Lines changed: 204 additions & 104 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ sonic_platform_common.egg-info/
1111
# Unit test / coverage reports
1212
.coverage
1313
htmlcov/
14+
coverage.xml
15+
test-results.xml

sonic_platform_base/sonic_eeprom/eeprom_base.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ def __init__(self, path, format, start, status, readonly):
2727
self.s = start
2828
self.u = status
2929
self.r = readonly
30+
# Warning: the following members are deprecated, the parsed EEPROM data is stored in the
31+
# Redis STATE_DB, cached data should be fetched from STATE_DB.EEPROM_INFO.
3032
self.cache_name = None
3133
self.cache_update_needed = False
3234
self.lock_file = None
@@ -47,6 +49,9 @@ def check_status(self):
4749
return 'ok'
4850

4951
def set_cache_name(self, name):
52+
# Warning: this method is deprecated, the parsed EEPROM data is stored in the
53+
# Redis STATE_DB, cached data should be fetched from STATE_DB.EEPROM_INFO.
54+
5055
# before accessing the eeprom we acquire an exclusive lock on the eeprom file.
5156
# this will prevent a race condition where multiple instances of this app
5257
# could try to update the cache at the same time
@@ -214,6 +219,9 @@ def open_eeprom(self):
214219
using_eeprom = True
215220
eeprom_file = self.p
216221
try:
222+
# Warning: cache file is deprecated, the parsed EEPROM data is stored in the
223+
# Redis STATE_DB, cached data should be fetched from STATE_DB.EEPROM_INFO. This
224+
# code need to be adjusted once cache file is completely removing from the system.
217225
if os.path.isfile(self.cache_name):
218226
eeprom_file = self.cache_name
219227
using_eeprom = False
@@ -240,6 +248,9 @@ def read_eeprom_bytes(self, byteCount, offset=0):
240248
# expect, the file may be corrupt. Delete it and try again, this
241249
# time reading from the actual EEPROM.
242250
if len(o) != byteCount and not self.cache_update_needed:
251+
# Warning: cache file is deprecated, the parsed EEPROM data is stored in the
252+
# Redis STATE_DB, cached data should be fetched from STATE_DB.EEPROM_INFO. This
253+
# code needs to be adjusted once cache file is completely removed from the system.
243254
os.remove(self.cache_name)
244255
self.cache_update_needed = True
245256
F.close()
@@ -277,6 +288,9 @@ def write_eeprom(self, e):
277288
self.write_cache(e)
278289

279290
def write_cache(self, e):
291+
# Warning: this method is deprecated, the parsed EEPROM data is stored in the
292+
# Redis STATE_DB, cached data should be fetched from STATE_DB.EEPROM_INFO.
293+
280294
if self.cache_name:
281295
F = None
282296
try:
@@ -290,6 +304,9 @@ def write_cache(self, e):
290304
F.close()
291305

292306
def update_cache(self, e):
307+
# Warning: this method is deprecated, the parsed EEPROM data is stored in the
308+
# Redis STATE_DB, cached data should be fetched from STATE_DB.EEPROM_INFO.
309+
293310
if self.cache_update_needed:
294311
self.write_cache(e)
295312
fcntl.flock(self.lock_file, fcntl.LOCK_UN)

0 commit comments

Comments
 (0)