blob: 0883484ee259ad729a2a6c6df9f9efc858a23faf [file] [log] [blame]
Jon Hall85794ff2015-07-08 14:12:30 -07001"""
2Description: This test is to determine if a single
3 instance ONOS 'cluster' can handle a restart
4
5List of test cases:
6CASE1: Compile ONOS and push it to the test machines
7CASE2: Assign devices to controllers
8CASE21: Assign mastership to controllers
9CASE3: Assign intents
10CASE4: Ping across added host intents
11CASE5: Reading state of ONOS
12CASE6: The Failure case.
13CASE7: Check state after control plane failure
14CASE8: Compare topo
15CASE9: Link s3-s28 down
16CASE10: Link s3-s28 up
17CASE11: Switch down
18CASE12: Switch up
19CASE13: Clean up
20CASE14: start election app on all onos nodes
21CASE15: Check that Leadership Election is still functional
22CASE16: Install Distributed Primitives app
23CASE17: Check for basic functionality with distributed primitives
24"""
25
26
27class HAsingleInstanceRestart:
28
29 def __init__( self ):
30 self.default = ''
31
32 def CASE1( self, main ):
33 """
34 CASE1 is to compile ONOS and push it to the test machines
35
36 Startup sequence:
37 cell <name>
38 onos-verify-cell
39 NOTE: temporary - onos-remove-raft-logs
40 onos-uninstall
41 start mininet
42 git pull
43 mvn clean install
44 onos-package
45 onos-install -f
46 onos-wait-for-start
47 start cli sessions
48 start tcpdump
49 """
Jon Halle1a3b752015-07-22 13:02:46 -070050 import imp
Jon Hall85794ff2015-07-08 14:12:30 -070051 main.log.info( "ONOS Single node cluster restart " +
52 "HA test - initialization" )
53 main.case( "Setting up test environment" )
Jon Hall783bbf92015-07-23 14:33:19 -070054 main.caseExplanation = "Setup the test environment including " +\
Jon Hall85794ff2015-07-08 14:12:30 -070055 "installing ONOS, starting Mininet and ONOS" +\
56 "cli sessions."
57 # TODO: save all the timers and output them for plotting
58
59 # load some variables from the params file
60 PULLCODE = False
61 if main.params[ 'Git' ] == 'True':
62 PULLCODE = True
63 gitBranch = main.params[ 'branch' ]
64 cellName = main.params[ 'ENV' ][ 'cellName' ]
65
Jon Halle1a3b752015-07-22 13:02:46 -070066 main.numCtrls = int( main.params[ 'num_controllers' ] )
Jon Hall5cf14d52015-07-16 12:15:19 -070067 if main.ONOSbench.maxNodes:
Jon Halle1a3b752015-07-22 13:02:46 -070068 if main.ONOSbench.maxNodes < main.numCtrls:
69 main.numCtrls = int( main.ONOSbench.maxNodes )
Jon Hall85794ff2015-07-08 14:12:30 -070070
Jon Halle1a3b752015-07-22 13:02:46 -070071 try:
72 fileName = "Counters"
73 path = main.params[ 'imports' ][ 'path' ]
74 main.Counters = imp.load_source( fileName,
75 path + fileName + ".py" )
76 except Exception as e:
77 main.log.exception( e )
78 main.cleanup()
79 main.exit()
80
81 main.CLIs = []
82 main.nodes = []
Jon Hall5cf14d52015-07-16 12:15:19 -070083 ipList = []
84 for i in range( 1, int( main.ONOSbench.maxNodes ) + 1 ):
85 try:
Jon Halle1a3b752015-07-22 13:02:46 -070086 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
87 main.nodes.append( getattr( main, 'ONOS' + str( i ) ) )
88 ipList.append( main.nodes[ -1 ].ip_address )
Jon Hall5cf14d52015-07-16 12:15:19 -070089 except AttributeError:
90 break
Jon Hall85794ff2015-07-08 14:12:30 -070091
Jon Hall5cf14d52015-07-16 12:15:19 -070092 main.step( "Create cell file" )
93 cellAppString = main.params[ 'ENV' ][ 'appString' ]
94 main.ONOSbench.createCellFile( main.ONOSbench.ip_address, cellName,
95 main.Mininet1.ip_address,
96 cellAppString, ipList )
Jon Hall85794ff2015-07-08 14:12:30 -070097 main.step( "Applying cell variable to environment" )
98 cellResult = main.ONOSbench.setCell( cellName )
99 verifyResult = main.ONOSbench.verifyCell()
100
101 # FIXME:this is short term fix
102 main.log.info( "Removing raft logs" )
103 main.ONOSbench.onosRemoveRaftLogs()
104
105 main.log.info( "Uninstalling ONOS" )
Jon Halle1a3b752015-07-22 13:02:46 -0700106 for node in main.nodes:
Jon Hall85794ff2015-07-08 14:12:30 -0700107 main.ONOSbench.onosUninstall( node.ip_address )
108
109 # Make sure ONOS is DEAD
110 main.log.info( "Killing any ONOS processes" )
111 killResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -0700112 for node in main.nodes:
Jon Hall85794ff2015-07-08 14:12:30 -0700113 killed = main.ONOSbench.onosKill( node.ip_address )
114 killResults = killResults and killed
115
116 cleanInstallResult = main.TRUE
117 gitPullResult = main.TRUE
118
119 main.step( "Starting Mininet" )
120 # scp topo file to mininet
121 # TODO: move to params?
122 topoName = "obelisk.py"
123 filePath = main.ONOSbench.home + "/tools/test/topos/"
kelvin-onlabd9e23de2015-08-06 10:34:44 -0700124 main.ONOSbench.scp( main.Mininet1,
125 filePath + topoName,
126 main.Mininet1.home,
127 direction="to" )
Jon Hall85794ff2015-07-08 14:12:30 -0700128 mnResult = main.Mininet1.startNet( )
129 utilities.assert_equals( expect=main.TRUE, actual=mnResult,
130 onpass="Mininet Started",
131 onfail="Error starting Mininet" )
132
133 main.step( "Git checkout and pull " + gitBranch )
134 if PULLCODE:
135 main.ONOSbench.gitCheckout( gitBranch )
136 gitPullResult = main.ONOSbench.gitPull()
137 # values of 1 or 3 are good
138 utilities.assert_lesser( expect=0, actual=gitPullResult,
139 onpass="Git pull successful",
140 onfail="Git pull failed" )
141 main.ONOSbench.getVersion( report=True )
142
143 main.step( "Using mvn clean install" )
144 cleanInstallResult = main.TRUE
145 if PULLCODE and gitPullResult == main.TRUE:
146 cleanInstallResult = main.ONOSbench.cleanInstall()
147 else:
148 main.log.warn( "Did not pull new code so skipping mvn " +
149 "clean install" )
150 utilities.assert_equals( expect=main.TRUE,
151 actual=cleanInstallResult,
152 onpass="MCI successful",
153 onfail="MCI failed" )
154 # GRAPHS
155 # NOTE: important params here:
156 # job = name of Jenkins job
157 # Plot Name = Plot-HA, only can be used if multiple plots
158 # index = The number of the graph under plot name
Jon Hall5cf14d52015-07-16 12:15:19 -0700159 job = "HAsingleInstanceRestart"
Jon Hall85794ff2015-07-08 14:12:30 -0700160 plotName = "Plot-HA"
161 graphs = '<ac:structured-macro ac:name="html">\n'
162 graphs += '<ac:plain-text-body><![CDATA[\n'
163 graphs += '<iframe src="https://onos-jenkins.onlab.us/job/' + job +\
164 '/plot/' + plotName + '/getPlot?index=0' +\
165 '&width=500&height=300"' +\
166 'noborder="0" width="500" height="300" scrolling="yes" ' +\
167 'seamless="seamless"></iframe>\n'
168 graphs += ']]></ac:plain-text-body>\n'
169 graphs += '</ac:structured-macro>\n'
170 main.log.wiki(graphs)
171
Jon Halle1a3b752015-07-22 13:02:46 -0700172 main.CLIs = []
173 main.nodes = []
Jon Hall5cf14d52015-07-16 12:15:19 -0700174 ipList = []
Jon Halle1a3b752015-07-22 13:02:46 -0700175 for i in range( 1, main.numCtrls + 1 ):
176 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
177 main.nodes.append( getattr( main, 'ONOS' + str( i ) ) )
178 ipList.append( main.nodes[ -1 ].ip_address )
Jon Hall5cf14d52015-07-16 12:15:19 -0700179
180 main.ONOSbench.createCellFile( main.ONOSbench.ip_address, "SingleHA",
181 main.Mininet1.ip_address,
182 cellAppString, ipList[ 0 ] )
Jon Hall85794ff2015-07-08 14:12:30 -0700183 cellResult = main.ONOSbench.setCell( "SingleHA" )
184 verifyResult = main.ONOSbench.verifyCell()
185 main.step( "Creating ONOS package" )
186 packageResult = main.ONOSbench.onosPackage()
187 utilities.assert_equals( expect=main.TRUE, actual=packageResult,
188 onpass="ONOS package successful",
189 onfail="ONOS package failed" )
190
191 main.step( "Installing ONOS package" )
192 onosInstallResult = main.ONOSbench.onosInstall(
Jon Halle1a3b752015-07-22 13:02:46 -0700193 options="-f", node=main.nodes[0].ip_address )
Jon Hall85794ff2015-07-08 14:12:30 -0700194 utilities.assert_equals( expect=main.TRUE, actual=onosInstallResult,
195 onpass="ONOS install successful",
196 onfail="ONOS install failed" )
197
198 main.step( "Checking if ONOS is up yet" )
199 for i in range( 2 ):
Jon Halle1a3b752015-07-22 13:02:46 -0700200 onos1Isup = main.ONOSbench.isup( main.nodes[0].ip_address )
Jon Hall85794ff2015-07-08 14:12:30 -0700201 if onos1Isup:
202 break
203 utilities.assert_equals( expect=main.TRUE, actual=onos1Isup,
204 onpass="ONOS startup successful",
205 onfail="ONOS startup failed" )
206
207 main.log.step( "Starting ONOS CLI sessions" )
Jon Halle1a3b752015-07-22 13:02:46 -0700208 cliResults = main.ONOScli1.startOnosCli( main.nodes[0].ip_address )
Jon Hall85794ff2015-07-08 14:12:30 -0700209 utilities.assert_equals( expect=main.TRUE, actual=cliResults,
210 onpass="ONOS cli startup successful",
211 onfail="ONOS cli startup failed" )
212
213 if main.params[ 'tcpdump' ].lower() == "true":
214 main.step( "Start Packet Capture MN" )
215 main.Mininet2.startTcpdump(
216 str( main.params[ 'MNtcpdump' ][ 'folder' ] ) + str( main.TEST )
217 + "-MN.pcap",
218 intf=main.params[ 'MNtcpdump' ][ 'intf' ],
219 port=main.params[ 'MNtcpdump' ][ 'port' ] )
220
221 main.step( "App Ids check" )
222 appCheck = main.ONOScli1.appToIDCheck()
223 if appCheck != main.TRUE:
Jon Halle1a3b752015-07-22 13:02:46 -0700224 main.log.warn( main.CLIs[0].apps() )
225 main.log.warn( main.CLIs[0].appIDs() )
Jon Hall85794ff2015-07-08 14:12:30 -0700226 utilities.assert_equals( expect=main.TRUE, actual=appCheck,
227 onpass="App Ids seem to be correct",
228 onfail="Something is wrong with app Ids" )
229
230 if cliResults == main.FALSE:
231 main.log.error( "Failed to start ONOS, stopping test" )
232 main.cleanup()
233 main.exit()
234
235 def CASE2( self, main ):
236 """
237 Assign devices to controllers
238 """
239 import re
Jon Halle1a3b752015-07-22 13:02:46 -0700240 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall85794ff2015-07-08 14:12:30 -0700241 assert main, "main not defined"
242 assert utilities.assert_equals, "utilities.assert_equals not defined"
243
244 main.case( "Assigning devices to controllers" )
Jon Hall783bbf92015-07-23 14:33:19 -0700245 main.caseExplanation = "Assign switches to ONOS using 'ovs-vsctl' " +\
Jon Hall85794ff2015-07-08 14:12:30 -0700246 "and check that an ONOS node becomes the " +\
247 "master of the device."
248 main.step( "Assign switches to controllers" )
249
250 ipList = []
Jon Halle1a3b752015-07-22 13:02:46 -0700251 for i in range( main.numCtrls ):
252 ipList.append( main.nodes[ i ].ip_address )
Jon Hall85794ff2015-07-08 14:12:30 -0700253 swList = []
254 for i in range( 1, 29 ):
255 swList.append( "s" + str( i ) )
256 main.Mininet1.assignSwController( sw=swList, ip=ipList )
257
258 mastershipCheck = main.TRUE
259 for i in range( 1, 29 ):
260 response = main.Mininet1.getSwController( "s" + str( i ) )
261 try:
262 main.log.info( str( response ) )
263 except Exception:
264 main.log.info( repr( response ) )
Jon Halle1a3b752015-07-22 13:02:46 -0700265 if re.search( "tcp:" + main.nodes[0].ip_address, response ):
Jon Hall85794ff2015-07-08 14:12:30 -0700266 mastershipCheck = mastershipCheck and main.TRUE
267 else:
268 mastershipCheck = main.FALSE
269 if mastershipCheck == main.TRUE:
270 main.log.info( "Switch mastership assigned correctly" )
271 utilities.assert_equals(
272 expect=main.TRUE,
273 actual=mastershipCheck,
274 onpass="Switch mastership assigned correctly",
275 onfail="Switches not assigned correctly to controllers" )
276
277 def CASE21( self, main ):
278 """
279 Assign mastership to controllers
280 """
Jon Halle1a3b752015-07-22 13:02:46 -0700281 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall85794ff2015-07-08 14:12:30 -0700282 assert main, "main not defined"
283 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -0700284 assert main.CLIs, "main.CLIs not defined"
285 assert main.nodes, "main.nodes not defined"
Jon Hall85794ff2015-07-08 14:12:30 -0700286
287 main.case( "Assigning Controller roles for switches" )
Jon Hall783bbf92015-07-23 14:33:19 -0700288 main.caseExplanation = "Check that ONOS is connected to each " +\
Jon Hall85794ff2015-07-08 14:12:30 -0700289 "device. Then manually assign" +\
290 " mastership to specific ONOS nodes using" +\
291 " 'device-role'"
292 main.step( "Assign mastership of switches to specific controllers" )
293 roleCall = main.TRUE
294 roleCheck = main.TRUE
295 try:
296 for i in range( 1, 29 ): # switches 1 through 28
Jon Halle1a3b752015-07-22 13:02:46 -0700297 ip = main.nodes[ 0 ].ip_address # ONOS1
Jon Hall85794ff2015-07-08 14:12:30 -0700298 # set up correct variables:
299 if i == 1:
300 deviceId = main.ONOScli1.getDevice( "1000" ).get( 'id' )
301 elif i == 2:
302 deviceId = main.ONOScli1.getDevice( "2000" ).get( 'id' )
303 elif i == 3:
304 deviceId = main.ONOScli1.getDevice( "3000" ).get( 'id' )
305 elif i == 4:
306 deviceId = main.ONOScli1.getDevice( "3004" ).get( 'id' )
307 elif i == 5:
308 deviceId = main.ONOScli1.getDevice( "5000" ).get( 'id' )
309 elif i == 6:
310 deviceId = main.ONOScli1.getDevice( "6000" ).get( 'id' )
311 elif i == 7:
312 deviceId = main.ONOScli1.getDevice( "6007" ).get( 'id' )
313 elif i >= 8 and i <= 17:
314 dpid = '3' + str( i ).zfill( 3 )
315 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
316 elif i >= 18 and i <= 27:
317 dpid = '6' + str( i ).zfill( 3 )
318 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
319 elif i == 28:
320 deviceId = main.ONOScli1.getDevice( "2800" ).get( 'id' )
321 else:
322 main.log.error( "You didn't write an else statement for " +
323 "switch s" + str( i ) )
324 # Assign switch
325 assert deviceId, "No device id for s" + str( i ) + " in ONOS"
326 # TODO: make this controller dynamic
327 roleCall = roleCall and main.ONOScli1.deviceRole( deviceId,
328 ip )
329 # Check assignment
330 master = main.ONOScli1.getRole( deviceId ).get( 'master' )
331 if ip in master:
332 roleCheck = roleCheck and main.TRUE
333 else:
334 roleCheck = roleCheck and main.FALSE
335 main.log.error( "Error, controller " + ip + " is not" +
336 " master " + "of device " +
337 str( deviceId ) + ". Master is " +
338 repr( master ) + "." )
339 except ( AttributeError, AssertionError ):
340 main.log.exception( "Something is wrong with ONOS device view" )
341 main.log.info( main.ONOScli1.devices() )
342 utilities.assert_equals(
343 expect=main.TRUE,
344 actual=roleCall,
345 onpass="Re-assigned switch mastership to designated controller",
346 onfail="Something wrong with deviceRole calls" )
347
348 main.step( "Check mastership was correctly assigned" )
349 utilities.assert_equals(
350 expect=main.TRUE,
351 actual=roleCheck,
352 onpass="Switches were successfully reassigned to designated " +
353 "controller",
354 onfail="Switches were not successfully reassigned" )
355
356 def CASE3( self, main ):
357 """
358 Assign intents
359 """
360 import time
361 import json
Jon Halle1a3b752015-07-22 13:02:46 -0700362 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall85794ff2015-07-08 14:12:30 -0700363 assert main, "main not defined"
364 assert utilities.assert_equals, "utilities.assert_equals not defined"
365 # NOTE: we must reinstall intents until we have a persistant intent
366 # datastore!
367 main.case( "Adding host Intents" )
Jon Hall783bbf92015-07-23 14:33:19 -0700368 main.caseExplanation = "Discover hosts by using pingall then " +\
Jon Hall85794ff2015-07-08 14:12:30 -0700369 "assign predetermined host-to-host intents." +\
370 " After installation, check that the intent" +\
371 " is distributed to all nodes and the state" +\
372 " is INSTALLED"
373
374 # install onos-app-fwd
375 main.step( "Install reactive forwarding app" )
Jon Halle1a3b752015-07-22 13:02:46 -0700376 installResults = main.CLIs[0].activateApp( "org.onosproject.fwd" )
Jon Hall85794ff2015-07-08 14:12:30 -0700377 utilities.assert_equals( expect=main.TRUE, actual=installResults,
378 onpass="Install fwd successful",
379 onfail="Install fwd failed" )
380
381 main.step( "Check app ids" )
382 appCheck = main.ONOScli1.appToIDCheck()
383 if appCheck != main.TRUE:
Jon Halle1a3b752015-07-22 13:02:46 -0700384 main.log.warn( main.CLIs[0].apps() )
385 main.log.warn( main.CLIs[0].appIDs() )
Jon Hall85794ff2015-07-08 14:12:30 -0700386 utilities.assert_equals( expect=main.TRUE, actual=appCheck,
387 onpass="App Ids seem to be correct",
388 onfail="Something is wrong with app Ids" )
389
390 main.step( "Discovering Hosts( Via pingall for now )" )
391 # FIXME: Once we have a host discovery mechanism, use that instead
392 # REACTIVE FWD test
393 pingResult = main.FALSE
Jon Hall96091e62015-09-21 17:34:17 -0700394 passMsg = "Reactive Pingall test passed"
395 time1 = time.time()
396 pingResult = main.Mininet1.pingall()
397 time2 = time.time()
398 if not pingResult:
399 main.log.warn("First pingall failed. Trying again...")
Jon Hall85794ff2015-07-08 14:12:30 -0700400 pingResult = main.Mininet1.pingall()
Jon Hall96091e62015-09-21 17:34:17 -0700401 passMsg += " on the second try"
402 utilities.assert_equals(
403 expect=main.TRUE,
404 actual=pingResult,
405 onpass= passMsg,
406 onfail="Reactive Pingall failed, " +
407 "one or more ping pairs failed" )
408 main.log.info( "Time for pingall: %2f seconds" %
409 ( time2 - time1 ) )
Jon Hall85794ff2015-07-08 14:12:30 -0700410 # timeout for fwd flows
411 time.sleep( 11 )
412 # uninstall onos-app-fwd
413 main.step( "Uninstall reactive forwarding app" )
Jon Halle1a3b752015-07-22 13:02:46 -0700414 uninstallResult = main.CLIs[0].deactivateApp( "org.onosproject.fwd" )
Jon Hall85794ff2015-07-08 14:12:30 -0700415 utilities.assert_equals( expect=main.TRUE, actual=uninstallResult,
416 onpass="Uninstall fwd successful",
417 onfail="Uninstall fwd failed" )
418
419 main.step( "Check app ids" )
420 appCheck2 = main.ONOScli1.appToIDCheck()
421 if appCheck2 != main.TRUE:
Jon Halle1a3b752015-07-22 13:02:46 -0700422 main.log.warn( main.CLIs[0].apps() )
423 main.log.warn( main.CLIs[0].appIDs() )
Jon Hall85794ff2015-07-08 14:12:30 -0700424 utilities.assert_equals( expect=main.TRUE, actual=appCheck2,
425 onpass="App Ids seem to be correct",
426 onfail="Something is wrong with app Ids" )
427
428 main.step( "Add host intents via cli" )
429 intentIds = []
430 # TODO: move the host numbers to params
431 # Maybe look at all the paths we ping?
432 intentAddResult = True
433 hostResult = main.TRUE
434 for i in range( 8, 18 ):
435 main.log.info( "Adding host intent between h" + str( i ) +
436 " and h" + str( i + 10 ) )
437 host1 = "00:00:00:00:00:" + \
438 str( hex( i )[ 2: ] ).zfill( 2 ).upper()
439 host2 = "00:00:00:00:00:" + \
440 str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper()
441 # NOTE: getHost can return None
442 host1Dict = main.ONOScli1.getHost( host1 )
443 host2Dict = main.ONOScli1.getHost( host2 )
444 host1Id = None
445 host2Id = None
446 if host1Dict and host2Dict:
447 host1Id = host1Dict.get( 'id', None )
448 host2Id = host2Dict.get( 'id', None )
449 if host1Id and host2Id:
450 tmpId = main.ONOScli1.addHostIntent( host1Id, host2Id )
451 if tmpId:
452 main.log.info( "Added intent with id: " + tmpId )
453 intentIds.append( tmpId )
454 else:
455 main.log.error( "addHostIntent returned: " +
456 repr( tmpId ) )
457 else:
458 main.log.error( "Error, getHost() failed for h" + str( i ) +
459 " and/or h" + str( i + 10 ) )
460 hosts = main.ONOScli1.hosts()
461 main.log.warn( "Hosts output: " )
462 try:
463 main.log.warn( json.dumps( json.loads( hosts ),
464 sort_keys=True,
465 indent=4,
466 separators=( ',', ': ' ) ) )
467 except ( ValueError, TypeError ):
468 main.log.warn( repr( hosts ) )
469 hostResult = main.FALSE
470 utilities.assert_equals( expect=main.TRUE, actual=hostResult,
471 onpass="Found a host id for each host",
472 onfail="Error looking up host ids" )
473
474 intentStart = time.time()
475 onosIds = main.ONOScli1.getAllIntentsId()
476 main.log.info( "Submitted intents: " + str( intentIds ) )
477 main.log.info( "Intents in ONOS: " + str( onosIds ) )
478 for intent in intentIds:
479 if intent in onosIds:
480 pass # intent submitted is in onos
481 else:
482 intentAddResult = False
483 if intentAddResult:
484 intentStop = time.time()
485 else:
486 intentStop = None
487 # Print the intent states
488 intents = main.ONOScli1.intents()
489 intentStates = []
490 installedCheck = True
491 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
492 count = 0
493 try:
494 for intent in json.loads( intents ):
495 state = intent.get( 'state', None )
496 if "INSTALLED" not in state:
497 installedCheck = False
498 intentId = intent.get( 'id', None )
499 intentStates.append( ( intentId, state ) )
500 except ( ValueError, TypeError ):
501 main.log.exception( "Error parsing intents" )
502 # add submitted intents not in the store
503 tmplist = [ i for i, s in intentStates ]
504 missingIntents = False
505 for i in intentIds:
506 if i not in tmplist:
507 intentStates.append( ( i, " - " ) )
508 missingIntents = True
509 intentStates.sort()
510 for i, s in intentStates:
511 count += 1
512 main.log.info( "%-6s%-15s%-15s" %
513 ( str( count ), str( i ), str( s ) ) )
514 leaders = main.ONOScli1.leaders()
515 try:
516 missing = False
517 if leaders:
518 parsedLeaders = json.loads( leaders )
519 main.log.warn( json.dumps( parsedLeaders,
520 sort_keys=True,
521 indent=4,
522 separators=( ',', ': ' ) ) )
523 # check for all intent partitions
524 topics = []
525 for i in range( 14 ):
526 topics.append( "intent-partition-" + str( i ) )
527 main.log.debug( topics )
528 ONOStopics = [ j['topic'] for j in parsedLeaders ]
529 for topic in topics:
530 if topic not in ONOStopics:
531 main.log.error( "Error: " + topic +
532 " not in leaders" )
533 missing = True
534 else:
535 main.log.error( "leaders() returned None" )
536 except ( ValueError, TypeError ):
537 main.log.exception( "Error parsing leaders" )
538 main.log.error( repr( leaders ) )
539 # Check all nodes
540 if missing:
541 response = main.ONOScli1.leaders( jsonFormat=False)
542 main.log.warn( "ONOS1 leaders output: \n" +
543 str( response ) )
544
545 partitions = main.ONOScli1.partitions()
546 try:
547 if partitions :
548 parsedPartitions = json.loads( partitions )
549 main.log.warn( json.dumps( parsedPartitions,
550 sort_keys=True,
551 indent=4,
552 separators=( ',', ': ' ) ) )
553 # TODO check for a leader in all paritions
554 # TODO check for consistency among nodes
555 else:
556 main.log.error( "partitions() returned None" )
557 except ( ValueError, TypeError ):
558 main.log.exception( "Error parsing partitions" )
559 main.log.error( repr( partitions ) )
560 pendingMap = main.ONOScli1.pendingMap()
561 try:
562 if pendingMap :
563 parsedPending = json.loads( pendingMap )
564 main.log.warn( json.dumps( parsedPending,
565 sort_keys=True,
566 indent=4,
567 separators=( ',', ': ' ) ) )
568 # TODO check something here?
569 else:
570 main.log.error( "pendingMap() returned None" )
571 except ( ValueError, TypeError ):
572 main.log.exception( "Error parsing pending map" )
573 main.log.error( repr( pendingMap ) )
574
575 intentAddResult = bool( intentAddResult and not missingIntents and
576 installedCheck )
577 if not intentAddResult:
578 main.log.error( "Error in pushing host intents to ONOS" )
579
580 main.step( "Intent Anti-Entropy dispersion" )
581 for i in range(100):
582 correct = True
583 main.log.info( "Submitted intents: " + str( sorted( intentIds ) ) )
Jon Halle1a3b752015-07-22 13:02:46 -0700584 for cli in main.CLIs:
Jon Hall85794ff2015-07-08 14:12:30 -0700585 onosIds = []
586 ids = cli.getAllIntentsId()
587 onosIds.append( ids )
588 main.log.debug( "Intents in " + cli.name + ": " +
589 str( sorted( onosIds ) ) )
590 if sorted( ids ) != sorted( intentIds ):
591 main.log.warn( "Set of intent IDs doesn't match" )
592 correct = False
593 break
594 else:
595 intents = json.loads( cli.intents() )
596 for intent in intents:
597 if intent[ 'state' ] != "INSTALLED":
598 main.log.warn( "Intent " + intent[ 'id' ] +
599 " is " + intent[ 'state' ] )
600 correct = False
601 break
602 if correct:
603 break
604 else:
605 time.sleep(1)
606 if not intentStop:
607 intentStop = time.time()
608 global gossipTime
609 gossipTime = intentStop - intentStart
610 main.log.info( "It took about " + str( gossipTime ) +
611 " seconds for all intents to appear in each node" )
Jon Hallb3ed8ed2015-10-28 16:43:55 -0700612 gossipPeriod = int( main.params['timers']['gossip'] )
613 maxGossipTime = gossipPeriod * len( main.nodes )
Jon Hall85794ff2015-07-08 14:12:30 -0700614 utilities.assert_greater_equals(
Jon Hallb3ed8ed2015-10-28 16:43:55 -0700615 expect=maxGossipTime, actual=gossipTime,
Jon Hall85794ff2015-07-08 14:12:30 -0700616 onpass="ECM anti-entropy for intents worked within " +
617 "expected time",
Jon Hallb3ed8ed2015-10-28 16:43:55 -0700618 onfail="Intent ECM anti-entropy took too long. " +
619 "Expected time:{}, Actual time:{}".format( maxGossipTime,
620 gossipTime ) )
621 if gossipTime <= maxGossipTime:
Jon Hall85794ff2015-07-08 14:12:30 -0700622 intentAddResult = True
623
624 if not intentAddResult or "key" in pendingMap:
625 import time
626 installedCheck = True
627 main.log.info( "Sleeping 60 seconds to see if intents are found" )
628 time.sleep( 60 )
629 onosIds = main.ONOScli1.getAllIntentsId()
630 main.log.info( "Submitted intents: " + str( intentIds ) )
631 main.log.info( "Intents in ONOS: " + str( onosIds ) )
632 # Print the intent states
633 intents = main.ONOScli1.intents()
634 intentStates = []
635 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
636 count = 0
637 try:
638 for intent in json.loads( intents ):
639 # Iter through intents of a node
640 state = intent.get( 'state', None )
641 if "INSTALLED" not in state:
642 installedCheck = False
643 intentId = intent.get( 'id', None )
644 intentStates.append( ( intentId, state ) )
645 except ( ValueError, TypeError ):
646 main.log.exception( "Error parsing intents" )
647 # add submitted intents not in the store
648 tmplist = [ i for i, s in intentStates ]
649 for i in intentIds:
650 if i not in tmplist:
651 intentStates.append( ( i, " - " ) )
652 intentStates.sort()
653 for i, s in intentStates:
654 count += 1
655 main.log.info( "%-6s%-15s%-15s" %
656 ( str( count ), str( i ), str( s ) ) )
657 leaders = main.ONOScli1.leaders()
658 try:
659 missing = False
660 if leaders:
661 parsedLeaders = json.loads( leaders )
662 main.log.warn( json.dumps( parsedLeaders,
663 sort_keys=True,
664 indent=4,
665 separators=( ',', ': ' ) ) )
666 # check for all intent partitions
667 # check for election
668 topics = []
669 for i in range( 14 ):
670 topics.append( "intent-partition-" + str( i ) )
671 # FIXME: this should only be after we start the app
672 topics.append( "org.onosproject.election" )
673 main.log.debug( topics )
674 ONOStopics = [ j['topic'] for j in parsedLeaders ]
675 for topic in topics:
676 if topic not in ONOStopics:
677 main.log.error( "Error: " + topic +
678 " not in leaders" )
679 missing = True
680 else:
681 main.log.error( "leaders() returned None" )
682 except ( ValueError, TypeError ):
683 main.log.exception( "Error parsing leaders" )
684 main.log.error( repr( leaders ) )
685 # Check all nodes
686 if missing:
687 response = main.ONOScli1.leaders( jsonFormat=False)
688 main.log.warn( "ONOS1 leaders output: \n" +
689 str( response ) )
690 partitions = main.ONOScli1.partitions()
691 try:
692 if partitions :
693 parsedPartitions = json.loads( partitions )
694 main.log.warn( json.dumps( parsedPartitions,
695 sort_keys=True,
696 indent=4,
697 separators=( ',', ': ' ) ) )
698 # TODO check for a leader in all paritions
699 # TODO check for consistency among nodes
700 else:
701 main.log.error( "partitions() returned None" )
702 except ( ValueError, TypeError ):
703 main.log.exception( "Error parsing partitions" )
704 main.log.error( repr( partitions ) )
705 pendingMap = main.ONOScli1.pendingMap()
706 try:
707 if pendingMap :
708 parsedPending = json.loads( pendingMap )
709 main.log.warn( json.dumps( parsedPending,
710 sort_keys=True,
711 indent=4,
712 separators=( ',', ': ' ) ) )
713 # TODO check something here?
714 else:
715 main.log.error( "pendingMap() returned None" )
716 except ( ValueError, TypeError ):
717 main.log.exception( "Error parsing pending map" )
718 main.log.error( repr( pendingMap ) )
719
720 def CASE4( self, main ):
721 """
722 Ping across added host intents
723 """
724 import json
725 import time
Jon Halle1a3b752015-07-22 13:02:46 -0700726 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall85794ff2015-07-08 14:12:30 -0700727 assert main, "main not defined"
728 assert utilities.assert_equals, "utilities.assert_equals not defined"
729 main.case( "Verify connectivity by sendind traffic across Intents" )
Jon Hall783bbf92015-07-23 14:33:19 -0700730 main.caseExplanation = "Ping across added host intents to check " +\
Jon Hall85794ff2015-07-08 14:12:30 -0700731 "functionality and check the state of " +\
732 "the intent"
733 main.step( "Ping across added host intents" )
734 PingResult = main.TRUE
735 for i in range( 8, 18 ):
736 ping = main.Mininet1.pingHost( src="h" + str( i ),
737 target="h" + str( i + 10 ) )
738 PingResult = PingResult and ping
739 if ping == main.FALSE:
740 main.log.warn( "Ping failed between h" + str( i ) +
741 " and h" + str( i + 10 ) )
742 elif ping == main.TRUE:
743 main.log.info( "Ping test passed!" )
744 # Don't set PingResult or you'd override failures
745 if PingResult == main.FALSE:
746 main.log.error(
747 "Intents have not been installed correctly, pings failed." )
748 # TODO: pretty print
749 main.log.warn( "ONOS1 intents: " )
750 try:
751 tmpIntents = main.ONOScli1.intents()
752 main.log.warn( json.dumps( json.loads( tmpIntents ),
753 sort_keys=True,
754 indent=4,
755 separators=( ',', ': ' ) ) )
756 except ( ValueError, TypeError ):
757 main.log.warn( repr( tmpIntents ) )
758 utilities.assert_equals(
759 expect=main.TRUE,
760 actual=PingResult,
761 onpass="Intents have been installed correctly and pings work",
762 onfail="Intents have not been installed correctly, pings failed." )
763
764 main.step( "Check Intent state" )
765 installedCheck = True
766 # Print the intent states
767 intents = main.ONOScli1.intents()
768 intentStates = []
769 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
770 count = 0
771 # Iter through intents of a node
772 try:
773 for intent in json.loads( intents ):
774 state = intent.get( 'state', None )
775 if "INSTALLED" not in state:
776 installedCheck = False
777 intentId = intent.get( 'id', None )
778 intentStates.append( ( intentId, state ) )
779 except ( ValueError, TypeError ):
780 main.log.exception( "Error parsing intents." )
781 # Print states
782 intentStates.sort()
783 for i, s in intentStates:
784 count += 1
785 main.log.info( "%-6s%-15s%-15s" %
786 ( str( count ), str( i ), str( s ) ) )
787 utilities.assert_equals( expect=True, actual=installedCheck,
788 onpass="Intents are all INSTALLED",
789 onfail="Intents are not all in " +
790 "INSTALLED state" )
791
792 main.step( "Check leadership of topics" )
793 leaders = main.ONOScli1.leaders()
794 topicCheck = main.TRUE
795 try:
796 if leaders:
797 parsedLeaders = json.loads( leaders )
798 main.log.warn( json.dumps( parsedLeaders,
799 sort_keys=True,
800 indent=4,
801 separators=( ',', ': ' ) ) )
802 # check for all intent partitions
803 # check for election
804 # TODO: Look at Devices as topics now that it uses this system
805 topics = []
806 for i in range( 14 ):
807 topics.append( "intent-partition-" + str( i ) )
808 # FIXME: this should only be after we start the app
809 # FIXME: topics.append( "org.onosproject.election" )
810 # Print leaders output
811 main.log.debug( topics )
812 ONOStopics = [ j['topic'] for j in parsedLeaders ]
813 for topic in topics:
814 if topic not in ONOStopics:
815 main.log.error( "Error: " + topic +
816 " not in leaders" )
817 topicCheck = main.FALSE
818 else:
819 main.log.error( "leaders() returned None" )
820 topicCheck = main.FALSE
821 except ( ValueError, TypeError ):
822 topicCheck = main.FALSE
823 main.log.exception( "Error parsing leaders" )
824 main.log.error( repr( leaders ) )
825 # TODO: Check for a leader of these topics
826 utilities.assert_equals( expect=main.TRUE, actual=topicCheck,
827 onpass="intent Partitions is in leaders",
828 onfail="Some topics were lost " )
829 # Print partitions
830 partitions = main.ONOScli1.partitions()
831 try:
832 if partitions :
833 parsedPartitions = json.loads( partitions )
834 main.log.warn( json.dumps( parsedPartitions,
835 sort_keys=True,
836 indent=4,
837 separators=( ',', ': ' ) ) )
838 # TODO check for a leader in all paritions
839 # TODO check for consistency among nodes
840 else:
841 main.log.error( "partitions() returned None" )
842 except ( ValueError, TypeError ):
843 main.log.exception( "Error parsing partitions" )
844 main.log.error( repr( partitions ) )
845 # Print Pending Map
846 pendingMap = main.ONOScli1.pendingMap()
847 try:
848 if pendingMap :
849 parsedPending = json.loads( pendingMap )
850 main.log.warn( json.dumps( parsedPending,
851 sort_keys=True,
852 indent=4,
853 separators=( ',', ': ' ) ) )
854 # TODO check something here?
855 else:
856 main.log.error( "pendingMap() returned None" )
857 except ( ValueError, TypeError ):
858 main.log.exception( "Error parsing pending map" )
859 main.log.error( repr( pendingMap ) )
860
861 if not installedCheck:
862 main.log.info( "Waiting 60 seconds to see if the state of " +
863 "intents change" )
864 time.sleep( 60 )
865 # Print the intent states
866 intents = main.ONOScli1.intents()
867 intentStates = []
868 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
869 count = 0
870 # Iter through intents of a node
871 try:
872 for intent in json.loads( intents ):
873 state = intent.get( 'state', None )
874 if "INSTALLED" not in state:
875 installedCheck = False
876 intentId = intent.get( 'id', None )
877 intentStates.append( ( intentId, state ) )
878 except ( ValueError, TypeError ):
879 main.log.exception( "Error parsing intents." )
880 intentStates.sort()
881 for i, s in intentStates:
882 count += 1
883 main.log.info( "%-6s%-15s%-15s" %
884 ( str( count ), str( i ), str( s ) ) )
885 leaders = main.ONOScli1.leaders()
886 try:
887 missing = False
888 if leaders:
889 parsedLeaders = json.loads( leaders )
890 main.log.warn( json.dumps( parsedLeaders,
891 sort_keys=True,
892 indent=4,
893 separators=( ',', ': ' ) ) )
894 # check for all intent partitions
895 # check for election
896 topics = []
897 for i in range( 14 ):
898 topics.append( "intent-partition-" + str( i ) )
899 # FIXME: this should only be after we start the app
900 topics.append( "org.onosproject.election" )
901 main.log.debug( topics )
902 ONOStopics = [ j['topic'] for j in parsedLeaders ]
903 for topic in topics:
904 if topic not in ONOStopics:
905 main.log.error( "Error: " + topic +
906 " not in leaders" )
907 missing = True
908 else:
909 main.log.error( "leaders() returned None" )
910 except ( ValueError, TypeError ):
911 main.log.exception( "Error parsing leaders" )
912 main.log.error( repr( leaders ) )
913 if missing:
914 response = main.ONOScli1.leaders( jsonFormat=False)
915 main.log.warn( "ONOS1 leaders output: \n" +
916 str( response ) )
917 partitions = main.ONOScli1.partitions()
918 try:
919 if partitions :
920 parsedPartitions = json.loads( partitions )
921 main.log.warn( json.dumps( parsedPartitions,
922 sort_keys=True,
923 indent=4,
924 separators=( ',', ': ' ) ) )
925 # TODO check for a leader in all paritions
926 # TODO check for consistency among nodes
927 else:
928 main.log.error( "partitions() returned None" )
929 except ( ValueError, TypeError ):
930 main.log.exception( "Error parsing partitions" )
931 main.log.error( repr( partitions ) )
932 pendingMap = main.ONOScli1.pendingMap()
933 try:
934 if pendingMap :
935 parsedPending = json.loads( pendingMap )
936 main.log.warn( json.dumps( parsedPending,
937 sort_keys=True,
938 indent=4,
939 separators=( ',', ': ' ) ) )
940 # TODO check something here?
941 else:
942 main.log.error( "pendingMap() returned None" )
943 except ( ValueError, TypeError ):
944 main.log.exception( "Error parsing pending map" )
945 main.log.error( repr( pendingMap ) )
946 # Print flowrules
Jon Halle1a3b752015-07-22 13:02:46 -0700947 main.log.debug( main.CLIs[0].flows( jsonFormat=False ) )
Jon Hall85794ff2015-07-08 14:12:30 -0700948 main.step( "Wait a minute then ping again" )
949 # the wait is above
950 PingResult = main.TRUE
951 for i in range( 8, 18 ):
952 ping = main.Mininet1.pingHost( src="h" + str( i ),
953 target="h" + str( i + 10 ) )
954 PingResult = PingResult and ping
955 if ping == main.FALSE:
956 main.log.warn( "Ping failed between h" + str( i ) +
957 " and h" + str( i + 10 ) )
958 elif ping == main.TRUE:
959 main.log.info( "Ping test passed!" )
960 # Don't set PingResult or you'd override failures
961 if PingResult == main.FALSE:
962 main.log.error(
963 "Intents have not been installed correctly, pings failed." )
964 # TODO: pretty print
965 main.log.warn( "ONOS1 intents: " )
966 try:
967 tmpIntents = main.ONOScli1.intents()
968 main.log.warn( json.dumps( json.loads( tmpIntents ),
969 sort_keys=True,
970 indent=4,
971 separators=( ',', ': ' ) ) )
972 except ( ValueError, TypeError ):
973 main.log.warn( repr( tmpIntents ) )
974 utilities.assert_equals(
975 expect=main.TRUE,
976 actual=PingResult,
977 onpass="Intents have been installed correctly and pings work",
978 onfail="Intents have not been installed correctly, pings failed." )
979
980 def CASE5( self, main ):
981 """
982 Reading state of ONOS
983 """
984 import json
Jon Halle1a3b752015-07-22 13:02:46 -0700985 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall85794ff2015-07-08 14:12:30 -0700986 assert main, "main not defined"
987 assert utilities.assert_equals, "utilities.assert_equals not defined"
988
989 main.case( "Setting up and gathering data for current state" )
990 # The general idea for this test case is to pull the state of
991 # ( intents,flows, topology,... ) from each ONOS node
992 # We can then compare them with each other and also with past states
993
994 main.step( "Check that each switch has a master" )
995 global mastershipState
996 mastershipState = '[]'
997
998 # Assert that each device has a master
999 rolesNotNull = main.ONOScli1.rolesNotNull()
1000 utilities.assert_equals(
1001 expect=main.TRUE,
1002 actual=rolesNotNull,
1003 onpass="Each device has a master",
1004 onfail="Some devices don't have a master assigned" )
1005
1006 main.step( "Get the Mastership of each switch" )
1007 ONOS1Mastership = main.ONOScli1.roles()
1008 # TODO: Make this a meaningful check
1009 if "Error" in ONOS1Mastership or not ONOS1Mastership:
1010 main.log.error( "Error in getting ONOS roles" )
1011 main.log.warn(
1012 "ONOS1 mastership response: " +
1013 repr( ONOS1Mastership ) )
1014 consistentMastership = main.FALSE
1015 else:
1016 mastershipState = ONOS1Mastership
1017 consistentMastership = main.TRUE
1018
1019 main.step( "Get the intents from each controller" )
1020 global intentState
1021 intentState = []
1022 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
1023 intentCheck = main.FALSE
1024 if "Error" in ONOS1Intents or not ONOS1Intents:
1025 main.log.error( "Error in getting ONOS intents" )
1026 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
1027 else:
1028 intentCheck = main.TRUE
1029
1030 main.step( "Get the flows from each controller" )
1031 global flowState
1032 flowState = []
1033 flowCheck = main.FALSE
1034 ONOS1Flows = main.ONOScli1.flows( jsonFormat=True )
1035 if "Error" in ONOS1Flows or not ONOS1Flows:
1036 main.log.error( "Error in getting ONOS flows" )
1037 main.log.warn( "ONOS1 flows repsponse: " + ONOS1Flows )
1038 else:
1039 # TODO: Do a better check, maybe compare flows on switches?
1040 flowState = ONOS1Flows
1041 flowCheck = main.TRUE
1042
1043 main.step( "Get the OF Table entries" )
1044 global flows
1045 flows = []
1046 for i in range( 1, 29 ):
Jon Hall9043c902015-07-30 14:23:44 -07001047 flows.append( main.Mininet1.getFlowTable( 1.3, "s" + str( i ) ) )
Jon Hall85794ff2015-07-08 14:12:30 -07001048 if flowCheck == main.FALSE:
1049 for table in flows:
1050 main.log.warn( table )
1051 # TODO: Compare switch flow tables with ONOS flow tables
1052
1053 main.step( "Collecting topology information from ONOS" )
1054 devices = []
1055 devices.append( main.ONOScli1.devices() )
1056 hosts = []
1057 hosts.append( json.loads( main.ONOScli1.hosts() ) )
1058 ports = []
1059 ports.append( main.ONOScli1.ports() )
1060 links = []
1061 links.append( main.ONOScli1.links() )
1062 clusters = []
1063 clusters.append( main.ONOScli1.clusters() )
1064
1065 main.step( "Each host has an IP address" )
1066 ipResult = main.TRUE
1067 for controller in range( 0, len( hosts ) ):
1068 controllerStr = str( controller + 1 )
1069 for host in hosts[ controller ]:
1070 if host is None or host.get( 'ipAddresses', [] ) == []:
1071 main.log.error(
1072 "DEBUG:Error with host ips on controller" +
1073 controllerStr + ": " + str( host ) )
1074 ipResult = main.FALSE
1075 utilities.assert_equals(
1076 expect=main.TRUE,
1077 actual=ipResult,
1078 onpass="The ips of the hosts aren't empty",
1079 onfail="The ip of at least one host is missing" )
1080
1081 # there should always only be one cluster
1082 main.step( "There is only one dataplane cluster" )
1083 try:
1084 numClusters = len( json.loads( clusters[ 0 ] ) )
1085 except ( ValueError, TypeError ):
1086 main.log.exception( "Error parsing clusters[0]: " +
1087 repr( clusters[ 0 ] ) )
1088 clusterResults = main.FALSE
1089 if numClusters == 1:
1090 clusterResults = main.TRUE
1091 utilities.assert_equals(
1092 expect=1,
1093 actual=numClusters,
1094 onpass="ONOS shows 1 SCC",
1095 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
1096
1097 main.step( "Comparing ONOS topology to MN" )
1098 devicesResults = main.TRUE
1099 linksResults = main.TRUE
1100 hostsResults = main.TRUE
1101 mnSwitches = main.Mininet1.getSwitches()
1102 mnLinks = main.Mininet1.getLinks()
1103 mnHosts = main.Mininet1.getHosts()
Jon Halle1a3b752015-07-22 13:02:46 -07001104 for controller in range( main.numCtrls ):
Jon Hall85794ff2015-07-08 14:12:30 -07001105 controllerStr = str( controller + 1 )
1106 if devices[ controller ] and ports[ controller ] and\
1107 "Error" not in devices[ controller ] and\
1108 "Error" not in ports[ controller ]:
1109
1110 currentDevicesResult = main.Mininet1.compareSwitches(
1111 mnSwitches,
1112 json.loads( devices[ controller ] ),
1113 json.loads( ports[ controller ] ) )
1114 else:
1115 currentDevicesResult = main.FALSE
1116 utilities.assert_equals( expect=main.TRUE,
1117 actual=currentDevicesResult,
1118 onpass="ONOS" + controllerStr +
1119 " Switches view is correct",
1120 onfail="ONOS" + controllerStr +
1121 " Switches view is incorrect" )
1122 if links[ controller ] and "Error" not in links[ controller ]:
1123 currentLinksResult = main.Mininet1.compareLinks(
1124 mnSwitches, mnLinks,
1125 json.loads( links[ controller ] ) )
1126 else:
1127 currentLinksResult = main.FALSE
1128 utilities.assert_equals( expect=main.TRUE,
1129 actual=currentLinksResult,
1130 onpass="ONOS" + controllerStr +
1131 " links view is correct",
1132 onfail="ONOS" + controllerStr +
1133 " links view is incorrect" )
1134
1135 if hosts[ controller ] or "Error" not in hosts[ controller ]:
1136 currentHostsResult = main.Mininet1.compareHosts(
1137 mnHosts,
1138 hosts[ controller ] )
1139 else:
1140 currentHostsResult = main.FALSE
1141 utilities.assert_equals( expect=main.TRUE,
1142 actual=currentHostsResult,
1143 onpass="ONOS" + controllerStr +
1144 " hosts exist in Mininet",
1145 onfail="ONOS" + controllerStr +
1146 " hosts don't match Mininet" )
1147
1148 devicesResults = devicesResults and currentDevicesResult
1149 linksResults = linksResults and currentLinksResult
1150 hostsResults = hostsResults and currentHostsResult
1151
1152 main.step( "Device information is correct" )
1153 utilities.assert_equals(
1154 expect=main.TRUE,
1155 actual=devicesResults,
1156 onpass="Device information is correct",
1157 onfail="Device information is incorrect" )
1158
1159 main.step( "Links are correct" )
1160 utilities.assert_equals(
1161 expect=main.TRUE,
1162 actual=linksResults,
1163 onpass="Link are correct",
1164 onfail="Links are incorrect" )
1165
1166 main.step( "Hosts are correct" )
1167 utilities.assert_equals(
1168 expect=main.TRUE,
1169 actual=hostsResults,
1170 onpass="Hosts are correct",
1171 onfail="Hosts are incorrect" )
1172
1173 def CASE6( self, main ):
1174 """
1175 The Failure case.
1176 """
1177 import time
Jon Halle1a3b752015-07-22 13:02:46 -07001178 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07001179 assert main, "main not defined"
1180 assert utilities.assert_equals, "utilities.assert_equals not defined"
1181
1182 # Reset non-persistent variables
1183 try:
1184 iCounterValue = 0
1185 except NameError:
1186 main.log.error( "iCounterValue not defined, setting to 0" )
1187 iCounterValue = 0
1188
1189 main.case( "Restart ONOS node" )
Jon Hall783bbf92015-07-23 14:33:19 -07001190 main.caseExplanation = "Killing ONOS process and restart cli " +\
Jon Hall85794ff2015-07-08 14:12:30 -07001191 "sessions once onos is up."
Jon Hall96091e62015-09-21 17:34:17 -07001192
1193 main.step( "Checking ONOS Logs for errors" )
1194 for node in main.nodes:
1195 main.log.debug( "Checking logs for errors on " + node.name + ":" )
1196 main.log.warn( main.ONOSbench.checkLogs( node.ip_address ) )
1197
Jon Hall85794ff2015-07-08 14:12:30 -07001198 main.step( "Killing ONOS processes" )
Jon Halle1a3b752015-07-22 13:02:46 -07001199 killResult = main.ONOSbench.onosKill( main.nodes[0].ip_address )
Jon Hall85794ff2015-07-08 14:12:30 -07001200 start = time.time()
1201 utilities.assert_equals( expect=main.TRUE, actual=killResult,
1202 onpass="ONOS Killed",
1203 onfail="Error killing ONOS" )
1204
1205 main.step( "Checking if ONOS is up yet" )
1206 count = 0
1207 while count < 10:
Jon Halle1a3b752015-07-22 13:02:46 -07001208 onos1Isup = main.ONOSbench.isup( main.nodes[0].ip_address )
Jon Hall85794ff2015-07-08 14:12:30 -07001209 if onos1Isup == main.TRUE:
1210 elapsed = time.time() - start
1211 break
1212 else:
1213 count = count + 1
1214 utilities.assert_equals( expect=main.TRUE, actual=onos1Isup,
1215 onpass="ONOS is back up",
1216 onfail="ONOS failed to start" )
1217
1218 main.log.step( "Starting ONOS CLI sessions" )
Jon Halle1a3b752015-07-22 13:02:46 -07001219 cliResults = main.ONOScli1.startOnosCli( main.nodes[0].ip_address )
Jon Hall85794ff2015-07-08 14:12:30 -07001220 utilities.assert_equals( expect=main.TRUE, actual=cliResults,
1221 onpass="ONOS cli startup successful",
1222 onfail="ONOS cli startup failed" )
1223
1224 if elapsed:
1225 main.log.info( "ESTIMATE: ONOS took %s seconds to restart" %
1226 str( elapsed ) )
1227 main.restartTime = elapsed
1228 else:
1229 main.restartTime = -1
1230 time.sleep( 5 )
1231 # rerun on election apps
1232 main.ONOScli1.electionTestRun()
1233
1234 def CASE7( self, main ):
1235 """
1236 Check state after ONOS failure
1237 """
1238 import json
Jon Halle1a3b752015-07-22 13:02:46 -07001239 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07001240 assert main, "main not defined"
1241 assert utilities.assert_equals, "utilities.assert_equals not defined"
1242 main.case( "Running ONOS Constant State Tests" )
1243 main.step( "Check that each switch has a master" )
1244 # Assert that each device has a master
1245 rolesNotNull = main.ONOScli1.rolesNotNull()
1246 utilities.assert_equals(
1247 expect=main.TRUE,
1248 actual=rolesNotNull,
1249 onpass="Each device has a master",
1250 onfail="Some devices don't have a master assigned" )
1251
1252 main.step( "Check if switch roles are consistent across all nodes" )
1253 ONOS1Mastership = main.ONOScli1.roles()
1254 # FIXME: Refactor this whole case for single instance
1255 if "Error" in ONOS1Mastership or not ONOS1Mastership:
1256 main.log.error( "Error in getting ONOS mastership" )
1257 main.log.warn( "ONOS1 mastership response: " +
1258 repr( ONOS1Mastership ) )
1259 consistentMastership = main.FALSE
1260 else:
1261 consistentMastership = main.TRUE
1262 utilities.assert_equals(
1263 expect=main.TRUE,
1264 actual=consistentMastership,
1265 onpass="Switch roles are consistent across all ONOS nodes",
1266 onfail="ONOS nodes have different views of switch roles" )
1267
1268 description2 = "Compare switch roles from before failure"
1269 main.step( description2 )
1270
1271 currentJson = json.loads( ONOS1Mastership )
1272 oldJson = json.loads( mastershipState )
1273 mastershipCheck = main.TRUE
1274 for i in range( 1, 29 ):
1275 switchDPID = str(
1276 main.Mininet1.getSwitchDPID( switch="s" + str( i ) ) )
1277
1278 current = [ switch[ 'master' ] for switch in currentJson
1279 if switchDPID in switch[ 'id' ] ]
1280 old = [ switch[ 'master' ] for switch in oldJson
1281 if switchDPID in switch[ 'id' ] ]
1282 if current == old:
1283 mastershipCheck = mastershipCheck and main.TRUE
1284 else:
1285 main.log.warn( "Mastership of switch %s changed" % switchDPID )
1286 mastershipCheck = main.FALSE
1287 utilities.assert_equals(
1288 expect=main.TRUE,
1289 actual=mastershipCheck,
1290 onpass="Mastership of Switches was not changed",
1291 onfail="Mastership of some switches changed" )
1292 mastershipCheck = mastershipCheck and consistentMastership
1293
1294 main.step( "Get the intents and compare across all nodes" )
1295 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
1296 intentCheck = main.FALSE
1297 if "Error" in ONOS1Intents or not ONOS1Intents:
1298 main.log.error( "Error in getting ONOS intents" )
1299 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
1300 else:
1301 intentCheck = main.TRUE
1302 utilities.assert_equals(
1303 expect=main.TRUE,
1304 actual=intentCheck,
1305 onpass="Intents are consistent across all ONOS nodes",
1306 onfail="ONOS nodes have different views of intents" )
1307 # Print the intent states
1308 intents = []
1309 intents.append( ONOS1Intents )
1310 intentStates = []
1311 for node in intents: # Iter through ONOS nodes
1312 nodeStates = []
1313 # Iter through intents of a node
1314 for intent in json.loads( node ):
1315 nodeStates.append( intent[ 'state' ] )
1316 intentStates.append( nodeStates )
1317 out = [ (i, nodeStates.count( i ) ) for i in set( nodeStates ) ]
1318 main.log.info( dict( out ) )
1319
1320 # NOTE: Store has no durability, so intents are lost across system
1321 # restarts
1322 """
1323 main.step( "Compare current intents with intents before the failure" )
1324 # NOTE: this requires case 5 to pass for intentState to be set.
1325 # maybe we should stop the test if that fails?
1326 sameIntents = main.FALSE
1327 if intentState and intentState == ONOSIntents[ 0 ]:
1328 sameIntents = main.TRUE
1329 main.log.info( "Intents are consistent with before failure" )
1330 # TODO: possibly the states have changed? we may need to figure out
1331 # what the acceptable states are
1332 elif len( intentState ) == len( ONOSIntents[ 0 ] ):
1333 sameIntents = main.TRUE
1334 try:
1335 before = json.loads( intentState )
1336 after = json.loads( ONOSIntents[ 0 ] )
1337 for intent in before:
1338 if intent not in after:
1339 sameIntents = main.FALSE
1340 main.log.debug( "Intent is not currently in ONOS " +
1341 "(at least in the same form):" )
1342 main.log.debug( json.dumps( intent ) )
1343 except ( ValueError, TypeError ):
1344 main.log.exception( "Exception printing intents" )
1345 main.log.debug( repr( ONOSIntents[0] ) )
1346 main.log.debug( repr( intentState ) )
1347 if sameIntents == main.FALSE:
1348 try:
1349 main.log.debug( "ONOS intents before: " )
1350 main.log.debug( json.dumps( json.loads( intentState ),
1351 sort_keys=True, indent=4,
1352 separators=( ',', ': ' ) ) )
1353 main.log.debug( "Current ONOS intents: " )
1354 main.log.debug( json.dumps( json.loads( ONOSIntents[ 0 ] ),
1355 sort_keys=True, indent=4,
1356 separators=( ',', ': ' ) ) )
1357 except ( ValueError, TypeError ):
1358 main.log.exception( "Exception printing intents" )
1359 main.log.debug( repr( ONOSIntents[0] ) )
1360 main.log.debug( repr( intentState ) )
1361 utilities.assert_equals(
1362 expect=main.TRUE,
1363 actual=sameIntents,
1364 onpass="Intents are consistent with before failure",
1365 onfail="The Intents changed during failure" )
1366 intentCheck = intentCheck and sameIntents
1367 """
1368 main.step( "Get the OF Table entries and compare to before " +
1369 "component failure" )
1370 FlowTables = main.TRUE
1371 flows2 = []
1372 for i in range( 28 ):
1373 main.log.info( "Checking flow table on s" + str( i + 1 ) )
Jon Hall9043c902015-07-30 14:23:44 -07001374 tmpFlows = main.Mininet1.getFlowTable( 1.3, "s" + str( i + 1 ) )
Jon Hall85794ff2015-07-08 14:12:30 -07001375 flows2.append( tmpFlows )
Jon Hall9043c902015-07-30 14:23:44 -07001376 tempResult = main.Mininet1.flowComp(
Jon Hall85794ff2015-07-08 14:12:30 -07001377 flow1=flows[ i ],
1378 flow2=tmpFlows )
1379 FlowTables = FlowTables and tempResult
1380 if FlowTables == main.FALSE:
1381 main.log.info( "Differences in flow table for switch: s" +
1382 str( i + 1 ) )
1383 utilities.assert_equals(
1384 expect=main.TRUE,
1385 actual=FlowTables,
1386 onpass="No changes were found in the flow tables",
1387 onfail="Changes were found in the flow tables" )
1388
1389 main.step( "Leadership Election is still functional" )
1390 # Test of LeadershipElection
1391
Jon Halle1a3b752015-07-22 13:02:46 -07001392 leader = main.nodes[0].ip_address
Jon Hall85794ff2015-07-08 14:12:30 -07001393 leaderResult = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07001394 for controller in range( 1, main.numCtrls + 1 ):
Jon Hall85794ff2015-07-08 14:12:30 -07001395 # loop through ONOScli handlers
1396 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
1397 leaderN = node.electionTestLeader()
1398 # verify leader is ONOS1
1399 # NOTE even though we restarted ONOS, it is the only one so onos 1
1400 # must be leader
1401 if leaderN == leader:
1402 # all is well
1403 pass
1404 elif leaderN == main.FALSE:
1405 # error in response
1406 main.log.error( "Something is wrong with " +
1407 "electionTestLeader function, check the" +
1408 " error logs" )
1409 leaderResult = main.FALSE
1410 elif leader != leaderN:
1411 leaderResult = main.FALSE
1412 main.log.error( "ONOS" + str( controller ) + " sees " +
1413 str( leaderN ) +
1414 " as the leader of the election app. " +
1415 "Leader should be " + str( leader ) )
1416 utilities.assert_equals(
1417 expect=main.TRUE,
1418 actual=leaderResult,
1419 onpass="Leadership election passed",
1420 onfail="Something went wrong with Leadership election" )
1421
1422 def CASE8( self, main ):
1423 """
1424 Compare topo
1425 """
1426 import json
1427 import time
Jon Halle1a3b752015-07-22 13:02:46 -07001428 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07001429 assert main, "main not defined"
1430 assert utilities.assert_equals, "utilities.assert_equals not defined"
1431
1432 main.case( "Compare ONOS Topology view to Mininet topology" )
Jon Hall783bbf92015-07-23 14:33:19 -07001433 main.caseExplanation = "Compare topology objects between Mininet" +\
Jon Hall85794ff2015-07-08 14:12:30 -07001434 " and ONOS"
1435
1436 main.step( "Comparing ONOS topology to MN" )
Jon Hall85794ff2015-07-08 14:12:30 -07001437 topoResult = main.FALSE
1438 elapsed = 0
1439 count = 0
1440 main.step( "Collecting topology information from ONOS" )
1441 startTime = time.time()
1442 # Give time for Gossip to work
1443 while topoResult == main.FALSE and elapsed < 60:
Jon Hall96091e62015-09-21 17:34:17 -07001444 devicesResults = main.TRUE
1445 linksResults = main.TRUE
1446 hostsResults = main.TRUE
1447 hostAttachmentResults = True
Jon Hall85794ff2015-07-08 14:12:30 -07001448 count += 1
1449 cliStart = time.time()
1450 devices = []
1451 devices.append( main.ONOScli1.devices() )
1452 hosts = []
1453 hosts.append( json.loads( main.ONOScli1.hosts() ) )
1454 ipResult = main.TRUE
1455 for controller in range( 0, len( hosts ) ):
1456 controllerStr = str( controller + 1 )
1457 for host in hosts[ controller ]:
1458 if host is None or host.get( 'ipAddresses', [] ) == []:
1459 main.log.error(
1460 "DEBUG:Error with host ips on controller" +
1461 controllerStr + ": " + str( host ) )
1462 ipResult = main.FALSE
1463 ports = []
1464 ports.append( main.ONOScli1.ports() )
1465 links = []
1466 links.append( main.ONOScli1.links() )
1467 clusters = []
1468 clusters.append( main.ONOScli1.clusters() )
1469
1470 elapsed = time.time() - startTime
1471 cliTime = time.time() - cliStart
1472 print "CLI time: " + str( cliTime )
1473
1474 mnSwitches = main.Mininet1.getSwitches()
1475 mnLinks = main.Mininet1.getLinks()
1476 mnHosts = main.Mininet1.getHosts()
Jon Halle1a3b752015-07-22 13:02:46 -07001477 for controller in range( main.numCtrls ):
Jon Hall85794ff2015-07-08 14:12:30 -07001478 controllerStr = str( controller + 1 )
1479 if devices[ controller ] and ports[ controller ] and\
1480 "Error" not in devices[ controller ] and\
1481 "Error" not in ports[ controller ]:
1482
1483 currentDevicesResult = main.Mininet1.compareSwitches(
1484 mnSwitches,
1485 json.loads( devices[ controller ] ),
1486 json.loads( ports[ controller ] ) )
1487 else:
1488 currentDevicesResult = main.FALSE
1489 utilities.assert_equals( expect=main.TRUE,
1490 actual=currentDevicesResult,
1491 onpass="ONOS" + controllerStr +
1492 " Switches view is correct",
1493 onfail="ONOS" + controllerStr +
1494 " Switches view is incorrect" )
1495
1496 if links[ controller ] and "Error" not in links[ controller ]:
1497 currentLinksResult = main.Mininet1.compareLinks(
1498 mnSwitches, mnLinks,
1499 json.loads( links[ controller ] ) )
1500 else:
1501 currentLinksResult = main.FALSE
1502 utilities.assert_equals( expect=main.TRUE,
1503 actual=currentLinksResult,
1504 onpass="ONOS" + controllerStr +
1505 " links view is correct",
1506 onfail="ONOS" + controllerStr +
1507 " links view is incorrect" )
1508
1509 if hosts[ controller ] or "Error" not in hosts[ controller ]:
1510 currentHostsResult = main.Mininet1.compareHosts(
1511 mnHosts,
1512 hosts[ controller ] )
1513 else:
1514 currentHostsResult = main.FALSE
1515 utilities.assert_equals( expect=main.TRUE,
1516 actual=currentHostsResult,
1517 onpass="ONOS" + controllerStr +
1518 " hosts exist in Mininet",
1519 onfail="ONOS" + controllerStr +
1520 " hosts don't match Mininet" )
1521 # CHECKING HOST ATTACHMENT POINTS
1522 hostAttachment = True
1523 zeroHosts = False
1524 # FIXME: topo-HA/obelisk specific mappings:
1525 # key is mac and value is dpid
1526 mappings = {}
1527 for i in range( 1, 29 ): # hosts 1 through 28
1528 # set up correct variables:
1529 macId = "00:" * 5 + hex( i ).split( "0x" )[1].upper().zfill(2)
1530 if i == 1:
1531 deviceId = "1000".zfill(16)
1532 elif i == 2:
1533 deviceId = "2000".zfill(16)
1534 elif i == 3:
1535 deviceId = "3000".zfill(16)
1536 elif i == 4:
1537 deviceId = "3004".zfill(16)
1538 elif i == 5:
1539 deviceId = "5000".zfill(16)
1540 elif i == 6:
1541 deviceId = "6000".zfill(16)
1542 elif i == 7:
1543 deviceId = "6007".zfill(16)
1544 elif i >= 8 and i <= 17:
1545 dpid = '3' + str( i ).zfill( 3 )
1546 deviceId = dpid.zfill(16)
1547 elif i >= 18 and i <= 27:
1548 dpid = '6' + str( i ).zfill( 3 )
1549 deviceId = dpid.zfill(16)
1550 elif i == 28:
1551 deviceId = "2800".zfill(16)
1552 mappings[ macId ] = deviceId
1553 if hosts[ controller ] or "Error" not in hosts[ controller ]:
1554 if hosts[ controller ] == []:
1555 main.log.warn( "There are no hosts discovered" )
1556 zeroHosts = True
1557 else:
1558 for host in hosts[ controller ]:
1559 mac = None
1560 location = None
1561 device = None
1562 port = None
1563 try:
1564 mac = host.get( 'mac' )
1565 assert mac, "mac field could not be found for this host object"
1566
1567 location = host.get( 'location' )
1568 assert location, "location field could not be found for this host object"
1569
1570 # Trim the protocol identifier off deviceId
1571 device = str( location.get( 'elementId' ) ).split(':')[1]
1572 assert device, "elementId field could not be found for this host location object"
1573
1574 port = location.get( 'port' )
1575 assert port, "port field could not be found for this host location object"
1576
1577 # Now check if this matches where they should be
1578 if mac and device and port:
1579 if str( port ) != "1":
1580 main.log.error( "The attachment port is incorrect for " +
1581 "host " + str( mac ) +
1582 ". Expected: 1 Actual: " + str( port) )
1583 hostAttachment = False
1584 if device != mappings[ str( mac ) ]:
1585 main.log.error( "The attachment device is incorrect for " +
1586 "host " + str( mac ) +
1587 ". Expected: " + mappings[ str( mac ) ] +
1588 " Actual: " + device )
1589 hostAttachment = False
1590 else:
1591 hostAttachment = False
1592 except AssertionError:
1593 main.log.exception( "Json object not as expected" )
1594 main.log.error( repr( host ) )
1595 hostAttachment = False
1596 else:
1597 main.log.error( "No hosts json output or \"Error\"" +
1598 " in output. hosts = " +
1599 repr( hosts[ controller ] ) )
1600 if zeroHosts is False:
1601 hostAttachment = True
1602
Jon Hall85794ff2015-07-08 14:12:30 -07001603 devicesResults = devicesResults and currentDevicesResult
1604 linksResults = linksResults and currentLinksResult
1605 hostsResults = hostsResults and currentHostsResult
1606 hostAttachmentResults = hostAttachmentResults and\
1607 hostAttachment
1608
1609 # "consistent" results don't make sense for single instance
1610 # there should always only be one cluster
1611 numClusters = len( json.loads( clusters[ 0 ] ) )
1612 clusterResults = main.FALSE
1613 if numClusters == 1:
1614 clusterResults = main.TRUE
1615 utilities.assert_equals(
1616 expect=1,
1617 actual=numClusters,
1618 onpass="ONOS shows 1 SCC",
1619 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
1620
1621 topoResult = ( devicesResults and linksResults
1622 and hostsResults and ipResult and clusterResults and
1623 hostAttachmentResults )
1624
1625 topoResult = topoResult and int( count <= 2 )
1626 note = "note it takes about " + str( int( cliTime ) ) + \
1627 " seconds for the test to make all the cli calls to fetch " +\
1628 "the topology from each ONOS instance"
1629 main.log.info(
1630 "Very crass estimate for topology discovery/convergence( " +
1631 str( note ) + " ): " + str( elapsed ) + " seconds, " +
1632 str( count ) + " tries" )
1633 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
1634 onpass="Topology Check Test successful",
1635 onfail="Topology Check Test NOT successful" )
1636
1637 def CASE9( self, main ):
1638 """
1639 Link s3-s28 down
1640 """
1641 import time
Jon Halle1a3b752015-07-22 13:02:46 -07001642 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07001643 assert main, "main not defined"
1644 assert utilities.assert_equals, "utilities.assert_equals not defined"
1645 # NOTE: You should probably run a topology check after this
1646
1647 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
1648
1649 description = "Turn off a link to ensure that Link Discovery " +\
1650 "is working properly"
1651 main.case( description )
1652
1653 main.step( "Kill Link between s3 and s28" )
1654 LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" )
1655 main.log.info( "Waiting " + str( linkSleep ) +
1656 " seconds for link down to be discovered" )
1657 time.sleep( linkSleep )
1658 utilities.assert_equals( expect=main.TRUE, actual=LinkDown,
1659 onpass="Link down successful",
1660 onfail="Failed to bring link down" )
1661 # TODO do some sort of check here
1662
1663 def CASE10( self, main ):
1664 """
1665 Link s3-s28 up
1666 """
1667 import time
Jon Halle1a3b752015-07-22 13:02:46 -07001668 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07001669 assert main, "main not defined"
1670 assert utilities.assert_equals, "utilities.assert_equals not defined"
1671 # NOTE: You should probably run a topology check after this
1672
1673 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
1674
1675 description = "Restore a link to ensure that Link Discovery is " + \
1676 "working properly"
1677 main.case( description )
1678
1679 main.step( "Bring link between s3 and s28 back up" )
1680 LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" )
1681 main.log.info( "Waiting " + str( linkSleep ) +
1682 " seconds for link up to be discovered" )
1683 time.sleep( linkSleep )
1684 utilities.assert_equals( expect=main.TRUE, actual=LinkUp,
1685 onpass="Link up successful",
1686 onfail="Failed to bring link up" )
1687 # TODO do some sort of check here
1688
1689 def CASE11( self, main ):
1690 """
1691 Switch Down
1692 """
1693 # NOTE: You should probably run a topology check after this
1694 import time
Jon Halle1a3b752015-07-22 13:02:46 -07001695 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07001696 assert main, "main not defined"
1697 assert utilities.assert_equals, "utilities.assert_equals not defined"
1698
1699 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
1700
1701 description = "Killing a switch to ensure it is discovered correctly"
1702 main.case( description )
1703 switch = main.params[ 'kill' ][ 'switch' ]
1704 switchDPID = main.params[ 'kill' ][ 'dpid' ]
1705
1706 # TODO: Make this switch parameterizable
1707 main.step( "Kill " + switch )
1708 main.log.info( "Deleting " + switch )
1709 main.Mininet1.delSwitch( switch )
1710 main.log.info( "Waiting " + str( switchSleep ) +
1711 " seconds for switch down to be discovered" )
1712 time.sleep( switchSleep )
1713 device = main.ONOScli1.getDevice( dpid=switchDPID )
1714 # Peek at the deleted switch
1715 main.log.warn( str( device ) )
1716 result = main.FALSE
1717 if device and device[ 'available' ] is False:
1718 result = main.TRUE
1719 utilities.assert_equals( expect=main.TRUE, actual=result,
1720 onpass="Kill switch successful",
1721 onfail="Failed to kill switch?" )
1722
1723 def CASE12( self, main ):
1724 """
1725 Switch Up
1726 """
1727 # NOTE: You should probably run a topology check after this
1728 import time
Jon Halle1a3b752015-07-22 13:02:46 -07001729 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07001730 assert main, "main not defined"
1731 assert utilities.assert_equals, "utilities.assert_equals not defined"
1732
1733 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
1734 switch = main.params[ 'kill' ][ 'switch' ]
1735 switchDPID = main.params[ 'kill' ][ 'dpid' ]
1736 links = main.params[ 'kill' ][ 'links' ].split()
1737 description = "Adding a switch to ensure it is discovered correctly"
1738 main.case( description )
1739
1740 main.step( "Add back " + switch )
1741 main.Mininet1.addSwitch( switch, dpid=switchDPID )
1742 for peer in links:
1743 main.Mininet1.addLink( switch, peer )
1744 ipList = []
Jon Halle1a3b752015-07-22 13:02:46 -07001745 for i in range( main.numCtrls ):
1746 ipList.append( main.nodes[ i ].ip_address )
Jon Hall85794ff2015-07-08 14:12:30 -07001747 main.Mininet1.assignSwController( sw=switch, ip=ipList )
1748 main.log.info( "Waiting " + str( switchSleep ) +
1749 " seconds for switch up to be discovered" )
1750 time.sleep( switchSleep )
1751 device = main.ONOScli1.getDevice( dpid=switchDPID )
1752 # Peek at the deleted switch
1753 main.log.warn( str( device ) )
1754 result = main.FALSE
1755 if device and device[ 'available' ]:
1756 result = main.TRUE
1757 utilities.assert_equals( expect=main.TRUE, actual=result,
1758 onpass="add switch successful",
1759 onfail="Failed to add switch?" )
1760
1761 def CASE13( self, main ):
1762 """
1763 Clean up
1764 """
1765 import os
1766 import time
Jon Halle1a3b752015-07-22 13:02:46 -07001767 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07001768 assert main, "main not defined"
1769 assert utilities.assert_equals, "utilities.assert_equals not defined"
1770 # printing colors to terminal
1771 colors = { 'cyan': '\033[96m', 'purple': '\033[95m',
1772 'blue': '\033[94m', 'green': '\033[92m',
1773 'yellow': '\033[93m', 'red': '\033[91m', 'end': '\033[0m' }
1774 main.case( "Test Cleanup" )
1775 main.step( "Killing tcpdumps" )
1776 main.Mininet2.stopTcpdump()
1777
1778 testname = main.TEST
Jon Hall96091e62015-09-21 17:34:17 -07001779 if main.params[ 'BACKUP' ][ 'ENABLED' ] == "True":
Jon Hall85794ff2015-07-08 14:12:30 -07001780 main.step( "Copying MN pcap and ONOS log files to test station" )
1781 teststationUser = main.params[ 'BACKUP' ][ 'TESTONUSER' ]
1782 teststationIP = main.params[ 'BACKUP' ][ 'TESTONIP' ]
Jon Hall96091e62015-09-21 17:34:17 -07001783 # NOTE: MN Pcap file is being saved to logdir.
1784 # We scp this file as MN and TestON aren't necessarily the same vm
1785
1786 # FIXME: To be replaced with a Jenkin's post script
Jon Hall85794ff2015-07-08 14:12:30 -07001787 # TODO: Load these from params
1788 # NOTE: must end in /
1789 logFolder = "/opt/onos/log/"
1790 logFiles = [ "karaf.log", "karaf.log.1" ]
1791 # NOTE: must end in /
Jon Hall85794ff2015-07-08 14:12:30 -07001792 for f in logFiles:
Jon Hall96091e62015-09-21 17:34:17 -07001793 for node in main.nodes:
1794 dstName = main.logdir + "/" + node.name + "-" + f
1795 main.ONOSbench.secureCopy( node.user_name, node.ip_address,
1796 logFolder + f, dstName )
Jon Hall85794ff2015-07-08 14:12:30 -07001797 # std*.log's
1798 # NOTE: must end in /
1799 logFolder = "/opt/onos/var/"
1800 logFiles = [ "stderr.log", "stdout.log" ]
1801 # NOTE: must end in /
Jon Hall85794ff2015-07-08 14:12:30 -07001802 for f in logFiles:
Jon Hall96091e62015-09-21 17:34:17 -07001803 for node in main.nodes:
1804 dstName = main.logdir + "/" + node.name + "-" + f
1805 main.ONOSbench.secureCopy( node.user_name, node.ip_address,
1806 logFolder + f, dstName )
1807 else:
1808 main.log.debug( "skipping saving log files" )
Jon Hall85794ff2015-07-08 14:12:30 -07001809
Jon Hall85794ff2015-07-08 14:12:30 -07001810 main.step( "Stopping Mininet" )
1811 mnResult = main.Mininet1.stopNet()
1812 utilities.assert_equals( expect=main.TRUE, actual=mnResult,
1813 onpass="Mininet stopped",
1814 onfail="MN cleanup NOT successful" )
1815
1816 main.step( "Checking ONOS Logs for errors" )
Jon Hall96091e62015-09-21 17:34:17 -07001817 for node in main.nodes:
1818 main.log.debug( "Checking logs for errors on " + node.name + ":" )
1819 main.log.warn( main.ONOSbench.checkLogs( node.ip_address ) )
Jon Hall85794ff2015-07-08 14:12:30 -07001820
1821 try:
1822 timerLog = open( main.logdir + "/Timers.csv", 'w')
1823 # Overwrite with empty line and close
1824 labels = "Gossip Intents, Restart"
1825 data = str( gossipTime ) + ", " + str( main.restartTime )
1826 timerLog.write( labels + "\n" + data )
1827 timerLog.close()
1828 except NameError, e:
1829 main.log.exception(e)
1830
1831 def CASE14( self, main ):
1832 """
1833 start election app on all onos nodes
1834 """
Jon Halle1a3b752015-07-22 13:02:46 -07001835 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07001836 assert main, "main not defined"
1837 assert utilities.assert_equals, "utilities.assert_equals not defined"
1838
1839 main.case("Start Leadership Election app")
1840 main.step( "Install leadership election app" )
1841 appResult = main.ONOScli1.activateApp( "org.onosproject.election" )
1842 utilities.assert_equals(
1843 expect=main.TRUE,
1844 actual=appResult,
1845 onpass="Election app installed",
1846 onfail="Something went wrong with installing Leadership election" )
1847
1848 main.step( "Run for election on each node" )
1849 leaderResult = main.ONOScli1.electionTestRun()
1850 # check for leader
1851 leader = main.ONOScli1.electionTestLeader()
1852 # verify leader is ONOS1
Jon Halle1a3b752015-07-22 13:02:46 -07001853 if leader == main.nodes[0].ip_address:
Jon Hall85794ff2015-07-08 14:12:30 -07001854 # all is well
1855 pass
1856 elif leader is None:
1857 # No leader elected
1858 main.log.error( "No leader was elected" )
1859 leaderResult = main.FALSE
1860 elif leader == main.FALSE:
1861 # error in response
1862 # TODO: add check for "Command not found:" in the driver, this
1863 # means the app isn't loaded
1864 main.log.error( "Something is wrong with electionTestLeader" +
1865 " function, check the error logs" )
1866 leaderResult = main.FALSE
1867 else:
1868 # error in response
1869 main.log.error(
1870 "Unexpected response from electionTestLeader function:'" +
1871 str( leader ) +
1872 "'" )
1873 leaderResult = main.FALSE
1874 utilities.assert_equals(
1875 expect=main.TRUE,
1876 actual=leaderResult,
1877 onpass="Successfully ran for leadership",
1878 onfail="Failed to run for leadership" )
1879
1880 def CASE15( self, main ):
1881 """
1882 Check that Leadership Election is still functional
acsmars71adceb2015-08-31 15:09:26 -07001883 15.1 Run election on each node
1884 15.2 Check that each node has the same leaders and candidates
1885 15.3 Find current leader and withdraw
1886 15.4 Check that a new node was elected leader
1887 15.5 Check that that new leader was the candidate of old leader
1888 15.6 Run for election on old leader
1889 15.7 Check that oldLeader is a candidate, and leader if only 1 node
1890 15.8 Make sure that the old leader was added to the candidate list
1891
1892 old and new variable prefixes refer to data from before vs after
1893 withdrawl and later before withdrawl vs after re-election
Jon Hall85794ff2015-07-08 14:12:30 -07001894 """
acsmars71adceb2015-08-31 15:09:26 -07001895 import time
Jon Halle1a3b752015-07-22 13:02:46 -07001896 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07001897 assert main, "main not defined"
1898 assert utilities.assert_equals, "utilities.assert_equals not defined"
acsmars71adceb2015-08-31 15:09:26 -07001899 assert main.CLIs, "main.CLIs not defined"
1900 assert main.nodes, "main.nodes not defined"
1901
Jon Hall85794ff2015-07-08 14:12:30 -07001902 description = "Check that Leadership Election is still functional"
1903 main.case( description )
acsmars71adceb2015-08-31 15:09:26 -07001904 # NOTE: Need to re-run since being a canidate is not persistant
1905 # TODO: add check for "Command not found:" in the driver, this
1906 # means the election test app isn't loaded
acsmars2c2fcdd2015-08-25 17:14:13 -07001907
acsmars71adceb2015-08-31 15:09:26 -07001908 oldLeaders = [] # leaders by node before withdrawl from candidates
1909 newLeaders = [] # leaders by node after withdrawl from candidates
1910 oldAllCandidates = [] # list of lists of each nodes' candidates before
1911 newAllCandidates = [] # list of lists of each nodes' candidates after
1912 oldCandidates = [] # list of candidates from node 0 before withdrawl
1913 newCandidates = [] # list of candidates from node 0 after withdrawl
1914 oldLeader = '' # the old leader from oldLeaders, None if not same
1915 newLeader = '' # the new leaders fron newLoeaders, None if not same
1916 oldLeaderCLI = None # the CLI of the old leader used for re-electing
1917 expectNoLeader = False # True when there is only one leader
1918 if main.numCtrls == 1:
1919 expectNoLeader = True
acsmars2c2fcdd2015-08-25 17:14:13 -07001920
acsmars71adceb2015-08-31 15:09:26 -07001921 main.step( "Run for election on each node" )
1922 electionResult = main.TRUE
1923
1924 for cli in main.CLIs: # run test election on each node
1925 if cli.electionTestRun() == main.FALSE:
1926 electionResult = main.FALSE
1927
1928 utilities.assert_equals(
1929 expect=main.TRUE,
1930 actual=electionResult,
1931 onpass="All nodes successfully ran for leadership",
1932 onfail="At least one node failed to run for leadership" )
1933
acsmars3a72bde2015-09-02 14:16:22 -07001934 if electionResult == main.FALSE:
1935 main.log.error(
1936 "Skipping Test Case because Election Test App isn't loaded" )
1937 main.skipCase()
1938
acsmars71adceb2015-08-31 15:09:26 -07001939 main.step( "Check that each node shows the same leader and candidates" )
1940 sameResult = main.TRUE
1941 failMessage = "Nodes have different leaders"
1942 for cli in main.CLIs:
1943 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
1944 oldAllCandidates.append( node )
1945 oldLeaders.append( node[ 0 ] )
1946 oldCandidates = oldAllCandidates[ 0 ]
1947
1948 # Check that each node has the same leader. Defines oldLeader
1949 if len( set( oldLeaders ) ) != 1:
1950 sameResult = main.FALSE
1951 main.log.error( "More than one leader present:" + str( oldLeaders ) )
Jon Hall85794ff2015-07-08 14:12:30 -07001952 oldLeader = None
1953 else:
acsmars71adceb2015-08-31 15:09:26 -07001954 oldLeader = oldLeaders[ 0 ]
1955
1956 # Check that each node's candidate list is the same
1957 for candidates in oldAllCandidates:
1958 if set( candidates ) != set( oldCandidates ):
1959 sameResult = main.FALSE
1960 failMessage += "and candidates"
1961
1962 utilities.assert_equals(
1963 expect=main.TRUE,
1964 actual=sameResult,
1965 onpass="Leadership is consistent for the election topic",
1966 onfail=failMessage )
1967
1968 main.step( "Find current leader and withdraw" )
1969 withdrawResult = main.TRUE
1970 # do some sanity checking on leader before using it
1971 if oldLeader is None:
1972 main.log.error( "Leadership isn't consistent." )
1973 withdrawResult = main.FALSE
1974 # Get the CLI of the oldLeader
1975 for i in range( len( main.CLIs ) ):
1976 if oldLeader == main.nodes[ i ].ip_address:
1977 oldLeaderCLI = main.CLIs[ i ]
1978 break
1979 else: # FOR/ELSE statement
1980 main.log.error( "Leader election, could not find current leader" )
Jon Hall85794ff2015-07-08 14:12:30 -07001981 if oldLeader:
acsmars71adceb2015-08-31 15:09:26 -07001982 withdrawResult = oldLeaderCLI.electionTestWithdraw()
Jon Hall85794ff2015-07-08 14:12:30 -07001983 utilities.assert_equals(
1984 expect=main.TRUE,
1985 actual=withdrawResult,
1986 onpass="Node was withdrawn from election",
1987 onfail="Node was not withdrawn from election" )
1988
acsmars71adceb2015-08-31 15:09:26 -07001989 main.step( "Check that a new node was elected leader" )
1990
1991 # FIXME: use threads
1992 newLeaderResult = main.TRUE
1993 failMessage = "Nodes have different leaders"
1994
1995 # Get new leaders and candidates
1996 for cli in main.CLIs:
1997 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
1998 # elections might no have finished yet
1999 if node[ 0 ] == 'none' and not expectNoLeader:
2000 main.log.info( "Node has no leader, waiting 5 seconds to be " +
2001 "sure elections are complete." )
2002 time.sleep(5)
2003 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
2004 # election still isn't done or there is a problem
2005 if node[ 0 ] == 'none':
2006 main.log.error( "No leader was elected on at least 1 node" )
2007 newLeaderResult = main.FALSE
2008 newAllCandidates.append( node )
2009 newLeaders.append( node[ 0 ] )
2010 newCandidates = newAllCandidates[ 0 ]
2011
2012 # Check that each node has the same leader. Defines newLeader
2013 if len( set( newLeaders ) ) != 1:
2014 newLeaderResult = main.FALSE
2015 main.log.error( "Nodes have different leaders: " +
2016 str( newLeaders ) )
2017 newLeader = None
2018 else:
2019 newLeader = newLeaders[ 0 ]
2020
2021 # Check that each node's candidate list is the same
2022 for candidates in newAllCandidates:
2023 if set( candidates ) != set( newCandidates ):
2024 newLeaderResult = main.FALSE
Jon Hallceb4abb2015-09-25 12:03:06 -07002025 main.log.error( "Discrepancy in candidate lists detected" )
acsmars71adceb2015-08-31 15:09:26 -07002026
2027 # Check that the new leader is not the older leader, which was withdrawn
2028 if newLeader == oldLeader:
2029 newLeaderResult = main.FALSE
2030 main.log.error( "All nodes still see old leader: " + oldLeader +
2031 " as the current leader" )
2032
Jon Hall85794ff2015-07-08 14:12:30 -07002033 utilities.assert_equals(
2034 expect=main.TRUE,
acsmars71adceb2015-08-31 15:09:26 -07002035 actual=newLeaderResult,
2036 onpass="Leadership election passed",
2037 onfail="Something went wrong with Leadership election" )
Jon Hall85794ff2015-07-08 14:12:30 -07002038
acsmars71adceb2015-08-31 15:09:26 -07002039 main.step( "Check that that new leader was the candidate of old leader")
2040 # candidates[ 2 ] should be come the top candidate after withdrawl
2041 correctCandidateResult = main.TRUE
2042 if expectNoLeader:
2043 if newLeader == 'none':
2044 main.log.info( "No leader expected. None found. Pass" )
2045 correctCandidateResult = main.TRUE
2046 else:
2047 main.log.info( "Expected no leader, got: " + str( newLeader ) )
2048 correctCandidateResult = main.FALSE
2049 elif newLeader != oldCandidates[ 2 ]:
2050 correctCandidateResult = main.FALSE
2051 main.log.error( "Candidate " + newLeader + " was elected. " +
2052 oldCandidates[ 2 ] + " should have had priority." )
2053
2054 utilities.assert_equals(
2055 expect=main.TRUE,
2056 actual=correctCandidateResult,
2057 onpass="Correct Candidate Elected",
2058 onfail="Incorrect Candidate Elected" )
2059
Jon Hall85794ff2015-07-08 14:12:30 -07002060 main.step( "Run for election on old leader( just so everyone " +
2061 "is in the hat )" )
acsmars71adceb2015-08-31 15:09:26 -07002062 if oldLeaderCLI is not None:
2063 runResult = oldLeaderCLI.electionTestRun()
Jon Hall85794ff2015-07-08 14:12:30 -07002064 else:
acsmars71adceb2015-08-31 15:09:26 -07002065 main.log.error( "No old leader to re-elect" )
Jon Hall85794ff2015-07-08 14:12:30 -07002066 runResult = main.FALSE
2067 utilities.assert_equals(
2068 expect=main.TRUE,
2069 actual=runResult,
2070 onpass="App re-ran for election",
2071 onfail="App failed to run for election" )
acsmars71adceb2015-08-31 15:09:26 -07002072 main.step(
2073 "Check that oldLeader is a candidate, and leader if only 1 node" )
2074 # verify leader didn't just change
2075 positionResult = main.TRUE
2076 # Get new leaders and candidates, wait if oldLeader is not a candidate yet
Jon Hall85794ff2015-07-08 14:12:30 -07002077
acsmars71adceb2015-08-31 15:09:26 -07002078 # Reset and reuse the new candidate and leaders lists
2079 newAllCandidates = []
2080 newCandidates = []
2081 newLeaders = []
2082 for cli in main.CLIs:
2083 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
2084 if oldLeader not in node: # election might no have finished yet
2085 main.log.info( "Old Leader not elected, waiting 5 seconds to " +
2086 "be sure elections are complete" )
2087 time.sleep(5)
2088 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
2089 if oldLeader not in node: # election still isn't done, errors
2090 main.log.error(
2091 "Old leader was not elected on at least one node" )
2092 positionResult = main.FALSE
2093 newAllCandidates.append( node )
2094 newLeaders.append( node[ 0 ] )
2095 newCandidates = newAllCandidates[ 0 ]
2096
2097 # Check that each node has the same leader. Defines newLeader
2098 if len( set( newLeaders ) ) != 1:
2099 positionResult = main.FALSE
2100 main.log.error( "Nodes have different leaders: " +
2101 str( newLeaders ) )
2102 newLeader = None
Jon Hall85794ff2015-07-08 14:12:30 -07002103 else:
acsmars71adceb2015-08-31 15:09:26 -07002104 newLeader = newLeaders[ 0 ]
2105
2106 # Check that each node's candidate list is the same
2107 for candidates in newAllCandidates:
2108 if set( candidates ) != set( newCandidates ):
2109 newLeaderResult = main.FALSE
Jon Hallceb4abb2015-09-25 12:03:06 -07002110 main.log.error( "Discrepancy in candidate lists detected" )
acsmars71adceb2015-08-31 15:09:26 -07002111
2112 # Check that the re-elected node is last on the candidate List
2113 if oldLeader != newCandidates[ -1 ]:
2114 main.log.error( "Old Leader (" + oldLeader + ") not in the proper position " +
2115 str( newCandidates ) )
2116 positionResult = main.FALSE
Jon Hall85794ff2015-07-08 14:12:30 -07002117
2118 utilities.assert_equals(
2119 expect=main.TRUE,
acsmars71adceb2015-08-31 15:09:26 -07002120 actual=positionResult,
Jon Hall85794ff2015-07-08 14:12:30 -07002121 onpass="Old leader successfully re-ran for election",
2122 onfail="Something went wrong with Leadership election after " +
2123 "the old leader re-ran for election" )
2124
2125 def CASE16( self, main ):
2126 """
2127 Install Distributed Primitives app
2128 """
Jon Halle1a3b752015-07-22 13:02:46 -07002129 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07002130 assert main, "main not defined"
2131 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002132 assert main.CLIs, "main.CLIs not defined"
2133 assert main.nodes, "main.nodes not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07002134
2135 # Variables for the distributed primitives tests
2136 global pCounterName
2137 global iCounterName
2138 global pCounterValue
2139 global iCounterValue
2140 global onosSet
2141 global onosSetName
2142 pCounterName = "TestON-Partitions"
2143 iCounterName = "TestON-inMemory"
2144 pCounterValue = 0
2145 iCounterValue = 0
2146 onosSet = set([])
2147 onosSetName = "TestON-set"
2148
2149 description = "Install Primitives app"
2150 main.case( description )
2151 main.step( "Install Primitives app" )
2152 appName = "org.onosproject.distributedprimitives"
Jon Halle1a3b752015-07-22 13:02:46 -07002153 appResults = main.CLIs[0].activateApp( appName )
Jon Hall85794ff2015-07-08 14:12:30 -07002154 utilities.assert_equals( expect=main.TRUE,
2155 actual=appResults,
2156 onpass="Primitives app activated",
2157 onfail="Primitives app not activated" )
2158
2159 def CASE17( self, main ):
2160 """
2161 Check for basic functionality with distributed primitives
2162 """
Jon Hall85794ff2015-07-08 14:12:30 -07002163 # Make sure variables are defined/set
Jon Halle1a3b752015-07-22 13:02:46 -07002164 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07002165 assert main, "main not defined"
2166 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002167 assert main.CLIs, "main.CLIs not defined"
2168 assert main.nodes, "main.nodes not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07002169 assert pCounterName, "pCounterName not defined"
2170 assert iCounterName, "iCounterName not defined"
2171 assert onosSetName, "onosSetName not defined"
2172 # NOTE: assert fails if value is 0/None/Empty/False
2173 try:
2174 pCounterValue
2175 except NameError:
2176 main.log.error( "pCounterValue not defined, setting to 0" )
2177 pCounterValue = 0
2178 try:
2179 iCounterValue
2180 except NameError:
2181 main.log.error( "iCounterValue not defined, setting to 0" )
2182 iCounterValue = 0
2183 try:
2184 onosSet
2185 except NameError:
2186 main.log.error( "onosSet not defined, setting to empty Set" )
2187 onosSet = set([])
2188 # Variables for the distributed primitives tests. These are local only
2189 addValue = "a"
2190 addAllValue = "a b c d e f"
2191 retainValue = "c d e f"
2192
2193 description = "Check for basic functionality with distributed " +\
2194 "primitives"
2195 main.case( description )
Jon Halle1a3b752015-07-22 13:02:46 -07002196 main.caseExplanation = "Test the methods of the distributed " +\
2197 "primitives (counters and sets) throught the cli"
Jon Hall85794ff2015-07-08 14:12:30 -07002198 # DISTRIBUTED ATOMIC COUNTERS
Jon Halle1a3b752015-07-22 13:02:46 -07002199 # Partitioned counters
2200 main.step( "Increment then get a default counter on each node" )
Jon Hall85794ff2015-07-08 14:12:30 -07002201 pCounters = []
2202 threads = []
2203 addedPValues = []
Jon Halle1a3b752015-07-22 13:02:46 -07002204 for i in range( main.numCtrls ):
2205 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
2206 name="counterAddAndGet-" + str( i ),
Jon Hall85794ff2015-07-08 14:12:30 -07002207 args=[ pCounterName ] )
2208 pCounterValue += 1
2209 addedPValues.append( pCounterValue )
2210 threads.append( t )
2211 t.start()
2212
2213 for t in threads:
2214 t.join()
2215 pCounters.append( t.result )
2216 # Check that counter incremented numController times
2217 pCounterResults = True
2218 for i in addedPValues:
2219 tmpResult = i in pCounters
2220 pCounterResults = pCounterResults and tmpResult
2221 if not tmpResult:
2222 main.log.error( str( i ) + " is not in partitioned "
2223 "counter incremented results" )
2224 utilities.assert_equals( expect=True,
2225 actual=pCounterResults,
2226 onpass="Default counter incremented",
2227 onfail="Error incrementing default" +
2228 " counter" )
2229
Jon Halle1a3b752015-07-22 13:02:46 -07002230 main.step( "Get then Increment a default counter on each node" )
2231 pCounters = []
2232 threads = []
2233 addedPValues = []
2234 for i in range( main.numCtrls ):
2235 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
2236 name="counterGetAndAdd-" + str( i ),
2237 args=[ pCounterName ] )
2238 addedPValues.append( pCounterValue )
2239 pCounterValue += 1
2240 threads.append( t )
2241 t.start()
2242
2243 for t in threads:
2244 t.join()
2245 pCounters.append( t.result )
2246 # Check that counter incremented numController times
2247 pCounterResults = True
2248 for i in addedPValues:
2249 tmpResult = i in pCounters
2250 pCounterResults = pCounterResults and tmpResult
2251 if not tmpResult:
2252 main.log.error( str( i ) + " is not in partitioned "
2253 "counter incremented results" )
2254 utilities.assert_equals( expect=True,
2255 actual=pCounterResults,
2256 onpass="Default counter incremented",
2257 onfail="Error incrementing default" +
2258 " counter" )
2259
2260 main.step( "Counters we added have the correct values" )
2261 incrementCheck = main.Counters.counterCheck( pCounterName, pCounterValue )
2262 utilities.assert_equals( expect=main.TRUE,
2263 actual=incrementCheck,
2264 onpass="Added counters are correct",
2265 onfail="Added counters are incorrect" )
2266
2267 main.step( "Add -8 to then get a default counter on each node" )
2268 pCounters = []
2269 threads = []
2270 addedPValues = []
2271 for i in range( main.numCtrls ):
2272 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
2273 name="counterIncrement-" + str( i ),
2274 args=[ pCounterName ],
2275 kwargs={ "delta": -8 } )
2276 pCounterValue += -8
2277 addedPValues.append( pCounterValue )
2278 threads.append( t )
2279 t.start()
2280
2281 for t in threads:
2282 t.join()
2283 pCounters.append( t.result )
2284 # Check that counter incremented numController times
2285 pCounterResults = True
2286 for i in addedPValues:
2287 tmpResult = i in pCounters
2288 pCounterResults = pCounterResults and tmpResult
2289 if not tmpResult:
2290 main.log.error( str( i ) + " is not in partitioned "
2291 "counter incremented results" )
2292 utilities.assert_equals( expect=True,
2293 actual=pCounterResults,
2294 onpass="Default counter incremented",
2295 onfail="Error incrementing default" +
2296 " counter" )
2297
2298 main.step( "Add 5 to then get a default counter on each node" )
2299 pCounters = []
2300 threads = []
2301 addedPValues = []
2302 for i in range( main.numCtrls ):
2303 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
2304 name="counterIncrement-" + str( i ),
2305 args=[ pCounterName ],
2306 kwargs={ "delta": 5 } )
2307 pCounterValue += 5
2308 addedPValues.append( pCounterValue )
2309 threads.append( t )
2310 t.start()
2311
2312 for t in threads:
2313 t.join()
2314 pCounters.append( t.result )
2315 # Check that counter incremented numController times
2316 pCounterResults = True
2317 for i in addedPValues:
2318 tmpResult = i in pCounters
2319 pCounterResults = pCounterResults and tmpResult
2320 if not tmpResult:
2321 main.log.error( str( i ) + " is not in partitioned "
2322 "counter incremented results" )
2323 utilities.assert_equals( expect=True,
2324 actual=pCounterResults,
2325 onpass="Default counter incremented",
2326 onfail="Error incrementing default" +
2327 " counter" )
2328
2329 main.step( "Get then add 5 to a default counter on each node" )
2330 pCounters = []
2331 threads = []
2332 addedPValues = []
2333 for i in range( main.numCtrls ):
2334 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
2335 name="counterIncrement-" + str( i ),
2336 args=[ pCounterName ],
2337 kwargs={ "delta": 5 } )
2338 addedPValues.append( pCounterValue )
2339 pCounterValue += 5
2340 threads.append( t )
2341 t.start()
2342
2343 for t in threads:
2344 t.join()
2345 pCounters.append( t.result )
2346 # Check that counter incremented numController times
2347 pCounterResults = True
2348 for i in addedPValues:
2349 tmpResult = i in pCounters
2350 pCounterResults = pCounterResults and tmpResult
2351 if not tmpResult:
2352 main.log.error( str( i ) + " is not in partitioned "
2353 "counter incremented results" )
2354 utilities.assert_equals( expect=True,
2355 actual=pCounterResults,
2356 onpass="Default counter incremented",
2357 onfail="Error incrementing default" +
2358 " counter" )
2359
2360 main.step( "Counters we added have the correct values" )
2361 incrementCheck = main.Counters.counterCheck( pCounterName, pCounterValue )
2362 utilities.assert_equals( expect=main.TRUE,
2363 actual=incrementCheck,
2364 onpass="Added counters are correct",
2365 onfail="Added counters are incorrect" )
2366
2367 # In-Memory counters
2368 main.step( "Increment and get an in-memory counter on each node" )
Jon Hall85794ff2015-07-08 14:12:30 -07002369 iCounters = []
2370 addedIValues = []
2371 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002372 for i in range( main.numCtrls ):
2373 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
Jon Hall85794ff2015-07-08 14:12:30 -07002374 name="icounterIncrement-" + str( i ),
2375 args=[ iCounterName ],
2376 kwargs={ "inMemory": True } )
2377 iCounterValue += 1
2378 addedIValues.append( iCounterValue )
2379 threads.append( t )
2380 t.start()
2381
2382 for t in threads:
2383 t.join()
2384 iCounters.append( t.result )
2385 # Check that counter incremented numController times
2386 iCounterResults = True
2387 for i in addedIValues:
2388 tmpResult = i in iCounters
2389 iCounterResults = iCounterResults and tmpResult
2390 if not tmpResult:
2391 main.log.error( str( i ) + " is not in the in-memory "
2392 "counter incremented results" )
2393 utilities.assert_equals( expect=True,
2394 actual=iCounterResults,
Jon Halle1a3b752015-07-22 13:02:46 -07002395 onpass="In-memory counter incremented",
2396 onfail="Error incrementing in-memory" +
Jon Hall85794ff2015-07-08 14:12:30 -07002397 " counter" )
2398
Jon Halle1a3b752015-07-22 13:02:46 -07002399 main.step( "Get then Increment a in-memory counter on each node" )
2400 iCounters = []
2401 threads = []
2402 addedIValues = []
2403 for i in range( main.numCtrls ):
2404 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
2405 name="counterGetAndAdd-" + str( i ),
2406 args=[ iCounterName ],
2407 kwargs={ "inMemory": True } )
2408 addedIValues.append( iCounterValue )
2409 iCounterValue += 1
2410 threads.append( t )
2411 t.start()
2412
2413 for t in threads:
2414 t.join()
2415 iCounters.append( t.result )
2416 # Check that counter incremented numController times
2417 iCounterResults = True
2418 for i in addedIValues:
2419 tmpResult = i in iCounters
2420 iCounterResults = iCounterResults and tmpResult
2421 if not tmpResult:
2422 main.log.error( str( i ) + " is not in in-memory "
2423 "counter incremented results" )
2424 utilities.assert_equals( expect=True,
2425 actual=iCounterResults,
2426 onpass="In-memory counter incremented",
2427 onfail="Error incrementing in-memory" +
2428 " counter" )
2429
2430 main.step( "Counters we added have the correct values" )
2431 incrementCheck = main.Counters.counterCheck( iCounterName, iCounterValue )
2432 utilities.assert_equals( expect=main.TRUE,
2433 actual=incrementCheck,
2434 onpass="Added counters are correct",
2435 onfail="Added counters are incorrect" )
2436
2437 main.step( "Add -8 to then get a in-memory counter on each node" )
2438 iCounters = []
2439 threads = []
2440 addedIValues = []
2441 for i in range( main.numCtrls ):
2442 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
2443 name="counterIncrement-" + str( i ),
2444 args=[ iCounterName ],
2445 kwargs={ "delta": -8, "inMemory": True } )
2446 iCounterValue += -8
2447 addedIValues.append( iCounterValue )
2448 threads.append( t )
2449 t.start()
2450
2451 for t in threads:
2452 t.join()
2453 iCounters.append( t.result )
2454 # Check that counter incremented numController times
2455 iCounterResults = True
2456 for i in addedIValues:
2457 tmpResult = i in iCounters
2458 iCounterResults = iCounterResults and tmpResult
2459 if not tmpResult:
2460 main.log.error( str( i ) + " is not in in-memory "
2461 "counter incremented results" )
2462 utilities.assert_equals( expect=True,
2463 actual=pCounterResults,
2464 onpass="In-memory counter incremented",
2465 onfail="Error incrementing in-memory" +
2466 " counter" )
2467
2468 main.step( "Add 5 to then get a in-memory counter on each node" )
2469 iCounters = []
2470 threads = []
2471 addedIValues = []
2472 for i in range( main.numCtrls ):
2473 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
2474 name="counterIncrement-" + str( i ),
2475 args=[ iCounterName ],
2476 kwargs={ "delta": 5, "inMemory": True } )
2477 iCounterValue += 5
2478 addedIValues.append( iCounterValue )
2479 threads.append( t )
2480 t.start()
2481
2482 for t in threads:
2483 t.join()
2484 iCounters.append( t.result )
2485 # Check that counter incremented numController times
2486 iCounterResults = True
2487 for i in addedIValues:
2488 tmpResult = i in iCounters
2489 iCounterResults = iCounterResults and tmpResult
2490 if not tmpResult:
2491 main.log.error( str( i ) + " is not in in-memory "
2492 "counter incremented results" )
2493 utilities.assert_equals( expect=True,
2494 actual=pCounterResults,
2495 onpass="In-memory counter incremented",
2496 onfail="Error incrementing in-memory" +
2497 " counter" )
2498
2499 main.step( "Get then add 5 to a in-memory counter on each node" )
2500 iCounters = []
2501 threads = []
2502 addedIValues = []
2503 for i in range( main.numCtrls ):
2504 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
2505 name="counterIncrement-" + str( i ),
2506 args=[ iCounterName ],
2507 kwargs={ "delta": 5, "inMemory": True } )
2508 addedIValues.append( iCounterValue )
2509 iCounterValue += 5
2510 threads.append( t )
2511 t.start()
2512
2513 for t in threads:
2514 t.join()
2515 iCounters.append( t.result )
2516 # Check that counter incremented numController times
2517 iCounterResults = True
2518 for i in addedIValues:
2519 tmpResult = i in iCounters
2520 iCounterResults = iCounterResults and tmpResult
2521 if not tmpResult:
2522 main.log.error( str( i ) + " is not in in-memory "
2523 "counter incremented results" )
2524 utilities.assert_equals( expect=True,
2525 actual=iCounterResults,
2526 onpass="In-memory counter incremented",
2527 onfail="Error incrementing in-memory" +
2528 " counter" )
2529
2530 main.step( "Counters we added have the correct values" )
2531 incrementCheck = main.Counters.counterCheck( iCounterName, iCounterValue )
2532 utilities.assert_equals( expect=main.TRUE,
2533 actual=incrementCheck,
2534 onpass="Added counters are correct",
2535 onfail="Added counters are incorrect" )
2536
Jon Hall85794ff2015-07-08 14:12:30 -07002537 main.step( "Check counters are consistant across nodes" )
Jon Hall57b50432015-10-22 10:20:10 -07002538 onosCounters, consistentCounterResults = main.Counters.consistentCheck()
Jon Hall85794ff2015-07-08 14:12:30 -07002539 utilities.assert_equals( expect=main.TRUE,
2540 actual=consistentCounterResults,
2541 onpass="ONOS counters are consistent " +
2542 "across nodes",
2543 onfail="ONOS Counters are inconsistent " +
2544 "across nodes" )
2545
2546 main.step( "Counters we added have the correct values" )
Jon Halle1a3b752015-07-22 13:02:46 -07002547 incrementCheck = main.Counters.counterCheck( iCounterName, iCounterValue )
2548 incrementCheck = incrementCheck and \
2549 main.Counters.counterCheck( iCounterName, iCounterValue )
Jon Hall85794ff2015-07-08 14:12:30 -07002550 utilities.assert_equals( expect=main.TRUE,
Jon Halle1a3b752015-07-22 13:02:46 -07002551 actual=incrementCheck,
Jon Hall85794ff2015-07-08 14:12:30 -07002552 onpass="Added counters are correct",
2553 onfail="Added counters are incorrect" )
2554 # DISTRIBUTED SETS
2555 main.step( "Distributed Set get" )
2556 size = len( onosSet )
2557 getResponses = []
2558 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002559 for i in range( main.numCtrls ):
2560 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07002561 name="setTestGet-" + str( i ),
2562 args=[ onosSetName ] )
2563 threads.append( t )
2564 t.start()
2565 for t in threads:
2566 t.join()
2567 getResponses.append( t.result )
2568
2569 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07002570 for i in range( main.numCtrls ):
Jon Hall85794ff2015-07-08 14:12:30 -07002571 if isinstance( getResponses[ i ], list):
2572 current = set( getResponses[ i ] )
2573 if len( current ) == len( getResponses[ i ] ):
2574 # no repeats
2575 if onosSet != current:
2576 main.log.error( "ONOS" + str( i + 1 ) +
2577 " has incorrect view" +
2578 " of set " + onosSetName + ":\n" +
2579 str( getResponses[ i ] ) )
2580 main.log.debug( "Expected: " + str( onosSet ) )
2581 main.log.debug( "Actual: " + str( current ) )
2582 getResults = main.FALSE
2583 else:
2584 # error, set is not a set
2585 main.log.error( "ONOS" + str( i + 1 ) +
2586 " has repeat elements in" +
2587 " set " + onosSetName + ":\n" +
2588 str( getResponses[ i ] ) )
2589 getResults = main.FALSE
2590 elif getResponses[ i ] == main.ERROR:
2591 getResults = main.FALSE
2592 utilities.assert_equals( expect=main.TRUE,
2593 actual=getResults,
2594 onpass="Set elements are correct",
2595 onfail="Set elements are incorrect" )
2596
2597 main.step( "Distributed Set size" )
2598 sizeResponses = []
2599 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002600 for i in range( main.numCtrls ):
2601 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall85794ff2015-07-08 14:12:30 -07002602 name="setTestSize-" + str( i ),
2603 args=[ onosSetName ] )
2604 threads.append( t )
2605 t.start()
2606 for t in threads:
2607 t.join()
2608 sizeResponses.append( t.result )
2609
2610 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07002611 for i in range( main.numCtrls ):
Jon Hall85794ff2015-07-08 14:12:30 -07002612 if size != sizeResponses[ i ]:
2613 sizeResults = main.FALSE
2614 main.log.error( "ONOS" + str( i + 1 ) +
2615 " expected a size of " + str( size ) +
2616 " for set " + onosSetName +
2617 " but got " + str( sizeResponses[ i ] ) )
2618 utilities.assert_equals( expect=main.TRUE,
2619 actual=sizeResults,
2620 onpass="Set sizes are correct",
2621 onfail="Set sizes are incorrect" )
2622
2623 main.step( "Distributed Set add()" )
2624 onosSet.add( addValue )
2625 addResponses = []
2626 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002627 for i in range( main.numCtrls ):
2628 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall85794ff2015-07-08 14:12:30 -07002629 name="setTestAdd-" + str( i ),
2630 args=[ onosSetName, addValue ] )
2631 threads.append( t )
2632 t.start()
2633 for t in threads:
2634 t.join()
2635 addResponses.append( t.result )
2636
2637 # main.TRUE = successfully changed the set
2638 # main.FALSE = action resulted in no change in set
2639 # main.ERROR - Some error in executing the function
2640 addResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07002641 for i in range( main.numCtrls ):
Jon Hall85794ff2015-07-08 14:12:30 -07002642 if addResponses[ i ] == main.TRUE:
2643 # All is well
2644 pass
2645 elif addResponses[ i ] == main.FALSE:
2646 # Already in set, probably fine
2647 pass
2648 elif addResponses[ i ] == main.ERROR:
2649 # Error in execution
2650 addResults = main.FALSE
2651 else:
2652 # unexpected result
2653 addResults = main.FALSE
2654 if addResults != main.TRUE:
2655 main.log.error( "Error executing set add" )
2656
2657 # Check if set is still correct
2658 size = len( onosSet )
2659 getResponses = []
2660 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002661 for i in range( main.numCtrls ):
2662 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07002663 name="setTestGet-" + str( i ),
2664 args=[ onosSetName ] )
2665 threads.append( t )
2666 t.start()
2667 for t in threads:
2668 t.join()
2669 getResponses.append( t.result )
2670 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07002671 for i in range( main.numCtrls ):
Jon Hall85794ff2015-07-08 14:12:30 -07002672 if isinstance( getResponses[ i ], list):
2673 current = set( getResponses[ i ] )
2674 if len( current ) == len( getResponses[ i ] ):
2675 # no repeats
2676 if onosSet != current:
2677 main.log.error( "ONOS" + str( i + 1 ) +
2678 " has incorrect view" +
2679 " of set " + onosSetName + ":\n" +
2680 str( getResponses[ i ] ) )
2681 main.log.debug( "Expected: " + str( onosSet ) )
2682 main.log.debug( "Actual: " + str( current ) )
2683 getResults = main.FALSE
2684 else:
2685 # error, set is not a set
2686 main.log.error( "ONOS" + str( i + 1 ) +
2687 " has repeat elements in" +
2688 " set " + onosSetName + ":\n" +
2689 str( getResponses[ i ] ) )
2690 getResults = main.FALSE
2691 elif getResponses[ i ] == main.ERROR:
2692 getResults = main.FALSE
2693 sizeResponses = []
2694 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002695 for i in range( main.numCtrls ):
2696 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall85794ff2015-07-08 14:12:30 -07002697 name="setTestSize-" + str( i ),
2698 args=[ onosSetName ] )
2699 threads.append( t )
2700 t.start()
2701 for t in threads:
2702 t.join()
2703 sizeResponses.append( t.result )
2704 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07002705 for i in range( main.numCtrls ):
Jon Hall85794ff2015-07-08 14:12:30 -07002706 if size != sizeResponses[ i ]:
2707 sizeResults = main.FALSE
2708 main.log.error( "ONOS" + str( i + 1 ) +
2709 " expected a size of " + str( size ) +
2710 " for set " + onosSetName +
2711 " but got " + str( sizeResponses[ i ] ) )
2712 addResults = addResults and getResults and sizeResults
2713 utilities.assert_equals( expect=main.TRUE,
2714 actual=addResults,
2715 onpass="Set add correct",
2716 onfail="Set add was incorrect" )
2717
2718 main.step( "Distributed Set addAll()" )
2719 onosSet.update( addAllValue.split() )
2720 addResponses = []
2721 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002722 for i in range( main.numCtrls ):
2723 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall85794ff2015-07-08 14:12:30 -07002724 name="setTestAddAll-" + str( i ),
2725 args=[ onosSetName, addAllValue ] )
2726 threads.append( t )
2727 t.start()
2728 for t in threads:
2729 t.join()
2730 addResponses.append( t.result )
2731
2732 # main.TRUE = successfully changed the set
2733 # main.FALSE = action resulted in no change in set
2734 # main.ERROR - Some error in executing the function
2735 addAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07002736 for i in range( main.numCtrls ):
Jon Hall85794ff2015-07-08 14:12:30 -07002737 if addResponses[ i ] == main.TRUE:
2738 # All is well
2739 pass
2740 elif addResponses[ i ] == main.FALSE:
2741 # Already in set, probably fine
2742 pass
2743 elif addResponses[ i ] == main.ERROR:
2744 # Error in execution
2745 addAllResults = main.FALSE
2746 else:
2747 # unexpected result
2748 addAllResults = main.FALSE
2749 if addAllResults != main.TRUE:
2750 main.log.error( "Error executing set addAll" )
2751
2752 # Check if set is still correct
2753 size = len( onosSet )
2754 getResponses = []
2755 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002756 for i in range( main.numCtrls ):
2757 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07002758 name="setTestGet-" + str( i ),
2759 args=[ onosSetName ] )
2760 threads.append( t )
2761 t.start()
2762 for t in threads:
2763 t.join()
2764 getResponses.append( t.result )
2765 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07002766 for i in range( main.numCtrls ):
Jon Hall85794ff2015-07-08 14:12:30 -07002767 if isinstance( getResponses[ i ], list):
2768 current = set( getResponses[ i ] )
2769 if len( current ) == len( getResponses[ i ] ):
2770 # no repeats
2771 if onosSet != current:
2772 main.log.error( "ONOS" + str( i + 1 ) +
2773 " has incorrect view" +
2774 " of set " + onosSetName + ":\n" +
2775 str( getResponses[ i ] ) )
2776 main.log.debug( "Expected: " + str( onosSet ) )
2777 main.log.debug( "Actual: " + str( current ) )
2778 getResults = main.FALSE
2779 else:
2780 # error, set is not a set
2781 main.log.error( "ONOS" + str( i + 1 ) +
2782 " has repeat elements in" +
2783 " set " + onosSetName + ":\n" +
2784 str( getResponses[ i ] ) )
2785 getResults = main.FALSE
2786 elif getResponses[ i ] == main.ERROR:
2787 getResults = main.FALSE
2788 sizeResponses = []
2789 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002790 for i in range( main.numCtrls ):
2791 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall85794ff2015-07-08 14:12:30 -07002792 name="setTestSize-" + str( i ),
2793 args=[ onosSetName ] )
2794 threads.append( t )
2795 t.start()
2796 for t in threads:
2797 t.join()
2798 sizeResponses.append( t.result )
2799 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07002800 for i in range( main.numCtrls ):
Jon Hall85794ff2015-07-08 14:12:30 -07002801 if size != sizeResponses[ i ]:
2802 sizeResults = main.FALSE
2803 main.log.error( "ONOS" + str( i + 1 ) +
2804 " expected a size of " + str( size ) +
2805 " for set " + onosSetName +
2806 " but got " + str( sizeResponses[ i ] ) )
2807 addAllResults = addAllResults and getResults and sizeResults
2808 utilities.assert_equals( expect=main.TRUE,
2809 actual=addAllResults,
2810 onpass="Set addAll correct",
2811 onfail="Set addAll was incorrect" )
2812
2813 main.step( "Distributed Set contains()" )
2814 containsResponses = []
2815 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002816 for i in range( main.numCtrls ):
2817 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07002818 name="setContains-" + str( i ),
2819 args=[ onosSetName ],
2820 kwargs={ "values": addValue } )
2821 threads.append( t )
2822 t.start()
2823 for t in threads:
2824 t.join()
2825 # NOTE: This is the tuple
2826 containsResponses.append( t.result )
2827
2828 containsResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07002829 for i in range( main.numCtrls ):
Jon Hall85794ff2015-07-08 14:12:30 -07002830 if containsResponses[ i ] == main.ERROR:
2831 containsResults = main.FALSE
2832 else:
2833 containsResults = containsResults and\
2834 containsResponses[ i ][ 1 ]
2835 utilities.assert_equals( expect=main.TRUE,
2836 actual=containsResults,
2837 onpass="Set contains is functional",
2838 onfail="Set contains failed" )
2839
2840 main.step( "Distributed Set containsAll()" )
2841 containsAllResponses = []
2842 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002843 for i in range( main.numCtrls ):
2844 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07002845 name="setContainsAll-" + str( i ),
2846 args=[ onosSetName ],
2847 kwargs={ "values": addAllValue } )
2848 threads.append( t )
2849 t.start()
2850 for t in threads:
2851 t.join()
2852 # NOTE: This is the tuple
2853 containsAllResponses.append( t.result )
2854
2855 containsAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07002856 for i in range( main.numCtrls ):
Jon Hall85794ff2015-07-08 14:12:30 -07002857 if containsResponses[ i ] == main.ERROR:
2858 containsResults = main.FALSE
2859 else:
2860 containsResults = containsResults and\
2861 containsResponses[ i ][ 1 ]
2862 utilities.assert_equals( expect=main.TRUE,
2863 actual=containsAllResults,
2864 onpass="Set containsAll is functional",
2865 onfail="Set containsAll failed" )
2866
2867 main.step( "Distributed Set remove()" )
2868 onosSet.remove( addValue )
2869 removeResponses = []
2870 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002871 for i in range( main.numCtrls ):
2872 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall85794ff2015-07-08 14:12:30 -07002873 name="setTestRemove-" + str( i ),
2874 args=[ onosSetName, addValue ] )
2875 threads.append( t )
2876 t.start()
2877 for t in threads:
2878 t.join()
2879 removeResponses.append( t.result )
2880
2881 # main.TRUE = successfully changed the set
2882 # main.FALSE = action resulted in no change in set
2883 # main.ERROR - Some error in executing the function
2884 removeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07002885 for i in range( main.numCtrls ):
Jon Hall85794ff2015-07-08 14:12:30 -07002886 if removeResponses[ i ] == main.TRUE:
2887 # All is well
2888 pass
2889 elif removeResponses[ i ] == main.FALSE:
2890 # not in set, probably fine
2891 pass
2892 elif removeResponses[ i ] == main.ERROR:
2893 # Error in execution
2894 removeResults = main.FALSE
2895 else:
2896 # unexpected result
2897 removeResults = main.FALSE
2898 if removeResults != main.TRUE:
2899 main.log.error( "Error executing set remove" )
2900
2901 # Check if set is still correct
2902 size = len( onosSet )
2903 getResponses = []
2904 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002905 for i in range( main.numCtrls ):
2906 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07002907 name="setTestGet-" + str( i ),
2908 args=[ onosSetName ] )
2909 threads.append( t )
2910 t.start()
2911 for t in threads:
2912 t.join()
2913 getResponses.append( t.result )
2914 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07002915 for i in range( main.numCtrls ):
Jon Hall85794ff2015-07-08 14:12:30 -07002916 if isinstance( getResponses[ i ], list):
2917 current = set( getResponses[ i ] )
2918 if len( current ) == len( getResponses[ i ] ):
2919 # no repeats
2920 if onosSet != current:
2921 main.log.error( "ONOS" + str( i + 1 ) +
2922 " has incorrect view" +
2923 " of set " + onosSetName + ":\n" +
2924 str( getResponses[ i ] ) )
2925 main.log.debug( "Expected: " + str( onosSet ) )
2926 main.log.debug( "Actual: " + str( current ) )
2927 getResults = main.FALSE
2928 else:
2929 # error, set is not a set
2930 main.log.error( "ONOS" + str( i + 1 ) +
2931 " has repeat elements in" +
2932 " set " + onosSetName + ":\n" +
2933 str( getResponses[ i ] ) )
2934 getResults = main.FALSE
2935 elif getResponses[ i ] == main.ERROR:
2936 getResults = main.FALSE
2937 sizeResponses = []
2938 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002939 for i in range( main.numCtrls ):
2940 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall85794ff2015-07-08 14:12:30 -07002941 name="setTestSize-" + str( i ),
2942 args=[ onosSetName ] )
2943 threads.append( t )
2944 t.start()
2945 for t in threads:
2946 t.join()
2947 sizeResponses.append( t.result )
2948 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07002949 for i in range( main.numCtrls ):
Jon Hall85794ff2015-07-08 14:12:30 -07002950 if size != sizeResponses[ i ]:
2951 sizeResults = main.FALSE
2952 main.log.error( "ONOS" + str( i + 1 ) +
2953 " expected a size of " + str( size ) +
2954 " for set " + onosSetName +
2955 " but got " + str( sizeResponses[ i ] ) )
2956 removeResults = removeResults and getResults and sizeResults
2957 utilities.assert_equals( expect=main.TRUE,
2958 actual=removeResults,
2959 onpass="Set remove correct",
2960 onfail="Set remove was incorrect" )
2961
2962 main.step( "Distributed Set removeAll()" )
2963 onosSet.difference_update( addAllValue.split() )
2964 removeAllResponses = []
2965 threads = []
2966 try:
Jon Halle1a3b752015-07-22 13:02:46 -07002967 for i in range( main.numCtrls ):
2968 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall85794ff2015-07-08 14:12:30 -07002969 name="setTestRemoveAll-" + str( i ),
2970 args=[ onosSetName, addAllValue ] )
2971 threads.append( t )
2972 t.start()
2973 for t in threads:
2974 t.join()
2975 removeAllResponses.append( t.result )
2976 except Exception, e:
2977 main.log.exception(e)
2978
2979 # main.TRUE = successfully changed the set
2980 # main.FALSE = action resulted in no change in set
2981 # main.ERROR - Some error in executing the function
2982 removeAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07002983 for i in range( main.numCtrls ):
Jon Hall85794ff2015-07-08 14:12:30 -07002984 if removeAllResponses[ i ] == main.TRUE:
2985 # All is well
2986 pass
2987 elif removeAllResponses[ i ] == main.FALSE:
2988 # not in set, probably fine
2989 pass
2990 elif removeAllResponses[ i ] == main.ERROR:
2991 # Error in execution
2992 removeAllResults = main.FALSE
2993 else:
2994 # unexpected result
2995 removeAllResults = main.FALSE
2996 if removeAllResults != main.TRUE:
2997 main.log.error( "Error executing set removeAll" )
2998
2999 # Check if set is still correct
3000 size = len( onosSet )
3001 getResponses = []
3002 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003003 for i in range( main.numCtrls ):
3004 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07003005 name="setTestGet-" + str( i ),
3006 args=[ onosSetName ] )
3007 threads.append( t )
3008 t.start()
3009 for t in threads:
3010 t.join()
3011 getResponses.append( t.result )
3012 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003013 for i in range( main.numCtrls ):
Jon Hall85794ff2015-07-08 14:12:30 -07003014 if isinstance( getResponses[ i ], list):
3015 current = set( getResponses[ i ] )
3016 if len( current ) == len( getResponses[ i ] ):
3017 # no repeats
3018 if onosSet != current:
3019 main.log.error( "ONOS" + str( i + 1 ) +
3020 " has incorrect view" +
3021 " of set " + onosSetName + ":\n" +
3022 str( getResponses[ i ] ) )
3023 main.log.debug( "Expected: " + str( onosSet ) )
3024 main.log.debug( "Actual: " + str( current ) )
3025 getResults = main.FALSE
3026 else:
3027 # error, set is not a set
3028 main.log.error( "ONOS" + str( i + 1 ) +
3029 " has repeat elements in" +
3030 " set " + onosSetName + ":\n" +
3031 str( getResponses[ i ] ) )
3032 getResults = main.FALSE
3033 elif getResponses[ i ] == main.ERROR:
3034 getResults = main.FALSE
3035 sizeResponses = []
3036 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003037 for i in range( main.numCtrls ):
3038 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall85794ff2015-07-08 14:12:30 -07003039 name="setTestSize-" + str( i ),
3040 args=[ onosSetName ] )
3041 threads.append( t )
3042 t.start()
3043 for t in threads:
3044 t.join()
3045 sizeResponses.append( t.result )
3046 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003047 for i in range( main.numCtrls ):
Jon Hall85794ff2015-07-08 14:12:30 -07003048 if size != sizeResponses[ i ]:
3049 sizeResults = main.FALSE
3050 main.log.error( "ONOS" + str( i + 1 ) +
3051 " expected a size of " + str( size ) +
3052 " for set " + onosSetName +
3053 " but got " + str( sizeResponses[ i ] ) )
3054 removeAllResults = removeAllResults and getResults and sizeResults
3055 utilities.assert_equals( expect=main.TRUE,
3056 actual=removeAllResults,
3057 onpass="Set removeAll correct",
3058 onfail="Set removeAll was incorrect" )
3059
3060 main.step( "Distributed Set addAll()" )
3061 onosSet.update( addAllValue.split() )
3062 addResponses = []
3063 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003064 for i in range( main.numCtrls ):
3065 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall85794ff2015-07-08 14:12:30 -07003066 name="setTestAddAll-" + str( i ),
3067 args=[ onosSetName, addAllValue ] )
3068 threads.append( t )
3069 t.start()
3070 for t in threads:
3071 t.join()
3072 addResponses.append( t.result )
3073
3074 # main.TRUE = successfully changed the set
3075 # main.FALSE = action resulted in no change in set
3076 # main.ERROR - Some error in executing the function
3077 addAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003078 for i in range( main.numCtrls ):
Jon Hall85794ff2015-07-08 14:12:30 -07003079 if addResponses[ i ] == main.TRUE:
3080 # All is well
3081 pass
3082 elif addResponses[ i ] == main.FALSE:
3083 # Already in set, probably fine
3084 pass
3085 elif addResponses[ i ] == main.ERROR:
3086 # Error in execution
3087 addAllResults = main.FALSE
3088 else:
3089 # unexpected result
3090 addAllResults = main.FALSE
3091 if addAllResults != main.TRUE:
3092 main.log.error( "Error executing set addAll" )
3093
3094 # Check if set is still correct
3095 size = len( onosSet )
3096 getResponses = []
3097 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003098 for i in range( main.numCtrls ):
3099 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07003100 name="setTestGet-" + str( i ),
3101 args=[ onosSetName ] )
3102 threads.append( t )
3103 t.start()
3104 for t in threads:
3105 t.join()
3106 getResponses.append( t.result )
3107 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003108 for i in range( main.numCtrls ):
Jon Hall85794ff2015-07-08 14:12:30 -07003109 if isinstance( getResponses[ i ], list):
3110 current = set( getResponses[ i ] )
3111 if len( current ) == len( getResponses[ i ] ):
3112 # no repeats
3113 if onosSet != current:
3114 main.log.error( "ONOS" + str( i + 1 ) +
3115 " has incorrect view" +
3116 " of set " + onosSetName + ":\n" +
3117 str( getResponses[ i ] ) )
3118 main.log.debug( "Expected: " + str( onosSet ) )
3119 main.log.debug( "Actual: " + str( current ) )
3120 getResults = main.FALSE
3121 else:
3122 # error, set is not a set
3123 main.log.error( "ONOS" + str( i + 1 ) +
3124 " has repeat elements in" +
3125 " set " + onosSetName + ":\n" +
3126 str( getResponses[ i ] ) )
3127 getResults = main.FALSE
3128 elif getResponses[ i ] == main.ERROR:
3129 getResults = main.FALSE
3130 sizeResponses = []
3131 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003132 for i in range( main.numCtrls ):
3133 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall85794ff2015-07-08 14:12:30 -07003134 name="setTestSize-" + str( i ),
3135 args=[ onosSetName ] )
3136 threads.append( t )
3137 t.start()
3138 for t in threads:
3139 t.join()
3140 sizeResponses.append( t.result )
3141 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003142 for i in range( main.numCtrls ):
Jon Hall85794ff2015-07-08 14:12:30 -07003143 if size != sizeResponses[ i ]:
3144 sizeResults = main.FALSE
3145 main.log.error( "ONOS" + str( i + 1 ) +
3146 " expected a size of " + str( size ) +
3147 " for set " + onosSetName +
3148 " but got " + str( sizeResponses[ i ] ) )
3149 addAllResults = addAllResults and getResults and sizeResults
3150 utilities.assert_equals( expect=main.TRUE,
3151 actual=addAllResults,
3152 onpass="Set addAll correct",
3153 onfail="Set addAll was incorrect" )
3154
3155 main.step( "Distributed Set clear()" )
3156 onosSet.clear()
3157 clearResponses = []
3158 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003159 for i in range( main.numCtrls ):
3160 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall85794ff2015-07-08 14:12:30 -07003161 name="setTestClear-" + str( i ),
3162 args=[ onosSetName, " "], # Values doesn't matter
3163 kwargs={ "clear": True } )
3164 threads.append( t )
3165 t.start()
3166 for t in threads:
3167 t.join()
3168 clearResponses.append( t.result )
3169
3170 # main.TRUE = successfully changed the set
3171 # main.FALSE = action resulted in no change in set
3172 # main.ERROR - Some error in executing the function
3173 clearResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003174 for i in range( main.numCtrls ):
Jon Hall85794ff2015-07-08 14:12:30 -07003175 if clearResponses[ i ] == main.TRUE:
3176 # All is well
3177 pass
3178 elif clearResponses[ i ] == main.FALSE:
3179 # Nothing set, probably fine
3180 pass
3181 elif clearResponses[ i ] == main.ERROR:
3182 # Error in execution
3183 clearResults = main.FALSE
3184 else:
3185 # unexpected result
3186 clearResults = main.FALSE
3187 if clearResults != main.TRUE:
3188 main.log.error( "Error executing set clear" )
3189
3190 # Check if set is still correct
3191 size = len( onosSet )
3192 getResponses = []
3193 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003194 for i in range( main.numCtrls ):
3195 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07003196 name="setTestGet-" + str( i ),
3197 args=[ onosSetName ] )
3198 threads.append( t )
3199 t.start()
3200 for t in threads:
3201 t.join()
3202 getResponses.append( t.result )
3203 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003204 for i in range( main.numCtrls ):
Jon Hall85794ff2015-07-08 14:12:30 -07003205 if isinstance( getResponses[ i ], list):
3206 current = set( getResponses[ i ] )
3207 if len( current ) == len( getResponses[ i ] ):
3208 # no repeats
3209 if onosSet != current:
3210 main.log.error( "ONOS" + str( i + 1 ) +
3211 " has incorrect view" +
3212 " of set " + onosSetName + ":\n" +
3213 str( getResponses[ i ] ) )
3214 main.log.debug( "Expected: " + str( onosSet ) )
3215 main.log.debug( "Actual: " + str( current ) )
3216 getResults = main.FALSE
3217 else:
3218 # error, set is not a set
3219 main.log.error( "ONOS" + str( i + 1 ) +
3220 " has repeat elements in" +
3221 " set " + onosSetName + ":\n" +
3222 str( getResponses[ i ] ) )
3223 getResults = main.FALSE
3224 elif getResponses[ i ] == main.ERROR:
3225 getResults = main.FALSE
3226 sizeResponses = []
3227 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003228 for i in range( main.numCtrls ):
3229 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall85794ff2015-07-08 14:12:30 -07003230 name="setTestSize-" + str( i ),
3231 args=[ onosSetName ] )
3232 threads.append( t )
3233 t.start()
3234 for t in threads:
3235 t.join()
3236 sizeResponses.append( t.result )
3237 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003238 for i in range( main.numCtrls ):
Jon Hall85794ff2015-07-08 14:12:30 -07003239 if size != sizeResponses[ i ]:
3240 sizeResults = main.FALSE
3241 main.log.error( "ONOS" + str( i + 1 ) +
3242 " expected a size of " + str( size ) +
3243 " for set " + onosSetName +
3244 " but got " + str( sizeResponses[ i ] ) )
3245 clearResults = clearResults and getResults and sizeResults
3246 utilities.assert_equals( expect=main.TRUE,
3247 actual=clearResults,
3248 onpass="Set clear correct",
3249 onfail="Set clear was incorrect" )
3250
3251 main.step( "Distributed Set addAll()" )
3252 onosSet.update( addAllValue.split() )
3253 addResponses = []
3254 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003255 for i in range( main.numCtrls ):
3256 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall85794ff2015-07-08 14:12:30 -07003257 name="setTestAddAll-" + str( i ),
3258 args=[ onosSetName, addAllValue ] )
3259 threads.append( t )
3260 t.start()
3261 for t in threads:
3262 t.join()
3263 addResponses.append( t.result )
3264
3265 # main.TRUE = successfully changed the set
3266 # main.FALSE = action resulted in no change in set
3267 # main.ERROR - Some error in executing the function
3268 addAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003269 for i in range( main.numCtrls ):
Jon Hall85794ff2015-07-08 14:12:30 -07003270 if addResponses[ i ] == main.TRUE:
3271 # All is well
3272 pass
3273 elif addResponses[ i ] == main.FALSE:
3274 # Already in set, probably fine
3275 pass
3276 elif addResponses[ i ] == main.ERROR:
3277 # Error in execution
3278 addAllResults = main.FALSE
3279 else:
3280 # unexpected result
3281 addAllResults = main.FALSE
3282 if addAllResults != main.TRUE:
3283 main.log.error( "Error executing set addAll" )
3284
3285 # Check if set is still correct
3286 size = len( onosSet )
3287 getResponses = []
3288 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003289 for i in range( main.numCtrls ):
3290 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07003291 name="setTestGet-" + str( i ),
3292 args=[ onosSetName ] )
3293 threads.append( t )
3294 t.start()
3295 for t in threads:
3296 t.join()
3297 getResponses.append( t.result )
3298 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003299 for i in range( main.numCtrls ):
Jon Hall85794ff2015-07-08 14:12:30 -07003300 if isinstance( getResponses[ i ], list):
3301 current = set( getResponses[ i ] )
3302 if len( current ) == len( getResponses[ i ] ):
3303 # no repeats
3304 if onosSet != current:
3305 main.log.error( "ONOS" + str( i + 1 ) +
3306 " has incorrect view" +
3307 " of set " + onosSetName + ":\n" +
3308 str( getResponses[ i ] ) )
3309 main.log.debug( "Expected: " + str( onosSet ) )
3310 main.log.debug( "Actual: " + str( current ) )
3311 getResults = main.FALSE
3312 else:
3313 # error, set is not a set
3314 main.log.error( "ONOS" + str( i + 1 ) +
3315 " has repeat elements in" +
3316 " set " + onosSetName + ":\n" +
3317 str( getResponses[ i ] ) )
3318 getResults = main.FALSE
3319 elif getResponses[ i ] == main.ERROR:
3320 getResults = main.FALSE
3321 sizeResponses = []
3322 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003323 for i in range( main.numCtrls ):
3324 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall85794ff2015-07-08 14:12:30 -07003325 name="setTestSize-" + str( i ),
3326 args=[ onosSetName ] )
3327 threads.append( t )
3328 t.start()
3329 for t in threads:
3330 t.join()
3331 sizeResponses.append( t.result )
3332 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003333 for i in range( main.numCtrls ):
Jon Hall85794ff2015-07-08 14:12:30 -07003334 if size != sizeResponses[ i ]:
3335 sizeResults = main.FALSE
3336 main.log.error( "ONOS" + str( i + 1 ) +
3337 " expected a size of " + str( size ) +
3338 " for set " + onosSetName +
3339 " but got " + str( sizeResponses[ i ] ) )
3340 addAllResults = addAllResults and getResults and sizeResults
3341 utilities.assert_equals( expect=main.TRUE,
3342 actual=addAllResults,
3343 onpass="Set addAll correct",
3344 onfail="Set addAll was incorrect" )
3345
3346 main.step( "Distributed Set retain()" )
3347 onosSet.intersection_update( retainValue.split() )
3348 retainResponses = []
3349 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003350 for i in range( main.numCtrls ):
3351 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall85794ff2015-07-08 14:12:30 -07003352 name="setTestRetain-" + str( i ),
3353 args=[ onosSetName, retainValue ],
3354 kwargs={ "retain": True } )
3355 threads.append( t )
3356 t.start()
3357 for t in threads:
3358 t.join()
3359 retainResponses.append( t.result )
3360
3361 # main.TRUE = successfully changed the set
3362 # main.FALSE = action resulted in no change in set
3363 # main.ERROR - Some error in executing the function
3364 retainResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003365 for i in range( main.numCtrls ):
Jon Hall85794ff2015-07-08 14:12:30 -07003366 if retainResponses[ i ] == main.TRUE:
3367 # All is well
3368 pass
3369 elif retainResponses[ i ] == main.FALSE:
3370 # Already in set, probably fine
3371 pass
3372 elif retainResponses[ i ] == main.ERROR:
3373 # Error in execution
3374 retainResults = main.FALSE
3375 else:
3376 # unexpected result
3377 retainResults = main.FALSE
3378 if retainResults != main.TRUE:
3379 main.log.error( "Error executing set retain" )
3380
3381 # Check if set is still correct
3382 size = len( onosSet )
3383 getResponses = []
3384 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003385 for i in range( main.numCtrls ):
3386 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07003387 name="setTestGet-" + str( i ),
3388 args=[ onosSetName ] )
3389 threads.append( t )
3390 t.start()
3391 for t in threads:
3392 t.join()
3393 getResponses.append( t.result )
3394 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003395 for i in range( main.numCtrls ):
Jon Hall85794ff2015-07-08 14:12:30 -07003396 if isinstance( getResponses[ i ], list):
3397 current = set( getResponses[ i ] )
3398 if len( current ) == len( getResponses[ i ] ):
3399 # no repeats
3400 if onosSet != current:
3401 main.log.error( "ONOS" + str( i + 1 ) +
3402 " has incorrect view" +
3403 " of set " + onosSetName + ":\n" +
3404 str( getResponses[ i ] ) )
3405 main.log.debug( "Expected: " + str( onosSet ) )
3406 main.log.debug( "Actual: " + str( current ) )
3407 getResults = main.FALSE
3408 else:
3409 # error, set is not a set
3410 main.log.error( "ONOS" + str( i + 1 ) +
3411 " has repeat elements in" +
3412 " set " + onosSetName + ":\n" +
3413 str( getResponses[ i ] ) )
3414 getResults = main.FALSE
3415 elif getResponses[ i ] == main.ERROR:
3416 getResults = main.FALSE
3417 sizeResponses = []
3418 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003419 for i in range( main.numCtrls ):
3420 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall85794ff2015-07-08 14:12:30 -07003421 name="setTestSize-" + str( i ),
3422 args=[ onosSetName ] )
3423 threads.append( t )
3424 t.start()
3425 for t in threads:
3426 t.join()
3427 sizeResponses.append( t.result )
3428 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003429 for i in range( main.numCtrls ):
Jon Hall85794ff2015-07-08 14:12:30 -07003430 if size != sizeResponses[ i ]:
3431 sizeResults = main.FALSE
3432 main.log.error( "ONOS" + str( i + 1 ) +
3433 " expected a size of " +
3434 str( size ) + " for set " + onosSetName +
3435 " but got " + str( sizeResponses[ i ] ) )
3436 retainResults = retainResults and getResults and sizeResults
3437 utilities.assert_equals( expect=main.TRUE,
3438 actual=retainResults,
3439 onpass="Set retain correct",
3440 onfail="Set retain was incorrect" )
3441
Jon Hall2a5002c2015-08-21 16:49:11 -07003442 # Transactional maps
3443 main.step( "Partitioned Transactional maps put" )
3444 tMapValue = "Testing"
3445 numKeys = 100
3446 putResult = True
3447 putResponses = main.CLIs[ 0 ].transactionalMapPut( numKeys, tMapValue )
3448 if len( putResponses ) == 100:
3449 for i in putResponses:
3450 if putResponses[ i ][ 'value' ] != tMapValue:
3451 putResult = False
3452 else:
3453 putResult = False
3454 if not putResult:
3455 main.log.debug( "Put response values: " + str( putResponses ) )
3456 utilities.assert_equals( expect=True,
3457 actual=putResult,
3458 onpass="Partitioned Transactional Map put successful",
3459 onfail="Partitioned Transactional Map put values are incorrect" )
3460
3461 main.step( "Partitioned Transactional maps get" )
3462 getCheck = True
3463 for n in range( 1, numKeys + 1 ):
3464 getResponses = []
3465 threads = []
3466 valueCheck = True
3467 for i in range( main.numCtrls ):
3468 t = main.Thread( target=main.CLIs[i].transactionalMapGet,
3469 name="TMap-get-" + str( i ),
3470 args=[ "Key" + str ( n ) ] )
3471 threads.append( t )
3472 t.start()
3473 for t in threads:
3474 t.join()
3475 getResponses.append( t.result )
3476 for node in getResponses:
3477 if node != tMapValue:
3478 valueCheck = False
3479 if not valueCheck:
3480 main.log.warn( "Values for key 'Key" + str( n ) + "' do not match:" )
3481 main.log.warn( getResponses )
3482 getCheck = getCheck and valueCheck
3483 utilities.assert_equals( expect=True,
3484 actual=getCheck,
3485 onpass="Partitioned Transactional Map get values were correct",
3486 onfail="Partitioned Transactional Map values incorrect" )
3487
3488 main.step( "In-memory Transactional maps put" )
3489 tMapValue = "Testing"
3490 numKeys = 100
3491 putResult = True
3492 putResponses = main.CLIs[ 0 ].transactionalMapPut( numKeys, tMapValue, inMemory=True )
3493 if len( putResponses ) == 100:
3494 for i in putResponses:
3495 if putResponses[ i ][ 'value' ] != tMapValue:
3496 putResult = False
3497 else:
3498 putResult = False
3499 if not putResult:
3500 main.log.debug( "Put response values: " + str( putResponses ) )
3501 utilities.assert_equals( expect=True,
3502 actual=putResult,
3503 onpass="In-Memory Transactional Map put successful",
3504 onfail="In-Memory Transactional Map put values are incorrect" )
3505
3506 main.step( "In-Memory Transactional maps get" )
3507 getCheck = True
3508 for n in range( 1, numKeys + 1 ):
3509 getResponses = []
3510 threads = []
3511 valueCheck = True
3512 for i in range( main.numCtrls ):
3513 t = main.Thread( target=main.CLIs[i].transactionalMapGet,
3514 name="TMap-get-" + str( i ),
3515 args=[ "Key" + str ( n ) ],
3516 kwargs={ "inMemory": True } )
3517 threads.append( t )
3518 t.start()
3519 for t in threads:
3520 t.join()
3521 getResponses.append( t.result )
3522 for node in getResponses:
3523 if node != tMapValue:
3524 valueCheck = False
3525 if not valueCheck:
3526 main.log.warn( "Values for key 'Key" + str( n ) + "' do not match:" )
3527 main.log.warn( getResponses )
3528 getCheck = getCheck and valueCheck
3529 utilities.assert_equals( expect=True,
3530 actual=getCheck,
3531 onpass="In-Memory Transactional Map get values were correct",
3532 onfail="In-Memory Transactional Map values incorrect" )