From 3c55d61eb9d3ac0c462e72ed6daad0a1508827c8 Mon Sep 17 00:00:00 2001 From: Arvindsrinivasan Lakshmi Narasimhan Date: Thu, 4 Mar 2021 20:49:58 +0000 Subject: [PATCH 1/3] add the changed for bgp monitor --- utilities_common/bgp_util.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/utilities_common/bgp_util.py b/utilities_common/bgp_util.py index 3d3968bd32..e07092fec4 100644 --- a/utilities_common/bgp_util.py +++ b/utilities_common/bgp_util.py @@ -177,7 +177,20 @@ def get_bgp_summary_from_all_bgp_instances(af, namespace, display): bgp_summary = {} cmd_output_json = {} - for ns in device.get_ns_list_based_on_options(): + ns_list = [] + + if not device.is_multi_asic: + ns_list = [multi_asic.DEFAULT_NAMESPACE] + else: + if namespace is not None: + if namespace not in multi_asic.get_namespace_list(): + raise ValueError( + 'Unknown Namespace {}'.format(namespace)) + ns_list = [namespace] + else: + ns_list = multi_asic.get_namespace_list() + + for ns in ns_list: cmd_output = run_bgp_command(vtysh_cmd, ns) try: cmd_output_json = json.loads(cmd_output) @@ -258,7 +271,7 @@ def process_bgp_summary_json(bgp_summary, cmd_output, device): bgp_summary['peerGroupMemory'] = bgp_summary.get( 'peerGroupMemory', 0) + cmd_output['peerGroupMemory'] - #store instance level field is seperate dict + # store instance level field is seperate dict router_info = {} router_info['router_id'] = cmd_output['routerId'] router_info['vrf'] = cmd_output['vrfId'] From 98a9bfb9f87b516310dcc3f6f4a4ad5d4037b7f1 Mon Sep 17 00:00:00 2001 From: Arvindsrinivasan Lakshmi Narasimhan Date: Thu, 4 Mar 2021 23:09:40 +0000 Subject: [PATCH 2/3] add unit tests for multi asic Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan --- tests/bgp_commands_test.py | 256 +++++++++++++++++- tests/conftest.py | 60 +++- tests/mock_tables/asic0/config_db.json | 76 +++++- tests/mock_tables/asic0/ipv4_bgp_summary.json | 78 ++++++ tests/mock_tables/asic0/ipv6_bgp_summary.json | 81 ++++++ tests/mock_tables/asic1/config_db.json | 36 ++- tests/mock_tables/asic1/ipv4_bgp_summary.json | 43 +++ tests/mock_tables/asic1/ipv6_bgp_summary.json | 43 +++ utilities_common/bgp_util.py | 3 +- 9 files changed, 651 insertions(+), 25 deletions(-) create mode 100644 tests/mock_tables/asic0/ipv4_bgp_summary.json create mode 100644 tests/mock_tables/asic0/ipv6_bgp_summary.json create mode 100644 tests/mock_tables/asic1/ipv4_bgp_summary.json create mode 100644 tests/mock_tables/asic1/ipv6_bgp_summary.json diff --git a/tests/bgp_commands_test.py b/tests/bgp_commands_test.py index 24b4fdeafb..4feef780cd 100644 --- a/tests/bgp_commands_test.py +++ b/tests/bgp_commands_test.py @@ -3,7 +3,7 @@ import pytest from click.testing import CliRunner - +from importlib import reload show_bgp_summary_v4 = """\ IPv4 Unicast Summary: @@ -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 @@ -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 + + + diff --git a/tests/conftest.py b/tests/conftest.py index 309e65f055..d8da07f342 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,3 +1,4 @@ +from importlib import reload import json import os import sys @@ -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' @@ -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 @@ -209,3 +217,43 @@ 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 click + _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 + dbconnector.load_namespace_config() + yield + + multi_asic_util.multi_asic_click_options = _multi_asic_click_options + dbconnector.load_database_config() diff --git a/tests/mock_tables/asic0/config_db.json b/tests/mock_tables/asic0/config_db.json index cd7b49fd0a..3038e910bf 100644 --- a/tests/mock_tables/asic0/config_db.json +++ b/tests/mock_tables/asic0/config_db.json @@ -38,7 +38,7 @@ "speed": "40000", "asic_port_name": "Eth1-ASIC0" }, - "PORT|Ethernet-BP0" : { + "PORT|Ethernet-BP0": { "lanes": "93,94,95,96", "description": "ASIC1:Eth0-ASIC1", "pfc_asym": "off", @@ -49,7 +49,7 @@ "speed": "40000", "asic_port_name": "Eth16-ASIC0" }, - "PORT|Ethernet-BP4" : { + "PORT|Ethernet-BP4": { "lanes": "97,98,99,100", "description": "ASIC1:Eth1-ASIC1", "pfc_asym": "off", @@ -161,20 +161,80 @@ }, "MUX_CABLE|Ethernet32": { "state": "auto", - "server_ipv4": "10.1.1.1", - "server_ipv6": "fc00::75" + "server_ipv4": "10.1.1.1", + "server_ipv6": "fc00::75" }, "MUX_CABLE|Ethernet0": { "state": "auto", - "server_ipv4": "10.2.1.1", - "server_ipv6": "e800::46" + "server_ipv4": "10.2.1.1", + "server_ipv6": "e800::46" }, - "PEER_SWITCH|sonic" : { - "address_ipv4": "10.2.2.2" + "PEER_SWITCH|sonic": { + "address_ipv4": "10.2.2.2" }, "FEATURE|bgp": { "state": "enabled", "auto_restart": "enabled", "high_mem_alert": "disabled" + }, + "BGP_NEIGHBOR|10.0.0.5": { + "rrclient": "0", + "name": "ARISTA03T2", + "local_addr": "10.0.0.4", + "nhopself": "0", + "admin_status": "up", + "holdtime": "10", + "asn": "65200", + "keepalive": "3" + }, + "BGP_NEIGHBOR|fc00::6": { + "rrclient": "0", + "name": "ARISTA03T2", + "local_addr": "fc00::5", + "nhopself": "0", + "admin_status": "up", + "holdtime": "10", + "asn": "65200", + "keepalive": "3" + }, + "BGP_NEIGHBOR|10.0.0.1": { + "rrclient": "0", + "name": "ARISTA01T2", + "local_addr": "10.0.0.0", + "nhopself": "0", + "admin_status": "up", + "holdtime": "10", + "asn": "65200", + "keepalive": "3" + }, + "BGP_NEIGHBOR|fc00::2": { + "rrclient": "0", + "name": "ARISTA01T2", + "local_addr": "fc00::1", + "nhopself": "0", + "admin_status": "up", + "holdtime": "10", + "asn": "65200", + "keepalive": "3" + }, + "BGP_INTERNAL_NEIGHBOR|10.1.0.2": { + "rrclient": "0", + "name": "ASIC1", + "local_addr": "10.1.0.3", + "nhopself": "0", + "admin_status": "up", + "holdtime": "0", + "asn": "65100", + "keepalive": "0" + }, + "BGP_INTERNAL_NEIGHBOR|2603:10e2:400:1::1": { + "rrclient": "0", + "name": "ASIC1", + "local_addr": "2603:10e2:400:1::2", + "nhopself": "0", + "admin_status": "up", + "holdtime": "0", + "asn": "65100", + "keepalive": "0" } } diff --git a/tests/mock_tables/asic0/ipv4_bgp_summary.json b/tests/mock_tables/asic0/ipv4_bgp_summary.json new file mode 100644 index 0000000000..0ea16d19e5 --- /dev/null +++ b/tests/mock_tables/asic0/ipv4_bgp_summary.json @@ -0,0 +1,78 @@ +{ + "ipv4Unicast": { + "routerId": "10.1.0.32", + "as": 65100, + "vrfId": 0, + "vrfName": "default", + "tableVersion": 12172, + "ribCount": 12751, + "ribMemory": 2346184, + "peerCount": 4, + "peerMemory": 83680, + "peerGroupCount": 4, + "peerGroupMemory": 256, + "peers": { + "10.1.0.2": { + "remoteAs": 65100, + "version": 4, + "msgRcvd": 0, + "msgSent": 0, + "tableVersion": 0, + "outq": 0, + "inq": 0, + "peerUptime": "never", + "peerUptimeMsec": 0, + "prefixReceivedCount": 0, + "pfxRcd": 0, + "state": "Active", + "connectionsEstablished": 0, + "connectionsDropped": 0, + "idType": "ipv4" + }, + "10.0.0.1": { + "remoteAs": 65200, + "version": 4, + "msgRcvd": 3191, + "msgSent": 5, + "tableVersion": 0, + "outq": 0, + "inq": 0, + "peerUptime": "00:01:29", + "peerUptimeMsec": 89000, + "peerUptimeEstablishedEpoch": 1614894400, + "prefixReceivedCount": 6370, + "pfxRcd": 6370, + "pfxSnt": 1, + "state": "Established", + "connectionsEstablished": 1, + "connectionsDropped": 0, + "idType": "ipv4" + }, + "10.0.0.5": { + "remoteAs": 65200, + "version": 4, + "msgRcvd": 3191, + "msgSent": 5, + "tableVersion": 0, + "outq": 0, + "inq": 0, + "peerUptime": "00:01:29", + "peerUptimeMsec": 89000, + "peerUptimeEstablishedEpoch": 1614894400, + "prefixReceivedCount": 6370, + "pfxRcd": 6370, + "pfxSnt": 1, + "state": "Established", + "connectionsEstablished": 1, + "connectionsDropped": 0, + "idType": "ipv4" + } + }, + "failedPeers": 2, + "totalPeers": 4, + "dynamicPeers": 0, + "bestPath": { + "multiPathRelax": "true" + } + } +} \ No newline at end of file diff --git a/tests/mock_tables/asic0/ipv6_bgp_summary.json b/tests/mock_tables/asic0/ipv6_bgp_summary.json new file mode 100644 index 0000000000..35d60afe73 --- /dev/null +++ b/tests/mock_tables/asic0/ipv6_bgp_summary.json @@ -0,0 +1,81 @@ +{ + "ipv6Unicast": { + "routerId": "10.1.0.32", + "as": 65100, + "vrfId": 0, + "vrfName": "default", + "tableVersion": 8185, + "ribCount": 12885, + "ribMemory": 2370840, + "peerCount": 4, + "peerMemory": 83680, + "peerGroupCount": 4, + "peerGroupMemory": 256, + "peers": { + "2603:10e2:400:1::1": { + "hostname": "sonic", + "remoteAs": 65100, + "version": 4, + "msgRcvd": 6265, + "msgSent": 3591, + "tableVersion": 0, + "outq": 0, + "inq": 0, + "peerUptime": "00:02:14", + "peerUptimeMsec": 134000, + "peerUptimeEstablishedEpoch": 1614892951, + "prefixReceivedCount": 6445, + "pfxRcd": 6445, + "pfxSnt": 6380, + "state": "Established", + "connectionsEstablished": 1, + "connectionsDropped": 0, + "idType": "ipv6" + }, + "fc00::2": { + "remoteAs": 65200, + "version": 4, + "msgRcvd": 3192, + "msgSent": 12, + "tableVersion": 0, + "outq": 0, + "inq": 0, + "peerUptime": "00:02:13", + "peerUptimeMsec": 133000, + "peerUptimeEstablishedEpoch": 1614892952, + "prefixReceivedCount": 6370, + "pfxRcd": 6370, + "pfxSnt": 33, + "state": "Established", + "connectionsEstablished": 1, + "connectionsDropped": 0, + "idType": "ipv6" + }, + "fc00::6": { + "remoteAs": 65200, + "version": 4, + "msgRcvd": 3192, + "msgSent": 12, + "tableVersion": 0, + "outq": 0, + "inq": 0, + "peerUptime": "00:02:13", + "peerUptimeMsec": 133000, + "peerUptimeEstablishedEpoch": 1614892952, + "prefixReceivedCount": 6370, + "pfxRcd": 6370, + "pfxSnt": 33, + "state": "Established", + "connectionsEstablished": 1, + "connectionsDropped": 0, + "idType": "ipv6" + } + }, + "failedPeers": 0, + "totalPeers": 4, + "dynamicPeers": 0, + "bestPath": { + "multiPathRelax": "true" + } + } +} \ No newline at end of file diff --git a/tests/mock_tables/asic1/config_db.json b/tests/mock_tables/asic1/config_db.json index 4d515ba2d3..4b654a241b 100644 --- a/tests/mock_tables/asic1/config_db.json +++ b/tests/mock_tables/asic1/config_db.json @@ -60,7 +60,7 @@ "PORTCHANNEL_MEMBER|PortChannel4009|Ethernet-BP256": { "NULL": "NULL" }, - "PORTCHANNEL_MEMBER|PortChannel4009|Ethernet-BP260" : { + "PORTCHANNEL_MEMBER|PortChannel4009|Ethernet-BP260": { "NULL": "NULL" }, "PFC_WD|Ethernet-BP256": { @@ -130,20 +130,40 @@ }, "MUX_CABLE|Ethernet32": { "state": "auto", - "server_ipv4": "10.1.1.1", - "server_ipv6": "fc00::75" + "server_ipv4": "10.1.1.1", + "server_ipv6": "fc00::75" }, "MUX_CABLE|Ethernet0": { "state": "auto", - "server_ipv4": "10.2.1.1", - "server_ipv6": "e800::46" + "server_ipv4": "10.2.1.1", + "server_ipv6": "e800::46" }, - "PEER_SWITCH|sonic" : { - "address_ipv4": "10.2.2.2" + "PEER_SWITCH|sonic": { + "address_ipv4": "10.2.2.2" }, "FEATURE|bgp": { "state": "enabled", "auto_restart": "enabled", "high_mem_alert": "disabled" + }, + "BGP_INTERNAL_NEIGHBOR|10.1.0.1": { + "rrclient": "0", + "name": "ASIC0", + "local_addr": "10.1.0.0", + "nhopself": "0", + "admin_status": "up", + "holdtime": "0", + "asn": "65100", + "keepalive": "0" + }, + "BGP_INTERNAL_NEIGHBOR|2603:10e2:400:1::2": { + "rrclient": "0", + "name": "ASIC0", + "local_addr": "2603:10e2:400:1::1", + "nhopself": "0", + "admin_status": "up", + "holdtime": "0", + "asn": "65100", + "keepalive": "0" } -} +} \ No newline at end of file diff --git a/tests/mock_tables/asic1/ipv4_bgp_summary.json b/tests/mock_tables/asic1/ipv4_bgp_summary.json new file mode 100644 index 0000000000..826591f59c --- /dev/null +++ b/tests/mock_tables/asic1/ipv4_bgp_summary.json @@ -0,0 +1,43 @@ +{ + "ipv4Unicast": { + "routerId": "8.0.0.4", + "as": 65100, + "vrfId": 0, + "vrfName": "default", + "tableVersion": 54717, + "ribCount": 12925, + "ribMemory": 2378200, + "peerCount": 4, + "peerMemory": 83680, + "peerGroupCount": 2, + "peerGroupMemory": 128, + "peers": { + "10.1.0.1": { + "hostname": "sonic", + "remoteAs": 65100, + "version": 4, + "msgRcvd": 3344, + "msgSent": 24107, + "tableVersion": 0, + "outq": 0, + "inq": 0, + "peerUptime": "00:07:26", + "peerUptimeMsec": 446000, + "peerUptimeEstablishedEpoch": 1614893789, + "prefixReceivedCount": 6377, + "pfxRcd": 6377, + "pfxSnt": 6464, + "state": "Established", + "connectionsEstablished": 1, + "connectionsDropped": 0, + "idType": "ipv4" + } + }, + "failedPeers": 0, + "totalPeers": 4, + "dynamicPeers": 0, + "bestPath": { + "multiPathRelax": "true" + } + } +} \ No newline at end of file diff --git a/tests/mock_tables/asic1/ipv6_bgp_summary.json b/tests/mock_tables/asic1/ipv6_bgp_summary.json new file mode 100644 index 0000000000..28539a641f --- /dev/null +++ b/tests/mock_tables/asic1/ipv6_bgp_summary.json @@ -0,0 +1,43 @@ +{ + "ipv6Unicast": { + "routerId": "8.0.0.4", + "as": 65100, + "vrfId": 0, + "vrfName": "default", + "tableVersion": 12148, + "ribCount": 12885, + "ribMemory": 2370840, + "peerCount": 4, + "peerMemory": 83680, + "peerGroupCount": 2, + "peerGroupMemory": 128, + "peers": { + "2603:10e2:400:1::2": { + "hostname": "sonic", + "remoteAs": 65100, + "version": 4, + "msgRcvd": 4887, + "msgSent": 6052, + "tableVersion": 0, + "outq": 0, + "inq": 0, + "peerUptime": "00:09:37", + "peerUptimeMsec": 577000, + "peerUptimeEstablishedEpoch": 1614893673, + "prefixReceivedCount": 6380, + "pfxRcd": 6380, + "pfxSnt": 6445, + "state": "Established", + "connectionsEstablished": 1, + "connectionsDropped": 0, + "idType": "ipv6" + } + }, + "failedPeers": 0, + "totalPeers": 1, + "dynamicPeers": 0, + "bestPath": { + "multiPathRelax": "true" + } + } +} \ No newline at end of file diff --git a/utilities_common/bgp_util.py b/utilities_common/bgp_util.py index e07092fec4..bfbee5fe71 100644 --- a/utilities_common/bgp_util.py +++ b/utilities_common/bgp_util.py @@ -165,7 +165,6 @@ def run_bgp_command(vtysh_cmd, bgp_namespace=multi_asic.DEFAULT_NAMESPACE): def get_bgp_summary_from_all_bgp_instances(af, namespace, display): - device = multi_asic_util.MultiAsic(display, namespace) ctx = click.get_current_context() if af is constants.IPV4: @@ -186,7 +185,7 @@ def get_bgp_summary_from_all_bgp_instances(af, namespace, display): if namespace not in multi_asic.get_namespace_list(): raise ValueError( 'Unknown Namespace {}'.format(namespace)) - ns_list = [namespace] + ns_list = [namespace] else: ns_list = multi_asic.get_namespace_list() From 18db329a39284d89577d4ba3ab244c5dd591939f Mon Sep 17 00:00:00 2001 From: Arvindsrinivasan Lakshmi Narasimhan Date: Fri, 5 Mar 2021 03:43:33 +0000 Subject: [PATCH 3/3] fix test failures Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan --- tests/conftest.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index d8da07f342..5eb9473aff 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -224,8 +224,13 @@ 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 = [ @@ -255,5 +260,10 @@ def mock_multi_asic_click_options(func): 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)