]>
Commit | Line | Data |
---|---|---|
dc5298d7 | 1 | #!/usr/bin/python |
2 | ||
3 | # | |
4 | # Copyright (c) 2020 by VMware, Inc. ("VMware") | |
5 | # Used Copyright (c) 2018 by Network Device Education Foundation, Inc. | |
6 | # ("NetDEF") in this file. | |
7 | # | |
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 | |
11 | # in all copies. | |
12 | # | |
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 | |
20 | # OF THIS SOFTWARE. | |
21 | # | |
22 | ||
23 | ||
24 | """OSPF Basic Functionality Automation.""" | |
25 | import os | |
26 | import sys | |
27 | import time | |
28 | import pytest | |
29 | import json | |
30 | from copy import deepcopy | |
31 | from ipaddress import IPv4Address | |
32 | ||
33 | # Save the Current Working Directory to find configuration files. | |
34 | CWD = os.path.dirname(os.path.realpath(__file__)) | |
35 | sys.path.append(os.path.join(CWD, "../")) | |
36 | sys.path.append(os.path.join(CWD, "../lib/")) | |
37 | ||
38 | # pylint: disable=C0413 | |
39 | # Import topogen and topotest helpers | |
8db751b8 | 40 | from lib.micronet_compat import Topo |
dc5298d7 | 41 | from lib.topogen import Topogen, get_topogen |
42 | import ipaddress | |
43 | ||
44 | # Import topoJson from lib, to create topology and initial configuration | |
45 | from lib.common_config import ( | |
46 | start_topology, | |
47 | write_test_header, | |
48 | write_test_footer, | |
49 | reset_config_on_routers, | |
50 | verify_rib, | |
51 | create_static_routes, | |
52 | step, | |
53 | create_route_maps, | |
54 | shutdown_bringup_interface, | |
55 | create_interfaces_cfg, | |
56 | topo_daemons, | |
57 | ) | |
58 | from lib.topolog import logger | |
59 | from lib.topojson import build_topo_from_json, build_config_from_json | |
8db751b8 | 60 | from lib.topotest import frr_unicode |
dc5298d7 | 61 | |
62 | from lib.ospf import ( | |
63 | verify_ospf_neighbor, | |
64 | config_ospf_interface, | |
65 | clear_ospf, | |
66 | verify_ospf_rib, | |
67 | create_router_ospf, | |
68 | verify_ospf_interface, | |
69 | verify_ospf_database, | |
70 | ) | |
71 | ||
6ff492b1 | 72 | |
e82b531d | 73 | pytestmark = [pytest.mark.ospfd, pytest.mark.staticd] |
6ff492b1 | 74 | |
dc5298d7 | 75 | # Global variables |
76 | topo = None | |
77 | ||
dc5298d7 | 78 | |
79 | """ | |
80 | TOPOOLOGY = | |
81 | Please view in a fixed-width font such as Courier. | |
82 | +---+ A1 +---+ | |
83 | +R1 +------------+R2 | | |
84 | +-+-+- +--++ | |
85 | | -- -- | | |
86 | | -- A0 -- | | |
87 | A0| ---- | | |
88 | | ---- | A2 | |
89 | | -- -- | | |
90 | | -- -- | | |
91 | +-+-+- +-+-+ | |
92 | +R0 +-------------+R3 | | |
93 | +---+ A3 +---+ | |
94 | ||
95 | TESTCASES = | |
96 | 1. OSPF P2MP -Verify state change events on p2mp network. | |
97 | """ | |
98 | ||
99 | ||
dc5298d7 | 100 | def setup_module(mod): |
101 | """ | |
102 | Sets up the pytest environment | |
103 | ||
104 | * `mod`: module name | |
105 | """ | |
dc5298d7 | 106 | testsuite_run_time = time.asctime(time.localtime(time.time())) |
107 | logger.info("Testsuite start time: {}".format(testsuite_run_time)) | |
108 | logger.info("=" * 40) | |
109 | ||
110 | logger.info("Running setup_module to create topology") | |
111 | ||
112 | # This function initiates the topology build with Topogen... | |
e82b531d CH |
113 | json_file = "{}/ospf_p2mp.json".format(CWD) |
114 | tgen = Topogen(json_file, mod.__name__) | |
115 | global topo | |
116 | topo = tgen.json_topo | |
dc5298d7 | 117 | # ... and here it calls Mininet initialization functions. |
118 | ||
119 | # get list of daemons needs to be started for this suite. | |
120 | daemons = topo_daemons(tgen, topo) | |
121 | ||
122 | # Starting topology, create tmp files which are loaded to routers | |
123 | # to start deamons and then start routers | |
124 | start_topology(tgen, daemons) | |
125 | ||
126 | # Creating configuration from JSON | |
127 | build_config_from_json(tgen, topo) | |
128 | ||
129 | # Don't run this test if we have any failure. | |
130 | if tgen.routers_have_failure(): | |
131 | pytest.skip(tgen.errors) | |
132 | ||
dc5298d7 | 133 | logger.info("Running setup_module() done") |
134 | ||
135 | ||
136 | def teardown_module(mod): | |
137 | """ | |
138 | Teardown the pytest environment. | |
139 | ||
140 | * `mod`: module name | |
141 | """ | |
142 | ||
143 | logger.info("Running teardown_module to delete topology") | |
144 | ||
145 | tgen = get_topogen() | |
146 | ||
147 | # Stop toplogy and Remove tmp files | |
148 | tgen.stop_topology() | |
149 | ||
150 | logger.info( | |
151 | "Testsuite end time: {}".format(time.asctime(time.localtime(time.time()))) | |
152 | ) | |
153 | logger.info("=" * 40) | |
154 | ||
155 | ||
156 | # ################################## | |
157 | # Test cases start here. | |
158 | # ################################## | |
159 | ||
160 | ||
161 | def test_ospf_p2mp_tc1_p0(request): | |
162 | """OSPF IFSM -Verify state change events on p2mp network.""" | |
163 | tc_name = request.node.name | |
164 | write_test_header(tc_name) | |
165 | tgen = get_topogen() | |
166 | ||
167 | # Don't run this test if we have any failure. | |
168 | if tgen.routers_have_failure(): | |
169 | pytest.skip(tgen.errors) | |
170 | ||
171 | global topo | |
172 | step("Bring up the base config as per the topology") | |
173 | reset_config_on_routers(tgen) | |
174 | step( | |
175 | "Verify that OSPF is subscribed to multi cast services " | |
176 | "(All SPF, all DR Routers)." | |
177 | ) | |
178 | step("Verify that interface is enabled in ospf.") | |
179 | step("Verify that config is successful.") | |
180 | dut = "r0" | |
181 | input_dict = { | |
182 | "r0": { | |
183 | "links": { | |
184 | "r3": {"ospf": {"mcastMemberOspfAllRouters": True, "ospfEnabled": True}} | |
185 | } | |
186 | } | |
187 | } | |
188 | result = verify_ospf_interface(tgen, topo, dut=dut, input_dict=input_dict) | |
189 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
190 | ||
191 | step("Delete the ip address") | |
192 | topo1 = { | |
193 | "r0": { | |
194 | "links": { | |
195 | "r3": { | |
196 | "ipv4": topo["routers"]["r0"]["links"]["r3"]["ipv4"], | |
197 | "interface": topo["routers"]["r0"]["links"]["r3"]["interface"], | |
198 | "delete": True, | |
199 | } | |
200 | } | |
201 | } | |
202 | } | |
203 | ||
204 | result = create_interfaces_cfg(tgen, topo1) | |
205 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
206 | ||
207 | step("Change the ip on the R0 interface") | |
208 | ||
209 | topo_modify_change_ip = deepcopy(topo) | |
210 | intf_ip = topo_modify_change_ip["routers"]["r0"]["links"]["r3"]["ipv4"] | |
211 | topo_modify_change_ip["routers"]["r0"]["links"]["r3"]["ipv4"] = str( | |
d7d21c3a | 212 | IPv4Address(frr_unicode(intf_ip.split("/")[0])) + 3 |
dc5298d7 | 213 | ) + "/{}".format(intf_ip.split("/")[1]) |
214 | ||
215 | build_config_from_json(tgen, topo_modify_change_ip, save_bkup=False) | |
216 | step("Verify that interface is enabled in ospf.") | |
217 | dut = "r0" | |
218 | input_dict = { | |
219 | "r0": { | |
220 | "links": { | |
221 | "r3": { | |
222 | "ospf": { | |
223 | "ipAddress": topo_modify_change_ip["routers"]["r0"]["links"][ | |
224 | "r3" | |
225 | ]["ipv4"].split("/")[0], | |
226 | "ipAddressPrefixlen": int( | |
227 | topo_modify_change_ip["routers"]["r0"]["links"]["r3"][ | |
228 | "ipv4" | |
229 | ].split("/")[1] | |
230 | ), | |
231 | } | |
232 | } | |
233 | } | |
234 | } | |
235 | } | |
236 | result = verify_ospf_interface(tgen, topo, dut=dut, input_dict=input_dict) | |
237 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
238 | ||
239 | step("Modify the mask on the R0 interface") | |
240 | ip_addr = topo_modify_change_ip["routers"]["r0"]["links"]["r3"]["ipv4"] | |
241 | mask = topo_modify_change_ip["routers"]["r0"]["links"]["r3"]["ipv4"] | |
242 | step("Delete the ip address") | |
243 | topo1 = { | |
244 | "r0": { | |
245 | "links": { | |
246 | "r3": { | |
247 | "ipv4": ip_addr, | |
248 | "interface": topo["routers"]["r0"]["links"]["r3"]["interface"], | |
249 | "delete": True, | |
250 | } | |
251 | } | |
252 | } | |
253 | } | |
254 | ||
255 | result = create_interfaces_cfg(tgen, topo1) | |
256 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
257 | ||
258 | step("Change the ip on the R0 interface") | |
259 | ||
260 | topo_modify_change_ip = deepcopy(topo) | |
261 | intf_ip = topo_modify_change_ip["routers"]["r0"]["links"]["r3"]["ipv4"] | |
262 | topo_modify_change_ip["routers"]["r0"]["links"]["r3"]["ipv4"] = str( | |
d7d21c3a | 263 | IPv4Address(frr_unicode(intf_ip.split("/")[0])) + 3 |
dc5298d7 | 264 | ) + "/{}".format(int(intf_ip.split("/")[1]) + 1) |
265 | ||
266 | build_config_from_json(tgen, topo_modify_change_ip, save_bkup=False) | |
267 | step("Verify that interface is enabled in ospf.") | |
268 | dut = "r0" | |
269 | input_dict = { | |
270 | "r0": { | |
271 | "links": { | |
272 | "r3": { | |
273 | "ospf": { | |
274 | "ipAddress": topo_modify_change_ip["routers"]["r0"]["links"][ | |
275 | "r3" | |
276 | ]["ipv4"].split("/")[0], | |
277 | "ipAddressPrefixlen": int( | |
278 | topo_modify_change_ip["routers"]["r0"]["links"]["r3"][ | |
279 | "ipv4" | |
280 | ].split("/")[1] | |
281 | ), | |
282 | } | |
283 | } | |
284 | } | |
285 | } | |
286 | } | |
287 | result = verify_ospf_interface(tgen, topo, dut=dut, input_dict=input_dict) | |
288 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
289 | ||
290 | topo1 = { | |
291 | "r0": { | |
292 | "links": { | |
293 | "r3": { | |
294 | "ipv4": topo_modify_change_ip["routers"]["r0"]["links"]["r3"][ | |
295 | "ipv4" | |
296 | ], | |
297 | "interface": topo_modify_change_ip["routers"]["r0"]["links"]["r3"][ | |
298 | "interface" | |
299 | ], | |
300 | "delete": True, | |
301 | } | |
302 | } | |
303 | } | |
304 | } | |
305 | ||
306 | result = create_interfaces_cfg(tgen, topo1) | |
307 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
308 | ||
309 | build_config_from_json(tgen, topo, save_bkup=False) | |
310 | ||
311 | step("Change the area id on the interface") | |
312 | input_dict = { | |
313 | "r0": { | |
314 | "links": { | |
315 | "r3": { | |
316 | "interface": topo["routers"]["r0"]["links"]["r3"]["interface"], | |
317 | "ospf": {"area": "0.0.0.0"}, | |
318 | "delete": True, | |
319 | } | |
320 | } | |
321 | } | |
322 | } | |
323 | ||
324 | result = create_interfaces_cfg(tgen, input_dict) | |
325 | assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) | |
326 | ||
327 | input_dict = { | |
328 | "r0": { | |
329 | "links": { | |
330 | "r3": { | |
331 | "interface": topo["routers"]["r0"]["links"]["r3"]["interface"], | |
332 | "ospf": {"area": "0.0.0.1"}, | |
333 | } | |
334 | } | |
335 | } | |
336 | } | |
337 | ||
338 | result = create_interfaces_cfg(tgen, input_dict) | |
339 | assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) | |
340 | step("Verify that interface is enabled in ospf.") | |
341 | dut = "r0" | |
342 | input_dict = { | |
343 | "r0": {"links": {"r3": {"ospf": {"area": "0.0.0.1", "ospfEnabled": True}}}} | |
344 | } | |
345 | result = verify_ospf_interface(tgen, topo, dut=dut, input_dict=input_dict) | |
346 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
347 | ||
348 | input_dict = { | |
349 | "r0": { | |
350 | "links": { | |
351 | "r3": { | |
352 | "interface": topo["routers"]["r0"]["links"]["r3"]["interface"], | |
353 | "ospf": {"area": "0.0.0.1"}, | |
354 | "delete": True, | |
355 | } | |
356 | } | |
357 | } | |
358 | } | |
359 | ||
360 | result = create_interfaces_cfg(tgen, input_dict) | |
361 | assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) | |
362 | ||
363 | input_dict = { | |
364 | "r0": { | |
365 | "links": { | |
366 | "r3": { | |
367 | "interface": topo["routers"]["r0"]["links"]["r3"]["interface"], | |
368 | "ospf": {"area": "0.0.0.0"}, | |
369 | } | |
370 | } | |
371 | } | |
372 | } | |
373 | ||
374 | result = create_interfaces_cfg(tgen, input_dict) | |
375 | assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) | |
376 | ||
377 | step("Verify if interface is enabled with network type P2MP") | |
378 | input_dict = { | |
379 | "r0": { | |
380 | "links": { | |
381 | "r3": { | |
382 | "interface": topo["routers"]["r0"]["links"]["r3"]["interface"], | |
5980ad0a | 383 | "ospf": {"area": "0.0.0.0", "networkType": "POINTOMULTIPOINT"}, |
dc5298d7 | 384 | } |
385 | } | |
386 | } | |
387 | } | |
388 | result = create_interfaces_cfg(tgen, input_dict) | |
389 | assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) | |
390 | ||
391 | write_test_footer(tc_name) | |
392 | ||
393 | ||
394 | if __name__ == "__main__": | |
395 | args = ["-s"] + sys.argv[1:] | |
396 | sys.exit(pytest.main(args)) |