diff --git a/show/bgp_common.py b/show/bgp_common.py index 7ff859e06735..f439c97e65dd 100644 --- a/show/bgp_common.py +++ b/show/bgp_common.py @@ -330,7 +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 + found_other_parms = 0 ns_l = [] print_ns_str = False filter_by_ip = False @@ -353,26 +353,24 @@ def show_routes(args, namespace, display, verbose, ipver): else: back_end_intf_set = None # get all the other arguments except json that needs to be the last argument of the cmd if present + # For Multi-ASIC platform the support for combining routes will be supported for "show ip/v6 route" + # and optionally with specific IP address as parameter and the json option. If any other option is + # specified, the handling will always be handled by the specific namespace FRR. for arg in args: 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 - # 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 + found_other_parms = 1 + if multi_asic.is_multi_asic(): - if found_tables: - print("% Unknown command: show {} route {}".format(ipver, arg_strg)) - return - if not found_json: + if not found_json and not found_other_parms: 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 @@ -398,6 +396,13 @@ def show_routes(args, namespace, display, verbose, ipver): error_msg = output print(error_msg) return + + # Multi-asic show ip route with additional parms are handled by going to FRR directly and get those outputs from each namespace + if found_other_parms: + print("{}:".format(ns)) + print(output) + continue + route_info = json.loads(output) if filter_back_end or print_ns_str: # clean up the dictionary to remove all the nexthops that are back-end interface diff --git a/tests/conftest.py b/tests/conftest.py index f57ec4263b03..309e65f0558d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -170,8 +170,10 @@ 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_route_summary': + m_asic_json_file = 'ip_route_summary.txt' else: - bgp_mocked_json = os.path.join( + m_asic_json_file = os.path.join( test_path, 'mock_tables', 'dummy.json') def mock_run_bgp_command(vtysh_cmd, bgp_namespace): diff --git a/tests/ip_show_routes_multi_asic_test.py b/tests/ip_show_routes_multi_asic_test.py index 384cda4f6b5e..19e9137df066 100644 --- a/tests/ip_show_routes_multi_asic_test.py +++ b/tests/ip_show_routes_multi_asic_test.py @@ -91,20 +91,6 @@ def test_show_multi_asic_ipv6_route_specific( assert result.exit_code == 0 assert result.output == show_ip_route_common.show_ipv6_route_multi_asic_specific_route_output - @pytest.mark.parametrize('setup_multi_asic_bgp_instance', - ['ip_route'], indirect=['setup_multi_asic_bgp_instance']) - def test_show_multi_asic_ip_route_tables_option_err( - 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"], ["tables"]) - print("{}".format(result.output)) - assert result.exit_code == 0 - assert result.output == show_ip_route_common.show_ip_route_multi_asic_invalid_tables_cmd_err_output - # note that we purposely use the single bgp instance setup to cause trigger a param error bad # just bail out while executing in multi-asic show ipv6 route handling. # This is to test out the error parm handling code path @@ -220,6 +206,20 @@ def test_show_multi_asic_ip_route_empty_route( assert result.exit_code == 0 assert result.output == "" + @pytest.mark.parametrize('setup_multi_asic_bgp_instance', + ['ip_route_summary'], indirect=['setup_multi_asic_bgp_instance']) + def test_show_multi_asic_ip_route_summay( + 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"], ["summary"]) + print("{}".format(result.output)) + assert result.exit_code == 0 + assert result.output == show_ip_route_common.show_ip_route_summary_expected_output + @classmethod def teardown_class(cls): print("TEARDOWN") diff --git a/tests/mock_tables/asic0/ip_route_summary.txt b/tests/mock_tables/asic0/ip_route_summary.txt new file mode 100644 index 000000000000..36ca93368f04 --- /dev/null +++ b/tests/mock_tables/asic0/ip_route_summary.txt @@ -0,0 +1,8 @@ +Route Source Routes FIB (vrf default) +kernel 1 1 +connected 6 6 +static 1 0 +ebgp 6371 6371 +ibgp 88 88 +------ +Totals 6467 6466 diff --git a/tests/mock_tables/asic1/ip_route_summary.txt b/tests/mock_tables/asic1/ip_route_summary.txt new file mode 100644 index 000000000000..36ca93368f04 --- /dev/null +++ b/tests/mock_tables/asic1/ip_route_summary.txt @@ -0,0 +1,8 @@ +Route Source Routes FIB (vrf default) +kernel 1 1 +connected 6 6 +static 1 0 +ebgp 6371 6371 +ibgp 88 88 +------ +Totals 6467 6466 diff --git a/tests/mock_tables/asic2/ip_route_summary.txt b/tests/mock_tables/asic2/ip_route_summary.txt new file mode 100644 index 000000000000..1b81f29e93a3 --- /dev/null +++ b/tests/mock_tables/asic2/ip_route_summary.txt @@ -0,0 +1,8 @@ +Route Source Routes FIB (vrf default) +kernel 1 1 +connected 14 14 +static 1 0 +ebgp 42 42 +ibgp 6409 6409 +------ +Totals 6467 6466 diff --git a/tests/show_ip_route_common.py b/tests/show_ip_route_common.py index d6d82acb9c77..e18e8b0a5a15 100644 --- a/tests/show_ip_route_common.py +++ b/tests/show_ip_route_common.py @@ -584,10 +584,6 @@ dislay option 'everything' is not a valid option. """ -show_ip_route_multi_asic_invalid_tables_cmd_err_output = """\ -% Unknown command: show ip route tables -""" - show_ip_route_multi_asic_specific_route_output = """\ Routing entry for 10.0.0.4/31 Known via "connected", distance 0, metric 0, best @@ -644,3 +640,25 @@ } """ +show_ip_route_summary_expected_output = """\ +asic0: +Route Source Routes FIB (vrf default) +kernel 1 1 +connected 6 6 +static 1 0 +ebgp 6371 6371 +ibgp 88 88 +------ +Totals 6467 6466 + +asic2: +Route Source Routes FIB (vrf default) +kernel 1 1 +connected 14 14 +static 1 0 +ebgp 42 42 +ibgp 6409 6409 +------ +Totals 6467 6466 + +"""