Skip to content

Commit d09667b

Browse files
authored
Multi-ASIC support for show ip(v6) route (201911 branch) (#1283)
Ported "show ip/v6 route" Multi ASIC support changes from master branch to 201911 branch.
1 parent 28399bf commit d09667b

32 files changed

+12337
-27
lines changed

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
'mock_tables/*.json',
6262
'mock_tables/asic0/*.json',
6363
'mock_tables/asic1/*.json',
64+
'mock_tables/asic2/*.json',
6465
'filter_fdb_input/*',
6566
'pfcwd_input/*',
6667
'sku_create_input/*',

show/bgp_common.py

+413
Large diffs are not rendered by default.

show/main.py

+12-18
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import subprocess
1010
import sys
1111

12+
import bgp_common
1213
import click
1314
from click_default_group import DefaultGroup
1415
from natsort import natsorted
@@ -20,6 +21,7 @@
2021
import utilities_common.cli as clicommon
2122
import utilities_common.multi_asic as multi_asic_util
2223

24+
2325
SONIC_CFGGEN_PATH = '/usr/local/bin/sonic-cfggen'
2426

2527
VLAN_SUB_INTERFACE_SEPARATOR = '.'
@@ -1333,17 +1335,13 @@ def get_bgp_peer():
13331335

13341336
@ip.command()
13351337
@click.argument('args', metavar='[IPADDRESS] [vrf <vrf_name>] [...]', nargs=-1, required=False)
1338+
@click.option('--display', '-d', 'display', default=None, show_default=False, type=str, help='all|frontend')
1339+
@click.option('--namespace', '-n', 'namespace', default=None, type=str, show_default=False, help='Namespace name or all')
13361340
@click.option('--verbose', is_flag=True, help="Enable verbose output")
1337-
def route(args, verbose):
1341+
def route(args, namespace, display, verbose):
13381342
"""Show IP (IPv4) routing table"""
1339-
cmd = 'sudo vtysh -c "show ip route'
1340-
1341-
for arg in args:
1342-
cmd += " " + str(arg)
1343-
1344-
cmd += '"'
1345-
1346-
run_command(cmd, display_cmd=verbose)
1343+
# Call common handler to handle the show ip route cmd
1344+
bgp_common.show_routes(args, namespace, display, verbose, "ip")
13471345

13481346
#
13491347
# 'prefix-list' subcommand ("show ip prefix-list")
@@ -1452,17 +1450,13 @@ def interfaces():
14521450

14531451
@ipv6.command()
14541452
@click.argument('args', metavar='[IPADDRESS] [vrf <vrf_name>] [...]', nargs=-1, required=False)
1453+
@click.option('--display', '-d', 'display', default=None, show_default=False, type=str, help='all|frontend')
1454+
@click.option('--namespace', '-n', 'namespace', default=None, type=str, show_default=False, help='Namespace name or all')
14551455
@click.option('--verbose', is_flag=True, help="Enable verbose output")
1456-
def route(args, verbose):
1456+
def route(args, namespace, display, verbose):
14571457
"""Show IPv6 routing table"""
1458-
cmd = 'sudo vtysh -c "show ipv6 route'
1459-
1460-
for arg in args:
1461-
cmd += " " + str(arg)
1462-
1463-
cmd += '"'
1464-
1465-
run_command(cmd, display_cmd=verbose)
1458+
# Call common handler to handle the show ipv6 route cmd
1459+
bgp_common.show_routes(args, namespace, display, verbose, "ipv6")
14661460

14671461

14681462
# 'protocol' command

sonic-utilities-tests/conftest.py

+71-8
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,80 @@ def setup_single_bgp_instance(request):
1717
import utilities_common.bgp_util as bgp_util
1818

1919
if request.param == 'v4':
20-
bgp_summary_json = os.path.join(
20+
bgp_mocked_json = os.path.join(
2121
test_path, 'mock_tables', 'ipv4_bgp_summary.json')
2222
elif request.param == 'v6':
23-
bgp_summary_json = os.path.join(
23+
bgp_mocked_json = os.path.join(
2424
test_path, 'mock_tables', 'ipv6_bgp_summary.json')
25+
elif request.param == 'ip_route':
26+
bgp_mocked_json = os.path.join(
27+
test_path, 'mock_tables', 'ip_route.json')
28+
elif request.param == 'ip_specific_route':
29+
bgp_mocked_json = os.path.join(
30+
test_path, 'mock_tables', 'ip_specific_route.json')
31+
elif request.param == 'ip_special_route':
32+
bgp_mocked_json = os.path.join(
33+
test_path, 'mock_tables', 'ip_special_route.json')
34+
elif request.param == 'ipv6_route':
35+
bgp_mocked_json = os.path.join(
36+
test_path, 'mock_tables', 'ipv6_route.json')
37+
elif request.param == 'ipv6_specific_route':
38+
bgp_mocked_json = os.path.join(
39+
test_path, 'mock_tables', 'ipv6_specific_route.json')
2540
else:
26-
bgp_summary_json = os.path.join(
41+
bgp_mocked_json = os.path.join(
2742
test_path, 'mock_tables', 'dummy.json')
2843

2944
def mock_run_bgp_command(vtysh_cmd, bgp_namespace):
30-
if os.path.isfile(bgp_summary_json):
31-
with open(bgp_summary_json) as json_data:
45+
if os.path.isfile(bgp_mocked_json):
46+
with open(bgp_mocked_json) as json_data:
3247
mock_frr_data = json_data.read()
3348
return mock_frr_data
3449
return ""
3550

36-
bgp_util.run_bgp_command = mock.MagicMock(
37-
return_value=mock_run_bgp_command("", ""))
51+
def mock_run_bgp_ipv6_err_command(vtysh_cmd, bgp_namespace):
52+
return "% Unknown command: show ipv6 route garbage"
53+
54+
if request.param == 'ipv6_route_err':
55+
bgp_util.run_bgp_command = mock.MagicMock(
56+
return_value=mock_run_bgp_ipv6_err_command("", ""))
57+
else:
58+
bgp_util.run_bgp_command = mock.MagicMock(
59+
return_value=mock_run_bgp_command("", ""))
60+
61+
62+
@pytest.fixture
63+
def setup_multi_asic_bgp_instance(request):
64+
import utilities_common.bgp_util as bgp_util
65+
66+
if request.param == 'ip_route':
67+
m_asic_json_file = 'ip_route.json'
68+
elif request.param == 'ip_specific_route':
69+
m_asic_json_file = 'ip_specific_route.json'
70+
elif request.param == 'ipv6_specific_route':
71+
m_asic_json_file = 'ipv6_specific_route.json'
72+
elif request.param == 'ipv6_route':
73+
m_asic_json_file = 'ipv6_route.json'
74+
else:
75+
m_asic_json_file = os.path.join(
76+
test_path, 'mock_tables', 'dummy.json')
77+
78+
def mock_run_bgp_command(vtysh_cmd, bgp_namespace):
79+
bgp_mocked_json = os.path.join(
80+
test_path, 'mock_tables', bgp_namespace, m_asic_json_file)
81+
if os.path.isfile(bgp_mocked_json):
82+
with open(bgp_mocked_json) as json_data:
83+
mock_frr_data = json_data.read()
84+
return mock_frr_data
85+
else:
86+
return ""
87+
88+
_old_run_bgp_command = bgp_util.run_bgp_command
89+
bgp_util.run_bgp_command = mock_run_bgp_command
90+
91+
yield
92+
93+
bgp_util.run_bgp_command = _old_run_bgp_command
3894

3995

4096
@pytest.fixture
@@ -45,4 +101,11 @@ def setup_bgp_commands():
45101

46102
show.ip.add_command(bgpv4)
47103
show.ipv6.add_command(bgpv6)
48-
return show
104+
return show
105+
106+
107+
@pytest.fixture
108+
def setup_ip_route_commands():
109+
import show.main as show
110+
111+
return show

0 commit comments

Comments
 (0)