]> git.puffer.fish Git - mirror/frr.git/commitdiff
topotests: fix bgp_vpnv4_noretain 12685/head
authorLouis Scalbert <louis.scalbert@6wind.com>
Mon, 23 Jan 2023 17:03:58 +0000 (18:03 +0100)
committerLouis Scalbert <louis.scalbert@6wind.com>
Tue, 24 Jan 2023 09:20:19 +0000 (10:20 +0100)
Fix the following issues:
- two tests are done in one function. Dispatch the tests in two
functions to help the test debug.
- the first test passes even if a third prefix is not filtered. Match
the exact to avoid false positive.
- the expected values contains variable like version. Do no check
variable values.

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
tests/topotests/bgp_vpnv4_noretain/r1/ipv4_vpn_routes.json
tests/topotests/bgp_vpnv4_noretain/r1/ipv4_vpn_routes_unfiltered.json
tests/topotests/bgp_vpnv4_noretain/test_bgp_vpnv4_noretain.py

index 903c4603c55caff492fc3c6eb7fc699aacfb98bd..28e153e3de89cadbeeb820de532c86ff8067aa1a 100644 (file)
@@ -1,7 +1,6 @@
 {
    "vrfId":0,
    "vrfName":"default",
-   "tableVersion":1,
    "routerId":"1.1.1.1",
    "defaultLocPrf":100,
    "localAS":65500,
@@ -17,7 +16,6 @@
                   "prefix":"10.201.0.0",
                   "prefixLen":24,
                   "network":"10.201.0.0\/24",
-                  "version":1,
                   "metric":0,
                   "weight":32768,
                   "peerId":"(unspec)",
@@ -28,6 +26,7 @@
                   "nexthops":[
                      {
                         "ip":"0.0.0.0",
+                        "hostname":"r1",
                         "afi":"ipv4",
                         "used":true
                      }
@@ -45,7 +44,6 @@
                   "prefix":"10.200.0.0",
                   "prefixLen":24,
                   "network":"10.200.0.0\/24",
-                  "version":1,
                   "metric":0,
                   "locPrf":100,
                   "weight":0,
@@ -55,6 +53,7 @@
                   "nexthops":[
                      {
                         "ip":"10.125.0.2",
+                        "hostname":"r2",
                         "afi":"ipv4",
                         "used":true
                      }
index 3cc0b4a5f510e0eee5fd9f4a7eefe60b822fdaeb..45f4acce6f95b1806199351c3d090c82c936bfcf 100644 (file)
@@ -1,7 +1,6 @@
 {
    "vrfId":0,
    "vrfName":"default",
-   "tableVersion":1,
    "routerId":"1.1.1.1",
    "defaultLocPrf":100,
    "localAS":65500,
@@ -17,7 +16,6 @@
                   "prefix":"10.201.0.0",
                   "prefixLen":24,
                   "network":"10.201.0.0\/24",
-                  "version":1,
                   "metric":0,
                   "weight":32768,
                   "peerId":"(unspec)",
@@ -28,6 +26,7 @@
                   "nexthops":[
                      {
                         "ip":"0.0.0.0",
+                        "hostname":"r1",
                         "afi":"ipv4",
                         "used":true
                      }
@@ -45,7 +44,6 @@
                   "prefix":"10.200.0.0",
                   "prefixLen":24,
                   "network":"10.200.0.0\/24",
-                  "version":1,
                   "metric":0,
                   "locPrf":100,
                   "weight":0,
@@ -55,6 +53,7 @@
                   "nexthops":[
                      {
                         "ip":"10.125.0.2",
+                        "hostname":"r2",
                         "afi":"ipv4",
                         "used":true
                      }
@@ -72,7 +71,6 @@
                   "prefix":"10.210.0.0",
                   "prefixLen":24,
                   "network":"10.210.0.0\/24",
-                  "version":1,
                   "metric":0,
                   "locPrf":100,
                   "weight":0,
@@ -82,6 +80,7 @@
                   "nexthops":[
                      {
                         "ip":"10.125.0.2",
+                        "hostname":"r2",
                         "afi":"ipv4",
                         "used":true
                      }
index b4a841d9cf6874bff41f441d9bbb0253e1c75a1a..ed5cc3faf66187ce950daf74f96e56ded3b04153 100644 (file)
@@ -133,27 +133,37 @@ def teardown_module(_mod):
     tgen.stop_topology()
 
 
-def test_protocols_convergence():
+def router_json_cmp_exact_filter(router, cmd, expected):
+    # filter out tableVersion, version and nhVrfID
+    output = router.cmd('vtysh -c "{}" | grep -v ersion | grep -v nhVrfId'.format(cmd))
+    logger.info("{}: {}\n{}".format(router.name, cmd, output))
+
+    json_output = json.loads(output)
+
+    return topotest.json_cmp(json_output, expected, exact=True)
+
+
+def test_bgp_no_retain():
     """
-    Assert that all protocols have converged
-    statuses as they depend on it.
+    Check bgp no retain route-target all on r1
     """
+
     tgen = get_topogen()
     if tgen.routers_have_failure():
         pytest.skip(tgen.errors)
 
     # Check IPv4 VPN routing tables on r1
-    logger.info("Checking IPv4 routes for convergence on r1")
-    router = tgen.gears['r1']
+    logger.info("Checking VPNv4 routes for convergence on r1")
+    router = tgen.gears["r1"]
     json_file = "{}/{}/ipv4_vpn_routes.json".format(CWD, router.name)
     if not os.path.isfile(json_file):
         logger.info("skipping file {}".format(json_file))
-        assert 0, 'ipv4_vpn_routes.json file not found'
+        assert 0, "{} file not found".format(json_file)
         return
 
     expected = json.loads(open(json_file).read())
     test_func = partial(
-        topotest.router_json_cmp,
+        router_json_cmp_exact_filter,
         router,
         "show bgp ipv4 vpn json",
         expected,
@@ -162,23 +172,31 @@ def test_protocols_convergence():
     assertmsg = '"{}" JSON output mismatches'.format(router.name)
     assert result is None, assertmsg
 
-    # Check BGP IPv4 routing tables after unsetting no retain flag
-    logger.info("Checking BGP IPv4 routes for convergence on r2")
-    router = tgen.gears['r1']
-    router.vtysh_cmd("configure\nrouter bgp 65500\naddress-family ipv4 vpn\nbgp retain route-target all\n")
+
+def test_bgp_retain():
+    """
+    Apply and check bgp retain route-target all on r1
+    """
+
+    tgen = get_topogen()
+    if tgen.routers_have_failure():
+        pytest.skip(tgen.errors)
 
     # Check IPv4 VPN routing tables on r1
-    logger.info("Checking IPv4 routes for convergence on r1")
-    router = tgen.gears['r1']
+    logger.info("Checking VPNv4 routes on r1 after bgp no retain")
+    router = tgen.gears["r1"]
+    router.vtysh_cmd(
+        "configure\nrouter bgp 65500\naddress-family ipv4 vpn\nbgp retain route-target all\n"
+    )
     json_file = "{}/{}/ipv4_vpn_routes_unfiltered.json".format(CWD, router.name)
     if not os.path.isfile(json_file):
         logger.info("skipping file {}".format(json_file))
-        assert 0, 'ipv4_vpn_routes_unfiltered.json file not found'
+        assert 0, "{} file not found".format(json_file)
         return
 
     expected = json.loads(open(json_file).read())
     test_func = partial(
-        topotest.router_json_cmp,
+        router_json_cmp_exact_filter,
         router,
         "show bgp ipv4 vpn json",
         expected,
@@ -187,6 +205,7 @@ def test_protocols_convergence():
     assertmsg = '"{}" JSON output mismatches'.format(router.name)
     assert result is None, assertmsg
 
+
 def test_memory_leak():
     "Run the memory leak test and report results."
     tgen = get_topogen()