]> git.puffer.fish Git - mirror/frr.git/commitdiff
topotests: stabilize ospf-sr-topo1 run 6533/head
authorRafael Zalamena <rzalamena@opensourcerouting.org>
Mon, 8 Jun 2020 19:14:41 +0000 (16:14 -0300)
committerRafael Zalamena <rzalamena@opensourcerouting.org>
Mon, 8 Jun 2020 19:14:41 +0000 (16:14 -0300)
Use `json_cmp` instead of raw text comparison. It should fix some of the
ordering problems we are seeing in CI runs.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
tests/topotests/ospf-sr-topo1/r1/ospf_srdb.json
tests/topotests/ospf-sr-topo1/r1/zebra_mpls.json
tests/topotests/ospf-sr-topo1/r2/ospf_srdb.json
tests/topotests/ospf-sr-topo1/r2/zebra_mpls.json
tests/topotests/ospf-sr-topo1/r3/ospf_srdb.json
tests/topotests/ospf-sr-topo1/r3/zebra_mpls.json
tests/topotests/ospf-sr-topo1/r4/ospf_srdb.json
tests/topotests/ospf-sr-topo1/r4/zebra_mpls.json
tests/topotests/ospf-sr-topo1/test_ospf_sr_topo1.py

index 652978aff8fa586942f4b9d43221abc5ab31d517..0416bd6ce2a1ad12fdb452a94370803f0bdca463 100644 (file)
       "extendedLink":[
         {
           "prefix":"10.0.0.1\/32",
-          "sid":"XX",
-          "inputLabel":"XX",
+          "sid":"*",
+          "inputLabel":"*",
           "outputLabel":3,
           "interface":"r1-eth0",
           "nexthop":"10.0.0.2"
         },
         {
           "prefix":"10.0.0.1\/32",
-          "sid":"XX",
-          "inputLabel":"XX",
+          "sid":"*",
+          "inputLabel":"*",
           "outputLabel":3,
           "interface":"r1-eth0",
           "nexthop":"10.0.0.2"
         },
         {
           "prefix":"10.0.1.1\/32",
-          "sid":"XX",
-          "inputLabel":"XX",
+          "sid":"*",
+          "inputLabel":"*",
           "outputLabel":3,
           "interface":"r1-eth1",
           "nexthop":"10.0.1.2"
         },
         {
           "prefix":"10.0.1.1\/32",
-          "sid":"XX",
-          "inputLabel":"XX",
+          "sid":"*",
+          "inputLabel":"*",
           "outputLabel":3,
           "interface":"r1-eth1",
           "nexthop":"10.0.1.2"
index 88ba28da42f563ee514917126ae989e898701b93..a0059e625e69b3c273d60e62171a5bf4999b0a61 100644 (file)
@@ -71,8 +71,8 @@
       }
     ]
   },
