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

[masic support] 'show run bgp' support for multi-asic #2427

Merged
merged 39 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
fe52110
Update main.py
wenyiz2021 Oct 6, 2022
92816b0
remove import bgp_utils
wenyiz2021 Oct 6, 2022
269b53e
Update main.py
wenyiz2021 Oct 6, 2022
5564920
fix indent and constants.RVTYSH_COMMAND
wenyiz2021 Oct 6, 2022
7e6b0b5
refine output, also rctysh doesnt take whole cmd
wenyiz2021 Oct 6, 2022
62eac78
support single-asic case
wenyiz2021 Oct 7, 2022
3646e2f
Update main.py
wenyiz2021 Oct 7, 2022
322aa45
Update main.py
wenyiz2021 Oct 7, 2022
c6b27a9
fix bug multi_asic.is_multi_asic
wenyiz2021 Oct 7, 2022
a3a300f
remove 'callback' argument in option '-n'
wenyiz2021 Oct 7, 2022
c2ad10a
Update multi_asic.py
wenyiz2021 Oct 7, 2022
3dd0302
refine help message
wenyiz2021 Oct 7, 2022
0555e40
ok
wenyiz2021 Nov 17, 2022
fe16855
remove unrelated change for show int counters
wenyiz2021 Nov 17, 2022
cffba1c
multi-asic can run without -n and show all
wenyiz2021 Nov 30, 2022
f900faa
fix typo
wenyiz2021 Nov 30, 2022
377740d
remove debug breakpoint
wenyiz2021 Nov 30, 2022
e6a166c
unit test
wenyiz2021 Nov 30, 2022
ef4dda8
add import importlib
wenyiz2021 Nov 30, 2022
74e8674
Update show_run_bgp_test.py
wenyiz2021 Dec 1, 2022
2f11eac
add teardown
wenyiz2021 Dec 1, 2022
d16e67c
Update show_run_bgp_test.py
wenyiz2021 Dec 1, 2022
66a51f2
Update main.py
wenyiz2021 Dec 16, 2022
823fe87
reuse bgp_util.run_bgp_command
wenyiz2021 Jan 24, 2023
c1c7357
remove separate vector file
wenyiz2021 Jan 24, 2023
d8b557f
Merge branch 'sonic-net:master' into show_run_bgp_masic
wenyiz2021 Jan 24, 2023
533982b
mock for single asic
wenyiz2021 Jan 24, 2023
c87888a
mock multi_asic for 'show run bgp'
wenyiz2021 Jan 24, 2023
5950d09
mock tables for 'show run bgp', test changed
wenyiz2021 Jan 24, 2023
e1cba3d
syntax
wenyiz2021 Jan 24, 2023
d419877
add cmd definition
wenyiz2021 Jan 24, 2023
4fa78f0
fix indent and spaces
wenyiz2021 Jan 24, 2023
400fd00
fix indent
wenyiz2021 Jan 24, 2023
189f598
remove comments, raise issue instead
wenyiz2021 Jan 30, 2023
e22605b
use run_bgp_show_command to run readonly vtysh
wenyiz2021 Jan 30, 2023
b6d058f
Merge branch 'sonic-net:master' into show_run_bgp_masic
wenyiz2021 Jan 31, 2023
11e1d1a
Update conftest.py
wenyiz2021 Jan 31, 2023
3dc5129
add bgp not running tests
wenyiz2021 Jan 31, 2023
3a5bc31
add mock table for not running bgp
wenyiz2021 Jan 31, 2023
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
38 changes: 34 additions & 4 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1439,10 +1439,40 @@ def ports(portname, verbose):
# 'bgp' subcommand ("show runningconfiguration bgp")
@runningconfiguration.command()
@click.option('--verbose', is_flag=True, help="Enable verbose output")
def bgp(verbose):
"""Show BGP running configuration"""
cmd = 'sudo {} -c "show running-config"'.format(constants.RVTYSH_COMMAND)
run_command(cmd, display_cmd=verbose)
@click.option('--namespace', '-n', 'namespace', required=False, default=None, type=str, show_default=False,
help='Option needed for multi-asic only: provide namespace name',
callback=multi_asic_util.multi_asic_namespace_validation_callback)
def bgp(namespace, verbose):
"""
Show BGP running configuration
Note:
multi-asic can run 'show run bgp' and show from all asics, or 'show run bgp -n <ns>'
single-asic only run 'show run bgp', '-n' is not available
"""

