From 9b9f23d9bce80f24f4f70a5f4e2569b25c59d5dc Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Thu, 15 Aug 2024 16:02:55 -0400 Subject: [PATCH] tests: Add some tests to show new behavior works as expected a) A noprefix address by itself should not create a connected route. This was pre-existing. b) A noprefix address with a corresponding route should result in a connected route. This is how NetworkManager appears to work. This is new behavior, so a new test. c) A route is added to the system from someone else. This is new behavior, so a new test. Signed-off-by: Donald Sharp --- .../r1/ip_route_connected.json | 24 +++++++++++ .../r1/ip_route_kernel.json | 24 +++++++++++ .../test_zebra_multiple_connected.py | 43 +++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 tests/topotests/zebra_multiple_connected/r1/ip_route_connected.json create mode 100644 tests/topotests/zebra_multiple_connected/r1/ip_route_kernel.json diff --git a/tests/topotests/zebra_multiple_connected/r1/ip_route_connected.json b/tests/topotests/zebra_multiple_connected/r1/ip_route_connected.json new file mode 100644 index 000000000000..db03ce84a6a4 --- /dev/null +++ b/tests/topotests/zebra_multiple_connected/r1/ip_route_connected.json @@ -0,0 +1,24 @@ +{ + "192.168.44.0/24":[ + { + "prefix":"192.168.44.0/24", + "prefixLen":24, + "protocol":"connected", + "vrfName":"default", + "selected":true, + "destSelected":true, + "distance":0, + "metric":0, + "installed":true, + "table":254, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"r1-eth1", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/zebra_multiple_connected/r1/ip_route_kernel.json b/tests/topotests/zebra_multiple_connected/r1/ip_route_kernel.json new file mode 100644 index 000000000000..22465cb477d3 --- /dev/null +++ b/tests/topotests/zebra_multiple_connected/r1/ip_route_kernel.json @@ -0,0 +1,24 @@ +{ + "4.5.6.7/32":[ + { + "prefix":"4.5.6.7/32", + "prefixLen":32, + "protocol":"kernel", + "vrfName":"default", + "selected":true, + "destSelected":true, + "distance":0, + "metric":0, + "installed":true, + "table":254, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"r1-eth1", + "active":true + } + ] + } + ] +} 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 dc47527c74c2..7dbeb6f1ccb3 100644 --- a/tests/topotests/zebra_multiple_connected/test_zebra_multiple_connected.py +++ b/tests/topotests/zebra_multiple_connected/test_zebra_multiple_connected.py @@ -19,6 +19,9 @@ 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__)) @@ -159,6 +162,46 @@ def test_zebra_noprefix_connected(): 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(_) + + if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args))