]> git.proxmox.com Git - mirror_frr.git/blobdiff - tests/topotests/ldp_topo1/test_ldp_topo1.py
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / tests / topotests / ldp_topo1 / test_ldp_topo1.py
index 4a33edb9d13751f614cdba296ae824885f98c180..fdd75581a3ec5cb789517a0498d19819e562a718 100644 (file)
@@ -1,4 +1,5 @@
 #!/usr/bin/env python
+# SPDX-License-Identifier: ISC
 
 #
 # test_bgp_multiview_topo1.py
@@ -7,22 +8,8 @@
 # Copyright (c) 2016 by
 # Network Device Education Foundation, Inc. ("NetDEF")
 #
-# Permission to use, copy, modify, and/or distribute this software
-# for any purpose with or without fee is hereby granted, provided
-# that the above copyright notice and this permission notice appear
-# in all copies.
-#
-# THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
-# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
-# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
-# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
-# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
-# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
-# OF THIS SOFTWARE.
-#
 
-"""
+r"""
 test_ldp_topo1.py: Simple FRR LDP Test
 
              +---------+
@@ -63,9 +50,15 @@ import os
 import re
 import sys
 import pytest
+import json
+from functools import partial
 from time import sleep
 from lib.topolog import logger
 
+# Save the Current Working Directory to find configuration files.
+CWD = os.path.dirname(os.path.realpath(__file__))
+sys.path.append(os.path.join(CWD, "../"))
+
 sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
 from lib import topotest
 from lib.topogen import Topogen, get_topogen
@@ -102,6 +95,29 @@ def build_topo(tgen):
     switch.add_link(tgen.gears["r3"])
 
 
+#####################################################
+##
+##   Helper functions
+##
+#####################################################
+
+
+def router_compare_json_output(rname, command, reference, count=60, wait=1):
+    "Compare router JSON output"
+
+    logger.info('Comparing router "%s" "%s" output', rname, command)
+
+    tgen = get_topogen()
+    filename = "{}/{}/{}".format(CWD, rname, reference)
+    expected = json.loads(open(filename).read())
+
+    # Run test function until we get an result.
+    test_func = partial(topotest.router_json_cmp, tgen.gears[rname], command, expected)
+    _, diff = topotest.run_and_expect(test_func, None, count, wait)
+    assertmsg = '"{}" JSON output mismatches the expected result'.format(rname)
+    assert diff is None, assertmsg
+
+
 #####################################################
 ##
 ##   Tests starting
@@ -218,6 +234,19 @@ def test_mpls_interfaces():
         assert fatal_error == "", fatal_error
 
 
+def test_ospf_convergence():
+    logger.info("Test: check OSPF adjacencies")
+
+    # Skip if previous fatal error condition is raised
+    if fatal_error != "":
+        pytest.skip(fatal_error)
+
+    for rname in ["r1", "r2", "r3", "r4"]:
+        router_compare_json_output(
+            rname, "show ip ospf neighbor json", "show_ip_ospf_neighbor.json"
+        )
+
+
 def test_mpls_ldp_neighbor_establish():
     global fatal_error
     net = get_topogen().net
@@ -510,9 +539,10 @@ def test_mpls_ldp_binding():
             else:
                 print("r%s ok" % i)
 
-            assert (
-                failures == 0
-            ), "MPLS LDP Interface binding output for router r%s:\n%s" % (i, diff)
+            assert failures == 0, "MPLS LDP binding output for router r%s:\n%s" % (
+                i,
+                diff,
+            )
 
     # Make sure that all daemons are running
     for i in range(1, 5):