Skip to content

Commit 81c5349

Browse files
authored
[chassis] fix show bgp summary when no neighbors are present on one ASIC (#3158)
This PR #3099 fixes the case where on chassis Linecard there are no BGP neighbors. However, if the Linecard has neighbors on one ASIC but not on other, the command show bgp summary displayed no neighbors. This PR fixes this. How I did it Add check in bgp_util to create empty peer list only once Add UT to cover this case
1 parent a3cf5c0 commit 81c5349

File tree

4 files changed

+161
-10
lines changed

4 files changed

+161
-10
lines changed

tests/bgp_commands_test.py

+46-7
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,12 @@
280280
281281
Total number of neighbors 23
282282
"""
283-
284-
SHOW_BGP_SUMMARY_V4_NO_EXT_NEIGHBORS = """
283+
SHOW_BGP_SUMMARY_V4_NO_EXT_NEIGHBORS_ON_ALL_ASIC = """
285284
IPv4 Unicast Summary:
286285
asic0: BGP router identifier 10.1.0.32, local AS number 65100 vrf-id 0
287286
BGP table version 8972
287+
asic1: BGP router identifier 10.1.0.32, local AS number 65100 vrf-id 0
288+
BGP table version 8972
288289
RIB entries 0, using 0 bytes of memory
289290
Peers 0, using 0 KiB of memory
290291
Peer groups 0, using 0 bytes of memory
@@ -296,6 +297,24 @@
296297
Total number of neighbors 0
297298
"""
298299

300+
SHOW_BGP_SUMMARY_V4_NO_EXT_NEIGHBORS_ON_ASIC1 = """
301+
IPv4 Unicast Summary:
302+
asic0: BGP router identifier 192.0.0.6, local AS number 65100 vrf-id 0
303+
BGP table version 59923
304+
asic1: BGP router identifier 10.1.0.32, local AS number 65100 vrf-id 0
305+
BGP table version 8972
306+
RIB entries 3, using 3 bytes of memory
307+
Peers 3, using 3 KiB of memory
308+
Peer groups 3, using 3 bytes of memory
309+
310+
311+
Neighbhor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd NeighborName
312+
----------- --- ----- --------- --------- -------- ----- ------ --------- -------------- --------------
313+
10.0.0.1 4 65222 4633 11029 0 0 0 00:18:33 8514 ARISTA01T2
314+
315+
Total number of neighbors 1
316+
"""
317+
299318
SHOW_BGP_SUMMARY_ALL_V4_NO_EXT_NEIGHBORS = """
300319
IPv4 Unicast Summary:
301320
asic0: BGP router identifier 192.0.0.6, local AS number 65100 vrf-id 0
@@ -513,13 +532,14 @@ def test_bgp_summary_multi_asic_no_v6_neigh(
513532
assert result.exit_code == 0
514533
assert result.output == show_error_no_v6_neighbor_multi_asic
515534

516-
517535
@patch.object(bgp_util, 'get_external_bgp_neighbors_dict', mock.MagicMock(return_value={}))
536+
@patch.object(multi_asic.MultiAsic, 'get_ns_list_based_on_options', mock.Mock(return_value=['asic0', 'asic1']))
518537
@patch.object(multi_asic.MultiAsic, 'get_display_option', mock.MagicMock(return_value=constants.DISPLAY_EXTERNAL))
519538
@pytest.mark.parametrize('setup_multi_asic_bgp_instance',
520-
['show_bgp_summary_no_ext_neigh_on_all_asic'], indirect=['setup_multi_asic_bgp_instance'])
539+
['show_bgp_summary_no_ext_neigh_on_all_asic'],
540+
indirect=['setup_multi_asic_bgp_instance'])
521541
@patch.object(device_info, 'is_chassis', mock.MagicMock(return_value=True))
522-
def test_bgp_summary_multi_asic_no_external_neighbor(
542+
def test_bgp_summary_multi_asic_no_external_neighbors_on_all_asic(
523543
self,
524544
setup_bgp_commands,
525545
setup_multi_asic_bgp_instance):
@@ -529,8 +549,27 @@ def test_bgp_summary_multi_asic_no_external_neighbor(
529549
show.cli.commands["ip"].commands["bgp"].commands["summary"], [])
530550
print("{}".format(result.output))
531551
assert result.exit_code == 0
532-
assert result.output == SHOW_BGP_SUMMARY_V4_NO_EXT_NEIGHBORS
533-
552+
assert result.output == SHOW_BGP_SUMMARY_V4_NO_EXT_NEIGHBORS_ON_ALL_ASIC
553+
554+
555+
@patch.object(multi_asic.MultiAsic, 'get_ns_list_based_on_options', mock.Mock(return_value=['asic0', 'asic1']))
556+
@patch.object(multi_asic.MultiAsic, 'get_display_option', mock.MagicMock(return_value=constants.DISPLAY_EXTERNAL))
557+
@pytest.mark.parametrize('setup_multi_asic_bgp_instance',
558+
['show_bgp_summary_no_ext_neigh_on_asic1'],
559+
indirect=['setup_multi_asic_bgp_instance'])
560+
@patch.object(device_info, 'is_chassis', mock.MagicMock(return_value=True))
561+
def test_bgp_summary_multi_asic_no_external_neighbor_on_asic1(
562+
self,
563+
setup_bgp_commands,
564+
setup_multi_asic_bgp_instance):
565+
show = setup_bgp_commands
566+
runner = CliRunner()
567+
result = runner.invoke(
568+
show.cli.commands["ip"].commands["bgp"].commands["summary"], [])
569+
print("{}".format(result.output))
570+
assert result.exit_code == 0
571+
assert result.output == SHOW_BGP_SUMMARY_V4_NO_EXT_NEIGHBORS_ON_ASIC1
572+
534573

535574
@pytest.mark.parametrize('setup_multi_asic_bgp_instance',
536575
['show_bgp_summary_no_ext_neigh_on_all_asic'], indirect=['setup_multi_asic_bgp_instance'])

tests/conftest.py

+21-2
Original file line numberDiff line numberDiff line change
@@ -364,15 +364,34 @@ def mock_run_show_summ_bgp_command_no_ext_neigh_on_all_asic(vtysh_cmd, bgp_names
364364
return mock_frr_data
365365
else:
366366
return ""
367-
368-
367+
368+
def mock_run_show_summ_bgp_command_no_ext_neigh_on_asic1(vtysh_cmd, bgp_namespace, vtysh_shell_cmd=constants.VTYSH_COMMAND):
369+
if vtysh_cmd == "show ip bgp summary json":
370+
if bgp_namespace == "asic1":
371+
m_asic_json_file = 'no_ext_bgp_neigh.json'
372+
else:
373+
m_asic_json_file = 'show_ip_bgp_summary.json'
374+
else:
375+
m_asic_json_file = 'device_bgp_info.json'
376+
377+
bgp_mocked_json = os.path.join(
378+
test_path, 'mock_tables', bgp_namespace, m_asic_json_file)
379+
if os.path.isfile(bgp_mocked_json):
380+
with open(bgp_mocked_json) as json_data:
381+
mock_frr_data = json_data.read()
382+
return mock_frr_data
383+
else:
384+
return ""
385+
369386
_old_run_bgp_command = bgp_util.run_bgp_command
370387
if request.param == 'ip_route_for_int_ip':
371388
bgp_util.run_bgp_command = mock_run_bgp_command_for_static
372389
elif request.param == 'show_bgp_summary_no_neigh':
373390
bgp_util.run_bgp_command = mock_run_show_sum_bgp_command
374391
elif request.param == 'show_bgp_summary_no_ext_neigh_on_all_asic':
375392
bgp_util.run_bgp_command = mock_run_show_summ_bgp_command_no_ext_neigh_on_all_asic
393+
elif request.param == 'show_bgp_summary_no_ext_neigh_on_asic1':
394+
bgp_util.run_bgp_command = mock_run_show_summ_bgp_command_no_ext_neigh_on_asic1
376395
else:
377396
bgp_util.run_bgp_command = mock_run_bgp_command
378397

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
{
2+
"ipv4Unicast":{
3+
"routerId":"192.0.0.6",
4+
"as":65100,
5+
"vrfId":0,
6+
"vrfName":"default",
7+
"tableVersion":59923,
8+
"ribCount":163,
9+
"ribMemory":29992,
10+
"peerCount":3,
11+
"peerMemory":3704040,
12+
"peerGroupCount":3,
13+
"peerGroupMemory":128,
14+
"peers":{
15+
"3.3.3.2":{
16+
"hostname":"svcstr-sonic-lc1-1",
17+
"remoteAs":65100,
18+
"localAs":65100,
19+
"version":4,
20+
"msgRcvd":127,
21+
"msgSent":123,
22+
"tableVersion":0,
23+
"outq":0,
24+
"inq":0,
25+
"peerUptime":"00:05:26",
26+
"peerUptimeMsec":326000,
27+
"peerUptimeEstablishedEpoch":1707332746,
28+
"pfxRcd":16,
29+
"pfxSnt":12,
30+
"state":"Established",
31+
"peerState":"OK",
32+
"connectionsEstablished":1,
33+
"connectionsDropped":0,
34+
"desc":"ASIC1",
35+
"idType":"ipv4"
36+
},
37+
"3.3.3.8":{
38+
"hostname":"svcstr-sonic-lc2-1",
39+
"remoteAs":65100,
40+
"localAs":65100,
41+
"version":4,
42+
"msgRcvd":129,
43+
"msgSent":123,
44+
"tableVersion":0,
45+
"outq":0,
46+
"inq":0,
47+
"peerUptime":"00:05:26",
48+
"peerUptimeMsec":326000,
49+
"peerUptimeEstablishedEpoch":1707332746,
50+
"pfxRcd":18,
51+
"pfxSnt":12,
52+
"state":"Established",
53+
"peerState":"OK",
54+
"connectionsEstablished":1,
55+
"connectionsDropped":0,
56+
"desc":"svcstr-sonic-lc2-1-ASIC1",
57+
"idType":"ipv4"
58+
},
59+
"10.0.0.1":{
60+
"hostname":"ARISTA01T2",
61+
"remoteAs":65222,
62+
"localAs":65200,
63+
"version":4,
64+
"msgRcvd":4633,
65+
"msgSent":11029,
66+
"tableVersion":0,
67+
"outq":0,
68+
"inq":0,
69+
"peerUptime":"00:18:33",
70+
"peerUptimeMsec":326000,
71+
"peerUptimeEstablishedEpoch":1707332746,
72+
"pfxRcd":8514,
73+
"pfxSnt":12,
74+
"state":"Established",
75+
"peerState":"OK",
76+
"connectionsEstablished":1,
77+
"connectionsDropped":0,
78+
"desc":"ARISTA01T2",
79+
"idType":"ipv4"
80+
}
81+
82+
},
83+
"failedPeers":0,
84+
"displayedPeers": 5,
85+
"totalPeers":5,
86+
"dynamicPeers":0,
87+
"bestPath":{
88+
"multiPathRelax":"true",
89+
"peerTypeRelax":true
90+
}
91+
}
92+
}

utilities_common/bgp_util.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,8 @@ def process_bgp_summary_json(bgp_summary, cmd_output, device, has_bgp_neighbors=
401401

402402
bgp_summary.setdefault('peers', []).append(peers)
403403
else:
404-
bgp_summary['peers'] = []
404+
if 'peers' not in bgp_summary:
405+
bgp_summary['peers'] = []
405406
except KeyError as e:
406407
ctx = click.get_current_context()
407408
ctx.fail("{} missing in the bgp_summary".format(e.args[0]))

0 commit comments

Comments
 (0)