-  "XX":{
-    "inLabel":"XX",
+  "label-1":{
+    "inLabel":"*",
     "installed":true,
     "nexthops":[
       {
@@ -84,8 +84,8 @@
       }
     ]
   },
-  "XX":{
-    "inLabel":"XX",
+  "label-2":{
+    "inLabel":"*",
     "installed":true,
     "nexthops":[
       {
@@ -97,8 +97,8 @@
       }
     ]
   },
-  "XX":{
-    "inLabel":"XX",
+  "label-3":{
+    "inLabel":"*",
     "installed":true,
     "nexthops":[
       {
       }
     ]
   },
-  "XX":{
-    "inLabel":"XX",
+  "label-4":{
+    "inLabel":"*",
     "installed":true,
     "nexthops":[
       {
index 13437c9cf53b929709aa7fa0959cf85ee6694fe8..eb202b82cd560e8ac7def20606a1084477d4b466 100644 (file)
       "extendedLink":[
         {
           "prefix":"10.0.4.2\/32",
-          "sid":"XX",
-          "inputLabel":"XX",
+          "sid":"*",
+          "inputLabel":"*",
           "outputLabel":3,
           "interface":"r2-eth3",
           "nexthop":"10.0.4.1"
         },
         {
           "prefix":"10.0.4.2\/32",
-          "sid":"XX",
-          "inputLabel":"XX",
+          "sid":"*",
+          "inputLabel":"*",
           "outputLabel":3,
           "interface":"r2-eth3",
           "nexthop":"10.0.4.1"
         },
         {
           "prefix":"10.0.0.2\/32",
-          "sid":"XX",
-          "inputLabel":"XX",
+          "sid":"*",
+          "inputLabel":"*",
           "outputLabel":3,
           "interface":"r2-eth0",
           "nexthop":"10.0.0.1"
         },
         {
           "prefix":"10.0.0.2\/32",
-          "sid":"XX",
-          "inputLabel":"XX",
+          "sid":"*",
+          "inputLabel":"*",
           "outputLabel":3,
           "interface":"r2-eth0",
           "nexthop":"10.0.0.1"
         },
         {
           "prefix":"10.0.1.2\/32",
-          "sid":"XX",
-          "inputLabel":"XX",
+          "sid":"*",
+          "inputLabel":"*",
           "outputLabel":3,
           "interface":"r2-eth1",
           "nexthop":"10.0.1.1"
         },
         {
           "prefix":"10.0.1.2\/32",
-          "sid":"XX",
-          "inputLabel":"XX",
+          "sid":"*",
+          "inputLabel":"*",
           "outputLabel":3,
           "interface":"r2-eth1",
           "nexthop":"10.0.1.1"
         },
         {
           "prefix":"10.0.3.2\/32",
-          "sid":"XX",
-          "inputLabel":"XX",
+          "sid":"*",
+          "inputLabel":"*",
           "outputLabel":3,
           "interface":"r2-eth2",
           "nexthop":"10.0.3.1"
         },
         {
           "prefix":"10.0.3.2\/32",
-          "sid":"XX",
-          "inputLabel":"XX",
+          "sid":"*",
+          "inputLabel":"*",
           "outputLabel":3,
           "interface":"r2-eth2",
           "nexthop":"10.0.3.1"
index 2931b7dc34d432dcc9fd254873fd46ffb2ae2e67..a6dd22b5b7d872227ddfbb308772c4cd2ec24da2 100644 (file)
@@ -45,8 +45,8 @@
       }
     ]
   },
-  "XX":{
-    "inLabel":"XX",
+  "label-1":{
+    "inLabel":"*",
     "installed":true,
     "nexthops":[
       {
@@ -58,8 +58,8 @@
       }
     ]
   },
-  "XX":{
-    "inLabel":"XX",
+  "label-2":{
+    "inLabel":"*",
     "installed":true,
     "nexthops":[
       {
@@ -71,8 +71,8 @@
       }
     ]
   },
-  "XX":{
-    "inLabel":"XX",
+  "label-3":{
+    "inLabel":"*",
     "installed":true,
     "nexthops":[
       {
@@ -84,8 +84,8 @@
       }
     ]
   },
-  "XX":{
-    "inLabel":"XX",
+  "label-4":{
+    "inLabel":"*",
     "installed":true,
     "nexthops":[
       {
@@ -97,8 +97,8 @@
       }
     ]
   },
-  "XX":{
-    "inLabel":"XX",
+  "label-5":{
+    "inLabel":"*",
     "installed":true,
     "nexthops":[
       {
       }
     ]
   },
-  "XX":{
-    "inLabel":"XX",
+  "label-6":{
+    "inLabel":"*",
     "installed":true,
     "nexthops":[
       {
       }
     ]
   },
-  "XX":{
-    "inLabel":"XX",
+  "label-7":{
+    "inLabel":"*",
     "installed":true,
     "nexthops":[
       {
       }
     ]
   },
-  "XX":{
-    "inLabel":"XX",
+  "label-8":{
+    "inLabel":"*",
     "installed":true,
     "nexthops":[
       {
index d070aafb1eee394be5e5025f6409804dfeb27627..b36fe674ad12f7180ab9c81f995a6fe976118461 100644 (file)
       "extendedLink":[
         {
           "prefix":"10.0.3.1\/32",
-          "sid":"XX",
-          "inputLabel":"XX",
+          "sid":"*",
+          "inputLabel":"*",
           "outputLabel":3,
           "interface":"r3-eth0",
           "nexthop":"10.0.3.2"
         },
         {
           "prefix":"10.0.3.1\/32",
-          "sid":"XX",
-          "inputLabel":"XX",
+          "sid":"*",
+          "inputLabel":"*",
           "outputLabel":3,
           "interface":"r3-eth0",
           "nexthop":"10.0.3.2"
index c9264d8a42eda2bbe43be09c9588cf09d1456b44..6900f30502e238ef4e53968ebf11c57c9b6082f0 100644 (file)
@@ -38,8 +38,8 @@
       }
     ]
   },
-  "XX":{
-    "inLabel":"XX",
+  "label-1":{
+    "inLabel":"*",
     "installed":true,
     "nexthops":[
       {
@@ -51,8 +51,8 @@
       }
     ]
   },
-  "XX":{
-    "inLabel":"XX",
+  "label-2":{
+    "inLabel":"*",
     "installed":true,
     "nexthops":[
       {
index 17c0ea276ee96b2f0531a4b0896b4f2ef8787414..d92ec91c7294ef1cbb5d851000bfe5d95a6dbd7a 100644 (file)
       "extendedLink":[
         {
           "prefix":"10.0.4.1\/32",
-          "sid":"XX",
-          "inputLabel":"XX",
+          "sid":"*",
+          "inputLabel":"*",
           "outputLabel":3,
           "interface":"r4-eth0",
           "nexthop":"10.0.4.2"
         },
         {
           "prefix":"10.0.4.1\/32",
-          "sid":"XX",
-          "inputLabel":"XX",
+          "sid":"*",
+          "inputLabel":"*",
           "outputLabel":3,
           "interface":"r4-eth0",
           "nexthop":"10.0.4.2"
index 3a829fa8581ce66b420c23e78cd78f95f55cd75d..1fff699b586382fe68734fc8011c8749eba1c0f2 100644 (file)
@@ -50,8 +50,8 @@
       }
     ]
   },
-  "XX":{
-    "inLabel":"XX",
+  "label-1":{
+    "inLabel":"*",
     "installed":true,
     "nexthops":[
       {
@@ -63,8 +63,8 @@
       }
     ]
   },
-  "XX":{
-    "inLabel":"XX",
+  "label-2":{
+    "inLabel":"*",
     "installed":true,
     "nexthops":[
       {
index ac97ee7ebd52afe7dbf61d46a13529367c8ae243..abf3bf3c02c47a87e913b5127c629218ebf7ff40 100755 (executable)
@@ -29,6 +29,7 @@ test_ospf_sr_topo1.py: Test the FRR OSPF routing daemon with Segment Routing.
 import os
 import re
 import sys
+import json
 from functools import partial
 
 # Save the Current Working Directory to find configuration files.
@@ -113,37 +114,6 @@ def teardown_module(mod):
     logger.info("\n\n---- OSPF Segment Routing tests End ----\n")
 
 
-# Shared test function to validate expected output.
-def compare_ospf_srdb(rname, expected):
-    """
-    Calls 'show ip ospf database segment-routing json' for router `rname`
-    and compare the obtained result with the expected output.
-    """
-    tgen = get_topogen()
-    current = tgen.gears[rname].vtysh_cmd("show ip ospf database segment-routing json")
-    # Filter Adjacency SID allocation
-    current = re.sub(r'"sid":5000[0-9],', '"sid":"XX",', current)
-    current = re.sub(r'"inputLabel":5000[0-9],', '"inputLabel":"XX",', current)
-    return topotest.difflines(
-        current, expected, title1="Current output", title2="Expected output"
-    )
-
-
-def compare_mpls_table(rname, expected):
-    """
-    Calls 'show mpls table json' for router `rname` and compare the obtained
-    result with the expected output.
-    """
-    tgen = get_topogen()
-    current = tgen.gears[rname].vtysh_cmd("show mpls table json")
-    # Filter Adjacency SID allocation
-    current = re.sub(r'"5000[0-9]":', '"XX":', current)
-    current = re.sub(r'"inLabel":5000[0-9],', '"inLabel":"XX",', current)
-    return topotest.difflines(
-        current, expected, title1="Current output", title2="Expected output"
-    )
-
-
 def test_ospf_sr():
     "Test OSPF daemon Segment Routing"
     tgen = get_topogen()
@@ -159,12 +129,15 @@ def test_ospf_sr():
 
         # Load expected results from the command
         reffile = os.path.join(CWD, "{}/ospf_srdb.json".format(router))
-        expected = open(reffile).read()
+        expected = json.loads(open(reffile).read())
 
         # Run test function until we get an result. Wait at most 60 seconds.
-        test_func = partial(compare_ospf_srdb, router, expected)
-        result, diff = topotest.run_and_expect(test_func, "", count=25, wait=3)
-        assert result, ("OSPF did not start Segment Routing on {}:\n{}").format(
+        rt = tgen.gears[router]
+        test_func = partial(
+            topotest.router_json_cmp, rt, 'show ip ospf database segment-routing json', expected
+        )
+        rv, diff = topotest.run_and_expect(test_func, None, count=25, wait=3)
+        assert rv, "OSPF did not start Segment Routing on {}:\n{}".format(
             router, diff
         )
 
@@ -177,6 +150,20 @@ def test_ospf_kernel_route():
 
     logger.info("--- test OSPF Segment Routing MPLS tables ---")
 
+    def show_mpls_table_json_cmp(rt, expected):
+        "Removes random label and use `label-X` instead."
+        text = rt.vtysh_cmd('show mpls table json')
+
+        # Substitue random labels with fixed label value.
+        for label in range(1, 10):
+            text = re.sub(r'"5000[0-9]"', '"label-{}"'.format(label), text,
+                          count=1)
+
+        print '\n{}\n'.format(text)
+
+        output = json.loads(text)
+        return topotest.json_cmp(output, expected)
+
     for rnum in range(1, 5):
         router = "r{}".format(rnum)
 
@@ -184,12 +171,13 @@ def test_ospf_kernel_route():
 
         # Load expected results from the command
         reffile = os.path.join(CWD, "{}/zebra_mpls.json".format(router))
-        expected = open(reffile).read()
+        expected = json.loads(open(reffile).read())
 
         # Run test function until we get an result. Wait at most 60 seconds.
-        test_func = partial(compare_mpls_table, router, expected)
-        result, diff = topotest.run_and_expect(test_func, "", count=25, wait=3)
-        assert result, ("OSPF did not properly instal MPLS table on {}:\n{}").format(
+        rt = tgen.gears[router]
+        test_func = partial(show_mpls_table_json_cmp, rt, expected)
+        rv, diff = topotest.run_and_expect(test_func, None, count=25, wait=3)
+        assert rv, "OSPF did not properly instal MPLS table on {}:\n{}".format(
             router, diff
         )