diff --git a/tests/bgp_commands_test.py b/tests/bgp_commands_test.py index c862468781..67c05a2fd3 100644 --- a/tests/bgp_commands_test.py +++ b/tests/bgp_commands_test.py @@ -97,6 +97,14 @@ Error: bgp summary from bgp container not in json format """ +show_error_no_v6_neighbor = """\ +No IPv6 neighbor is configured +""" + +show_error_no_v4_neighbor = """\ +No IPv4 neighbor is configured +""" + show_bgp_summary_v4_chassis = """\ IPv4 Unicast Summary: @@ -319,3 +327,31 @@ def test_bgp_summary_v4_all_chassis( print("{}".format(result.output)) assert result.exit_code == 0 assert result.output == show_bgp_summary_v4_all_chassis + + @pytest.mark.parametrize('setup_single_bgp_instance', + ['show_bgp_summary_no_neigh'], indirect=['setup_single_bgp_instance']) + def test_bgp_summary_no_v4_neigh( + self, + setup_bgp_commands, + setup_single_bgp_instance): + show = setup_bgp_commands + runner = CliRunner() + result = runner.invoke( + show.cli.commands["ipv6"].commands["bgp"].commands["summary"], []) + print("{}".format(result.output)) + assert result.exit_code == 0 + assert result.output == show_error_no_v6_neighbor + + @pytest.mark.parametrize('setup_single_bgp_instance', + ['show_bgp_summary_no_neigh'], indirect=['setup_single_bgp_instance']) + def test_bgp_summary_no_v6_neigh( + self, + setup_bgp_commands, + setup_single_bgp_instance): + show = setup_bgp_commands + runner = CliRunner() + result = runner.invoke( + show.cli.commands["ip"].commands["bgp"].commands["summary"], []) + print("{}".format(result.output)) + assert result.exit_code == 0 + assert result.output == show_error_no_v4_neighbor diff --git a/tests/conftest.py b/tests/conftest.py index b48d0ef93f..32a8dd6056 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -169,6 +169,9 @@ def setup_single_bgp_instance(request): bgp_mocked_json = os.path.join( test_path, 'mock_tables', 'dummy.json') + def mock_show_bgp_summary_no_neigh(vtysh_cmd, bgp_namespace, vtysh_shell_cmd=constants.RVTYSH_COMMAND): + return "{}" + def mock_show_bgp_summary(vtysh_cmd, bgp_namespace, vtysh_shell_cmd=constants.RVTYSH_COMMAND): if os.path.isfile(bgp_mocked_json): with open(bgp_mocked_json) as json_data: @@ -217,6 +220,9 @@ def mock_run_show_ip_route_commands(request): elif request.param == 'ip_route_for_int_ip': _old_run_bgp_command = bgp_util.run_bgp_command bgp_util.run_bgp_command = mock_run_bgp_command_for_static + elif request.param == "show_bgp_summary_no_neigh": + bgp_util.run_bgp_command = mock.MagicMock( + return_value=mock_show_bgp_summary_no_neigh("", "")) else: bgp_util.run_bgp_command = mock.MagicMock( return_value=mock_show_bgp_summary("", "")) diff --git a/utilities_common/bgp_util.py b/utilities_common/bgp_util.py index 3b2ef99a11..6691cf2a26 100644 --- a/utilities_common/bgp_util.py +++ b/utilities_common/bgp_util.py @@ -215,8 +215,10 @@ def get_bgp_summary_from_all_bgp_instances(af, namespace, display): except ValueError: ctx.fail("bgp summary from bgp container not in json format") + # exit cli command without printing the error message if key not in cmd_output_json: - ctx.fail("bgp summary from bgp container in invalid format") + click.echo("No IP{} neighbor is configured".format(af)) + exit() device.current_namespace = ns