Skip to content

Commit 980ea0d

Browse files
authored
Fix show ip route summary on pizzabox platforms (sonic-net#1302)
Handling of "show ip/v6 route xxxx" for non-multi-asic platforms to be handled by FRR completely instead of using the common code added to support multi-asic platform.
1 parent af1bb47 commit 980ea0d

13 files changed

Lines changed: 1035 additions & 641 deletions

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
'mock_tables/*.json',
5959
'mock_tables/asic0/*.json',
6060
'mock_tables/asic1/*.json',
61+
'mock_tables/asic2/*.json',
6162
'filter_fdb_input/*',
6263
'pfcwd_input/*',
6364
'wm_input/*']

show/bgp_common.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ def show_routes(args, namespace, display, verbose, ipver):
330330
device = multi_asic_util.MultiAsic(display, namespace)
331331
arg_strg = ""
332332
found_json = 0
333+
found_tables = 0
333334
ns_l = []
334335
print_ns_str = False
335336
filter_by_ip = False
@@ -356,14 +357,22 @@ def show_routes(args, namespace, display, verbose, ipver):
356357
arg_strg += str(arg) + " "
357358
if str(arg) == "json":
358359
found_json = 1
360+
elif str(arg) == "tables":
361+
found_tables = 1
359362
else:
360363
try:
361364
filter_by_ip = ipaddress.ip_network(arg)
362365
except ValueError:
363366
# Not ip address just ignore it
364367
pass
365-
if not found_json:
366-
arg_strg += "json"
368+
# Due to options such as "summary" and "tables" are not yet supported in multi-asic platform
369+
# we will let FRR handle all the processing instead of handling it here for non multi-asic platform
370+
if multi_asic.is_multi_asic():
371+
if found_tables:
372+
print("% Unknown command: show {} route {}".format(ipver, arg_strg))
373+
return
374+
if not found_json:
375+
arg_strg += "json"
367376
combined_route = {}
368377
for ns in ns_l:
369378
# Need to add "ns" to form bgpX so it is sent to the correct bgpX docker to handle the request
@@ -373,6 +382,8 @@ def show_routes(args, namespace, display, verbose, ipver):
373382
output = bgp_util.run_bgp_command(cmd, ns)
374383
else:
375384
output = bgp_util.run_bgp_command(cmd)
385+
print("{}".format(output))
386+
return
376387

377388
# in case no output or something went wrong with user specified cmd argument(s) error it out
378389
# error from FRR always start with character "%"
@@ -394,6 +405,9 @@ def show_routes(args, namespace, display, verbose, ipver):
394405
else:
395406
combined_route = route_info
396407

408+
if not combined_route:
409+
return
410+
397411
if not found_json:
398412
#print out the header if this is not a json request
399413
if not filter_by_ip:

tests/conftest.py

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from swsssdk import ConfigDBConnector
99

1010
from .mock_tables import dbconnector
11-
11+
from . import show_ip_route_common
1212

1313
test_path = os.path.dirname(os.path.abspath(__file__))
1414
modules_path = os.path.dirname(test_path)
@@ -85,21 +85,6 @@ def setup_single_bgp_instance(request):
8585
elif request.param == 'v6':
8686
bgp_mocked_json = os.path.join(
8787
test_path, 'mock_tables', 'ipv6_bgp_summary.json')
88-
elif request.param == 'ip_route':
89-
bgp_mocked_json = os.path.join(
90-
test_path, 'mock_tables', 'ip_route.json')
91-
elif request.param == 'ip_specific_route':
92-
bgp_mocked_json = os.path.join(
93-
test_path, 'mock_tables', 'ip_specific_route.json')
94-
elif request.param == 'ip_special_route':
95-
bgp_mocked_json = os.path.join(
96-
test_path, 'mock_tables', 'ip_special_route.json')
97-
elif request.param == 'ipv6_route':
98-
bgp_mocked_json = os.path.join(
99-
test_path, 'mock_tables', 'ipv6_route.json')
100-
elif request.param == 'ipv6_specific_route':
101-
bgp_mocked_json = os.path.join(
102-
test_path, 'mock_tables', 'ipv6_specific_route.json')
10388
else:
10489
bgp_mocked_json = os.path.join(
10590
test_path, 'mock_tables', 'dummy.json')
@@ -111,12 +96,28 @@ def mock_run_bgp_command(vtysh_cmd, bgp_namespace):
11196
return mock_frr_data
11297
return ""
11398

114-
def mock_run_bgp_ipv6_err_command(vtysh_cmd, bgp_namespace):
115-
return "% Unknown command: show ipv6 route garbage"
99+
def mock_run_show_ip_route_commands(request):
100+
if request.param == 'ipv6_route_err':
101+
return show_ip_route_common.show_ipv6_route_err_expected_output
102+
elif request.param == 'ip_route':
103+
return show_ip_route_common.show_ip_route_expected_output
104+
elif request.param == 'ip_specific_route':
105+
return show_ip_route_common.show_specific_ip_route_expected_output
106+
elif request.param == 'ip_special_route':
107+
return show_ip_route_common.show_special_ip_route_expected_output
108+
elif request.param == 'ipv6_route':
109+
return show_ip_route_common.show_ipv6_route_expected_output
110+
elif request.param == 'ipv6_specific_route':
111+
return show_ip_route_common.show_ipv6_route_single_json_expected_output
112+
else:
113+
return ""
114+
116115

117-
if request.param == 'ipv6_route_err':
116+
if any ([request.param == 'ipv6_route_err', request.param == 'ip_route',\
117+
request.param == 'ip_specific_route', request.param == 'ip_special_route',\
118+
request.param == 'ipv6_route', request.param == 'ipv6_specific_route']):
118119
bgp_util.run_bgp_command = mock.MagicMock(
119-
return_value=mock_run_bgp_ipv6_err_command("", ""))
120+
return_value=mock_run_show_ip_route_commands(request))
120121
else:
121122
bgp_util.run_bgp_command = mock.MagicMock(
122123
return_value=mock_run_bgp_command("", ""))
@@ -134,6 +135,12 @@ def setup_multi_asic_bgp_instance(request):
134135
m_asic_json_file = 'ipv6_specific_route.json'
135136
elif request.param == 'ipv6_route':
136137
m_asic_json_file = 'ipv6_route.json'
138+
elif request.param == 'ip_special_route':
139+
m_asic_json_file = 'ip_special_route.json'
140+
elif request.param == 'ip_empty_route':
141+
m_asic_json_file = 'ip_empty_route.json'
142+
elif request.param == 'ip_specific_route_on_1_asic':
143+
m_asic_json_file = 'ip_special_route_asic0_only.json'
137144
else:
138145
bgp_mocked_json = os.path.join(
139146
test_path, 'mock_tables', 'dummy.json')

0 commit comments

Comments
 (0)