]> git.puffer.fish Git - matthieu/frr.git/commitdiff
topotest: improve reliability of `verify_rib`
authorRafael Zalamena <rzalamena@opensourcerouting.org>
Wed, 17 Jul 2019 21:39:03 +0000 (18:39 -0300)
committerRafael Zalamena <rzalamena@opensourcerouting.org>
Tue, 23 Jul 2019 13:28:56 +0000 (10:28 -0300)
Attempt to run the function multiple times to make sure we got the
result we expected. This is a middle ground between big sleeps and short
test intervals.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
tests/topotests/lib/common_config.py

index 628c198e1a8e5d58fb504a5d3b52ba17797603f1..a2ad307f8b75212a2e97a436e72bd548332182ce 100644 (file)
@@ -30,6 +30,9 @@ import traceback
 import socket
 import ipaddr
 
+from lib import topotest
+
+from functools import partial
 from lib.topolog import logger, logger_config
 from lib.topogen import TopoRouter
 
@@ -1089,7 +1092,7 @@ def create_route_maps(tgen, input_dict, build=False):
 #############################################
 # Verification APIs
 #############################################
-def verify_rib(tgen, addr_type, dut, input_dict, next_hop=None, protocol=None):
+def _verify_rib(tgen, addr_type, dut, input_dict, next_hop=None, protocol=None):
     """
     Data will be read from input_dict or input JSON file, API will generate
     same prefixes, which were redistributed by either create_static_routes() or
@@ -1258,6 +1261,19 @@ def verify_rib(tgen, addr_type, dut, input_dict, next_hop=None, protocol=None):
     return True
 
 
+def verify_rib(tgen, addr_type, dut, input_dict, next_hop=None, protocol=None):
+    "Wrapper function for `_verify_rib` that tries multiple time to get results."
+
+    # Use currying to hide the parameters and create a test function.
+    test_func = partial(_verify_rib, tgen, addr_type, dut, input_dict, next_hop, protocol)
+
+    # Call the test function and expect it to return True, otherwise try it again.
+    _, result = topotest.run_and_expect(test_func, True, count=20, wait=6)
+
+    # Return as normal.
+    return result
+
+
 def verify_admin_distance_for_static_routes(tgen, input_dict):
     """
     API to verify admin distance for static routes as defined in input_dict/