Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@
'sonic-utilities-tests': ['acl_input/*',
'mock_tables/*.py',
'mock_tables/*.json',
'mock_tables/asic0/*.json',
'mock_tables/asic1/*.json',
'mock_tables/asic2/*.json',
'mock_tables/asic0/*',
'mock_tables/asic1/*',
'mock_tables/asic2/*',
'filter_fdb_input/*',
'pfcwd_input/*',
'sku_create_input/*',
Expand Down
25 changes: 15 additions & 10 deletions show/bgp_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions sonic-utilities-tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,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_route_summary':
m_asic_json_file = 'ip_route_summary.txt'
else:
m_asic_json_file = os.path.join(
test_path, 'mock_tables', 'dummy.json')
Expand Down
28 changes: 14 additions & 14 deletions sonic-utilities-tests/ip_show_routes_multi_asic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,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
Expand Down Expand Up @@ -219,6 +205,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")
Expand Down
8 changes: 8 additions & 0 deletions sonic-utilities-tests/mock_tables/asic0/ip_route_summary.txt
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions sonic-utilities-tests/mock_tables/asic1/ip_route_summary.txt
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions sonic-utilities-tests/mock_tables/asic2/ip_route_summary.txt
Original file line number Diff line number Diff line change
@@ -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
27 changes: 23 additions & 4 deletions sonic-utilities-tests/show_ip_route_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -643,3 +639,26 @@
]
}
"""

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

"""