if multi_asic.is_multi_asic():
if namespace and namespace not in multi_asic.get_namespace_list():
ctx = click.get_current_context()
ctx.fail("invalid value for -n/--namespace option. provide namespace from list {}".format(multi_asic.get_namespace_list()))
if not multi_asic.is_multi_asic() and namespace:
ctx = click.get_current_context()
ctx.fail("-n/--namespace is not available for single asic")

output = ""
cmd = "show running-config bgp"
import utilities_common.bgp_util as bgp_util
if multi_asic.is_multi_asic():
if not namespace:
ns_list = multi_asic.get_namespace_list()
for ns in ns_list:
output += "\n------------Showing running config bgp on {}------------\n".format(ns)
output += bgp_util.run_bgp_show_command(cmd, ns)
else:
output += "\n------------Showing running config bgp on {}------------\n".format(namespace)
output += bgp_util.run_bgp_show_command(cmd, namespace)
else:
output += bgp_util.run_bgp_show_command(cmd)
print(output)


# 'interfaces' subcommand ("show runningconfiguration interfaces")
Expand Down
17 changes: 17 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ 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 == 'show_run_bgp':
bgp_mocked_json = os.path.join(
test_path, 'mock_tables', 'show_run_bgp.txt')
elif request.param == 'ip_route':
bgp_mocked_json = 'ip_route.json'
elif request.param == 'ip_specific_route':
Expand All @@ -193,6 +196,13 @@ def mock_show_bgp_summary(vtysh_cmd, bgp_namespace, vtysh_shell_cmd=constants.RV
return mock_frr_data
return ""

def mock_show_run_bgp(request):
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 ""

def mock_run_bgp_command_for_static(vtysh_cmd, bgp_namespace="", vtysh_shell_cmd=constants.RVTYSH_COMMAND):
if vtysh_cmd == "show ip route vrf all static":
return config_int_ip_common.show_ip_route_with_static_expected_output
Expand Down Expand Up @@ -239,6 +249,9 @@ def mock_run_bgp_command(vtysh_cmd, bgp_namespace, vtysh_shell_cmd=constants.RVT
elif request.param == "show_bgp_summary_no_neigh":
bgp_util.run_bgp_command = mock.MagicMock(
return_value=mock_show_bgp_summary_no_neigh("", ""))
elif request.param.startswith('show_run_bgp'):
bgp_util.run_bgp_command = mock.MagicMock(
return_value=mock_show_run_bgp(request))
else:
bgp_util.run_bgp_command = mock.MagicMock(
return_value=mock_show_bgp_summary("", ""))
Expand Down Expand Up @@ -270,6 +283,10 @@ def setup_multi_asic_bgp_instance(request):
m_asic_json_file = 'ip_special_recursive_route.json'
elif request.param == 'ip_route_summary':
m_asic_json_file = 'ip_route_summary.txt'
elif request.param == 'show_run_bgp':
m_asic_json_file = 'show_run_bgp.txt'
elif request.param == 'show_not_running_bgp':
m_asic_json_file = 'show_not_running_bgp.txt'
elif request.param.startswith('bgp_v4_network') or \
request.param.startswith('bgp_v6_network') or \
request.param.startswith('bgp_v4_neighbor') or \
Expand Down
1 change: 1 addition & 0 deletions tests/mock_tables/asic0/show_not_running_bgp.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Error response from daemon: Container 70e3d3bafd1ab5faf796892acff3e2ccbea3dcd5dcfefcc34f25f7cc916b67bb is not running
12 changes: 12 additions & 0 deletions tests/mock_tables/asic0/show_run_bgp.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
neighbor 10.0.0.1 remote-as 65200
neighbor 10.0.0.1 peer-group TIER2_V4
neighbor 10.0.0.1 description ARISTA01T2
neighbor 10.0.0.5 remote-as 65200
neighbor 10.0.0.5 peer-group TIER2_V4
neighbor 10.0.0.5 description ARISTA03T2
neighbor fc00::2 remote-as 65200
neighbor fc00::2 peer-group TIER2_V6
neighbor fc00::2 description ARISTA01T2
neighbor fc00::6 remote-as 65200
neighbor fc00::6 peer-group TIER2_V6
neighbor fc00::6 description ARISTA03T2
12 changes: 12 additions & 0 deletions tests/mock_tables/asic1/show_run_bgp.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
neighbor 10.0.0.9 remote-as 65200
neighbor 10.0.0.9 peer-group TIER2_V4
neighbor 10.0.0.9 description ARISTA05T2
neighbor 10.0.0.13 remote-as 65200
neighbor 10.0.0.13 peer-group TIER2_V4
neighbor 10.0.0.13 description ARISTA07T2
neighbor fc00::a remote-as 65200
neighbor fc00::a peer-group TIER2_V6
neighbor fc00::a description ARISTA05T2
neighbor fc00::e remote-as 65200
neighbor fc00::e peer-group TIER2_V6
neighbor fc00::e description ARISTA07T2
64 changes: 64 additions & 0 deletions tests/mock_tables/show_run_bgp.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
router bgp 65100
bgp router-id 10.1.0.32
bgp log-neighbor-changes
no bgp ebgp-requires-policy
no bgp default ipv4-unicast
bgp graceful-restart restart-time 240
bgp graceful-restart select-defer-time 45
bgp graceful-restart
bgp graceful-restart preserve-fw-state
bgp bestpath as-path multipath-relax
neighbor BGPSLBPassive peer-group
neighbor BGPSLBPassive remote-as 65432
neighbor BGPSLBPassive passive
neighbor BGPSLBPassive ebgp-multihop 255
neighbor BGPSLBPassive update-source 10.1.0.32
neighbor BGPVac peer-group
neighbor BGPVac remote-as 65432
neighbor BGPVac passive
neighbor BGPVac ebgp-multihop 255
neighbor BGPVac update-source 10.1.0.32
neighbor PEER_V4 peer-group
neighbor PEER_V6 peer-group
neighbor 10.0.0.57 remote-as 64600
neighbor 10.0.0.57 peer-group PEER_V4
neighbor 10.0.0.57 description ARISTA01T1
neighbor 10.0.0.57 timers 3 10
neighbor 10.0.0.57 timers connect 10
neighbor 10.0.0.59 remote-as 64600
neighbor 10.0.0.59 peer-group PEER_V4
neighbor 10.0.0.59 description ARISTA02T1
neighbor 10.0.0.59 timers 3 10
neighbor 10.0.0.59 timers connect 10
neighbor 10.0.0.61 remote-as 64600
neighbor 10.0.0.61 peer-group PEER_V4
neighbor 10.0.0.61 description ARISTA03T1
neighbor 10.0.0.61 timers 3 10
neighbor 10.0.0.61 timers connect 10
neighbor 10.0.0.63 remote-as 64600
neighbor 10.0.0.63 peer-group PEER_V4
neighbor 10.0.0.63 description ARISTA04T1
neighbor 10.0.0.63 timers 3 10
neighbor 10.0.0.63 timers connect 10
neighbor fc00::72 remote-as 64600
neighbor fc00::72 peer-group PEER_V6
neighbor fc00::72 description ARISTA01T1
neighbor fc00::72 timers 3 10
neighbor fc00::72 timers connect 10
neighbor fc00::76 remote-as 64600
neighbor fc00::76 peer-group PEER_V6
neighbor fc00::76 description ARISTA02T1
neighbor fc00::76 timers 3 10
neighbor fc00::76 timers connect 10
neighbor fc00::7a remote-as 64600
neighbor fc00::7a peer-group PEER_V6
neighbor fc00::7a description ARISTA03T1
neighbor fc00::7a timers 3 10
neighbor fc00::7a timers connect 10
neighbor fc00::7e remote-as 64600
neighbor fc00::7e peer-group PEER_V6
neighbor fc00::7e description ARISTA04T1
neighbor fc00::7e timers 3 10
neighbor fc00::7e timers connect 10
bgp listen range 10.255.0.0/25 peer-group BGPSLBPassive
bgp listen range 192.168.0.0/21 peer-group BGPVac
Loading