test: add test case for kernel blackhole routes

The test verifies that a kernel blackhole route is not affected by
interface's link change.

Signed-off-by: anlan_cs <anlan_cs@126.com>
(cherry picked from commit 0073a870d1)
This commit is contained in:
anlan_cs 2024-11-01 15:16:09 +08:00 committed by Mergify
parent 3cb4dcda5c
commit ac1bd83312
2 changed files with 45 additions and 0 deletions

View File

@ -0,0 +1,24 @@
{
"0.0.0.0/0":[
{
"prefix":"0.0.0.0/0",
"prefixLen":0,
"protocol":"kernel",
"vrfName":"default",
"selected":true,
"destSelected":true,
"distance":0,
"metric":0,
"installed":true,
"table":254,
"nexthops":[
{
"fib":true,
"unreachable":true,
"blackhole":true,
"active":true
}
]
}
]
}

View File

@ -202,6 +202,27 @@ def test_zebra_kernel_route_add():
assert result, "Connected Route should have been added\n{}".format(_)
def test_zebra_kernel_route_blackhole_add():
"Test that a blackhole route is not affected by interface's link change"
tgen = get_topogen()
if tgen.routers_have_failure():
pytest.skip(tgen.errors)
router = tgen.gears["r1"]
router.run("ip route add blackhole default")
router.run("ip link set dev r1-eth1 down")
kernel = "{}/{}/ip_route_kernel_blackhole.json".format(CWD, router.name)
expected = json.loads(open(kernel).read())
test_func = partial(
topotest.router_json_cmp, router, "show ip route 0.0.0.0/0 json", expected
)
result, _ = topotest.run_and_expect(test_func, None, count=20, wait=1)
assert result, "Blackhole Route should have not been removed\n{}".format(_)
if __name__ == "__main__":
args = ["-s"] + sys.argv[1:]
sys.exit(pytest.main(args))