Skip to content

Commit 3fa0854

Browse files
authored
[CLI][show bgp] On chassis don't show internal BGP sessions by default (#1927)
1 parent 6de91af commit 3fa0854

File tree

7 files changed

+1113
-10
lines changed

7 files changed

+1113
-10
lines changed

tests/bgp_commands_test.py

+180
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
from click.testing import CliRunner
66

7+
from utilities_common import multi_asic
8+
from utilities_common import constants
9+
10+
from unittest.mock import patch
11+
12+
from sonic_py_common import device_info
713
show_bgp_summary_v4 = """\
814
915
IPv4 Unicast Summary:
@@ -91,6 +97,117 @@
9197
Error: bgp summary from bgp container not in json format
9298
"""
9399

100+
show_bgp_summary_v4_chassis = """\
101+
102+
IPv4 Unicast Summary:
103+
BGP router identifier 10.3.147.15, local AS number 65100 vrf-id 0
104+
BGP table version 21464
105+
RIB entries 25783, using 4950336 bytes of memory
106+
Peers 23, using 501768 KiB of memory
107+
Peer groups 3, using 192 bytes of memory
108+
109+
110+
Neighbhor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd NeighborName
111+
----------- --- ----- --------- --------- -------- ----- ------ --------- -------------- --------------
112+
10.0.0.1 4 65200 4632 11028 0 0 0 00:18:31 8514 ARISTA01T2
113+
10.0.0.9 4 65202 4632 11029 0 0 0 00:18:33 8514 ARISTA05T2
114+
10.0.0.13 4 65203 4632 11028 0 0 0 00:18:33 8514 ARISTA07T2
115+
10.0.0.17 4 65204 4631 11028 0 0 0 00:18:31 8514 ARISTA09T2
116+
10.0.0.21 4 65205 4632 11031 0 0 0 00:18:33 8514 ARISTA11T2
117+
10.0.0.25 4 65206 4632 11031 0 0 0 00:18:33 8514 ARISTA13T2
118+
10.0.0.29 4 65207 4632 11028 0 0 0 00:18:31 8514 ARISTA15T2
119+
10.0.0.33 4 65208 4633 11029 0 0 0 00:18:33 8514 ARISTA01T0
120+
10.0.0.37 4 65210 4632 11028 0 0 0 00:18:32 8514 ARISTA03T0
121+
10.0.0.39 4 65211 4629 6767 0 0 0 00:18:22 8514 ARISTA04T0
122+
10.0.0.41 4 65212 4632 11028 0 0 0 00:18:32 8514 ARISTA05T0
123+
10.0.0.43 4 65213 4629 6767 0 0 0 00:18:23 8514 ARISTA06T0
124+
10.0.0.45 4 65214 4633 11029 0 0 0 00:18:33 8514 ARISTA07T0
125+
10.0.0.47 4 65215 4629 6767 0 0 0 00:18:23 8514 ARISTA08T0
126+
10.0.0.49 4 65216 4633 11029 0 0 0 00:18:35 8514 ARISTA09T0
127+
10.0.0.51 4 65217 4633 11029 0 0 0 00:18:33 8514 ARISTA10T0
128+
10.0.0.53 4 65218 4632 11029 0 0 0 00:18:35 8514 ARISTA11T0
129+
10.0.0.55 4 65219 4632 11029 0 0 0 00:18:33 8514 ARISTA12T0
130+
10.0.0.57 4 65220 4632 11029 0 0 0 00:18:35 8514 ARISTA13T0
131+
10.0.0.59 4 65221 4632 11029 0 0 0 00:18:33 8514 ARISTA14T0
132+
133+
Total number of neighbors 20
134+
"""
135+
136+
show_bgp_summary_v6_chassis = """\
137+
138+
IPv6 Unicast Summary:
139+
BGP router identifier 10.3.147.15, local AS number 65100 vrf-id 0
140+
BGP table version 12971
141+
RIB entries 25783, using 4950336 bytes of memory
142+
Peers 23, using 501768 KiB of memory
143+
Peer groups 3, using 192 bytes of memory
144+
145+
146+
Neighbhor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd NeighborName
147+
----------- --- ----- --------- --------- -------- ----- ------ --------- -------------- --------------
148+
fc00::1a 4 65203 4438 6578 0 0 0 00:08:57 8514 ARISTA07T2
149+
fc00::2 4 65200 4439 6578 0 0 0 00:08:56 8513 ARISTA01T2
150+
fc00::2a 4 65205 4439 6578 0 0 0 00:08:57 8514 ARISTA11T2
151+
fc00::3a 4 65207 4439 6578 0 0 0 00:08:57 8514 ARISTA15T2
152+
fc00::4a 4 65210 4439 6579 0 0 0 00:08:59 8514 ARISTA03T0
153+
fc00::4e 4 65211 4440 6579 0 0 0 00:09:00 8514 ARISTA04T0
154+
fc00::5a 4 65214 4440 6579 0 0 0 00:09:00 8514 ARISTA07T0
155+
fc00::5e 4 65215 4438 6576 0 0 0 00:08:50 8514 ARISTA08T0
156+
fc00::6a 4 65218 4441 6580 0 0 0 00:09:01 8514 ARISTA11T0
157+
fc00::6e 4 65219 4442 6580 0 0 0 00:09:01 8514 ARISTA12T0
158+
fc00::7a 4 65222 4441 6580 0 0 0 00:09:01 8514 ARISTA15T0
159+
fc00::12 4 65202 4438 6578 0 0 0 00:08:57 8514 ARISTA05T2
160+
fc00::22 4 65204 4438 6578 0 0 0 00:08:57 8514 ARISTA09T2
161+
fc00::32 4 65206 4438 6578 0 0 0 00:08:57 8514 ARISTA13T2
162+
fc00::42 4 65208 4442 6580 0 0 0 00:09:01 8514 ARISTA01T0
163+
fc00::52 4 65212 4439 6579 0 0 0 00:08:59 8514 ARISTA05T0
164+
fc00::56 4 65213 4439 6579 0 0 0 00:08:59 8514 ARISTA06T0
165+
fc00::62 4 65216 4438 6576 0 0 0 00:08:50 8514 ARISTA09T0
166+
fc00::66 4 65217 4442 6580 0 0 0 00:09:01 8514 ARISTA10T0
167+
fc00::72 4 65220 4441 6580 0 0 0 00:09:01 8514 ARISTA13T0
168+
169+
Total number of neighbors 20
170+
"""
171+
172+
show_bgp_summary_v4_all_chassis = """\
173+
174+
IPv4 Unicast Summary:
175+
BGP router identifier 10.3.147.15, local AS number 65100 vrf-id 0
176+
BGP table version 21464
177+
RIB entries 25783, using 4950336 bytes of memory
178+
Peers 23, using 501768 KiB of memory
179+
Peer groups 3, using 192 bytes of memory
180+
181+
182+
Neighbhor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd NeighborName
183+
----------- --- ----- --------- --------- -------- ----- ------ --------- -------------- ------------------
184+
3.3.3.6 4 65100 0 0 0 0 0 never Connect str2-chassis-lc6-1
185+
3.3.3.7 4 65100 808 178891 0 0 0 00:17:47 1458 str2-chassis-lc7-1
186+
10.0.0.1 4 65200 4632 11028 0 0 0 00:18:31 8514 ARISTA01T2
187+
10.0.0.9 4 65202 4632 11029 0 0 0 00:18:33 8514 ARISTA05T2
188+
10.0.0.13 4 65203 4632 11028 0 0 0 00:18:33 8514 ARISTA07T2
189+
10.0.0.17 4 65204 4631 11028 0 0 0 00:18:31 8514 ARISTA09T2
190+
10.0.0.21 4 65205 4632 11031 0 0 0 00:18:33 8514 ARISTA11T2
191+
10.0.0.25 4 65206 4632 11031 0 0 0 00:18:33 8514 ARISTA13T2
192+
10.0.0.29 4 65207 4632 11028 0 0 0 00:18:31 8514 ARISTA15T2
193+
10.0.0.33 4 65208 4633 11029 0 0 0 00:18:33 8514 ARISTA01T0
194+
10.0.0.37 4 65210 4632 11028 0 0 0 00:18:32 8514 ARISTA03T0
195+
10.0.0.39 4 65211 4629 6767 0 0 0 00:18:22 8514 ARISTA04T0
196+
10.0.0.41 4 65212 4632 11028 0 0 0 00:18:32 8514 ARISTA05T0
197+
10.0.0.43 4 65213 4629 6767 0 0 0 00:18:23 8514 ARISTA06T0
198+
10.0.0.45 4 65214 4633 11029 0 0 0 00:18:33 8514 ARISTA07T0
199+
10.0.0.47 4 65215 4629 6767 0 0 0 00:18:23 8514 ARISTA08T0
200+
10.0.0.49 4 65216 4633 11029 0 0 0 00:18:35 8514 ARISTA09T0
201+
10.0.0.51 4 65217 4633 11029 0 0 0 00:18:33 8514 ARISTA10T0
202+
10.0.0.53 4 65218 4632 11029 0 0 0 00:18:35 8514 ARISTA11T0
203+
10.0.0.55 4 65219 4632 11029 0 0 0 00:18:33 8514 ARISTA12T0
204+
10.0.0.57 4 65220 4632 11029 0 0 0 00:18:35 8514 ARISTA13T0
205+
10.0.0.59 4 65221 4632 11029 0 0 0 00:18:33 8514 ARISTA14T0
206+
10.0.0.61 4 65222 4633 11029 0 0 0 00:18:33 8514 INT_NEIGH0
207+
208+
Total number of neighbors 23
209+
"""
210+
94211

