Why I did it To enhance pddf_eeprom.py to use caching and fix #13835 How I did it Utilising the in-built caching mechanism in the base class eeprom_base.py. Adding a cache file to store the eeprom data. How to verify it By running 'decode-syseeprom' or 'show platform syseeprom' commands.
This commit is contained in:
parent
f822373e53
commit
d3e3565a6c
@ -6,9 +6,12 @@
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
from sonic_eeprom import eeprom_tlvinfo
|
from sonic_eeprom import eeprom_tlvinfo
|
||||||
|
import os
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
raise ImportError(str(e) + "- required module not found")
|
raise ImportError(str(e) + "- required module not found")
|
||||||
|
|
||||||
|
CACHE_ROOT = '/var/cache/sonic/decode-syseeprom'
|
||||||
|
CACHE_FILE = 'syseeprom_cache'
|
||||||
|
|
||||||
class PddfEeprom(eeprom_tlvinfo.TlvInfoDecoder):
|
class PddfEeprom(eeprom_tlvinfo.TlvInfoDecoder):
|
||||||
_TLV_INFO_MAX_LEN = 256
|
_TLV_INFO_MAX_LEN = 256
|
||||||
@ -29,6 +32,20 @@ class PddfEeprom(eeprom_tlvinfo.TlvInfoDecoder):
|
|||||||
|
|
||||||
super(PddfEeprom, self).__init__(self.eeprom_path, 0, '', True)
|
super(PddfEeprom, self).__init__(self.eeprom_path, 0, '', True)
|
||||||
self.eeprom_tlv_dict = dict()
|
self.eeprom_tlv_dict = dict()
|
||||||
|
|
||||||
|
# Create the cache directory if not created
|
||||||
|
if not os.path.exists(CACHE_ROOT):
|
||||||
|
try:
|
||||||
|
os.makedirs(CACHE_ROOT)
|
||||||
|
except Exception as e:
|
||||||
|
print("Error in creating Eeprom cache directory - {}".format(str(e)))
|
||||||
|
|
||||||
|
# Assign cache_name in eeprom_base.py
|
||||||
|
try:
|
||||||
|
self.set_cache_name(os.path.join(CACHE_ROOT, CACHE_FILE))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.eeprom_data = self.read_eeprom()
|
self.eeprom_data = self.read_eeprom()
|
||||||
except:
|
except:
|
||||||
@ -37,6 +54,11 @@ class PddfEeprom(eeprom_tlvinfo.TlvInfoDecoder):
|
|||||||
else:
|
else:
|
||||||
eeprom = self.eeprom_data
|
eeprom = self.eeprom_data
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.update_cache(eeprom)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
if not self.is_valid_tlvinfo_header(eeprom):
|
if not self.is_valid_tlvinfo_header(eeprom):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user