Skip to content

Commit

Permalink
[Mellanox] Remove eeprom cache file when first time init eeprom object (
Browse files Browse the repository at this point in the history
#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.
  • Loading branch information
Junchao-Mellanox authored Dec 1, 2020
1 parent 165cae7 commit 6399258
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion platform/mellanox/mlnx-platform-api/sonic_platform/eeprom.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@
else:
from cStringIO import StringIO

from sonic_py_common.logger import Logger

try:
from sonic_platform_base.sonic_eeprom import eeprom_tlvinfo
except ImportError as e:
raise ImportError (str(e) + "- required module not found")

logger = Logger()

#
# CACHE_XXX stuffs are supposted to be moved to the base classes
# since they are common for all vendors
Expand Down Expand Up @@ -60,14 +64,22 @@ def __init__(self):
self._eeprom_loaded = True

def _load_eeprom(self):
cache_file = os.path.join(CACHE_ROOT, CACHE_FILE)
if not os.path.exists(CACHE_ROOT):
try:
os.makedirs(CACHE_ROOT)
except:
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:
self.set_cache_name(os.path.join(CACHE_ROOT, CACHE_FILE))
self.set_cache_name(cache_file)
except:
pass

Expand Down

0 comments on commit 6399258

Please sign in to comment.