]> git.puffer.fish Git - matthieu/frr.git/commitdiff
tests: Fix test_bgp_vpnv4_per_nexthop_label.py to handle timing changes
authorDonald Sharp <sharpd@nvidia.com>
Fri, 26 Jul 2024 18:02:31 +0000 (14:02 -0400)
committerDonald Sharp <sharpd@nvidia.com>
Fri, 26 Jul 2024 18:19:43 +0000 (14:19 -0400)
So the test script is making changes to a vpn configuration by
changing something fundamental about the vpn.  This is causing
a window where routes we are interested in are:
present ( from pre-change ) then
withdrawn ( the test change causes this ) then
present ( with the new data )

The test code was trying to test for this by checking
to see if the prefix was there, but due to timing issues
it's not always there when we look for it.

Modify the test to get the vpn table version prior to
the change( as that it should not be moving around ) and
then change the test for the prefix to look for a version
that is later than the vpn's table version.  Then we know
that it is *after* everything has stabilized again.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
tests/topotests/bgp_vpnv4_per_nexthop_label/test_bgp_vpnv4_per_nexthop_label.py

index cf1d3cb2b8d869cbd52d322246a6ffbe73023330..8a41b55ffb5abd55a1af418dad39a9ed224f1f83 100644 (file)
@@ -151,17 +151,24 @@ def teardown_module(_mod):
     tgen.stop_topology()
 
 
-def check_bgp_vpnv4_prefix_presence(router, prefix):
+def check_bgp_vpnv4_prefix_presence(router, prefix, table_version):
     "Check the presence of a prefix"
     tgen = get_topogen()
 
     dump = router.vtysh_cmd("show bgp ipv4 vpn {} json".format(prefix), isjson=True)
     if not dump:
         return "{}, prefix ipv4 vpn {} is not installed yet".format(router.name, prefix)
+
+    for _, paths in dump.items():
+        for path in paths["paths"]:
+            new_version = path["version"]
+        if new_version <= table_version:
+            return "{}, prefix ipv4 vpn {} has not been updated yet".format(router.name, prefix)
+
     return None
 
 
-def bgp_vpnv4_table_check(router, group, label_list=None, label_value_expected=None):
+def bgp_vpnv4_table_check(router, group, label_list=None, label_value_expected=None, table_version=0):
     """
     Dump and check that vpnv4 entries have the same MPLS label value
     * 'router': the router to check
@@ -173,7 +180,7 @@ def bgp_vpnv4_table_check(router, group, label_list=None, label_value_expected=N
 
     stored_label_inited = False
     for prefix in group:
-        test_func = functools.partial(check_bgp_vpnv4_prefix_presence, router, prefix)
+        test_func = functools.partial(check_bgp_vpnv4_prefix_presence, router, prefix, table_version)
         success, _ = topotest.run_and_expect(test_func, None, count=10, wait=0.5)
         assert success, "{}, prefix ipv4 vpn {} is not installed yet".format(
             router.name, prefix
@@ -218,7 +225,7 @@ def bgp_vpnv4_table_check(router, group, label_list=None, label_value_expected=N
                     )
 
 
-def bgp_vpnv4_table_check_all(router, label_list=None, same=False):
+def bgp_vpnv4_table_check_all(router, label_list=None, same=False, table_version=0):
     """
     Dump and check that vpnv4 entries are correctly configured with specific label values
     * 'router': the router to check
@@ -236,6 +243,7 @@ def bgp_vpnv4_table_check_all(router, label_list=None, same=False):
             + PREFIXES_REDIST
             + PREFIXES_CONNECTED,
             label_list=label_list,
+            table_version=table_version
         )
     else:
         for group in (
@@ -245,7 +253,7 @@ def bgp_vpnv4_table_check_all(router, label_list=None, same=False):
             PREFIXES_REDIST,
             PREFIXES_CONNECTED,
         ):
-            bgp_vpnv4_table_check(router, group=group, label_list=label_list)
+            bgp_vpnv4_table_check(router, group=group, label_list=label_list, table_version=table_version)
 
 
 def check_show_mpls_table(router, blacklist=None, label_list=None, whitelist=None):
@@ -349,6 +357,9 @@ def check_show_mpls_table_entry_label_not_found(router, inlabel):
         return "not good"
     return None
 
+def get_table_version(router):
+    table = router.vtysh_cmd("show bgp ipv4 vpn json", isjson=True)
+    return table["tableVersion"]
 
 def mpls_entry_get_interface(router, label):
     """
@@ -686,6 +697,7 @@ def test_changing_default_label_value():
         old_len != 1
     ), "r1, number of labels used should be greater than 1, oberved {} ".format(old_len)
 
+    table_version = get_table_version(router)
     logger.info("r1, vrf1, changing the default MPLS label value to export to 222")
     router.vtysh_cmd(
         "configure terminal\nrouter bgp 65500 vrf vrf1\naddress-family ipv4 unicast\nlabel vpn export 222\n",
@@ -705,7 +717,7 @@ def test_changing_default_label_value():
     # check label repartition is ok
     logger.info("r1, vpnv4 table, check the number of labels used after modification")
     label_list = set()
-    bgp_vpnv4_table_check_all(router, label_list)
+    bgp_vpnv4_table_check_all(router, label_list, table_version=table_version)
     new_len = len(label_list)
     assert (
         old_len == new_len
@@ -734,6 +746,7 @@ def test_unconfigure_allocation_mode_nexthop():
 
     logger.info("Unconfiguring allocation mode per nexthop")
     router = tgen.gears["r1"]
+    table_version = get_table_version(router)
     router.vtysh_cmd(
         "configure terminal\nrouter bgp 65500 vrf vrf1\naddress-family ipv4 unicast\nno label vpn export allocation-mode per-nexthop\n",
         isjson=False,
@@ -752,7 +765,7 @@ def test_unconfigure_allocation_mode_nexthop():
     # Check vpnv4 routes from r1
     logger.info("Checking vpnv4 routes on r1")
     label_list = set()
-    bgp_vpnv4_table_check_all(router, label_list=label_list, same=True)
+    bgp_vpnv4_table_check_all(router, label_list=label_list, same=True, table_version=table_version)
     assert len(label_list) == 1, "r1, multiple Label values found for vpnv4 updates"
 
     new_label = label_list.pop()
@@ -782,6 +795,8 @@ def test_reconfigure_allocation_mode_nexthop():
 
     logger.info("Reconfiguring allocation mode per nexthop")
     router = tgen.gears["r1"]
+
+    table_version = get_table_version(router)
     router.vtysh_cmd(
         "configure terminal\nrouter bgp 65500 vrf vrf1\naddress-family ipv4 unicast\nlabel vpn export allocation-mode per-nexthop\n",
         isjson=False,
@@ -800,7 +815,7 @@ def test_reconfigure_allocation_mode_nexthop():
     # Check vpnv4 routes from r1
     logger.info("Checking vpnv4 routes on r1")
     label_list = set()
-    bgp_vpnv4_table_check_all(router, label_list=label_list)
+    bgp_vpnv4_table_check_all(router, label_list=label_list, table_version=table_version)
     assert len(label_list) != 1, "r1, only 1 label values found for vpnv4 updates"
 
     # Check mpls table with all values