Skip to content

Commit

Permalink
Fix show ip route summary on pizzabox platforms (#1302)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gechiang committed Dec 11, 2020
1 parent af1bb47 commit 980ea0d
Show file tree
Hide file tree
Showing 13 changed files with 1,035 additions and 641 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
'mock_tables/*.json',
'mock_tables/asic0/*.json',
'mock_tables/asic1/*.json',
'mock_tables/asic2/*.json',
'filter_fdb_input/*',
'pfcwd_input/*',
'wm_input/*']
Expand Down
18 changes: 16 additions & 2 deletions show/bgp_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ def show_routes(args, namespace, display, verbose, ipver):
device = multi_asic_util.MultiAsic(display, namespace)
arg_strg = ""
found_json = 0
found_tables = 0
ns_l = []
print_ns_str = False
filter_by_ip = False
Expand All @@ -356,14 +357,22 @@ def show_routes(args, namespace, display, verbose, ipver):
arg_strg += str(arg) + " "
if str(arg) == "json":
found_json = 1
elif str(arg) == "tables":
found_tables = 1
else:
try:
filter_by_ip = ipaddress.ip_network(arg)
except ValueError:
# Not ip address just ignore it
pass
if not found_json:
arg_strg += "json"
# Due to options such as "summary" and "tables" are not yet supported in multi-asic platform
# we will let FRR handle all the processing instead of handling it here for non multi-asic platform
if multi_asic.is_multi_asic():
if found_tables:
print("% Unknown command: show {} route {}".format(ipver, arg_strg))
return
if not found_json:
arg_strg += "json"
combined_route = {}
for ns in ns_l:
# Need to add "ns" to form bgpX so it is sent to the correct bgpX docker to handle the request
Expand All @@ -373,6 +382,8 @@ def show_routes(args, namespace, display, verbose, ipver):
output = bgp_util.run_bgp_command(cmd, ns)
else:
output = bgp_util.run_bgp_command(cmd)
print("{}".format(output))
return

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

if not combined_route:
return

if not found_json:
#print out the header if this is not a json request
if not filter_by_ip:
Expand Down
47 changes: 27 additions & 20 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from swsssdk import ConfigDBConnector

from .mock_tables import dbconnector

from . import show_ip_route_common

test_path = os.path.dirname(os.path.abspath(__file__))
modules_path = os.path.dirname(test_path)
Expand Down Expand Up @@ -85,21 +85,6 @@ def setup_single_bgp_instance(request):
elif request.param == 'v6':
bgp_mocked_json = os.path.join(
test_path, 'mock_tables', 'ipv6_bgp_summary.json')
elif request.param == 'ip_route':
bgp_mocked_json = os.path.join(
test_path, 'mock_tables', 'ip_route.json')
elif request.param == 'ip_specific_route':
bgp_mocked_json = os.path.join(
test_path, 'mock_tables', 'ip_specific_route.json')
elif request.param == 'ip_special_route':
bgp_mocked_json = os.path.join(
test_path, 'mock_tables', 'ip_special_route.json')
elif request.param == 'ipv6_route':
bgp_mocked_json = os.path.join(
test_path, 'mock_tables', 'ipv6_route.json')
elif request.param == 'ipv6_specific_route':
bgp_mocked_json = os.path.join(
test_path, 'mock_tables', 'ipv6_specific_route.json')
else:
bgp_mocked_json = os.path.join(
test_path, 'mock_tables', 'dummy.json')
Expand All @@ -111,12 +96,28 @@ def mock_run_bgp_command(vtysh_cmd, bgp_namespace):
return mock_frr_data
return ""

def mock_run_bgp_ipv6_err_command(vtysh_cmd, bgp_namespace):
return "% Unknown command: show ipv6 route garbage"
def mock_run_show_ip_route_commands(request):
if request.param == 'ipv6_route_err':
return show_ip_route_common.show_ipv6_route_err_expected_output
elif request.param == 'ip_route':
return show_ip_route_common.show_ip_route_expected_output
elif request.param == 'ip_specific_route':
return show_ip_route_common.show_specific_ip_route_expected_output
elif request.param == 'ip_special_route':
return show_ip_route_common.show_special_ip_route_expected_output
elif request.param == 'ipv6_route':
return show_ip_route_common.show_ipv6_route_expected_output
elif request.param == 'ipv6_specific_route':
return show_ip_route_common.show_ipv6_route_single_json_expected_output
else:
return ""


if request.param == 'ipv6_route_err':
if any ([request.param == 'ipv6_route_err', request.param == 'ip_route',\
request.param == 'ip_specific_route', request.param == 'ip_special_route',\
request.param == 'ipv6_route', request.param == 'ipv6_specific_route']):
bgp_util.run_bgp_command = mock.MagicMock(
return_value=mock_run_bgp_ipv6_err_command("", ""))
return_value=mock_run_show_ip_route_commands(request))
else:
bgp_util.run_bgp_command = mock.MagicMock(
return_value=mock_run_bgp_command("", ""))
Expand All @@ -134,6 +135,12 @@ def setup_multi_asic_bgp_instance(request):
m_asic_json_file = 'ipv6_specific_route.json'
elif request.param == 'ipv6_route':
m_asic_json_file = 'ipv6_route.json'
elif request.param == 'ip_special_route':
m_asic_json_file = 'ip_special_route.json'
elif request.param == 'ip_empty_route':
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'
else:
bgp_mocked_json = os.path.join(
test_path, 'mock_tables', 'dummy.json')
Expand Down
Loading

0 comments on commit 980ea0d

Please sign in to comment.