blob: 8989672a0775f880ddf779b2106fc52acbf678fc [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
You Wangdb927a52016-02-26 11:03:28 -080048 start event scheduler
49 start event listener
50 """
51 import time
52 from threading import Lock, Condition
You Wang221db322016-06-03 15:45:52 -070053 from core.graph import Graph
You Wangdb927a52016-02-26 11:03:28 -080054 from tests.CHOTestMonkey.dependencies.elements.ONOSElement import Controller
55 from tests.CHOTestMonkey.dependencies.EventGenerator import EventGenerator
56 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduler
57
Devin Lim58046fa2017-07-05 16:55:00 -070058 try:
59 from tests.dependencies.ONOSSetup import ONOSSetup
60 main.testSetUp = ONOSSetup()
61 except ImportError:
62 main.log.error( "ONOSSetup not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -070063 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070064 main.testSetUp.envSetupDescription()
65
You Wangc61aaa22019-02-01 15:49:48 -080066 from tests.dependencies.Network import Network
67 main.Network = Network()
68
Devin Lim58046fa2017-07-05 16:55:00 -070069 try:
70 onosPackage = main.params[ 'TEST' ][ 'package' ]
71 karafTimeout = main.params[ 'TEST' ][ 'karafCliTimeout' ]
You Wang9fc5ce42019-01-23 15:10:08 -080072 main.enableIPv6 = main.params[ 'TEST' ][ 'IPv6' ].lower() == "on"
Devin Lim58046fa2017-07-05 16:55:00 -070073 main.caseSleep = int( main.params[ 'TEST' ][ 'caseSleep' ] )
Devin Limc5c9e112017-08-17 15:16:05 -070074 main.onosCell = main.params[ 'ENV' ][ 'cellName' ]
75 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
You Wangc61aaa22019-02-01 15:49:48 -080076 main.restartCluster = main.params[ 'TEST' ][ 'restartCluster' ] == "True"
77 main.excludeNodes = main.params[ 'TOPO' ][ 'excludeNodes' ].split( ',' ) \
78 if main.params[ 'TOPO' ][ 'excludeNodes' ] else []
79 main.skipSwitches = main.params[ 'CASE70' ][ 'skipSwitches' ].split( ',' ) \
80 if main.params[ 'CASE70' ][ 'skipSwitches' ] else []
81 main.skipLinks = main.params[ 'CASE70' ][ 'skipLinks' ].split( ',' ) \
82 if main.params[ 'CASE70' ][ 'skipLinks' ] else []
Devin Lim58046fa2017-07-05 16:55:00 -070083 main.controllers = []
Devin Lim58046fa2017-07-05 16:55:00 -070084 main.devices = []
85 main.links = []
86 main.hosts = []
87 main.intents = []
You Wangc61aaa22019-02-01 15:49:48 -080088 main.flowObj = False
Devin Lim58046fa2017-07-05 16:55:00 -070089 main.enabledEvents = {}
90 for eventName in main.params[ 'EVENT' ].keys():
91 if main.params[ 'EVENT' ][ eventName ][ 'status' ] == 'on':
92 main.enabledEvents[ int( main.params[ 'EVENT' ][ eventName ][ 'typeIndex' ] ) ] = eventName
Devin Lim58046fa2017-07-05 16:55:00 -070093 main.graph = Graph()
94 main.eventScheduler = EventScheduler()
95 main.eventGenerator = EventGenerator()
96 main.variableLock = Lock()
You Wangc61aaa22019-02-01 15:49:48 -080097 main.networkLock = Lock()
Devin Lim58046fa2017-07-05 16:55:00 -070098 main.ONOSbenchLock = Lock()
99 main.threadID = 0
100 main.eventID = 0
101 main.caseResult = main.TRUE
102 stepResult = main.testSetUp.envSetup()
103 except Exception as e:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700104 main.testSetUp.envSetupException( e )
Devin Lim58046fa2017-07-05 16:55:00 -0700105
106 main.testSetUp.evnSetupConclusion( stepResult )
107
You Wanga0f6ff62018-01-11 15:46:30 -0800108 setupResult = main.testSetUp.ONOSSetUp( main.Cluster,
You Wangc61aaa22019-02-01 15:49:48 -0800109 cellName=main.onosCell,
110 restartCluster=main.restartCluster )
Devin Lim142b5342017-07-20 15:22:39 -0700111 for i in range( 1, main.Cluster.numCtrls + 1 ):
112 newController = Controller( i )
You Wang9fc5ce42019-01-23 15:10:08 -0800113 newController.setCLI( main.Cluster.runningNodes[ i - 1 ].CLI )
Devin Lim142b5342017-07-20 15:22:39 -0700114 main.controllers.append( newController )
You Wangdb927a52016-02-26 11:03:28 -0800115
You Wang89f028d2019-03-06 16:24:35 -0800116 # Set logging levels
117 for logLevel in [ 'DEBUG', 'TRACE' ]:
118 if main.params[ 'LOGGING' ].get( logLevel ):
119 for logger in main.params[ 'LOGGING' ][ logLevel ].split( ',' ):
120 for ctrl in main.Cluster.active():
121 ctrl.CLI.logSet( logLevel, logger )
122
You Wangdb927a52016-02-26 11:03:28 -0800123 main.step( "Start a thread for the scheduler" )
124 t = main.Thread( target=main.eventScheduler.startScheduler,
125 threadID=main.threadID,
126 name="startScheduler",
127 args=[] )
128 t.start()
129 stepResult = main.TRUE
130 with main.variableLock:
131 main.threadID = main.threadID + 1
132
133 utilities.assert_equals( expect=main.TRUE,
134 actual=stepResult,
135 onpass="Test step PASS",
136 onfail="Test step FAIL" )
137
138 main.step( "Start a thread to listen to and handle network, ONOS and application events" )
139 t = main.Thread( target=main.eventGenerator.startListener,
140 threadID=main.threadID,
141 name="startListener",
142 args=[] )
143 t.start()
144 with main.variableLock:
145 main.threadID = main.threadID + 1
146
You Wang9fc5ce42019-01-23 15:10:08 -0800147 caseResult = setupResult
You Wangdb927a52016-02-26 11:03:28 -0800148 utilities.assert_equals( expect=main.TRUE,
149 actual=caseResult,
150 onpass="Set up test environment PASS",
151 onfail="Set up test environment FAIL" )
152
153 def CASE1( self, main ):
154 """
You Wang9fc5ce42019-01-23 15:10:08 -0800155 Set IPv6 cfg parameters for Neighbor Discovery
156 """
157 main.step( "Set IPv6 cfg parameters for Neighbor Discovery" )
158 setIPv6CfgSleep = int( main.params[ 'CASE1' ][ 'setIPv6CfgSleep' ] )
159 if main.enableIPv6:
160 time.sleep( setIPv6CfgSleep )
161 cfgResult1 = main.Cluster.active( 0 ).CLI.setCfg( "org.onosproject.net.neighbour.impl.NeighbourResolutionManager",
162 "ndpEnabled",
163 "true" )
164 time.sleep( setIPv6CfgSleep )
165 cfgResult2 = main.Cluster.active( 0 ).CLI.setCfg( "org.onosproject.provider.host.impl.HostLocationProvider",
166 "requestIpv6ND",
167 "true" )
168 else:
169 main.log.info( "Skipped setting IPv6 cfg parameters as it is disabled in params file" )
170 cfgResult1 = main.TRUE
171 cfgResult2 = main.TRUE
172 cfgResult = cfgResult1 and cfgResult2
173 utilities.assert_equals( expect=main.TRUE,
174 actual=cfgResult,
175 onpass="ipv6NeighborDiscovery cfg is set to true",
176 onfail="Failed to cfg set ipv6NeighborDiscovery" )
177
178 def CASE2( self, main ):
179 """
180 Load network configuration files
181 """
182 import json
183 main.case( "Load json files for configuring the network" )
184
185 main.step( "Load json files for configuring the network" )
186 cfgResult = main.TRUE
187 jsonFileName = main.params[ 'CASE2' ][ 'fileName' ]
188 jsonFile = main.testDir + "/dependencies/topologies/json/" + jsonFileName
189 with open( jsonFile ) as cfg:
190 main.Cluster.active( 0 ).REST.setNetCfg( json.load( cfg ) )
191
192 main.step( "Load host files" )
193 hostFileName = main.params[ 'CASE2' ][ 'hostFileName' ]
194 hostFile = main.testDir + "/dependencies/topologies/host/" + hostFileName
195 with open( hostFile ) as cfg:
196 main.expectedHosts = json.load( cfg )
197
198 utilities.assert_equals( expect=main.TRUE,
199 actual=cfgResult,
200 onpass="Correctly loaded network configurations",
201 onfail="Failed to load network configurations" )
202
203 def CASE4( self, main ):
204 """
205 Copy topology lib and config files to Mininet node
You Wangdb927a52016-02-26 11:03:28 -0800206 """
207 import re
You Wang9fc5ce42019-01-23 15:10:08 -0800208 main.case( "Copy topology lib and config files to Mininet node" )
209
210 copyResult = main.TRUE
211 main.step( "Copy topology lib files to Mininet node" )
212 for libFileName in main.params[ 'CASE4' ][ 'lib' ].split(","):
213 libFile = main.testDir + "/dependencies/topologies/lib/" + libFileName
214 copyResult = copyResult and main.ONOSbench.scp( main.Mininet1,
215 libFile,
216 main.Mininet1.home + "/custom",
217 direction="to" )
218
219 main.step( "Copy topology config files to Mininet node" )
220 controllerIPs = [ ctrl.ipAddress for ctrl in main.Cluster.runningNodes ]
221 index = 0
222 for confFileName in main.params[ 'CASE4' ][ 'conf' ].split(","):
223 confFile = main.testDir + "/dependencies/topologies/conf/" + confFileName
224 # Update zebra configurations with correct ONOS instance IP
225 if confFileName in [ "zebradbgp1.conf", "zebradbgp2.conf" ]:
226 ip = controllerIPs[ index ]
227 index = ( index + 1 ) % len( controllerIPs )
228 with open( confFile ) as f:
229 s = f.read()
230 s = re.sub( r"(fpm connection ip).*(port 2620)", r"\1 " + ip + r" \2", s )
231 with open( confFile, "w" ) as f:
232 f.write( s )
233 copyResult = copyResult and main.ONOSbench.scp( main.Mininet1,
234 confFile,
235 "~/",
236 direction="to" )
237
238 utilities.assert_equals( expect=main.TRUE,
239 actual=copyResult,
240 onpass="Successfully copied topo lib/conf files",
241 onfail="Failed to copy topo lib/conf files" )
242
243 def CASE5( self, main ):
244 """
You Wangc61aaa22019-02-01 15:49:48 -0800245 Load Mininet or physical network topology and balances switch mastership
You Wang9fc5ce42019-01-23 15:10:08 -0800246 """
You Wangdb927a52016-02-26 11:03:28 -0800247 import time
You Wang9fc5ce42019-01-23 15:10:08 -0800248 import re
You Wangc61aaa22019-02-01 15:49:48 -0800249 main.log.report( "Load Mininet or physical network topology and Balance switch mastership" )
You Wangdb927a52016-02-26 11:03:28 -0800250 main.log.report( "________________________________________________________________________" )
You Wangc61aaa22019-02-01 15:49:48 -0800251 main.case( "Load Mininet or physical network topology and Balance switch mastership" )
You Wangdb927a52016-02-26 11:03:28 -0800252
You Wangc61aaa22019-02-01 15:49:48 -0800253 if hasattr( main, 'Mininet1' ):
254 main.step( "Copy Mininet topology files" )
255 main.topoIndex = "topo" + str( main.params[ 'TEST' ][ 'topo' ] )
256 topoFileName = main.params[ 'TOPO' ][ main.topoIndex ][ 'fileName' ]
257 topoFile = main.testDir + "/dependencies/topologies/" + topoFileName
258 copyResult = main.ONOSbench.scp( main.Mininet1, topoFile, main.Mininet1.home + "/custom", direction="to" )
259 utilities.assert_equals( expect=main.TRUE,
260 actual=copyResult,
261 onpass="Successfully copied topo files",
262 onfail="Failed to copy topo files" )
You Wang9fc5ce42019-01-23 15:10:08 -0800263
You Wangc61aaa22019-02-01 15:49:48 -0800264 main.step( "Load topology" )
265 if hasattr( main, 'Mininet1' ):
266 topoResult = main.Mininet1.startNet( topoFile=main.Mininet1.home + "/custom/" + topoFileName,
267 args=main.params[ 'TOPO' ][ 'mininetArgs' ] )
268 else:
269 topoResult = main.NetworkBench.connectToNet()
You Wangdb927a52016-02-26 11:03:28 -0800270 utilities.assert_equals( expect=main.TRUE,
You Wangc61aaa22019-02-01 15:49:48 -0800271 actual=topoResult,
272 onpass="Successfully loaded topology",
273 onfail="Failed to load topology" )
274 # Exit if topology did not load properly
275 if not topoResult:
276 main.cleanAndExit()
You Wangdb927a52016-02-26 11:03:28 -0800277
278 main.step( "Assign switches to controllers" )
You Wangc61aaa22019-02-01 15:49:48 -0800279 if hasattr( main, 'Mininet1' ):
280 main.networkSwitches = main.Network.getSwitches( excludeNodes=main.excludeNodes )
281 else:
282 main.networkSwitches = main.Network.getSwitches( excludeNodes=main.excludeNodes,
283 includeStopped=True )
284 assignResult = main.TRUE
285 for name in main.networkSwitches.keys():
Devin Lim142b5342017-07-20 15:22:39 -0700286 ips = main.Cluster.getIps()
You Wangc61aaa22019-02-01 15:49:48 -0800287 assignResult = assignResult and main.Network.assignSwController( sw=name, ip=ips )
You Wangdb927a52016-02-26 11:03:28 -0800288 utilities.assert_equals( expect=main.TRUE,
You Wangc61aaa22019-02-01 15:49:48 -0800289 actual=assignResult,
290 onpass="Successfully assign switches to controllers",
291 onfail="Failed to assign switches to controllers" )
292
You Wangdb927a52016-02-26 11:03:28 -0800293 # Waiting here to make sure topology converges across all nodes
You Wang9fc5ce42019-01-23 15:10:08 -0800294 sleep = int( main.params[ 'TOPO' ][ 'loadTopoSleep' ] )
You Wangdb927a52016-02-26 11:03:28 -0800295 time.sleep( sleep )
296
297 main.step( "Balance devices across controllers" )
Devin Lim142b5342017-07-20 15:22:39 -0700298 balanceResult = main.Cluster.active( 0 ).CLI.balanceMasters()
You Wangc61aaa22019-02-01 15:49:48 -0800299 utilities.assert_equals( expect=main.TRUE,
300 actual=balanceResult,
301 onpass="Successfully balanced mastership",
302 onfail="Faild to balance mastership" )
You Wangdb927a52016-02-26 11:03:28 -0800303 # giving some breathing time for ONOS to complete re-balance
You Wang9fc5ce42019-01-23 15:10:08 -0800304 time.sleep( 5 )
305
You Wangc61aaa22019-02-01 15:49:48 -0800306 # Connecting to hosts that only have data plane connectivity
307 if hasattr( main, 'NetworkBench' ):
308 main.step( "Connecting inband hosts" )
309 hostResult = main.NetworkBench.connectInbandHosts()
310 utilities.assert_equals( expect=main.TRUE,
311 actual=hostResult,
312 onpass="Successfully connected inband hosts",
313 onfail="Failed to connect inband hosts" )
314 else:
315 hostResult = main.TRUE
You Wangdb927a52016-02-26 11:03:28 -0800316
You Wangc61aaa22019-02-01 15:49:48 -0800317 # Get network hosts and links
318 main.networkHosts = main.Network.getHosts()
319 if hasattr( main, "expectedHosts" ):
320 main.networkHosts = { key: value for key, value in main.networkHosts.items() if key in main.expectedHosts[ "network" ].keys() }
321 main.networkLinks = main.Network.getLinks()
322 main.networkLinks = [ link for link in main.networkLinks if
323 link[ 'node1' ] in main.networkHosts.keys() + main.networkSwitches.keys() and
324 link[ 'node2' ] in main.networkHosts.keys() + main.networkSwitches.keys() ]
325
326 caseResult = ( topoResult and assignResult and balanceResult and hostResult )
You Wangdb927a52016-02-26 11:03:28 -0800327 utilities.assert_equals( expect=main.TRUE,
328 actual=caseResult,
You Wangc61aaa22019-02-01 15:49:48 -0800329 onpass="Starting new topology test PASS",
330 onfail="Starting new topology test FAIL" )
You Wangdb927a52016-02-26 11:03:28 -0800331
You Wang9fc5ce42019-01-23 15:10:08 -0800332 def CASE6( self, main ):
You Wangdb927a52016-02-26 11:03:28 -0800333 """
334 Collect and store device and link data from ONOS
335 """
336 import json
337 from tests.CHOTestMonkey.dependencies.elements.NetworkElement import Device, Link
338
339 main.log.report( "Collect and Store topology details from ONOS" )
340 main.log.report( "____________________________________________________________________" )
341 main.case( "Collect and Store Topology Details from ONOS" )
You Wang9fc5ce42019-01-23 15:10:08 -0800342
You Wangdb927a52016-02-26 11:03:28 -0800343 topoResult = main.TRUE
Devin Lim142b5342017-07-20 15:22:39 -0700344 topologyOutput = main.Cluster.active( 0 ).CLI.topology()
345 topologyResult = main.Cluster.active( 0 ).CLI.getTopology( topologyOutput )
You Wangdb927a52016-02-26 11:03:28 -0800346 ONOSDeviceNum = int( topologyResult[ 'devices' ] )
347 ONOSLinkNum = int( topologyResult[ 'links' ] )
You Wangc61aaa22019-02-01 15:49:48 -0800348 networkSwitchNum = len( main.networkSwitches )
349 if hasattr( main, 'Mininet1' ):
350 networkLinkNum = ( len( main.networkLinks ) - len( main.networkHosts ) ) * 2
351 else:
352 networkLinkNum = len( main.networkLinks ) * 2
353 if networkSwitchNum == ONOSDeviceNum and networkLinkNum == ONOSLinkNum:
You Wangdb927a52016-02-26 11:03:28 -0800354 main.step( "Collect and store device data" )
355 stepResult = main.TRUE
356 dpidToName = {}
You Wangc61aaa22019-02-01 15:49:48 -0800357 for key, value in main.networkSwitches.items():
You Wangdb927a52016-02-26 11:03:28 -0800358 dpidToName[ 'of:' + str( value[ 'dpid' ] ) ] = key
You Wang9fc5ce42019-01-23 15:10:08 -0800359 main.devicesRaw = main.Cluster.active( 0 ).CLI.devices()
360 devices = json.loads( main.devicesRaw )
You Wangdb927a52016-02-26 11:03:28 -0800361 deviceInitIndex = 0
362 for device in devices:
363 name = dpidToName[ device[ 'id' ] ]
364 newDevice = Device( deviceInitIndex, name, device[ 'id' ] )
You Wang9fc5ce42019-01-23 15:10:08 -0800365 main.log.info( 'New device: {}'.format( newDevice ) )
You Wangdb927a52016-02-26 11:03:28 -0800366 main.devices.append( newDevice )
367 deviceInitIndex += 1
368 utilities.assert_equals( expect=main.TRUE,
369 actual=stepResult,
370 onpass="Successfully collected and stored device data",
371 onfail="Failed to collect and store device data" )
372
373 main.step( "Collect and store link data" )
374 stepResult = main.TRUE
You Wang9fc5ce42019-01-23 15:10:08 -0800375 main.linksRaw = main.Cluster.active( 0 ).CLI.links()
376 links = json.loads( main.linksRaw )
You Wangdb927a52016-02-26 11:03:28 -0800377 linkInitIndex = 0
378 for link in links:
379 for device in main.devices:
380 if device.dpid == link[ 'src' ][ 'device' ]:
381 deviceA = device
382 elif device.dpid == link[ 'dst' ][ 'device' ]:
383 deviceB = device
Jon Hall2bb3e212017-05-24 17:07:25 -0700384 assert deviceA is not None and deviceB is not None
You Wangdb927a52016-02-26 11:03:28 -0800385 newLink = Link( linkInitIndex, deviceA, link[ 'src' ][ 'port' ], deviceB, link[ 'dst' ][ 'port' ] )
You Wang9fc5ce42019-01-23 15:10:08 -0800386 main.log.info( 'New link: {}'.format( newLink ) )
You Wangdb927a52016-02-26 11:03:28 -0800387 main.links.append( newLink )
388 linkInitIndex += 1
389 # Set backward links and outgoing links of devices
390 for linkA in main.links:
391 linkA.deviceA.outgoingLinks.append( linkA )
Jon Hall2bb3e212017-05-24 17:07:25 -0700392 if linkA.backwardLink is not None:
You Wangdb927a52016-02-26 11:03:28 -0800393 continue
394 for linkB in main.links:
Jon Hall2bb3e212017-05-24 17:07:25 -0700395 if linkB.backwardLink is not None:
You Wangdb927a52016-02-26 11:03:28 -0800396 continue
397 if linkA.deviceA == linkB.deviceB and\
Jon Hall2bb3e212017-05-24 17:07:25 -0700398 linkA.deviceB == linkB.deviceA and\
399 linkA.portA == linkB.portB and\
400 linkA.portB == linkB.portA:
You Wangdb927a52016-02-26 11:03:28 -0800401 linkA.setBackwardLink( linkB )
402 linkB.setBackwardLink( linkA )
403 utilities.assert_equals( expect=main.TRUE,
404 actual=stepResult,
405 onpass="Successfully collected and stored link data",
406 onfail="Failed to collect and store link data" )
407 else:
You Wangc61aaa22019-02-01 15:49:48 -0800408 main.log.info( "Devices (expected): %s, Links (expected): %s" % ( networkSwitchNum, networkLinkNum ) )
You Wangdb927a52016-02-26 11:03:28 -0800409 main.log.info( "Devices (actual): %s, Links (actual): %s" % ( ONOSDeviceNum, ONOSLinkNum ) )
410 topoResult = main.FALSE
411
412 caseResult = topoResult
413 utilities.assert_equals( expect=main.TRUE,
414 actual=caseResult,
415 onpass="Saving ONOS topology data test PASS",
416 onfail="Saving ONOS topology data test FAIL" )
417
418 if not caseResult:
Jon Hall2bb3e212017-05-24 17:07:25 -0700419 main.log.info( "Topology does not match, exiting test..." )
Devin Lim44075962017-08-11 10:56:37 -0700420 main.cleanAndExit()
You Wangdb927a52016-02-26 11:03:28 -0800421
You Wang9fc5ce42019-01-23 15:10:08 -0800422 def CASE7( self, main ):
You Wangdb927a52016-02-26 11:03:28 -0800423 """
424 Collect and store host data from ONOS
425 """
426 import json
427 from tests.CHOTestMonkey.dependencies.elements.NetworkElement import Host
428
429 main.log.report( "Collect and store host adta from ONOS" )
430 main.log.report( "______________________________________________" )
You Wang9fc5ce42019-01-23 15:10:08 -0800431 main.case( "Use fwd app and pingall to discover all the hosts if necessary, then collect and store host data" )
You Wangdb927a52016-02-26 11:03:28 -0800432
You Wang9fc5ce42019-01-23 15:10:08 -0800433 if main.params[ 'TEST' ][ 'dataPlaneConnectivity' ] == 'False':
434 main.step( "Enable Reactive forwarding" )
435 appResult = main.Cluster.active( 0 ).CLI.activateApp( "org.onosproject.fwd" )
436 cfgResult1 = main.TRUE
437 cfgResult2 = main.TRUE
438 if main.enableIPv6:
439 cfgResult1 = main.Cluster.active( 0 ).CLI.setCfg( "org.onosproject.fwd.ReactiveForwarding", "ipv6Forwarding", "true" )
440 cfgResult2 = main.Cluster.active( 0 ).CLI.setCfg( "org.onosproject.fwd.ReactiveForwarding", "matchIpv6Address", "true" )
441 stepResult = appResult and cfgResult1 and cfgResult2
442 utilities.assert_equals( expect=main.TRUE,
443 actual=stepResult,
444 onpass="Successfully enabled reactive forwarding",
445 onfail="Failed to enable reactive forwarding" )
You Wangdb927a52016-02-26 11:03:28 -0800446
You Wang9fc5ce42019-01-23 15:10:08 -0800447 main.step( "Discover hosts using pingall" )
You Wangc61aaa22019-02-01 15:49:48 -0800448 main.Network.pingall()
You Wang9fc5ce42019-01-23 15:10:08 -0800449 if main.enableIPv6:
You Wangc61aaa22019-02-01 15:49:48 -0800450 ping6Result = main.Network.pingall( protocol="IPv6" )
You Wang9fc5ce42019-01-23 15:10:08 -0800451
452 main.step( "Disable Reactive forwarding" )
453 appResult = main.Cluster.active( 0 ).CLI.deactivateApp( "org.onosproject.fwd" )
454 stepResult = appResult
455 utilities.assert_equals( expect=main.TRUE,
456 actual=stepResult,
457 onpass="Successfully deactivated fwd app",
458 onfail="Failed to deactivate fwd app" )
459
460 main.step( "Verify host discovery" )
You Wangdb927a52016-02-26 11:03:28 -0800461 stepResult = main.TRUE
You Wang9fc5ce42019-01-23 15:10:08 -0800462 main.hostsRaw = main.Cluster.active( 0 ).CLI.hosts()
463 hosts = json.loads( main.hostsRaw )
464 if hasattr( main, "expectedHosts" ):
465 hosts = [ host for host in hosts if host[ 'id' ] in main.expectedHosts[ 'onos' ].keys() ]
You Wangc61aaa22019-02-01 15:49:48 -0800466 if not len( hosts ) == len( main.networkHosts ):
You Wangdb927a52016-02-26 11:03:28 -0800467 stepResult = main.FALSE
468 utilities.assert_equals( expect=main.TRUE,
469 actual=stepResult,
470 onpass="Host discovery PASS",
471 onfail="Host discovery FAIL" )
472 if not stepResult:
473 main.log.debug( hosts )
Devin Lim44075962017-08-11 10:56:37 -0700474 main.cleanAndExit()
You Wangdb927a52016-02-26 11:03:28 -0800475
You Wangdb927a52016-02-26 11:03:28 -0800476 main.step( "Collect and store host data" )
477 stepResult = main.TRUE
478 macToName = {}
You Wangc61aaa22019-02-01 15:49:48 -0800479 for key, value in main.networkHosts.items():
You Wangdb927a52016-02-26 11:03:28 -0800480 macToName[ value[ 'interfaces' ][ 0 ][ 'mac' ].upper() ] = key
481 dpidToDevice = {}
482 for device in main.devices:
483 dpidToDevice[ device.dpid ] = device
484 hostInitIndex = 0
485 for host in hosts:
486 name = macToName[ host[ 'mac' ] ]
You Wang9fc5ce42019-01-23 15:10:08 -0800487 devices = {}
488 for location in host[ 'locations' ]:
489 device = dpidToDevice[ location[ 'elementId' ] ]
490 devices[ device ] = location[ 'port' ]
You Wangdb927a52016-02-26 11:03:28 -0800491 newHost = Host( hostInitIndex,
492 name, host[ 'id' ], host[ 'mac' ],
You Wang9fc5ce42019-01-23 15:10:08 -0800493 devices,
You Wangdb927a52016-02-26 11:03:28 -0800494 host[ 'vlan' ], host[ 'ipAddresses' ] )
You Wang9fc5ce42019-01-23 15:10:08 -0800495 main.log.info( 'New host: {}'.format( newHost ) )
You Wangdb927a52016-02-26 11:03:28 -0800496 main.hosts.append( newHost )
You Wangdb927a52016-02-26 11:03:28 -0800497 hostInitIndex += 1
You Wang9fc5ce42019-01-23 15:10:08 -0800498 for location in host[ 'locations' ]:
499 device = dpidToDevice[ location[ 'elementId' ] ]
500 main.devices[ device.index ].hosts[ newHost ] = location[ 'port' ]
501
502 # Collect IPv4 and IPv6 hosts
503 main.ipv4Hosts = []
504 main.ipv6Hosts = []
505 for host in main.hosts:
506 if any( re.match( str( main.params[ 'TEST' ][ 'ipv6Regex' ] ), ipAddress ) for ipAddress in host.ipAddresses ):
507 main.ipv6Hosts.append( host )
508 if any( re.match( str( main.params[ 'TEST' ][ 'ipv4Regex' ] ), ipAddress ) for ipAddress in host.ipAddresses ):
509 main.ipv4Hosts.append( host )
You Wangdb927a52016-02-26 11:03:28 -0800510 utilities.assert_equals( expect=main.TRUE,
511 actual=stepResult,
512 onpass="Successfully collected and stored host data",
513 onfail="Failed to collect and store host data" )
514
515 main.step( "Create one host component for each host and then start host cli" )
You Wangc61aaa22019-02-01 15:49:48 -0800516 hostResult = main.TRUE
You Wangdb927a52016-02-26 11:03:28 -0800517 for host in main.hosts:
You Wangc61aaa22019-02-01 15:49:48 -0800518 main.Network.createHostComponent( host.name )
You Wangdb927a52016-02-26 11:03:28 -0800519 hostHandle = getattr( main, host.name )
You Wangc61aaa22019-02-01 15:49:48 -0800520 if hasattr( main, "Mininet1" ):
521 main.log.info( "Starting CLI on host " + str( host.name ) )
522 hostResult = hostResult and hostHandle.startHostCli()
523 else:
524 main.log.info( "Connecting inband host " + str( host.name ) )
525 hostResult = hostResult and hostHandle.connectInband()
You Wangdb927a52016-02-26 11:03:28 -0800526 host.setHandle( hostHandle )
You Wang9fc5ce42019-01-23 15:10:08 -0800527 if main.params[ 'TEST' ][ 'dataPlaneConnectivity' ] == 'True':
528 # Hosts should already be able to ping each other
529 if host in main.ipv4Hosts:
530 host.correspondents += main.ipv4Hosts
531 if host in main.ipv6Hosts:
532 host.correspondents += main.ipv6Hosts
533 utilities.assert_equals( expect=main.TRUE,
You Wangc61aaa22019-02-01 15:49:48 -0800534 actual=hostResult,
535 onpass="Host components created",
536 onfail="Failed to create host components" )
You Wangdb927a52016-02-26 11:03:28 -0800537
538 def CASE10( self, main ):
539 """
540 Run all enabled checks
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( "Run all enabled checks" )
547 main.log.report( "__________________________________________________" )
548 main.case( "Run all enabled checks" )
549 main.step( "Run all enabled checks" )
550 main.caseResult = main.TRUE
551 main.eventGenerator.triggerEvent( EventType().CHECK_ALL, EventScheduleMethod().RUN_BLOCK )
552 # Wait for the scheduler to become idle before going to the next testcase
553 with main.eventScheduler.idleCondition:
554 while not main.eventScheduler.isIdle():
555 main.eventScheduler.idleCondition.wait()
556 utilities.assert_equals( expect=main.TRUE,
557 actual=main.caseResult,
558 onpass="All enabled checks passed",
559 onfail="Not all enabled checks passed" )
560 time.sleep( main.caseSleep )
561
562 def CASE20( self, main ):
563 """
564 Bring down/up links and check topology and ping
565 """
566 import time
567 from tests.CHOTestMonkey.dependencies.events.Event import EventType
568 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
569
570 main.log.report( "Bring down/up links and check topology and ping" )
571 main.log.report( "__________________________________________________" )
572 main.case( "Bring down/up links and check topology and ping" )
573 main.step( "Bring down/up links and check topology and ping" )
574 main.caseResult = main.TRUE
575 linkToggleNum = int( main.params[ 'CASE20' ][ 'linkToggleNum' ] )
576 linkDownUpInterval = int( main.params[ 'CASE20' ][ 'linkDownUpInterval' ] )
577 for i in range( 0, linkToggleNum ):
578 main.eventGenerator.triggerEvent( EventType().NETWORK_LINK_RANDOM_TOGGLE, EventScheduleMethod().RUN_BLOCK, linkDownUpInterval )
579 with main.eventScheduler.idleCondition:
580 while not main.eventScheduler.isIdle():
581 main.eventScheduler.idleCondition.wait()
582 utilities.assert_equals( expect=main.TRUE,
583 actual=main.caseResult,
584 onpass="Toggle network links test passed",
585 onfail="Toggle network links test failed" )
586 time.sleep( main.caseSleep )
587
588 def CASE21( self, main ):
589 """
590 Bring down/up a group of links and check topology and ping
591 """
592 import time
593 from tests.CHOTestMonkey.dependencies.events.Event import EventType
594 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
595
596 main.log.report( "Bring down/up a group of links and check topology and ping" )
597 main.log.report( "__________________________________________________" )
598 main.case( "Bring down/up a group of links and check topology and ping" )
599 main.step( "Bring down/up a group of links and check topology and ping" )
600 main.caseResult = main.TRUE
601 linkGroupSize = int( main.params[ 'CASE21' ][ 'linkGroupSize' ] )
602 linkDownDownInterval = int( main.params[ 'CASE21' ][ 'linkDownDownInterval' ] )
603 linkDownUpInterval = int( main.params[ 'CASE21' ][ 'linkDownUpInterval' ] )
604 main.eventGenerator.triggerEvent( EventType().NETWORK_LINK_GROUP_RANDOM_TOGGLE, EventScheduleMethod().RUN_BLOCK, linkGroupSize, linkDownDownInterval, linkDownUpInterval )
605 with main.eventScheduler.idleCondition:
606 while not main.eventScheduler.isIdle():
607 main.eventScheduler.idleCondition.wait()
608 utilities.assert_equals( expect=main.TRUE,
609 actual=main.caseResult,
610 onpass="Toggle network link group test passed",
611 onfail="Toggle network link group test failed" )
612 time.sleep( main.caseSleep )
613
614 def CASE30( self, main ):
615 """
616 Install host intents and check intent states and ping
617 """
618 import time
619 from tests.CHOTestMonkey.dependencies.events.Event import EventType
620 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
621
622 main.log.report( "Install host intents and check intent states and ping" )
623 main.log.report( "__________________________________________________" )
624 main.case( "Install host intents and check intent states and ping" )
625 main.step( "Install host intents and check intent states and ping" )
626 main.caseResult = main.TRUE
627 main.eventGenerator.triggerEvent( EventType().APP_INTENT_HOST_ADD_ALL, EventScheduleMethod().RUN_BLOCK )
628 with main.eventScheduler.idleCondition:
629 while not main.eventScheduler.isIdle():
630 main.eventScheduler.idleCondition.wait()
631 utilities.assert_equals( expect=main.TRUE,
632 actual=main.caseResult,
633 onpass="Install host intents test passed",
634 onfail="Install host intents test failed" )
635 time.sleep( main.caseSleep )
636
637 def CASE31( self, main ):
638 """
639 Uninstall host intents and check intent states and ping
640 """
641 import time
642 from tests.CHOTestMonkey.dependencies.events.Event import EventType
643 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
644
645 main.log.report( "Uninstall host intents and check intent states and ping" )
646 main.log.report( "__________________________________________________" )
647 main.case( "Uninstall host intents and check intent states and ping" )
648 main.step( "Uninstall host intents and check intent states and ping" )
649 main.caseResult = main.TRUE
650 main.eventGenerator.triggerEvent( EventType().APP_INTENT_HOST_DEL_ALL, EventScheduleMethod().RUN_BLOCK )
651 with main.eventScheduler.idleCondition:
652 while not main.eventScheduler.isIdle():
653 main.eventScheduler.idleCondition.wait()
654 utilities.assert_equals( expect=main.TRUE,
655 actual=main.caseResult,
656 onpass="Uninstall host intents test passed",
657 onfail="Uninstall host intents test failed" )
658 time.sleep( main.caseSleep )
659
660 def CASE32( self, main ):
661 """
662 Install point intents and check intent states and ping
663 """
664 import time
665 from tests.CHOTestMonkey.dependencies.events.Event import EventType
666 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
667
668 main.log.report( "Install point intents and check intent states and ping" )
669 main.log.report( "__________________________________________________" )
670 main.case( "Install point intents and check intent states and ping" )
671 main.step( "Install point intents and check intent states and ping" )
672 main.caseResult = main.TRUE
673 main.eventGenerator.triggerEvent( EventType().APP_INTENT_POINT_ADD_ALL, EventScheduleMethod().RUN_BLOCK )
674 with main.eventScheduler.idleCondition:
675 while not main.eventScheduler.isIdle():
676 main.eventScheduler.idleCondition.wait()
677 utilities.assert_equals( expect=main.TRUE,
678 actual=main.caseResult,
679 onpass="Install point intents test passed",
680 onfail="Install point intents test failed" )
681 time.sleep( main.caseSleep )
682
683 def CASE33( self, main ):
684 """
685 Uninstall point intents and check intent states and ping
686 """
687 import time
688 from tests.CHOTestMonkey.dependencies.events.Event import EventType
689 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
690
691 main.log.report( "Uninstall point intents and check intent states and ping" )
692 main.log.report( "__________________________________________________" )
693 main.case( "Uninstall point intents and check intent states and ping" )
694 main.step( "Uninstall point intents and check intent states and ping" )
695 main.caseResult = main.TRUE
696 main.eventGenerator.triggerEvent( EventType().APP_INTENT_POINT_DEL_ALL, EventScheduleMethod().RUN_BLOCK )
697 with main.eventScheduler.idleCondition:
698 while not main.eventScheduler.isIdle():
699 main.eventScheduler.idleCondition.wait()
700 utilities.assert_equals( expect=main.TRUE,
701 actual=main.caseResult,
702 onpass="Uninstall point intents test passed",
703 onfail="Uninstall point intents test failed" )
704 time.sleep( main.caseSleep )
705
706 def CASE40( self, main ):
707 """
708 Randomly bring down one ONOS node
709 """
710 import time
711 import random
712 from tests.CHOTestMonkey.dependencies.events.Event import EventType
713 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
714
715 main.log.report( "Randomly bring down one ONOS node" )
716 main.log.report( "__________________________________________________" )
717 main.case( "Randomly bring down one ONOS node" )
718 main.step( "Randomly bring down one ONOS node" )
719 main.caseResult = main.TRUE
720 availableControllers = []
721 for controller in main.controllers:
722 if controller.isUp():
723 availableControllers.append( controller.index )
724 if len( availableControllers ) == 0:
725 main.log.warn( "No available controllers" )
726 main.caseResult = main.FALSE
727 else:
728 index = random.sample( availableControllers, 1 )
729 main.eventGenerator.triggerEvent( EventType().ONOS_ONOS_DOWN, EventScheduleMethod().RUN_BLOCK, index[ 0 ] )
730 with main.eventScheduler.idleCondition:
731 while not main.eventScheduler.isIdle():
732 main.eventScheduler.idleCondition.wait()
733 utilities.assert_equals( expect=main.TRUE,
734 actual=main.caseResult,
735 onpass="Randomly bring down ONOS test passed",
736 onfail="Randomly bring down ONOS test failed" )
You Wang817990a2019-01-22 15:07:25 -0800737 time.sleep( int( main.params[ 'CASE40' ][ 'sleepSec' ] ) )
You Wangdb927a52016-02-26 11:03:28 -0800738
739 def CASE41( self, main ):
740 """
741 Randomly bring up one ONOS node that is down
742 """
743 import time
744 import random
745 from tests.CHOTestMonkey.dependencies.events.Event import EventType
746 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
747
748 main.log.report( "Randomly bring up one ONOS node that is down" )
749 main.log.report( "__________________________________________________" )
750 main.case( "Randomly bring up one ONOS node that is down" )
751 main.step( "Randomly bring up one ONOS node that is down" )
752 main.caseResult = main.TRUE
753 targetControllers = []
754 for controller in main.controllers:
755 if not controller.isUp():
756 targetControllers.append( controller.index )
757 if len( targetControllers ) == 0:
758 main.log.warn( "All controllers are up" )
759 main.caseResult = main.FALSE
760 else:
761 index = random.sample( targetControllers, 1 )
762 main.eventGenerator.triggerEvent( EventType().ONOS_ONOS_UP, EventScheduleMethod().RUN_BLOCK, index[ 0 ] )
763 with main.eventScheduler.idleCondition:
764 while not main.eventScheduler.isIdle():
765 main.eventScheduler.idleCondition.wait()
766 utilities.assert_equals( expect=main.TRUE,
767 actual=main.caseResult,
768 onpass="Randomly bring up ONOS test passed",
769 onfail="Randomly bring up ONOS test failed" )
You Wang817990a2019-01-22 15:07:25 -0800770 time.sleep( int( main.params[ 'CASE41' ][ 'sleepSec' ] ) )
You Wangdb927a52016-02-26 11:03:28 -0800771
772 def CASE50( self, main ):
773 """
774 Set FlowObjective to True
775 """
776 import time
777 from tests.CHOTestMonkey.dependencies.events.Event import EventType
778 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
779
780 main.log.report( "Set FlowObjective to True" )
781 main.log.report( "__________________________________________________" )
782 main.case( "Set FlowObjective to True" )
783 main.step( "Set FlowObjective to True" )
784 main.caseResult = main.TRUE
785 main.eventGenerator.triggerEvent( EventType().ONOS_SET_FLOWOBJ, EventScheduleMethod().RUN_BLOCK, 'true' )
786 with main.eventScheduler.idleCondition:
787 while not main.eventScheduler.isIdle():
788 main.eventScheduler.idleCondition.wait()
789 utilities.assert_equals( expect=main.TRUE,
790 actual=main.caseResult,
791 onpass="Set FlowObjective test passed",
792 onfail="Set FlowObjective test failed" )
793 time.sleep( main.caseSleep )
794
795 def CASE51( self, main ):
796 """
797 Set FlowObjective to False
798 """
799 import time
800 from tests.CHOTestMonkey.dependencies.events.Event import EventType
801 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
802
803 main.log.report( "Set FlowObjective to False" )
804 main.log.report( "__________________________________________________" )
805 main.case( "Set FlowObjective to False" )
806 main.step( "Set FlowObjective to False" )
807 main.caseResult = main.TRUE
808 main.eventGenerator.triggerEvent( EventType().ONOS_SET_FLOWOBJ, EventScheduleMethod().RUN_BLOCK, 'false' )
809 with main.eventScheduler.idleCondition:
810 while not main.eventScheduler.isIdle():
811 main.eventScheduler.idleCondition.wait()
812 utilities.assert_equals( expect=main.TRUE,
813 actual=main.caseResult,
814 onpass="Set FlowObjective test passed",
815 onfail="Set FlowObjective test failed" )
816 time.sleep( main.caseSleep )
817
818 def CASE60( self, main ):
819 """
820 Balance device masters
821 """
822 import time
823 from tests.CHOTestMonkey.dependencies.events.Event import EventType
824 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
825
826 main.log.report( "Balance device masters" )
827 main.log.report( "__________________________________________________" )
828 main.case( "Balance device masters" )
829 main.step( "Balance device masters" )
830 main.caseResult = main.TRUE
831 main.eventGenerator.triggerEvent( EventType().ONOS_BALANCE_MASTERS, EventScheduleMethod().RUN_BLOCK )
832 with main.eventScheduler.idleCondition:
833 while not main.eventScheduler.isIdle():
834 main.eventScheduler.idleCondition.wait()
835 utilities.assert_equals( expect=main.TRUE,
836 actual=main.caseResult,
837 onpass="Balance masters test passed",
838 onfail="Balance masters test failed" )
839 time.sleep( main.caseSleep )
840
You Wang7a27f3a2016-07-05 10:12:27 -0700841 def CASE70( self, main ):
842 """
843 Randomly generate events
844 """
845 import time
846 import random
847 from tests.CHOTestMonkey.dependencies.events.Event import EventType
848 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
849
850 main.log.report( "Randomly generate events" )
851 main.log.report( "__________________________________________________" )
852 main.case( "Randomly generate events" )
853 main.step( "Randomly generate events" )
854 main.caseResult = main.TRUE
855 sleepSec = int( main.params[ 'CASE70' ][ 'sleepSec' ] )
You Wangc61aaa22019-02-01 15:49:48 -0800856 allControllers = range( 1, int( main.params[ 'TEST' ][ 'numCtrl' ] ) + 1 )
You Wang7a27f3a2016-07-05 10:12:27 -0700857 while True:
You Wangc61aaa22019-02-01 15:49:48 -0800858 upControllers = [ i for i in allControllers if main.controllers[ i - 1 ].isUp() ]
You Wangad483c82019-03-13 15:25:44 -0700859 downControllers = [ i for i in allControllers if i not in upControllers ]
You Wangc61aaa22019-02-01 15:49:48 -0800860 hostIntentNum = len( [ intent for intent in main.intents if intent.type == 'INTENT_HOST' ] )
861 pointIntentNum = len( [ intent for intent in main.intents if intent.type == 'INTENT_POINT' ] )
862 downDeviceNum = len( [ device for device in main.devices if device.isDown() or device.isRemoved() ] )
863 downLinkNum = len( [ link for link in main.links if link.isDown() ] ) / 2
864 downPortNum = sum( [ len( device.downPorts ) for device in main.devices ] )
You Wang7a27f3a2016-07-05 10:12:27 -0700865 events = []
You Wangc61aaa22019-02-01 15:49:48 -0800866 for event, weight in main.params[ 'CASE70' ][ 'eventWeight' ].items():
867 events += [ event ] * int( weight )
868 events += [ 'del-host-intent' ] * int( pow( hostIntentNum, 1.5 ) / 100 )
869 events += [ 'del-point-intent' ] * int( pow( pointIntentNum, 1.5 ) / 100 )
You Wangad483c82019-03-13 15:25:44 -0700870 events += [ 'device-up' ] * int( pow( 3, downDeviceNum ) - 1 )
You Wangc61aaa22019-02-01 15:49:48 -0800871 if 'link-down' in main.params[ 'CASE70' ][ 'eventWeight' ].keys():
You Wangad483c82019-03-13 15:25:44 -0700872 events += [ 'link-up' ] * int( pow( 3, downLinkNum ) - 1 )
You Wangc61aaa22019-02-01 15:49:48 -0800873 if 'port-down' in main.params[ 'CASE70' ][ 'eventWeight' ].keys():
You Wangad483c82019-03-13 15:25:44 -0700874 events += [ 'port-up' ] * int( pow( 3, downPortNum ) - 1 )
875 events += [ 'onos-up' ] * int( pow( 3, len( downControllers ) - 1 ) )
You Wang7a27f3a2016-07-05 10:12:27 -0700876 main.log.debug( events )
877 event = random.sample( events, 1 )[ 0 ]
878 if event == 'add-host-intent':
879 n = random.randint( 5, 50 )
880 for i in range( n ):
881 cliIndex = random.sample( upControllers, 1 )[ 0 ]
You Wangc848af12016-07-14 09:53:58 -0700882 main.eventGenerator.triggerEvent( EventType().APP_INTENT_HOST_ADD, EventScheduleMethod().RUN_BLOCK, 'random', 'random', cliIndex )
You Wang7a27f3a2016-07-05 10:12:27 -0700883 elif event == 'del-host-intent':
884 n = random.randint( 5, hostIntentNum )
885 for i in range( n ):
886 cliIndex = random.sample( upControllers, 1 )[ 0 ]
You Wangc848af12016-07-14 09:53:58 -0700887 main.eventGenerator.triggerEvent( EventType().APP_INTENT_HOST_DEL, EventScheduleMethod().RUN_BLOCK, 'random', 'random', cliIndex )
You Wang7a27f3a2016-07-05 10:12:27 -0700888 elif event == 'add-point-intent':
889 n = random.randint( 5, 50 )
890 for i in range( n ):
891 cliIndex = random.sample( upControllers, 1 )[ 0 ]
You Wangc848af12016-07-14 09:53:58 -0700892 main.eventGenerator.triggerEvent( EventType().APP_INTENT_POINT_ADD, EventScheduleMethod().RUN_BLOCK, 'random', 'random', cliIndex, 'bidirectional' )
You Wang7a27f3a2016-07-05 10:12:27 -0700893 elif event == 'del-point-intent':
You Wang52163202016-07-14 16:37:15 -0700894 n = random.randint( 5, pointIntentNum / 2 )
You Wang7a27f3a2016-07-05 10:12:27 -0700895 for i in range( n ):
896 cliIndex = random.sample( upControllers, 1 )[ 0 ]
You Wangc848af12016-07-14 09:53:58 -0700897 main.eventGenerator.triggerEvent( EventType().APP_INTENT_POINT_DEL, EventScheduleMethod().RUN_BLOCK, 'random', 'random', cliIndex, 'bidirectional' )
You Wang7a27f3a2016-07-05 10:12:27 -0700898 elif event == 'link-down':
899 main.eventGenerator.triggerEvent( EventType().NETWORK_LINK_DOWN, EventScheduleMethod().RUN_BLOCK, 'random', 'random' )
You Wang7a27f3a2016-07-05 10:12:27 -0700900 elif event == 'link-up':
901 main.eventGenerator.triggerEvent( EventType().NETWORK_LINK_UP, EventScheduleMethod().RUN_BLOCK, 'random', 'random' )
You Wang7a27f3a2016-07-05 10:12:27 -0700902 elif event == 'device-down':
903 main.eventGenerator.triggerEvent( EventType().NETWORK_DEVICE_DOWN, EventScheduleMethod().RUN_BLOCK, 'random' )
You Wang7a27f3a2016-07-05 10:12:27 -0700904 elif event == 'device-up':
905 main.eventGenerator.triggerEvent( EventType().NETWORK_DEVICE_UP, EventScheduleMethod().RUN_BLOCK, 'random' )
You Wang9fc5ce42019-01-23 15:10:08 -0800906 elif event == 'port-down':
907 main.eventGenerator.triggerEvent( EventType().NETWORK_PORT_DOWN, EventScheduleMethod().RUN_BLOCK, 'random', 'random' )
You Wang9fc5ce42019-01-23 15:10:08 -0800908 elif event == 'port-up':
909 main.eventGenerator.triggerEvent( EventType().NETWORK_PORT_UP, EventScheduleMethod().RUN_BLOCK, 'random', 'random' )
You Wangad483c82019-03-13 15:25:44 -0700910 elif event == 'onos-down' and len( downControllers ) == 0:
911 onosIndex = random.sample( upControllers, 1 )[ 0 ]
912 main.eventGenerator.triggerEvent( EventType().ONOS_ONOS_DOWN, EventScheduleMethod().RUN_BLOCK, onosIndex )
913 elif event == 'onos-up' and len( downControllers ) > 0:
914 main.eventGenerator.triggerEvent( EventType().ONOS_ONOS_UP, EventScheduleMethod().RUN_BLOCK, downControllers[ 0 ] )
You Wang9fc5ce42019-01-23 15:10:08 -0800915 main.eventGenerator.triggerEvent( EventType().ONOS_BALANCE_MASTERS, EventScheduleMethod().RUN_BLOCK )
You Wangf6e98a82016-11-14 14:46:49 -0800916 elif event == 'toggle-flowobj':
You Wangc61aaa22019-02-01 15:49:48 -0800917 main.eventGenerator.triggerEvent( EventType().ONOS_SET_FLOWOBJ, EventScheduleMethod().RUN_BLOCK, 'false' if main.flowObj else 'true' )
You Wang7a27f3a2016-07-05 10:12:27 -0700918 else:
919 pass
You Wangc61aaa22019-02-01 15:49:48 -0800920 main.eventGenerator.triggerEvent( EventType().CHECK_ALL, EventScheduleMethod().RUN_NON_BLOCK )
You Wang7a27f3a2016-07-05 10:12:27 -0700921 with main.eventScheduler.idleCondition:
922 while not main.eventScheduler.isIdle():
923 main.eventScheduler.idleCondition.wait()
You Wang5f4f36e2016-09-21 15:30:30 -0700924 time.sleep( sleepSec )
You Wang7a27f3a2016-07-05 10:12:27 -0700925 utilities.assert_equals( expect=main.TRUE,
926 actual=main.caseResult,
927 onpass="Randomly generate events test passed",
928 onfail="Randomly generate events test failed" )
929 time.sleep( main.caseSleep )
930
You Wang52163202016-07-14 16:37:15 -0700931 def CASE80( self, main ):
932 """
933 Replay events from log file
934 """
935 import time
936 from tests.CHOTestMonkey.dependencies.events.Event import EventType
937 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
938
939 main.log.report( "Replay events from log file" )
940 main.log.report( "__________________________________________________" )
941 main.case( "Replay events from log file" )
942 main.step( "Replay events from log file" )
943 main.caseResult = main.TRUE
944 try:
945 f = open( main.params[ 'CASE80' ][ 'filePath' ], 'r' )
946 for line in f.readlines():
947 if 'CHOTestMonkey' in line and 'Event recorded' in line:
948 line = line.split()
949 eventIndex = int( line[ 9 ] )
950 eventName = line[ 10 ]
951 args = line[ 11: ]
952 assert eventName.startswith( 'CHECK' )\
Jon Hall2bb3e212017-05-24 17:07:25 -0700953 or eventName.startswith( 'NETWORK' )\
954 or eventName.startswith( 'APP' )\
955 or eventName.startswith( 'ONOS' )
You Wang52163202016-07-14 16:37:15 -0700956 if main.params[ 'CASE80' ][ 'skipChecks' ] == 'on' and eventName.startswith( 'CHECK' ):
957 continue
958 with main.eventScheduler.idleCondition:
959 while not main.eventScheduler.isIdle():
960 main.eventScheduler.idleCondition.wait()
961 main.eventGenerator.triggerEvent( eventIndex, EventScheduleMethod().RUN_BLOCK, *args )
962 time.sleep( float( main.params[ 'CASE80' ][ 'sleepTime' ] ) )
963 except Exception as e:
You Wang9fc5ce42019-01-23 15:10:08 -0800964 main.log.error( "Uncaught exception: {}".format( e ) )
You Wang52163202016-07-14 16:37:15 -0700965 utilities.assert_equals( expect=main.TRUE,
966 actual=main.caseResult,
967 onpass="Replay from log file passed",
968 onfail="Replay from log file failed" )
969
You Wangdb927a52016-02-26 11:03:28 -0800970 def CASE90( self, main ):
971 """
972 Sleep for some time
973 """
974 import time
975 from tests.CHOTestMonkey.dependencies.events.Event import EventType
976 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
977
978 main.log.report( "Sleep for some time" )
979 main.log.report( "__________________________________________________" )
980 main.case( "Sleep for some time" )
981 main.step( "Sleep for some time" )
982 main.caseResult = main.TRUE
983 sleepSec = int( main.params[ 'CASE90' ][ 'sleepSec' ] )
984 main.eventGenerator.triggerEvent( EventType().TEST_SLEEP, EventScheduleMethod().RUN_BLOCK, sleepSec )
985 with main.eventScheduler.idleCondition:
986 while not main.eventScheduler.isIdle():
987 main.eventScheduler.idleCondition.wait()
988 utilities.assert_equals( expect=main.TRUE,
989 actual=main.caseResult,
990 onpass="Sleep test passed",
991 onfail="Sleep test failed" )
992 time.sleep( main.caseSleep )
993
994 def CASE100( self, main ):
995 """
996 Do something else?
997 """
998 import time
999
1000 main.log.report( "Do something else?" )
1001 main.log.report( "__________________________________________________" )
1002 main.case( "..." )
1003
1004 main.step( "Wait until the test stops" )
1005
1006 main.caseResult = main.TRUE
1007 utilities.assert_equals( expect=main.TRUE,
1008 actual=main.caseResult,
1009 onpass="Test PASS",
1010 onfail="Test FAIL" )
1011
1012 testDuration = int( main.params[ 'TEST' ][ 'testDuration' ] )
1013 time.sleep( testDuration )