[Mellanox] Remove eeprom cache file when first time init eeprom object (#6071)
EEPROM cache file is not refreshed after install a new ONIE version even if the eeprom data is updated. The current Eeprom class always try to read from the cache file when the file exists. The PR is aimed to fix it.
This commit is contained in:
parent
3a24e7f31f
commit
8f45bfa1be
@ -13,11 +13,15 @@ import sys
|
|||||||
import re
|
import re
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
|
|
||||||
|
from sonic_py_common.logger import Logger
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from sonic_platform_base.sonic_eeprom import eeprom_tlvinfo
|
from sonic_platform_base.sonic_eeprom import eeprom_tlvinfo
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
raise ImportError (str(e) + "- required module not found")
|
raise ImportError (str(e) + "- required module not found")
|
||||||
|
|
||||||
|
logger = Logger()
|
||||||
|
|
||||||
#
|
#
|
||||||
# CACHE_XXX stuffs are supposted to be moved to the base classes
|
# CACHE_XXX stuffs are supposted to be moved to the base classes
|
||||||
# since they are common for all vendors
|
# since they are common for all vendors
|
||||||
@ -59,14 +63,22 @@ class Eeprom(eeprom_tlvinfo.TlvInfoDecoder):
|
|||||||
self._eeprom_loaded = True
|
self._eeprom_loaded = True
|
||||||
|
|
||||||
def _load_eeprom(self):
|
def _load_eeprom(self):
|
||||||
|
cache_file = os.path.join(CACHE_ROOT, CACHE_FILE)
|
||||||
if not os.path.exists(CACHE_ROOT):
|
if not os.path.exists(CACHE_ROOT):
|
||||||
try:
|
try:
|
||||||
os.makedirs(CACHE_ROOT)
|
os.makedirs(CACHE_ROOT)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
# Make sure first time always read eeprom data from hardware
|
||||||
|
if os.path.exists(cache_file):
|
||||||
|
os.remove(cache_file)
|
||||||
|
except Exception as e:
|
||||||
|
logger.log_error('Failed to remove cache file {} - {}'.format(cache_file, repr(e)))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.set_cache_name(os.path.join(CACHE_ROOT, CACHE_FILE))
|
self.set_cache_name(cache_file)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user