From caaf6780744295a0240719a56636b05e127778f1 Mon Sep 17 00:00:00 2001 From: Soumya Roy Date: Thu, 1 May 2025 06:17:27 +0000 Subject: [PATCH] tests: Add test to verify bgp path count in json This fix adds test case, to verify bgp path count in json output. Signed-off-by: Soumya Roy --- .../test_bgp_addpath_paths_limit.py | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/topotests/bgp_addpath_paths_limit/test_bgp_addpath_paths_limit.py b/tests/topotests/bgp_addpath_paths_limit/test_bgp_addpath_paths_limit.py index fb863e454f..44042f449c 100644 --- a/tests/topotests/bgp_addpath_paths_limit/test_bgp_addpath_paths_limit.py +++ b/tests/topotests/bgp_addpath_paths_limit/test_bgp_addpath_paths_limit.py @@ -123,6 +123,43 @@ def test_bgp_addpath_paths_limit(): assert result is None, "Received routes count is not as expected" +def test_bgp_pathcount_json(): + """ + Test to verify the pathCount key exists in BGP JSON output and has correct values + """ + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + r1 = tgen.gears["r1"] + r7 = tgen.gears["r7"] + + def _bgp_check_path_count(router, expected_count): + output = json.loads( + router.vtysh_cmd("show bgp ipv4 unicast 172.16.16.254/32 json") + ) + + if "pathCount" not in output: + return "pathCount key not found in JSON output" + + return topotest.json_cmp(output["pathCount"], expected_count) + + # Check pathCount for r1 (should be 2) + test_func = functools.partial(_bgp_check_path_count, r1, 2) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert ( + result is None + ), "pathCount in JSON output doesn't match expected value for r1" + + # Check pathCount for r7 (should be 3) + test_func = functools.partial(_bgp_check_path_count, r7, 3) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert ( + result is None + ), "pathCount in JSON output doesn't match expected value for r7" + + if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) -- 2.39.5