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
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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how are you checking for "summary" option there?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Non-multi-asic platform the parameter checking is all done by BGP itself.
For Multi-ASIC platform it currently will fail due to the added "json" parm was requested to BGP and BGP will fail the request. So there is no need to specifically check for this for now.
I will be adding the support for the Multi-ASIC platform for the "summary" option which at that time it will be inspected and handled accordingly. Not part of this PR though...

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
46 changes: 26 additions & 20 deletions sonic-utilities-tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# noinspection PyUnresolvedReferences
import mock_tables.dbconnector

import show_ip_route_common

test_path = os.path.dirname(os.path.abspath(__file__))
modules_path = os.path.dirname(test_path)
Expand All @@ -22,21 +22,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 @@ -48,12 +33,27 @@ 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 @@ -71,6 +71,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:
m_asic_json_file = os.path.join(
test_path, 'mock_tables', 'dummy.json')
Expand Down
Loading