95212
class TestBgpCommands(object):
96213
@classmethod
@@ -139,3 +256,66 @@ def test_bgp_summary_error(
139256
print("{}".format(result.output))
140257
assert result.exit_code == 2
141258
assert result.output == show_error_invalid_json
259+
260+
def display_external(self):
261+
return constants.DISPLAY_EXTERNAL
262+
263+
def display_all(self):
264+
return constants.DISPLAY_ALL
265+
266+
@pytest.mark.parametrize(
267+
'setup_single_bgp_instance_chassis', ['v4'],
268+
indirect=['setup_single_bgp_instance_chassis']
269+
)
270+
@patch.object(multi_asic.MultiAsic, 'get_display_option', display_external)
271+
@patch('sonic_py_common.device_info.get_platform_info')
272+
def test_bgp_summary_v4_chassis(
273+
self, mock_is_chassis, setup_bgp_commands,
274+
setup_single_bgp_instance_chassis
275+
):
276+
mock_is_chassis.return_value = {'switch_type': 'voq'}
277+
show = setup_bgp_commands
278+
runner = CliRunner()
279+
result = runner.invoke(
280+
show.cli.commands["ip"].commands["bgp"].commands["summary"], [])
281+
print("{}".format(result.output))
282+
assert result.exit_code == 0
283+
assert result.output == show_bgp_summary_v4_chassis
284+
285+
@pytest.mark.parametrize(
286+
'setup_single_bgp_instance_chassis', ['v6'],
287+
indirect=['setup_single_bgp_instance_chassis']
288+
)
289+
@patch.object(multi_asic.MultiAsic, 'get_display_option', display_external)
290+
@patch('sonic_py_common.device_info.get_platform_info')
291+
def test_bgp_summary_v6_chassis(
292+
self, mock_is_chassis, setup_bgp_commands,
293+
setup_single_bgp_instance_chassis
294+
):
295+
mock_is_chassis.return_value = {'switch_type': 'voq'}
296+
show = setup_bgp_commands
297+
runner = CliRunner()
298+
result = runner.invoke(
299+
show.cli.commands["ipv6"].commands["bgp"].commands["summary"], [])
300+
print("{}".format(result.output))
301+
assert result.exit_code == 0
302+
assert result.output == show_bgp_summary_v6_chassis
303+
304+
@pytest.mark.parametrize(
305+
'setup_single_bgp_instance_chassis', ['v4'],
306+
indirect=['setup_single_bgp_instance_chassis']
307+
)
308+
@patch.object(multi_asic.MultiAsic, 'get_display_option', display_all)
309+
@patch('sonic_py_common.device_info.get_platform_info')
310+
def test_bgp_summary_v4_all_chassis(
311+
self, mock_is_chassis, setup_bgp_commands,
312+
setup_single_bgp_instance_chassis
313+
):
314+
mock_is_chassis.return_value = {'switch_type': 'voq'}
315+
show = setup_bgp_commands
316+
runner = CliRunner()
317+
result = runner.invoke(
318+
show.cli.commands["ip"].commands["bgp"].commands["summary"], [])
319+
print("{}".format(result.output))
320+
assert result.exit_code == 0
321+
assert result.output == show_bgp_summary_v4_all_chassis

tests/conftest.py

+28-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import sys
55
from unittest import mock
66

7-
87
import pytest
98
from sonic_py_common import device_info, multi_asic
109
from swsscommon.swsscommon import ConfigDBConnector
@@ -126,12 +125,37 @@ def setup_multi_broadcom_masic():
126125
multi_asic.is_multi_asic= mock.MagicMock(return_value=False)
127126

128127

128+
@pytest.fixture
129+
def setup_single_bgp_instance_chassis(request):
130+
import utilities_common.bgp_util as bgp_util
131+
132+
def mock_show_bgp_summary(
133+
vtysh_cmd, bgp_namespace, vtysh_shell_cmd=constants.RVTYSH_COMMAND
134+
):
135+
if os.path.isfile(bgp_mocked_json):
136+
with open(bgp_mocked_json) as json_data:
137+
mock_frr_data = json_data.read()
138+
return mock_frr_data
139+
return ""
140+
141+
if request.param == 'v4':
142+
bgp_mocked_json = os.path.join(
143+
test_path, 'mock_tables', 'ipv4_bgp_summary_chassis.json')
144+
elif request.param == 'v6':
145+
bgp_mocked_json = os.path.join(
146+
test_path, 'mock_tables', 'ipv6_bgp_summary_chassis.json')
147+
148+
bgp_util.run_bgp_command = mock.MagicMock(
149+
return_value=mock_show_bgp_summary("", ""))
150+
151+
129152
@pytest.fixture
130153
def setup_t1_topo():
131154
dbconnector.topo = "t1"
132155
yield
133156
dbconnector.topo = None
134157

158+
135159
@pytest.fixture
136160
def setup_single_bgp_instance(request):
137161
import utilities_common.bgp_util as bgp_util
@@ -151,7 +175,7 @@ def mock_show_bgp_summary(vtysh_cmd, bgp_namespace, vtysh_shell_cmd=constants.RV
151175
mock_frr_data = json_data.read()
152176
return mock_frr_data
153177
return ""
154-
178+
155179
def mock_run_bgp_command_for_static(vtysh_cmd, bgp_namespace="", vtysh_shell_cmd=constants.RVTYSH_COMMAND):
156180
if vtysh_cmd == "show ip route vrf all static":
157181
return config_int_ip_common.show_ip_route_with_static_expected_output
@@ -176,7 +200,7 @@ def mock_run_show_ip_route_commands(request):
176200
else:
177201
return ""
178202

179-
203+
180204
if any ([request.param == 'ipv6_route_err', request.param == 'ip_route',\
181205
request.param == 'ip_specific_route', request.param == 'ip_special_route',\
182206
request.param == 'ipv6_route', request.param == 'ipv6_specific_route']):
@@ -248,7 +272,7 @@ def mock_run_bgp_command(vtysh_cmd, bgp_namespace, vtysh_shell_cmd=constants.RVT
248272
if m_asic_json_file.startswith('bgp_v4_network') or \
249273
m_asic_json_file.startswith('bgp_v6_network'):
250274
return mock_show_bgp_network_multi_asic(m_asic_json_file)
251-
275+
252276
if m_asic_json_file.startswith('bgp_v4_neighbor') or \
253277
m_asic_json_file.startswith('bgp_v6_neighbor'):
254278
return mock_show_bgp_neighbor_multi_asic(m_asic_json_file, bgp_namespace)

tests/mock_tables/config_db.json

+20
Original file line numberDiff line numberDiff line change
@@ -1533,6 +1533,26 @@
15331533
"nhopself": "0",
15341534
"rrclient": "0"
15351535
},
1536+
"BGP_VOQ_CHASSIS_NEIGHBOR|3.3.3.6": {
1537+
"admin_status": "up",
1538+
"asn": "65100",
1539+
"holdtime": "0",
1540+
"keepalive": "0",
1541+
"local_addr": "3.3.3.3",
1542+
"name": "str2-chassis-lc6-1",
1543+
"nhopself": "0",
1544+
"rrclient": "0"
1545+
},
1546+
"BGP_VOQ_CHASSIS_NEIGHBOR|3.3.3.7": {
1547+
"admin_status": "up",
1548+
"asn": "65100",
1549+
"holdtime": "0",
1550+
"keepalive": "0",
1551+
"local_addr": "3.3.3.3",
1552+
"name": "str2-chassis-lc7-1",
1553+
"nhopself": "0",
1554+
"rrclient": "0"
1555+
},
15361556
"FLEX_COUNTER_TABLE|QUEUE": {
15371557
"POLL_INTERVAL": "10000",
15381558
"FLEX_COUNTER_STATUS": "enable"

0 commit comments

Comments
 (0)