From 6d90f4db81df70cc6d955e1451df12e606210b02 Mon Sep 17 00:00:00 2001 From: Walter Doekes Date: Tue, 19 Nov 2024 11:11:39 +0100 Subject: [PATCH] [broadcom] Add broadcom ASIC info to "show version" click command ==== 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. --- show/main.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/show/main.py b/show/main.py index 370798d219..796c6a3641 100755 --- a/show/main.py +++ b/show/main.py @@ -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) @@ -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'])) @@ -1506,6 +1520,31 @@ 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") #