]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/ospf_basic_functionality/test_ospf_chaos.py
4 # Copyright (c) 2020 by VMware, Inc. ("VMware")
5 # Used Copyright (c) 2018 by Network Device Education Foundation, Inc.
6 # ("NetDEF") in this file.
8 # Permission to use, copy, modify, and/or distribute this software
9 # for any purpose with or without fee is hereby granted, provided
10 # that the above copyright notice and this permission notice appear
13 # THE SOFTWARE IS PROVIDED "AS IS" AND VMWARE DISCLAIMS ALL WARRANTIES
14 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL VMWARE BE LIABLE FOR
16 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
17 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
18 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
19 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
24 """OSPF Basic Functionality Automation."""
30 # Save the Current Working Directory to find configuration files.
31 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
32 sys
.path
.append(os
.path
.join(CWD
, "../"))
33 sys
.path
.append(os
.path
.join(CWD
, "../lib/"))
35 # pylint: disable=C0413
36 # Import topogen and topotest helpers
37 from lib
.topogen
import Topogen
, get_topogen
39 # Import topoJson from lib, to create topology and initial configuration
40 from lib
.common_config
import (
44 reset_config_on_routers
,
54 from lib
.ospf
import verify_ospf_neighbor
, verify_ospf_rib
, create_router_ospf
56 from lib
.topolog
import logger
57 from lib
.topojson
import build_config_from_json
59 pytestmark
= [pytest
.mark
.ospfd
, pytest
.mark
.staticd
]
75 Please view in a fixed-width font such as Courier.
77 +R1 +------------+R2 |
86 +R0 +-------------+R3 |
90 1. Verify ospf functionality after restart ospfd.
91 2. Verify ospf functionality after restart FRR service.
92 3. Verify ospf functionality when staticd is restarted.
96 def setup_module(mod
):
98 Sets up the pytest environment
102 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
103 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
104 logger
.info("=" * 40)
106 logger
.info("Running setup_module to create topology")
108 # This function initiates the topology build with Topogen...
109 json_file
= "{}/ospf_chaos.json".format(CWD
)
110 tgen
= Topogen(json_file
, mod
.__name
__)
112 topo
= tgen
.json_topo
113 # ... and here it calls Mininet initialization functions.
115 # Starting topology, create tmp files which are loaded to routers
116 # to start daemons and then start routers
119 # Creating configuration from JSON
120 build_config_from_json(tgen
, topo
)
122 # Don't run this test if we have any failure.
123 if tgen
.routers_have_failure():
124 pytest
.skip(tgen
.errors
)
126 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
)
127 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
131 logger
.info("Running setup_module() done")
134 def teardown_module(mod
):
136 Teardown the pytest environment.
141 logger
.info("Running teardown_module to delete topology")
145 # Stop toplogy and Remove tmp files
149 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
151 logger
.info("=" * 40)
154 # ##################################
155 # Test cases start here.
156 # ##################################
157 def test_ospf_chaos_tc31_p1(request
):
158 """Verify ospf functionality after restart ospfd."""
159 tc_name
= request
.node
.name
160 write_test_header(tc_name
)
163 step("Bring up the base config as per the topology")
164 reset_config_on_routers(tgen
)
167 "Create static routes(10.0.20.1/32) in R1 and redistribute "
168 "to OSPF using route map."
171 # Create Static routes
176 "network": NETWORK
["ipv4"][0],
183 result
= create_static_routes(tgen
, input_dict
)
184 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
186 ospf_red_r0
= {"r0": {"ospf": {"redistribute": [{"redist_type": "static"}]}}}
187 result
= create_router_ospf(tgen
, topo
, ospf_red_r0
)
188 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
190 step("Verify OSPF neighbors after base config is done.")
191 # Api call verify whether OSPF is converged
192 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
)
193 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
197 step("Verify that route is advertised to R1.")
200 nh
= topo
["routers"]["r0"]["links"]["r1"]["ipv4"].split("/")[0]
201 result
= verify_ospf_rib(tgen
, dut
, input_dict
, next_hop
=nh
)
202 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
204 result
= verify_rib(tgen
, "ipv4", dut
, input_dict
, protocol
=protocol
, next_hop
=nh
)
205 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
207 step("Kill OSPFd daemon on R0.")
208 kill_router_daemons(tgen
, "r0", ["ospfd"])
210 step("Verify OSPF neighbors are down after killing ospfd in R0")
212 # Api call verify whether OSPF is converged
213 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
, expected
=False)
214 assert ospf_covergence
is not True, "setup_module :Failed \n Error:" " {}".format(
218 step("Verify that route advertised to R1 are deleted from RIB and FIB.")
221 result
= verify_ospf_rib(tgen
, dut
, input_dict
, expected
=False)
224 ), "Testcase {} : Failed \n " "r1: OSPF routes are present \n Error: {}".format(
229 tgen
, "ipv4", dut
, input_dict
, protocol
=protocol
, expected
=False
233 ), "Testcase {} : Failed \n " "r1: routes are still present \n Error: {}".format(
237 step("Bring up OSPFd daemon on R0.")
238 start_router_daemons(tgen
, "r0", ["ospfd"])
240 step("Verify OSPF neighbors are up after bringing back ospfd in R0")
241 # Api call verify whether OSPF is converged
242 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
)
243 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
248 "All the neighbours are up and routes are installed before the"
249 " restart. Verify OSPF route table and ip route table."
253 result
= verify_ospf_rib(tgen
, dut
, input_dict
, next_hop
=nh
)
254 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
256 result
= verify_rib(tgen
, "ipv4", dut
, input_dict
, protocol
=protocol
, next_hop
=nh
)
257 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
259 step("Kill OSPFd daemon on R1.")
260 kill_router_daemons(tgen
, "r1", ["ospfd"])
262 step("Verify OSPF neighbors are down after killing ospfd in R1")
264 # Api call verify whether OSPF is converged
265 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
, expected
=False)
266 assert ospf_covergence
is not True, "setup_module :Failed \n Error:" " {}".format(
270 step("Bring up OSPFd daemon on R1.")
271 start_router_daemons(tgen
, "r1", ["ospfd"])
273 step("Verify OSPF neighbors are up after bringing back ospfd in R1")
274 # Api call verify whether OSPF is converged
275 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
)
276 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
281 "All the neighbours are up and routes are installed before the"
282 " restart. Verify OSPF route table and ip route table."
287 result
= verify_ospf_rib(tgen
, dut
, input_dict
, next_hop
=nh
)
288 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
290 result
= verify_rib(tgen
, "ipv4", dut
, input_dict
, protocol
=protocol
, next_hop
=nh
)
291 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
293 write_test_footer(tc_name
)
296 def test_ospf_chaos_tc32_p1(request
):
297 """Verify ospf functionality after restart FRR service."""
298 tc_name
= request
.node
.name
299 write_test_header(tc_name
)
302 step("Bring up the base config as per the topology")
303 reset_config_on_routers(tgen
)
306 "Create static routes(10.0.20.1/32) in R1 and redistribute "
307 "to OSPF using route map."
310 # Create Static routes
315 "network": NETWORK
["ipv4"][0],
322 result
= create_static_routes(tgen
, input_dict
)
323 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
325 ospf_red_r0
= {"r0": {"ospf": {"redistribute": [{"redist_type": "static"}]}}}
326 result
= create_router_ospf(tgen
, topo
, ospf_red_r0
)
327 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
329 step("Verify OSPF neighbors after base config is done.")
330 # Api call verify whether OSPF is converged
331 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
)
332 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
336 step("Verify that route is advertised to R1.")
340 nh
= topo
["routers"]["r0"]["links"]["r1"]["ipv4"].split("/")[0]
341 result
= verify_ospf_rib(tgen
, dut
, input_dict
, next_hop
=nh
)
342 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
344 result
= verify_rib(tgen
, "ipv4", dut
, input_dict
, protocol
=protocol
, next_hop
=nh
)
345 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
347 step("Restart frr on R0")
348 stop_router(tgen
, "r0")
349 start_router(tgen
, "r0")
351 step("Verify OSPF neighbors are up after restarting R0")
352 # Api call verify whether OSPF is converged
353 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
)
354 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
359 "All the neighbours are up and routes are installed before the"
360 " restart. Verify OSPF route table and ip route table."
364 result
= verify_ospf_rib(tgen
, dut
, input_dict
, next_hop
=nh
)
365 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
367 result
= verify_rib(tgen
, "ipv4", dut
, input_dict
, protocol
=protocol
, next_hop
=nh
)
368 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
370 step("Restart frr on R1")
371 stop_router(tgen
, "r1")
372 start_router(tgen
, "r1")
374 step("Verify OSPF neighbors are up after restarting R1")
375 # Api call verify whether OSPF is converged
376 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
)
377 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
382 "All the neighbours are up and routes are installed before the"
383 " restart. Verify OSPF route table and ip route table."
387 result
= verify_ospf_rib(tgen
, dut
, input_dict
, next_hop
=nh
)
388 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
390 result
= verify_rib(tgen
, "ipv4", dut
, input_dict
, protocol
=protocol
, next_hop
=nh
)
391 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
393 write_test_footer(tc_name
)
396 def test_ospf_chaos_tc34_p1(request
):
398 verify ospf functionality when staticd is restarted.
400 Verify ospf functionalitywhen staticroutes are
401 redistributed & Staticd is restarted.
403 tc_name
= request
.node
.name
404 write_test_header(tc_name
)
407 step("Bring up the base config as per the topology")
408 reset_config_on_routers(tgen
)
411 "Create static routes(10.0.20.1/32) in R1 and redistribute "
412 "to OSPF using route map."
415 # Create Static routes
420 "network": NETWORK
["ipv4"][0],
427 result
= create_static_routes(tgen
, input_dict
)
428 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
430 ospf_red_r0
= {"r0": {"ospf": {"redistribute": [{"redist_type": "static"}]}}}
431 result
= create_router_ospf(tgen
, topo
, ospf_red_r0
)
432 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
434 step("Verify OSPF neighbors after base config is done.")
435 # Api call verify whether OSPF is converged
436 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
)
437 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
441 step("Verify that route is advertised to R1.")
444 nh
= topo
["routers"]["r0"]["links"]["r1"]["ipv4"].split("/")[0]
445 result
= verify_ospf_rib(tgen
, dut
, input_dict
, next_hop
=nh
)
446 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
448 result
= verify_rib(tgen
, "ipv4", dut
, input_dict
, protocol
=protocol
, next_hop
=nh
)
449 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
451 step("Kill staticd daemon on R0.")
452 kill_router_daemons(tgen
, "r0", ["staticd"])
454 step("Verify that route advertised to R1 are deleted from RIB and FIB.")
457 result
= verify_ospf_rib(tgen
, dut
, input_dict
, expected
=False)
460 ), "Testcase {} : Failed \n " "r1: OSPF routes are present \n Error: {}".format(
465 tgen
, "ipv4", dut
, input_dict
, protocol
=protocol
, expected
=False
469 ), "Testcase {} : Failed \n " "r1: routes are still present \n Error: {}".format(
473 step("Bring up staticd daemon on R0.")
474 start_router_daemons(tgen
, "r0", ["staticd"])
476 step("Verify OSPF neighbors are up after bringing back ospfd in R0")
477 # Api call verify whether OSPF is converged
478 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
)
479 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
484 "All the neighbours are up and routes are installed before the"
485 " restart. Verify OSPF route table and ip route table."
489 result
= verify_ospf_rib(tgen
, dut
, input_dict
, next_hop
=nh
)
490 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
492 result
= verify_rib(tgen
, "ipv4", dut
, input_dict
, protocol
=protocol
, next_hop
=nh
)
493 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
495 step("Kill staticd daemon on R1.")
496 kill_router_daemons(tgen
, "r1", ["staticd"])
498 step("Bring up staticd daemon on R1.")
499 start_router_daemons(tgen
, "r1", ["staticd"])
501 step("Verify OSPF neighbors are up after bringing back ospfd in R1")
502 # Api call verify whether OSPF is converged
503 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
)
504 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
509 "All the neighbours are up and routes are installed before the"
510 " restart. Verify OSPF route table and ip route table."
515 result
= verify_ospf_rib(tgen
, dut
, input_dict
, next_hop
=nh
)
516 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
518 result
= verify_rib(tgen
, "ipv4", dut
, input_dict
, protocol
=protocol
, next_hop
=nh
)
519 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
521 write_test_footer(tc_name
)
524 if __name__
== "__main__":
525 args
= ["-s"] + sys
.argv
[1:]
526 sys
.exit(pytest
.main(args
))