From 85461de8bf58360b0b2d11c199030f7cb5b54011 Mon Sep 17 00:00:00 2001 From: Mykola Faryma Date: Thu, 29 Nov 2018 23:36:13 +0200 Subject: [PATCH] [eeprom] check if source exists before reading eeprom on mlnx platform Signed-off-by: Mykola Faryma --- .../x86_64-mlnx_msn2700-r0/plugins/eeprom.py | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/eeprom.py b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/eeprom.py index 351288e849..6a1b8fc414 100644 --- a/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/eeprom.py +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/plugins/eeprom.py @@ -24,12 +24,32 @@ try: except ImportError, e: raise ImportError (str(e) + "- required module not found") +SYSLOG_IDENTIFIER = "eeprom.py" +EEPROM_SYMLINK = "/bsp/eeprom/vpd_info" +CACHE_FILE = "/var/cache/sonic/decode-syseeprom/syseeprom_cache" + +def log_error(msg): + syslog.openlog(SYSLOG_IDENTIFIER) + syslog.syslog(syslog.LOG_ERR, msg) + syslog.closelog() + class board(eeprom_tlvinfo.TlvInfoDecoder): _TLV_INFO_MAX_LEN = 256 + RETRIES = 5 def __init__(self, name, path, cpld_root, ro): - self.eeprom_path = "/bsp/eeprom/vpd_info" + for attempt in range(self.RETRIES): + if not os.path.islink(EEPROM_SYMLINK): + time.sleep(1) + else: + break + + if not (os.path.islink(EEPROM_SYMLINK) or os.isfile(CACHE_FILE)): + log_error("Nowhere to read syseeprom from! No symlink or cache file found") + raise RuntimeError("No syseeprom symlink or cache file found") + + self.eeprom_path = EEPROM_SYMLINK super(board, self).__init__(self.eeprom_path, 0, '', True) def decode_eeprom(self, e):