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

[chassis]: Support show ip bgp summary to display without error when … #40

Merged
merged 1 commit into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
80 changes: 79 additions & 1 deletion tests/bgp_commands_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@

import pytest
import importlib
import mock

from click.testing import CliRunner

from utilities_common import multi_asic
from utilities_common import constants
from utilities_common import bgp_util
from utilities_common.db import Db

from unittest.mock import patch

from sonic_py_common import device_info
from sonic_py_common import multi_asic as masic
show_bgp_summary_v4 = """\

IPv4 Unicast Summary:
Expand Down Expand Up @@ -277,6 +281,44 @@
Total number of neighbors 23
"""

SHOW_BGP_SUMMARY_V4_NO_EXT_NEIGHBORS = """
IPv4 Unicast Summary:
asic0: BGP router identifier 10.1.0.32, local AS number 65100 vrf-id 0
BGP table version 8972
RIB entries 0, using 0 bytes of memory
Peers 0, using 0 KiB of memory
Peer groups 0, using 0 bytes of memory


Neighbhor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd NeighborName
----------- --- ---- --------- --------- -------- ----- ------ --------- -------------- --------------

Total number of neighbors 0
"""

SHOW_BGP_SUMMARY_ALL_V4_NO_EXT_NEIGHBORS = """
IPv4 Unicast Summary:
asic0: BGP router identifier 192.0.0.6, local AS number 65100 vrf-id 0
BGP table version 59923
asic1: BGP router identifier 192.0.0.8, local AS number 65100 vrf-id 0
BGP table version 64918
RIB entries 202298, using 37222832 bytes of memory
Peers 6, using 4444848 KiB of memory
Peer groups 4, using 256 bytes of memory


Neighbhor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd NeighborName
----------- --- ----- --------- --------- -------- ----- ------ --------- -------------- ----------------------
3.3.3.1 4 65100 277 9 0 0 0 00:00:14 33798 str2-sonic-lc1-1-ASIC0
3.3.3.1 4 65100 280 14 0 0 0 00:00:22 33798 str2-sonic-lc1-1-ASIC1
3.3.3.2 4 65100 277 9 0 0 0 00:00:14 33798 str2-sonic-lc2-1-ASIC0
3.3.3.2 4 65100 280 14 0 0 0 00:00:22 33798 str2-sonic-lc3-1-ASIC0
3.3.3.6 4 65100 14 14 0 0 0 00:00:23 4 str2-sonic-lc3-1-ASIC1
3.3.3.8 4 65100 12 10 0 0 0 00:00:15 4 str2-sonic-lc1-1-ASIC1

Total number of neighbors 6
"""


class TestBgpCommandsSingleAsic(object):
@classmethod
Expand Down Expand Up @@ -430,6 +472,7 @@ def teardown_class(cls):
dbconnector.load_database_config()



class TestBgpCommandsMultiAsic(object):
@classmethod
def setup_class(cls):
Expand All @@ -439,6 +482,8 @@ def setup_class(cls):
from .mock_tables import dbconnector
dbconnector.load_namespace_config()



