blob: d1f413322ac6596c5ba2ed2893078e8d930f3a67 [file] [log] [blame]
Jon Hall5cf14d52015-07-16 12:15:19 -07001"""
2Description: This test is to determine if ONOS can handle
3 all of it's nodes restarting
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 HAclusterRestart:
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 Hall5cf14d52015-07-16 12:15:19 -070051 main.log.info( "ONOS HA test: Restart all ONOS nodes - " +
52 "initialization" )
53 main.case( "Setting up test environment" )
Jon Hall783bbf92015-07-23 14:33:19 -070054 main.caseExplanation = "Setup the test environment including " +\
Jon Hall5cf14d52015-07-16 12:15:19 -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 )
70 # set global variables
Jon Hall5cf14d52015-07-16 12:15:19 -070071 global ONOS1Port
72 global ONOS2Port
73 global ONOS3Port
74 global ONOS4Port
75 global ONOS5Port
76 global ONOS6Port
77 global ONOS7Port
78 # These are for csv plotting in jenkins
79 global labels
80 global data
81 labels = []
82 data = []
83
84 # FIXME: just get controller port from params?
85 # TODO: do we really need all these?
86 ONOS1Port = main.params[ 'CTRL' ][ 'port1' ]
87 ONOS2Port = main.params[ 'CTRL' ][ 'port2' ]
88 ONOS3Port = main.params[ 'CTRL' ][ 'port3' ]
89 ONOS4Port = main.params[ 'CTRL' ][ 'port4' ]
90 ONOS5Port = main.params[ 'CTRL' ][ 'port5' ]
91 ONOS6Port = main.params[ 'CTRL' ][ 'port6' ]
92 ONOS7Port = main.params[ 'CTRL' ][ 'port7' ]
93
Jon Halle1a3b752015-07-22 13:02:46 -070094 try:
95 fileName = "Counters"
96 path = main.params[ 'imports' ][ 'path' ]
97 main.Counters = imp.load_source( fileName,
98 path + fileName + ".py" )
99 except Exception as e:
100 main.log.exception( e )
101 main.cleanup()
102 main.exit()
103
104 main.CLIs = []
105 main.nodes = []
Jon Hall5cf14d52015-07-16 12:15:19 -0700106 ipList = []
Jon Halle1a3b752015-07-22 13:02:46 -0700107 for i in range( 1, main.numCtrls + 1 ):
108 try:
109 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
110 main.nodes.append( getattr( main, 'ONOS' + str( i ) ) )
111 ipList.append( main.nodes[ -1 ].ip_address )
112 except AttributeError:
113 break
Jon Hall5cf14d52015-07-16 12:15:19 -0700114
115 main.step( "Create cell file" )
116 cellAppString = main.params[ 'ENV' ][ 'appString' ]
117 main.ONOSbench.createCellFile( main.ONOSbench.ip_address, cellName,
118 main.Mininet1.ip_address,
119 cellAppString, ipList )
120 main.step( "Applying cell variable to environment" )
121 cellResult = main.ONOSbench.setCell( cellName )
122 verifyResult = main.ONOSbench.verifyCell()
123
124 # FIXME:this is short term fix
125 main.log.info( "Removing raft logs" )
126 main.ONOSbench.onosRemoveRaftLogs()
127
128 main.log.info( "Uninstalling ONOS" )
Jon Halle1a3b752015-07-22 13:02:46 -0700129 for node in main.nodes:
Jon Hall5cf14d52015-07-16 12:15:19 -0700130 main.ONOSbench.onosUninstall( node.ip_address )
131
132 # Make sure ONOS is DEAD
133 main.log.info( "Killing any ONOS processes" )
134 killResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -0700135 for node in main.nodes:
Jon Hall5cf14d52015-07-16 12:15:19 -0700136 killed = main.ONOSbench.onosKill( node.ip_address )
137 killResults = killResults and killed
138
139 cleanInstallResult = main.TRUE
140 gitPullResult = main.TRUE
141
142 main.step( "Starting Mininet" )
143 # scp topo file to mininet
144 # TODO: move to params?
145 topoName = "obelisk.py"
146 filePath = main.ONOSbench.home + "/tools/test/topos/"
kelvin-onlabd9e23de2015-08-06 10:34:44 -0700147 main.ONOSbench.scp( main.Mininet1,
148 filePath + topoName,
149 main.Mininet1.home,
150 direction="to" )
Jon Hall5cf14d52015-07-16 12:15:19 -0700151 mnResult = main.Mininet1.startNet( )
152 utilities.assert_equals( expect=main.TRUE, actual=mnResult,
153 onpass="Mininet Started",
154 onfail="Error starting Mininet" )
155
156 main.step( "Git checkout and pull " + gitBranch )
157 if PULLCODE:
158 main.ONOSbench.gitCheckout( gitBranch )
159 gitPullResult = main.ONOSbench.gitPull()
160 # values of 1 or 3 are good
161 utilities.assert_lesser( expect=0, actual=gitPullResult,
162 onpass="Git pull successful",
163 onfail="Git pull failed" )
164 main.ONOSbench.getVersion( report=True )
165
166 main.step( "Using mvn clean install" )
167 cleanInstallResult = main.TRUE
168 if PULLCODE and gitPullResult == main.TRUE:
169 cleanInstallResult = main.ONOSbench.cleanInstall()
170 else:
171 main.log.warn( "Did not pull new code so skipping mvn " +
172 "clean install" )
173 utilities.assert_equals( expect=main.TRUE,
174 actual=cleanInstallResult,
175 onpass="MCI successful",
176 onfail="MCI failed" )
177 # GRAPHS
178 # NOTE: important params here:
179 # job = name of Jenkins job
180 # Plot Name = Plot-HA, only can be used if multiple plots
181 # index = The number of the graph under plot name
182 job = "HAclusterRestart"
183 plotName = "Plot-HA"
184 graphs = '<ac:structured-macro ac:name="html">\n'
185 graphs += '<ac:plain-text-body><![CDATA[\n'
186 graphs += '<iframe src="https://onos-jenkins.onlab.us/job/' + job +\
187 '/plot/' + plotName + '/getPlot?index=0' +\
188 '&width=500&height=300"' +\
189 'noborder="0" width="500" height="300" scrolling="yes" ' +\
190 'seamless="seamless"></iframe>\n'
191 graphs += ']]></ac:plain-text-body>\n'
192 graphs += '</ac:structured-macro>\n'
193 main.log.wiki(graphs)
194
195 main.step( "Creating ONOS package" )
196 packageResult = main.ONOSbench.onosPackage()
197 utilities.assert_equals( expect=main.TRUE, actual=packageResult,
198 onpass="ONOS package successful",
199 onfail="ONOS package failed" )
200
201 main.step( "Installing ONOS package" )
202 onosInstallResult = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -0700203 for node in main.nodes:
Jon Hall5cf14d52015-07-16 12:15:19 -0700204 tmpResult = main.ONOSbench.onosInstall( options="-f",
205 node=node.ip_address )
206 onosInstallResult = onosInstallResult and tmpResult
207 utilities.assert_equals( expect=main.TRUE, actual=onosInstallResult,
208 onpass="ONOS install successful",
209 onfail="ONOS install failed" )
210
211 main.step( "Checking if ONOS is up yet" )
212 for i in range( 2 ):
213 onosIsupResult = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -0700214 for node in main.nodes:
Jon Hall5cf14d52015-07-16 12:15:19 -0700215 started = main.ONOSbench.isup( node.ip_address )
216 if not started:
217 main.log.error( node.name + " didn't start!" )
218 main.ONOSbench.onosStop( node.ip_address )
219 main.ONOSbench.onosStart( node.ip_address )
220 onosIsupResult = onosIsupResult and started
221 if onosIsupResult == main.TRUE:
222 break
223 utilities.assert_equals( expect=main.TRUE, actual=onosIsupResult,
224 onpass="ONOS startup successful",
225 onfail="ONOS startup failed" )
226
227 main.log.step( "Starting ONOS CLI sessions" )
228 cliResults = main.TRUE
229 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -0700230 for i in range( main.numCtrls ):
231 t = main.Thread( target=main.CLIs[i].startOnosCli,
Jon Hall5cf14d52015-07-16 12:15:19 -0700232 name="startOnosCli-" + str( i ),
Jon Halle1a3b752015-07-22 13:02:46 -0700233 args=[main.nodes[i].ip_address] )
Jon Hall5cf14d52015-07-16 12:15:19 -0700234 threads.append( t )
235 t.start()
236
237 for t in threads:
238 t.join()
239 cliResults = cliResults and t.result
240 utilities.assert_equals( expect=main.TRUE, actual=cliResults,
241 onpass="ONOS cli startup successful",
242 onfail="ONOS cli startup failed" )
243
244 if main.params[ 'tcpdump' ].lower() == "true":
245 main.step( "Start Packet Capture MN" )
246 main.Mininet2.startTcpdump(
247 str( main.params[ 'MNtcpdump' ][ 'folder' ] ) + str( main.TEST )
248 + "-MN.pcap",
249 intf=main.params[ 'MNtcpdump' ][ 'intf' ],
250 port=main.params[ 'MNtcpdump' ][ 'port' ] )
251
252 main.step( "App Ids check" )
253 appCheck = main.TRUE
254 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -0700255 for i in range( main.numCtrls ):
256 t = main.Thread( target=main.CLIs[i].appToIDCheck,
Jon Hall5cf14d52015-07-16 12:15:19 -0700257 name="appToIDCheck-" + str( i ),
258 args=[] )
259 threads.append( t )
260 t.start()
261
262 for t in threads:
263 t.join()
264 appCheck = appCheck and t.result
265 if appCheck != main.TRUE:
Jon Halle1a3b752015-07-22 13:02:46 -0700266 main.log.warn( main.CLIs[0].apps() )
267 main.log.warn( main.CLIs[0].appIDs() )
Jon Hall5cf14d52015-07-16 12:15:19 -0700268 utilities.assert_equals( expect=main.TRUE, actual=appCheck,
269 onpass="App Ids seem to be correct",
270 onfail="Something is wrong with app Ids" )
271
272 if cliResults == main.FALSE:
273 main.log.error( "Failed to start ONOS, stopping test" )
274 main.cleanup()
275 main.exit()
276
277 def CASE2( self, main ):
278 """
279 Assign devices to controllers
280 """
281 import re
Jon Halle1a3b752015-07-22 13:02:46 -0700282 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -0700283 assert main, "main not defined"
284 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -0700285 assert main.CLIs, "main.CLIs not defined"
286 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -0700287 assert ONOS1Port, "ONOS1Port not defined"
288 assert ONOS2Port, "ONOS2Port not defined"
289 assert ONOS3Port, "ONOS3Port not defined"
290 assert ONOS4Port, "ONOS4Port not defined"
291 assert ONOS5Port, "ONOS5Port not defined"
292 assert ONOS6Port, "ONOS6Port not defined"
293 assert ONOS7Port, "ONOS7Port not defined"
294
295 main.case( "Assigning devices to controllers" )
Jon Hall783bbf92015-07-23 14:33:19 -0700296 main.caseExplanation = "Assign switches to ONOS using 'ovs-vsctl' " +\
Jon Hall5cf14d52015-07-16 12:15:19 -0700297 "and check that an ONOS node becomes the " +\
298 "master of the device."
299 main.step( "Assign switches to controllers" )
300
301 ipList = []
Jon Halle1a3b752015-07-22 13:02:46 -0700302 for i in range( main.numCtrls ):
303 ipList.append( main.nodes[ i ].ip_address )
Jon Hall5cf14d52015-07-16 12:15:19 -0700304 swList = []
305 for i in range( 1, 29 ):
306 swList.append( "s" + str( i ) )
307 main.Mininet1.assignSwController( sw=swList, ip=ipList )
308
309 mastershipCheck = main.TRUE
310 for i in range( 1, 29 ):
311 response = main.Mininet1.getSwController( "s" + str( i ) )
312 try:
313 main.log.info( str( response ) )
314 except Exception:
315 main.log.info( repr( response ) )
Jon Halle1a3b752015-07-22 13:02:46 -0700316 for node in main.nodes:
Jon Hall5cf14d52015-07-16 12:15:19 -0700317 if re.search( "tcp:" + node.ip_address, response ):
318 mastershipCheck = mastershipCheck and main.TRUE
319 else:
320 main.log.error( "Error, node " + node.ip_address + " is " +
321 "not in the list of controllers s" +
322 str( i ) + " is connecting to." )
323 mastershipCheck = main.FALSE
324 utilities.assert_equals(
325 expect=main.TRUE,
326 actual=mastershipCheck,
327 onpass="Switch mastership assigned correctly",
328 onfail="Switches not assigned correctly to controllers" )
329
330 def CASE21( self, main ):
331 """
332 Assign mastership to controllers
333 """
Jon Hall5cf14d52015-07-16 12:15:19 -0700334 import time
Jon Halle1a3b752015-07-22 13:02:46 -0700335 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -0700336 assert main, "main not defined"
337 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -0700338 assert main.CLIs, "main.CLIs not defined"
339 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -0700340 assert ONOS1Port, "ONOS1Port not defined"
341 assert ONOS2Port, "ONOS2Port not defined"
342 assert ONOS3Port, "ONOS3Port not defined"
343 assert ONOS4Port, "ONOS4Port not defined"
344 assert ONOS5Port, "ONOS5Port not defined"
345 assert ONOS6Port, "ONOS6Port not defined"
346 assert ONOS7Port, "ONOS7Port not defined"
347
348 main.case( "Assigning Controller roles for switches" )
Jon Hall783bbf92015-07-23 14:33:19 -0700349 main.caseExplanation = "Check that ONOS is connected to each " +\
Jon Hall5cf14d52015-07-16 12:15:19 -0700350 "device. Then manually assign" +\
351 " mastership to specific ONOS nodes using" +\
352 " 'device-role'"
353 main.step( "Assign mastership of switches to specific controllers" )
354 # Manually assign mastership to the controller we want
355 roleCall = main.TRUE
356
357 ipList = [ ]
358 deviceList = []
359 try:
360 # Assign mastership to specific controllers. This assignment was
361 # determined for a 7 node cluser, but will work with any sized
362 # cluster
363 for i in range( 1, 29 ): # switches 1 through 28
364 # set up correct variables:
365 if i == 1:
366 c = 0
Jon Halle1a3b752015-07-22 13:02:46 -0700367 ip = main.nodes[ c ].ip_address # ONOS1
Jon Hall5cf14d52015-07-16 12:15:19 -0700368 deviceId = main.ONOScli1.getDevice( "1000" ).get( 'id' )
369 elif i == 2:
Jon Halle1a3b752015-07-22 13:02:46 -0700370 c = 1 % main.numCtrls
371 ip = main.nodes[ c ].ip_address # ONOS2
Jon Hall5cf14d52015-07-16 12:15:19 -0700372 deviceId = main.ONOScli1.getDevice( "2000" ).get( 'id' )
373 elif i == 3:
Jon Halle1a3b752015-07-22 13:02:46 -0700374 c = 1 % main.numCtrls
375 ip = main.nodes[ c ].ip_address # ONOS2
Jon Hall5cf14d52015-07-16 12:15:19 -0700376 deviceId = main.ONOScli1.getDevice( "3000" ).get( 'id' )
377 elif i == 4:
Jon Halle1a3b752015-07-22 13:02:46 -0700378 c = 3 % main.numCtrls
379 ip = main.nodes[ c ].ip_address # ONOS4
Jon Hall5cf14d52015-07-16 12:15:19 -0700380 deviceId = main.ONOScli1.getDevice( "3004" ).get( 'id' )
381 elif i == 5:
Jon Halle1a3b752015-07-22 13:02:46 -0700382 c = 2 % main.numCtrls
383 ip = main.nodes[ c ].ip_address # ONOS3
Jon Hall5cf14d52015-07-16 12:15:19 -0700384 deviceId = main.ONOScli1.getDevice( "5000" ).get( 'id' )
385 elif i == 6:
Jon Halle1a3b752015-07-22 13:02:46 -0700386 c = 2 % main.numCtrls
387 ip = main.nodes[ c ].ip_address # ONOS3
Jon Hall5cf14d52015-07-16 12:15:19 -0700388 deviceId = main.ONOScli1.getDevice( "6000" ).get( 'id' )
389 elif i == 7:
Jon Halle1a3b752015-07-22 13:02:46 -0700390 c = 5 % main.numCtrls
391 ip = main.nodes[ c ].ip_address # ONOS6
Jon Hall5cf14d52015-07-16 12:15:19 -0700392 deviceId = main.ONOScli1.getDevice( "6007" ).get( 'id' )
393 elif i >= 8 and i <= 17:
Jon Halle1a3b752015-07-22 13:02:46 -0700394 c = 4 % main.numCtrls
395 ip = main.nodes[ c ].ip_address # ONOS5
Jon Hall5cf14d52015-07-16 12:15:19 -0700396 dpid = '3' + str( i ).zfill( 3 )
397 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
398 elif i >= 18 and i <= 27:
Jon Halle1a3b752015-07-22 13:02:46 -0700399 c = 6 % main.numCtrls
400 ip = main.nodes[ c ].ip_address # ONOS7
Jon Hall5cf14d52015-07-16 12:15:19 -0700401 dpid = '6' + str( i ).zfill( 3 )
402 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
403 elif i == 28:
404 c = 0
Jon Halle1a3b752015-07-22 13:02:46 -0700405 ip = main.nodes[ c ].ip_address # ONOS1
Jon Hall5cf14d52015-07-16 12:15:19 -0700406 deviceId = main.ONOScli1.getDevice( "2800" ).get( 'id' )
407 else:
408 main.log.error( "You didn't write an else statement for " +
409 "switch s" + str( i ) )
410 roleCall = main.FALSE
411 # Assign switch
412 assert deviceId, "No device id for s" + str( i ) + " in ONOS"
413 # TODO: make this controller dynamic
414 roleCall = roleCall and main.ONOScli1.deviceRole( deviceId,
415 ip )
416 ipList.append( ip )
417 deviceList.append( deviceId )
418 except ( AttributeError, AssertionError ):
419 main.log.exception( "Something is wrong with ONOS device view" )
420 main.log.info( main.ONOScli1.devices() )
421 utilities.assert_equals(
422 expect=main.TRUE,
423 actual=roleCall,
424 onpass="Re-assigned switch mastership to designated controller",
425 onfail="Something wrong with deviceRole calls" )
426
427 main.step( "Check mastership was correctly assigned" )
428 roleCheck = main.TRUE
429 # NOTE: This is due to the fact that device mastership change is not
430 # atomic and is actually a multi step process
431 time.sleep( 5 )
432 for i in range( len( ipList ) ):
433 ip = ipList[i]
434 deviceId = deviceList[i]
435 # Check assignment
436 master = main.ONOScli1.getRole( deviceId ).get( 'master' )
437 if ip in master:
438 roleCheck = roleCheck and main.TRUE
439 else:
440 roleCheck = roleCheck and main.FALSE
441 main.log.error( "Error, controller " + ip + " is not" +
442 " master " + "of device " +
443 str( deviceId ) + ". Master is " +
444 repr( master ) + "." )
445 utilities.assert_equals(
446 expect=main.TRUE,
447 actual=roleCheck,
448 onpass="Switches were successfully reassigned to designated " +
449 "controller",
450 onfail="Switches were not successfully reassigned" )
451
452 def CASE3( self, main ):
453 """
454 Assign intents
455 """
456 import time
457 import json
Jon Halle1a3b752015-07-22 13:02:46 -0700458 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -0700459 assert main, "main not defined"
460 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -0700461 assert main.CLIs, "main.CLIs not defined"
462 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -0700463 try:
464 labels
465 except NameError:
466 main.log.error( "labels not defined, setting to []" )
467 labels = []
468 try:
469 data
470 except NameError:
471 main.log.error( "data not defined, setting to []" )
472 data = []
473 # NOTE: we must reinstall intents until we have a persistant intent
474 # datastore!
475 main.case( "Adding host Intents" )
Jon Hall783bbf92015-07-23 14:33:19 -0700476 main.caseExplanation = "Discover hosts by using pingall then " +\
Jon Hall5cf14d52015-07-16 12:15:19 -0700477 "assign predetermined host-to-host intents." +\
478 " After installation, check that the intent" +\
479 " is distributed to all nodes and the state" +\
480 " is INSTALLED"
481
482 # install onos-app-fwd
483 main.step( "Install reactive forwarding app" )
Jon Halle1a3b752015-07-22 13:02:46 -0700484 installResults = main.CLIs[0].activateApp( "org.onosproject.fwd" )
Jon Hall5cf14d52015-07-16 12:15:19 -0700485 utilities.assert_equals( expect=main.TRUE, actual=installResults,
486 onpass="Install fwd successful",
487 onfail="Install fwd failed" )
488
489 main.step( "Check app ids" )
490 appCheck = main.TRUE
491 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -0700492 for i in range( main.numCtrls ):
493 t = main.Thread( target=main.CLIs[i].appToIDCheck,
Jon Hall5cf14d52015-07-16 12:15:19 -0700494 name="appToIDCheck-" + str( i ),
495 args=[] )
496 threads.append( t )
497 t.start()
498
499 for t in threads:
500 t.join()
501 appCheck = appCheck and t.result
502 if appCheck != main.TRUE:
Jon Halle1a3b752015-07-22 13:02:46 -0700503 main.log.warn( main.CLIs[0].apps() )
504 main.log.warn( main.CLIs[0].appIDs() )
Jon Hall5cf14d52015-07-16 12:15:19 -0700505 utilities.assert_equals( expect=main.TRUE, actual=appCheck,
506 onpass="App Ids seem to be correct",
507 onfail="Something is wrong with app Ids" )
508
509 main.step( "Discovering Hosts( Via pingall for now )" )
510 # FIXME: Once we have a host discovery mechanism, use that instead
511 # REACTIVE FWD test
512 pingResult = main.FALSE
513 for i in range(2): # Retry if pingall fails first time
514 time1 = time.time()
515 pingResult = main.Mininet1.pingall()
516 if i == 0:
517 utilities.assert_equals(
518 expect=main.TRUE,
519 actual=pingResult,
520 onpass="Reactive Pingall test passed",
521 onfail="Reactive Pingall failed, " +
522 "one or more ping pairs failed" )
523 time2 = time.time()
524 main.log.info( "Time for pingall: %2f seconds" %
525 ( time2 - time1 ) )
526 # timeout for fwd flows
527 time.sleep( 11 )
528 # uninstall onos-app-fwd
529 main.step( "Uninstall reactive forwarding app" )
Jon Halle1a3b752015-07-22 13:02:46 -0700530 uninstallResult = main.CLIs[0].deactivateApp( "org.onosproject.fwd" )
Jon Hall5cf14d52015-07-16 12:15:19 -0700531 utilities.assert_equals( expect=main.TRUE, actual=uninstallResult,
532 onpass="Uninstall fwd successful",
533 onfail="Uninstall fwd failed" )
534
535 main.step( "Check app ids" )
536 threads = []
537 appCheck2 = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -0700538 for i in range( main.numCtrls ):
539 t = main.Thread( target=main.CLIs[i].appToIDCheck,
Jon Hall5cf14d52015-07-16 12:15:19 -0700540 name="appToIDCheck-" + str( i ),
541 args=[] )
542 threads.append( t )
543 t.start()
544
545 for t in threads:
546 t.join()
547 appCheck2 = appCheck2 and t.result
548 if appCheck2 != main.TRUE:
Jon Halle1a3b752015-07-22 13:02:46 -0700549 main.log.warn( main.CLIs[0].apps() )
550 main.log.warn( main.CLIs[0].appIDs() )
Jon Hall5cf14d52015-07-16 12:15:19 -0700551 utilities.assert_equals( expect=main.TRUE, actual=appCheck2,
552 onpass="App Ids seem to be correct",
553 onfail="Something is wrong with app Ids" )
554
555 main.step( "Add host intents via cli" )
556 intentIds = []
557 # TODO: move the host numbers to params
558 # Maybe look at all the paths we ping?
559 intentAddResult = True
560 hostResult = main.TRUE
561 for i in range( 8, 18 ):
562 main.log.info( "Adding host intent between h" + str( i ) +
563 " and h" + str( i + 10 ) )
564 host1 = "00:00:00:00:00:" + \
565 str( hex( i )[ 2: ] ).zfill( 2 ).upper()
566 host2 = "00:00:00:00:00:" + \
567 str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper()
568 # NOTE: getHost can return None
569 host1Dict = main.ONOScli1.getHost( host1 )
570 host2Dict = main.ONOScli1.getHost( host2 )
571 host1Id = None
572 host2Id = None
573 if host1Dict and host2Dict:
574 host1Id = host1Dict.get( 'id', None )
575 host2Id = host2Dict.get( 'id', None )
576 if host1Id and host2Id:
Jon Halle1a3b752015-07-22 13:02:46 -0700577 nodeNum = ( i % main.numCtrls )
578 tmpId = main.CLIs[ nodeNum ].addHostIntent( host1Id, host2Id )
Jon Hall5cf14d52015-07-16 12:15:19 -0700579 if tmpId:
580 main.log.info( "Added intent with id: " + tmpId )
581 intentIds.append( tmpId )
582 else:
583 main.log.error( "addHostIntent returned: " +
584 repr( tmpId ) )
585 else:
586 main.log.error( "Error, getHost() failed for h" + str( i ) +
587 " and/or h" + str( i + 10 ) )
Jon Halle1a3b752015-07-22 13:02:46 -0700588 hosts = main.CLIs[ 0 ].hosts()
Jon Hall5cf14d52015-07-16 12:15:19 -0700589 main.log.warn( "Hosts output: " )
590 try:
591 main.log.warn( json.dumps( json.loads( hosts ),
592 sort_keys=True,
593 indent=4,
594 separators=( ',', ': ' ) ) )
595 except ( ValueError, TypeError ):
596 main.log.warn( repr( hosts ) )
597 hostResult = main.FALSE
598 utilities.assert_equals( expect=main.TRUE, actual=hostResult,
599 onpass="Found a host id for each host",
600 onfail="Error looking up host ids" )
601
602 intentStart = time.time()
603 onosIds = main.ONOScli1.getAllIntentsId()
604 main.log.info( "Submitted intents: " + str( intentIds ) )
605 main.log.info( "Intents in ONOS: " + str( onosIds ) )
606 for intent in intentIds:
607 if intent in onosIds:
608 pass # intent submitted is in onos
609 else:
610 intentAddResult = False
611 if intentAddResult:
612 intentStop = time.time()
613 else:
614 intentStop = None
615 # Print the intent states
616 intents = main.ONOScli1.intents()
617 intentStates = []
618 installedCheck = True
619 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
620 count = 0
621 try:
622 for intent in json.loads( intents ):
623 state = intent.get( 'state', None )
624 if "INSTALLED" not in state:
625 installedCheck = False
626 intentId = intent.get( 'id', None )
627 intentStates.append( ( intentId, state ) )
628 except ( ValueError, TypeError ):
629 main.log.exception( "Error parsing intents" )
630 # add submitted intents not in the store
631 tmplist = [ i for i, s in intentStates ]
632 missingIntents = False
633 for i in intentIds:
634 if i not in tmplist:
635 intentStates.append( ( i, " - " ) )
636 missingIntents = True
637 intentStates.sort()
638 for i, s in intentStates:
639 count += 1
640 main.log.info( "%-6s%-15s%-15s" %
641 ( str( count ), str( i ), str( s ) ) )
642 leaders = main.ONOScli1.leaders()
643 try:
644 missing = False
645 if leaders:
646 parsedLeaders = json.loads( leaders )
647 main.log.warn( json.dumps( parsedLeaders,
648 sort_keys=True,
649 indent=4,
650 separators=( ',', ': ' ) ) )
651 # check for all intent partitions
652 topics = []
653 for i in range( 14 ):
654 topics.append( "intent-partition-" + str( i ) )
655 main.log.debug( topics )
656 ONOStopics = [ j['topic'] for j in parsedLeaders ]
657 for topic in topics:
658 if topic not in ONOStopics:
659 main.log.error( "Error: " + topic +
660 " not in leaders" )
661 missing = True
662 else:
663 main.log.error( "leaders() returned None" )
664 except ( ValueError, TypeError ):
665 main.log.exception( "Error parsing leaders" )
666 main.log.error( repr( leaders ) )
667 # Check all nodes
668 if missing:
Jon Halle1a3b752015-07-22 13:02:46 -0700669 for node in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -0700670 response = node.leaders( jsonFormat=False)
671 main.log.warn( str( node.name ) + " leaders output: \n" +
672 str( response ) )
673
674 partitions = main.ONOScli1.partitions()
675 try:
676 if partitions :
677 parsedPartitions = json.loads( partitions )
678 main.log.warn( json.dumps( parsedPartitions,
679 sort_keys=True,
680 indent=4,
681 separators=( ',', ': ' ) ) )
682 # TODO check for a leader in all paritions
683 # TODO check for consistency among nodes
684 else:
685 main.log.error( "partitions() returned None" )
686 except ( ValueError, TypeError ):
687 main.log.exception( "Error parsing partitions" )
688 main.log.error( repr( partitions ) )
689 pendingMap = main.ONOScli1.pendingMap()
690 try:
691 if pendingMap :
692 parsedPending = json.loads( pendingMap )
693 main.log.warn( json.dumps( parsedPending,
694 sort_keys=True,
695 indent=4,
696 separators=( ',', ': ' ) ) )
697 # TODO check something here?
698 else:
699 main.log.error( "pendingMap() returned None" )
700 except ( ValueError, TypeError ):
701 main.log.exception( "Error parsing pending map" )
702 main.log.error( repr( pendingMap ) )
703
704 intentAddResult = bool( intentAddResult and not missingIntents and
705 installedCheck )
706 if not intentAddResult:
707 main.log.error( "Error in pushing host intents to ONOS" )
708
709 main.step( "Intent Anti-Entropy dispersion" )
710 for i in range(100):
711 correct = True
712 main.log.info( "Submitted intents: " + str( sorted( intentIds ) ) )
Jon Halle1a3b752015-07-22 13:02:46 -0700713 for cli in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -0700714 onosIds = []
715 ids = cli.getAllIntentsId()
716 onosIds.append( ids )
717 main.log.debug( "Intents in " + cli.name + ": " +
718 str( sorted( onosIds ) ) )
719 if sorted( ids ) != sorted( intentIds ):
720 main.log.warn( "Set of intent IDs doesn't match" )
721 correct = False
722 break
723 else:
724 intents = json.loads( cli.intents() )
725 for intent in intents:
726 if intent[ 'state' ] != "INSTALLED":
727 main.log.warn( "Intent " + intent[ 'id' ] +
728 " is " + intent[ 'state' ] )
729 correct = False
730 break
731 if correct:
732 break
733 else:
734 time.sleep(1)
735 if not intentStop:
736 intentStop = time.time()
737 global gossipTime
738 gossipTime = intentStop - intentStart
739 main.log.info( "It took about " + str( gossipTime ) +
740 " seconds for all intents to appear in each node" )
741 append = False
742 title = "Gossip Intents"
743 count = 1
744 while append is False:
745 curTitle = title + str( count )
746 if curTitle not in labels:
747 labels.append( curTitle )
748 data.append( str( gossipTime ) )
749 append = True
750 else:
751 count += 1
752 # FIXME: make this time configurable/calculate based off of number of
753 # nodes and gossip rounds
754 utilities.assert_greater_equals(
755 expect=40, actual=gossipTime,
756 onpass="ECM anti-entropy for intents worked within " +
757 "expected time",
758 onfail="Intent ECM anti-entropy took too long" )
759 if gossipTime <= 40:
760 intentAddResult = True
761
762 if not intentAddResult or "key" in pendingMap:
763 import time
764 installedCheck = True
765 main.log.info( "Sleeping 60 seconds to see if intents are found" )
766 time.sleep( 60 )
767 onosIds = main.ONOScli1.getAllIntentsId()
768 main.log.info( "Submitted intents: " + str( intentIds ) )
769 main.log.info( "Intents in ONOS: " + str( onosIds ) )
770 # Print the intent states
771 intents = main.ONOScli1.intents()
772 intentStates = []
773 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
774 count = 0
775 try:
776 for intent in json.loads( intents ):
777 # Iter through intents of a node
778 state = intent.get( 'state', None )
779 if "INSTALLED" not in state:
780 installedCheck = False
781 intentId = intent.get( 'id', None )
782 intentStates.append( ( intentId, state ) )
783 except ( ValueError, TypeError ):
784 main.log.exception( "Error parsing intents" )
785 # add submitted intents not in the store
786 tmplist = [ i for i, s in intentStates ]
787 for i in intentIds:
788 if i not in tmplist:
789 intentStates.append( ( i, " - " ) )
790 intentStates.sort()
791 for i, s in intentStates:
792 count += 1
793 main.log.info( "%-6s%-15s%-15s" %
794 ( str( count ), str( i ), str( s ) ) )
795 leaders = main.ONOScli1.leaders()
796 try:
797 missing = False
798 if leaders:
799 parsedLeaders = json.loads( leaders )
800 main.log.warn( json.dumps( parsedLeaders,
801 sort_keys=True,
802 indent=4,
803 separators=( ',', ': ' ) ) )
804 # check for all intent partitions
805 # check for election
806 topics = []
807 for i in range( 14 ):
808 topics.append( "intent-partition-" + str( i ) )
809 # FIXME: this should only be after we start the app
810 topics.append( "org.onosproject.election" )
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 missing = True
818 else:
819 main.log.error( "leaders() returned None" )
820 except ( ValueError, TypeError ):
821 main.log.exception( "Error parsing leaders" )
822 main.log.error( repr( leaders ) )
823 # Check all nodes
824 if missing:
Jon Halle1a3b752015-07-22 13:02:46 -0700825 for node in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -0700826 response = node.leaders( jsonFormat=False)
827 main.log.warn( str( node.name ) + " leaders output: \n" +
828 str( response ) )
829
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 pendingMap = main.ONOScli1.pendingMap()
846 try:
847 if pendingMap :
848 parsedPending = json.loads( pendingMap )
849 main.log.warn( json.dumps( parsedPending,
850 sort_keys=True,
851 indent=4,
852 separators=( ',', ': ' ) ) )
853 # TODO check something here?
854 else:
855 main.log.error( "pendingMap() returned None" )
856 except ( ValueError, TypeError ):
857 main.log.exception( "Error parsing pending map" )
858 main.log.error( repr( pendingMap ) )
859
860 def CASE4( self, main ):
861 """
862 Ping across added host intents
863 """
864 import json
865 import time
Jon Halle1a3b752015-07-22 13:02:46 -0700866 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -0700867 assert main, "main not defined"
868 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -0700869 assert main.CLIs, "main.CLIs not defined"
870 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -0700871 main.case( "Verify connectivity by sendind traffic across Intents" )
Jon Hall783bbf92015-07-23 14:33:19 -0700872 main.caseExplanation = "Ping across added host intents to check " +\
Jon Hall5cf14d52015-07-16 12:15:19 -0700873 "functionality and check the state of " +\
874 "the intent"
875 main.step( "Ping across added host intents" )
876 PingResult = main.TRUE
877 for i in range( 8, 18 ):
878 ping = main.Mininet1.pingHost( src="h" + str( i ),
879 target="h" + str( i + 10 ) )
880 PingResult = PingResult and ping
881 if ping == main.FALSE:
882 main.log.warn( "Ping failed between h" + str( i ) +
883 " and h" + str( i + 10 ) )
884 elif ping == main.TRUE:
885 main.log.info( "Ping test passed!" )
886 # Don't set PingResult or you'd override failures
887 if PingResult == main.FALSE:
888 main.log.error(
889 "Intents have not been installed correctly, pings failed." )
890 # TODO: pretty print
891 main.log.warn( "ONOS1 intents: " )
892 try:
893 tmpIntents = main.ONOScli1.intents()
894 main.log.warn( json.dumps( json.loads( tmpIntents ),
895 sort_keys=True,
896 indent=4,
897 separators=( ',', ': ' ) ) )
898 except ( ValueError, TypeError ):
899 main.log.warn( repr( tmpIntents ) )
900 utilities.assert_equals(
901 expect=main.TRUE,
902 actual=PingResult,
903 onpass="Intents have been installed correctly and pings work",
904 onfail="Intents have not been installed correctly, pings failed." )
905
906 main.step( "Check Intent state" )
907 installedCheck = False
908 loopCount = 0
909 while not installedCheck and loopCount < 40:
910 installedCheck = True
911 # Print the intent states
912 intents = main.ONOScli1.intents()
913 intentStates = []
914 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
Jon Halle1a3b752015-07-22 13:02:46 -0700915 count = 0
Jon Hall5cf14d52015-07-16 12:15:19 -0700916 # Iter through intents of a node
917 try:
918 for intent in json.loads( intents ):
919 state = intent.get( 'state', None )
920 if "INSTALLED" not in state:
921 installedCheck = False
922 intentId = intent.get( 'id', None )
923 intentStates.append( ( intentId, state ) )
924 except ( ValueError, TypeError ):
925 main.log.exception( "Error parsing intents." )
926 # Print states
927 intentStates.sort()
928 for i, s in intentStates:
929 count += 1
930 main.log.info( "%-6s%-15s%-15s" %
931 ( str( count ), str( i ), str( s ) ) )
932 if not installedCheck:
933 time.sleep( 1 )
934 loopCount += 1
935 utilities.assert_equals( expect=True, actual=installedCheck,
936 onpass="Intents are all INSTALLED",
937 onfail="Intents are not all in " +
938 "INSTALLED state" )
939
940 main.step( "Check leadership of topics" )
941 leaders = main.ONOScli1.leaders()
942 topicCheck = main.TRUE
943 try:
944 if leaders:
945 parsedLeaders = json.loads( leaders )
946 main.log.warn( json.dumps( parsedLeaders,
947 sort_keys=True,
948 indent=4,
949 separators=( ',', ': ' ) ) )
950 # check for all intent partitions
951 # check for election
952 # TODO: Look at Devices as topics now that it uses this system
953 topics = []
954 for i in range( 14 ):
955 topics.append( "intent-partition-" + str( i ) )
956 # FIXME: this should only be after we start the app
957 # FIXME: topics.append( "org.onosproject.election" )
958 # Print leaders output
959 main.log.debug( topics )
960 ONOStopics = [ j['topic'] for j in parsedLeaders ]
961 for topic in topics:
962 if topic not in ONOStopics:
963 main.log.error( "Error: " + topic +
964 " not in leaders" )
965 topicCheck = main.FALSE
966 else:
967 main.log.error( "leaders() returned None" )
968 topicCheck = main.FALSE
969 except ( ValueError, TypeError ):
970 topicCheck = main.FALSE
971 main.log.exception( "Error parsing leaders" )
972 main.log.error( repr( leaders ) )
973 # TODO: Check for a leader of these topics
974 # Check all nodes
975 if topicCheck:
Jon Halle1a3b752015-07-22 13:02:46 -0700976 for node in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -0700977 response = node.leaders( jsonFormat=False)
978 main.log.warn( str( node.name ) + " leaders output: \n" +
979 str( response ) )
980
981 utilities.assert_equals( expect=main.TRUE, actual=topicCheck,
982 onpass="intent Partitions is in leaders",
983 onfail="Some topics were lost " )
984 # Print partitions
985 partitions = main.ONOScli1.partitions()
986 try:
987 if partitions :
988 parsedPartitions = json.loads( partitions )
989 main.log.warn( json.dumps( parsedPartitions,
990 sort_keys=True,
991 indent=4,
992 separators=( ',', ': ' ) ) )
993 # TODO check for a leader in all paritions
994 # TODO check for consistency among nodes
995 else:
996 main.log.error( "partitions() returned None" )
997 except ( ValueError, TypeError ):
998 main.log.exception( "Error parsing partitions" )
999 main.log.error( repr( partitions ) )
1000 # Print Pending Map
1001 pendingMap = main.ONOScli1.pendingMap()
1002 try:
1003 if pendingMap :
1004 parsedPending = json.loads( pendingMap )
1005 main.log.warn( json.dumps( parsedPending,
1006 sort_keys=True,
1007 indent=4,
1008 separators=( ',', ': ' ) ) )
1009 # TODO check something here?
1010 else:
1011 main.log.error( "pendingMap() returned None" )
1012 except ( ValueError, TypeError ):
1013 main.log.exception( "Error parsing pending map" )
1014 main.log.error( repr( pendingMap ) )
1015
1016 if not installedCheck:
1017 main.log.info( "Waiting 60 seconds to see if the state of " +
1018 "intents change" )
1019 time.sleep( 60 )
1020 # Print the intent states
1021 intents = main.ONOScli1.intents()
1022 intentStates = []
1023 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
1024 count = 0
1025 # Iter through intents of a node
1026 try:
1027 for intent in json.loads( intents ):
1028 state = intent.get( 'state', None )
1029 if "INSTALLED" not in state:
1030 installedCheck = False
1031 intentId = intent.get( 'id', None )
1032 intentStates.append( ( intentId, state ) )
1033 except ( ValueError, TypeError ):
1034 main.log.exception( "Error parsing intents." )
1035 intentStates.sort()
1036 for i, s in intentStates:
1037 count += 1
1038 main.log.info( "%-6s%-15s%-15s" %
1039 ( str( count ), str( i ), str( s ) ) )
1040 leaders = main.ONOScli1.leaders()
1041 try:
1042 missing = False
1043 if leaders:
1044 parsedLeaders = json.loads( leaders )
1045 main.log.warn( json.dumps( parsedLeaders,
1046 sort_keys=True,
1047 indent=4,
1048 separators=( ',', ': ' ) ) )
1049 # check for all intent partitions
1050 # check for election
1051 topics = []
1052 for i in range( 14 ):
1053 topics.append( "intent-partition-" + str( i ) )
1054 # FIXME: this should only be after we start the app
1055 topics.append( "org.onosproject.election" )
1056 main.log.debug( topics )
1057 ONOStopics = [ j['topic'] for j in parsedLeaders ]
1058 for topic in topics:
1059 if topic not in ONOStopics:
1060 main.log.error( "Error: " + topic +
1061 " not in leaders" )
1062 missing = True
1063 else:
1064 main.log.error( "leaders() returned None" )
1065 except ( ValueError, TypeError ):
1066 main.log.exception( "Error parsing leaders" )
1067 main.log.error( repr( leaders ) )
1068 if missing:
Jon Halle1a3b752015-07-22 13:02:46 -07001069 for node in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -07001070 response = node.leaders( jsonFormat=False)
1071 main.log.warn( str( node.name ) + " leaders output: \n" +
1072 str( response ) )
1073
1074 partitions = main.ONOScli1.partitions()
1075 try:
1076 if partitions :
1077 parsedPartitions = json.loads( partitions )
1078 main.log.warn( json.dumps( parsedPartitions,
1079 sort_keys=True,
1080 indent=4,
1081 separators=( ',', ': ' ) ) )
1082 # TODO check for a leader in all paritions
1083 # TODO check for consistency among nodes
1084 else:
1085 main.log.error( "partitions() returned None" )
1086 except ( ValueError, TypeError ):
1087 main.log.exception( "Error parsing partitions" )
1088 main.log.error( repr( partitions ) )
1089 pendingMap = main.ONOScli1.pendingMap()
1090 try:
1091 if pendingMap :
1092 parsedPending = json.loads( pendingMap )
1093 main.log.warn( json.dumps( parsedPending,
1094 sort_keys=True,
1095 indent=4,
1096 separators=( ',', ': ' ) ) )
1097 # TODO check something here?
1098 else:
1099 main.log.error( "pendingMap() returned None" )
1100 except ( ValueError, TypeError ):
1101 main.log.exception( "Error parsing pending map" )
1102 main.log.error( repr( pendingMap ) )
1103 # Print flowrules
Jon Halle1a3b752015-07-22 13:02:46 -07001104 main.log.debug( main.CLIs[0].flows( jsonFormat=False ) )
Jon Hall5cf14d52015-07-16 12:15:19 -07001105 main.step( "Wait a minute then ping again" )
1106 # the wait is above
1107 PingResult = main.TRUE
1108 for i in range( 8, 18 ):
1109 ping = main.Mininet1.pingHost( src="h" + str( i ),
1110 target="h" + str( i + 10 ) )
1111 PingResult = PingResult and ping
1112 if ping == main.FALSE:
1113 main.log.warn( "Ping failed between h" + str( i ) +
1114 " and h" + str( i + 10 ) )
1115 elif ping == main.TRUE:
1116 main.log.info( "Ping test passed!" )
1117 # Don't set PingResult or you'd override failures
1118 if PingResult == main.FALSE:
1119 main.log.error(
1120 "Intents have not been installed correctly, pings failed." )
1121 # TODO: pretty print
1122 main.log.warn( "ONOS1 intents: " )
1123 try:
1124 tmpIntents = main.ONOScli1.intents()
1125 main.log.warn( json.dumps( json.loads( tmpIntents ),
1126 sort_keys=True,
1127 indent=4,
1128 separators=( ',', ': ' ) ) )
1129 except ( ValueError, TypeError ):
1130 main.log.warn( repr( tmpIntents ) )
1131 utilities.assert_equals(
1132 expect=main.TRUE,
1133 actual=PingResult,
1134 onpass="Intents have been installed correctly and pings work",
1135 onfail="Intents have not been installed correctly, pings failed." )
1136
1137 def CASE5( self, main ):
1138 """
1139 Reading state of ONOS
1140 """
1141 import json
1142 import time
Jon Halle1a3b752015-07-22 13:02:46 -07001143 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07001144 assert main, "main not defined"
1145 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07001146 assert main.CLIs, "main.CLIs not defined"
1147 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07001148
1149 main.case( "Setting up and gathering data for current state" )
1150 # The general idea for this test case is to pull the state of
1151 # ( intents,flows, topology,... ) from each ONOS node
1152 # We can then compare them with each other and also with past states
1153
1154 main.step( "Check that each switch has a master" )
1155 global mastershipState
1156 mastershipState = '[]'
1157
1158 # Assert that each device has a master
1159 rolesNotNull = main.TRUE
1160 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001161 for i in range( main.numCtrls ):
1162 t = main.Thread( target=main.CLIs[i].rolesNotNull,
Jon Hall5cf14d52015-07-16 12:15:19 -07001163 name="rolesNotNull-" + str( i ),
1164 args=[] )
1165 threads.append( t )
1166 t.start()
1167
1168 for t in threads:
1169 t.join()
1170 rolesNotNull = rolesNotNull and t.result
1171 utilities.assert_equals(
1172 expect=main.TRUE,
1173 actual=rolesNotNull,
1174 onpass="Each device has a master",
1175 onfail="Some devices don't have a master assigned" )
1176
1177 main.step( "Get the Mastership of each switch from each controller" )
1178 ONOSMastership = []
1179 mastershipCheck = main.FALSE
1180 consistentMastership = True
1181 rolesResults = True
1182 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001183 for i in range( main.numCtrls ):
1184 t = main.Thread( target=main.CLIs[i].roles,
Jon Hall5cf14d52015-07-16 12:15:19 -07001185 name="roles-" + str( i ),
1186 args=[] )
1187 threads.append( t )
1188 t.start()
1189
1190 for t in threads:
1191 t.join()
1192 ONOSMastership.append( t.result )
1193
Jon Halle1a3b752015-07-22 13:02:46 -07001194 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001195 if not ONOSMastership[i] or "Error" in ONOSMastership[i]:
1196 main.log.error( "Error in getting ONOS" + str( i + 1 ) +
1197 " roles" )
1198 main.log.warn(
1199 "ONOS" + str( i + 1 ) + " mastership response: " +
1200 repr( ONOSMastership[i] ) )
1201 rolesResults = False
1202 utilities.assert_equals(
1203 expect=True,
1204 actual=rolesResults,
1205 onpass="No error in reading roles output",
1206 onfail="Error in reading roles from ONOS" )
1207
1208 main.step( "Check for consistency in roles from each controller" )
1209 if all([ i == ONOSMastership[ 0 ] for i in ONOSMastership ] ):
1210 main.log.info(
1211 "Switch roles are consistent across all ONOS nodes" )
1212 else:
1213 consistentMastership = False
1214 utilities.assert_equals(
1215 expect=True,
1216 actual=consistentMastership,
1217 onpass="Switch roles are consistent across all ONOS nodes",
1218 onfail="ONOS nodes have different views of switch roles" )
1219
1220 if rolesResults and not consistentMastership:
Jon Halle1a3b752015-07-22 13:02:46 -07001221 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001222 try:
1223 main.log.warn(
1224 "ONOS" + str( i + 1 ) + " roles: ",
1225 json.dumps(
1226 json.loads( ONOSMastership[ i ] ),
1227 sort_keys=True,
1228 indent=4,
1229 separators=( ',', ': ' ) ) )
1230 except ( ValueError, TypeError ):
1231 main.log.warn( repr( ONOSMastership[ i ] ) )
1232 elif rolesResults and consistentMastership:
1233 mastershipCheck = main.TRUE
1234 mastershipState = ONOSMastership[ 0 ]
1235
1236 main.step( "Get the intents from each controller" )
1237 global intentState
1238 intentState = []
1239 ONOSIntents = []
1240 intentCheck = main.FALSE
1241 consistentIntents = True
1242 intentsResults = True
1243 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001244 for i in range( main.numCtrls ):
1245 t = main.Thread( target=main.CLIs[i].intents,
Jon Hall5cf14d52015-07-16 12:15:19 -07001246 name="intents-" + str( i ),
1247 args=[],
1248 kwargs={ 'jsonFormat': True } )
1249 threads.append( t )
1250 t.start()
1251
1252 for t in threads:
1253 t.join()
1254 ONOSIntents.append( t.result )
1255
Jon Halle1a3b752015-07-22 13:02:46 -07001256 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001257 if not ONOSIntents[ i ] or "Error" in ONOSIntents[ i ]:
1258 main.log.error( "Error in getting ONOS" + str( i + 1 ) +
1259 " intents" )
1260 main.log.warn( "ONOS" + str( i + 1 ) + " intents response: " +
1261 repr( ONOSIntents[ i ] ) )
1262 intentsResults = False
1263 utilities.assert_equals(
1264 expect=True,
1265 actual=intentsResults,
1266 onpass="No error in reading intents output",
1267 onfail="Error in reading intents from ONOS" )
1268
1269 main.step( "Check for consistency in Intents from each controller" )
1270 if all([ sorted( i ) == sorted( ONOSIntents[ 0 ] ) for i in ONOSIntents ] ):
1271 main.log.info( "Intents are consistent across all ONOS " +
1272 "nodes" )
1273 else:
1274 consistentIntents = False
1275 main.log.error( "Intents not consistent" )
1276 utilities.assert_equals(
1277 expect=True,
1278 actual=consistentIntents,
1279 onpass="Intents are consistent across all ONOS nodes",
1280 onfail="ONOS nodes have different views of intents" )
1281
1282 if intentsResults:
1283 # Try to make it easy to figure out what is happening
1284 #
1285 # Intent ONOS1 ONOS2 ...
1286 # 0x01 INSTALLED INSTALLING
1287 # ... ... ...
1288 # ... ... ...
1289 title = " Id"
Jon Halle1a3b752015-07-22 13:02:46 -07001290 for n in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001291 title += " " * 10 + "ONOS" + str( n + 1 )
1292 main.log.warn( title )
1293 # get all intent keys in the cluster
1294 keys = []
1295 for nodeStr in ONOSIntents:
1296 node = json.loads( nodeStr )
1297 for intent in node:
1298 keys.append( intent.get( 'id' ) )
1299 keys = set( keys )
1300 for key in keys:
1301 row = "%-13s" % key
1302 for nodeStr in ONOSIntents:
1303 node = json.loads( nodeStr )
1304 for intent in node:
1305 if intent.get( 'id', "Error" ) == key:
1306 row += "%-15s" % intent.get( 'state' )
1307 main.log.warn( row )
1308 # End table view
1309
1310 if intentsResults and not consistentIntents:
1311 # print the json objects
1312 n = len(ONOSIntents)
1313 main.log.debug( "ONOS" + str( n ) + " intents: " )
1314 main.log.debug( json.dumps( json.loads( ONOSIntents[ -1 ] ),
1315 sort_keys=True,
1316 indent=4,
1317 separators=( ',', ': ' ) ) )
Jon Halle1a3b752015-07-22 13:02:46 -07001318 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001319 if ONOSIntents[ i ] != ONOSIntents[ -1 ]:
1320 main.log.debug( "ONOS" + str( i + 1 ) + " intents: " )
1321 main.log.debug( json.dumps( json.loads( ONOSIntents[i] ),
1322 sort_keys=True,
1323 indent=4,
1324 separators=( ',', ': ' ) ) )
1325 else:
Jon Halle1a3b752015-07-22 13:02:46 -07001326 main.log.debug( main.nodes[ i ].name + " intents match ONOS" +
Jon Hall5cf14d52015-07-16 12:15:19 -07001327 str( n ) + " intents" )
1328 elif intentsResults and consistentIntents:
1329 intentCheck = main.TRUE
1330 intentState = ONOSIntents[ 0 ]
1331
1332 main.step( "Get the flows from each controller" )
1333 global flowState
1334 flowState = []
1335 ONOSFlows = []
1336 ONOSFlowsJson = []
1337 flowCheck = main.FALSE
1338 consistentFlows = True
1339 flowsResults = True
1340 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001341 for i in range( main.numCtrls ):
1342 t = main.Thread( target=main.CLIs[i].flows,
Jon Hall5cf14d52015-07-16 12:15:19 -07001343 name="flows-" + str( i ),
1344 args=[],
1345 kwargs={ 'jsonFormat': True } )
1346 threads.append( t )
1347 t.start()
1348
1349 # NOTE: Flows command can take some time to run
1350 time.sleep(30)
1351 for t in threads:
1352 t.join()
1353 result = t.result
1354 ONOSFlows.append( result )
1355
Jon Halle1a3b752015-07-22 13:02:46 -07001356 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001357 num = str( i + 1 )
1358 if not ONOSFlows[ i ] or "Error" in ONOSFlows[ i ]:
1359 main.log.error( "Error in getting ONOS" + num + " flows" )
1360 main.log.warn( "ONOS" + num + " flows response: " +
1361 repr( ONOSFlows[ i ] ) )
1362 flowsResults = False
1363 ONOSFlowsJson.append( None )
1364 else:
1365 try:
1366 ONOSFlowsJson.append( json.loads( ONOSFlows[ i ] ) )
1367 except ( ValueError, TypeError ):
1368 # FIXME: change this to log.error?
1369 main.log.exception( "Error in parsing ONOS" + num +
1370 " response as json." )
1371 main.log.error( repr( ONOSFlows[ i ] ) )
1372 ONOSFlowsJson.append( None )
1373 flowsResults = False
1374 utilities.assert_equals(
1375 expect=True,
1376 actual=flowsResults,
1377 onpass="No error in reading flows output",
1378 onfail="Error in reading flows from ONOS" )
1379
1380 main.step( "Check for consistency in Flows from each controller" )
1381 tmp = [ len( i ) == len( ONOSFlowsJson[ 0 ] ) for i in ONOSFlowsJson ]
1382 if all( tmp ):
1383 main.log.info( "Flow count is consistent across all ONOS nodes" )
1384 else:
1385 consistentFlows = False
1386 utilities.assert_equals(
1387 expect=True,
1388 actual=consistentFlows,
1389 onpass="The flow count is consistent across all ONOS nodes",
1390 onfail="ONOS nodes have different flow counts" )
1391
1392 if flowsResults and not consistentFlows:
Jon Halle1a3b752015-07-22 13:02:46 -07001393 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001394 try:
1395 main.log.warn(
1396 "ONOS" + str( i + 1 ) + " flows: " +
1397 json.dumps( json.loads( ONOSFlows[i] ), sort_keys=True,
1398 indent=4, separators=( ',', ': ' ) ) )
1399 except ( ValueError, TypeError ):
1400 main.log.warn(
1401 "ONOS" + str( i + 1 ) + " flows: " +
1402 repr( ONOSFlows[ i ] ) )
1403 elif flowsResults and consistentFlows:
1404 flowCheck = main.TRUE
1405 flowState = ONOSFlows[ 0 ]
1406
1407 main.step( "Get the OF Table entries" )
1408 global flows
1409 flows = []
1410 for i in range( 1, 29 ):
Jon Hall9043c902015-07-30 14:23:44 -07001411 flows.append( main.Mininet1.getFlowTable( 1.3, "s" + str( i ) ) )
Jon Hall5cf14d52015-07-16 12:15:19 -07001412 if flowCheck == main.FALSE:
1413 for table in flows:
1414 main.log.warn( table )
1415 # TODO: Compare switch flow tables with ONOS flow tables
1416
1417 main.step( "Start continuous pings" )
1418 main.Mininet2.pingLong(
1419 src=main.params[ 'PING' ][ 'source1' ],
1420 target=main.params[ 'PING' ][ 'target1' ],
1421 pingTime=500 )
1422 main.Mininet2.pingLong(
1423 src=main.params[ 'PING' ][ 'source2' ],
1424 target=main.params[ 'PING' ][ 'target2' ],
1425 pingTime=500 )
1426 main.Mininet2.pingLong(
1427 src=main.params[ 'PING' ][ 'source3' ],
1428 target=main.params[ 'PING' ][ 'target3' ],
1429 pingTime=500 )
1430 main.Mininet2.pingLong(
1431 src=main.params[ 'PING' ][ 'source4' ],
1432 target=main.params[ 'PING' ][ 'target4' ],
1433 pingTime=500 )
1434 main.Mininet2.pingLong(
1435 src=main.params[ 'PING' ][ 'source5' ],
1436 target=main.params[ 'PING' ][ 'target5' ],
1437 pingTime=500 )
1438 main.Mininet2.pingLong(
1439 src=main.params[ 'PING' ][ 'source6' ],
1440 target=main.params[ 'PING' ][ 'target6' ],
1441 pingTime=500 )
1442 main.Mininet2.pingLong(
1443 src=main.params[ 'PING' ][ 'source7' ],
1444 target=main.params[ 'PING' ][ 'target7' ],
1445 pingTime=500 )
1446 main.Mininet2.pingLong(
1447 src=main.params[ 'PING' ][ 'source8' ],
1448 target=main.params[ 'PING' ][ 'target8' ],
1449 pingTime=500 )
1450 main.Mininet2.pingLong(
1451 src=main.params[ 'PING' ][ 'source9' ],
1452 target=main.params[ 'PING' ][ 'target9' ],
1453 pingTime=500 )
1454 main.Mininet2.pingLong(
1455 src=main.params[ 'PING' ][ 'source10' ],
1456 target=main.params[ 'PING' ][ 'target10' ],
1457 pingTime=500 )
1458
1459 main.step( "Collecting topology information from ONOS" )
1460 devices = []
1461 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001462 for i in range( main.numCtrls ):
1463 t = main.Thread( target=main.CLIs[i].devices,
Jon Hall5cf14d52015-07-16 12:15:19 -07001464 name="devices-" + str( i ),
1465 args=[ ] )
1466 threads.append( t )
1467 t.start()
1468
1469 for t in threads:
1470 t.join()
1471 devices.append( t.result )
1472 hosts = []
1473 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001474 for i in range( main.numCtrls ):
1475 t = main.Thread( target=main.CLIs[i].hosts,
Jon Hall5cf14d52015-07-16 12:15:19 -07001476 name="hosts-" + str( i ),
1477 args=[ ] )
1478 threads.append( t )
1479 t.start()
1480
1481 for t in threads:
1482 t.join()
1483 try:
1484 hosts.append( json.loads( t.result ) )
1485 except ( ValueError, TypeError ):
1486 # FIXME: better handling of this, print which node
1487 # Maybe use thread name?
1488 main.log.exception( "Error parsing json output of hosts" )
1489 # FIXME: should this be an empty json object instead?
1490 hosts.append( None )
1491
1492 ports = []
1493 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001494 for i in range( main.numCtrls ):
1495 t = main.Thread( target=main.CLIs[i].ports,
Jon Hall5cf14d52015-07-16 12:15:19 -07001496 name="ports-" + str( i ),
1497 args=[ ] )
1498 threads.append( t )
1499 t.start()
1500
1501 for t in threads:
1502 t.join()
1503 ports.append( t.result )
1504 links = []
1505 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001506 for i in range( main.numCtrls ):
1507 t = main.Thread( target=main.CLIs[i].links,
Jon Hall5cf14d52015-07-16 12:15:19 -07001508 name="links-" + str( i ),
1509 args=[ ] )
1510 threads.append( t )
1511 t.start()
1512
1513 for t in threads:
1514 t.join()
1515 links.append( t.result )
1516 clusters = []
1517 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001518 for i in range( main.numCtrls ):
1519 t = main.Thread( target=main.CLIs[i].clusters,
Jon Hall5cf14d52015-07-16 12:15:19 -07001520 name="clusters-" + str( i ),
1521 args=[ ] )
1522 threads.append( t )
1523 t.start()
1524
1525 for t in threads:
1526 t.join()
1527 clusters.append( t.result )
1528 # Compare json objects for hosts and dataplane clusters
1529
1530 # hosts
1531 main.step( "Host view is consistent across ONOS nodes" )
1532 consistentHostsResult = main.TRUE
1533 for controller in range( len( hosts ) ):
1534 controllerStr = str( controller + 1 )
1535 if "Error" not in hosts[ controller ]:
1536 if hosts[ controller ] == hosts[ 0 ]:
1537 continue
1538 else: # hosts not consistent
1539 main.log.error( "hosts from ONOS" +
1540 controllerStr +
1541 " is inconsistent with ONOS1" )
1542 main.log.warn( repr( hosts[ controller ] ) )
1543 consistentHostsResult = main.FALSE
1544
1545 else:
1546 main.log.error( "Error in getting ONOS hosts from ONOS" +
1547 controllerStr )
1548 consistentHostsResult = main.FALSE
1549 main.log.warn( "ONOS" + controllerStr +
1550 " hosts response: " +
1551 repr( hosts[ controller ] ) )
1552 utilities.assert_equals(
1553 expect=main.TRUE,
1554 actual=consistentHostsResult,
1555 onpass="Hosts view is consistent across all ONOS nodes",
1556 onfail="ONOS nodes have different views of hosts" )
1557
1558 main.step( "Each host has an IP address" )
1559 ipResult = main.TRUE
1560 for controller in range( 0, len( hosts ) ):
1561 controllerStr = str( controller + 1 )
1562 for host in hosts[ controller ]:
1563 if not host.get( 'ipAddresses', [ ] ):
1564 main.log.error( "DEBUG:Error with host ips on controller" +
1565 controllerStr + ": " + str( host ) )
1566 ipResult = main.FALSE
1567 utilities.assert_equals(
1568 expect=main.TRUE,
1569 actual=ipResult,
1570 onpass="The ips of the hosts aren't empty",
1571 onfail="The ip of at least one host is missing" )
1572
1573 # Strongly connected clusters of devices
1574 main.step( "Cluster view is consistent across ONOS nodes" )
1575 consistentClustersResult = main.TRUE
1576 for controller in range( len( clusters ) ):
1577 controllerStr = str( controller + 1 )
1578 if "Error" not in clusters[ controller ]:
1579 if clusters[ controller ] == clusters[ 0 ]:
1580 continue
1581 else: # clusters not consistent
1582 main.log.error( "clusters from ONOS" + controllerStr +
1583 " is inconsistent with ONOS1" )
1584 consistentClustersResult = main.FALSE
1585
1586 else:
1587 main.log.error( "Error in getting dataplane clusters " +
1588 "from ONOS" + controllerStr )
1589 consistentClustersResult = main.FALSE
1590 main.log.warn( "ONOS" + controllerStr +
1591 " clusters response: " +
1592 repr( clusters[ controller ] ) )
1593 utilities.assert_equals(
1594 expect=main.TRUE,
1595 actual=consistentClustersResult,
1596 onpass="Clusters view is consistent across all ONOS nodes",
1597 onfail="ONOS nodes have different views of clusters" )
1598 # there should always only be one cluster
1599 main.step( "Cluster view correct across ONOS nodes" )
1600 try:
1601 numClusters = len( json.loads( clusters[ 0 ] ) )
1602 except ( ValueError, TypeError ):
1603 main.log.exception( "Error parsing clusters[0]: " +
1604 repr( clusters[ 0 ] ) )
1605 clusterResults = main.FALSE
1606 if numClusters == 1:
1607 clusterResults = main.TRUE
1608 utilities.assert_equals(
1609 expect=1,
1610 actual=numClusters,
1611 onpass="ONOS shows 1 SCC",
1612 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
1613
1614 main.step( "Comparing ONOS topology to MN" )
1615 devicesResults = main.TRUE
1616 linksResults = main.TRUE
1617 hostsResults = main.TRUE
1618 mnSwitches = main.Mininet1.getSwitches()
1619 mnLinks = main.Mininet1.getLinks()
1620 mnHosts = main.Mininet1.getHosts()
Jon Halle1a3b752015-07-22 13:02:46 -07001621 for controller in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001622 controllerStr = str( controller + 1 )
1623 if devices[ controller ] and ports[ controller ] and\
1624 "Error" not in devices[ controller ] and\
1625 "Error" not in ports[ controller ]:
Jon Halle1a3b752015-07-22 13:02:46 -07001626 currentDevicesResult = main.Mininet1.compareSwitches(
1627 mnSwitches,
1628 json.loads( devices[ controller ] ),
1629 json.loads( ports[ controller ] ) )
Jon Hall5cf14d52015-07-16 12:15:19 -07001630 else:
1631 currentDevicesResult = main.FALSE
1632 utilities.assert_equals( expect=main.TRUE,
1633 actual=currentDevicesResult,
1634 onpass="ONOS" + controllerStr +
1635 " Switches view is correct",
1636 onfail="ONOS" + controllerStr +
1637 " Switches view is incorrect" )
1638 if links[ controller ] and "Error" not in links[ controller ]:
1639 currentLinksResult = main.Mininet1.compareLinks(
1640 mnSwitches, mnLinks,
1641 json.loads( links[ controller ] ) )
1642 else:
1643 currentLinksResult = main.FALSE
1644 utilities.assert_equals( expect=main.TRUE,
1645 actual=currentLinksResult,
1646 onpass="ONOS" + controllerStr +
1647 " links view is correct",
1648 onfail="ONOS" + controllerStr +
1649 " links view is incorrect" )
1650
1651 if hosts[ controller ] or "Error" not in hosts[ controller ]:
1652 currentHostsResult = main.Mininet1.compareHosts(
1653 mnHosts,
1654 hosts[ controller ] )
1655 else:
1656 currentHostsResult = main.FALSE
1657 utilities.assert_equals( expect=main.TRUE,
1658 actual=currentHostsResult,
1659 onpass="ONOS" + controllerStr +
1660 " hosts exist in Mininet",
1661 onfail="ONOS" + controllerStr +
1662 " hosts don't match Mininet" )
1663
1664 devicesResults = devicesResults and currentDevicesResult
1665 linksResults = linksResults and currentLinksResult
1666 hostsResults = hostsResults and currentHostsResult
1667
1668 main.step( "Device information is correct" )
1669 utilities.assert_equals(
1670 expect=main.TRUE,
1671 actual=devicesResults,
1672 onpass="Device information is correct",
1673 onfail="Device information is incorrect" )
1674
1675 main.step( "Links are correct" )
1676 utilities.assert_equals(
1677 expect=main.TRUE,
1678 actual=linksResults,
1679 onpass="Link are correct",
1680 onfail="Links are incorrect" )
1681
1682 main.step( "Hosts are correct" )
1683 utilities.assert_equals(
1684 expect=main.TRUE,
1685 actual=hostsResults,
1686 onpass="Hosts are correct",
1687 onfail="Hosts are incorrect" )
1688
1689 def CASE6( self, main ):
1690 """
1691 The Failure case.
1692 """
1693 import time
Jon Halle1a3b752015-07-22 13:02:46 -07001694 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07001695 assert main, "main not defined"
1696 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07001697 assert main.CLIs, "main.CLIs not defined"
1698 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07001699 try:
1700 labels
1701 except NameError:
1702 main.log.error( "labels not defined, setting to []" )
1703 global labels
1704 labels = []
1705 try:
1706 data
1707 except NameError:
1708 main.log.error( "data not defined, setting to []" )
1709 global data
1710 data = []
1711 # Reset non-persistent variables
1712 try:
1713 iCounterValue = 0
1714 except NameError:
1715 main.log.error( "iCounterValue not defined, setting to 0" )
1716 iCounterValue = 0
1717
1718 main.case( "Restart entire ONOS cluster" )
1719
1720 main.step( "Killing ONOS nodes" )
1721 killResults = main.TRUE
1722 killTime = time.time()
Jon Halle1a3b752015-07-22 13:02:46 -07001723 for node in main.nodes:
Jon Hall5cf14d52015-07-16 12:15:19 -07001724 killed = main.ONOSbench.onosKill( node.ip_address )
1725 killResults = killResults and killed
1726 utilities.assert_equals( expect=main.TRUE, actual=killResults,
1727 onpass="ONOS nodes killed",
1728 onfail="ONOS kill unsuccessful" )
1729
1730 main.step( "Checking if ONOS is up yet" )
1731 for i in range( 2 ):
1732 onosIsupResult = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07001733 for node in main.nodes:
Jon Hall5cf14d52015-07-16 12:15:19 -07001734 started = main.ONOSbench.isup( node.ip_address )
1735 if not started:
1736 main.log.error( node.name + " didn't start!" )
1737 onosIsupResult = onosIsupResult and started
1738 if onosIsupResult == main.TRUE:
1739 break
1740 utilities.assert_equals( expect=main.TRUE, actual=onosIsupResult,
1741 onpass="ONOS restarted",
1742 onfail="ONOS restart NOT successful" )
1743
1744 main.log.step( "Starting ONOS CLI sessions" )
1745 cliResults = main.TRUE
1746 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001747 for i in range( main.numCtrls ):
1748 t = main.Thread( target=main.CLIs[i].startOnosCli,
Jon Hall5cf14d52015-07-16 12:15:19 -07001749 name="startOnosCli-" + str( i ),
Jon Halle1a3b752015-07-22 13:02:46 -07001750 args=[main.nodes[i].ip_address] )
Jon Hall5cf14d52015-07-16 12:15:19 -07001751 threads.append( t )
1752 t.start()
1753
1754 for t in threads:
1755 t.join()
1756 cliResults = cliResults and t.result
1757 utilities.assert_equals( expect=main.TRUE, actual=cliResults,
1758 onpass="ONOS cli started",
1759 onfail="ONOS clis did not restart" )
1760
1761 # Grab the time of restart so we chan check how long the gossip
1762 # protocol has had time to work
1763 main.restartTime = time.time() - killTime
1764 main.log.debug( "Restart time: " + str( main.restartTime ) )
1765 labels.append( "Restart" )
1766 data.append( str( main.restartTime ) )
1767
1768 # FIXME: revisit test plan for election with madan
1769 # Rerun for election on restarted nodes
1770 runResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07001771 for cli in main.CLIs:
1772 run = main.CLIs[0].electionTestRun()
Jon Hall5cf14d52015-07-16 12:15:19 -07001773 if run != main.TRUE:
1774 main.log.error( "Error running for election on " + cli.name )
1775 runResults = runResults and run
1776 utilities.assert_equals( expect=main.TRUE, actual=runResults,
1777 onpass="Reran for election",
1778 onfail="Failed to rerun for election" )
1779
1780 # TODO: Make this configurable
1781 time.sleep( 60 )
Jon Halle1a3b752015-07-22 13:02:46 -07001782 main.log.debug( main.CLIs[0].nodes( jsonFormat=False ) )
1783 main.log.debug( main.CLIs[0].leaders( jsonFormat=False ) )
1784 main.log.debug( main.CLIs[0].partitions( jsonFormat=False ) )
Jon Hall5cf14d52015-07-16 12:15:19 -07001785
1786 def CASE7( self, main ):
1787 """
1788 Check state after ONOS failure
1789 """
1790 import json
Jon Halle1a3b752015-07-22 13:02:46 -07001791 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07001792 assert main, "main not defined"
1793 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07001794 assert main.CLIs, "main.CLIs not defined"
1795 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07001796 main.case( "Running ONOS Constant State Tests" )
1797
1798 main.step( "Check that each switch has a master" )
1799 # Assert that each device has a master
1800 rolesNotNull = main.TRUE
1801 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001802 for i in range( main.numCtrls ):
1803 t = main.Thread( target=main.CLIs[i].rolesNotNull,
Jon Hall5cf14d52015-07-16 12:15:19 -07001804 name="rolesNotNull-" + str( i ),
1805 args=[ ] )
1806 threads.append( t )
1807 t.start()
1808
1809 for t in threads:
1810 t.join()
1811 rolesNotNull = rolesNotNull and t.result
1812 utilities.assert_equals(
1813 expect=main.TRUE,
1814 actual=rolesNotNull,
1815 onpass="Each device has a master",
1816 onfail="Some devices don't have a master assigned" )
1817
1818 main.step( "Read device roles from ONOS" )
1819 ONOSMastership = []
1820 mastershipCheck = main.FALSE
1821 consistentMastership = True
1822 rolesResults = True
1823 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001824 for i in range( main.numCtrls ):
1825 t = main.Thread( target=main.CLIs[i].roles,
Jon Hall5cf14d52015-07-16 12:15:19 -07001826 name="roles-" + str( i ),
1827 args=[] )
1828 threads.append( t )
1829 t.start()
1830
1831 for t in threads:
1832 t.join()
1833 ONOSMastership.append( t.result )
1834
Jon Halle1a3b752015-07-22 13:02:46 -07001835 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001836 if not ONOSMastership[i] or "Error" in ONOSMastership[i]:
1837 main.log.error( "Error in getting ONOS" + str( i + 1 ) +
1838 " roles" )
1839 main.log.warn(
1840 "ONOS" + str( i + 1 ) + " mastership response: " +
1841 repr( ONOSMastership[i] ) )
1842 rolesResults = False
1843 utilities.assert_equals(
1844 expect=True,
1845 actual=rolesResults,
1846 onpass="No error in reading roles output",
1847 onfail="Error in reading roles from ONOS" )
1848
1849 main.step( "Check for consistency in roles from each controller" )
1850 if all([ i == ONOSMastership[ 0 ] for i in ONOSMastership ] ):
1851 main.log.info(
1852 "Switch roles are consistent across all ONOS nodes" )
1853 else:
1854 consistentMastership = False
1855 utilities.assert_equals(
1856 expect=True,
1857 actual=consistentMastership,
1858 onpass="Switch roles are consistent across all ONOS nodes",
1859 onfail="ONOS nodes have different views of switch roles" )
1860
1861 if rolesResults and not consistentMastership:
Jon Halle1a3b752015-07-22 13:02:46 -07001862 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001863 main.log.warn(
1864 "ONOS" + str( i + 1 ) + " roles: ",
1865 json.dumps(
1866 json.loads( ONOSMastership[ i ] ),
1867 sort_keys=True,
1868 indent=4,
1869 separators=( ',', ': ' ) ) )
1870 elif rolesResults and not consistentMastership:
1871 mastershipCheck = main.TRUE
1872
1873 '''
1874 description2 = "Compare switch roles from before failure"
1875 main.step( description2 )
1876 try:
1877 currentJson = json.loads( ONOSMastership[0] )
1878 oldJson = json.loads( mastershipState )
1879 except ( ValueError, TypeError ):
1880 main.log.exception( "Something is wrong with parsing " +
1881 "ONOSMastership[0] or mastershipState" )
1882 main.log.error( "ONOSMastership[0]: " + repr( ONOSMastership[0] ) )
1883 main.log.error( "mastershipState" + repr( mastershipState ) )
1884 main.cleanup()
1885 main.exit()
1886 mastershipCheck = main.TRUE
1887 for i in range( 1, 29 ):
1888 switchDPID = str(
1889 main.Mininet1.getSwitchDPID( switch="s" + str( i ) ) )
1890 current = [ switch[ 'master' ] for switch in currentJson
1891 if switchDPID in switch[ 'id' ] ]
1892 old = [ switch[ 'master' ] for switch in oldJson
1893 if switchDPID in switch[ 'id' ] ]
1894 if current == old:
1895 mastershipCheck = mastershipCheck and main.TRUE
1896 else:
1897 main.log.warn( "Mastership of switch %s changed" % switchDPID )
1898 mastershipCheck = main.FALSE
1899 utilities.assert_equals(
1900 expect=main.TRUE,
1901 actual=mastershipCheck,
1902 onpass="Mastership of Switches was not changed",
1903 onfail="Mastership of some switches changed" )
1904 '''
1905 # NOTE: we expect mastership to change on controller failure
1906
1907 main.step( "Get the intents and compare across all nodes" )
1908 ONOSIntents = []
1909 intentCheck = main.FALSE
1910 consistentIntents = True
1911 intentsResults = True
1912 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001913 for i in range( main.numCtrls ):
1914 t = main.Thread( target=main.CLIs[i].intents,
Jon Hall5cf14d52015-07-16 12:15:19 -07001915 name="intents-" + str( i ),
1916 args=[],
1917 kwargs={ 'jsonFormat': True } )
1918 threads.append( t )
1919 t.start()
1920
1921 for t in threads:
1922 t.join()
1923 ONOSIntents.append( t.result )
1924
Jon Halle1a3b752015-07-22 13:02:46 -07001925 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001926 if not ONOSIntents[ i ] or "Error" in ONOSIntents[ i ]:
1927 main.log.error( "Error in getting ONOS" + str( i + 1 ) +
1928 " intents" )
1929 main.log.warn( "ONOS" + str( i + 1 ) + " intents response: " +
1930 repr( ONOSIntents[ i ] ) )
1931 intentsResults = False
1932 utilities.assert_equals(
1933 expect=True,
1934 actual=intentsResults,
1935 onpass="No error in reading intents output",
1936 onfail="Error in reading intents from ONOS" )
1937
1938 main.step( "Check for consistency in Intents from each controller" )
1939 if all([ sorted( i ) == sorted( ONOSIntents[ 0 ] ) for i in ONOSIntents ] ):
1940 main.log.info( "Intents are consistent across all ONOS " +
1941 "nodes" )
1942 else:
1943 consistentIntents = False
1944
1945 # Try to make it easy to figure out what is happening
1946 #
1947 # Intent ONOS1 ONOS2 ...
1948 # 0x01 INSTALLED INSTALLING
1949 # ... ... ...
1950 # ... ... ...
1951 title = " ID"
Jon Halle1a3b752015-07-22 13:02:46 -07001952 for n in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001953 title += " " * 10 + "ONOS" + str( n + 1 )
1954 main.log.warn( title )
1955 # get all intent keys in the cluster
1956 keys = []
1957 for nodeStr in ONOSIntents:
1958 node = json.loads( nodeStr )
1959 for intent in node:
1960 keys.append( intent.get( 'id' ) )
1961 keys = set( keys )
1962 for key in keys:
1963 row = "%-13s" % key
1964 for nodeStr in ONOSIntents:
1965 node = json.loads( nodeStr )
1966 for intent in node:
1967 if intent.get( 'id' ) == key:
1968 row += "%-15s" % intent.get( 'state' )
1969 main.log.warn( row )
1970 # End table view
1971
1972 utilities.assert_equals(
1973 expect=True,
1974 actual=consistentIntents,
1975 onpass="Intents are consistent across all ONOS nodes",
1976 onfail="ONOS nodes have different views of intents" )
1977 intentStates = []
1978 for node in ONOSIntents: # Iter through ONOS nodes
1979 nodeStates = []
1980 # Iter through intents of a node
1981 try:
1982 for intent in json.loads( node ):
1983 nodeStates.append( intent[ 'state' ] )
1984 except ( ValueError, TypeError ):
1985 main.log.exception( "Error in parsing intents" )
1986 main.log.error( repr( node ) )
1987 intentStates.append( nodeStates )
1988 out = [ (i, nodeStates.count( i ) ) for i in set( nodeStates ) ]
1989 main.log.info( dict( out ) )
1990
1991 if intentsResults and not consistentIntents:
Jon Halle1a3b752015-07-22 13:02:46 -07001992 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001993 main.log.warn( "ONOS" + str( i + 1 ) + " intents: " )
1994 main.log.warn( json.dumps(
1995 json.loads( ONOSIntents[ i ] ),
1996 sort_keys=True,
1997 indent=4,
1998 separators=( ',', ': ' ) ) )
1999 elif intentsResults and consistentIntents:
2000 intentCheck = main.TRUE
2001
2002 # NOTE: Store has no durability, so intents are lost across system
2003 # restarts
2004 """
2005 main.step( "Compare current intents with intents before the failure" )
2006 # NOTE: this requires case 5 to pass for intentState to be set.
2007 # maybe we should stop the test if that fails?
2008 sameIntents = main.FALSE
2009 if intentState and intentState == ONOSIntents[ 0 ]:
2010 sameIntents = main.TRUE
2011 main.log.info( "Intents are consistent with before failure" )
2012 # TODO: possibly the states have changed? we may need to figure out
2013 # what the acceptable states are
2014 elif len( intentState ) == len( ONOSIntents[ 0 ] ):
2015 sameIntents = main.TRUE
2016 try:
2017 before = json.loads( intentState )
2018 after = json.loads( ONOSIntents[ 0 ] )
2019 for intent in before:
2020 if intent not in after:
2021 sameIntents = main.FALSE
2022 main.log.debug( "Intent is not currently in ONOS " +
2023 "(at least in the same form):" )
2024 main.log.debug( json.dumps( intent ) )
2025 except ( ValueError, TypeError ):
2026 main.log.exception( "Exception printing intents" )
2027 main.log.debug( repr( ONOSIntents[0] ) )
2028 main.log.debug( repr( intentState ) )
2029 if sameIntents == main.FALSE:
2030 try:
2031 main.log.debug( "ONOS intents before: " )
2032 main.log.debug( json.dumps( json.loads( intentState ),
2033 sort_keys=True, indent=4,
2034 separators=( ',', ': ' ) ) )
2035 main.log.debug( "Current ONOS intents: " )
2036 main.log.debug( json.dumps( json.loads( ONOSIntents[ 0 ] ),
2037 sort_keys=True, indent=4,
2038 separators=( ',', ': ' ) ) )
2039 except ( ValueError, TypeError ):
2040 main.log.exception( "Exception printing intents" )
2041 main.log.debug( repr( ONOSIntents[0] ) )
2042 main.log.debug( repr( intentState ) )
2043 utilities.assert_equals(
2044 expect=main.TRUE,
2045 actual=sameIntents,
2046 onpass="Intents are consistent with before failure",
2047 onfail="The Intents changed during failure" )
2048 intentCheck = intentCheck and sameIntents
2049 """
2050 main.step( "Get the OF Table entries and compare to before " +
2051 "component failure" )
2052 FlowTables = main.TRUE
2053 flows2 = []
2054 for i in range( 28 ):
2055 main.log.info( "Checking flow table on s" + str( i + 1 ) )
Jon Hall9043c902015-07-30 14:23:44 -07002056 tmpFlows = main.Mininet1.getFlowTable( 1.3, "s" + str( i + 1 ) )
Jon Hall5cf14d52015-07-16 12:15:19 -07002057 flows2.append( tmpFlows )
Jon Hall9043c902015-07-30 14:23:44 -07002058 tempResult = main.Mininet1.flowComp(
Jon Hall5cf14d52015-07-16 12:15:19 -07002059 flow1=flows[ i ],
2060 flow2=tmpFlows )
2061 FlowTables = FlowTables and tempResult
2062 if FlowTables == main.FALSE:
2063 main.log.info( "Differences in flow table for switch: s" +
2064 str( i + 1 ) )
2065 utilities.assert_equals(
2066 expect=main.TRUE,
2067 actual=FlowTables,
2068 onpass="No changes were found in the flow tables",
2069 onfail="Changes were found in the flow tables" )
2070
2071 main.Mininet2.pingLongKill()
2072 '''
2073 # main.step( "Check the continuous pings to ensure that no packets " +
2074 # "were dropped during component failure" )
2075 main.Mininet2.pingKill( main.params[ 'TESTONUSER' ],
2076 main.params[ 'TESTONIP' ] )
2077 LossInPings = main.FALSE
2078 # NOTE: checkForLoss returns main.FALSE with 0% packet loss
2079 for i in range( 8, 18 ):
2080 main.log.info(
2081 "Checking for a loss in pings along flow from s" +
2082 str( i ) )
2083 LossInPings = main.Mininet2.checkForLoss(
2084 "/tmp/ping.h" +
2085 str( i ) ) or LossInPings
2086 if LossInPings == main.TRUE:
2087 main.log.info( "Loss in ping detected" )
2088 elif LossInPings == main.ERROR:
2089 main.log.info( "There are multiple mininet process running" )
2090 elif LossInPings == main.FALSE:
2091 main.log.info( "No Loss in the pings" )
2092 main.log.info( "No loss of dataplane connectivity" )
2093 # utilities.assert_equals(
2094 # expect=main.FALSE,
2095 # actual=LossInPings,
2096 # onpass="No Loss of connectivity",
2097 # onfail="Loss of dataplane connectivity detected" )
2098
2099 # NOTE: Since intents are not persisted with IntnentStore,
2100 # we expect loss in dataplane connectivity
2101 LossInPings = main.FALSE
2102 '''
2103
2104 main.step( "Leadership Election is still functional" )
2105 # Test of LeadershipElection
2106 leaderList = []
2107 leaderResult = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07002108 for cli in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -07002109 leaderN = cli.electionTestLeader()
2110 leaderList.append( leaderN )
2111 if leaderN == main.FALSE:
2112 # error in response
2113 main.log.error( "Something is wrong with " +
2114 "electionTestLeader function, check the" +
2115 " error logs" )
2116 leaderResult = main.FALSE
2117 elif leaderN is None:
2118 main.log.error( cli.name +
2119 " shows no leader for the election-app." )
2120 leaderResult = main.FALSE
2121 if len( set( leaderList ) ) != 1:
2122 leaderResult = main.FALSE
2123 main.log.error(
2124 "Inconsistent view of leader for the election test app" )
2125 # TODO: print the list
2126 utilities.assert_equals(
2127 expect=main.TRUE,
2128 actual=leaderResult,
2129 onpass="Leadership election passed",
2130 onfail="Something went wrong with Leadership election" )
2131
2132 def CASE8( self, main ):
2133 """
2134 Compare topo
2135 """
2136 import json
2137 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002138 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002139 assert main, "main not defined"
2140 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002141 assert main.CLIs, "main.CLIs not defined"
2142 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002143
2144 main.case( "Compare ONOS Topology view to Mininet topology" )
Jon Hall783bbf92015-07-23 14:33:19 -07002145 main.caseExplanation = "Compare topology objects between Mininet" +\
Jon Hall5cf14d52015-07-16 12:15:19 -07002146 " and ONOS"
2147
2148 main.step( "Comparing ONOS topology to MN" )
2149 devicesResults = main.TRUE
2150 linksResults = main.TRUE
2151 hostsResults = main.TRUE
2152 hostAttachmentResults = True
2153 topoResult = main.FALSE
2154 elapsed = 0
2155 count = 0
2156 main.step( "Collecting topology information from ONOS" )
2157 startTime = time.time()
2158 # Give time for Gossip to work
2159 while topoResult == main.FALSE and elapsed < 60:
2160 count += 1
2161 cliStart = time.time()
2162 devices = []
2163 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002164 for i in range( main.numCtrls ):
2165 t = main.Thread( target=main.CLIs[i].devices,
Jon Hall5cf14d52015-07-16 12:15:19 -07002166 name="devices-" + str( i ),
2167 args=[ ] )
2168 threads.append( t )
2169 t.start()
2170
2171 for t in threads:
2172 t.join()
2173 devices.append( t.result )
2174 hosts = []
2175 ipResult = main.TRUE
2176 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002177 for i in range( main.numCtrls ):
2178 t = main.Thread( target=main.CLIs[i].hosts,
Jon Hall5cf14d52015-07-16 12:15:19 -07002179 name="hosts-" + str( i ),
2180 args=[ ] )
2181 threads.append( t )
2182 t.start()
2183
2184 for t in threads:
2185 t.join()
2186 try:
2187 hosts.append( json.loads( t.result ) )
2188 except ( ValueError, TypeError ):
2189 main.log.exception( "Error parsing hosts results" )
2190 main.log.error( repr( t.result ) )
2191 for controller in range( 0, len( hosts ) ):
2192 controllerStr = str( controller + 1 )
2193 for host in hosts[ controller ]:
2194 if host is None or host.get( 'ipAddresses', [] ) == []:
2195 main.log.error(
2196 "DEBUG:Error with host ipAddresses on controller" +
2197 controllerStr + ": " + str( host ) )
2198 ipResult = main.FALSE
2199 ports = []
2200 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002201 for i in range( main.numCtrls ):
2202 t = main.Thread( target=main.CLIs[i].ports,
Jon Hall5cf14d52015-07-16 12:15:19 -07002203 name="ports-" + str( i ),
2204 args=[ ] )
2205 threads.append( t )
2206 t.start()
2207
2208 for t in threads:
2209 t.join()
2210 ports.append( t.result )
2211 links = []
2212 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002213 for i in range( main.numCtrls ):
2214 t = main.Thread( target=main.CLIs[i].links,
Jon Hall5cf14d52015-07-16 12:15:19 -07002215 name="links-" + str( i ),
2216 args=[ ] )
2217 threads.append( t )
2218 t.start()
2219
2220 for t in threads:
2221 t.join()
2222 links.append( t.result )
2223 clusters = []
2224 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002225 for i in range( main.numCtrls ):
2226 t = main.Thread( target=main.CLIs[i].clusters,
Jon Hall5cf14d52015-07-16 12:15:19 -07002227 name="clusters-" + str( i ),
2228 args=[ ] )
2229 threads.append( t )
2230 t.start()
2231
2232 for t in threads:
2233 t.join()
2234 clusters.append( t.result )
2235
2236 elapsed = time.time() - startTime
2237 cliTime = time.time() - cliStart
2238 print "Elapsed time: " + str( elapsed )
2239 print "CLI time: " + str( cliTime )
2240
2241 mnSwitches = main.Mininet1.getSwitches()
2242 mnLinks = main.Mininet1.getLinks()
2243 mnHosts = main.Mininet1.getHosts()
Jon Halle1a3b752015-07-22 13:02:46 -07002244 for controller in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07002245 controllerStr = str( controller + 1 )
2246 if devices[ controller ] and ports[ controller ] and\
2247 "Error" not in devices[ controller ] and\
2248 "Error" not in ports[ controller ]:
2249
2250 currentDevicesResult = main.Mininet1.compareSwitches(
2251 mnSwitches,
2252 json.loads( devices[ controller ] ),
2253 json.loads( ports[ controller ] ) )
2254 else:
2255 currentDevicesResult = main.FALSE
2256 utilities.assert_equals( expect=main.TRUE,
2257 actual=currentDevicesResult,
2258 onpass="ONOS" + controllerStr +
2259 " Switches view is correct",
2260 onfail="ONOS" + controllerStr +
2261 " Switches view is incorrect" )
2262
2263 if links[ controller ] and "Error" not in links[ controller ]:
2264 currentLinksResult = main.Mininet1.compareLinks(
2265 mnSwitches, mnLinks,
2266 json.loads( links[ controller ] ) )
2267 else:
2268 currentLinksResult = main.FALSE
2269 utilities.assert_equals( expect=main.TRUE,
2270 actual=currentLinksResult,
2271 onpass="ONOS" + controllerStr +
2272 " links view is correct",
2273 onfail="ONOS" + controllerStr +
2274 " links view is incorrect" )
2275
2276 if hosts[ controller ] or "Error" not in hosts[ controller ]:
2277 currentHostsResult = main.Mininet1.compareHosts(
2278 mnHosts,
2279 hosts[ controller ] )
2280 else:
2281 currentHostsResult = main.FALSE
2282 utilities.assert_equals( expect=main.TRUE,
2283 actual=currentHostsResult,
2284 onpass="ONOS" + controllerStr +
2285 " hosts exist in Mininet",
2286 onfail="ONOS" + controllerStr +
2287 " hosts don't match Mininet" )
2288 # CHECKING HOST ATTACHMENT POINTS
2289 hostAttachment = True
2290 noHosts = False
2291 # FIXME: topo-HA/obelisk specific mappings:
2292 # key is mac and value is dpid
2293 mappings = {}
2294 for i in range( 1, 29 ): # hosts 1 through 28
2295 # set up correct variables:
2296 macId = "00:" * 5 + hex( i ).split( "0x" )[1].upper().zfill(2)
2297 if i == 1:
2298 deviceId = "1000".zfill(16)
2299 elif i == 2:
2300 deviceId = "2000".zfill(16)
2301 elif i == 3:
2302 deviceId = "3000".zfill(16)
2303 elif i == 4:
2304 deviceId = "3004".zfill(16)
2305 elif i == 5:
2306 deviceId = "5000".zfill(16)
2307 elif i == 6:
2308 deviceId = "6000".zfill(16)
2309 elif i == 7:
2310 deviceId = "6007".zfill(16)
2311 elif i >= 8 and i <= 17:
2312 dpid = '3' + str( i ).zfill( 3 )
2313 deviceId = dpid.zfill(16)
2314 elif i >= 18 and i <= 27:
2315 dpid = '6' + str( i ).zfill( 3 )
2316 deviceId = dpid.zfill(16)
2317 elif i == 28:
2318 deviceId = "2800".zfill(16)
2319 mappings[ macId ] = deviceId
2320 if hosts[ controller ] or "Error" not in hosts[ controller ]:
2321 if hosts[ controller ] == []:
2322 main.log.warn( "There are no hosts discovered" )
2323 noHosts = True
2324 else:
2325 for host in hosts[ controller ]:
2326 mac = None
2327 location = None
2328 device = None
2329 port = None
2330 try:
2331 mac = host.get( 'mac' )
2332 assert mac, "mac field could not be found for this host object"
2333
2334 location = host.get( 'location' )
2335 assert location, "location field could not be found for this host object"
2336
2337 # Trim the protocol identifier off deviceId
2338 device = str( location.get( 'elementId' ) ).split(':')[1]
2339 assert device, "elementId field could not be found for this host location object"
2340
2341 port = location.get( 'port' )
2342 assert port, "port field could not be found for this host location object"
2343
2344 # Now check if this matches where they should be
2345 if mac and device and port:
2346 if str( port ) != "1":
2347 main.log.error( "The attachment port is incorrect for " +
2348 "host " + str( mac ) +
2349 ". Expected: 1 Actual: " + str( port) )
2350 hostAttachment = False
2351 if device != mappings[ str( mac ) ]:
2352 main.log.error( "The attachment device is incorrect for " +
2353 "host " + str( mac ) +
2354 ". Expected: " + mappings[ str( mac ) ] +
2355 " Actual: " + device )
2356 hostAttachment = False
2357 else:
2358 hostAttachment = False
2359 except AssertionError:
2360 main.log.exception( "Json object not as expected" )
2361 main.log.error( repr( host ) )
2362 hostAttachment = False
2363 else:
2364 main.log.error( "No hosts json output or \"Error\"" +
2365 " in output. hosts = " +
2366 repr( hosts[ controller ] ) )
2367 if noHosts is False:
2368 # TODO: Find a way to know if there should be hosts in a
2369 # given point of the test
2370 hostAttachment = True
2371
2372 # END CHECKING HOST ATTACHMENT POINTS
2373 devicesResults = devicesResults and currentDevicesResult
2374 linksResults = linksResults and currentLinksResult
2375 hostsResults = hostsResults and currentHostsResult
2376 hostAttachmentResults = hostAttachmentResults and\
2377 hostAttachment
2378 topoResult = ( devicesResults and linksResults
2379 and hostsResults and ipResult and
2380 hostAttachmentResults )
2381
2382 # Compare json objects for hosts and dataplane clusters
2383
2384 # hosts
2385 main.step( "Hosts view is consistent across all ONOS nodes" )
2386 consistentHostsResult = main.TRUE
2387 for controller in range( len( hosts ) ):
2388 controllerStr = str( controller + 1 )
2389 if "Error" not in hosts[ controller ]:
2390 if hosts[ controller ] == hosts[ 0 ]:
2391 continue
2392 else: # hosts not consistent
2393 main.log.error( "hosts from ONOS" + controllerStr +
2394 " is inconsistent with ONOS1" )
2395 main.log.warn( repr( hosts[ controller ] ) )
2396 consistentHostsResult = main.FALSE
2397
2398 else:
2399 main.log.error( "Error in getting ONOS hosts from ONOS" +
2400 controllerStr )
2401 consistentHostsResult = main.FALSE
2402 main.log.warn( "ONOS" + controllerStr +
2403 " hosts response: " +
2404 repr( hosts[ controller ] ) )
2405 utilities.assert_equals(
2406 expect=main.TRUE,
2407 actual=consistentHostsResult,
2408 onpass="Hosts view is consistent across all ONOS nodes",
2409 onfail="ONOS nodes have different views of hosts" )
2410
2411 main.step( "Hosts information is correct" )
2412 hostsResults = hostsResults and ipResult
2413 utilities.assert_equals(
2414 expect=main.TRUE,
2415 actual=hostsResults,
2416 onpass="Host information is correct",
2417 onfail="Host information is incorrect" )
2418
2419 main.step( "Host attachment points to the network" )
2420 utilities.assert_equals(
2421 expect=True,
2422 actual=hostAttachmentResults,
2423 onpass="Hosts are correctly attached to the network",
2424 onfail="ONOS did not correctly attach hosts to the network" )
2425
2426 # Strongly connected clusters of devices
2427 main.step( "Clusters view is consistent across all ONOS nodes" )
2428 consistentClustersResult = main.TRUE
2429 for controller in range( len( clusters ) ):
2430 controllerStr = str( controller + 1 )
2431 if "Error" not in clusters[ controller ]:
2432 if clusters[ controller ] == clusters[ 0 ]:
2433 continue
2434 else: # clusters not consistent
2435 main.log.error( "clusters from ONOS" +
2436 controllerStr +
2437 " is inconsistent with ONOS1" )
2438 consistentClustersResult = main.FALSE
2439
2440 else:
2441 main.log.error( "Error in getting dataplane clusters " +
2442 "from ONOS" + controllerStr )
2443 consistentClustersResult = main.FALSE
2444 main.log.warn( "ONOS" + controllerStr +
2445 " clusters response: " +
2446 repr( clusters[ controller ] ) )
2447 utilities.assert_equals(
2448 expect=main.TRUE,
2449 actual=consistentClustersResult,
2450 onpass="Clusters view is consistent across all ONOS nodes",
2451 onfail="ONOS nodes have different views of clusters" )
2452
2453 main.step( "There is only one SCC" )
2454 # there should always only be one cluster
2455 try:
2456 numClusters = len( json.loads( clusters[ 0 ] ) )
2457 except ( ValueError, TypeError ):
2458 main.log.exception( "Error parsing clusters[0]: " +
2459 repr( clusters[0] ) )
2460 clusterResults = main.FALSE
2461 if numClusters == 1:
2462 clusterResults = main.TRUE
2463 utilities.assert_equals(
2464 expect=1,
2465 actual=numClusters,
2466 onpass="ONOS shows 1 SCC",
2467 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
2468
2469 topoResult = ( devicesResults and linksResults
2470 and hostsResults and consistentHostsResult
2471 and consistentClustersResult and clusterResults
2472 and ipResult and hostAttachmentResults )
2473
2474 topoResult = topoResult and int( count <= 2 )
2475 note = "note it takes about " + str( int( cliTime ) ) + \
2476 " seconds for the test to make all the cli calls to fetch " +\
2477 "the topology from each ONOS instance"
2478 main.log.info(
2479 "Very crass estimate for topology discovery/convergence( " +
2480 str( note ) + " ): " + str( elapsed ) + " seconds, " +
2481 str( count ) + " tries" )
2482
2483 main.step( "Device information is correct" )
2484 utilities.assert_equals(
2485 expect=main.TRUE,
2486 actual=devicesResults,
2487 onpass="Device information is correct",
2488 onfail="Device information is incorrect" )
2489
2490 main.step( "Links are correct" )
2491 utilities.assert_equals(
2492 expect=main.TRUE,
2493 actual=linksResults,
2494 onpass="Link are correct",
2495 onfail="Links are incorrect" )
2496
2497 # FIXME: move this to an ONOS state case
2498 main.step( "Checking ONOS nodes" )
2499 nodesOutput = []
2500 nodeResults = main.TRUE
2501 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002502 for i in range( main.numCtrls ):
2503 t = main.Thread( target=main.CLIs[i].nodes,
Jon Hall5cf14d52015-07-16 12:15:19 -07002504 name="nodes-" + str( i ),
2505 args=[ ] )
2506 threads.append( t )
2507 t.start()
2508
2509 for t in threads:
2510 t.join()
2511 nodesOutput.append( t.result )
Jon Halle1a3b752015-07-22 13:02:46 -07002512 ips = [ node.ip_address for node in main.nodes ]
Jon Hall5cf14d52015-07-16 12:15:19 -07002513 for i in nodesOutput:
2514 try:
2515 current = json.loads( i )
2516 for node in current:
2517 currentResult = main.FALSE
2518 if node['ip'] in ips: # node in nodes() output is in cell
2519 if node['state'] == 'ACTIVE':
2520 currentResult = main.TRUE
2521 else:
2522 main.log.error( "Error in ONOS node availability" )
2523 main.log.error(
2524 json.dumps( current,
2525 sort_keys=True,
2526 indent=4,
2527 separators=( ',', ': ' ) ) )
2528 break
2529 nodeResults = nodeResults and currentResult
2530 except ( ValueError, TypeError ):
2531 main.log.error( "Error parsing nodes output" )
2532 main.log.warn( repr( i ) )
2533 utilities.assert_equals( expect=main.TRUE, actual=nodeResults,
2534 onpass="Nodes check successful",
2535 onfail="Nodes check NOT successful" )
2536
2537 def CASE9( self, main ):
2538 """
2539 Link s3-s28 down
2540 """
2541 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002542 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002543 assert main, "main not defined"
2544 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002545 assert main.CLIs, "main.CLIs not defined"
2546 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002547 # NOTE: You should probably run a topology check after this
2548
2549 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
2550
2551 description = "Turn off a link to ensure that Link Discovery " +\
2552 "is working properly"
2553 main.case( description )
2554
2555 main.step( "Kill Link between s3 and s28" )
2556 LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" )
2557 main.log.info( "Waiting " + str( linkSleep ) +
2558 " seconds for link down to be discovered" )
2559 time.sleep( linkSleep )
2560 utilities.assert_equals( expect=main.TRUE, actual=LinkDown,
2561 onpass="Link down successful",
2562 onfail="Failed to bring link down" )
2563 # TODO do some sort of check here
2564
2565 def CASE10( self, main ):
2566 """
2567 Link s3-s28 up
2568 """
2569 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002570 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002571 assert main, "main not defined"
2572 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002573 assert main.CLIs, "main.CLIs not defined"
2574 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002575 # NOTE: You should probably run a topology check after this
2576
2577 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
2578
2579 description = "Restore a link to ensure that Link Discovery is " + \
2580 "working properly"
2581 main.case( description )
2582
2583 main.step( "Bring link between s3 and s28 back up" )
2584 LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" )
2585 main.log.info( "Waiting " + str( linkSleep ) +
2586 " seconds for link up to be discovered" )
2587 time.sleep( linkSleep )
2588 utilities.assert_equals( expect=main.TRUE, actual=LinkUp,
2589 onpass="Link up successful",
2590 onfail="Failed to bring link up" )
2591 # TODO do some sort of check here
2592
2593 def CASE11( self, main ):
2594 """
2595 Switch Down
2596 """
2597 # NOTE: You should probably run a topology check after this
2598 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002599 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002600 assert main, "main not defined"
2601 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002602 assert main.CLIs, "main.CLIs not defined"
2603 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002604
2605 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
2606
2607 description = "Killing a switch to ensure it is discovered correctly"
2608 main.case( description )
2609 switch = main.params[ 'kill' ][ 'switch' ]
2610 switchDPID = main.params[ 'kill' ][ 'dpid' ]
2611
2612 # TODO: Make this switch parameterizable
2613 main.step( "Kill " + switch )
2614 main.log.info( "Deleting " + switch )
2615 main.Mininet1.delSwitch( switch )
2616 main.log.info( "Waiting " + str( switchSleep ) +
2617 " seconds for switch down to be discovered" )
2618 time.sleep( switchSleep )
2619 device = main.ONOScli1.getDevice( dpid=switchDPID )
2620 # Peek at the deleted switch
2621 main.log.warn( str( device ) )
2622 result = main.FALSE
2623 if device and device[ 'available' ] is False:
2624 result = main.TRUE
2625 utilities.assert_equals( expect=main.TRUE, actual=result,
2626 onpass="Kill switch successful",
2627 onfail="Failed to kill switch?" )
2628
2629 def CASE12( self, main ):
2630 """
2631 Switch Up
2632 """
2633 # NOTE: You should probably run a topology check after this
2634 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002635 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002636 assert main, "main not defined"
2637 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002638 assert main.CLIs, "main.CLIs not defined"
2639 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002640 assert ONOS1Port, "ONOS1Port not defined"
2641 assert ONOS2Port, "ONOS2Port not defined"
2642 assert ONOS3Port, "ONOS3Port not defined"
2643 assert ONOS4Port, "ONOS4Port not defined"
2644 assert ONOS5Port, "ONOS5Port not defined"
2645 assert ONOS6Port, "ONOS6Port not defined"
2646 assert ONOS7Port, "ONOS7Port not defined"
2647
2648 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
2649 switch = main.params[ 'kill' ][ 'switch' ]
2650 switchDPID = main.params[ 'kill' ][ 'dpid' ]
2651 links = main.params[ 'kill' ][ 'links' ].split()
2652 description = "Adding a switch to ensure it is discovered correctly"
2653 main.case( description )
2654
2655 main.step( "Add back " + switch )
2656 main.Mininet1.addSwitch( switch, dpid=switchDPID )
2657 for peer in links:
2658 main.Mininet1.addLink( switch, peer )
2659 ipList = []
Jon Halle1a3b752015-07-22 13:02:46 -07002660 for i in range( main.numCtrls ):
2661 ipList.append( main.nodes[ i ].ip_address )
Jon Hall5cf14d52015-07-16 12:15:19 -07002662 main.Mininet1.assignSwController( sw=switch, ip=ipList )
2663 main.log.info( "Waiting " + str( switchSleep ) +
2664 " seconds for switch up to be discovered" )
2665 time.sleep( switchSleep )
2666 device = main.ONOScli1.getDevice( dpid=switchDPID )
2667 # Peek at the deleted switch
2668 main.log.warn( str( device ) )
2669 result = main.FALSE
2670 if device and device[ 'available' ]:
2671 result = main.TRUE
2672 utilities.assert_equals( expect=main.TRUE, actual=result,
2673 onpass="add switch successful",
2674 onfail="Failed to add switch?" )
2675
2676 def CASE13( self, main ):
2677 """
2678 Clean up
2679 """
2680 import os
2681 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002682 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002683 assert main, "main not defined"
2684 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002685 assert main.CLIs, "main.CLIs not defined"
2686 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002687
2688 # printing colors to terminal
2689 colors = { 'cyan': '\033[96m', 'purple': '\033[95m',
2690 'blue': '\033[94m', 'green': '\033[92m',
2691 'yellow': '\033[93m', 'red': '\033[91m', 'end': '\033[0m' }
2692 main.case( "Test Cleanup" )
2693 main.step( "Killing tcpdumps" )
2694 main.Mininet2.stopTcpdump()
2695
2696 testname = main.TEST
2697 if main.params[ 'BACKUP' ] == "True":
2698 main.step( "Copying MN pcap and ONOS log files to test station" )
2699 teststationUser = main.params[ 'BACKUP' ][ 'TESTONUSER' ]
2700 teststationIP = main.params[ 'BACKUP' ][ 'TESTONIP' ]
2701 # NOTE: MN Pcap file is being saved to ~/packet_captures
2702 # scp this file as MN and TestON aren't necessarily the same vm
2703 # FIXME: scp
2704 # mn files
2705 # TODO: Load these from params
2706 # NOTE: must end in /
2707 logFolder = "/opt/onos/log/"
2708 logFiles = [ "karaf.log", "karaf.log.1" ]
2709 # NOTE: must end in /
2710 dstDir = "~/packet_captures/"
2711 for f in logFiles:
Jon Halle1a3b752015-07-22 13:02:46 -07002712 for node in main.nodes:
Jon Hall5cf14d52015-07-16 12:15:19 -07002713 main.ONOSbench.handle.sendline( "scp sdn@" + node.ip_address +
2714 ":" + logFolder + f + " " +
2715 teststationUser + "@" +
2716 teststationIP + ":" +
2717 dstDir + str( testname ) +
2718 "-" + node.name + "-" + f )
2719 main.ONOSbench.handle.expect( "\$" )
2720
2721 # std*.log's
2722 # NOTE: must end in /
2723 logFolder = "/opt/onos/var/"
2724 logFiles = [ "stderr.log", "stdout.log" ]
2725 # NOTE: must end in /
2726 dstDir = "~/packet_captures/"
2727 for f in logFiles:
Jon Halle1a3b752015-07-22 13:02:46 -07002728 for node in main.nodes:
Jon Hall5cf14d52015-07-16 12:15:19 -07002729 main.ONOSbench.handle.sendline( "scp sdn@" + node.ip_address +
2730 ":" + logFolder + f + " " +
2731 teststationUser + "@" +
2732 teststationIP + ":" +
2733 dstDir + str( testname ) +
2734 "-" + node.name + "-" + f )
2735 main.ONOSbench.handle.expect( "\$" )
2736 # sleep so scp can finish
2737 time.sleep( 10 )
2738 main.step( "Packing and rotating pcap archives" )
2739 os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) )
2740
2741 main.step( "Stopping Mininet" )
2742 mnResult = main.Mininet1.stopNet()
2743 utilities.assert_equals( expect=main.TRUE, actual=mnResult,
2744 onpass="Mininet stopped",
2745 onfail="MN cleanup NOT successful" )
2746
2747 main.step( "Checking ONOS Logs for errors" )
Jon Halle1a3b752015-07-22 13:02:46 -07002748 for node in main.nodes:
Jon Hall5cf14d52015-07-16 12:15:19 -07002749 print colors[ 'purple' ] + "Checking logs for errors on " + \
2750 node.name + ":" + colors[ 'end' ]
2751 print main.ONOSbench.checkLogs( node.ip_address, restart=True )
2752
2753 try:
2754 timerLog = open( main.logdir + "/Timers.csv", 'w')
2755 main.log.error( ", ".join( labels ) + "\n" + ", ".join( data ) )
2756 timerLog.write( ", ".join( labels ) + "\n" + ", ".join( data ) )
2757 timerLog.close()
2758 except NameError, e:
2759 main.log.exception(e)
2760
2761 def CASE14( self, main ):
2762 """
2763 start election app on all onos nodes
2764 """
Jon Halle1a3b752015-07-22 13:02:46 -07002765 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002766 assert main, "main not defined"
2767 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002768 assert main.CLIs, "main.CLIs not defined"
2769 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002770
2771 main.case("Start Leadership Election app")
2772 main.step( "Install leadership election app" )
2773 appResult = main.ONOScli1.activateApp( "org.onosproject.election" )
2774 utilities.assert_equals(
2775 expect=main.TRUE,
2776 actual=appResult,
2777 onpass="Election app installed",
2778 onfail="Something went wrong with installing Leadership election" )
2779
2780 main.step( "Run for election on each node" )
2781 leaderResult = main.TRUE
2782 leaders = []
Jon Halle1a3b752015-07-22 13:02:46 -07002783 for cli in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -07002784 cli.electionTestRun()
Jon Halle1a3b752015-07-22 13:02:46 -07002785 for cli in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -07002786 leader = cli.electionTestLeader()
2787 if leader is None or leader == main.FALSE:
2788 main.log.error( cli.name + ": Leader for the election app " +
2789 "should be an ONOS node, instead got '" +
2790 str( leader ) + "'" )
2791 leaderResult = main.FALSE
2792 leaders.append( leader )
2793 utilities.assert_equals(
2794 expect=main.TRUE,
2795 actual=leaderResult,
2796 onpass="Successfully ran for leadership",
2797 onfail="Failed to run for leadership" )
2798
2799 main.step( "Check that each node shows the same leader" )
2800 sameLeader = main.TRUE
2801 if len( set( leaders ) ) != 1:
2802 sameLeader = main.FALSE
2803 main.log.error( "Results of electionTestLeader is order of CLIs:" +
2804 str( leaders ) )
2805 utilities.assert_equals(
2806 expect=main.TRUE,
2807 actual=sameLeader,
2808 onpass="Leadership is consistent for the election topic",
2809 onfail="Nodes have different leaders" )
2810
2811 def CASE15( self, main ):
2812 """
2813 Check that Leadership Election is still functional
acsmars9475b1c2015-08-28 18:02:08 -07002814 15.1 Run election on each node
2815 15.2 Check that each node has the same leaders and candidates
2816 15.3 Find current leader and withdraw
2817 15.4 Check that a new node was elected leader
2818 15.5 Check that that new leader was the candidate of old leader
2819 15.6 Run for election on old leader
2820 15.7 Check that oldLeader is a candidate, and leader if only 1 node
2821 15.8 Make sure that the old leader was added to the candidate list
2822
2823 old and new variable prefixes refer to data from before vs after
2824 withdrawl and later before withdrawl vs after re-election
Jon Hall5cf14d52015-07-16 12:15:19 -07002825 """
2826 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002827 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002828 assert main, "main not defined"
2829 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002830 assert main.CLIs, "main.CLIs not defined"
2831 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002832
Jon Hall5cf14d52015-07-16 12:15:19 -07002833 description = "Check that Leadership Election is still functional"
2834 main.case( description )
2835 # NOTE: Need to re-run since being a canidate is not persistant
acsmars9475b1c2015-08-28 18:02:08 -07002836 # TODO: add check for "Command not found:" in the driver, this
2837 # means the election test app isn't loaded
2838
2839 oldLeaders = [] # leaders by node before withdrawl from candidates
2840 newLeaders = [] # leaders by node after withdrawl from candidates
2841 oldAllCandidates = [] # list of lists of each nodes' candidates before
2842 newAllCandidates = [] # list of lists of each nodes' candidates after
2843 oldCandidates = [] # list of candidates from node 0 before withdrawl
2844 newCandidates = [] # list of candidates from node 0 after withdrawl
2845 oldLeader = '' # the old leader from oldLeaders, None if not same
2846 newLeader = '' # the new leaders fron newLoeaders, None if not same
2847 oldLeaderCLI = None # the CLI of the old leader used for re-electing
acsmars71adceb2015-08-31 15:09:26 -07002848 expectNoLeader = False # True when there is only one leader
2849 if main.numCtrls == 1:
2850 expectNoLeader = True
acsmars9475b1c2015-08-28 18:02:08 -07002851
Jon Hall5cf14d52015-07-16 12:15:19 -07002852 main.step( "Run for election on each node" )
acsmars9475b1c2015-08-28 18:02:08 -07002853 electionResult = main.TRUE
2854
2855 for cli in main.CLIs: # run test election on each node
2856 if cli.electionTestRun() == main.FALSE:
2857 electionResult = main.FALSE
2858
Jon Hall5cf14d52015-07-16 12:15:19 -07002859 utilities.assert_equals(
2860 expect=main.TRUE,
acsmars9475b1c2015-08-28 18:02:08 -07002861 actual=electionResult,
2862 onpass="All nodes successfully ran for leadership",
2863 onfail="At least one node failed to run for leadership" )
Jon Hall5cf14d52015-07-16 12:15:19 -07002864
acsmars9475b1c2015-08-28 18:02:08 -07002865 main.step( "Check that each node shows the same leader and candidates" )
2866 sameResult = main.TRUE
2867 failMessage = "Nodes have different leaders"
2868 for cli in main.CLIs:
2869 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
2870 oldAllCandidates.append( node )
2871 oldLeaders.append( node[ 0 ] )
2872 oldCandidates = oldAllCandidates[ 0 ]
2873
2874 # Check that each node has the same leader. Defines oldLeader
2875 if len( set( oldLeaders ) ) != 1:
2876 sameResult = main.FALSE
acsmars71adceb2015-08-31 15:09:26 -07002877 main.log.error( "More than one leader present:" + str( oldLeaders ) )
acsmars9475b1c2015-08-28 18:02:08 -07002878 oldLeader = None
2879 else:
2880 oldLeader = oldLeaders[ 0 ]
2881
2882 # Check that each node's candidate list is the same
2883 for candidates in oldAllCandidates:
2884 if set( candidates ) != set( oldCandidates ):
2885 sameResult = main.FALSE
2886 failMessage += "and candidates"
2887
Jon Hall5cf14d52015-07-16 12:15:19 -07002888 utilities.assert_equals(
2889 expect=main.TRUE,
acsmars71adceb2015-08-31 15:09:26 -07002890 actual=sameResult,
Jon Hall5cf14d52015-07-16 12:15:19 -07002891 onpass="Leadership is consistent for the election topic",
acsmars9475b1c2015-08-28 18:02:08 -07002892 onfail=failMessage )
Jon Hall5cf14d52015-07-16 12:15:19 -07002893
2894 main.step( "Find current leader and withdraw" )
acsmars9475b1c2015-08-28 18:02:08 -07002895 withdrawResult = main.TRUE
Jon Hall5cf14d52015-07-16 12:15:19 -07002896 # do some sanity checking on leader before using it
acsmars9475b1c2015-08-28 18:02:08 -07002897 if oldLeader is None:
2898 main.log.error( "Leadership isn't consistent." )
2899 withdrawResult = main.FALSE
2900 # Get the CLI of the oldLeader
Jon Halle1a3b752015-07-22 13:02:46 -07002901 for i in range( len( main.CLIs ) ):
acsmars9475b1c2015-08-28 18:02:08 -07002902 if oldLeader == main.nodes[ i ].ip_address:
2903 oldLeaderCLI = main.CLIs[ i ]
Jon Hall5cf14d52015-07-16 12:15:19 -07002904 break
2905 else: # FOR/ELSE statement
2906 main.log.error( "Leader election, could not find current leader" )
2907 if oldLeader:
acsmars9475b1c2015-08-28 18:02:08 -07002908 withdrawResult = oldLeaderCLI.electionTestWithdraw()
Jon Hall5cf14d52015-07-16 12:15:19 -07002909 utilities.assert_equals(
2910 expect=main.TRUE,
2911 actual=withdrawResult,
2912 onpass="Node was withdrawn from election",
2913 onfail="Node was not withdrawn from election" )
2914
acsmars9475b1c2015-08-28 18:02:08 -07002915 main.step( "Check that a new node was elected leader" )
acsmars71adceb2015-08-31 15:09:26 -07002916
Jon Hall5cf14d52015-07-16 12:15:19 -07002917 # FIXME: use threads
acsmars9475b1c2015-08-28 18:02:08 -07002918 newLeaderResult = main.TRUE
2919 failMessage = "Nodes have different leaders"
2920
2921 # Get new leaders and candidates
Jon Halle1a3b752015-07-22 13:02:46 -07002922 for cli in main.CLIs:
acsmars9475b1c2015-08-28 18:02:08 -07002923 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
acsmars71adceb2015-08-31 15:09:26 -07002924 # elections might no have finished yet
2925 if node[ 0 ] == 'none' and not expectNoLeader:
acsmars9475b1c2015-08-28 18:02:08 -07002926 main.log.info( "Node has no leader, waiting 5 seconds to be " +
2927 "sure elections are complete." )
2928 time.sleep(5)
2929 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
acsmars71adceb2015-08-31 15:09:26 -07002930 # election still isn't done or there is a problem
2931 if node[ 0 ] == 'none':
2932 main.log.error( "No leader was elected on at least 1 node" )
2933 newLeaderResult = main.FALSE
acsmars9475b1c2015-08-28 18:02:08 -07002934 newAllCandidates.append( node )
2935 newLeaders.append( node[ 0 ] )
2936 newCandidates = newAllCandidates[ 0 ]
2937
2938 # Check that each node has the same leader. Defines newLeader
2939 if len( set( newLeaders ) ) != 1:
2940 newLeaderResult = main.FALSE
2941 main.log.error( "Nodes have different leaders: " +
2942 str( newLeaders ) )
2943 newLeader = None
Jon Hall5cf14d52015-07-16 12:15:19 -07002944 else:
acsmars9475b1c2015-08-28 18:02:08 -07002945 newLeader = newLeaders[ 0 ]
2946
acsmars71adceb2015-08-31 15:09:26 -07002947 # Check that each node's candidate list is the same
2948 for candidates in newAllCandidates:
2949 if set( candidates ) != set( newCandidates ):
2950 newLeaderResult = main.FALSE
2951 main.error.log( "Discrepancy in candidate lists detected" )
2952
acsmars9475b1c2015-08-28 18:02:08 -07002953 # Check that the new leader is not the older leader, which was withdrawn
2954 if newLeader == oldLeader:
2955 newLeaderResult = main.FALSE
2956 main.log.error( "All nodes still see old leader: " + oldLeader +
2957 " as the current leader" )
2958
Jon Hall5cf14d52015-07-16 12:15:19 -07002959 utilities.assert_equals(
2960 expect=main.TRUE,
acsmars9475b1c2015-08-28 18:02:08 -07002961 actual=newLeaderResult,
Jon Hall5cf14d52015-07-16 12:15:19 -07002962 onpass="Leadership election passed",
2963 onfail="Something went wrong with Leadership election" )
2964
acsmars9475b1c2015-08-28 18:02:08 -07002965 main.step( "Check that that new leader was the candidate of old leader")
2966 # candidates[ 2 ] should be come the top candidate after withdrawl
2967 correctCandidateResult = main.TRUE
acsmars71adceb2015-08-31 15:09:26 -07002968 if expectNoLeader:
2969 if newLeader == 'none':
2970 main.log.info( "No leader expected. None found. Pass" )
2971 correctCandidateResult = main.TRUE
2972 else:
2973 main.log.info( "Expected no leader, got: " + str( newLeader ) )
2974 correctCandidateResult = main.FALSE
2975 elif newLeader != oldCandidates[ 2 ]:
acsmars9475b1c2015-08-28 18:02:08 -07002976 correctCandidateResult = main.FALSE
2977 main.log.error( "Candidate " + newLeader + " was elected. " +
2978 oldCandidates[ 2 ] + " should have had priority." )
2979
2980 utilities.assert_equals(
2981 expect=main.TRUE,
2982 actual=correctCandidateResult,
2983 onpass="Correct Candidate Elected",
2984 onfail="Incorrect Candidate Elected" )
2985
Jon Hall5cf14d52015-07-16 12:15:19 -07002986 main.step( "Run for election on old leader( just so everyone " +
2987 "is in the hat )" )
acsmars9475b1c2015-08-28 18:02:08 -07002988 if oldLeaderCLI is not None:
2989 runResult = oldLeaderCLI.electionTestRun()
Jon Hall5cf14d52015-07-16 12:15:19 -07002990 else:
acsmars9475b1c2015-08-28 18:02:08 -07002991 main.log.error( "No old leader to re-elect" )
Jon Hall5cf14d52015-07-16 12:15:19 -07002992 runResult = main.FALSE
2993 utilities.assert_equals(
2994 expect=main.TRUE,
2995 actual=runResult,
2996 onpass="App re-ran for election",
2997 onfail="App failed to run for election" )
acsmars9475b1c2015-08-28 18:02:08 -07002998 main.step(
2999 "Check that oldLeader is a candidate, and leader if only 1 node" )
Jon Hall5cf14d52015-07-16 12:15:19 -07003000 # verify leader didn't just change
acsmars9475b1c2015-08-28 18:02:08 -07003001 positionResult = main.TRUE
3002 # Get new leaders and candidates, wait if oldLeader is not a candidate yet
3003
3004 # Reset and reuse the new candidate and leaders lists
3005 newAllCandidates = []
3006 newCandidates = []
3007 newLeaders = []
3008 for cli in main.CLIs:
3009 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
3010 if oldLeader not in node: # election might no have finished yet
3011 main.log.info( "Old Leader not elected, waiting 5 seconds to " +
3012 "be sure elections are complete" )
3013 time.sleep(5)
3014 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
3015 if oldLeader not in node: # election still isn't done, errors
3016 main.log.error(
3017 "Old leader was not elected on at least one node" )
3018 positionResult = main.FALSE
3019 newAllCandidates.append( node )
3020 newLeaders.append( node[ 0 ] )
3021 newCandidates = newAllCandidates[ 0 ]
3022
3023 # Check that each node has the same leader. Defines newLeader
3024 if len( set( newLeaders ) ) != 1:
3025 positionResult = main.FALSE
3026 main.log.error( "Nodes have different leaders: " +
3027 str( newLeaders ) )
3028 newLeader = None
Jon Hall5cf14d52015-07-16 12:15:19 -07003029 else:
acsmars9475b1c2015-08-28 18:02:08 -07003030 newLeader = newLeaders[ 0 ]
3031
acsmars71adceb2015-08-31 15:09:26 -07003032 # Check that each node's candidate list is the same
3033 for candidates in newAllCandidates:
3034 if set( candidates ) != set( newCandidates ):
3035 newLeaderResult = main.FALSE
3036 main.error.log( "Discrepancy in candidate lists detected" )
3037
acsmars9475b1c2015-08-28 18:02:08 -07003038 # Check that the re-elected node is last on the candidate List
3039 if oldLeader != newCandidates[ -1 ]:
3040 main.log.error( "Old Leader (" + oldLeader + ") not in the proper position " +
3041 str( newCandidates ) )
3042 positionResult = main.FALSE
Jon Hall5cf14d52015-07-16 12:15:19 -07003043
3044 utilities.assert_equals(
3045 expect=main.TRUE,
acsmars9475b1c2015-08-28 18:02:08 -07003046 actual=positionResult,
Jon Hall5cf14d52015-07-16 12:15:19 -07003047 onpass="Old leader successfully re-ran for election",
3048 onfail="Something went wrong with Leadership election after " +
3049 "the old leader re-ran for election" )
3050
3051 def CASE16( self, main ):
3052 """
3053 Install Distributed Primitives app
3054 """
3055 import time
Jon Halle1a3b752015-07-22 13:02:46 -07003056 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07003057 assert main, "main not defined"
3058 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07003059 assert main.CLIs, "main.CLIs not defined"
3060 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07003061
3062 # Variables for the distributed primitives tests
3063 global pCounterName
3064 global iCounterName
3065 global pCounterValue
3066 global iCounterValue
3067 global onosSet
3068 global onosSetName
3069 pCounterName = "TestON-Partitions"
3070 iCounterName = "TestON-inMemory"
3071 pCounterValue = 0
3072 iCounterValue = 0
3073 onosSet = set([])
3074 onosSetName = "TestON-set"
3075
3076 description = "Install Primitives app"
3077 main.case( description )
3078 main.step( "Install Primitives app" )
3079 appName = "org.onosproject.distributedprimitives"
Jon Halle1a3b752015-07-22 13:02:46 -07003080 appResults = main.CLIs[0].activateApp( appName )
Jon Hall5cf14d52015-07-16 12:15:19 -07003081 utilities.assert_equals( expect=main.TRUE,
3082 actual=appResults,
3083 onpass="Primitives app activated",
3084 onfail="Primitives app not activated" )
3085 time.sleep( 5 ) # To allow all nodes to activate
3086
3087 def CASE17( self, main ):
3088 """
3089 Check for basic functionality with distributed primitives
3090 """
Jon Hall5cf14d52015-07-16 12:15:19 -07003091 # Make sure variables are defined/set
Jon Halle1a3b752015-07-22 13:02:46 -07003092 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07003093 assert main, "main not defined"
3094 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07003095 assert main.CLIs, "main.CLIs not defined"
3096 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07003097 assert pCounterName, "pCounterName not defined"
3098 assert iCounterName, "iCounterName not defined"
3099 assert onosSetName, "onosSetName not defined"
3100 # NOTE: assert fails if value is 0/None/Empty/False
3101 try:
3102 pCounterValue
3103 except NameError:
3104 main.log.error( "pCounterValue not defined, setting to 0" )
3105 pCounterValue = 0
3106 try:
3107 iCounterValue
3108 except NameError:
3109 main.log.error( "iCounterValue not defined, setting to 0" )
3110 iCounterValue = 0
3111 try:
3112 onosSet
3113 except NameError:
3114 main.log.error( "onosSet not defined, setting to empty Set" )
3115 onosSet = set([])
3116 # Variables for the distributed primitives tests. These are local only
3117 addValue = "a"
3118 addAllValue = "a b c d e f"
3119 retainValue = "c d e f"
3120
3121 description = "Check for basic functionality with distributed " +\
3122 "primitives"
3123 main.case( description )
Jon Halle1a3b752015-07-22 13:02:46 -07003124 main.caseExplanation = "Test the methods of the distributed " +\
3125 "primitives (counters and sets) throught the cli"
Jon Hall5cf14d52015-07-16 12:15:19 -07003126 # DISTRIBUTED ATOMIC COUNTERS
Jon Halle1a3b752015-07-22 13:02:46 -07003127 # Partitioned counters
3128 main.step( "Increment then get a default counter on each node" )
Jon Hall5cf14d52015-07-16 12:15:19 -07003129 pCounters = []
3130 threads = []
3131 addedPValues = []
Jon Halle1a3b752015-07-22 13:02:46 -07003132 for i in range( main.numCtrls ):
3133 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
3134 name="counterAddAndGet-" + str( i ),
Jon Hall5cf14d52015-07-16 12:15:19 -07003135 args=[ pCounterName ] )
3136 pCounterValue += 1
3137 addedPValues.append( pCounterValue )
3138 threads.append( t )
3139 t.start()
3140
3141 for t in threads:
3142 t.join()
3143 pCounters.append( t.result )
3144 # Check that counter incremented numController times
3145 pCounterResults = True
3146 for i in addedPValues:
3147 tmpResult = i in pCounters
3148 pCounterResults = pCounterResults and tmpResult
3149 if not tmpResult:
3150 main.log.error( str( i ) + " is not in partitioned "
3151 "counter incremented results" )
3152 utilities.assert_equals( expect=True,
3153 actual=pCounterResults,
3154 onpass="Default counter incremented",
3155 onfail="Error incrementing default" +
3156 " counter" )
3157
Jon Halle1a3b752015-07-22 13:02:46 -07003158 main.step( "Get then Increment a default counter on each node" )
3159 pCounters = []
3160 threads = []
3161 addedPValues = []
3162 for i in range( main.numCtrls ):
3163 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
3164 name="counterGetAndAdd-" + str( i ),
3165 args=[ pCounterName ] )
3166 addedPValues.append( pCounterValue )
3167 pCounterValue += 1
3168 threads.append( t )
3169 t.start()
3170
3171 for t in threads:
3172 t.join()
3173 pCounters.append( t.result )
3174 # Check that counter incremented numController times
3175 pCounterResults = True
3176 for i in addedPValues:
3177 tmpResult = i in pCounters
3178 pCounterResults = pCounterResults and tmpResult
3179 if not tmpResult:
3180 main.log.error( str( i ) + " is not in partitioned "
3181 "counter incremented results" )
3182 utilities.assert_equals( expect=True,
3183 actual=pCounterResults,
3184 onpass="Default counter incremented",
3185 onfail="Error incrementing default" +
3186 " counter" )
3187
3188 main.step( "Counters we added have the correct values" )
3189 incrementCheck = main.Counters.counterCheck( pCounterName, pCounterValue )
3190 utilities.assert_equals( expect=main.TRUE,
3191 actual=incrementCheck,
3192 onpass="Added counters are correct",
3193 onfail="Added counters are incorrect" )
3194
3195 main.step( "Add -8 to then get a default counter on each node" )
3196 pCounters = []
3197 threads = []
3198 addedPValues = []
3199 for i in range( main.numCtrls ):
3200 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
3201 name="counterIncrement-" + str( i ),
3202 args=[ pCounterName ],
3203 kwargs={ "delta": -8 } )
3204 pCounterValue += -8
3205 addedPValues.append( pCounterValue )
3206 threads.append( t )
3207 t.start()
3208
3209 for t in threads:
3210 t.join()
3211 pCounters.append( t.result )
3212 # Check that counter incremented numController times
3213 pCounterResults = True
3214 for i in addedPValues:
3215 tmpResult = i in pCounters
3216 pCounterResults = pCounterResults and tmpResult
3217 if not tmpResult:
3218 main.log.error( str( i ) + " is not in partitioned "
3219 "counter incremented results" )
3220 utilities.assert_equals( expect=True,
3221 actual=pCounterResults,
3222 onpass="Default counter incremented",
3223 onfail="Error incrementing default" +
3224 " counter" )
3225
3226 main.step( "Add 5 to then get a default counter on each node" )
3227 pCounters = []
3228 threads = []
3229 addedPValues = []
3230 for i in range( main.numCtrls ):
3231 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
3232 name="counterIncrement-" + str( i ),
3233 args=[ pCounterName ],
3234 kwargs={ "delta": 5 } )
3235 pCounterValue += 5
3236 addedPValues.append( pCounterValue )
3237 threads.append( t )
3238 t.start()
3239
3240 for t in threads:
3241 t.join()
3242 pCounters.append( t.result )
3243 # Check that counter incremented numController times
3244 pCounterResults = True
3245 for i in addedPValues:
3246 tmpResult = i in pCounters
3247 pCounterResults = pCounterResults and tmpResult
3248 if not tmpResult:
3249 main.log.error( str( i ) + " is not in partitioned "
3250 "counter incremented results" )
3251 utilities.assert_equals( expect=True,
3252 actual=pCounterResults,
3253 onpass="Default counter incremented",
3254 onfail="Error incrementing default" +
3255 " counter" )
3256
3257 main.step( "Get then add 5 to a default counter on each node" )
3258 pCounters = []
3259 threads = []
3260 addedPValues = []
3261 for i in range( main.numCtrls ):
3262 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
3263 name="counterIncrement-" + str( i ),
3264 args=[ pCounterName ],
3265 kwargs={ "delta": 5 } )
3266 addedPValues.append( pCounterValue )
3267 pCounterValue += 5
3268 threads.append( t )
3269 t.start()
3270
3271 for t in threads:
3272 t.join()
3273 pCounters.append( t.result )
3274 # Check that counter incremented numController times
3275 pCounterResults = True
3276 for i in addedPValues:
3277 tmpResult = i in pCounters
3278 pCounterResults = pCounterResults and tmpResult
3279 if not tmpResult:
3280 main.log.error( str( i ) + " is not in partitioned "
3281 "counter incremented results" )
3282 utilities.assert_equals( expect=True,
3283 actual=pCounterResults,
3284 onpass="Default counter incremented",
3285 onfail="Error incrementing default" +
3286 " counter" )
3287
3288 main.step( "Counters we added have the correct values" )
3289 incrementCheck = main.Counters.counterCheck( pCounterName, pCounterValue )
3290 utilities.assert_equals( expect=main.TRUE,
3291 actual=incrementCheck,
3292 onpass="Added counters are correct",
3293 onfail="Added counters are incorrect" )
3294
3295 # In-Memory counters
3296 main.step( "Increment and get an in-memory counter on each node" )
Jon Hall5cf14d52015-07-16 12:15:19 -07003297 iCounters = []
3298 addedIValues = []
3299 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003300 for i in range( main.numCtrls ):
3301 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003302 name="icounterIncrement-" + str( i ),
3303 args=[ iCounterName ],
3304 kwargs={ "inMemory": True } )
3305 iCounterValue += 1
3306 addedIValues.append( iCounterValue )
3307 threads.append( t )
3308 t.start()
3309
3310 for t in threads:
3311 t.join()
3312 iCounters.append( t.result )
3313 # Check that counter incremented numController times
3314 iCounterResults = True
3315 for i in addedIValues:
3316 tmpResult = i in iCounters
3317 iCounterResults = iCounterResults and tmpResult
3318 if not tmpResult:
3319 main.log.error( str( i ) + " is not in the in-memory "
3320 "counter incremented results" )
3321 utilities.assert_equals( expect=True,
3322 actual=iCounterResults,
Jon Halle1a3b752015-07-22 13:02:46 -07003323 onpass="In-memory counter incremented",
3324 onfail="Error incrementing in-memory" +
Jon Hall5cf14d52015-07-16 12:15:19 -07003325 " counter" )
3326
Jon Halle1a3b752015-07-22 13:02:46 -07003327 main.step( "Get then Increment a in-memory counter on each node" )
3328 iCounters = []
3329 threads = []
3330 addedIValues = []
3331 for i in range( main.numCtrls ):
3332 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
3333 name="counterGetAndAdd-" + str( i ),
3334 args=[ iCounterName ],
3335 kwargs={ "inMemory": True } )
3336 addedIValues.append( iCounterValue )
3337 iCounterValue += 1
3338 threads.append( t )
3339 t.start()
3340
3341 for t in threads:
3342 t.join()
3343 iCounters.append( t.result )
3344 # Check that counter incremented numController times
3345 iCounterResults = True
3346 for i in addedIValues:
3347 tmpResult = i in iCounters
3348 iCounterResults = iCounterResults and tmpResult
3349 if not tmpResult:
3350 main.log.error( str( i ) + " is not in in-memory "
3351 "counter incremented results" )
3352 utilities.assert_equals( expect=True,
3353 actual=iCounterResults,
3354 onpass="In-memory counter incremented",
3355 onfail="Error incrementing in-memory" +
3356 " counter" )
3357
3358 main.step( "Counters we added have the correct values" )
3359 incrementCheck = main.Counters.counterCheck( iCounterName, iCounterValue )
3360 utilities.assert_equals( expect=main.TRUE,
3361 actual=incrementCheck,
3362 onpass="Added counters are correct",
3363 onfail="Added counters are incorrect" )
3364
3365 main.step( "Add -8 to then get a in-memory counter on each node" )
3366 iCounters = []
3367 threads = []
3368 addedIValues = []
3369 for i in range( main.numCtrls ):
3370 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
3371 name="counterIncrement-" + str( i ),
3372 args=[ iCounterName ],
3373 kwargs={ "delta": -8, "inMemory": True } )
3374 iCounterValue += -8
3375 addedIValues.append( iCounterValue )
3376 threads.append( t )
3377 t.start()
3378
3379 for t in threads:
3380 t.join()
3381 iCounters.append( t.result )
3382 # Check that counter incremented numController times
3383 iCounterResults = True
3384 for i in addedIValues:
3385 tmpResult = i in iCounters
3386 iCounterResults = iCounterResults and tmpResult
3387 if not tmpResult:
3388 main.log.error( str( i ) + " is not in in-memory "
3389 "counter incremented results" )
3390 utilities.assert_equals( expect=True,
3391 actual=pCounterResults,
3392 onpass="In-memory counter incremented",
3393 onfail="Error incrementing in-memory" +
3394 " counter" )
3395
3396 main.step( "Add 5 to then get a in-memory counter on each node" )
3397 iCounters = []
3398 threads = []
3399 addedIValues = []
3400 for i in range( main.numCtrls ):
3401 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
3402 name="counterIncrement-" + str( i ),
3403 args=[ iCounterName ],
3404 kwargs={ "delta": 5, "inMemory": True } )
3405 iCounterValue += 5
3406 addedIValues.append( iCounterValue )
3407 threads.append( t )
3408 t.start()
3409
3410 for t in threads:
3411 t.join()
3412 iCounters.append( t.result )
3413 # Check that counter incremented numController times
3414 iCounterResults = True
3415 for i in addedIValues:
3416 tmpResult = i in iCounters
3417 iCounterResults = iCounterResults and tmpResult
3418 if not tmpResult:
3419 main.log.error( str( i ) + " is not in in-memory "
3420 "counter incremented results" )
3421 utilities.assert_equals( expect=True,
3422 actual=pCounterResults,
3423 onpass="In-memory counter incremented",
3424 onfail="Error incrementing in-memory" +
3425 " counter" )
3426
3427 main.step( "Get then add 5 to a in-memory counter on each node" )
3428 iCounters = []
3429 threads = []
3430 addedIValues = []
3431 for i in range( main.numCtrls ):
3432 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
3433 name="counterIncrement-" + str( i ),
3434 args=[ iCounterName ],
3435 kwargs={ "delta": 5, "inMemory": True } )
3436 addedIValues.append( iCounterValue )
3437 iCounterValue += 5
3438 threads.append( t )
3439 t.start()
3440
3441 for t in threads:
3442 t.join()
3443 iCounters.append( t.result )
3444 # Check that counter incremented numController times
3445 iCounterResults = True
3446 for i in addedIValues:
3447 tmpResult = i in iCounters
3448 iCounterResults = iCounterResults and tmpResult
3449 if not tmpResult:
3450 main.log.error( str( i ) + " is not in in-memory "
3451 "counter incremented results" )
3452 utilities.assert_equals( expect=True,
3453 actual=iCounterResults,
3454 onpass="In-memory counter incremented",
3455 onfail="Error incrementing in-memory" +
3456 " counter" )
3457
3458 main.step( "Counters we added have the correct values" )
3459 incrementCheck = main.Counters.counterCheck( iCounterName, iCounterValue )
3460 utilities.assert_equals( expect=main.TRUE,
3461 actual=incrementCheck,
3462 onpass="Added counters are correct",
3463 onfail="Added counters are incorrect" )
3464
Jon Hall5cf14d52015-07-16 12:15:19 -07003465 main.step( "Check counters are consistant across nodes" )
3466 onosCounters = []
3467 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003468 for i in range( main.numCtrls ):
3469 t = main.Thread( target=main.CLIs[i].counters,
Jon Hall5cf14d52015-07-16 12:15:19 -07003470 name="counters-" + str( i ) )
3471 threads.append( t )
3472 t.start()
3473 for t in threads:
3474 t.join()
3475 onosCounters.append( t.result )
3476 tmp = [ i == onosCounters[ 0 ] for i in onosCounters ]
3477 if all( tmp ):
3478 main.log.info( "Counters are consistent across all nodes" )
3479 consistentCounterResults = main.TRUE
3480 else:
3481 main.log.error( "Counters are not consistent across all nodes" )
3482 consistentCounterResults = main.FALSE
3483 utilities.assert_equals( expect=main.TRUE,
3484 actual=consistentCounterResults,
3485 onpass="ONOS counters are consistent " +
3486 "across nodes",
3487 onfail="ONOS Counters are inconsistent " +
3488 "across nodes" )
3489
3490 main.step( "Counters we added have the correct values" )
Jon Halle1a3b752015-07-22 13:02:46 -07003491 incrementCheck = main.Counters.counterCheck( iCounterName, iCounterValue )
3492 incrementCheck = incrementCheck and \
3493 main.Counters.counterCheck( iCounterName, iCounterValue )
Jon Hall5cf14d52015-07-16 12:15:19 -07003494 utilities.assert_equals( expect=main.TRUE,
Jon Halle1a3b752015-07-22 13:02:46 -07003495 actual=incrementCheck,
Jon Hall5cf14d52015-07-16 12:15:19 -07003496 onpass="Added counters are correct",
3497 onfail="Added counters are incorrect" )
Jon Halle1a3b752015-07-22 13:02:46 -07003498
Jon Hall5cf14d52015-07-16 12:15:19 -07003499 # DISTRIBUTED SETS
3500 main.step( "Distributed Set get" )
3501 size = len( onosSet )
3502 getResponses = []
3503 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003504 for i in range( main.numCtrls ):
3505 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003506 name="setTestGet-" + str( i ),
3507 args=[ onosSetName ] )
3508 threads.append( t )
3509 t.start()
3510 for t in threads:
3511 t.join()
3512 getResponses.append( t.result )
3513
3514 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003515 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003516 if isinstance( getResponses[ i ], list):
3517 current = set( getResponses[ i ] )
3518 if len( current ) == len( getResponses[ i ] ):
3519 # no repeats
3520 if onosSet != current:
3521 main.log.error( "ONOS" + str( i + 1 ) +
3522 " has incorrect view" +
3523 " of set " + onosSetName + ":\n" +
3524 str( getResponses[ i ] ) )
3525 main.log.debug( "Expected: " + str( onosSet ) )
3526 main.log.debug( "Actual: " + str( current ) )
3527 getResults = main.FALSE
3528 else:
3529 # error, set is not a set
3530 main.log.error( "ONOS" + str( i + 1 ) +
3531 " has repeat elements in" +
3532 " set " + onosSetName + ":\n" +
3533 str( getResponses[ i ] ) )
3534 getResults = main.FALSE
3535 elif getResponses[ i ] == main.ERROR:
3536 getResults = main.FALSE
3537 utilities.assert_equals( expect=main.TRUE,
3538 actual=getResults,
3539 onpass="Set elements are correct",
3540 onfail="Set elements are incorrect" )
3541
3542 main.step( "Distributed Set size" )
3543 sizeResponses = []
3544 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003545 for i in range( main.numCtrls ):
3546 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003547 name="setTestSize-" + str( i ),
3548 args=[ onosSetName ] )
3549 threads.append( t )
3550 t.start()
3551 for t in threads:
3552 t.join()
3553 sizeResponses.append( t.result )
3554
3555 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003556 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003557 if size != sizeResponses[ i ]:
3558 sizeResults = main.FALSE
3559 main.log.error( "ONOS" + str( i + 1 ) +
3560 " expected a size of " + str( size ) +
3561 " for set " + onosSetName +
3562 " but got " + str( sizeResponses[ i ] ) )
3563 utilities.assert_equals( expect=main.TRUE,
3564 actual=sizeResults,
3565 onpass="Set sizes are correct",
3566 onfail="Set sizes are incorrect" )
3567
3568 main.step( "Distributed Set add()" )
3569 onosSet.add( addValue )
3570 addResponses = []
3571 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003572 for i in range( main.numCtrls ):
3573 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall5cf14d52015-07-16 12:15:19 -07003574 name="setTestAdd-" + str( i ),
3575 args=[ onosSetName, addValue ] )
3576 threads.append( t )
3577 t.start()
3578 for t in threads:
3579 t.join()
3580 addResponses.append( t.result )
3581
3582 # main.TRUE = successfully changed the set
3583 # main.FALSE = action resulted in no change in set
3584 # main.ERROR - Some error in executing the function
3585 addResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003586 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003587 if addResponses[ i ] == main.TRUE:
3588 # All is well
3589 pass
3590 elif addResponses[ i ] == main.FALSE:
3591 # Already in set, probably fine
3592 pass
3593 elif addResponses[ i ] == main.ERROR:
3594 # Error in execution
3595 addResults = main.FALSE
3596 else:
3597 # unexpected result
3598 addResults = main.FALSE
3599 if addResults != main.TRUE:
3600 main.log.error( "Error executing set add" )
3601
3602 # Check if set is still correct
3603 size = len( onosSet )
3604 getResponses = []
3605 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003606 for i in range( main.numCtrls ):
3607 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003608 name="setTestGet-" + str( i ),
3609 args=[ onosSetName ] )
3610 threads.append( t )
3611 t.start()
3612 for t in threads:
3613 t.join()
3614 getResponses.append( t.result )
3615 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003616 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003617 if isinstance( getResponses[ i ], list):
3618 current = set( getResponses[ i ] )
3619 if len( current ) == len( getResponses[ i ] ):
3620 # no repeats
3621 if onosSet != current:
3622 main.log.error( "ONOS" + str( i + 1 ) +
3623 " has incorrect view" +
3624 " of set " + onosSetName + ":\n" +
3625 str( getResponses[ i ] ) )
3626 main.log.debug( "Expected: " + str( onosSet ) )
3627 main.log.debug( "Actual: " + str( current ) )
3628 getResults = main.FALSE
3629 else:
3630 # error, set is not a set
3631 main.log.error( "ONOS" + str( i + 1 ) +
3632 " has repeat elements in" +
3633 " set " + onosSetName + ":\n" +
3634 str( getResponses[ i ] ) )
3635 getResults = main.FALSE
3636 elif getResponses[ i ] == main.ERROR:
3637 getResults = main.FALSE
3638 sizeResponses = []
3639 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003640 for i in range( main.numCtrls ):
3641 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003642 name="setTestSize-" + str( i ),
3643 args=[ onosSetName ] )
3644 threads.append( t )
3645 t.start()
3646 for t in threads:
3647 t.join()
3648 sizeResponses.append( t.result )
3649 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003650 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003651 if size != sizeResponses[ i ]:
3652 sizeResults = main.FALSE
3653 main.log.error( "ONOS" + str( i + 1 ) +
3654 " expected a size of " + str( size ) +
3655 " for set " + onosSetName +
3656 " but got " + str( sizeResponses[ i ] ) )
3657 addResults = addResults and getResults and sizeResults
3658 utilities.assert_equals( expect=main.TRUE,
3659 actual=addResults,
3660 onpass="Set add correct",
3661 onfail="Set add was incorrect" )
3662
3663 main.step( "Distributed Set addAll()" )
3664 onosSet.update( addAllValue.split() )
3665 addResponses = []
3666 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003667 for i in range( main.numCtrls ):
3668 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall5cf14d52015-07-16 12:15:19 -07003669 name="setTestAddAll-" + str( i ),
3670 args=[ onosSetName, addAllValue ] )
3671 threads.append( t )
3672 t.start()
3673 for t in threads:
3674 t.join()
3675 addResponses.append( t.result )
3676
3677 # main.TRUE = successfully changed the set
3678 # main.FALSE = action resulted in no change in set
3679 # main.ERROR - Some error in executing the function
3680 addAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003681 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003682 if addResponses[ i ] == main.TRUE:
3683 # All is well
3684 pass
3685 elif addResponses[ i ] == main.FALSE:
3686 # Already in set, probably fine
3687 pass
3688 elif addResponses[ i ] == main.ERROR:
3689 # Error in execution
3690 addAllResults = main.FALSE
3691 else:
3692 # unexpected result
3693 addAllResults = main.FALSE
3694 if addAllResults != main.TRUE:
3695 main.log.error( "Error executing set addAll" )
3696
3697 # Check if set is still correct
3698 size = len( onosSet )
3699 getResponses = []
3700 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003701 for i in range( main.numCtrls ):
3702 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003703 name="setTestGet-" + str( i ),
3704 args=[ onosSetName ] )
3705 threads.append( t )
3706 t.start()
3707 for t in threads:
3708 t.join()
3709 getResponses.append( t.result )
3710 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003711 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003712 if isinstance( getResponses[ i ], list):
3713 current = set( getResponses[ i ] )
3714 if len( current ) == len( getResponses[ i ] ):
3715 # no repeats
3716 if onosSet != current:
3717 main.log.error( "ONOS" + str( i + 1 ) +
3718 " has incorrect view" +
3719 " of set " + onosSetName + ":\n" +
3720 str( getResponses[ i ] ) )
3721 main.log.debug( "Expected: " + str( onosSet ) )
3722 main.log.debug( "Actual: " + str( current ) )
3723 getResults = main.FALSE
3724 else:
3725 # error, set is not a set
3726 main.log.error( "ONOS" + str( i + 1 ) +
3727 " has repeat elements in" +
3728 " set " + onosSetName + ":\n" +
3729 str( getResponses[ i ] ) )
3730 getResults = main.FALSE
3731 elif getResponses[ i ] == main.ERROR:
3732 getResults = main.FALSE
3733 sizeResponses = []
3734 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003735 for i in range( main.numCtrls ):
3736 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003737 name="setTestSize-" + str( i ),
3738 args=[ onosSetName ] )
3739 threads.append( t )
3740 t.start()
3741 for t in threads:
3742 t.join()
3743 sizeResponses.append( t.result )
3744 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003745 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003746 if size != sizeResponses[ i ]:
3747 sizeResults = main.FALSE
3748 main.log.error( "ONOS" + str( i + 1 ) +
3749 " expected a size of " + str( size ) +
3750 " for set " + onosSetName +
3751 " but got " + str( sizeResponses[ i ] ) )
3752 addAllResults = addAllResults and getResults and sizeResults
3753 utilities.assert_equals( expect=main.TRUE,
3754 actual=addAllResults,
3755 onpass="Set addAll correct",
3756 onfail="Set addAll was incorrect" )
3757
3758 main.step( "Distributed Set contains()" )
3759 containsResponses = []
3760 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003761 for i in range( main.numCtrls ):
3762 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003763 name="setContains-" + str( i ),
3764 args=[ onosSetName ],
3765 kwargs={ "values": addValue } )
3766 threads.append( t )
3767 t.start()
3768 for t in threads:
3769 t.join()
3770 # NOTE: This is the tuple
3771 containsResponses.append( t.result )
3772
3773 containsResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003774 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003775 if containsResponses[ i ] == main.ERROR:
3776 containsResults = main.FALSE
3777 else:
3778 containsResults = containsResults and\
3779 containsResponses[ i ][ 1 ]
3780 utilities.assert_equals( expect=main.TRUE,
3781 actual=containsResults,
3782 onpass="Set contains is functional",
3783 onfail="Set contains failed" )
3784
3785 main.step( "Distributed Set containsAll()" )
3786 containsAllResponses = []
3787 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003788 for i in range( main.numCtrls ):
3789 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003790 name="setContainsAll-" + str( i ),
3791 args=[ onosSetName ],
3792 kwargs={ "values": addAllValue } )
3793 threads.append( t )
3794 t.start()
3795 for t in threads:
3796 t.join()
3797 # NOTE: This is the tuple
3798 containsAllResponses.append( t.result )
3799
3800 containsAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003801 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003802 if containsResponses[ i ] == main.ERROR:
3803 containsResults = main.FALSE
3804 else:
3805 containsResults = containsResults and\
3806 containsResponses[ i ][ 1 ]
3807 utilities.assert_equals( expect=main.TRUE,
3808 actual=containsAllResults,
3809 onpass="Set containsAll is functional",
3810 onfail="Set containsAll failed" )
3811
3812 main.step( "Distributed Set remove()" )
3813 onosSet.remove( addValue )
3814 removeResponses = []
3815 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003816 for i in range( main.numCtrls ):
3817 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall5cf14d52015-07-16 12:15:19 -07003818 name="setTestRemove-" + str( i ),
3819 args=[ onosSetName, addValue ] )
3820 threads.append( t )
3821 t.start()
3822 for t in threads:
3823 t.join()
3824 removeResponses.append( t.result )
3825
3826 # main.TRUE = successfully changed the set
3827 # main.FALSE = action resulted in no change in set
3828 # main.ERROR - Some error in executing the function
3829 removeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003830 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003831 if removeResponses[ i ] == main.TRUE:
3832 # All is well
3833 pass
3834 elif removeResponses[ i ] == main.FALSE:
3835 # not in set, probably fine
3836 pass
3837 elif removeResponses[ i ] == main.ERROR:
3838 # Error in execution
3839 removeResults = main.FALSE
3840 else:
3841 # unexpected result
3842 removeResults = main.FALSE
3843 if removeResults != main.TRUE:
3844 main.log.error( "Error executing set remove" )
3845
3846 # Check if set is still correct
3847 size = len( onosSet )
3848 getResponses = []
3849 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003850 for i in range( main.numCtrls ):
3851 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003852 name="setTestGet-" + str( i ),
3853 args=[ onosSetName ] )
3854 threads.append( t )
3855 t.start()
3856 for t in threads:
3857 t.join()
3858 getResponses.append( t.result )
3859 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003860 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003861 if isinstance( getResponses[ i ], list):
3862 current = set( getResponses[ i ] )
3863 if len( current ) == len( getResponses[ i ] ):
3864 # no repeats
3865 if onosSet != current:
3866 main.log.error( "ONOS" + str( i + 1 ) +
3867 " has incorrect view" +
3868 " of set " + onosSetName + ":\n" +
3869 str( getResponses[ i ] ) )
3870 main.log.debug( "Expected: " + str( onosSet ) )
3871 main.log.debug( "Actual: " + str( current ) )
3872 getResults = main.FALSE
3873 else:
3874 # error, set is not a set
3875 main.log.error( "ONOS" + str( i + 1 ) +
3876 " has repeat elements in" +
3877 " set " + onosSetName + ":\n" +
3878 str( getResponses[ i ] ) )
3879 getResults = main.FALSE
3880 elif getResponses[ i ] == main.ERROR:
3881 getResults = main.FALSE
3882 sizeResponses = []
3883 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003884 for i in range( main.numCtrls ):
3885 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003886 name="setTestSize-" + str( i ),
3887 args=[ onosSetName ] )
3888 threads.append( t )
3889 t.start()
3890 for t in threads:
3891 t.join()
3892 sizeResponses.append( t.result )
3893 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003894 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003895 if size != sizeResponses[ i ]:
3896 sizeResults = main.FALSE
3897 main.log.error( "ONOS" + str( i + 1 ) +
3898 " expected a size of " + str( size ) +
3899 " for set " + onosSetName +
3900 " but got " + str( sizeResponses[ i ] ) )
3901 removeResults = removeResults and getResults and sizeResults
3902 utilities.assert_equals( expect=main.TRUE,
3903 actual=removeResults,
3904 onpass="Set remove correct",
3905 onfail="Set remove was incorrect" )
3906
3907 main.step( "Distributed Set removeAll()" )
3908 onosSet.difference_update( addAllValue.split() )
3909 removeAllResponses = []
3910 threads = []
3911 try:
Jon Halle1a3b752015-07-22 13:02:46 -07003912 for i in range( main.numCtrls ):
3913 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall5cf14d52015-07-16 12:15:19 -07003914 name="setTestRemoveAll-" + str( i ),
3915 args=[ onosSetName, addAllValue ] )
3916 threads.append( t )
3917 t.start()
3918 for t in threads:
3919 t.join()
3920 removeAllResponses.append( t.result )
3921 except Exception, e:
3922 main.log.exception(e)
3923
3924 # main.TRUE = successfully changed the set
3925 # main.FALSE = action resulted in no change in set
3926 # main.ERROR - Some error in executing the function
3927 removeAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003928 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003929 if removeAllResponses[ i ] == main.TRUE:
3930 # All is well
3931 pass
3932 elif removeAllResponses[ i ] == main.FALSE:
3933 # not in set, probably fine
3934 pass
3935 elif removeAllResponses[ i ] == main.ERROR:
3936 # Error in execution
3937 removeAllResults = main.FALSE
3938 else:
3939 # unexpected result
3940 removeAllResults = main.FALSE
3941 if removeAllResults != main.TRUE:
3942 main.log.error( "Error executing set removeAll" )
3943
3944 # Check if set is still correct
3945 size = len( onosSet )
3946 getResponses = []
3947 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003948 for i in range( main.numCtrls ):
3949 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003950 name="setTestGet-" + str( i ),
3951 args=[ onosSetName ] )
3952 threads.append( t )
3953 t.start()
3954 for t in threads:
3955 t.join()
3956 getResponses.append( t.result )
3957 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003958 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003959 if isinstance( getResponses[ i ], list):
3960 current = set( getResponses[ i ] )
3961 if len( current ) == len( getResponses[ i ] ):
3962 # no repeats
3963 if onosSet != current:
3964 main.log.error( "ONOS" + str( i + 1 ) +
3965 " has incorrect view" +
3966 " of set " + onosSetName + ":\n" +
3967 str( getResponses[ i ] ) )
3968 main.log.debug( "Expected: " + str( onosSet ) )
3969 main.log.debug( "Actual: " + str( current ) )
3970 getResults = main.FALSE
3971 else:
3972 # error, set is not a set
3973 main.log.error( "ONOS" + str( i + 1 ) +
3974 " has repeat elements in" +
3975 " set " + onosSetName + ":\n" +
3976 str( getResponses[ i ] ) )
3977 getResults = main.FALSE
3978 elif getResponses[ i ] == main.ERROR:
3979 getResults = main.FALSE
3980 sizeResponses = []
3981 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003982 for i in range( main.numCtrls ):
3983 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003984 name="setTestSize-" + str( i ),
3985 args=[ onosSetName ] )
3986 threads.append( t )
3987 t.start()
3988 for t in threads:
3989 t.join()
3990 sizeResponses.append( t.result )
3991 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003992 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003993 if size != sizeResponses[ i ]:
3994 sizeResults = main.FALSE
3995 main.log.error( "ONOS" + str( i + 1 ) +
3996 " expected a size of " + str( size ) +
3997 " for set " + onosSetName +
3998 " but got " + str( sizeResponses[ i ] ) )
3999 removeAllResults = removeAllResults and getResults and sizeResults
4000 utilities.assert_equals( expect=main.TRUE,
4001 actual=removeAllResults,
4002 onpass="Set removeAll correct",
4003 onfail="Set removeAll was incorrect" )
4004
4005 main.step( "Distributed Set addAll()" )
4006 onosSet.update( addAllValue.split() )
4007 addResponses = []
4008 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004009 for i in range( main.numCtrls ):
4010 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall5cf14d52015-07-16 12:15:19 -07004011 name="setTestAddAll-" + str( i ),
4012 args=[ onosSetName, addAllValue ] )
4013 threads.append( t )
4014 t.start()
4015 for t in threads:
4016 t.join()
4017 addResponses.append( t.result )
4018
4019 # main.TRUE = successfully changed the set
4020 # main.FALSE = action resulted in no change in set
4021 # main.ERROR - Some error in executing the function
4022 addAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004023 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004024 if addResponses[ i ] == main.TRUE:
4025 # All is well
4026 pass
4027 elif addResponses[ i ] == main.FALSE:
4028 # Already in set, probably fine
4029 pass
4030 elif addResponses[ i ] == main.ERROR:
4031 # Error in execution
4032 addAllResults = main.FALSE
4033 else:
4034 # unexpected result
4035 addAllResults = main.FALSE
4036 if addAllResults != main.TRUE:
4037 main.log.error( "Error executing set addAll" )
4038
4039 # Check if set is still correct
4040 size = len( onosSet )
4041 getResponses = []
4042 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004043 for i in range( main.numCtrls ):
4044 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07004045 name="setTestGet-" + str( i ),
4046 args=[ onosSetName ] )
4047 threads.append( t )
4048 t.start()
4049 for t in threads:
4050 t.join()
4051 getResponses.append( t.result )
4052 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004053 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004054 if isinstance( getResponses[ i ], list):
4055 current = set( getResponses[ i ] )
4056 if len( current ) == len( getResponses[ i ] ):
4057 # no repeats
4058 if onosSet != current:
4059 main.log.error( "ONOS" + str( i + 1 ) +
4060 " has incorrect view" +
4061 " of set " + onosSetName + ":\n" +
4062 str( getResponses[ i ] ) )
4063 main.log.debug( "Expected: " + str( onosSet ) )
4064 main.log.debug( "Actual: " + str( current ) )
4065 getResults = main.FALSE
4066 else:
4067 # error, set is not a set
4068 main.log.error( "ONOS" + str( i + 1 ) +
4069 " has repeat elements in" +
4070 " set " + onosSetName + ":\n" +
4071 str( getResponses[ i ] ) )
4072 getResults = main.FALSE
4073 elif getResponses[ i ] == main.ERROR:
4074 getResults = main.FALSE
4075 sizeResponses = []
4076 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004077 for i in range( main.numCtrls ):
4078 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07004079 name="setTestSize-" + str( i ),
4080 args=[ onosSetName ] )
4081 threads.append( t )
4082 t.start()
4083 for t in threads:
4084 t.join()
4085 sizeResponses.append( t.result )
4086 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004087 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004088 if size != sizeResponses[ i ]:
4089 sizeResults = main.FALSE
4090 main.log.error( "ONOS" + str( i + 1 ) +
4091 " expected a size of " + str( size ) +
4092 " for set " + onosSetName +
4093 " but got " + str( sizeResponses[ i ] ) )
4094 addAllResults = addAllResults and getResults and sizeResults
4095 utilities.assert_equals( expect=main.TRUE,
4096 actual=addAllResults,
4097 onpass="Set addAll correct",
4098 onfail="Set addAll was incorrect" )
4099
4100 main.step( "Distributed Set clear()" )
4101 onosSet.clear()
4102 clearResponses = []
4103 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004104 for i in range( main.numCtrls ):
4105 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall5cf14d52015-07-16 12:15:19 -07004106 name="setTestClear-" + str( i ),
4107 args=[ onosSetName, " "], # Values doesn't matter
4108 kwargs={ "clear": True } )
4109 threads.append( t )
4110 t.start()
4111 for t in threads:
4112 t.join()
4113 clearResponses.append( t.result )
4114
4115 # main.TRUE = successfully changed the set
4116 # main.FALSE = action resulted in no change in set
4117 # main.ERROR - Some error in executing the function
4118 clearResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004119 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004120 if clearResponses[ i ] == main.TRUE:
4121 # All is well
4122 pass
4123 elif clearResponses[ i ] == main.FALSE:
4124 # Nothing set, probably fine
4125 pass
4126 elif clearResponses[ i ] == main.ERROR:
4127 # Error in execution
4128 clearResults = main.FALSE
4129 else:
4130 # unexpected result
4131 clearResults = main.FALSE
4132 if clearResults != main.TRUE:
4133 main.log.error( "Error executing set clear" )
4134
4135 # Check if set is still correct
4136 size = len( onosSet )
4137 getResponses = []
4138 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004139 for i in range( main.numCtrls ):
4140 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07004141 name="setTestGet-" + str( i ),
4142 args=[ onosSetName ] )
4143 threads.append( t )
4144 t.start()
4145 for t in threads:
4146 t.join()
4147 getResponses.append( t.result )
4148 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004149 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004150 if isinstance( getResponses[ i ], list):
4151 current = set( getResponses[ i ] )
4152 if len( current ) == len( getResponses[ i ] ):
4153 # no repeats
4154 if onosSet != current:
4155 main.log.error( "ONOS" + str( i + 1 ) +
4156 " has incorrect view" +
4157 " of set " + onosSetName + ":\n" +
4158 str( getResponses[ i ] ) )
4159 main.log.debug( "Expected: " + str( onosSet ) )
4160 main.log.debug( "Actual: " + str( current ) )
4161 getResults = main.FALSE
4162 else:
4163 # error, set is not a set
4164 main.log.error( "ONOS" + str( i + 1 ) +
4165 " has repeat elements in" +
4166 " set " + onosSetName + ":\n" +
4167 str( getResponses[ i ] ) )
4168 getResults = main.FALSE
4169 elif getResponses[ i ] == main.ERROR:
4170 getResults = main.FALSE
4171 sizeResponses = []
4172 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004173 for i in range( main.numCtrls ):
4174 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07004175 name="setTestSize-" + str( i ),
4176 args=[ onosSetName ] )
4177 threads.append( t )
4178 t.start()
4179 for t in threads:
4180 t.join()
4181 sizeResponses.append( t.result )
4182 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004183 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004184 if size != sizeResponses[ i ]:
4185 sizeResults = main.FALSE
4186 main.log.error( "ONOS" + str( i + 1 ) +
4187 " expected a size of " + str( size ) +
4188 " for set " + onosSetName +
4189 " but got " + str( sizeResponses[ i ] ) )
4190 clearResults = clearResults and getResults and sizeResults
4191 utilities.assert_equals( expect=main.TRUE,
4192 actual=clearResults,
4193 onpass="Set clear correct",
4194 onfail="Set clear was incorrect" )
4195
4196 main.step( "Distributed Set addAll()" )
4197 onosSet.update( addAllValue.split() )
4198 addResponses = []
4199 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004200 for i in range( main.numCtrls ):
4201 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall5cf14d52015-07-16 12:15:19 -07004202 name="setTestAddAll-" + str( i ),
4203 args=[ onosSetName, addAllValue ] )
4204 threads.append( t )
4205 t.start()
4206 for t in threads:
4207 t.join()
4208 addResponses.append( t.result )
4209
4210 # main.TRUE = successfully changed the set
4211 # main.FALSE = action resulted in no change in set
4212 # main.ERROR - Some error in executing the function
4213 addAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004214 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004215 if addResponses[ i ] == main.TRUE:
4216 # All is well
4217 pass
4218 elif addResponses[ i ] == main.FALSE:
4219 # Already in set, probably fine
4220 pass
4221 elif addResponses[ i ] == main.ERROR:
4222 # Error in execution
4223 addAllResults = main.FALSE
4224 else:
4225 # unexpected result
4226 addAllResults = main.FALSE
4227 if addAllResults != main.TRUE:
4228 main.log.error( "Error executing set addAll" )
4229
4230 # Check if set is still correct
4231 size = len( onosSet )
4232 getResponses = []
4233 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004234 for i in range( main.numCtrls ):
4235 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07004236 name="setTestGet-" + str( i ),
4237 args=[ onosSetName ] )
4238 threads.append( t )
4239 t.start()
4240 for t in threads:
4241 t.join()
4242 getResponses.append( t.result )
4243 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004244 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004245 if isinstance( getResponses[ i ], list):
4246 current = set( getResponses[ i ] )
4247 if len( current ) == len( getResponses[ i ] ):
4248 # no repeats
4249 if onosSet != current:
4250 main.log.error( "ONOS" + str( i + 1 ) +
4251 " has incorrect view" +
4252 " of set " + onosSetName + ":\n" +
4253 str( getResponses[ i ] ) )
4254 main.log.debug( "Expected: " + str( onosSet ) )
4255 main.log.debug( "Actual: " + str( current ) )
4256 getResults = main.FALSE
4257 else:
4258 # error, set is not a set
4259 main.log.error( "ONOS" + str( i + 1 ) +
4260 " has repeat elements in" +
4261 " set " + onosSetName + ":\n" +
4262 str( getResponses[ i ] ) )
4263 getResults = main.FALSE
4264 elif getResponses[ i ] == main.ERROR:
4265 getResults = main.FALSE
4266 sizeResponses = []
4267 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004268 for i in range( main.numCtrls ):
4269 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07004270 name="setTestSize-" + str( i ),
4271 args=[ onosSetName ] )
4272 threads.append( t )
4273 t.start()
4274 for t in threads:
4275 t.join()
4276 sizeResponses.append( t.result )
4277 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004278 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004279 if size != sizeResponses[ i ]:
4280 sizeResults = main.FALSE
4281 main.log.error( "ONOS" + str( i + 1 ) +
4282 " expected a size of " + str( size ) +
4283 " for set " + onosSetName +
4284 " but got " + str( sizeResponses[ i ] ) )
4285 addAllResults = addAllResults and getResults and sizeResults
4286 utilities.assert_equals( expect=main.TRUE,
4287 actual=addAllResults,
4288 onpass="Set addAll correct",
4289 onfail="Set addAll was incorrect" )
4290
4291 main.step( "Distributed Set retain()" )
4292 onosSet.intersection_update( retainValue.split() )
4293 retainResponses = []
4294 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004295 for i in range( main.numCtrls ):
4296 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall5cf14d52015-07-16 12:15:19 -07004297 name="setTestRetain-" + str( i ),
4298 args=[ onosSetName, retainValue ],
4299 kwargs={ "retain": True } )
4300 threads.append( t )
4301 t.start()
4302 for t in threads:
4303 t.join()
4304 retainResponses.append( t.result )
4305
4306 # main.TRUE = successfully changed the set
4307 # main.FALSE = action resulted in no change in set
4308 # main.ERROR - Some error in executing the function
4309 retainResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004310 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004311 if retainResponses[ i ] == main.TRUE:
4312 # All is well
4313 pass
4314 elif retainResponses[ i ] == main.FALSE:
4315 # Already in set, probably fine
4316 pass
4317 elif retainResponses[ i ] == main.ERROR:
4318 # Error in execution
4319 retainResults = main.FALSE
4320 else:
4321 # unexpected result
4322 retainResults = main.FALSE
4323 if retainResults != main.TRUE:
4324 main.log.error( "Error executing set retain" )
4325
4326 # Check if set is still correct
4327 size = len( onosSet )
4328 getResponses = []
4329 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004330 for i in range( main.numCtrls ):
4331 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07004332 name="setTestGet-" + str( i ),
4333 args=[ onosSetName ] )
4334 threads.append( t )
4335 t.start()
4336 for t in threads:
4337 t.join()
4338 getResponses.append( t.result )
4339 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004340 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004341 if isinstance( getResponses[ i ], list):
4342 current = set( getResponses[ i ] )
4343 if len( current ) == len( getResponses[ i ] ):
4344 # no repeats
4345 if onosSet != current:
4346 main.log.error( "ONOS" + str( i + 1 ) +
4347 " has incorrect view" +
4348 " of set " + onosSetName + ":\n" +
4349 str( getResponses[ i ] ) )
4350 main.log.debug( "Expected: " + str( onosSet ) )
4351 main.log.debug( "Actual: " + str( current ) )
4352 getResults = main.FALSE
4353 else:
4354 # error, set is not a set
4355 main.log.error( "ONOS" + str( i + 1 ) +
4356 " has repeat elements in" +
4357 " set " + onosSetName + ":\n" +
4358 str( getResponses[ i ] ) )
4359 getResults = main.FALSE
4360 elif getResponses[ i ] == main.ERROR:
4361 getResults = main.FALSE
4362 sizeResponses = []
4363 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004364 for i in range( main.numCtrls ):
4365 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07004366 name="setTestSize-" + str( i ),
4367 args=[ onosSetName ] )
4368 threads.append( t )
4369 t.start()
4370 for t in threads:
4371 t.join()
4372 sizeResponses.append( t.result )
4373 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004374 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004375 if size != sizeResponses[ i ]:
4376 sizeResults = main.FALSE
4377 main.log.error( "ONOS" + str( i + 1 ) +
4378 " expected a size of " +
4379 str( size ) + " for set " + onosSetName +
4380 " but got " + str( sizeResponses[ i ] ) )
4381 retainResults = retainResults and getResults and sizeResults
4382 utilities.assert_equals( expect=main.TRUE,
4383 actual=retainResults,
4384 onpass="Set retain correct",
4385 onfail="Set retain was incorrect" )
4386
Jon Hall2a5002c2015-08-21 16:49:11 -07004387 # Transactional maps
4388 main.step( "Partitioned Transactional maps put" )
4389 tMapValue = "Testing"
4390 numKeys = 100
4391 putResult = True
4392 putResponses = main.CLIs[ 0 ].transactionalMapPut( numKeys, tMapValue )
4393 if len( putResponses ) == 100:
4394 for i in putResponses:
4395 if putResponses[ i ][ 'value' ] != tMapValue:
4396 putResult = False
4397 else:
4398 putResult = False
4399 if not putResult:
4400 main.log.debug( "Put response values: " + str( putResponses ) )
4401 utilities.assert_equals( expect=True,
4402 actual=putResult,
4403 onpass="Partitioned Transactional Map put successful",
4404 onfail="Partitioned Transactional Map put values are incorrect" )
4405
4406 main.step( "Partitioned Transactional maps get" )
4407 getCheck = True
4408 for n in range( 1, numKeys + 1 ):
4409 getResponses = []
4410 threads = []
4411 valueCheck = True
4412 for i in range( main.numCtrls ):
4413 t = main.Thread( target=main.CLIs[i].transactionalMapGet,
4414 name="TMap-get-" + str( i ),
4415 args=[ "Key" + str ( n ) ] )
4416 threads.append( t )
4417 t.start()
4418 for t in threads:
4419 t.join()
4420 getResponses.append( t.result )
4421 for node in getResponses:
4422 if node != tMapValue:
4423 valueCheck = False
4424 if not valueCheck:
4425 main.log.warn( "Values for key 'Key" + str( n ) + "' do not match:" )
4426 main.log.warn( getResponses )
4427 getCheck = getCheck and valueCheck
4428 utilities.assert_equals( expect=True,
4429 actual=getCheck,
4430 onpass="Partitioned Transactional Map get values were correct",
4431 onfail="Partitioned Transactional Map values incorrect" )
4432
4433 main.step( "In-memory Transactional maps put" )
4434 tMapValue = "Testing"
4435 numKeys = 100
4436 putResult = True
4437 putResponses = main.CLIs[ 0 ].transactionalMapPut( numKeys, tMapValue, inMemory=True )
4438 if len( putResponses ) == 100:
4439 for i in putResponses:
4440 if putResponses[ i ][ 'value' ] != tMapValue:
4441 putResult = False
4442 else:
4443 putResult = False
4444 if not putResult:
4445 main.log.debug( "Put response values: " + str( putResponses ) )
4446 utilities.assert_equals( expect=True,
4447 actual=putResult,
4448 onpass="In-Memory Transactional Map put successful",
4449 onfail="In-Memory Transactional Map put values are incorrect" )
4450
4451 main.step( "In-Memory Transactional maps get" )
4452 getCheck = True
4453 for n in range( 1, numKeys + 1 ):
4454 getResponses = []
4455 threads = []
4456 valueCheck = True
4457 for i in range( main.numCtrls ):
4458 t = main.Thread( target=main.CLIs[i].transactionalMapGet,
4459 name="TMap-get-" + str( i ),
4460 args=[ "Key" + str ( n ) ],
4461 kwargs={ "inMemory": True } )
4462 threads.append( t )
4463 t.start()
4464 for t in threads:
4465 t.join()
4466 getResponses.append( t.result )
4467 for node in getResponses:
4468 if node != tMapValue:
4469 valueCheck = False
4470 if not valueCheck:
4471 main.log.warn( "Values for key 'Key" + str( n ) + "' do not match:" )
4472 main.log.warn( getResponses )
4473 getCheck = getCheck and valueCheck
4474 utilities.assert_equals( expect=True,
4475 actual=getCheck,
4476 onpass="In-Memory Transactional Map get values were correct",
4477 onfail="In-Memory Transactional Map values incorrect" )