Skip to content

Commit eba5c04

Browse files
authored
Fix Multi-ASIC show specific resursive route by using common parsing function (#1560)
* Fix Multi-ASIC show specific resursive route by using common parsing function * Use True/False as parameter instead or 1/0
1 parent e57e7f7 commit eba5c04

7 files changed

+113
-11
lines changed

show/bgp_common.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,18 @@ def get_mpls_label_strgs(label_list):
5252
label_str_2_return += "/" + label_string
5353
return label_str_2_return
5454

55-
def get_nexthop_info_str(nxhp_info):
55+
def get_nexthop_info_str(nxhp_info, filterByIp):
5656
str_2_return = ""
5757
if "ip" in nxhp_info:
58-
str_2_return = " via {},".format(nxhp_info['ip'])
58+
if filterByIp:
59+
str_2_return = " * {}".format(nxhp_info['ip'])
60+
else:
61+
str_2_return = " via {},".format(nxhp_info['ip'])
5962
if "interfaceName" in nxhp_info:
60-
str_2_return += " {},".format(nxhp_info['interfaceName'])
63+
if filterByIp:
64+
str_2_return += ", via {}".format(nxhp_info['interfaceName'])
65+
else:
66+
str_2_return += " {},".format(nxhp_info['interfaceName'])
6167
elif "directlyConnected" in nxhp_info:
6268
str_2_return = " is directly connected,"
6369
if "interfaceName" in nxhp_info:
@@ -152,13 +158,7 @@ def print_ip_routes(route_info, filter_by_ip):
152158
if "directlyConnected" in info[i]['nexthops'][j]:
153159
print(" * directly connected, {}\n".format(info[i]['nexthops'][j]['interfaceName']))
154160
else:
155-
if "ip" in info[i]['nexthops'][j]:
156-
str_2_print = " * {}".format(info[i]['nexthops'][j]['ip'])
157-
158-
if "active" in info[i]['nexthops'][j]:
159-
str_2_print += ", via {}".format(info[i]['nexthops'][j]['interfaceName'])
160-
else:
161-
str_2_print += " inactive"
161+
str_2_print = get_nexthop_info_str(info[i]['nexthops'][j], True)
162162
print(str_2_print)
163163
print("")
164164
else:
@@ -183,7 +183,7 @@ def print_ip_routes(route_info, filter_by_ip):
183183
# For all subsequent nexthops skip the spacing to not repeat the prefix section
184184
str_2_print += " "*(str_length - 3)
185185
# Get the nexhop info portion of the string
186-
str_2_print += get_nexthop_info_str(info[i]['nexthops'][j])
186+
str_2_print += get_nexthop_info_str(info[i]['nexthops'][j], False)
187187
# add uptime at the end of the string
188188
str_2_print += " {}".format(info[i]['uptime'])
189189
# print out this string

tests/conftest.py

+2
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ def setup_multi_asic_bgp_instance(request):
170170
m_asic_json_file = 'ip_empty_route.json'
171171
elif request.param == 'ip_specific_route_on_1_asic':
172172
m_asic_json_file = 'ip_special_route_asic0_only.json'
173+
elif request.param == 'ip_specific_recursive_route':
174+
m_asic_json_file = 'ip_special_recursive_route.json'
173175
elif request.param == 'ip_route_summary':
174176
m_asic_json_file = 'ip_route_summary.txt'
175177
else:

tests/ip_show_routes_multi_asic_test.py

+14
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,20 @@ def test_show_multi_asic_ip_route_specific_on_1_asic(
7777
assert result.exit_code == 0
7878
assert result.output == show_ip_route_common.show_specific_ip_route_expected_output
7979

80+
@pytest.mark.parametrize('setup_multi_asic_bgp_instance',
81+
['ip_specific_recursive_route'], indirect=['setup_multi_asic_bgp_instance'])
82+
def test_show_multi_asic_ip_route_specific_recursive_route(
83+
self,
84+
setup_ip_route_commands,
85+
setup_multi_asic_bgp_instance):
86+
show = setup_ip_route_commands
87+
runner = CliRunner()
88+
result = runner.invoke(
89+
show.cli.commands["ip"].commands["route"], ["193.11.208.0/25"])
90+
print("{}".format(result.output))
91+
assert result.exit_code == 0
92+
assert result.output == show_ip_route_common.show_specific_recursive_route_expected_output
93+
8094
@pytest.mark.parametrize('setup_multi_asic_bgp_instance',
8195
['ipv6_specific_route'], indirect=['setup_multi_asic_bgp_instance'])
8296
def test_show_multi_asic_ipv6_route_specific(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"193.11.208.0/25": [
3+
{
4+
"destSelected": true,
5+
"distance": 20,
6+
"installed": true,
7+
"internalFlags": 8,
8+
"internalNextHopActiveNum": 2,
9+
"internalNextHopNum": 2,
10+
"internalStatus": 16,
11+
"metric": 0,
12+
"nexthops": [
13+
{
14+
"active": true,
15+
"afi": "ipv4",
16+
"fib": true,
17+
"flags": 3,
18+
"interfaceIndex": 728,
19+
"interfaceName": "PortChannel0005",
20+
"ip": "10.0.0.5"
21+
},
22+
{
23+
"active": true,
24+
"afi": "ipv4",
25+
"fib": true,
26+
"flags": 3,
27+
"interfaceIndex": 727,
28+
"interfaceName": "PortChannel0002",
29+
"ip": "10.0.0.1"
30+
}
31+
],
32+
"prefix": "193.11.208.0/25",
33+
"protocol": "bgp",
34+
"selected": true,
35+
"table": 254,
36+
"uptime": "00:14:32"
37+
}
38+
]
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"193.11.208.0/25": [
3+
{
4+
"destSelected": true,
5+
"distance": 20,
6+
"installed": true,
7+
"internalFlags": 8,
8+
"internalNextHopActiveNum": 0,
9+
"internalNextHopNum": 0,
10+
"internalStatus": 16,
11+
"metric": 0,
12+
"nexthops": [
13+
{
14+
"active": true,
15+
"afi": "ipv4",
16+
"flags": 5,
17+
"ip": "10.0.0.9",
18+
"recursive": true
19+
},
20+
{
21+
"active": true,
22+
"afi": "ipv4",
23+
"flags": 5,
24+
"ip": "10.0.0.1",
25+
"recursive": true
26+
}
27+
],
28+
"prefix": "193.11.208.0/25",
29+
"protocol": "bgp",
30+
"selected": true,
31+
"table": 254,
32+
"uptime": "00:14:35"
33+
}
34+
]
35+
}

tests/show_ip_route_common.py

+11
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,17 @@
9393
9494
"""
9595

96+
show_specific_recursive_route_expected_output = """\
97+
Routing entry for 193.11.208.0/25
98+
Known via "bgp", distance 20, metric 0, best
99+
Last update 00:14:32 ago
100+
* 10.0.0.1, via PortChannel0002
101+
* 10.0.0.5, via PortChannel0005
102+
* 10.0.0.9 (recursive)
103+
* 10.0.0.1 (recursive)
104+
105+
"""
106+
96107
show_special_ip_route_expected_output = """\
97108
Codes: K - kernel route, C - connected, S - static, R - RIP,
98109
O - OSPF, I - IS-IS, B - BGP, E - EIGRP, N - NHRP,

0 commit comments

Comments
 (0)