@pytest.mark.parametrize('setup_multi_asic_bgp_instance',
['show_bgp_summary_no_neigh'], indirect=['setup_multi_asic_bgp_instance'])
def test_bgp_summary_multi_asic_no_v4_neigh(
Expand All @@ -453,6 +498,7 @@ def test_bgp_summary_multi_asic_no_v4_neigh(
assert result.exit_code == 0
assert result.output == show_error_no_v4_neighbor_multi_asic


@pytest.mark.parametrize('setup_multi_asic_bgp_instance',
['show_bgp_summary_no_neigh'], indirect=['setup_multi_asic_bgp_instance'])
def test_bgp_summary_multi_asic_no_v6_neigh(
Expand All @@ -467,7 +513,39 @@ def test_bgp_summary_multi_asic_no_v6_neigh(
assert result.exit_code == 0
assert result.output == show_error_no_v6_neighbor_multi_asic

@classmethod

@patch.object(bgp_util, 'get_external_bgp_neighbors_dict', mock.MagicMock(return_value={}))
@patch.object(multi_asic.MultiAsic, 'get_display_option', mock.MagicMock(return_value=constants.DISPLAY_EXTERNAL))
@pytest.mark.parametrize('setup_multi_asic_bgp_instance',
['show_bgp_summary_no_ext_neigh_on_all_asic'], indirect=['setup_multi_asic_bgp_instance'])
@patch.object(device_info, 'is_chassis', mock.MagicMock(return_value=True))
def test_bgp_summary_multi_asic_no_external_neighbor(
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_BGP_SUMMARY_V4_NO_EXT_NEIGHBORS


@pytest.mark.parametrize('setup_multi_asic_bgp_instance',
['show_bgp_summary_no_ext_neigh_on_all_asic'], indirect=['setup_multi_asic_bgp_instance'])
def test_bgp_summary_multi_asic_display_with_no_external_neighbor(
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_BGP_SUMMARY_ALL_V4_NO_EXT_NEIGHBORS

def teardown_class(cls):
print("TEARDOWN")
from .mock_tables import mock_single_asic
Expand Down
18 changes: 18 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,29 @@ def mock_run_show_sum_bgp_command(vtysh_cmd, bgp_namespace, vtysh_shell_cmd=cons
else:
return ""

def mock_run_show_summ_bgp_command_no_ext_neigh_on_all_asic(vtysh_cmd, bgp_namespace, vtysh_shell_cmd=constants.VTYSH_COMMAND):
if vtysh_cmd == "show ip bgp summary json":
m_asic_json_file = 'no_ext_bgp_neigh.json'
else:
m_asic_json_file = 'device_bgp_info.json'

bgp_mocked_json = os.path.join(
test_path, 'mock_tables', bgp_namespace, m_asic_json_file)
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
else:
return ""


_old_run_bgp_command = bgp_util.run_bgp_command
if request.param == 'ip_route_for_int_ip':
bgp_util.run_bgp_command = mock_run_bgp_command_for_static
elif request.param == 'show_bgp_summary_no_neigh':
bgp_util.run_bgp_command = mock_run_show_sum_bgp_command
elif request.param == 'show_bgp_summary_no_ext_neigh_on_all_asic':
bgp_util.run_bgp_command = mock_run_show_summ_bgp_command_no_ext_neigh_on_all_asic
else:
bgp_util.run_bgp_command = mock_run_bgp_command

Expand Down
30 changes: 30 additions & 0 deletions tests/mock_tables/asic0/config_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,36 @@
"asn": "65200",
"keepalive": "3"
},
"BGP_VOQ_CHASSIS_NEIGHBOR|3.3.3.1": {
"rrclient": "0",
"name": "str2-sonic-lc1-1-ASIC0",
"local_addr": "3.3.3.2",
"nhopself": "0",
"admin_status": "up",
"holdtime": "10",
"asn": "65200",
"keepalive": "3"
},
"BGP_VOQ_CHASSIS_NEIGHBOR|3.3.3.2": {
"rrclient": "0",
"name": "str2-sonic-lc2-1-ASIC0",
"local_addr": "3.3.3.2",
"nhopself": "0",
"admin_status": "up",
"holdtime": "10",
"asn": "65200",
"keepalive": "3"
},
"BGP_VOQ_CHASSIS_NEIGHBOR|3.3.3.8": {
"rrclient": "0",
"name": "str2-sonic-lc1-1-ASIC1",
"local_addr": "3.3.3.9",
"nhopself": "0",
"admin_status": "up",
"holdtime": "10",
"asn": "65200",
"keepalive": "3"
},
"ACL_RULE|DATAACL_5|RULE_1": {
"IP_PROTOCOL": "126",
"PACKET_ACTION": "FORWARD",
Expand Down
91 changes: 91 additions & 0 deletions tests/mock_tables/asic0/no_ext_bgp_neigh.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
"ipv4Unicast":{
"routerId":"192.0.0.6",
"as":65100,
"vrfId":0,
"vrfName":"default",
"tableVersion":59923,
"ribCount":101147,
"ribMemory":18611048,
"peerCount":3,
"peerMemory":2222424,
"peerGroupCount":2,
"peerGroupMemory":128,
"peers":{
"3.3.3.1":{
"hostname":"str2-sonic-lc1-1",
"remoteAs":65100,
"localAs":65100,
"version":4,
"msgRcvd":277,
"msgSent":9,
"tableVersion":0,
"outq":0,
"inq":0,
"peerUptime":"00:00:14",
"peerUptimeMsec":14000,
"peerUptimeEstablishedEpoch":1703036129,
"pfxRcd":33798,
"pfxSnt":2,
"state":"Established",
"peerState":"OK",
"connectionsEstablished":1,
"connectionsDropped":0,
"desc":"str2-sonic-lc1-1-ASIC0",
"idType":"ipv4"
},
"3.3.3.2":{
"hostname":"str2-sonic-lc1-1",
"remoteAs":65100,
"localAs":65100,
"version":4,
"msgRcvd":277,
"msgSent":9,
"tableVersion":0,
"outq":0,
"inq":0,
"peerUptime":"00:00:14",
"peerUptimeMsec":14000,
"peerUptimeEstablishedEpoch":1703036129,
"pfxRcd":33798,
"pfxSnt":2,
"state":"Established",
"peerState":"OK",
"connectionsEstablished":1,
"connectionsDropped":0,
"desc":"str2-sonic-lc1-1-ASIC1",
"idType":"ipv4"
},
"3.3.3.8":{
"hostname":"str2-sonic-lc2-1",
"remoteAs":65100,
"localAs":65100,
"version":4,
"msgRcvd":12,
"msgSent":10,
"tableVersion":0,
"outq":0,
"inq":0,
"peerUptime":"00:00:15",
"peerUptimeMsec":15000,
"peerUptimeEstablishedEpoch":1703036128,
"pfxRcd":4,
"pfxSnt":2,
"state":"Established",
"peerState":"OK",
"connectionsEstablished":1,
"connectionsDropped":0,
"desc":"ASIC1",
"idType":"ipv4"
}
},
"failedPeers":0,
"displayedPeers":3,
"totalPeers":3,
"dynamicPeers":0,
"bestPath":{
"multiPathRelax":"true",
"peerTypeRelax":true
}
}
}
57 changes: 57 additions & 0 deletions tests/mock_tables/asic0/show_ip_bgp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"vrfId": 0,
"vrfName": "default",
"tableVersion": 59925,
"routerId": "192.0.0.6",
"defaultLocPrf": 100,
"localAS": 65100,
"routes": {
"0.0.0.0/0": [
{
"valid": true,
"multipath": true,
"pathFrom": "internal",
"prefix": "0.0.0.0",
"prefixLen": 0,
"network": "0.0.0.0\/0",
"version": 12050,
"locPrf": 100,
"weight": 0,
"peerId": "3.3.3.2",
"path": "65200 6666 6667",
"origin": "IGP",
"nexthops": [
{
"ip": "10.0.0.7",
"hostname": "str2-sonic-lc1-1",
"afi": "ipv4",
"used": true
}
]
},
{
"valid": true,
"bestpath": true,
"selectionReason": "Router ID",
"pathFrom": "internal",
"prefix": "0.0.0.0",
"prefixLen": 0,
"network": "0.0.0.0\/0",
"version": 12050,
"locPrf": 100,
"weight": 0,
"peerId": "3.3.3.1",
"path": "65200 6666 6667",
"origin": "IGP",
"nexthops": [
{
"ip": "10.0.0.1",
"hostname": "str2-sonic-lc1-1",
"afi": "ipv4",
"used": true
}
]
}
]
}
}
30 changes: 30 additions & 0 deletions tests/mock_tables/asic1/config_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -197,5 +197,35 @@
"holdtime": "0",
"asn": "65100",
"keepalive": "0"
},
"BGP_VOQ_CHASSIS_NEIGHBOR|3.3.3.1": {
"rrclient": "0",
"name": "str2-sonic-lc1-1-ASIC1",
"local_addr": "3.3.3.2",
"nhopself": "0",
"admin_status": "up",
"holdtime": "10",
"asn": "65200",
"keepalive": "3"
},
"BGP_VOQ_CHASSIS_NEIGHBOR|3.3.3.2": {
"rrclient": "0",
"name": "str2-sonic-lc3-1-ASIC0",
"local_addr": "3.3.3.2",
"nhopself": "0",
"admin_status": "up",
"holdtime": "10",
"asn": "65200",
"keepalive": "3"
},
"BGP_VOQ_CHASSIS_NEIGHBOR|3.3.3.6": {
"rrclient": "0",
"name": "str2-sonic-lc3-1-ASIC1",
"local_addr": "3.3.3.7",
"nhopself": "0",
"admin_status": "up",
"holdtime": "10",
"asn": "65200",
"keepalive": "3"
}
}
Loading
Loading