blob: 0c3ce16c14746e9ccdd85c314ca720766e4dde9b [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 Hallf3d16e72015-12-16 17:45:08 -080051 import time
Jon Hall5cf14d52015-07-16 12:15:19 -070052 main.log.info( "ONOS HA test: Restart all ONOS nodes - " +
53 "initialization" )
54 main.case( "Setting up test environment" )
Jon Hall783bbf92015-07-23 14:33:19 -070055 main.caseExplanation = "Setup the test environment including " +\
Jon Hall5cf14d52015-07-16 12:15:19 -070056 "installing ONOS, starting Mininet and ONOS" +\
57 "cli sessions."
58 # TODO: save all the timers and output them for plotting
59
60 # load some variables from the params file
61 PULLCODE = False
62 if main.params[ 'Git' ] == 'True':
63 PULLCODE = True
64 gitBranch = main.params[ 'branch' ]
65 cellName = main.params[ 'ENV' ][ 'cellName' ]
66
Jon Halle1a3b752015-07-22 13:02:46 -070067 main.numCtrls = int( main.params[ 'num_controllers' ] )
Jon Hall5cf14d52015-07-16 12:15:19 -070068 if main.ONOSbench.maxNodes:
Jon Halle1a3b752015-07-22 13:02:46 -070069 if main.ONOSbench.maxNodes < main.numCtrls:
70 main.numCtrls = int( main.ONOSbench.maxNodes )
71 # set global variables
Jon Hall5cf14d52015-07-16 12:15:19 -070072 global ONOS1Port
73 global ONOS2Port
74 global ONOS3Port
75 global ONOS4Port
76 global ONOS5Port
77 global ONOS6Port
78 global ONOS7Port
79 # These are for csv plotting in jenkins
80 global labels
81 global data
82 labels = []
83 data = []
84
85 # FIXME: just get controller port from params?
86 # TODO: do we really need all these?
87 ONOS1Port = main.params[ 'CTRL' ][ 'port1' ]
88 ONOS2Port = main.params[ 'CTRL' ][ 'port2' ]
89 ONOS3Port = main.params[ 'CTRL' ][ 'port3' ]
90 ONOS4Port = main.params[ 'CTRL' ][ 'port4' ]
91 ONOS5Port = main.params[ 'CTRL' ][ 'port5' ]
92 ONOS6Port = main.params[ 'CTRL' ][ 'port6' ]
93 ONOS7Port = main.params[ 'CTRL' ][ 'port7' ]
94
Jon Halle1a3b752015-07-22 13:02:46 -070095 try:
96 fileName = "Counters"
97 path = main.params[ 'imports' ][ 'path' ]
98 main.Counters = imp.load_source( fileName,
99 path + fileName + ".py" )
100 except Exception as e:
101 main.log.exception( e )
102 main.cleanup()
103 main.exit()
104
105 main.CLIs = []
106 main.nodes = []
Jon Hall5cf14d52015-07-16 12:15:19 -0700107 ipList = []
Jon Halle1a3b752015-07-22 13:02:46 -0700108 for i in range( 1, main.numCtrls + 1 ):
109 try:
110 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
111 main.nodes.append( getattr( main, 'ONOS' + str( i ) ) )
112 ipList.append( main.nodes[ -1 ].ip_address )
113 except AttributeError:
114 break
Jon Hall5cf14d52015-07-16 12:15:19 -0700115
116 main.step( "Create cell file" )
117 cellAppString = main.params[ 'ENV' ][ 'appString' ]
118 main.ONOSbench.createCellFile( main.ONOSbench.ip_address, cellName,
119 main.Mininet1.ip_address,
120 cellAppString, ipList )
121 main.step( "Applying cell variable to environment" )
122 cellResult = main.ONOSbench.setCell( cellName )
123 verifyResult = main.ONOSbench.verifyCell()
124
125 # FIXME:this is short term fix
126 main.log.info( "Removing raft logs" )
127 main.ONOSbench.onosRemoveRaftLogs()
128
129 main.log.info( "Uninstalling ONOS" )
Jon Halle1a3b752015-07-22 13:02:46 -0700130 for node in main.nodes:
Jon Hall5cf14d52015-07-16 12:15:19 -0700131 main.ONOSbench.onosUninstall( node.ip_address )
132
133 # Make sure ONOS is DEAD
134 main.log.info( "Killing any ONOS processes" )
135 killResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -0700136 for node in main.nodes:
Jon Hall5cf14d52015-07-16 12:15:19 -0700137 killed = main.ONOSbench.onosKill( node.ip_address )
138 killResults = killResults and killed
139
140 cleanInstallResult = main.TRUE
141 gitPullResult = main.TRUE
142
143 main.step( "Starting Mininet" )
144 # scp topo file to mininet
145 # TODO: move to params?
146 topoName = "obelisk.py"
147 filePath = main.ONOSbench.home + "/tools/test/topos/"
kelvin-onlabd9e23de2015-08-06 10:34:44 -0700148 main.ONOSbench.scp( main.Mininet1,
149 filePath + topoName,
150 main.Mininet1.home,
151 direction="to" )
Jon Hall5cf14d52015-07-16 12:15:19 -0700152 mnResult = main.Mininet1.startNet( )
153 utilities.assert_equals( expect=main.TRUE, actual=mnResult,
154 onpass="Mininet Started",
155 onfail="Error starting Mininet" )
156
157 main.step( "Git checkout and pull " + gitBranch )
158 if PULLCODE:
159 main.ONOSbench.gitCheckout( gitBranch )
160 gitPullResult = main.ONOSbench.gitPull()
161 # values of 1 or 3 are good
162 utilities.assert_lesser( expect=0, actual=gitPullResult,
163 onpass="Git pull successful",
164 onfail="Git pull failed" )
165 main.ONOSbench.getVersion( report=True )
166
167 main.step( "Using mvn clean install" )
168 cleanInstallResult = main.TRUE
169 if PULLCODE and gitPullResult == main.TRUE:
170 cleanInstallResult = main.ONOSbench.cleanInstall()
171 else:
172 main.log.warn( "Did not pull new code so skipping mvn " +
173 "clean install" )
174 utilities.assert_equals( expect=main.TRUE,
175 actual=cleanInstallResult,
176 onpass="MCI successful",
177 onfail="MCI failed" )
178 # GRAPHS
179 # NOTE: important params here:
180 # job = name of Jenkins job
181 # Plot Name = Plot-HA, only can be used if multiple plots
182 # index = The number of the graph under plot name
183 job = "HAclusterRestart"
184 plotName = "Plot-HA"
185 graphs = '<ac:structured-macro ac:name="html">\n'
186 graphs += '<ac:plain-text-body><![CDATA[\n'
187 graphs += '<iframe src="https://onos-jenkins.onlab.us/job/' + job +\
188 '/plot/' + plotName + '/getPlot?index=0' +\
189 '&width=500&height=300"' +\
190 'noborder="0" width="500" height="300" scrolling="yes" ' +\
191 'seamless="seamless"></iframe>\n'
192 graphs += ']]></ac:plain-text-body>\n'
193 graphs += '</ac:structured-macro>\n'
194 main.log.wiki(graphs)
195
196 main.step( "Creating ONOS package" )
197 packageResult = main.ONOSbench.onosPackage()
198 utilities.assert_equals( expect=main.TRUE, actual=packageResult,
199 onpass="ONOS package successful",
200 onfail="ONOS package failed" )
201
202 main.step( "Installing ONOS package" )
203 onosInstallResult = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -0700204 for node in main.nodes:
Jon Hall5cf14d52015-07-16 12:15:19 -0700205 tmpResult = main.ONOSbench.onosInstall( options="-f",
206 node=node.ip_address )
207 onosInstallResult = onosInstallResult and tmpResult
208 utilities.assert_equals( expect=main.TRUE, actual=onosInstallResult,
209 onpass="ONOS install successful",
210 onfail="ONOS install failed" )
211
212 main.step( "Checking if ONOS is up yet" )
213 for i in range( 2 ):
214 onosIsupResult = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -0700215 for node in main.nodes:
Jon Hall5cf14d52015-07-16 12:15:19 -0700216 started = main.ONOSbench.isup( node.ip_address )
217 if not started:
218 main.log.error( node.name + " didn't start!" )
219 main.ONOSbench.onosStop( node.ip_address )
220 main.ONOSbench.onosStart( node.ip_address )
221 onosIsupResult = onosIsupResult and started
222 if onosIsupResult == main.TRUE:
223 break
224 utilities.assert_equals( expect=main.TRUE, actual=onosIsupResult,
225 onpass="ONOS startup successful",
226 onfail="ONOS startup failed" )
227
228 main.log.step( "Starting ONOS CLI sessions" )
229 cliResults = main.TRUE
230 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -0700231 for i in range( main.numCtrls ):
232 t = main.Thread( target=main.CLIs[i].startOnosCli,
Jon Hall5cf14d52015-07-16 12:15:19 -0700233 name="startOnosCli-" + str( i ),
Jon Halle1a3b752015-07-22 13:02:46 -0700234 args=[main.nodes[i].ip_address] )
Jon Hall5cf14d52015-07-16 12:15:19 -0700235 threads.append( t )
236 t.start()
237
238 for t in threads:
239 t.join()
240 cliResults = cliResults and t.result
241 utilities.assert_equals( expect=main.TRUE, actual=cliResults,
242 onpass="ONOS cli startup successful",
243 onfail="ONOS cli startup failed" )
244
245 if main.params[ 'tcpdump' ].lower() == "true":
246 main.step( "Start Packet Capture MN" )
247 main.Mininet2.startTcpdump(
248 str( main.params[ 'MNtcpdump' ][ 'folder' ] ) + str( main.TEST )
249 + "-MN.pcap",
250 intf=main.params[ 'MNtcpdump' ][ 'intf' ],
251 port=main.params[ 'MNtcpdump' ][ 'port' ] )
252
253 main.step( "App Ids check" )
Jon Hallf3d16e72015-12-16 17:45:08 -0800254 time.sleep(60)
Jon Hall5cf14d52015-07-16 12:15:19 -0700255 appCheck = main.TRUE
256 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -0700257 for i in range( main.numCtrls ):
258 t = main.Thread( target=main.CLIs[i].appToIDCheck,
Jon Hall5cf14d52015-07-16 12:15:19 -0700259 name="appToIDCheck-" + str( i ),
260 args=[] )
261 threads.append( t )
262 t.start()
263
264 for t in threads:
265 t.join()
266 appCheck = appCheck and t.result
267 if appCheck != main.TRUE:
Jon Halle1a3b752015-07-22 13:02:46 -0700268 main.log.warn( main.CLIs[0].apps() )
269 main.log.warn( main.CLIs[0].appIDs() )
Jon Hall5cf14d52015-07-16 12:15:19 -0700270 utilities.assert_equals( expect=main.TRUE, actual=appCheck,
271 onpass="App Ids seem to be correct",
272 onfail="Something is wrong with app Ids" )
273
274 if cliResults == main.FALSE:
275 main.log.error( "Failed to start ONOS, stopping test" )
276 main.cleanup()
277 main.exit()
278
279 def CASE2( self, main ):
280 """
281 Assign devices to controllers
282 """
283 import re
Jon Halle1a3b752015-07-22 13:02:46 -0700284 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -0700285 assert main, "main not defined"
286 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -0700287 assert main.CLIs, "main.CLIs not defined"
288 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -0700289 assert ONOS1Port, "ONOS1Port not defined"
290 assert ONOS2Port, "ONOS2Port not defined"
291 assert ONOS3Port, "ONOS3Port not defined"
292 assert ONOS4Port, "ONOS4Port not defined"
293 assert ONOS5Port, "ONOS5Port not defined"
294 assert ONOS6Port, "ONOS6Port not defined"
295 assert ONOS7Port, "ONOS7Port not defined"
296
297 main.case( "Assigning devices to controllers" )
Jon Hall783bbf92015-07-23 14:33:19 -0700298 main.caseExplanation = "Assign switches to ONOS using 'ovs-vsctl' " +\
Jon Hall5cf14d52015-07-16 12:15:19 -0700299 "and check that an ONOS node becomes the " +\
300 "master of the device."
301 main.step( "Assign switches to controllers" )
302
303 ipList = []
Jon Halle1a3b752015-07-22 13:02:46 -0700304 for i in range( main.numCtrls ):
305 ipList.append( main.nodes[ i ].ip_address )
Jon Hall5cf14d52015-07-16 12:15:19 -0700306 swList = []
307 for i in range( 1, 29 ):
308 swList.append( "s" + str( i ) )
309 main.Mininet1.assignSwController( sw=swList, ip=ipList )
310
311 mastershipCheck = main.TRUE
312 for i in range( 1, 29 ):
313 response = main.Mininet1.getSwController( "s" + str( i ) )
314 try:
315 main.log.info( str( response ) )
316 except Exception:
317 main.log.info( repr( response ) )
Jon Halle1a3b752015-07-22 13:02:46 -0700318 for node in main.nodes:
Jon Hall5cf14d52015-07-16 12:15:19 -0700319 if re.search( "tcp:" + node.ip_address, response ):
320 mastershipCheck = mastershipCheck and main.TRUE
321 else:
322 main.log.error( "Error, node " + node.ip_address + " is " +
323 "not in the list of controllers s" +
324 str( i ) + " is connecting to." )
325 mastershipCheck = main.FALSE
326 utilities.assert_equals(
327 expect=main.TRUE,
328 actual=mastershipCheck,
329 onpass="Switch mastership assigned correctly",
330 onfail="Switches not assigned correctly to controllers" )
331
332 def CASE21( self, main ):
333 """
334 Assign mastership to controllers
335 """
Jon Hall5cf14d52015-07-16 12:15:19 -0700336 import time
Jon Halle1a3b752015-07-22 13:02:46 -0700337 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -0700338 assert main, "main not defined"
339 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -0700340 assert main.CLIs, "main.CLIs not defined"
341 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -0700342 assert ONOS1Port, "ONOS1Port not defined"
343 assert ONOS2Port, "ONOS2Port not defined"
344 assert ONOS3Port, "ONOS3Port not defined"
345 assert ONOS4Port, "ONOS4Port not defined"
346 assert ONOS5Port, "ONOS5Port not defined"
347 assert ONOS6Port, "ONOS6Port not defined"
348 assert ONOS7Port, "ONOS7Port not defined"
349
350 main.case( "Assigning Controller roles for switches" )
Jon Hall783bbf92015-07-23 14:33:19 -0700351 main.caseExplanation = "Check that ONOS is connected to each " +\
Jon Hall5cf14d52015-07-16 12:15:19 -0700352 "device. Then manually assign" +\
353 " mastership to specific ONOS nodes using" +\
354 " 'device-role'"
355 main.step( "Assign mastership of switches to specific controllers" )
356 # Manually assign mastership to the controller we want
357 roleCall = main.TRUE
358
359 ipList = [ ]
360 deviceList = []
361 try:
362 # Assign mastership to specific controllers. This assignment was
363 # determined for a 7 node cluser, but will work with any sized
364 # cluster
365 for i in range( 1, 29 ): # switches 1 through 28
366 # set up correct variables:
367 if i == 1:
368 c = 0
Jon Halle1a3b752015-07-22 13:02:46 -0700369 ip = main.nodes[ c ].ip_address # ONOS1
Jon Hall5cf14d52015-07-16 12:15:19 -0700370 deviceId = main.ONOScli1.getDevice( "1000" ).get( 'id' )
371 elif i == 2:
Jon Halle1a3b752015-07-22 13:02:46 -0700372 c = 1 % main.numCtrls
373 ip = main.nodes[ c ].ip_address # ONOS2
Jon Hall5cf14d52015-07-16 12:15:19 -0700374 deviceId = main.ONOScli1.getDevice( "2000" ).get( 'id' )
375 elif i == 3:
Jon Halle1a3b752015-07-22 13:02:46 -0700376 c = 1 % main.numCtrls
377 ip = main.nodes[ c ].ip_address # ONOS2
Jon Hall5cf14d52015-07-16 12:15:19 -0700378 deviceId = main.ONOScli1.getDevice( "3000" ).get( 'id' )
379 elif i == 4:
Jon Halle1a3b752015-07-22 13:02:46 -0700380 c = 3 % main.numCtrls
381 ip = main.nodes[ c ].ip_address # ONOS4
Jon Hall5cf14d52015-07-16 12:15:19 -0700382 deviceId = main.ONOScli1.getDevice( "3004" ).get( 'id' )
383 elif i == 5:
Jon Halle1a3b752015-07-22 13:02:46 -0700384 c = 2 % main.numCtrls
385 ip = main.nodes[ c ].ip_address # ONOS3
Jon Hall5cf14d52015-07-16 12:15:19 -0700386 deviceId = main.ONOScli1.getDevice( "5000" ).get( 'id' )
387 elif i == 6:
Jon Halle1a3b752015-07-22 13:02:46 -0700388 c = 2 % main.numCtrls
389 ip = main.nodes[ c ].ip_address # ONOS3
Jon Hall5cf14d52015-07-16 12:15:19 -0700390 deviceId = main.ONOScli1.getDevice( "6000" ).get( 'id' )
391 elif i == 7:
Jon Halle1a3b752015-07-22 13:02:46 -0700392 c = 5 % main.numCtrls
393 ip = main.nodes[ c ].ip_address # ONOS6
Jon Hall5cf14d52015-07-16 12:15:19 -0700394 deviceId = main.ONOScli1.getDevice( "6007" ).get( 'id' )
395 elif i >= 8 and i <= 17:
Jon Halle1a3b752015-07-22 13:02:46 -0700396 c = 4 % main.numCtrls
397 ip = main.nodes[ c ].ip_address # ONOS5
Jon Hall5cf14d52015-07-16 12:15:19 -0700398 dpid = '3' + str( i ).zfill( 3 )
399 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
400 elif i >= 18 and i <= 27:
Jon Halle1a3b752015-07-22 13:02:46 -0700401 c = 6 % main.numCtrls
402 ip = main.nodes[ c ].ip_address # ONOS7
Jon Hall5cf14d52015-07-16 12:15:19 -0700403 dpid = '6' + str( i ).zfill( 3 )
404 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
405 elif i == 28:
406 c = 0
Jon Halle1a3b752015-07-22 13:02:46 -0700407 ip = main.nodes[ c ].ip_address # ONOS1
Jon Hall5cf14d52015-07-16 12:15:19 -0700408 deviceId = main.ONOScli1.getDevice( "2800" ).get( 'id' )
409 else:
410 main.log.error( "You didn't write an else statement for " +
411 "switch s" + str( i ) )
412 roleCall = main.FALSE
413 # Assign switch
414 assert deviceId, "No device id for s" + str( i ) + " in ONOS"
415 # TODO: make this controller dynamic
416 roleCall = roleCall and main.ONOScli1.deviceRole( deviceId,
417 ip )
418 ipList.append( ip )
419 deviceList.append( deviceId )
420 except ( AttributeError, AssertionError ):
421 main.log.exception( "Something is wrong with ONOS device view" )
422 main.log.info( main.ONOScli1.devices() )
423 utilities.assert_equals(
424 expect=main.TRUE,
425 actual=roleCall,
426 onpass="Re-assigned switch mastership to designated controller",
427 onfail="Something wrong with deviceRole calls" )
428
429 main.step( "Check mastership was correctly assigned" )
430 roleCheck = main.TRUE
431 # NOTE: This is due to the fact that device mastership change is not
432 # atomic and is actually a multi step process
433 time.sleep( 5 )
434 for i in range( len( ipList ) ):
435 ip = ipList[i]
436 deviceId = deviceList[i]
437 # Check assignment
438 master = main.ONOScli1.getRole( deviceId ).get( 'master' )
439 if ip in master:
440 roleCheck = roleCheck and main.TRUE
441 else:
442 roleCheck = roleCheck and main.FALSE
443 main.log.error( "Error, controller " + ip + " is not" +
444 " master " + "of device " +
445 str( deviceId ) + ". Master is " +
446 repr( master ) + "." )
447 utilities.assert_equals(
448 expect=main.TRUE,
449 actual=roleCheck,
450 onpass="Switches were successfully reassigned to designated " +
451 "controller",
452 onfail="Switches were not successfully reassigned" )
453
454 def CASE3( self, main ):
455 """
456 Assign intents
457 """
458 import time
459 import json
Jon Halle1a3b752015-07-22 13:02:46 -0700460 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -0700461 assert main, "main not defined"
462 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -0700463 assert main.CLIs, "main.CLIs not defined"
464 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -0700465 try:
466 labels
467 except NameError:
468 main.log.error( "labels not defined, setting to []" )
469 labels = []
470 try:
471 data
472 except NameError:
473 main.log.error( "data not defined, setting to []" )
474 data = []
475 # NOTE: we must reinstall intents until we have a persistant intent
476 # datastore!
477 main.case( "Adding host Intents" )
Jon Hall783bbf92015-07-23 14:33:19 -0700478 main.caseExplanation = "Discover hosts by using pingall then " +\
Jon Hall5cf14d52015-07-16 12:15:19 -0700479 "assign predetermined host-to-host intents." +\
480 " After installation, check that the intent" +\
481 " is distributed to all nodes and the state" +\
482 " is INSTALLED"
483
484 # install onos-app-fwd
485 main.step( "Install reactive forwarding app" )
Jon Halle1a3b752015-07-22 13:02:46 -0700486 installResults = main.CLIs[0].activateApp( "org.onosproject.fwd" )
Jon Hall5cf14d52015-07-16 12:15:19 -0700487 utilities.assert_equals( expect=main.TRUE, actual=installResults,
488 onpass="Install fwd successful",
489 onfail="Install fwd failed" )
490
491 main.step( "Check app ids" )
492 appCheck = main.TRUE
493 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -0700494 for i in range( main.numCtrls ):
495 t = main.Thread( target=main.CLIs[i].appToIDCheck,
Jon Hall5cf14d52015-07-16 12:15:19 -0700496 name="appToIDCheck-" + str( i ),
497 args=[] )
498 threads.append( t )
499 t.start()
500
501 for t in threads:
502 t.join()
503 appCheck = appCheck and t.result
504 if appCheck != main.TRUE:
Jon Halle1a3b752015-07-22 13:02:46 -0700505 main.log.warn( main.CLIs[0].apps() )
506 main.log.warn( main.CLIs[0].appIDs() )
Jon Hall5cf14d52015-07-16 12:15:19 -0700507 utilities.assert_equals( expect=main.TRUE, actual=appCheck,
508 onpass="App Ids seem to be correct",
509 onfail="Something is wrong with app Ids" )
510
511 main.step( "Discovering Hosts( Via pingall for now )" )
512 # FIXME: Once we have a host discovery mechanism, use that instead
513 # REACTIVE FWD test
514 pingResult = main.FALSE
Jon Hall96091e62015-09-21 17:34:17 -0700515 passMsg = "Reactive Pingall test passed"
516 time1 = time.time()
517 pingResult = main.Mininet1.pingall()
518 time2 = time.time()
519 if not pingResult:
520 main.log.warn("First pingall failed. Trying again...")
Jon Hall5cf14d52015-07-16 12:15:19 -0700521 pingResult = main.Mininet1.pingall()
Jon Hall96091e62015-09-21 17:34:17 -0700522 passMsg += " on the second try"
523 utilities.assert_equals(
524 expect=main.TRUE,
525 actual=pingResult,
526 onpass= passMsg,
527 onfail="Reactive Pingall failed, " +
528 "one or more ping pairs failed" )
529 main.log.info( "Time for pingall: %2f seconds" %
530 ( time2 - time1 ) )
Jon Hall5cf14d52015-07-16 12:15:19 -0700531 # timeout for fwd flows
532 time.sleep( 11 )
533 # uninstall onos-app-fwd
534 main.step( "Uninstall reactive forwarding app" )
Jon Halle1a3b752015-07-22 13:02:46 -0700535 uninstallResult = main.CLIs[0].deactivateApp( "org.onosproject.fwd" )
Jon Hall5cf14d52015-07-16 12:15:19 -0700536 utilities.assert_equals( expect=main.TRUE, actual=uninstallResult,
537 onpass="Uninstall fwd successful",
538 onfail="Uninstall fwd failed" )
539
540 main.step( "Check app ids" )
541 threads = []
542 appCheck2 = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -0700543 for i in range( main.numCtrls ):
544 t = main.Thread( target=main.CLIs[i].appToIDCheck,
Jon Hall5cf14d52015-07-16 12:15:19 -0700545 name="appToIDCheck-" + str( i ),
546 args=[] )
547 threads.append( t )
548 t.start()
549
550 for t in threads:
551 t.join()
552 appCheck2 = appCheck2 and t.result
553 if appCheck2 != main.TRUE:
Jon Halle1a3b752015-07-22 13:02:46 -0700554 main.log.warn( main.CLIs[0].apps() )
555 main.log.warn( main.CLIs[0].appIDs() )
Jon Hall5cf14d52015-07-16 12:15:19 -0700556 utilities.assert_equals( expect=main.TRUE, actual=appCheck2,
557 onpass="App Ids seem to be correct",
558 onfail="Something is wrong with app Ids" )
559
560 main.step( "Add host intents via cli" )
561 intentIds = []
562 # TODO: move the host numbers to params
563 # Maybe look at all the paths we ping?
564 intentAddResult = True
565 hostResult = main.TRUE
566 for i in range( 8, 18 ):
567 main.log.info( "Adding host intent between h" + str( i ) +
568 " and h" + str( i + 10 ) )
569 host1 = "00:00:00:00:00:" + \
570 str( hex( i )[ 2: ] ).zfill( 2 ).upper()
571 host2 = "00:00:00:00:00:" + \
572 str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper()
573 # NOTE: getHost can return None
574 host1Dict = main.ONOScli1.getHost( host1 )
575 host2Dict = main.ONOScli1.getHost( host2 )
576 host1Id = None
577 host2Id = None
578 if host1Dict and host2Dict:
579 host1Id = host1Dict.get( 'id', None )
580 host2Id = host2Dict.get( 'id', None )
581 if host1Id and host2Id:
Jon Halle1a3b752015-07-22 13:02:46 -0700582 nodeNum = ( i % main.numCtrls )
583 tmpId = main.CLIs[ nodeNum ].addHostIntent( host1Id, host2Id )
Jon Hall5cf14d52015-07-16 12:15:19 -0700584 if tmpId:
585 main.log.info( "Added intent with id: " + tmpId )
586 intentIds.append( tmpId )
587 else:
588 main.log.error( "addHostIntent returned: " +
589 repr( tmpId ) )
590 else:
591 main.log.error( "Error, getHost() failed for h" + str( i ) +
592 " and/or h" + str( i + 10 ) )
Jon Halle1a3b752015-07-22 13:02:46 -0700593 hosts = main.CLIs[ 0 ].hosts()
Jon Hall5cf14d52015-07-16 12:15:19 -0700594 main.log.warn( "Hosts output: " )
595 try:
596 main.log.warn( json.dumps( json.loads( hosts ),
597 sort_keys=True,
598 indent=4,
599 separators=( ',', ': ' ) ) )
600 except ( ValueError, TypeError ):
601 main.log.warn( repr( hosts ) )
602 hostResult = main.FALSE
603 utilities.assert_equals( expect=main.TRUE, actual=hostResult,
604 onpass="Found a host id for each host",
605 onfail="Error looking up host ids" )
606
607 intentStart = time.time()
608 onosIds = main.ONOScli1.getAllIntentsId()
609 main.log.info( "Submitted intents: " + str( intentIds ) )
610 main.log.info( "Intents in ONOS: " + str( onosIds ) )
611 for intent in intentIds:
612 if intent in onosIds:
613 pass # intent submitted is in onos
614 else:
615 intentAddResult = False
616 if intentAddResult:
617 intentStop = time.time()
618 else:
619 intentStop = None
620 # Print the intent states
621 intents = main.ONOScli1.intents()
622 intentStates = []
623 installedCheck = True
624 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
625 count = 0
626 try:
627 for intent in json.loads( intents ):
628 state = intent.get( 'state', None )
629 if "INSTALLED" not in state:
630 installedCheck = False
631 intentId = intent.get( 'id', None )
632 intentStates.append( ( intentId, state ) )
633 except ( ValueError, TypeError ):
634 main.log.exception( "Error parsing intents" )
635 # add submitted intents not in the store
636 tmplist = [ i for i, s in intentStates ]
637 missingIntents = False
638 for i in intentIds:
639 if i not in tmplist:
640 intentStates.append( ( i, " - " ) )
641 missingIntents = True
642 intentStates.sort()
643 for i, s in intentStates:
644 count += 1
645 main.log.info( "%-6s%-15s%-15s" %
646 ( str( count ), str( i ), str( s ) ) )
647 leaders = main.ONOScli1.leaders()
648 try:
649 missing = False
650 if leaders:
651 parsedLeaders = json.loads( leaders )
652 main.log.warn( json.dumps( parsedLeaders,
653 sort_keys=True,
654 indent=4,
655 separators=( ',', ': ' ) ) )
656 # check for all intent partitions
657 topics = []
658 for i in range( 14 ):
659 topics.append( "intent-partition-" + str( i ) )
660 main.log.debug( topics )
661 ONOStopics = [ j['topic'] for j in parsedLeaders ]
662 for topic in topics:
663 if topic not in ONOStopics:
664 main.log.error( "Error: " + topic +
665 " not in leaders" )
666 missing = True
667 else:
668 main.log.error( "leaders() returned None" )
669 except ( ValueError, TypeError ):
670 main.log.exception( "Error parsing leaders" )
671 main.log.error( repr( leaders ) )
672 # Check all nodes
673 if missing:
Jon Halle1a3b752015-07-22 13:02:46 -0700674 for node in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -0700675 response = node.leaders( jsonFormat=False)
676 main.log.warn( str( node.name ) + " leaders output: \n" +
677 str( response ) )
678
679 partitions = main.ONOScli1.partitions()
680 try:
681 if partitions :
682 parsedPartitions = json.loads( partitions )
683 main.log.warn( json.dumps( parsedPartitions,
684 sort_keys=True,
685 indent=4,
686 separators=( ',', ': ' ) ) )
687 # TODO check for a leader in all paritions
688 # TODO check for consistency among nodes
689 else:
690 main.log.error( "partitions() returned None" )
691 except ( ValueError, TypeError ):
692 main.log.exception( "Error parsing partitions" )
693 main.log.error( repr( partitions ) )
694 pendingMap = main.ONOScli1.pendingMap()
695 try:
696 if pendingMap :
697 parsedPending = json.loads( pendingMap )
698 main.log.warn( json.dumps( parsedPending,
699 sort_keys=True,
700 indent=4,
701 separators=( ',', ': ' ) ) )
702 # TODO check something here?
703 else:
704 main.log.error( "pendingMap() returned None" )
705 except ( ValueError, TypeError ):
706 main.log.exception( "Error parsing pending map" )
707 main.log.error( repr( pendingMap ) )
708
709 intentAddResult = bool( intentAddResult and not missingIntents and
710 installedCheck )
711 if not intentAddResult:
712 main.log.error( "Error in pushing host intents to ONOS" )
713
714 main.step( "Intent Anti-Entropy dispersion" )
715 for i in range(100):
716 correct = True
717 main.log.info( "Submitted intents: " + str( sorted( intentIds ) ) )
Jon Halle1a3b752015-07-22 13:02:46 -0700718 for cli in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -0700719 onosIds = []
720 ids = cli.getAllIntentsId()
721 onosIds.append( ids )
722 main.log.debug( "Intents in " + cli.name + ": " +
723 str( sorted( onosIds ) ) )
724 if sorted( ids ) != sorted( intentIds ):
725 main.log.warn( "Set of intent IDs doesn't match" )
726 correct = False
727 break
728 else:
729 intents = json.loads( cli.intents() )
730 for intent in intents:
731 if intent[ 'state' ] != "INSTALLED":
732 main.log.warn( "Intent " + intent[ 'id' ] +
733 " is " + intent[ 'state' ] )
734 correct = False
735 break
736 if correct:
737 break
738 else:
739 time.sleep(1)
740 if not intentStop:
741 intentStop = time.time()
742 global gossipTime
743 gossipTime = intentStop - intentStart
744 main.log.info( "It took about " + str( gossipTime ) +
745 " seconds for all intents to appear in each node" )
746 append = False
747 title = "Gossip Intents"
748 count = 1
749 while append is False:
750 curTitle = title + str( count )
751 if curTitle not in labels:
752 labels.append( curTitle )
753 data.append( str( gossipTime ) )
754 append = True
755 else:
756 count += 1
Jon Hallb3ed8ed2015-10-28 16:43:55 -0700757 gossipPeriod = int( main.params['timers']['gossip'] )
758 maxGossipTime = gossipPeriod * len( main.nodes )
Jon Hall5cf14d52015-07-16 12:15:19 -0700759 utilities.assert_greater_equals(
Jon Hallb3ed8ed2015-10-28 16:43:55 -0700760 expect=maxGossipTime, actual=gossipTime,
Jon Hall5cf14d52015-07-16 12:15:19 -0700761 onpass="ECM anti-entropy for intents worked within " +
762 "expected time",
Jon Hallb3ed8ed2015-10-28 16:43:55 -0700763 onfail="Intent ECM anti-entropy took too long. " +
764 "Expected time:{}, Actual time:{}".format( maxGossipTime,
765 gossipTime ) )
766 if gossipTime <= maxGossipTime:
Jon Hall5cf14d52015-07-16 12:15:19 -0700767 intentAddResult = True
768
769 if not intentAddResult or "key" in pendingMap:
770 import time
771 installedCheck = True
772 main.log.info( "Sleeping 60 seconds to see if intents are found" )
773 time.sleep( 60 )
774 onosIds = main.ONOScli1.getAllIntentsId()
775 main.log.info( "Submitted intents: " + str( intentIds ) )
776 main.log.info( "Intents in ONOS: " + str( onosIds ) )
777 # Print the intent states
778 intents = main.ONOScli1.intents()
779 intentStates = []
780 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
781 count = 0
782 try:
783 for intent in json.loads( intents ):
784 # Iter through intents of a node
785 state = intent.get( 'state', None )
786 if "INSTALLED" not in state:
787 installedCheck = False
788 intentId = intent.get( 'id', None )
789 intentStates.append( ( intentId, state ) )
790 except ( ValueError, TypeError ):
791 main.log.exception( "Error parsing intents" )
792 # add submitted intents not in the store
793 tmplist = [ i for i, s in intentStates ]
794 for i in intentIds:
795 if i not in tmplist:
796 intentStates.append( ( i, " - " ) )
797 intentStates.sort()
798 for i, s in intentStates:
799 count += 1
800 main.log.info( "%-6s%-15s%-15s" %
801 ( str( count ), str( i ), str( s ) ) )
802 leaders = main.ONOScli1.leaders()
803 try:
804 missing = False
805 if leaders:
806 parsedLeaders = json.loads( leaders )
807 main.log.warn( json.dumps( parsedLeaders,
808 sort_keys=True,
809 indent=4,
810 separators=( ',', ': ' ) ) )
811 # check for all intent partitions
812 # check for election
813 topics = []
814 for i in range( 14 ):
815 topics.append( "intent-partition-" + str( i ) )
816 # FIXME: this should only be after we start the app
817 topics.append( "org.onosproject.election" )
818 main.log.debug( topics )
819 ONOStopics = [ j['topic'] for j in parsedLeaders ]
820 for topic in topics:
821 if topic not in ONOStopics:
822 main.log.error( "Error: " + topic +
823 " not in leaders" )
824 missing = True
825 else:
826 main.log.error( "leaders() returned None" )
827 except ( ValueError, TypeError ):
828 main.log.exception( "Error parsing leaders" )
829 main.log.error( repr( leaders ) )
830 # Check all nodes
831 if missing:
Jon Halle1a3b752015-07-22 13:02:46 -0700832 for node in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -0700833 response = node.leaders( jsonFormat=False)
834 main.log.warn( str( node.name ) + " leaders output: \n" +
835 str( response ) )
836
837 partitions = main.ONOScli1.partitions()
838 try:
839 if partitions :
840 parsedPartitions = json.loads( partitions )
841 main.log.warn( json.dumps( parsedPartitions,
842 sort_keys=True,
843 indent=4,
844 separators=( ',', ': ' ) ) )
845 # TODO check for a leader in all paritions
846 # TODO check for consistency among nodes
847 else:
848 main.log.error( "partitions() returned None" )
849 except ( ValueError, TypeError ):
850 main.log.exception( "Error parsing partitions" )
851 main.log.error( repr( partitions ) )
852 pendingMap = main.ONOScli1.pendingMap()
853 try:
854 if pendingMap :
855 parsedPending = json.loads( pendingMap )
856 main.log.warn( json.dumps( parsedPending,
857 sort_keys=True,
858 indent=4,
859 separators=( ',', ': ' ) ) )
860 # TODO check something here?
861 else:
862 main.log.error( "pendingMap() returned None" )
863 except ( ValueError, TypeError ):
864 main.log.exception( "Error parsing pending map" )
865 main.log.error( repr( pendingMap ) )
866
867 def CASE4( self, main ):
868 """
869 Ping across added host intents
870 """
871 import json
872 import time
Jon Halle1a3b752015-07-22 13:02:46 -0700873 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -0700874 assert main, "main not defined"
875 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -0700876 assert main.CLIs, "main.CLIs not defined"
877 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -0700878 main.case( "Verify connectivity by sendind traffic across Intents" )
Jon Hall783bbf92015-07-23 14:33:19 -0700879 main.caseExplanation = "Ping across added host intents to check " +\
Jon Hall5cf14d52015-07-16 12:15:19 -0700880 "functionality and check the state of " +\
881 "the intent"
882 main.step( "Ping across added host intents" )
883 PingResult = main.TRUE
884 for i in range( 8, 18 ):
885 ping = main.Mininet1.pingHost( src="h" + str( i ),
886 target="h" + str( i + 10 ) )
887 PingResult = PingResult and ping
888 if ping == main.FALSE:
889 main.log.warn( "Ping failed between h" + str( i ) +
890 " and h" + str( i + 10 ) )
891 elif ping == main.TRUE:
892 main.log.info( "Ping test passed!" )
893 # Don't set PingResult or you'd override failures
894 if PingResult == main.FALSE:
895 main.log.error(
896 "Intents have not been installed correctly, pings failed." )
897 # TODO: pretty print
898 main.log.warn( "ONOS1 intents: " )
899 try:
900 tmpIntents = main.ONOScli1.intents()
901 main.log.warn( json.dumps( json.loads( tmpIntents ),
902 sort_keys=True,
903 indent=4,
904 separators=( ',', ': ' ) ) )
905 except ( ValueError, TypeError ):
906 main.log.warn( repr( tmpIntents ) )
907 utilities.assert_equals(
908 expect=main.TRUE,
909 actual=PingResult,
910 onpass="Intents have been installed correctly and pings work",
911 onfail="Intents have not been installed correctly, pings failed." )
912
913 main.step( "Check Intent state" )
914 installedCheck = False
915 loopCount = 0
916 while not installedCheck and loopCount < 40:
917 installedCheck = True
918 # Print the intent states
919 intents = main.ONOScli1.intents()
920 intentStates = []
921 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
Jon Halle1a3b752015-07-22 13:02:46 -0700922 count = 0
Jon Hall5cf14d52015-07-16 12:15:19 -0700923 # Iter through intents of a node
924 try:
925 for intent in json.loads( intents ):
926 state = intent.get( 'state', None )
927 if "INSTALLED" not in state:
928 installedCheck = False
929 intentId = intent.get( 'id', None )
930 intentStates.append( ( intentId, state ) )
931 except ( ValueError, TypeError ):
932 main.log.exception( "Error parsing intents." )
933 # Print states
934 intentStates.sort()
935 for i, s in intentStates:
936 count += 1
937 main.log.info( "%-6s%-15s%-15s" %
938 ( str( count ), str( i ), str( s ) ) )
939 if not installedCheck:
940 time.sleep( 1 )
941 loopCount += 1
942 utilities.assert_equals( expect=True, actual=installedCheck,
943 onpass="Intents are all INSTALLED",
944 onfail="Intents are not all in " +
945 "INSTALLED state" )
946
947 main.step( "Check leadership of topics" )
948 leaders = main.ONOScli1.leaders()
949 topicCheck = main.TRUE
950 try:
951 if leaders:
952 parsedLeaders = json.loads( leaders )
953 main.log.warn( json.dumps( parsedLeaders,
954 sort_keys=True,
955 indent=4,
956 separators=( ',', ': ' ) ) )
957 # check for all intent partitions
958 # check for election
959 # TODO: Look at Devices as topics now that it uses this system
960 topics = []
961 for i in range( 14 ):
962 topics.append( "intent-partition-" + str( i ) )
963 # FIXME: this should only be after we start the app
964 # FIXME: topics.append( "org.onosproject.election" )
965 # Print leaders output
966 main.log.debug( topics )
967 ONOStopics = [ j['topic'] for j in parsedLeaders ]
968 for topic in topics:
969 if topic not in ONOStopics:
970 main.log.error( "Error: " + topic +
971 " not in leaders" )
972 topicCheck = main.FALSE
973 else:
974 main.log.error( "leaders() returned None" )
975 topicCheck = main.FALSE
976 except ( ValueError, TypeError ):
977 topicCheck = main.FALSE
978 main.log.exception( "Error parsing leaders" )
979 main.log.error( repr( leaders ) )
980 # TODO: Check for a leader of these topics
981 # Check all nodes
982 if topicCheck:
Jon Halle1a3b752015-07-22 13:02:46 -0700983 for node in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -0700984 response = node.leaders( jsonFormat=False)
985 main.log.warn( str( node.name ) + " leaders output: \n" +
986 str( response ) )
987
988 utilities.assert_equals( expect=main.TRUE, actual=topicCheck,
989 onpass="intent Partitions is in leaders",
990 onfail="Some topics were lost " )
991 # Print partitions
992 partitions = main.ONOScli1.partitions()
993 try:
994 if partitions :
995 parsedPartitions = json.loads( partitions )
996 main.log.warn( json.dumps( parsedPartitions,
997 sort_keys=True,
998 indent=4,
999 separators=( ',', ': ' ) ) )
1000 # TODO check for a leader in all paritions
1001 # TODO check for consistency among nodes
1002 else:
1003 main.log.error( "partitions() returned None" )
1004 except ( ValueError, TypeError ):
1005 main.log.exception( "Error parsing partitions" )
1006 main.log.error( repr( partitions ) )
1007 # Print Pending Map
1008 pendingMap = main.ONOScli1.pendingMap()
1009 try:
1010 if pendingMap :
1011 parsedPending = json.loads( pendingMap )
1012 main.log.warn( json.dumps( parsedPending,
1013 sort_keys=True,
1014 indent=4,
1015 separators=( ',', ': ' ) ) )
1016 # TODO check something here?
1017 else:
1018 main.log.error( "pendingMap() returned None" )
1019 except ( ValueError, TypeError ):
1020 main.log.exception( "Error parsing pending map" )
1021 main.log.error( repr( pendingMap ) )
1022
1023 if not installedCheck:
1024 main.log.info( "Waiting 60 seconds to see if the state of " +
1025 "intents change" )
1026 time.sleep( 60 )
1027 # Print the intent states
1028 intents = main.ONOScli1.intents()
1029 intentStates = []
1030 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
1031 count = 0
1032 # Iter through intents of a node
1033 try:
1034 for intent in json.loads( intents ):
1035 state = intent.get( 'state', None )
1036 if "INSTALLED" not in state:
1037 installedCheck = False
1038 intentId = intent.get( 'id', None )
1039 intentStates.append( ( intentId, state ) )
1040 except ( ValueError, TypeError ):
1041 main.log.exception( "Error parsing intents." )
1042 intentStates.sort()
1043 for i, s in intentStates:
1044 count += 1
1045 main.log.info( "%-6s%-15s%-15s" %
1046 ( str( count ), str( i ), str( s ) ) )
1047 leaders = main.ONOScli1.leaders()
1048 try:
1049 missing = False
1050 if leaders:
1051 parsedLeaders = json.loads( leaders )
1052 main.log.warn( json.dumps( parsedLeaders,
1053 sort_keys=True,
1054 indent=4,
1055 separators=( ',', ': ' ) ) )
1056 # check for all intent partitions
1057 # check for election
1058 topics = []
1059 for i in range( 14 ):
1060 topics.append( "intent-partition-" + str( i ) )
1061 # FIXME: this should only be after we start the app
1062 topics.append( "org.onosproject.election" )
1063 main.log.debug( topics )
1064 ONOStopics = [ j['topic'] for j in parsedLeaders ]
1065 for topic in topics:
1066 if topic not in ONOStopics:
1067 main.log.error( "Error: " + topic +
1068 " not in leaders" )
1069 missing = True
1070 else:
1071 main.log.error( "leaders() returned None" )
1072 except ( ValueError, TypeError ):
1073 main.log.exception( "Error parsing leaders" )
1074 main.log.error( repr( leaders ) )
1075 if missing:
Jon Halle1a3b752015-07-22 13:02:46 -07001076 for node in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -07001077 response = node.leaders( jsonFormat=False)
1078 main.log.warn( str( node.name ) + " leaders output: \n" +
1079 str( response ) )
1080
1081 partitions = main.ONOScli1.partitions()
1082 try:
1083 if partitions :
1084 parsedPartitions = json.loads( partitions )
1085 main.log.warn( json.dumps( parsedPartitions,
1086 sort_keys=True,
1087 indent=4,
1088 separators=( ',', ': ' ) ) )
1089 # TODO check for a leader in all paritions
1090 # TODO check for consistency among nodes
1091 else:
1092 main.log.error( "partitions() returned None" )
1093 except ( ValueError, TypeError ):
1094 main.log.exception( "Error parsing partitions" )
1095 main.log.error( repr( partitions ) )
1096 pendingMap = main.ONOScli1.pendingMap()
1097 try:
1098 if pendingMap :
1099 parsedPending = json.loads( pendingMap )
1100 main.log.warn( json.dumps( parsedPending,
1101 sort_keys=True,
1102 indent=4,
1103 separators=( ',', ': ' ) ) )
1104 # TODO check something here?
1105 else:
1106 main.log.error( "pendingMap() returned None" )
1107 except ( ValueError, TypeError ):
1108 main.log.exception( "Error parsing pending map" )
1109 main.log.error( repr( pendingMap ) )
1110 # Print flowrules
Jon Halle1a3b752015-07-22 13:02:46 -07001111 main.log.debug( main.CLIs[0].flows( jsonFormat=False ) )
Jon Hall5cf14d52015-07-16 12:15:19 -07001112 main.step( "Wait a minute then ping again" )
1113 # the wait is above
1114 PingResult = main.TRUE
1115 for i in range( 8, 18 ):
1116 ping = main.Mininet1.pingHost( src="h" + str( i ),
1117 target="h" + str( i + 10 ) )
1118 PingResult = PingResult and ping
1119 if ping == main.FALSE:
1120 main.log.warn( "Ping failed between h" + str( i ) +
1121 " and h" + str( i + 10 ) )
1122 elif ping == main.TRUE:
1123 main.log.info( "Ping test passed!" )
1124 # Don't set PingResult or you'd override failures
1125 if PingResult == main.FALSE:
1126 main.log.error(
1127 "Intents have not been installed correctly, pings failed." )
1128 # TODO: pretty print
1129 main.log.warn( "ONOS1 intents: " )
1130 try:
1131 tmpIntents = main.ONOScli1.intents()
1132 main.log.warn( json.dumps( json.loads( tmpIntents ),
1133 sort_keys=True,
1134 indent=4,
1135 separators=( ',', ': ' ) ) )
1136 except ( ValueError, TypeError ):
1137 main.log.warn( repr( tmpIntents ) )
1138 utilities.assert_equals(
1139 expect=main.TRUE,
1140 actual=PingResult,
1141 onpass="Intents have been installed correctly and pings work",
1142 onfail="Intents have not been installed correctly, pings failed." )
1143
1144 def CASE5( self, main ):
1145 """
1146 Reading state of ONOS
1147 """
1148 import json
1149 import time
Jon Halle1a3b752015-07-22 13:02:46 -07001150 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07001151 assert main, "main not defined"
1152 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07001153 assert main.CLIs, "main.CLIs not defined"
1154 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07001155
1156 main.case( "Setting up and gathering data for current state" )
1157 # The general idea for this test case is to pull the state of
1158 # ( intents,flows, topology,... ) from each ONOS node
1159 # We can then compare them with each other and also with past states
1160
1161 main.step( "Check that each switch has a master" )
1162 global mastershipState
1163 mastershipState = '[]'
1164
1165 # Assert that each device has a master
1166 rolesNotNull = main.TRUE
1167 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001168 for i in range( main.numCtrls ):
1169 t = main.Thread( target=main.CLIs[i].rolesNotNull,
Jon Hall5cf14d52015-07-16 12:15:19 -07001170 name="rolesNotNull-" + str( i ),
1171 args=[] )
1172 threads.append( t )
1173 t.start()
1174
1175 for t in threads:
1176 t.join()
1177 rolesNotNull = rolesNotNull and t.result
1178 utilities.assert_equals(
1179 expect=main.TRUE,
1180 actual=rolesNotNull,
1181 onpass="Each device has a master",
1182 onfail="Some devices don't have a master assigned" )
1183
1184 main.step( "Get the Mastership of each switch from each controller" )
1185 ONOSMastership = []
1186 mastershipCheck = main.FALSE
1187 consistentMastership = True
1188 rolesResults = True
1189 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001190 for i in range( main.numCtrls ):
1191 t = main.Thread( target=main.CLIs[i].roles,
Jon Hall5cf14d52015-07-16 12:15:19 -07001192 name="roles-" + str( i ),
1193 args=[] )
1194 threads.append( t )
1195 t.start()
1196
1197 for t in threads:
1198 t.join()
1199 ONOSMastership.append( t.result )
1200
Jon Halle1a3b752015-07-22 13:02:46 -07001201 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001202 if not ONOSMastership[i] or "Error" in ONOSMastership[i]:
1203 main.log.error( "Error in getting ONOS" + str( i + 1 ) +
1204 " roles" )
1205 main.log.warn(
1206 "ONOS" + str( i + 1 ) + " mastership response: " +
1207 repr( ONOSMastership[i] ) )
1208 rolesResults = False
1209 utilities.assert_equals(
1210 expect=True,
1211 actual=rolesResults,
1212 onpass="No error in reading roles output",
1213 onfail="Error in reading roles from ONOS" )
1214
1215 main.step( "Check for consistency in roles from each controller" )
1216 if all([ i == ONOSMastership[ 0 ] for i in ONOSMastership ] ):
1217 main.log.info(
1218 "Switch roles are consistent across all ONOS nodes" )
1219 else:
1220 consistentMastership = False
1221 utilities.assert_equals(
1222 expect=True,
1223 actual=consistentMastership,
1224 onpass="Switch roles are consistent across all ONOS nodes",
1225 onfail="ONOS nodes have different views of switch roles" )
1226
1227 if rolesResults and not consistentMastership:
Jon Halle1a3b752015-07-22 13:02:46 -07001228 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001229 try:
1230 main.log.warn(
1231 "ONOS" + str( i + 1 ) + " roles: ",
1232 json.dumps(
1233 json.loads( ONOSMastership[ i ] ),
1234 sort_keys=True,
1235 indent=4,
1236 separators=( ',', ': ' ) ) )
1237 except ( ValueError, TypeError ):
1238 main.log.warn( repr( ONOSMastership[ i ] ) )
1239 elif rolesResults and consistentMastership:
1240 mastershipCheck = main.TRUE
1241 mastershipState = ONOSMastership[ 0 ]
1242
1243 main.step( "Get the intents from each controller" )
1244 global intentState
1245 intentState = []
1246 ONOSIntents = []
1247 intentCheck = main.FALSE
1248 consistentIntents = True
1249 intentsResults = True
1250 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001251 for i in range( main.numCtrls ):
1252 t = main.Thread( target=main.CLIs[i].intents,
Jon Hall5cf14d52015-07-16 12:15:19 -07001253 name="intents-" + str( i ),
1254 args=[],
1255 kwargs={ 'jsonFormat': True } )
1256 threads.append( t )
1257 t.start()
1258
1259 for t in threads:
1260 t.join()
1261 ONOSIntents.append( t.result )
1262
Jon Halle1a3b752015-07-22 13:02:46 -07001263 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001264 if not ONOSIntents[ i ] or "Error" in ONOSIntents[ i ]:
1265 main.log.error( "Error in getting ONOS" + str( i + 1 ) +
1266 " intents" )
1267 main.log.warn( "ONOS" + str( i + 1 ) + " intents response: " +
1268 repr( ONOSIntents[ i ] ) )
1269 intentsResults = False
1270 utilities.assert_equals(
1271 expect=True,
1272 actual=intentsResults,
1273 onpass="No error in reading intents output",
1274 onfail="Error in reading intents from ONOS" )
1275
1276 main.step( "Check for consistency in Intents from each controller" )
1277 if all([ sorted( i ) == sorted( ONOSIntents[ 0 ] ) for i in ONOSIntents ] ):
1278 main.log.info( "Intents are consistent across all ONOS " +
1279 "nodes" )
1280 else:
1281 consistentIntents = False
1282 main.log.error( "Intents not consistent" )
1283 utilities.assert_equals(
1284 expect=True,
1285 actual=consistentIntents,
1286 onpass="Intents are consistent across all ONOS nodes",
1287 onfail="ONOS nodes have different views of intents" )
1288
1289 if intentsResults:
1290 # Try to make it easy to figure out what is happening
1291 #
1292 # Intent ONOS1 ONOS2 ...
1293 # 0x01 INSTALLED INSTALLING
1294 # ... ... ...
1295 # ... ... ...
1296 title = " Id"
Jon Halle1a3b752015-07-22 13:02:46 -07001297 for n in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001298 title += " " * 10 + "ONOS" + str( n + 1 )
1299 main.log.warn( title )
1300 # get all intent keys in the cluster
1301 keys = []
1302 for nodeStr in ONOSIntents:
1303 node = json.loads( nodeStr )
1304 for intent in node:
1305 keys.append( intent.get( 'id' ) )
1306 keys = set( keys )
1307 for key in keys:
1308 row = "%-13s" % key
1309 for nodeStr in ONOSIntents:
1310 node = json.loads( nodeStr )
1311 for intent in node:
1312 if intent.get( 'id', "Error" ) == key:
1313 row += "%-15s" % intent.get( 'state' )
1314 main.log.warn( row )
1315 # End table view
1316
1317 if intentsResults and not consistentIntents:
1318 # print the json objects
1319 n = len(ONOSIntents)
1320 main.log.debug( "ONOS" + str( n ) + " intents: " )
1321 main.log.debug( json.dumps( json.loads( ONOSIntents[ -1 ] ),
1322 sort_keys=True,
1323 indent=4,
1324 separators=( ',', ': ' ) ) )
Jon Halle1a3b752015-07-22 13:02:46 -07001325 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001326 if ONOSIntents[ i ] != ONOSIntents[ -1 ]:
1327 main.log.debug( "ONOS" + str( i + 1 ) + " intents: " )
1328 main.log.debug( json.dumps( json.loads( ONOSIntents[i] ),
1329 sort_keys=True,
1330 indent=4,
1331 separators=( ',', ': ' ) ) )
1332 else:
Jon Halle1a3b752015-07-22 13:02:46 -07001333 main.log.debug( main.nodes[ i ].name + " intents match ONOS" +
Jon Hall5cf14d52015-07-16 12:15:19 -07001334 str( n ) + " intents" )
1335 elif intentsResults and consistentIntents:
1336 intentCheck = main.TRUE
1337 intentState = ONOSIntents[ 0 ]
1338
1339 main.step( "Get the flows from each controller" )
1340 global flowState
1341 flowState = []
1342 ONOSFlows = []
1343 ONOSFlowsJson = []
1344 flowCheck = main.FALSE
1345 consistentFlows = True
1346 flowsResults = True
1347 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001348 for i in range( main.numCtrls ):
1349 t = main.Thread( target=main.CLIs[i].flows,
Jon Hall5cf14d52015-07-16 12:15:19 -07001350 name="flows-" + str( i ),
1351 args=[],
1352 kwargs={ 'jsonFormat': True } )
1353 threads.append( t )
1354 t.start()
1355
1356 # NOTE: Flows command can take some time to run
1357 time.sleep(30)
1358 for t in threads:
1359 t.join()
1360 result = t.result
1361 ONOSFlows.append( result )
1362
Jon Halle1a3b752015-07-22 13:02:46 -07001363 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001364 num = str( i + 1 )
1365 if not ONOSFlows[ i ] or "Error" in ONOSFlows[ i ]:
1366 main.log.error( "Error in getting ONOS" + num + " flows" )
1367 main.log.warn( "ONOS" + num + " flows response: " +
1368 repr( ONOSFlows[ i ] ) )
1369 flowsResults = False
1370 ONOSFlowsJson.append( None )
1371 else:
1372 try:
1373 ONOSFlowsJson.append( json.loads( ONOSFlows[ i ] ) )
1374 except ( ValueError, TypeError ):
1375 # FIXME: change this to log.error?
1376 main.log.exception( "Error in parsing ONOS" + num +
1377 " response as json." )
1378 main.log.error( repr( ONOSFlows[ i ] ) )
1379 ONOSFlowsJson.append( None )
1380 flowsResults = False
1381 utilities.assert_equals(
1382 expect=True,
1383 actual=flowsResults,
1384 onpass="No error in reading flows output",
1385 onfail="Error in reading flows from ONOS" )
1386
1387 main.step( "Check for consistency in Flows from each controller" )
1388 tmp = [ len( i ) == len( ONOSFlowsJson[ 0 ] ) for i in ONOSFlowsJson ]
1389 if all( tmp ):
1390 main.log.info( "Flow count is consistent across all ONOS nodes" )
1391 else:
1392 consistentFlows = False
1393 utilities.assert_equals(
1394 expect=True,
1395 actual=consistentFlows,
1396 onpass="The flow count is consistent across all ONOS nodes",
1397 onfail="ONOS nodes have different flow counts" )
1398
1399 if flowsResults and not consistentFlows:
Jon Halle1a3b752015-07-22 13:02:46 -07001400 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001401 try:
1402 main.log.warn(
1403 "ONOS" + str( i + 1 ) + " flows: " +
1404 json.dumps( json.loads( ONOSFlows[i] ), sort_keys=True,
1405 indent=4, separators=( ',', ': ' ) ) )
1406 except ( ValueError, TypeError ):
1407 main.log.warn(
1408 "ONOS" + str( i + 1 ) + " flows: " +
1409 repr( ONOSFlows[ i ] ) )
1410 elif flowsResults and consistentFlows:
1411 flowCheck = main.TRUE
1412 flowState = ONOSFlows[ 0 ]
1413
1414 main.step( "Get the OF Table entries" )
1415 global flows
1416 flows = []
1417 for i in range( 1, 29 ):
Jon Hallca7ac292015-11-11 09:28:12 -08001418 flows.append( main.Mininet1.getFlowTable( "s" + str( i ), version="1.3" ) )
Jon Hall5cf14d52015-07-16 12:15:19 -07001419 if flowCheck == main.FALSE:
1420 for table in flows:
1421 main.log.warn( table )
1422 # TODO: Compare switch flow tables with ONOS flow tables
1423
1424 main.step( "Start continuous pings" )
1425 main.Mininet2.pingLong(
1426 src=main.params[ 'PING' ][ 'source1' ],
1427 target=main.params[ 'PING' ][ 'target1' ],
1428 pingTime=500 )
1429 main.Mininet2.pingLong(
1430 src=main.params[ 'PING' ][ 'source2' ],
1431 target=main.params[ 'PING' ][ 'target2' ],
1432 pingTime=500 )
1433 main.Mininet2.pingLong(
1434 src=main.params[ 'PING' ][ 'source3' ],
1435 target=main.params[ 'PING' ][ 'target3' ],
1436 pingTime=500 )
1437 main.Mininet2.pingLong(
1438 src=main.params[ 'PING' ][ 'source4' ],
1439 target=main.params[ 'PING' ][ 'target4' ],
1440 pingTime=500 )
1441 main.Mininet2.pingLong(
1442 src=main.params[ 'PING' ][ 'source5' ],
1443 target=main.params[ 'PING' ][ 'target5' ],
1444 pingTime=500 )
1445 main.Mininet2.pingLong(
1446 src=main.params[ 'PING' ][ 'source6' ],
1447 target=main.params[ 'PING' ][ 'target6' ],
1448 pingTime=500 )
1449 main.Mininet2.pingLong(
1450 src=main.params[ 'PING' ][ 'source7' ],
1451 target=main.params[ 'PING' ][ 'target7' ],
1452 pingTime=500 )
1453 main.Mininet2.pingLong(
1454 src=main.params[ 'PING' ][ 'source8' ],
1455 target=main.params[ 'PING' ][ 'target8' ],
1456 pingTime=500 )
1457 main.Mininet2.pingLong(
1458 src=main.params[ 'PING' ][ 'source9' ],
1459 target=main.params[ 'PING' ][ 'target9' ],
1460 pingTime=500 )
1461 main.Mininet2.pingLong(
1462 src=main.params[ 'PING' ][ 'source10' ],
1463 target=main.params[ 'PING' ][ 'target10' ],
1464 pingTime=500 )
1465
1466 main.step( "Collecting topology information from ONOS" )
1467 devices = []
1468 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001469 for i in range( main.numCtrls ):
1470 t = main.Thread( target=main.CLIs[i].devices,
Jon Hall5cf14d52015-07-16 12:15:19 -07001471 name="devices-" + str( i ),
1472 args=[ ] )
1473 threads.append( t )
1474 t.start()
1475
1476 for t in threads:
1477 t.join()
1478 devices.append( t.result )
1479 hosts = []
1480 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001481 for i in range( main.numCtrls ):
1482 t = main.Thread( target=main.CLIs[i].hosts,
Jon Hall5cf14d52015-07-16 12:15:19 -07001483 name="hosts-" + str( i ),
1484 args=[ ] )
1485 threads.append( t )
1486 t.start()
1487
1488 for t in threads:
1489 t.join()
1490 try:
1491 hosts.append( json.loads( t.result ) )
1492 except ( ValueError, TypeError ):
1493 # FIXME: better handling of this, print which node
1494 # Maybe use thread name?
1495 main.log.exception( "Error parsing json output of hosts" )
Jon Hall3afe4c92015-12-14 19:30:38 -08001496 main.log.warn( repr( t.result ) )
Jon Hall5cf14d52015-07-16 12:15:19 -07001497 hosts.append( None )
1498
1499 ports = []
1500 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001501 for i in range( main.numCtrls ):
1502 t = main.Thread( target=main.CLIs[i].ports,
Jon Hall5cf14d52015-07-16 12:15:19 -07001503 name="ports-" + str( i ),
1504 args=[ ] )
1505 threads.append( t )
1506 t.start()
1507
1508 for t in threads:
1509 t.join()
1510 ports.append( t.result )
1511 links = []
1512 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001513 for i in range( main.numCtrls ):
1514 t = main.Thread( target=main.CLIs[i].links,
Jon Hall5cf14d52015-07-16 12:15:19 -07001515 name="links-" + str( i ),
1516 args=[ ] )
1517 threads.append( t )
1518 t.start()
1519
1520 for t in threads:
1521 t.join()
1522 links.append( t.result )
1523 clusters = []
1524 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001525 for i in range( main.numCtrls ):
1526 t = main.Thread( target=main.CLIs[i].clusters,
Jon Hall5cf14d52015-07-16 12:15:19 -07001527 name="clusters-" + str( i ),
1528 args=[ ] )
1529 threads.append( t )
1530 t.start()
1531
1532 for t in threads:
1533 t.join()
1534 clusters.append( t.result )
1535 # Compare json objects for hosts and dataplane clusters
1536
1537 # hosts
1538 main.step( "Host view is consistent across ONOS nodes" )
1539 consistentHostsResult = main.TRUE
1540 for controller in range( len( hosts ) ):
1541 controllerStr = str( controller + 1 )
Jon Hall3afe4c92015-12-14 19:30:38 -08001542 if hosts[ controller ] and "Error" not in hosts[ controller ]:
Jon Hall5cf14d52015-07-16 12:15:19 -07001543 if hosts[ controller ] == hosts[ 0 ]:
1544 continue
1545 else: # hosts not consistent
1546 main.log.error( "hosts from ONOS" +
1547 controllerStr +
1548 " is inconsistent with ONOS1" )
1549 main.log.warn( repr( hosts[ controller ] ) )
1550 consistentHostsResult = main.FALSE
1551
1552 else:
1553 main.log.error( "Error in getting ONOS hosts from ONOS" +
1554 controllerStr )
1555 consistentHostsResult = main.FALSE
1556 main.log.warn( "ONOS" + controllerStr +
1557 " hosts response: " +
1558 repr( hosts[ controller ] ) )
1559 utilities.assert_equals(
1560 expect=main.TRUE,
1561 actual=consistentHostsResult,
1562 onpass="Hosts view is consistent across all ONOS nodes",
1563 onfail="ONOS nodes have different views of hosts" )
1564
1565 main.step( "Each host has an IP address" )
1566 ipResult = main.TRUE
1567 for controller in range( 0, len( hosts ) ):
1568 controllerStr = str( controller + 1 )
Jon Hall3afe4c92015-12-14 19:30:38 -08001569 if hosts[ controller ]:
1570 for host in hosts[ controller ]:
1571 if not host.get( 'ipAddresses', [ ] ):
Jon Hallf3d16e72015-12-16 17:45:08 -08001572 main.log.error( "Error with host ips on controller" +
Jon Hall3afe4c92015-12-14 19:30:38 -08001573 controllerStr + ": " + str( host ) )
1574 ipResult = main.FALSE
Jon Hall5cf14d52015-07-16 12:15:19 -07001575 utilities.assert_equals(
1576 expect=main.TRUE,
1577 actual=ipResult,
1578 onpass="The ips of the hosts aren't empty",
1579 onfail="The ip of at least one host is missing" )
1580
1581 # Strongly connected clusters of devices
1582 main.step( "Cluster view is consistent across ONOS nodes" )
1583 consistentClustersResult = main.TRUE
1584 for controller in range( len( clusters ) ):
1585 controllerStr = str( controller + 1 )
1586 if "Error" not in clusters[ controller ]:
1587 if clusters[ controller ] == clusters[ 0 ]:
1588 continue
1589 else: # clusters not consistent
1590 main.log.error( "clusters from ONOS" + controllerStr +
1591 " is inconsistent with ONOS1" )
1592 consistentClustersResult = main.FALSE
1593
1594 else:
1595 main.log.error( "Error in getting dataplane clusters " +
1596 "from ONOS" + controllerStr )
1597 consistentClustersResult = main.FALSE
1598 main.log.warn( "ONOS" + controllerStr +
1599 " clusters response: " +
1600 repr( clusters[ controller ] ) )
1601 utilities.assert_equals(
1602 expect=main.TRUE,
1603 actual=consistentClustersResult,
1604 onpass="Clusters view is consistent across all ONOS nodes",
1605 onfail="ONOS nodes have different views of clusters" )
1606 # there should always only be one cluster
1607 main.step( "Cluster view correct across ONOS nodes" )
1608 try:
1609 numClusters = len( json.loads( clusters[ 0 ] ) )
1610 except ( ValueError, TypeError ):
1611 main.log.exception( "Error parsing clusters[0]: " +
1612 repr( clusters[ 0 ] ) )
1613 clusterResults = main.FALSE
1614 if numClusters == 1:
1615 clusterResults = main.TRUE
1616 utilities.assert_equals(
1617 expect=1,
1618 actual=numClusters,
1619 onpass="ONOS shows 1 SCC",
1620 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
1621
1622 main.step( "Comparing ONOS topology to MN" )
1623 devicesResults = main.TRUE
1624 linksResults = main.TRUE
1625 hostsResults = main.TRUE
1626 mnSwitches = main.Mininet1.getSwitches()
1627 mnLinks = main.Mininet1.getLinks()
1628 mnHosts = main.Mininet1.getHosts()
Jon Halle1a3b752015-07-22 13:02:46 -07001629 for controller in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001630 controllerStr = str( controller + 1 )
1631 if devices[ controller ] and ports[ controller ] and\
1632 "Error" not in devices[ controller ] and\
1633 "Error" not in ports[ controller ]:
Jon Halle1a3b752015-07-22 13:02:46 -07001634 currentDevicesResult = main.Mininet1.compareSwitches(
1635 mnSwitches,
1636 json.loads( devices[ controller ] ),
1637 json.loads( ports[ controller ] ) )
Jon Hall5cf14d52015-07-16 12:15:19 -07001638 else:
1639 currentDevicesResult = main.FALSE
1640 utilities.assert_equals( expect=main.TRUE,
1641 actual=currentDevicesResult,
1642 onpass="ONOS" + controllerStr +
1643 " Switches view is correct",
1644 onfail="ONOS" + controllerStr +
1645 " Switches view is incorrect" )
1646 if links[ controller ] and "Error" not in links[ controller ]:
1647 currentLinksResult = main.Mininet1.compareLinks(
1648 mnSwitches, mnLinks,
1649 json.loads( links[ controller ] ) )
1650 else:
1651 currentLinksResult = main.FALSE
1652 utilities.assert_equals( expect=main.TRUE,
1653 actual=currentLinksResult,
1654 onpass="ONOS" + controllerStr +
1655 " links view is correct",
1656 onfail="ONOS" + controllerStr +
1657 " links view is incorrect" )
1658
1659 if hosts[ controller ] or "Error" not in hosts[ controller ]:
1660 currentHostsResult = main.Mininet1.compareHosts(
1661 mnHosts,
1662 hosts[ controller ] )
1663 else:
1664 currentHostsResult = main.FALSE
1665 utilities.assert_equals( expect=main.TRUE,
1666 actual=currentHostsResult,
1667 onpass="ONOS" + controllerStr +
1668 " hosts exist in Mininet",
1669 onfail="ONOS" + controllerStr +
1670 " hosts don't match Mininet" )
1671
1672 devicesResults = devicesResults and currentDevicesResult
1673 linksResults = linksResults and currentLinksResult
1674 hostsResults = hostsResults and currentHostsResult
1675
1676 main.step( "Device information is correct" )
1677 utilities.assert_equals(
1678 expect=main.TRUE,
1679 actual=devicesResults,
1680 onpass="Device information is correct",
1681 onfail="Device information is incorrect" )
1682
1683 main.step( "Links are correct" )
1684 utilities.assert_equals(
1685 expect=main.TRUE,
1686 actual=linksResults,
1687 onpass="Link are correct",
1688 onfail="Links are incorrect" )
1689
1690 main.step( "Hosts are correct" )
1691 utilities.assert_equals(
1692 expect=main.TRUE,
1693 actual=hostsResults,
1694 onpass="Hosts are correct",
1695 onfail="Hosts are incorrect" )
1696
1697 def CASE6( self, main ):
1698 """
1699 The Failure case.
1700 """
1701 import time
Jon Halle1a3b752015-07-22 13:02:46 -07001702 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07001703 assert main, "main not defined"
1704 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07001705 assert main.CLIs, "main.CLIs not defined"
1706 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07001707 try:
1708 labels
1709 except NameError:
1710 main.log.error( "labels not defined, setting to []" )
1711 global labels
1712 labels = []
1713 try:
1714 data
1715 except NameError:
1716 main.log.error( "data not defined, setting to []" )
1717 global data
1718 data = []
1719 # Reset non-persistent variables
1720 try:
1721 iCounterValue = 0
1722 except NameError:
1723 main.log.error( "iCounterValue not defined, setting to 0" )
1724 iCounterValue = 0
1725
1726 main.case( "Restart entire ONOS cluster" )
1727
Jon Hall5ec6b1b2015-09-17 18:20:14 -07001728 main.step( "Checking ONOS Logs for errors" )
1729 for node in main.nodes:
1730 main.log.debug( "Checking logs for errors on " + node.name + ":" )
1731 main.log.warn( main.ONOSbench.checkLogs( node.ip_address ) )
1732
Jon Hall5cf14d52015-07-16 12:15:19 -07001733 main.step( "Killing ONOS nodes" )
1734 killResults = main.TRUE
1735 killTime = time.time()
Jon Halle1a3b752015-07-22 13:02:46 -07001736 for node in main.nodes:
Jon Hall5cf14d52015-07-16 12:15:19 -07001737 killed = main.ONOSbench.onosKill( node.ip_address )
1738 killResults = killResults and killed
1739 utilities.assert_equals( expect=main.TRUE, actual=killResults,
1740 onpass="ONOS nodes killed",
1741 onfail="ONOS kill unsuccessful" )
1742
1743 main.step( "Checking if ONOS is up yet" )
1744 for i in range( 2 ):
1745 onosIsupResult = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07001746 for node in main.nodes:
Jon Hall5cf14d52015-07-16 12:15:19 -07001747 started = main.ONOSbench.isup( node.ip_address )
1748 if not started:
1749 main.log.error( node.name + " didn't start!" )
1750 onosIsupResult = onosIsupResult and started
1751 if onosIsupResult == main.TRUE:
1752 break
1753 utilities.assert_equals( expect=main.TRUE, actual=onosIsupResult,
1754 onpass="ONOS restarted",
1755 onfail="ONOS restart NOT successful" )
1756
1757 main.log.step( "Starting ONOS CLI sessions" )
1758 cliResults = main.TRUE
1759 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001760 for i in range( main.numCtrls ):
1761 t = main.Thread( target=main.CLIs[i].startOnosCli,
Jon Hall5cf14d52015-07-16 12:15:19 -07001762 name="startOnosCli-" + str( i ),
Jon Halle1a3b752015-07-22 13:02:46 -07001763 args=[main.nodes[i].ip_address] )
Jon Hall5cf14d52015-07-16 12:15:19 -07001764 threads.append( t )
1765 t.start()
1766
1767 for t in threads:
1768 t.join()
1769 cliResults = cliResults and t.result
1770 utilities.assert_equals( expect=main.TRUE, actual=cliResults,
1771 onpass="ONOS cli started",
1772 onfail="ONOS clis did not restart" )
1773
1774 # Grab the time of restart so we chan check how long the gossip
1775 # protocol has had time to work
1776 main.restartTime = time.time() - killTime
1777 main.log.debug( "Restart time: " + str( main.restartTime ) )
1778 labels.append( "Restart" )
1779 data.append( str( main.restartTime ) )
1780
1781 # FIXME: revisit test plan for election with madan
1782 # Rerun for election on restarted nodes
1783 runResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07001784 for cli in main.CLIs:
1785 run = main.CLIs[0].electionTestRun()
Jon Hall5cf14d52015-07-16 12:15:19 -07001786 if run != main.TRUE:
1787 main.log.error( "Error running for election on " + cli.name )
1788 runResults = runResults and run
1789 utilities.assert_equals( expect=main.TRUE, actual=runResults,
1790 onpass="Reran for election",
1791 onfail="Failed to rerun for election" )
1792
1793 # TODO: Make this configurable
1794 time.sleep( 60 )
Jon Halle1a3b752015-07-22 13:02:46 -07001795 main.log.debug( main.CLIs[0].nodes( jsonFormat=False ) )
1796 main.log.debug( main.CLIs[0].leaders( jsonFormat=False ) )
1797 main.log.debug( main.CLIs[0].partitions( jsonFormat=False ) )
Jon Hall5cf14d52015-07-16 12:15:19 -07001798
1799 def CASE7( self, main ):
1800 """
1801 Check state after ONOS failure
1802 """
1803 import json
Jon Halle1a3b752015-07-22 13:02:46 -07001804 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07001805 assert main, "main not defined"
1806 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07001807 assert main.CLIs, "main.CLIs not defined"
1808 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07001809 main.case( "Running ONOS Constant State Tests" )
1810
1811 main.step( "Check that each switch has a master" )
1812 # Assert that each device has a master
1813 rolesNotNull = main.TRUE
1814 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001815 for i in range( main.numCtrls ):
1816 t = main.Thread( target=main.CLIs[i].rolesNotNull,
Jon Hall5cf14d52015-07-16 12:15:19 -07001817 name="rolesNotNull-" + str( i ),
1818 args=[ ] )
1819 threads.append( t )
1820 t.start()
1821
1822 for t in threads:
1823 t.join()
1824 rolesNotNull = rolesNotNull and t.result
1825 utilities.assert_equals(
1826 expect=main.TRUE,
1827 actual=rolesNotNull,
1828 onpass="Each device has a master",
1829 onfail="Some devices don't have a master assigned" )
1830
1831 main.step( "Read device roles from ONOS" )
1832 ONOSMastership = []
1833 mastershipCheck = main.FALSE
1834 consistentMastership = True
1835 rolesResults = True
1836 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001837 for i in range( main.numCtrls ):
1838 t = main.Thread( target=main.CLIs[i].roles,
Jon Hall5cf14d52015-07-16 12:15:19 -07001839 name="roles-" + str( i ),
1840 args=[] )
1841 threads.append( t )
1842 t.start()
1843
1844 for t in threads:
1845 t.join()
1846 ONOSMastership.append( t.result )
1847
Jon Halle1a3b752015-07-22 13:02:46 -07001848 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001849 if not ONOSMastership[i] or "Error" in ONOSMastership[i]:
1850 main.log.error( "Error in getting ONOS" + str( i + 1 ) +
1851 " roles" )
1852 main.log.warn(
1853 "ONOS" + str( i + 1 ) + " mastership response: " +
1854 repr( ONOSMastership[i] ) )
1855 rolesResults = False
1856 utilities.assert_equals(
1857 expect=True,
1858 actual=rolesResults,
1859 onpass="No error in reading roles output",
1860 onfail="Error in reading roles from ONOS" )
1861
1862 main.step( "Check for consistency in roles from each controller" )
1863 if all([ i == ONOSMastership[ 0 ] for i in ONOSMastership ] ):
1864 main.log.info(
1865 "Switch roles are consistent across all ONOS nodes" )
1866 else:
1867 consistentMastership = False
1868 utilities.assert_equals(
1869 expect=True,
1870 actual=consistentMastership,
1871 onpass="Switch roles are consistent across all ONOS nodes",
1872 onfail="ONOS nodes have different views of switch roles" )
1873
1874 if rolesResults and not consistentMastership:
Jon Halle1a3b752015-07-22 13:02:46 -07001875 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001876 main.log.warn(
1877 "ONOS" + str( i + 1 ) + " roles: ",
1878 json.dumps(
1879 json.loads( ONOSMastership[ i ] ),
1880 sort_keys=True,
1881 indent=4,
1882 separators=( ',', ': ' ) ) )
1883 elif rolesResults and not consistentMastership:
1884 mastershipCheck = main.TRUE
1885
1886 '''
1887 description2 = "Compare switch roles from before failure"
1888 main.step( description2 )
1889 try:
1890 currentJson = json.loads( ONOSMastership[0] )
1891 oldJson = json.loads( mastershipState )
1892 except ( ValueError, TypeError ):
1893 main.log.exception( "Something is wrong with parsing " +
1894 "ONOSMastership[0] or mastershipState" )
1895 main.log.error( "ONOSMastership[0]: " + repr( ONOSMastership[0] ) )
1896 main.log.error( "mastershipState" + repr( mastershipState ) )
1897 main.cleanup()
1898 main.exit()
1899 mastershipCheck = main.TRUE
1900 for i in range( 1, 29 ):
1901 switchDPID = str(
1902 main.Mininet1.getSwitchDPID( switch="s" + str( i ) ) )
1903 current = [ switch[ 'master' ] for switch in currentJson
1904 if switchDPID in switch[ 'id' ] ]
1905 old = [ switch[ 'master' ] for switch in oldJson
1906 if switchDPID in switch[ 'id' ] ]
1907 if current == old:
1908 mastershipCheck = mastershipCheck and main.TRUE
1909 else:
1910 main.log.warn( "Mastership of switch %s changed" % switchDPID )
1911 mastershipCheck = main.FALSE
1912 utilities.assert_equals(
1913 expect=main.TRUE,
1914 actual=mastershipCheck,
1915 onpass="Mastership of Switches was not changed",
1916 onfail="Mastership of some switches changed" )
1917 '''
1918 # NOTE: we expect mastership to change on controller failure
1919
1920 main.step( "Get the intents and compare across all nodes" )
1921 ONOSIntents = []
1922 intentCheck = main.FALSE
1923 consistentIntents = True
1924 intentsResults = True
1925 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001926 for i in range( main.numCtrls ):
1927 t = main.Thread( target=main.CLIs[i].intents,
Jon Hall5cf14d52015-07-16 12:15:19 -07001928 name="intents-" + str( i ),
1929 args=[],
1930 kwargs={ 'jsonFormat': True } )
1931 threads.append( t )
1932 t.start()
1933
1934 for t in threads:
1935 t.join()
1936 ONOSIntents.append( t.result )
1937
Jon Halle1a3b752015-07-22 13:02:46 -07001938 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001939 if not ONOSIntents[ i ] or "Error" in ONOSIntents[ i ]:
1940 main.log.error( "Error in getting ONOS" + str( i + 1 ) +
1941 " intents" )
1942 main.log.warn( "ONOS" + str( i + 1 ) + " intents response: " +
1943 repr( ONOSIntents[ i ] ) )
1944 intentsResults = False
1945 utilities.assert_equals(
1946 expect=True,
1947 actual=intentsResults,
1948 onpass="No error in reading intents output",
1949 onfail="Error in reading intents from ONOS" )
1950
1951 main.step( "Check for consistency in Intents from each controller" )
1952 if all([ sorted( i ) == sorted( ONOSIntents[ 0 ] ) for i in ONOSIntents ] ):
1953 main.log.info( "Intents are consistent across all ONOS " +
1954 "nodes" )
1955 else:
1956 consistentIntents = False
1957
1958 # Try to make it easy to figure out what is happening
1959 #
1960 # Intent ONOS1 ONOS2 ...
1961 # 0x01 INSTALLED INSTALLING
1962 # ... ... ...
1963 # ... ... ...
1964 title = " ID"
Jon Halle1a3b752015-07-22 13:02:46 -07001965 for n in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001966 title += " " * 10 + "ONOS" + str( n + 1 )
1967 main.log.warn( title )
1968 # get all intent keys in the cluster
1969 keys = []
1970 for nodeStr in ONOSIntents:
1971 node = json.loads( nodeStr )
1972 for intent in node:
1973 keys.append( intent.get( 'id' ) )
1974 keys = set( keys )
1975 for key in keys:
1976 row = "%-13s" % key
1977 for nodeStr in ONOSIntents:
1978 node = json.loads( nodeStr )
1979 for intent in node:
1980 if intent.get( 'id' ) == key:
1981 row += "%-15s" % intent.get( 'state' )
1982 main.log.warn( row )
1983 # End table view
1984
1985 utilities.assert_equals(
1986 expect=True,
1987 actual=consistentIntents,
1988 onpass="Intents are consistent across all ONOS nodes",
1989 onfail="ONOS nodes have different views of intents" )
1990 intentStates = []
1991 for node in ONOSIntents: # Iter through ONOS nodes
1992 nodeStates = []
1993 # Iter through intents of a node
1994 try:
1995 for intent in json.loads( node ):
1996 nodeStates.append( intent[ 'state' ] )
1997 except ( ValueError, TypeError ):
1998 main.log.exception( "Error in parsing intents" )
1999 main.log.error( repr( node ) )
2000 intentStates.append( nodeStates )
2001 out = [ (i, nodeStates.count( i ) ) for i in set( nodeStates ) ]
2002 main.log.info( dict( out ) )
2003
2004 if intentsResults and not consistentIntents:
Jon Halle1a3b752015-07-22 13:02:46 -07002005 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07002006 main.log.warn( "ONOS" + str( i + 1 ) + " intents: " )
2007 main.log.warn( json.dumps(
2008 json.loads( ONOSIntents[ i ] ),
2009 sort_keys=True,
2010 indent=4,
2011 separators=( ',', ': ' ) ) )
2012 elif intentsResults and consistentIntents:
2013 intentCheck = main.TRUE
2014
2015 # NOTE: Store has no durability, so intents are lost across system
2016 # restarts
2017 """
2018 main.step( "Compare current intents with intents before the failure" )
2019 # NOTE: this requires case 5 to pass for intentState to be set.
2020 # maybe we should stop the test if that fails?
2021 sameIntents = main.FALSE
2022 if intentState and intentState == ONOSIntents[ 0 ]:
2023 sameIntents = main.TRUE
2024 main.log.info( "Intents are consistent with before failure" )
2025 # TODO: possibly the states have changed? we may need to figure out
2026 # what the acceptable states are
2027 elif len( intentState ) == len( ONOSIntents[ 0 ] ):
2028 sameIntents = main.TRUE
2029 try:
2030 before = json.loads( intentState )
2031 after = json.loads( ONOSIntents[ 0 ] )
2032 for intent in before:
2033 if intent not in after:
2034 sameIntents = main.FALSE
2035 main.log.debug( "Intent is not currently in ONOS " +
2036 "(at least in the same form):" )
2037 main.log.debug( json.dumps( intent ) )
2038 except ( ValueError, TypeError ):
2039 main.log.exception( "Exception printing intents" )
2040 main.log.debug( repr( ONOSIntents[0] ) )
2041 main.log.debug( repr( intentState ) )
2042 if sameIntents == main.FALSE:
2043 try:
2044 main.log.debug( "ONOS intents before: " )
2045 main.log.debug( json.dumps( json.loads( intentState ),
2046 sort_keys=True, indent=4,
2047 separators=( ',', ': ' ) ) )
2048 main.log.debug( "Current ONOS intents: " )
2049 main.log.debug( json.dumps( json.loads( ONOSIntents[ 0 ] ),
2050 sort_keys=True, indent=4,
2051 separators=( ',', ': ' ) ) )
2052 except ( ValueError, TypeError ):
2053 main.log.exception( "Exception printing intents" )
2054 main.log.debug( repr( ONOSIntents[0] ) )
2055 main.log.debug( repr( intentState ) )
2056 utilities.assert_equals(
2057 expect=main.TRUE,
2058 actual=sameIntents,
2059 onpass="Intents are consistent with before failure",
2060 onfail="The Intents changed during failure" )
2061 intentCheck = intentCheck and sameIntents
2062 """
2063 main.step( "Get the OF Table entries and compare to before " +
2064 "component failure" )
2065 FlowTables = main.TRUE
Jon Hall5cf14d52015-07-16 12:15:19 -07002066 for i in range( 28 ):
2067 main.log.info( "Checking flow table on s" + str( i + 1 ) )
GlennRC68467eb2015-11-16 18:01:01 -08002068 tmpFlows = main.Mininet1.getFlowTable( "s" + str( i + 1 ), version="1.3", debug=False )
2069 FlowTables = FlowTables and main.Mininet1.flowTableComp( flows[i], tmpFlows )
Jon Hall5cf14d52015-07-16 12:15:19 -07002070 if FlowTables == main.FALSE:
GlennRC68467eb2015-11-16 18:01:01 -08002071 main.log.warn( "Differences in flow table for switch: s{}".format( i + 1 ) )
2072
Jon Hall5cf14d52015-07-16 12:15:19 -07002073 utilities.assert_equals(
2074 expect=main.TRUE,
2075 actual=FlowTables,
2076 onpass="No changes were found in the flow tables",
2077 onfail="Changes were found in the flow tables" )
2078
2079 main.Mininet2.pingLongKill()
2080 '''
2081 # main.step( "Check the continuous pings to ensure that no packets " +
2082 # "were dropped during component failure" )
2083 main.Mininet2.pingKill( main.params[ 'TESTONUSER' ],
2084 main.params[ 'TESTONIP' ] )
2085 LossInPings = main.FALSE
2086 # NOTE: checkForLoss returns main.FALSE with 0% packet loss
2087 for i in range( 8, 18 ):
2088 main.log.info(
2089 "Checking for a loss in pings along flow from s" +
2090 str( i ) )
2091 LossInPings = main.Mininet2.checkForLoss(
2092 "/tmp/ping.h" +
2093 str( i ) ) or LossInPings
2094 if LossInPings == main.TRUE:
2095 main.log.info( "Loss in ping detected" )
2096 elif LossInPings == main.ERROR:
2097 main.log.info( "There are multiple mininet process running" )
2098 elif LossInPings == main.FALSE:
2099 main.log.info( "No Loss in the pings" )
2100 main.log.info( "No loss of dataplane connectivity" )
2101 # utilities.assert_equals(
2102 # expect=main.FALSE,
2103 # actual=LossInPings,
2104 # onpass="No Loss of connectivity",
2105 # onfail="Loss of dataplane connectivity detected" )
2106
2107 # NOTE: Since intents are not persisted with IntnentStore,
2108 # we expect loss in dataplane connectivity
2109 LossInPings = main.FALSE
2110 '''
2111
2112 main.step( "Leadership Election is still functional" )
2113 # Test of LeadershipElection
2114 leaderList = []
2115 leaderResult = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07002116 for cli in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -07002117 leaderN = cli.electionTestLeader()
2118 leaderList.append( leaderN )
2119 if leaderN == main.FALSE:
2120 # error in response
2121 main.log.error( "Something is wrong with " +
2122 "electionTestLeader function, check the" +
2123 " error logs" )
2124 leaderResult = main.FALSE
2125 elif leaderN is None:
2126 main.log.error( cli.name +
2127 " shows no leader for the election-app." )
2128 leaderResult = main.FALSE
2129 if len( set( leaderList ) ) != 1:
2130 leaderResult = main.FALSE
2131 main.log.error(
2132 "Inconsistent view of leader for the election test app" )
2133 # TODO: print the list
2134 utilities.assert_equals(
2135 expect=main.TRUE,
2136 actual=leaderResult,
2137 onpass="Leadership election passed",
2138 onfail="Something went wrong with Leadership election" )
2139
2140 def CASE8( self, main ):
2141 """
2142 Compare topo
2143 """
2144 import json
2145 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002146 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002147 assert main, "main not defined"
2148 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002149 assert main.CLIs, "main.CLIs not defined"
2150 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002151
2152 main.case( "Compare ONOS Topology view to Mininet topology" )
Jon Hall783bbf92015-07-23 14:33:19 -07002153 main.caseExplanation = "Compare topology objects between Mininet" +\
Jon Hall5cf14d52015-07-16 12:15:19 -07002154 " and ONOS"
Jon Hall5cf14d52015-07-16 12:15:19 -07002155 topoResult = main.FALSE
2156 elapsed = 0
2157 count = 0
Jon Halle9b1fa32015-12-08 15:32:21 -08002158 main.step( "Comparing ONOS topology to MN topology" )
Jon Hall5cf14d52015-07-16 12:15:19 -07002159 startTime = time.time()
2160 # Give time for Gossip to work
Jon Halle9b1fa32015-12-08 15:32:21 -08002161 while topoResult == main.FALSE and ( elapsed < 60 or count < 3 ):
Jon Hallba609822015-09-18 12:00:21 -07002162 devicesResults = main.TRUE
2163 linksResults = main.TRUE
2164 hostsResults = main.TRUE
2165 hostAttachmentResults = True
Jon Hall5cf14d52015-07-16 12:15:19 -07002166 count += 1
2167 cliStart = time.time()
2168 devices = []
2169 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002170 for i in range( main.numCtrls ):
2171 t = main.Thread( target=main.CLIs[i].devices,
Jon Hall5cf14d52015-07-16 12:15:19 -07002172 name="devices-" + str( i ),
2173 args=[ ] )
2174 threads.append( t )
2175 t.start()
2176
2177 for t in threads:
2178 t.join()
2179 devices.append( t.result )
2180 hosts = []
2181 ipResult = main.TRUE
2182 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002183 for i in range( main.numCtrls ):
2184 t = main.Thread( target=main.CLIs[i].hosts,
Jon Hall5cf14d52015-07-16 12:15:19 -07002185 name="hosts-" + str( i ),
2186 args=[ ] )
2187 threads.append( t )
2188 t.start()
2189
2190 for t in threads:
2191 t.join()
2192 try:
2193 hosts.append( json.loads( t.result ) )
2194 except ( ValueError, TypeError ):
2195 main.log.exception( "Error parsing hosts results" )
2196 main.log.error( repr( t.result ) )
Jon Hall3afe4c92015-12-14 19:30:38 -08002197 hosts.append( None )
Jon Hall5cf14d52015-07-16 12:15:19 -07002198 for controller in range( 0, len( hosts ) ):
2199 controllerStr = str( controller + 1 )
Jon Hallacd1b182015-12-17 11:43:20 -08002200 if hosts[ controller ]:
2201 for host in hosts[ controller ]:
2202 if host is None or host.get( 'ipAddresses', [] ) == []:
2203 main.log.error(
2204 "Error with host ipAddresses on controller" +
2205 controllerStr + ": " + str( host ) )
2206 ipResult = main.FALSE
Jon Hall5cf14d52015-07-16 12:15:19 -07002207 ports = []
2208 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002209 for i in range( main.numCtrls ):
2210 t = main.Thread( target=main.CLIs[i].ports,
Jon Hall5cf14d52015-07-16 12:15:19 -07002211 name="ports-" + str( i ),
2212 args=[ ] )
2213 threads.append( t )
2214 t.start()
2215
2216 for t in threads:
2217 t.join()
2218 ports.append( t.result )
2219 links = []
2220 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002221 for i in range( main.numCtrls ):
2222 t = main.Thread( target=main.CLIs[i].links,
Jon Hall5cf14d52015-07-16 12:15:19 -07002223 name="links-" + str( i ),
2224 args=[ ] )
2225 threads.append( t )
2226 t.start()
2227
2228 for t in threads:
2229 t.join()
2230 links.append( t.result )
2231 clusters = []
2232 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002233 for i in range( main.numCtrls ):
2234 t = main.Thread( target=main.CLIs[i].clusters,
Jon Hall5cf14d52015-07-16 12:15:19 -07002235 name="clusters-" + str( i ),
2236 args=[ ] )
2237 threads.append( t )
2238 t.start()
2239
2240 for t in threads:
2241 t.join()
2242 clusters.append( t.result )
2243
2244 elapsed = time.time() - startTime
2245 cliTime = time.time() - cliStart
2246 print "Elapsed time: " + str( elapsed )
2247 print "CLI time: " + str( cliTime )
2248
2249 mnSwitches = main.Mininet1.getSwitches()
2250 mnLinks = main.Mininet1.getLinks()
2251 mnHosts = main.Mininet1.getHosts()
Jon Halle1a3b752015-07-22 13:02:46 -07002252 for controller in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07002253 controllerStr = str( controller + 1 )
2254 if devices[ controller ] and ports[ controller ] and\
2255 "Error" not in devices[ controller ] and\
2256 "Error" not in ports[ controller ]:
2257
2258 currentDevicesResult = main.Mininet1.compareSwitches(
2259 mnSwitches,
2260 json.loads( devices[ controller ] ),
2261 json.loads( ports[ controller ] ) )
2262 else:
2263 currentDevicesResult = main.FALSE
2264 utilities.assert_equals( expect=main.TRUE,
2265 actual=currentDevicesResult,
2266 onpass="ONOS" + controllerStr +
2267 " Switches view is correct",
2268 onfail="ONOS" + controllerStr +
2269 " Switches view is incorrect" )
2270
2271 if links[ controller ] and "Error" not in links[ controller ]:
2272 currentLinksResult = main.Mininet1.compareLinks(
2273 mnSwitches, mnLinks,
2274 json.loads( links[ controller ] ) )
2275 else:
2276 currentLinksResult = main.FALSE
2277 utilities.assert_equals( expect=main.TRUE,
2278 actual=currentLinksResult,
2279 onpass="ONOS" + controllerStr +
2280 " links view is correct",
2281 onfail="ONOS" + controllerStr +
2282 " links view is incorrect" )
2283
2284 if hosts[ controller ] or "Error" not in hosts[ controller ]:
2285 currentHostsResult = main.Mininet1.compareHosts(
2286 mnHosts,
2287 hosts[ controller ] )
2288 else:
2289 currentHostsResult = main.FALSE
2290 utilities.assert_equals( expect=main.TRUE,
2291 actual=currentHostsResult,
2292 onpass="ONOS" + controllerStr +
2293 " hosts exist in Mininet",
2294 onfail="ONOS" + controllerStr +
2295 " hosts don't match Mininet" )
2296 # CHECKING HOST ATTACHMENT POINTS
2297 hostAttachment = True
2298 noHosts = False
2299 # FIXME: topo-HA/obelisk specific mappings:
2300 # key is mac and value is dpid
2301 mappings = {}
2302 for i in range( 1, 29 ): # hosts 1 through 28
2303 # set up correct variables:
2304 macId = "00:" * 5 + hex( i ).split( "0x" )[1].upper().zfill(2)
2305 if i == 1:
2306 deviceId = "1000".zfill(16)
2307 elif i == 2:
2308 deviceId = "2000".zfill(16)
2309 elif i == 3:
2310 deviceId = "3000".zfill(16)
2311 elif i == 4:
2312 deviceId = "3004".zfill(16)
2313 elif i == 5:
2314 deviceId = "5000".zfill(16)
2315 elif i == 6:
2316 deviceId = "6000".zfill(16)
2317 elif i == 7:
2318 deviceId = "6007".zfill(16)
2319 elif i >= 8 and i <= 17:
2320 dpid = '3' + str( i ).zfill( 3 )
2321 deviceId = dpid.zfill(16)
2322 elif i >= 18 and i <= 27:
2323 dpid = '6' + str( i ).zfill( 3 )
2324 deviceId = dpid.zfill(16)
2325 elif i == 28:
2326 deviceId = "2800".zfill(16)
2327 mappings[ macId ] = deviceId
2328 if hosts[ controller ] or "Error" not in hosts[ controller ]:
2329 if hosts[ controller ] == []:
2330 main.log.warn( "There are no hosts discovered" )
2331 noHosts = True
2332 else:
2333 for host in hosts[ controller ]:
2334 mac = None
2335 location = None
2336 device = None
2337 port = None
2338 try:
2339 mac = host.get( 'mac' )
2340 assert mac, "mac field could not be found for this host object"
2341
2342 location = host.get( 'location' )
2343 assert location, "location field could not be found for this host object"
2344
2345 # Trim the protocol identifier off deviceId
2346 device = str( location.get( 'elementId' ) ).split(':')[1]
2347 assert device, "elementId field could not be found for this host location object"
2348
2349 port = location.get( 'port' )
2350 assert port, "port field could not be found for this host location object"
2351
2352 # Now check if this matches where they should be
2353 if mac and device and port:
2354 if str( port ) != "1":
2355 main.log.error( "The attachment port is incorrect for " +
2356 "host " + str( mac ) +
2357 ". Expected: 1 Actual: " + str( port) )
2358 hostAttachment = False
2359 if device != mappings[ str( mac ) ]:
2360 main.log.error( "The attachment device is incorrect for " +
2361 "host " + str( mac ) +
2362 ". Expected: " + mappings[ str( mac ) ] +
2363 " Actual: " + device )
2364 hostAttachment = False
2365 else:
2366 hostAttachment = False
2367 except AssertionError:
2368 main.log.exception( "Json object not as expected" )
2369 main.log.error( repr( host ) )
2370 hostAttachment = False
2371 else:
2372 main.log.error( "No hosts json output or \"Error\"" +
2373 " in output. hosts = " +
2374 repr( hosts[ controller ] ) )
2375 if noHosts is False:
2376 # TODO: Find a way to know if there should be hosts in a
2377 # given point of the test
2378 hostAttachment = True
2379
2380 # END CHECKING HOST ATTACHMENT POINTS
2381 devicesResults = devicesResults and currentDevicesResult
2382 linksResults = linksResults and currentLinksResult
2383 hostsResults = hostsResults and currentHostsResult
2384 hostAttachmentResults = hostAttachmentResults and\
2385 hostAttachment
2386 topoResult = ( devicesResults and linksResults
2387 and hostsResults and ipResult and
2388 hostAttachmentResults )
Jon Halle9b1fa32015-12-08 15:32:21 -08002389 utilities.assert_equals( expect=True,
2390 actual=topoResult,
2391 onpass="ONOS topology matches Mininet",
2392 onfail="ONOS topology don't match Mininet" )
2393 # End of While loop to pull ONOS state
Jon Hall5cf14d52015-07-16 12:15:19 -07002394
2395 # Compare json objects for hosts and dataplane clusters
2396
2397 # hosts
2398 main.step( "Hosts view is consistent across all ONOS nodes" )
2399 consistentHostsResult = main.TRUE
2400 for controller in range( len( hosts ) ):
2401 controllerStr = str( controller + 1 )
Jon Hall3afe4c92015-12-14 19:30:38 -08002402 if hosts[ controller ] or "Error" not in hosts[ controller ]:
Jon Hall5cf14d52015-07-16 12:15:19 -07002403 if hosts[ controller ] == hosts[ 0 ]:
2404 continue
2405 else: # hosts not consistent
2406 main.log.error( "hosts from ONOS" + controllerStr +
2407 " is inconsistent with ONOS1" )
2408 main.log.warn( repr( hosts[ controller ] ) )
2409 consistentHostsResult = main.FALSE
2410
2411 else:
2412 main.log.error( "Error in getting ONOS hosts from ONOS" +
2413 controllerStr )
2414 consistentHostsResult = main.FALSE
2415 main.log.warn( "ONOS" + controllerStr +
2416 " hosts response: " +
2417 repr( hosts[ controller ] ) )
2418 utilities.assert_equals(
2419 expect=main.TRUE,
2420 actual=consistentHostsResult,
2421 onpass="Hosts view is consistent across all ONOS nodes",
2422 onfail="ONOS nodes have different views of hosts" )
2423
2424 main.step( "Hosts information is correct" )
2425 hostsResults = hostsResults and ipResult
2426 utilities.assert_equals(
2427 expect=main.TRUE,
2428 actual=hostsResults,
2429 onpass="Host information is correct",
2430 onfail="Host information is incorrect" )
2431
2432 main.step( "Host attachment points to the network" )
2433 utilities.assert_equals(
2434 expect=True,
2435 actual=hostAttachmentResults,
2436 onpass="Hosts are correctly attached to the network",
2437 onfail="ONOS did not correctly attach hosts to the network" )
2438
2439 # Strongly connected clusters of devices
2440 main.step( "Clusters view is consistent across all ONOS nodes" )
2441 consistentClustersResult = main.TRUE
2442 for controller in range( len( clusters ) ):
2443 controllerStr = str( controller + 1 )
2444 if "Error" not in clusters[ controller ]:
2445 if clusters[ controller ] == clusters[ 0 ]:
2446 continue
2447 else: # clusters not consistent
2448 main.log.error( "clusters from ONOS" +
2449 controllerStr +
2450 " is inconsistent with ONOS1" )
2451 consistentClustersResult = main.FALSE
2452
2453 else:
2454 main.log.error( "Error in getting dataplane clusters " +
2455 "from ONOS" + controllerStr )
2456 consistentClustersResult = main.FALSE
2457 main.log.warn( "ONOS" + controllerStr +
2458 " clusters response: " +
2459 repr( clusters[ controller ] ) )
2460 utilities.assert_equals(
2461 expect=main.TRUE,
2462 actual=consistentClustersResult,
2463 onpass="Clusters view is consistent across all ONOS nodes",
2464 onfail="ONOS nodes have different views of clusters" )
2465
2466 main.step( "There is only one SCC" )
2467 # there should always only be one cluster
2468 try:
2469 numClusters = len( json.loads( clusters[ 0 ] ) )
2470 except ( ValueError, TypeError ):
2471 main.log.exception( "Error parsing clusters[0]: " +
2472 repr( clusters[0] ) )
2473 clusterResults = main.FALSE
2474 if numClusters == 1:
2475 clusterResults = main.TRUE
2476 utilities.assert_equals(
2477 expect=1,
2478 actual=numClusters,
2479 onpass="ONOS shows 1 SCC",
2480 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
2481
2482 topoResult = ( devicesResults and linksResults
2483 and hostsResults and consistentHostsResult
2484 and consistentClustersResult and clusterResults
2485 and ipResult and hostAttachmentResults )
2486
2487 topoResult = topoResult and int( count <= 2 )
2488 note = "note it takes about " + str( int( cliTime ) ) + \
2489 " seconds for the test to make all the cli calls to fetch " +\
2490 "the topology from each ONOS instance"
2491 main.log.info(
2492 "Very crass estimate for topology discovery/convergence( " +
2493 str( note ) + " ): " + str( elapsed ) + " seconds, " +
2494 str( count ) + " tries" )
2495
2496 main.step( "Device information is correct" )
2497 utilities.assert_equals(
2498 expect=main.TRUE,
2499 actual=devicesResults,
2500 onpass="Device information is correct",
2501 onfail="Device information is incorrect" )
2502
2503 main.step( "Links are correct" )
2504 utilities.assert_equals(
2505 expect=main.TRUE,
2506 actual=linksResults,
2507 onpass="Link are correct",
2508 onfail="Links are incorrect" )
2509
2510 # FIXME: move this to an ONOS state case
2511 main.step( "Checking ONOS nodes" )
2512 nodesOutput = []
2513 nodeResults = main.TRUE
2514 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002515 for i in range( main.numCtrls ):
2516 t = main.Thread( target=main.CLIs[i].nodes,
Jon Hall5cf14d52015-07-16 12:15:19 -07002517 name="nodes-" + str( i ),
2518 args=[ ] )
2519 threads.append( t )
2520 t.start()
2521
2522 for t in threads:
2523 t.join()
2524 nodesOutput.append( t.result )
Jon Halle1a3b752015-07-22 13:02:46 -07002525 ips = [ node.ip_address for node in main.nodes ]
Jon Halle9b1fa32015-12-08 15:32:21 -08002526 ips.sort()
Jon Hall5cf14d52015-07-16 12:15:19 -07002527 for i in nodesOutput:
2528 try:
2529 current = json.loads( i )
Jon Halle9b1fa32015-12-08 15:32:21 -08002530 activeIps = []
2531 currentResult = main.FALSE
Jon Hall5cf14d52015-07-16 12:15:19 -07002532 for node in current:
Jon Halle9b1fa32015-12-08 15:32:21 -08002533 if node['state'] == 'ACTIVE':
2534 activeIps.append( node['ip'] )
2535 activeIps.sort()
2536 if ips == activeIps:
2537 currentResult = main.TRUE
Jon Hall5cf14d52015-07-16 12:15:19 -07002538 except ( ValueError, TypeError ):
2539 main.log.error( "Error parsing nodes output" )
2540 main.log.warn( repr( i ) )
Jon Halle9b1fa32015-12-08 15:32:21 -08002541 currentResult = main.FALSE
2542 nodeResults = nodeResults and currentResult
Jon Hall5cf14d52015-07-16 12:15:19 -07002543 utilities.assert_equals( expect=main.TRUE, actual=nodeResults,
2544 onpass="Nodes check successful",
2545 onfail="Nodes check NOT successful" )
2546
2547 def CASE9( self, main ):
2548 """
2549 Link s3-s28 down
2550 """
2551 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002552 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002553 assert main, "main not defined"
2554 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002555 assert main.CLIs, "main.CLIs not defined"
2556 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002557 # NOTE: You should probably run a topology check after this
2558
2559 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
2560
2561 description = "Turn off a link to ensure that Link Discovery " +\
2562 "is working properly"
2563 main.case( description )
2564
2565 main.step( "Kill Link between s3 and s28" )
2566 LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" )
2567 main.log.info( "Waiting " + str( linkSleep ) +
2568 " seconds for link down to be discovered" )
2569 time.sleep( linkSleep )
2570 utilities.assert_equals( expect=main.TRUE, actual=LinkDown,
2571 onpass="Link down successful",
2572 onfail="Failed to bring link down" )
2573 # TODO do some sort of check here
2574
2575 def CASE10( self, main ):
2576 """
2577 Link s3-s28 up
2578 """
2579 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002580 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002581 assert main, "main not defined"
2582 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002583 assert main.CLIs, "main.CLIs not defined"
2584 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002585 # NOTE: You should probably run a topology check after this
2586
2587 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
2588
2589 description = "Restore a link to ensure that Link Discovery is " + \
2590 "working properly"
2591 main.case( description )
2592
2593 main.step( "Bring link between s3 and s28 back up" )
2594 LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" )
2595 main.log.info( "Waiting " + str( linkSleep ) +
2596 " seconds for link up to be discovered" )
2597 time.sleep( linkSleep )
2598 utilities.assert_equals( expect=main.TRUE, actual=LinkUp,
2599 onpass="Link up successful",
2600 onfail="Failed to bring link up" )
2601 # TODO do some sort of check here
2602
2603 def CASE11( self, main ):
2604 """
2605 Switch Down
2606 """
2607 # NOTE: You should probably run a topology check after this
2608 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002609 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002610 assert main, "main not defined"
2611 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002612 assert main.CLIs, "main.CLIs not defined"
2613 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002614
2615 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
2616
2617 description = "Killing a switch to ensure it is discovered correctly"
2618 main.case( description )
2619 switch = main.params[ 'kill' ][ 'switch' ]
2620 switchDPID = main.params[ 'kill' ][ 'dpid' ]
2621
2622 # TODO: Make this switch parameterizable
2623 main.step( "Kill " + switch )
2624 main.log.info( "Deleting " + switch )
2625 main.Mininet1.delSwitch( switch )
2626 main.log.info( "Waiting " + str( switchSleep ) +
2627 " seconds for switch down to be discovered" )
2628 time.sleep( switchSleep )
2629 device = main.ONOScli1.getDevice( dpid=switchDPID )
2630 # Peek at the deleted switch
2631 main.log.warn( str( device ) )
2632 result = main.FALSE
2633 if device and device[ 'available' ] is False:
2634 result = main.TRUE
2635 utilities.assert_equals( expect=main.TRUE, actual=result,
2636 onpass="Kill switch successful",
2637 onfail="Failed to kill switch?" )
2638
2639 def CASE12( self, main ):
2640 """
2641 Switch Up
2642 """
2643 # NOTE: You should probably run a topology check after this
2644 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002645 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002646 assert main, "main not defined"
2647 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002648 assert main.CLIs, "main.CLIs not defined"
2649 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002650 assert ONOS1Port, "ONOS1Port not defined"
2651 assert ONOS2Port, "ONOS2Port not defined"
2652 assert ONOS3Port, "ONOS3Port not defined"
2653 assert ONOS4Port, "ONOS4Port not defined"
2654 assert ONOS5Port, "ONOS5Port not defined"
2655 assert ONOS6Port, "ONOS6Port not defined"
2656 assert ONOS7Port, "ONOS7Port not defined"
2657
2658 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
2659 switch = main.params[ 'kill' ][ 'switch' ]
2660 switchDPID = main.params[ 'kill' ][ 'dpid' ]
2661 links = main.params[ 'kill' ][ 'links' ].split()
2662 description = "Adding a switch to ensure it is discovered correctly"
2663 main.case( description )
2664
2665 main.step( "Add back " + switch )
2666 main.Mininet1.addSwitch( switch, dpid=switchDPID )
2667 for peer in links:
2668 main.Mininet1.addLink( switch, peer )
2669 ipList = []
Jon Halle1a3b752015-07-22 13:02:46 -07002670 for i in range( main.numCtrls ):
2671 ipList.append( main.nodes[ i ].ip_address )
Jon Hall5cf14d52015-07-16 12:15:19 -07002672 main.Mininet1.assignSwController( sw=switch, ip=ipList )
2673 main.log.info( "Waiting " + str( switchSleep ) +
2674 " seconds for switch up to be discovered" )
2675 time.sleep( switchSleep )
2676 device = main.ONOScli1.getDevice( dpid=switchDPID )
2677 # Peek at the deleted switch
2678 main.log.warn( str( device ) )
2679 result = main.FALSE
2680 if device and device[ 'available' ]:
2681 result = main.TRUE
2682 utilities.assert_equals( expect=main.TRUE, actual=result,
2683 onpass="add switch successful",
2684 onfail="Failed to add switch?" )
2685
2686 def CASE13( self, main ):
2687 """
2688 Clean up
2689 """
2690 import os
2691 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002692 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002693 assert main, "main not defined"
2694 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002695 assert main.CLIs, "main.CLIs not defined"
2696 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002697
2698 # printing colors to terminal
2699 colors = { 'cyan': '\033[96m', 'purple': '\033[95m',
2700 'blue': '\033[94m', 'green': '\033[92m',
2701 'yellow': '\033[93m', 'red': '\033[91m', 'end': '\033[0m' }
2702 main.case( "Test Cleanup" )
2703 main.step( "Killing tcpdumps" )
2704 main.Mininet2.stopTcpdump()
2705
2706 testname = main.TEST
Jon Hall5ec6b1b2015-09-17 18:20:14 -07002707 if main.params[ 'BACKUP' ][ 'ENABLED' ] == "True":
Jon Hall5cf14d52015-07-16 12:15:19 -07002708 main.step( "Copying MN pcap and ONOS log files to test station" )
2709 teststationUser = main.params[ 'BACKUP' ][ 'TESTONUSER' ]
2710 teststationIP = main.params[ 'BACKUP' ][ 'TESTONIP' ]
Jon Hall96091e62015-09-21 17:34:17 -07002711 # NOTE: MN Pcap file is being saved to logdir.
2712 # We scp this file as MN and TestON aren't necessarily the same vm
2713
2714 # FIXME: To be replaced with a Jenkin's post script
Jon Hall5cf14d52015-07-16 12:15:19 -07002715 # TODO: Load these from params
2716 # NOTE: must end in /
2717 logFolder = "/opt/onos/log/"
2718 logFiles = [ "karaf.log", "karaf.log.1" ]
2719 # NOTE: must end in /
Jon Hall5cf14d52015-07-16 12:15:19 -07002720 for f in logFiles:
Jon Halle1a3b752015-07-22 13:02:46 -07002721 for node in main.nodes:
Jon Hall96091e62015-09-21 17:34:17 -07002722 dstName = main.logdir + "/" + node.name + "-" + f
2723 main.ONOSbench.secureCopy( node.user_name, node.ip_address,
2724 logFolder + f, dstName )
Jon Hall5cf14d52015-07-16 12:15:19 -07002725 # std*.log's
2726 # NOTE: must end in /
2727 logFolder = "/opt/onos/var/"
2728 logFiles = [ "stderr.log", "stdout.log" ]
2729 # NOTE: must end in /
Jon Hall5cf14d52015-07-16 12:15:19 -07002730 for f in logFiles:
Jon Halle1a3b752015-07-22 13:02:46 -07002731 for node in main.nodes:
Jon Hall96091e62015-09-21 17:34:17 -07002732 dstName = main.logdir + "/" + node.name + "-" + f
2733 main.ONOSbench.secureCopy( node.user_name, node.ip_address,
2734 logFolder + f, dstName )
Jon Hall5ec6b1b2015-09-17 18:20:14 -07002735 else:
2736 main.log.debug( "skipping saving log files" )
Jon Hall5cf14d52015-07-16 12:15:19 -07002737
2738 main.step( "Stopping Mininet" )
2739 mnResult = main.Mininet1.stopNet()
2740 utilities.assert_equals( expect=main.TRUE, actual=mnResult,
2741 onpass="Mininet stopped",
2742 onfail="MN cleanup NOT successful" )
2743
2744 main.step( "Checking ONOS Logs for errors" )
Jon Halle1a3b752015-07-22 13:02:46 -07002745 for node in main.nodes:
Jon Hall5ec6b1b2015-09-17 18:20:14 -07002746 main.log.debug( "Checking logs for errors on " + node.name + ":" )
2747 main.log.warn( main.ONOSbench.checkLogs( node.ip_address ) )
Jon Hall5cf14d52015-07-16 12:15:19 -07002748
2749 try:
2750 timerLog = open( main.logdir + "/Timers.csv", 'w')
2751 main.log.error( ", ".join( labels ) + "\n" + ", ".join( data ) )
2752 timerLog.write( ", ".join( labels ) + "\n" + ", ".join( data ) )
2753 timerLog.close()
2754 except NameError, e:
2755 main.log.exception(e)
2756
2757 def CASE14( self, main ):
2758 """
2759 start election app on all onos nodes
2760 """
Jon Halle1a3b752015-07-22 13:02:46 -07002761 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002762 assert main, "main not defined"
2763 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002764 assert main.CLIs, "main.CLIs not defined"
2765 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002766
2767 main.case("Start Leadership Election app")
2768 main.step( "Install leadership election app" )
2769 appResult = main.ONOScli1.activateApp( "org.onosproject.election" )
2770 utilities.assert_equals(
2771 expect=main.TRUE,
2772 actual=appResult,
2773 onpass="Election app installed",
2774 onfail="Something went wrong with installing Leadership election" )
2775
2776 main.step( "Run for election on each node" )
2777 leaderResult = main.TRUE
2778 leaders = []
Jon Halle1a3b752015-07-22 13:02:46 -07002779 for cli in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -07002780 cli.electionTestRun()
Jon Halle1a3b752015-07-22 13:02:46 -07002781 for cli in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -07002782 leader = cli.electionTestLeader()
2783 if leader is None or leader == main.FALSE:
2784 main.log.error( cli.name + ": Leader for the election app " +
2785 "should be an ONOS node, instead got '" +
2786 str( leader ) + "'" )
2787 leaderResult = main.FALSE
2788 leaders.append( leader )
2789 utilities.assert_equals(
2790 expect=main.TRUE,
2791 actual=leaderResult,
2792 onpass="Successfully ran for leadership",
2793 onfail="Failed to run for leadership" )
2794
2795 main.step( "Check that each node shows the same leader" )
2796 sameLeader = main.TRUE
2797 if len( set( leaders ) ) != 1:
2798 sameLeader = main.FALSE
2799 main.log.error( "Results of electionTestLeader is order of CLIs:" +
2800 str( leaders ) )
2801 utilities.assert_equals(
2802 expect=main.TRUE,
2803 actual=sameLeader,
2804 onpass="Leadership is consistent for the election topic",
2805 onfail="Nodes have different leaders" )
2806
2807 def CASE15( self, main ):
2808 """
2809 Check that Leadership Election is still functional
acsmars9475b1c2015-08-28 18:02:08 -07002810 15.1 Run election on each node
2811 15.2 Check that each node has the same leaders and candidates
2812 15.3 Find current leader and withdraw
2813 15.4 Check that a new node was elected leader
2814 15.5 Check that that new leader was the candidate of old leader
2815 15.6 Run for election on old leader
2816 15.7 Check that oldLeader is a candidate, and leader if only 1 node
2817 15.8 Make sure that the old leader was added to the candidate list
2818
2819 old and new variable prefixes refer to data from before vs after
2820 withdrawl and later before withdrawl vs after re-election
Jon Hall5cf14d52015-07-16 12:15:19 -07002821 """
2822 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002823 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002824 assert main, "main not defined"
2825 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002826 assert main.CLIs, "main.CLIs not defined"
2827 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002828
Jon Hall5cf14d52015-07-16 12:15:19 -07002829 description = "Check that Leadership Election is still functional"
2830 main.case( description )
2831 # NOTE: Need to re-run since being a canidate is not persistant
acsmars9475b1c2015-08-28 18:02:08 -07002832 # TODO: add check for "Command not found:" in the driver, this
2833 # means the election test app isn't loaded
2834
2835 oldLeaders = [] # leaders by node before withdrawl from candidates
2836 newLeaders = [] # leaders by node after withdrawl from candidates
2837 oldAllCandidates = [] # list of lists of each nodes' candidates before
2838 newAllCandidates = [] # list of lists of each nodes' candidates after
2839 oldCandidates = [] # list of candidates from node 0 before withdrawl
2840 newCandidates = [] # list of candidates from node 0 after withdrawl
2841 oldLeader = '' # the old leader from oldLeaders, None if not same
2842 newLeader = '' # the new leaders fron newLoeaders, None if not same
2843 oldLeaderCLI = None # the CLI of the old leader used for re-electing
acsmars71adceb2015-08-31 15:09:26 -07002844 expectNoLeader = False # True when there is only one leader
2845 if main.numCtrls == 1:
2846 expectNoLeader = True
acsmars9475b1c2015-08-28 18:02:08 -07002847
Jon Hall5cf14d52015-07-16 12:15:19 -07002848 main.step( "Run for election on each node" )
acsmars9475b1c2015-08-28 18:02:08 -07002849 electionResult = main.TRUE
2850
2851 for cli in main.CLIs: # run test election on each node
2852 if cli.electionTestRun() == main.FALSE:
2853 electionResult = main.FALSE
2854
Jon Hall5cf14d52015-07-16 12:15:19 -07002855 utilities.assert_equals(
2856 expect=main.TRUE,
acsmars9475b1c2015-08-28 18:02:08 -07002857 actual=electionResult,
2858 onpass="All nodes successfully ran for leadership",
2859 onfail="At least one node failed to run for leadership" )
Jon Hall5cf14d52015-07-16 12:15:19 -07002860
acsmars3a72bde2015-09-02 14:16:22 -07002861 if electionResult == main.FALSE:
2862 main.log.error(
2863 "Skipping Test Case because Election Test App isn't loaded" )
2864 main.skipCase()
2865
acsmars9475b1c2015-08-28 18:02:08 -07002866 main.step( "Check that each node shows the same leader and candidates" )
2867 sameResult = main.TRUE
2868 failMessage = "Nodes have different leaders"
2869 for cli in main.CLIs:
2870 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
2871 oldAllCandidates.append( node )
2872 oldLeaders.append( node[ 0 ] )
2873 oldCandidates = oldAllCandidates[ 0 ]
2874
2875 # Check that each node has the same leader. Defines oldLeader
2876 if len( set( oldLeaders ) ) != 1:
2877 sameResult = main.FALSE
acsmars71adceb2015-08-31 15:09:26 -07002878 main.log.error( "More than one leader present:" + str( oldLeaders ) )
acsmars9475b1c2015-08-28 18:02:08 -07002879 oldLeader = None
2880 else:
2881 oldLeader = oldLeaders[ 0 ]
2882
2883 # Check that each node's candidate list is the same
acsmars29233db2015-11-04 11:15:00 -08002884 candidateDiscrepancy = False # Boolean of candidate mismatches
acsmars9475b1c2015-08-28 18:02:08 -07002885 for candidates in oldAllCandidates:
2886 if set( candidates ) != set( oldCandidates ):
2887 sameResult = main.FALSE
acsmars29233db2015-11-04 11:15:00 -08002888 candidateDiscrepancy = True
2889
2890 if candidateDiscrepancy:
2891 failMessage += " and candidates"
acsmars9475b1c2015-08-28 18:02:08 -07002892
Jon Hall5cf14d52015-07-16 12:15:19 -07002893 utilities.assert_equals(
2894 expect=main.TRUE,
acsmars71adceb2015-08-31 15:09:26 -07002895 actual=sameResult,
Jon Hall5cf14d52015-07-16 12:15:19 -07002896 onpass="Leadership is consistent for the election topic",
acsmars9475b1c2015-08-28 18:02:08 -07002897 onfail=failMessage )
Jon Hall5cf14d52015-07-16 12:15:19 -07002898
2899 main.step( "Find current leader and withdraw" )
acsmars9475b1c2015-08-28 18:02:08 -07002900 withdrawResult = main.TRUE
Jon Hall5cf14d52015-07-16 12:15:19 -07002901 # do some sanity checking on leader before using it
acsmars9475b1c2015-08-28 18:02:08 -07002902 if oldLeader is None:
2903 main.log.error( "Leadership isn't consistent." )
2904 withdrawResult = main.FALSE
2905 # Get the CLI of the oldLeader
Jon Halle1a3b752015-07-22 13:02:46 -07002906 for i in range( len( main.CLIs ) ):
acsmars9475b1c2015-08-28 18:02:08 -07002907 if oldLeader == main.nodes[ i ].ip_address:
2908 oldLeaderCLI = main.CLIs[ i ]
Jon Hall5cf14d52015-07-16 12:15:19 -07002909 break
2910 else: # FOR/ELSE statement
2911 main.log.error( "Leader election, could not find current leader" )
2912 if oldLeader:
acsmars9475b1c2015-08-28 18:02:08 -07002913 withdrawResult = oldLeaderCLI.electionTestWithdraw()
Jon Hall5cf14d52015-07-16 12:15:19 -07002914 utilities.assert_equals(
2915 expect=main.TRUE,
2916 actual=withdrawResult,
2917 onpass="Node was withdrawn from election",
2918 onfail="Node was not withdrawn from election" )
2919
acsmars9475b1c2015-08-28 18:02:08 -07002920 main.step( "Check that a new node was elected leader" )
acsmars71adceb2015-08-31 15:09:26 -07002921
Jon Hall5cf14d52015-07-16 12:15:19 -07002922 # FIXME: use threads
acsmars9475b1c2015-08-28 18:02:08 -07002923 newLeaderResult = main.TRUE
2924 failMessage = "Nodes have different leaders"
2925
2926 # Get new leaders and candidates
Jon Halle1a3b752015-07-22 13:02:46 -07002927 for cli in main.CLIs:
acsmars9475b1c2015-08-28 18:02:08 -07002928 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
acsmars71adceb2015-08-31 15:09:26 -07002929 # elections might no have finished yet
2930 if node[ 0 ] == 'none' and not expectNoLeader:
acsmars9475b1c2015-08-28 18:02:08 -07002931 main.log.info( "Node has no leader, waiting 5 seconds to be " +
2932 "sure elections are complete." )
2933 time.sleep(5)
2934 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
acsmars71adceb2015-08-31 15:09:26 -07002935 # election still isn't done or there is a problem
2936 if node[ 0 ] == 'none':
2937 main.log.error( "No leader was elected on at least 1 node" )
2938 newLeaderResult = main.FALSE
acsmars9475b1c2015-08-28 18:02:08 -07002939 newAllCandidates.append( node )
2940 newLeaders.append( node[ 0 ] )
2941 newCandidates = newAllCandidates[ 0 ]
2942
2943 # Check that each node has the same leader. Defines newLeader
2944 if len( set( newLeaders ) ) != 1:
2945 newLeaderResult = main.FALSE
2946 main.log.error( "Nodes have different leaders: " +
2947 str( newLeaders ) )
2948 newLeader = None
Jon Hall5cf14d52015-07-16 12:15:19 -07002949 else:
acsmars9475b1c2015-08-28 18:02:08 -07002950 newLeader = newLeaders[ 0 ]
2951
acsmars71adceb2015-08-31 15:09:26 -07002952 # Check that each node's candidate list is the same
2953 for candidates in newAllCandidates:
2954 if set( candidates ) != set( newCandidates ):
2955 newLeaderResult = main.FALSE
Jon Hallceb4abb2015-09-25 12:03:06 -07002956 main.log.error( "Discrepancy in candidate lists detected" )
acsmars71adceb2015-08-31 15:09:26 -07002957
acsmars9475b1c2015-08-28 18:02:08 -07002958 # Check that the new leader is not the older leader, which was withdrawn
2959 if newLeader == oldLeader:
2960 newLeaderResult = main.FALSE
2961 main.log.error( "All nodes still see old leader: " + oldLeader +
2962 " as the current leader" )
2963
Jon Hall5cf14d52015-07-16 12:15:19 -07002964 utilities.assert_equals(
2965 expect=main.TRUE,
acsmars9475b1c2015-08-28 18:02:08 -07002966 actual=newLeaderResult,
Jon Hall5cf14d52015-07-16 12:15:19 -07002967 onpass="Leadership election passed",
2968 onfail="Something went wrong with Leadership election" )
2969
acsmars9475b1c2015-08-28 18:02:08 -07002970 main.step( "Check that that new leader was the candidate of old leader")
2971 # candidates[ 2 ] should be come the top candidate after withdrawl
2972 correctCandidateResult = main.TRUE
acsmars71adceb2015-08-31 15:09:26 -07002973 if expectNoLeader:
2974 if newLeader == 'none':
2975 main.log.info( "No leader expected. None found. Pass" )
2976 correctCandidateResult = main.TRUE
2977 else:
2978 main.log.info( "Expected no leader, got: " + str( newLeader ) )
2979 correctCandidateResult = main.FALSE
2980 elif newLeader != oldCandidates[ 2 ]:
acsmars9475b1c2015-08-28 18:02:08 -07002981 correctCandidateResult = main.FALSE
2982 main.log.error( "Candidate " + newLeader + " was elected. " +
2983 oldCandidates[ 2 ] + " should have had priority." )
2984
2985 utilities.assert_equals(
2986 expect=main.TRUE,
2987 actual=correctCandidateResult,
2988 onpass="Correct Candidate Elected",
2989 onfail="Incorrect Candidate Elected" )
2990
Jon Hall5cf14d52015-07-16 12:15:19 -07002991 main.step( "Run for election on old leader( just so everyone " +
2992 "is in the hat )" )
acsmars9475b1c2015-08-28 18:02:08 -07002993 if oldLeaderCLI is not None:
2994 runResult = oldLeaderCLI.electionTestRun()
Jon Hall5cf14d52015-07-16 12:15:19 -07002995 else:
acsmars9475b1c2015-08-28 18:02:08 -07002996 main.log.error( "No old leader to re-elect" )
Jon Hall5cf14d52015-07-16 12:15:19 -07002997 runResult = main.FALSE
2998 utilities.assert_equals(
2999 expect=main.TRUE,
3000 actual=runResult,
3001 onpass="App re-ran for election",
3002 onfail="App failed to run for election" )
acsmars9475b1c2015-08-28 18:02:08 -07003003 main.step(
3004 "Check that oldLeader is a candidate, and leader if only 1 node" )
Jon Hall5cf14d52015-07-16 12:15:19 -07003005 # verify leader didn't just change
acsmars9475b1c2015-08-28 18:02:08 -07003006 positionResult = main.TRUE
3007 # Get new leaders and candidates, wait if oldLeader is not a candidate yet
3008
3009 # Reset and reuse the new candidate and leaders lists
3010 newAllCandidates = []
3011 newCandidates = []
3012 newLeaders = []
3013 for cli in main.CLIs:
3014 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
3015 if oldLeader not in node: # election might no have finished yet
3016 main.log.info( "Old Leader not elected, waiting 5 seconds to " +
3017 "be sure elections are complete" )
3018 time.sleep(5)
3019 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
3020 if oldLeader not in node: # election still isn't done, errors
3021 main.log.error(
3022 "Old leader was not elected on at least one node" )
3023 positionResult = main.FALSE
3024 newAllCandidates.append( node )
3025 newLeaders.append( node[ 0 ] )
3026 newCandidates = newAllCandidates[ 0 ]
3027
3028 # Check that each node has the same leader. Defines newLeader
3029 if len( set( newLeaders ) ) != 1:
3030 positionResult = main.FALSE
3031 main.log.error( "Nodes have different leaders: " +
3032 str( newLeaders ) )
3033 newLeader = None
Jon Hall5cf14d52015-07-16 12:15:19 -07003034 else:
acsmars9475b1c2015-08-28 18:02:08 -07003035 newLeader = newLeaders[ 0 ]
3036
acsmars71adceb2015-08-31 15:09:26 -07003037 # Check that each node's candidate list is the same
3038 for candidates in newAllCandidates:
3039 if set( candidates ) != set( newCandidates ):
3040 newLeaderResult = main.FALSE
Jon Hallceb4abb2015-09-25 12:03:06 -07003041 main.log.error( "Discrepancy in candidate lists detected" )
acsmars71adceb2015-08-31 15:09:26 -07003042
acsmars9475b1c2015-08-28 18:02:08 -07003043 # Check that the re-elected node is last on the candidate List
3044 if oldLeader != newCandidates[ -1 ]:
3045 main.log.error( "Old Leader (" + oldLeader + ") not in the proper position " +
3046 str( newCandidates ) )
3047 positionResult = main.FALSE
Jon Hall5cf14d52015-07-16 12:15:19 -07003048
3049 utilities.assert_equals(
3050 expect=main.TRUE,
acsmars9475b1c2015-08-28 18:02:08 -07003051 actual=positionResult,
Jon Hall5cf14d52015-07-16 12:15:19 -07003052 onpass="Old leader successfully re-ran for election",
3053 onfail="Something went wrong with Leadership election after " +
3054 "the old leader re-ran for election" )
3055
3056 def CASE16( self, main ):
3057 """
3058 Install Distributed Primitives app
3059 """
3060 import time
Jon Halle1a3b752015-07-22 13:02:46 -07003061 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07003062 assert main, "main not defined"
3063 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07003064 assert main.CLIs, "main.CLIs not defined"
3065 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07003066
3067 # Variables for the distributed primitives tests
3068 global pCounterName
3069 global iCounterName
3070 global pCounterValue
3071 global iCounterValue
3072 global onosSet
3073 global onosSetName
3074 pCounterName = "TestON-Partitions"
3075 iCounterName = "TestON-inMemory"
3076 pCounterValue = 0
3077 iCounterValue = 0
3078 onosSet = set([])
3079 onosSetName = "TestON-set"
3080
3081 description = "Install Primitives app"
3082 main.case( description )
3083 main.step( "Install Primitives app" )
3084 appName = "org.onosproject.distributedprimitives"
Jon Halle1a3b752015-07-22 13:02:46 -07003085 appResults = main.CLIs[0].activateApp( appName )
Jon Hall5cf14d52015-07-16 12:15:19 -07003086 utilities.assert_equals( expect=main.TRUE,
3087 actual=appResults,
3088 onpass="Primitives app activated",
3089 onfail="Primitives app not activated" )
3090 time.sleep( 5 ) # To allow all nodes to activate
3091
3092 def CASE17( self, main ):
3093 """
3094 Check for basic functionality with distributed primitives
3095 """
Jon Hall5cf14d52015-07-16 12:15:19 -07003096 # Make sure variables are defined/set
Jon Halle1a3b752015-07-22 13:02:46 -07003097 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07003098 assert main, "main not defined"
3099 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07003100 assert main.CLIs, "main.CLIs not defined"
3101 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07003102 assert pCounterName, "pCounterName not defined"
3103 assert iCounterName, "iCounterName not defined"
3104 assert onosSetName, "onosSetName not defined"
3105 # NOTE: assert fails if value is 0/None/Empty/False
3106 try:
3107 pCounterValue
3108 except NameError:
3109 main.log.error( "pCounterValue not defined, setting to 0" )
3110 pCounterValue = 0
3111 try:
3112 iCounterValue
3113 except NameError:
3114 main.log.error( "iCounterValue not defined, setting to 0" )
3115 iCounterValue = 0
3116 try:
3117 onosSet
3118 except NameError:
3119 main.log.error( "onosSet not defined, setting to empty Set" )
3120 onosSet = set([])
3121 # Variables for the distributed primitives tests. These are local only
3122 addValue = "a"
3123 addAllValue = "a b c d e f"
3124 retainValue = "c d e f"
3125
3126 description = "Check for basic functionality with distributed " +\
3127 "primitives"
3128 main.case( description )
Jon Halle1a3b752015-07-22 13:02:46 -07003129 main.caseExplanation = "Test the methods of the distributed " +\
3130 "primitives (counters and sets) throught the cli"
Jon Hall5cf14d52015-07-16 12:15:19 -07003131 # DISTRIBUTED ATOMIC COUNTERS
Jon Halle1a3b752015-07-22 13:02:46 -07003132 # Partitioned counters
3133 main.step( "Increment then get a default counter on each node" )
Jon Hall5cf14d52015-07-16 12:15:19 -07003134 pCounters = []
3135 threads = []
3136 addedPValues = []
Jon Halle1a3b752015-07-22 13:02:46 -07003137 for i in range( main.numCtrls ):
3138 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
3139 name="counterAddAndGet-" + str( i ),
Jon Hall5cf14d52015-07-16 12:15:19 -07003140 args=[ pCounterName ] )
3141 pCounterValue += 1
3142 addedPValues.append( pCounterValue )
3143 threads.append( t )
3144 t.start()
3145
3146 for t in threads:
3147 t.join()
3148 pCounters.append( t.result )
3149 # Check that counter incremented numController times
3150 pCounterResults = True
3151 for i in addedPValues:
3152 tmpResult = i in pCounters
3153 pCounterResults = pCounterResults and tmpResult
3154 if not tmpResult:
3155 main.log.error( str( i ) + " is not in partitioned "
3156 "counter incremented results" )
3157 utilities.assert_equals( expect=True,
3158 actual=pCounterResults,
3159 onpass="Default counter incremented",
3160 onfail="Error incrementing default" +
3161 " counter" )
3162
Jon Halle1a3b752015-07-22 13:02:46 -07003163 main.step( "Get then Increment a default counter on each node" )
3164 pCounters = []
3165 threads = []
3166 addedPValues = []
3167 for i in range( main.numCtrls ):
3168 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
3169 name="counterGetAndAdd-" + str( i ),
3170 args=[ pCounterName ] )
3171 addedPValues.append( pCounterValue )
3172 pCounterValue += 1
3173 threads.append( t )
3174 t.start()
3175
3176 for t in threads:
3177 t.join()
3178 pCounters.append( t.result )
3179 # Check that counter incremented numController times
3180 pCounterResults = True
3181 for i in addedPValues:
3182 tmpResult = i in pCounters
3183 pCounterResults = pCounterResults and tmpResult
3184 if not tmpResult:
3185 main.log.error( str( i ) + " is not in partitioned "
3186 "counter incremented results" )
3187 utilities.assert_equals( expect=True,
3188 actual=pCounterResults,
3189 onpass="Default counter incremented",
3190 onfail="Error incrementing default" +
3191 " counter" )
3192
3193 main.step( "Counters we added have the correct values" )
3194 incrementCheck = main.Counters.counterCheck( pCounterName, pCounterValue )
3195 utilities.assert_equals( expect=main.TRUE,
3196 actual=incrementCheck,
3197 onpass="Added counters are correct",
3198 onfail="Added counters are incorrect" )
3199
3200 main.step( "Add -8 to then get a default counter on each node" )
3201 pCounters = []
3202 threads = []
3203 addedPValues = []
3204 for i in range( main.numCtrls ):
3205 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
3206 name="counterIncrement-" + str( i ),
3207 args=[ pCounterName ],
3208 kwargs={ "delta": -8 } )
3209 pCounterValue += -8
3210 addedPValues.append( pCounterValue )
3211 threads.append( t )
3212 t.start()
3213
3214 for t in threads:
3215 t.join()
3216 pCounters.append( t.result )
3217 # Check that counter incremented numController times
3218 pCounterResults = True
3219 for i in addedPValues:
3220 tmpResult = i in pCounters
3221 pCounterResults = pCounterResults and tmpResult
3222 if not tmpResult:
3223 main.log.error( str( i ) + " is not in partitioned "
3224 "counter incremented results" )
3225 utilities.assert_equals( expect=True,
3226 actual=pCounterResults,
3227 onpass="Default counter incremented",
3228 onfail="Error incrementing default" +
3229 " counter" )
3230
3231 main.step( "Add 5 to then get a default counter on each node" )
3232 pCounters = []
3233 threads = []
3234 addedPValues = []
3235 for i in range( main.numCtrls ):
3236 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
3237 name="counterIncrement-" + str( i ),
3238 args=[ pCounterName ],
3239 kwargs={ "delta": 5 } )
3240 pCounterValue += 5
3241 addedPValues.append( pCounterValue )
3242 threads.append( t )
3243 t.start()
3244
3245 for t in threads:
3246 t.join()
3247 pCounters.append( t.result )
3248 # Check that counter incremented numController times
3249 pCounterResults = True
3250 for i in addedPValues:
3251 tmpResult = i in pCounters
3252 pCounterResults = pCounterResults and tmpResult
3253 if not tmpResult:
3254 main.log.error( str( i ) + " is not in partitioned "
3255 "counter incremented results" )
3256 utilities.assert_equals( expect=True,
3257 actual=pCounterResults,
3258 onpass="Default counter incremented",
3259 onfail="Error incrementing default" +
3260 " counter" )
3261
3262 main.step( "Get then add 5 to a default counter on each node" )
3263 pCounters = []
3264 threads = []
3265 addedPValues = []
3266 for i in range( main.numCtrls ):
3267 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
3268 name="counterIncrement-" + str( i ),
3269 args=[ pCounterName ],
3270 kwargs={ "delta": 5 } )
3271 addedPValues.append( pCounterValue )
3272 pCounterValue += 5
3273 threads.append( t )
3274 t.start()
3275
3276 for t in threads:
3277 t.join()
3278 pCounters.append( t.result )
3279 # Check that counter incremented numController times
3280 pCounterResults = True
3281 for i in addedPValues:
3282 tmpResult = i in pCounters
3283 pCounterResults = pCounterResults and tmpResult
3284 if not tmpResult:
3285 main.log.error( str( i ) + " is not in partitioned "
3286 "counter incremented results" )
3287 utilities.assert_equals( expect=True,
3288 actual=pCounterResults,
3289 onpass="Default counter incremented",
3290 onfail="Error incrementing default" +
3291 " counter" )
3292
3293 main.step( "Counters we added have the correct values" )
3294 incrementCheck = main.Counters.counterCheck( pCounterName, pCounterValue )
3295 utilities.assert_equals( expect=main.TRUE,
3296 actual=incrementCheck,
3297 onpass="Added counters are correct",
3298 onfail="Added counters are incorrect" )
3299
3300 # In-Memory counters
3301 main.step( "Increment and get an in-memory counter on each node" )
Jon Hall5cf14d52015-07-16 12:15:19 -07003302 iCounters = []
3303 addedIValues = []
3304 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003305 for i in range( main.numCtrls ):
3306 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003307 name="icounterIncrement-" + str( i ),
3308 args=[ iCounterName ],
3309 kwargs={ "inMemory": True } )
3310 iCounterValue += 1
3311 addedIValues.append( iCounterValue )
3312 threads.append( t )
3313 t.start()
3314
3315 for t in threads:
3316 t.join()
3317 iCounters.append( t.result )
3318 # Check that counter incremented numController times
3319 iCounterResults = True
3320 for i in addedIValues:
3321 tmpResult = i in iCounters
3322 iCounterResults = iCounterResults and tmpResult
3323 if not tmpResult:
3324 main.log.error( str( i ) + " is not in the in-memory "
3325 "counter incremented results" )
3326 utilities.assert_equals( expect=True,
3327 actual=iCounterResults,
Jon Halle1a3b752015-07-22 13:02:46 -07003328 onpass="In-memory counter incremented",
3329 onfail="Error incrementing in-memory" +
Jon Hall5cf14d52015-07-16 12:15:19 -07003330 " counter" )
3331
Jon Halle1a3b752015-07-22 13:02:46 -07003332 main.step( "Get then Increment a in-memory counter on each node" )
3333 iCounters = []
3334 threads = []
3335 addedIValues = []
3336 for i in range( main.numCtrls ):
3337 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
3338 name="counterGetAndAdd-" + str( i ),
3339 args=[ iCounterName ],
3340 kwargs={ "inMemory": True } )
3341 addedIValues.append( iCounterValue )
3342 iCounterValue += 1
3343 threads.append( t )
3344 t.start()
3345
3346 for t in threads:
3347 t.join()
3348 iCounters.append( t.result )
3349 # Check that counter incremented numController times
3350 iCounterResults = True
3351 for i in addedIValues:
3352 tmpResult = i in iCounters
3353 iCounterResults = iCounterResults and tmpResult
3354 if not tmpResult:
3355 main.log.error( str( i ) + " is not in in-memory "
3356 "counter incremented results" )
3357 utilities.assert_equals( expect=True,
3358 actual=iCounterResults,
3359 onpass="In-memory counter incremented",
3360 onfail="Error incrementing in-memory" +
3361 " counter" )
3362
3363 main.step( "Counters we added have the correct values" )
3364 incrementCheck = main.Counters.counterCheck( iCounterName, iCounterValue )
3365 utilities.assert_equals( expect=main.TRUE,
3366 actual=incrementCheck,
3367 onpass="Added counters are correct",
3368 onfail="Added counters are incorrect" )
3369
3370 main.step( "Add -8 to then get a in-memory counter on each node" )
3371 iCounters = []
3372 threads = []
3373 addedIValues = []
3374 for i in range( main.numCtrls ):
3375 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
3376 name="counterIncrement-" + str( i ),
3377 args=[ iCounterName ],
3378 kwargs={ "delta": -8, "inMemory": True } )
3379 iCounterValue += -8
3380 addedIValues.append( iCounterValue )
3381 threads.append( t )
3382 t.start()
3383
3384 for t in threads:
3385 t.join()
3386 iCounters.append( t.result )
3387 # Check that counter incremented numController times
3388 iCounterResults = True
3389 for i in addedIValues:
3390 tmpResult = i in iCounters
3391 iCounterResults = iCounterResults and tmpResult
3392 if not tmpResult:
3393 main.log.error( str( i ) + " is not in in-memory "
3394 "counter incremented results" )
3395 utilities.assert_equals( expect=True,
3396 actual=pCounterResults,
3397 onpass="In-memory counter incremented",
3398 onfail="Error incrementing in-memory" +
3399 " counter" )
3400
3401 main.step( "Add 5 to then get a in-memory counter on each node" )
3402 iCounters = []
3403 threads = []
3404 addedIValues = []
3405 for i in range( main.numCtrls ):
3406 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
3407 name="counterIncrement-" + str( i ),
3408 args=[ iCounterName ],
3409 kwargs={ "delta": 5, "inMemory": True } )
3410 iCounterValue += 5
3411 addedIValues.append( iCounterValue )
3412 threads.append( t )
3413 t.start()
3414
3415 for t in threads:
3416 t.join()
3417 iCounters.append( t.result )
3418 # Check that counter incremented numController times
3419 iCounterResults = True
3420 for i in addedIValues:
3421 tmpResult = i in iCounters
3422 iCounterResults = iCounterResults and tmpResult
3423 if not tmpResult:
3424 main.log.error( str( i ) + " is not in in-memory "
3425 "counter incremented results" )
3426 utilities.assert_equals( expect=True,
3427 actual=pCounterResults,
3428 onpass="In-memory counter incremented",
3429 onfail="Error incrementing in-memory" +
3430 " counter" )
3431
3432 main.step( "Get then add 5 to a in-memory counter on each node" )
3433 iCounters = []
3434 threads = []
3435 addedIValues = []
3436 for i in range( main.numCtrls ):
3437 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
3438 name="counterIncrement-" + str( i ),
3439 args=[ iCounterName ],
3440 kwargs={ "delta": 5, "inMemory": True } )
3441 addedIValues.append( iCounterValue )
3442 iCounterValue += 5
3443 threads.append( t )
3444 t.start()
3445
3446 for t in threads:
3447 t.join()
3448 iCounters.append( t.result )
3449 # Check that counter incremented numController times
3450 iCounterResults = True
3451 for i in addedIValues:
3452 tmpResult = i in iCounters
3453 iCounterResults = iCounterResults and tmpResult
3454 if not tmpResult:
3455 main.log.error( str( i ) + " is not in in-memory "
3456 "counter incremented results" )
3457 utilities.assert_equals( expect=True,
3458 actual=iCounterResults,
3459 onpass="In-memory counter incremented",
3460 onfail="Error incrementing in-memory" +
3461 " counter" )
3462
3463 main.step( "Counters we added have the correct values" )
3464 incrementCheck = main.Counters.counterCheck( iCounterName, iCounterValue )
3465 utilities.assert_equals( expect=main.TRUE,
3466 actual=incrementCheck,
3467 onpass="Added counters are correct",
3468 onfail="Added counters are incorrect" )
3469
Jon Hall5cf14d52015-07-16 12:15:19 -07003470 main.step( "Check counters are consistant across nodes" )
Jon Hall57b50432015-10-22 10:20:10 -07003471 onosCounters, consistentCounterResults = main.Counters.consistentCheck()
Jon Hall5cf14d52015-07-16 12:15:19 -07003472 utilities.assert_equals( expect=main.TRUE,
3473 actual=consistentCounterResults,
3474 onpass="ONOS counters are consistent " +
3475 "across nodes",
3476 onfail="ONOS Counters are inconsistent " +
3477 "across nodes" )
3478
3479 main.step( "Counters we added have the correct values" )
Jon Halle1a3b752015-07-22 13:02:46 -07003480 incrementCheck = main.Counters.counterCheck( iCounterName, iCounterValue )
3481 incrementCheck = incrementCheck and \
3482 main.Counters.counterCheck( iCounterName, iCounterValue )
Jon Hall5cf14d52015-07-16 12:15:19 -07003483 utilities.assert_equals( expect=main.TRUE,
Jon Halle1a3b752015-07-22 13:02:46 -07003484 actual=incrementCheck,
Jon Hall5cf14d52015-07-16 12:15:19 -07003485 onpass="Added counters are correct",
3486 onfail="Added counters are incorrect" )
3487 # DISTRIBUTED SETS
3488 main.step( "Distributed Set get" )
3489 size = len( onosSet )
3490 getResponses = []
3491 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003492 for i in range( main.numCtrls ):
3493 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003494 name="setTestGet-" + str( i ),
3495 args=[ onosSetName ] )
3496 threads.append( t )
3497 t.start()
3498 for t in threads:
3499 t.join()
3500 getResponses.append( t.result )
3501
3502 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003503 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003504 if isinstance( getResponses[ i ], list):
3505 current = set( getResponses[ i ] )
3506 if len( current ) == len( getResponses[ i ] ):
3507 # no repeats
3508 if onosSet != current:
3509 main.log.error( "ONOS" + str( i + 1 ) +
3510 " has incorrect view" +
3511 " of set " + onosSetName + ":\n" +
3512 str( getResponses[ i ] ) )
3513 main.log.debug( "Expected: " + str( onosSet ) )
3514 main.log.debug( "Actual: " + str( current ) )
3515 getResults = main.FALSE
3516 else:
3517 # error, set is not a set
3518 main.log.error( "ONOS" + str( i + 1 ) +
3519 " has repeat elements in" +
3520 " set " + onosSetName + ":\n" +
3521 str( getResponses[ i ] ) )
3522 getResults = main.FALSE
3523 elif getResponses[ i ] == main.ERROR:
3524 getResults = main.FALSE
3525 utilities.assert_equals( expect=main.TRUE,
3526 actual=getResults,
3527 onpass="Set elements are correct",
3528 onfail="Set elements are incorrect" )
3529
3530 main.step( "Distributed Set size" )
3531 sizeResponses = []
3532 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003533 for i in range( main.numCtrls ):
3534 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003535 name="setTestSize-" + str( i ),
3536 args=[ onosSetName ] )
3537 threads.append( t )
3538 t.start()
3539 for t in threads:
3540 t.join()
3541 sizeResponses.append( t.result )
3542
3543 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003544 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003545 if size != sizeResponses[ i ]:
3546 sizeResults = main.FALSE
3547 main.log.error( "ONOS" + str( i + 1 ) +
3548 " expected a size of " + str( size ) +
3549 " for set " + onosSetName +
3550 " but got " + str( sizeResponses[ i ] ) )
3551 utilities.assert_equals( expect=main.TRUE,
3552 actual=sizeResults,
3553 onpass="Set sizes are correct",
3554 onfail="Set sizes are incorrect" )
3555
3556 main.step( "Distributed Set add()" )
3557 onosSet.add( addValue )
3558 addResponses = []
3559 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003560 for i in range( main.numCtrls ):
3561 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall5cf14d52015-07-16 12:15:19 -07003562 name="setTestAdd-" + str( i ),
3563 args=[ onosSetName, addValue ] )
3564 threads.append( t )
3565 t.start()
3566 for t in threads:
3567 t.join()
3568 addResponses.append( t.result )
3569
3570 # main.TRUE = successfully changed the set
3571 # main.FALSE = action resulted in no change in set
3572 # main.ERROR - Some error in executing the function
3573 addResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003574 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003575 if addResponses[ i ] == main.TRUE:
3576 # All is well
3577 pass
3578 elif addResponses[ i ] == main.FALSE:
3579 # Already in set, probably fine
3580 pass
3581 elif addResponses[ i ] == main.ERROR:
3582 # Error in execution
3583 addResults = main.FALSE
3584 else:
3585 # unexpected result
3586 addResults = main.FALSE
3587 if addResults != main.TRUE:
3588 main.log.error( "Error executing set add" )
3589
3590 # Check if set is still correct
3591 size = len( onosSet )
3592 getResponses = []
3593 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003594 for i in range( main.numCtrls ):
3595 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003596 name="setTestGet-" + str( i ),
3597 args=[ onosSetName ] )
3598 threads.append( t )
3599 t.start()
3600 for t in threads:
3601 t.join()
3602 getResponses.append( t.result )
3603 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003604 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003605 if isinstance( getResponses[ i ], list):
3606 current = set( getResponses[ i ] )
3607 if len( current ) == len( getResponses[ i ] ):
3608 # no repeats
3609 if onosSet != current:
3610 main.log.error( "ONOS" + str( i + 1 ) +
3611 " has incorrect view" +
3612 " of set " + onosSetName + ":\n" +
3613 str( getResponses[ i ] ) )
3614 main.log.debug( "Expected: " + str( onosSet ) )
3615 main.log.debug( "Actual: " + str( current ) )
3616 getResults = main.FALSE
3617 else:
3618 # error, set is not a set
3619 main.log.error( "ONOS" + str( i + 1 ) +
3620 " has repeat elements in" +
3621 " set " + onosSetName + ":\n" +
3622 str( getResponses[ i ] ) )
3623 getResults = main.FALSE
3624 elif getResponses[ i ] == main.ERROR:
3625 getResults = main.FALSE
3626 sizeResponses = []
3627 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003628 for i in range( main.numCtrls ):
3629 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003630 name="setTestSize-" + str( i ),
3631 args=[ onosSetName ] )
3632 threads.append( t )
3633 t.start()
3634 for t in threads:
3635 t.join()
3636 sizeResponses.append( t.result )
3637 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003638 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003639 if size != sizeResponses[ i ]:
3640 sizeResults = main.FALSE
3641 main.log.error( "ONOS" + str( i + 1 ) +
3642 " expected a size of " + str( size ) +
3643 " for set " + onosSetName +
3644 " but got " + str( sizeResponses[ i ] ) )
3645 addResults = addResults and getResults and sizeResults
3646 utilities.assert_equals( expect=main.TRUE,
3647 actual=addResults,
3648 onpass="Set add correct",
3649 onfail="Set add was incorrect" )
3650
3651 main.step( "Distributed Set addAll()" )
3652 onosSet.update( addAllValue.split() )
3653 addResponses = []
3654 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003655 for i in range( main.numCtrls ):
3656 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall5cf14d52015-07-16 12:15:19 -07003657 name="setTestAddAll-" + str( i ),
3658 args=[ onosSetName, addAllValue ] )
3659 threads.append( t )
3660 t.start()
3661 for t in threads:
3662 t.join()
3663 addResponses.append( t.result )
3664
3665 # main.TRUE = successfully changed the set
3666 # main.FALSE = action resulted in no change in set
3667 # main.ERROR - Some error in executing the function
3668 addAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003669 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003670 if addResponses[ i ] == main.TRUE:
3671 # All is well
3672 pass
3673 elif addResponses[ i ] == main.FALSE:
3674 # Already in set, probably fine
3675 pass
3676 elif addResponses[ i ] == main.ERROR:
3677 # Error in execution
3678 addAllResults = main.FALSE
3679 else:
3680 # unexpected result
3681 addAllResults = main.FALSE
3682 if addAllResults != main.TRUE:
3683 main.log.error( "Error executing set addAll" )
3684
3685 # Check if set is still correct
3686 size = len( onosSet )
3687 getResponses = []
3688 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003689 for i in range( main.numCtrls ):
3690 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003691 name="setTestGet-" + str( i ),
3692 args=[ onosSetName ] )
3693 threads.append( t )
3694 t.start()
3695 for t in threads:
3696 t.join()
3697 getResponses.append( t.result )
3698 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003699 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003700 if isinstance( getResponses[ i ], list):
3701 current = set( getResponses[ i ] )
3702 if len( current ) == len( getResponses[ i ] ):
3703 # no repeats
3704 if onosSet != current:
3705 main.log.error( "ONOS" + str( i + 1 ) +
3706 " has incorrect view" +
3707 " of set " + onosSetName + ":\n" +
3708 str( getResponses[ i ] ) )
3709 main.log.debug( "Expected: " + str( onosSet ) )
3710 main.log.debug( "Actual: " + str( current ) )
3711 getResults = main.FALSE
3712 else:
3713 # error, set is not a set
3714 main.log.error( "ONOS" + str( i + 1 ) +
3715 " has repeat elements in" +
3716 " set " + onosSetName + ":\n" +
3717 str( getResponses[ i ] ) )
3718 getResults = main.FALSE
3719 elif getResponses[ i ] == main.ERROR:
3720 getResults = main.FALSE
3721 sizeResponses = []
3722 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003723 for i in range( main.numCtrls ):
3724 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003725 name="setTestSize-" + str( i ),
3726 args=[ onosSetName ] )
3727 threads.append( t )
3728 t.start()
3729 for t in threads:
3730 t.join()
3731 sizeResponses.append( t.result )
3732 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003733 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003734 if size != sizeResponses[ i ]:
3735 sizeResults = main.FALSE
3736 main.log.error( "ONOS" + str( i + 1 ) +
3737 " expected a size of " + str( size ) +
3738 " for set " + onosSetName +
3739 " but got " + str( sizeResponses[ i ] ) )
3740 addAllResults = addAllResults and getResults and sizeResults
3741 utilities.assert_equals( expect=main.TRUE,
3742 actual=addAllResults,
3743 onpass="Set addAll correct",
3744 onfail="Set addAll was incorrect" )
3745
3746 main.step( "Distributed Set contains()" )
3747 containsResponses = []
3748 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003749 for i in range( main.numCtrls ):
3750 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003751 name="setContains-" + str( i ),
3752 args=[ onosSetName ],
3753 kwargs={ "values": addValue } )
3754 threads.append( t )
3755 t.start()
3756 for t in threads:
3757 t.join()
3758 # NOTE: This is the tuple
3759 containsResponses.append( t.result )
3760
3761 containsResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003762 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003763 if containsResponses[ i ] == main.ERROR:
3764 containsResults = main.FALSE
3765 else:
3766 containsResults = containsResults and\
3767 containsResponses[ i ][ 1 ]
3768 utilities.assert_equals( expect=main.TRUE,
3769 actual=containsResults,
3770 onpass="Set contains is functional",
3771 onfail="Set contains failed" )
3772
3773 main.step( "Distributed Set containsAll()" )
3774 containsAllResponses = []
3775 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003776 for i in range( main.numCtrls ):
3777 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003778 name="setContainsAll-" + str( i ),
3779 args=[ onosSetName ],
3780 kwargs={ "values": addAllValue } )
3781 threads.append( t )
3782 t.start()
3783 for t in threads:
3784 t.join()
3785 # NOTE: This is the tuple
3786 containsAllResponses.append( t.result )
3787
3788 containsAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003789 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003790 if containsResponses[ i ] == main.ERROR:
3791 containsResults = main.FALSE
3792 else:
3793 containsResults = containsResults and\
3794 containsResponses[ i ][ 1 ]
3795 utilities.assert_equals( expect=main.TRUE,
3796 actual=containsAllResults,
3797 onpass="Set containsAll is functional",
3798 onfail="Set containsAll failed" )
3799
3800 main.step( "Distributed Set remove()" )
3801 onosSet.remove( addValue )
3802 removeResponses = []
3803 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003804 for i in range( main.numCtrls ):
3805 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall5cf14d52015-07-16 12:15:19 -07003806 name="setTestRemove-" + str( i ),
3807 args=[ onosSetName, addValue ] )
3808 threads.append( t )
3809 t.start()
3810 for t in threads:
3811 t.join()
3812 removeResponses.append( t.result )
3813
3814 # main.TRUE = successfully changed the set
3815 # main.FALSE = action resulted in no change in set
3816 # main.ERROR - Some error in executing the function
3817 removeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003818 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003819 if removeResponses[ i ] == main.TRUE:
3820 # All is well
3821 pass
3822 elif removeResponses[ i ] == main.FALSE:
3823 # not in set, probably fine
3824 pass
3825 elif removeResponses[ i ] == main.ERROR:
3826 # Error in execution
3827 removeResults = main.FALSE
3828 else:
3829 # unexpected result
3830 removeResults = main.FALSE
3831 if removeResults != main.TRUE:
3832 main.log.error( "Error executing set remove" )
3833
3834 # Check if set is still correct
3835 size = len( onosSet )
3836 getResponses = []
3837 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003838 for i in range( main.numCtrls ):
3839 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003840 name="setTestGet-" + str( i ),
3841 args=[ onosSetName ] )
3842 threads.append( t )
3843 t.start()
3844 for t in threads:
3845 t.join()
3846 getResponses.append( t.result )
3847 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003848 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003849 if isinstance( getResponses[ i ], list):
3850 current = set( getResponses[ i ] )
3851 if len( current ) == len( getResponses[ i ] ):
3852 # no repeats
3853 if onosSet != current:
3854 main.log.error( "ONOS" + str( i + 1 ) +
3855 " has incorrect view" +
3856 " of set " + onosSetName + ":\n" +
3857 str( getResponses[ i ] ) )
3858 main.log.debug( "Expected: " + str( onosSet ) )
3859 main.log.debug( "Actual: " + str( current ) )
3860 getResults = main.FALSE
3861 else:
3862 # error, set is not a set
3863 main.log.error( "ONOS" + str( i + 1 ) +
3864 " has repeat elements in" +
3865 " set " + onosSetName + ":\n" +
3866 str( getResponses[ i ] ) )
3867 getResults = main.FALSE
3868 elif getResponses[ i ] == main.ERROR:
3869 getResults = main.FALSE
3870 sizeResponses = []
3871 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003872 for i in range( main.numCtrls ):
3873 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003874 name="setTestSize-" + str( i ),
3875 args=[ onosSetName ] )
3876 threads.append( t )
3877 t.start()
3878 for t in threads:
3879 t.join()
3880 sizeResponses.append( t.result )
3881 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003882 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003883 if size != sizeResponses[ i ]:
3884 sizeResults = main.FALSE
3885 main.log.error( "ONOS" + str( i + 1 ) +
3886 " expected a size of " + str( size ) +
3887 " for set " + onosSetName +
3888 " but got " + str( sizeResponses[ i ] ) )
3889 removeResults = removeResults and getResults and sizeResults
3890 utilities.assert_equals( expect=main.TRUE,
3891 actual=removeResults,
3892 onpass="Set remove correct",
3893 onfail="Set remove was incorrect" )
3894
3895 main.step( "Distributed Set removeAll()" )
3896 onosSet.difference_update( addAllValue.split() )
3897 removeAllResponses = []
3898 threads = []
3899 try:
Jon Halle1a3b752015-07-22 13:02:46 -07003900 for i in range( main.numCtrls ):
3901 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall5cf14d52015-07-16 12:15:19 -07003902 name="setTestRemoveAll-" + str( i ),
3903 args=[ onosSetName, addAllValue ] )
3904 threads.append( t )
3905 t.start()
3906 for t in threads:
3907 t.join()
3908 removeAllResponses.append( t.result )
3909 except Exception, e:
3910 main.log.exception(e)
3911
3912 # main.TRUE = successfully changed the set
3913 # main.FALSE = action resulted in no change in set
3914 # main.ERROR - Some error in executing the function
3915 removeAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003916 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003917 if removeAllResponses[ i ] == main.TRUE:
3918 # All is well
3919 pass
3920 elif removeAllResponses[ i ] == main.FALSE:
3921 # not in set, probably fine
3922 pass
3923 elif removeAllResponses[ i ] == main.ERROR:
3924 # Error in execution
3925 removeAllResults = main.FALSE
3926 else:
3927 # unexpected result
3928 removeAllResults = main.FALSE
3929 if removeAllResults != main.TRUE:
3930 main.log.error( "Error executing set removeAll" )
3931
3932 # Check if set is still correct
3933 size = len( onosSet )
3934 getResponses = []
3935 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003936 for i in range( main.numCtrls ):
3937 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003938 name="setTestGet-" + str( i ),
3939 args=[ onosSetName ] )
3940 threads.append( t )
3941 t.start()
3942 for t in threads:
3943 t.join()
3944 getResponses.append( t.result )
3945 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003946 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003947 if isinstance( getResponses[ i ], list):
3948 current = set( getResponses[ i ] )
3949 if len( current ) == len( getResponses[ i ] ):
3950 # no repeats
3951 if onosSet != current:
3952 main.log.error( "ONOS" + str( i + 1 ) +
3953 " has incorrect view" +
3954 " of set " + onosSetName + ":\n" +
3955 str( getResponses[ i ] ) )
3956 main.log.debug( "Expected: " + str( onosSet ) )
3957 main.log.debug( "Actual: " + str( current ) )
3958 getResults = main.FALSE
3959 else:
3960 # error, set is not a set
3961 main.log.error( "ONOS" + str( i + 1 ) +
3962 " has repeat elements in" +
3963 " set " + onosSetName + ":\n" +
3964 str( getResponses[ i ] ) )
3965 getResults = main.FALSE
3966 elif getResponses[ i ] == main.ERROR:
3967 getResults = main.FALSE
3968 sizeResponses = []
3969 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003970 for i in range( main.numCtrls ):
3971 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003972 name="setTestSize-" + str( i ),
3973 args=[ onosSetName ] )
3974 threads.append( t )
3975 t.start()
3976 for t in threads:
3977 t.join()
3978 sizeResponses.append( t.result )
3979 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003980 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003981 if size != sizeResponses[ i ]:
3982 sizeResults = main.FALSE
3983 main.log.error( "ONOS" + str( i + 1 ) +
3984 " expected a size of " + str( size ) +
3985 " for set " + onosSetName +
3986 " but got " + str( sizeResponses[ i ] ) )
3987 removeAllResults = removeAllResults and getResults and sizeResults
3988 utilities.assert_equals( expect=main.TRUE,
3989 actual=removeAllResults,
3990 onpass="Set removeAll correct",
3991 onfail="Set removeAll was incorrect" )
3992
3993 main.step( "Distributed Set addAll()" )
3994 onosSet.update( addAllValue.split() )
3995 addResponses = []
3996 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003997 for i in range( main.numCtrls ):
3998 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall5cf14d52015-07-16 12:15:19 -07003999 name="setTestAddAll-" + str( i ),
4000 args=[ onosSetName, addAllValue ] )
4001 threads.append( t )
4002 t.start()
4003 for t in threads:
4004 t.join()
4005 addResponses.append( t.result )
4006
4007 # main.TRUE = successfully changed the set
4008 # main.FALSE = action resulted in no change in set
4009 # main.ERROR - Some error in executing the function
4010 addAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004011 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004012 if addResponses[ i ] == main.TRUE:
4013 # All is well
4014 pass
4015 elif addResponses[ i ] == main.FALSE:
4016 # Already in set, probably fine
4017 pass
4018 elif addResponses[ i ] == main.ERROR:
4019 # Error in execution
4020 addAllResults = main.FALSE
4021 else:
4022 # unexpected result
4023 addAllResults = main.FALSE
4024 if addAllResults != main.TRUE:
4025 main.log.error( "Error executing set addAll" )
4026
4027 # Check if set is still correct
4028 size = len( onosSet )
4029 getResponses = []
4030 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004031 for i in range( main.numCtrls ):
4032 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07004033 name="setTestGet-" + str( i ),
4034 args=[ onosSetName ] )
4035 threads.append( t )
4036 t.start()
4037 for t in threads:
4038 t.join()
4039 getResponses.append( t.result )
4040 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004041 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004042 if isinstance( getResponses[ i ], list):
4043 current = set( getResponses[ i ] )
4044 if len( current ) == len( getResponses[ i ] ):
4045 # no repeats
4046 if onosSet != current:
4047 main.log.error( "ONOS" + str( i + 1 ) +
4048 " has incorrect view" +
4049 " of set " + onosSetName + ":\n" +
4050 str( getResponses[ i ] ) )
4051 main.log.debug( "Expected: " + str( onosSet ) )
4052 main.log.debug( "Actual: " + str( current ) )
4053 getResults = main.FALSE
4054 else:
4055 # error, set is not a set
4056 main.log.error( "ONOS" + str( i + 1 ) +
4057 " has repeat elements in" +
4058 " set " + onosSetName + ":\n" +
4059 str( getResponses[ i ] ) )
4060 getResults = main.FALSE
4061 elif getResponses[ i ] == main.ERROR:
4062 getResults = main.FALSE
4063 sizeResponses = []
4064 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004065 for i in range( main.numCtrls ):
4066 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07004067 name="setTestSize-" + str( i ),
4068 args=[ onosSetName ] )
4069 threads.append( t )
4070 t.start()
4071 for t in threads:
4072 t.join()
4073 sizeResponses.append( t.result )
4074 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004075 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004076 if size != sizeResponses[ i ]:
4077 sizeResults = main.FALSE
4078 main.log.error( "ONOS" + str( i + 1 ) +
4079 " expected a size of " + str( size ) +
4080 " for set " + onosSetName +
4081 " but got " + str( sizeResponses[ i ] ) )
4082 addAllResults = addAllResults and getResults and sizeResults
4083 utilities.assert_equals( expect=main.TRUE,
4084 actual=addAllResults,
4085 onpass="Set addAll correct",
4086 onfail="Set addAll was incorrect" )
4087
4088 main.step( "Distributed Set clear()" )
4089 onosSet.clear()
4090 clearResponses = []
4091 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004092 for i in range( main.numCtrls ):
4093 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall5cf14d52015-07-16 12:15:19 -07004094 name="setTestClear-" + str( i ),
4095 args=[ onosSetName, " "], # Values doesn't matter
4096 kwargs={ "clear": True } )
4097 threads.append( t )
4098 t.start()
4099 for t in threads:
4100 t.join()
4101 clearResponses.append( t.result )
4102
4103 # main.TRUE = successfully changed the set
4104 # main.FALSE = action resulted in no change in set
4105 # main.ERROR - Some error in executing the function
4106 clearResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004107 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004108 if clearResponses[ i ] == main.TRUE:
4109 # All is well
4110 pass
4111 elif clearResponses[ i ] == main.FALSE:
4112 # Nothing set, probably fine
4113 pass
4114 elif clearResponses[ i ] == main.ERROR:
4115 # Error in execution
4116 clearResults = main.FALSE
4117 else:
4118 # unexpected result
4119 clearResults = main.FALSE
4120 if clearResults != main.TRUE:
4121 main.log.error( "Error executing set clear" )
4122
4123 # Check if set is still correct
4124 size = len( onosSet )
4125 getResponses = []
4126 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004127 for i in range( main.numCtrls ):
4128 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07004129 name="setTestGet-" + str( i ),
4130 args=[ onosSetName ] )
4131 threads.append( t )
4132 t.start()
4133 for t in threads:
4134 t.join()
4135 getResponses.append( t.result )
4136 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004137 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004138 if isinstance( getResponses[ i ], list):
4139 current = set( getResponses[ i ] )
4140 if len( current ) == len( getResponses[ i ] ):
4141 # no repeats
4142 if onosSet != current:
4143 main.log.error( "ONOS" + str( i + 1 ) +
4144 " has incorrect view" +
4145 " of set " + onosSetName + ":\n" +
4146 str( getResponses[ i ] ) )
4147 main.log.debug( "Expected: " + str( onosSet ) )
4148 main.log.debug( "Actual: " + str( current ) )
4149 getResults = main.FALSE
4150 else:
4151 # error, set is not a set
4152 main.log.error( "ONOS" + str( i + 1 ) +
4153 " has repeat elements in" +
4154 " set " + onosSetName + ":\n" +
4155 str( getResponses[ i ] ) )
4156 getResults = main.FALSE
4157 elif getResponses[ i ] == main.ERROR:
4158 getResults = main.FALSE
4159 sizeResponses = []
4160 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004161 for i in range( main.numCtrls ):
4162 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07004163 name="setTestSize-" + str( i ),
4164 args=[ onosSetName ] )
4165 threads.append( t )
4166 t.start()
4167 for t in threads:
4168 t.join()
4169 sizeResponses.append( t.result )
4170 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004171 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004172 if size != sizeResponses[ i ]:
4173 sizeResults = main.FALSE
4174 main.log.error( "ONOS" + str( i + 1 ) +
4175 " expected a size of " + str( size ) +
4176 " for set " + onosSetName +
4177 " but got " + str( sizeResponses[ i ] ) )
4178 clearResults = clearResults and getResults and sizeResults
4179 utilities.assert_equals( expect=main.TRUE,
4180 actual=clearResults,
4181 onpass="Set clear correct",
4182 onfail="Set clear was incorrect" )
4183
4184 main.step( "Distributed Set addAll()" )
4185 onosSet.update( addAllValue.split() )
4186 addResponses = []
4187 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004188 for i in range( main.numCtrls ):
4189 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall5cf14d52015-07-16 12:15:19 -07004190 name="setTestAddAll-" + str( i ),
4191 args=[ onosSetName, addAllValue ] )
4192 threads.append( t )
4193 t.start()
4194 for t in threads:
4195 t.join()
4196 addResponses.append( t.result )
4197
4198 # main.TRUE = successfully changed the set
4199 # main.FALSE = action resulted in no change in set
4200 # main.ERROR - Some error in executing the function
4201 addAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004202 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004203 if addResponses[ i ] == main.TRUE:
4204 # All is well
4205 pass
4206 elif addResponses[ i ] == main.FALSE:
4207 # Already in set, probably fine
4208 pass
4209 elif addResponses[ i ] == main.ERROR:
4210 # Error in execution
4211 addAllResults = main.FALSE
4212 else:
4213 # unexpected result
4214 addAllResults = main.FALSE
4215 if addAllResults != main.TRUE:
4216 main.log.error( "Error executing set addAll" )
4217
4218 # Check if set is still correct
4219 size = len( onosSet )
4220 getResponses = []
4221 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004222 for i in range( main.numCtrls ):
4223 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07004224 name="setTestGet-" + str( i ),
4225 args=[ onosSetName ] )
4226 threads.append( t )
4227 t.start()
4228 for t in threads:
4229 t.join()
4230 getResponses.append( t.result )
4231 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004232 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004233 if isinstance( getResponses[ i ], list):
4234 current = set( getResponses[ i ] )
4235 if len( current ) == len( getResponses[ i ] ):
4236 # no repeats
4237 if onosSet != current:
4238 main.log.error( "ONOS" + str( i + 1 ) +
4239 " has incorrect view" +
4240 " of set " + onosSetName + ":\n" +
4241 str( getResponses[ i ] ) )
4242 main.log.debug( "Expected: " + str( onosSet ) )
4243 main.log.debug( "Actual: " + str( current ) )
4244 getResults = main.FALSE
4245 else:
4246 # error, set is not a set
4247 main.log.error( "ONOS" + str( i + 1 ) +
4248 " has repeat elements in" +
4249 " set " + onosSetName + ":\n" +
4250 str( getResponses[ i ] ) )
4251 getResults = main.FALSE
4252 elif getResponses[ i ] == main.ERROR:
4253 getResults = main.FALSE
4254 sizeResponses = []
4255 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004256 for i in range( main.numCtrls ):
4257 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07004258 name="setTestSize-" + str( i ),
4259 args=[ onosSetName ] )
4260 threads.append( t )
4261 t.start()
4262 for t in threads:
4263 t.join()
4264 sizeResponses.append( t.result )
4265 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004266 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004267 if size != sizeResponses[ i ]:
4268 sizeResults = main.FALSE
4269 main.log.error( "ONOS" + str( i + 1 ) +
4270 " expected a size of " + str( size ) +
4271 " for set " + onosSetName +
4272 " but got " + str( sizeResponses[ i ] ) )
4273 addAllResults = addAllResults and getResults and sizeResults
4274 utilities.assert_equals( expect=main.TRUE,
4275 actual=addAllResults,
4276 onpass="Set addAll correct",
4277 onfail="Set addAll was incorrect" )
4278
4279 main.step( "Distributed Set retain()" )
4280 onosSet.intersection_update( retainValue.split() )
4281 retainResponses = []
4282 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004283 for i in range( main.numCtrls ):
4284 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall5cf14d52015-07-16 12:15:19 -07004285 name="setTestRetain-" + str( i ),
4286 args=[ onosSetName, retainValue ],
4287 kwargs={ "retain": True } )
4288 threads.append( t )
4289 t.start()
4290 for t in threads:
4291 t.join()
4292 retainResponses.append( t.result )
4293
4294 # main.TRUE = successfully changed the set
4295 # main.FALSE = action resulted in no change in set
4296 # main.ERROR - Some error in executing the function
4297 retainResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004298 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004299 if retainResponses[ i ] == main.TRUE:
4300 # All is well
4301 pass
4302 elif retainResponses[ i ] == main.FALSE:
4303 # Already in set, probably fine
4304 pass
4305 elif retainResponses[ i ] == main.ERROR:
4306 # Error in execution
4307 retainResults = main.FALSE
4308 else:
4309 # unexpected result
4310 retainResults = main.FALSE
4311 if retainResults != main.TRUE:
4312 main.log.error( "Error executing set retain" )
4313
4314 # Check if set is still correct
4315 size = len( onosSet )
4316 getResponses = []
4317 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004318 for i in range( main.numCtrls ):
4319 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07004320 name="setTestGet-" + str( i ),
4321 args=[ onosSetName ] )
4322 threads.append( t )
4323 t.start()
4324 for t in threads:
4325 t.join()
4326 getResponses.append( t.result )
4327 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004328 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004329 if isinstance( getResponses[ i ], list):
4330 current = set( getResponses[ i ] )
4331 if len( current ) == len( getResponses[ i ] ):
4332 # no repeats
4333 if onosSet != current:
4334 main.log.error( "ONOS" + str( i + 1 ) +
4335 " has incorrect view" +
4336 " of set " + onosSetName + ":\n" +
4337 str( getResponses[ i ] ) )
4338 main.log.debug( "Expected: " + str( onosSet ) )
4339 main.log.debug( "Actual: " + str( current ) )
4340 getResults = main.FALSE
4341 else:
4342 # error, set is not a set
4343 main.log.error( "ONOS" + str( i + 1 ) +
4344 " has repeat elements in" +
4345 " set " + onosSetName + ":\n" +
4346 str( getResponses[ i ] ) )
4347 getResults = main.FALSE
4348 elif getResponses[ i ] == main.ERROR:
4349 getResults = main.FALSE
4350 sizeResponses = []
4351 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004352 for i in range( main.numCtrls ):
4353 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07004354 name="setTestSize-" + str( i ),
4355 args=[ onosSetName ] )
4356 threads.append( t )
4357 t.start()
4358 for t in threads:
4359 t.join()
4360 sizeResponses.append( t.result )
4361 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004362 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004363 if size != sizeResponses[ i ]:
4364 sizeResults = main.FALSE
4365 main.log.error( "ONOS" + str( i + 1 ) +
4366 " expected a size of " +
4367 str( size ) + " for set " + onosSetName +
4368 " but got " + str( sizeResponses[ i ] ) )
4369 retainResults = retainResults and getResults and sizeResults
4370 utilities.assert_equals( expect=main.TRUE,
4371 actual=retainResults,
4372 onpass="Set retain correct",
4373 onfail="Set retain was incorrect" )
4374
Jon Hall2a5002c2015-08-21 16:49:11 -07004375 # Transactional maps
4376 main.step( "Partitioned Transactional maps put" )
4377 tMapValue = "Testing"
4378 numKeys = 100
4379 putResult = True
4380 putResponses = main.CLIs[ 0 ].transactionalMapPut( numKeys, tMapValue )
4381 if len( putResponses ) == 100:
4382 for i in putResponses:
4383 if putResponses[ i ][ 'value' ] != tMapValue:
4384 putResult = False
4385 else:
4386 putResult = False
4387 if not putResult:
4388 main.log.debug( "Put response values: " + str( putResponses ) )
4389 utilities.assert_equals( expect=True,
4390 actual=putResult,
4391 onpass="Partitioned Transactional Map put successful",
4392 onfail="Partitioned Transactional Map put values are incorrect" )
4393
4394 main.step( "Partitioned Transactional maps get" )
4395 getCheck = True
4396 for n in range( 1, numKeys + 1 ):
4397 getResponses = []
4398 threads = []
4399 valueCheck = True
4400 for i in range( main.numCtrls ):
4401 t = main.Thread( target=main.CLIs[i].transactionalMapGet,
4402 name="TMap-get-" + str( i ),
4403 args=[ "Key" + str ( n ) ] )
4404 threads.append( t )
4405 t.start()
4406 for t in threads:
4407 t.join()
4408 getResponses.append( t.result )
4409 for node in getResponses:
4410 if node != tMapValue:
4411 valueCheck = False
4412 if not valueCheck:
4413 main.log.warn( "Values for key 'Key" + str( n ) + "' do not match:" )
4414 main.log.warn( getResponses )
4415 getCheck = getCheck and valueCheck
4416 utilities.assert_equals( expect=True,
4417 actual=getCheck,
4418 onpass="Partitioned Transactional Map get values were correct",
4419 onfail="Partitioned Transactional Map values incorrect" )
4420
4421 main.step( "In-memory Transactional maps put" )
4422 tMapValue = "Testing"
4423 numKeys = 100
4424 putResult = True
4425 putResponses = main.CLIs[ 0 ].transactionalMapPut( numKeys, tMapValue, inMemory=True )
4426 if len( putResponses ) == 100:
4427 for i in putResponses:
4428 if putResponses[ i ][ 'value' ] != tMapValue:
4429 putResult = False
4430 else:
4431 putResult = False
4432 if not putResult:
4433 main.log.debug( "Put response values: " + str( putResponses ) )
4434 utilities.assert_equals( expect=True,
4435 actual=putResult,
4436 onpass="In-Memory Transactional Map put successful",
4437 onfail="In-Memory Transactional Map put values are incorrect" )
4438
4439 main.step( "In-Memory Transactional maps get" )
4440 getCheck = True
4441 for n in range( 1, numKeys + 1 ):
4442 getResponses = []
4443 threads = []
4444 valueCheck = True
4445 for i in range( main.numCtrls ):
4446 t = main.Thread( target=main.CLIs[i].transactionalMapGet,
4447 name="TMap-get-" + str( i ),
4448 args=[ "Key" + str ( n ) ],
4449 kwargs={ "inMemory": True } )
4450 threads.append( t )
4451 t.start()
4452 for t in threads:
4453 t.join()
4454 getResponses.append( t.result )
4455 for node in getResponses:
4456 if node != tMapValue:
4457 valueCheck = False
4458 if not valueCheck:
4459 main.log.warn( "Values for key 'Key" + str( n ) + "' do not match:" )
4460 main.log.warn( getResponses )
4461 getCheck = getCheck and valueCheck
4462 utilities.assert_equals( expect=True,
4463 actual=getCheck,
4464 onpass="In-Memory Transactional Map get values were correct",
4465 onfail="In-Memory Transactional Map values incorrect" )