]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/ldp_oc_topo1/test_ldp_oc_topo1.py
5 # Part of NetDEF Topology Tests
7 # Copyright (c) 2020 by by Volta Networks
9 # Permission to use, copy, modify, and/or distribute this software
10 # for any purpose with or without fee is hereby granted, provided
11 # that the above copyright notice and this permission notice appear
14 # THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
15 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
17 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
18 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
19 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
20 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
25 test_ldp_oc_topo1.py: Simple FRR LDP Test
44 r2-eth2 .2 | | .2 r2-eth1
47 ~~~~~~~~~~~~~ ~~~~~~~~~~~~~
49 ~~ 10.0.3.0/24 ~~ ~~ 10.0.2.0/24 ~~
50 ~~~~~~~~~~~~~ ~~~~~~~~~~~~~
54 r3-eth1 .3 | | .3 r3-eth0 | .4 r4-eth0
55 +----+--+---+ +----+----+
57 | 3.3.3.3 | | 4.4.4.4 |
58 +-----------+ +---------+
65 from functools
import partial
67 # Save the Current Working Directory to find configuration files.
68 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
69 sys
.path
.append(os
.path
.join(CWD
, "../"))
71 # pylint: disable=C0413
72 # Import topogen and topotest helpers
73 from lib
import topotest
74 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
75 from lib
.topolog
import logger
77 # Required to instantiate the topology builder class.
79 pytestmark
= [pytest
.mark
.ldpd
, pytest
.mark
.ospfd
]
88 for router
in ["r1", "r2", "r3", "r4"]:
89 tgen
.add_router(router
)
94 switch
= tgen
.add_switch("s0")
95 switch
.add_link(tgen
.gears
["r1"])
96 switch
.add_link(tgen
.gears
["r2"])
98 switch
= tgen
.add_switch("s1")
99 switch
.add_link(tgen
.gears
["r2"])
100 switch
.add_link(tgen
.gears
["r3"])
101 switch
.add_link(tgen
.gears
["r4"])
103 switch
= tgen
.add_switch("s2")
104 switch
.add_link(tgen
.gears
["r2"])
105 switch
.add_link(tgen
.gears
["r3"])
108 def setup_module(mod
):
109 "Sets up the pytest environment"
110 tgen
= Topogen(build_topo
, mod
.__name
__)
111 tgen
.start_topology()
113 router_list
= tgen
.routers()
115 # For all registered routers, load the zebra configuration file
116 for rname
, router
in router_list
.items():
118 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
120 # Don't start ospfd and ldpd in the CE nodes
121 if router
.name
[0] == "r":
123 TopoRouter
.RD_OSPF
, os
.path
.join(CWD
, "{}/ospfd.conf".format(rname
))
126 TopoRouter
.RD_LDP
, os
.path
.join(CWD
, "{}/ldpd.conf".format(rname
))
132 def teardown_module(mod
):
133 "Teardown the pytest environment"
136 # This function tears down the whole topology.
140 def router_compare_json_output(rname
, command
, reference
):
141 "Compare router JSON output"
143 logger
.info('Comparing router "%s" "%s" output', rname
, command
)
146 filename
= "{}/{}/{}".format(CWD
, rname
, reference
)
147 expected
= json
.loads(open(filename
).read())
149 # Run test function until we get an result. Wait at most 80 seconds.
150 test_func
= partial(topotest
.router_json_cmp
, tgen
.gears
[rname
], command
, expected
)
151 _
, diff
= topotest
.run_and_expect(test_func
, None, count
=160, wait
=0.5)
153 assertmsg
= '"{}" JSON output mismatches the expected result'.format(rname
)
154 assert diff
is None, assertmsg
157 def test_ospf_convergence():
158 logger
.info("Test: check OSPF adjacencies")
162 # Skip if previous fatal error condition is raised
163 if tgen
.routers_have_failure():
164 pytest
.skip(tgen
.errors
)
166 for rname
in ["r1", "r2", "r3", "r4"]:
167 router_compare_json_output(
168 rname
, "show ip ospf neighbor json", "show_ip_ospf_neighbor.json"
173 logger
.info("Test: verify RIB")
176 # Skip if previous fatal error condition is raised
177 if tgen
.routers_have_failure():
178 pytest
.skip(tgen
.errors
)
180 for rname
in ["r1", "r2", "r3", "r4"]:
181 router_compare_json_output(rname
, "show ip route json", "show_ip_route.ref")
184 def test_ldp_adjacencies():
185 logger
.info("Test: verify LDP adjacencies")
188 # Skip if previous fatal error condition is raised
189 if tgen
.routers_have_failure():
190 pytest
.skip(tgen
.errors
)
192 for rname
in ["r1", "r2", "r3", "r4"]:
193 router_compare_json_output(
194 rname
, "show mpls ldp discovery json", "show_ldp_discovery.ref"
198 def test_ldp_neighbors():
199 logger
.info("Test: verify LDP neighbors")
202 # Skip if previous fatal error condition is raised
203 if tgen
.routers_have_failure():
204 pytest
.skip(tgen
.errors
)
206 for rname
in ["r1", "r2", "r3", "r4"]:
207 router_compare_json_output(
208 rname
, "show mpls ldp neighbor json", "show_ldp_neighbor.ref"
212 def test_ldp_bindings():
213 logger
.info("Test: verify LDP bindings")
216 # Skip if previous fatal error condition is raised
217 if tgen
.routers_have_failure():
218 pytest
.skip(tgen
.errors
)
220 for rname
in ["r1", "r2", "r3", "r4"]:
221 router_compare_json_output(
222 rname
, "show mpls ldp binding json", "show_ldp_binding.ref"
226 # Memory leak test template
227 def test_memory_leak():
228 "Run the memory leak test and report results."
230 if not tgen
.is_memleak_enabled():
231 pytest
.skip("Memory leak test/report is disabled")
233 tgen
.report_memory_leaks()
236 if __name__
== "__main__":
237 args
= ["-s"] + sys
.argv
[1:]
238 sys
.exit(pytest
.main(args
))