Fix issue: enhancing PDDF common eeprom APIs to use caching (#13835) (#13848)

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:
FuzailBrcm 2023-03-15 06:24:58 +05:30 committed by GitHub
parent f822373e53
commit d3e3565a6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,9 +6,12 @@
try:
from sonic_eeprom import eeprom_tlvinfo
import os
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
CACHE_ROOT = '/var/cache/sonic/decode-syseeprom'
CACHE_FILE = 'syseeprom_cache'
class PddfEeprom(eeprom_tlvinfo.TlvInfoDecoder):
_TLV_INFO_MAX_LEN = 256
@ -29,6 +32,20 @@ class PddfEeprom(eeprom_tlvinfo.TlvInfoDecoder):
super(PddfEeprom, self).__init__(self.eeprom_path, 0, '', True)
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:
self.eeprom_data = self.read_eeprom()
except:
@ -37,6 +54,11 @@ class PddfEeprom(eeprom_tlvinfo.TlvInfoDecoder):
else:
eeprom = self.eeprom_data
try:
self.update_cache(eeprom)
except:
pass
if not self.is_valid_tlvinfo_header(eeprom):
return