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 @@ -61,6 +61,7 @@
'mock_tables/*.json',
'mock_tables/asic0/*.json',
'mock_tables/asic1/*.json',
'mock_tables/asic2/*.json',
'filter_fdb_input/*',
'pfcwd_input/*']
},
Expand Down
413 changes: 413 additions & 0 deletions show/bgp_common.py

Large diffs are not rendered by default.

30 changes: 12 additions & 18 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import subprocess
import sys

import bgp_common
import click
from click_default_group import DefaultGroup
from natsort import natsorted
Expand All @@ -20,6 +21,7 @@
import utilities_common.cli as clicommon
import utilities_common.multi_asic as multi_asic_util


SONIC_CFGGEN_PATH = '/usr/local/bin/sonic-cfggen'

VLAN_SUB_INTERFACE_SEPARATOR = '.'
Expand Down Expand Up @@ -1333,17 +1335,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 @@ -1452,17 +1450,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
79 changes: 71 additions & 8 deletions sonic-utilities-tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,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:
m_asic_json_file = 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
Expand All @@ -45,4 +101,11 @@ def setup_bgp_commands():

show.ip.add_command(bgpv4)
show.ipv6.add_command(bgpv6)
return show
return show


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

return show
Loading