Skip to content

Commit

Permalink
tests: Add some tests to show new behavior works as expected
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
donaldsharp committed Aug 27, 2024
1 parent 9bc0cd8 commit 37dd518
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
}
]
}
]
}
24 changes: 24 additions & 0 deletions tests/topotests/zebra_multiple_connected/r1/ip_route_kernel.json
Original file line number Diff line number Diff line change
@@ -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
}
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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__))
Expand Down Expand Up @@ -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))

0 comments on commit 37dd518

Please sign in to comment.