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

[201911][multi asic] show ip bgp summary changes for bgp mon #1483

Merged
merged 6 commits into from
Mar 6, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
258 changes: 258 additions & 0 deletions sonic-utilities-tests/bgp_commands_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest

from click.testing import CliRunner

show_bgp_summary_v4 = """\
Expand Down Expand Up @@ -88,13 +89,137 @@
Error: bgp summary from bgp container not in json format
"""

show_ipv4_bgp_summary_frontend = """\

IPv4 Unicast Summary:
asic0: BGP router identifier 10.1.0.32, local AS number 65100 vrf-id 0
BGP table version 12172
asic1: BGP router identifier 8.0.0.4, local AS number 65100 vrf-id 0
BGP table version 54717
RIB entries 25676, using 4724384 bytes of memory
Peers 8, using 167360 KiB of memory
Peer groups 6, using 384 bytes of memory


Neighbhor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd NeighborName
----------- --- ----- --------- --------- -------- ----- ------ --------- -------------- --------------
1.1.1.1 4 65100 0 0 0 0 0 never Connect bgp_monitor
10.0.0.1 4 65200 3191 5 0 0 0 00:01:29 6370 ARISTA01T2
10.0.0.5 4 65200 3191 5 0 0 0 00:01:29 6370 ARISTA03T2

Total number of neighbors 3
"""

show_ipv4_bgp_summary_all = """\

IPv4 Unicast Summary:
asic0: BGP router identifier 10.1.0.32, local AS number 65100 vrf-id 0
BGP table version 12172
asic1: BGP router identifier 8.0.0.4, local AS number 65100 vrf-id 0
BGP table version 54717
RIB entries 25676, using 4724384 bytes of memory
Peers 8, using 167360 KiB of memory
Peer groups 6, using 384 bytes of memory


Neighbhor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd NeighborName
----------- --- ----- --------- --------- -------- ----- ------ --------- -------------- --------------
1.1.1.1 4 65100 0 0 0 0 0 never Connect bgp_monitor
10.0.0.1 4 65200 3191 5 0 0 0 00:01:29 6370 ARISTA01T2
10.0.0.5 4 65200 3191 5 0 0 0 00:01:29 6370 ARISTA03T2
10.1.0.1 4 65100 3344 24107 0 0 0 00:07:26 6377 ASIC0
10.1.0.2 4 65100 0 0 0 0 0 never Active ASIC1

Total number of neighbors 5
"""

show_ipv4_bgp_summary_asic_all = """\

IPv4 Unicast Summary:
asic0: BGP router identifier 10.1.0.32, local AS number 65100 vrf-id 0
BGP table version 12172
RIB entries 12751, using 2346184 bytes of memory
Peers 4, using 83680 KiB of memory
Peer groups 4, using 256 bytes of memory


Neighbhor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd NeighborName
----------- --- ----- --------- --------- -------- ----- ------ --------- -------------- --------------
10.0.0.1 4 65200 3191 5 0 0 0 00:01:29 6370 ARISTA01T2
10.0.0.5 4 65200 3191 5 0 0 0 00:01:29 6370 ARISTA03T2
10.1.0.2 4 65100 0 0 0 0 0 never Active ASIC1

Total number of neighbors 3
"""

show_ipv6_bgp_summary_frontend = """\

IPv6 Unicast Summary:
asic0: BGP router identifier 10.1.0.32, local AS number 65100 vrf-id 0
BGP table version 8185
asic1: BGP router identifier 8.0.0.4, local AS number 65100 vrf-id 0
BGP table version 12148
RIB entries 25770, using 4741680 bytes of memory
Peers 8, using 167360 KiB of memory
Peer groups 6, using 384 bytes of memory


Neighbhor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd NeighborName
----------- --- ----- --------- --------- -------- ----- ------ --------- -------------- --------------
fc00::2 4 65200 3192 12 0 0 0 00:02:13 6370 ARISTA01T2
fc00::6 4 65200 3192 12 0 0 0 00:02:13 6370 ARISTA03T2

Total number of neighbors 2
"""

