diff options
| author | Russ White <russ@riw.us> | 2021-03-23 11:25:35 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-23 11:25:35 -0400 |
| commit | 638fa8dd4e8b436a286ea2528448d3c94b434b3c (patch) | |
| tree | 22bd37c9ccbb625a847748e6c7cf913771d74a76 /tests/topotests/lib/topotest.py | |
| parent | 09e623fbe125eb2d7fe1cc380e991a744ac0aa0e (diff) | |
| parent | 83d2076e4f515dc7248408c690d49b99fce83eed (diff) | |
Merge pull request #8253 from opensourcerouting/topotest-python3-backports
tests: iproute2 VRF capability check for topotests
Diffstat (limited to 'tests/topotests/lib/topotest.py')
| -rw-r--r-- | tests/topotests/lib/topotest.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/topotests/lib/topotest.py b/tests/topotests/lib/topotest.py index 5cc1a6981d..70b2cfd648 100644 --- a/tests/topotests/lib/topotest.py +++ b/tests/topotests/lib/topotest.py @@ -516,6 +516,44 @@ def normalize_text(text): return text +def is_linux(): + """ + Parses unix name output to check if running on GNU/Linux. + + Returns True if running on Linux, returns False otherwise. + """ + + if os.uname()[0] == "Linux": + return True + return False + + +def iproute2_is_vrf_capable(): + """ + Checks if the iproute2 version installed on the system is capable of + handling VRFs by interpreting the output of the 'ip' utility found in PATH. + + Returns True if capability can be detected, returns False otherwise. + """ + + if is_linux(): + try: + subp = subprocess.Popen( + ["ip", "route", "show", "vrf"], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + stdin=subprocess.PIPE, + encoding="utf-8" + ) + iproute2_err = subp.communicate()[1].splitlines()[0].split()[0] + + if iproute2_err != "Error:": + return True + except Exception: + pass + return False + + def module_present_linux(module, load): """ Returns whether `module` is present. |
