Skip to content

Commit 8a76099

Browse files
wenyiz2021isabelmsft
authored andcommitted
[masic support] 'show run bgp' support for multi-asic (sonic-net#2427)
Support 'show run bgp' for multi-asics Add mock tables and UTs for single-asic, multi-asic, bgp not running cases
1 parent 370fe81 commit 8a76099

7 files changed

+368
-4
lines changed

show/main.py

+34-4
Original file line numberDiff line numberDiff line change
@@ -1439,10 +1439,40 @@ def ports(portname, verbose):
14391439
# 'bgp' subcommand ("show runningconfiguration bgp")
14401440
@runningconfiguration.command()
14411441
@click.option('--verbose', is_flag=True, help="Enable verbose output")
1442-
def bgp(verbose):
1443-
"""Show BGP running configuration"""
1444-
cmd = 'sudo {} -c "show running-config"'.format(constants.RVTYSH_COMMAND)
1445-
run_command(cmd, display_cmd=verbose)
1442+
@click.option('--namespace', '-n', 'namespace', required=False, default=None, type=str, show_default=False,
1443+
help='Option needed for multi-asic only: provide namespace name',
1444+
callback=multi_asic_util.multi_asic_namespace_validation_callback)
1445+
def bgp(namespace, verbose):
1446+
"""
1447+
Show BGP running configuration
1448+
Note:
1449+
multi-asic can run 'show run bgp' and show from all asics, or 'show run bgp -n <ns>'
1450+
single-asic only run 'show run bgp', '-n' is not available
1451+
"""
1452+
1453+
if multi_asic.is_multi_asic():
1454+
if namespace and namespace not in multi_asic.get_namespace_list():
1455+
ctx = click.get_current_context()
1456+
ctx.fail("invalid value for -n/--namespace option. provide namespace from list {}".format(multi_asic.get_namespace_list()))
1457+
if not multi_asic.is_multi_asic() and namespace:
1458+
ctx = click.get_current_context()
1459+
ctx.fail("-n/--namespace is not available for single asic")
1460+
1461+
output = ""
1462+
cmd = "show running-config bgp"
1463+
import utilities_common.bgp_util as bgp_util
1464+
if multi_asic.is_multi_asic():
1465+
if not namespace:
1466+
ns_list = multi_asic.get_namespace_list()
1467+
for ns in ns_list:
1468+
output += "\n------------Showing running config bgp on {}------------\n".format(ns)
1469+
output += bgp_util.run_bgp_show_command(cmd, ns)
1470+
else:
1471+
output += "\n------------Showing running config bgp on {}------------\n".format(namespace)
1472+
output += bgp_util.run_bgp_show_command(cmd, namespace)
1473+
else:
1474+
output += bgp_util.run_bgp_show_command(cmd)
1475+
print(output)
14461476

14471477

14481478
# 'interfaces' subcommand ("show runningconfiguration interfaces")

tests/conftest.py

+17
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ def setup_single_bgp_instance(request):
169169
elif request.param == 'v6':
170170
bgp_mocked_json = os.path.join(
171171
test_path, 'mock_tables', 'ipv6_bgp_summary.json')
172+
elif request.param == 'show_run_bgp':
173+
bgp_mocked_json = os.path.join(
174+
test_path, 'mock_tables', 'show_run_bgp.txt')
172175
elif request.param == 'ip_route':
173176
bgp_mocked_json = 'ip_route.json'
174177
elif request.param == 'ip_specific_route':
@@ -193,6 +196,13 @@ def mock_show_bgp_summary(vtysh_cmd, bgp_namespace, vtysh_shell_cmd=constants.RV
193196
return mock_frr_data
194197
return ""
195198

199+
def mock_show_run_bgp(request):
200+
if os.path.isfile(bgp_mocked_json):
201+
with open(bgp_mocked_json) as json_data:
202+
mock_frr_data = json_data.read()
203+
return mock_frr_data
204+
return ""
205+
196206
def mock_run_bgp_command_for_static(vtysh_cmd, bgp_namespace="", vtysh_shell_cmd=constants.RVTYSH_COMMAND):
197207
if vtysh_cmd == "show ip route vrf all static":
198208
return config_int_ip_common.show_ip_route_with_static_expected_output
@@ -239,6 +249,9 @@ def mock_run_bgp_command(vtysh_cmd, bgp_namespace, vtysh_shell_cmd=constants.RVT
239249
elif request.param == "show_bgp_summary_no_neigh":
240250
bgp_util.run_bgp_command = mock.MagicMock(
241251
return_value=mock_show_bgp_summary_no_neigh("", ""))
252+
elif request.param.startswith('show_run_bgp'):
253+
bgp_util.run_bgp_command = mock.MagicMock(
254+
return_value=mock_show_run_bgp(request))
242255
else:
243256
bgp_util.run_bgp_command = mock.MagicMock(
244257
return_value=mock_show_bgp_summary("", ""))
@@ -270,6 +283,10 @@ def setup_multi_asic_bgp_instance(request):
270283
m_asic_json_file = 'ip_special_recursive_route.json'
271284
elif request.param == 'ip_route_summary':
272285
m_asic_json_file = 'ip_route_summary.txt'
286+
elif request.param == 'show_run_bgp':
287+
m_asic_json_file = 'show_run_bgp.txt'
288+
elif request.param == 'show_not_running_bgp':
289+
m_asic_json_file = 'show_not_running_bgp.txt'
273290
elif request.param.startswith('bgp_v4_network') or \
274291
request.param.startswith('bgp_v6_network') or \
275292
request.param.startswith('bgp_v4_neighbor') or \
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Error response from daemon: Container 70e3d3bafd1ab5faf796892acff3e2ccbea3dcd5dcfefcc34f25f7cc916b67bb is not running
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
neighbor 10.0.0.1 remote-as 65200
2+
neighbor 10.0.0.1 peer-group TIER2_V4
3+
neighbor 10.0.0.1 description ARISTA01T2
4+
neighbor 10.0.0.5 remote-as 65200
5+
neighbor 10.0.0.5 peer-group TIER2_V4
6+
neighbor 10.0.0.5 description ARISTA03T2
7+
neighbor fc00::2 remote-as 65200
8+
neighbor fc00::2 peer-group TIER2_V6
9+
neighbor fc00::2 description ARISTA01T2
10+
neighbor fc00::6 remote-as 65200
11+
neighbor fc00::6 peer-group TIER2_V6
12+
neighbor fc00::6 description ARISTA03T2
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
neighbor 10.0.0.9 remote-as 65200
2+
neighbor 10.0.0.9 peer-group TIER2_V4
3+
neighbor 10.0.0.9 description ARISTA05T2
4+
neighbor 10.0.0.13 remote-as 65200
5+
neighbor 10.0.0.13 peer-group TIER2_V4
6+
neighbor 10.0.0.13 description ARISTA07T2
7+
neighbor fc00::a remote-as 65200
8+
neighbor fc00::a peer-group TIER2_V6
9+
neighbor fc00::a description ARISTA05T2
10+
neighbor fc00::e remote-as 65200
11+
neighbor fc00::e peer-group TIER2_V6
12+
neighbor fc00::e description ARISTA07T2

tests/mock_tables/show_run_bgp.txt

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
router bgp 65100
2+
bgp router-id 10.1.0.32
3+
bgp log-neighbor-changes
4+
no bgp ebgp-requires-policy
5+
no bgp default ipv4-unicast
6+
bgp graceful-restart restart-time 240
7+
bgp graceful-restart select-defer-time 45
8+
bgp graceful-restart
9+
bgp graceful-restart preserve-fw-state
10+
bgp bestpath as-path multipath-relax
11+
neighbor BGPSLBPassive peer-group
12+
neighbor BGPSLBPassive remote-as 65432
13+
neighbor BGPSLBPassive passive
14+
neighbor BGPSLBPassive ebgp-multihop 255
15+
neighbor BGPSLBPassive update-source 10.1.0.32
16+
neighbor BGPVac peer-group
17+
neighbor BGPVac remote-as 65432
18+
neighbor BGPVac passive
19+
neighbor BGPVac ebgp-multihop 255
20+
neighbor BGPVac update-source 10.1.0.32
21+
neighbor PEER_V4 peer-group
22+
neighbor PEER_V6 peer-group
23+
neighbor 10.0.0.57 remote-as 64600
24+
neighbor 10.0.0.57 peer-group PEER_V4
25+
neighbor 10.0.0.57 description ARISTA01T1
26+
neighbor 10.0.0.57 timers 3 10
27+
neighbor 10.0.0.57 timers connect 10
28+
neighbor 10.0.0.59 remote-as 64600
29+
neighbor 10.0.0.59 peer-group PEER_V4
30+
neighbor 10.0.0.59 description ARISTA02T1
31+
neighbor 10.0.0.59 timers 3 10
32+
neighbor 10.0.0.59 timers connect 10
33+
neighbor 10.0.0.61 remote-as 64600
34+
neighbor 10.0.0.61 peer-group PEER_V4
35+
neighbor 10.0.0.61 description ARISTA03T1
36+
neighbor 10.0.0.61 timers 3 10
37+
neighbor 10.0.0.61 timers connect 10
38+
neighbor 10.0.0.63 remote-as 64600
39+
neighbor 10.0.0.63 peer-group PEER_V4
40+
neighbor 10.0.0.63 description ARISTA04T1
41+
neighbor 10.0.0.63 timers 3 10
42+
neighbor 10.0.0.63 timers connect 10
43+
neighbor fc00::72 remote-as 64600
44+
neighbor fc00::72 peer-group PEER_V6
45+
neighbor fc00::72 description ARISTA01T1
46+
neighbor fc00::72 timers 3 10
47+
neighbor fc00::72 timers connect 10
48+
neighbor fc00::76 remote-as 64600
49+
neighbor fc00::76 peer-group PEER_V6
50+
neighbor fc00::76 description ARISTA02T1
51+
neighbor fc00::76 timers 3 10
52+
neighbor fc00::76 timers connect 10
53+
neighbor fc00::7a remote-as 64600
54+
neighbor fc00::7a peer-group PEER_V6
55+
neighbor fc00::7a description ARISTA03T1
56+
neighbor fc00::7a timers 3 10
57+
neighbor fc00::7a timers connect 10
58+
neighbor fc00::7e remote-as 64600
59+
neighbor fc00::7e peer-group PEER_V6
60+
neighbor fc00::7e description ARISTA04T1
61+
neighbor fc00::7e timers 3 10
62+
neighbor fc00::7e timers connect 10
63+
bgp listen range 10.255.0.0/25 peer-group BGPSLBPassive
64+
bgp listen range 192.168.0.0/21 peer-group BGPVac

0 commit comments

Comments
 (0)