blob: 78bed5547906b91f2ec2b9d1ff6760ff29de8131 [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':
Jon Hallbd60ea02016-08-23 10:03:59 -0700119 packageResult = main.ONOSbench.buckBuild()
You Wangdb927a52016-02-26 11:03:28 -0800120 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
Chiyu Chengef109502016-11-21 15:51:38 -0800150 main.step( "Set up ONOS secure SSH" )
151 secureSshResult = main.TRUE
152 for i in range( int( main.numCtrls ) ):
You Wang81eff0f2016-11-22 13:20:51 -0800153 secureSshResult = secureSshResult and main.ONOSbench.onosSecureSSH( node=main.onosIPs[i] )
Chiyu Chengef109502016-11-21 15:51:38 -0800154 utilities.assert_equals( expect=main.TRUE, actual=secureSshResult,
155 onpass="Test step PASS",
156 onfail="Test step FAIL" )
157
You Wang0357c432017-01-09 16:13:33 -0800158 time.sleep( 5 )
159 main.step( "Starting ONOS service" )
160 stopResult = main.TRUE
161 startResult = main.TRUE
162 onosIsUp = main.TRUE
163 for i in range( main.numCtrls ):
164 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
165 if onosIsUp == main.TRUE:
166 main.log.report( "ONOS instance is up and ready" )
167 else:
168 main.log.report( "ONOS instance may not be up, stop and " +
169 "start ONOS again " )
170 for i in range( main.numCtrls ):
171 stopResult = stopResult and \
172 main.ONOSbench.onosStop( main.ONOSip[ i ] )
173 for i in range( main.numCtrls ):
174 startResult = startResult and \
175 main.ONOSbench.onosStart( main.ONOSip[ i ] )
176 stepResult = onosIsUp and stopResult and startResult
177 utilities.assert_equals( expect=main.TRUE,
178 actual=stepResult,
179 onpass="ONOS service is ready",
180 onfail="ONOS service did not start properly" )
181
You Wangdb927a52016-02-26 11:03:28 -0800182 main.step( "Start ONOS CLI on all nodes" )
183 cliResult = main.TRUE
184 startCliResult = main.TRUE
185 pool = []
186 for controller in main.controllers:
187 t = main.Thread( target=controller.startCLI,
188 threadID=main.threadID,
189 name="startOnosCli",
190 args=[ ] )
191 pool.append(t)
192 t.start()
193 main.threadID = main.threadID + 1
194 for t in pool:
195 t.join()
196 startCliResult = startCliResult and t.result
197 if not startCliResult:
198 main.log.info( "ONOS CLI did not start up properly" )
199 main.cleanup()
200 main.exit()
201 else:
202 main.log.info( "Successful CLI startup" )
203 startCliResult = main.TRUE
204 utilities.assert_equals( expect=main.TRUE,
205 actual=startCliResult,
206 onpass="Test step PASS",
207 onfail="Test step FAIL" )
208
209 main.step( "Set IPv6 cfg parameters for Neighbor Discovery" )
210 setIPv6CfgSleep = int( main.params[ 'TEST' ][ 'setIPv6CfgSleep' ] )
211 if main.enableIPv6:
212 time.sleep( setIPv6CfgSleep )
You Wang5f4f36e2016-09-21 15:30:30 -0700213 cfgResult1 = main.controllers[ 0 ].CLI.setCfg( "org.onosproject.incubator.net.neighbour.impl.NeighbourResolutionManager",
214 "ndpEnabled",
You Wangdb927a52016-02-26 11:03:28 -0800215 "true" )
216 time.sleep( setIPv6CfgSleep )
217 cfgResult2 = main.controllers[ 0 ].CLI.setCfg( "org.onosproject.provider.host.impl.HostLocationProvider",
You Wang092d9b22016-11-22 13:38:01 -0800218 "useIpv6ND",
You Wangdb927a52016-02-26 11:03:28 -0800219 "true" )
220 else:
221 main.log.info( "Skipped setting IPv6 cfg parameters as it is disabled in params file" )
222 cfgResult1 = main.TRUE
223 cfgResult2 = main.TRUE
224 cfgResult = cfgResult1 and cfgResult2
225 utilities.assert_equals( expect=main.TRUE,
226 actual=cfgResult,
227 onpass="ipv6NeighborDiscovery cfg is set to true",
228 onfail="Failed to cfg set ipv6NeighborDiscovery" )
229
230 main.step( "Start a thread for the scheduler" )
231 t = main.Thread( target=main.eventScheduler.startScheduler,
232 threadID=main.threadID,
233 name="startScheduler",
234 args=[] )
235 t.start()
236 stepResult = main.TRUE
237 with main.variableLock:
238 main.threadID = main.threadID + 1
239
240 utilities.assert_equals( expect=main.TRUE,
241 actual=stepResult,
242 onpass="Test step PASS",
243 onfail="Test step FAIL" )
244
245 main.step( "Start a thread to listen to and handle network, ONOS and application events" )
246 t = main.Thread( target=main.eventGenerator.startListener,
247 threadID=main.threadID,
248 name="startListener",
249 args=[] )
250 t.start()
251 with main.variableLock:
252 main.threadID = main.threadID + 1
253
254 caseResult = installResult and uninstallResult and startCliResult and cfgResult
255 utilities.assert_equals( expect=main.TRUE,
256 actual=caseResult,
257 onpass="Set up test environment PASS",
258 onfail="Set up test environment FAIL" )
259
260 def CASE1( self, main ):
261 """
262 Load Mininet topology and balances all switches
263 """
264 import re
265 import time
266 import copy
267
268 main.topoIndex = "topo" + str ( main.params[ 'TEST' ][ 'topo' ] )
269
270 main.log.report( "Load Mininet topology and Balance all Mininet switches across controllers" )
271 main.log.report( "________________________________________________________________________" )
272 main.case( "Assign and Balance all Mininet switches across controllers" )
273
274 main.step( "Start Mininet topology" )
275 newTopo = main.params[ 'TOPO' ][ main.topoIndex ][ 'fileName' ]
276 mininetDir = main.Mininet1.home + "/custom/"
277 topoPath = main.testDir + "/" + main.TEST + "/dependencies/topologies/" + newTopo
278 main.ONOSbench.secureCopy( main.Mininet1.user_name, main.Mininet1.ip_address, topoPath, mininetDir, direction="to" )
279 topoPath = mininetDir + newTopo
280 startStatus = main.Mininet1.startNet( topoFile = topoPath )
281 main.mininetSwitches = main.Mininet1.getSwitches()
282 main.mininetHosts = main.Mininet1.getHosts()
You Wang55503a32016-06-27 15:11:40 -0700283 main.mininetLinks = main.Mininet1.getLinks( timeout=60 )
You Wangdb927a52016-02-26 11:03:28 -0800284 utilities.assert_equals( expect=main.TRUE,
285 actual=startStatus,
286 onpass="Start Mininet topology test PASS",
287 onfail="Start Mininet topology test FAIL" )
288
289 main.step( "Assign switches to controllers" )
290 switchMastership = main.TRUE
291 for switchName in main.mininetSwitches.keys():
292 main.Mininet1.assignSwController( sw=switchName, ip=main.onosIPs )
293 response = main.Mininet1.getSwController( switchName )
294 print( "Response is " + str( response ) )
295 if re.search( "tcp:" + main.onosIPs[ 0 ], response ):
296 switchMastership = switchMastership and main.TRUE
297 else:
298 switchMastership = main.FALSE
299 utilities.assert_equals( expect=main.TRUE,
300 actual=switchMastership,
301 onpass="Assign switches to controllers test PASS",
302 onfail="Assign switches to controllers test FAIL" )
303 # Waiting here to make sure topology converges across all nodes
304 sleep = int( main.params[ 'TEST' ][ 'loadTopoSleep' ] )
305 time.sleep( sleep )
306
307 main.step( "Balance devices across controllers" )
308 balanceResult = main.ONOScli1.balanceMasters()
309 # giving some breathing time for ONOS to complete re-balance
310 time.sleep( sleep )
311
312 caseResult = ( startStatus and switchMastership and balanceResult )
313 utilities.assert_equals( expect=main.TRUE,
314 actual=caseResult,
315 onpass="Starting new Att topology test PASS",
316 onfail="Starting new Att topology test FAIL" )
317
318 def CASE2( self, main ):
319 """
320 Collect and store device and link data from ONOS
321 """
322 import json
323 from tests.CHOTestMonkey.dependencies.elements.NetworkElement import Device, Link
324
325 main.log.report( "Collect and Store topology details from ONOS" )
326 main.log.report( "____________________________________________________________________" )
327 main.case( "Collect and Store Topology Details from ONOS" )
328 topoResult = main.TRUE
329 topologyOutput = main.ONOScli1.topology()
330 topologyResult = main.ONOScli1.getTopology( topologyOutput )
331 ONOSDeviceNum = int( topologyResult[ 'devices' ] )
332 ONOSLinkNum = int( topologyResult[ 'links' ] )
333 mininetSwitchNum = len( main.mininetSwitches )
334 mininetLinkNum = ( len( main.mininetLinks ) - len( main.mininetHosts ) ) * 2
335 if mininetSwitchNum == ONOSDeviceNum and mininetLinkNum == ONOSLinkNum:
336 main.step( "Collect and store device data" )
337 stepResult = main.TRUE
338 dpidToName = {}
339 for key, value in main.mininetSwitches.items():
340 dpidToName[ 'of:' + str( value[ 'dpid' ] ) ] = key
341 devicesRaw = main.ONOScli1.devices()
342 devices = json.loads( devicesRaw )
343 deviceInitIndex = 0
344 for device in devices:
345 name = dpidToName[ device[ 'id' ] ]
346 newDevice = Device( deviceInitIndex, name, device[ 'id' ] )
347 print newDevice
348 main.devices.append( newDevice )
349 deviceInitIndex += 1
350 utilities.assert_equals( expect=main.TRUE,
351 actual=stepResult,
352 onpass="Successfully collected and stored device data",
353 onfail="Failed to collect and store device data" )
354
355 main.step( "Collect and store link data" )
356 stepResult = main.TRUE
357 linksRaw = main.ONOScli1.links()
358 links = json.loads( linksRaw )
359 linkInitIndex = 0
360 for link in links:
361 for device in main.devices:
362 if device.dpid == link[ 'src' ][ 'device' ]:
363 deviceA = device
364 elif device.dpid == link[ 'dst' ][ 'device' ]:
365 deviceB = device
366 assert deviceA != None and deviceB != None
367 newLink = Link( linkInitIndex, deviceA, link[ 'src' ][ 'port' ], deviceB, link[ 'dst' ][ 'port' ] )
368 print newLink
369 main.links.append( newLink )
370 linkInitIndex += 1
371 # Set backward links and outgoing links of devices
372 for linkA in main.links:
373 linkA.deviceA.outgoingLinks.append( linkA )
374 if linkA.backwardLink != None:
375 continue
376 for linkB in main.links:
377 if linkB.backwardLink != None:
378 continue
379 if linkA.deviceA == linkB.deviceB and\
380 linkA.deviceB == linkB.deviceA and\
381 linkA.portA == linkB.portB and\
382 linkA.portB == linkB.portA:
383 linkA.setBackwardLink( linkB )
384 linkB.setBackwardLink( linkA )
385 utilities.assert_equals( expect=main.TRUE,
386 actual=stepResult,
387 onpass="Successfully collected and stored link data",
388 onfail="Failed to collect and store link data" )
389 else:
390 main.log.info( "Devices (expected): %s, Links (expected): %s" % ( mininetSwitchNum, mininetLinkNum ) )
391 main.log.info( "Devices (actual): %s, Links (actual): %s" % ( ONOSDeviceNum, ONOSLinkNum ) )
392 topoResult = main.FALSE
393
394 caseResult = topoResult
395 utilities.assert_equals( expect=main.TRUE,
396 actual=caseResult,
397 onpass="Saving ONOS topology data test PASS",
398 onfail="Saving ONOS topology data test FAIL" )
399
400 if not caseResult:
401 main.log.info("Topology does not match, exiting test...")
402 main.cleanup()
403 main.exit()
404
405 def CASE3( self, main ):
406 """
407 Collect and store host data from ONOS
408 """
409 import json
410 from tests.CHOTestMonkey.dependencies.elements.NetworkElement import Host
411
412 main.log.report( "Collect and store host adta from ONOS" )
413 main.log.report( "______________________________________________" )
414 main.case( "Use fwd app and pingall to discover all the hosts, then collect and store host data" )
415
416 main.step( "Enable Reactive forwarding" )
417 appResult = main.controllers[ 0 ].CLI.activateApp( "org.onosproject.fwd" )
418 cfgResult1 = main.TRUE
419 cfgResult2 = main.TRUE
420 if main.enableIPv6:
421 cfgResult1 = main.controllers[ 0 ].CLI.setCfg( "org.onosproject.fwd.ReactiveForwarding", "ipv6Forwarding", "true" )
422 cfgResult2 = main.controllers[ 0 ].CLI.setCfg( "org.onosproject.fwd.ReactiveForwarding", "matchIpv6Address", "true" )
423 stepResult = appResult and cfgResult1 and cfgResult2
424 utilities.assert_equals( expect=main.TRUE,
425 actual=stepResult,
426 onpass="Successfully enabled reactive forwarding",
427 onfail="Failed to enable reactive forwarding" )
428
429 main.step( "Discover hosts using pingall" )
430 stepResult = main.TRUE
431 main.Mininet1.pingall()
432 if main.enableIPv6:
433 ping6Result = main.Mininet1.pingall( protocol="IPv6" )
434 hosts = main.controllers[ 0 ].CLI.hosts()
435 hosts = json.loads( hosts )
436 if not len( hosts ) == len( main.mininetHosts ):
437 stepResult = main.FALSE
438 utilities.assert_equals( expect=main.TRUE,
439 actual=stepResult,
440 onpass="Host discovery PASS",
441 onfail="Host discovery FAIL" )
442 if not stepResult:
443 main.log.debug( hosts )
444 main.cleanup()
445 main.exit()
446
447 main.step( "Disable Reactive forwarding" )
448 appResult = main.controllers[ 0 ].CLI.deactivateApp( "org.onosproject.fwd" )
449 stepResult = appResult
450 utilities.assert_equals( expect=main.TRUE,
451 actual=stepResult,
452 onpass="Successfully deactivated fwd app",
453 onfail="Failed to deactivate fwd app" )
454
455 main.step( "Collect and store host data" )
456 stepResult = main.TRUE
457 macToName = {}
458 for key, value in main.mininetHosts.items():
459 macToName[ value[ 'interfaces' ][ 0 ][ 'mac' ].upper() ] = key
460 dpidToDevice = {}
461 for device in main.devices:
462 dpidToDevice[ device.dpid ] = device
463 hostInitIndex = 0
464 for host in hosts:
465 name = macToName[ host[ 'mac' ] ]
466 dpid = host[ 'location' ][ 'elementId' ]
467 device = dpidToDevice[ dpid ]
468 newHost = Host( hostInitIndex,
469 name, host[ 'id' ], host[ 'mac' ],
470 device, host[ 'location' ][ 'port' ],
471 host[ 'vlan' ], host[ 'ipAddresses' ] )
472 print newHost
473 main.hosts.append( newHost )
474 main.devices[ device.index ].hosts.append( newHost )
475 hostInitIndex += 1
476 utilities.assert_equals( expect=main.TRUE,
477 actual=stepResult,
478 onpass="Successfully collected and stored host data",
479 onfail="Failed to collect and store host data" )
480
481 main.step( "Create one host component for each host and then start host cli" )
482 for host in main.hosts:
483 main.Mininet1.createHostComponent( host.name )
484 hostHandle = getattr( main, host.name )
485 main.log.info( "Starting CLI on host " + str( host.name ) )
486 startCLIResult = hostHandle.startHostCli()
487 host.setHandle( hostHandle )
488 stepResult = startCLIResult
489 utilities.assert_equals( expect=main.TRUE,
490 actual=startCLIResult,
491 onpass="Host CLI started",
492 onfail="Failed to start host CLI" )
493
494 def CASE10( self, main ):
495 """
496 Run all enabled checks
497 """
498 import time
499 from tests.CHOTestMonkey.dependencies.events.Event import EventType
500 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
501
502 main.log.report( "Run all enabled checks" )
503 main.log.report( "__________________________________________________" )
504 main.case( "Run all enabled checks" )
505 main.step( "Run all enabled checks" )
506 main.caseResult = main.TRUE
507 main.eventGenerator.triggerEvent( EventType().CHECK_ALL, EventScheduleMethod().RUN_BLOCK )
508 # Wait for the scheduler to become idle before going to the next testcase
509 with main.eventScheduler.idleCondition:
510 while not main.eventScheduler.isIdle():
511 main.eventScheduler.idleCondition.wait()
512 utilities.assert_equals( expect=main.TRUE,
513 actual=main.caseResult,
514 onpass="All enabled checks passed",
515 onfail="Not all enabled checks passed" )
516 time.sleep( main.caseSleep )
517
518 def CASE20( self, main ):
519 """
520 Bring down/up links and check topology and ping
521 """
522 import time
523 from tests.CHOTestMonkey.dependencies.events.Event import EventType
524 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
525
526 main.log.report( "Bring down/up links and check topology and ping" )
527 main.log.report( "__________________________________________________" )
528 main.case( "Bring down/up links and check topology and ping" )
529 main.step( "Bring down/up links and check topology and ping" )
530 main.caseResult = main.TRUE
531 linkToggleNum = int( main.params[ 'CASE20' ][ 'linkToggleNum' ] )
532 linkDownUpInterval = int( main.params[ 'CASE20' ][ 'linkDownUpInterval' ] )
533 for i in range( 0, linkToggleNum ):
534 main.eventGenerator.triggerEvent( EventType().NETWORK_LINK_RANDOM_TOGGLE, EventScheduleMethod().RUN_BLOCK, linkDownUpInterval )
535 with main.eventScheduler.idleCondition:
536 while not main.eventScheduler.isIdle():
537 main.eventScheduler.idleCondition.wait()
538 utilities.assert_equals( expect=main.TRUE,
539 actual=main.caseResult,
540 onpass="Toggle network links test passed",
541 onfail="Toggle network links test failed" )
542 time.sleep( main.caseSleep )
543
544 def CASE21( self, main ):
545 """
546 Bring down/up a group of links and check topology and ping
547 """
548 import time
549 from tests.CHOTestMonkey.dependencies.events.Event import EventType
550 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
551
552 main.log.report( "Bring down/up a group of links and check topology and ping" )
553 main.log.report( "__________________________________________________" )
554 main.case( "Bring down/up a group of links and check topology and ping" )
555 main.step( "Bring down/up a group of links and check topology and ping" )
556 main.caseResult = main.TRUE
557 linkGroupSize = int( main.params[ 'CASE21' ][ 'linkGroupSize' ] )
558 linkDownDownInterval = int( main.params[ 'CASE21' ][ 'linkDownDownInterval' ] )
559 linkDownUpInterval = int( main.params[ 'CASE21' ][ 'linkDownUpInterval' ] )
560 main.eventGenerator.triggerEvent( EventType().NETWORK_LINK_GROUP_RANDOM_TOGGLE, EventScheduleMethod().RUN_BLOCK, linkGroupSize, linkDownDownInterval, linkDownUpInterval )
561 with main.eventScheduler.idleCondition:
562 while not main.eventScheduler.isIdle():
563 main.eventScheduler.idleCondition.wait()
564 utilities.assert_equals( expect=main.TRUE,
565 actual=main.caseResult,
566 onpass="Toggle network link group test passed",
567 onfail="Toggle network link group test failed" )
568 time.sleep( main.caseSleep )
569
570 def CASE30( self, main ):
571 """
572 Install host intents and check intent states and ping
573 """
574 import time
575 from tests.CHOTestMonkey.dependencies.events.Event import EventType
576 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
577
578 main.log.report( "Install host intents and check intent states and ping" )
579 main.log.report( "__________________________________________________" )
580 main.case( "Install host intents and check intent states and ping" )
581 main.step( "Install host intents and check intent states and ping" )
582 main.caseResult = main.TRUE
583 main.eventGenerator.triggerEvent( EventType().APP_INTENT_HOST_ADD_ALL, EventScheduleMethod().RUN_BLOCK )
584 with main.eventScheduler.idleCondition:
585 while not main.eventScheduler.isIdle():
586 main.eventScheduler.idleCondition.wait()
587 utilities.assert_equals( expect=main.TRUE,
588 actual=main.caseResult,
589 onpass="Install host intents test passed",
590 onfail="Install host intents test failed" )
591 time.sleep( main.caseSleep )
592
593 def CASE31( self, main ):
594 """
595 Uninstall host intents and check intent states and ping
596 """
597 import time
598 from tests.CHOTestMonkey.dependencies.events.Event import EventType
599 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
600
601 main.log.report( "Uninstall host intents and check intent states and ping" )
602 main.log.report( "__________________________________________________" )
603 main.case( "Uninstall host intents and check intent states and ping" )
604 main.step( "Uninstall host intents and check intent states and ping" )
605 main.caseResult = main.TRUE
606 main.eventGenerator.triggerEvent( EventType().APP_INTENT_HOST_DEL_ALL, EventScheduleMethod().RUN_BLOCK )
607 with main.eventScheduler.idleCondition:
608 while not main.eventScheduler.isIdle():
609 main.eventScheduler.idleCondition.wait()
610 utilities.assert_equals( expect=main.TRUE,
611 actual=main.caseResult,
612 onpass="Uninstall host intents test passed",
613 onfail="Uninstall host intents test failed" )
614 time.sleep( main.caseSleep )
615
616 def CASE32( self, main ):
617 """
618 Install point intents and check intent states and ping
619 """
620 import time
621 from tests.CHOTestMonkey.dependencies.events.Event import EventType
622 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
623
624 main.log.report( "Install point intents and check intent states and ping" )
625 main.log.report( "__________________________________________________" )
626 main.case( "Install point intents and check intent states and ping" )
627 main.step( "Install point intents and check intent states and ping" )
628 main.caseResult = main.TRUE
629 main.eventGenerator.triggerEvent( EventType().APP_INTENT_POINT_ADD_ALL, EventScheduleMethod().RUN_BLOCK )
630 with main.eventScheduler.idleCondition:
631 while not main.eventScheduler.isIdle():
632 main.eventScheduler.idleCondition.wait()
633 utilities.assert_equals( expect=main.TRUE,
634 actual=main.caseResult,
635 onpass="Install point intents test passed",
636 onfail="Install point intents test failed" )
637 time.sleep( main.caseSleep )
638
639 def CASE33( self, main ):
640 """
641 Uninstall point intents and check intent states and ping
642 """
643 import time
644 from tests.CHOTestMonkey.dependencies.events.Event import EventType
645 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
646
647 main.log.report( "Uninstall point intents and check intent states and ping" )
648 main.log.report( "__________________________________________________" )
649 main.case( "Uninstall point intents and check intent states and ping" )
650 main.step( "Uninstall point intents and check intent states and ping" )
651 main.caseResult = main.TRUE
652 main.eventGenerator.triggerEvent( EventType().APP_INTENT_POINT_DEL_ALL, EventScheduleMethod().RUN_BLOCK )
653 with main.eventScheduler.idleCondition:
654 while not main.eventScheduler.isIdle():
655 main.eventScheduler.idleCondition.wait()
656 utilities.assert_equals( expect=main.TRUE,
657 actual=main.caseResult,
658 onpass="Uninstall point intents test passed",
659 onfail="Uninstall point intents test failed" )
660 time.sleep( main.caseSleep )
661
662 def CASE40( self, main ):
663 """
664 Randomly bring down one ONOS node
665 """
666 import time
667 import random
668 from tests.CHOTestMonkey.dependencies.events.Event import EventType
669 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
670
671 main.log.report( "Randomly bring down one ONOS node" )
672 main.log.report( "__________________________________________________" )
673 main.case( "Randomly bring down one ONOS node" )
674 main.step( "Randomly bring down one ONOS node" )
675 main.caseResult = main.TRUE
676 availableControllers = []
677 for controller in main.controllers:
678 if controller.isUp():
679 availableControllers.append( controller.index )
680 if len( availableControllers ) == 0:
681 main.log.warn( "No available controllers" )
682 main.caseResult = main.FALSE
683 else:
684 index = random.sample( availableControllers, 1 )
685 main.eventGenerator.triggerEvent( EventType().ONOS_ONOS_DOWN, EventScheduleMethod().RUN_BLOCK, index[ 0 ] )
686 with main.eventScheduler.idleCondition:
687 while not main.eventScheduler.isIdle():
688 main.eventScheduler.idleCondition.wait()
689 utilities.assert_equals( expect=main.TRUE,
690 actual=main.caseResult,
691 onpass="Randomly bring down ONOS test passed",
692 onfail="Randomly bring down ONOS test failed" )
693 time.sleep( main.caseSleep )
694
695 def CASE41( self, main ):
696 """
697 Randomly bring up one ONOS node that is down
698 """
699 import time
700 import random
701 from tests.CHOTestMonkey.dependencies.events.Event import EventType
702 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
703
704 main.log.report( "Randomly bring up one ONOS node that is down" )
705 main.log.report( "__________________________________________________" )
706 main.case( "Randomly bring up one ONOS node that is down" )
707 main.step( "Randomly bring up one ONOS node that is down" )
708 main.caseResult = main.TRUE
709 targetControllers = []
710 for controller in main.controllers:
711 if not controller.isUp():
712 targetControllers.append( controller.index )
713 if len( targetControllers ) == 0:
714 main.log.warn( "All controllers are up" )
715 main.caseResult = main.FALSE
716 else:
717 index = random.sample( targetControllers, 1 )
718 main.eventGenerator.triggerEvent( EventType().ONOS_ONOS_UP, EventScheduleMethod().RUN_BLOCK, index[ 0 ] )
719 with main.eventScheduler.idleCondition:
720 while not main.eventScheduler.isIdle():
721 main.eventScheduler.idleCondition.wait()
722 utilities.assert_equals( expect=main.TRUE,
723 actual=main.caseResult,
724 onpass="Randomly bring up ONOS test passed",
725 onfail="Randomly bring up ONOS test failed" )
726 time.sleep( main.caseSleep )
727
728 def CASE50( self, main ):
729 """
730 Set FlowObjective to True
731 """
732 import time
733 from tests.CHOTestMonkey.dependencies.events.Event import EventType
734 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
735
736 main.log.report( "Set FlowObjective to True" )
737 main.log.report( "__________________________________________________" )
738 main.case( "Set FlowObjective to True" )
739 main.step( "Set FlowObjective to True" )
740 main.caseResult = main.TRUE
741 main.eventGenerator.triggerEvent( EventType().ONOS_SET_FLOWOBJ, EventScheduleMethod().RUN_BLOCK, 'true' )
742 with main.eventScheduler.idleCondition:
743 while not main.eventScheduler.isIdle():
744 main.eventScheduler.idleCondition.wait()
745 utilities.assert_equals( expect=main.TRUE,
746 actual=main.caseResult,
747 onpass="Set FlowObjective test passed",
748 onfail="Set FlowObjective test failed" )
749 time.sleep( main.caseSleep )
750
751 def CASE51( self, main ):
752 """
753 Set FlowObjective to False
754 """
755 import time
756 from tests.CHOTestMonkey.dependencies.events.Event import EventType
757 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
758
759 main.log.report( "Set FlowObjective to False" )
760 main.log.report( "__________________________________________________" )
761 main.case( "Set FlowObjective to False" )
762 main.step( "Set FlowObjective to False" )
763 main.caseResult = main.TRUE
764 main.eventGenerator.triggerEvent( EventType().ONOS_SET_FLOWOBJ, EventScheduleMethod().RUN_BLOCK, 'false' )
765 with main.eventScheduler.idleCondition:
766 while not main.eventScheduler.isIdle():
767 main.eventScheduler.idleCondition.wait()
768 utilities.assert_equals( expect=main.TRUE,
769 actual=main.caseResult,
770 onpass="Set FlowObjective test passed",
771 onfail="Set FlowObjective test failed" )
772 time.sleep( main.caseSleep )
773
774 def CASE60( self, main ):
775 """
776 Balance device masters
777 """
778 import time
779 from tests.CHOTestMonkey.dependencies.events.Event import EventType
780 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
781
782 main.log.report( "Balance device masters" )
783 main.log.report( "__________________________________________________" )
784 main.case( "Balance device masters" )
785 main.step( "Balance device masters" )
786 main.caseResult = main.TRUE
787 main.eventGenerator.triggerEvent( EventType().ONOS_BALANCE_MASTERS, EventScheduleMethod().RUN_BLOCK )
788 with main.eventScheduler.idleCondition:
789 while not main.eventScheduler.isIdle():
790 main.eventScheduler.idleCondition.wait()
791 utilities.assert_equals( expect=main.TRUE,
792 actual=main.caseResult,
793 onpass="Balance masters test passed",
794 onfail="Balance masters test failed" )
795 time.sleep( main.caseSleep )
796
You Wang7a27f3a2016-07-05 10:12:27 -0700797 def CASE70( self, main ):
798 """
799 Randomly generate events
800 """
801 import time
802 import random
803 from tests.CHOTestMonkey.dependencies.events.Event import EventType
804 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
805
806 main.log.report( "Randomly generate events" )
807 main.log.report( "__________________________________________________" )
808 main.case( "Randomly generate events" )
809 main.step( "Randomly generate events" )
810 main.caseResult = main.TRUE
811 sleepSec = int( main.params[ 'CASE70' ][ 'sleepSec' ] )
812 hostIntentNum = 0
813 pointIntentNum = 0
814 downDeviceNum = 0
815 downLinkNum = 0
You Wangf6e98a82016-11-14 14:46:49 -0800816 flowObj = False
You Wang7a27f3a2016-07-05 10:12:27 -0700817 upControllers = [ 1, 2, 3 ]
818 while True:
819 events = []
You Wangf6e98a82016-11-14 14:46:49 -0800820 for i in range( int( main.params[ 'CASE70' ][ 'toggleFlowObj' ] ) ):
821 events.append( 'toggle-flowobj' )
You Wang7a27f3a2016-07-05 10:12:27 -0700822 for i in range( int( main.params[ 'CASE70' ][ 'addHostIntentWeight' ] ) ):
823 events.append( 'add-host-intent' )
824 for i in range( int( main.params[ 'CASE70' ][ 'addPointIntentWeight' ] ) ):
825 events.append( 'add-point-intent' )
826 for i in range( int( main.params[ 'CASE70' ][ 'linkDownWeight' ] ) ):
827 events.append( 'link-down' )
828 for i in range( int( main.params[ 'CASE70' ][ 'deviceDownWeight' ] ) ):
829 events.append( 'device-down' )
830 for i in range( int( pow( hostIntentNum, 1.5 ) / 100 ) ):
831 events.append( 'del-host-intent' )
You Wang52163202016-07-14 16:37:15 -0700832 for i in range( int( pow( pointIntentNum, 1.5 ) / 100 ) ):
You Wang7a27f3a2016-07-05 10:12:27 -0700833 events.append( 'del-point-intent' )
834 for i in range( pow( 2, downLinkNum ) - 1 ):
835 events.append( 'link-up' )
836 for i in range( pow( 5, downDeviceNum ) - 1 ):
837 events.append( 'device-up' )
838 main.log.debug( events )
839 event = random.sample( events, 1 )[ 0 ]
840 if event == 'add-host-intent':
841 n = random.randint( 5, 50 )
842 for i in range( n ):
843 cliIndex = random.sample( upControllers, 1 )[ 0 ]
You Wangc848af12016-07-14 09:53:58 -0700844 main.eventGenerator.triggerEvent( EventType().APP_INTENT_HOST_ADD, EventScheduleMethod().RUN_BLOCK, 'random', 'random', cliIndex )
You Wang7a27f3a2016-07-05 10:12:27 -0700845 hostIntentNum += 1
You Wang7a27f3a2016-07-05 10:12:27 -0700846 elif event == 'del-host-intent':
847 n = random.randint( 5, hostIntentNum )
848 for i in range( n ):
849 cliIndex = random.sample( upControllers, 1 )[ 0 ]
You Wangc848af12016-07-14 09:53:58 -0700850 main.eventGenerator.triggerEvent( EventType().APP_INTENT_HOST_DEL, EventScheduleMethod().RUN_BLOCK, 'random', 'random', cliIndex )
You Wang7a27f3a2016-07-05 10:12:27 -0700851 hostIntentNum -= 1
You Wang7a27f3a2016-07-05 10:12:27 -0700852 elif event == 'add-point-intent':
853 n = random.randint( 5, 50 )
854 for i in range( n ):
855 cliIndex = random.sample( upControllers, 1 )[ 0 ]
You Wangc848af12016-07-14 09:53:58 -0700856 main.eventGenerator.triggerEvent( EventType().APP_INTENT_POINT_ADD, EventScheduleMethod().RUN_BLOCK, 'random', 'random', cliIndex, 'bidirectional' )
You Wang52163202016-07-14 16:37:15 -0700857 pointIntentNum += 2
You Wang7a27f3a2016-07-05 10:12:27 -0700858 elif event == 'del-point-intent':
You Wang52163202016-07-14 16:37:15 -0700859 n = random.randint( 5, pointIntentNum / 2 )
You Wang7a27f3a2016-07-05 10:12:27 -0700860 for i in range( n ):
861 cliIndex = random.sample( upControllers, 1 )[ 0 ]
You Wangc848af12016-07-14 09:53:58 -0700862 main.eventGenerator.triggerEvent( EventType().APP_INTENT_POINT_DEL, EventScheduleMethod().RUN_BLOCK, 'random', 'random', cliIndex, 'bidirectional' )
You Wang52163202016-07-14 16:37:15 -0700863 pointIntentNum -= 2
You Wang7a27f3a2016-07-05 10:12:27 -0700864 elif event == 'link-down':
865 main.eventGenerator.triggerEvent( EventType().NETWORK_LINK_DOWN, EventScheduleMethod().RUN_BLOCK, 'random', 'random' )
866 downLinkNum += 1
867 elif event == 'link-up':
868 main.eventGenerator.triggerEvent( EventType().NETWORK_LINK_UP, EventScheduleMethod().RUN_BLOCK, 'random', 'random' )
869 downLinkNum -= 1
870 elif event == 'device-down':
871 main.eventGenerator.triggerEvent( EventType().NETWORK_DEVICE_DOWN, EventScheduleMethod().RUN_BLOCK, 'random' )
872 downDeviceNum += 1
873 elif event == 'device-up':
874 main.eventGenerator.triggerEvent( EventType().NETWORK_DEVICE_UP, EventScheduleMethod().RUN_BLOCK, 'random' )
875 downDeviceNum -= 1
You Wangf6e98a82016-11-14 14:46:49 -0800876 elif event == 'toggle-flowobj':
877 if flowObj == False:
878 main.eventGenerator.triggerEvent( EventType().ONOS_SET_FLOWOBJ, EventScheduleMethod().RUN_BLOCK, 'true' )
879 else:
880 main.eventGenerator.triggerEvent( EventType().ONOS_SET_FLOWOBJ, EventScheduleMethod().RUN_BLOCK, 'false' )
881 flowObj = not flowObj
You Wang7a27f3a2016-07-05 10:12:27 -0700882 else:
883 pass
884 main.eventGenerator.triggerEvent( EventType().CHECK_TOPO, EventScheduleMethod().RUN_NON_BLOCK )
885 main.eventGenerator.triggerEvent( EventType().CHECK_ONOS, EventScheduleMethod().RUN_NON_BLOCK )
886 main.eventGenerator.triggerEvent( EventType().CHECK_TRAFFIC, EventScheduleMethod().RUN_NON_BLOCK )
887 main.eventGenerator.triggerEvent( EventType().CHECK_FLOW, EventScheduleMethod().RUN_NON_BLOCK )
888 main.eventGenerator.triggerEvent( EventType().CHECK_INTENT, EventScheduleMethod().RUN_NON_BLOCK )
You Wang7a27f3a2016-07-05 10:12:27 -0700889 with main.eventScheduler.idleCondition:
890 while not main.eventScheduler.isIdle():
891 main.eventScheduler.idleCondition.wait()
You Wang5f4f36e2016-09-21 15:30:30 -0700892 time.sleep( sleepSec )
You Wang7a27f3a2016-07-05 10:12:27 -0700893 utilities.assert_equals( expect=main.TRUE,
894 actual=main.caseResult,
895 onpass="Randomly generate events test passed",
896 onfail="Randomly generate events test failed" )
897 time.sleep( main.caseSleep )
898
You Wang52163202016-07-14 16:37:15 -0700899 def CASE80( self, main ):
900 """
901 Replay events from log file
902 """
903 import time
904 from tests.CHOTestMonkey.dependencies.events.Event import EventType
905 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
906
907 main.log.report( "Replay events from log file" )
908 main.log.report( "__________________________________________________" )
909 main.case( "Replay events from log file" )
910 main.step( "Replay events from log file" )
911 main.caseResult = main.TRUE
912 try:
913 f = open( main.params[ 'CASE80' ][ 'filePath' ], 'r' )
914 for line in f.readlines():
915 if 'CHOTestMonkey' in line and 'Event recorded' in line:
916 line = line.split()
917 eventIndex = int( line[ 9 ] )
918 eventName = line[ 10 ]
919 args = line[ 11: ]
920 assert eventName.startswith( 'CHECK' )\
921 or eventName.startswith( 'NETWORK' )\
922 or eventName.startswith( 'APP' )\
923 or eventName.startswith( 'ONOS' )
924 if main.params[ 'CASE80' ][ 'skipChecks' ] == 'on' and eventName.startswith( 'CHECK' ):
925 continue
926 with main.eventScheduler.idleCondition:
927 while not main.eventScheduler.isIdle():
928 main.eventScheduler.idleCondition.wait()
929 main.eventGenerator.triggerEvent( eventIndex, EventScheduleMethod().RUN_BLOCK, *args )
930 time.sleep( float( main.params[ 'CASE80' ][ 'sleepTime' ] ) )
931 except Exception as e:
932 print e
933 utilities.assert_equals( expect=main.TRUE,
934 actual=main.caseResult,
935 onpass="Replay from log file passed",
936 onfail="Replay from log file failed" )
937
You Wangdb927a52016-02-26 11:03:28 -0800938 def CASE90( self, main ):
939 """
940 Sleep for some time
941 """
942 import time
943 from tests.CHOTestMonkey.dependencies.events.Event import EventType
944 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
945
946 main.log.report( "Sleep for some time" )
947 main.log.report( "__________________________________________________" )
948 main.case( "Sleep for some time" )
949 main.step( "Sleep for some time" )
950 main.caseResult = main.TRUE
951 sleepSec = int( main.params[ 'CASE90' ][ 'sleepSec' ] )
952 main.eventGenerator.triggerEvent( EventType().TEST_SLEEP, EventScheduleMethod().RUN_BLOCK, sleepSec )
953 with main.eventScheduler.idleCondition:
954 while not main.eventScheduler.isIdle():
955 main.eventScheduler.idleCondition.wait()
956 utilities.assert_equals( expect=main.TRUE,
957 actual=main.caseResult,
958 onpass="Sleep test passed",
959 onfail="Sleep test failed" )
960 time.sleep( main.caseSleep )
961
962 def CASE100( self, main ):
963 """
964 Do something else?
965 """
966 import time
967
968 main.log.report( "Do something else?" )
969 main.log.report( "__________________________________________________" )
970 main.case( "..." )
971
972 main.step( "Wait until the test stops" )
973
974 main.caseResult = main.TRUE
975 utilities.assert_equals( expect=main.TRUE,
976 actual=main.caseResult,
977 onpass="Test PASS",
978 onfail="Test FAIL" )
979
980 testDuration = int( main.params[ 'TEST' ][ 'testDuration' ] )
981 time.sleep( testDuration )