Skip to content
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

[show] Fix exception error for "show ip route vrf all" #3482

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MuLinForest
Copy link
Contributor

What I did

Fix the unexpected exception error that appears when the interface is not resolved, causing the key for interfaceName to be missing in the case of static route configuration.

How I did it

Handle the case where interface_name is missing.

How to verify it

Previous command output (if the output of a command-line utility has changed)

VRF Vrf1:
C>*192.168.1.0/24 is directly connected, Vlan1, 00:02:36
K>*192.168.1.254/32 [0/0] is directly connected, Vlan1, 00:04:54
Traceback (most recent call last):
  File "/usr/local/bin/show", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.9/dist-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.9/dist-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.9/dist-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.9/dist-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.9/dist-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/click/decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/show/main.py", line 1043, in route
    bgp_common.show_routes(args, namespace, display, verbose, "ip")
  File "/usr/local/lib/python3.9/dist-packages/show/bgp_common.py", line 474, in show_routes
    print_ip_routes(combined_route, filter_by_ip)
  File "/usr/local/lib/python3.9/dist-packages/show/bgp_common.py", line 189, in print_ip_routes
    str_2_print += get_nexthop_info_str(info[i]['nexthops'][j], False)
  File "/usr/local/lib/python3.9/dist-packages/show/bgp_common.py", line 80, in get_nexthop_info_str
    str_2_return += "(vrf {}, {},".format(nxhp_info['vrf'], nxhp_info['interfaceName'])
KeyError: 'interfaceName'

New command output (if the output of a command-line utility has changed)

VRF Vrf1:
C>*192.168.1.0/24 is directly connected, Vlan1, 00:00:42
K>*192.168.1.254/32 [0/0] is directly connected, Vlan1, 00:01:45
S 192.168.2.0/24 [1/0] via 192.168.2.1 (vrf Vrf2) inactive, 00:00:28

- Fix the unexpected exception error that appears when running "show ip route vrf all" when key 'interfaceName' does not exist.
- Revise some output formats to ensure brackets are properly paired.

Signed-off-by: mulin_huang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant