Skip to content

Commit

Permalink
[broadcom] Add broadcom ASIC info to "show version" click command
Browse files Browse the repository at this point in the history
==== What I did

When the ASIC platform is broadcom, expand the "show version" output
with additional versions. This helps keeping track of different
versions when building/testing.

==== How I did it

Added _get_broadcom_info() function that calls 'bcmcmd' with 'bsv' and
'show unit'.

==== How to verify it

Run "show version" on a device with broadcom ASIC and observe how it now
lists this:

     # show version

     SONiC Software Version: SONiC.master.0-123456789
     SONiC OS Version: 12
     Distribution: Debian 12.8
     Kernel: 6.1.0-22-2-amd64
     Build commit: 123456789
     Build date: Tue Nov 12 15:28:30 UTC 2024
     Built by: sonic-builder

     Platform: x86_64-accton_as9716_32d-r0
     HwSKU: Accton-AS9716-32D
     ASIC: broadcom
     ASIC Count: 1
    +ASIC API BRCM SAI ver: [10.1.42.0]
    +ASIC API OCP SAI ver: [1.13.2]
    +ASIC API SDK ver: [sdk-6.5.29]
    +ASIC Model: Unit 0 chip BCM56980_B0 (current)
     Serial Number: ...

On other platforms, that info will not be added. On any regular failure
(command not found, permission denied, command rejected, unexpected
output), show version will still complete.
  • Loading branch information
wdoekes committed Nov 19, 2024
1 parent 2cbfcc9 commit 8ef76b9
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,18 @@ def version(verbose):
platform_info = device_info.get_platform_info()
chassis_info = platform.get_chassis_info()

if platform_info['asic_type'] == 'broadcom':
asic_info = _get_broadcom_info()
asic_info_str = []
asic_info_str.extend(
# NOTE: No ':' because that is in the output as well.
["ASIC API {}".format(line) for line in asic_info['versions']])
asic_info_str.extend(
["ASIC Model: {}".format(line) for line in asic_info['units']])
asic_info_str = '\n'.join(asic_info_str)
else:
asic_info = None

sys_uptime_cmd = ["uptime"]
sys_uptime = subprocess.Popen(sys_uptime_cmd, text=True, stdout=subprocess.PIPE)

Expand All @@ -1496,6 +1508,8 @@ def version(verbose):
click.echo("HwSKU: {}".format(platform_info['hwsku']))
click.echo("ASIC: {}".format(platform_info['asic_type']))
click.echo("ASIC Count: {}".format(platform_info['asic_count']))
if asic_info:
click.echo(asic_info_str)
click.echo("Serial Number: {}".format(chassis_info['serial']))
click.echo("Model Number: {}".format(chassis_info['model']))
click.echo("Hardware Revision: {}".format(chassis_info['revision']))
Expand All @@ -1506,6 +1520,30 @@ def version(verbose):
p = subprocess.Popen(cmd, text=True, stdout=subprocess.PIPE)
click.echo(p.stdout.read())

def _get_broadcom_info():
def _bcmcmd(command):
try:
res = subprocess.check_output(
# NOTE: There's also -n $UNIT in the bcmcmd shell script.
['bcmcmd', '-t', '1', command],
stderr=subprocess.DEVNULL, text=True)
except (FileNotFoundError, PermissionError, subprocess.CalledProcessError) as e:
res = str(e)
lines = [
line.strip() for line in res.split('\n')
if line.strip() not in (
'', command, 'drivshell>')]
res = '\n'.join(lines)
return res

ret = {
# Slow: these calls easily take 2x300ms.
'versions': _bcmcmd('bsv').replace('\n', ' ').split(', '),
'units': _bcmcmd('show unit').split('\n'),
# 'monitor_version': _bcmcmd('ver'),
}
return ret

#
# 'environment' command ("show environment")
#
Expand Down

0 comments on commit 8ef76b9

Please sign in to comment.