blob: 3efb3cc96e78659195b3f2c580c1f5121930d6be [file] [log] [blame]
You Wangdb927a52016-02-26 11:03:28 -08001"""
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07002Copyright 2016 Open Networking Foundation ( ONF )
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07003
4Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
5the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
6or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
7
8 TestON is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070011 ( at your option ) any later version.
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -070012
13 TestON is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with TestON. If not, see <http://www.gnu.org/licenses/>.
20"""
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -070021"""
You Wangdb927a52016-02-26 11:03:28 -080022CHOTestMonkey class
23Author: you@onlab.us
24"""
You Wangdb927a52016-02-26 11:03:28 -080025import sys
26import os
27import re
28import time
29import json
30import itertools
31
Jon Hall2bb3e212017-05-24 17:07:25 -070032
You Wangdb927a52016-02-26 11:03:28 -080033class CHOTestMonkey:
34
35 def __init__( self ):
36 self.default = ''
37
38 def CASE0( self, main ):
39 """
40 Startup sequence:
41 apply cell <name>
42 git pull
You Wangdb927a52016-02-26 11:03:28 -080043 onos-package
44 onos-verify-cell
45 onos-uninstall
46 onos-install
47 onos-start-cli
48 Set IPv6 cfg parameters for Neighbor Discovery
49 start event scheduler
50 start event listener
51 """
52 import time
53 from threading import Lock, Condition
You Wang221db322016-06-03 15:45:52 -070054 from core.graph import Graph
You Wangdb927a52016-02-26 11:03:28 -080055 from tests.CHOTestMonkey.dependencies.elements.ONOSElement import Controller
56 from tests.CHOTestMonkey.dependencies.EventGenerator import EventGenerator
57 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduler
58
Devin Lim58046fa2017-07-05 16:55:00 -070059 try:
60 from tests.dependencies.ONOSSetup import ONOSSetup
61 main.testSetUp = ONOSSetup()
62 except ImportError:
63 main.log.error( "ONOSSetup not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -070064 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070065 main.testSetUp.envSetupDescription()
66
67 try:
68 onosPackage = main.params[ 'TEST' ][ 'package' ]
69 karafTimeout = main.params[ 'TEST' ][ 'karafCliTimeout' ]
70 main.enableIPv6 = main.params[ 'TEST' ][ 'IPv6' ]
71 main.enableIPv6 = True if main.enableIPv6 == "on" else False
72 main.caseSleep = int( main.params[ 'TEST' ][ 'caseSleep' ] )
Devin Limc5c9e112017-08-17 15:16:05 -070073 main.onosCell = main.params[ 'ENV' ][ 'cellName' ]
74 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
Devin Lim58046fa2017-07-05 16:55:00 -070075 main.controllers = []
76
77 main.devices = []
78 main.links = []
79 main.hosts = []
80 main.intents = []
81 main.enabledEvents = {}
82 for eventName in main.params[ 'EVENT' ].keys():
83 if main.params[ 'EVENT' ][ eventName ][ 'status' ] == 'on':
84 main.enabledEvents[ int( main.params[ 'EVENT' ][ eventName ][ 'typeIndex' ] ) ] = eventName
85 print main.enabledEvents
86 main.graph = Graph()
87 main.eventScheduler = EventScheduler()
88 main.eventGenerator = EventGenerator()
89 main.variableLock = Lock()
90 main.mininetLock = Lock()
91 main.ONOSbenchLock = Lock()
92 main.threadID = 0
93 main.eventID = 0
94 main.caseResult = main.TRUE
95 stepResult = main.testSetUp.envSetup()
96 except Exception as e:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070097 main.testSetUp.envSetupException( e )
Devin Lim58046fa2017-07-05 16:55:00 -070098
99 main.testSetUp.evnSetupConclusion( stepResult )
100
You Wanga0f6ff62018-01-11 15:46:30 -0800101 setupResult = main.testSetUp.ONOSSetUp( main.Cluster,
Devin Limc5c9e112017-08-17 15:16:05 -0700102 cellName=main.onosCell )
Devin Lim142b5342017-07-20 15:22:39 -0700103 for i in range( 1, main.Cluster.numCtrls + 1 ):
104 newController = Controller( i )
105 newController.setCLI( main.Cluster.active( i - 1 ).CLI )
106 main.controllers.append( newController )
You Wangdb927a52016-02-26 11:03:28 -0800107
108 main.step( "Set IPv6 cfg parameters for Neighbor Discovery" )
109 setIPv6CfgSleep = int( main.params[ 'TEST' ][ 'setIPv6CfgSleep' ] )
110 if main.enableIPv6:
111 time.sleep( setIPv6CfgSleep )
You Wang6ce33b02017-08-08 13:05:09 -0700112 cfgResult1 = main.controllers[ 0 ].CLI.setCfg( "org.onosproject.net.neighbour.impl.NeighbourResolutionManager",
You Wang5f4f36e2016-09-21 15:30:30 -0700113 "ndpEnabled",
You Wangdb927a52016-02-26 11:03:28 -0800114 "true" )
115 time.sleep( setIPv6CfgSleep )
116 cfgResult2 = main.controllers[ 0 ].CLI.setCfg( "org.onosproject.provider.host.impl.HostLocationProvider",
You Wang6ce33b02017-08-08 13:05:09 -0700117 "requestIpv6ND",
You Wangdb927a52016-02-26 11:03:28 -0800118 "true" )
119 else:
120 main.log.info( "Skipped setting IPv6 cfg parameters as it is disabled in params file" )
121 cfgResult1 = main.TRUE
122 cfgResult2 = main.TRUE
123 cfgResult = cfgResult1 and cfgResult2
124 utilities.assert_equals( expect=main.TRUE,
125 actual=cfgResult,
126 onpass="ipv6NeighborDiscovery cfg is set to true",
127 onfail="Failed to cfg set ipv6NeighborDiscovery" )
128
129 main.step( "Start a thread for the scheduler" )
130 t = main.Thread( target=main.eventScheduler.startScheduler,
131 threadID=main.threadID,
132 name="startScheduler",
133 args=[] )
134 t.start()
135 stepResult = main.TRUE
136 with main.variableLock:
137 main.threadID = main.threadID + 1
138
139 utilities.assert_equals( expect=main.TRUE,
140 actual=stepResult,
141 onpass="Test step PASS",
142 onfail="Test step FAIL" )
143
144 main.step( "Start a thread to listen to and handle network, ONOS and application events" )
145 t = main.Thread( target=main.eventGenerator.startListener,
146 threadID=main.threadID,
147 name="startListener",
148 args=[] )
149 t.start()
150 with main.variableLock:
151 main.threadID = main.threadID + 1
152
Devin Lim58046fa2017-07-05 16:55:00 -0700153 caseResult = setupResult and cfgResult
You Wangdb927a52016-02-26 11:03:28 -0800154 utilities.assert_equals( expect=main.TRUE,
155 actual=caseResult,
156 onpass="Set up test environment PASS",
157 onfail="Set up test environment FAIL" )
158
159 def CASE1( self, main ):
160 """
161 Load Mininet topology and balances all switches
162 """
163 import re
164 import time
165 import copy
166
Jon Hall2bb3e212017-05-24 17:07:25 -0700167 main.topoIndex = "topo" + str( main.params[ 'TEST' ][ 'topo' ] )
You Wangdb927a52016-02-26 11:03:28 -0800168
169 main.log.report( "Load Mininet topology and Balance all Mininet switches across controllers" )
170 main.log.report( "________________________________________________________________________" )
171 main.case( "Assign and Balance all Mininet switches across controllers" )
172
173 main.step( "Start Mininet topology" )
174 newTopo = main.params[ 'TOPO' ][ main.topoIndex ][ 'fileName' ]
175 mininetDir = main.Mininet1.home + "/custom/"
Jon Hall2bb3e212017-05-24 17:07:25 -0700176 topoPath = main.testDir + "/" + main.TEST + "/dependencies/topologies/" + newTopo
You Wangdb927a52016-02-26 11:03:28 -0800177 main.ONOSbench.secureCopy( main.Mininet1.user_name, main.Mininet1.ip_address, topoPath, mininetDir, direction="to" )
178 topoPath = mininetDir + newTopo
Jon Hall2bb3e212017-05-24 17:07:25 -0700179 startStatus = main.Mininet1.startNet( topoFile=topoPath )
You Wangdb927a52016-02-26 11:03:28 -0800180 main.mininetSwitches = main.Mininet1.getSwitches()
181 main.mininetHosts = main.Mininet1.getHosts()
You Wang55503a32016-06-27 15:11:40 -0700182 main.mininetLinks = main.Mininet1.getLinks( timeout=60 )
You Wangdb927a52016-02-26 11:03:28 -0800183 utilities.assert_equals( expect=main.TRUE,
184 actual=startStatus,
185 onpass="Start Mininet topology test PASS",
186 onfail="Start Mininet topology test FAIL" )
187
188 main.step( "Assign switches to controllers" )
189 switchMastership = main.TRUE
190 for switchName in main.mininetSwitches.keys():
Devin Lim142b5342017-07-20 15:22:39 -0700191 ips = main.Cluster.getIps()
192 main.Mininet1.assignSwController( sw=switchName, ip=ips )
You Wangdb927a52016-02-26 11:03:28 -0800193 response = main.Mininet1.getSwController( switchName )
194 print( "Response is " + str( response ) )
Devin Lim142b5342017-07-20 15:22:39 -0700195 if re.search( "tcp:" + main.Cluster.active( 0 ).ipAddress, response ):
You Wangdb927a52016-02-26 11:03:28 -0800196 switchMastership = switchMastership and main.TRUE
197 else:
198 switchMastership = main.FALSE
199 utilities.assert_equals( expect=main.TRUE,
200 actual=switchMastership,
201 onpass="Assign switches to controllers test PASS",
202 onfail="Assign switches to controllers test FAIL" )
203 # Waiting here to make sure topology converges across all nodes
204 sleep = int( main.params[ 'TEST' ][ 'loadTopoSleep' ] )
205 time.sleep( sleep )
206
207 main.step( "Balance devices across controllers" )
Devin Lim142b5342017-07-20 15:22:39 -0700208 balanceResult = main.Cluster.active( 0 ).CLI.balanceMasters()
You Wangdb927a52016-02-26 11:03:28 -0800209 # giving some breathing time for ONOS to complete re-balance
210 time.sleep( sleep )
211
212 caseResult = ( startStatus and switchMastership and balanceResult )
213 utilities.assert_equals( expect=main.TRUE,
214 actual=caseResult,
215 onpass="Starting new Att topology test PASS",
216 onfail="Starting new Att topology test FAIL" )
217
218 def CASE2( self, main ):
219 """
220 Collect and store device and link data from ONOS
221 """
222 import json
223 from tests.CHOTestMonkey.dependencies.elements.NetworkElement import Device, Link
224
225 main.log.report( "Collect and Store topology details from ONOS" )
226 main.log.report( "____________________________________________________________________" )
227 main.case( "Collect and Store Topology Details from ONOS" )
228 topoResult = main.TRUE
Devin Lim142b5342017-07-20 15:22:39 -0700229 topologyOutput = main.Cluster.active( 0 ).CLI.topology()
230 topologyResult = main.Cluster.active( 0 ).CLI.getTopology( topologyOutput )
You Wangdb927a52016-02-26 11:03:28 -0800231 ONOSDeviceNum = int( topologyResult[ 'devices' ] )
232 ONOSLinkNum = int( topologyResult[ 'links' ] )
233 mininetSwitchNum = len( main.mininetSwitches )
234 mininetLinkNum = ( len( main.mininetLinks ) - len( main.mininetHosts ) ) * 2
235 if mininetSwitchNum == ONOSDeviceNum and mininetLinkNum == ONOSLinkNum:
236 main.step( "Collect and store device data" )
237 stepResult = main.TRUE
238 dpidToName = {}
239 for key, value in main.mininetSwitches.items():
240 dpidToName[ 'of:' + str( value[ 'dpid' ] ) ] = key
Devin Lim142b5342017-07-20 15:22:39 -0700241 devicesRaw = main.Cluster.active( 0 ).CLI.devices()
You Wangdb927a52016-02-26 11:03:28 -0800242 devices = json.loads( devicesRaw )
243 deviceInitIndex = 0
244 for device in devices:
245 name = dpidToName[ device[ 'id' ] ]
246 newDevice = Device( deviceInitIndex, name, device[ 'id' ] )
247 print newDevice
248 main.devices.append( newDevice )
249 deviceInitIndex += 1
250 utilities.assert_equals( expect=main.TRUE,
251 actual=stepResult,
252 onpass="Successfully collected and stored device data",
253 onfail="Failed to collect and store device data" )
254
255 main.step( "Collect and store link data" )
256 stepResult = main.TRUE
Devin Lim142b5342017-07-20 15:22:39 -0700257 linksRaw = main.Cluster.active( 0 ).CLI.links()
You Wangdb927a52016-02-26 11:03:28 -0800258 links = json.loads( linksRaw )
259 linkInitIndex = 0
260 for link in links:
261 for device in main.devices:
262 if device.dpid == link[ 'src' ][ 'device' ]:
263 deviceA = device
264 elif device.dpid == link[ 'dst' ][ 'device' ]:
265 deviceB = device
Jon Hall2bb3e212017-05-24 17:07:25 -0700266 assert deviceA is not None and deviceB is not None
You Wangdb927a52016-02-26 11:03:28 -0800267 newLink = Link( linkInitIndex, deviceA, link[ 'src' ][ 'port' ], deviceB, link[ 'dst' ][ 'port' ] )
268 print newLink
269 main.links.append( newLink )
270 linkInitIndex += 1
271 # Set backward links and outgoing links of devices
272 for linkA in main.links:
273 linkA.deviceA.outgoingLinks.append( linkA )
Jon Hall2bb3e212017-05-24 17:07:25 -0700274 if linkA.backwardLink is not None:
You Wangdb927a52016-02-26 11:03:28 -0800275 continue
276 for linkB in main.links:
Jon Hall2bb3e212017-05-24 17:07:25 -0700277 if linkB.backwardLink is not None:
You Wangdb927a52016-02-26 11:03:28 -0800278 continue
279 if linkA.deviceA == linkB.deviceB and\
Jon Hall2bb3e212017-05-24 17:07:25 -0700280 linkA.deviceB == linkB.deviceA and\
281 linkA.portA == linkB.portB and\
282 linkA.portB == linkB.portA:
You Wangdb927a52016-02-26 11:03:28 -0800283 linkA.setBackwardLink( linkB )
284 linkB.setBackwardLink( linkA )
285 utilities.assert_equals( expect=main.TRUE,
286 actual=stepResult,
287 onpass="Successfully collected and stored link data",
288 onfail="Failed to collect and store link data" )
289 else:
290 main.log.info( "Devices (expected): %s, Links (expected): %s" % ( mininetSwitchNum, mininetLinkNum ) )
291 main.log.info( "Devices (actual): %s, Links (actual): %s" % ( ONOSDeviceNum, ONOSLinkNum ) )
292 topoResult = main.FALSE
293
294 caseResult = topoResult
295 utilities.assert_equals( expect=main.TRUE,
296 actual=caseResult,
297 onpass="Saving ONOS topology data test PASS",
298 onfail="Saving ONOS topology data test FAIL" )
299
300 if not caseResult:
Jon Hall2bb3e212017-05-24 17:07:25 -0700301 main.log.info( "Topology does not match, exiting test..." )
Devin Lim44075962017-08-11 10:56:37 -0700302 main.cleanAndExit()
You Wangdb927a52016-02-26 11:03:28 -0800303
304 def CASE3( self, main ):
305 """
306 Collect and store host data from ONOS
307 """
308 import json
309 from tests.CHOTestMonkey.dependencies.elements.NetworkElement import Host
310
311 main.log.report( "Collect and store host adta from ONOS" )
312 main.log.report( "______________________________________________" )
313 main.case( "Use fwd app and pingall to discover all the hosts, then collect and store host data" )
314
315 main.step( "Enable Reactive forwarding" )
316 appResult = main.controllers[ 0 ].CLI.activateApp( "org.onosproject.fwd" )
317 cfgResult1 = main.TRUE
318 cfgResult2 = main.TRUE
319 if main.enableIPv6:
320 cfgResult1 = main.controllers[ 0 ].CLI.setCfg( "org.onosproject.fwd.ReactiveForwarding", "ipv6Forwarding", "true" )
321 cfgResult2 = main.controllers[ 0 ].CLI.setCfg( "org.onosproject.fwd.ReactiveForwarding", "matchIpv6Address", "true" )
322 stepResult = appResult and cfgResult1 and cfgResult2
323 utilities.assert_equals( expect=main.TRUE,
324 actual=stepResult,
325 onpass="Successfully enabled reactive forwarding",
326 onfail="Failed to enable reactive forwarding" )
327
328 main.step( "Discover hosts using pingall" )
329 stepResult = main.TRUE
330 main.Mininet1.pingall()
331 if main.enableIPv6:
332 ping6Result = main.Mininet1.pingall( protocol="IPv6" )
333 hosts = main.controllers[ 0 ].CLI.hosts()
334 hosts = json.loads( hosts )
335 if not len( hosts ) == len( main.mininetHosts ):
336 stepResult = main.FALSE
337 utilities.assert_equals( expect=main.TRUE,
338 actual=stepResult,
339 onpass="Host discovery PASS",
340 onfail="Host discovery FAIL" )
341 if not stepResult:
342 main.log.debug( hosts )
Devin Lim44075962017-08-11 10:56:37 -0700343 main.cleanAndExit()
You Wangdb927a52016-02-26 11:03:28 -0800344
345 main.step( "Disable Reactive forwarding" )
346 appResult = main.controllers[ 0 ].CLI.deactivateApp( "org.onosproject.fwd" )
347 stepResult = appResult
348 utilities.assert_equals( expect=main.TRUE,
349 actual=stepResult,
350 onpass="Successfully deactivated fwd app",
351 onfail="Failed to deactivate fwd app" )
352
353 main.step( "Collect and store host data" )
354 stepResult = main.TRUE
355 macToName = {}
356 for key, value in main.mininetHosts.items():
357 macToName[ value[ 'interfaces' ][ 0 ][ 'mac' ].upper() ] = key
358 dpidToDevice = {}
359 for device in main.devices:
360 dpidToDevice[ device.dpid ] = device
361 hostInitIndex = 0
362 for host in hosts:
363 name = macToName[ host[ 'mac' ] ]
Jeremy Ronquillo0e538bc2017-06-13 15:16:09 -0700364 dpid = host[ 'locations' ][ 0 ][ 'elementId' ]
You Wangdb927a52016-02-26 11:03:28 -0800365 device = dpidToDevice[ dpid ]
366 newHost = Host( hostInitIndex,
367 name, host[ 'id' ], host[ 'mac' ],
Jeremy Ronquillo0e538bc2017-06-13 15:16:09 -0700368 device, host[ 'locations' ][ 0 ][ 'port' ],
You Wangdb927a52016-02-26 11:03:28 -0800369 host[ 'vlan' ], host[ 'ipAddresses' ] )
370 print newHost
371 main.hosts.append( newHost )
372 main.devices[ device.index ].hosts.append( newHost )
373 hostInitIndex += 1
374 utilities.assert_equals( expect=main.TRUE,
375 actual=stepResult,
376 onpass="Successfully collected and stored host data",
377 onfail="Failed to collect and store host data" )
378
379 main.step( "Create one host component for each host and then start host cli" )
380 for host in main.hosts:
381 main.Mininet1.createHostComponent( host.name )
382 hostHandle = getattr( main, host.name )
383 main.log.info( "Starting CLI on host " + str( host.name ) )
384 startCLIResult = hostHandle.startHostCli()
385 host.setHandle( hostHandle )
386 stepResult = startCLIResult
387 utilities.assert_equals( expect=main.TRUE,
388 actual=startCLIResult,
389 onpass="Host CLI started",
390 onfail="Failed to start host CLI" )
391
392 def CASE10( self, main ):
393 """
394 Run all enabled checks
395 """
396 import time
397 from tests.CHOTestMonkey.dependencies.events.Event import EventType
398 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
399
400 main.log.report( "Run all enabled checks" )
401 main.log.report( "__________________________________________________" )
402 main.case( "Run all enabled checks" )
403 main.step( "Run all enabled checks" )
404 main.caseResult = main.TRUE
405 main.eventGenerator.triggerEvent( EventType().CHECK_ALL, EventScheduleMethod().RUN_BLOCK )
406 # Wait for the scheduler to become idle before going to the next testcase
407 with main.eventScheduler.idleCondition:
408 while not main.eventScheduler.isIdle():
409 main.eventScheduler.idleCondition.wait()
410 utilities.assert_equals( expect=main.TRUE,
411 actual=main.caseResult,
412 onpass="All enabled checks passed",
413 onfail="Not all enabled checks passed" )
414 time.sleep( main.caseSleep )
415
416 def CASE20( self, main ):
417 """
418 Bring down/up links and check topology and ping
419 """
420 import time
421 from tests.CHOTestMonkey.dependencies.events.Event import EventType
422 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
423
424 main.log.report( "Bring down/up links and check topology and ping" )
425 main.log.report( "__________________________________________________" )
426 main.case( "Bring down/up links and check topology and ping" )
427 main.step( "Bring down/up links and check topology and ping" )
428 main.caseResult = main.TRUE
429 linkToggleNum = int( main.params[ 'CASE20' ][ 'linkToggleNum' ] )
430 linkDownUpInterval = int( main.params[ 'CASE20' ][ 'linkDownUpInterval' ] )
431 for i in range( 0, linkToggleNum ):
432 main.eventGenerator.triggerEvent( EventType().NETWORK_LINK_RANDOM_TOGGLE, EventScheduleMethod().RUN_BLOCK, linkDownUpInterval )
433 with main.eventScheduler.idleCondition:
434 while not main.eventScheduler.isIdle():
435 main.eventScheduler.idleCondition.wait()
436 utilities.assert_equals( expect=main.TRUE,
437 actual=main.caseResult,
438 onpass="Toggle network links test passed",
439 onfail="Toggle network links test failed" )
440 time.sleep( main.caseSleep )
441
442 def CASE21( self, main ):
443 """
444 Bring down/up a group of links and check topology and ping
445 """
446 import time
447 from tests.CHOTestMonkey.dependencies.events.Event import EventType
448 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
449
450 main.log.report( "Bring down/up a group of links and check topology and ping" )
451 main.log.report( "__________________________________________________" )
452 main.case( "Bring down/up a group of links and check topology and ping" )
453 main.step( "Bring down/up a group of links and check topology and ping" )
454 main.caseResult = main.TRUE
455 linkGroupSize = int( main.params[ 'CASE21' ][ 'linkGroupSize' ] )
456 linkDownDownInterval = int( main.params[ 'CASE21' ][ 'linkDownDownInterval' ] )
457 linkDownUpInterval = int( main.params[ 'CASE21' ][ 'linkDownUpInterval' ] )
458 main.eventGenerator.triggerEvent( EventType().NETWORK_LINK_GROUP_RANDOM_TOGGLE, EventScheduleMethod().RUN_BLOCK, linkGroupSize, linkDownDownInterval, linkDownUpInterval )
459 with main.eventScheduler.idleCondition:
460 while not main.eventScheduler.isIdle():
461 main.eventScheduler.idleCondition.wait()
462 utilities.assert_equals( expect=main.TRUE,
463 actual=main.caseResult,
464 onpass="Toggle network link group test passed",
465 onfail="Toggle network link group test failed" )
466 time.sleep( main.caseSleep )
467
468 def CASE30( self, main ):
469 """
470 Install host intents and check intent states and ping
471 """
472 import time
473 from tests.CHOTestMonkey.dependencies.events.Event import EventType
474 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
475
476 main.log.report( "Install host intents and check intent states and ping" )
477 main.log.report( "__________________________________________________" )
478 main.case( "Install host intents and check intent states and ping" )
479 main.step( "Install host intents and check intent states and ping" )
480 main.caseResult = main.TRUE
481 main.eventGenerator.triggerEvent( EventType().APP_INTENT_HOST_ADD_ALL, EventScheduleMethod().RUN_BLOCK )
482 with main.eventScheduler.idleCondition:
483 while not main.eventScheduler.isIdle():
484 main.eventScheduler.idleCondition.wait()
485 utilities.assert_equals( expect=main.TRUE,
486 actual=main.caseResult,
487 onpass="Install host intents test passed",
488 onfail="Install host intents test failed" )
489 time.sleep( main.caseSleep )
490
491 def CASE31( self, main ):
492 """
493 Uninstall host intents and check intent states and ping
494 """
495 import time
496 from tests.CHOTestMonkey.dependencies.events.Event import EventType
497 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
498
499 main.log.report( "Uninstall host intents and check intent states and ping" )
500 main.log.report( "__________________________________________________" )
501 main.case( "Uninstall host intents and check intent states and ping" )
502 main.step( "Uninstall host intents and check intent states and ping" )
503 main.caseResult = main.TRUE
504 main.eventGenerator.triggerEvent( EventType().APP_INTENT_HOST_DEL_ALL, EventScheduleMethod().RUN_BLOCK )
505 with main.eventScheduler.idleCondition:
506 while not main.eventScheduler.isIdle():
507 main.eventScheduler.idleCondition.wait()
508 utilities.assert_equals( expect=main.TRUE,
509 actual=main.caseResult,
510 onpass="Uninstall host intents test passed",
511 onfail="Uninstall host intents test failed" )
512 time.sleep( main.caseSleep )
513
514 def CASE32( self, main ):
515 """
516 Install point intents and check intent states and ping
517 """
518 import time
519 from tests.CHOTestMonkey.dependencies.events.Event import EventType
520 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
521
522 main.log.report( "Install point intents and check intent states and ping" )
523 main.log.report( "__________________________________________________" )
524 main.case( "Install point intents and check intent states and ping" )
525 main.step( "Install point intents and check intent states and ping" )
526 main.caseResult = main.TRUE
527 main.eventGenerator.triggerEvent( EventType().APP_INTENT_POINT_ADD_ALL, EventScheduleMethod().RUN_BLOCK )
528 with main.eventScheduler.idleCondition:
529 while not main.eventScheduler.isIdle():
530 main.eventScheduler.idleCondition.wait()
531 utilities.assert_equals( expect=main.TRUE,
532 actual=main.caseResult,
533 onpass="Install point intents test passed",
534 onfail="Install point intents test failed" )
535 time.sleep( main.caseSleep )
536
537 def CASE33( self, main ):
538 """
539 Uninstall point intents and check intent states and ping
540 """
541 import time
542 from tests.CHOTestMonkey.dependencies.events.Event import EventType
543 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
544
545 main.log.report( "Uninstall point intents and check intent states and ping" )
546 main.log.report( "__________________________________________________" )
547 main.case( "Uninstall point intents and check intent states and ping" )
548 main.step( "Uninstall point intents and check intent states and ping" )
549 main.caseResult = main.TRUE
550 main.eventGenerator.triggerEvent( EventType().APP_INTENT_POINT_DEL_ALL, EventScheduleMethod().RUN_BLOCK )
551 with main.eventScheduler.idleCondition:
552 while not main.eventScheduler.isIdle():
553 main.eventScheduler.idleCondition.wait()
554 utilities.assert_equals( expect=main.TRUE,
555 actual=main.caseResult,
556 onpass="Uninstall point intents test passed",
557 onfail="Uninstall point intents test failed" )
558 time.sleep( main.caseSleep )
559
560 def CASE40( self, main ):
561 """
562 Randomly bring down one ONOS node
563 """
564 import time
565 import random
566 from tests.CHOTestMonkey.dependencies.events.Event import EventType
567 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
568
569 main.log.report( "Randomly bring down one ONOS node" )
570 main.log.report( "__________________________________________________" )
571 main.case( "Randomly bring down one ONOS node" )
572 main.step( "Randomly bring down one ONOS node" )
573 main.caseResult = main.TRUE
574 availableControllers = []
575 for controller in main.controllers:
576 if controller.isUp():
577 availableControllers.append( controller.index )
578 if len( availableControllers ) == 0:
579 main.log.warn( "No available controllers" )
580 main.caseResult = main.FALSE
581 else:
582 index = random.sample( availableControllers, 1 )
583 main.eventGenerator.triggerEvent( EventType().ONOS_ONOS_DOWN, EventScheduleMethod().RUN_BLOCK, index[ 0 ] )
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="Randomly bring down ONOS test passed",
590 onfail="Randomly bring down ONOS test failed" )
591 time.sleep( main.caseSleep )
592
593 def CASE41( self, main ):
594 """
595 Randomly bring up one ONOS node that is down
596 """
597 import time
598 import random
599 from tests.CHOTestMonkey.dependencies.events.Event import EventType
600 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
601
602 main.log.report( "Randomly bring up one ONOS node that is down" )
603 main.log.report( "__________________________________________________" )
604 main.case( "Randomly bring up one ONOS node that is down" )
605 main.step( "Randomly bring up one ONOS node that is down" )
606 main.caseResult = main.TRUE
607 targetControllers = []
608 for controller in main.controllers:
609 if not controller.isUp():
610 targetControllers.append( controller.index )
611 if len( targetControllers ) == 0:
612 main.log.warn( "All controllers are up" )
613 main.caseResult = main.FALSE
614 else:
615 index = random.sample( targetControllers, 1 )
616 main.eventGenerator.triggerEvent( EventType().ONOS_ONOS_UP, EventScheduleMethod().RUN_BLOCK, index[ 0 ] )
617 with main.eventScheduler.idleCondition:
618 while not main.eventScheduler.isIdle():
619 main.eventScheduler.idleCondition.wait()
620 utilities.assert_equals( expect=main.TRUE,
621 actual=main.caseResult,
622 onpass="Randomly bring up ONOS test passed",
623 onfail="Randomly bring up ONOS test failed" )
624 time.sleep( main.caseSleep )
625
626 def CASE50( self, main ):
627 """
628 Set FlowObjective to True
629 """
630 import time
631 from tests.CHOTestMonkey.dependencies.events.Event import EventType
632 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
633
634 main.log.report( "Set FlowObjective to True" )
635 main.log.report( "__________________________________________________" )
636 main.case( "Set FlowObjective to True" )
637 main.step( "Set FlowObjective to True" )
638 main.caseResult = main.TRUE
639 main.eventGenerator.triggerEvent( EventType().ONOS_SET_FLOWOBJ, EventScheduleMethod().RUN_BLOCK, 'true' )
640 with main.eventScheduler.idleCondition:
641 while not main.eventScheduler.isIdle():
642 main.eventScheduler.idleCondition.wait()
643 utilities.assert_equals( expect=main.TRUE,
644 actual=main.caseResult,
645 onpass="Set FlowObjective test passed",
646 onfail="Set FlowObjective test failed" )
647 time.sleep( main.caseSleep )
648
649 def CASE51( self, main ):
650 """
651 Set FlowObjective to False
652 """
653 import time
654 from tests.CHOTestMonkey.dependencies.events.Event import EventType
655 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
656
657 main.log.report( "Set FlowObjective to False" )
658 main.log.report( "__________________________________________________" )
659 main.case( "Set FlowObjective to False" )
660 main.step( "Set FlowObjective to False" )
661 main.caseResult = main.TRUE
662 main.eventGenerator.triggerEvent( EventType().ONOS_SET_FLOWOBJ, EventScheduleMethod().RUN_BLOCK, 'false' )
663 with main.eventScheduler.idleCondition:
664 while not main.eventScheduler.isIdle():
665 main.eventScheduler.idleCondition.wait()
666 utilities.assert_equals( expect=main.TRUE,
667 actual=main.caseResult,
668 onpass="Set FlowObjective test passed",
669 onfail="Set FlowObjective test failed" )
670 time.sleep( main.caseSleep )
671
672 def CASE60( self, main ):
673 """
674 Balance device masters
675 """
676 import time
677 from tests.CHOTestMonkey.dependencies.events.Event import EventType
678 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
679
680 main.log.report( "Balance device masters" )
681 main.log.report( "__________________________________________________" )
682 main.case( "Balance device masters" )
683 main.step( "Balance device masters" )
684 main.caseResult = main.TRUE
685 main.eventGenerator.triggerEvent( EventType().ONOS_BALANCE_MASTERS, EventScheduleMethod().RUN_BLOCK )
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="Balance masters test passed",
692 onfail="Balance masters test failed" )
693 time.sleep( main.caseSleep )
694
You Wang7a27f3a2016-07-05 10:12:27 -0700695 def CASE70( self, main ):
696 """
697 Randomly generate events
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 generate events" )
705 main.log.report( "__________________________________________________" )
706 main.case( "Randomly generate events" )
707 main.step( "Randomly generate events" )
708 main.caseResult = main.TRUE
709 sleepSec = int( main.params[ 'CASE70' ][ 'sleepSec' ] )
710 hostIntentNum = 0
711 pointIntentNum = 0
712 downDeviceNum = 0
713 downLinkNum = 0
You Wangf6e98a82016-11-14 14:46:49 -0800714 flowObj = False
You Wang7a27f3a2016-07-05 10:12:27 -0700715 upControllers = [ 1, 2, 3 ]
716 while True:
717 events = []
You Wangf6e98a82016-11-14 14:46:49 -0800718 for i in range( int( main.params[ 'CASE70' ][ 'toggleFlowObj' ] ) ):
719 events.append( 'toggle-flowobj' )
You Wang7a27f3a2016-07-05 10:12:27 -0700720 for i in range( int( main.params[ 'CASE70' ][ 'addHostIntentWeight' ] ) ):
721 events.append( 'add-host-intent' )
722 for i in range( int( main.params[ 'CASE70' ][ 'addPointIntentWeight' ] ) ):
723 events.append( 'add-point-intent' )
724 for i in range( int( main.params[ 'CASE70' ][ 'linkDownWeight' ] ) ):
725 events.append( 'link-down' )
726 for i in range( int( main.params[ 'CASE70' ][ 'deviceDownWeight' ] ) ):
727 events.append( 'device-down' )
728 for i in range( int( pow( hostIntentNum, 1.5 ) / 100 ) ):
729 events.append( 'del-host-intent' )
You Wang52163202016-07-14 16:37:15 -0700730 for i in range( int( pow( pointIntentNum, 1.5 ) / 100 ) ):
You Wang7a27f3a2016-07-05 10:12:27 -0700731 events.append( 'del-point-intent' )
732 for i in range( pow( 2, downLinkNum ) - 1 ):
733 events.append( 'link-up' )
734 for i in range( pow( 5, downDeviceNum ) - 1 ):
735 events.append( 'device-up' )
736 main.log.debug( events )
737 event = random.sample( events, 1 )[ 0 ]
738 if event == 'add-host-intent':
739 n = random.randint( 5, 50 )
740 for i in range( n ):
741 cliIndex = random.sample( upControllers, 1 )[ 0 ]
You Wangc848af12016-07-14 09:53:58 -0700742 main.eventGenerator.triggerEvent( EventType().APP_INTENT_HOST_ADD, EventScheduleMethod().RUN_BLOCK, 'random', 'random', cliIndex )
You Wang7a27f3a2016-07-05 10:12:27 -0700743 hostIntentNum += 1
You Wang7a27f3a2016-07-05 10:12:27 -0700744 elif event == 'del-host-intent':
745 n = random.randint( 5, hostIntentNum )
746 for i in range( n ):
747 cliIndex = random.sample( upControllers, 1 )[ 0 ]
You Wangc848af12016-07-14 09:53:58 -0700748 main.eventGenerator.triggerEvent( EventType().APP_INTENT_HOST_DEL, EventScheduleMethod().RUN_BLOCK, 'random', 'random', cliIndex )
You Wang7a27f3a2016-07-05 10:12:27 -0700749 hostIntentNum -= 1
You Wang7a27f3a2016-07-05 10:12:27 -0700750 elif event == 'add-point-intent':
751 n = random.randint( 5, 50 )
752 for i in range( n ):
753 cliIndex = random.sample( upControllers, 1 )[ 0 ]
You Wangc848af12016-07-14 09:53:58 -0700754 main.eventGenerator.triggerEvent( EventType().APP_INTENT_POINT_ADD, EventScheduleMethod().RUN_BLOCK, 'random', 'random', cliIndex, 'bidirectional' )
You Wang52163202016-07-14 16:37:15 -0700755 pointIntentNum += 2
You Wang7a27f3a2016-07-05 10:12:27 -0700756 elif event == 'del-point-intent':
You Wang52163202016-07-14 16:37:15 -0700757 n = random.randint( 5, pointIntentNum / 2 )
You Wang7a27f3a2016-07-05 10:12:27 -0700758 for i in range( n ):
759 cliIndex = random.sample( upControllers, 1 )[ 0 ]
You Wangc848af12016-07-14 09:53:58 -0700760 main.eventGenerator.triggerEvent( EventType().APP_INTENT_POINT_DEL, EventScheduleMethod().RUN_BLOCK, 'random', 'random', cliIndex, 'bidirectional' )
You Wang52163202016-07-14 16:37:15 -0700761 pointIntentNum -= 2
You Wang7a27f3a2016-07-05 10:12:27 -0700762 elif event == 'link-down':
763 main.eventGenerator.triggerEvent( EventType().NETWORK_LINK_DOWN, EventScheduleMethod().RUN_BLOCK, 'random', 'random' )
764 downLinkNum += 1
765 elif event == 'link-up':
766 main.eventGenerator.triggerEvent( EventType().NETWORK_LINK_UP, EventScheduleMethod().RUN_BLOCK, 'random', 'random' )
767 downLinkNum -= 1
768 elif event == 'device-down':
769 main.eventGenerator.triggerEvent( EventType().NETWORK_DEVICE_DOWN, EventScheduleMethod().RUN_BLOCK, 'random' )
770 downDeviceNum += 1
771 elif event == 'device-up':
772 main.eventGenerator.triggerEvent( EventType().NETWORK_DEVICE_UP, EventScheduleMethod().RUN_BLOCK, 'random' )
773 downDeviceNum -= 1
You Wangf6e98a82016-11-14 14:46:49 -0800774 elif event == 'toggle-flowobj':
Jon Hall2bb3e212017-05-24 17:07:25 -0700775 if not flowObj:
You Wangf6e98a82016-11-14 14:46:49 -0800776 main.eventGenerator.triggerEvent( EventType().ONOS_SET_FLOWOBJ, EventScheduleMethod().RUN_BLOCK, 'true' )
777 else:
778 main.eventGenerator.triggerEvent( EventType().ONOS_SET_FLOWOBJ, EventScheduleMethod().RUN_BLOCK, 'false' )
779 flowObj = not flowObj
You Wang7a27f3a2016-07-05 10:12:27 -0700780 else:
781 pass
782 main.eventGenerator.triggerEvent( EventType().CHECK_TOPO, EventScheduleMethod().RUN_NON_BLOCK )
783 main.eventGenerator.triggerEvent( EventType().CHECK_ONOS, EventScheduleMethod().RUN_NON_BLOCK )
784 main.eventGenerator.triggerEvent( EventType().CHECK_TRAFFIC, EventScheduleMethod().RUN_NON_BLOCK )
785 main.eventGenerator.triggerEvent( EventType().CHECK_FLOW, EventScheduleMethod().RUN_NON_BLOCK )
786 main.eventGenerator.triggerEvent( EventType().CHECK_INTENT, EventScheduleMethod().RUN_NON_BLOCK )
Devin Limf0822182017-09-12 14:52:57 -0700787 main.eventGenerator.triggerEvent( EventType().CHECK_RAFT_LOG_SIZE, EventScheduleMethod().RUN_NON_BLOCK )
You Wang7a27f3a2016-07-05 10:12:27 -0700788 with main.eventScheduler.idleCondition:
789 while not main.eventScheduler.isIdle():
790 main.eventScheduler.idleCondition.wait()
You Wang5f4f36e2016-09-21 15:30:30 -0700791 time.sleep( sleepSec )
You Wang7a27f3a2016-07-05 10:12:27 -0700792 utilities.assert_equals( expect=main.TRUE,
793 actual=main.caseResult,
794 onpass="Randomly generate events test passed",
795 onfail="Randomly generate events test failed" )
796 time.sleep( main.caseSleep )
797
You Wang52163202016-07-14 16:37:15 -0700798 def CASE80( self, main ):
799 """
800 Replay events from log file
801 """
802 import time
803 from tests.CHOTestMonkey.dependencies.events.Event import EventType
804 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
805
806 main.log.report( "Replay events from log file" )
807 main.log.report( "__________________________________________________" )
808 main.case( "Replay events from log file" )
809 main.step( "Replay events from log file" )
810 main.caseResult = main.TRUE
811 try:
812 f = open( main.params[ 'CASE80' ][ 'filePath' ], 'r' )
813 for line in f.readlines():
814 if 'CHOTestMonkey' in line and 'Event recorded' in line:
815 line = line.split()
816 eventIndex = int( line[ 9 ] )
817 eventName = line[ 10 ]
818 args = line[ 11: ]
819 assert eventName.startswith( 'CHECK' )\
Jon Hall2bb3e212017-05-24 17:07:25 -0700820 or eventName.startswith( 'NETWORK' )\
821 or eventName.startswith( 'APP' )\
822 or eventName.startswith( 'ONOS' )
You Wang52163202016-07-14 16:37:15 -0700823 if main.params[ 'CASE80' ][ 'skipChecks' ] == 'on' and eventName.startswith( 'CHECK' ):
824 continue
825 with main.eventScheduler.idleCondition:
826 while not main.eventScheduler.isIdle():
827 main.eventScheduler.idleCondition.wait()
828 main.eventGenerator.triggerEvent( eventIndex, EventScheduleMethod().RUN_BLOCK, *args )
829 time.sleep( float( main.params[ 'CASE80' ][ 'sleepTime' ] ) )
830 except Exception as e:
831 print e
832 utilities.assert_equals( expect=main.TRUE,
833 actual=main.caseResult,
834 onpass="Replay from log file passed",
835 onfail="Replay from log file failed" )
836
You Wangdb927a52016-02-26 11:03:28 -0800837 def CASE90( self, main ):
838 """
839 Sleep for some time
840 """
841 import time
842 from tests.CHOTestMonkey.dependencies.events.Event import EventType
843 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
844
845 main.log.report( "Sleep for some time" )
846 main.log.report( "__________________________________________________" )
847 main.case( "Sleep for some time" )
848 main.step( "Sleep for some time" )
849 main.caseResult = main.TRUE
850 sleepSec = int( main.params[ 'CASE90' ][ 'sleepSec' ] )
851 main.eventGenerator.triggerEvent( EventType().TEST_SLEEP, EventScheduleMethod().RUN_BLOCK, sleepSec )
852 with main.eventScheduler.idleCondition:
853 while not main.eventScheduler.isIdle():
854 main.eventScheduler.idleCondition.wait()
855 utilities.assert_equals( expect=main.TRUE,
856 actual=main.caseResult,
857 onpass="Sleep test passed",
858 onfail="Sleep test failed" )
859 time.sleep( main.caseSleep )
860
861 def CASE100( self, main ):
862 """
863 Do something else?
864 """
865 import time
866
867 main.log.report( "Do something else?" )
868 main.log.report( "__________________________________________________" )
869 main.case( "..." )
870
871 main.step( "Wait until the test stops" )
872
873 main.caseResult = main.TRUE
874 utilities.assert_equals( expect=main.TRUE,
875 actual=main.caseResult,
876 onpass="Test PASS",
877 onfail="Test FAIL" )
878
879 testDuration = int( main.params[ 'TEST' ][ 'testDuration' ] )
880 time.sleep( testDuration )