]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/zebra_multiple_connected/test_zebra_multiple_connected.py
2 # SPDX-License-Identifier: ISC
5 # test_zebra_multiple_connected.py
7 # Copyright (c) 2022 by
13 test_zebra_multiple_connected.py: Testing multiple connected
22 from functools
import partial
24 # Save the Current Working Directory to find configuration files.
25 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
26 sys
.path
.append(os
.path
.join(CWD
, "../"))
28 # pylint: disable=C0413
29 # Import topogen and topotest helpers
30 from lib
import topotest
31 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
32 from lib
.topolog
import logger
34 # Required to instantiate the topology builder class.
36 #####################################################
38 ## Network Topology Definition
40 #####################################################
44 for routern
in range(1, 4):
45 tgen
.add_router("r{}".format(routern
))
48 # First switch is for a dummy interface (for local network)
49 switch
= tgen
.add_switch("sw1")
50 switch
.add_link(tgen
.gears
["r1"])
53 # switch 2 switch is for connection to zebra router
54 switch
= tgen
.add_switch("sw2")
55 switch
.add_link(tgen
.gears
["r1"])
56 switch
.add_link(tgen
.gears
["r2"])
58 # switch 4 is stub on remote zebra router
59 switch
= tgen
.add_switch("sw4")
60 switch
.add_link(tgen
.gears
["r3"])
62 # switch 3 is between zebra routers
63 switch
= tgen
.add_switch("sw3")
64 switch
.add_link(tgen
.gears
["r2"])
65 switch
.add_link(tgen
.gears
["r3"])
68 #####################################################
72 #####################################################
75 def setup_module(module
):
77 tgen
= Topogen(build_topo
, module
.__name
__)
80 # This is a sample of configuration loading.
81 router_list
= tgen
.routers()
82 for rname
, router
in router_list
.items():
84 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
90 def teardown_module(_mod
):
91 "Teardown the pytest environment"
94 # This function tears down the whole topology.
98 def test_zebra_connected_multiple():
99 "Test multiple connected routes that have a kernel route pointing at one"
102 # Don't run this test if we have any failure.
103 if tgen
.routers_have_failure():
104 pytest
.skip(tgen
.errors
)
106 router
= tgen
.gears
["r1"]
107 router
.run("ip route add 192.168.1.1/32 via 10.0.1.99 dev r1-eth1")
108 router
.run("ip link add dummy1 type dummy")
109 router
.run("ip link set dummy1 up")
110 router
.run("ip link set dummy1 down")
112 routes
= "{}/{}/ip_route.json".format(CWD
, router
.name
)
113 expected
= json
.loads(open(routes
).read())
116 topotest
.router_json_cmp
, router
, "show ip route json", expected
119 _
, result
= topotest
.run_and_expect(test_func
, None, count
=20, wait
=1)
120 assert result
is None, "Kernel route is missing from zebra"
123 def test_zebra_system_recursion():
124 "Test a system route recursing through another system route"
127 if tgen
.routers_have_failure():
128 pytest
.skip(tgen
.errors
)
130 router
= tgen
.gears
["r1"]
131 router
.run("ip route add 10.0.1.30/32 dev r1-eth1")
132 router
.run("ip route add 10.9.9.0/24 via 10.0.1.30 dev r1-eth1")
133 router
.run("ip link add dummy2 type dummy")
134 router
.run("ip link set dummy2 up")
135 router
.run("ip link set dummy2 down")
137 routes
= "{}/{}/ip_route2.json".format(CWD
, router
.name
)
138 expected
= json
.loads(open(routes
).read())
140 topotest
.router_json_cmp
, router
, "show ip route json", expected
143 _
, result
= topotest
.run_and_expect(test_func
, None, count
=20, wait
=1)
144 assert result
is None, "Kernel route is missing from zebra"
147 if __name__
== "__main__":
148 args
= ["-s"] + sys
.argv
[1:]
149 sys
.exit(pytest
.main(args
))