From: Donatas Abraitis Date: Mon, 12 Jun 2023 08:35:37 +0000 (+0300) Subject: tests: Use run_and_expect() for rip_topo1 X-Git-Tag: base_9.1~369^2~2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=3349754a80c1f8ca825e22e58a2e8147df794898;p=matthieu%2Ffrr.git tests: Use run_and_expect() for rip_topo1 Avoid checking once and failing immediately. Signed-off-by: Donatas Abraitis --- diff --git a/tests/topotests/rip_topo1/test_rip_topo1.py b/tests/topotests/rip_topo1/test_rip_topo1.py index d23962b77d..9850cc695d 100644 --- a/tests/topotests/rip_topo1/test_rip_topo1.py +++ b/tests/topotests/rip_topo1/test_rip_topo1.py @@ -19,6 +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__)))) @@ -258,58 +259,43 @@ def test_zebra_ipv4_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 ip route" 2> /dev/null | grep "^R"') + .rstrip() + ) + # 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 IPv4 routing table", + title2="expected Zebra IPv4 routing table", + ) + # Skip if previous fatal error condition is raised if fatal_error != "": pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) - # Verify OSPFv3 Routing Table print("\n\n** Verifing Zebra IPv4 Routing Table") print("******************************************\n") - failures = 0 for i in range(1, 4): refTableFile = "%s/r%s/show_ip_route.ref" % (thisDir, i) if os.path.isfile(refTableFile): - # Read expected result from file expected = open(refTableFile).read().rstrip() # 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 ip route" 2> /dev/null | grep "^R"') - .rstrip() - ) - # 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 IPv4 routing table", - title2="expected Zebra IPv4 routing table", - ) - - # Empty string if it matches, otherwise diff contains unified diff - if diff: - sys.stderr.write( - "r%s failed Zebra IPv4 Routing Table Check:\n%s\n" % (i, diff) - ) - failures += 1 - else: - print("r%s ok" % i) - - assert ( - failures == 0 - ), "Zebra IPv4 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 IPv4 routes for r{}".format(i) # Make sure that all daemons are still running for i in range(1, 4):