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

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

index ce2f5986d1ea43e005a8b94e7f8f2dd4caee8b15..b9e63ed5fa6e1bb27bee32cbe5f32a6b77f4ecfa 100644 (file)
@@ -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):