Skip to content

Commit 1f26c8c

Browse files
arlakshmyxieca
authored andcommitted
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 2573aae commit 1f26c8c

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
@@ -179,6 +179,9 @@ def setup_single_bgp_instance(request):
179179
bgp_mocked_json = os.path.join(
180180
test_path, 'mock_tables', 'dummy.json')
181181

182+
def mock_show_bgp_summary_no_neigh(vtysh_cmd, bgp_namespace, vtysh_shell_cmd=constants.RVTYSH_COMMAND):
183+
return "{}"
184+
182185
def mock_show_bgp_summary(vtysh_cmd, bgp_namespace, vtysh_shell_cmd=constants.RVTYSH_COMMAND):
183186
if os.path.isfile(bgp_mocked_json):
184187
with open(bgp_mocked_json) as json_data:
@@ -229,6 +232,9 @@ def mock_run_bgp_command(vtysh_cmd, bgp_namespace, vtysh_shell_cmd=constants.RVT
229232
elif request.param == 'ip_route_for_int_ip':
230233
_old_run_bgp_command = bgp_util.run_bgp_command
231234
bgp_util.run_bgp_command = mock_run_bgp_command_for_static
235+
elif request.param == "show_bgp_summary_no_neigh":
236+
bgp_util.run_bgp_command = mock.MagicMock(
237+
return_value=mock_show_bgp_summary_no_neigh("", ""))
232238
else:
233239
bgp_util.run_bgp_command = mock.MagicMock(
234240
return_value=mock_show_bgp_summary("", ""))

utilities_common/bgp_util.py

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

235+
# exit cli command without printing the error message
235236
if key not in cmd_output_json:
236-
ctx.fail("bgp summary from bgp container in invalid format")
237+
click.echo("No IP{} neighbor is configured".format(af))
238+
exit()
237239

238240
device.current_namespace = ns
239241

0 commit comments

Comments
 (0)