blob: 314bde92035085ae37a1c283d3808741ea0a9cd8 [file] [log] [blame]
You Wangdb927a52016-02-26 11:03:28 -08001"""
2CHOTestMonkey class
3Author: you@onlab.us
4"""
5
6import sys
7import os
8import re
9import time
10import json
11import itertools
12
13class CHOTestMonkey:
14
15 def __init__( self ):
16 self.default = ''
17
18 def CASE0( self, main ):
19 """
20 Startup sequence:
21 apply cell <name>
22 git pull
23 mvn clean install
24 onos-package
25 onos-verify-cell
26 onos-uninstall
27 onos-install
28 onos-start-cli
29 Set IPv6 cfg parameters for Neighbor Discovery
30 start event scheduler
31 start event listener
32 """
33 import time
34 from threading import Lock, Condition
35 from tests.CHOTestMonkey.dependencies.elements.ONOSElement import Controller
36 from tests.CHOTestMonkey.dependencies.EventGenerator import EventGenerator
37 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduler
38
39 gitPull = main.params[ 'TEST' ][ 'autoPull' ]
40 onosPackage = main.params[ 'TEST' ][ 'package' ]
41 gitBranch = main.params[ 'TEST' ][ 'branch' ]
42 karafTimeout = main.params[ 'TEST' ][ 'karafCliTimeout' ]
43 main.enableIPv6 = main.params[ 'TEST' ][ 'IPv6' ]
44 main.enableIPv6 = True if main.enableIPv6 == "on" else False
45 main.caseSleep = int( main.params[ 'TEST' ][ 'caseSleep' ] )
46 main.numCtrls = main.params[ 'TEST' ][ 'numCtrl' ]
47 main.controllers = []
48 for i in range( 1, int( main.numCtrls ) + 1 ):
49 newController = Controller( i )
50 newController.setCLI( getattr( main, 'ONOScli' + str( i ) ) )
51 main.controllers.append( newController )
52 main.devices = []
53 main.links = []
54 main.hosts = []
55 main.intents = []
56 main.enabledEvents = {}
57 for eventName in main.params[ 'EVENT' ].keys():
58 if main.params[ 'EVENT' ][ eventName ][ 'status' ] == 'on':
59 main.enabledEvents[ int( main.params[ 'EVENT' ][ eventName ][ 'typeIndex' ] ) ] = eventName
60 print main.enabledEvents
61 main.eventScheduler = EventScheduler()
62 main.eventGenerator = EventGenerator()
63 main.variableLock = Lock()
64 main.mininetLock = Lock()
65 main.ONOSbenchLock = Lock()
66 main.threadID = 0
67 main.eventID = 0
68 main.caseResult = main.TRUE
69
70 main.case( "Set up test environment" )
71 main.log.report( "Set up test environment" )
72 main.log.report( "_______________________" )
73
74 main.step( "Apply Cell environment for ONOS" )
75 if ( main.onoscell ):
76 cellName = main.onoscell
77 cellResult = main.ONOSbench.setCell( cellName )
78 utilities.assert_equals( expect=main.TRUE,
79 actual=cellResult,
80 onpass="Test step PASS",
81 onfail="Test step FAIL" )
82 else:
83 main.log.error( "Please provide onoscell option at TestON CLI to run CHO tests" )
84 main.log.error( "Example: ~/TestON/bin/cli.py run CHOTestMonkey onoscell <cellName>" )
85 main.cleanup()
86 main.exit()
87
88 main.step( "Git checkout and pull " + gitBranch )
89 if gitPull == 'on':
90 checkoutResult = main.ONOSbench.gitCheckout( gitBranch )
91 pullResult = main.ONOSbench.gitPull()
92 cpResult = ( checkoutResult and pullResult )
93 else:
94 checkoutResult = main.TRUE
95 pullResult = main.TRUE
96 main.log.info( "Skipped git checkout and pull as they are disabled in params file" )
97 cpResult = ( checkoutResult and pullResult )
98 utilities.assert_equals( expect=main.TRUE,
99 actual=cpResult,
100 onpass="Test step PASS",
101 onfail="Test step FAIL" )
102
103 main.step( "mvn clean & install" )
104 if gitPull == 'on':
105 mvnResult = main.ONOSbench.cleanInstall()
106 else:
107 mvnResult = main.TRUE
108 main.log.info( "Skipped mvn clean install as it is disabled in params file" )
109 utilities.assert_equals( expect=main.TRUE,
110 actual=mvnResult,
111 onpass="Test step PASS",
112 onfail="Test step FAIL" )
113 main.ONOSbench.getVersion( report=True )
114
115 main.step( "Create ONOS package" )
116 if onosPackage == 'on':
117 packageResult = main.ONOSbench.onosPackage()
118 else:
119 packageResult = main.TRUE
120 main.log.info( "Skipped onos package as it is disabled in params file" )
121 utilities.assert_equals( expect=main.TRUE,
122 actual=packageResult,
123 onpass="Test step PASS",
124 onfail="Test step FAIL" )
125
126 main.step( "Uninstall ONOS package on all Nodes" )
127 uninstallResult = main.TRUE
128 for i in range( int( main.numCtrls ) ):
129 main.log.info( "Uninstalling package on ONOS Node IP: " + main.onosIPs[i] )
130 uResult = main.ONOSbench.onosUninstall( main.onosIPs[i] )
131 utilities.assert_equals( expect=main.TRUE,
132 actual=uResult,
133 onpass="Test step PASS",
134 onfail="Test step FAIL" )
135 uninstallResult = ( uninstallResult and uResult )
136
137 main.step( "Install ONOS package on all Nodes" )
138 installResult = main.TRUE
139 for i in range( int( main.numCtrls ) ):
140 main.log.info( "Installing package on ONOS Node IP: " + main.onosIPs[i] )
141 iResult = main.ONOSbench.onosInstall( node=main.onosIPs[i] )
142 utilities.assert_equals( expect=main.TRUE,
143 actual=iResult,
144 onpass="Test step PASS",
145 onfail="Test step FAIL" )
146 installResult = ( installResult and iResult )
147
148 main.step( "Start ONOS CLI on all nodes" )
149 cliResult = main.TRUE
150 startCliResult = main.TRUE
151 pool = []
152 for controller in main.controllers:
153 t = main.Thread( target=controller.startCLI,
154 threadID=main.threadID,
155 name="startOnosCli",
156 args=[ ] )
157 pool.append(t)
158 t.start()
159 main.threadID = main.threadID + 1
160 for t in pool:
161 t.join()
162 startCliResult = startCliResult and t.result
163 if not startCliResult:
164 main.log.info( "ONOS CLI did not start up properly" )
165 main.cleanup()
166 main.exit()
167 else:
168 main.log.info( "Successful CLI startup" )
169 startCliResult = main.TRUE
170 utilities.assert_equals( expect=main.TRUE,
171 actual=startCliResult,
172 onpass="Test step PASS",
173 onfail="Test step FAIL" )
174
175 main.step( "Set IPv6 cfg parameters for Neighbor Discovery" )
176 setIPv6CfgSleep = int( main.params[ 'TEST' ][ 'setIPv6CfgSleep' ] )
177 if main.enableIPv6:
178 time.sleep( setIPv6CfgSleep )
179 cfgResult1 = main.controllers[ 0 ].CLI.setCfg( "org.onosproject.proxyarp.ProxyArp",
180 "ipv6NeighborDiscovery",
181 "true" )
182 time.sleep( setIPv6CfgSleep )
183 cfgResult2 = main.controllers[ 0 ].CLI.setCfg( "org.onosproject.provider.host.impl.HostLocationProvider",
184 "ipv6NeighborDiscovery",
185 "true" )
186 else:
187 main.log.info( "Skipped setting IPv6 cfg parameters as it is disabled in params file" )
188 cfgResult1 = main.TRUE
189 cfgResult2 = main.TRUE
190 cfgResult = cfgResult1 and cfgResult2
191 utilities.assert_equals( expect=main.TRUE,
192 actual=cfgResult,
193 onpass="ipv6NeighborDiscovery cfg is set to true",
194 onfail="Failed to cfg set ipv6NeighborDiscovery" )
195
196 main.step( "Start a thread for the scheduler" )
197 t = main.Thread( target=main.eventScheduler.startScheduler,
198 threadID=main.threadID,
199 name="startScheduler",
200 args=[] )
201 t.start()
202 stepResult = main.TRUE
203 with main.variableLock:
204 main.threadID = main.threadID + 1
205
206 utilities.assert_equals( expect=main.TRUE,
207 actual=stepResult,
208 onpass="Test step PASS",
209 onfail="Test step FAIL" )
210
211 main.step( "Start a thread to listen to and handle network, ONOS and application events" )
212 t = main.Thread( target=main.eventGenerator.startListener,
213 threadID=main.threadID,
214 name="startListener",
215 args=[] )
216 t.start()
217 with main.variableLock:
218 main.threadID = main.threadID + 1
219
220 caseResult = installResult and uninstallResult and startCliResult and cfgResult
221 utilities.assert_equals( expect=main.TRUE,
222 actual=caseResult,
223 onpass="Set up test environment PASS",
224 onfail="Set up test environment FAIL" )
225
226 def CASE1( self, main ):
227 """
228 Load Mininet topology and balances all switches
229 """
230 import re
231 import time
232 import copy
233
234 main.topoIndex = "topo" + str ( main.params[ 'TEST' ][ 'topo' ] )
235
236 main.log.report( "Load Mininet topology and Balance all Mininet switches across controllers" )
237 main.log.report( "________________________________________________________________________" )
238 main.case( "Assign and Balance all Mininet switches across controllers" )
239
240 main.step( "Start Mininet topology" )
241 newTopo = main.params[ 'TOPO' ][ main.topoIndex ][ 'fileName' ]
242 mininetDir = main.Mininet1.home + "/custom/"
243 topoPath = main.testDir + "/" + main.TEST + "/dependencies/topologies/" + newTopo
244 main.ONOSbench.secureCopy( main.Mininet1.user_name, main.Mininet1.ip_address, topoPath, mininetDir, direction="to" )
245 topoPath = mininetDir + newTopo
246 startStatus = main.Mininet1.startNet( topoFile = topoPath )
247 main.mininetSwitches = main.Mininet1.getSwitches()
248 main.mininetHosts = main.Mininet1.getHosts()
249 main.mininetLinks = main.Mininet1.getLinks()
250 utilities.assert_equals( expect=main.TRUE,
251 actual=startStatus,
252 onpass="Start Mininet topology test PASS",
253 onfail="Start Mininet topology test FAIL" )
254
255 main.step( "Assign switches to controllers" )
256 switchMastership = main.TRUE
257 for switchName in main.mininetSwitches.keys():
258 main.Mininet1.assignSwController( sw=switchName, ip=main.onosIPs )
259 response = main.Mininet1.getSwController( switchName )
260 print( "Response is " + str( response ) )
261 if re.search( "tcp:" + main.onosIPs[ 0 ], response ):
262 switchMastership = switchMastership and main.TRUE
263 else:
264 switchMastership = main.FALSE
265 utilities.assert_equals( expect=main.TRUE,
266 actual=switchMastership,
267 onpass="Assign switches to controllers test PASS",
268 onfail="Assign switches to controllers test FAIL" )
269 # Waiting here to make sure topology converges across all nodes
270 sleep = int( main.params[ 'TEST' ][ 'loadTopoSleep' ] )
271 time.sleep( sleep )
272
273 main.step( "Balance devices across controllers" )
274 balanceResult = main.ONOScli1.balanceMasters()
275 # giving some breathing time for ONOS to complete re-balance
276 time.sleep( sleep )
277
278 caseResult = ( startStatus and switchMastership and balanceResult )
279 utilities.assert_equals( expect=main.TRUE,
280 actual=caseResult,
281 onpass="Starting new Att topology test PASS",
282 onfail="Starting new Att topology test FAIL" )
283
284 def CASE2( self, main ):
285 """
286 Collect and store device and link data from ONOS
287 """
288 import json
289 from tests.CHOTestMonkey.dependencies.elements.NetworkElement import Device, Link
290
291 main.log.report( "Collect and Store topology details from ONOS" )
292 main.log.report( "____________________________________________________________________" )
293 main.case( "Collect and Store Topology Details from ONOS" )
294 topoResult = main.TRUE
295 topologyOutput = main.ONOScli1.topology()
296 topologyResult = main.ONOScli1.getTopology( topologyOutput )
297 ONOSDeviceNum = int( topologyResult[ 'devices' ] )
298 ONOSLinkNum = int( topologyResult[ 'links' ] )
299 mininetSwitchNum = len( main.mininetSwitches )
300 mininetLinkNum = ( len( main.mininetLinks ) - len( main.mininetHosts ) ) * 2
301 if mininetSwitchNum == ONOSDeviceNum and mininetLinkNum == ONOSLinkNum:
302 main.step( "Collect and store device data" )
303 stepResult = main.TRUE
304 dpidToName = {}
305 for key, value in main.mininetSwitches.items():
306 dpidToName[ 'of:' + str( value[ 'dpid' ] ) ] = key
307 devicesRaw = main.ONOScli1.devices()
308 devices = json.loads( devicesRaw )
309 deviceInitIndex = 0
310 for device in devices:
311 name = dpidToName[ device[ 'id' ] ]
312 newDevice = Device( deviceInitIndex, name, device[ 'id' ] )
313 print newDevice
314 main.devices.append( newDevice )
315 deviceInitIndex += 1
316 utilities.assert_equals( expect=main.TRUE,
317 actual=stepResult,
318 onpass="Successfully collected and stored device data",
319 onfail="Failed to collect and store device data" )
320
321 main.step( "Collect and store link data" )
322 stepResult = main.TRUE
323 linksRaw = main.ONOScli1.links()
324 links = json.loads( linksRaw )
325 linkInitIndex = 0
326 for link in links:
327 for device in main.devices:
328 if device.dpid == link[ 'src' ][ 'device' ]:
329 deviceA = device
330 elif device.dpid == link[ 'dst' ][ 'device' ]:
331 deviceB = device
332 assert deviceA != None and deviceB != None
333 newLink = Link( linkInitIndex, deviceA, link[ 'src' ][ 'port' ], deviceB, link[ 'dst' ][ 'port' ] )
334 print newLink
335 main.links.append( newLink )
336 linkInitIndex += 1
337 # Set backward links and outgoing links of devices
338 for linkA in main.links:
339 linkA.deviceA.outgoingLinks.append( linkA )
340 if linkA.backwardLink != None:
341 continue
342 for linkB in main.links:
343 if linkB.backwardLink != None:
344 continue
345 if linkA.deviceA == linkB.deviceB and\
346 linkA.deviceB == linkB.deviceA and\
347 linkA.portA == linkB.portB and\
348 linkA.portB == linkB.portA:
349 linkA.setBackwardLink( linkB )
350 linkB.setBackwardLink( linkA )
351 utilities.assert_equals( expect=main.TRUE,
352 actual=stepResult,
353 onpass="Successfully collected and stored link data",
354 onfail="Failed to collect and store link data" )
355 else:
356 main.log.info( "Devices (expected): %s, Links (expected): %s" % ( mininetSwitchNum, mininetLinkNum ) )
357 main.log.info( "Devices (actual): %s, Links (actual): %s" % ( ONOSDeviceNum, ONOSLinkNum ) )
358 topoResult = main.FALSE
359
360 caseResult = topoResult
361 utilities.assert_equals( expect=main.TRUE,
362 actual=caseResult,
363 onpass="Saving ONOS topology data test PASS",
364 onfail="Saving ONOS topology data test FAIL" )
365
366 if not caseResult:
367 main.log.info("Topology does not match, exiting test...")
368 main.cleanup()
369 main.exit()
370
371 def CASE3( self, main ):
372 """
373 Collect and store host data from ONOS
374 """
375 import json
376 from tests.CHOTestMonkey.dependencies.elements.NetworkElement import Host
377
378 main.log.report( "Collect and store host adta from ONOS" )
379 main.log.report( "______________________________________________" )
380 main.case( "Use fwd app and pingall to discover all the hosts, then collect and store host data" )
381
382 main.step( "Enable Reactive forwarding" )
383 appResult = main.controllers[ 0 ].CLI.activateApp( "org.onosproject.fwd" )
384 cfgResult1 = main.TRUE
385 cfgResult2 = main.TRUE
386 if main.enableIPv6:
387 cfgResult1 = main.controllers[ 0 ].CLI.setCfg( "org.onosproject.fwd.ReactiveForwarding", "ipv6Forwarding", "true" )
388 cfgResult2 = main.controllers[ 0 ].CLI.setCfg( "org.onosproject.fwd.ReactiveForwarding", "matchIpv6Address", "true" )
389 stepResult = appResult and cfgResult1 and cfgResult2
390 utilities.assert_equals( expect=main.TRUE,
391 actual=stepResult,
392 onpass="Successfully enabled reactive forwarding",
393 onfail="Failed to enable reactive forwarding" )
394
395 main.step( "Discover hosts using pingall" )
396 stepResult = main.TRUE
397 main.Mininet1.pingall()
398 if main.enableIPv6:
399 ping6Result = main.Mininet1.pingall( protocol="IPv6" )
400 hosts = main.controllers[ 0 ].CLI.hosts()
401 hosts = json.loads( hosts )
402 if not len( hosts ) == len( main.mininetHosts ):
403 stepResult = main.FALSE
404 utilities.assert_equals( expect=main.TRUE,
405 actual=stepResult,
406 onpass="Host discovery PASS",
407 onfail="Host discovery FAIL" )
408 if not stepResult:
409 main.log.debug( hosts )
410 main.cleanup()
411 main.exit()
412
413 main.step( "Disable Reactive forwarding" )
414 appResult = main.controllers[ 0 ].CLI.deactivateApp( "org.onosproject.fwd" )
415 stepResult = appResult
416 utilities.assert_equals( expect=main.TRUE,
417 actual=stepResult,
418 onpass="Successfully deactivated fwd app",
419 onfail="Failed to deactivate fwd app" )
420
421 main.step( "Collect and store host data" )
422 stepResult = main.TRUE
423 macToName = {}
424 for key, value in main.mininetHosts.items():
425 macToName[ value[ 'interfaces' ][ 0 ][ 'mac' ].upper() ] = key
426 dpidToDevice = {}
427 for device in main.devices:
428 dpidToDevice[ device.dpid ] = device
429 hostInitIndex = 0
430 for host in hosts:
431 name = macToName[ host[ 'mac' ] ]
432 dpid = host[ 'location' ][ 'elementId' ]
433 device = dpidToDevice[ dpid ]
434 newHost = Host( hostInitIndex,
435 name, host[ 'id' ], host[ 'mac' ],
436 device, host[ 'location' ][ 'port' ],
437 host[ 'vlan' ], host[ 'ipAddresses' ] )
438 print newHost
439 main.hosts.append( newHost )
440 main.devices[ device.index ].hosts.append( newHost )
441 hostInitIndex += 1
442 utilities.assert_equals( expect=main.TRUE,
443 actual=stepResult,
444 onpass="Successfully collected and stored host data",
445 onfail="Failed to collect and store host data" )
446
447 main.step( "Create one host component for each host and then start host cli" )
448 for host in main.hosts:
449 main.Mininet1.createHostComponent( host.name )
450 hostHandle = getattr( main, host.name )
451 main.log.info( "Starting CLI on host " + str( host.name ) )
452 startCLIResult = hostHandle.startHostCli()
453 host.setHandle( hostHandle )
454 stepResult = startCLIResult
455 utilities.assert_equals( expect=main.TRUE,
456 actual=startCLIResult,
457 onpass="Host CLI started",
458 onfail="Failed to start host CLI" )
459
460 def CASE10( self, main ):
461 """
462 Run all enabled checks
463 """
464 import time
465 from tests.CHOTestMonkey.dependencies.events.Event import EventType
466 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
467
468 main.log.report( "Run all enabled checks" )
469 main.log.report( "__________________________________________________" )
470 main.case( "Run all enabled checks" )
471 main.step( "Run all enabled checks" )
472 main.caseResult = main.TRUE
473 main.eventGenerator.triggerEvent( EventType().CHECK_ALL, EventScheduleMethod().RUN_BLOCK )
474 # Wait for the scheduler to become idle before going to the next testcase
475 with main.eventScheduler.idleCondition:
476 while not main.eventScheduler.isIdle():
477 main.eventScheduler.idleCondition.wait()
478 utilities.assert_equals( expect=main.TRUE,
479 actual=main.caseResult,
480 onpass="All enabled checks passed",
481 onfail="Not all enabled checks passed" )
482 time.sleep( main.caseSleep )
483
484 def CASE20( self, main ):
485 """
486 Bring down/up links and check topology and ping
487 """
488 import time
489 from tests.CHOTestMonkey.dependencies.events.Event import EventType
490 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
491
492 main.log.report( "Bring down/up links and check topology and ping" )
493 main.log.report( "__________________________________________________" )
494 main.case( "Bring down/up links and check topology and ping" )
495 main.step( "Bring down/up links and check topology and ping" )
496 main.caseResult = main.TRUE
497 linkToggleNum = int( main.params[ 'CASE20' ][ 'linkToggleNum' ] )
498 linkDownUpInterval = int( main.params[ 'CASE20' ][ 'linkDownUpInterval' ] )
499 for i in range( 0, linkToggleNum ):
500 main.eventGenerator.triggerEvent( EventType().NETWORK_LINK_RANDOM_TOGGLE, EventScheduleMethod().RUN_BLOCK, linkDownUpInterval )
501 with main.eventScheduler.idleCondition:
502 while not main.eventScheduler.isIdle():
503 main.eventScheduler.idleCondition.wait()
504 utilities.assert_equals( expect=main.TRUE,
505 actual=main.caseResult,
506 onpass="Toggle network links test passed",
507 onfail="Toggle network links test failed" )
508 time.sleep( main.caseSleep )
509
510 def CASE21( self, main ):
511 """
512 Bring down/up a group of links and check topology and ping
513 """
514 import time
515 from tests.CHOTestMonkey.dependencies.events.Event import EventType
516 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
517
518 main.log.report( "Bring down/up a group of links and check topology and ping" )
519 main.log.report( "__________________________________________________" )
520 main.case( "Bring down/up a group of links and check topology and ping" )
521 main.step( "Bring down/up a group of links and check topology and ping" )
522 main.caseResult = main.TRUE
523 linkGroupSize = int( main.params[ 'CASE21' ][ 'linkGroupSize' ] )
524 linkDownDownInterval = int( main.params[ 'CASE21' ][ 'linkDownDownInterval' ] )
525 linkDownUpInterval = int( main.params[ 'CASE21' ][ 'linkDownUpInterval' ] )
526 main.eventGenerator.triggerEvent( EventType().NETWORK_LINK_GROUP_RANDOM_TOGGLE, EventScheduleMethod().RUN_BLOCK, linkGroupSize, linkDownDownInterval, linkDownUpInterval )
527 with main.eventScheduler.idleCondition:
528 while not main.eventScheduler.isIdle():
529 main.eventScheduler.idleCondition.wait()
530 utilities.assert_equals( expect=main.TRUE,
531 actual=main.caseResult,
532 onpass="Toggle network link group test passed",
533 onfail="Toggle network link group test failed" )
534 time.sleep( main.caseSleep )
535
536 def CASE30( self, main ):
537 """
538 Install host intents and check intent states and ping
539 """
540 import time
541 from tests.CHOTestMonkey.dependencies.events.Event import EventType
542 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
543
544 main.log.report( "Install host intents and check intent states and ping" )
545 main.log.report( "__________________________________________________" )
546 main.case( "Install host intents and check intent states and ping" )
547 main.step( "Install host intents and check intent states and ping" )
548 main.caseResult = main.TRUE
549 main.eventGenerator.triggerEvent( EventType().APP_INTENT_HOST_ADD_ALL, EventScheduleMethod().RUN_BLOCK )
550 with main.eventScheduler.idleCondition:
551 while not main.eventScheduler.isIdle():
552 main.eventScheduler.idleCondition.wait()
553 utilities.assert_equals( expect=main.TRUE,
554 actual=main.caseResult,
555 onpass="Install host intents test passed",
556 onfail="Install host intents test failed" )
557 time.sleep( main.caseSleep )
558
559 def CASE31( self, main ):
560 """
561 Uninstall host intents and check intent states and ping
562 """
563 import time
564 from tests.CHOTestMonkey.dependencies.events.Event import EventType
565 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
566
567 main.log.report( "Uninstall host intents and check intent states and ping" )
568 main.log.report( "__________________________________________________" )
569 main.case( "Uninstall host intents and check intent states and ping" )
570 main.step( "Uninstall host intents and check intent states and ping" )
571 main.caseResult = main.TRUE
572 main.eventGenerator.triggerEvent( EventType().APP_INTENT_HOST_DEL_ALL, EventScheduleMethod().RUN_BLOCK )
573 with main.eventScheduler.idleCondition:
574 while not main.eventScheduler.isIdle():
575 main.eventScheduler.idleCondition.wait()
576 utilities.assert_equals( expect=main.TRUE,
577 actual=main.caseResult,
578 onpass="Uninstall host intents test passed",
579 onfail="Uninstall host intents test failed" )
580 time.sleep( main.caseSleep )
581
582 def CASE32( self, main ):
583 """
584 Install point intents and check intent states and ping
585 """
586 import time
587 from tests.CHOTestMonkey.dependencies.events.Event import EventType
588 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
589
590 main.log.report( "Install point intents and check intent states and ping" )
591 main.log.report( "__________________________________________________" )
592 main.case( "Install point intents and check intent states and ping" )
593 main.step( "Install point intents and check intent states and ping" )
594 main.caseResult = main.TRUE
595 main.eventGenerator.triggerEvent( EventType().APP_INTENT_POINT_ADD_ALL, EventScheduleMethod().RUN_BLOCK )
596 with main.eventScheduler.idleCondition:
597 while not main.eventScheduler.isIdle():
598 main.eventScheduler.idleCondition.wait()
599 utilities.assert_equals( expect=main.TRUE,
600 actual=main.caseResult,
601 onpass="Install point intents test passed",
602 onfail="Install point intents test failed" )
603 time.sleep( main.caseSleep )
604
605 def CASE33( self, main ):
606 """
607 Uninstall point intents and check intent states and ping
608 """
609 import time
610 from tests.CHOTestMonkey.dependencies.events.Event import EventType
611 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
612
613 main.log.report( "Uninstall point intents and check intent states and ping" )
614 main.log.report( "__________________________________________________" )
615 main.case( "Uninstall point intents and check intent states and ping" )
616 main.step( "Uninstall point intents and check intent states and ping" )
617 main.caseResult = main.TRUE
618 main.eventGenerator.triggerEvent( EventType().APP_INTENT_POINT_DEL_ALL, EventScheduleMethod().RUN_BLOCK )
619 with main.eventScheduler.idleCondition:
620 while not main.eventScheduler.isIdle():
621 main.eventScheduler.idleCondition.wait()
622 utilities.assert_equals( expect=main.TRUE,
623 actual=main.caseResult,
624 onpass="Uninstall point intents test passed",
625 onfail="Uninstall point intents test failed" )
626 time.sleep( main.caseSleep )
627
628 def CASE40( self, main ):
629 """
630 Randomly bring down one ONOS node
631 """
632 import time
633 import random
634 from tests.CHOTestMonkey.dependencies.events.Event import EventType
635 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
636
637 main.log.report( "Randomly bring down one ONOS node" )
638 main.log.report( "__________________________________________________" )
639 main.case( "Randomly bring down one ONOS node" )
640 main.step( "Randomly bring down one ONOS node" )
641 main.caseResult = main.TRUE
642 availableControllers = []
643 for controller in main.controllers:
644 if controller.isUp():
645 availableControllers.append( controller.index )
646 if len( availableControllers ) == 0:
647 main.log.warn( "No available controllers" )
648 main.caseResult = main.FALSE
649 else:
650 index = random.sample( availableControllers, 1 )
651 main.eventGenerator.triggerEvent( EventType().ONOS_ONOS_DOWN, EventScheduleMethod().RUN_BLOCK, index[ 0 ] )
652 with main.eventScheduler.idleCondition:
653 while not main.eventScheduler.isIdle():
654 main.eventScheduler.idleCondition.wait()
655 utilities.assert_equals( expect=main.TRUE,
656 actual=main.caseResult,
657 onpass="Randomly bring down ONOS test passed",
658 onfail="Randomly bring down ONOS test failed" )
659 time.sleep( main.caseSleep )
660
661 def CASE41( self, main ):
662 """
663 Randomly bring up one ONOS node that is down
664 """
665 import time
666 import random
667 from tests.CHOTestMonkey.dependencies.events.Event import EventType
668 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
669
670 main.log.report( "Randomly bring up one ONOS node that is down" )
671 main.log.report( "__________________________________________________" )
672 main.case( "Randomly bring up one ONOS node that is down" )
673 main.step( "Randomly bring up one ONOS node that is down" )
674 main.caseResult = main.TRUE
675 targetControllers = []
676 for controller in main.controllers:
677 if not controller.isUp():
678 targetControllers.append( controller.index )
679 if len( targetControllers ) == 0:
680 main.log.warn( "All controllers are up" )
681 main.caseResult = main.FALSE
682 else:
683 index = random.sample( targetControllers, 1 )
684 main.eventGenerator.triggerEvent( EventType().ONOS_ONOS_UP, EventScheduleMethod().RUN_BLOCK, index[ 0 ] )
685 with main.eventScheduler.idleCondition:
686 while not main.eventScheduler.isIdle():
687 main.eventScheduler.idleCondition.wait()
688 utilities.assert_equals( expect=main.TRUE,
689 actual=main.caseResult,
690 onpass="Randomly bring up ONOS test passed",
691 onfail="Randomly bring up ONOS test failed" )
692 time.sleep( main.caseSleep )
693
694 def CASE50( self, main ):
695 """
696 Set FlowObjective to True
697 """
698 import time
699 from tests.CHOTestMonkey.dependencies.events.Event import EventType
700 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
701
702 main.log.report( "Set FlowObjective to True" )
703 main.log.report( "__________________________________________________" )
704 main.case( "Set FlowObjective to True" )
705 main.step( "Set FlowObjective to True" )
706 main.caseResult = main.TRUE
707 main.eventGenerator.triggerEvent( EventType().ONOS_SET_FLOWOBJ, EventScheduleMethod().RUN_BLOCK, 'true' )
708 with main.eventScheduler.idleCondition:
709 while not main.eventScheduler.isIdle():
710 main.eventScheduler.idleCondition.wait()
711 utilities.assert_equals( expect=main.TRUE,
712 actual=main.caseResult,
713 onpass="Set FlowObjective test passed",
714 onfail="Set FlowObjective test failed" )
715 time.sleep( main.caseSleep )
716
717 def CASE51( self, main ):
718 """
719 Set FlowObjective to False
720 """
721 import time
722 from tests.CHOTestMonkey.dependencies.events.Event import EventType
723 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
724
725 main.log.report( "Set FlowObjective to False" )
726 main.log.report( "__________________________________________________" )
727 main.case( "Set FlowObjective to False" )
728 main.step( "Set FlowObjective to False" )
729 main.caseResult = main.TRUE
730 main.eventGenerator.triggerEvent( EventType().ONOS_SET_FLOWOBJ, EventScheduleMethod().RUN_BLOCK, 'false' )
731 with main.eventScheduler.idleCondition:
732 while not main.eventScheduler.isIdle():
733 main.eventScheduler.idleCondition.wait()
734 utilities.assert_equals( expect=main.TRUE,
735 actual=main.caseResult,
736 onpass="Set FlowObjective test passed",
737 onfail="Set FlowObjective test failed" )
738 time.sleep( main.caseSleep )
739
740 def CASE60( self, main ):
741 """
742 Balance device masters
743 """
744 import time
745 from tests.CHOTestMonkey.dependencies.events.Event import EventType
746 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
747
748 main.log.report( "Balance device masters" )
749 main.log.report( "__________________________________________________" )
750 main.case( "Balance device masters" )
751 main.step( "Balance device masters" )
752 main.caseResult = main.TRUE
753 main.eventGenerator.triggerEvent( EventType().ONOS_BALANCE_MASTERS, EventScheduleMethod().RUN_BLOCK )
754 with main.eventScheduler.idleCondition:
755 while not main.eventScheduler.isIdle():
756 main.eventScheduler.idleCondition.wait()
757 utilities.assert_equals( expect=main.TRUE,
758 actual=main.caseResult,
759 onpass="Balance masters test passed",
760 onfail="Balance masters test failed" )
761 time.sleep( main.caseSleep )
762
763 def CASE90( self, main ):
764 """
765 Sleep for some time
766 """
767 import time
768 from tests.CHOTestMonkey.dependencies.events.Event import EventType
769 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
770
771 main.log.report( "Sleep for some time" )
772 main.log.report( "__________________________________________________" )
773 main.case( "Sleep for some time" )
774 main.step( "Sleep for some time" )
775 main.caseResult = main.TRUE
776 sleepSec = int( main.params[ 'CASE90' ][ 'sleepSec' ] )
777 main.eventGenerator.triggerEvent( EventType().TEST_SLEEP, EventScheduleMethod().RUN_BLOCK, sleepSec )
778 with main.eventScheduler.idleCondition:
779 while not main.eventScheduler.isIdle():
780 main.eventScheduler.idleCondition.wait()
781 utilities.assert_equals( expect=main.TRUE,
782 actual=main.caseResult,
783 onpass="Sleep test passed",
784 onfail="Sleep test failed" )
785 time.sleep( main.caseSleep )
786
787 def CASE100( self, main ):
788 """
789 Do something else?
790 """
791 import time
792
793 main.log.report( "Do something else?" )
794 main.log.report( "__________________________________________________" )
795 main.case( "..." )
796
797 main.step( "Wait until the test stops" )
798
799 main.caseResult = main.TRUE
800 utilities.assert_equals( expect=main.TRUE,
801 actual=main.caseResult,
802 onpass="Test PASS",
803 onfail="Test FAIL" )
804
805 testDuration = int( main.params[ 'TEST' ][ 'testDuration' ] )
806 time.sleep( testDuration )