]> git.puffer.fish Git - mirror/frr.git/commitdiff
tests: Add test to verify bgp path count in json 18740/head
authorSoumya Roy <souroy@nvidia.com>
Thu, 1 May 2025 06:17:27 +0000 (06:17 +0000)
committerSoumya Roy <souroy@nvidia.com>
Thu, 1 May 2025 17:31:58 +0000 (17:31 +0000)
This fix adds test case, to verify bgp path count
in json output.

Signed-off-by: Soumya Roy <souroy@nvidia.com>
tests/topotests/bgp_addpath_paths_limit/test_bgp_addpath_paths_limit.py

index fb863e454f1431a7a946684a15be277b4d0acc07..44042f449c24bbdb30e0a56e34c3058844ce36d1 100644 (file)
@@ -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))