]> git.puffer.fish Git - mirror/frr.git/commitdiff
tests: Use run_and_expect() for rip_topo1
authorDonatas Abraitis <donatas@opensourcerouting.org>
Mon, 12 Jun 2023 08:35:37 +0000 (11:35 +0300)
committerDonatas Abraitis <donatas@opensourcerouting.org>
Mon, 12 Jun 2023 08:38:01 +0000 (11:38 +0300)
Avoid checking once and failing immediately.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
tests/topotests/rip_topo1/test_rip_topo1.py

index d23962b77d211499057ec96ff1fd704ad36b7679..9850cc695d4e93593056bbdd5387aa952e6ece09 100644 (file)
@@ -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):