blob: 3a838fa0a80a24f7a42e092b02bf4d4bfc96e79d [file] [log] [blame]
Hari Krishnaa43d4e92014-12-19 13:22:40 -08001import time
2import sys
3import os
4import re
5import time
6import json
7import itertools
8
9class OnosCHO:
10 def __init__(self):
11 self.default = ''
12 global deviceDPIDs
13 global hostMACs
14 global deviceLinks
15 global deviceActiveLinksCount
16 global devicePortsEnabledCount
17 global installedIntents
18 global randomLink1, randomLink2, randomLink3, numSwitches, numLinks
19 def CASE1(self, main):
20 '''
21 Startup sequence:
22 git pull
23 mvn clean install
24 onos-package
25 cell <name>
26 onos-verify-cell
27 onos-install -f
28 onos-wait-for-start
29 '''
30 import time
31 cell_name = main.params['ENV']['cellName']
32 git_pull = main.params['GIT']['autoPull']
33 numCtrls = main.params['CTRL']['numCtrl']
34 git_branch = main.params['GIT']['branch']
35
36 main.case("Set up test environment")
37 main.log.report("Set up test environment")
38 main.log.report("_______________________")
39
40 main.step("Git checkout and pull "+git_branch)
41 if git_pull == 'on':
42 checkout_result = main.ONOSbench.git_checkout(git_branch)
43 pull_result = main.ONOSbench.git_pull()
44 cp_result = (checkout_result and pull_result)
45 else:
46 checkout_result = main.TRUE
47 pull_result = main.TRUE
48 main.log.info("Skipped git checkout and pull")
49 cp_result = (checkout_result and pull_result)
50 utilities.assert_equals(expect=main.TRUE, actual=cp_result,
51 onpass="Test step PASS",
52 onfail="Test step FAIL")
53
54 main.step("mvn clean & install")
55 mvn_result = main.ONOSbench.clean_install()
56 utilities.assert_equals(expect=main.TRUE, actual=mvn_result,
57 onpass="Test step PASS",
58 onfail="Test step FAIL")
59
60 main.ONOSbench.get_version(report=True)
61
62 main.step("Apply Cell environment for ONOS")
63 cell_result = main.ONOSbench.set_cell(cell_name)
64 utilities.assert_equals(expect=main.TRUE, actual=cell_result,
65 onpass="Test step PASS",
66 onfail="Test step FAIL")
67
68 main.step("Create ONOS package")
69 packageResult = main.ONOSbench.onos_package()
70 utilities.assert_equals(expect=main.TRUE, actual=packageResult,
71 onpass="Test step PASS",
72 onfail="Test step FAIL")
73
74 main.step("Uninstall ONOS package on all Nodes")
75 uninstallResult=main.TRUE
76 for i in range(1,int(numCtrls)+1):
77 ONOS_ip = main.params['CTRL']['ip'+str(i)]
78 main.log.info("Unintsalling package on ONOS Node IP: "+ONOS_ip)
79 u_result= main.ONOSbench.onos_uninstall(ONOS_ip)
80 utilities.assert_equals(expect=main.TRUE, actual=u_result,
81 onpass="Test step PASS",
82 onfail="Test step FAIL")
83 uninstallResult=(uninstallResult and u_result)
84
85 main.step("Removing copy-cat logs from ONOS nodes")
86 main.ONOSbench.onos_remove_raft_logs()
87
88 main.step("Install ONOS package on all Nodes")
89 installResult=main.TRUE
90 for i in range(1,int(numCtrls)+1):
91 ONOS_ip = main.params['CTRL']['ip'+str(i)]
92 main.log.info("Intsalling package on ONOS Node IP: "+ONOS_ip)
93 i_result= main.ONOSbench.onos_install(node=ONOS_ip)
94 utilities.assert_equals(expect=main.TRUE, actual=i_result,
95 onpass="Test step PASS",
96 onfail="Test step FAIL")
97 installResult=(installResult and i_result)
98
99 main.step("Verify ONOS nodes UP status")
100 statusResult=main.TRUE
101 for i in range(1,int(numCtrls)+1):
102 ONOS_ip = main.params['CTRL']['ip'+str(i)]
103 main.log.info("ONOS Node "+ONOS_ip+" status:")
104 onos_status = main.ONOSbench.onos_status(node=ONOS_ip)
105 utilities.assert_equals(expect=main.TRUE, actual=onos_status,
106 onpass="Test step PASS",
107 onfail="Test step FAIL")
108 statusResult=(statusResult and onos_status)
109
110 main.step("Start ONOS CLI on all nodes")
111 cliResult = main.TRUE
112 time.sleep(15) # need to wait here for sometime. This will be removed once ONOS is stable enough
113 for i in range(1,int(numCtrls)+1):
114 ONOS_ip = main.params['CTRL']['ip'+str(i)]
115 ONOScli = 'ONOScli'+str(i)
116 main.log.info("ONOS Node "+ONOS_ip+" cli start:")
117 exec "startcli=main."+ONOScli+".start_onos_cli(ONOS_ip)"
118 utilities.assert_equals(expect=main.TRUE, actual=startcli,
119 onpass="Test step PASS",
120 onfail="Test step FAIL")
121 cliResult = (cliResult and startcli)
122
123 case1Result = (cp_result and cell_result
124 and packageResult and installResult and statusResult and cliResult)
125 utilities.assert_equals(expect=main.TRUE, actual=case1Result,
126 onpass="Set up test environment PASS",
127 onfail="Set up test environment FAIL")
128
129 def CASE2(self, main):
130 '''
131 This test script still needs more refactoring
132 '''
133 import re
134 import time
135 import copy
136 numCtrls = main.params['CTRL']['numCtrl']
137 ONOS1_ip = main.params['CTRL']['ip1']
138 ONOS2_ip = main.params['CTRL']['ip2']
139 ONOS3_ip = main.params['CTRL']['ip3']
140 ONOS4_ip = main.params['CTRL']['ip4']
141 ONOS5_ip = main.params['CTRL']['ip5']
142 ONOS1_port = main.params['CTRL']['port1']
143 ONOS2_port = main.params['CTRL']['port2']
144 ONOS3_port = main.params['CTRL']['port3']
145 ONOS4_port = main.params['CTRL']['port4']
146 ONOS5_port = main.params['CTRL']['port5']
147
148 numCtrls = main.params['CTRL']['numCtrl']
149 main.log.report("Assign and Balance all Mininet switches across controllers")
150 main.log.report("_________________________________________________________")
151 time.sleep(15) # need to wait here for sometime. This will be removed once ONOS is stable enough
152 main.case("Assign and Balance all Mininet switches across controllers")
153 main.step("Assign switches to controllers")
154 for i in range(1,26): #1 to (num of switches +1)
155 main.Mininet1.assign_sw_controller(sw=str(i),count=int(numCtrls),
156 ip1=ONOS1_ip, port1=ONOS1_port,
157 ip2=ONOS2_ip, port2=ONOS2_port,
158 ip3=ONOS3_ip, port3=ONOS3_port, ip4=ONOS4_ip, port4=ONOS4_port,
159 ip5=ONOS5_ip, port5=ONOS5_port)
160
161 switch_mastership = main.TRUE
162 for i in range (1,26):
163 response = main.Mininet1.get_sw_controller("s"+str(i))
164 print("Response is " + str(response))
165 if re.search("tcp:"+ONOS1_ip,response):
166 switch_mastership = switch_mastership and main.TRUE
167 else:
168 switch_mastership = main.FALSE
169
170 if switch_mastership == main.TRUE:
171 main.log.report("Controller assignment successfull")
172 else:
173 main.log.report("Controller assignment failed")
174 time.sleep(5)
175
176 main.step("Balance devices across controllers")
177 for i in range(int(numCtrls)):
178 balanceResult = main.ONOScli1.balance_masters()
179 time.sleep(3) # giving some breathing time for ONOS to complete re-balance
180
181 utilities.assert_equals(expect=main.TRUE, actual=balanceResult,
182 onpass="Assign and Balance devices test PASS",
183 onfail="Assign and Balance devices test FAIL")
184
185 def CASE3(self,main) :
186 '''
187 This Test case will be extended to collect and store more data related
188 ONOS state.
189 '''
190 import re
191 import copy
192 deviceDPIDs = []
193 hostMACs = []
194 deviceLinks = []
195 deviceActiveLinksCount = []
196 devicePortsEnabledCount = []
197
198 main.log.report("Collect and Store topology details from ONOS before running any Tests")
199 main.log.report("____________________________________________________________________")
200 main.case ("Collect and Store Topology Deatils from ONOS")
201
202 main.step("Collect and store current number of switches and links")
203 topology_output = main.ONOScli1.topology()
204 topology_result = main.ONOSbench.get_topology(topology_output)
205 numSwitches = topology_result['devices']
206 numLinks = topology_result['links']
207 main.log.info("Currently there are %s switches and %s links" %(str(numSwitches), str(numLinks)))
208
209 main.step("Store Device DPIDs")
210 for i in range(1,26):
211 deviceDPIDs.append("of:00000000000000"+format(i, '02x'))
212 print "Device DPIDs in Store: \n", str(deviceDPIDs)
213
214 main.step("Store Host MACs")
215 for i in range(1,26):
216 hostMACs.append("00:00:00:00:00:"+format(i, '02x')+"/-1")
217 print "Host MACs in Store: \n", str(hostMACs)
218
219 main.step("Collect and store all Devices Links")
220 linksResult = main.ONOScli1.links(json_format=False)
221 ansi_escape = re.compile(r'\x1b[^m]*m')
222 linksResult = ansi_escape.sub('', linksResult)
223 linksResult = linksResult.replace(" links","").replace("\r\r","")
224 linksResult=linksResult.splitlines()
225 linksResult = linksResult[1:]
226 deviceLinks = copy.copy(linksResult)
227 print "Device Links Stored: \n", str(deviceLinks)
228 print "Length of Links Store", len(deviceLinks) # this will be asserted to check with the params provided count of links
229
230 main.step("Collect and store each Device ports enabled Count")
231 for i in range(1,26):
232 portResult = main.ONOScli1.getDevicePortsEnabledCount("of:00000000000000"+format(i, '02x'))
233 portTemp = re.split(r'\t+', portResult)
234 portCount = portTemp[1].replace("\r\r\n\x1b[32m","")
235 devicePortsEnabledCount.append(portCount)
236 print "Device Enabled Port Counts Stored: \n", str(devicePortsEnabledCount)
237
238 main.step("Collect and store each Device active links Count")
239 for i in range(1,26):
240 linkCountResult = main.ONOScli1.getDeviceLinksActiveCount("of:00000000000000"+format(i, '02x'))
241 linkCountTemp = re.split(r'\t+', linkCountResult)
242 linkCount = linkCountTemp[1].replace("\r\r\n\x1b[32m","")
243 deviceActiveLinksCount.append(linkCount)
244 print "Device Active Links Count Stored: \n", str(deviceActiveLinksCount)
245
246 caseResult = main.TRUE # just returning TRUE for now as this one just collects data
247 utilities.assert_equals(expect=main.TRUE, actual=case1Result,
248 onpass="Saving ONOS topology data test PASS",
249 onfail="Saving ONOS topology data test FAIL")
250
251 def CASE4(self,main) :
252 '''
253 Enable onos-app-fwd, Verify Reactive forwarding through ping all and Disable it
254 '''
255 import re
256 import copy
257 import time
258 numCtrls = main.params['CTRL']['numCtrl']
259 main.log.report("Enable Reactive forwarding and Verify ping all")
260 main.log.report("______________________________________________")
261 main.case ("Enable Reactive forwarding and Verify ping all")
262 main.step("Enable Reactive forwarding")
263 installResult = main.TRUE
264 for i in range(1,int(numCtrls)+1):
265 onosFeature = 'onos-app-fwd'
266 ONOS_ip = main.params['CTRL']['ip'+str(i)]
267 ONOScli = 'ONOScli'+str(i)
268 main.log.info("Enabling Reactive mode on ONOS Node "+ONOS_ip)
269 exec "inResult=main."+ONOScli+".feature_install(onosFeature)"
270 installResult = inResult and installResult
271
272 time.sleep(5)
273
274 main.step("Verify Pingall")
275 ping_result = main.FALSE
276 time1 = time.time()
277 ping_result = main.Mininet1.pingall()
278 time2 = time.time()
279 timeDiff = round((time2-time1),2)
280 main.log.report("Time taken for Ping All: "+str(timeDiff)+" seconds")
281
282 if ping_result == main.TRUE:
283 main.log.report("Pingall Test in Reactive mode successful")
284 else:
285 main.log.report("Pingall Test in Reactive mode failed")
286
287 main.step("Disable Reactive forwarding")
288 uninstallResult = main.TRUE
289 for i in range(1,int(numCtrls)+1):
290 onosFeature = 'onos-app-fwd'
291 ONOS_ip = main.params['CTRL']['ip'+str(i)]
292 ONOScli = 'ONOScli'+str(i)
293 main.log.info("Disabling Reactive mode on ONOS Node "+ONOS_ip)
294 exec "unResult=main."+ONOScli+".feature_uninstall(onosFeature)"
295 uninstallResult = unResult and uninstallResult
296
297 #Waiting for reative flows to be cleared.
298 time.sleep(10)
299
300 case3Result = installResult and ping_result and uninstallResult
301 utilities.assert_equals(expect=main.TRUE, actual=case3Result,
302 onpass="Reactive Mode Pingall test PASS",
303 onfail="Reactive Mode Pingall test FAIL")
304
305 def CASE5(self,main) :
306 '''
307 Compare current ONOS topology with reference data
308 '''
309 import re
310 devicesDPID_tmp = []
311 hostMACs_tmp = []
312 deviceLinks_tmp = []
313 deviceActiveLinksCount_tmp = []
314 devicePortsEnabledCount_tmp = []
315
316 main.log.report("Compare ONOS topology with reference data in Stores")
317 main.log.report("__________________________________________________")
318 main.case ("Compare ONOS topology with reference data")
319
320 main.step("Compare current Device ports enabled with reference")
321 for i in range(1,26):
322 portResult = main.ONOScli1.getDevicePortsEnabledCount("of:00000000000000"+format(i, '02x'))
323 portTemp = re.split(r'\t+', portResult)
324 portCount = portTemp[1].replace("\r\r\n\x1b[32m","")
325 devicePortsEnabledCount_tmp.append(portCount)
326 time.sleep(2)
327 print ("Device Enabled ports EXPECTED: \n"+ str(devicePortsEnabledCount))
328 print ("Device Enabled ports ACTUAL: \n"+ str(devicePortsEnabledCount_tmp))
329 if (cmp(devicePortsEnabledCount,devicePortsEnabledCount_tmp)==0):
330 stepResult1 = main.TRUE
331 else:
332 stepResult1 = main.FALSE
333
334 main.step("Compare Device active links with reference")
335 for i in range(1,26):
336 linkResult = main.ONOScli1.getDeviceLinksActiveCount("of:00000000000000"+format(i, '02x'))
337 linkTemp = re.split(r'\t+', linkResult)
338 linkCount = linkTemp[1].replace("\r\r\n\x1b[32m","")
339 deviceActiveLinksCount_tmp.append(linkCount)
340 time.sleep(3)
341 print ("Device Active links EXPECTED: \n"+str(deviceActiveLinksCount))
342 print ("Device Active links ACTUAL: \n"+str(deviceActiveLinksCount_tmp))
343 if (cmp(deviceActiveLinksCount,deviceActiveLinksCount_tmp)==0):
344 stepResult2 = main.TRUE
345 else:
346 stepResult2 = main.FALSE
347
348 '''
349 place holder for comparing devices, hosts and paths if required.
350 Links and ports data would be incorrect with out devices anyways.
351 '''
352
353 caseResult=(stepResult1 and stepResult2)
354 utilities.assert_equals(expect=main.TRUE, actual=case1Result,
355 onpass="Compare Topology test PASS",
356 onfail="Compare Topology test FAIL")
357 if caseResult == main.TRUE:
358 main.log.report("Compare Topology test Pass")
359
360 def CASE6(self):
361 '''
362 Install 300 host intents and verify ping all
363 '''
364 main.log.report("Add 300 host intents and verify pingall")
365 main.log.report("_______________________________________")
366 import itertools
367 main.case("Install 300 host intents")
368 main.step("Add host Intents")
369 intentResult=main.TRUE
370 hostCombos = list(itertools.combinations(hostMACs, 2))
371 for i in range(len(hostCombos)):
372 iResult = main.ONOScli1.add_host_intent(hostCombos[i][0],hostCombos[i][1])
373 intentResult=(intentResult and iResult)
374
375 main.step("Verify Ping across all hosts")
376 pingResult = main.FALSE
377 time1 = time.time()
378 pingResult = main.Mininet1.pingall()
379 time2 = time.time()
380 timeDiff = round((time2-time1),2)
381 main.log.report("Time taken for Ping All: "+str(timeDiff)+" seconds")
382 utilities.assert_equals(expect=main.TRUE, actual=pingResult,
383 onpass="PING ALL PASS",
384 onfail="PING ALL FAIL")
385
386 case4Result=(intentResult and pingResult)
387 utilities.assert_equals(expect=main.TRUE, actual=case4Result,
388 onpass="Install 300 Host Intents and Ping All test PASS",
389 onfail="Install 300 Host Intents and Ping All test FAIL")
390
391 def CASE7(self,main):
392 '''
393 Randomly bring some core links down and verify ping all
394 '''
395 import random
396 ONOS1_ip = main.params['CTRL']['ip1']
397 link1End1 = main.params['CORELINKS']['linkS3a']
398 link1End2 = main.params['CORELINKS']['linkS3b'].split(',')
399 link2End1 = main.params['CORELINKS']['linkS14a']
400 link2End2 = main.params['CORELINKS']['linkS14b'].split(',')
401 link3End1 = main.params['CORELINKS']['linkS18a']
402 link3End2 = main.params['CORELINKS']['linkS18b'].split(',')
403 switchLinksToToggle = main.params['CORELINKS']['toggleLinks']
404 link_sleep = int(main.params['timers']['LinkDiscovery'])
405
406 main.log.report("Randomly bring some core links down and verify ping all")
407 main.log.report("____________________________________________________")
408 main.case("Randomly bring some core links down and verify ping all")
409 main.step("Verify number of Switch links to toggle on each Core Switch are between 1 - 5")
410 if (int(switchLinksToToggle) == 0 or int(switchLinksToToggle) > 5):
411 main.log.info("Please check you PARAMS file. Valid range for number of switch links to toggle is between 1 to 5")
412 main.cleanup()
413 main.exit()
414 else:
415 main.log.info("User provided Core switch links range to toggle is correct, proceeding to run the test")
416
417 main.step("Cut links on Core devices using user provided range")
418 randomLink1 = random.sample(link1End2,int(switchLinksToToggle))
419 randomLink2 = random.sample(link2End2,int(switchLinksToToggle))
420 randomLink3 = random.sample(link3End2,int(switchLinksToToggle))
421 for i in range(int(switchLinksToToggle)):
422 main.Mininet1.link(END1=link1End1,END2=randomLink1[i],OPTION="down")
423 main.Mininet1.link(END1=link2End1,END2=randomLink2[i],OPTION="down")
424 main.Mininet1.link(END1=link3End1,END2=randomLink3[i],OPTION="down")
425 time.sleep(link_sleep)
426
427 topology_output = main.ONOScli2.topology()
428 linkDown = main.ONOSbench.check_status(topology_output,numSwitches,str(int(numLinks)-int(switchLinksToToggle)*6))
429 utilities.assert_equals(expect=main.TRUE,actual=linkDown,
430 onpass="Link Down discovered properly",
431 onfail="Link down was not discovered in "+ str(link_sleep) + " seconds")
432
433 main.step("Verify Ping across all hosts")
434 pingResultLinkDown = main.FALSE
435 time1 = time.time()
436 pingResultLinkDown = main.Mininet1.pingall()
437 time2 = time.time()
438 timeDiff = round((time2-time1),2)
439 main.log.report("Time taken for Ping All: "+str(timeDiff)+" seconds")
440 utilities.assert_equals(expect=main.TRUE, actual=pingResultLinkDown,
441 onpass="PING ALL PASS",
442 onfail="PING ALL FAIL")
443
444 caseResult7 = linkDown and pingResultLinkDown
445 utilities.assert_equals(expect=main.TRUE, actual=caseResult7,
446 onpass="Random Link cut Test PASS",
447 onfail="Random Link cut Test FAIL")
448
449 def CASE8(self,main):
450 '''
451 Bring the core links up that are down and verify ping all
452 '''
453 import random
454 ONOS1_ip = main.params['CTRL']['ip1']
455 link1End1 = main.params['CORELINKS']['linkS3a']
456 link2End1 = main.params['CORELINKS']['linkS14a']
457 link3End1 = main.params['CORELINKS']['linkS18a']
458 link_sleep = int(main.params['timers']['LinkDiscovery'])
459 switchLinksToToggle = main.params['CORELINKS']['toggleLinks']
460
461 main.log.report("Bring the core links up that are down and verify ping all")
462 main.log.report("_____________________________________________________")
463 main.case("Bring the core links up that are down and verify ping all")
464 main.step("Bring randomly cut links on Core devices up")
465 for i in range(int(switchLinksToToggle)):
466 main.Mininet1.link(END1=link1End1,END2=randomLink1[i],OPTION="up")
467 main.Mininet1.link(END1=link2End1,END2=randomLink2[i],OPTION="up")
468 main.Mininet1.link(END1=link3End1,END2=randomLink3[i],OPTION="up")
469 time.sleep(link_sleep)
470
471 topology_output = main.ONOScli2.topology()
472 linkUp = main.ONOSbench.check_status(topology_output,numSwitches,str(numLinks))
473 utilities.assert_equals(expect=main.TRUE,actual=linkUp,
474 onpass="Link up discovered properly",
475 onfail="Link up was not discovered in "+ str(link_sleep) + " seconds")
476
477 main.step("Verify Ping across all hosts")
478 pingResultLinkUp = main.FALSE
479 time1 = time.time()
480 pingResultLinkUp = main.Mininet1.pingall()
481 time2 = time.time()
482 timeDiff = round((time2-time1),2)
483 main.log.report("Time taken for Ping All: "+str(timeDiff)+" seconds")
484 utilities.assert_equals(expect=main.TRUE, actual=pingResultLinkUp,
485 onpass="PING ALL PASS",
486 onfail="PING ALL FAIL")
487
488 caseResult8 = linkUp and pingResultLinkUp
489 utilities.assert_equals(expect=main.TRUE, actual=caseResult8,
490 onpass="Link Up Test PASS",
491 onfail="Link Up Test FAIL")
492
493 def CASE9(self):
494 '''
495 Install 114 point intents and verify Ping all works
496 '''
497 import copy
498 main.log.report("Install 114 point intents and verify Ping all")
499 main.log.report("___________________________________________")
500 main.case("Install 114 point intents and Ping all")
501 deviceLinks_copy = copy.copy(deviceLinks)
502 main.step("Install 114 point intents")
503 for i in range(len(deviceLinks_copy)):
504 pointLink = str(deviceLinks_copy[i]).replace("src=","").replace("dst=","").split(',')
505 point1 = pointLink[0].split('/')
506 point2 = pointLink[1].split('/')
507 installResult = main.ONOScli1.add_point_intent(point1[0],point2[0],int(point1[1]),int(point2[1]))
508 if installResult == main.TRUE:
509 print "Installed Point intent between :",point1[0], int(point1[1]), point2[0], int(point2[1])
510
511 main.step("Obtain the intent id's")
512 intentsList = main.ONOScli1.getAllIntentIds()
513 ansi_escape = re.compile(r'\x1b[^m]*m')
514 intentsList = ansi_escape.sub('', intentsList)
515 intentsList = intentsList.replace(" onos:intents | grep id=","").replace("id=","").replace("\r\r","")
516 intentsList=intentsList.splitlines()
517 intentsList = intentsList[1:]
518 intentIdList = []
519 for i in range(len(intentsList)):
520 intentsTemp = intentsList[i].split(',')
521 intentIdList.append(intentsTemp[0])
522 print "Intent IDs: ", intentIdList
523 print "Total Intents installed: ", len(intentIdList)
524
525 main.step("Verify Ping across all hosts")
526 pingResult = main.FALSE
527 time1 = time.time()
528 pingResult = main.Mininet1.pingall()
529 time2 = time.time()
530 timeDiff = round((time2-time1),2)
531 main.log.report("Time taken for Ping All: "+str(timeDiff)+" seconds")
532 utilities.assert_equals(expect=main.TRUE, actual=pingResult,
533 onpass="PING ALL PASS",
534 onfail="PING ALL FAIL")
535
536 case8_result = installResult and pingResult
537 utilities.assert_equals(expect=main.TRUE, actual=case8_result,
538 onpass="Ping all test after Point intents addition successful",
539 onfail="Ping all test after Point intents addition failed")
540
541 def CASE10(self):
542 '''
543 Remove all Intents
544 '''
545 main.log.report("Remove all intents that were installed previously")
546 main.log.report("______________________________________________")
547 main.log.info("Remove all intents")
548 main.case("Removing intents")
549 main.step("Obtain the intent id's first")
550 intentsList = main.ONOScli1.getAllIntentIds()
551 ansi_escape = re.compile(r'\x1b[^m]*m')
552 intentsList = ansi_escape.sub('', intentsList)
553 intentsList = intentsList.replace(" onos:intents | grep id=","").replace("id=","").replace("\r\r","")
554 intentsList=intentsList.splitlines()
555 intentsList = intentsList[1:]
556 intentIdList = []
557 step1Result = main.TRUE
558 if (len(intentsList) > 1):
559 for i in range(len(intentsList)):
560 intentsTemp = intentsList[i].split(',')
561 intentIdList.append(intentsTemp[0])
562 print "Intent IDs: ", intentIdList
563 for id in range(len(intentIdList)):
564 print "Removing intent id (round 1) :", intentIdList[id]
565 main.ONOScli1.remove_intent(intent_id = intentIdList[id])
566 time.sleep(1)
567
568 main.log.info("Verify all intents are removed and if any leftovers try remove one more time")
569 intentsList1 = main.ONOScli1.getAllIntentIds()
570 ansi_escape = re.compile(r'\x1b[^m]*m')
571 intentsList1 = ansi_escape.sub('', intentsList1)
572 intentsList1 = intentsList1.replace(" onos:intents | grep id=","").replace(" state=","").replace("\r\r","")
573 intentsList1=intentsList1.splitlines()
574 intentsList1 = intentsList1[1:]
575 print "Round 2 (leftover) intents to remove: ", intentsList1
576 intentIdList1 = []
577 if (len(intentsList1) > 1):
578 for i in range(len(intentsList1)):
579 intentsTemp1 = intentsList[i].split(',')
580 intentIdList1.append(intentsTemp1[0])
581 print "Leftover Intent IDs: ", intentIdList1
582 for id in range(len(intentIdList1)):
583 print "Removing intent id (round 2):", intentIdList1[id]
584 main.ONOScli1.remove_intent(intent_id = intentIdList1[id])
585 time.sleep(2)
586 else:
587 print "There are no more intents that need to be removed"
588 step1Result = main.TRUE
589 else:
590 print "No Intent IDs found in Intents list: ", intentsList
591 step1Result = main.FALSE
592
593 caseResult7 = step1Result
594 utilities.assert_equals(expect=main.TRUE, actual=caseResult7,
595 onpass="Intent removal test successful",
596 onfail="Intent removal test failed")