blob: b9d2925b56c30bfeba5396754aa505303c1bbb99 [file] [log] [blame]
Jon Hall73cf9cc2014-11-20 22:28:38 -08001'''
2Description: This test is to determine if ONOS can handle
3 a minority 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 HATestMinorityRestart:
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 minority of 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
Jon Hall669173b2014-12-17 11:36:30 -0800190
Jon Hall73cf9cc2014-11-20 22:28:38 -0800191 main.step("Start Packet Capture MN")
192 main.Mininet2.start_tcpdump(
193 str(main.params['MNtcpdump']['folder'])+str(main.TEST)+"-MN.pcap",
194 intf = main.params['MNtcpdump']['intf'],
195 port = main.params['MNtcpdump']['port'])
196
197
198 case1_result = (clean_install_result and package_result and
199 cell_result and verify_result and onos_install_result and
200 onos_isup_result and cli_results)
201
202 utilities.assert_equals(expect=main.TRUE, actual=case1_result,
203 onpass="Test startup successful",
204 onfail="Test startup NOT successful")
205
206
Jon Hall94fd0472014-12-08 11:52:42 -0800207 if case1_result==main.FALSE:
208 main.cleanup()
209 main.exit()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800210
211 def CASE2(self,main) :
212 '''
213 Assign mastership to controllers
214 '''
215 import time
216 import json
217 import re
218
Jon Hall73cf9cc2014-11-20 22:28:38 -0800219 main.log.report("Assigning switches to controllers")
220 main.case("Assigning Controllers")
221 main.step("Assign switches to controllers")
222
223 for i in range (1,29):
Jon Hall669173b2014-12-17 11:36:30 -0800224 main.Mininet1.assign_sw_controller(sw=str(i),count=num_controllers,
Jon Hall73cf9cc2014-11-20 22:28:38 -0800225 ip1=ONOS1_ip,port1=ONOS1_port,
226 ip2=ONOS2_ip,port2=ONOS2_port,
227 ip3=ONOS3_ip,port3=ONOS3_port,
228 ip4=ONOS4_ip,port4=ONOS4_port,
229 ip5=ONOS5_ip,port5=ONOS5_port,
230 ip6=ONOS6_ip,port6=ONOS6_port,
231 ip7=ONOS7_ip,port7=ONOS7_port)
232
233 mastership_check = main.TRUE
234 for i in range (1,29):
235 response = main.Mininet1.get_sw_controller("s"+str(i))
Jon Hallffb386d2014-11-21 13:43:38 -0800236 try:
237 main.log.info(str(response))
238 except:
239 main.log.info(repr(response))
Jon Hall73cf9cc2014-11-20 22:28:38 -0800240 if re.search("tcp:"+ONOS1_ip,response)\
241 and re.search("tcp:"+ONOS2_ip,response)\
242 and re.search("tcp:"+ONOS3_ip,response)\
243 and re.search("tcp:"+ONOS4_ip,response)\
244 and re.search("tcp:"+ONOS5_ip,response)\
245 and re.search("tcp:"+ONOS6_ip,response)\
246 and re.search("tcp:"+ONOS7_ip,response):
247 mastership_check = mastership_check and main.TRUE
248 else:
249 mastership_check = main.FALSE
250 if mastership_check == main.TRUE:
251 main.log.report("Switch mastership assigned correctly")
252 utilities.assert_equals(expect = main.TRUE,actual=mastership_check,
253 onpass="Switch mastership assigned correctly",
254 onfail="Switches not assigned correctly to controllers")
255
Jon Hall94fd0472014-12-08 11:52:42 -0800256 #Manually assign mastership to the controller we want
257 role_call = main.TRUE
258 role_check = main.TRUE
259
260 device_id = main.ONOScli1.get_device("1000")['id']
261 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS1_ip)
262 if ONOS1_ip in main.ONOScli1.get_role(device_id)['master']:
263 role_check = role_check and main.TRUE
264 else:
265 role_check = role_check and main.FALSE
266
267 device_id = main.ONOScli1.get_device("2800")['id']
268 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS1_ip)
269 if ONOS1_ip in main.ONOScli1.get_role(device_id)['master']:
270 role_check = role_check and main.TRUE
271 else:
272 role_check = role_check and main.FALSE
273
274 device_id = main.ONOScli1.get_device("2000")['id']
275 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS2_ip)
276 if ONOS2_ip in main.ONOScli1.get_role(device_id)['master']:
277 role_check = role_check and main.TRUE
278 else:
279 role_check = role_check and main.FALSE
280
281 device_id = main.ONOScli1.get_device("3000")['id']
282 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS2_ip)
283 if ONOS2_ip in main.ONOScli1.get_role(device_id)['master']:
284 role_check = role_check and main.TRUE
285 else:
286 role_check = role_check and main.FALSE
287
288 device_id = main.ONOScli1.get_device("5000")['id']
289 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS3_ip)
290 if ONOS3_ip in main.ONOScli1.get_role(device_id)['master']:
291 role_check = role_check and main.TRUE
292 else:
293 role_check = role_check and main.FALSE
294
295 device_id = main.ONOScli1.get_device("6000")['id']
296 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS3_ip)
297 if ONOS3_ip in main.ONOScli1.get_role(device_id)['master']:
298 role_check = role_check and main.TRUE
299 else:
300 role_check = role_check and main.FALSE
301
302 device_id = main.ONOScli1.get_device("3004")['id']
303 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS4_ip)
304 if ONOS4_ip in main.ONOScli1.get_role(device_id)['master']:
305 role_check = role_check and main.TRUE
306 else:
307 role_check = role_check and main.FALSE
308
309 device_id = main.ONOScli1.get_device("3008")['id']
310 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS5_ip)
311 if ONOS5_ip in main.ONOScli1.get_role(device_id)['master']:
312 role_check = role_check and main.TRUE
313 else:
314 role_check = role_check and main.FALSE
315
316 device_id = main.ONOScli1.get_device("3009")['id']
317 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS5_ip)
318 if ONOS5_ip in main.ONOScli1.get_role(device_id)['master']:
319 role_check = role_check and main.TRUE
320 else:
321 role_check = role_check and main.FALSE
322
323 device_id = main.ONOScli1.get_device("3010")['id']
324 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS5_ip)
325 if ONOS5_ip in main.ONOScli1.get_role(device_id)['master']:
326 role_check = role_check and main.TRUE
327 else:
328 role_check = role_check and main.FALSE
329
330 device_id = main.ONOScli1.get_device("3011")['id']
331 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS5_ip)
332 if ONOS5_ip in main.ONOScli1.get_role(device_id)['master']:
333 role_check = role_check and main.TRUE
334 else:
335 role_check = role_check and main.FALSE
336
337 device_id = main.ONOScli1.get_device("3012")['id']
338 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS5_ip)
339 if ONOS5_ip in main.ONOScli1.get_role(device_id)['master']:
340 role_check = role_check and main.TRUE
341 else:
342 role_check = role_check and main.FALSE
343
344 device_id = main.ONOScli1.get_device("3013")['id']
345 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS5_ip)
346 if ONOS5_ip in main.ONOScli1.get_role(device_id)['master']:
347 role_check = role_check and main.TRUE
348 else:
349 role_check = role_check and main.FALSE
350
351 device_id = main.ONOScli1.get_device("3014")['id']
352 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS5_ip)
353 if ONOS5_ip in main.ONOScli1.get_role(device_id)['master']:
354 role_check = role_check and main.TRUE
355 else:
356 role_check = role_check and main.FALSE
357
358 device_id = main.ONOScli1.get_device("3015")['id']
359 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS5_ip)
360 if ONOS5_ip in main.ONOScli1.get_role(device_id)['master']:
361 role_check = role_check and main.TRUE
362 else:
363 role_check = role_check and main.FALSE
364
365 device_id = main.ONOScli1.get_device("3016")['id']
366 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS5_ip)
367 if ONOS5_ip in main.ONOScli1.get_role(device_id)['master']:
368 role_check = role_check and main.TRUE
369 else:
370 role_check = role_check and main.FALSE
371
372 device_id = main.ONOScli1.get_device("3017")['id']
373 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS5_ip)
374 if ONOS5_ip in main.ONOScli1.get_role(device_id)['master']:
375 role_check = role_check and main.TRUE
376 else:
377 role_check = role_check and main.FALSE
378
379 device_id = main.ONOScli1.get_device("6007")['id']
380 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS6_ip)
381 if ONOS6_ip in main.ONOScli1.get_role(device_id)['master']:
382 role_check = role_check and main.TRUE
383 else:
384 role_check = role_check and main.FALSE
385
386 device_id = main.ONOScli1.get_device("6018")['id']
387 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS7_ip)
388 if ONOS7_ip in main.ONOScli1.get_role(device_id)['master']:
389 role_check = role_check and main.TRUE
390 else:
391 role_check = role_check and main.FALSE
392
393 device_id = main.ONOScli1.get_device("6019")['id']
394 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS7_ip)
395 if ONOS7_ip in main.ONOScli1.get_role(device_id)['master']:
396 role_check = role_check and main.TRUE
397 else:
398 role_check = role_check and main.FALSE
399
400 device_id = main.ONOScli1.get_device("6020")['id']
401 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS7_ip)
402 if ONOS7_ip in main.ONOScli1.get_role(device_id)['master']:
403 role_check = role_check and main.TRUE
404 else:
405 role_check = role_check and main.FALSE
406
407 device_id = main.ONOScli1.get_device("6021")['id']
408 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS7_ip)
409 if ONOS7_ip in main.ONOScli1.get_role(device_id)['master']:
410 role_check = role_check and main.TRUE
411 else:
412 role_check = role_check and main.FALSE
413
414 device_id = main.ONOScli1.get_device("6022")['id']
415 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS7_ip)
416 if ONOS7_ip in main.ONOScli1.get_role(device_id)['master']:
417 role_check = role_check and main.TRUE
418 else:
419 role_check = role_check and main.FALSE
420
421 device_id = main.ONOScli1.get_device("6023")['id']
422 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS7_ip)
423 if ONOS7_ip in main.ONOScli1.get_role(device_id)['master']:
424 role_check = role_check and main.TRUE
425 else:
426 role_check = role_check and main.FALSE
427
428 device_id = main.ONOScli1.get_device("6024")['id']
429 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS7_ip)
430 if ONOS7_ip in main.ONOScli1.get_role(device_id)['master']:
431 role_check = role_check and main.TRUE
432 else:
433 role_check = role_check and main.FALSE
434
435 device_id = main.ONOScli1.get_device("6025")['id']
436 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS7_ip)
437 if ONOS7_ip in main.ONOScli1.get_role(device_id)['master']:
438 role_check = role_check and main.TRUE
439 else:
440 role_check = role_check and main.FALSE
441
442 device_id = main.ONOScli1.get_device("6026")['id']
443 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS7_ip)
444 if ONOS7_ip in main.ONOScli1.get_role(device_id)['master']:
445 role_check = role_check and main.TRUE
446 else:
447 role_check = role_check and main.FALSE
448
449 device_id = main.ONOScli1.get_device("6027")['id']
450 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS7_ip)
451 if ONOS7_ip in main.ONOScli1.get_role(device_id)['master']:
452 role_check = role_check and main.TRUE
453 else:
454 role_check = role_check and main.FALSE
455
456 utilities.assert_equals(expect = main.TRUE,actual=role_call,
457 onpass="Re-assigned switch mastership to designated controller",
458 onfail="Something wrong with device_role calls")
459
460 utilities.assert_equals(expect = main.TRUE,actual=role_check,
461 onpass="Switches were successfully reassigned to designated controller",
462 onfail="Switches were not successfully reassigned")
463 mastership_check = mastership_check and role_call and role_check
464 utilities.assert_equals(expect = main.TRUE,actual=mastership_check,
465 onpass="Switch mastership correctly assigned",
466 onfail="Error in (re)assigning switch mastership")
Jon Hall73cf9cc2014-11-20 22:28:38 -0800467
468
469 def CASE3(self,main) :
470 """
471 Assign intents
472
473 """
474 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 = []
Jon Hall669173b2014-12-17 11:36:30 -0800818 hosts.append( json.loads( main.ONOScli1.hosts() ) )
819 hosts.append( json.loads( main.ONOScli2.hosts() ) )
820 hosts.append( json.loads( main.ONOScli3.hosts() ) )
821 hosts.append( json.loads( main.ONOScli4.hosts() ) )
822 hosts.append( json.loads( main.ONOScli5.hosts() ) )
823 hosts.append( json.loads( main.ONOScli6.hosts() ) )
824 hosts.append( json.loads( main.ONOScli7.hosts() ) )
825 for controller in range(0, len(hosts) ):
826 for host in hosts[controller]:
827 if host['ips'] == []:
828 main.log.error("DEBUG:Error with host ips on controller"+str(controller+1)+": " + str(host))
Jon Hall73cf9cc2014-11-20 22:28:38 -0800829 ports = []
830 ports.append( main.ONOScli1.ports() )
831 ports.append( main.ONOScli2.ports() )
832 ports.append( main.ONOScli3.ports() )
833 ports.append( main.ONOScli4.ports() )
834 ports.append( main.ONOScli5.ports() )
835 ports.append( main.ONOScli6.ports() )
836 ports.append( main.ONOScli7.ports() )
837 links = []
838 links.append( main.ONOScli1.links() )
839 links.append( main.ONOScli2.links() )
840 links.append( main.ONOScli3.links() )
841 links.append( main.ONOScli4.links() )
842 links.append( main.ONOScli5.links() )
843 links.append( main.ONOScli6.links() )
844 links.append( main.ONOScli7.links() )
Jon Hall94fd0472014-12-08 11:52:42 -0800845 clusters = []
846 clusters.append( main.ONOScli1.clusters() )
847 clusters.append( main.ONOScli2.clusters() )
848 clusters.append( main.ONOScli3.clusters() )
849 clusters.append( main.ONOScli4.clusters() )
850 clusters.append( main.ONOScli5.clusters() )
851 clusters.append( main.ONOScli6.clusters() )
852 clusters.append( main.ONOScli7.clusters() )
853 paths = []
854 temp_topo = main.ONOSbench.get_topology( main.ONOScli1.topology() )
855 paths.append( temp_topo.get('paths', False) )
856 temp_topo = main.ONOSbench.get_topology( main.ONOScli2.topology() )
857 paths.append( temp_topo.get('paths', False) )
858 temp_topo = main.ONOSbench.get_topology( main.ONOScli3.topology() )
859 paths.append( temp_topo.get('paths', False) )
860 temp_topo = main.ONOSbench.get_topology( main.ONOScli4.topology() )
861 paths.append( temp_topo.get('paths', False) )
862 temp_topo = main.ONOSbench.get_topology( main.ONOScli5.topology() )
863 paths.append( temp_topo.get('paths', False) )
864 temp_topo = main.ONOSbench.get_topology( main.ONOScli6.topology() )
865 paths.append( temp_topo.get('paths', False) )
866 temp_topo = main.ONOSbench.get_topology( main.ONOScli7.topology() )
867 paths.append( temp_topo.get('paths', False) )
868
869 #Compare json objects for hosts, dataplane clusters and paths
870
871 #hosts
872 consistent_hosts_result = main.TRUE
873 for controller in range( len( hosts ) ):
874 if not "Error" in hosts[controller]:
875 if hosts[controller] == hosts[0]:
876 continue
877 else:#hosts not consistent
878 main.log.report("hosts from ONOS" + str(controller + 1) + " is inconsistent with ONOS1")
879 main.log.warn( repr( hosts[controller] ) )
880 consistent_hosts_result = main.FALSE
881
882 else:
883 main.log.report("Error in getting ONOS hosts from ONOS" + str(controller + 1) )
884 consistent_hosts_result = main.FALSE
885 main.log.warn("ONOS" + str(controller + 1) + " hosts response: " + repr(hosts[controller]) )
886 utilities.assert_equals(expect = main.TRUE,actual=consistent_hosts_result,
887 onpass="Hosts view is consistent across all ONOS nodes",
888 onfail="ONOS nodes have different views of hosts")
889
890 #Strongly connected clusters of devices
891 consistent_clusters_result = main.TRUE
892 for controller in range( len( clusters ) ):
893 if not "Error" in clusters[controller]:
894 if clusters[controller] == clusters[0]:
895 continue
896 else:#clusters not consistent
897 main.log.report("clusters from ONOS" + str(controller + 1) + " is inconsistent with ONOS1")
898 consistent_clusters_result = main.FALSE
899
900 else:
901 main.log.report("Error in getting dataplane clusters from ONOS" + str(controller + 1) )
902 consistent_clusters_result = main.FALSE
903 main.log.warn("ONOS" + str(controller + 1) + " clusters response: " + repr(clusters[controller]) )
904 utilities.assert_equals(expect = main.TRUE,actual=consistent_clusters_result,
905 onpass="Clusters view is consistent across all ONOS nodes",
906 onfail="ONOS nodes have different views of clusters")
907 num_clusters = len(json.loads(clusters[0])) #there should always only be one cluster
908 utilities.assert_equals(expect = 1, actual = num_clusters,
909 onpass="ONOS shows 1 SCC",
910 onfail="ONOS shows "+str(num_clusters) +" SCCs")
911
912
913 #paths
914 consistent_paths_result = main.TRUE
915 for controller in range( len( paths ) ):
916 if not "Error" in paths[controller]:
917 if paths[controller] == paths[0]:
918 continue
919 else:#paths not consistent
920 main.log.report("paths from ONOS" + str(controller + 1) + " is inconsistent with ONOS1")
921 consistent_paths_result = main.FALSE
922
923 else:
924 main.log.report("Error in getting paths from ONOS" + str(controller + 1) )
925 consistent_paths_result = main.FALSE
926 main.log.warn("ONOS" + str(controller + 1) + " paths response: " + repr(paths[controller]) )
927 utilities.assert_equals(expect = main.TRUE,actual=consistent_paths_result,
928 onpass="Paths count is consistent across all ONOS nodes",
929 onfail="ONOS nodes have different counts of paths")
Jon Hall73cf9cc2014-11-20 22:28:38 -0800930
931
932 main.step("Comparing ONOS topology to MN")
933 devices_results = main.TRUE
934 ports_results = main.TRUE
935 links_results = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -0800936 for controller in range(num_controllers):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800937 if devices[controller] or not "Error" in devices[controller]:
938 current_devices_result = main.Mininet1.compare_switches(MNTopo, json.loads(devices[controller]))
939 else:
940 current_devices_result = main.FALSE
941 utilities.assert_equals(expect=main.TRUE, actual=current_devices_result,
942 onpass="ONOS"+str(int(controller+1))+" Switches view is correct",
943 onfail="ONOS"+str(int(controller+1))+" Switches view is incorrect")
944
945 if ports[controller] or not "Error" in ports[controller]:
946 current_ports_result = main.Mininet1.compare_ports(MNTopo, json.loads(ports[controller]))
947 else:
948 current_ports_result = main.FALSE
949 utilities.assert_equals(expect=main.TRUE, actual=current_ports_result,
950 onpass="ONOS"+str(int(controller+1))+" ports view is correct",
951 onfail="ONOS"+str(int(controller+1))+" ports view is incorrect")
952
953 if links[controller] or not "Error" in links[controller]:
954 current_links_result = main.Mininet1.compare_links(MNTopo, json.loads(links[controller]))
955 else:
956 current_links_result = main.FALSE
957 utilities.assert_equals(expect=main.TRUE, actual=current_links_result,
958 onpass="ONOS"+str(int(controller+1))+" links view is correct",
959 onfail="ONOS"+str(int(controller+1))+" links view is incorrect")
960
961 devices_results = devices_results and current_devices_result
962 ports_results = ports_results and current_ports_result
963 links_results = links_results and current_links_result
964
Jon Hall94fd0472014-12-08 11:52:42 -0800965 topo_result = devices_results and ports_results and links_results\
966 and consistent_hosts_result and consistent_clusters_result\
967 and consistent_paths_result
Jon Hall73cf9cc2014-11-20 22:28:38 -0800968 utilities.assert_equals(expect=main.TRUE, actual=topo_result,
969 onpass="Topology Check Test successful",
970 onfail="Topology Check Test NOT successful")
971
972 final_assert = main.TRUE
973 final_assert = final_assert and topo_result and flow_check \
Jon Hall94fd0472014-12-08 11:52:42 -0800974 and intent_check and consistent_mastership and roles_not_null
Jon Hall73cf9cc2014-11-20 22:28:38 -0800975 utilities.assert_equals(expect=main.TRUE, actual=final_assert,
976 onpass="State check successful",
977 onfail="State check NOT successful")
978
979
980 def CASE6(self,main) :
981 '''
982 The Failure case.
983 '''
Jon Hall94fd0472014-12-08 11:52:42 -0800984 import time
Jon Hall73cf9cc2014-11-20 22:28:38 -0800985 main.log.report("Killing 3 ONOS nodes")
986 main.log.case("Restart minority of ONOS nodes")
987 #TODO: Randomize these nodes
988 main.ONOSbench.onos_kill(ONOS1_ip)
Jon Hall94fd0472014-12-08 11:52:42 -0800989 time.sleep(10)
Jon Hall73cf9cc2014-11-20 22:28:38 -0800990 main.ONOSbench.onos_kill(ONOS2_ip)
Jon Hall94fd0472014-12-08 11:52:42 -0800991 time.sleep(10)
Jon Hall73cf9cc2014-11-20 22:28:38 -0800992 main.ONOSbench.onos_kill(ONOS3_ip)
993
994 main.step("Checking if ONOS is up yet")
Jon Hallffb386d2014-11-21 13:43:38 -0800995 count = 0
996 onos_isup_result = main.FALSE
997 while onos_isup_result == main.FALSE and count < 10:
998 onos1_isup = main.ONOSbench.isup(ONOS1_ip)
999 onos2_isup = main.ONOSbench.isup(ONOS2_ip)
1000 onos3_isup = main.ONOSbench.isup(ONOS3_ip)
1001 onos_isup_result = onos1_isup and onos2_isup and onos3_isup
1002 count = count + 1
Jon Hall73cf9cc2014-11-20 22:28:38 -08001003 # TODO: if it becomes an issue, we can retry this step a few times
1004
1005
1006 cli_result1 = main.ONOScli1.start_onos_cli(ONOS1_ip)
1007 cli_result2 = main.ONOScli2.start_onos_cli(ONOS2_ip)
1008 cli_result3 = main.ONOScli3.start_onos_cli(ONOS3_ip)
1009 cli_results = cli_result1 and cli_result2 and cli_result3
1010
Jon Hall669173b2014-12-17 11:36:30 -08001011 main.log.info("Install leadership election app on restarted node")
1012
Jon Hall73cf9cc2014-11-20 22:28:38 -08001013 case_results = main.TRUE and onos_isup_result and cli_results
1014 utilities.assert_equals(expect=main.TRUE, actual=case_results,
1015 onpass="ONOS restart successful",
1016 onfail="ONOS restart NOT successful")
1017
1018
1019 def CASE7(self,main) :
1020 '''
1021 Check state after ONOS failure
1022 '''
1023 import os
1024 import json
1025 main.case("Running ONOS Constant State Tests")
1026
Jon Hall94fd0472014-12-08 11:52:42 -08001027 #Assert that each device has a master
1028 ONOS1_master_not_null = main.ONOScli1.roles_not_null()
1029 ONOS2_master_not_null = main.ONOScli2.roles_not_null()
1030 ONOS3_master_not_null = main.ONOScli3.roles_not_null()
1031 ONOS4_master_not_null = main.ONOScli4.roles_not_null()
1032 ONOS5_master_not_null = main.ONOScli5.roles_not_null()
1033 ONOS6_master_not_null = main.ONOScli6.roles_not_null()
1034 ONOS7_master_not_null = main.ONOScli7.roles_not_null()
1035 roles_not_null = ONOS1_master_not_null and ONOS2_master_not_null and\
1036 ONOS3_master_not_null and ONOS4_master_not_null and\
1037 ONOS5_master_not_null and ONOS6_master_not_null and\
1038 ONOS7_master_not_null
1039 utilities.assert_equals(expect = main.TRUE,actual=roles_not_null,
1040 onpass="Each device has a master",
1041 onfail="Some devices don't have a master assigned")
1042
1043
1044
Jon Hall73cf9cc2014-11-20 22:28:38 -08001045 main.step("Check if switch roles are consistent across all nodes")
1046 ONOS1_mastership = main.ONOScli1.roles()
1047 ONOS2_mastership = main.ONOScli2.roles()
1048 ONOS3_mastership = main.ONOScli3.roles()
1049 ONOS4_mastership = main.ONOScli4.roles()
1050 ONOS5_mastership = main.ONOScli5.roles()
1051 ONOS6_mastership = main.ONOScli6.roles()
1052 ONOS7_mastership = main.ONOScli7.roles()
Jon Hall73cf9cc2014-11-20 22:28:38 -08001053 #print json.dumps(json.loads(ONOS1_mastership), sort_keys=True, indent=4, separators=(',', ': '))
1054 if "Error" in ONOS1_mastership or not ONOS1_mastership\
1055 or "Error" in ONOS2_mastership or not ONOS2_mastership\
1056 or "Error" in ONOS3_mastership or not ONOS3_mastership\
1057 or "Error" in ONOS4_mastership or not ONOS4_mastership\
1058 or "Error" in ONOS5_mastership or not ONOS5_mastership\
1059 or "Error" in ONOS6_mastership or not ONOS6_mastership\
1060 or "Error" in ONOS7_mastership or not ONOS7_mastership:
1061 main.log.error("Error in getting ONOS mastership")
1062 main.log.warn("ONOS1 mastership response: " + repr(ONOS1_mastership))
1063 main.log.warn("ONOS2 mastership response: " + repr(ONOS2_mastership))
1064 main.log.warn("ONOS3 mastership response: " + repr(ONOS3_mastership))
1065 main.log.warn("ONOS4 mastership response: " + repr(ONOS4_mastership))
1066 main.log.warn("ONOS5 mastership response: " + repr(ONOS5_mastership))
1067 main.log.warn("ONOS6 mastership response: " + repr(ONOS6_mastership))
1068 main.log.warn("ONOS7 mastership response: " + repr(ONOS7_mastership))
1069 consistent_mastership = main.FALSE
1070 elif ONOS1_mastership == ONOS2_mastership\
1071 and ONOS1_mastership == ONOS3_mastership\
1072 and ONOS1_mastership == ONOS4_mastership\
1073 and ONOS1_mastership == ONOS5_mastership\
1074 and ONOS1_mastership == ONOS6_mastership\
1075 and ONOS1_mastership == ONOS7_mastership:
Jon Hall73cf9cc2014-11-20 22:28:38 -08001076 consistent_mastership = main.TRUE
1077 main.log.report("Switch roles are consistent across all ONOS nodes")
1078 else:
1079 main.log.warn("ONOS1 roles: ", json.dumps(json.loads(ONOS1_mastership),
1080 sort_keys=True, indent=4, separators=(',', ': ')))
1081 main.log.warn("ONOS2 roles: ", json.dumps(json.loads(ONOS2_mastership),
1082 sort_keys=True, indent=4, separators=(',', ': ')))
1083 main.log.warn("ONOS3 roles: ", json.dumps(json.loads(ONOS3_mastership),
1084 sort_keys=True, indent=4, separators=(',', ': ')))
1085 main.log.warn("ONOS4 roles: ", json.dumps(json.loads(ONOS4_mastership),
1086 sort_keys=True, indent=4, separators=(',', ': ')))
1087 main.log.warn("ONOS5 roles: ", json.dumps(json.loads(ONOS5_mastership),
1088 sort_keys=True, indent=4, separators=(',', ': ')))
1089 main.log.warn("ONOS6 roles: ", json.dumps(json.loads(ONOS6_mastership),
1090 sort_keys=True, indent=4, separators=(',', ': ')))
1091 main.log.warn("ONOS7 roles: ", json.dumps(json.loads(ONOS7_mastership),
1092 sort_keys=True, indent=4, separators=(',', ': ')))
1093 consistent_mastership = main.FALSE
1094 utilities.assert_equals(expect = main.TRUE,actual=consistent_mastership,
1095 onpass="Switch roles are consistent across all ONOS nodes",
1096 onfail="ONOS nodes have different views of switch roles")
1097
1098
1099 description2 = "Compare switch roles from before failure"
1100 main.step(description2)
1101
1102 current_json = json.loads(ONOS1_mastership)
1103 old_json = json.loads(mastership_state)
1104 mastership_check = main.TRUE
1105 for i in range(1,29):
1106 switchDPID = str(main.Mininet1.getSwitchDPID(switch="s"+str(i)))
1107
1108 current = [switch['master'] for switch in current_json if switchDPID in switch['id']]
1109 old = [switch['master'] for switch in old_json if switchDPID in switch['id']]
1110 if current == old:
1111 mastership_check = mastership_check and main.TRUE
1112 else:
1113 main.log.warn("Mastership of switch %s changed" % switchDPID)
1114 mastership_check = main.FALSE
1115 if mastership_check == main.TRUE:
1116 main.log.report("Mastership of Switches was not changed")
1117 utilities.assert_equals(expect=main.TRUE,actual=mastership_check,
1118 onpass="Mastership of Switches was not changed",
1119 onfail="Mastership of some switches changed")
1120 #NOTE: we expect mastership to change on controller failure
Jon Hall669173b2014-12-17 11:36:30 -08001121 mastership_check = consistent_mastership
Jon Hall73cf9cc2014-11-20 22:28:38 -08001122
1123
1124
1125 main.step("Get the intents and compare across all nodes")
1126 ONOS1_intents = main.ONOScli1.intents( json_format=True )
1127 ONOS2_intents = main.ONOScli2.intents( json_format=True )
1128 ONOS3_intents = main.ONOScli3.intents( json_format=True )
1129 ONOS4_intents = main.ONOScli4.intents( json_format=True )
1130 ONOS5_intents = main.ONOScli5.intents( json_format=True )
1131 ONOS6_intents = main.ONOScli6.intents( json_format=True )
1132 ONOS7_intents = main.ONOScli7.intents( json_format=True )
1133 intent_check = main.FALSE
1134 if "Error" in ONOS1_intents or not ONOS1_intents\
1135 or "Error" in ONOS2_intents or not ONOS2_intents\
1136 or "Error" in ONOS3_intents or not ONOS3_intents\
1137 or "Error" in ONOS4_intents or not ONOS4_intents\
1138 or "Error" in ONOS5_intents or not ONOS5_intents\
1139 or "Error" in ONOS6_intents or not ONOS6_intents\
1140 or "Error" in ONOS7_intents or not ONOS7_intents:
1141 main.log.report("Error in getting ONOS intents")
1142 main.log.warn("ONOS1 intents response: " + repr(ONOS1_intents))
1143 main.log.warn("ONOS2 intents response: " + repr(ONOS2_intents))
1144 main.log.warn("ONOS3 intents response: " + repr(ONOS3_intents))
1145 main.log.warn("ONOS4 intents response: " + repr(ONOS4_intents))
1146 main.log.warn("ONOS5 intents response: " + repr(ONOS5_intents))
1147 main.log.warn("ONOS6 intents response: " + repr(ONOS6_intents))
1148 main.log.warn("ONOS7 intents response: " + repr(ONOS7_intents))
1149 elif ONOS1_intents == ONOS2_intents\
1150 and ONOS1_intents == ONOS3_intents\
1151 and ONOS1_intents == ONOS4_intents\
1152 and ONOS1_intents == ONOS5_intents\
1153 and ONOS1_intents == ONOS6_intents\
1154 and ONOS1_intents == ONOS7_intents:
1155 intent_check = main.TRUE
1156 main.log.report("Intents are consistent across all ONOS nodes")
1157 else:
Jon Hall669173b2014-12-17 11:36:30 -08001158 main.log.warn("ONOS1 intents: ")
Jon Hall94fd0472014-12-08 11:52:42 -08001159 print json.dumps(json.loads(ONOS1_intents),
1160 sort_keys=True, indent=4, separators=(',', ': '))
1161 main.log.warn("ONOS2 intents: ")
1162 print json.dumps(json.loads(ONOS2_intents),
1163 sort_keys=True, indent=4, separators=(',', ': '))
1164 main.log.warn("ONOS3 intents: ")
1165 print json.dumps(json.loads(ONOS3_intents),
1166 sort_keys=True, indent=4, separators=(',', ': '))
1167 main.log.warn("ONOS4 intents: ")
1168 print json.dumps(json.loads(ONOS4_intents),
1169 sort_keys=True, indent=4, separators=(',', ': '))
1170 main.log.warn("ONOS5 intents: ")
1171 print json.dumps(json.loads(ONOS5_intents),
1172 sort_keys=True, indent=4, separators=(',', ': '))
1173 main.log.warn("ONOS6 intents: ")
1174 print json.dumps(json.loads(ONOS6_intents),
1175 sort_keys=True, indent=4, separators=(',', ': '))
1176 main.log.warn("ONOS7 intents: ")
1177 print json.dumps(json.loads(ONOS7_intents),
1178 sort_keys=True, indent=4, separators=(',', ': '))
Jon Hall73cf9cc2014-11-20 22:28:38 -08001179 utilities.assert_equals(expect = main.TRUE,actual=intent_check,
1180 onpass="Intents are consistent across all ONOS nodes",
1181 onfail="ONOS nodes have different views of intents")
1182
Jon Hall669173b2014-12-17 11:36:30 -08001183 #NOTE: Hazelcast has no durability, so intents are lost across system restarts
Jon Hall73cf9cc2014-11-20 22:28:38 -08001184 main.step("Compare current intents with intents before the failure")
Jon Hall94fd0472014-12-08 11:52:42 -08001185 #NOTE: this requires case 5 to pass for intent_state to be set.
1186 # maybe we should stop the test if that fails?
Jon Hall73cf9cc2014-11-20 22:28:38 -08001187 if intent_state == ONOS1_intents:
1188 same_intents = main.TRUE
1189 main.log.report("Intents are consistent with before failure")
1190 #TODO: possibly the states have changed? we may need to figure out what the aceptable states are
1191 else:
Jon Hall669173b2014-12-17 11:36:30 -08001192 try:
1193 main.log.warn("ONOS1 intents: ")
1194 print json.dumps(json.loads(ONOS1_intents),
1195 sort_keys=True, indent=4, separators=(',', ': '))
1196 except:
1197 pass
Jon Hall73cf9cc2014-11-20 22:28:38 -08001198 same_intents = main.FALSE
1199 utilities.assert_equals(expect = main.TRUE,actual=same_intents,
1200 onpass="Intents are consistent with before failure",
1201 onfail="The Intents changed during failure")
1202 intent_check = intent_check and same_intents
1203
1204
1205
1206 main.step("Get the OF Table entries and compare to before component failure")
1207 Flow_Tables = main.TRUE
1208 flows2=[]
1209 for i in range(28):
1210 main.log.info("Checking flow table on s" + str(i+1))
Jon Hall94fd0472014-12-08 11:52:42 -08001211 tmp_flows = main.Mininet2.get_flowTable(1.3, "s"+str(i+1))
Jon Hall73cf9cc2014-11-20 22:28:38 -08001212 flows2.append(tmp_flows)
Jon Hall94fd0472014-12-08 11:52:42 -08001213 temp_result = main.Mininet2.flow_comp(flow1=flows[i],flow2=tmp_flows)
1214 Flow_Tables = Flow_Tables and temp_result
Jon Hall73cf9cc2014-11-20 22:28:38 -08001215 if Flow_Tables == main.FALSE:
1216 main.log.info("Differences in flow table for switch: "+str(i+1))
Jon Hall73cf9cc2014-11-20 22:28:38 -08001217 if Flow_Tables == main.TRUE:
1218 main.log.report("No changes were found in the flow tables")
1219 utilities.assert_equals(expect=main.TRUE,actual=Flow_Tables,
1220 onpass="No changes were found in the flow tables",
1221 onfail="Changes were found in the flow tables")
1222
1223 main.step("Check the continuous pings to ensure that no packets were dropped during component failure")
1224 #FIXME: This check is always failing. Investigate cause
1225 #NOTE: this may be something to do with file permsissions
1226 # or slight change in format
1227 main.Mininet2.pingKill(main.params['TESTONUSER'], main.params['TESTONIP'])
1228 Loss_In_Pings = main.FALSE
1229 #NOTE: checkForLoss returns main.FALSE with 0% packet loss
1230 for i in range(8,18):
1231 main.log.info("Checking for a loss in pings along flow from s" + str(i))
Jon Hall94fd0472014-12-08 11:52:42 -08001232 Loss_In_Pings = main.Mininet2.checkForLoss("/tmp/ping.h"+str(i)) or Loss_In_Pings
Jon Hall73cf9cc2014-11-20 22:28:38 -08001233 if Loss_In_Pings == main.TRUE:
1234 main.log.info("Loss in ping detected")
1235 elif Loss_In_Pings == main.ERROR:
1236 main.log.info("There are multiple mininet process running")
1237 elif Loss_In_Pings == main.FALSE:
1238 main.log.info("No Loss in the pings")
1239 main.log.report("No loss of dataplane connectivity")
1240 utilities.assert_equals(expect=main.FALSE,actual=Loss_In_Pings,
1241 onpass="No Loss of connectivity",
1242 onfail="Loss of dataplane connectivity detected")
1243
1244
Jon Hall669173b2014-12-17 11:36:30 -08001245 #Test of LeadershipElection
1246 leader_list = []
1247 leader_result = main.TRUE
1248 for controller in range(1,num_controllers+1):
1249 node = getattr( main, ( 'ONOScli' + str( controller ) ) )#loop through ONOScli handlers
1250 leaderN = node.election_test_leader()
1251 leader_list.append(leaderN)
1252 if leaderN == main.FALSE:
1253 #error in response
1254 main.log.report("Something is wrong with election_test_leader function, check the error logs")
1255 leader_result = main.FALSE
1256 elif leaderN == None:
1257 main.log.report("ONOS"+str(controller) + " shows no leader for the election-app was elected after the old one died")
1258 leader_result = main.FALSE
1259 elif leaderN == ONOS1_ip or leaderN == ONOS2_ip or leaderN == ONOS3_ip:
1260 main.log.report("ONOS"+str(controller) + " shows "+str(leaderN)+" as leader for the election-app, but it was restarted")
1261 leader_result = main.FALSE
1262 if len( set( leader_list ) ) != 1:
1263 leader_result = main.FALSE
1264 main.log.error("Inconsistent view of leader for the election test app")
1265 #TODO: print the list
1266 if leader_result:
1267 main.log.report("Leadership election tests passed(consistent view of leader across listeners and a new leader was re-elected if applicable)")
1268 utilities.assert_equals(expect=main.TRUE, actual=leader_result,
1269 onpass="Leadership election passed",
1270 onfail="Something went wrong with Leadership election")
1271
1272
1273 result = mastership_check and intent_check and Flow_Tables and (not Loss_In_Pings) and roles_not_null\
1274 and leader_result
Jon Hall73cf9cc2014-11-20 22:28:38 -08001275 result = int(result)
1276 if result == main.TRUE:
1277 main.log.report("Constant State Tests Passed")
1278 utilities.assert_equals(expect=main.TRUE,actual=result,
1279 onpass="Constant State Tests Passed",
1280 onfail="Constant state tests failed")
1281
1282 def CASE8 (self,main):
1283 '''
1284 Compare topo
1285 '''
1286 import sys
1287 sys.path.append("/home/admin/sts") # Trying to remove some dependancies, #FIXME add this path to params
1288 from sts.topology.teston_topology import TestONTopology # assumes that sts is already in you PYTHONPATH
1289 import json
1290 import time
1291
1292 description ="Compare ONOS Topology view to Mininet topology"
1293 main.case(description)
1294 main.log.report(description)
1295 main.step("Create TestONTopology object")
1296 ctrls = []
1297 count = 1
1298 while True:
1299 temp = ()
1300 if ('ip' + str(count)) in main.params['CTRL']:
1301 temp = temp + (getattr(main,('ONOS' + str(count))),)
1302 temp = temp + ("ONOS"+str(count),)
1303 temp = temp + (main.params['CTRL']['ip'+str(count)],)
1304 temp = temp + (eval(main.params['CTRL']['port'+str(count)]),)
1305 ctrls.append(temp)
1306 count = count + 1
1307 else:
1308 break
1309 MNTopo = TestONTopology(main.Mininet1, ctrls) # can also add Intent API info for intent operations
1310
Jon Hall73cf9cc2014-11-20 22:28:38 -08001311 main.step("Comparing ONOS topology to MN")
1312 devices_results = main.TRUE
1313 ports_results = main.TRUE
1314 links_results = main.TRUE
1315 topo_result = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001316 elapsed = 0
Jon Hallffb386d2014-11-21 13:43:38 -08001317 count = 0
Jon Hall94fd0472014-12-08 11:52:42 -08001318 main.step("Collecting topology information from ONOS")
1319 start_time = time.time()
1320 while topo_result == main.FALSE and elapsed < 60:
Jon Hallffb386d2014-11-21 13:43:38 -08001321 count = count + 1
Jon Hall94fd0472014-12-08 11:52:42 -08001322 if count > 1:
1323 MNTopo = TestONTopology(main.Mininet1, ctrls) # can also add Intent API info for intent operations
1324 cli_start = time.time()
1325 devices = []
1326 devices.append( main.ONOScli1.devices() )
1327 devices.append( main.ONOScli2.devices() )
1328 devices.append( main.ONOScli3.devices() )
1329 devices.append( main.ONOScli4.devices() )
1330 devices.append( main.ONOScli5.devices() )
1331 devices.append( main.ONOScli6.devices() )
1332 devices.append( main.ONOScli7.devices() )
1333 hosts = []
Jon Hall669173b2014-12-17 11:36:30 -08001334 hosts.append( json.loads( main.ONOScli1.hosts() ) )
1335 hosts.append( json.loads( main.ONOScli2.hosts() ) )
1336 hosts.append( json.loads( main.ONOScli3.hosts() ) )
1337 hosts.append( json.loads( main.ONOScli4.hosts() ) )
1338 hosts.append( json.loads( main.ONOScli5.hosts() ) )
1339 hosts.append( json.loads( main.ONOScli6.hosts() ) )
1340 hosts.append( json.loads( main.ONOScli7.hosts() ) )
1341 for controller in range(0, len(hosts) ):
1342 for host in hosts[controller]:
1343 host
1344 if host['ips'] == []:
1345 main.log.error("DEBUG:Error with host ips on controller"+str(controller+1)+": " + str(host))
Jon Hall94fd0472014-12-08 11:52:42 -08001346 ports = []
1347 ports.append( main.ONOScli1.ports() )
1348 ports.append( main.ONOScli2.ports() )
1349 ports.append( main.ONOScli3.ports() )
1350 ports.append( main.ONOScli4.ports() )
1351 ports.append( main.ONOScli5.ports() )
1352 ports.append( main.ONOScli6.ports() )
1353 ports.append( main.ONOScli7.ports() )
1354 links = []
1355 links.append( main.ONOScli1.links() )
1356 links.append( main.ONOScli2.links() )
1357 links.append( main.ONOScli3.links() )
1358 links.append( main.ONOScli4.links() )
1359 links.append( main.ONOScli5.links() )
1360 links.append( main.ONOScli6.links() )
1361 links.append( main.ONOScli7.links() )
1362 clusters = []
1363 clusters.append( main.ONOScli1.clusters() )
1364 clusters.append( main.ONOScli2.clusters() )
1365 clusters.append( main.ONOScli3.clusters() )
1366 clusters.append( main.ONOScli4.clusters() )
1367 clusters.append( main.ONOScli5.clusters() )
1368 clusters.append( main.ONOScli6.clusters() )
1369 clusters.append( main.ONOScli7.clusters() )
1370 paths = []
1371 temp_topo = main.ONOSbench.get_topology( main.ONOScli1.topology() )
1372 paths.append( temp_topo.get('paths', False) )
1373 temp_topo = main.ONOSbench.get_topology( main.ONOScli2.topology() )
1374 paths.append( temp_topo.get('paths', False) )
1375 temp_topo = main.ONOSbench.get_topology( main.ONOScli3.topology() )
1376 paths.append( temp_topo.get('paths', False) )
1377 temp_topo = main.ONOSbench.get_topology( main.ONOScli4.topology() )
1378 paths.append( temp_topo.get('paths', False) )
1379 temp_topo = main.ONOSbench.get_topology( main.ONOScli5.topology() )
1380 paths.append( temp_topo.get('paths', False) )
1381 temp_topo = main.ONOSbench.get_topology( main.ONOScli6.topology() )
1382 paths.append( temp_topo.get('paths', False) )
1383 temp_topo = main.ONOSbench.get_topology( main.ONOScli7.topology() )
1384 paths.append( temp_topo.get('paths', False) )
Jon Hallffb386d2014-11-21 13:43:38 -08001385
Jon Hall73cf9cc2014-11-20 22:28:38 -08001386
Jon Hall94fd0472014-12-08 11:52:42 -08001387 elapsed = time.time() - start_time
1388 cli_time = time.time() - cli_start
1389 print "CLI time: " + str(cli_time)
Jon Hall73cf9cc2014-11-20 22:28:38 -08001390
Jon Hall669173b2014-12-17 11:36:30 -08001391 for controller in range(num_controllers):
Jon Hall94fd0472014-12-08 11:52:42 -08001392 if devices[controller] or not "Error" in devices[controller]:
1393 current_devices_result = main.Mininet1.compare_switches(MNTopo, json.loads(devices[controller]))
1394 else:
1395 current_devices_result = main.FALSE
1396 utilities.assert_equals(expect=main.TRUE, actual=current_devices_result,
1397 onpass="ONOS"+str(int(controller+1))+" Switches view is correct",
1398 onfail="ONOS"+str(int(controller+1))+" Switches view is incorrect")
Jon Hall73cf9cc2014-11-20 22:28:38 -08001399
Jon Hall94fd0472014-12-08 11:52:42 -08001400 if ports[controller] or not "Error" in ports[controller]:
1401 current_ports_result = main.Mininet1.compare_ports(MNTopo, json.loads(ports[controller]))
1402 else:
1403 current_ports_result = main.FALSE
1404 utilities.assert_equals(expect=main.TRUE, actual=current_ports_result,
1405 onpass="ONOS"+str(int(controller+1))+" ports view is correct",
1406 onfail="ONOS"+str(int(controller+1))+" ports view is incorrect")
1407
1408 if links[controller] or not "Error" in links[controller]:
1409 current_links_result = main.Mininet1.compare_links(MNTopo, json.loads(links[controller]))
1410 else:
1411 current_links_result = main.FALSE
1412 utilities.assert_equals(expect=main.TRUE, actual=current_links_result,
1413 onpass="ONOS"+str(int(controller+1))+" links view is correct",
1414 onfail="ONOS"+str(int(controller+1))+" links view is incorrect")
Jon Hall73cf9cc2014-11-20 22:28:38 -08001415 devices_results = devices_results and current_devices_result
1416 ports_results = ports_results and current_ports_result
1417 links_results = links_results and current_links_result
Jon Hall94fd0472014-12-08 11:52:42 -08001418
1419 #Compare json objects for hosts, dataplane clusters and paths
1420
1421 #hosts
1422 consistent_hosts_result = main.TRUE
1423 for controller in range( len( hosts ) ):
1424 if not "Error" in hosts[controller]:
1425 if hosts[controller] == hosts[0]:
1426 continue
1427 else:#hosts not consistent
1428 main.log.report("hosts from ONOS" + str(controller + 1) + " is inconsistent with ONOS1")
1429 main.log.warn( repr( hosts[controller] ) )
1430 consistent_hosts_result = main.FALSE
1431
1432 else:
1433 main.log.report("Error in getting ONOS hosts from ONOS" + str(controller + 1) )
1434 consistent_hosts_result = main.FALSE
1435 if consistent_hosts_result == main.FALSE:
1436 for controller in range( len( hosts ) ):
1437 main.log.warn("ONOS" + str(controller + 1) + " hosts response: " + repr(hosts[controller]) )
1438 utilities.assert_equals(expect = main.TRUE,actual=consistent_hosts_result,
1439 onpass="Hosts view is consistent across all ONOS nodes",
1440 onfail="ONOS nodes have different views of hosts")
1441
1442 #Strongly connected clusters of devices
1443 consistent_clusters_result = main.TRUE
1444 for controller in range( len( clusters ) ):
1445 if not "Error" in clusters[controller]:
1446 if clusters[controller] == clusters[0]:
1447 continue
1448 else:#clusters not consistent
1449 main.log.report("clusters from ONOS" + str(controller + 1) + " is inconsistent with ONOS1")
1450 consistent_clusters_result = main.FALSE
1451
1452 else:
1453 main.log.report("Error in getting dataplane clusters from ONOS" + str(controller + 1) )
1454 consistent_clusters_result = main.FALSE
1455 main.log.warn("ONOS" + str(controller + 1) + " clusters response: " + repr(clusters[controller]) )
1456 utilities.assert_equals(expect = main.TRUE,actual=consistent_clusters_result,
1457 onpass="Clusters view is consistent across all ONOS nodes",
1458 onfail="ONOS nodes have different views of clusters")
1459 num_clusters = len(json.loads(clusters[0])) #there should always only be one cluster
1460 utilities.assert_equals(expect = 1, actual = num_clusters,
1461 onpass="ONOS shows 1 SCC",
1462 onfail="ONOS shows "+str(num_clusters) +" SCCs")
1463
1464
1465 #paths
1466 consistent_paths_result = main.TRUE
1467 for controller in range( len( paths ) ):
1468 if not "Error" in paths[controller]:
1469 if paths[controller] == paths[0]:
1470 continue
1471 else:#paths not consistent
1472 main.log.report("paths from ONOS" + str(controller + 1) + " is inconsistent with ONOS1")
1473 consistent_paths_result = main.FALSE
1474
1475 else:
1476 main.log.report("Error in getting paths from ONOS" + str(controller + 1) )
1477 consistent_paths_result = main.FALSE
1478 main.log.warn("ONOS" + str(controller + 1) + " paths response: " + repr(paths[controller]) )
1479 utilities.assert_equals(expect = main.TRUE,actual=consistent_paths_result,
1480 onpass="Paths count is consistent across all ONOS nodes",
1481 onfail="ONOS nodes have different counts of paths")
1482
1483
1484 topo_result = devices_results and ports_results and links_results\
1485 and consistent_hosts_result and consistent_clusters_result and consistent_paths_result
1486
1487 topo_result = topo_result and int(count <= 2)
1488 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"
1489 main.log.report("Very crass estimate for topology discovery/convergence("+ str(note) + "): " +\
Jon Hallffb386d2014-11-21 13:43:38 -08001490 str(elapsed) + " seconds, " + str(count) +" tries" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001491 utilities.assert_equals(expect=main.TRUE, actual=topo_result,
1492 onpass="Topology Check Test successful",
1493 onfail="Topology Check Test NOT successful")
1494 if topo_result == main.TRUE:
1495 main.log.report("ONOS topology view matches Mininet topology")
1496
1497
1498 def CASE9 (self,main):
1499 '''
1500 Link s3-s28 down
1501 '''
1502 #NOTE: You should probably run a topology check after this
1503
Jon Hall669173b2014-12-17 11:36:30 -08001504 link_sleep = float(main.params['timers']['LinkDiscovery'])
Jon Hall73cf9cc2014-11-20 22:28:38 -08001505
1506 description = "Turn off a link to ensure that Link Discovery is working properly"
1507 main.log.report(description)
1508 main.case(description)
1509
1510
1511 main.step("Kill Link between s3 and s28")
1512 Link_Down = main.Mininet1.link(END1="s3",END2="s28",OPTION="down")
1513 main.log.info("Waiting " + str(link_sleep) + " seconds for link down to be discovered")
1514 time.sleep(link_sleep)
1515 utilities.assert_equals(expect=main.TRUE,actual=Link_Down,
1516 onpass="Link down succesful",
1517 onfail="Failed to bring link down")
1518 #TODO do some sort of check here
1519
1520 def CASE10 (self,main):
1521 '''
1522 Link s3-s28 up
1523 '''
1524 #NOTE: You should probably run a topology check after this
1525
Jon Hall669173b2014-12-17 11:36:30 -08001526 link_sleep = float(main.params['timers']['LinkDiscovery'])
Jon Hall73cf9cc2014-11-20 22:28:38 -08001527
1528 description = "Restore a link to ensure that Link Discovery is working properly"
1529 main.log.report(description)
1530 main.case(description)
1531
1532 main.step("Bring link between s3 and s28 back up")
1533 Link_Up = main.Mininet1.link(END1="s3",END2="s28",OPTION="up")
1534 main.log.info("Waiting " + str(link_sleep) + " seconds for link up to be discovered")
1535 time.sleep(link_sleep)
1536 utilities.assert_equals(expect=main.TRUE,actual=Link_Up,
1537 onpass="Link up succesful",
1538 onfail="Failed to bring link up")
1539 #TODO do some sort of check here
1540
1541
1542 def CASE11 (self, main) :
1543 '''
1544 Switch Down
1545 '''
1546 #NOTE: You should probably run a topology check after this
1547 import time
1548
Jon Hall669173b2014-12-17 11:36:30 -08001549 switch_sleep = float(main.params['timers']['SwitchDiscovery'])
Jon Hall73cf9cc2014-11-20 22:28:38 -08001550
1551 description = "Killing a switch to ensure it is discovered correctly"
1552 main.log.report(description)
1553 main.case(description)
1554
1555 #TODO: Make this switch parameterizable
1556 main.step("Kill s28 ")
1557 main.log.report("Deleting s28")
Jon Hall73cf9cc2014-11-20 22:28:38 -08001558 main.Mininet1.del_switch("s28")
1559 main.log.info("Waiting " + str(switch_sleep) + " seconds for switch down to be discovered")
1560 time.sleep(switch_sleep)
Jon Hall94fd0472014-12-08 11:52:42 -08001561 device = main.ONOScli1.get_device(dpid="0028")
Jon Hall73cf9cc2014-11-20 22:28:38 -08001562 #Peek at the deleted switch
Jon Hall94fd0472014-12-08 11:52:42 -08001563 main.log.warn( str(device) )
1564 result = main.FALSE
1565 if device and device['available'] == False:
1566 result = main.TRUE
1567 utilities.assert_equals(expect=main.TRUE,actual=result,
1568 onpass="Kill switch succesful",
1569 onfail="Failed to kill switch?")
Jon Hall73cf9cc2014-11-20 22:28:38 -08001570
1571 def CASE12 (self, main) :
1572 '''
1573 Switch Up
1574 '''
1575 #NOTE: You should probably run a topology check after this
1576 import time
Jon Hall669173b2014-12-17 11:36:30 -08001577
1578 switch_sleep = float(main.params['timers']['SwitchDiscovery'])
Jon Hall73cf9cc2014-11-20 22:28:38 -08001579 description = "Adding a switch to ensure it is discovered correctly"
1580 main.log.report(description)
1581 main.case(description)
1582
1583 main.step("Add back s28")
1584 main.log.report("Adding back s28")
1585 main.Mininet1.add_switch("s28", dpid = '0000000000002800')
1586 #TODO: New dpid or same? Ask Thomas?
1587 main.Mininet1.add_link('s28', 's3')
1588 main.Mininet1.add_link('s28', 's6')
1589 main.Mininet1.add_link('s28', 'h28')
Jon Hall669173b2014-12-17 11:36:30 -08001590 main.Mininet1.assign_sw_controller(sw="28",count=num_controllers,
Jon Hall73cf9cc2014-11-20 22:28:38 -08001591 ip1=ONOS1_ip,port1=ONOS1_port,
1592 ip2=ONOS2_ip,port2=ONOS2_port,
1593 ip3=ONOS3_ip,port3=ONOS3_port,
1594 ip4=ONOS4_ip,port4=ONOS4_port,
1595 ip5=ONOS5_ip,port5=ONOS5_port,
1596 ip6=ONOS6_ip,port6=ONOS6_port,
1597 ip7=ONOS7_ip,port7=ONOS7_port)
1598 main.log.info("Waiting " + str(switch_sleep) + " seconds for switch up to be discovered")
1599 time.sleep(switch_sleep)
Jon Hall94fd0472014-12-08 11:52:42 -08001600 device = main.ONOScli1.get_device(dpid="0028")
1601 #Peek at the deleted switch
1602 main.log.warn( str(device) )
1603 result = main.FALSE
1604 if device and device['available'] == True:
1605 result = main.TRUE
1606 utilities.assert_equals(expect=main.TRUE,actual=result,
1607 onpass="add switch succesful",
1608 onfail="Failed to add switch?")
Jon Hall73cf9cc2014-11-20 22:28:38 -08001609
1610 def CASE13 (self, main) :
1611 '''
1612 Clean up
1613 '''
1614 import os
1615 import time
Jon Hall669173b2014-12-17 11:36:30 -08001616 #printing colors to terminal
1617 colors = {}
1618 colors['cyan'] = '\033[96m'
1619 colors['purple'] = '\033[95m'
1620 colors['blue'] = '\033[94m'
1621 colors['green'] = '\033[92m'
1622 colors['yellow'] = '\033[93m'
1623 colors['red'] = '\033[91m'
1624 colors['end'] = '\033[0m'
Jon Hall73cf9cc2014-11-20 22:28:38 -08001625 description = "Test Cleanup"
1626 main.log.report(description)
1627 main.case(description)
1628 main.step("Killing tcpdumps")
1629 main.Mininet2.stop_tcpdump()
1630
Jon Hall94fd0472014-12-08 11:52:42 -08001631 main.step("Checking ONOS Logs for errors")
Jon Hall669173b2014-12-17 11:36:30 -08001632 print colors['purple'] + "Checking logs for errors on ONOS1:" + colors['end']
Jon Hall94fd0472014-12-08 11:52:42 -08001633 print main.ONOSbench.check_logs(ONOS1_ip)
Jon Hall669173b2014-12-17 11:36:30 -08001634 print colors['purple'] + "Checking logs for errors on ONOS2:" + colors['end']
Jon Hall94fd0472014-12-08 11:52:42 -08001635 print main.ONOSbench.check_logs(ONOS2_ip)
Jon Hall669173b2014-12-17 11:36:30 -08001636 print colors['purple'] + "Checking logs for errors on ONOS3:" + colors['end']
Jon Hall94fd0472014-12-08 11:52:42 -08001637 print main.ONOSbench.check_logs(ONOS3_ip)
Jon Hall669173b2014-12-17 11:36:30 -08001638 print colors['purple'] + "Checking logs for errors on ONOS4:" + colors['end']
Jon Hall94fd0472014-12-08 11:52:42 -08001639 print main.ONOSbench.check_logs(ONOS4_ip)
Jon Hall669173b2014-12-17 11:36:30 -08001640 print colors['purple'] + "Checking logs for errors on ONOS5:" + colors['end']
Jon Hall94fd0472014-12-08 11:52:42 -08001641 print main.ONOSbench.check_logs(ONOS5_ip)
Jon Hall669173b2014-12-17 11:36:30 -08001642 print colors['purple'] + "Checking logs for errors on ONOS6:" + colors['end']
Jon Hall94fd0472014-12-08 11:52:42 -08001643 print main.ONOSbench.check_logs(ONOS6_ip)
Jon Hall669173b2014-12-17 11:36:30 -08001644 print colors['purple'] + "Checking logs for errors on ONOS7:" + colors['end']
Jon Hall94fd0472014-12-08 11:52:42 -08001645 print main.ONOSbench.check_logs(ONOS7_ip)
1646
Jon Hall73cf9cc2014-11-20 22:28:38 -08001647 main.step("Copying MN pcap and ONOS log files to test station")
1648 testname = main.TEST
Jon Hall94fd0472014-12-08 11:52:42 -08001649 teststation_user = main.params['TESTONUSER']
1650 teststation_IP = main.params['TESTONIP']
Jon Hall73cf9cc2014-11-20 22:28:38 -08001651 #NOTE: MN Pcap file is being saved to ~/packet_captures
1652 # scp this file as MN and TestON aren't necessarily the same vm
1653 #FIXME: scp
1654 #####mn files
1655 #TODO: Load these from params
1656 #NOTE: must end in /
1657 log_folder = "/opt/onos/log/"
1658 log_files = ["karaf.log", "karaf.log.1"]
1659 #NOTE: must end in /
1660 dst_dir = "~/packet_captures/"
1661 for f in log_files:
Jon Hall94fd0472014-12-08 11:52:42 -08001662 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS1_ip+":"+log_folder+f+" "+
1663 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001664 dst_dir + str(testname) + "-ONOS1-"+f )
Jon Hall94fd0472014-12-08 11:52:42 -08001665 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS2_ip+":"+log_folder+f+" "+
1666 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001667 dst_dir + str(testname) + "-ONOS2-"+f )
Jon Hall94fd0472014-12-08 11:52:42 -08001668 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS3_ip+":"+log_folder+f+" "+
1669 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001670 dst_dir + str(testname) + "-ONOS3-"+f )
Jon Hall94fd0472014-12-08 11:52:42 -08001671 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS4_ip+":"+log_folder+f+" "+
1672 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001673 dst_dir + str(testname) + "-ONOS4-"+f )
Jon Hall94fd0472014-12-08 11:52:42 -08001674 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS5_ip+":"+log_folder+f+" "+
1675 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001676 dst_dir + str(testname) + "-ONOS5-"+f )
Jon Hall94fd0472014-12-08 11:52:42 -08001677 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS6_ip+":"+log_folder+f+" "+
1678 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001679 dst_dir + str(testname) + "-ONOS6-"+f )
Jon Hall94fd0472014-12-08 11:52:42 -08001680 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS7_ip+":"+log_folder+f+" "+
1681 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001682 dst_dir + str(testname) + "-ONOS7-"+f )
1683
1684 #std*.log's
1685 #NOTE: must end in /
1686 log_folder = "/opt/onos/var/"
1687 log_files = ["stderr.log", "stdout.log"]
1688 #NOTE: must end in /
1689 dst_dir = "~/packet_captures/"
1690 for f in log_files:
Jon Hall94fd0472014-12-08 11:52:42 -08001691 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS1_ip+":"+log_folder+f+" "+
1692 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001693 dst_dir + str(testname) + "-ONOS1-"+f )
Jon Hall94fd0472014-12-08 11:52:42 -08001694 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS2_ip+":"+log_folder+f+" "+
1695 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001696 dst_dir + str(testname) + "-ONOS2-"+f )
Jon Hall94fd0472014-12-08 11:52:42 -08001697 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS3_ip+":"+log_folder+f+" "+
1698 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001699 dst_dir + str(testname) + "-ONOS3-"+f )
Jon Hall94fd0472014-12-08 11:52:42 -08001700 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS4_ip+":"+log_folder+f+" "+
1701 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001702 dst_dir + str(testname) + "-ONOS4-"+f )
Jon Hall94fd0472014-12-08 11:52:42 -08001703 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS5_ip+":"+log_folder+f+" "+
1704 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001705 dst_dir + str(testname) + "-ONOS5-"+f )
Jon Hall94fd0472014-12-08 11:52:42 -08001706 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS6_ip+":"+log_folder+f+" "+
1707 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001708 dst_dir + str(testname) + "-ONOS6-"+f )
Jon Hall94fd0472014-12-08 11:52:42 -08001709 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS7_ip+":"+log_folder+f+" "+
1710 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001711 dst_dir + str(testname) + "-ONOS7-"+f )
1712
1713
Jon Hall73cf9cc2014-11-20 22:28:38 -08001714 #sleep so scp can finish
1715 time.sleep(10)
1716 main.step("Packing and rotating pcap archives")
1717 os.system("~/TestON/dependencies/rotate.sh "+ str(testname))
1718
1719
1720 #TODO: actually check something here
1721 utilities.assert_equals(expect=main.TRUE, actual=main.TRUE,
1722 onpass="Test cleanup successful",
1723 onfail="Test cleanup NOT successful")
Jon Hall669173b2014-12-17 11:36:30 -08001724
1725 def CASE14 ( self, main ) :
1726 '''
1727 start election app on all onos nodes
1728 '''
1729 leader_result = main.TRUE
1730 #install app on onos 1
1731 main.log.info("Install leadership election app")
1732 main.ONOScli1.feature_install("onos-app-election")
1733 #wait for election
1734 #check for leader
1735 leader = main.ONOScli1.election_test_leader()
1736 #verify leader is ONOS1
1737 if leader == ONOS1_ip:
1738 #all is well
1739 pass
1740 elif leader == None:
1741 #No leader elected
1742 main.log.report("No leader was elected")
1743 leader_result = main.FALSE
1744 elif leader == main.FALSE:
1745 #error in response
1746 #TODO: add check for "Command not found:" in the driver, this means the app isn't loaded
1747 main.log.report("Something is wrong with election_test_leader function, check the error logs")
1748 leader_result = main.FALSE
1749 else:
1750 #error in response
1751 main.log.report("Unexpected response from election_test_leader function:'"+str(leader)+"'")
1752 leader_result = main.FALSE
1753
1754
1755
1756
1757 #install on other nodes and check for leader.
1758 #Should be onos1 and each app should show the same leader
1759 for controller in range(2,num_controllers+1):
1760 node = getattr( main, ( 'ONOScli' + str( controller ) ) )#loop through ONOScli handlers
1761 node.feature_install("onos-app-election")
1762 leaderN = node.election_test_leader()
1763 #verify leader is ONOS1
1764 if leaderN == ONOS1_ip:
1765 #all is well
1766 pass
1767 elif leaderN == main.FALSE:
1768 #error in response
1769 #TODO: add check for "Command not found:" in the driver, this means the app isn't loaded
1770 main.log.report("Something is wrong with election_test_leader function, check the error logs")
1771 leader_result = main.FALSE
1772 elif leader != leaderN:
1773 leader_result = main.FALSE
1774 main.log.report("ONOS" + str(controller) + " sees "+str(leaderN) +
1775 " as the leader of the election app. Leader should be "+str(leader) )
1776 if leader_result:
1777 main.log.report("Leadership election tests passed(consistent view of leader across listeners and a leader was elected)")
1778 utilities.assert_equals(expect=main.TRUE, actual=leader_result,
1779 onpass="Leadership election passed",
1780 onfail="Something went wrong with Leadership election")
1781
1782 def CASE15 ( self, main ) :
1783 '''
1784 Check that Leadership Election is still functional
1785 '''
1786 leader_result = main.TRUE
1787 description = "Check that Leadership Election is still functional"
1788 main.log.report(description)
1789 main.case(description)
1790 main.step("Find current leader and withdraw")
1791 leader = main.ONOScli1.election_test_leader()
1792 #TODO: do some sanity checking on leader before using it
1793 withdraw_result = main.FALSE
1794 if leader == ONOS1_ip:
1795 old_leader = getattr( main, "ONOScli1" )
1796 elif leader == ONOS2_ip:
1797 old_leader = getattr( main, "ONOScli2" )
1798 elif leader == ONOS3_ip:
1799 old_leader = getattr( main, "ONOScli3" )
1800 elif leader == ONOS4_ip:
1801 old_leader = getattr( main, "ONOScli4" )
1802 elif leader == ONOS5_ip:
1803 old_leader = getattr( main, "ONOScli5" )
1804 elif leader == ONOS6_ip:
1805 old_leader = getattr( main, "ONOScli6" )
1806 elif leader == ONOS7_ip:
1807 old_leader = getattr( main, "ONOScli7" )
1808 elif leader == None or leader == main.FALSE:
1809 main.log.report("Leader for the election app should be an ONOS node,"\
1810 +"instead got '"+str(leader)+"'")
1811 leader_result = main.FALSE
1812 withdraw_result = old_leader.election_test_withdraw()
1813
1814
1815 main.step("Make sure new leader is elected")
1816 leader_list = []
1817 for controller in range(1,num_controllers+1):
1818 node = getattr( main, ( 'ONOScli' + str( controller ) ) )#loop through ONOScli handlers
1819 leader_list.append( node.election_test_leader() )
1820 for leaderN in leader_list:
1821 if leaderN == leader:
1822 main.log.report("ONOS"+str(controller)+" still sees " + str(leader) +\
1823 " as leader after they withdrew")
1824 leader_result = main.FALSE
1825 elif leaderN == main.FALSE:
1826 #error in response
1827 #TODO: add check for "Command not found:" in the driver, this means the app isn't loaded
1828 main.log.report("Something is wrong with election_test_leader function, check the error logs")
1829 leader_result = main.FALSE
1830 consistent_leader = main.FALSE
1831 if len( set( leader_list ) ) == 1:
1832 main.log.info("Each Election-app sees '"+str(leader_list[0])+"' as the leader")
1833 consistent_leader = main.TRUE
1834 else:
1835 main.log.report("Inconsistent responses for leader of Election-app:")
1836 for n in range(len(leader_list)):
1837 main.log.report("ONOS" + str(n+1) + " response: " + str(leader_list[n]) )
1838 if leader_result:
1839 main.log.report("Leadership election tests passed(consistent view of leader across listeners and a new leader was elected when the old leader resigned)")
1840 utilities.assert_equals(expect=main.TRUE, actual=leader_result,
1841 onpass="Leadership election passed",
1842 onfail="Something went wrong with Leadership election")
1843
1844
1845 main.step("Run for election on old leader(just so everyone is in the hat)")
1846 run_result = old_leader.election_test_run()
1847 if consistent_leader == main.TRUE:
1848 after_run = main.ONOScli1.election_test_leader()
1849 #verify leader didn't just change
1850 if after_run == leader_list[0]:
1851 leader_result = main.TRUE
1852 else:
1853 leader_result = main.FALSE
1854 #TODO: assert on run and withdraw results?
1855
1856 utilities.assert_equals(expect=main.TRUE, actual=leader_result,
1857 onpass="Leadership election passed",
1858 onfail="Something went wrong with Leadership election after the old leader re-ran for election")
1859