From fff40512b21c5e894856a3723e52b5f711cf8edd Mon Sep 17 00:00:00 2001 From: Sudharsan Dhamal Gopalarathnam Date: Wed, 5 May 2021 10:09:52 -0700 Subject: [PATCH] Fixing serial number read to get from DB if it is populated (#1580) #### What I did Modified show version command to pick serial number from STATE_DB if it was populated instead of getting it from EEPROM. #### How I did it Check state_db to see if serial number EEPROM section is populated. If yes use the data from DB. If not, read it from the decode-syseeprom --- show/main.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/show/main.py b/show/main.py index b0b2986a7870..d0ca14650a04 100755 --- a/show/main.py +++ b/show/main.py @@ -960,8 +960,15 @@ def version(verbose): asic_type = version_info['asic_type'] asic_count = multi_asic.get_num_asics() - serial_number_cmd = "sudo decode-syseeprom -s" - serial_number = subprocess.Popen(serial_number_cmd, shell=True, text=True, stdout=subprocess.PIPE) + serial_number = None + db = SonicV2Connector() + db.connect(db.STATE_DB) + eeprom_table = db.get_all(db.STATE_DB, 'EEPROM_INFO|0x23') + if "Name" in eeprom_table and eeprom_table["Name"] == "Serial Number" and "Value" in eeprom_table: + serial_number = eeprom_table["Value"] + else: + serial_number_cmd = "sudo decode-syseeprom -s" + serial_number = subprocess.Popen(serial_number_cmd, shell=True, text=True, stdout=subprocess.PIPE).stdout.read() sys_uptime_cmd = "uptime" sys_uptime = subprocess.Popen(sys_uptime_cmd, shell=True, text=True, stdout=subprocess.PIPE) @@ -976,7 +983,7 @@ def version(verbose): click.echo("HwSKU: {}".format(hwsku)) click.echo("ASIC: {}".format(asic_type)) click.echo("ASIC Count: {}".format(asic_count)) - click.echo("Serial Number: {}".format(serial_number.stdout.read().strip())) + click.echo("Serial Number: {}".format(serial_number.strip())) click.echo("Uptime: {}".format(sys_uptime.stdout.read().strip())) click.echo("\nDocker images:") cmd = 'sudo docker images --format "table {{.Repository}}\\t{{.Tag}}\\t{{.ID}}\\t{{.Size}}"'