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