diff options
| author | Donatas Abraitis <donatas@opensourcerouting.org> | 2023-06-12 11:40:09 +0300 |
|---|---|---|
| committer | Donatas Abraitis <donatas@opensourcerouting.org> | 2023-06-12 11:40:09 +0300 |
| commit | 717f180a496b521f92232ffd7274abbae81d0d71 (patch) | |
| tree | 9cd07d97323906175c8eebcacfbfa6bff6d93156 /tests/topotests/ripng_topo1 | |
| parent | 3349754a80c1f8ca825e22e58a2e8147df794898 (diff) | |
tests: Use run_and_expect() for ripng_topo1
Avoid checking once and failing immediately.
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
Diffstat (limited to 'tests/topotests/ripng_topo1')
| -rw-r--r-- | tests/topotests/ripng_topo1/test_ripng_topo1.py | 62 |
1 files changed, 25 insertions, 37 deletions
diff --git a/tests/topotests/ripng_topo1/test_ripng_topo1.py b/tests/topotests/ripng_topo1/test_ripng_topo1.py index ce2f5986d1..b9e63ed5fa 100644 --- a/tests/topotests/ripng_topo1/test_ripng_topo1.py +++ b/tests/topotests/ripng_topo1/test_ripng_topo1.py @@ -19,7 +19,7 @@ import re import sys import pytest from time import sleep - +import functools sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from lib import topotest @@ -273,6 +273,27 @@ def test_zebra_ipv6_routingTable(): global fatal_error net = get_topogen().net + def _verify_ip_route(expected): + # Actual output from router + actual = ( + net["r%s" % i] + .cmd('vtysh -c "show ipv6 route" 2> /dev/null | grep "^R"') + .rstrip() + ) + # Mask out Link-Local mac address portion. They are random... + actual = re.sub(r" fe80::[0-9a-f:]+", " fe80::XXXX:XXXX:XXXX:XXXX", actual) + # Drop timers on end of line + actual = re.sub(r", [0-2][0-9]:[0-5][0-9]:[0-5][0-9]", "", actual) + # Fix newlines (make them all the same) + actual = ("\n".join(actual.splitlines()) + "\n").splitlines(1) + + return topotest.get_textdiff( + actual, + expected, + title1="actual Zebra IPv6 routing table", + title2="expected Zebra IPv6 routing table", + ) + # Skip if previous fatal error condition is raised if fatal_error != "": pytest.skip(fatal_error) @@ -291,42 +312,9 @@ def test_zebra_ipv6_routingTable(): # Fix newlines (make them all the same) expected = ("\n".join(expected.splitlines()) + "\n").splitlines(1) - # Actual output from router - actual = ( - net["r%s" % i] - .cmd('vtysh -c "show ipv6 route" 2> /dev/null | grep "^R"') - .rstrip() - ) - # Mask out Link-Local mac address portion. They are random... - actual = re.sub(r" fe80::[0-9a-f:]+", " fe80::XXXX:XXXX:XXXX:XXXX", actual) - # Drop timers on end of line - actual = re.sub(r", [0-2][0-9]:[0-5][0-9]:[0-5][0-9]", "", actual) - # Fix newlines (make them all the same) - actual = ("\n".join(actual.splitlines()) + "\n").splitlines(1) - - # Generate Diff - diff = topotest.get_textdiff( - actual, - expected, - title1="actual Zebra IPv6 routing table", - title2="expected Zebra IPv6 routing table", - ) - - # Empty string if it matches, otherwise diff contains unified diff - if diff: - sys.stderr.write( - "r%s failed Zebra IPv6 Routing Table Check:\n%s\n" % (i, diff) - ) - failures += 1 - else: - print("r%s ok" % i) - - assert ( - failures == 0 - ), "Zebra IPv6 Routing Table verification failed for router r%s:\n%s" % ( - i, - diff, - ) + test_func = functools.partial(_verify_ip_route, expected) + success, _ = topotest.run_and_expect(test_func, "", count=30, wait=1) + assert success, "Failed verifying IPv6 routes for r{}".format(i) # Make sure that all daemons are running for i in range(1, 4): |
