From 8d54f86b89c6065da7ed0a86e344075c23c25a60 Mon Sep 17 00:00:00 2001 From: Maksym Belei Date: Tue, 22 Dec 2020 17:06:03 +0200 Subject: [PATCH] [show]: Fix show ip route result in "alias" naming mode * Adding case for "show ip route" command for naming mode "alias" to display proper result, instead of json table Signed-off-by: Maksym Belei --- utilities_common/cli.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/utilities_common/cli.py b/utilities_common/cli.py index f521a576b8..fb5c1ea814 100644 --- a/utilities_common/cli.py +++ b/utilities_common/cli.py @@ -375,10 +375,20 @@ def print_output_in_alias_mode(output, index): def run_command_in_alias_mode(command): """Run command and replace all instances of SONiC interface names in output with vendor-sepecific interface aliases. + Returns output for "show ip route" command, print output for the + rest of commands. """ process = subprocess.Popen(command, shell=True, text=True, stdout=subprocess.PIPE) + if "show ip route" in command: + """Show ip route""" + output = process.communicate()[0] + for port_name in iface_alias_converter.port_dict: + if port_name in output: + output = output.replace(port_name, iface_alias_converter.name_to_alias(port_name)) + return output + while True: output = process.stdout.readline() if output == '' and process.poll() is not None: @@ -504,8 +514,12 @@ def run_command(command, display_cmd=False, ignore_error=False, return_cmd=False # No conversion needed for intfutil commands as it already displays # both SONiC interface name and alias name for all interfaces. if get_interface_naming_mode() == "alias" and not command.startswith("intfutil"): - run_command_in_alias_mode(command) - sys.exit(0) + # in case of "show ip route" command, perform the command and return execution result + return_output = run_command_in_alias_mode(command) + if return_cmd and return_output: + return return_output + else: + sys.exit(0) proc = subprocess.Popen(command, shell=True, text=True, stdout=subprocess.PIPE)