]> git.puffer.fish Git - matthieu/frr.git/commitdiff
tests: do not use exclude grep
authorLouis Scalbert <louis.scalbert@6wind.com>
Wed, 8 Feb 2023 11:05:15 +0000 (12:05 +0100)
committerMergify <37929162+mergify[bot]@users.noreply.github.com>
Wed, 8 Feb 2023 19:54:01 +0000 (19:54 +0000)
Filter out keys in JSON output with "grep -v" does not work when JSON
does not use the pretty format.

Use native python code to filter out keys.

Fixes: 6c13bd5744 ("topotests: fix bgp_vpnv4_noretain")
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
(cherry picked from commit a8d6faa9864c78f8570c8ac89c78d3095c43532d)

tests/topotests/bgp_vpnv4_noretain/test_bgp_vpnv4_noretain.py

index ed5cc3faf66187ce950daf74f96e56ded3b04153..d3b9b75efca4603b2238e3b27e14efc263642928 100644 (file)
@@ -134,12 +134,21 @@ def teardown_module(_mod):
 
 
 def router_json_cmp_exact_filter(router, cmd, expected):
-    # filter out tableVersion, version and nhVrfID
-    output = router.cmd('vtysh -c "{}" | grep -v ersion | grep -v nhVrfId'.format(cmd))
+    output = router.vtysh_cmd(cmd)
     logger.info("{}: {}\n{}".format(router.name, cmd, output))
 
     json_output = json.loads(output)
 
+    # filter out tableVersion, version and nhVrfID
+    json_output.pop("tableVersion")
+    for rd, data in json_output["routes"]["routeDistinguishers"].items():
+        for prefix, attrs in data.items():
+            for attr in attrs:
+                if "nhVrfId" in attr:
+                    attr.pop("nhVrfId")
+                if "version" in attr:
+                    attr.pop("version")
+
     return topotest.json_cmp(json_output, expected, exact=True)