From: Philippe Guibert Date: Mon, 10 Jun 2024 06:38:22 +0000 (+0200) Subject: topotests: add API to detect if iproute2 is json capable X-Git-Tag: base_10.2~341^2~1 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=a6b1d38d7f038c335143d963b7b7a13377ef5f22;p=matthieu%2Ffrr.git topotests: add API to detect if iproute2 is json capable 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 --- diff --git a/tests/topotests/lib/topotest.py b/tests/topotests/lib/topotest.py index 087d8454fc..1d4bc2eac6 100644 --- a/tests/topotests/lib/topotest.py +++ b/tests/topotests/lib/topotest.py @@ -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