]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/babel_topo1/test_babel_topo1.py
6 # Copyright (c) 2017 by
7 # Cumulus Networks, Inc.
10 # Permission to use, copy, modify, and/or distribute this software
11 # for any purpose with or without fee is hereby granted, provided
12 # that the above copyright notice and this permission notice appear
15 # THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
16 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
17 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
18 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
19 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
21 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
26 test_babel_topo1.py: Testing BABEL
36 pytestmark
= [pytest
.mark
.babeld
]
38 # Save the Current Working Directory to find configuration files.
39 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
40 sys
.path
.append(os
.path
.join(CWD
, "../"))
42 # pylint: disable=C0413
43 # Import topogen and topotest helpers
44 from lib
import topotest
45 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
46 from lib
.topolog
import logger
48 # Required to instantiate the topology builder class.
50 #####################################################
52 ## Network Topology Definition
54 #####################################################
58 for routern
in range(1, 4):
59 tgen
.add_router("r{}".format(routern
))
62 # First switch is for a dummy interface (for local network)
63 switch
= tgen
.add_switch("sw1")
64 switch
.add_link(tgen
.gears
["r1"])
67 # switch 2 switch is for connection to BABEL router
68 switch
= tgen
.add_switch("sw2")
69 switch
.add_link(tgen
.gears
["r1"])
70 switch
.add_link(tgen
.gears
["r2"])
72 # switch 4 is stub on remote BABEL router
73 switch
= tgen
.add_switch("sw4")
74 switch
.add_link(tgen
.gears
["r3"])
76 # switch 3 is between BABEL routers
77 switch
= tgen
.add_switch("sw3")
78 switch
.add_link(tgen
.gears
["r2"])
79 switch
.add_link(tgen
.gears
["r3"])
82 #####################################################
86 #####################################################
89 def setup_module(module
):
91 tgen
= Topogen(build_topo
, module
.__name
__)
94 # This is a sample of configuration loading.
95 router_list
= tgen
.routers()
96 for rname
, router
in router_list
.items():
98 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
101 TopoRouter
.RD_BABEL
, os
.path
.join(CWD
, "{}/babeld.conf".format(rname
))
107 def teardown_module(_mod
):
108 "Teardown the pytest environment"
111 # This function tears down the whole topology.
115 def test_converge_protocols():
116 "Wait for protocol convergence"
119 # Don't run this test if we have any failure.
120 if tgen
.routers_have_failure():
121 pytest
.skip(tgen
.errors
)
123 topotest
.sleep(10, "Waiting for BABEL convergence")
126 def test_zebra_ipv4_routingTable():
127 "Test 'show ip route'"
130 # Don't run this test if we have any failure.
131 if tgen
.routers_have_failure():
132 pytest
.skip(tgen
.errors
)
135 router_list
= tgen
.routers().values()
136 for router
in router_list
:
137 output
= router
.vtysh_cmd("show ip route json", isjson
=True)
138 refTableFile
= "{}/{}/show_ip_route.json_ref".format(CWD
, router
.name
)
139 expected
= json
.loads(open(refTableFile
).read())
141 assertmsg
= "Zebra IPv4 Routing Table verification failed for router {}".format(
144 assert topotest
.json_cmp(output
, expected
) is None, assertmsg
146 def test_shutdown_check_stderr():
147 if os
.environ
.get("TOPOTESTS_CHECK_STDERR") is None:
148 pytest
.skip("Skipping test for Stderr output and memory leaks")
151 # Don't run this test if we have any failure.
152 if tgen
.routers_have_failure():
153 pytest
.skip(tgen
.errors
)
155 logger
.info("Verifying unexpected STDERR output from daemons")
157 router_list
= tgen
.routers().values()
158 for router
in router_list
:
161 log
= tgen
.net
[router
.name
].getStdErr("babeld")
163 logger
.error("BABELd StdErr Log:" + log
)
164 log
= tgen
.net
[router
.name
].getStdErr("zebra")
166 logger
.error("Zebra StdErr Log:" + log
)
169 if __name__
== "__main__":
170 args
= ["-s"] + sys
.argv
[1:]
171 sys
.exit(pytest
.main(args
))