From e86e275bf5bd8c1fa6c278b8f1a9f8c227dfbd61 Mon Sep 17 00:00:00 2001 From: jingwenxie Date: Fri, 17 Feb 2023 09:24:29 +0800 Subject: [PATCH] [201811] add bgpraw to show run all (#2603) What I did Backport #2537 Add bgpraw output to show runningconfiguration all How I did it Generate bgpraw output then append it to show runnningconfiguration all's output How to verify it There is not unit test support on such old version. Manually test on 201811 image. --- show/main.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/show/main.py b/show/main.py index 34d1814973..6dbf0d9350 100755 --- a/show/main.py +++ b/show/main.py @@ -192,6 +192,11 @@ def run_command(command, display_cmd=False): sys.exit(rc) +def get_cmd_output(cmd): + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE) + return proc.communicate()[0], proc.returncode + + def get_interface_mode(): mode = os.getenv('SONIC_CLI_IFACE_MODE') if mode is None: @@ -1322,8 +1327,24 @@ def runningconfiguration(): @click.option('--verbose', is_flag=True, help="Enable verbose output") def all(verbose): """Show full running configuration""" - cmd = "sonic-cfggen -d --print-data" - run_command(cmd, display_cmd=verbose) + cmd = ['sonic-cfggen', '-d', '--print-data'] + stdout, rc = get_cmd_output(cmd) + if rc: + click.echo("Failed to get cmd output '{}':rc {}".format(cmd, rc)) + raise click.Abort() + + try: + output = json.loads(stdout) + except ValueError as e: + click.echo("Failed to load output '{}':{}".format(cmd, e)) + raise click.Abort() + + bgpraw_cmd = ['rvtysh', '-c', 'show running-config'] + bgpraw, rc = get_cmd_output(bgpraw_cmd) + if rc: + bgpraw = "" + output['bgpraw'] = bgpraw + click.echo(json.dumps(output, indent=4)) # 'acl' subcommand ("show runningconfiguration acl")