Skip to content

Commit

Permalink
Fix Multi-ASIC show specific resursive route by using common parsing …
Browse files Browse the repository at this point in the history
…function (#1560)

* Fix Multi-ASIC show specific resursive route by using common parsing function

* Use True/False as parameter instead or 1/0
  • Loading branch information
gechiang committed Apr 15, 2021
1 parent e57e7f7 commit eba5c04
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 11 deletions.
22 changes: 11 additions & 11 deletions show/bgp_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,18 @@ def get_mpls_label_strgs(label_list):
label_str_2_return += "/" + label_string
return label_str_2_return

def get_nexthop_info_str(nxhp_info):
def get_nexthop_info_str(nxhp_info, filterByIp):
str_2_return = ""
if "ip" in nxhp_info:
str_2_return = " via {},".format(nxhp_info['ip'])
if filterByIp:
str_2_return = " * {}".format(nxhp_info['ip'])
else:
str_2_return = " via {},".format(nxhp_info['ip'])
if "interfaceName" in nxhp_info:
str_2_return += " {},".format(nxhp_info['interfaceName'])
if filterByIp:
str_2_return += ", via {}".format(nxhp_info['interfaceName'])
else:
str_2_return += " {},".format(nxhp_info['interfaceName'])
elif "directlyConnected" in nxhp_info:
str_2_return = " is directly connected,"
if "interfaceName" in nxhp_info:
Expand Down Expand Up @@ -152,13 +158,7 @@ def print_ip_routes(route_info, filter_by_ip):
if "directlyConnected" in info[i]['nexthops'][j]:
print(" * directly connected, {}\n".format(info[i]['nexthops'][j]['interfaceName']))
else:
if "ip" in info[i]['nexthops'][j]:
str_2_print = " * {}".format(info[i]['nexthops'][j]['ip'])

if "active" in info[i]['nexthops'][j]:
str_2_print += ", via {}".format(info[i]['nexthops'][j]['interfaceName'])
else:
str_2_print += " inactive"
str_2_print = get_nexthop_info_str(info[i]['nexthops'][j], True)
print(str_2_print)
print("")
else:
Expand All @@ -183,7 +183,7 @@ def print_ip_routes(route_info, filter_by_ip):
# For all subsequent nexthops skip the spacing to not repeat the prefix section
str_2_print += " "*(str_length - 3)
# Get the nexhop info portion of the string
str_2_print += get_nexthop_info_str(info[i]['nexthops'][j])
str_2_print += get_nexthop_info_str(info[i]['nexthops'][j], False)
# add uptime at the end of the string
str_2_print += " {}".format(info[i]['uptime'])
# print out this string
Expand Down
2 changes: 2 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ def setup_multi_asic_bgp_instance(request):
m_asic_json_file = 'ip_empty_route.json'
elif request.param == 'ip_specific_route_on_1_asic':
m_asic_json_file = 'ip_special_route_asic0_only.json'
elif request.param == 'ip_specific_recursive_route':
m_asic_json_file = 'ip_special_recursive_route.json'
elif request.param == 'ip_route_summary':
m_asic_json_file = 'ip_route_summary.txt'
else:
Expand Down
14 changes: 14 additions & 0 deletions tests/ip_show_routes_multi_asic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,20 @@ def test_show_multi_asic_ip_route_specific_on_1_asic(
assert result.exit_code == 0
assert result.output == show_ip_route_common.show_specific_ip_route_expected_output

@pytest.mark.parametrize('setup_multi_asic_bgp_instance',
['ip_specific_recursive_route'], indirect=['setup_multi_asic_bgp_instance'])
def test_show_multi_asic_ip_route_specific_recursive_route(
self,
setup_ip_route_commands,
setup_multi_asic_bgp_instance):
show = setup_ip_route_commands
runner = CliRunner()
result = runner.invoke(
show.cli.commands["ip"].commands["route"], ["193.11.208.0/25"])
print("{}".format(result.output))
assert result.exit_code == 0
assert result.output == show_ip_route_common.show_specific_recursive_route_expected_output

@pytest.mark.parametrize('setup_multi_asic_bgp_instance',
['ipv6_specific_route'], indirect=['setup_multi_asic_bgp_instance'])
def test_show_multi_asic_ipv6_route_specific(
Expand Down
39 changes: 39 additions & 0 deletions tests/mock_tables/asic0/ip_special_recursive_route.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"193.11.208.0/25": [
{
"destSelected": true,
"distance": 20,
"installed": true,
"internalFlags": 8,
"internalNextHopActiveNum": 2,
"internalNextHopNum": 2,
"internalStatus": 16,
"metric": 0,
"nexthops": [
{
"active": true,
"afi": "ipv4",
"fib": true,
"flags": 3,
"interfaceIndex": 728,
"interfaceName": "PortChannel0005",
"ip": "10.0.0.5"
},
{
"active": true,
"afi": "ipv4",
"fib": true,
"flags": 3,
"interfaceIndex": 727,
"interfaceName": "PortChannel0002",
"ip": "10.0.0.1"
}
],
"prefix": "193.11.208.0/25",
"protocol": "bgp",
"selected": true,
"table": 254,
"uptime": "00:14:32"
}
]
}
1 change: 1 addition & 0 deletions tests/mock_tables/asic1/ip_special_recursive_route.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
35 changes: 35 additions & 0 deletions tests/mock_tables/asic2/ip_special_recursive_route.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"193.11.208.0/25": [
{
"destSelected": true,
"distance": 20,
"installed": true,
"internalFlags": 8,
"internalNextHopActiveNum": 0,
"internalNextHopNum": 0,
"internalStatus": 16,
"metric": 0,
"nexthops": [
{
"active": true,
"afi": "ipv4",
"flags": 5,
"ip": "10.0.0.9",
"recursive": true
},
{
"active": true,
"afi": "ipv4",
"flags": 5,
"ip": "10.0.0.1",
"recursive": true
}
],
"prefix": "193.11.208.0/25",
"protocol": "bgp",
"selected": true,
"table": 254,
"uptime": "00:14:35"
}
]
}
11 changes: 11 additions & 0 deletions tests/show_ip_route_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@
"""

show_specific_recursive_route_expected_output = """\
Routing entry for 193.11.208.0/25
Known via "bgp", distance 20, metric 0, best
Last update 00:14:32 ago
* 10.0.0.1, via PortChannel0002
* 10.0.0.5, via PortChannel0005
* 10.0.0.9 (recursive)
* 10.0.0.1 (recursive)
"""

show_special_ip_route_expected_output = """\
Codes: K - kernel route, C - connected, S - static, R - RIP,
O - OSPF, I - IS-IS, B - BGP, E - EIGRP, N - NHRP,
Expand Down

0 comments on commit eba5c04

Please sign in to comment.