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
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