diff options
| author | Jakub Urbańczyk <xthaid@gmail.com> | 2020-05-26 18:24:16 +0200 |
|---|---|---|
| committer | Jakub Urbańczyk <xthaid@gmail.com> | 2020-06-10 16:29:14 +0200 |
| commit | 9b7decf28e7d6e9b13b7fa6d0225b3cfa823fdfd (patch) | |
| tree | 69e35af86781561815ed62100f3248559de78c6e /tests/topotests/lib/topotest.py | |
| parent | f62e5480ec901d3e9563b715a556c1d9f68822ee (diff) | |
topotest: add pbr test suite
Add some basic tests for installing PBR rules into the kernel.
Signed-off-by: Jakub Urbańczyk <xthaid@gmail.com>
Diffstat (limited to 'tests/topotests/lib/topotest.py')
| -rw-r--r-- | tests/topotests/lib/topotest.py | 51 |
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 |
