Skip to content

Commit

Permalink
Fixing serial number read to get from DB if it is populated (#1580)
Browse files Browse the repository at this point in the history
#### 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
  • Loading branch information
dgsudharsan authored May 5, 2021
1 parent be974bf commit fff4051
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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}}"'
Expand Down

0 comments on commit fff4051

Please sign in to comment.