show_ipv6_bgp_summary_all = """\

IPv6 Unicast Summary:
asic0: BGP router identifier 10.1.0.32, local AS number 65100 vrf-id 0
BGP table version 8185
asic1: BGP router identifier 8.0.0.4, local AS number 65100 vrf-id 0
BGP table version 12148
RIB entries 25770, using 4741680 bytes of memory
Peers 8, using 167360 KiB of memory
Peer groups 6, using 384 bytes of memory


Neighbhor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd NeighborName
------------------ --- ----- --------- --------- -------- ----- ------ --------- -------------- --------------
2603:10e2:400:1::1 4 65100 6265 3591 0 0 0 00:02:14 6445 ASIC1
2603:10e2:400:1::2 4 65100 4887 6052 0 0 0 00:09:37 6380 ASIC0
fc00::2 4 65200 3192 12 0 0 0 00:02:13 6370 ARISTA01T2
fc00::6 4 65200 3192 12 0 0 0 00:02:13 6370 ARISTA03T2

Total number of neighbors 4
"""

show_ipv6_bgp_summary_asic_all = """\

IPv6 Unicast Summary:
asic0: BGP router identifier 10.1.0.32, local AS number 65100 vrf-id 0
BGP table version 8185
RIB entries 12885, using 2370840 bytes of memory
Peers 4, using 83680 KiB of memory
Peer groups 4, using 256 bytes of memory


Neighbhor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd NeighborName
------------------ --- ----- --------- --------- -------- ----- ------ --------- -------------- --------------
2603:10e2:400:1::1 4 65100 6265 3591 0 0 0 00:02:14 6445 ASIC1
fc00::2 4 65200 3192 12 0 0 0 00:02:13 6370 ARISTA01T2
fc00::6 4 65200 3192 12 0 0 0 00:02:13 6370 ARISTA03T2

Total number of neighbors 3
"""

class TestBgpCommands(object):
@classmethod
def setup_class(cls):
print("SETUP")
import mock_tables.dbconnector


