Skip to content

Commit

Permalink
[decode-syseeprom] Add option '-d' for decode-syseeprom (sonic-net#467)
Browse files Browse the repository at this point in the history
* Option '-d' means read the EEPROM information from DB directly
* CLI "show platform syseeprom" will invoke decode-syseeprom with
  '-d' option

Signed-off-by: Kevin Wang <kevinw@mellanox.com>
  • Loading branch information
kevinwangsk authored and jleveque committed Mar 6, 2019
1 parent 1f7f44f commit 3fc45d7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
26 changes: 21 additions & 5 deletions scripts/decode-syseeprom
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ CACHE_ROOT = '/var/cache/sonic/decode-syseeprom'
CACHE_FILE = 'syseeprom_cache'

def main():

support_eeprom_db = True
if not os.geteuid() == 0:
raise RuntimeError("must be root to run")

Expand All @@ -36,6 +36,9 @@ def main():

platform_path = '/'.join([PLATFORM_ROOT, platform])

# Currently, don't support eeprom db on Arista platform
if 'arista' in platform_path:
support_eeprom_db = False
#
# Currently we only support board eeprom decode.
#
Expand All @@ -55,14 +58,16 @@ def main():
#
# execute the command
#
run(t, opts, args)
run(t, opts, args, support_eeprom_db)

#-------------------------------------------------------------------------------
#
# sets global variable "optcfg"
#
def get_cmdline_opts():
optcfg = optparse.OptionParser(usage="usage: %s [-s][-m]" % sys.argv[0])
optcfg.add_option("-d", dest="db", action="store_true",
default=False, help="print eeprom from database")
optcfg.add_option("-s", dest="serial", action="store_true",
default=False, help="print device serial number/service tag")
optcfg.add_option("-m", dest="mgmtmac", action="store_true", default=False,
Expand All @@ -75,7 +80,16 @@ def get_cmdline_opts():
#
# Run
#
def run(target, opts, args):
def run(target, opts, args, support_eeprom_db):

if support_eeprom_db and opts.db:
err = target.read_eeprom_db()
if err:
# Failed to read EEPROM information from database. Read from cache file
pass
else:
return 0

status = target.check_status()
if status <> 'ok':
sys.stderr.write("Device is not ready: " + status + "\n")
Expand Down Expand Up @@ -109,8 +123,10 @@ def run(target, opts, args):
pass

if opts.init:
return 0

err = target.update_eeprom_db(e)
if err:
print "Failed to update eeprom database"
return -1
elif opts.mgmtmac:
mm = target.mgmtaddrstr(e)
if mm != None:
Expand Down
2 changes: 1 addition & 1 deletion show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,7 @@ def summary():
@click.option('--verbose', is_flag=True, help="Enable verbose output")
def syseeprom(verbose):
"""Show system EEPROM information"""
cmd = "sudo decode-syseeprom"
cmd = "sudo decode-syseeprom -d"
run_command(cmd, display_cmd=verbose)

# 'psustatus' subcommand ("show platform psustatus")
Expand Down

0 comments on commit 3fc45d7

Please sign in to comment.