]> git.puffer.fish Git - matthieu/frr.git/commitdiff
topotests: add API to detect if iproute2 is json capable
authorPhilippe Guibert <philippe.guibert@6wind.com>
Mon, 10 Jun 2024 06:38:22 +0000 (08:38 +0200)
committerPhilippe Guibert <philippe.guibert@6wind.com>
Tue, 11 Jun 2024 08:01:56 +0000 (10:01 +0200)
Some tests may want to use the json facility of iproute2 to
dump some results.
Add an internal API in lib/topotest.py that tells whether iproute2
is json capable or not.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
tests/topotests/lib/topotest.py

index 087d8454fce38a825689040b3d7cc4654173217e..1d4bc2eac6a56941021e7ab4a2c98c6cea4d9c97 100644 (file)
@@ -602,6 +602,30 @@ def is_linux():
     return False
 
 
+def iproute2_is_json_capable():
+    """
+    Checks if the iproute2 version installed on the system is capable of
+    handling JSON outputss
+
+    Returns True if capability can be detected, returns False otherwise.
+    """
+    if is_linux():
+        try:
+            subp = subprocess.Popen(
+                ["ip", "-json", "route", "show"],
+                stdout=subprocess.PIPE,
+                stderr=subprocess.PIPE,
+                stdin=subprocess.PIPE,
+            )
+            iproute2_err = subp.communicate()[1].splitlines()[0].split()[0]
+
+            if iproute2_err != "Error:":
+                return True
+        except Exception:
+            pass
+    return False
+
+
 def iproute2_is_vrf_capable():
     """
     Checks if the iproute2 version installed on the system is capable of