]>
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
,
55 from lib
.ospf
import verify_ospf_neighbor
, verify_ospf_rib
, create_router_ospf
57 from lib
.topolog
import logger
58 from lib
.topojson
import build_config_from_json
60 pytestmark
= [pytest
.mark
.ospfd
, pytest
.mark
.staticd
]
76 Please view in a fixed-width font such as Courier.
78 +R1 +------------+R2 |
87 +R0 +-------------+R3 |
91 1. Verify ospf functionality after restart ospfd.
92 2. Verify ospf functionality after restart FRR service.
93 3. Verify ospf functionality when staticd is restarted.
97 def setup_module(mod
):
99 Sets up the pytest environment
103 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
104 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
105 logger
.info("=" * 40)
107 logger
.info("Running setup_module to create topology")
109 # This function initiates the topology build with Topogen...
110 json_file
= "{}/ospf_chaos.json".format(CWD
)
111 tgen
= Topogen(json_file
, mod
.__name
__)
113 topo
= tgen
.json_topo
114 # ... and here it calls Mininet initialization functions.
116 # get list of daemons needs to be started for this suite.
117 daemons
= topo_daemons(tgen
, topo
)
119 # Starting topology, create tmp files which are loaded to routers
120 # to start deamons and then start routers
121 start_topology(tgen
, daemons
)
123 # Creating configuration from JSON
124 build_config_from_json(tgen
, topo
)
126 # Don't run this test if we have any failure.
127 if tgen
.routers_have_failure():
128 pytest
.skip(tgen
.errors
)
130 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
)
131 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
135 logger
.info("Running setup_module() done")
138 def teardown_module(mod
):
140 Teardown the pytest environment.
145 logger
.info("Running teardown_module to delete topology")
149 # Stop toplogy and Remove tmp files
153 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
155 logger
.info("=" * 40)
158 # ##################################
159 # Test cases start here.
160 # ##################################
161 def test_ospf_chaos_tc31_p1(request
):
162 """Verify ospf functionality after restart ospfd."""
163 tc_name
= request
.node
.name
164 write_test_header(tc_name
)
167 step("Bring up the base config as per the topology")
168 reset_config_on_routers(tgen
)
171 "Create static routes(10.0.20.1/32) in R1 and redistribute "
172 "to OSPF using route map."
175 # Create Static routes
180 "network": NETWORK
["ipv4"][0],
187 result
= create_static_routes(tgen
, input_dict
)
188 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
190 ospf_red_r0
= {"r0": {"ospf": {"redistribute": [{"redist_type": "static"}]}}}
191 result
= create_router_ospf(tgen
, topo
, ospf_red_r0
)
192 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
194 step("Verify OSPF neighbors after base config is done.")
195 # Api call verify whether OSPF is converged
196 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
)
197 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
201 step("Verify that route is advertised to R1.")
204 nh
= topo
["routers"]["r0"]["links"]["r1"]["ipv4"].split("/")[0]
205 result
= verify_ospf_rib(tgen
, dut
, input_dict
, next_hop
=nh
)
206 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
208 result
= verify_rib(tgen
, "ipv4", dut
, input_dict
, protocol
=protocol
, next_hop
=nh
)
209 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
211 step("Kill OSPFd daemon on R0.")
212 kill_router_daemons(tgen
, "r0", ["ospfd"])
214 step("Verify OSPF neighbors are down after killing ospfd in R0")
216 # Api call verify whether OSPF is converged
217 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
, expected
=False)
218 assert ospf_covergence
is not True, "setup_module :Failed \n Error:" " {}".format(
222 step("Verify that route advertised to R1 are deleted from RIB and FIB.")
225 result
= verify_ospf_rib(tgen
, dut
, input_dict
, expected
=False)
228 ), "Testcase {} : Failed \n " "r1: OSPF routes are present \n Error: {}".format(
233 tgen
, "ipv4", dut
, input_dict
, protocol
=protocol
, expected
=False
237 ), "Testcase {} : Failed \n " "r1: routes are still present \n Error: {}".format(
241 step("Bring up OSPFd daemon on R0.")
242 start_router_daemons(tgen
, "r0", ["ospfd"])
244 step("Verify OSPF neighbors are up after bringing back ospfd in R0")
245 # Api call verify whether OSPF is converged
246 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
)
247 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
252 "All the neighbours are up and routes are installed before the"
253 " restart. Verify OSPF route table and ip route table."
257 result
= verify_ospf_rib(tgen
, dut
, input_dict
, next_hop
=nh
)
258 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
260 result
= verify_rib(tgen
, "ipv4", dut
, input_dict
, protocol
=protocol
, next_hop
=nh
)
261 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
263 step("Kill OSPFd daemon on R1.")
264 kill_router_daemons(tgen
, "r1", ["ospfd"])
266 step("Verify OSPF neighbors are down after killing ospfd in R1")
268 # Api call verify whether OSPF is converged
269 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
, expected
=False)
270 assert ospf_covergence
is not True, "setup_module :Failed \n Error:" " {}".format(
274 step("Bring up OSPFd daemon on R1.")
275 start_router_daemons(tgen
, "r1", ["ospfd"])
277 step("Verify OSPF neighbors are up after bringing back ospfd in R1")
278 # Api call verify whether OSPF is converged
279 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
)
280 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
285 "All the neighbours are up and routes are installed before the"
286 " restart. Verify OSPF route table and ip route table."
291 result
= verify_ospf_rib(tgen
, dut
, input_dict
, next_hop
=nh
)
292 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
294 result
= verify_rib(tgen
, "ipv4", dut
, input_dict
, protocol
=protocol
, next_hop
=nh
)
295 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
297 write_test_footer(tc_name
)
300 def test_ospf_chaos_tc32_p1(request
):
301 """Verify ospf functionality after restart FRR service."""
302 tc_name
= request
.node
.name
303 write_test_header(tc_name
)
306 step("Bring up the base config as per the topology")
307 reset_config_on_routers(tgen
)
310 "Create static routes(10.0.20.1/32) in R1 and redistribute "
311 "to OSPF using route map."
314 # Create Static routes
319 "network": NETWORK
["ipv4"][0],
326 result
= create_static_routes(tgen
, input_dict
)
327 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
329 ospf_red_r0
= {"r0": {"ospf": {"redistribute": [{"redist_type": "static"}]}}}
330 result
= create_router_ospf(tgen
, topo
, ospf_red_r0
)
331 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
333 step("Verify OSPF neighbors after base config is done.")
334 # Api call verify whether OSPF is converged
335 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
)
336 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
340 step("Verify that route is advertised to R1.")
344 nh
= topo
["routers"]["r0"]["links"]["r1"]["ipv4"].split("/")[0]
345 result
= verify_ospf_rib(tgen
, dut
, input_dict
, next_hop
=nh
)
346 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
348 result
= verify_rib(tgen
, "ipv4", dut
, input_dict
, protocol
=protocol
, next_hop
=nh
)
349 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
351 step("Restart frr on R0")
352 stop_router(tgen
, "r0")
353 start_router(tgen
, "r0")
355 step("Verify OSPF neighbors are up after restarting R0")
356 # Api call verify whether OSPF is converged
357 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
)
358 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
363 "All the neighbours are up and routes are installed before the"
364 " restart. Verify OSPF route table and ip route table."
368 result
= verify_ospf_rib(tgen
, dut
, input_dict
, next_hop
=nh
)
369 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
371 result
= verify_rib(tgen
, "ipv4", dut
, input_dict
, protocol
=protocol
, next_hop
=nh
)
372 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
374 step("Restart frr on R1")
375 stop_router(tgen
, "r1")
376 start_router(tgen
, "r1")
378 step("Verify OSPF neighbors are up after restarting R1")
379 # Api call verify whether OSPF is converged
380 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
)
381 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
386 "All the neighbours are up and routes are installed before the"
387 " restart. Verify OSPF route table and ip route table."
391 result
= verify_ospf_rib(tgen
, dut
, input_dict
, next_hop
=nh
)
392 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
394 result
= verify_rib(tgen
, "ipv4", dut
, input_dict
, protocol
=protocol
, next_hop
=nh
)
395 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
397 write_test_footer(tc_name
)
400 def test_ospf_chaos_tc34_p1(request
):
402 verify ospf functionality when staticd is restarted.
404 Verify ospf functionalitywhen staticroutes are
405 redistributed & Staticd is restarted.
407 tc_name
= request
.node
.name
408 write_test_header(tc_name
)
411 step("Bring up the base config as per the topology")
412 reset_config_on_routers(tgen
)
415 "Create static routes(10.0.20.1/32) in R1 and redistribute "
416 "to OSPF using route map."
419 # Create Static routes
424 "network": NETWORK
["ipv4"][0],
431 result
= create_static_routes(tgen
, input_dict
)
432 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
434 ospf_red_r0
= {"r0": {"ospf": {"redistribute": [{"redist_type": "static"}]}}}
435 result
= create_router_ospf(tgen
, topo
, ospf_red_r0
)
436 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
438 step("Verify OSPF neighbors after base config is done.")
439 # Api call verify whether OSPF is converged
440 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
)
441 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
445 step("Verify that route is advertised to R1.")
448 nh
= topo
["routers"]["r0"]["links"]["r1"]["ipv4"].split("/")[0]
449 result
= verify_ospf_rib(tgen
, dut
, input_dict
, next_hop
=nh
)
450 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
452 result
= verify_rib(tgen
, "ipv4", dut
, input_dict
, protocol
=protocol
, next_hop
=nh
)
453 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
455 step("Kill staticd daemon on R0.")
456 kill_router_daemons(tgen
, "r0", ["staticd"])
458 step("Verify that route advertised to R1 are deleted from RIB and FIB.")
461 result
= verify_ospf_rib(tgen
, dut
, input_dict
, expected
=False)
464 ), "Testcase {} : Failed \n " "r1: OSPF routes are present \n Error: {}".format(
469 tgen
, "ipv4", dut
, input_dict
, protocol
=protocol
, expected
=False
473 ), "Testcase {} : Failed \n " "r1: routes are still present \n Error: {}".format(
477 step("Bring up staticd daemon on R0.")
478 start_router_daemons(tgen
, "r0", ["staticd"])
480 step("Verify OSPF neighbors are up after bringing back ospfd in R0")
481 # Api call verify whether OSPF is converged
482 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
)
483 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
488 "All the neighbours are up and routes are installed before the"
489 " restart. Verify OSPF route table and ip route table."
493 result
= verify_ospf_rib(tgen
, dut
, input_dict
, next_hop
=nh
)
494 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
496 result
= verify_rib(tgen
, "ipv4", dut
, input_dict
, protocol
=protocol
, next_hop
=nh
)
497 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
499 step("Kill staticd daemon on R1.")
500 kill_router_daemons(tgen
, "r1", ["staticd"])
502 step("Bring up staticd daemon on R1.")
503 start_router_daemons(tgen
, "r1", ["staticd"])
505 step("Verify OSPF neighbors are up after bringing back ospfd in R1")
506 # Api call verify whether OSPF is converged
507 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
)
508 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
513 "All the neighbours are up and routes are installed before the"
514 " restart. Verify OSPF route table and ip route table."
519 result
= verify_ospf_rib(tgen
, dut
, input_dict
, next_hop
=nh
)
520 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
522 result
= verify_rib(tgen
, "ipv4", dut
, input_dict
, protocol
=protocol
, next_hop
=nh
)
523 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
525 write_test_footer(tc_name
)
528 if __name__
== "__main__":
529 args
= ["-s"] + sys
.argv
[1:]
530 sys
.exit(pytest
.main(args
))