blob: f7eceb37f578ed6ab5bacdfcdc275b9b3dfbad45 [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
Jon Hall5ec6b1b2015-09-17 18:20:14 -07001720 main.step( "Checking ONOS Logs for errors" )
1721 for node in main.nodes:
1722 main.log.debug( "Checking logs for errors on " + node.name + ":" )
1723 main.log.warn( main.ONOSbench.checkLogs( node.ip_address ) )
1724
Jon Hall5cf14d52015-07-16 12:15:19 -07001725 main.step( "Killing ONOS nodes" )
1726 killResults = main.TRUE
1727 killTime = time.time()
Jon Halle1a3b752015-07-22 13:02:46 -07001728 for node in main.nodes:
Jon Hall5cf14d52015-07-16 12:15:19 -07001729 killed = main.ONOSbench.onosKill( node.ip_address )
1730 killResults = killResults and killed
1731 utilities.assert_equals( expect=main.TRUE, actual=killResults,
1732 onpass="ONOS nodes killed",
1733 onfail="ONOS kill unsuccessful" )
1734
1735 main.step( "Checking if ONOS is up yet" )
1736 for i in range( 2 ):
1737 onosIsupResult = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07001738 for node in main.nodes:
Jon Hall5cf14d52015-07-16 12:15:19 -07001739 started = main.ONOSbench.isup( node.ip_address )
1740 if not started:
1741 main.log.error( node.name + " didn't start!" )
1742 onosIsupResult = onosIsupResult and started
1743 if onosIsupResult == main.TRUE:
1744 break
1745 utilities.assert_equals( expect=main.TRUE, actual=onosIsupResult,
1746 onpass="ONOS restarted",
1747 onfail="ONOS restart NOT successful" )
1748
1749 main.log.step( "Starting ONOS CLI sessions" )
1750 cliResults = main.TRUE
1751 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001752 for i in range( main.numCtrls ):
1753 t = main.Thread( target=main.CLIs[i].startOnosCli,
Jon Hall5cf14d52015-07-16 12:15:19 -07001754 name="startOnosCli-" + str( i ),
Jon Halle1a3b752015-07-22 13:02:46 -07001755 args=[main.nodes[i].ip_address] )
Jon Hall5cf14d52015-07-16 12:15:19 -07001756 threads.append( t )
1757 t.start()
1758
1759 for t in threads:
1760 t.join()
1761 cliResults = cliResults and t.result
1762 utilities.assert_equals( expect=main.TRUE, actual=cliResults,
1763 onpass="ONOS cli started",
1764 onfail="ONOS clis did not restart" )
1765
1766 # Grab the time of restart so we chan check how long the gossip
1767 # protocol has had time to work
1768 main.restartTime = time.time() - killTime
1769 main.log.debug( "Restart time: " + str( main.restartTime ) )
1770 labels.append( "Restart" )
1771 data.append( str( main.restartTime ) )
1772
1773 # FIXME: revisit test plan for election with madan
1774 # Rerun for election on restarted nodes
1775 runResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07001776 for cli in main.CLIs:
1777 run = main.CLIs[0].electionTestRun()
Jon Hall5cf14d52015-07-16 12:15:19 -07001778 if run != main.TRUE:
1779 main.log.error( "Error running for election on " + cli.name )
1780 runResults = runResults and run
1781 utilities.assert_equals( expect=main.TRUE, actual=runResults,
1782 onpass="Reran for election",
1783 onfail="Failed to rerun for election" )
1784
1785 # TODO: Make this configurable
1786 time.sleep( 60 )
Jon Halle1a3b752015-07-22 13:02:46 -07001787 main.log.debug( main.CLIs[0].nodes( jsonFormat=False ) )
1788 main.log.debug( main.CLIs[0].leaders( jsonFormat=False ) )
1789 main.log.debug( main.CLIs[0].partitions( jsonFormat=False ) )
Jon Hall5cf14d52015-07-16 12:15:19 -07001790
1791 def CASE7( self, main ):
1792 """
1793 Check state after ONOS failure
1794 """
1795 import json
Jon Halle1a3b752015-07-22 13:02:46 -07001796 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07001797 assert main, "main not defined"
1798 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07001799 assert main.CLIs, "main.CLIs not defined"
1800 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07001801 main.case( "Running ONOS Constant State Tests" )
1802
1803 main.step( "Check that each switch has a master" )
1804 # Assert that each device has a master
1805 rolesNotNull = main.TRUE
1806 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001807 for i in range( main.numCtrls ):
1808 t = main.Thread( target=main.CLIs[i].rolesNotNull,
Jon Hall5cf14d52015-07-16 12:15:19 -07001809 name="rolesNotNull-" + str( i ),
1810 args=[ ] )
1811 threads.append( t )
1812 t.start()
1813
1814 for t in threads:
1815 t.join()
1816 rolesNotNull = rolesNotNull and t.result
1817 utilities.assert_equals(
1818 expect=main.TRUE,
1819 actual=rolesNotNull,
1820 onpass="Each device has a master",
1821 onfail="Some devices don't have a master assigned" )
1822
1823 main.step( "Read device roles from ONOS" )
1824 ONOSMastership = []
1825 mastershipCheck = main.FALSE
1826 consistentMastership = True
1827 rolesResults = True
1828 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001829 for i in range( main.numCtrls ):
1830 t = main.Thread( target=main.CLIs[i].roles,
Jon Hall5cf14d52015-07-16 12:15:19 -07001831 name="roles-" + str( i ),
1832 args=[] )
1833 threads.append( t )
1834 t.start()
1835
1836 for t in threads:
1837 t.join()
1838 ONOSMastership.append( t.result )
1839
Jon Halle1a3b752015-07-22 13:02:46 -07001840 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001841 if not ONOSMastership[i] or "Error" in ONOSMastership[i]:
1842 main.log.error( "Error in getting ONOS" + str( i + 1 ) +
1843 " roles" )
1844 main.log.warn(
1845 "ONOS" + str( i + 1 ) + " mastership response: " +
1846 repr( ONOSMastership[i] ) )
1847 rolesResults = False
1848 utilities.assert_equals(
1849 expect=True,
1850 actual=rolesResults,
1851 onpass="No error in reading roles output",
1852 onfail="Error in reading roles from ONOS" )
1853
1854 main.step( "Check for consistency in roles from each controller" )
1855 if all([ i == ONOSMastership[ 0 ] for i in ONOSMastership ] ):
1856 main.log.info(
1857 "Switch roles are consistent across all ONOS nodes" )
1858 else:
1859 consistentMastership = False
1860 utilities.assert_equals(
1861 expect=True,
1862 actual=consistentMastership,
1863 onpass="Switch roles are consistent across all ONOS nodes",
1864 onfail="ONOS nodes have different views of switch roles" )
1865
1866 if rolesResults and not consistentMastership:
Jon Halle1a3b752015-07-22 13:02:46 -07001867 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001868 main.log.warn(
1869 "ONOS" + str( i + 1 ) + " roles: ",
1870 json.dumps(
1871 json.loads( ONOSMastership[ i ] ),
1872 sort_keys=True,
1873 indent=4,
1874 separators=( ',', ': ' ) ) )
1875 elif rolesResults and not consistentMastership:
1876 mastershipCheck = main.TRUE
1877
1878 '''
1879 description2 = "Compare switch roles from before failure"
1880 main.step( description2 )
1881 try:
1882 currentJson = json.loads( ONOSMastership[0] )
1883 oldJson = json.loads( mastershipState )
1884 except ( ValueError, TypeError ):
1885 main.log.exception( "Something is wrong with parsing " +
1886 "ONOSMastership[0] or mastershipState" )
1887 main.log.error( "ONOSMastership[0]: " + repr( ONOSMastership[0] ) )
1888 main.log.error( "mastershipState" + repr( mastershipState ) )
1889 main.cleanup()
1890 main.exit()
1891 mastershipCheck = main.TRUE
1892 for i in range( 1, 29 ):
1893 switchDPID = str(
1894 main.Mininet1.getSwitchDPID( switch="s" + str( i ) ) )
1895 current = [ switch[ 'master' ] for switch in currentJson
1896 if switchDPID in switch[ 'id' ] ]
1897 old = [ switch[ 'master' ] for switch in oldJson
1898 if switchDPID in switch[ 'id' ] ]
1899 if current == old:
1900 mastershipCheck = mastershipCheck and main.TRUE
1901 else:
1902 main.log.warn( "Mastership of switch %s changed" % switchDPID )
1903 mastershipCheck = main.FALSE
1904 utilities.assert_equals(
1905 expect=main.TRUE,
1906 actual=mastershipCheck,
1907 onpass="Mastership of Switches was not changed",
1908 onfail="Mastership of some switches changed" )
1909 '''
1910 # NOTE: we expect mastership to change on controller failure
1911
1912 main.step( "Get the intents and compare across all nodes" )
1913 ONOSIntents = []
1914 intentCheck = main.FALSE
1915 consistentIntents = True
1916 intentsResults = True
1917 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001918 for i in range( main.numCtrls ):
1919 t = main.Thread( target=main.CLIs[i].intents,
Jon Hall5cf14d52015-07-16 12:15:19 -07001920 name="intents-" + str( i ),
1921 args=[],
1922 kwargs={ 'jsonFormat': True } )
1923 threads.append( t )
1924 t.start()
1925
1926 for t in threads:
1927 t.join()
1928 ONOSIntents.append( t.result )
1929
Jon Halle1a3b752015-07-22 13:02:46 -07001930 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001931 if not ONOSIntents[ i ] or "Error" in ONOSIntents[ i ]:
1932 main.log.error( "Error in getting ONOS" + str( i + 1 ) +
1933 " intents" )
1934 main.log.warn( "ONOS" + str( i + 1 ) + " intents response: " +
1935 repr( ONOSIntents[ i ] ) )
1936 intentsResults = False
1937 utilities.assert_equals(
1938 expect=True,
1939 actual=intentsResults,
1940 onpass="No error in reading intents output",
1941 onfail="Error in reading intents from ONOS" )
1942
1943 main.step( "Check for consistency in Intents from each controller" )
1944 if all([ sorted( i ) == sorted( ONOSIntents[ 0 ] ) for i in ONOSIntents ] ):
1945 main.log.info( "Intents are consistent across all ONOS " +
1946 "nodes" )
1947 else:
1948 consistentIntents = False
1949
1950 # Try to make it easy to figure out what is happening
1951 #
1952 # Intent ONOS1 ONOS2 ...
1953 # 0x01 INSTALLED INSTALLING
1954 # ... ... ...
1955 # ... ... ...
1956 title = " ID"
Jon Halle1a3b752015-07-22 13:02:46 -07001957 for n in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001958 title += " " * 10 + "ONOS" + str( n + 1 )
1959 main.log.warn( title )
1960 # get all intent keys in the cluster
1961 keys = []
1962 for nodeStr in ONOSIntents:
1963 node = json.loads( nodeStr )
1964 for intent in node:
1965 keys.append( intent.get( 'id' ) )
1966 keys = set( keys )
1967 for key in keys:
1968 row = "%-13s" % key
1969 for nodeStr in ONOSIntents:
1970 node = json.loads( nodeStr )
1971 for intent in node:
1972 if intent.get( 'id' ) == key:
1973 row += "%-15s" % intent.get( 'state' )
1974 main.log.warn( row )
1975 # End table view
1976
1977 utilities.assert_equals(
1978 expect=True,
1979 actual=consistentIntents,
1980 onpass="Intents are consistent across all ONOS nodes",
1981 onfail="ONOS nodes have different views of intents" )
1982 intentStates = []
1983 for node in ONOSIntents: # Iter through ONOS nodes
1984 nodeStates = []
1985 # Iter through intents of a node
1986 try:
1987 for intent in json.loads( node ):
1988 nodeStates.append( intent[ 'state' ] )
1989 except ( ValueError, TypeError ):
1990 main.log.exception( "Error in parsing intents" )
1991 main.log.error( repr( node ) )
1992 intentStates.append( nodeStates )
1993 out = [ (i, nodeStates.count( i ) ) for i in set( nodeStates ) ]
1994 main.log.info( dict( out ) )
1995
1996 if intentsResults and not consistentIntents:
Jon Halle1a3b752015-07-22 13:02:46 -07001997 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001998 main.log.warn( "ONOS" + str( i + 1 ) + " intents: " )
1999 main.log.warn( json.dumps(
2000 json.loads( ONOSIntents[ i ] ),
2001 sort_keys=True,
2002 indent=4,
2003 separators=( ',', ': ' ) ) )
2004 elif intentsResults and consistentIntents:
2005 intentCheck = main.TRUE
2006
2007 # NOTE: Store has no durability, so intents are lost across system
2008 # restarts
2009 """
2010 main.step( "Compare current intents with intents before the failure" )
2011 # NOTE: this requires case 5 to pass for intentState to be set.
2012 # maybe we should stop the test if that fails?
2013 sameIntents = main.FALSE
2014 if intentState and intentState == ONOSIntents[ 0 ]:
2015 sameIntents = main.TRUE
2016 main.log.info( "Intents are consistent with before failure" )
2017 # TODO: possibly the states have changed? we may need to figure out
2018 # what the acceptable states are
2019 elif len( intentState ) == len( ONOSIntents[ 0 ] ):
2020 sameIntents = main.TRUE
2021 try:
2022 before = json.loads( intentState )
2023 after = json.loads( ONOSIntents[ 0 ] )
2024 for intent in before:
2025 if intent not in after:
2026 sameIntents = main.FALSE
2027 main.log.debug( "Intent is not currently in ONOS " +
2028 "(at least in the same form):" )
2029 main.log.debug( json.dumps( intent ) )
2030 except ( ValueError, TypeError ):
2031 main.log.exception( "Exception printing intents" )
2032 main.log.debug( repr( ONOSIntents[0] ) )
2033 main.log.debug( repr( intentState ) )
2034 if sameIntents == main.FALSE:
2035 try:
2036 main.log.debug( "ONOS intents before: " )
2037 main.log.debug( json.dumps( json.loads( intentState ),
2038 sort_keys=True, indent=4,
2039 separators=( ',', ': ' ) ) )
2040 main.log.debug( "Current ONOS intents: " )
2041 main.log.debug( json.dumps( json.loads( ONOSIntents[ 0 ] ),
2042 sort_keys=True, indent=4,
2043 separators=( ',', ': ' ) ) )
2044 except ( ValueError, TypeError ):
2045 main.log.exception( "Exception printing intents" )
2046 main.log.debug( repr( ONOSIntents[0] ) )
2047 main.log.debug( repr( intentState ) )
2048 utilities.assert_equals(
2049 expect=main.TRUE,
2050 actual=sameIntents,
2051 onpass="Intents are consistent with before failure",
2052 onfail="The Intents changed during failure" )
2053 intentCheck = intentCheck and sameIntents
2054 """
2055 main.step( "Get the OF Table entries and compare to before " +
2056 "component failure" )
2057 FlowTables = main.TRUE
2058 flows2 = []
2059 for i in range( 28 ):
2060 main.log.info( "Checking flow table on s" + str( i + 1 ) )
Jon Hall9043c902015-07-30 14:23:44 -07002061 tmpFlows = main.Mininet1.getFlowTable( 1.3, "s" + str( i + 1 ) )
Jon Hall5cf14d52015-07-16 12:15:19 -07002062 flows2.append( tmpFlows )
Jon Hall9043c902015-07-30 14:23:44 -07002063 tempResult = main.Mininet1.flowComp(
Jon Hall5cf14d52015-07-16 12:15:19 -07002064 flow1=flows[ i ],
2065 flow2=tmpFlows )
2066 FlowTables = FlowTables and tempResult
2067 if FlowTables == main.FALSE:
2068 main.log.info( "Differences in flow table for switch: s" +
2069 str( i + 1 ) )
2070 utilities.assert_equals(
2071 expect=main.TRUE,
2072 actual=FlowTables,
2073 onpass="No changes were found in the flow tables",
2074 onfail="Changes were found in the flow tables" )
2075
2076 main.Mininet2.pingLongKill()
2077 '''
2078 # main.step( "Check the continuous pings to ensure that no packets " +
2079 # "were dropped during component failure" )
2080 main.Mininet2.pingKill( main.params[ 'TESTONUSER' ],
2081 main.params[ 'TESTONIP' ] )
2082 LossInPings = main.FALSE
2083 # NOTE: checkForLoss returns main.FALSE with 0% packet loss
2084 for i in range( 8, 18 ):
2085 main.log.info(
2086 "Checking for a loss in pings along flow from s" +
2087 str( i ) )
2088 LossInPings = main.Mininet2.checkForLoss(
2089 "/tmp/ping.h" +
2090 str( i ) ) or LossInPings
2091 if LossInPings == main.TRUE:
2092 main.log.info( "Loss in ping detected" )
2093 elif LossInPings == main.ERROR:
2094 main.log.info( "There are multiple mininet process running" )
2095 elif LossInPings == main.FALSE:
2096 main.log.info( "No Loss in the pings" )
2097 main.log.info( "No loss of dataplane connectivity" )
2098 # utilities.assert_equals(
2099 # expect=main.FALSE,
2100 # actual=LossInPings,
2101 # onpass="No Loss of connectivity",
2102 # onfail="Loss of dataplane connectivity detected" )
2103
2104 # NOTE: Since intents are not persisted with IntnentStore,
2105 # we expect loss in dataplane connectivity
2106 LossInPings = main.FALSE
2107 '''
2108
2109 main.step( "Leadership Election is still functional" )
2110 # Test of LeadershipElection
2111 leaderList = []
2112 leaderResult = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07002113 for cli in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -07002114 leaderN = cli.electionTestLeader()
2115 leaderList.append( leaderN )
2116 if leaderN == main.FALSE:
2117 # error in response
2118 main.log.error( "Something is wrong with " +
2119 "electionTestLeader function, check the" +
2120 " error logs" )
2121 leaderResult = main.FALSE
2122 elif leaderN is None:
2123 main.log.error( cli.name +
2124 " shows no leader for the election-app." )
2125 leaderResult = main.FALSE
2126 if len( set( leaderList ) ) != 1:
2127 leaderResult = main.FALSE
2128 main.log.error(
2129 "Inconsistent view of leader for the election test app" )
2130 # TODO: print the list
2131 utilities.assert_equals(
2132 expect=main.TRUE,
2133 actual=leaderResult,
2134 onpass="Leadership election passed",
2135 onfail="Something went wrong with Leadership election" )
2136
2137 def CASE8( self, main ):
2138 """
2139 Compare topo
2140 """
2141 import json
2142 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002143 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002144 assert main, "main not defined"
2145 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002146 assert main.CLIs, "main.CLIs not defined"
2147 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002148
2149 main.case( "Compare ONOS Topology view to Mininet topology" )
Jon Hall783bbf92015-07-23 14:33:19 -07002150 main.caseExplanation = "Compare topology objects between Mininet" +\
Jon Hall5cf14d52015-07-16 12:15:19 -07002151 " and ONOS"
2152
2153 main.step( "Comparing ONOS topology to MN" )
2154 devicesResults = main.TRUE
2155 linksResults = main.TRUE
2156 hostsResults = main.TRUE
2157 hostAttachmentResults = True
2158 topoResult = main.FALSE
2159 elapsed = 0
2160 count = 0
2161 main.step( "Collecting topology information from ONOS" )
2162 startTime = time.time()
2163 # Give time for Gossip to work
2164 while topoResult == main.FALSE and elapsed < 60:
2165 count += 1
2166 cliStart = time.time()
2167 devices = []
2168 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002169 for i in range( main.numCtrls ):
2170 t = main.Thread( target=main.CLIs[i].devices,
Jon Hall5cf14d52015-07-16 12:15:19 -07002171 name="devices-" + str( i ),
2172 args=[ ] )
2173 threads.append( t )
2174 t.start()
2175
2176 for t in threads:
2177 t.join()
2178 devices.append( t.result )
2179 hosts = []
2180 ipResult = main.TRUE
2181 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002182 for i in range( main.numCtrls ):
2183 t = main.Thread( target=main.CLIs[i].hosts,
Jon Hall5cf14d52015-07-16 12:15:19 -07002184 name="hosts-" + str( i ),
2185 args=[ ] )
2186 threads.append( t )
2187 t.start()
2188
2189 for t in threads:
2190 t.join()
2191 try:
2192 hosts.append( json.loads( t.result ) )
2193 except ( ValueError, TypeError ):
2194 main.log.exception( "Error parsing hosts results" )
2195 main.log.error( repr( t.result ) )
2196 for controller in range( 0, len( hosts ) ):
2197 controllerStr = str( controller + 1 )
2198 for host in hosts[ controller ]:
2199 if host is None or host.get( 'ipAddresses', [] ) == []:
2200 main.log.error(
2201 "DEBUG:Error with host ipAddresses on controller" +
2202 controllerStr + ": " + str( host ) )
2203 ipResult = main.FALSE
2204 ports = []
2205 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002206 for i in range( main.numCtrls ):
2207 t = main.Thread( target=main.CLIs[i].ports,
Jon Hall5cf14d52015-07-16 12:15:19 -07002208 name="ports-" + str( i ),
2209 args=[ ] )
2210 threads.append( t )
2211 t.start()
2212
2213 for t in threads:
2214 t.join()
2215 ports.append( t.result )
2216 links = []
2217 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002218 for i in range( main.numCtrls ):
2219 t = main.Thread( target=main.CLIs[i].links,
Jon Hall5cf14d52015-07-16 12:15:19 -07002220 name="links-" + str( i ),
2221 args=[ ] )
2222 threads.append( t )
2223 t.start()
2224
2225 for t in threads:
2226 t.join()
2227 links.append( t.result )
2228 clusters = []
2229 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002230 for i in range( main.numCtrls ):
2231 t = main.Thread( target=main.CLIs[i].clusters,
Jon Hall5cf14d52015-07-16 12:15:19 -07002232 name="clusters-" + str( i ),
2233 args=[ ] )
2234 threads.append( t )
2235 t.start()
2236
2237 for t in threads:
2238 t.join()
2239 clusters.append( t.result )
2240
2241 elapsed = time.time() - startTime
2242 cliTime = time.time() - cliStart
2243 print "Elapsed time: " + str( elapsed )
2244 print "CLI time: " + str( cliTime )
2245
2246 mnSwitches = main.Mininet1.getSwitches()
2247 mnLinks = main.Mininet1.getLinks()
2248 mnHosts = main.Mininet1.getHosts()
Jon Halle1a3b752015-07-22 13:02:46 -07002249 for controller in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07002250 controllerStr = str( controller + 1 )
2251 if devices[ controller ] and ports[ controller ] and\
2252 "Error" not in devices[ controller ] and\
2253 "Error" not in ports[ controller ]:
2254
2255 currentDevicesResult = main.Mininet1.compareSwitches(
2256 mnSwitches,
2257 json.loads( devices[ controller ] ),
2258 json.loads( ports[ controller ] ) )
2259 else:
2260 currentDevicesResult = main.FALSE
2261 utilities.assert_equals( expect=main.TRUE,
2262 actual=currentDevicesResult,
2263 onpass="ONOS" + controllerStr +
2264 " Switches view is correct",
2265 onfail="ONOS" + controllerStr +
2266 " Switches view is incorrect" )
2267
2268 if links[ controller ] and "Error" not in links[ controller ]:
2269 currentLinksResult = main.Mininet1.compareLinks(
2270 mnSwitches, mnLinks,
2271 json.loads( links[ controller ] ) )
2272 else:
2273 currentLinksResult = main.FALSE
2274 utilities.assert_equals( expect=main.TRUE,
2275 actual=currentLinksResult,
2276 onpass="ONOS" + controllerStr +
2277 " links view is correct",
2278 onfail="ONOS" + controllerStr +
2279 " links view is incorrect" )
2280
2281 if hosts[ controller ] or "Error" not in hosts[ controller ]:
2282 currentHostsResult = main.Mininet1.compareHosts(
2283 mnHosts,
2284 hosts[ controller ] )
2285 else:
2286 currentHostsResult = main.FALSE
2287 utilities.assert_equals( expect=main.TRUE,
2288 actual=currentHostsResult,
2289 onpass="ONOS" + controllerStr +
2290 " hosts exist in Mininet",
2291 onfail="ONOS" + controllerStr +
2292 " hosts don't match Mininet" )
2293 # CHECKING HOST ATTACHMENT POINTS
2294 hostAttachment = True
2295 noHosts = False
2296 # FIXME: topo-HA/obelisk specific mappings:
2297 # key is mac and value is dpid
2298 mappings = {}
2299 for i in range( 1, 29 ): # hosts 1 through 28
2300 # set up correct variables:
2301 macId = "00:" * 5 + hex( i ).split( "0x" )[1].upper().zfill(2)
2302 if i == 1:
2303 deviceId = "1000".zfill(16)
2304 elif i == 2:
2305 deviceId = "2000".zfill(16)
2306 elif i == 3:
2307 deviceId = "3000".zfill(16)
2308 elif i == 4:
2309 deviceId = "3004".zfill(16)
2310 elif i == 5:
2311 deviceId = "5000".zfill(16)
2312 elif i == 6:
2313 deviceId = "6000".zfill(16)
2314 elif i == 7:
2315 deviceId = "6007".zfill(16)
2316 elif i >= 8 and i <= 17:
2317 dpid = '3' + str( i ).zfill( 3 )
2318 deviceId = dpid.zfill(16)
2319 elif i >= 18 and i <= 27:
2320 dpid = '6' + str( i ).zfill( 3 )
2321 deviceId = dpid.zfill(16)
2322 elif i == 28:
2323 deviceId = "2800".zfill(16)
2324 mappings[ macId ] = deviceId
2325 if hosts[ controller ] or "Error" not in hosts[ controller ]:
2326 if hosts[ controller ] == []:
2327 main.log.warn( "There are no hosts discovered" )
2328 noHosts = True
2329 else:
2330 for host in hosts[ controller ]:
2331 mac = None
2332 location = None
2333 device = None
2334 port = None
2335 try:
2336 mac = host.get( 'mac' )
2337 assert mac, "mac field could not be found for this host object"
2338
2339 location = host.get( 'location' )
2340 assert location, "location field could not be found for this host object"
2341
2342 # Trim the protocol identifier off deviceId
2343 device = str( location.get( 'elementId' ) ).split(':')[1]
2344 assert device, "elementId field could not be found for this host location object"
2345
2346 port = location.get( 'port' )
2347 assert port, "port field could not be found for this host location object"
2348
2349 # Now check if this matches where they should be
2350 if mac and device and port:
2351 if str( port ) != "1":
2352 main.log.error( "The attachment port is incorrect for " +
2353 "host " + str( mac ) +
2354 ". Expected: 1 Actual: " + str( port) )
2355 hostAttachment = False
2356 if device != mappings[ str( mac ) ]:
2357 main.log.error( "The attachment device is incorrect for " +
2358 "host " + str( mac ) +
2359 ". Expected: " + mappings[ str( mac ) ] +
2360 " Actual: " + device )
2361 hostAttachment = False
2362 else:
2363 hostAttachment = False
2364 except AssertionError:
2365 main.log.exception( "Json object not as expected" )
2366 main.log.error( repr( host ) )
2367 hostAttachment = False
2368 else:
2369 main.log.error( "No hosts json output or \"Error\"" +
2370 " in output. hosts = " +
2371 repr( hosts[ controller ] ) )
2372 if noHosts is False:
2373 # TODO: Find a way to know if there should be hosts in a
2374 # given point of the test
2375 hostAttachment = True
2376
2377 # END CHECKING HOST ATTACHMENT POINTS
2378 devicesResults = devicesResults and currentDevicesResult
2379 linksResults = linksResults and currentLinksResult
2380 hostsResults = hostsResults and currentHostsResult
2381 hostAttachmentResults = hostAttachmentResults and\
2382 hostAttachment
2383 topoResult = ( devicesResults and linksResults
2384 and hostsResults and ipResult and
2385 hostAttachmentResults )
2386
2387 # Compare json objects for hosts and dataplane clusters
2388
2389 # hosts
2390 main.step( "Hosts view is consistent across all ONOS nodes" )
2391 consistentHostsResult = main.TRUE
2392 for controller in range( len( hosts ) ):
2393 controllerStr = str( controller + 1 )
2394 if "Error" not in hosts[ controller ]:
2395 if hosts[ controller ] == hosts[ 0 ]:
2396 continue
2397 else: # hosts not consistent
2398 main.log.error( "hosts from ONOS" + controllerStr +
2399 " is inconsistent with ONOS1" )
2400 main.log.warn( repr( hosts[ controller ] ) )
2401 consistentHostsResult = main.FALSE
2402
2403 else:
2404 main.log.error( "Error in getting ONOS hosts from ONOS" +
2405 controllerStr )
2406 consistentHostsResult = main.FALSE
2407 main.log.warn( "ONOS" + controllerStr +
2408 " hosts response: " +
2409 repr( hosts[ controller ] ) )
2410 utilities.assert_equals(
2411 expect=main.TRUE,
2412 actual=consistentHostsResult,
2413 onpass="Hosts view is consistent across all ONOS nodes",
2414 onfail="ONOS nodes have different views of hosts" )
2415
2416 main.step( "Hosts information is correct" )
2417 hostsResults = hostsResults and ipResult
2418 utilities.assert_equals(
2419 expect=main.TRUE,
2420 actual=hostsResults,
2421 onpass="Host information is correct",
2422 onfail="Host information is incorrect" )
2423
2424 main.step( "Host attachment points to the network" )
2425 utilities.assert_equals(
2426 expect=True,
2427 actual=hostAttachmentResults,
2428 onpass="Hosts are correctly attached to the network",
2429 onfail="ONOS did not correctly attach hosts to the network" )
2430
2431 # Strongly connected clusters of devices
2432 main.step( "Clusters view is consistent across all ONOS nodes" )
2433 consistentClustersResult = main.TRUE
2434 for controller in range( len( clusters ) ):
2435 controllerStr = str( controller + 1 )
2436 if "Error" not in clusters[ controller ]:
2437 if clusters[ controller ] == clusters[ 0 ]:
2438 continue
2439 else: # clusters not consistent
2440 main.log.error( "clusters from ONOS" +
2441 controllerStr +
2442 " is inconsistent with ONOS1" )
2443 consistentClustersResult = main.FALSE
2444
2445 else:
2446 main.log.error( "Error in getting dataplane clusters " +
2447 "from ONOS" + controllerStr )
2448 consistentClustersResult = main.FALSE
2449 main.log.warn( "ONOS" + controllerStr +
2450 " clusters response: " +
2451 repr( clusters[ controller ] ) )
2452 utilities.assert_equals(
2453 expect=main.TRUE,
2454 actual=consistentClustersResult,
2455 onpass="Clusters view is consistent across all ONOS nodes",
2456 onfail="ONOS nodes have different views of clusters" )
2457
2458 main.step( "There is only one SCC" )
2459 # there should always only be one cluster
2460 try:
2461 numClusters = len( json.loads( clusters[ 0 ] ) )
2462 except ( ValueError, TypeError ):
2463 main.log.exception( "Error parsing clusters[0]: " +
2464 repr( clusters[0] ) )
2465 clusterResults = main.FALSE
2466 if numClusters == 1:
2467 clusterResults = main.TRUE
2468 utilities.assert_equals(
2469 expect=1,
2470 actual=numClusters,
2471 onpass="ONOS shows 1 SCC",
2472 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
2473
2474 topoResult = ( devicesResults and linksResults
2475 and hostsResults and consistentHostsResult
2476 and consistentClustersResult and clusterResults
2477 and ipResult and hostAttachmentResults )
2478
2479 topoResult = topoResult and int( count <= 2 )
2480 note = "note it takes about " + str( int( cliTime ) ) + \
2481 " seconds for the test to make all the cli calls to fetch " +\
2482 "the topology from each ONOS instance"
2483 main.log.info(
2484 "Very crass estimate for topology discovery/convergence( " +
2485 str( note ) + " ): " + str( elapsed ) + " seconds, " +
2486 str( count ) + " tries" )
2487
2488 main.step( "Device information is correct" )
2489 utilities.assert_equals(
2490 expect=main.TRUE,
2491 actual=devicesResults,
2492 onpass="Device information is correct",
2493 onfail="Device information is incorrect" )
2494
2495 main.step( "Links are correct" )
2496 utilities.assert_equals(
2497 expect=main.TRUE,
2498 actual=linksResults,
2499 onpass="Link are correct",
2500 onfail="Links are incorrect" )
2501
2502 # FIXME: move this to an ONOS state case
2503 main.step( "Checking ONOS nodes" )
2504 nodesOutput = []
2505 nodeResults = main.TRUE
2506 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002507 for i in range( main.numCtrls ):
2508 t = main.Thread( target=main.CLIs[i].nodes,
Jon Hall5cf14d52015-07-16 12:15:19 -07002509 name="nodes-" + str( i ),
2510 args=[ ] )
2511 threads.append( t )
2512 t.start()
2513
2514 for t in threads:
2515 t.join()
2516 nodesOutput.append( t.result )
Jon Halle1a3b752015-07-22 13:02:46 -07002517 ips = [ node.ip_address for node in main.nodes ]
Jon Hall5cf14d52015-07-16 12:15:19 -07002518 for i in nodesOutput:
2519 try:
2520 current = json.loads( i )
2521 for node in current:
2522 currentResult = main.FALSE
2523 if node['ip'] in ips: # node in nodes() output is in cell
2524 if node['state'] == 'ACTIVE':
2525 currentResult = main.TRUE
2526 else:
2527 main.log.error( "Error in ONOS node availability" )
2528 main.log.error(
2529 json.dumps( current,
2530 sort_keys=True,
2531 indent=4,
2532 separators=( ',', ': ' ) ) )
2533 break
2534 nodeResults = nodeResults and currentResult
2535 except ( ValueError, TypeError ):
2536 main.log.error( "Error parsing nodes output" )
2537 main.log.warn( repr( i ) )
2538 utilities.assert_equals( expect=main.TRUE, actual=nodeResults,
2539 onpass="Nodes check successful",
2540 onfail="Nodes check NOT successful" )
2541
2542 def CASE9( self, main ):
2543 """
2544 Link s3-s28 down
2545 """
2546 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002547 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002548 assert main, "main not defined"
2549 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002550 assert main.CLIs, "main.CLIs not defined"
2551 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002552 # NOTE: You should probably run a topology check after this
2553
2554 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
2555
2556 description = "Turn off a link to ensure that Link Discovery " +\
2557 "is working properly"
2558 main.case( description )
2559
2560 main.step( "Kill Link between s3 and s28" )
2561 LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" )
2562 main.log.info( "Waiting " + str( linkSleep ) +
2563 " seconds for link down to be discovered" )
2564 time.sleep( linkSleep )
2565 utilities.assert_equals( expect=main.TRUE, actual=LinkDown,
2566 onpass="Link down successful",
2567 onfail="Failed to bring link down" )
2568 # TODO do some sort of check here
2569
2570 def CASE10( self, main ):
2571 """
2572 Link s3-s28 up
2573 """
2574 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002575 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002576 assert main, "main not defined"
2577 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002578 assert main.CLIs, "main.CLIs not defined"
2579 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002580 # NOTE: You should probably run a topology check after this
2581
2582 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
2583
2584 description = "Restore a link to ensure that Link Discovery is " + \
2585 "working properly"
2586 main.case( description )
2587
2588 main.step( "Bring link between s3 and s28 back up" )
2589 LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" )
2590 main.log.info( "Waiting " + str( linkSleep ) +
2591 " seconds for link up to be discovered" )
2592 time.sleep( linkSleep )
2593 utilities.assert_equals( expect=main.TRUE, actual=LinkUp,
2594 onpass="Link up successful",
2595 onfail="Failed to bring link up" )
2596 # TODO do some sort of check here
2597
2598 def CASE11( self, main ):
2599 """
2600 Switch Down
2601 """
2602 # NOTE: You should probably run a topology check after this
2603 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002604 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002605 assert main, "main not defined"
2606 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002607 assert main.CLIs, "main.CLIs not defined"
2608 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002609
2610 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
2611
2612 description = "Killing a switch to ensure it is discovered correctly"
2613 main.case( description )
2614 switch = main.params[ 'kill' ][ 'switch' ]
2615 switchDPID = main.params[ 'kill' ][ 'dpid' ]
2616
2617 # TODO: Make this switch parameterizable
2618 main.step( "Kill " + switch )
2619 main.log.info( "Deleting " + switch )
2620 main.Mininet1.delSwitch( switch )
2621 main.log.info( "Waiting " + str( switchSleep ) +
2622 " seconds for switch down to be discovered" )
2623 time.sleep( switchSleep )
2624 device = main.ONOScli1.getDevice( dpid=switchDPID )
2625 # Peek at the deleted switch
2626 main.log.warn( str( device ) )
2627 result = main.FALSE
2628 if device and device[ 'available' ] is False:
2629 result = main.TRUE
2630 utilities.assert_equals( expect=main.TRUE, actual=result,
2631 onpass="Kill switch successful",
2632 onfail="Failed to kill switch?" )
2633
2634 def CASE12( self, main ):
2635 """
2636 Switch Up
2637 """
2638 # NOTE: You should probably run a topology check after this
2639 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002640 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002641 assert main, "main not defined"
2642 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002643 assert main.CLIs, "main.CLIs not defined"
2644 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002645 assert ONOS1Port, "ONOS1Port not defined"
2646 assert ONOS2Port, "ONOS2Port not defined"
2647 assert ONOS3Port, "ONOS3Port not defined"
2648 assert ONOS4Port, "ONOS4Port not defined"
2649 assert ONOS5Port, "ONOS5Port not defined"
2650 assert ONOS6Port, "ONOS6Port not defined"
2651 assert ONOS7Port, "ONOS7Port not defined"
2652
2653 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
2654 switch = main.params[ 'kill' ][ 'switch' ]
2655 switchDPID = main.params[ 'kill' ][ 'dpid' ]
2656 links = main.params[ 'kill' ][ 'links' ].split()
2657 description = "Adding a switch to ensure it is discovered correctly"
2658 main.case( description )
2659
2660 main.step( "Add back " + switch )
2661 main.Mininet1.addSwitch( switch, dpid=switchDPID )
2662 for peer in links:
2663 main.Mininet1.addLink( switch, peer )
2664 ipList = []
Jon Halle1a3b752015-07-22 13:02:46 -07002665 for i in range( main.numCtrls ):
2666 ipList.append( main.nodes[ i ].ip_address )
Jon Hall5cf14d52015-07-16 12:15:19 -07002667 main.Mininet1.assignSwController( sw=switch, ip=ipList )
2668 main.log.info( "Waiting " + str( switchSleep ) +
2669 " seconds for switch up to be discovered" )
2670 time.sleep( switchSleep )
2671 device = main.ONOScli1.getDevice( dpid=switchDPID )
2672 # Peek at the deleted switch
2673 main.log.warn( str( device ) )
2674 result = main.FALSE
2675 if device and device[ 'available' ]:
2676 result = main.TRUE
2677 utilities.assert_equals( expect=main.TRUE, actual=result,
2678 onpass="add switch successful",
2679 onfail="Failed to add switch?" )
2680
2681 def CASE13( self, main ):
2682 """
2683 Clean up
2684 """
2685 import os
2686 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002687 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002688 assert main, "main not defined"
2689 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002690 assert main.CLIs, "main.CLIs not defined"
2691 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002692
2693 # printing colors to terminal
2694 colors = { 'cyan': '\033[96m', 'purple': '\033[95m',
2695 'blue': '\033[94m', 'green': '\033[92m',
2696 'yellow': '\033[93m', 'red': '\033[91m', 'end': '\033[0m' }
2697 main.case( "Test Cleanup" )
2698 main.step( "Killing tcpdumps" )
2699 main.Mininet2.stopTcpdump()
2700
2701 testname = main.TEST
Jon Hall5ec6b1b2015-09-17 18:20:14 -07002702 main.log.error( main.params[ 'BACKUP' ][ 'ENABLED' ] )
2703 if main.params[ 'BACKUP' ][ 'ENABLED' ] == "True":
Jon Hall5cf14d52015-07-16 12:15:19 -07002704 main.step( "Copying MN pcap and ONOS log files to test station" )
2705 teststationUser = main.params[ 'BACKUP' ][ 'TESTONUSER' ]
2706 teststationIP = main.params[ 'BACKUP' ][ 'TESTONIP' ]
2707 # NOTE: MN Pcap file is being saved to ~/packet_captures
2708 # scp this file as MN and TestON aren't necessarily the same vm
2709 # FIXME: scp
2710 # mn files
2711 # TODO: Load these from params
2712 # NOTE: must end in /
2713 logFolder = "/opt/onos/log/"
2714 logFiles = [ "karaf.log", "karaf.log.1" ]
2715 # NOTE: must end in /
Jon Hall5cf14d52015-07-16 12:15:19 -07002716 for f in logFiles:
Jon Halle1a3b752015-07-22 13:02:46 -07002717 for node in main.nodes:
Jon Hall5cf14d52015-07-16 12:15:19 -07002718 main.ONOSbench.handle.sendline( "scp sdn@" + node.ip_address +
2719 ":" + logFolder + f + " " +
2720 teststationUser + "@" +
2721 teststationIP + ":" +
Jon Hall5ec6b1b2015-09-17 18:20:14 -07002722 main.logdir + "/" +
2723 node.name + "-" + f )
2724 main.ONOSbench.handle.expect( "\$ " )
2725 print main.ONOSbench.handle.before
Jon Hall5cf14d52015-07-16 12:15:19 -07002726
2727 # std*.log's
2728 # NOTE: must end in /
2729 logFolder = "/opt/onos/var/"
2730 logFiles = [ "stderr.log", "stdout.log" ]
2731 # NOTE: must end in /
Jon Hall5cf14d52015-07-16 12:15:19 -07002732 for f in logFiles:
Jon Halle1a3b752015-07-22 13:02:46 -07002733 for node in main.nodes:
Jon Hall5cf14d52015-07-16 12:15:19 -07002734 main.ONOSbench.handle.sendline( "scp sdn@" + node.ip_address +
2735 ":" + logFolder + f + " " +
2736 teststationUser + "@" +
2737 teststationIP + ":" +
Jon Hall5ec6b1b2015-09-17 18:20:14 -07002738 main.logdir + "/" +
2739 node.name + "-" + f )
2740 main.ONOSbench.handle.expect( "\$ " )
2741 print main.ONOSbench.handle.before
Jon Hall5cf14d52015-07-16 12:15:19 -07002742 # sleep so scp can finish
2743 time.sleep( 10 )
Jon Hall5ec6b1b2015-09-17 18:20:14 -07002744 # main.step( "Packing and rotating pcap archives" )
2745 # os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) )
2746 else:
2747 main.log.debug( "skipping saving log files" )
Jon Hall5cf14d52015-07-16 12:15:19 -07002748
2749 main.step( "Stopping Mininet" )
2750 mnResult = main.Mininet1.stopNet()
2751 utilities.assert_equals( expect=main.TRUE, actual=mnResult,
2752 onpass="Mininet stopped",
2753 onfail="MN cleanup NOT successful" )
2754
2755 main.step( "Checking ONOS Logs for errors" )
Jon Halle1a3b752015-07-22 13:02:46 -07002756 for node in main.nodes:
Jon Hall5ec6b1b2015-09-17 18:20:14 -07002757 main.log.debug( "Checking logs for errors on " + node.name + ":" )
2758 main.log.warn( main.ONOSbench.checkLogs( node.ip_address ) )
Jon Hall5cf14d52015-07-16 12:15:19 -07002759
2760 try:
2761 timerLog = open( main.logdir + "/Timers.csv", 'w')
2762 main.log.error( ", ".join( labels ) + "\n" + ", ".join( data ) )
2763 timerLog.write( ", ".join( labels ) + "\n" + ", ".join( data ) )
2764 timerLog.close()
2765 except NameError, e:
2766 main.log.exception(e)
2767
2768 def CASE14( self, main ):
2769 """
2770 start election app on all onos nodes
2771 """
Jon Halle1a3b752015-07-22 13:02:46 -07002772 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002773 assert main, "main not defined"
2774 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002775 assert main.CLIs, "main.CLIs not defined"
2776 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002777
2778 main.case("Start Leadership Election app")
2779 main.step( "Install leadership election app" )
2780 appResult = main.ONOScli1.activateApp( "org.onosproject.election" )
2781 utilities.assert_equals(
2782 expect=main.TRUE,
2783 actual=appResult,
2784 onpass="Election app installed",
2785 onfail="Something went wrong with installing Leadership election" )
2786
2787 main.step( "Run for election on each node" )
2788 leaderResult = main.TRUE
2789 leaders = []
Jon Halle1a3b752015-07-22 13:02:46 -07002790 for cli in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -07002791 cli.electionTestRun()
Jon Halle1a3b752015-07-22 13:02:46 -07002792 for cli in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -07002793 leader = cli.electionTestLeader()
2794 if leader is None or leader == main.FALSE:
2795 main.log.error( cli.name + ": Leader for the election app " +
2796 "should be an ONOS node, instead got '" +
2797 str( leader ) + "'" )
2798 leaderResult = main.FALSE
2799 leaders.append( leader )
2800 utilities.assert_equals(
2801 expect=main.TRUE,
2802 actual=leaderResult,
2803 onpass="Successfully ran for leadership",
2804 onfail="Failed to run for leadership" )
2805
2806 main.step( "Check that each node shows the same leader" )
2807 sameLeader = main.TRUE
2808 if len( set( leaders ) ) != 1:
2809 sameLeader = main.FALSE
2810 main.log.error( "Results of electionTestLeader is order of CLIs:" +
2811 str( leaders ) )
2812 utilities.assert_equals(
2813 expect=main.TRUE,
2814 actual=sameLeader,
2815 onpass="Leadership is consistent for the election topic",
2816 onfail="Nodes have different leaders" )
2817
2818 def CASE15( self, main ):
2819 """
2820 Check that Leadership Election is still functional
acsmars9475b1c2015-08-28 18:02:08 -07002821 15.1 Run election on each node
2822 15.2 Check that each node has the same leaders and candidates
2823 15.3 Find current leader and withdraw
2824 15.4 Check that a new node was elected leader
2825 15.5 Check that that new leader was the candidate of old leader
2826 15.6 Run for election on old leader
2827 15.7 Check that oldLeader is a candidate, and leader if only 1 node
2828 15.8 Make sure that the old leader was added to the candidate list
2829
2830 old and new variable prefixes refer to data from before vs after
2831 withdrawl and later before withdrawl vs after re-election
Jon Hall5cf14d52015-07-16 12:15:19 -07002832 """
2833 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002834 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002835 assert main, "main not defined"
2836 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002837 assert main.CLIs, "main.CLIs not defined"
2838 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002839
Jon Hall5cf14d52015-07-16 12:15:19 -07002840 description = "Check that Leadership Election is still functional"
2841 main.case( description )
2842 # NOTE: Need to re-run since being a canidate is not persistant
acsmars9475b1c2015-08-28 18:02:08 -07002843 # TODO: add check for "Command not found:" in the driver, this
2844 # means the election test app isn't loaded
2845
2846 oldLeaders = [] # leaders by node before withdrawl from candidates
2847 newLeaders = [] # leaders by node after withdrawl from candidates
2848 oldAllCandidates = [] # list of lists of each nodes' candidates before
2849 newAllCandidates = [] # list of lists of each nodes' candidates after
2850 oldCandidates = [] # list of candidates from node 0 before withdrawl
2851 newCandidates = [] # list of candidates from node 0 after withdrawl
2852 oldLeader = '' # the old leader from oldLeaders, None if not same
2853 newLeader = '' # the new leaders fron newLoeaders, None if not same
2854 oldLeaderCLI = None # the CLI of the old leader used for re-electing
acsmars71adceb2015-08-31 15:09:26 -07002855 expectNoLeader = False # True when there is only one leader
2856 if main.numCtrls == 1:
2857 expectNoLeader = True
acsmars9475b1c2015-08-28 18:02:08 -07002858
Jon Hall5cf14d52015-07-16 12:15:19 -07002859 main.step( "Run for election on each node" )
acsmars9475b1c2015-08-28 18:02:08 -07002860 electionResult = main.TRUE
2861
2862 for cli in main.CLIs: # run test election on each node
2863 if cli.electionTestRun() == main.FALSE:
2864 electionResult = main.FALSE
2865
Jon Hall5cf14d52015-07-16 12:15:19 -07002866 utilities.assert_equals(
2867 expect=main.TRUE,
acsmars9475b1c2015-08-28 18:02:08 -07002868 actual=electionResult,
2869 onpass="All nodes successfully ran for leadership",
2870 onfail="At least one node failed to run for leadership" )
Jon Hall5cf14d52015-07-16 12:15:19 -07002871
acsmars3a72bde2015-09-02 14:16:22 -07002872 if electionResult == main.FALSE:
2873 main.log.error(
2874 "Skipping Test Case because Election Test App isn't loaded" )
2875 main.skipCase()
2876
acsmars9475b1c2015-08-28 18:02:08 -07002877 main.step( "Check that each node shows the same leader and candidates" )
2878 sameResult = main.TRUE
2879 failMessage = "Nodes have different leaders"
2880 for cli in main.CLIs:
2881 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
2882 oldAllCandidates.append( node )
2883 oldLeaders.append( node[ 0 ] )
2884 oldCandidates = oldAllCandidates[ 0 ]
2885
2886 # Check that each node has the same leader. Defines oldLeader
2887 if len( set( oldLeaders ) ) != 1:
2888 sameResult = main.FALSE
acsmars71adceb2015-08-31 15:09:26 -07002889 main.log.error( "More than one leader present:" + str( oldLeaders ) )
acsmars9475b1c2015-08-28 18:02:08 -07002890 oldLeader = None
2891 else:
2892 oldLeader = oldLeaders[ 0 ]
2893
2894 # Check that each node's candidate list is the same
2895 for candidates in oldAllCandidates:
2896 if set( candidates ) != set( oldCandidates ):
2897 sameResult = main.FALSE
2898 failMessage += "and candidates"
2899
Jon Hall5cf14d52015-07-16 12:15:19 -07002900 utilities.assert_equals(
2901 expect=main.TRUE,
acsmars71adceb2015-08-31 15:09:26 -07002902 actual=sameResult,
Jon Hall5cf14d52015-07-16 12:15:19 -07002903 onpass="Leadership is consistent for the election topic",
acsmars9475b1c2015-08-28 18:02:08 -07002904 onfail=failMessage )
Jon Hall5cf14d52015-07-16 12:15:19 -07002905
2906 main.step( "Find current leader and withdraw" )
acsmars9475b1c2015-08-28 18:02:08 -07002907 withdrawResult = main.TRUE
Jon Hall5cf14d52015-07-16 12:15:19 -07002908 # do some sanity checking on leader before using it
acsmars9475b1c2015-08-28 18:02:08 -07002909 if oldLeader is None:
2910 main.log.error( "Leadership isn't consistent." )
2911 withdrawResult = main.FALSE
2912 # Get the CLI of the oldLeader
Jon Halle1a3b752015-07-22 13:02:46 -07002913 for i in range( len( main.CLIs ) ):
acsmars9475b1c2015-08-28 18:02:08 -07002914 if oldLeader == main.nodes[ i ].ip_address:
2915 oldLeaderCLI = main.CLIs[ i ]
Jon Hall5cf14d52015-07-16 12:15:19 -07002916 break
2917 else: # FOR/ELSE statement
2918 main.log.error( "Leader election, could not find current leader" )
2919 if oldLeader:
acsmars9475b1c2015-08-28 18:02:08 -07002920 withdrawResult = oldLeaderCLI.electionTestWithdraw()
Jon Hall5cf14d52015-07-16 12:15:19 -07002921 utilities.assert_equals(
2922 expect=main.TRUE,
2923 actual=withdrawResult,
2924 onpass="Node was withdrawn from election",
2925 onfail="Node was not withdrawn from election" )
2926
acsmars9475b1c2015-08-28 18:02:08 -07002927 main.step( "Check that a new node was elected leader" )
acsmars71adceb2015-08-31 15:09:26 -07002928
Jon Hall5cf14d52015-07-16 12:15:19 -07002929 # FIXME: use threads
acsmars9475b1c2015-08-28 18:02:08 -07002930 newLeaderResult = main.TRUE
2931 failMessage = "Nodes have different leaders"
2932
2933 # Get new leaders and candidates
Jon Halle1a3b752015-07-22 13:02:46 -07002934 for cli in main.CLIs:
acsmars9475b1c2015-08-28 18:02:08 -07002935 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
acsmars71adceb2015-08-31 15:09:26 -07002936 # elections might no have finished yet
2937 if node[ 0 ] == 'none' and not expectNoLeader:
acsmars9475b1c2015-08-28 18:02:08 -07002938 main.log.info( "Node has no leader, waiting 5 seconds to be " +
2939 "sure elections are complete." )
2940 time.sleep(5)
2941 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
acsmars71adceb2015-08-31 15:09:26 -07002942 # election still isn't done or there is a problem
2943 if node[ 0 ] == 'none':
2944 main.log.error( "No leader was elected on at least 1 node" )
2945 newLeaderResult = main.FALSE
acsmars9475b1c2015-08-28 18:02:08 -07002946 newAllCandidates.append( node )
2947 newLeaders.append( node[ 0 ] )
2948 newCandidates = newAllCandidates[ 0 ]
2949
2950 # Check that each node has the same leader. Defines newLeader
2951 if len( set( newLeaders ) ) != 1:
2952 newLeaderResult = main.FALSE
2953 main.log.error( "Nodes have different leaders: " +
2954 str( newLeaders ) )
2955 newLeader = None
Jon Hall5cf14d52015-07-16 12:15:19 -07002956 else:
acsmars9475b1c2015-08-28 18:02:08 -07002957 newLeader = newLeaders[ 0 ]
2958
acsmars71adceb2015-08-31 15:09:26 -07002959 # Check that each node's candidate list is the same
2960 for candidates in newAllCandidates:
2961 if set( candidates ) != set( newCandidates ):
2962 newLeaderResult = main.FALSE
2963 main.error.log( "Discrepancy in candidate lists detected" )
2964
acsmars9475b1c2015-08-28 18:02:08 -07002965 # Check that the new leader is not the older leader, which was withdrawn
2966 if newLeader == oldLeader:
2967 newLeaderResult = main.FALSE
2968 main.log.error( "All nodes still see old leader: " + oldLeader +
2969 " as the current leader" )
2970
Jon Hall5cf14d52015-07-16 12:15:19 -07002971 utilities.assert_equals(
2972 expect=main.TRUE,
acsmars9475b1c2015-08-28 18:02:08 -07002973 actual=newLeaderResult,
Jon Hall5cf14d52015-07-16 12:15:19 -07002974 onpass="Leadership election passed",
2975 onfail="Something went wrong with Leadership election" )
2976
acsmars9475b1c2015-08-28 18:02:08 -07002977 main.step( "Check that that new leader was the candidate of old leader")
2978 # candidates[ 2 ] should be come the top candidate after withdrawl
2979 correctCandidateResult = main.TRUE
acsmars71adceb2015-08-31 15:09:26 -07002980 if expectNoLeader:
2981 if newLeader == 'none':
2982 main.log.info( "No leader expected. None found. Pass" )
2983 correctCandidateResult = main.TRUE
2984 else:
2985 main.log.info( "Expected no leader, got: " + str( newLeader ) )
2986 correctCandidateResult = main.FALSE
2987 elif newLeader != oldCandidates[ 2 ]:
acsmars9475b1c2015-08-28 18:02:08 -07002988 correctCandidateResult = main.FALSE
2989 main.log.error( "Candidate " + newLeader + " was elected. " +
2990 oldCandidates[ 2 ] + " should have had priority." )
2991
2992 utilities.assert_equals(
2993 expect=main.TRUE,
2994 actual=correctCandidateResult,
2995 onpass="Correct Candidate Elected",
2996 onfail="Incorrect Candidate Elected" )
2997
Jon Hall5cf14d52015-07-16 12:15:19 -07002998 main.step( "Run for election on old leader( just so everyone " +
2999 "is in the hat )" )
acsmars9475b1c2015-08-28 18:02:08 -07003000 if oldLeaderCLI is not None:
3001 runResult = oldLeaderCLI.electionTestRun()
Jon Hall5cf14d52015-07-16 12:15:19 -07003002 else:
acsmars9475b1c2015-08-28 18:02:08 -07003003 main.log.error( "No old leader to re-elect" )
Jon Hall5cf14d52015-07-16 12:15:19 -07003004 runResult = main.FALSE
3005 utilities.assert_equals(
3006 expect=main.TRUE,
3007 actual=runResult,
3008 onpass="App re-ran for election",
3009 onfail="App failed to run for election" )
acsmars9475b1c2015-08-28 18:02:08 -07003010 main.step(
3011 "Check that oldLeader is a candidate, and leader if only 1 node" )
Jon Hall5cf14d52015-07-16 12:15:19 -07003012 # verify leader didn't just change
acsmars9475b1c2015-08-28 18:02:08 -07003013 positionResult = main.TRUE
3014 # Get new leaders and candidates, wait if oldLeader is not a candidate yet
3015
3016 # Reset and reuse the new candidate and leaders lists
3017 newAllCandidates = []
3018 newCandidates = []
3019 newLeaders = []
3020 for cli in main.CLIs:
3021 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
3022 if oldLeader not in node: # election might no have finished yet
3023 main.log.info( "Old Leader not elected, waiting 5 seconds to " +
3024 "be sure elections are complete" )
3025 time.sleep(5)
3026 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
3027 if oldLeader not in node: # election still isn't done, errors
3028 main.log.error(
3029 "Old leader was not elected on at least one node" )
3030 positionResult = main.FALSE
3031 newAllCandidates.append( node )
3032 newLeaders.append( node[ 0 ] )
3033 newCandidates = newAllCandidates[ 0 ]
3034
3035 # Check that each node has the same leader. Defines newLeader
3036 if len( set( newLeaders ) ) != 1:
3037 positionResult = main.FALSE
3038 main.log.error( "Nodes have different leaders: " +
3039 str( newLeaders ) )
3040 newLeader = None
Jon Hall5cf14d52015-07-16 12:15:19 -07003041 else:
acsmars9475b1c2015-08-28 18:02:08 -07003042 newLeader = newLeaders[ 0 ]
3043
acsmars71adceb2015-08-31 15:09:26 -07003044 # Check that each node's candidate list is the same
3045 for candidates in newAllCandidates:
3046 if set( candidates ) != set( newCandidates ):
3047 newLeaderResult = main.FALSE
3048 main.error.log( "Discrepancy in candidate lists detected" )
3049
acsmars9475b1c2015-08-28 18:02:08 -07003050 # Check that the re-elected node is last on the candidate List
3051 if oldLeader != newCandidates[ -1 ]:
3052 main.log.error( "Old Leader (" + oldLeader + ") not in the proper position " +
3053 str( newCandidates ) )
3054 positionResult = main.FALSE
Jon Hall5cf14d52015-07-16 12:15:19 -07003055
3056 utilities.assert_equals(
3057 expect=main.TRUE,
acsmars9475b1c2015-08-28 18:02:08 -07003058 actual=positionResult,
Jon Hall5cf14d52015-07-16 12:15:19 -07003059 onpass="Old leader successfully re-ran for election",
3060 onfail="Something went wrong with Leadership election after " +
3061 "the old leader re-ran for election" )
3062
3063 def CASE16( self, main ):
3064 """
3065 Install Distributed Primitives app
3066 """
3067 import time
Jon Halle1a3b752015-07-22 13:02:46 -07003068 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07003069 assert main, "main not defined"
3070 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07003071 assert main.CLIs, "main.CLIs not defined"
3072 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07003073
3074 # Variables for the distributed primitives tests
3075 global pCounterName
3076 global iCounterName
3077 global pCounterValue
3078 global iCounterValue
3079 global onosSet
3080 global onosSetName
3081 pCounterName = "TestON-Partitions"
3082 iCounterName = "TestON-inMemory"
3083 pCounterValue = 0
3084 iCounterValue = 0
3085 onosSet = set([])
3086 onosSetName = "TestON-set"
3087
3088 description = "Install Primitives app"
3089 main.case( description )
3090 main.step( "Install Primitives app" )
3091 appName = "org.onosproject.distributedprimitives"
Jon Halle1a3b752015-07-22 13:02:46 -07003092 appResults = main.CLIs[0].activateApp( appName )
Jon Hall5cf14d52015-07-16 12:15:19 -07003093 utilities.assert_equals( expect=main.TRUE,
3094 actual=appResults,
3095 onpass="Primitives app activated",
3096 onfail="Primitives app not activated" )
3097 time.sleep( 5 ) # To allow all nodes to activate
3098
3099 def CASE17( self, main ):
3100 """
3101 Check for basic functionality with distributed primitives
3102 """
Jon Hall5cf14d52015-07-16 12:15:19 -07003103 # Make sure variables are defined/set
Jon Halle1a3b752015-07-22 13:02:46 -07003104 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07003105 assert main, "main not defined"
3106 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07003107 assert main.CLIs, "main.CLIs not defined"
3108 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07003109 assert pCounterName, "pCounterName not defined"
3110 assert iCounterName, "iCounterName not defined"
3111 assert onosSetName, "onosSetName not defined"
3112 # NOTE: assert fails if value is 0/None/Empty/False
3113 try:
3114 pCounterValue
3115 except NameError:
3116 main.log.error( "pCounterValue not defined, setting to 0" )
3117 pCounterValue = 0
3118 try:
3119 iCounterValue
3120 except NameError:
3121 main.log.error( "iCounterValue not defined, setting to 0" )
3122 iCounterValue = 0
3123 try:
3124 onosSet
3125 except NameError:
3126 main.log.error( "onosSet not defined, setting to empty Set" )
3127 onosSet = set([])
3128 # Variables for the distributed primitives tests. These are local only
3129 addValue = "a"
3130 addAllValue = "a b c d e f"
3131 retainValue = "c d e f"
3132
3133 description = "Check for basic functionality with distributed " +\
3134 "primitives"
3135 main.case( description )
Jon Halle1a3b752015-07-22 13:02:46 -07003136 main.caseExplanation = "Test the methods of the distributed " +\
3137 "primitives (counters and sets) throught the cli"
Jon Hall5cf14d52015-07-16 12:15:19 -07003138 # DISTRIBUTED ATOMIC COUNTERS
Jon Halle1a3b752015-07-22 13:02:46 -07003139 # Partitioned counters
3140 main.step( "Increment then get a default counter on each node" )
Jon Hall5cf14d52015-07-16 12:15:19 -07003141 pCounters = []
3142 threads = []
3143 addedPValues = []
Jon Halle1a3b752015-07-22 13:02:46 -07003144 for i in range( main.numCtrls ):
3145 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
3146 name="counterAddAndGet-" + str( i ),
Jon Hall5cf14d52015-07-16 12:15:19 -07003147 args=[ pCounterName ] )
3148 pCounterValue += 1
3149 addedPValues.append( pCounterValue )
3150 threads.append( t )
3151 t.start()
3152
3153 for t in threads:
3154 t.join()
3155 pCounters.append( t.result )
3156 # Check that counter incremented numController times
3157 pCounterResults = True
3158 for i in addedPValues:
3159 tmpResult = i in pCounters
3160 pCounterResults = pCounterResults and tmpResult
3161 if not tmpResult:
3162 main.log.error( str( i ) + " is not in partitioned "
3163 "counter incremented results" )
3164 utilities.assert_equals( expect=True,
3165 actual=pCounterResults,
3166 onpass="Default counter incremented",
3167 onfail="Error incrementing default" +
3168 " counter" )
3169
Jon Halle1a3b752015-07-22 13:02:46 -07003170 main.step( "Get then Increment a default counter on each node" )
3171 pCounters = []
3172 threads = []
3173 addedPValues = []
3174 for i in range( main.numCtrls ):
3175 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
3176 name="counterGetAndAdd-" + str( i ),
3177 args=[ pCounterName ] )
3178 addedPValues.append( pCounterValue )
3179 pCounterValue += 1
3180 threads.append( t )
3181 t.start()
3182
3183 for t in threads:
3184 t.join()
3185 pCounters.append( t.result )
3186 # Check that counter incremented numController times
3187 pCounterResults = True
3188 for i in addedPValues:
3189 tmpResult = i in pCounters
3190 pCounterResults = pCounterResults and tmpResult
3191 if not tmpResult:
3192 main.log.error( str( i ) + " is not in partitioned "
3193 "counter incremented results" )
3194 utilities.assert_equals( expect=True,
3195 actual=pCounterResults,
3196 onpass="Default counter incremented",
3197 onfail="Error incrementing default" +
3198 " counter" )
3199
3200 main.step( "Counters we added have the correct values" )
3201 incrementCheck = main.Counters.counterCheck( pCounterName, pCounterValue )
3202 utilities.assert_equals( expect=main.TRUE,
3203 actual=incrementCheck,
3204 onpass="Added counters are correct",
3205 onfail="Added counters are incorrect" )
3206
3207 main.step( "Add -8 to then get a default counter on each node" )
3208 pCounters = []
3209 threads = []
3210 addedPValues = []
3211 for i in range( main.numCtrls ):
3212 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
3213 name="counterIncrement-" + str( i ),
3214 args=[ pCounterName ],
3215 kwargs={ "delta": -8 } )
3216 pCounterValue += -8
3217 addedPValues.append( pCounterValue )
3218 threads.append( t )
3219 t.start()
3220
3221 for t in threads:
3222 t.join()
3223 pCounters.append( t.result )
3224 # Check that counter incremented numController times
3225 pCounterResults = True
3226 for i in addedPValues:
3227 tmpResult = i in pCounters
3228 pCounterResults = pCounterResults and tmpResult
3229 if not tmpResult:
3230 main.log.error( str( i ) + " is not in partitioned "
3231 "counter incremented results" )
3232 utilities.assert_equals( expect=True,
3233 actual=pCounterResults,
3234 onpass="Default counter incremented",
3235 onfail="Error incrementing default" +
3236 " counter" )
3237
3238 main.step( "Add 5 to then get a default counter on each node" )
3239 pCounters = []
3240 threads = []
3241 addedPValues = []
3242 for i in range( main.numCtrls ):
3243 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
3244 name="counterIncrement-" + str( i ),
3245 args=[ pCounterName ],
3246 kwargs={ "delta": 5 } )
3247 pCounterValue += 5
3248 addedPValues.append( pCounterValue )
3249 threads.append( t )
3250 t.start()
3251
3252 for t in threads:
3253 t.join()
3254 pCounters.append( t.result )
3255 # Check that counter incremented numController times
3256 pCounterResults = True
3257 for i in addedPValues:
3258 tmpResult = i in pCounters
3259 pCounterResults = pCounterResults and tmpResult
3260 if not tmpResult:
3261 main.log.error( str( i ) + " is not in partitioned "
3262 "counter incremented results" )
3263 utilities.assert_equals( expect=True,
3264 actual=pCounterResults,
3265 onpass="Default counter incremented",
3266 onfail="Error incrementing default" +
3267 " counter" )
3268
3269 main.step( "Get then add 5 to a default counter on each node" )
3270 pCounters = []
3271 threads = []
3272 addedPValues = []
3273 for i in range( main.numCtrls ):
3274 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
3275 name="counterIncrement-" + str( i ),
3276 args=[ pCounterName ],
3277 kwargs={ "delta": 5 } )
3278 addedPValues.append( pCounterValue )
3279 pCounterValue += 5
3280 threads.append( t )
3281 t.start()
3282
3283 for t in threads:
3284 t.join()
3285 pCounters.append( t.result )
3286 # Check that counter incremented numController times
3287 pCounterResults = True
3288 for i in addedPValues:
3289 tmpResult = i in pCounters
3290 pCounterResults = pCounterResults and tmpResult
3291 if not tmpResult:
3292 main.log.error( str( i ) + " is not in partitioned "
3293 "counter incremented results" )
3294 utilities.assert_equals( expect=True,
3295 actual=pCounterResults,
3296 onpass="Default counter incremented",
3297 onfail="Error incrementing default" +
3298 " counter" )
3299
3300 main.step( "Counters we added have the correct values" )
3301 incrementCheck = main.Counters.counterCheck( pCounterName, pCounterValue )
3302 utilities.assert_equals( expect=main.TRUE,
3303 actual=incrementCheck,
3304 onpass="Added counters are correct",
3305 onfail="Added counters are incorrect" )
3306
3307 # In-Memory counters
3308 main.step( "Increment and get an in-memory counter on each node" )
Jon Hall5cf14d52015-07-16 12:15:19 -07003309 iCounters = []
3310 addedIValues = []
3311 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003312 for i in range( main.numCtrls ):
3313 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003314 name="icounterIncrement-" + str( i ),
3315 args=[ iCounterName ],
3316 kwargs={ "inMemory": True } )
3317 iCounterValue += 1
3318 addedIValues.append( iCounterValue )
3319 threads.append( t )
3320 t.start()
3321
3322 for t in threads:
3323 t.join()
3324 iCounters.append( t.result )
3325 # Check that counter incremented numController times
3326 iCounterResults = True
3327 for i in addedIValues:
3328 tmpResult = i in iCounters
3329 iCounterResults = iCounterResults and tmpResult
3330 if not tmpResult:
3331 main.log.error( str( i ) + " is not in the in-memory "
3332 "counter incremented results" )
3333 utilities.assert_equals( expect=True,
3334 actual=iCounterResults,
Jon Halle1a3b752015-07-22 13:02:46 -07003335 onpass="In-memory counter incremented",
3336 onfail="Error incrementing in-memory" +
Jon Hall5cf14d52015-07-16 12:15:19 -07003337 " counter" )
3338
Jon Halle1a3b752015-07-22 13:02:46 -07003339 main.step( "Get then Increment a in-memory counter on each node" )
3340 iCounters = []
3341 threads = []
3342 addedIValues = []
3343 for i in range( main.numCtrls ):
3344 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
3345 name="counterGetAndAdd-" + str( i ),
3346 args=[ iCounterName ],
3347 kwargs={ "inMemory": True } )
3348 addedIValues.append( iCounterValue )
3349 iCounterValue += 1
3350 threads.append( t )
3351 t.start()
3352
3353 for t in threads:
3354 t.join()
3355 iCounters.append( t.result )
3356 # Check that counter incremented numController times
3357 iCounterResults = True
3358 for i in addedIValues:
3359 tmpResult = i in iCounters
3360 iCounterResults = iCounterResults and tmpResult
3361 if not tmpResult:
3362 main.log.error( str( i ) + " is not in in-memory "
3363 "counter incremented results" )
3364 utilities.assert_equals( expect=True,
3365 actual=iCounterResults,
3366 onpass="In-memory counter incremented",
3367 onfail="Error incrementing in-memory" +
3368 " counter" )
3369
3370 main.step( "Counters we added have the correct values" )
3371 incrementCheck = main.Counters.counterCheck( iCounterName, iCounterValue )
3372 utilities.assert_equals( expect=main.TRUE,
3373 actual=incrementCheck,
3374 onpass="Added counters are correct",
3375 onfail="Added counters are incorrect" )
3376
3377 main.step( "Add -8 to then get a in-memory counter on each node" )
3378 iCounters = []
3379 threads = []
3380 addedIValues = []
3381 for i in range( main.numCtrls ):
3382 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
3383 name="counterIncrement-" + str( i ),
3384 args=[ iCounterName ],
3385 kwargs={ "delta": -8, "inMemory": True } )
3386 iCounterValue += -8
3387 addedIValues.append( iCounterValue )
3388 threads.append( t )
3389 t.start()
3390
3391 for t in threads:
3392 t.join()
3393 iCounters.append( t.result )
3394 # Check that counter incremented numController times
3395 iCounterResults = True
3396 for i in addedIValues:
3397 tmpResult = i in iCounters
3398 iCounterResults = iCounterResults and tmpResult
3399 if not tmpResult:
3400 main.log.error( str( i ) + " is not in in-memory "
3401 "counter incremented results" )
3402 utilities.assert_equals( expect=True,
3403 actual=pCounterResults,
3404 onpass="In-memory counter incremented",
3405 onfail="Error incrementing in-memory" +
3406 " counter" )
3407
3408 main.step( "Add 5 to then get a in-memory counter on each node" )
3409 iCounters = []
3410 threads = []
3411 addedIValues = []
3412 for i in range( main.numCtrls ):
3413 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
3414 name="counterIncrement-" + str( i ),
3415 args=[ iCounterName ],
3416 kwargs={ "delta": 5, "inMemory": True } )
3417 iCounterValue += 5
3418 addedIValues.append( iCounterValue )
3419 threads.append( t )
3420 t.start()
3421
3422 for t in threads:
3423 t.join()
3424 iCounters.append( t.result )
3425 # Check that counter incremented numController times
3426 iCounterResults = True
3427 for i in addedIValues:
3428 tmpResult = i in iCounters
3429 iCounterResults = iCounterResults and tmpResult
3430 if not tmpResult:
3431 main.log.error( str( i ) + " is not in in-memory "
3432 "counter incremented results" )
3433 utilities.assert_equals( expect=True,
3434 actual=pCounterResults,
3435 onpass="In-memory counter incremented",
3436 onfail="Error incrementing in-memory" +
3437 " counter" )
3438
3439 main.step( "Get then add 5 to a in-memory counter on each node" )
3440 iCounters = []
3441 threads = []
3442 addedIValues = []
3443 for i in range( main.numCtrls ):
3444 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
3445 name="counterIncrement-" + str( i ),
3446 args=[ iCounterName ],
3447 kwargs={ "delta": 5, "inMemory": True } )
3448 addedIValues.append( iCounterValue )
3449 iCounterValue += 5
3450 threads.append( t )
3451 t.start()
3452
3453 for t in threads:
3454 t.join()
3455 iCounters.append( t.result )
3456 # Check that counter incremented numController times
3457 iCounterResults = True
3458 for i in addedIValues:
3459 tmpResult = i in iCounters
3460 iCounterResults = iCounterResults and tmpResult
3461 if not tmpResult:
3462 main.log.error( str( i ) + " is not in in-memory "
3463 "counter incremented results" )
3464 utilities.assert_equals( expect=True,
3465 actual=iCounterResults,
3466 onpass="In-memory counter incremented",
3467 onfail="Error incrementing in-memory" +
3468 " counter" )
3469
3470 main.step( "Counters we added have the correct values" )
3471 incrementCheck = main.Counters.counterCheck( iCounterName, iCounterValue )
3472 utilities.assert_equals( expect=main.TRUE,
3473 actual=incrementCheck,
3474 onpass="Added counters are correct",
3475 onfail="Added counters are incorrect" )
3476
Jon Hall5cf14d52015-07-16 12:15:19 -07003477 main.step( "Check counters are consistant across nodes" )
3478 onosCounters = []
3479 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003480 for i in range( main.numCtrls ):
3481 t = main.Thread( target=main.CLIs[i].counters,
Jon Hall5cf14d52015-07-16 12:15:19 -07003482 name="counters-" + str( i ) )
3483 threads.append( t )
3484 t.start()
3485 for t in threads:
3486 t.join()
3487 onosCounters.append( t.result )
3488 tmp = [ i == onosCounters[ 0 ] for i in onosCounters ]
3489 if all( tmp ):
3490 main.log.info( "Counters are consistent across all nodes" )
3491 consistentCounterResults = main.TRUE
3492 else:
3493 main.log.error( "Counters are not consistent across all nodes" )
3494 consistentCounterResults = main.FALSE
3495 utilities.assert_equals( expect=main.TRUE,
3496 actual=consistentCounterResults,
3497 onpass="ONOS counters are consistent " +
3498 "across nodes",
3499 onfail="ONOS Counters are inconsistent " +
3500 "across nodes" )
3501
3502 main.step( "Counters we added have the correct values" )
Jon Halle1a3b752015-07-22 13:02:46 -07003503 incrementCheck = main.Counters.counterCheck( iCounterName, iCounterValue )
3504 incrementCheck = incrementCheck and \
3505 main.Counters.counterCheck( iCounterName, iCounterValue )
Jon Hall5cf14d52015-07-16 12:15:19 -07003506 utilities.assert_equals( expect=main.TRUE,
Jon Halle1a3b752015-07-22 13:02:46 -07003507 actual=incrementCheck,
Jon Hall5cf14d52015-07-16 12:15:19 -07003508 onpass="Added counters are correct",
3509 onfail="Added counters are incorrect" )
Jon Halle1a3b752015-07-22 13:02:46 -07003510
Jon Hall5cf14d52015-07-16 12:15:19 -07003511 # DISTRIBUTED SETS
3512 main.step( "Distributed Set get" )
3513 size = len( onosSet )
3514 getResponses = []
3515 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003516 for i in range( main.numCtrls ):
3517 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003518 name="setTestGet-" + str( i ),
3519 args=[ onosSetName ] )
3520 threads.append( t )
3521 t.start()
3522 for t in threads:
3523 t.join()
3524 getResponses.append( t.result )
3525
3526 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003527 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003528 if isinstance( getResponses[ i ], list):
3529 current = set( getResponses[ i ] )
3530 if len( current ) == len( getResponses[ i ] ):
3531 # no repeats
3532 if onosSet != current:
3533 main.log.error( "ONOS" + str( i + 1 ) +
3534 " has incorrect view" +
3535 " of set " + onosSetName + ":\n" +
3536 str( getResponses[ i ] ) )
3537 main.log.debug( "Expected: " + str( onosSet ) )
3538 main.log.debug( "Actual: " + str( current ) )
3539 getResults = main.FALSE
3540 else:
3541 # error, set is not a set
3542 main.log.error( "ONOS" + str( i + 1 ) +
3543 " has repeat elements in" +
3544 " set " + onosSetName + ":\n" +
3545 str( getResponses[ i ] ) )
3546 getResults = main.FALSE
3547 elif getResponses[ i ] == main.ERROR:
3548 getResults = main.FALSE
3549 utilities.assert_equals( expect=main.TRUE,
3550 actual=getResults,
3551 onpass="Set elements are correct",
3552 onfail="Set elements are incorrect" )
3553
3554 main.step( "Distributed Set size" )
3555 sizeResponses = []
3556 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003557 for i in range( main.numCtrls ):
3558 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003559 name="setTestSize-" + str( i ),
3560 args=[ onosSetName ] )
3561 threads.append( t )
3562 t.start()
3563 for t in threads:
3564 t.join()
3565 sizeResponses.append( t.result )
3566
3567 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003568 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003569 if size != sizeResponses[ i ]:
3570 sizeResults = main.FALSE
3571 main.log.error( "ONOS" + str( i + 1 ) +
3572 " expected a size of " + str( size ) +
3573 " for set " + onosSetName +
3574 " but got " + str( sizeResponses[ i ] ) )
3575 utilities.assert_equals( expect=main.TRUE,
3576 actual=sizeResults,
3577 onpass="Set sizes are correct",
3578 onfail="Set sizes are incorrect" )
3579
3580 main.step( "Distributed Set add()" )
3581 onosSet.add( addValue )
3582 addResponses = []
3583 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003584 for i in range( main.numCtrls ):
3585 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall5cf14d52015-07-16 12:15:19 -07003586 name="setTestAdd-" + str( i ),
3587 args=[ onosSetName, addValue ] )
3588 threads.append( t )
3589 t.start()
3590 for t in threads:
3591 t.join()
3592 addResponses.append( t.result )
3593
3594 # main.TRUE = successfully changed the set
3595 # main.FALSE = action resulted in no change in set
3596 # main.ERROR - Some error in executing the function
3597 addResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003598 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003599 if addResponses[ i ] == main.TRUE:
3600 # All is well
3601 pass
3602 elif addResponses[ i ] == main.FALSE:
3603 # Already in set, probably fine
3604 pass
3605 elif addResponses[ i ] == main.ERROR:
3606 # Error in execution
3607 addResults = main.FALSE
3608 else:
3609 # unexpected result
3610 addResults = main.FALSE
3611 if addResults != main.TRUE:
3612 main.log.error( "Error executing set add" )
3613
3614 # Check if set is still correct
3615 size = len( onosSet )
3616 getResponses = []
3617 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003618 for i in range( main.numCtrls ):
3619 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003620 name="setTestGet-" + str( i ),
3621 args=[ onosSetName ] )
3622 threads.append( t )
3623 t.start()
3624 for t in threads:
3625 t.join()
3626 getResponses.append( t.result )
3627 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003628 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003629 if isinstance( getResponses[ i ], list):
3630 current = set( getResponses[ i ] )
3631 if len( current ) == len( getResponses[ i ] ):
3632 # no repeats
3633 if onosSet != current:
3634 main.log.error( "ONOS" + str( i + 1 ) +
3635 " has incorrect view" +
3636 " of set " + onosSetName + ":\n" +
3637 str( getResponses[ i ] ) )
3638 main.log.debug( "Expected: " + str( onosSet ) )
3639 main.log.debug( "Actual: " + str( current ) )
3640 getResults = main.FALSE
3641 else:
3642 # error, set is not a set
3643 main.log.error( "ONOS" + str( i + 1 ) +
3644 " has repeat elements in" +
3645 " set " + onosSetName + ":\n" +
3646 str( getResponses[ i ] ) )
3647 getResults = main.FALSE
3648 elif getResponses[ i ] == main.ERROR:
3649 getResults = main.FALSE
3650 sizeResponses = []
3651 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003652 for i in range( main.numCtrls ):
3653 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003654 name="setTestSize-" + str( i ),
3655 args=[ onosSetName ] )
3656 threads.append( t )
3657 t.start()
3658 for t in threads:
3659 t.join()
3660 sizeResponses.append( t.result )
3661 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003662 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003663 if size != sizeResponses[ i ]:
3664 sizeResults = main.FALSE
3665 main.log.error( "ONOS" + str( i + 1 ) +
3666 " expected a size of " + str( size ) +
3667 " for set " + onosSetName +
3668 " but got " + str( sizeResponses[ i ] ) )
3669 addResults = addResults and getResults and sizeResults
3670 utilities.assert_equals( expect=main.TRUE,
3671 actual=addResults,
3672 onpass="Set add correct",
3673 onfail="Set add was incorrect" )
3674
3675 main.step( "Distributed Set addAll()" )
3676 onosSet.update( addAllValue.split() )
3677 addResponses = []
3678 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003679 for i in range( main.numCtrls ):
3680 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall5cf14d52015-07-16 12:15:19 -07003681 name="setTestAddAll-" + str( i ),
3682 args=[ onosSetName, addAllValue ] )
3683 threads.append( t )
3684 t.start()
3685 for t in threads:
3686 t.join()
3687 addResponses.append( t.result )
3688
3689 # main.TRUE = successfully changed the set
3690 # main.FALSE = action resulted in no change in set
3691 # main.ERROR - Some error in executing the function
3692 addAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003693 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003694 if addResponses[ i ] == main.TRUE:
3695 # All is well
3696 pass
3697 elif addResponses[ i ] == main.FALSE:
3698 # Already in set, probably fine
3699 pass
3700 elif addResponses[ i ] == main.ERROR:
3701 # Error in execution
3702 addAllResults = main.FALSE
3703 else:
3704 # unexpected result
3705 addAllResults = main.FALSE
3706 if addAllResults != main.TRUE:
3707 main.log.error( "Error executing set addAll" )
3708
3709 # Check if set is still correct
3710 size = len( onosSet )
3711 getResponses = []
3712 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003713 for i in range( main.numCtrls ):
3714 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003715 name="setTestGet-" + str( i ),
3716 args=[ onosSetName ] )
3717 threads.append( t )
3718 t.start()
3719 for t in threads:
3720 t.join()
3721 getResponses.append( t.result )
3722 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003723 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003724 if isinstance( getResponses[ i ], list):
3725 current = set( getResponses[ i ] )
3726 if len( current ) == len( getResponses[ i ] ):
3727 # no repeats
3728 if onosSet != current:
3729 main.log.error( "ONOS" + str( i + 1 ) +
3730 " has incorrect view" +
3731 " of set " + onosSetName + ":\n" +
3732 str( getResponses[ i ] ) )
3733 main.log.debug( "Expected: " + str( onosSet ) )
3734 main.log.debug( "Actual: " + str( current ) )
3735 getResults = main.FALSE
3736 else:
3737 # error, set is not a set
3738 main.log.error( "ONOS" + str( i + 1 ) +
3739 " has repeat elements in" +
3740 " set " + onosSetName + ":\n" +
3741 str( getResponses[ i ] ) )
3742 getResults = main.FALSE
3743 elif getResponses[ i ] == main.ERROR:
3744 getResults = main.FALSE
3745 sizeResponses = []
3746 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003747 for i in range( main.numCtrls ):
3748 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003749 name="setTestSize-" + str( i ),
3750 args=[ onosSetName ] )
3751 threads.append( t )
3752 t.start()
3753 for t in threads:
3754 t.join()
3755 sizeResponses.append( t.result )
3756 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003757 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003758 if size != sizeResponses[ i ]:
3759 sizeResults = main.FALSE
3760 main.log.error( "ONOS" + str( i + 1 ) +
3761 " expected a size of " + str( size ) +
3762 " for set " + onosSetName +
3763 " but got " + str( sizeResponses[ i ] ) )
3764 addAllResults = addAllResults and getResults and sizeResults
3765 utilities.assert_equals( expect=main.TRUE,
3766 actual=addAllResults,
3767 onpass="Set addAll correct",
3768 onfail="Set addAll was incorrect" )
3769
3770 main.step( "Distributed Set contains()" )
3771 containsResponses = []
3772 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003773 for i in range( main.numCtrls ):
3774 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003775 name="setContains-" + str( i ),
3776 args=[ onosSetName ],
3777 kwargs={ "values": addValue } )
3778 threads.append( t )
3779 t.start()
3780 for t in threads:
3781 t.join()
3782 # NOTE: This is the tuple
3783 containsResponses.append( t.result )
3784
3785 containsResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003786 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003787 if containsResponses[ i ] == main.ERROR:
3788 containsResults = main.FALSE
3789 else:
3790 containsResults = containsResults and\
3791 containsResponses[ i ][ 1 ]
3792 utilities.assert_equals( expect=main.TRUE,
3793 actual=containsResults,
3794 onpass="Set contains is functional",
3795 onfail="Set contains failed" )
3796
3797 main.step( "Distributed Set containsAll()" )
3798 containsAllResponses = []
3799 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003800 for i in range( main.numCtrls ):
3801 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003802 name="setContainsAll-" + str( i ),
3803 args=[ onosSetName ],
3804 kwargs={ "values": addAllValue } )
3805 threads.append( t )
3806 t.start()
3807 for t in threads:
3808 t.join()
3809 # NOTE: This is the tuple
3810 containsAllResponses.append( t.result )
3811
3812 containsAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003813 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003814 if containsResponses[ i ] == main.ERROR:
3815 containsResults = main.FALSE
3816 else:
3817 containsResults = containsResults and\
3818 containsResponses[ i ][ 1 ]
3819 utilities.assert_equals( expect=main.TRUE,
3820 actual=containsAllResults,
3821 onpass="Set containsAll is functional",
3822 onfail="Set containsAll failed" )
3823
3824 main.step( "Distributed Set remove()" )
3825 onosSet.remove( addValue )
3826 removeResponses = []
3827 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003828 for i in range( main.numCtrls ):
3829 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall5cf14d52015-07-16 12:15:19 -07003830 name="setTestRemove-" + str( i ),
3831 args=[ onosSetName, addValue ] )
3832 threads.append( t )
3833 t.start()
3834 for t in threads:
3835 t.join()
3836 removeResponses.append( t.result )
3837
3838 # main.TRUE = successfully changed the set
3839 # main.FALSE = action resulted in no change in set
3840 # main.ERROR - Some error in executing the function
3841 removeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003842 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003843 if removeResponses[ i ] == main.TRUE:
3844 # All is well
3845 pass
3846 elif removeResponses[ i ] == main.FALSE:
3847 # not in set, probably fine
3848 pass
3849 elif removeResponses[ i ] == main.ERROR:
3850 # Error in execution
3851 removeResults = main.FALSE
3852 else:
3853 # unexpected result
3854 removeResults = main.FALSE
3855 if removeResults != main.TRUE:
3856 main.log.error( "Error executing set remove" )
3857
3858 # Check if set is still correct
3859 size = len( onosSet )
3860 getResponses = []
3861 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003862 for i in range( main.numCtrls ):
3863 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003864 name="setTestGet-" + str( i ),
3865 args=[ onosSetName ] )
3866 threads.append( t )
3867 t.start()
3868 for t in threads:
3869 t.join()
3870 getResponses.append( t.result )
3871 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003872 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003873 if isinstance( getResponses[ i ], list):
3874 current = set( getResponses[ i ] )
3875 if len( current ) == len( getResponses[ i ] ):
3876 # no repeats
3877 if onosSet != current:
3878 main.log.error( "ONOS" + str( i + 1 ) +
3879 " has incorrect view" +
3880 " of set " + onosSetName + ":\n" +
3881 str( getResponses[ i ] ) )
3882 main.log.debug( "Expected: " + str( onosSet ) )
3883 main.log.debug( "Actual: " + str( current ) )
3884 getResults = main.FALSE
3885 else:
3886 # error, set is not a set
3887 main.log.error( "ONOS" + str( i + 1 ) +
3888 " has repeat elements in" +
3889 " set " + onosSetName + ":\n" +
3890 str( getResponses[ i ] ) )
3891 getResults = main.FALSE
3892 elif getResponses[ i ] == main.ERROR:
3893 getResults = main.FALSE
3894 sizeResponses = []
3895 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003896 for i in range( main.numCtrls ):
3897 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003898 name="setTestSize-" + str( i ),
3899 args=[ onosSetName ] )
3900 threads.append( t )
3901 t.start()
3902 for t in threads:
3903 t.join()
3904 sizeResponses.append( t.result )
3905 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003906 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003907 if size != sizeResponses[ i ]:
3908 sizeResults = main.FALSE
3909 main.log.error( "ONOS" + str( i + 1 ) +
3910 " expected a size of " + str( size ) +
3911 " for set " + onosSetName +
3912 " but got " + str( sizeResponses[ i ] ) )
3913 removeResults = removeResults and getResults and sizeResults
3914 utilities.assert_equals( expect=main.TRUE,
3915 actual=removeResults,
3916 onpass="Set remove correct",
3917 onfail="Set remove was incorrect" )
3918
3919 main.step( "Distributed Set removeAll()" )
3920 onosSet.difference_update( addAllValue.split() )
3921 removeAllResponses = []
3922 threads = []
3923 try:
Jon Halle1a3b752015-07-22 13:02:46 -07003924 for i in range( main.numCtrls ):
3925 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall5cf14d52015-07-16 12:15:19 -07003926 name="setTestRemoveAll-" + str( i ),
3927 args=[ onosSetName, addAllValue ] )
3928 threads.append( t )
3929 t.start()
3930 for t in threads:
3931 t.join()
3932 removeAllResponses.append( t.result )
3933 except Exception, e:
3934 main.log.exception(e)
3935
3936 # main.TRUE = successfully changed the set
3937 # main.FALSE = action resulted in no change in set
3938 # main.ERROR - Some error in executing the function
3939 removeAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003940 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003941 if removeAllResponses[ i ] == main.TRUE:
3942 # All is well
3943 pass
3944 elif removeAllResponses[ i ] == main.FALSE:
3945 # not in set, probably fine
3946 pass
3947 elif removeAllResponses[ i ] == main.ERROR:
3948 # Error in execution
3949 removeAllResults = main.FALSE
3950 else:
3951 # unexpected result
3952 removeAllResults = main.FALSE
3953 if removeAllResults != main.TRUE:
3954 main.log.error( "Error executing set removeAll" )
3955
3956 # Check if set is still correct
3957 size = len( onosSet )
3958 getResponses = []
3959 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003960 for i in range( main.numCtrls ):
3961 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003962 name="setTestGet-" + str( i ),
3963 args=[ onosSetName ] )
3964 threads.append( t )
3965 t.start()
3966 for t in threads:
3967 t.join()
3968 getResponses.append( t.result )
3969 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003970 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003971 if isinstance( getResponses[ i ], list):
3972 current = set( getResponses[ i ] )
3973 if len( current ) == len( getResponses[ i ] ):
3974 # no repeats
3975 if onosSet != current:
3976 main.log.error( "ONOS" + str( i + 1 ) +
3977 " has incorrect view" +
3978 " of set " + onosSetName + ":\n" +
3979 str( getResponses[ i ] ) )
3980 main.log.debug( "Expected: " + str( onosSet ) )
3981 main.log.debug( "Actual: " + str( current ) )
3982 getResults = main.FALSE
3983 else:
3984 # error, set is not a set
3985 main.log.error( "ONOS" + str( i + 1 ) +
3986 " has repeat elements in" +
3987 " set " + onosSetName + ":\n" +
3988 str( getResponses[ i ] ) )
3989 getResults = main.FALSE
3990 elif getResponses[ i ] == main.ERROR:
3991 getResults = main.FALSE
3992 sizeResponses = []
3993 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003994 for i in range( main.numCtrls ):
3995 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003996 name="setTestSize-" + str( i ),
3997 args=[ onosSetName ] )
3998 threads.append( t )
3999 t.start()
4000 for t in threads:
4001 t.join()
4002 sizeResponses.append( t.result )
4003 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004004 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004005 if size != sizeResponses[ i ]:
4006 sizeResults = main.FALSE
4007 main.log.error( "ONOS" + str( i + 1 ) +
4008 " expected a size of " + str( size ) +
4009 " for set " + onosSetName +
4010 " but got " + str( sizeResponses[ i ] ) )
4011 removeAllResults = removeAllResults and getResults and sizeResults
4012 utilities.assert_equals( expect=main.TRUE,
4013 actual=removeAllResults,
4014 onpass="Set removeAll correct",
4015 onfail="Set removeAll was incorrect" )
4016
4017 main.step( "Distributed Set addAll()" )
4018 onosSet.update( addAllValue.split() )
4019 addResponses = []
4020 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004021 for i in range( main.numCtrls ):
4022 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall5cf14d52015-07-16 12:15:19 -07004023 name="setTestAddAll-" + str( i ),
4024 args=[ onosSetName, addAllValue ] )
4025 threads.append( t )
4026 t.start()
4027 for t in threads:
4028 t.join()
4029 addResponses.append( t.result )
4030
4031 # main.TRUE = successfully changed the set
4032 # main.FALSE = action resulted in no change in set
4033 # main.ERROR - Some error in executing the function
4034 addAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004035 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004036 if addResponses[ i ] == main.TRUE:
4037 # All is well
4038 pass
4039 elif addResponses[ i ] == main.FALSE:
4040 # Already in set, probably fine
4041 pass
4042 elif addResponses[ i ] == main.ERROR:
4043 # Error in execution
4044 addAllResults = main.FALSE
4045 else:
4046 # unexpected result
4047 addAllResults = main.FALSE
4048 if addAllResults != main.TRUE:
4049 main.log.error( "Error executing set addAll" )
4050
4051 # Check if set is still correct
4052 size = len( onosSet )
4053 getResponses = []
4054 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004055 for i in range( main.numCtrls ):
4056 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07004057 name="setTestGet-" + str( i ),
4058 args=[ onosSetName ] )
4059 threads.append( t )
4060 t.start()
4061 for t in threads:
4062 t.join()
4063 getResponses.append( t.result )
4064 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004065 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004066 if isinstance( getResponses[ i ], list):
4067 current = set( getResponses[ i ] )
4068 if len( current ) == len( getResponses[ i ] ):
4069 # no repeats
4070 if onosSet != current:
4071 main.log.error( "ONOS" + str( i + 1 ) +
4072 " has incorrect view" +
4073 " of set " + onosSetName + ":\n" +
4074 str( getResponses[ i ] ) )
4075 main.log.debug( "Expected: " + str( onosSet ) )
4076 main.log.debug( "Actual: " + str( current ) )
4077 getResults = main.FALSE
4078 else:
4079 # error, set is not a set
4080 main.log.error( "ONOS" + str( i + 1 ) +
4081 " has repeat elements in" +
4082 " set " + onosSetName + ":\n" +
4083 str( getResponses[ i ] ) )
4084 getResults = main.FALSE
4085 elif getResponses[ i ] == main.ERROR:
4086 getResults = main.FALSE
4087 sizeResponses = []
4088 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004089 for i in range( main.numCtrls ):
4090 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07004091 name="setTestSize-" + str( i ),
4092 args=[ onosSetName ] )
4093 threads.append( t )
4094 t.start()
4095 for t in threads:
4096 t.join()
4097 sizeResponses.append( t.result )
4098 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004099 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004100 if size != sizeResponses[ i ]:
4101 sizeResults = main.FALSE
4102 main.log.error( "ONOS" + str( i + 1 ) +
4103 " expected a size of " + str( size ) +
4104 " for set " + onosSetName +
4105 " but got " + str( sizeResponses[ i ] ) )
4106 addAllResults = addAllResults and getResults and sizeResults
4107 utilities.assert_equals( expect=main.TRUE,
4108 actual=addAllResults,
4109 onpass="Set addAll correct",
4110 onfail="Set addAll was incorrect" )
4111
4112 main.step( "Distributed Set clear()" )
4113 onosSet.clear()
4114 clearResponses = []
4115 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004116 for i in range( main.numCtrls ):
4117 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall5cf14d52015-07-16 12:15:19 -07004118 name="setTestClear-" + str( i ),
4119 args=[ onosSetName, " "], # Values doesn't matter
4120 kwargs={ "clear": True } )
4121 threads.append( t )
4122 t.start()
4123 for t in threads:
4124 t.join()
4125 clearResponses.append( t.result )
4126
4127 # main.TRUE = successfully changed the set
4128 # main.FALSE = action resulted in no change in set
4129 # main.ERROR - Some error in executing the function
4130 clearResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004131 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004132 if clearResponses[ i ] == main.TRUE:
4133 # All is well
4134 pass
4135 elif clearResponses[ i ] == main.FALSE:
4136 # Nothing set, probably fine
4137 pass
4138 elif clearResponses[ i ] == main.ERROR:
4139 # Error in execution
4140 clearResults = main.FALSE
4141 else:
4142 # unexpected result
4143 clearResults = main.FALSE
4144 if clearResults != main.TRUE:
4145 main.log.error( "Error executing set clear" )
4146
4147 # Check if set is still correct
4148 size = len( onosSet )
4149 getResponses = []
4150 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004151 for i in range( main.numCtrls ):
4152 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07004153 name="setTestGet-" + str( i ),
4154 args=[ onosSetName ] )
4155 threads.append( t )
4156 t.start()
4157 for t in threads:
4158 t.join()
4159 getResponses.append( t.result )
4160 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004161 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004162 if isinstance( getResponses[ i ], list):
4163 current = set( getResponses[ i ] )
4164 if len( current ) == len( getResponses[ i ] ):
4165 # no repeats
4166 if onosSet != current:
4167 main.log.error( "ONOS" + str( i + 1 ) +
4168 " has incorrect view" +
4169 " of set " + onosSetName + ":\n" +
4170 str( getResponses[ i ] ) )
4171 main.log.debug( "Expected: " + str( onosSet ) )
4172 main.log.debug( "Actual: " + str( current ) )
4173 getResults = main.FALSE
4174 else:
4175 # error, set is not a set
4176 main.log.error( "ONOS" + str( i + 1 ) +
4177 " has repeat elements in" +
4178 " set " + onosSetName + ":\n" +
4179 str( getResponses[ i ] ) )
4180 getResults = main.FALSE
4181 elif getResponses[ i ] == main.ERROR:
4182 getResults = main.FALSE
4183 sizeResponses = []
4184 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004185 for i in range( main.numCtrls ):
4186 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07004187 name="setTestSize-" + str( i ),
4188 args=[ onosSetName ] )
4189 threads.append( t )
4190 t.start()
4191 for t in threads:
4192 t.join()
4193 sizeResponses.append( t.result )
4194 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004195 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004196 if size != sizeResponses[ i ]:
4197 sizeResults = main.FALSE
4198 main.log.error( "ONOS" + str( i + 1 ) +
4199 " expected a size of " + str( size ) +
4200 " for set " + onosSetName +
4201 " but got " + str( sizeResponses[ i ] ) )
4202 clearResults = clearResults and getResults and sizeResults
4203 utilities.assert_equals( expect=main.TRUE,
4204 actual=clearResults,
4205 onpass="Set clear correct",
4206 onfail="Set clear was incorrect" )
4207
4208 main.step( "Distributed Set addAll()" )
4209 onosSet.update( addAllValue.split() )
4210 addResponses = []
4211 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004212 for i in range( main.numCtrls ):
4213 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall5cf14d52015-07-16 12:15:19 -07004214 name="setTestAddAll-" + str( i ),
4215 args=[ onosSetName, addAllValue ] )
4216 threads.append( t )
4217 t.start()
4218 for t in threads:
4219 t.join()
4220 addResponses.append( t.result )
4221
4222 # main.TRUE = successfully changed the set
4223 # main.FALSE = action resulted in no change in set
4224 # main.ERROR - Some error in executing the function
4225 addAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004226 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004227 if addResponses[ i ] == main.TRUE:
4228 # All is well
4229 pass
4230 elif addResponses[ i ] == main.FALSE:
4231 # Already in set, probably fine
4232 pass
4233 elif addResponses[ i ] == main.ERROR:
4234 # Error in execution
4235 addAllResults = main.FALSE
4236 else:
4237 # unexpected result
4238 addAllResults = main.FALSE
4239 if addAllResults != main.TRUE:
4240 main.log.error( "Error executing set addAll" )
4241
4242 # Check if set is still correct
4243 size = len( onosSet )
4244 getResponses = []
4245 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004246 for i in range( main.numCtrls ):
4247 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07004248 name="setTestGet-" + str( i ),
4249 args=[ onosSetName ] )
4250 threads.append( t )
4251 t.start()
4252 for t in threads:
4253 t.join()
4254 getResponses.append( t.result )
4255 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004256 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004257 if isinstance( getResponses[ i ], list):
4258 current = set( getResponses[ i ] )
4259 if len( current ) == len( getResponses[ i ] ):
4260 # no repeats
4261 if onosSet != current:
4262 main.log.error( "ONOS" + str( i + 1 ) +
4263 " has incorrect view" +
4264 " of set " + onosSetName + ":\n" +
4265 str( getResponses[ i ] ) )
4266 main.log.debug( "Expected: " + str( onosSet ) )
4267 main.log.debug( "Actual: " + str( current ) )
4268 getResults = main.FALSE
4269 else:
4270 # error, set is not a set
4271 main.log.error( "ONOS" + str( i + 1 ) +
4272 " has repeat elements in" +
4273 " set " + onosSetName + ":\n" +
4274 str( getResponses[ i ] ) )
4275 getResults = main.FALSE
4276 elif getResponses[ i ] == main.ERROR:
4277 getResults = main.FALSE
4278 sizeResponses = []
4279 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004280 for i in range( main.numCtrls ):
4281 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07004282 name="setTestSize-" + str( i ),
4283 args=[ onosSetName ] )
4284 threads.append( t )
4285 t.start()
4286 for t in threads:
4287 t.join()
4288 sizeResponses.append( t.result )
4289 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004290 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004291 if size != sizeResponses[ i ]:
4292 sizeResults = main.FALSE
4293 main.log.error( "ONOS" + str( i + 1 ) +
4294 " expected a size of " + str( size ) +
4295 " for set " + onosSetName +
4296 " but got " + str( sizeResponses[ i ] ) )
4297 addAllResults = addAllResults and getResults and sizeResults
4298 utilities.assert_equals( expect=main.TRUE,
4299 actual=addAllResults,
4300 onpass="Set addAll correct",
4301 onfail="Set addAll was incorrect" )
4302
4303 main.step( "Distributed Set retain()" )
4304 onosSet.intersection_update( retainValue.split() )
4305 retainResponses = []
4306 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004307 for i in range( main.numCtrls ):
4308 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall5cf14d52015-07-16 12:15:19 -07004309 name="setTestRetain-" + str( i ),
4310 args=[ onosSetName, retainValue ],
4311 kwargs={ "retain": True } )
4312 threads.append( t )
4313 t.start()
4314 for t in threads:
4315 t.join()
4316 retainResponses.append( t.result )
4317
4318 # main.TRUE = successfully changed the set
4319 # main.FALSE = action resulted in no change in set
4320 # main.ERROR - Some error in executing the function
4321 retainResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004322 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004323 if retainResponses[ i ] == main.TRUE:
4324 # All is well
4325 pass
4326 elif retainResponses[ i ] == main.FALSE:
4327 # Already in set, probably fine
4328 pass
4329 elif retainResponses[ i ] == main.ERROR:
4330 # Error in execution
4331 retainResults = main.FALSE
4332 else:
4333 # unexpected result
4334 retainResults = main.FALSE
4335 if retainResults != main.TRUE:
4336 main.log.error( "Error executing set retain" )
4337
4338 # Check if set is still correct
4339 size = len( onosSet )
4340 getResponses = []
4341 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004342 for i in range( main.numCtrls ):
4343 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07004344 name="setTestGet-" + str( i ),
4345 args=[ onosSetName ] )
4346 threads.append( t )
4347 t.start()
4348 for t in threads:
4349 t.join()
4350 getResponses.append( t.result )
4351 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004352 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004353 if isinstance( getResponses[ i ], list):
4354 current = set( getResponses[ i ] )
4355 if len( current ) == len( getResponses[ i ] ):
4356 # no repeats
4357 if onosSet != current:
4358 main.log.error( "ONOS" + str( i + 1 ) +
4359 " has incorrect view" +
4360 " of set " + onosSetName + ":\n" +
4361 str( getResponses[ i ] ) )
4362 main.log.debug( "Expected: " + str( onosSet ) )
4363 main.log.debug( "Actual: " + str( current ) )
4364 getResults = main.FALSE
4365 else:
4366 # error, set is not a set
4367 main.log.error( "ONOS" + str( i + 1 ) +
4368 " has repeat elements in" +
4369 " set " + onosSetName + ":\n" +
4370 str( getResponses[ i ] ) )
4371 getResults = main.FALSE
4372 elif getResponses[ i ] == main.ERROR:
4373 getResults = main.FALSE
4374 sizeResponses = []
4375 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004376 for i in range( main.numCtrls ):
4377 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07004378 name="setTestSize-" + str( i ),
4379 args=[ onosSetName ] )
4380 threads.append( t )
4381 t.start()
4382 for t in threads:
4383 t.join()
4384 sizeResponses.append( t.result )
4385 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004386 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004387 if size != sizeResponses[ i ]:
4388 sizeResults = main.FALSE
4389 main.log.error( "ONOS" + str( i + 1 ) +
4390 " expected a size of " +
4391 str( size ) + " for set " + onosSetName +
4392 " but got " + str( sizeResponses[ i ] ) )
4393 retainResults = retainResults and getResults and sizeResults
4394 utilities.assert_equals( expect=main.TRUE,
4395 actual=retainResults,
4396 onpass="Set retain correct",
4397 onfail="Set retain was incorrect" )
4398
Jon Hall2a5002c2015-08-21 16:49:11 -07004399 # Transactional maps
4400 main.step( "Partitioned Transactional maps put" )
4401 tMapValue = "Testing"
4402 numKeys = 100
4403 putResult = True
4404 putResponses = main.CLIs[ 0 ].transactionalMapPut( numKeys, tMapValue )
4405 if len( putResponses ) == 100:
4406 for i in putResponses:
4407 if putResponses[ i ][ 'value' ] != tMapValue:
4408 putResult = False
4409 else:
4410 putResult = False
4411 if not putResult:
4412 main.log.debug( "Put response values: " + str( putResponses ) )
4413 utilities.assert_equals( expect=True,
4414 actual=putResult,
4415 onpass="Partitioned Transactional Map put successful",
4416 onfail="Partitioned Transactional Map put values are incorrect" )
4417
4418 main.step( "Partitioned Transactional maps get" )
4419 getCheck = True
4420 for n in range( 1, numKeys + 1 ):
4421 getResponses = []
4422 threads = []
4423 valueCheck = True
4424 for i in range( main.numCtrls ):
4425 t = main.Thread( target=main.CLIs[i].transactionalMapGet,
4426 name="TMap-get-" + str( i ),
4427 args=[ "Key" + str ( n ) ] )
4428 threads.append( t )
4429 t.start()
4430 for t in threads:
4431 t.join()
4432 getResponses.append( t.result )
4433 for node in getResponses:
4434 if node != tMapValue:
4435 valueCheck = False
4436 if not valueCheck:
4437 main.log.warn( "Values for key 'Key" + str( n ) + "' do not match:" )
4438 main.log.warn( getResponses )
4439 getCheck = getCheck and valueCheck
4440 utilities.assert_equals( expect=True,
4441 actual=getCheck,
4442 onpass="Partitioned Transactional Map get values were correct",
4443 onfail="Partitioned Transactional Map values incorrect" )
4444
4445 main.step( "In-memory Transactional maps put" )
4446 tMapValue = "Testing"
4447 numKeys = 100
4448 putResult = True
4449 putResponses = main.CLIs[ 0 ].transactionalMapPut( numKeys, tMapValue, inMemory=True )
4450 if len( putResponses ) == 100:
4451 for i in putResponses:
4452 if putResponses[ i ][ 'value' ] != tMapValue:
4453 putResult = False
4454 else:
4455 putResult = False
4456 if not putResult:
4457 main.log.debug( "Put response values: " + str( putResponses ) )
4458 utilities.assert_equals( expect=True,
4459 actual=putResult,
4460 onpass="In-Memory Transactional Map put successful",
4461 onfail="In-Memory Transactional Map put values are incorrect" )
4462
4463 main.step( "In-Memory Transactional maps get" )
4464 getCheck = True
4465 for n in range( 1, numKeys + 1 ):
4466 getResponses = []
4467 threads = []
4468 valueCheck = True
4469 for i in range( main.numCtrls ):
4470 t = main.Thread( target=main.CLIs[i].transactionalMapGet,
4471 name="TMap-get-" + str( i ),
4472 args=[ "Key" + str ( n ) ],
4473 kwargs={ "inMemory": True } )
4474 threads.append( t )
4475 t.start()
4476 for t in threads:
4477 t.join()
4478 getResponses.append( t.result )
4479 for node in getResponses:
4480 if node != tMapValue:
4481 valueCheck = False
4482 if not valueCheck:
4483 main.log.warn( "Values for key 'Key" + str( n ) + "' do not match:" )
4484 main.log.warn( getResponses )
4485 getCheck = getCheck and valueCheck
4486 utilities.assert_equals( expect=True,
4487 actual=getCheck,
4488 onpass="In-Memory Transactional Map get values were correct",
4489 onfail="In-Memory Transactional Map values incorrect" )