]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/ospf_basic_functionality/test_ospf_chaos.py
2 # SPDX-License-Identifier: ISC
5 # Copyright (c) 2020 by VMware, Inc. ("VMware")
6 # Used Copyright (c) 2018 by Network Device Education Foundation, Inc.
7 # ("NetDEF") in this file.
11 """OSPF Basic Functionality Automation."""
17 # Save the Current Working Directory to find configuration files.
18 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
19 sys
.path
.append(os
.path
.join(CWD
, "../"))
20 sys
.path
.append(os
.path
.join(CWD
, "../lib/"))
22 # pylint: disable=C0413
23 # Import topogen and topotest helpers
24 from lib
.topogen
import Topogen
, get_topogen
26 # Import topoJson from lib, to create topology and initial configuration
27 from lib
.common_config
import (
31 reset_config_on_routers
,
41 from lib
.ospf
import verify_ospf_neighbor
, verify_ospf_rib
, create_router_ospf
43 from lib
.topolog
import logger
44 from lib
.topojson
import build_config_from_json
46 pytestmark
= [pytest
.mark
.ospfd
, pytest
.mark
.staticd
]
62 Please view in a fixed-width font such as Courier.
64 +R1 +------------+R2 |
73 +R0 +-------------+R3 |
77 1. Verify ospf functionality after restart ospfd.
78 2. Verify ospf functionality after restart FRR service.
79 3. Verify ospf functionality when staticd is restarted.
83 def setup_module(mod
):
85 Sets up the pytest environment
89 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
90 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
93 logger
.info("Running setup_module to create topology")
95 # This function initiates the topology build with Topogen...
96 json_file
= "{}/ospf_chaos.json".format(CWD
)
97 tgen
= Topogen(json_file
, mod
.__name
__)
100 # ... and here it calls Mininet initialization functions.
102 # Starting topology, create tmp files which are loaded to routers
103 # to start daemons and then start routers
106 # Creating configuration from JSON
107 build_config_from_json(tgen
, topo
)
109 # Don't run this test if we have any failure.
110 if tgen
.routers_have_failure():
111 pytest
.skip(tgen
.errors
)
113 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
)
114 assert ospf_covergence
is True, "setup_module :Failed \n Error {}".format(
118 logger
.info("Running setup_module() done")
121 def teardown_module(mod
):
123 Teardown the pytest environment.
128 logger
.info("Running teardown_module to delete topology")
132 # Stop toplogy and Remove tmp files
136 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
138 logger
.info("=" * 40)
141 # ##################################
142 # Test cases start here.
143 # ##################################
144 def test_ospf_chaos_tc31_p1(request
):
145 """Verify ospf functionality after restart ospfd."""
146 tc_name
= request
.node
.name
147 write_test_header(tc_name
)
150 step("Bring up the base config as per the topology")
151 reset_config_on_routers(tgen
)
154 "Create static routes(10.0.20.1/32) in R1 and redistribute "
155 "to OSPF using route map."
158 # Create Static routes
163 "network": NETWORK
["ipv4"][0],
170 result
= create_static_routes(tgen
, input_dict
)
171 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
173 ospf_red_r0
= {"r0": {"ospf": {"redistribute": [{"redist_type": "static"}]}}}
174 result
= create_router_ospf(tgen
, topo
, ospf_red_r0
)
175 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
177 step("Verify OSPF neighbors after base config is done.")
178 # Api call verify whether OSPF is converged
179 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
)
180 assert ospf_covergence
is True, "Testcase Failed \n Error {}".format(
184 step("Verify that route is advertised to R1.")
187 nh
= topo
["routers"]["r0"]["links"]["r1"]["ipv4"].split("/")[0]
188 result
= verify_ospf_rib(tgen
, dut
, input_dict
, next_hop
=nh
)
189 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
191 result
= verify_rib(tgen
, "ipv4", dut
, input_dict
, protocol
=protocol
, next_hop
=nh
)
192 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
194 step("Kill OSPFd daemon on R0.")
195 kill_router_daemons(tgen
, "r0", ["ospfd"])
197 step("Verify OSPF neighbors are down after killing ospfd in R0")
199 # Api call verify whether OSPF is converged
200 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
, expected
=False)
201 assert ospf_covergence
is not True, "Testcase Failed \n Error {}".format(
205 step("Verify that route advertised to R1 are deleted from RIB and FIB.")
208 result
= verify_ospf_rib(tgen
, dut
, input_dict
, expected
=False)
211 ), "Testcase {} : Failed \n r1: OSPF routes are present \n Error: {}".format(
216 tgen
, "ipv4", dut
, input_dict
, protocol
=protocol
, expected
=False
220 ), "Testcase {} : Failed \n r1: routes are still present \n Error: {}".format(
224 step("Bring up OSPFd daemon on R0.")
225 start_router_daemons(tgen
, "r0", ["ospfd"])
227 step("Verify OSPF neighbors are up after bringing back ospfd in R0")
228 # Api call verify whether OSPF is converged
229 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
)
230 assert ospf_covergence
is True, "Testcase Failed \n Error {}".format(
235 "All the neighbours are up and routes are installed before the"
236 " restart. Verify OSPF route table and ip route table."
240 result
= verify_ospf_rib(tgen
, dut
, input_dict
, next_hop
=nh
)
241 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
243 result
= verify_rib(tgen
, "ipv4", dut
, input_dict
, protocol
=protocol
, next_hop
=nh
)
244 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
246 step("Kill OSPFd daemon on R1.")
247 kill_router_daemons(tgen
, "r1", ["ospfd"])
249 step("Verify OSPF neighbors are down after killing ospfd in R1")
251 # Api call verify whether OSPF is converged
252 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
, expected
=False)
253 assert ospf_covergence
is not True, "Testcase Failed \n Error {}".format(
257 step("Bring up OSPFd daemon on R1.")
258 start_router_daemons(tgen
, "r1", ["ospfd"])
260 step("Verify OSPF neighbors are up after bringing back ospfd in R1")
261 # Api call verify whether OSPF is converged
262 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
)
263 assert ospf_covergence
is True, "Testcase Failed \n Error {}".format(
268 "All the neighbours are up and routes are installed before the"
269 " restart. Verify OSPF route table and ip route table."
274 result
= verify_ospf_rib(tgen
, dut
, input_dict
, next_hop
=nh
)
275 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
277 result
= verify_rib(tgen
, "ipv4", dut
, input_dict
, protocol
=protocol
, next_hop
=nh
)
278 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
280 write_test_footer(tc_name
)
283 def test_ospf_chaos_tc32_p1(request
):
284 """Verify ospf functionality after restart FRR service."""
285 tc_name
= request
.node
.name
286 write_test_header(tc_name
)
289 step("Bring up the base config as per the topology")
290 reset_config_on_routers(tgen
)
293 "Create static routes(10.0.20.1/32) in R1 and redistribute "
294 "to OSPF using route map."
297 # Create Static routes
302 "network": NETWORK
["ipv4"][0],
309 result
= create_static_routes(tgen
, input_dict
)
310 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
312 ospf_red_r0
= {"r0": {"ospf": {"redistribute": [{"redist_type": "static"}]}}}
313 result
= create_router_ospf(tgen
, topo
, ospf_red_r0
)
314 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
316 step("Verify OSPF neighbors after base config is done.")
317 # Api call verify whether OSPF is converged
318 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
)
319 assert ospf_covergence
is True, "Testcase Failed \n Error {}".format(
323 step("Verify that route is advertised to R1.")
327 nh
= topo
["routers"]["r0"]["links"]["r1"]["ipv4"].split("/")[0]
328 result
= verify_ospf_rib(tgen
, dut
, input_dict
, next_hop
=nh
)
329 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
331 result
= verify_rib(tgen
, "ipv4", dut
, input_dict
, protocol
=protocol
, next_hop
=nh
)
332 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
334 step("Restart frr on R0")
335 stop_router(tgen
, "r0")
336 start_router(tgen
, "r0")
338 step("Verify OSPF neighbors are up after restarting R0")
339 # Api call verify whether OSPF is converged
340 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
)
341 assert ospf_covergence
is True, "Testcase Failed \n Error {}".format(
346 "All the neighbours are up and routes are installed before the"
347 " restart. Verify OSPF route table and ip route table."
351 result
= verify_ospf_rib(tgen
, dut
, input_dict
, next_hop
=nh
)
352 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
354 result
= verify_rib(tgen
, "ipv4", dut
, input_dict
, protocol
=protocol
, next_hop
=nh
)
355 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
357 step("Restart frr on R1")
358 stop_router(tgen
, "r1")
359 start_router(tgen
, "r1")
361 step("Verify OSPF neighbors are up after restarting R1")
362 # Api call verify whether OSPF is converged
363 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
)
364 assert ospf_covergence
is True, "Testcase Failed \n Error {}".format(
369 "All the neighbours are up and routes are installed before the"
370 " restart. Verify OSPF route table and ip route table."
374 result
= verify_ospf_rib(tgen
, dut
, input_dict
, next_hop
=nh
)
375 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
377 result
= verify_rib(tgen
, "ipv4", dut
, input_dict
, protocol
=protocol
, next_hop
=nh
)
378 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
380 write_test_footer(tc_name
)
383 def test_ospf_chaos_tc34_p1(request
):
385 verify ospf functionality when staticd is restarted.
387 Verify ospf functionalitywhen staticroutes are
388 redistributed & Staticd is restarted.
390 tc_name
= request
.node
.name
391 write_test_header(tc_name
)
394 step("Bring up the base config as per the topology")
395 reset_config_on_routers(tgen
)
398 "Create static routes(10.0.20.1/32) in R1 and redistribute "
399 "to OSPF using route map."
402 # Create Static routes
407 "network": NETWORK
["ipv4"][0],
414 result
= create_static_routes(tgen
, input_dict
)
415 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
417 ospf_red_r0
= {"r0": {"ospf": {"redistribute": [{"redist_type": "static"}]}}}
418 result
= create_router_ospf(tgen
, topo
, ospf_red_r0
)
419 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
421 step("Verify OSPF neighbors after base config is done.")
422 # Api call verify whether OSPF is converged
423 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
)
424 assert ospf_covergence
is True, "Testcase Failed \n Error {}".format(
428 step("Verify that route is advertised to R1.")
431 nh
= topo
["routers"]["r0"]["links"]["r1"]["ipv4"].split("/")[0]
432 result
= verify_ospf_rib(tgen
, dut
, input_dict
, next_hop
=nh
)
433 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
435 result
= verify_rib(tgen
, "ipv4", dut
, input_dict
, protocol
=protocol
, next_hop
=nh
)
436 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
438 step("Kill staticd daemon on R0.")
439 kill_router_daemons(tgen
, "r0", ["staticd"])
441 step("Verify that route advertised to R1 are deleted from RIB and FIB.")
444 result
= verify_ospf_rib(tgen
, dut
, input_dict
, expected
=False)
447 ), "Testcase {} : Failed \n r1: OSPF routes are present \n Error: {}".format(
452 tgen
, "ipv4", dut
, input_dict
, protocol
=protocol
, expected
=False
456 ), "Testcase {} : Failed \n r1: routes are still present \n Error: {}".format(
460 step("Bring up staticd daemon on R0.")
461 start_router_daemons(tgen
, "r0", ["staticd"])
463 step("Verify OSPF neighbors are up after bringing back ospfd in R0")
464 # Api call verify whether OSPF is converged
465 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
)
466 assert ospf_covergence
is True, "Testcase Failed \n Error {}".format(
471 "All the neighbours are up and routes are installed before the"
472 " restart. Verify OSPF route table and ip route table."
476 result
= verify_ospf_rib(tgen
, dut
, input_dict
, next_hop
=nh
)
477 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
479 result
= verify_rib(tgen
, "ipv4", dut
, input_dict
, protocol
=protocol
, next_hop
=nh
)
480 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
482 step("Kill staticd daemon on R1.")
483 kill_router_daemons(tgen
, "r1", ["staticd"])
485 step("Bring up staticd daemon on R1.")
486 start_router_daemons(tgen
, "r1", ["staticd"])
488 step("Verify OSPF neighbors are up after bringing back ospfd in R1")
489 # Api call verify whether OSPF is converged
490 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
)
491 assert ospf_covergence
is True, "Testcase Failed \n Error {}".format(
496 "All the neighbours are up and routes are installed before the"
497 " restart. Verify OSPF route table and ip route table."
502 result
= verify_ospf_rib(tgen
, dut
, input_dict
, next_hop
=nh
)
503 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
505 result
= verify_rib(tgen
, "ipv4", dut
, input_dict
, protocol
=protocol
, next_hop
=nh
)
506 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
508 write_test_footer(tc_name
)
511 if __name__
== "__main__":
512 args
= ["-s"] + sys
.argv
[1:]
513 sys
.exit(pytest
.main(args
))