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

[multi asic] Display the bgp mon session in the show ip bgp summary #1480

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
256 changes: 255 additions & 1 deletion tests/bgp_commands_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest

from click.testing import CliRunner

from importlib import reload
show_bgp_summary_v4 = """\

IPv4 Unicast Summary:
Expand Down Expand Up @@ -91,6 +91,127 @@
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
----------- --- ----- --------- --------- -------- ----- ------ --------- -------------- --------------
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 2
"""

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
----------- --- ----- --------- --------- -------- ----- ------ --------- -------------- --------------
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 4
"""

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
Expand Down Expand Up @@ -139,3 +260,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



70 changes: 64 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from importlib import reload
import json
import os
import sys
Expand Down Expand Up @@ -156,7 +157,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 @@ -196,11 +201,14 @@ 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

show.ip.add_command(bgpv4)
show.ipv6.add_command(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)
return show


Expand All @@ -209,3 +217,53 @@ 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
from .mock_tables import dbconnector
import show.main as show
import click

_multi_asic_click_options = multi_asic_util.multi_asic_click_options
_get_num_asics = multi_asic.get_num_asics
_is_multi_asic = multi_asic.is_multi_asic
_get_namespace_list = multi_asic.get_namespace_list

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
dbconnector.load_namespace_config()
yield

multi_asic.get_num_asics = _get_num_asics
multi_asic.is_multi_asic = _is_multi_asic
multi_asic.get_namespace_list = _get_namespace_list

multi_asic_util.multi_asic_click_options = _multi_asic_click_options
dbconnector.load_database_config()
reload(show)
Loading