Skip to content

[show]: Fix show ip route result in "alias" naming mode #1327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions utilities_common/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)

Expand Down