]> git.puffer.fish Git - mirror/frr.git/commitdiff
topotests: improve OSPF(v2|v3) convergence test 8295/head
authorRafael Zalamena <rzalamena@opensourcerouting.org>
Tue, 23 Mar 2021 13:13:19 +0000 (10:13 -0300)
committerRafael Zalamena <rzalamena@opensourcerouting.org>
Tue, 23 Mar 2021 13:13:19 +0000 (10:13 -0300)
Wait until all routers are actually `Full` instead of just looking at routes.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
tests/topotests/ospf-topo1/test_ospf_topo1.py

index 4bb0abfb947775d098722d8a2f1379b2e0d70fe2..9117247ebd98856ee55626c7cafa59505d94b685 100644 (file)
@@ -116,6 +116,78 @@ def teardown_module(mod):
     tgen.stop_topology()
 
 
+def test_wait_protocol_convergence():
+    "Wait for OSPFv2/OSPFv3 to converge"
+    tgen = get_topogen()
+    if tgen.routers_have_failure():
+        pytest.skip(tgen.errors)
+
+    logger.info("waiting for protocols to converge")
+
+    def expect_ospfv2_neighbor_full(router, neighbor):
+        "Wait until OSPFv2 convergence."
+        logger.info("waiting OSPFv2 router '{}'".format(router))
+
+        def run_command_and_expect():
+            """
+            Function that runs command and expect the following outcomes:
+             * Full/DR
+             * Full/DROther
+             * Full/Backup
+            """
+            result = tgen.gears[router].vtysh_cmd('show ip ospf neighbor json',
+                                                  isjson=True)
+            if topotest.json_cmp(result, {"neighbors": {neighbor: [
+                    {"state": "Full/DR"}]}}) is None:
+                return None
+
+            if topotest.json_cmp(result, {"neighbors": {neighbor: [
+                    {"state": "Full/DROther"}]}}) is None:
+                return None
+
+            return topotest.json_cmp(result, {"neighbors": {neighbor: [
+                {"state": "Full/Backup"}]}})
+
+        _, result = topotest.run_and_expect(run_command_and_expect, None,
+                                            count=130, wait=1)
+        assertmsg = '"{}" convergence failure'.format(router)
+        assert result is None, assertmsg
+
+
+    def expect_ospfv3_neighbor_full(router, neighbor):
+        "Wait until OSPFv3 convergence."
+        logger.info("waiting OSPFv3 router '{}'".format(router))
+        test_func = partial(
+            topotest.router_json_cmp,
+            tgen.gears[router],
+            "show ipv6 ospf6 neighbor json",
+            {"neighbors": [{"neighborId": neighbor, "state": "Full"}]},
+        )
+        _, result = topotest.run_and_expect(test_func, None, count=130, wait=1)
+        assertmsg = '"{}" convergence failure'.format(router)
+        assert result is None, assertmsg
+
+    # Wait for OSPFv2 convergence
+    expect_ospfv2_neighbor_full("r1", "10.0.255.2")
+    expect_ospfv2_neighbor_full("r1", "10.0.255.3")
+    expect_ospfv2_neighbor_full("r2", "10.0.255.1")
+    expect_ospfv2_neighbor_full("r2", "10.0.255.3")
+    expect_ospfv2_neighbor_full("r3", "10.0.255.1")
+    expect_ospfv2_neighbor_full("r3", "10.0.255.2")
+    expect_ospfv2_neighbor_full("r3", "10.0.255.4")
+    expect_ospfv2_neighbor_full("r4", "10.0.255.3")
+
+    # Wait for OSPFv3 convergence
+    expect_ospfv3_neighbor_full("r1", "10.0.255.2")
+    expect_ospfv3_neighbor_full("r1", "10.0.255.3")
+    expect_ospfv3_neighbor_full("r2", "10.0.255.1")
+    expect_ospfv3_neighbor_full("r2", "10.0.255.3")
+    expect_ospfv3_neighbor_full("r3", "10.0.255.1")
+    expect_ospfv3_neighbor_full("r3", "10.0.255.2")
+    expect_ospfv3_neighbor_full("r3", "10.0.255.4")
+    expect_ospfv3_neighbor_full("r4", "10.0.255.3")
+
+
 def compare_show_ipv6_ospf6(rname, expected):
     """
     Calls 'show ipv6 ospf6 route' for router `rname` and compare the obtained