]> git.puffer.fish Git - mirror/frr.git/commitdiff
tests: Check if kernel routes work with changed vrf 13943/head
authoranlan_cs <vic.lan@pica8.com>
Mon, 26 Jun 2023 10:20:58 +0000 (18:20 +0800)
committerMergify <37929162+mergify[bot]@users.noreply.github.com>
Thu, 6 Jul 2023 06:02:05 +0000 (06:02 +0000)
Check `show ip route` for specific kernel routes after
the interface as their nexthop changes vrf.

After moving interface's vrf, there should be no kernel
route in old vrf.

Signed-off-by: anlan_cs <vic.lan@pica8.com>
(cherry picked from commit 019ac03e5b9fd46c51bd14f9f3a16c746e28fdac)

tests/topotests/zebra_rib/r1/v4_route_1_vrf_before.json [new file with mode: 0644]
tests/topotests/zebra_rib/test_zebra_rib.py

diff --git a/tests/topotests/zebra_rib/r1/v4_route_1_vrf_before.json b/tests/topotests/zebra_rib/r1/v4_route_1_vrf_before.json
new file mode 100644 (file)
index 0000000..997d12f
--- /dev/null
@@ -0,0 +1,27 @@
+{
+    "3.5.1.0/24":[
+        {
+            "prefix":"3.5.1.0/24",
+            "prefixLen":24,
+            "protocol":"kernel",
+            "vrfId":0,
+            "vrfName":"default",
+            "selected":true,
+            "destSelected":true,
+            "distance":0,
+            "metric":0,
+            "installed":true,
+            "table":254,
+            "nexthops":[
+                {
+                    "flags":3,
+                    "fib":true,
+                    "ip":"192.168.210.1",
+                    "afi":"ipv4",
+                    "interfaceName":"r1-eth0",
+                    "active":true
+                }
+            ]
+        }
+    ]
+}
index e2863218b0c1546f49e5d3e045c15d293f82e126..c45ac82d3000b928f7ed868502e45156c7ffa09d 100644 (file)
@@ -77,6 +77,41 @@ def teardown_module(mod):
     tgen.stop_topology()
 
 
+def test_zebra_kernel_route_vrf():
+    "Test kernel routes should be removed after interface changes vrf"
+    logger.info("Test kernel routes should be removed after interface changes vrf")
+    vrf = "RED"
+    tgen = get_topogen()
+    r1 = tgen.gears["r1"]
+
+    # Add kernel routes, the interface is initially in default vrf
+    r1.run("ip route add 3.5.1.0/24 via 192.168.210.1 dev r1-eth0")
+    json_file = "{}/r1/v4_route_1_vrf_before.json".format(CWD)
+    expected = json.loads(open(json_file).read())
+    test_func = partial(
+        topotest.router_json_cmp, r1, "show ip route 3.5.1.0/24 json", expected
+    )
+    _, result = topotest.run_and_expect(test_func, None, count=5, wait=1)
+    assert result is None, '"r1" JSON output mismatches'
+
+    # Change the interface's vrf
+    r1.run("ip link add {} type vrf table 1".format(vrf))
+    r1.run("ip link set {} up".format(vrf))
+    r1.run("ip link set dev r1-eth0 master {}".format(vrf))
+
+    expected = "{}"
+    test_func = partial(
+        topotest.router_output_cmp, r1, "show ip route 3.5.1.0/24 json", expected
+    )
+    result, diff = topotest.run_and_expect(test_func, "", count=5, wait=1)
+    assertmsg = "{} should not have the kernel route.\n{}".format('"r1"', diff)
+    assert result, assertmsg
+
+    # Clean up
+    r1.run("ip link set dev r1-eth0 nomaster")
+    r1.run("ip link del dev {}".format(vrf))
+
+
 def test_zebra_kernel_admin_distance():
     "Test some basic kernel routes added that should be accepted"
     logger.info("Test some basic kernel routes that should be accepted")