]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/ospf_dual_stack/test_ospf_dual_stack.py
tests: micronet: adapt tests
[mirror_frr.git] / tests / topotests / ospf_dual_stack / test_ospf_dual_stack.py
1 #!/usr/bin/python
2
3 import os
4 import sys
5 import time
6 import pytest
7 import json
8
9 CWD = os.path.dirname(os.path.realpath(__file__))
10 sys.path.append(os.path.join(CWD, "../"))
11 sys.path.append(os.path.join(CWD, "../lib/"))
12
13 from lib.micronet_compat import Topo
14 from lib.topogen import Topogen, get_topogen
15
16 from lib.common_config import (
17 start_topology,
18 write_test_header,
19 write_test_footer,
20 reset_config_on_routers,
21 stop_router,
22 start_router,
23 verify_rib,
24 create_static_routes,
25 step,
26 start_router_daemons,
27 shutdown_bringup_interface,
28 topo_daemons,
29 create_prefix_lists,
30 create_interfaces_cfg,
31 run_frr_cmd,
32 )
33 from lib.topolog import logger
34 from lib.topojson import build_topo_from_json, build_config_from_json
35 from lib.ospf import (
36 verify_ospf_neighbor,
37 verify_ospf6_neighbor,
38 create_router_ospf,
39 create_router_ospf6,
40 verify_ospf_summary,
41 redistribute_ospf,
42 verify_ospf_database,
43 )
44
45 pytestmark = [pytest.mark.ospfd, pytest.mark.staticd]
46
47
48 # Global variables
49 topo = None
50
51 # Reading the data from JSON File for topology creation
52 jsonFile = "{}/test_ospf_dual_stack.json".format(CWD)
53 try:
54 with open(jsonFile, "r") as topoJson:
55 topo = json.load(topoJson)
56 except IOError:
57 assert False, "Could not read file {}".format(jsonFile)
58
59
60 class CreateTopo(Topo):
61 """Test topology builder."""
62
63 def build(self, *_args, **_opts):
64 """Build function."""
65 tgen = get_topogen(self)
66
67 # Building topology from json file
68 build_topo_from_json(tgen, topo)
69
70
71 def setup_module(mod):
72 """Sets up the pytest environment."""
73 global topo
74 testsuite_run_time = time.asctime(time.localtime(time.time()))
75 logger.info("Testsuite start time: {}".format(testsuite_run_time))
76 logger.info("=" * 40)
77
78 logger.info("Running setup_module to create topology")
79
80 # This function initiates the topology build with Topogen...
81 tgen = Topogen(CreateTopo, mod.__name__)
82 # ... and here it calls Mininet initialization functions.
83
84 # get list of daemons needs to be started for this suite.
85 daemons = topo_daemons(tgen, topo)
86
87 # Starting topology, create tmp files which are loaded to routers
88 # to start daemons and then start routers
89 start_topology(tgen, daemons)
90
91 # Creating configuration from JSON
92 build_config_from_json(tgen, topo)
93
94 # Don't run this test if we have any failure.
95 if tgen.routers_have_failure():
96 pytest.skip(tgen.errors)
97
98 # Api call verify whether OSPF converged
99 ospf_covergence_ipv4 = verify_ospf_neighbor(tgen, topo)
100 assert ospf_covergence_ipv4 is True, "setup_module :Failed \n Error:" " {}".format(
101 ospf_covergence_ipv4
102 )
103
104 # Api call verify whether OSPF6 converged
105 ospf_covergence_ipv6 = verify_ospf6_neighbor(tgen, topo)
106 assert ospf_covergence_ipv6 is True, "setup_module :Failed \n Error:" " {}".format(
107 ospf_covergence_ipv6
108 )
109 logger.info("Running setup_module() done")
110
111
112 def teardown_module(mod):
113 """
114 Teardown the pytest environment.
115
116 * `mod`: module name
117 """
118
119 logger.info("Running teardown_module to delete topology")
120 tgen = get_topogen()
121 # Stop topology and remove tmp files
122 tgen.stop_topology()
123 logger.info(
124 "Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
125 )
126 logger.info("=" * 40)
127
128
129 #
130 # ##################################
131 # Test cases start here.
132 # ##################################
133 #
134 #
135 def test_ospf_dual_stack(request):
136 """OSPF test dual stack."""
137
138 tc_name = request.node.name
139 write_test_header(tc_name)
140
141 # Don't run this test if we have any failure.
142 tgen = get_topogen()
143 if tgen.routers_have_failure():
144 pytest.skip(tgen.errors)
145
146 global topo
147
148 step("Bring up the base configuration as per the JSON topology")
149 reset_config_on_routers(tgen)
150 write_test_footer(tc_name)
151
152
153 if __name__ == "__main__":
154 args = ["-s"] + sys.argv[1:]
155 sys.exit(pytest.main(args))