diff options
Diffstat (limited to 'tests/topotests/zebra_multiple_connected/test_zebra_multiple_connected.py')
-rw-r--r-- | tests/topotests/zebra_multiple_connected/test_zebra_multiple_connected.py | 68 |
1 files changed, 65 insertions, 3 deletions
diff --git a/tests/topotests/zebra_multiple_connected/test_zebra_multiple_connected.py b/tests/topotests/zebra_multiple_connected/test_zebra_multiple_connected.py index 0b2937c1..eda8c887 100644 --- a/tests/topotests/zebra_multiple_connected/test_zebra_multiple_connected.py +++ b/tests/topotests/zebra_multiple_connected/test_zebra_multiple_connected.py @@ -15,11 +15,13 @@ test_zebra_multiple_connected.py: Testing multiple connected """ import os -import re import sys import pytest import json from functools import partial +from lib.topolog import logger + +pytestmark = pytest.mark.random_order(disabled=True) # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) @@ -29,7 +31,6 @@ sys.path.append(os.path.join(CWD, "../")) # Import topogen and topotest helpers from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen -from lib.topolog import logger # Required to instantiate the topology builder class. @@ -157,10 +158,71 @@ def test_zebra_noprefix_connected(): test_func = partial( topotest.router_output_cmp, router, "show ip route 192.168.44.0/24", expected ) - result, diff = topotest.run_and_expect(test_func, "", count=20, wait=1) + result, _ = topotest.run_and_expect(test_func, "", count=20, wait=1) assert result, "Connected Route should not have been added" +def test_zebra_noprefix_connected_add(): + "Test that a noprefixroute created with a manual route works as expected, this is for NetworkManager" + + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + router = tgen.gears["r1"] + router.run("ip route add 192.168.44.0/24 dev r1-eth1") + + connected = "{}/{}/ip_route_connected.json".format(CWD, router.name) + expected = json.loads(open(connected).read()) + + test_func = partial( + topotest.router_json_cmp, router, "show ip route 192.168.44.0/24 json", expected + ) + result, _ = topotest.run_and_expect(test_func, None, count=20, wait=1) + assert result, "Connected Route should have been added\n{}".format(_) + + +def test_zebra_kernel_route_add(): + "Test that a random kernel route is properly handled as expected" + + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + router = tgen.gears["r1"] + router.run("ip route add 4.5.6.7/32 dev r1-eth1") + + kernel = "{}/{}/ip_route_kernel.json".format(CWD, router.name) + expected = json.loads(open(kernel).read()) + + test_func = partial( + topotest.router_json_cmp, router, "show ip route 4.5.6.7/32 json", expected + ) + result, _ = topotest.run_and_expect(test_func, None, count=20, wait=1) + 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)) |