Skip to content

Commit 2331e38

Browse files
authored
avoid printing error if no neighbors are present (#2502)
* avoid printing error if no neighbors are present Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan <[email protected]>
1 parent c497c84 commit 2331e38

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

tests/bgp_commands_test.py

+36
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@
9797
Error: bgp summary from bgp container not in json format
9898
"""
9999

100+
show_error_no_v6_neighbor = """\
101+
No IPv6 neighbor is configured
102+
"""
103+
104+
show_error_no_v4_neighbor = """\
105+
No IPv4 neighbor is configured
106+
"""
107+
100108
show_bgp_summary_v4_chassis = """\
101109
102110
IPv4 Unicast Summary:
@@ -319,3 +327,31 @@ def test_bgp_summary_v4_all_chassis(
319327
print("{}".format(result.output))
320328
assert result.exit_code == 0
321329
assert result.output == show_bgp_summary_v4_all_chassis
330+
331+
@pytest.mark.parametrize('setup_single_bgp_instance',
332+
['show_bgp_summary_no_neigh'], indirect=['setup_single_bgp_instance'])
333+
def test_bgp_summary_no_v4_neigh(
334+
self,
335+
setup_bgp_commands,
336+
setup_single_bgp_instance):
337+
show = setup_bgp_commands
338+
runner = CliRunner()
339+
result = runner.invoke(
340+
show.cli.commands["ipv6"].commands["bgp"].commands["summary"], [])
341+
print("{}".format(result.output))
342+
assert result.exit_code == 0
343+
assert result.output == show_error_no_v6_neighbor
344+
345+
@pytest.mark.parametrize('setup_single_bgp_instance',
346+
['show_bgp_summary_no_neigh'], indirect=['setup_single_bgp_instance'])
347+
def test_bgp_summary_no_v6_neigh(
348+
self,
349+
setup_bgp_commands,
350+
setup_single_bgp_instance):
351+
show = setup_bgp_commands
352+
runner = CliRunner()
353+
result = runner.invoke(
354+
show.cli.commands["ip"].commands["bgp"].commands["summary"], [])
355+
print("{}".format(result.output))
356+
assert result.exit_code == 0
357+
assert result.output == show_error_no_v4_neighbor

tests/conftest.py

+6
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ def setup_single_bgp_instance(request):
169169
bgp_mocked_json = os.path.join(
170170
test_path, 'mock_tables', 'dummy.json')
171171

172+
def mock_show_bgp_summary_no_neigh(vtysh_cmd, bgp_namespace, vtysh_shell_cmd=constants.RVTYSH_COMMAND):
173+
return "{}"
174+
172175
def mock_show_bgp_summary(vtysh_cmd, bgp_namespace, vtysh_shell_cmd=constants.RVTYSH_COMMAND):
173176
if os.path.isfile(bgp_mocked_json):
174177
with open(bgp_mocked_json) as json_data:
@@ -217,6 +220,9 @@ def mock_run_show_ip_route_commands(request):
217220
elif request.param == 'ip_route_for_int_ip':
218221
_old_run_bgp_command = bgp_util.run_bgp_command
219222
bgp_util.run_bgp_command = mock_run_bgp_command_for_static
223+
elif request.param == "show_bgp_summary_no_neigh":
224+
bgp_util.run_bgp_command = mock.MagicMock(
225+
return_value=mock_show_bgp_summary_no_neigh("", ""))
220226
else:
221227
bgp_util.run_bgp_command = mock.MagicMock(
222228
return_value=mock_show_bgp_summary("", ""))

utilities_common/bgp_util.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,10 @@ def get_bgp_summary_from_all_bgp_instances(af, namespace, display):
215215
except ValueError:
216216
ctx.fail("bgp summary from bgp container not in json format")
217217

218+
# exit cli command without printing the error message
218219
if key not in cmd_output_json:
219-
ctx.fail("bgp summary from bgp container in invalid format")
220+
click.echo("No IP{} neighbor is configured".format(af))
221+
exit()
220222

221223
device.current_namespace = ns
222224

0 commit comments

Comments
 (0)