Skip to content

Commit

Permalink
[masic support] 'show run bgp' support for multi-asic (#2427)
Browse files Browse the repository at this point in the history
Support 'show run bgp' for multi-asics
Add mock tables and UTs for single-asic, multi-asic, bgp not running cases
  • Loading branch information
wenyiz2021 authored and yxieca committed Feb 9, 2023
1 parent a2252d8 commit 32b1d4d
Show file tree
Hide file tree
Showing 7 changed files with 368 additions and 4 deletions.
38 changes: 34 additions & 4 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1289,10 +1289,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

0 comments on commit 32b1d4d

Please sign in to comment.