@pytest.mark.parametrize('setup_single_bgp_instance',
['v4'], indirect=['setup_single_bgp_instance'])
def test_bgp_summary_v4(
Expand Down Expand Up @@ -136,3 +261,136 @@ def test_bgp_summary_error(
print("{}".format(result.output))
assert result.exit_code == 2
assert result.output == show_error_invalid_json


@pytest.mark.usefixtures('setup_multi_asic_display_options')
class TestBgpCommandsMultiAsic(object):

@pytest.mark.parametrize('setup_multi_asic_bgp_instance',
['v4'],
indirect=['setup_multi_asic_bgp_instance']
)
def test_bgp_summary_v4(
self,
setup_bgp_commands,
setup_multi_asic_bgp_instance,
):
show = setup_bgp_commands
runner = CliRunner()
result = runner.invoke(
show.cli.commands["ip"].commands["bgp"].commands["summary"], [])
print("{}".format(result.output))
assert result.exit_code == 0
assert result.output == show_ipv4_bgp_summary_frontend

@pytest.mark.parametrize('setup_multi_asic_bgp_instance',
['v4'], indirect=['setup_multi_asic_bgp_instance'])
def test_bgp_summary_v4_frontend(
self,
setup_bgp_commands,
setup_multi_asic_bgp_instance,
):
show = setup_bgp_commands
runner = CliRunner()
result = runner.invoke(
show.cli.commands["ip"].commands["bgp"].commands["summary"], ["-dfrontend"])
print("{}".format(result.output))
assert result.exit_code == 0
assert result.output == show_ipv4_bgp_summary_frontend


@pytest.mark.parametrize('setup_multi_asic_bgp_instance',
['v4'], indirect=['setup_multi_asic_bgp_instance'])
def test_bgp_summary_v4_all(
self,
setup_bgp_commands,
setup_multi_asic_bgp_instance,
):
show = setup_bgp_commands
runner = CliRunner()
result = runner.invoke(
show.cli.commands["ip"].commands["bgp"].commands["summary"], ["-dall"])
print("{}".format(result.output))
assert result.exit_code == 0
assert result.output == show_ipv4_bgp_summary_all


@pytest.mark.parametrize('setup_multi_asic_bgp_instance',
['v4'], indirect=['setup_multi_asic_bgp_instance'])
def test_bgp_summary_v4_all_asic(
self,
setup_bgp_commands,
setup_multi_asic_bgp_instance,
):
show = setup_bgp_commands
runner = CliRunner()
result = runner.invoke(
show.cli.commands["ip"].commands["bgp"].commands["summary"], ["-nasic0", "-dall"])
print("{}".format(result.output))
assert result.exit_code == 0
assert result.output == show_ipv4_bgp_summary_asic_all

@pytest.mark.parametrize('setup_multi_asic_bgp_instance',
['v6'], indirect=['setup_multi_asic_bgp_instance'])
def test_bgp_summary_v6(
self,
setup_bgp_commands,
setup_multi_asic_bgp_instance,
):
show = setup_bgp_commands
runner = CliRunner()
result = runner.invoke(
show.cli.commands["ipv6"].commands["bgp"].commands["summary"], [])
print("{}".format(result.output))
assert result.exit_code == 0
assert result.output == show_ipv6_bgp_summary_frontend

@pytest.mark.parametrize('setup_multi_asic_bgp_instance',
['v6'], indirect=['setup_multi_asic_bgp_instance'])
def test_bgp_summary_v6_frontend(
self,
setup_bgp_commands,
setup_multi_asic_bgp_instance,
):
show = setup_bgp_commands
runner = CliRunner()
result = runner.invoke(
show.cli.commands["ipv6"].commands["bgp"].commands["summary"], ["-dfrontend"])
print("{}".format(result.output))
assert result.exit_code == 0
assert result.output == show_ipv6_bgp_summary_frontend

@pytest.mark.parametrize('setup_multi_asic_bgp_instance',
['v6'],
indirect=['setup_multi_asic_bgp_instance'])
def test_bgp_summary_v6_all(
self,
setup_bgp_commands,
setup_multi_asic_bgp_instance,
):
show = setup_bgp_commands
runner = CliRunner()
result = runner.invoke(
show.cli.commands["ipv6"].commands["bgp"].commands["summary"], ["-dall"])
print("{}".format(result.output))
assert result.exit_code == 0
assert result.output == show_ipv6_bgp_summary_all


@pytest.mark.parametrize('setup_multi_asic_bgp_instance',
['v6'], indirect=['setup_multi_asic_bgp_instance'])
def test_bgp_summary_v6_all_asic(
self,
setup_bgp_commands,
setup_multi_asic_bgp_instance,
):
show = setup_bgp_commands
runner = CliRunner()
result = runner.invoke(
show.cli.commands["ipv6"].commands["bgp"].commands["summary"], ["-nasic0", "-dall"])
print("{}".format(result.output))
assert result.exit_code == 0
assert result.output == show_ipv6_bgp_summary_asic_all



59 changes: 54 additions & 5 deletions sonic-utilities-tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ def mock_run_show_ip_route_commands(request):
def setup_multi_asic_bgp_instance(request):
import utilities_common.bgp_util as bgp_util

if request.param == 'ip_route':
if request.param == 'v4':
m_asic_json_file = 'ipv4_bgp_summary.json'
elif request.param == 'v6':
m_asic_json_file = 'ipv6_bgp_summary.json'
elif 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'
Expand Down Expand Up @@ -104,11 +108,15 @@ def mock_run_bgp_command(vtysh_cmd, bgp_namespace):
@pytest.fixture
def setup_bgp_commands():
import show.main as show
from show.bgp_frr_v4 import bgp as bgpv4
from show.bgp_frr_v6 import bgp as bgpv6
reload(show)
import show.bgp_frr_v4 as bgpv4
import show.bgp_frr_v6 as bgpv6
reload(bgpv4)
reload(bgpv6)

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

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


Expand All @@ -117,3 +125,44 @@ def setup_ip_route_commands():
import show.main as show

return show

@pytest.fixture(scope='class')
def setup_multi_asic_display_options():
from sonic_py_common import multi_asic
from utilities_common import multi_asic as multi_asic_util
import mock_tables.dbconnector
import click
import show.main as show
_multi_asic_click_options = multi_asic_util.multi_asic_click_options

def mock_multi_asic_click_options(func):
_mock_multi_asic_click_options = [
click.option('--display',
'-d', 'display',
default="frontend",
show_default=True,
type=click.Choice(["all", "frontend"]),
help='Show internal interfaces'),
click.option('--namespace',
'-n', 'namespace',
default=None,
type=click.Choice(["asic0", "asic1"]),
show_default=True,
help='Namespace name or all'),
]
for option in reversed(_mock_multi_asic_click_options):
func = option(func)
return func

multi_asic.get_num_asics = mock.MagicMock(return_value=2)
multi_asic.is_multi_asic = mock.MagicMock(return_value=True)
multi_asic.get_namespace_list = mock.MagicMock(
return_value=["asic0", "asic1"])

multi_asic_util.multi_asic_click_options = mock_multi_asic_click_options
mock_tables.dbconnector.load_namespace_config()
yield

multi_asic_util.multi_asic_click_options = _multi_asic_click_options
mock_tables.dbconnector.load_database_config()

Loading