blob: b9a07b974a8f548f1abc6b6d88b5d1958d9265f8 [file] [log] [blame]
Jon Hall73cf9cc2014-11-20 22:28:38 -08001'''
2Description: This test is to determine if ONOS can handle
3 all of it's nodes restarting
4
5List of test cases:
6CASE1: Compile ONOS and push it to the test machines
7CASE2: Assign mastership to controllers
8CASE3: Assign intents
9CASE4: Ping across added host intents
10CASE5: Reading state of ONOS
11CASE6: The Failure case.
12CASE7: Check state after control plane failure
13CASE8: Compare topo
14CASE9: Link s3-s28 down
15CASE10: Link s3-s28 up
16CASE11: Switch down
17CASE12: Switch up
18CASE13: Clean up
Jon Hall669173b2014-12-17 11:36:30 -080019CASE14: start election app on all onos nodes
20CASE15: Check that Leadership Election is still functional
Jon Hall73cf9cc2014-11-20 22:28:38 -080021'''
22class HATestClusterRestart:
23
24 def __init__(self) :
25 self.default = ''
26
27 def CASE1(self,main) :
28 '''
29 CASE1 is to compile ONOS and push it to the test machines
30
31 Startup sequence:
32 git pull
33 mvn clean install
34 onos-package
35 cell <name>
36 onos-verify-cell
37 NOTE: temporary - onos-remove-raft-logs
38 onos-install -f
39 onos-wait-for-start
40 '''
41 import time
42 main.log.report("ONOS HA test: Restart all ONOS nodes - initialization")
43 main.case("Setting up test environment")
44
45 # load some vairables from the params file
46 PULL_CODE = False
47 if main.params['Git'] == 'True':
48 PULL_CODE = True
49 cell_name = main.params['ENV']['cellName']
50
51 #set global variables
52 global ONOS1_ip
53 global ONOS1_port
54 global ONOS2_ip
55 global ONOS2_port
56 global ONOS3_ip
57 global ONOS3_port
58 global ONOS4_ip
59 global ONOS4_port
60 global ONOS5_ip
61 global ONOS5_port
62 global ONOS6_ip
63 global ONOS6_port
64 global ONOS7_ip
65 global ONOS7_port
Jon Hall669173b2014-12-17 11:36:30 -080066 global num_controllers
Jon Hall73cf9cc2014-11-20 22:28:38 -080067
68 ONOS1_ip = main.params['CTRL']['ip1']
69 ONOS1_port = main.params['CTRL']['port1']
70 ONOS2_ip = main.params['CTRL']['ip2']
71 ONOS2_port = main.params['CTRL']['port2']
72 ONOS3_ip = main.params['CTRL']['ip3']
73 ONOS3_port = main.params['CTRL']['port3']
74 ONOS4_ip = main.params['CTRL']['ip4']
75 ONOS4_port = main.params['CTRL']['port4']
76 ONOS5_ip = main.params['CTRL']['ip5']
77 ONOS5_port = main.params['CTRL']['port5']
78 ONOS6_ip = main.params['CTRL']['ip6']
79 ONOS6_port = main.params['CTRL']['port6']
80 ONOS7_ip = main.params['CTRL']['ip7']
81 ONOS7_port = main.params['CTRL']['port7']
Jon Hall669173b2014-12-17 11:36:30 -080082 num_controllers = int(main.params['num_controllers'])
Jon Hall73cf9cc2014-11-20 22:28:38 -080083
84
85 main.step("Applying cell variable to environment")
86 cell_result = main.ONOSbench.set_cell(cell_name)
87 verify_result = main.ONOSbench.verify_cell()
88
Jon Hall94fd0472014-12-08 11:52:42 -080089 #FIXME:this is short term fix
Jon Hall73cf9cc2014-11-20 22:28:38 -080090 main.log.report("Removing raft logs")
91 main.ONOSbench.onos_remove_raft_logs()
92 main.log.report("Uninstalling ONOS")
93 main.ONOSbench.onos_uninstall(ONOS1_ip)
94 main.ONOSbench.onos_uninstall(ONOS2_ip)
95 main.ONOSbench.onos_uninstall(ONOS3_ip)
96 main.ONOSbench.onos_uninstall(ONOS4_ip)
97 main.ONOSbench.onos_uninstall(ONOS5_ip)
98 main.ONOSbench.onos_uninstall(ONOS6_ip)
99 main.ONOSbench.onos_uninstall(ONOS7_ip)
100
101 clean_install_result = main.TRUE
102 git_pull_result = main.TRUE
103
104 main.step("Compiling the latest version of ONOS")
105 if PULL_CODE:
106 main.step("Git checkout and pull master")
107 main.ONOSbench.git_checkout("master")
108 git_pull_result = main.ONOSbench.git_pull()
109
110 main.step("Using mvn clean & install")
111 clean_install_result = main.TRUE
112 if git_pull_result == main.TRUE:
113 clean_install_result = main.ONOSbench.clean_install()
114 else:
115 main.log.warn("Did not pull new code so skipping mvn "+ \
116 "clean install")
117 main.ONOSbench.get_version(report=True)
118
119 main.step("Creating ONOS package")
120 package_result = main.ONOSbench.onos_package()
121
122 main.step("Installing ONOS package")
123 onos1_install_result = main.ONOSbench.onos_install(options="-f",
124 node=ONOS1_ip)
125 onos2_install_result = main.ONOSbench.onos_install(options="-f",
126 node=ONOS2_ip)
127 onos3_install_result = main.ONOSbench.onos_install(options="-f",
128 node=ONOS3_ip)
129 onos4_install_result = main.ONOSbench.onos_install(options="-f",
130 node=ONOS4_ip)
131 onos5_install_result = main.ONOSbench.onos_install(options="-f",
132 node=ONOS5_ip)
133 onos6_install_result = main.ONOSbench.onos_install(options="-f",
134 node=ONOS6_ip)
135 onos7_install_result = main.ONOSbench.onos_install(options="-f",
136 node=ONOS7_ip)
137 onos_install_result = onos1_install_result and onos2_install_result\
138 and onos3_install_result and onos4_install_result\
139 and onos5_install_result and onos6_install_result\
140 and onos7_install_result
141 '''
142 #FIXME: work around until onos is less fragile
143 main.ONOSbench.handle.sendline("onos-cluster-install")
144 print main.ONOSbench.handle.expect("\$")
145 onos_install_result = main.TRUE
146 '''
147
148
149 main.step("Checking if ONOS is up yet")
Jon Hall669173b2014-12-17 11:36:30 -0800150 #TODO check bundle:list?
Jon Hall94fd0472014-12-08 11:52:42 -0800151 for i in range(2):
152 onos1_isup = main.ONOSbench.isup(ONOS1_ip)
153 if not onos1_isup:
154 main.log.report("ONOS1 didn't start!")
155 onos2_isup = main.ONOSbench.isup(ONOS2_ip)
156 if not onos2_isup:
157 main.log.report("ONOS2 didn't start!")
158 onos3_isup = main.ONOSbench.isup(ONOS3_ip)
159 if not onos3_isup:
160 main.log.report("ONOS3 didn't start!")
161 onos4_isup = main.ONOSbench.isup(ONOS4_ip)
162 if not onos4_isup:
163 main.log.report("ONOS4 didn't start!")
164 onos5_isup = main.ONOSbench.isup(ONOS5_ip)
165 if not onos5_isup:
166 main.log.report("ONOS5 didn't start!")
167 onos6_isup = main.ONOSbench.isup(ONOS6_ip)
168 if not onos6_isup:
169 main.log.report("ONOS6 didn't start!")
170 onos7_isup = main.ONOSbench.isup(ONOS7_ip)
171 if not onos7_isup:
172 main.log.report("ONOS7 didn't start!")
173 onos_isup_result = onos1_isup and onos2_isup and onos3_isup\
174 and onos4_isup and onos5_isup and onos6_isup and onos7_isup
175 if onos_isup_result == main.TRUE:
176 break
Jon Hall73cf9cc2014-11-20 22:28:38 -0800177 # TODO: if it becomes an issue, we can retry this step a few times
178
179
180 cli_result1 = main.ONOScli1.start_onos_cli(ONOS1_ip)
181 cli_result2 = main.ONOScli2.start_onos_cli(ONOS2_ip)
182 cli_result3 = main.ONOScli3.start_onos_cli(ONOS3_ip)
183 cli_result4 = main.ONOScli4.start_onos_cli(ONOS4_ip)
184 cli_result5 = main.ONOScli5.start_onos_cli(ONOS5_ip)
185 cli_result6 = main.ONOScli6.start_onos_cli(ONOS6_ip)
186 cli_result7 = main.ONOScli7.start_onos_cli(ONOS7_ip)
187 cli_results = cli_result1 and cli_result2 and cli_result3 and\
188 cli_result4 and cli_result5 and cli_result6 and cli_result7
189
190 main.step("Start Packet Capture MN")
191 main.Mininet2.start_tcpdump(
192 str(main.params['MNtcpdump']['folder'])+str(main.TEST)+"-MN.pcap",
193 intf = main.params['MNtcpdump']['intf'],
194 port = main.params['MNtcpdump']['port'])
195
196
197 case1_result = (clean_install_result and package_result and
198 cell_result and verify_result and onos_install_result and
199 onos_isup_result and cli_results)
200
201 utilities.assert_equals(expect=main.TRUE, actual=case1_result,
202 onpass="Test startup successful",
203 onfail="Test startup NOT successful")
204
205
Jon Hall94fd0472014-12-08 11:52:42 -0800206 if case1_result==main.FALSE:
207 main.cleanup()
208 main.exit()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800209
210 def CASE2(self,main) :
211 '''
212 Assign mastership to controllers
213 '''
214 import time
215 import json
216 import re
217
Jon Hall73cf9cc2014-11-20 22:28:38 -0800218 main.log.report("Assigning switches to controllers")
219 main.case("Assigning Controllers")
220 main.step("Assign switches to controllers")
221
222 for i in range (1,29):
Jon Hall669173b2014-12-17 11:36:30 -0800223 main.Mininet1.assign_sw_controller(sw=str(i),count=num_controllers,
Jon Hall73cf9cc2014-11-20 22:28:38 -0800224 ip1=ONOS1_ip,port1=ONOS1_port,
225 ip2=ONOS2_ip,port2=ONOS2_port,
226 ip3=ONOS3_ip,port3=ONOS3_port,
227 ip4=ONOS4_ip,port4=ONOS4_port,
228 ip5=ONOS5_ip,port5=ONOS5_port,
229 ip6=ONOS6_ip,port6=ONOS6_port,
230 ip7=ONOS7_ip,port7=ONOS7_port)
231
232 mastership_check = main.TRUE
233 for i in range (1,29):
234 response = main.Mininet1.get_sw_controller("s"+str(i))
Jon Hallffb386d2014-11-21 13:43:38 -0800235 try:
236 main.log.info(str(response))
237 except:
238 main.log.info(repr(response))
Jon Hall73cf9cc2014-11-20 22:28:38 -0800239 if re.search("tcp:"+ONOS1_ip,response)\
240 and re.search("tcp:"+ONOS2_ip,response)\
241 and re.search("tcp:"+ONOS3_ip,response)\
242 and re.search("tcp:"+ONOS4_ip,response)\
243 and re.search("tcp:"+ONOS5_ip,response)\
244 and re.search("tcp:"+ONOS6_ip,response)\
245 and re.search("tcp:"+ONOS7_ip,response):
246 mastership_check = mastership_check and main.TRUE
247 else:
248 mastership_check = main.FALSE
249 if mastership_check == main.TRUE:
250 main.log.report("Switch mastership assigned correctly")
251 utilities.assert_equals(expect = main.TRUE,actual=mastership_check,
252 onpass="Switch mastership assigned correctly",
253 onfail="Switches not assigned correctly to controllers")
254
Jon Hall94fd0472014-12-08 11:52:42 -0800255 #Manually assign mastership to the controller we want
256 role_call = main.TRUE
257 role_check = main.TRUE
258
259 device_id = main.ONOScli1.get_device("1000")['id']
260 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS1_ip)
261 if ONOS1_ip in main.ONOScli1.get_role(device_id)['master']:
262 role_check = role_check and main.TRUE
263 else:
264 role_check = role_check and main.FALSE
265
266 device_id = main.ONOScli1.get_device("2800")['id']
267 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS1_ip)
268 if ONOS1_ip in main.ONOScli1.get_role(device_id)['master']:
269 role_check = role_check and main.TRUE
270 else:
271 role_check = role_check and main.FALSE
272
273 device_id = main.ONOScli1.get_device("2000")['id']
274 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS2_ip)
275 if ONOS2_ip in main.ONOScli1.get_role(device_id)['master']:
276 role_check = role_check and main.TRUE
277 else:
278 role_check = role_check and main.FALSE
279
280 device_id = main.ONOScli1.get_device("3000")['id']
281 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS2_ip)
282 if ONOS2_ip in main.ONOScli1.get_role(device_id)['master']:
283 role_check = role_check and main.TRUE
284 else:
285 role_check = role_check and main.FALSE
286
287 device_id = main.ONOScli1.get_device("5000")['id']
288 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS3_ip)
289 if ONOS3_ip in main.ONOScli1.get_role(device_id)['master']:
290 role_check = role_check and main.TRUE
291 else:
292 role_check = role_check and main.FALSE
293
294 device_id = main.ONOScli1.get_device("6000")['id']
295 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS3_ip)
296 if ONOS3_ip in main.ONOScli1.get_role(device_id)['master']:
297 role_check = role_check and main.TRUE
298 else:
299 role_check = role_check and main.FALSE
300
301 device_id = main.ONOScli1.get_device("3004")['id']
302 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS4_ip)
303 if ONOS4_ip in main.ONOScli1.get_role(device_id)['master']:
304 role_check = role_check and main.TRUE
305 else:
306 role_check = role_check and main.FALSE
307
308 device_id = main.ONOScli1.get_device("3008")['id']
309 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS5_ip)
310 if ONOS5_ip in main.ONOScli1.get_role(device_id)['master']:
311 role_check = role_check and main.TRUE
312 else:
313 role_check = role_check and main.FALSE
314
315 device_id = main.ONOScli1.get_device("3009")['id']
316 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS5_ip)
317 if ONOS5_ip in main.ONOScli1.get_role(device_id)['master']:
318 role_check = role_check and main.TRUE
319 else:
320 role_check = role_check and main.FALSE
321
322 device_id = main.ONOScli1.get_device("3010")['id']
323 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS5_ip)
324 if ONOS5_ip in main.ONOScli1.get_role(device_id)['master']:
325 role_check = role_check and main.TRUE
326 else:
327 role_check = role_check and main.FALSE
328
329 device_id = main.ONOScli1.get_device("3011")['id']
330 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS5_ip)
331 if ONOS5_ip in main.ONOScli1.get_role(device_id)['master']:
332 role_check = role_check and main.TRUE
333 else:
334 role_check = role_check and main.FALSE
335
336 device_id = main.ONOScli1.get_device("3012")['id']
337 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS5_ip)
338 if ONOS5_ip in main.ONOScli1.get_role(device_id)['master']:
339 role_check = role_check and main.TRUE
340 else:
341 role_check = role_check and main.FALSE
342
343 device_id = main.ONOScli1.get_device("3013")['id']
344 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS5_ip)
345 if ONOS5_ip in main.ONOScli1.get_role(device_id)['master']:
346 role_check = role_check and main.TRUE
347 else:
348 role_check = role_check and main.FALSE
349
350 device_id = main.ONOScli1.get_device("3014")['id']
351 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS5_ip)
352 if ONOS5_ip in main.ONOScli1.get_role(device_id)['master']:
353 role_check = role_check and main.TRUE
354 else:
355 role_check = role_check and main.FALSE
356
357 device_id = main.ONOScli1.get_device("3015")['id']
358 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS5_ip)
359 if ONOS5_ip in main.ONOScli1.get_role(device_id)['master']:
360 role_check = role_check and main.TRUE
361 else:
362 role_check = role_check and main.FALSE
363
364 device_id = main.ONOScli1.get_device("3016")['id']
365 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS5_ip)
366 if ONOS5_ip in main.ONOScli1.get_role(device_id)['master']:
367 role_check = role_check and main.TRUE
368 else:
369 role_check = role_check and main.FALSE
370
371 device_id = main.ONOScli1.get_device("3017")['id']
372 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS5_ip)
373 if ONOS5_ip in main.ONOScli1.get_role(device_id)['master']:
374 role_check = role_check and main.TRUE
375 else:
376 role_check = role_check and main.FALSE
377
378 device_id = main.ONOScli1.get_device("6007")['id']
379 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS6_ip)
380 if ONOS6_ip in main.ONOScli1.get_role(device_id)['master']:
381 role_check = role_check and main.TRUE
382 else:
383 role_check = role_check and main.FALSE
384
385 device_id = main.ONOScli1.get_device("6018")['id']
386 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS7_ip)
387 if ONOS7_ip in main.ONOScli1.get_role(device_id)['master']:
388 role_check = role_check and main.TRUE
389 else:
390 role_check = role_check and main.FALSE
391
392 device_id = main.ONOScli1.get_device("6019")['id']
393 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS7_ip)
394 if ONOS7_ip in main.ONOScli1.get_role(device_id)['master']:
395 role_check = role_check and main.TRUE
396 else:
397 role_check = role_check and main.FALSE
398
399 device_id = main.ONOScli1.get_device("6020")['id']
400 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS7_ip)
401 if ONOS7_ip in main.ONOScli1.get_role(device_id)['master']:
402 role_check = role_check and main.TRUE
403 else:
404 role_check = role_check and main.FALSE
405
406 device_id = main.ONOScli1.get_device("6021")['id']
407 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS7_ip)
408 if ONOS7_ip in main.ONOScli1.get_role(device_id)['master']:
409 role_check = role_check and main.TRUE
410 else:
411 role_check = role_check and main.FALSE
412
413 device_id = main.ONOScli1.get_device("6022")['id']
414 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS7_ip)
415 if ONOS7_ip in main.ONOScli1.get_role(device_id)['master']:
416 role_check = role_check and main.TRUE
417 else:
418 role_check = role_check and main.FALSE
419
420 device_id = main.ONOScli1.get_device("6023")['id']
421 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS7_ip)
422 if ONOS7_ip in main.ONOScli1.get_role(device_id)['master']:
423 role_check = role_check and main.TRUE
424 else:
425 role_check = role_check and main.FALSE
426
427 device_id = main.ONOScli1.get_device("6024")['id']
428 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS7_ip)
429 if ONOS7_ip in main.ONOScli1.get_role(device_id)['master']:
430 role_check = role_check and main.TRUE
431 else:
432 role_check = role_check and main.FALSE
433
434 device_id = main.ONOScli1.get_device("6025")['id']
435 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS7_ip)
436 if ONOS7_ip in main.ONOScli1.get_role(device_id)['master']:
437 role_check = role_check and main.TRUE
438 else:
439 role_check = role_check and main.FALSE
440
441 device_id = main.ONOScli1.get_device("6026")['id']
442 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS7_ip)
443 if ONOS7_ip in main.ONOScli1.get_role(device_id)['master']:
444 role_check = role_check and main.TRUE
445 else:
446 role_check = role_check and main.FALSE
447
448 device_id = main.ONOScli1.get_device("6027")['id']
449 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS7_ip)
450 if ONOS7_ip in main.ONOScli1.get_role(device_id)['master']:
451 role_check = role_check and main.TRUE
452 else:
453 role_check = role_check and main.FALSE
454
455 utilities.assert_equals(expect = main.TRUE,actual=role_call,
456 onpass="Re-assigned switch mastership to designated controller",
457 onfail="Something wrong with device_role calls")
458
459 utilities.assert_equals(expect = main.TRUE,actual=role_check,
460 onpass="Switches were successfully reassigned to designated controller",
461 onfail="Switches were not successfully reassigned")
462 mastership_check = mastership_check and role_call and role_check
463 utilities.assert_equals(expect = main.TRUE,actual=mastership_check,
464 onpass="Switch mastership correctly assigned",
465 onfail="Error in (re)assigning switch mastership")
Jon Hall73cf9cc2014-11-20 22:28:38 -0800466
467
468 def CASE3(self,main) :
469 """
470 Assign intents
471
472 """
Jon Hall669173b2014-12-17 11:36:30 -0800473 #FIXME: we must reinstall intents until we have a persistant datastore!
Jon Hall73cf9cc2014-11-20 22:28:38 -0800474 import time
475 import json
476 import re
477 main.log.report("Adding host intents")
478 main.case("Adding host Intents")
479
480 main.step("Discovering Hosts( Via pingall for now)")
481 #FIXME: Once we have a host discovery mechanism, use that instead
482
Jon Hall94fd0472014-12-08 11:52:42 -0800483 #install onos-app-fwd
484 main.log.info("Install reactive forwarding app")
485 main.ONOScli1.feature_install("onos-app-fwd")
486 main.ONOScli2.feature_install("onos-app-fwd")
487 main.ONOScli3.feature_install("onos-app-fwd")
488 main.ONOScli4.feature_install("onos-app-fwd")
489 main.ONOScli5.feature_install("onos-app-fwd")
490 main.ONOScli6.feature_install("onos-app-fwd")
491 main.ONOScli7.feature_install("onos-app-fwd")
492
Jon Hall73cf9cc2014-11-20 22:28:38 -0800493 #REACTIVE FWD test
494 ping_result = main.FALSE
495 time1 = time.time()
496 ping_result = main.Mininet1.pingall()
497 time2 = time.time()
498 main.log.info("Time for pingall: %2f seconds" % (time2 - time1))
499
500 #uninstall onos-app-fwd
501 main.log.info("Uninstall reactive forwarding app")
502 main.ONOScli1.feature_uninstall("onos-app-fwd")
503 main.ONOScli2.feature_uninstall("onos-app-fwd")
504 main.ONOScli3.feature_uninstall("onos-app-fwd")
505 main.ONOScli4.feature_uninstall("onos-app-fwd")
506 main.ONOScli5.feature_uninstall("onos-app-fwd")
507 main.ONOScli6.feature_uninstall("onos-app-fwd")
508 main.ONOScli7.feature_uninstall("onos-app-fwd")
Jon Hall669173b2014-12-17 11:36:30 -0800509 #timeout for fwd flows
510 time.sleep(10)
Jon Hall73cf9cc2014-11-20 22:28:38 -0800511
512 main.step("Add host intents")
513 #TODO: move the host numbers to params
514 import json
515 intents_json= json.loads(main.ONOScli1.hosts())
Jon Hall94fd0472014-12-08 11:52:42 -0800516 intent_add_result = True
Jon Hall73cf9cc2014-11-20 22:28:38 -0800517 for i in range(8,18):
518 main.log.info("Adding host intent between h"+str(i)+" and h"+str(i+10))
519 host1 = "00:00:00:00:00:" + str(hex(i)[2:]).zfill(2).upper()
520 host2 = "00:00:00:00:00:" + str(hex(i+10)[2:]).zfill(2).upper()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800521 host1_id = main.ONOScli1.get_host(host1)['id']
522 host2_id = main.ONOScli1.get_host(host2)['id']
Jon Hall669173b2014-12-17 11:36:30 -0800523 #NOTE: get host can return None
524 if host1_id and host2_id:
525 tmp_result = main.ONOScli1.add_host_intent(host1_id, host2_id )
526 else:
527 main.log.error("Error, get_host() failed")
528 tmp_result = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800529 intent_add_result = bool(intent_add_result and tmp_result)
530 utilities.assert_equals(expect=True, actual=intent_add_result,
531 onpass="Switch mastership correctly assigned",
532 onfail="Error in (re)assigning switch mastership")
Jon Hall73cf9cc2014-11-20 22:28:38 -0800533 #TODO Check if intents all exist in datastore
534 #NOTE: Do we need to print this once the test is working?
535 #main.log.info(json.dumps(json.loads(main.ONOScli1.intents(json_format=True)),
536 # sort_keys=True, indent=4, separators=(',', ': ') ) )
537
538 def CASE4(self,main) :
539 """
540 Ping across added host intents
541 """
542 description = " Ping across added host intents"
543 main.log.report(description)
544 main.case(description)
545 Ping_Result = main.TRUE
546 for i in range(8,18):
547 ping = main.Mininet1.pingHost(src="h"+str(i),target="h"+str(i+10))
548 Ping_Result = Ping_Result and ping
549 if ping==main.FALSE:
550 main.log.warn("Ping failed between h"+str(i)+" and h" + str(i+10))
551 elif ping==main.TRUE:
552 main.log.info("Ping test passed!")
553 Ping_Result = main.TRUE
554 if Ping_Result==main.FALSE:
555 main.log.report("Intents have not been installed correctly, pings failed.")
556 if Ping_Result==main.TRUE:
557 main.log.report("Intents have been installed correctly and verified by pings")
558 utilities.assert_equals(expect = main.TRUE,actual=Ping_Result,
559 onpass="Intents have been installed correctly and pings work",
560 onfail ="Intents have not been installed correctly, pings failed." )
561
562 def CASE5(self,main) :
563 '''
564 Reading state of ONOS
565 '''
566 import time
567 import json
568 from subprocess import Popen, PIPE
569 from sts.topology.teston_topology import TestONTopology # assumes that sts is already in you PYTHONPATH
570
571 main.log.report("Setting up and gathering data for current state")
572 main.case("Setting up and gathering data for current state")
573 #The general idea for this test case is to pull the state of (intents,flows, topology,...) from each ONOS node
574 #We can then compare them with eachother and also with past states
575
576 main.step("Get the Mastership of each switch from each controller")
577 global mastership_state
Jon Hall94fd0472014-12-08 11:52:42 -0800578 mastership_state = []
579
580 #Assert that each device has a master
581 ONOS1_master_not_null = main.ONOScli1.roles_not_null()
582 ONOS2_master_not_null = main.ONOScli2.roles_not_null()
583 ONOS3_master_not_null = main.ONOScli3.roles_not_null()
584 ONOS4_master_not_null = main.ONOScli4.roles_not_null()
585 ONOS5_master_not_null = main.ONOScli5.roles_not_null()
586 ONOS6_master_not_null = main.ONOScli6.roles_not_null()
587 ONOS7_master_not_null = main.ONOScli7.roles_not_null()
588 roles_not_null = ONOS1_master_not_null and ONOS2_master_not_null and\
589 ONOS3_master_not_null and ONOS4_master_not_null and\
590 ONOS5_master_not_null and ONOS6_master_not_null and\
591 ONOS7_master_not_null
592 utilities.assert_equals(expect = main.TRUE,actual=roles_not_null,
593 onpass="Each device has a master",
594 onfail="Some devices don't have a master assigned")
595
596
Jon Hall73cf9cc2014-11-20 22:28:38 -0800597 ONOS1_mastership = main.ONOScli1.roles()
598 ONOS2_mastership = main.ONOScli2.roles()
599 ONOS3_mastership = main.ONOScli3.roles()
600 ONOS4_mastership = main.ONOScli4.roles()
601 ONOS5_mastership = main.ONOScli5.roles()
602 ONOS6_mastership = main.ONOScli6.roles()
603 ONOS7_mastership = main.ONOScli7.roles()
604 #print json.dumps(json.loads(ONOS1_mastership), sort_keys=True, indent=4, separators=(',', ': '))
605 if "Error" in ONOS1_mastership or not ONOS1_mastership\
606 or "Error" in ONOS2_mastership or not ONOS2_mastership\
607 or "Error" in ONOS3_mastership or not ONOS3_mastership\
608 or "Error" in ONOS4_mastership or not ONOS4_mastership\
609 or "Error" in ONOS5_mastership or not ONOS5_mastership\
610 or "Error" in ONOS6_mastership or not ONOS6_mastership\
611 or "Error" in ONOS7_mastership or not ONOS7_mastership:
612 main.log.report("Error in getting ONOS roles")
613 main.log.warn("ONOS1 mastership response: " + repr(ONOS1_mastership))
614 main.log.warn("ONOS2 mastership response: " + repr(ONOS2_mastership))
615 main.log.warn("ONOS3 mastership response: " + repr(ONOS3_mastership))
616 main.log.warn("ONOS4 mastership response: " + repr(ONOS4_mastership))
617 main.log.warn("ONOS5 mastership response: " + repr(ONOS5_mastership))
618 main.log.warn("ONOS6 mastership response: " + repr(ONOS6_mastership))
619 main.log.warn("ONOS7 mastership response: " + repr(ONOS7_mastership))
620 consistent_mastership = main.FALSE
621 elif ONOS1_mastership == ONOS2_mastership\
622 and ONOS1_mastership == ONOS3_mastership\
623 and ONOS1_mastership == ONOS4_mastership\
624 and ONOS1_mastership == ONOS5_mastership\
625 and ONOS1_mastership == ONOS6_mastership\
626 and ONOS1_mastership == ONOS7_mastership:
627 mastership_state = ONOS1_mastership
628 consistent_mastership = main.TRUE
629 main.log.report("Switch roles are consistent across all ONOS nodes")
630 else:
631 main.log.warn("ONOS1 roles: ", json.dumps(json.loads(ONOS1_mastership),
632 sort_keys=True, indent=4, separators=(',', ': ')))
633 main.log.warn("ONOS2 roles: ", json.dumps(json.loads(ONOS2_mastership),
634 sort_keys=True, indent=4, separators=(',', ': ')))
635 main.log.warn("ONOS3 roles: ", json.dumps(json.loads(ONOS3_mastership),
636 sort_keys=True, indent=4, separators=(',', ': ')))
637 main.log.warn("ONOS4 roles: ", json.dumps(json.loads(ONOS4_mastership),
638 sort_keys=True, indent=4, separators=(',', ': ')))
639 main.log.warn("ONOS5 roles: ", json.dumps(json.loads(ONOS5_mastership),
640 sort_keys=True, indent=4, separators=(',', ': ')))
641 main.log.warn("ONOS6 roles: ", json.dumps(json.loads(ONOS6_mastership),
642 sort_keys=True, indent=4, separators=(',', ': ')))
643 main.log.warn("ONOS7 roles: ", json.dumps(json.loads(ONOS7_mastership),
644 sort_keys=True, indent=4, separators=(',', ': ')))
645 consistent_mastership = main.FALSE
646 utilities.assert_equals(expect = main.TRUE,actual=consistent_mastership,
647 onpass="Switch roles are consistent across all ONOS nodes",
648 onfail="ONOS nodes have different views of switch roles")
649
650
651 main.step("Get the intents from each controller")
652 global intent_state
Jon Hall94fd0472014-12-08 11:52:42 -0800653 intent_state = []
Jon Hall73cf9cc2014-11-20 22:28:38 -0800654 ONOS1_intents = main.ONOScli1.intents( json_format=True )
655 ONOS2_intents = main.ONOScli2.intents( json_format=True )
656 ONOS3_intents = main.ONOScli3.intents( json_format=True )
657 ONOS4_intents = main.ONOScli4.intents( json_format=True )
658 ONOS5_intents = main.ONOScli5.intents( json_format=True )
659 ONOS6_intents = main.ONOScli6.intents( json_format=True )
660 ONOS7_intents = main.ONOScli7.intents( json_format=True )
661 intent_check = main.FALSE
662 if "Error" in ONOS1_intents or not ONOS1_intents\
663 or "Error" in ONOS2_intents or not ONOS2_intents\
664 or "Error" in ONOS3_intents or not ONOS3_intents\
665 or "Error" in ONOS4_intents or not ONOS4_intents\
666 or "Error" in ONOS5_intents or not ONOS5_intents\
667 or "Error" in ONOS6_intents or not ONOS6_intents\
668 or "Error" in ONOS7_intents or not ONOS7_intents:
669 main.log.report("Error in getting ONOS intents")
670 main.log.warn("ONOS1 intents response: " + repr(ONOS1_intents))
671 main.log.warn("ONOS2 intents response: " + repr(ONOS2_intents))
672 main.log.warn("ONOS3 intents response: " + repr(ONOS3_intents))
673 main.log.warn("ONOS4 intents response: " + repr(ONOS4_intents))
674 main.log.warn("ONOS5 intents response: " + repr(ONOS5_intents))
675 main.log.warn("ONOS6 intents response: " + repr(ONOS6_intents))
676 main.log.warn("ONOS7 intents response: " + repr(ONOS7_intents))
677 elif ONOS1_intents == ONOS2_intents\
678 and ONOS1_intents == ONOS3_intents\
679 and ONOS1_intents == ONOS4_intents\
680 and ONOS1_intents == ONOS5_intents\
681 and ONOS1_intents == ONOS6_intents\
682 and ONOS1_intents == ONOS7_intents:
683 intent_state = ONOS1_intents
684 intent_check = main.TRUE
685 main.log.report("Intents are consistent across all ONOS nodes")
686 else:
687 main.log.warn("ONOS1 intents: ", json.dumps(json.loads(ONOS1_intents),
688 sort_keys=True, indent=4, separators=(',', ': ')))
689 main.log.warn("ONOS2 intents: ", json.dumps(json.loads(ONOS2_intents),
690 sort_keys=True, indent=4, separators=(',', ': ')))
691 main.log.warn("ONOS3 intents: ", json.dumps(json.loads(ONOS3_intents),
692 sort_keys=True, indent=4, separators=(',', ': ')))
693 main.log.warn("ONOS4 intents: ", json.dumps(json.loads(ONOS4_intents),
694 sort_keys=True, indent=4, separators=(',', ': ')))
695 main.log.warn("ONOS5 intents: ", json.dumps(json.loads(ONOS5_intents),
696 sort_keys=True, indent=4, separators=(',', ': ')))
697 main.log.warn("ONOS6 intents: ", json.dumps(json.loads(ONOS6_intents),
698 sort_keys=True, indent=4, separators=(',', ': ')))
699 main.log.warn("ONOS7 intents: ", json.dumps(json.loads(ONOS7_intents),
700 sort_keys=True, indent=4, separators=(',', ': ')))
701 utilities.assert_equals(expect = main.TRUE,actual=intent_check,
702 onpass="Intents are consistent across all ONOS nodes",
703 onfail="ONOS nodes have different views of intents")
704
705
706 main.step("Get the flows from each controller")
707 global flow_state
Jon Hall94fd0472014-12-08 11:52:42 -0800708 flow_state = []
Jon Hall73cf9cc2014-11-20 22:28:38 -0800709 ONOS1_flows = main.ONOScli1.flows( json_format=True )
710 ONOS2_flows = main.ONOScli2.flows( json_format=True )
711 ONOS3_flows = main.ONOScli3.flows( json_format=True )
712 ONOS4_flows = main.ONOScli4.flows( json_format=True )
713 ONOS5_flows = main.ONOScli5.flows( json_format=True )
714 ONOS6_flows = main.ONOScli6.flows( json_format=True )
715 ONOS7_flows = main.ONOScli7.flows( json_format=True )
716 flow_check = main.FALSE
717 if "Error" in ONOS1_flows or not ONOS1_flows\
718 or "Error" in ONOS2_flows or not ONOS2_flows\
719 or "Error" in ONOS3_flows or not ONOS3_flows\
720 or "Error" in ONOS4_flows or not ONOS4_flows\
721 or "Error" in ONOS5_flows or not ONOS5_flows\
722 or "Error" in ONOS6_flows or not ONOS6_flows\
723 or "Error" in ONOS7_flows or not ONOS7_flows:
724 main.log.report("Error in getting ONOS intents")
725 main.log.warn("ONOS1 flows repsponse: "+ ONOS1_flows)
726 main.log.warn("ONOS2 flows repsponse: "+ ONOS2_flows)
727 main.log.warn("ONOS3 flows repsponse: "+ ONOS3_flows)
728 main.log.warn("ONOS4 flows repsponse: "+ ONOS4_flows)
729 main.log.warn("ONOS5 flows repsponse: "+ ONOS5_flows)
730 main.log.warn("ONOS6 flows repsponse: "+ ONOS6_flows)
731 main.log.warn("ONOS7 flows repsponse: "+ ONOS7_flows)
732 elif len(json.loads(ONOS1_flows)) == len(json.loads(ONOS2_flows))\
733 and len(json.loads(ONOS1_flows)) == len(json.loads(ONOS3_flows))\
734 and len(json.loads(ONOS1_flows)) == len(json.loads(ONOS4_flows))\
735 and len(json.loads(ONOS1_flows)) == len(json.loads(ONOS5_flows))\
736 and len(json.loads(ONOS1_flows)) == len(json.loads(ONOS6_flows))\
737 and len(json.loads(ONOS1_flows)) == len(json.loads(ONOS7_flows)):
738 #TODO: Do a better check, maybe compare flows on switches?
739 flow_state = ONOS1_flows
740 flow_check = main.TRUE
741 main.log.report("Flow count is consistent across all ONOS nodes")
742 else:
743 main.log.warn("ONOS1 flows: "+ json.dumps(json.loads(ONOS1_flows),
744 sort_keys=True, indent=4, separators=(',', ': ')))
745 main.log.warn("ONOS2 flows: "+ json.dumps(json.loads(ONOS2_flows),
746 sort_keys=True, indent=4, separators=(',', ': ')))
747 main.log.warn("ONOS3 flows: "+ json.dumps(json.loads(ONOS3_flows),
748 sort_keys=True, indent=4, separators=(',', ': ')))
749 main.log.warn("ONOS4 flows: "+ json.dumps(json.loads(ONOS4_flows),
750 sort_keys=True, indent=4, separators=(',', ': ')))
751 main.log.warn("ONOS5 flows: "+ json.dumps(json.loads(ONOS5_flows),
752 sort_keys=True, indent=4, separators=(',', ': ')))
753 main.log.warn("ONOS6 flows: "+ json.dumps(json.loads(ONOS6_flows),
754 sort_keys=True, indent=4, separators=(',', ': ')))
755 main.log.warn("ONOS7 flows: "+ json.dumps(json.loads(ONOS7_flows),
756 sort_keys=True, indent=4, separators=(',', ': ')))
757 utilities.assert_equals(expect = main.TRUE,actual=flow_check,
758 onpass="The flow count is consistent across all ONOS nodes",
759 onfail="ONOS nodes have different flow counts")
760
761
762 main.step("Get the OF Table entries")
763 global flows
764 flows=[]
765 for i in range(1,29):
Jon Hall94fd0472014-12-08 11:52:42 -0800766 flows.append(main.Mininet2.get_flowTable(1.3, "s"+str(i)))
Jon Hall73cf9cc2014-11-20 22:28:38 -0800767
768 #TODO: Compare switch flow tables with ONOS flow tables
769
770 main.step("Start continuous pings")
771 main.Mininet2.pingLong(src=main.params['PING']['source1'],
772 target=main.params['PING']['target1'],pingTime=500)
773 main.Mininet2.pingLong(src=main.params['PING']['source2'],
774 target=main.params['PING']['target2'],pingTime=500)
775 main.Mininet2.pingLong(src=main.params['PING']['source3'],
776 target=main.params['PING']['target3'],pingTime=500)
777 main.Mininet2.pingLong(src=main.params['PING']['source4'],
778 target=main.params['PING']['target4'],pingTime=500)
779 main.Mininet2.pingLong(src=main.params['PING']['source5'],
780 target=main.params['PING']['target5'],pingTime=500)
781 main.Mininet2.pingLong(src=main.params['PING']['source6'],
782 target=main.params['PING']['target6'],pingTime=500)
783 main.Mininet2.pingLong(src=main.params['PING']['source7'],
784 target=main.params['PING']['target7'],pingTime=500)
785 main.Mininet2.pingLong(src=main.params['PING']['source8'],
786 target=main.params['PING']['target8'],pingTime=500)
787 main.Mininet2.pingLong(src=main.params['PING']['source9'],
788 target=main.params['PING']['target9'],pingTime=500)
789 main.Mininet2.pingLong(src=main.params['PING']['source10'],
790 target=main.params['PING']['target10'],pingTime=500)
791
792 main.step("Create TestONTopology object")
793 ctrls = []
794 count = 1
795 while True:
796 temp = ()
797 if ('ip' + str(count)) in main.params['CTRL']:
798 temp = temp + (getattr(main,('ONOS' + str(count))),)
799 temp = temp + ("ONOS"+str(count),)
800 temp = temp + (main.params['CTRL']['ip'+str(count)],)
801 temp = temp + (eval(main.params['CTRL']['port'+str(count)]),)
802 ctrls.append(temp)
803 count = count + 1
804 else:
805 break
806 MNTopo = TestONTopology(main.Mininet1, ctrls) # can also add Intent API info for intent operations
807
808 main.step("Collecting topology information from ONOS")
809 devices = []
810 devices.append( main.ONOScli1.devices() )
811 devices.append( main.ONOScli2.devices() )
812 devices.append( main.ONOScli3.devices() )
813 devices.append( main.ONOScli4.devices() )
814 devices.append( main.ONOScli5.devices() )
815 devices.append( main.ONOScli6.devices() )
816 devices.append( main.ONOScli7.devices() )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800817 hosts = []
818 hosts.append( main.ONOScli1.hosts() )
819 hosts.append( main.ONOScli2.hosts() )
820 hosts.append( main.ONOScli3.hosts() )
821 hosts.append( main.ONOScli4.hosts() )
822 hosts.append( main.ONOScli5.hosts() )
823 hosts.append( main.ONOScli6.hosts() )
824 hosts.append( main.ONOScli7.hosts() )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800825 ports = []
826 ports.append( main.ONOScli1.ports() )
827 ports.append( main.ONOScli2.ports() )
828 ports.append( main.ONOScli3.ports() )
829 ports.append( main.ONOScli4.ports() )
830 ports.append( main.ONOScli5.ports() )
831 ports.append( main.ONOScli6.ports() )
832 ports.append( main.ONOScli7.ports() )
833 links = []
834 links.append( main.ONOScli1.links() )
835 links.append( main.ONOScli2.links() )
836 links.append( main.ONOScli3.links() )
837 links.append( main.ONOScli4.links() )
838 links.append( main.ONOScli5.links() )
839 links.append( main.ONOScli6.links() )
840 links.append( main.ONOScli7.links() )
Jon Hall94fd0472014-12-08 11:52:42 -0800841 clusters = []
842 clusters.append( main.ONOScli1.clusters() )
843 clusters.append( main.ONOScli2.clusters() )
844 clusters.append( main.ONOScli3.clusters() )
845 clusters.append( main.ONOScli4.clusters() )
846 clusters.append( main.ONOScli5.clusters() )
847 clusters.append( main.ONOScli6.clusters() )
848 clusters.append( main.ONOScli7.clusters() )
849 paths = []
850 temp_topo = main.ONOSbench.get_topology( main.ONOScli1.topology() )
851 paths.append( temp_topo.get('paths', False) )
852 temp_topo = main.ONOSbench.get_topology( main.ONOScli2.topology() )
853 paths.append( temp_topo.get('paths', False) )
854 temp_topo = main.ONOSbench.get_topology( main.ONOScli3.topology() )
855 paths.append( temp_topo.get('paths', False) )
856 temp_topo = main.ONOSbench.get_topology( main.ONOScli4.topology() )
857 paths.append( temp_topo.get('paths', False) )
858 temp_topo = main.ONOSbench.get_topology( main.ONOScli5.topology() )
859 paths.append( temp_topo.get('paths', False) )
860 temp_topo = main.ONOSbench.get_topology( main.ONOScli6.topology() )
861 paths.append( temp_topo.get('paths', False) )
862 temp_topo = main.ONOSbench.get_topology( main.ONOScli7.topology() )
863 paths.append( temp_topo.get('paths', False) )
864
865 #Compare json objects for hosts, dataplane clusters and paths
866
867 #hosts
868 consistent_hosts_result = main.TRUE
869 for controller in range( len( hosts ) ):
870 if not "Error" in hosts[controller]:
871 if hosts[controller] == hosts[0]:
872 continue
873 else:#hosts not consistent
874 main.log.report("hosts from ONOS" + str(controller + 1) + " is inconsistent with ONOS1")
875 main.log.warn( repr( hosts[controller] ) )
876 consistent_hosts_result = main.FALSE
877
878 else:
879 main.log.report("Error in getting ONOS hosts from ONOS" + str(controller + 1) )
880 consistent_hosts_result = main.FALSE
881 main.log.warn("ONOS" + str(controller + 1) + " hosts response: " + repr(hosts[controller]) )
882 utilities.assert_equals(expect = main.TRUE,actual=consistent_hosts_result,
883 onpass="Hosts view is consistent across all ONOS nodes",
884 onfail="ONOS nodes have different views of hosts")
885
886 #Strongly connected clusters of devices
887 consistent_clusters_result = main.TRUE
888 for controller in range( len( clusters ) ):
889 if not "Error" in clusters[controller]:
890 if clusters[controller] == clusters[0]:
891 continue
892 else:#clusters not consistent
893 main.log.report("clusters from ONOS" + str(controller + 1) + " is inconsistent with ONOS1")
894 consistent_clusters_result = main.FALSE
895
896 else:
897 main.log.report("Error in getting dataplane clusters from ONOS" + str(controller + 1) )
898 consistent_clusters_result = main.FALSE
899 main.log.warn("ONOS" + str(controller + 1) + " clusters response: " + repr(clusters[controller]) )
900 utilities.assert_equals(expect = main.TRUE,actual=consistent_clusters_result,
901 onpass="Clusters view is consistent across all ONOS nodes",
902 onfail="ONOS nodes have different views of clusters")
903 num_clusters = len(json.loads(clusters[0])) #there should always only be one cluster
904 utilities.assert_equals(expect = 1, actual = num_clusters,
905 onpass="ONOS shows 1 SCC",
906 onfail="ONOS shows "+str(num_clusters) +" SCCs")
907
908
909 #paths
910 consistent_paths_result = main.TRUE
911 for controller in range( len( paths ) ):
912 if not "Error" in paths[controller]:
913 if paths[controller] == paths[0]:
914 continue
915 else:#paths not consistent
916 main.log.report("paths from ONOS" + str(controller + 1) + " is inconsistent with ONOS1")
917 consistent_paths_result = main.FALSE
918
919 else:
920 main.log.report("Error in getting paths from ONOS" + str(controller + 1) )
921 consistent_paths_result = main.FALSE
922 main.log.warn("ONOS" + str(controller + 1) + " paths response: " + repr(paths[controller]) )
923 utilities.assert_equals(expect = main.TRUE,actual=consistent_paths_result,
924 onpass="Paths count is consistent across all ONOS nodes",
925 onfail="ONOS nodes have different counts of paths")
Jon Hall73cf9cc2014-11-20 22:28:38 -0800926
927
928 main.step("Comparing ONOS topology to MN")
929 devices_results = main.TRUE
930 ports_results = main.TRUE
931 links_results = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -0800932 for controller in range(num_controllers):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800933 if devices[controller] or not "Error" in devices[controller]:
934 current_devices_result = main.Mininet1.compare_switches(MNTopo, json.loads(devices[controller]))
935 else:
936 current_devices_result = main.FALSE
937 utilities.assert_equals(expect=main.TRUE, actual=current_devices_result,
938 onpass="ONOS"+str(int(controller+1))+" Switches view is correct",
939 onfail="ONOS"+str(int(controller+1))+" Switches view is incorrect")
940
941 if ports[controller] or not "Error" in ports[controller]:
942 current_ports_result = main.Mininet1.compare_ports(MNTopo, json.loads(ports[controller]))
943 else:
944 current_ports_result = main.FALSE
945 utilities.assert_equals(expect=main.TRUE, actual=current_ports_result,
946 onpass="ONOS"+str(int(controller+1))+" ports view is correct",
947 onfail="ONOS"+str(int(controller+1))+" ports view is incorrect")
948
949 if links[controller] or not "Error" in links[controller]:
950 current_links_result = main.Mininet1.compare_links(MNTopo, json.loads(links[controller]))
951 else:
952 current_links_result = main.FALSE
953 utilities.assert_equals(expect=main.TRUE, actual=current_links_result,
954 onpass="ONOS"+str(int(controller+1))+" links view is correct",
955 onfail="ONOS"+str(int(controller+1))+" links view is incorrect")
956
957 devices_results = devices_results and current_devices_result
958 ports_results = ports_results and current_ports_result
959 links_results = links_results and current_links_result
960
Jon Hall94fd0472014-12-08 11:52:42 -0800961 topo_result = devices_results and ports_results and links_results\
962 and consistent_hosts_result and consistent_clusters_result\
963 and consistent_paths_result
Jon Hall73cf9cc2014-11-20 22:28:38 -0800964 utilities.assert_equals(expect=main.TRUE, actual=topo_result,
965 onpass="Topology Check Test successful",
966 onfail="Topology Check Test NOT successful")
967
968 final_assert = main.TRUE
969 final_assert = final_assert and topo_result and flow_check \
Jon Hall94fd0472014-12-08 11:52:42 -0800970 and intent_check and consistent_mastership and roles_not_null
Jon Hall73cf9cc2014-11-20 22:28:38 -0800971 utilities.assert_equals(expect=main.TRUE, actual=final_assert,
972 onpass="State check successful",
973 onfail="State check NOT successful")
974
975
976 def CASE6(self,main) :
977 '''
978 The Failure case.
979 '''
980 main.log.report("Restart entire ONOS cluster")
981 main.log.case("Restart entire ONOS cluster")
982 main.ONOSbench.onos_kill(ONOS1_ip)
983 main.ONOSbench.onos_kill(ONOS2_ip)
984 main.ONOSbench.onos_kill(ONOS3_ip)
985 main.ONOSbench.onos_kill(ONOS4_ip)
986 main.ONOSbench.onos_kill(ONOS5_ip)
987 main.ONOSbench.onos_kill(ONOS6_ip)
988 main.ONOSbench.onos_kill(ONOS7_ip)
989
990 main.step("Checking if ONOS is up yet")
Jon Hallffb386d2014-11-21 13:43:38 -0800991 count = 0
992 onos_isup_result = main.FALSE
993 while onos_isup_result == main.FALSE and count < 10:
994 onos1_isup = main.ONOSbench.isup(ONOS1_ip)
995 onos2_isup = main.ONOSbench.isup(ONOS2_ip)
996 onos3_isup = main.ONOSbench.isup(ONOS3_ip)
997 onos4_isup = main.ONOSbench.isup(ONOS4_ip)
998 onos5_isup = main.ONOSbench.isup(ONOS5_ip)
999 onos6_isup = main.ONOSbench.isup(ONOS6_ip)
1000 onos7_isup = main.ONOSbench.isup(ONOS7_ip)
1001 onos_isup_result = onos1_isup and onos2_isup and onos3_isup\
1002 and onos4_isup and onos5_isup and onos6_isup and onos7_isup
1003 count = count + 1
Jon Hall73cf9cc2014-11-20 22:28:38 -08001004 # TODO: if it becomes an issue, we can retry this step a few times
1005
1006
1007 cli_result1 = main.ONOScli1.start_onos_cli(ONOS1_ip)
1008 cli_result2 = main.ONOScli2.start_onos_cli(ONOS2_ip)
1009 cli_result3 = main.ONOScli3.start_onos_cli(ONOS3_ip)
1010 cli_result4 = main.ONOScli4.start_onos_cli(ONOS4_ip)
1011 cli_result5 = main.ONOScli5.start_onos_cli(ONOS5_ip)
1012 cli_result6 = main.ONOScli6.start_onos_cli(ONOS6_ip)
1013 cli_result7 = main.ONOScli7.start_onos_cli(ONOS7_ip)
1014 cli_results = cli_result1 and cli_result2 and cli_result3\
1015 and cli_result4 and cli_result5 and cli_result6\
1016 and cli_result7
1017
1018 case_results = main.TRUE and onos_isup_result and cli_results
1019 utilities.assert_equals(expect=main.TRUE, actual=case_results,
1020 onpass="ONOS restart successful",
1021 onfail="ONOS restart NOT successful")
1022
1023
1024 def CASE7(self,main) :
1025 '''
1026 Check state after ONOS failure
1027 '''
1028 import os
1029 import json
1030 main.case("Running ONOS Constant State Tests")
1031
Jon Hall94fd0472014-12-08 11:52:42 -08001032 #Assert that each device has a master
1033 ONOS1_master_not_null = main.ONOScli1.roles_not_null()
1034 ONOS2_master_not_null = main.ONOScli2.roles_not_null()
1035 ONOS3_master_not_null = main.ONOScli3.roles_not_null()
1036 ONOS4_master_not_null = main.ONOScli4.roles_not_null()
1037 ONOS5_master_not_null = main.ONOScli5.roles_not_null()
1038 ONOS6_master_not_null = main.ONOScli6.roles_not_null()
1039 ONOS7_master_not_null = main.ONOScli7.roles_not_null()
1040 roles_not_null = ONOS1_master_not_null and ONOS2_master_not_null and\
1041 ONOS3_master_not_null and ONOS4_master_not_null and\
1042 ONOS5_master_not_null and ONOS6_master_not_null and\
1043 ONOS7_master_not_null
1044 utilities.assert_equals(expect = main.TRUE,actual=roles_not_null,
1045 onpass="Each device has a master",
1046 onfail="Some devices don't have a master assigned")
1047
1048
1049
Jon Hall73cf9cc2014-11-20 22:28:38 -08001050 main.step("Check if switch roles are consistent across all nodes")
1051 ONOS1_mastership = main.ONOScli1.roles()
1052 ONOS2_mastership = main.ONOScli2.roles()
1053 ONOS3_mastership = main.ONOScli3.roles()
1054 ONOS4_mastership = main.ONOScli4.roles()
1055 ONOS5_mastership = main.ONOScli5.roles()
1056 ONOS6_mastership = main.ONOScli6.roles()
1057 ONOS7_mastership = main.ONOScli7.roles()
1058 #print json.dumps(json.loads(ONOS1_mastership), sort_keys=True, indent=4, separators=(',', ': '))
1059 if "Error" in ONOS1_mastership or not ONOS1_mastership\
1060 or "Error" in ONOS2_mastership or not ONOS2_mastership\
1061 or "Error" in ONOS3_mastership or not ONOS3_mastership\
1062 or "Error" in ONOS4_mastership or not ONOS4_mastership\
1063 or "Error" in ONOS5_mastership or not ONOS5_mastership\
1064 or "Error" in ONOS6_mastership or not ONOS6_mastership\
1065 or "Error" in ONOS7_mastership or not ONOS7_mastership:
1066 main.log.error("Error in getting ONOS mastership")
1067 main.log.warn("ONOS1 mastership response: " + repr(ONOS1_mastership))
1068 main.log.warn("ONOS2 mastership response: " + repr(ONOS2_mastership))
1069 main.log.warn("ONOS3 mastership response: " + repr(ONOS3_mastership))
1070 main.log.warn("ONOS4 mastership response: " + repr(ONOS4_mastership))
1071 main.log.warn("ONOS5 mastership response: " + repr(ONOS5_mastership))
1072 main.log.warn("ONOS6 mastership response: " + repr(ONOS6_mastership))
1073 main.log.warn("ONOS7 mastership response: " + repr(ONOS7_mastership))
1074 consistent_mastership = main.FALSE
1075 elif ONOS1_mastership == ONOS2_mastership\
1076 and ONOS1_mastership == ONOS3_mastership\
1077 and ONOS1_mastership == ONOS4_mastership\
1078 and ONOS1_mastership == ONOS5_mastership\
1079 and ONOS1_mastership == ONOS6_mastership\
1080 and ONOS1_mastership == ONOS7_mastership:
Jon Hall73cf9cc2014-11-20 22:28:38 -08001081 consistent_mastership = main.TRUE
1082 main.log.report("Switch roles are consistent across all ONOS nodes")
1083 else:
1084 main.log.warn("ONOS1 roles: ", json.dumps(json.loads(ONOS1_mastership),
1085 sort_keys=True, indent=4, separators=(',', ': ')))
1086 main.log.warn("ONOS2 roles: ", json.dumps(json.loads(ONOS2_mastership),
1087 sort_keys=True, indent=4, separators=(',', ': ')))
1088 main.log.warn("ONOS3 roles: ", json.dumps(json.loads(ONOS3_mastership),
1089 sort_keys=True, indent=4, separators=(',', ': ')))
1090 main.log.warn("ONOS4 roles: ", json.dumps(json.loads(ONOS4_mastership),
1091 sort_keys=True, indent=4, separators=(',', ': ')))
1092 main.log.warn("ONOS5 roles: ", json.dumps(json.loads(ONOS5_mastership),
1093 sort_keys=True, indent=4, separators=(',', ': ')))
1094 main.log.warn("ONOS6 roles: ", json.dumps(json.loads(ONOS6_mastership),
1095 sort_keys=True, indent=4, separators=(',', ': ')))
1096 main.log.warn("ONOS7 roles: ", json.dumps(json.loads(ONOS7_mastership),
1097 sort_keys=True, indent=4, separators=(',', ': ')))
1098 consistent_mastership = main.FALSE
1099 utilities.assert_equals(expect = main.TRUE,actual=consistent_mastership,
1100 onpass="Switch roles are consistent across all ONOS nodes",
1101 onfail="ONOS nodes have different views of switch roles")
1102
1103
1104 description2 = "Compare switch roles from before failure"
1105 main.step(description2)
1106
1107 current_json = json.loads(ONOS1_mastership)
1108 old_json = json.loads(mastership_state)
1109 mastership_check = main.TRUE
1110 for i in range(1,29):
1111 switchDPID = str(main.Mininet1.getSwitchDPID(switch="s"+str(i)))
1112
1113 current = [switch['master'] for switch in current_json if switchDPID in switch['id']]
1114 old = [switch['master'] for switch in old_json if switchDPID in switch['id']]
1115 if current == old:
1116 mastership_check = mastership_check and main.TRUE
1117 else:
1118 main.log.warn("Mastership of switch %s changed" % switchDPID)
1119 mastership_check = main.FALSE
1120 if mastership_check == main.TRUE:
1121 main.log.report("Mastership of Switches was not changed")
1122 utilities.assert_equals(expect=main.TRUE,actual=mastership_check,
1123 onpass="Mastership of Switches was not changed",
1124 onfail="Mastership of some switches changed")
1125 #NOTE: we expect mastership to change on controller failure
Jon Hall669173b2014-12-17 11:36:30 -08001126 mastership_check = consistent_mastership
Jon Hall73cf9cc2014-11-20 22:28:38 -08001127
1128
1129
1130 main.step("Get the intents and compare across all nodes")
1131 ONOS1_intents = main.ONOScli1.intents( json_format=True )
1132 ONOS2_intents = main.ONOScli2.intents( json_format=True )
1133 ONOS3_intents = main.ONOScli3.intents( json_format=True )
1134 ONOS4_intents = main.ONOScli4.intents( json_format=True )
1135 ONOS5_intents = main.ONOScli5.intents( json_format=True )
1136 ONOS6_intents = main.ONOScli6.intents( json_format=True )
1137 ONOS7_intents = main.ONOScli7.intents( json_format=True )
1138 intent_check = main.FALSE
1139 if "Error" in ONOS1_intents or not ONOS1_intents\
1140 or "Error" in ONOS2_intents or not ONOS2_intents\
1141 or "Error" in ONOS3_intents or not ONOS3_intents\
1142 or "Error" in ONOS4_intents or not ONOS4_intents\
1143 or "Error" in ONOS5_intents or not ONOS5_intents\
1144 or "Error" in ONOS6_intents or not ONOS6_intents\
1145 or "Error" in ONOS7_intents or not ONOS7_intents:
1146 main.log.report("Error in getting ONOS intents")
1147 main.log.warn("ONOS1 intents response: " + repr(ONOS1_intents))
1148 main.log.warn("ONOS2 intents response: " + repr(ONOS2_intents))
1149 main.log.warn("ONOS3 intents response: " + repr(ONOS3_intents))
1150 main.log.warn("ONOS4 intents response: " + repr(ONOS4_intents))
1151 main.log.warn("ONOS5 intents response: " + repr(ONOS5_intents))
1152 main.log.warn("ONOS6 intents response: " + repr(ONOS6_intents))
1153 main.log.warn("ONOS7 intents response: " + repr(ONOS7_intents))
1154 elif ONOS1_intents == ONOS2_intents\
1155 and ONOS1_intents == ONOS3_intents\
1156 and ONOS1_intents == ONOS4_intents\
1157 and ONOS1_intents == ONOS5_intents\
1158 and ONOS1_intents == ONOS6_intents\
1159 and ONOS1_intents == ONOS7_intents:
1160 intent_check = main.TRUE
1161 main.log.report("Intents are consistent across all ONOS nodes")
1162 else:
Jon Hall669173b2014-12-17 11:36:30 -08001163 main.log.warn("ONOS1 intents: ")
Jon Hall94fd0472014-12-08 11:52:42 -08001164 print json.dumps(json.loads(ONOS1_intents),
1165 sort_keys=True, indent=4, separators=(',', ': '))
1166 main.log.warn("ONOS2 intents: ")
1167 print json.dumps(json.loads(ONOS2_intents),
1168 sort_keys=True, indent=4, separators=(',', ': '))
1169 main.log.warn("ONOS3 intents: ")
1170 print json.dumps(json.loads(ONOS3_intents),
1171 sort_keys=True, indent=4, separators=(',', ': '))
1172 main.log.warn("ONOS4 intents: ")
1173 print json.dumps(json.loads(ONOS4_intents),
1174 sort_keys=True, indent=4, separators=(',', ': '))
1175 main.log.warn("ONOS5 intents: ")
1176 print json.dumps(json.loads(ONOS5_intents),
1177 sort_keys=True, indent=4, separators=(',', ': '))
1178 main.log.warn("ONOS6 intents: ")
1179 print json.dumps(json.loads(ONOS6_intents),
1180 sort_keys=True, indent=4, separators=(',', ': '))
1181 main.log.warn("ONOS7 intents: ")
1182 print json.dumps(json.loads(ONOS7_intents),
1183 sort_keys=True, indent=4, separators=(',', ': '))
Jon Hall73cf9cc2014-11-20 22:28:38 -08001184 utilities.assert_equals(expect = main.TRUE,actual=intent_check,
1185 onpass="Intents are consistent across all ONOS nodes",
1186 onfail="ONOS nodes have different views of intents")
1187
Jon Hall669173b2014-12-17 11:36:30 -08001188 #NOTE: Hazelcast has no durability, so intents are lost across system restarts
Jon Hall94fd0472014-12-08 11:52:42 -08001189 '''
Jon Hall73cf9cc2014-11-20 22:28:38 -08001190 main.step("Compare current intents with intents before the failure")
Jon Hall94fd0472014-12-08 11:52:42 -08001191 #NOTE: this requires case 5 to pass for intent_state to be set.
1192 # maybe we should stop the test if that fails?
Jon Hall73cf9cc2014-11-20 22:28:38 -08001193 if intent_state == ONOS1_intents:
1194 same_intents = main.TRUE
1195 main.log.report("Intents are consistent with before failure")
1196 #TODO: possibly the states have changed? we may need to figure out what the aceptable states are
1197 else:
Jon Hall669173b2014-12-17 11:36:30 -08001198 try:
1199 main.log.warn("ONOS1 intents: ")
1200 print json.dumps(json.loads(ONOS1_intents),
1201 sort_keys=True, indent=4, separators=(',', ': '))
1202 except:
1203 pass
Jon Hall73cf9cc2014-11-20 22:28:38 -08001204 same_intents = main.FALSE
1205 utilities.assert_equals(expect = main.TRUE,actual=same_intents,
1206 onpass="Intents are consistent with before failure",
1207 onfail="The Intents changed during failure")
1208 intent_check = intent_check and same_intents
Jon Hall94fd0472014-12-08 11:52:42 -08001209 '''
Jon Hall73cf9cc2014-11-20 22:28:38 -08001210
1211
1212
1213 main.step("Get the OF Table entries and compare to before component failure")
1214 Flow_Tables = main.TRUE
1215 flows2=[]
1216 for i in range(28):
1217 main.log.info("Checking flow table on s" + str(i+1))
Jon Hall94fd0472014-12-08 11:52:42 -08001218 tmp_flows = main.Mininet2.get_flowTable(1.3, "s"+str(i+1))
Jon Hall73cf9cc2014-11-20 22:28:38 -08001219 flows2.append(tmp_flows)
Jon Hall94fd0472014-12-08 11:52:42 -08001220 temp_result = main.Mininet2.flow_comp(flow1=flows[i],flow2=tmp_flows)
1221 Flow_Tables = Flow_Tables and temp_result
Jon Hall73cf9cc2014-11-20 22:28:38 -08001222 if Flow_Tables == main.FALSE:
1223 main.log.info("Differences in flow table for switch: "+str(i+1))
Jon Hall73cf9cc2014-11-20 22:28:38 -08001224 if Flow_Tables == main.TRUE:
1225 main.log.report("No changes were found in the flow tables")
1226 utilities.assert_equals(expect=main.TRUE,actual=Flow_Tables,
1227 onpass="No changes were found in the flow tables",
1228 onfail="Changes were found in the flow tables")
1229
1230 main.step("Check the continuous pings to ensure that no packets were dropped during component failure")
1231 #FIXME: This check is always failing. Investigate cause
1232 #NOTE: this may be something to do with file permsissions
1233 # or slight change in format
1234 main.Mininet2.pingKill(main.params['TESTONUSER'], main.params['TESTONIP'])
1235 Loss_In_Pings = main.FALSE
1236 #NOTE: checkForLoss returns main.FALSE with 0% packet loss
1237 for i in range(8,18):
1238 main.log.info("Checking for a loss in pings along flow from s" + str(i))
Jon Hall94fd0472014-12-08 11:52:42 -08001239 Loss_In_Pings = main.Mininet2.checkForLoss("/tmp/ping.h"+str(i)) or Loss_In_Pings
Jon Hall73cf9cc2014-11-20 22:28:38 -08001240 if Loss_In_Pings == main.TRUE:
1241 main.log.info("Loss in ping detected")
1242 elif Loss_In_Pings == main.ERROR:
1243 main.log.info("There are multiple mininet process running")
1244 elif Loss_In_Pings == main.FALSE:
1245 main.log.info("No Loss in the pings")
1246 main.log.report("No loss of dataplane connectivity")
1247 utilities.assert_equals(expect=main.FALSE,actual=Loss_In_Pings,
1248 onpass="No Loss of connectivity",
1249 onfail="Loss of dataplane connectivity detected")
Jon Hall94fd0472014-12-08 11:52:42 -08001250 #NOTE: Since intents are not persisted with Hazelcast, we expect this
1251 Loss_In_Pings = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001252
1253
Jon Hall669173b2014-12-17 11:36:30 -08001254 #Test of LeadershipElection
1255 leader_list = []
1256 leader_result = main.TRUE
1257 for controller in range(1,num_controllers+1):
1258 node = getattr( main, ( 'ONOScli' + str( controller ) ) )#loop through ONOScli handlers
1259 leaderN = node.election_test_leader()
1260 leader_list.append(leaderN)
1261 if leaderN == main.FALSE:
1262 #error in response
1263 main.log.report("Something is wrong with election_test_leader function, check the error logs")
1264 leader_result = main.FALSE
1265 elif leaderN == None:
1266 main.log.report("ONOS"+str(controller) + " shows no leader for the election-app was elected after the old one died")
1267 leader_result = main.FALSE
1268 if len( set( leader_list ) ) != 1:
1269 leader_result = main.FALSE
1270 main.log.error("Inconsistent view of leader for the election test app")
1271 #TODO: print the list
1272 if leader_result:
1273 main.log.report("Leadership election tests passed(consistent view of leader across listeners and a new leader was re-elected after restart)")
1274 utilities.assert_equals(expect=main.TRUE, actual=leader_result,
1275 onpass="Leadership election passed",
1276 onfail="Something went wrong with Leadership election")
1277
1278
1279 result = mastership_check and intent_check and Flow_Tables and (not Loss_In_Pings) and roles_not_null\
1280 and leader_result
Jon Hall73cf9cc2014-11-20 22:28:38 -08001281 result = int(result)
1282 if result == main.TRUE:
1283 main.log.report("Constant State Tests Passed")
1284 utilities.assert_equals(expect=main.TRUE,actual=result,
1285 onpass="Constant State Tests Passed",
1286 onfail="Constant state tests failed")
1287
1288 def CASE8 (self,main):
1289 '''
1290 Compare topo
1291 '''
1292 import sys
1293 sys.path.append("/home/admin/sts") # Trying to remove some dependancies, #FIXME add this path to params
1294 from sts.topology.teston_topology import TestONTopology # assumes that sts is already in you PYTHONPATH
1295 import json
1296 import time
1297
1298 description ="Compare ONOS Topology view to Mininet topology"
1299 main.case(description)
1300 main.log.report(description)
1301 main.step("Create TestONTopology object")
1302 ctrls = []
1303 count = 1
1304 while True:
1305 temp = ()
1306 if ('ip' + str(count)) in main.params['CTRL']:
1307 temp = temp + (getattr(main,('ONOS' + str(count))),)
1308 temp = temp + ("ONOS"+str(count),)
1309 temp = temp + (main.params['CTRL']['ip'+str(count)],)
1310 temp = temp + (eval(main.params['CTRL']['port'+str(count)]),)
1311 ctrls.append(temp)
1312 count = count + 1
1313 else:
1314 break
1315 MNTopo = TestONTopology(main.Mininet1, ctrls) # can also add Intent API info for intent operations
1316
Jon Hall73cf9cc2014-11-20 22:28:38 -08001317 main.step("Comparing ONOS topology to MN")
1318 devices_results = main.TRUE
1319 ports_results = main.TRUE
1320 links_results = main.TRUE
1321 topo_result = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001322 elapsed = 0
Jon Hallffb386d2014-11-21 13:43:38 -08001323 count = 0
Jon Hall94fd0472014-12-08 11:52:42 -08001324 main.step("Collecting topology information from ONOS")
1325 start_time = time.time()
1326 while topo_result == main.FALSE and elapsed < 60:
Jon Hallffb386d2014-11-21 13:43:38 -08001327 count = count + 1
Jon Hall94fd0472014-12-08 11:52:42 -08001328 if count > 1:
1329 MNTopo = TestONTopology(main.Mininet1, ctrls) # can also add Intent API info for intent operations
1330 cli_start = time.time()
1331 devices = []
1332 devices.append( main.ONOScli1.devices() )
1333 devices.append( main.ONOScli2.devices() )
1334 devices.append( main.ONOScli3.devices() )
1335 devices.append( main.ONOScli4.devices() )
1336 devices.append( main.ONOScli5.devices() )
1337 devices.append( main.ONOScli6.devices() )
1338 devices.append( main.ONOScli7.devices() )
1339 hosts = []
1340 hosts.append( main.ONOScli1.hosts() )
1341 hosts.append( main.ONOScli2.hosts() )
1342 hosts.append( main.ONOScli3.hosts() )
1343 hosts.append( main.ONOScli4.hosts() )
1344 hosts.append( main.ONOScli5.hosts() )
1345 hosts.append( main.ONOScli6.hosts() )
1346 hosts.append( main.ONOScli7.hosts() )
1347 ports = []
1348 ports.append( main.ONOScli1.ports() )
1349 ports.append( main.ONOScli2.ports() )
1350 ports.append( main.ONOScli3.ports() )
1351 ports.append( main.ONOScli4.ports() )
1352 ports.append( main.ONOScli5.ports() )
1353 ports.append( main.ONOScli6.ports() )
1354 ports.append( main.ONOScli7.ports() )
1355 links = []
1356 links.append( main.ONOScli1.links() )
1357 links.append( main.ONOScli2.links() )
1358 links.append( main.ONOScli3.links() )
1359 links.append( main.ONOScli4.links() )
1360 links.append( main.ONOScli5.links() )
1361 links.append( main.ONOScli6.links() )
1362 links.append( main.ONOScli7.links() )
1363 clusters = []
1364 clusters.append( main.ONOScli1.clusters() )
1365 clusters.append( main.ONOScli2.clusters() )
1366 clusters.append( main.ONOScli3.clusters() )
1367 clusters.append( main.ONOScli4.clusters() )
1368 clusters.append( main.ONOScli5.clusters() )
1369 clusters.append( main.ONOScli6.clusters() )
1370 clusters.append( main.ONOScli7.clusters() )
1371 paths = []
1372 temp_topo = main.ONOSbench.get_topology( main.ONOScli1.topology() )
1373 paths.append( temp_topo.get('paths', False) )
1374 temp_topo = main.ONOSbench.get_topology( main.ONOScli2.topology() )
1375 paths.append( temp_topo.get('paths', False) )
1376 temp_topo = main.ONOSbench.get_topology( main.ONOScli3.topology() )
1377 paths.append( temp_topo.get('paths', False) )
1378 temp_topo = main.ONOSbench.get_topology( main.ONOScli4.topology() )
1379 paths.append( temp_topo.get('paths', False) )
1380 temp_topo = main.ONOSbench.get_topology( main.ONOScli5.topology() )
1381 paths.append( temp_topo.get('paths', False) )
1382 temp_topo = main.ONOSbench.get_topology( main.ONOScli6.topology() )
1383 paths.append( temp_topo.get('paths', False) )
1384 temp_topo = main.ONOSbench.get_topology( main.ONOScli7.topology() )
1385 paths.append( temp_topo.get('paths', False) )
Jon Hallffb386d2014-11-21 13:43:38 -08001386
Jon Hall73cf9cc2014-11-20 22:28:38 -08001387
Jon Hall94fd0472014-12-08 11:52:42 -08001388 elapsed = time.time() - start_time
1389 cli_time = time.time() - cli_start
1390 print "CLI time: " + str(cli_time)
Jon Hall73cf9cc2014-11-20 22:28:38 -08001391
Jon Hall669173b2014-12-17 11:36:30 -08001392 for controller in range(num_controllers):
Jon Hall94fd0472014-12-08 11:52:42 -08001393 if devices[controller] or not "Error" in devices[controller]:
1394 current_devices_result = main.Mininet1.compare_switches(MNTopo, json.loads(devices[controller]))
1395 else:
1396 current_devices_result = main.FALSE
1397 utilities.assert_equals(expect=main.TRUE, actual=current_devices_result,
1398 onpass="ONOS"+str(int(controller+1))+" Switches view is correct",
1399 onfail="ONOS"+str(int(controller+1))+" Switches view is incorrect")
Jon Hall73cf9cc2014-11-20 22:28:38 -08001400
Jon Hall94fd0472014-12-08 11:52:42 -08001401 if ports[controller] or not "Error" in ports[controller]:
1402 current_ports_result = main.Mininet1.compare_ports(MNTopo, json.loads(ports[controller]))
1403 else:
1404 current_ports_result = main.FALSE
1405 utilities.assert_equals(expect=main.TRUE, actual=current_ports_result,
1406 onpass="ONOS"+str(int(controller+1))+" ports view is correct",
1407 onfail="ONOS"+str(int(controller+1))+" ports view is incorrect")
1408
1409 if links[controller] or not "Error" in links[controller]:
1410 current_links_result = main.Mininet1.compare_links(MNTopo, json.loads(links[controller]))
1411 else:
1412 current_links_result = main.FALSE
1413 utilities.assert_equals(expect=main.TRUE, actual=current_links_result,
1414 onpass="ONOS"+str(int(controller+1))+" links view is correct",
1415 onfail="ONOS"+str(int(controller+1))+" links view is incorrect")
Jon Hall73cf9cc2014-11-20 22:28:38 -08001416 devices_results = devices_results and current_devices_result
1417 ports_results = ports_results and current_ports_result
1418 links_results = links_results and current_links_result
Jon Hall94fd0472014-12-08 11:52:42 -08001419
1420 #Compare json objects for hosts, dataplane clusters and paths
1421
1422 #hosts
1423 consistent_hosts_result = main.TRUE
1424 for controller in range( len( hosts ) ):
1425 if not "Error" in hosts[controller]:
1426 if hosts[controller] == hosts[0]:
1427 continue
1428 else:#hosts not consistent
1429 main.log.report("hosts from ONOS" + str(controller + 1) + " is inconsistent with ONOS1")
1430 main.log.warn( repr( hosts[controller] ) )
1431 consistent_hosts_result = main.FALSE
1432
1433 else:
1434 main.log.report("Error in getting ONOS hosts from ONOS" + str(controller + 1) )
1435 consistent_hosts_result = main.FALSE
1436 main.log.warn("ONOS" + str(controller + 1) + " hosts response: " + repr(hosts[controller]) )
1437 utilities.assert_equals(expect = main.TRUE,actual=consistent_hosts_result,
1438 onpass="Hosts view is consistent across all ONOS nodes",
1439 onfail="ONOS nodes have different views of hosts")
1440
1441 #Strongly connected clusters of devices
1442 consistent_clusters_result = main.TRUE
1443 for controller in range( len( clusters ) ):
1444 if not "Error" in clusters[controller]:
1445 if clusters[controller] == clusters[0]:
1446 continue
1447 else:#clusters not consistent
1448 main.log.report("clusters from ONOS" + str(controller + 1) + " is inconsistent with ONOS1")
1449 consistent_clusters_result = main.FALSE
1450
1451 else:
1452 main.log.report("Error in getting dataplane clusters from ONOS" + str(controller + 1) )
1453 consistent_clusters_result = main.FALSE
1454 main.log.warn("ONOS" + str(controller + 1) + " clusters response: " + repr(clusters[controller]) )
1455 utilities.assert_equals(expect = main.TRUE,actual=consistent_clusters_result,
1456 onpass="Clusters view is consistent across all ONOS nodes",
1457 onfail="ONOS nodes have different views of clusters")
1458 num_clusters = len(json.loads(clusters[0])) #there should always only be one cluster
1459 utilities.assert_equals(expect = 1, actual = num_clusters,
1460 onpass="ONOS shows 1 SCC",
1461 onfail="ONOS shows "+str(num_clusters) +" SCCs")
1462
1463
1464 #paths
1465 consistent_paths_result = main.TRUE
1466 for controller in range( len( paths ) ):
1467 if not "Error" in paths[controller]:
1468 if paths[controller] == paths[0]:
1469 continue
1470 else:#paths not consistent
1471 main.log.report("paths from ONOS" + str(controller + 1) + " is inconsistent with ONOS1")
1472 consistent_paths_result = main.FALSE
1473
1474 else:
1475 main.log.report("Error in getting paths from ONOS" + str(controller + 1) )
1476 consistent_paths_result = main.FALSE
1477 main.log.warn("ONOS" + str(controller + 1) + " paths response: " + repr(paths[controller]) )
1478 utilities.assert_equals(expect = main.TRUE,actual=consistent_paths_result,
1479 onpass="Paths count is consistent across all ONOS nodes",
1480 onfail="ONOS nodes have different counts of paths")
1481
1482
1483 topo_result = devices_results and ports_results and links_results\
1484 and consistent_hosts_result and consistent_clusters_result and consistent_paths_result
1485
1486 topo_result = topo_result and int(count <= 2)
1487 note = "note it takes about "+str( int(cli_time) )+" seconds for the test to make all the cli calls to fetch the topology from each ONOS instance"
1488 main.log.report("Very crass estimate for topology discovery/convergence("+ str(note) + "): " +\
Jon Hallffb386d2014-11-21 13:43:38 -08001489 str(elapsed) + " seconds, " + str(count) +" tries" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001490 utilities.assert_equals(expect=main.TRUE, actual=topo_result,
1491 onpass="Topology Check Test successful",
1492 onfail="Topology Check Test NOT successful")
1493 if topo_result == main.TRUE:
1494 main.log.report("ONOS topology view matches Mininet topology")
1495
1496
1497 def CASE9 (self,main):
1498 '''
1499 Link s3-s28 down
1500 '''
1501 #NOTE: You should probably run a topology check after this
1502
Jon Hall669173b2014-12-17 11:36:30 -08001503 link_sleep = float(main.params['timers']['LinkDiscovery'])
Jon Hall73cf9cc2014-11-20 22:28:38 -08001504
1505 description = "Turn off a link to ensure that Link Discovery is working properly"
1506 main.log.report(description)
1507 main.case(description)
1508
1509
1510 main.step("Kill Link between s3 and s28")
1511 Link_Down = main.Mininet1.link(END1="s3",END2="s28",OPTION="down")
1512 main.log.info("Waiting " + str(link_sleep) + " seconds for link down to be discovered")
1513 time.sleep(link_sleep)
1514 utilities.assert_equals(expect=main.TRUE,actual=Link_Down,
1515 onpass="Link down succesful",
1516 onfail="Failed to bring link down")
1517 #TODO do some sort of check here
1518
1519 def CASE10 (self,main):
1520 '''
1521 Link s3-s28 up
1522 '''
1523 #NOTE: You should probably run a topology check after this
1524
Jon Hall669173b2014-12-17 11:36:30 -08001525 link_sleep = float(main.params['timers']['LinkDiscovery'])
Jon Hall73cf9cc2014-11-20 22:28:38 -08001526
1527 description = "Restore a link to ensure that Link Discovery is working properly"
1528 main.log.report(description)
1529 main.case(description)
1530
1531 main.step("Bring link between s3 and s28 back up")
1532 Link_Up = main.Mininet1.link(END1="s3",END2="s28",OPTION="up")
1533 main.log.info("Waiting " + str(link_sleep) + " seconds for link up to be discovered")
1534 time.sleep(link_sleep)
1535 utilities.assert_equals(expect=main.TRUE,actual=Link_Up,
1536 onpass="Link up succesful",
1537 onfail="Failed to bring link up")
1538 #TODO do some sort of check here
1539
1540
1541 def CASE11 (self, main) :
1542 '''
1543 Switch Down
1544 '''
1545 #NOTE: You should probably run a topology check after this
1546 import time
1547
Jon Hall669173b2014-12-17 11:36:30 -08001548 switch_sleep = float(main.params['timers']['SwitchDiscovery'])
Jon Hall73cf9cc2014-11-20 22:28:38 -08001549
1550 description = "Killing a switch to ensure it is discovered correctly"
1551 main.log.report(description)
1552 main.case(description)
1553
1554 #TODO: Make this switch parameterizable
1555 main.step("Kill s28 ")
1556 main.log.report("Deleting s28")
Jon Hall73cf9cc2014-11-20 22:28:38 -08001557 main.Mininet1.del_switch("s28")
1558 main.log.info("Waiting " + str(switch_sleep) + " seconds for switch down to be discovered")
1559 time.sleep(switch_sleep)
Jon Hall94fd0472014-12-08 11:52:42 -08001560 device = main.ONOScli1.get_device(dpid="0028")
Jon Hall73cf9cc2014-11-20 22:28:38 -08001561 #Peek at the deleted switch
Jon Hall94fd0472014-12-08 11:52:42 -08001562 main.log.warn( str(device) )
1563 result = main.FALSE
1564 if device and device['available'] == False:
1565 result = main.TRUE
1566 utilities.assert_equals(expect=main.TRUE,actual=result,
1567 onpass="Kill switch succesful",
1568 onfail="Failed to kill switch?")
Jon Hall73cf9cc2014-11-20 22:28:38 -08001569
1570 def CASE12 (self, main) :
1571 '''
1572 Switch Up
1573 '''
1574 #NOTE: You should probably run a topology check after this
1575 import time
Jon Hall669173b2014-12-17 11:36:30 -08001576
1577 switch_sleep = float(main.params['timers']['SwitchDiscovery'])
Jon Hall73cf9cc2014-11-20 22:28:38 -08001578 description = "Adding a switch to ensure it is discovered correctly"
1579 main.log.report(description)
1580 main.case(description)
1581
1582 main.step("Add back s28")
1583 main.log.report("Adding back s28")
1584 main.Mininet1.add_switch("s28", dpid = '0000000000002800')
1585 #TODO: New dpid or same? Ask Thomas?
1586 main.Mininet1.add_link('s28', 's3')
1587 main.Mininet1.add_link('s28', 's6')
1588 main.Mininet1.add_link('s28', 'h28')
Jon Hall669173b2014-12-17 11:36:30 -08001589 main.Mininet1.assign_sw_controller(sw="28",count=num_controllers,
Jon Hall73cf9cc2014-11-20 22:28:38 -08001590 ip1=ONOS1_ip,port1=ONOS1_port,
1591 ip2=ONOS2_ip,port2=ONOS2_port,
1592 ip3=ONOS3_ip,port3=ONOS3_port,
1593 ip4=ONOS4_ip,port4=ONOS4_port,
1594 ip5=ONOS5_ip,port5=ONOS5_port,
1595 ip6=ONOS6_ip,port6=ONOS6_port,
1596 ip7=ONOS7_ip,port7=ONOS7_port)
1597 main.log.info("Waiting " + str(switch_sleep) + " seconds for switch up to be discovered")
1598 time.sleep(switch_sleep)
Jon Hall94fd0472014-12-08 11:52:42 -08001599 device = main.ONOScli1.get_device(dpid="0028")
1600 #Peek at the deleted switch
1601 main.log.warn( str(device) )
1602 result = main.FALSE
1603 if device and device['available'] == True:
1604 result = main.TRUE
1605 utilities.assert_equals(expect=main.TRUE,actual=result,
1606 onpass="add switch succesful",
1607 onfail="Failed to add switch?")
Jon Hall73cf9cc2014-11-20 22:28:38 -08001608
1609 def CASE13 (self, main) :
1610 '''
1611 Clean up
1612 '''
1613 import os
1614 import time
Jon Hall669173b2014-12-17 11:36:30 -08001615 #printing colors to terminal
1616 colors = {}
1617 colors['cyan'] = '\033[96m'
1618 colors['purple'] = '\033[95m'
1619 colors['blue'] = '\033[94m'
1620 colors['green'] = '\033[92m'
1621 colors['yellow'] = '\033[93m'
1622 colors['red'] = '\033[91m'
1623 colors['end'] = '\033[0m'
Jon Hall73cf9cc2014-11-20 22:28:38 -08001624 description = "Test Cleanup"
1625 main.log.report(description)
1626 main.case(description)
1627 main.step("Killing tcpdumps")
1628 main.Mininet2.stop_tcpdump()
1629
Jon Hall94fd0472014-12-08 11:52:42 -08001630 main.step("Checking ONOS Logs for errors")
Jon Hall669173b2014-12-17 11:36:30 -08001631 print colors['purple'] + "Checking logs for errors on ONOS1:" + colors['end']
Jon Hall94fd0472014-12-08 11:52:42 -08001632 print main.ONOSbench.check_logs(ONOS1_ip)
Jon Hall669173b2014-12-17 11:36:30 -08001633 print colors['purple'] + "Checking logs for errors on ONOS2:" + colors['end']
Jon Hall94fd0472014-12-08 11:52:42 -08001634 print main.ONOSbench.check_logs(ONOS2_ip)
Jon Hall669173b2014-12-17 11:36:30 -08001635 print colors['purple'] + "Checking logs for errors on ONOS3:" + colors['end']
Jon Hall94fd0472014-12-08 11:52:42 -08001636 print main.ONOSbench.check_logs(ONOS3_ip)
Jon Hall669173b2014-12-17 11:36:30 -08001637 print colors['purple'] + "Checking logs for errors on ONOS4:" + colors['end']
Jon Hall94fd0472014-12-08 11:52:42 -08001638 print main.ONOSbench.check_logs(ONOS4_ip)
Jon Hall669173b2014-12-17 11:36:30 -08001639 print colors['purple'] + "Checking logs for errors on ONOS5:" + colors['end']
Jon Hall94fd0472014-12-08 11:52:42 -08001640 print main.ONOSbench.check_logs(ONOS5_ip)
Jon Hall669173b2014-12-17 11:36:30 -08001641 print colors['purple'] + "Checking logs for errors on ONOS6:" + colors['end']
Jon Hall94fd0472014-12-08 11:52:42 -08001642 print main.ONOSbench.check_logs(ONOS6_ip)
Jon Hall669173b2014-12-17 11:36:30 -08001643 print colors['purple'] + "Checking logs for errors on ONOS7:" + colors['end']
Jon Hall94fd0472014-12-08 11:52:42 -08001644 print main.ONOSbench.check_logs(ONOS7_ip)
1645
Jon Hall73cf9cc2014-11-20 22:28:38 -08001646 main.step("Copying MN pcap and ONOS log files to test station")
1647 testname = main.TEST
Jon Hall94fd0472014-12-08 11:52:42 -08001648 teststation_user = main.params['TESTONUSER']
1649 teststation_IP = main.params['TESTONIP']
Jon Hall73cf9cc2014-11-20 22:28:38 -08001650 #NOTE: MN Pcap file is being saved to ~/packet_captures
1651 # scp this file as MN and TestON aren't necessarily the same vm
1652 #FIXME: scp
1653 #####mn files
1654 #TODO: Load these from params
1655 #NOTE: must end in /
1656 log_folder = "/opt/onos/log/"
1657 log_files = ["karaf.log", "karaf.log.1"]
1658 #NOTE: must end in /
1659 dst_dir = "~/packet_captures/"
1660 for f in log_files:
Jon Hall94fd0472014-12-08 11:52:42 -08001661 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS1_ip+":"+log_folder+f+" "+
1662 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001663 dst_dir + str(testname) + "-ONOS1-"+f )
Jon Hall94fd0472014-12-08 11:52:42 -08001664 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS2_ip+":"+log_folder+f+" "+
1665 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001666 dst_dir + str(testname) + "-ONOS2-"+f )
Jon Hall94fd0472014-12-08 11:52:42 -08001667 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS3_ip+":"+log_folder+f+" "+
1668 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001669 dst_dir + str(testname) + "-ONOS3-"+f )
Jon Hall94fd0472014-12-08 11:52:42 -08001670 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS4_ip+":"+log_folder+f+" "+
1671 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001672 dst_dir + str(testname) + "-ONOS4-"+f )
Jon Hall94fd0472014-12-08 11:52:42 -08001673 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS5_ip+":"+log_folder+f+" "+
1674 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001675 dst_dir + str(testname) + "-ONOS5-"+f )
Jon Hall94fd0472014-12-08 11:52:42 -08001676 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS6_ip+":"+log_folder+f+" "+
1677 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001678 dst_dir + str(testname) + "-ONOS6-"+f )
Jon Hall94fd0472014-12-08 11:52:42 -08001679 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS7_ip+":"+log_folder+f+" "+
1680 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001681 dst_dir + str(testname) + "-ONOS7-"+f )
1682
1683 #std*.log's
1684 #NOTE: must end in /
1685 log_folder = "/opt/onos/var/"
1686 log_files = ["stderr.log", "stdout.log"]
1687 #NOTE: must end in /
1688 dst_dir = "~/packet_captures/"
1689 for f in log_files:
Jon Hall94fd0472014-12-08 11:52:42 -08001690 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS1_ip+":"+log_folder+f+" "+
1691 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001692 dst_dir + str(testname) + "-ONOS1-"+f )
Jon Hall94fd0472014-12-08 11:52:42 -08001693 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS2_ip+":"+log_folder+f+" "+
1694 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001695 dst_dir + str(testname) + "-ONOS2-"+f )
Jon Hall94fd0472014-12-08 11:52:42 -08001696 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS3_ip+":"+log_folder+f+" "+
1697 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001698 dst_dir + str(testname) + "-ONOS3-"+f )
Jon Hall94fd0472014-12-08 11:52:42 -08001699 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS4_ip+":"+log_folder+f+" "+
1700 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001701 dst_dir + str(testname) + "-ONOS4-"+f )
Jon Hall94fd0472014-12-08 11:52:42 -08001702 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS5_ip+":"+log_folder+f+" "+
1703 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001704 dst_dir + str(testname) + "-ONOS5-"+f )
Jon Hall94fd0472014-12-08 11:52:42 -08001705 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS6_ip+":"+log_folder+f+" "+
1706 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001707 dst_dir + str(testname) + "-ONOS6-"+f )
Jon Hall94fd0472014-12-08 11:52:42 -08001708 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS7_ip+":"+log_folder+f+" "+
1709 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001710 dst_dir + str(testname) + "-ONOS7-"+f )
1711
1712
Jon Hall73cf9cc2014-11-20 22:28:38 -08001713 #sleep so scp can finish
1714 time.sleep(10)
1715 main.step("Packing and rotating pcap archives")
1716 os.system("~/TestON/dependencies/rotate.sh "+ str(testname))
1717
1718
1719 #TODO: actually check something here
1720 utilities.assert_equals(expect=main.TRUE, actual=main.TRUE,
1721 onpass="Test cleanup successful",
1722 onfail="Test cleanup NOT successful")
Jon Hall669173b2014-12-17 11:36:30 -08001723
1724 def CASE14 ( self, main ) :
1725 '''
1726 start election app on all onos nodes
1727 '''
1728 leader_result = main.TRUE
1729 #install app on onos 1
1730 main.log.info("Install leadership election app")
1731 main.ONOScli1.feature_install("onos-app-election")
1732 #wait for election
1733 #check for leader
1734 leader = main.ONOScli1.election_test_leader()
1735 #verify leader is ONOS1
1736 if leader == ONOS1_ip:
1737 #all is well
1738 pass
1739 elif leader == None:
1740 #No leader elected
1741 main.log.report("No leader was elected")
1742 leader_result = main.FALSE
1743 elif leader == main.FALSE:
1744 #error in response
1745 #TODO: add check for "Command not found:" in the driver, this means the app isn't loaded
1746 main.log.report("Something is wrong with election_test_leader function, check the error logs")
1747 leader_result = main.FALSE
1748 else:
1749 #error in response
1750 main.log.report("Unexpected response from election_test_leader function:'"+str(leader)+"'")
1751 leader_result = main.FALSE
1752
1753
1754
1755
1756 #install on other nodes and check for leader.
1757 #Should be onos1 and each app should show the same leader
1758 for controller in range(2,num_controllers+1):
1759 node = getattr( main, ( 'ONOScli' + str( controller ) ) )#loop through ONOScli handlers
1760 node.feature_install("onos-app-election")
1761 leaderN = node.election_test_leader()
1762 #verify leader is ONOS1
1763 if leaderN == ONOS1_ip:
1764 #all is well
1765 pass
1766 elif leaderN == main.FALSE:
1767 #error in response
1768 #TODO: add check for "Command not found:" in the driver, this means the app isn't loaded
1769 main.log.report("Something is wrong with election_test_leader function, check the error logs")
1770 leader_result = main.FALSE
1771 elif leader != leaderN:
1772 leader_result = main.FALSE
1773 main.log.report("ONOS" + str(controller) + " sees "+str(leaderN) +
1774 " as the leader of the election app. Leader should be "+str(leader) )
1775 if leader_result:
1776 main.log.report("Leadership election tests passed(consistent view of leader across listeners and a leader was elected)")
1777 utilities.assert_equals(expect=main.TRUE, actual=leader_result,
1778 onpass="Leadership election passed",
1779 onfail="Something went wrong with Leadership election")
1780
1781 def CASE15 ( self, main ) :
1782 '''
1783 Check that Leadership Election is still functional
1784 '''
1785 leader_result = main.TRUE
1786 description = "Check that Leadership Election is still functional"
1787 main.log.report(description)
1788 main.case(description)
1789 main.step("Find current leader and withdraw")
1790 leader = main.ONOScli1.election_test_leader()
1791 #TODO: do some sanity checking on leader before using it
1792 withdraw_result = main.FALSE
1793 if leader == ONOS1_ip:
1794 old_leader = getattr( main, "ONOScli1" )
1795 elif leader == ONOS2_ip:
1796 old_leader = getattr( main, "ONOScli2" )
1797 elif leader == ONOS3_ip:
1798 old_leader = getattr( main, "ONOScli3" )
1799 elif leader == ONOS4_ip:
1800 old_leader = getattr( main, "ONOScli4" )
1801 elif leader == ONOS5_ip:
1802 old_leader = getattr( main, "ONOScli5" )
1803 elif leader == ONOS6_ip:
1804 old_leader = getattr( main, "ONOScli6" )
1805 elif leader == ONOS7_ip:
1806 old_leader = getattr( main, "ONOScli7" )
1807 elif leader == None or leader == main.FALSE:
1808 main.log.report("Leader for the election app should be an ONOS node,"\
1809 +"instead got '"+str(leader)+"'")
1810 leader_result = main.FALSE
1811 withdraw_result = old_leader.election_test_withdraw()
1812
1813
1814 main.step("Make sure new leader is elected")
1815 leader_list = []
1816 for controller in range(1,num_controllers+1):
1817 node = getattr( main, ( 'ONOScli' + str( controller ) ) )#loop through ONOScli handlers
1818 leader_list.append( node.election_test_leader() )
1819 for leaderN in leader_list:
1820 if leaderN == leader:
1821 main.log.report("ONOS"+str(controller)+" still sees " + str(leader) +\
1822 " as leader after they withdrew")
1823 leader_result = main.FALSE
1824 elif leaderN == main.FALSE:
1825 #error in response
1826 #TODO: add check for "Command not found:" in the driver, this means the app isn't loaded
1827 main.log.report("Something is wrong with election_test_leader function, check the error logs")
1828 leader_result = main.FALSE
1829 consistent_leader = main.FALSE
1830 if len( set( leader_list ) ) == 1:
1831 main.log.info("Each Election-app sees '"+str(leader_list[0])+"' as the leader")
1832 consistent_leader = main.TRUE
1833 else:
1834 main.log.report("Inconsistent responses for leader of Election-app:")
1835 for n in range(len(leader_list)):
1836 main.log.report("ONOS" + str(n+1) + " response: " + str(leader_list[n]) )
1837 if leader_result:
1838 main.log.report("Leadership election tests passed(consistent view of leader across listeners and a new leader was elected when the old leader resigned)")
1839 utilities.assert_equals(expect=main.TRUE, actual=leader_result,
1840 onpass="Leadership election passed",
1841 onfail="Something went wrong with Leadership election")
1842
1843
1844 main.step("Run for election on old leader(just so everyone is in the hat)")
1845 run_result = old_leader.election_test_run()
1846 if consistent_leader == main.TRUE:
1847 after_run = main.ONOScli1.election_test_leader()
1848 #verify leader didn't just change
1849 if after_run == leader_list[0]:
1850 leader_result = main.TRUE
1851 else:
1852 leader_result = main.FALSE
1853 #TODO: assert on run and withdraw results?
1854
1855 utilities.assert_equals(expect=main.TRUE, actual=leader_result,
1856 onpass="Leadership election passed",
1857 onfail="Something went wrong with Leadership election after the old leader re-ran for election")
1858