Skip to content

Commit 9515c64

Browse files
authored
[chassis]: Support show ip bgp summary to display without error when no external neighbors are configured on chassis LC (#3099)
Support show ip bgp summary to display without error when no external neighbors are configured on chassis LC
1 parent 9400691 commit 9515c64

File tree

9 files changed

+1588897
-10
lines changed

9 files changed

+1588897
-10
lines changed

tests/bgp_commands_test.py

+79-1
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22

33
import pytest
44
import importlib
5+
import mock
56

67
from click.testing import CliRunner
78

89
from utilities_common import multi_asic
910
from utilities_common import constants
11+
from utilities_common import bgp_util
12+
from utilities_common.db import Db
1013

1114
from unittest.mock import patch
1215

1316
from sonic_py_common import device_info
17+
from sonic_py_common import multi_asic as masic
1418
show_bgp_summary_v4 = """\
1519
1620
IPv4 Unicast Summary:
@@ -277,6 +281,44 @@
277281
Total number of neighbors 23
278282
"""
279283

284+
SHOW_BGP_SUMMARY_V4_NO_EXT_NEIGHBORS = """
285+
IPv4 Unicast Summary:
286+
asic0: BGP router identifier 10.1.0.32, local AS number 65100 vrf-id 0
287+
BGP table version 8972
288+
RIB entries 0, using 0 bytes of memory
289+
Peers 0, using 0 KiB of memory
290+
Peer groups 0, using 0 bytes of memory
291+
292+
293+
Neighbhor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd NeighborName
294+
----------- --- ---- --------- --------- -------- ----- ------ --------- -------------- --------------
295+
296+
Total number of neighbors 0
297+
"""
298+
299+
SHOW_BGP_SUMMARY_ALL_V4_NO_EXT_NEIGHBORS = """
300+
IPv4 Unicast Summary:
301+
asic0: BGP router identifier 192.0.0.6, local AS number 65100 vrf-id 0
302+
BGP table version 59923
303+
asic1: BGP router identifier 192.0.0.8, local AS number 65100 vrf-id 0
304+
BGP table version 64918
305+
RIB entries 202298, using 37222832 bytes of memory
306+
Peers 6, using 4444848 KiB of memory
307+
Peer groups 4, using 256 bytes of memory
308+
309+
310+
Neighbhor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd NeighborName
311+
----------- --- ----- --------- --------- -------- ----- ------ --------- -------------- ----------------------
312+
3.3.3.1 4 65100 277 9 0 0 0 00:00:14 33798 str2-sonic-lc1-1-ASIC0
313+
3.3.3.1 4 65100 280 14 0 0 0 00:00:22 33798 str2-sonic-lc1-1-ASIC1
314+
3.3.3.2 4 65100 277 9 0 0 0 00:00:14 33798 str2-sonic-lc2-1-ASIC0
315+
3.3.3.2 4 65100 280 14 0 0 0 00:00:22 33798 str2-sonic-lc3-1-ASIC0
316+
3.3.3.6 4 65100 14 14 0 0 0 00:00:23 4 str2-sonic-lc3-1-ASIC1
317+
3.3.3.8 4 65100 12 10 0 0 0 00:00:15 4 str2-sonic-lc1-1-ASIC1
318+
319+
Total number of neighbors 6
320+
"""
321+
280322

281323
class TestBgpCommandsSingleAsic(object):
282324
@classmethod
@@ -430,6 +472,7 @@ def teardown_class(cls):
430472
dbconnector.load_database_config()
431473

432474

475+
433476
class TestBgpCommandsMultiAsic(object):
434477
@classmethod
435478
def setup_class(cls):
@@ -439,6 +482,8 @@ def setup_class(cls):
439482
from .mock_tables import dbconnector
440483
dbconnector.load_namespace_config()
441484

485+
486+
442487
@pytest.mark.parametrize('setup_multi_asic_bgp_instance',
443488
['show_bgp_summary_no_neigh'], indirect=['setup_multi_asic_bgp_instance'])
444489
def test_bgp_summary_multi_asic_no_v4_neigh(
@@ -453,6 +498,7 @@ def test_bgp_summary_multi_asic_no_v4_neigh(
453498
assert result.exit_code == 0
454499
assert result.output == show_error_no_v4_neighbor_multi_asic
455500

501+
456502
@pytest.mark.parametrize('setup_multi_asic_bgp_instance',
457503
['show_bgp_summary_no_neigh'], indirect=['setup_multi_asic_bgp_instance'])
458504
def test_bgp_summary_multi_asic_no_v6_neigh(
@@ -467,7 +513,39 @@ def test_bgp_summary_multi_asic_no_v6_neigh(
467513
assert result.exit_code == 0
468514
assert result.output == show_error_no_v6_neighbor_multi_asic
469515

470-
@classmethod
516+
517+
@patch.object(bgp_util, 'get_external_bgp_neighbors_dict', mock.MagicMock(return_value={}))
518+
@patch.object(multi_asic.MultiAsic, 'get_display_option', mock.MagicMock(return_value=constants.DISPLAY_EXTERNAL))
519+
@pytest.mark.parametrize('setup_multi_asic_bgp_instance',
520+
['show_bgp_summary_no_ext_neigh_on_all_asic'], indirect=['setup_multi_asic_bgp_instance'])
521+
@patch.object(device_info, 'is_chassis', mock.MagicMock(return_value=True))
522+
def test_bgp_summary_multi_asic_no_external_neighbor(
523+
self,
524+
setup_bgp_commands,
525+
setup_multi_asic_bgp_instance):
526+
show = setup_bgp_commands
527+
runner = CliRunner()
528+
result = runner.invoke(
529+
show.cli.commands["ip"].commands["bgp"].commands["summary"], [])
530+
print("{}".format(result.output))
531+
assert result.exit_code == 0
532+
assert result.output == SHOW_BGP_SUMMARY_V4_NO_EXT_NEIGHBORS
533+
534+
535+
@pytest.mark.parametrize('setup_multi_asic_bgp_instance',
536+
['show_bgp_summary_no_ext_neigh_on_all_asic'], indirect=['setup_multi_asic_bgp_instance'])
537+
def test_bgp_summary_multi_asic_display_with_no_external_neighbor(
538+
self,
539+
setup_bgp_commands,
540+
setup_multi_asic_bgp_instance):
541+
show = setup_bgp_commands
542+
runner = CliRunner()
543+
result = runner.invoke(
544+
show.cli.commands["ip"].commands["bgp"].commands["summary"], ["-dall"])
545+
print("{}".format(result.output))
546+
assert result.exit_code == 0
547+
assert result.output == SHOW_BGP_SUMMARY_ALL_V4_NO_EXT_NEIGHBORS
548+
471549
def teardown_class(cls):
472550
print("TEARDOWN")
473551
from .mock_tables import mock_single_asic

tests/conftest.py

+18
Original file line numberDiff line numberDiff line change
@@ -350,11 +350,29 @@ def mock_run_show_sum_bgp_command(vtysh_cmd, bgp_namespace, vtysh_shell_cmd=cons
350350
else:
351351
return ""
352352

353+
def mock_run_show_summ_bgp_command_no_ext_neigh_on_all_asic(vtysh_cmd, bgp_namespace, vtysh_shell_cmd=constants.VTYSH_COMMAND):
354+
if vtysh_cmd == "show ip bgp summary json":
355+
m_asic_json_file = 'no_ext_bgp_neigh.json'
356+
else:
357+
m_asic_json_file = 'device_bgp_info.json'
358+
359+
bgp_mocked_json = os.path.join(
360+
test_path, 'mock_tables', bgp_namespace, m_asic_json_file)
361+
if os.path.isfile(bgp_mocked_json):
362+
with open(bgp_mocked_json) as json_data:
363+
mock_frr_data = json_data.read()
364+
return mock_frr_data
365+
else:
366+
return ""
367+
368+
353369
_old_run_bgp_command = bgp_util.run_bgp_command
354370
if request.param == 'ip_route_for_int_ip':
355371
bgp_util.run_bgp_command = mock_run_bgp_command_for_static
356372
elif request.param == 'show_bgp_summary_no_neigh':
357373
bgp_util.run_bgp_command = mock_run_show_sum_bgp_command
374+
elif request.param == 'show_bgp_summary_no_ext_neigh_on_all_asic':
375+
bgp_util.run_bgp_command = mock_run_show_summ_bgp_command_no_ext_neigh_on_all_asic
358376
else:
359377
bgp_util.run_bgp_command = mock_run_bgp_command
360378

tests/mock_tables/asic0/config_db.json

+30
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,36 @@
247247
"asn": "65200",
248248
"keepalive": "3"
249249
},
250+
"BGP_VOQ_CHASSIS_NEIGHBOR|3.3.3.1": {
251+
"rrclient": "0",
252+
"name": "str2-sonic-lc1-1-ASIC0",
253+
"local_addr": "3.3.3.2",
254+
"nhopself": "0",
255+
"admin_status": "up",
256+
"holdtime": "10",
257+
"asn": "65200",
258+
"keepalive": "3"
259+
},
260+
"BGP_VOQ_CHASSIS_NEIGHBOR|3.3.3.2": {
261+
"rrclient": "0",
262+
"name": "str2-sonic-lc2-1-ASIC0",
263+
"local_addr": "3.3.3.2",
264+
"nhopself": "0",
265+
"admin_status": "up",
266+
"holdtime": "10",
267+
"asn": "65200",
268+
"keepalive": "3"
269+
},
270+
"BGP_VOQ_CHASSIS_NEIGHBOR|3.3.3.8": {
271+
"rrclient": "0",
272+
"name": "str2-sonic-lc1-1-ASIC1",
273+
"local_addr": "3.3.3.9",
274+
"nhopself": "0",
275+
"admin_status": "up",
276+
"holdtime": "10",
277+
"asn": "65200",
278+
"keepalive": "3"
279+
},
250280
"ACL_RULE|DATAACL_5|RULE_1": {
251281
"IP_PROTOCOL": "126",
252282
"PACKET_ACTION": "FORWARD",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
{
2+
"ipv4Unicast":{
3+
"routerId":"192.0.0.6",
4+
"as":65100,
5+
"vrfId":0,
6+
"vrfName":"default",
7+
"tableVersion":59923,
8+
"ribCount":101147,
9+
"ribMemory":18611048,
10+
"peerCount":3,
11+
"peerMemory":2222424,
12+
"peerGroupCount":2,
13+
"peerGroupMemory":128,
14+
"peers":{
15+
"3.3.3.1":{
16+
"hostname":"str2-sonic-lc1-1",
17+
"remoteAs":65100,
18+
"localAs":65100,
19+
"version":4,
20+
"msgRcvd":277,
21+
"msgSent":9,
22+
"tableVersion":0,
23+
"outq":0,
24+
"inq":0,
25+
"peerUptime":"00:00:14",
26+
"peerUptimeMsec":14000,
27+
"peerUptimeEstablishedEpoch":1703036129,
28+
"pfxRcd":33798,
29+
"pfxSnt":2,
30+
"state":"Established",
31+
"peerState":"OK",
32+
"connectionsEstablished":1,
33+
"connectionsDropped":0,
34+
"desc":"str2-sonic-lc1-1-ASIC0",
35+
"idType":"ipv4"
36+
},
37+
"3.3.3.2":{
38+
"hostname":"str2-sonic-lc1-1",
39+
"remoteAs":65100,
40+
"localAs":65100,
41+
"version":4,
42+
"msgRcvd":277,
43+
"msgSent":9,
44+
"tableVersion":0,
45+
"outq":0,
46+
"inq":0,
47+
"peerUptime":"00:00:14",
48+
"peerUptimeMsec":14000,
49+
"peerUptimeEstablishedEpoch":1703036129,
50+
"pfxRcd":33798,
51+
"pfxSnt":2,
52+
"state":"Established",
53+
"peerState":"OK",
54+
"connectionsEstablished":1,
55+
"connectionsDropped":0,
56+
"desc":"str2-sonic-lc1-1-ASIC1",
57+
"idType":"ipv4"
58+
},
59+
"3.3.3.8":{
60+
"hostname":"str2-sonic-lc2-1",
61+
"remoteAs":65100,
62+
"localAs":65100,
63+
"version":4,
64+
"msgRcvd":12,
65+
"msgSent":10,
66+
"tableVersion":0,
67+
"outq":0,
68+
"inq":0,
69+
"peerUptime":"00:00:15",
70+
"peerUptimeMsec":15000,
71+
"peerUptimeEstablishedEpoch":1703036128,
72+
"pfxRcd":4,
73+
"pfxSnt":2,
74+
"state":"Established",
75+
"peerState":"OK",
76+
"connectionsEstablished":1,
77+
"connectionsDropped":0,
78+
"desc":"ASIC1",
79+
"idType":"ipv4"
80+
}
81+
},
82+
"failedPeers":0,
83+
"displayedPeers":3,
84+
"totalPeers":3,
85+
"dynamicPeers":0,
86+
"bestPath":{
87+
"multiPathRelax":"true",
88+
"peerTypeRelax":true
89+
}
90+
}
91+
}
+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"vrfId": 0,
3+
"vrfName": "default",
4+
"tableVersion": 59925,
5+
"routerId": "192.0.0.6",
6+
"defaultLocPrf": 100,
7+
"localAS": 65100,
8+
"routes": {
9+
"0.0.0.0/0": [
10+
{
11+
"valid": true,
12+
"multipath": true,
13+
"pathFrom": "internal",
14+
"prefix": "0.0.0.0",
15+
"prefixLen": 0,
16+
"network": "0.0.0.0\/0",
17+
"version": 12050,
18+
"locPrf": 100,
19+
"weight": 0,
20+
"peerId": "3.3.3.2",
21+
"path": "65200 6666 6667",
22+
"origin": "IGP",
23+
"nexthops": [
24+
{
25+
"ip": "10.0.0.7",
26+
"hostname": "str2-sonic-lc1-1",
27+
"afi": "ipv4",
28+
"used": true
29+
}
30+
]
31+
},
32+
{
33+
"valid": true,
34+
"bestpath": true,
35+
"selectionReason": "Router ID",
36+
"pathFrom": "internal",
37+
"prefix": "0.0.0.0",
38+
"prefixLen": 0,
39+
"network": "0.0.0.0\/0",
40+
"version": 12050,
41+
"locPrf": 100,
42+
"weight": 0,
43+
"peerId": "3.3.3.1",
44+
"path": "65200 6666 6667",
45+
"origin": "IGP",
46+
"nexthops": [
47+
{
48+
"ip": "10.0.0.1",
49+
"hostname": "str2-sonic-lc1-1",
50+
"afi": "ipv4",
51+
"used": true
52+
}
53+
]
54+
}
55+
]
56+
}
57+
}

tests/mock_tables/asic1/config_db.json

+30
Original file line numberDiff line numberDiff line change
@@ -197,5 +197,35 @@
197197
"holdtime": "0",
198198
"asn": "65100",
199199
"keepalive": "0"
200+
},
201+
"BGP_VOQ_CHASSIS_NEIGHBOR|3.3.3.1": {
202+
"rrclient": "0",
203+
"name": "str2-sonic-lc1-1-ASIC1",
204+
"local_addr": "3.3.3.2",
205+
"nhopself": "0",
206+
"admin_status": "up",
207+
"holdtime": "10",
208+
"asn": "65200",
209+
"keepalive": "3"
210+
},
211+
"BGP_VOQ_CHASSIS_NEIGHBOR|3.3.3.2": {
212+
"rrclient": "0",
213+
"name": "str2-sonic-lc3-1-ASIC0",
214+
"local_addr": "3.3.3.2",
215+
"nhopself": "0",
216+
"admin_status": "up",
217+
"holdtime": "10",
218+
"asn": "65200",
219+
"keepalive": "3"
220+
},
221+
"BGP_VOQ_CHASSIS_NEIGHBOR|3.3.3.6": {
222+
"rrclient": "0",
223+
"name": "str2-sonic-lc3-1-ASIC1",
224+
"local_addr": "3.3.3.7",
225+
"nhopself": "0",
226+
"admin_status": "up",
227+
"holdtime": "10",
228+
"asn": "65200",
229+
"keepalive": "3"
200230
}
201231
}

0 commit comments

Comments
 (0)