Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Multi-ASIC support for show ip(v6) route #1216

Merged
merged 9 commits into from
Nov 24, 2020
420 changes: 420 additions & 0 deletions show/bgp_common.py

Large diffs are not rendered by default.

29 changes: 11 additions & 18 deletions show/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import bgp_common
import json
import netaddr
import os
Expand Down Expand Up @@ -790,17 +791,13 @@ def get_bgp_peer():

@ip.command()
@click.argument('args', metavar='[IPADDRESS] [vrf <vrf_name>] [...]', nargs=-1, required=False)
@click.option('--display', '-d', 'display', default=None, show_default=False, type=str, help='all|frontend')
@click.option('--namespace', '-n', 'namespace', default=None, type=str, show_default=False, help='Namespace name or all')
@click.option('--verbose', is_flag=True, help="Enable verbose output")
def route(args, verbose):
def route(args, namespace, display, verbose):
"""Show IP (IPv4) routing table"""
cmd = 'sudo vtysh -c "show ip route'

for arg in args:
cmd += " " + str(arg)

cmd += '"'

run_command(cmd, display_cmd=verbose)
# Call common handler to handle the show ip route cmd
bgp_common.show_routes(args, namespace, display, verbose, "ip")

#
# 'prefix-list' subcommand ("show ip prefix-list")
Expand Down Expand Up @@ -913,17 +910,13 @@ def interfaces():

@ipv6.command()
@click.argument('args', metavar='[IPADDRESS] [vrf <vrf_name>] [...]', nargs=-1, required=False)
@click.option('--display', '-d', 'display', default=None, show_default=False, type=str, help='all|frontend')
@click.option('--namespace', '-n', 'namespace', default=None, type=str, show_default=False, help='Namespace name or all')
@click.option('--verbose', is_flag=True, help="Enable verbose output")
def route(args, verbose):
def route(args, namespace, display, verbose):
"""Show IPv6 routing table"""
cmd = 'sudo vtysh -c "show ipv6 route'

for arg in args:
cmd += " " + str(arg)

cmd += '"'

run_command(cmd, display_cmd=verbose)
# Call common handler to handle the show ipv6 route cmd
bgp_common.show_routes(args, namespace, display, verbose, "ipv6")


# 'protocol' command
Expand Down
76 changes: 69 additions & 7 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,80 @@ def setup_single_bgp_instance(request):
import utilities_common.bgp_util as bgp_util

if request.param == 'v4':
bgp_summary_json = os.path.join(
bgp_mocked_json = os.path.join(
test_path, 'mock_tables', 'ipv4_bgp_summary.json')
elif request.param == 'v6':
bgp_summary_json = os.path.join(
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_summary_json = os.path.join(
bgp_mocked_json = os.path.join(
test_path, 'mock_tables', 'dummy.json')

def mock_run_bgp_command(vtysh_cmd, bgp_namespace):
if os.path.isfile(bgp_summary_json):
with open(bgp_summary_json) as json_data:
if os.path.isfile(bgp_mocked_json):
with open(bgp_mocked_json) as json_data:
mock_frr_data = json_data.read()
return mock_frr_data
return ""

bgp_util.run_bgp_command = mock.MagicMock(
return_value=mock_run_bgp_command("", ""))
def mock_run_bgp_ipv6_err_command(vtysh_cmd, bgp_namespace):
return "% Unknown command: show ipv6 route garbage"

if request.param == 'ipv6_route_err':
bgp_util.run_bgp_command = mock.MagicMock(
return_value=mock_run_bgp_ipv6_err_command("", ""))
else:
bgp_util.run_bgp_command = mock.MagicMock(
return_value=mock_run_bgp_command("", ""))


@pytest.fixture
def setup_multi_asic_bgp_instance(request):
import utilities_common.bgp_util as bgp_util

if request.param == 'ip_route':
m_asic_json_file = 'ip_route.json'
elif request.param == 'ip_specific_route':
m_asic_json_file = 'ip_specific_route.json'
elif request.param == 'ipv6_specific_route':
m_asic_json_file = 'ipv6_specific_route.json'
elif request.param == 'ipv6_route':
m_asic_json_file = 'ipv6_route.json'
else:
bgp_mocked_json = os.path.join(
test_path, 'mock_tables', 'dummy.json')

def mock_run_bgp_command(vtysh_cmd, bgp_namespace):
bgp_mocked_json = os.path.join(
test_path, 'mock_tables', bgp_namespace, m_asic_json_file)
if os.path.isfile(bgp_mocked_json):
with open(bgp_mocked_json) as json_data:
mock_frr_data = json_data.read()
return mock_frr_data
else:
return ""

_old_run_bgp_command = bgp_util.run_bgp_command
bgp_util.run_bgp_command = mock_run_bgp_command

yield

bgp_util.run_bgp_command = _old_run_bgp_command

@pytest.fixture
def setup_bgp_commands():
Expand All @@ -110,3 +165,10 @@ def setup_bgp_commands():
show.ip.add_command(bgpv4)
show.ipv6.add_command(bgpv6)
return show


@pytest.fixture
def setup_ip_route_commands():
import show.main as show

return show
Loading