summaryrefslogtreecommitdiff
path: root/tests/topotests/lib/topotest.py
diff options
context:
space:
mode:
authorStephen Worley <sworley@cumulusnetworks.com>2020-06-10 12:35:36 -0400
committerGitHub <noreply@github.com>2020-06-10 12:35:36 -0400
commit5e0494b38a53e5a3501088efb4b48b2cbb7a080f (patch)
treef5e18ed8e373fbbcd8e58f47fdbe1d428c59b6f9 /tests/topotests/lib/topotest.py
parentb71ca5ae42878fffa387cad0ab9af4782e3bcd44 (diff)
parent99e387d5836307525e6afddc7ea3b93355a92af5 (diff)
Merge pull request #6465 from xThaid/iprules
zebra: move ip rule installation to use dplane thread
Diffstat (limited to 'tests/topotests/lib/topotest.py')
-rw-r--r--tests/topotests/lib/topotest.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/topotests/lib/topotest.py b/tests/topotests/lib/topotest.py
index 6262082193..9d945d5262 100644
--- a/tests/topotests/lib/topotest.py
+++ b/tests/topotests/lib/topotest.py
@@ -727,6 +727,57 @@ def ip6_route(node):
return result
+def ip_rules(node):
+ """
+ Gets a structured return of the command 'ip rule'. It can be used in
+ conjuction with json_cmp() to provide accurate assert explanations.
+
+ Return example:
+ [
+ {
+ "pref": "0"
+ "from": "all"
+ },
+ {
+ "pref": "32766"
+ "from": "all"
+ },
+ {
+ "to": "3.4.5.0/24",
+ "iif": "r1-eth2",
+ "pref": "304",
+ "from": "1.2.0.0/16",
+ "proto": "zebra"
+ }
+ ]
+ """
+ output = normalize_text(node.run("ip rule")).splitlines()
+ result = []
+ for line in output:
+ columns = line.split(" ")
+
+ route = {}
+ # remove last character, since it is ':'
+ pref = columns[0][:-1]
+ route["pref"] = pref
+ prev = None
+ for column in columns:
+ if prev == "from":
+ route["from"] = column
+ if prev == "to":
+ route["to"] = column
+ if prev == "proto":
+ route["proto"] = column
+ if prev == "iif":
+ route["iif"] = column
+ if prev == "fwmark":
+ route["fwmark"] = column
+ prev = column
+
+ result.append(route)
+ return result
+
+
def sleep(amount, reason=None):
"""
Sleep wrapper that registers in the log the amount of sleep