blob: 234c99549d832bb7959574b14435352c3471953b [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 )
2200 for host in hosts[ controller ]:
2201 if host is None or host.get( 'ipAddresses', [] ) == []:
2202 main.log.error(
Jon Hall3afe4c92015-12-14 19:30:38 -08002203 "Error with host ipAddresses on controller" +
Jon Hall5cf14d52015-07-16 12:15:19 -07002204 controllerStr + ": " + str( host ) )
2205 ipResult = main.FALSE
2206 ports = []
2207 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002208 for i in range( main.numCtrls ):
2209 t = main.Thread( target=main.CLIs[i].ports,
Jon Hall5cf14d52015-07-16 12:15:19 -07002210 name="ports-" + str( i ),
2211 args=[ ] )
2212 threads.append( t )
2213 t.start()
2214
2215 for t in threads:
2216 t.join()
2217 ports.append( t.result )
2218 links = []
2219 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002220 for i in range( main.numCtrls ):
2221 t = main.Thread( target=main.CLIs[i].links,
Jon Hall5cf14d52015-07-16 12:15:19 -07002222 name="links-" + str( i ),
2223 args=[ ] )
2224 threads.append( t )
2225 t.start()
2226
2227 for t in threads:
2228 t.join()
2229 links.append( t.result )
2230 clusters = []
2231 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002232 for i in range( main.numCtrls ):
2233 t = main.Thread( target=main.CLIs[i].clusters,
Jon Hall5cf14d52015-07-16 12:15:19 -07002234 name="clusters-" + str( i ),
2235 args=[ ] )
2236 threads.append( t )
2237 t.start()
2238
2239 for t in threads:
2240 t.join()
2241 clusters.append( t.result )
2242
2243 elapsed = time.time() - startTime
2244 cliTime = time.time() - cliStart
2245 print "Elapsed time: " + str( elapsed )
2246 print "CLI time: " + str( cliTime )
2247
2248 mnSwitches = main.Mininet1.getSwitches()
2249 mnLinks = main.Mininet1.getLinks()
2250 mnHosts = main.Mininet1.getHosts()
Jon Halle1a3b752015-07-22 13:02:46 -07002251 for controller in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07002252 controllerStr = str( controller + 1 )
2253 if devices[ controller ] and ports[ controller ] and\
2254 "Error" not in devices[ controller ] and\
2255 "Error" not in ports[ controller ]:
2256
2257 currentDevicesResult = main.Mininet1.compareSwitches(
2258 mnSwitches,
2259 json.loads( devices[ controller ] ),
2260 json.loads( ports[ controller ] ) )
2261 else:
2262 currentDevicesResult = main.FALSE
2263 utilities.assert_equals( expect=main.TRUE,
2264 actual=currentDevicesResult,
2265 onpass="ONOS" + controllerStr +
2266 " Switches view is correct",
2267 onfail="ONOS" + controllerStr +
2268 " Switches view is incorrect" )
2269
2270 if links[ controller ] and "Error" not in links[ controller ]:
2271 currentLinksResult = main.Mininet1.compareLinks(
2272 mnSwitches, mnLinks,
2273 json.loads( links[ controller ] ) )
2274 else:
2275 currentLinksResult = main.FALSE
2276 utilities.assert_equals( expect=main.TRUE,
2277 actual=currentLinksResult,
2278 onpass="ONOS" + controllerStr +
2279 " links view is correct",
2280 onfail="ONOS" + controllerStr +
2281 " links view is incorrect" )
2282
2283 if hosts[ controller ] or "Error" not in hosts[ controller ]:
2284 currentHostsResult = main.Mininet1.compareHosts(
2285 mnHosts,
2286 hosts[ controller ] )
2287 else:
2288 currentHostsResult = main.FALSE
2289 utilities.assert_equals( expect=main.TRUE,
2290 actual=currentHostsResult,
2291 onpass="ONOS" + controllerStr +
2292 " hosts exist in Mininet",
2293 onfail="ONOS" + controllerStr +
2294 " hosts don't match Mininet" )
2295 # CHECKING HOST ATTACHMENT POINTS
2296 hostAttachment = True
2297 noHosts = False
2298 # FIXME: topo-HA/obelisk specific mappings:
2299 # key is mac and value is dpid
2300 mappings = {}
2301 for i in range( 1, 29 ): # hosts 1 through 28
2302 # set up correct variables:
2303 macId = "00:" * 5 + hex( i ).split( "0x" )[1].upper().zfill(2)
2304 if i == 1:
2305 deviceId = "1000".zfill(16)
2306 elif i == 2:
2307 deviceId = "2000".zfill(16)
2308 elif i == 3:
2309 deviceId = "3000".zfill(16)
2310 elif i == 4:
2311 deviceId = "3004".zfill(16)
2312 elif i == 5:
2313 deviceId = "5000".zfill(16)
2314 elif i == 6:
2315 deviceId = "6000".zfill(16)
2316 elif i == 7:
2317 deviceId = "6007".zfill(16)
2318 elif i >= 8 and i <= 17:
2319 dpid = '3' + str( i ).zfill( 3 )
2320 deviceId = dpid.zfill(16)
2321 elif i >= 18 and i <= 27:
2322 dpid = '6' + str( i ).zfill( 3 )
2323 deviceId = dpid.zfill(16)
2324 elif i == 28:
2325 deviceId = "2800".zfill(16)
2326 mappings[ macId ] = deviceId
2327 if hosts[ controller ] or "Error" not in hosts[ controller ]:
2328 if hosts[ controller ] == []:
2329 main.log.warn( "There are no hosts discovered" )
2330 noHosts = True
2331 else:
2332 for host in hosts[ controller ]:
2333 mac = None
2334 location = None
2335 device = None
2336 port = None
2337 try:
2338 mac = host.get( 'mac' )
2339 assert mac, "mac field could not be found for this host object"
2340
2341 location = host.get( 'location' )
2342 assert location, "location field could not be found for this host object"
2343
2344 # Trim the protocol identifier off deviceId
2345 device = str( location.get( 'elementId' ) ).split(':')[1]
2346 assert device, "elementId field could not be found for this host location object"
2347
2348 port = location.get( 'port' )
2349 assert port, "port field could not be found for this host location object"
2350
2351 # Now check if this matches where they should be
2352 if mac and device and port:
2353 if str( port ) != "1":
2354 main.log.error( "The attachment port is incorrect for " +
2355 "host " + str( mac ) +
2356 ". Expected: 1 Actual: " + str( port) )
2357 hostAttachment = False
2358 if device != mappings[ str( mac ) ]:
2359 main.log.error( "The attachment device is incorrect for " +
2360 "host " + str( mac ) +
2361 ". Expected: " + mappings[ str( mac ) ] +
2362 " Actual: " + device )
2363 hostAttachment = False
2364 else:
2365 hostAttachment = False
2366 except AssertionError:
2367 main.log.exception( "Json object not as expected" )
2368 main.log.error( repr( host ) )
2369 hostAttachment = False
2370 else:
2371 main.log.error( "No hosts json output or \"Error\"" +
2372 " in output. hosts = " +
2373 repr( hosts[ controller ] ) )
2374 if noHosts is False:
2375 # TODO: Find a way to know if there should be hosts in a
2376 # given point of the test
2377 hostAttachment = True
2378
2379 # END CHECKING HOST ATTACHMENT POINTS
2380 devicesResults = devicesResults and currentDevicesResult
2381 linksResults = linksResults and currentLinksResult
2382 hostsResults = hostsResults and currentHostsResult
2383 hostAttachmentResults = hostAttachmentResults and\
2384 hostAttachment
2385 topoResult = ( devicesResults and linksResults
2386 and hostsResults and ipResult and
2387 hostAttachmentResults )
Jon Halle9b1fa32015-12-08 15:32:21 -08002388 utilities.assert_equals( expect=True,
2389 actual=topoResult,
2390 onpass="ONOS topology matches Mininet",
2391 onfail="ONOS topology don't match Mininet" )
2392 # End of While loop to pull ONOS state
Jon Hall5cf14d52015-07-16 12:15:19 -07002393
2394 # Compare json objects for hosts and dataplane clusters
2395
2396 # hosts
2397 main.step( "Hosts view is consistent across all ONOS nodes" )
2398 consistentHostsResult = main.TRUE
2399 for controller in range( len( hosts ) ):
2400 controllerStr = str( controller + 1 )
Jon Hall3afe4c92015-12-14 19:30:38 -08002401 if hosts[ controller ] or "Error" not in hosts[ controller ]:
Jon Hall5cf14d52015-07-16 12:15:19 -07002402 if hosts[ controller ] == hosts[ 0 ]:
2403 continue
2404 else: # hosts not consistent
2405 main.log.error( "hosts from ONOS" + controllerStr +
2406 " is inconsistent with ONOS1" )
2407 main.log.warn( repr( hosts[ controller ] ) )
2408 consistentHostsResult = main.FALSE
2409
2410 else:
2411 main.log.error( "Error in getting ONOS hosts from ONOS" +
2412 controllerStr )
2413 consistentHostsResult = main.FALSE
2414 main.log.warn( "ONOS" + controllerStr +
2415 " hosts response: " +
2416 repr( hosts[ controller ] ) )
2417 utilities.assert_equals(
2418 expect=main.TRUE,
2419 actual=consistentHostsResult,
2420 onpass="Hosts view is consistent across all ONOS nodes",
2421 onfail="ONOS nodes have different views of hosts" )
2422
2423 main.step( "Hosts information is correct" )
2424 hostsResults = hostsResults and ipResult
2425 utilities.assert_equals(
2426 expect=main.TRUE,
2427 actual=hostsResults,
2428 onpass="Host information is correct",
2429 onfail="Host information is incorrect" )
2430
2431 main.step( "Host attachment points to the network" )
2432 utilities.assert_equals(
2433 expect=True,
2434 actual=hostAttachmentResults,
2435 onpass="Hosts are correctly attached to the network",
2436 onfail="ONOS did not correctly attach hosts to the network" )
2437
2438 # Strongly connected clusters of devices
2439 main.step( "Clusters view is consistent across all ONOS nodes" )
2440 consistentClustersResult = main.TRUE
2441 for controller in range( len( clusters ) ):
2442 controllerStr = str( controller + 1 )
2443 if "Error" not in clusters[ controller ]:
2444 if clusters[ controller ] == clusters[ 0 ]:
2445 continue
2446 else: # clusters not consistent
2447 main.log.error( "clusters from ONOS" +
2448 controllerStr +
2449 " is inconsistent with ONOS1" )
2450 consistentClustersResult = main.FALSE
2451
2452 else:
2453 main.log.error( "Error in getting dataplane clusters " +
2454 "from ONOS" + controllerStr )
2455 consistentClustersResult = main.FALSE
2456 main.log.warn( "ONOS" + controllerStr +
2457 " clusters response: " +
2458 repr( clusters[ controller ] ) )
2459 utilities.assert_equals(
2460 expect=main.TRUE,
2461 actual=consistentClustersResult,
2462 onpass="Clusters view is consistent across all ONOS nodes",
2463 onfail="ONOS nodes have different views of clusters" )
2464
2465 main.step( "There is only one SCC" )
2466 # there should always only be one cluster
2467 try:
2468 numClusters = len( json.loads( clusters[ 0 ] ) )
2469 except ( ValueError, TypeError ):
2470 main.log.exception( "Error parsing clusters[0]: " +
2471 repr( clusters[0] ) )
2472 clusterResults = main.FALSE
2473 if numClusters == 1:
2474 clusterResults = main.TRUE
2475 utilities.assert_equals(
2476 expect=1,
2477 actual=numClusters,
2478 onpass="ONOS shows 1 SCC",
2479 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
2480
2481 topoResult = ( devicesResults and linksResults
2482 and hostsResults and consistentHostsResult
2483 and consistentClustersResult and clusterResults
2484 and ipResult and hostAttachmentResults )
2485
2486 topoResult = topoResult and int( count <= 2 )
2487 note = "note it takes about " + str( int( cliTime ) ) + \
2488 " seconds for the test to make all the cli calls to fetch " +\
2489 "the topology from each ONOS instance"
2490 main.log.info(
2491 "Very crass estimate for topology discovery/convergence( " +
2492 str( note ) + " ): " + str( elapsed ) + " seconds, " +
2493 str( count ) + " tries" )
2494
2495 main.step( "Device information is correct" )
2496 utilities.assert_equals(
2497 expect=main.TRUE,
2498 actual=devicesResults,
2499 onpass="Device information is correct",
2500 onfail="Device information is incorrect" )
2501
2502 main.step( "Links are correct" )
2503 utilities.assert_equals(
2504 expect=main.TRUE,
2505 actual=linksResults,
2506 onpass="Link are correct",
2507 onfail="Links are incorrect" )
2508
2509 # FIXME: move this to an ONOS state case
2510 main.step( "Checking ONOS nodes" )
2511 nodesOutput = []
2512 nodeResults = main.TRUE
2513 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002514 for i in range( main.numCtrls ):
2515 t = main.Thread( target=main.CLIs[i].nodes,
Jon Hall5cf14d52015-07-16 12:15:19 -07002516 name="nodes-" + str( i ),
2517 args=[ ] )
2518 threads.append( t )
2519 t.start()
2520
2521 for t in threads:
2522 t.join()
2523 nodesOutput.append( t.result )
Jon Halle1a3b752015-07-22 13:02:46 -07002524 ips = [ node.ip_address for node in main.nodes ]
Jon Halle9b1fa32015-12-08 15:32:21 -08002525 ips.sort()
Jon Hall5cf14d52015-07-16 12:15:19 -07002526 for i in nodesOutput:
2527 try:
2528 current = json.loads( i )
Jon Halle9b1fa32015-12-08 15:32:21 -08002529 activeIps = []
2530 currentResult = main.FALSE
Jon Hall5cf14d52015-07-16 12:15:19 -07002531 for node in current:
Jon Halle9b1fa32015-12-08 15:32:21 -08002532 if node['state'] == 'ACTIVE':
2533 activeIps.append( node['ip'] )
2534 activeIps.sort()
2535 if ips == activeIps:
2536 currentResult = main.TRUE
Jon Hall5cf14d52015-07-16 12:15:19 -07002537 except ( ValueError, TypeError ):
2538 main.log.error( "Error parsing nodes output" )
2539 main.log.warn( repr( i ) )
Jon Halle9b1fa32015-12-08 15:32:21 -08002540 currentResult = main.FALSE
2541 nodeResults = nodeResults and currentResult
Jon Hall5cf14d52015-07-16 12:15:19 -07002542 utilities.assert_equals( expect=main.TRUE, actual=nodeResults,
2543 onpass="Nodes check successful",
2544 onfail="Nodes check NOT successful" )
2545
2546 def CASE9( self, main ):
2547 """
2548 Link s3-s28 down
2549 """
2550 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002551 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002552 assert main, "main not defined"
2553 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002554 assert main.CLIs, "main.CLIs not defined"
2555 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002556 # NOTE: You should probably run a topology check after this
2557
2558 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
2559
2560 description = "Turn off a link to ensure that Link Discovery " +\
2561 "is working properly"
2562 main.case( description )
2563
2564 main.step( "Kill Link between s3 and s28" )
2565 LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" )
2566 main.log.info( "Waiting " + str( linkSleep ) +
2567 " seconds for link down to be discovered" )
2568 time.sleep( linkSleep )
2569 utilities.assert_equals( expect=main.TRUE, actual=LinkDown,
2570 onpass="Link down successful",
2571 onfail="Failed to bring link down" )
2572 # TODO do some sort of check here
2573
2574 def CASE10( self, main ):
2575 """
2576 Link s3-s28 up
2577 """
2578 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002579 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002580 assert main, "main not defined"
2581 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002582 assert main.CLIs, "main.CLIs not defined"
2583 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002584 # NOTE: You should probably run a topology check after this
2585
2586 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
2587
2588 description = "Restore a link to ensure that Link Discovery is " + \
2589 "working properly"
2590 main.case( description )
2591
2592 main.step( "Bring link between s3 and s28 back up" )
2593 LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" )
2594 main.log.info( "Waiting " + str( linkSleep ) +
2595 " seconds for link up to be discovered" )
2596 time.sleep( linkSleep )
2597 utilities.assert_equals( expect=main.TRUE, actual=LinkUp,
2598 onpass="Link up successful",
2599 onfail="Failed to bring link up" )
2600 # TODO do some sort of check here
2601
2602 def CASE11( self, main ):
2603 """
2604 Switch Down
2605 """
2606 # NOTE: You should probably run a topology check after this
2607 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002608 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002609 assert main, "main not defined"
2610 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002611 assert main.CLIs, "main.CLIs not defined"
2612 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002613
2614 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
2615
2616 description = "Killing a switch to ensure it is discovered correctly"
2617 main.case( description )
2618 switch = main.params[ 'kill' ][ 'switch' ]
2619 switchDPID = main.params[ 'kill' ][ 'dpid' ]
2620
2621 # TODO: Make this switch parameterizable
2622 main.step( "Kill " + switch )
2623 main.log.info( "Deleting " + switch )
2624 main.Mininet1.delSwitch( switch )
2625 main.log.info( "Waiting " + str( switchSleep ) +
2626 " seconds for switch down to be discovered" )
2627 time.sleep( switchSleep )
2628 device = main.ONOScli1.getDevice( dpid=switchDPID )
2629 # Peek at the deleted switch
2630 main.log.warn( str( device ) )
2631 result = main.FALSE
2632 if device and device[ 'available' ] is False:
2633 result = main.TRUE
2634 utilities.assert_equals( expect=main.TRUE, actual=result,
2635 onpass="Kill switch successful",
2636 onfail="Failed to kill switch?" )
2637
2638 def CASE12( self, main ):
2639 """
2640 Switch Up
2641 """
2642 # NOTE: You should probably run a topology check after this
2643 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002644 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002645 assert main, "main not defined"
2646 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002647 assert main.CLIs, "main.CLIs not defined"
2648 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002649 assert ONOS1Port, "ONOS1Port not defined"
2650 assert ONOS2Port, "ONOS2Port not defined"
2651 assert ONOS3Port, "ONOS3Port not defined"
2652 assert ONOS4Port, "ONOS4Port not defined"
2653 assert ONOS5Port, "ONOS5Port not defined"
2654 assert ONOS6Port, "ONOS6Port not defined"
2655 assert ONOS7Port, "ONOS7Port not defined"
2656
2657 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
2658 switch = main.params[ 'kill' ][ 'switch' ]
2659 switchDPID = main.params[ 'kill' ][ 'dpid' ]
2660 links = main.params[ 'kill' ][ 'links' ].split()
2661 description = "Adding a switch to ensure it is discovered correctly"
2662 main.case( description )
2663
2664 main.step( "Add back " + switch )
2665 main.Mininet1.addSwitch( switch, dpid=switchDPID )
2666 for peer in links:
2667 main.Mininet1.addLink( switch, peer )
2668 ipList = []
Jon Halle1a3b752015-07-22 13:02:46 -07002669 for i in range( main.numCtrls ):
2670 ipList.append( main.nodes[ i ].ip_address )
Jon Hall5cf14d52015-07-16 12:15:19 -07002671 main.Mininet1.assignSwController( sw=switch, ip=ipList )
2672 main.log.info( "Waiting " + str( switchSleep ) +
2673 " seconds for switch up to be discovered" )
2674 time.sleep( switchSleep )
2675 device = main.ONOScli1.getDevice( dpid=switchDPID )
2676 # Peek at the deleted switch
2677 main.log.warn( str( device ) )
2678 result = main.FALSE
2679 if device and device[ 'available' ]:
2680 result = main.TRUE
2681 utilities.assert_equals( expect=main.TRUE, actual=result,
2682 onpass="add switch successful",
2683 onfail="Failed to add switch?" )
2684
2685 def CASE13( self, main ):
2686 """
2687 Clean up
2688 """
2689 import os
2690 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002691 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002692 assert main, "main not defined"
2693 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002694 assert main.CLIs, "main.CLIs not defined"
2695 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002696
2697 # printing colors to terminal
2698 colors = { 'cyan': '\033[96m', 'purple': '\033[95m',
2699 'blue': '\033[94m', 'green': '\033[92m',
2700 'yellow': '\033[93m', 'red': '\033[91m', 'end': '\033[0m' }
2701 main.case( "Test Cleanup" )
2702 main.step( "Killing tcpdumps" )
2703 main.Mininet2.stopTcpdump()
2704
2705 testname = main.TEST
Jon Hall5ec6b1b2015-09-17 18:20:14 -07002706 if main.params[ 'BACKUP' ][ 'ENABLED' ] == "True":
Jon Hall5cf14d52015-07-16 12:15:19 -07002707 main.step( "Copying MN pcap and ONOS log files to test station" )
2708 teststationUser = main.params[ 'BACKUP' ][ 'TESTONUSER' ]
2709 teststationIP = main.params[ 'BACKUP' ][ 'TESTONIP' ]
Jon Hall96091e62015-09-21 17:34:17 -07002710 # NOTE: MN Pcap file is being saved to logdir.
2711 # We scp this file as MN and TestON aren't necessarily the same vm
2712
2713 # FIXME: To be replaced with a Jenkin's post script
Jon Hall5cf14d52015-07-16 12:15:19 -07002714 # TODO: Load these from params
2715 # NOTE: must end in /
2716 logFolder = "/opt/onos/log/"
2717 logFiles = [ "karaf.log", "karaf.log.1" ]
2718 # NOTE: must end in /
Jon Hall5cf14d52015-07-16 12:15:19 -07002719 for f in logFiles:
Jon Halle1a3b752015-07-22 13:02:46 -07002720 for node in main.nodes:
Jon Hall96091e62015-09-21 17:34:17 -07002721 dstName = main.logdir + "/" + node.name + "-" + f
2722 main.ONOSbench.secureCopy( node.user_name, node.ip_address,
2723 logFolder + f, dstName )
Jon Hall5cf14d52015-07-16 12:15:19 -07002724 # std*.log's
2725 # NOTE: must end in /
2726 logFolder = "/opt/onos/var/"
2727 logFiles = [ "stderr.log", "stdout.log" ]
2728 # NOTE: must end in /
Jon Hall5cf14d52015-07-16 12:15:19 -07002729 for f in logFiles:
Jon Halle1a3b752015-07-22 13:02:46 -07002730 for node in main.nodes:
Jon Hall96091e62015-09-21 17:34:17 -07002731 dstName = main.logdir + "/" + node.name + "-" + f
2732 main.ONOSbench.secureCopy( node.user_name, node.ip_address,
2733 logFolder + f, dstName )
Jon Hall5ec6b1b2015-09-17 18:20:14 -07002734 else:
2735 main.log.debug( "skipping saving log files" )
Jon Hall5cf14d52015-07-16 12:15:19 -07002736
2737 main.step( "Stopping Mininet" )
2738 mnResult = main.Mininet1.stopNet()
2739 utilities.assert_equals( expect=main.TRUE, actual=mnResult,
2740 onpass="Mininet stopped",
2741 onfail="MN cleanup NOT successful" )
2742
2743 main.step( "Checking ONOS Logs for errors" )
Jon Halle1a3b752015-07-22 13:02:46 -07002744 for node in main.nodes:
Jon Hall5ec6b1b2015-09-17 18:20:14 -07002745 main.log.debug( "Checking logs for errors on " + node.name + ":" )
2746 main.log.warn( main.ONOSbench.checkLogs( node.ip_address ) )
Jon Hall5cf14d52015-07-16 12:15:19 -07002747
2748 try:
2749 timerLog = open( main.logdir + "/Timers.csv", 'w')
2750 main.log.error( ", ".join( labels ) + "\n" + ", ".join( data ) )
2751 timerLog.write( ", ".join( labels ) + "\n" + ", ".join( data ) )
2752 timerLog.close()
2753 except NameError, e:
2754 main.log.exception(e)
2755
2756 def CASE14( self, main ):
2757 """
2758 start election app on all onos nodes
2759 """
Jon Halle1a3b752015-07-22 13:02:46 -07002760 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002761 assert main, "main not defined"
2762 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002763 assert main.CLIs, "main.CLIs not defined"
2764 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002765
2766 main.case("Start Leadership Election app")
2767 main.step( "Install leadership election app" )
2768 appResult = main.ONOScli1.activateApp( "org.onosproject.election" )
2769 utilities.assert_equals(
2770 expect=main.TRUE,
2771 actual=appResult,
2772 onpass="Election app installed",
2773 onfail="Something went wrong with installing Leadership election" )
2774
2775 main.step( "Run for election on each node" )
2776 leaderResult = main.TRUE
2777 leaders = []
Jon Halle1a3b752015-07-22 13:02:46 -07002778 for cli in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -07002779 cli.electionTestRun()
Jon Halle1a3b752015-07-22 13:02:46 -07002780 for cli in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -07002781 leader = cli.electionTestLeader()
2782 if leader is None or leader == main.FALSE:
2783 main.log.error( cli.name + ": Leader for the election app " +
2784 "should be an ONOS node, instead got '" +
2785 str( leader ) + "'" )
2786 leaderResult = main.FALSE
2787 leaders.append( leader )
2788 utilities.assert_equals(
2789 expect=main.TRUE,
2790 actual=leaderResult,
2791 onpass="Successfully ran for leadership",
2792 onfail="Failed to run for leadership" )
2793
2794 main.step( "Check that each node shows the same leader" )
2795 sameLeader = main.TRUE
2796 if len( set( leaders ) ) != 1:
2797 sameLeader = main.FALSE
2798 main.log.error( "Results of electionTestLeader is order of CLIs:" +
2799 str( leaders ) )
2800 utilities.assert_equals(
2801 expect=main.TRUE,
2802 actual=sameLeader,
2803 onpass="Leadership is consistent for the election topic",
2804 onfail="Nodes have different leaders" )
2805
2806 def CASE15( self, main ):
2807 """
2808 Check that Leadership Election is still functional
acsmars9475b1c2015-08-28 18:02:08 -07002809 15.1 Run election on each node
2810 15.2 Check that each node has the same leaders and candidates
2811 15.3 Find current leader and withdraw
2812 15.4 Check that a new node was elected leader
2813 15.5 Check that that new leader was the candidate of old leader
2814 15.6 Run for election on old leader
2815 15.7 Check that oldLeader is a candidate, and leader if only 1 node
2816 15.8 Make sure that the old leader was added to the candidate list
2817
2818 old and new variable prefixes refer to data from before vs after
2819 withdrawl and later before withdrawl vs after re-election
Jon Hall5cf14d52015-07-16 12:15:19 -07002820 """
2821 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002822 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002823 assert main, "main not defined"
2824 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002825 assert main.CLIs, "main.CLIs not defined"
2826 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002827
Jon Hall5cf14d52015-07-16 12:15:19 -07002828 description = "Check that Leadership Election is still functional"
2829 main.case( description )
2830 # NOTE: Need to re-run since being a canidate is not persistant
acsmars9475b1c2015-08-28 18:02:08 -07002831 # TODO: add check for "Command not found:" in the driver, this
2832 # means the election test app isn't loaded
2833
2834 oldLeaders = [] # leaders by node before withdrawl from candidates
2835 newLeaders = [] # leaders by node after withdrawl from candidates
2836 oldAllCandidates = [] # list of lists of each nodes' candidates before
2837 newAllCandidates = [] # list of lists of each nodes' candidates after
2838 oldCandidates = [] # list of candidates from node 0 before withdrawl
2839 newCandidates = [] # list of candidates from node 0 after withdrawl
2840 oldLeader = '' # the old leader from oldLeaders, None if not same
2841 newLeader = '' # the new leaders fron newLoeaders, None if not same
2842 oldLeaderCLI = None # the CLI of the old leader used for re-electing
acsmars71adceb2015-08-31 15:09:26 -07002843 expectNoLeader = False # True when there is only one leader
2844 if main.numCtrls == 1:
2845 expectNoLeader = True
acsmars9475b1c2015-08-28 18:02:08 -07002846
Jon Hall5cf14d52015-07-16 12:15:19 -07002847 main.step( "Run for election on each node" )
acsmars9475b1c2015-08-28 18:02:08 -07002848 electionResult = main.TRUE
2849
2850 for cli in main.CLIs: # run test election on each node
2851 if cli.electionTestRun() == main.FALSE:
2852 electionResult = main.FALSE
2853
Jon Hall5cf14d52015-07-16 12:15:19 -07002854 utilities.assert_equals(
2855 expect=main.TRUE,
acsmars9475b1c2015-08-28 18:02:08 -07002856 actual=electionResult,
2857 onpass="All nodes successfully ran for leadership",
2858 onfail="At least one node failed to run for leadership" )
Jon Hall5cf14d52015-07-16 12:15:19 -07002859
acsmars3a72bde2015-09-02 14:16:22 -07002860 if electionResult == main.FALSE:
2861 main.log.error(
2862 "Skipping Test Case because Election Test App isn't loaded" )
2863 main.skipCase()
2864
acsmars9475b1c2015-08-28 18:02:08 -07002865 main.step( "Check that each node shows the same leader and candidates" )
2866 sameResult = main.TRUE
2867 failMessage = "Nodes have different leaders"
2868 for cli in main.CLIs:
2869 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
2870 oldAllCandidates.append( node )
2871 oldLeaders.append( node[ 0 ] )
2872 oldCandidates = oldAllCandidates[ 0 ]
2873
2874 # Check that each node has the same leader. Defines oldLeader
2875 if len( set( oldLeaders ) ) != 1:
2876 sameResult = main.FALSE
acsmars71adceb2015-08-31 15:09:26 -07002877 main.log.error( "More than one leader present:" + str( oldLeaders ) )
acsmars9475b1c2015-08-28 18:02:08 -07002878 oldLeader = None
2879 else:
2880 oldLeader = oldLeaders[ 0 ]
2881
2882 # Check that each node's candidate list is the same
acsmars29233db2015-11-04 11:15:00 -08002883 candidateDiscrepancy = False # Boolean of candidate mismatches
acsmars9475b1c2015-08-28 18:02:08 -07002884 for candidates in oldAllCandidates:
2885 if set( candidates ) != set( oldCandidates ):
2886 sameResult = main.FALSE
acsmars29233db2015-11-04 11:15:00 -08002887 candidateDiscrepancy = True
2888
2889 if candidateDiscrepancy:
2890 failMessage += " and candidates"
acsmars9475b1c2015-08-28 18:02:08 -07002891
Jon Hall5cf14d52015-07-16 12:15:19 -07002892 utilities.assert_equals(
2893 expect=main.TRUE,
acsmars71adceb2015-08-31 15:09:26 -07002894 actual=sameResult,
Jon Hall5cf14d52015-07-16 12:15:19 -07002895 onpass="Leadership is consistent for the election topic",
acsmars9475b1c2015-08-28 18:02:08 -07002896 onfail=failMessage )
Jon Hall5cf14d52015-07-16 12:15:19 -07002897
2898 main.step( "Find current leader and withdraw" )
acsmars9475b1c2015-08-28 18:02:08 -07002899 withdrawResult = main.TRUE
Jon Hall5cf14d52015-07-16 12:15:19 -07002900 # do some sanity checking on leader before using it
acsmars9475b1c2015-08-28 18:02:08 -07002901 if oldLeader is None:
2902 main.log.error( "Leadership isn't consistent." )
2903 withdrawResult = main.FALSE
2904 # Get the CLI of the oldLeader
Jon Halle1a3b752015-07-22 13:02:46 -07002905 for i in range( len( main.CLIs ) ):
acsmars9475b1c2015-08-28 18:02:08 -07002906 if oldLeader == main.nodes[ i ].ip_address:
2907 oldLeaderCLI = main.CLIs[ i ]
Jon Hall5cf14d52015-07-16 12:15:19 -07002908 break
2909 else: # FOR/ELSE statement
2910 main.log.error( "Leader election, could not find current leader" )
2911 if oldLeader:
acsmars9475b1c2015-08-28 18:02:08 -07002912 withdrawResult = oldLeaderCLI.electionTestWithdraw()
Jon Hall5cf14d52015-07-16 12:15:19 -07002913 utilities.assert_equals(
2914 expect=main.TRUE,
2915 actual=withdrawResult,
2916 onpass="Node was withdrawn from election",
2917 onfail="Node was not withdrawn from election" )
2918
acsmars9475b1c2015-08-28 18:02:08 -07002919 main.step( "Check that a new node was elected leader" )
acsmars71adceb2015-08-31 15:09:26 -07002920
Jon Hall5cf14d52015-07-16 12:15:19 -07002921 # FIXME: use threads
acsmars9475b1c2015-08-28 18:02:08 -07002922 newLeaderResult = main.TRUE
2923 failMessage = "Nodes have different leaders"
2924
2925 # Get new leaders and candidates
Jon Halle1a3b752015-07-22 13:02:46 -07002926 for cli in main.CLIs:
acsmars9475b1c2015-08-28 18:02:08 -07002927 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
acsmars71adceb2015-08-31 15:09:26 -07002928 # elections might no have finished yet
2929 if node[ 0 ] == 'none' and not expectNoLeader:
acsmars9475b1c2015-08-28 18:02:08 -07002930 main.log.info( "Node has no leader, waiting 5 seconds to be " +
2931 "sure elections are complete." )
2932 time.sleep(5)
2933 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
acsmars71adceb2015-08-31 15:09:26 -07002934 # election still isn't done or there is a problem
2935 if node[ 0 ] == 'none':
2936 main.log.error( "No leader was elected on at least 1 node" )
2937 newLeaderResult = main.FALSE
acsmars9475b1c2015-08-28 18:02:08 -07002938 newAllCandidates.append( node )
2939 newLeaders.append( node[ 0 ] )
2940 newCandidates = newAllCandidates[ 0 ]
2941
2942 # Check that each node has the same leader. Defines newLeader
2943 if len( set( newLeaders ) ) != 1:
2944 newLeaderResult = main.FALSE
2945 main.log.error( "Nodes have different leaders: " +
2946 str( newLeaders ) )
2947 newLeader = None
Jon Hall5cf14d52015-07-16 12:15:19 -07002948 else:
acsmars9475b1c2015-08-28 18:02:08 -07002949 newLeader = newLeaders[ 0 ]
2950
acsmars71adceb2015-08-31 15:09:26 -07002951 # Check that each node's candidate list is the same
2952 for candidates in newAllCandidates:
2953 if set( candidates ) != set( newCandidates ):
2954 newLeaderResult = main.FALSE
Jon Hallceb4abb2015-09-25 12:03:06 -07002955 main.log.error( "Discrepancy in candidate lists detected" )
acsmars71adceb2015-08-31 15:09:26 -07002956
acsmars9475b1c2015-08-28 18:02:08 -07002957 # Check that the new leader is not the older leader, which was withdrawn
2958 if newLeader == oldLeader:
2959 newLeaderResult = main.FALSE
2960 main.log.error( "All nodes still see old leader: " + oldLeader +
2961 " as the current leader" )
2962
Jon Hall5cf14d52015-07-16 12:15:19 -07002963 utilities.assert_equals(
2964 expect=main.TRUE,
acsmars9475b1c2015-08-28 18:02:08 -07002965 actual=newLeaderResult,
Jon Hall5cf14d52015-07-16 12:15:19 -07002966 onpass="Leadership election passed",
2967 onfail="Something went wrong with Leadership election" )
2968
acsmars9475b1c2015-08-28 18:02:08 -07002969 main.step( "Check that that new leader was the candidate of old leader")
2970 # candidates[ 2 ] should be come the top candidate after withdrawl
2971 correctCandidateResult = main.TRUE
acsmars71adceb2015-08-31 15:09:26 -07002972 if expectNoLeader:
2973 if newLeader == 'none':
2974 main.log.info( "No leader expected. None found. Pass" )
2975 correctCandidateResult = main.TRUE
2976 else:
2977 main.log.info( "Expected no leader, got: " + str( newLeader ) )
2978 correctCandidateResult = main.FALSE
2979 elif newLeader != oldCandidates[ 2 ]:
acsmars9475b1c2015-08-28 18:02:08 -07002980 correctCandidateResult = main.FALSE
2981 main.log.error( "Candidate " + newLeader + " was elected. " +
2982 oldCandidates[ 2 ] + " should have had priority." )
2983
2984 utilities.assert_equals(
2985 expect=main.TRUE,
2986 actual=correctCandidateResult,
2987 onpass="Correct Candidate Elected",
2988 onfail="Incorrect Candidate Elected" )
2989
Jon Hall5cf14d52015-07-16 12:15:19 -07002990 main.step( "Run for election on old leader( just so everyone " +
2991 "is in the hat )" )
acsmars9475b1c2015-08-28 18:02:08 -07002992 if oldLeaderCLI is not None:
2993 runResult = oldLeaderCLI.electionTestRun()
Jon Hall5cf14d52015-07-16 12:15:19 -07002994 else:
acsmars9475b1c2015-08-28 18:02:08 -07002995 main.log.error( "No old leader to re-elect" )
Jon Hall5cf14d52015-07-16 12:15:19 -07002996 runResult = main.FALSE
2997 utilities.assert_equals(
2998 expect=main.TRUE,
2999 actual=runResult,
3000 onpass="App re-ran for election",
3001 onfail="App failed to run for election" )
acsmars9475b1c2015-08-28 18:02:08 -07003002 main.step(
3003 "Check that oldLeader is a candidate, and leader if only 1 node" )
Jon Hall5cf14d52015-07-16 12:15:19 -07003004 # verify leader didn't just change
acsmars9475b1c2015-08-28 18:02:08 -07003005 positionResult = main.TRUE
3006 # Get new leaders and candidates, wait if oldLeader is not a candidate yet
3007
3008 # Reset and reuse the new candidate and leaders lists
3009 newAllCandidates = []
3010 newCandidates = []
3011 newLeaders = []
3012 for cli in main.CLIs:
3013 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
3014 if oldLeader not in node: # election might no have finished yet
3015 main.log.info( "Old Leader not elected, waiting 5 seconds to " +
3016 "be sure elections are complete" )
3017 time.sleep(5)
3018 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
3019 if oldLeader not in node: # election still isn't done, errors
3020 main.log.error(
3021 "Old leader was not elected on at least one node" )
3022 positionResult = main.FALSE
3023 newAllCandidates.append( node )
3024 newLeaders.append( node[ 0 ] )
3025 newCandidates = newAllCandidates[ 0 ]
3026
3027 # Check that each node has the same leader. Defines newLeader
3028 if len( set( newLeaders ) ) != 1:
3029 positionResult = main.FALSE
3030 main.log.error( "Nodes have different leaders: " +
3031 str( newLeaders ) )
3032 newLeader = None
Jon Hall5cf14d52015-07-16 12:15:19 -07003033 else:
acsmars9475b1c2015-08-28 18:02:08 -07003034 newLeader = newLeaders[ 0 ]
3035
acsmars71adceb2015-08-31 15:09:26 -07003036 # Check that each node's candidate list is the same
3037 for candidates in newAllCandidates:
3038 if set( candidates ) != set( newCandidates ):
3039 newLeaderResult = main.FALSE
Jon Hallceb4abb2015-09-25 12:03:06 -07003040 main.log.error( "Discrepancy in candidate lists detected" )
acsmars71adceb2015-08-31 15:09:26 -07003041
acsmars9475b1c2015-08-28 18:02:08 -07003042 # Check that the re-elected node is last on the candidate List
3043 if oldLeader != newCandidates[ -1 ]:
3044 main.log.error( "Old Leader (" + oldLeader + ") not in the proper position " +
3045 str( newCandidates ) )
3046 positionResult = main.FALSE
Jon Hall5cf14d52015-07-16 12:15:19 -07003047
3048 utilities.assert_equals(
3049 expect=main.TRUE,
acsmars9475b1c2015-08-28 18:02:08 -07003050 actual=positionResult,
Jon Hall5cf14d52015-07-16 12:15:19 -07003051 onpass="Old leader successfully re-ran for election",
3052 onfail="Something went wrong with Leadership election after " +
3053 "the old leader re-ran for election" )
3054
3055 def CASE16( self, main ):
3056 """
3057 Install Distributed Primitives app
3058 """
3059 import time
Jon Halle1a3b752015-07-22 13:02:46 -07003060 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07003061 assert main, "main not defined"
3062 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07003063 assert main.CLIs, "main.CLIs not defined"
3064 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07003065
3066 # Variables for the distributed primitives tests
3067 global pCounterName
3068 global iCounterName
3069 global pCounterValue
3070 global iCounterValue
3071 global onosSet
3072 global onosSetName
3073 pCounterName = "TestON-Partitions"
3074 iCounterName = "TestON-inMemory"
3075 pCounterValue = 0
3076 iCounterValue = 0
3077 onosSet = set([])
3078 onosSetName = "TestON-set"
3079
3080 description = "Install Primitives app"
3081 main.case( description )
3082 main.step( "Install Primitives app" )
3083 appName = "org.onosproject.distributedprimitives"
Jon Halle1a3b752015-07-22 13:02:46 -07003084 appResults = main.CLIs[0].activateApp( appName )
Jon Hall5cf14d52015-07-16 12:15:19 -07003085 utilities.assert_equals( expect=main.TRUE,
3086 actual=appResults,
3087 onpass="Primitives app activated",
3088 onfail="Primitives app not activated" )
3089 time.sleep( 5 ) # To allow all nodes to activate
3090
3091 def CASE17( self, main ):
3092 """
3093 Check for basic functionality with distributed primitives
3094 """
Jon Hall5cf14d52015-07-16 12:15:19 -07003095 # Make sure variables are defined/set
Jon Halle1a3b752015-07-22 13:02:46 -07003096 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07003097 assert main, "main not defined"
3098 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07003099 assert main.CLIs, "main.CLIs not defined"
3100 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07003101 assert pCounterName, "pCounterName not defined"
3102 assert iCounterName, "iCounterName not defined"
3103 assert onosSetName, "onosSetName not defined"
3104 # NOTE: assert fails if value is 0/None/Empty/False
3105 try:
3106 pCounterValue
3107 except NameError:
3108 main.log.error( "pCounterValue not defined, setting to 0" )
3109 pCounterValue = 0
3110 try:
3111 iCounterValue
3112 except NameError:
3113 main.log.error( "iCounterValue not defined, setting to 0" )
3114 iCounterValue = 0
3115 try:
3116 onosSet
3117 except NameError:
3118 main.log.error( "onosSet not defined, setting to empty Set" )
3119 onosSet = set([])
3120 # Variables for the distributed primitives tests. These are local only
3121 addValue = "a"
3122 addAllValue = "a b c d e f"
3123 retainValue = "c d e f"
3124
3125 description = "Check for basic functionality with distributed " +\
3126 "primitives"
3127 main.case( description )
Jon Halle1a3b752015-07-22 13:02:46 -07003128 main.caseExplanation = "Test the methods of the distributed " +\
3129 "primitives (counters and sets) throught the cli"
Jon Hall5cf14d52015-07-16 12:15:19 -07003130 # DISTRIBUTED ATOMIC COUNTERS
Jon Halle1a3b752015-07-22 13:02:46 -07003131 # Partitioned counters
3132 main.step( "Increment then get a default counter on each node" )
Jon Hall5cf14d52015-07-16 12:15:19 -07003133 pCounters = []
3134 threads = []
3135 addedPValues = []
Jon Halle1a3b752015-07-22 13:02:46 -07003136 for i in range( main.numCtrls ):
3137 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
3138 name="counterAddAndGet-" + str( i ),
Jon Hall5cf14d52015-07-16 12:15:19 -07003139 args=[ pCounterName ] )
3140 pCounterValue += 1
3141 addedPValues.append( pCounterValue )
3142 threads.append( t )
3143 t.start()
3144
3145 for t in threads:
3146 t.join()
3147 pCounters.append( t.result )
3148 # Check that counter incremented numController times
3149 pCounterResults = True
3150 for i in addedPValues:
3151 tmpResult = i in pCounters
3152 pCounterResults = pCounterResults and tmpResult
3153 if not tmpResult:
3154 main.log.error( str( i ) + " is not in partitioned "
3155 "counter incremented results" )
3156 utilities.assert_equals( expect=True,
3157 actual=pCounterResults,
3158 onpass="Default counter incremented",
3159 onfail="Error incrementing default" +
3160 " counter" )
3161
Jon Halle1a3b752015-07-22 13:02:46 -07003162 main.step( "Get then Increment a default counter on each node" )
3163 pCounters = []
3164 threads = []
3165 addedPValues = []
3166 for i in range( main.numCtrls ):
3167 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
3168 name="counterGetAndAdd-" + str( i ),
3169 args=[ pCounterName ] )
3170 addedPValues.append( pCounterValue )
3171 pCounterValue += 1
3172 threads.append( t )
3173 t.start()
3174
3175 for t in threads:
3176 t.join()
3177 pCounters.append( t.result )
3178 # Check that counter incremented numController times
3179 pCounterResults = True
3180 for i in addedPValues:
3181 tmpResult = i in pCounters
3182 pCounterResults = pCounterResults and tmpResult
3183 if not tmpResult:
3184 main.log.error( str( i ) + " is not in partitioned "
3185 "counter incremented results" )
3186 utilities.assert_equals( expect=True,
3187 actual=pCounterResults,
3188 onpass="Default counter incremented",
3189 onfail="Error incrementing default" +
3190 " counter" )
3191
3192 main.step( "Counters we added have the correct values" )
3193 incrementCheck = main.Counters.counterCheck( pCounterName, pCounterValue )
3194 utilities.assert_equals( expect=main.TRUE,
3195 actual=incrementCheck,
3196 onpass="Added counters are correct",
3197 onfail="Added counters are incorrect" )
3198
3199 main.step( "Add -8 to then get a default counter on each node" )
3200 pCounters = []
3201 threads = []
3202 addedPValues = []
3203 for i in range( main.numCtrls ):
3204 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
3205 name="counterIncrement-" + str( i ),
3206 args=[ pCounterName ],
3207 kwargs={ "delta": -8 } )
3208 pCounterValue += -8
3209 addedPValues.append( pCounterValue )
3210 threads.append( t )
3211 t.start()
3212
3213 for t in threads:
3214 t.join()
3215 pCounters.append( t.result )
3216 # Check that counter incremented numController times
3217 pCounterResults = True
3218 for i in addedPValues:
3219 tmpResult = i in pCounters
3220 pCounterResults = pCounterResults and tmpResult
3221 if not tmpResult:
3222 main.log.error( str( i ) + " is not in partitioned "
3223 "counter incremented results" )
3224 utilities.assert_equals( expect=True,
3225 actual=pCounterResults,
3226 onpass="Default counter incremented",
3227 onfail="Error incrementing default" +
3228 " counter" )
3229
3230 main.step( "Add 5 to then get a default counter on each node" )
3231 pCounters = []
3232 threads = []
3233 addedPValues = []
3234 for i in range( main.numCtrls ):
3235 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
3236 name="counterIncrement-" + str( i ),
3237 args=[ pCounterName ],
3238 kwargs={ "delta": 5 } )
3239 pCounterValue += 5
3240 addedPValues.append( pCounterValue )
3241 threads.append( t )
3242 t.start()
3243
3244 for t in threads:
3245 t.join()
3246 pCounters.append( t.result )
3247 # Check that counter incremented numController times
3248 pCounterResults = True
3249 for i in addedPValues:
3250 tmpResult = i in pCounters
3251 pCounterResults = pCounterResults and tmpResult
3252 if not tmpResult:
3253 main.log.error( str( i ) + " is not in partitioned "
3254 "counter incremented results" )
3255 utilities.assert_equals( expect=True,
3256 actual=pCounterResults,
3257 onpass="Default counter incremented",
3258 onfail="Error incrementing default" +
3259 " counter" )
3260
3261 main.step( "Get then add 5 to a default counter on each node" )
3262 pCounters = []
3263 threads = []
3264 addedPValues = []
3265 for i in range( main.numCtrls ):
3266 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
3267 name="counterIncrement-" + str( i ),
3268 args=[ pCounterName ],
3269 kwargs={ "delta": 5 } )
3270 addedPValues.append( pCounterValue )
3271 pCounterValue += 5
3272 threads.append( t )
3273 t.start()
3274
3275 for t in threads:
3276 t.join()
3277 pCounters.append( t.result )
3278 # Check that counter incremented numController times
3279 pCounterResults = True
3280 for i in addedPValues:
3281 tmpResult = i in pCounters
3282 pCounterResults = pCounterResults and tmpResult
3283 if not tmpResult:
3284 main.log.error( str( i ) + " is not in partitioned "
3285 "counter incremented results" )
3286 utilities.assert_equals( expect=True,
3287 actual=pCounterResults,
3288 onpass="Default counter incremented",
3289 onfail="Error incrementing default" +
3290 " counter" )
3291
3292 main.step( "Counters we added have the correct values" )
3293 incrementCheck = main.Counters.counterCheck( pCounterName, pCounterValue )
3294 utilities.assert_equals( expect=main.TRUE,
3295 actual=incrementCheck,
3296 onpass="Added counters are correct",
3297 onfail="Added counters are incorrect" )
3298
3299 # In-Memory counters
3300 main.step( "Increment and get an in-memory counter on each node" )
Jon Hall5cf14d52015-07-16 12:15:19 -07003301 iCounters = []
3302 addedIValues = []
3303 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003304 for i in range( main.numCtrls ):
3305 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003306 name="icounterIncrement-" + str( i ),
3307 args=[ iCounterName ],
3308 kwargs={ "inMemory": True } )
3309 iCounterValue += 1
3310 addedIValues.append( iCounterValue )
3311 threads.append( t )
3312 t.start()
3313
3314 for t in threads:
3315 t.join()
3316 iCounters.append( t.result )
3317 # Check that counter incremented numController times
3318 iCounterResults = True
3319 for i in addedIValues:
3320 tmpResult = i in iCounters
3321 iCounterResults = iCounterResults and tmpResult
3322 if not tmpResult:
3323 main.log.error( str( i ) + " is not in the in-memory "
3324 "counter incremented results" )
3325 utilities.assert_equals( expect=True,
3326 actual=iCounterResults,
Jon Halle1a3b752015-07-22 13:02:46 -07003327 onpass="In-memory counter incremented",
3328 onfail="Error incrementing in-memory" +
Jon Hall5cf14d52015-07-16 12:15:19 -07003329 " counter" )
3330
Jon Halle1a3b752015-07-22 13:02:46 -07003331 main.step( "Get then Increment a in-memory counter on each node" )
3332 iCounters = []
3333 threads = []
3334 addedIValues = []
3335 for i in range( main.numCtrls ):
3336 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
3337 name="counterGetAndAdd-" + str( i ),
3338 args=[ iCounterName ],
3339 kwargs={ "inMemory": True } )
3340 addedIValues.append( iCounterValue )
3341 iCounterValue += 1
3342 threads.append( t )
3343 t.start()
3344
3345 for t in threads:
3346 t.join()
3347 iCounters.append( t.result )
3348 # Check that counter incremented numController times
3349 iCounterResults = True
3350 for i in addedIValues:
3351 tmpResult = i in iCounters
3352 iCounterResults = iCounterResults and tmpResult
3353 if not tmpResult:
3354 main.log.error( str( i ) + " is not in in-memory "
3355 "counter incremented results" )
3356 utilities.assert_equals( expect=True,
3357 actual=iCounterResults,
3358 onpass="In-memory counter incremented",
3359 onfail="Error incrementing in-memory" +
3360 " counter" )
3361
3362 main.step( "Counters we added have the correct values" )
3363 incrementCheck = main.Counters.counterCheck( iCounterName, iCounterValue )
3364 utilities.assert_equals( expect=main.TRUE,
3365 actual=incrementCheck,
3366 onpass="Added counters are correct",
3367 onfail="Added counters are incorrect" )
3368
3369 main.step( "Add -8 to then get a in-memory counter on each node" )
3370 iCounters = []
3371 threads = []
3372 addedIValues = []
3373 for i in range( main.numCtrls ):
3374 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
3375 name="counterIncrement-" + str( i ),
3376 args=[ iCounterName ],
3377 kwargs={ "delta": -8, "inMemory": True } )
3378 iCounterValue += -8
3379 addedIValues.append( iCounterValue )
3380 threads.append( t )
3381 t.start()
3382
3383 for t in threads:
3384 t.join()
3385 iCounters.append( t.result )
3386 # Check that counter incremented numController times
3387 iCounterResults = True
3388 for i in addedIValues:
3389 tmpResult = i in iCounters
3390 iCounterResults = iCounterResults and tmpResult
3391 if not tmpResult:
3392 main.log.error( str( i ) + " is not in in-memory "
3393 "counter incremented results" )
3394 utilities.assert_equals( expect=True,
3395 actual=pCounterResults,
3396 onpass="In-memory counter incremented",
3397 onfail="Error incrementing in-memory" +
3398 " counter" )
3399
3400 main.step( "Add 5 to then get a in-memory counter on each node" )
3401 iCounters = []
3402 threads = []
3403 addedIValues = []
3404 for i in range( main.numCtrls ):
3405 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
3406 name="counterIncrement-" + str( i ),
3407 args=[ iCounterName ],
3408 kwargs={ "delta": 5, "inMemory": True } )
3409 iCounterValue += 5
3410 addedIValues.append( iCounterValue )
3411 threads.append( t )
3412 t.start()
3413
3414 for t in threads:
3415 t.join()
3416 iCounters.append( t.result )
3417 # Check that counter incremented numController times
3418 iCounterResults = True
3419 for i in addedIValues:
3420 tmpResult = i in iCounters
3421 iCounterResults = iCounterResults and tmpResult
3422 if not tmpResult:
3423 main.log.error( str( i ) + " is not in in-memory "
3424 "counter incremented results" )
3425 utilities.assert_equals( expect=True,
3426 actual=pCounterResults,
3427 onpass="In-memory counter incremented",
3428 onfail="Error incrementing in-memory" +
3429 " counter" )
3430
3431 main.step( "Get then add 5 to a in-memory counter on each node" )
3432 iCounters = []
3433 threads = []
3434 addedIValues = []
3435 for i in range( main.numCtrls ):
3436 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
3437 name="counterIncrement-" + str( i ),
3438 args=[ iCounterName ],
3439 kwargs={ "delta": 5, "inMemory": True } )
3440 addedIValues.append( iCounterValue )
3441 iCounterValue += 5
3442 threads.append( t )
3443 t.start()
3444
3445 for t in threads:
3446 t.join()
3447 iCounters.append( t.result )
3448 # Check that counter incremented numController times
3449 iCounterResults = True
3450 for i in addedIValues:
3451 tmpResult = i in iCounters
3452 iCounterResults = iCounterResults and tmpResult
3453 if not tmpResult:
3454 main.log.error( str( i ) + " is not in in-memory "
3455 "counter incremented results" )
3456 utilities.assert_equals( expect=True,
3457 actual=iCounterResults,
3458 onpass="In-memory counter incremented",
3459 onfail="Error incrementing in-memory" +
3460 " counter" )
3461
3462 main.step( "Counters we added have the correct values" )
3463 incrementCheck = main.Counters.counterCheck( iCounterName, iCounterValue )
3464 utilities.assert_equals( expect=main.TRUE,
3465 actual=incrementCheck,
3466 onpass="Added counters are correct",
3467 onfail="Added counters are incorrect" )
3468
Jon Hall5cf14d52015-07-16 12:15:19 -07003469 main.step( "Check counters are consistant across nodes" )
Jon Hall57b50432015-10-22 10:20:10 -07003470 onosCounters, consistentCounterResults = main.Counters.consistentCheck()
Jon Hall5cf14d52015-07-16 12:15:19 -07003471 utilities.assert_equals( expect=main.TRUE,
3472 actual=consistentCounterResults,
3473 onpass="ONOS counters are consistent " +
3474 "across nodes",
3475 onfail="ONOS Counters are inconsistent " +
3476 "across nodes" )
3477
3478 main.step( "Counters we added have the correct values" )
Jon Halle1a3b752015-07-22 13:02:46 -07003479 incrementCheck = main.Counters.counterCheck( iCounterName, iCounterValue )
3480 incrementCheck = incrementCheck and \
3481 main.Counters.counterCheck( iCounterName, iCounterValue )
Jon Hall5cf14d52015-07-16 12:15:19 -07003482 utilities.assert_equals( expect=main.TRUE,
Jon Halle1a3b752015-07-22 13:02:46 -07003483 actual=incrementCheck,
Jon Hall5cf14d52015-07-16 12:15:19 -07003484 onpass="Added counters are correct",
3485 onfail="Added counters are incorrect" )
3486 # DISTRIBUTED SETS
3487 main.step( "Distributed Set get" )
3488 size = len( onosSet )
3489 getResponses = []
3490 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003491 for i in range( main.numCtrls ):
3492 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003493 name="setTestGet-" + str( i ),
3494 args=[ onosSetName ] )
3495 threads.append( t )
3496 t.start()
3497 for t in threads:
3498 t.join()
3499 getResponses.append( t.result )
3500
3501 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003502 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003503 if isinstance( getResponses[ i ], list):
3504 current = set( getResponses[ i ] )
3505 if len( current ) == len( getResponses[ i ] ):
3506 # no repeats
3507 if onosSet != current:
3508 main.log.error( "ONOS" + str( i + 1 ) +
3509 " has incorrect view" +
3510 " of set " + onosSetName + ":\n" +
3511 str( getResponses[ i ] ) )
3512 main.log.debug( "Expected: " + str( onosSet ) )
3513 main.log.debug( "Actual: " + str( current ) )
3514 getResults = main.FALSE
3515 else:
3516 # error, set is not a set
3517 main.log.error( "ONOS" + str( i + 1 ) +
3518 " has repeat elements in" +
3519 " set " + onosSetName + ":\n" +
3520 str( getResponses[ i ] ) )
3521 getResults = main.FALSE
3522 elif getResponses[ i ] == main.ERROR:
3523 getResults = main.FALSE
3524 utilities.assert_equals( expect=main.TRUE,
3525 actual=getResults,
3526 onpass="Set elements are correct",
3527 onfail="Set elements are incorrect" )
3528
3529 main.step( "Distributed Set size" )
3530 sizeResponses = []
3531 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003532 for i in range( main.numCtrls ):
3533 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003534 name="setTestSize-" + str( i ),
3535 args=[ onosSetName ] )
3536 threads.append( t )
3537 t.start()
3538 for t in threads:
3539 t.join()
3540 sizeResponses.append( t.result )
3541
3542 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003543 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003544 if size != sizeResponses[ i ]:
3545 sizeResults = main.FALSE
3546 main.log.error( "ONOS" + str( i + 1 ) +
3547 " expected a size of " + str( size ) +
3548 " for set " + onosSetName +
3549 " but got " + str( sizeResponses[ i ] ) )
3550 utilities.assert_equals( expect=main.TRUE,
3551 actual=sizeResults,
3552 onpass="Set sizes are correct",
3553 onfail="Set sizes are incorrect" )
3554
3555 main.step( "Distributed Set add()" )
3556 onosSet.add( addValue )
3557 addResponses = []
3558 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003559 for i in range( main.numCtrls ):
3560 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall5cf14d52015-07-16 12:15:19 -07003561 name="setTestAdd-" + str( i ),
3562 args=[ onosSetName, addValue ] )
3563 threads.append( t )
3564 t.start()
3565 for t in threads:
3566 t.join()
3567 addResponses.append( t.result )
3568
3569 # main.TRUE = successfully changed the set
3570 # main.FALSE = action resulted in no change in set
3571 # main.ERROR - Some error in executing the function
3572 addResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003573 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003574 if addResponses[ i ] == main.TRUE:
3575 # All is well
3576 pass
3577 elif addResponses[ i ] == main.FALSE:
3578 # Already in set, probably fine
3579 pass
3580 elif addResponses[ i ] == main.ERROR:
3581 # Error in execution
3582 addResults = main.FALSE
3583 else:
3584 # unexpected result
3585 addResults = main.FALSE
3586 if addResults != main.TRUE:
3587 main.log.error( "Error executing set add" )
3588
3589 # Check if set is still correct
3590 size = len( onosSet )
3591 getResponses = []
3592 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003593 for i in range( main.numCtrls ):
3594 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003595 name="setTestGet-" + str( i ),
3596 args=[ onosSetName ] )
3597 threads.append( t )
3598 t.start()
3599 for t in threads:
3600 t.join()
3601 getResponses.append( t.result )
3602 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003603 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003604 if isinstance( getResponses[ i ], list):
3605 current = set( getResponses[ i ] )
3606 if len( current ) == len( getResponses[ i ] ):
3607 # no repeats
3608 if onosSet != current:
3609 main.log.error( "ONOS" + str( i + 1 ) +
3610 " has incorrect view" +
3611 " of set " + onosSetName + ":\n" +
3612 str( getResponses[ i ] ) )
3613 main.log.debug( "Expected: " + str( onosSet ) )
3614 main.log.debug( "Actual: " + str( current ) )
3615 getResults = main.FALSE
3616 else:
3617 # error, set is not a set
3618 main.log.error( "ONOS" + str( i + 1 ) +
3619 " has repeat elements in" +
3620 " set " + onosSetName + ":\n" +
3621 str( getResponses[ i ] ) )
3622 getResults = main.FALSE
3623 elif getResponses[ i ] == main.ERROR:
3624 getResults = main.FALSE
3625 sizeResponses = []
3626 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003627 for i in range( main.numCtrls ):
3628 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003629 name="setTestSize-" + str( i ),
3630 args=[ onosSetName ] )
3631 threads.append( t )
3632 t.start()
3633 for t in threads:
3634 t.join()
3635 sizeResponses.append( t.result )
3636 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003637 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003638 if size != sizeResponses[ i ]:
3639 sizeResults = main.FALSE
3640 main.log.error( "ONOS" + str( i + 1 ) +
3641 " expected a size of " + str( size ) +
3642 " for set " + onosSetName +
3643 " but got " + str( sizeResponses[ i ] ) )
3644 addResults = addResults and getResults and sizeResults
3645 utilities.assert_equals( expect=main.TRUE,
3646 actual=addResults,
3647 onpass="Set add correct",
3648 onfail="Set add was incorrect" )
3649
3650 main.step( "Distributed Set addAll()" )
3651 onosSet.update( addAllValue.split() )
3652 addResponses = []
3653 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003654 for i in range( main.numCtrls ):
3655 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall5cf14d52015-07-16 12:15:19 -07003656 name="setTestAddAll-" + str( i ),
3657 args=[ onosSetName, addAllValue ] )
3658 threads.append( t )
3659 t.start()
3660 for t in threads:
3661 t.join()
3662 addResponses.append( t.result )
3663
3664 # main.TRUE = successfully changed the set
3665 # main.FALSE = action resulted in no change in set
3666 # main.ERROR - Some error in executing the function
3667 addAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003668 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003669 if addResponses[ i ] == main.TRUE:
3670 # All is well
3671 pass
3672 elif addResponses[ i ] == main.FALSE:
3673 # Already in set, probably fine
3674 pass
3675 elif addResponses[ i ] == main.ERROR:
3676 # Error in execution
3677 addAllResults = main.FALSE
3678 else:
3679 # unexpected result
3680 addAllResults = main.FALSE
3681 if addAllResults != main.TRUE:
3682 main.log.error( "Error executing set addAll" )
3683
3684 # Check if set is still correct
3685 size = len( onosSet )
3686 getResponses = []
3687 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003688 for i in range( main.numCtrls ):
3689 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003690 name="setTestGet-" + str( i ),
3691 args=[ onosSetName ] )
3692 threads.append( t )
3693 t.start()
3694 for t in threads:
3695 t.join()
3696 getResponses.append( t.result )
3697 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003698 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003699 if isinstance( getResponses[ i ], list):
3700 current = set( getResponses[ i ] )
3701 if len( current ) == len( getResponses[ i ] ):
3702 # no repeats
3703 if onosSet != current:
3704 main.log.error( "ONOS" + str( i + 1 ) +
3705 " has incorrect view" +
3706 " of set " + onosSetName + ":\n" +
3707 str( getResponses[ i ] ) )
3708 main.log.debug( "Expected: " + str( onosSet ) )
3709 main.log.debug( "Actual: " + str( current ) )
3710 getResults = main.FALSE
3711 else:
3712 # error, set is not a set
3713 main.log.error( "ONOS" + str( i + 1 ) +
3714 " has repeat elements in" +
3715 " set " + onosSetName + ":\n" +
3716 str( getResponses[ i ] ) )
3717 getResults = main.FALSE
3718 elif getResponses[ i ] == main.ERROR:
3719 getResults = main.FALSE
3720 sizeResponses = []
3721 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003722 for i in range( main.numCtrls ):
3723 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003724 name="setTestSize-" + str( i ),
3725 args=[ onosSetName ] )
3726 threads.append( t )
3727 t.start()
3728 for t in threads:
3729 t.join()
3730 sizeResponses.append( t.result )
3731 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003732 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003733 if size != sizeResponses[ i ]:
3734 sizeResults = main.FALSE
3735 main.log.error( "ONOS" + str( i + 1 ) +
3736 " expected a size of " + str( size ) +
3737 " for set " + onosSetName +
3738 " but got " + str( sizeResponses[ i ] ) )
3739 addAllResults = addAllResults and getResults and sizeResults
3740 utilities.assert_equals( expect=main.TRUE,
3741 actual=addAllResults,
3742 onpass="Set addAll correct",
3743 onfail="Set addAll was incorrect" )
3744
3745 main.step( "Distributed Set contains()" )
3746 containsResponses = []
3747 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003748 for i in range( main.numCtrls ):
3749 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003750 name="setContains-" + str( i ),
3751 args=[ onosSetName ],
3752 kwargs={ "values": addValue } )
3753 threads.append( t )
3754 t.start()
3755 for t in threads:
3756 t.join()
3757 # NOTE: This is the tuple
3758 containsResponses.append( t.result )
3759
3760 containsResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003761 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003762 if containsResponses[ i ] == main.ERROR:
3763 containsResults = main.FALSE
3764 else:
3765 containsResults = containsResults and\
3766 containsResponses[ i ][ 1 ]
3767 utilities.assert_equals( expect=main.TRUE,
3768 actual=containsResults,
3769 onpass="Set contains is functional",
3770 onfail="Set contains failed" )
3771
3772 main.step( "Distributed Set containsAll()" )
3773 containsAllResponses = []
3774 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003775 for i in range( main.numCtrls ):
3776 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003777 name="setContainsAll-" + str( i ),
3778 args=[ onosSetName ],
3779 kwargs={ "values": addAllValue } )
3780 threads.append( t )
3781 t.start()
3782 for t in threads:
3783 t.join()
3784 # NOTE: This is the tuple
3785 containsAllResponses.append( t.result )
3786
3787 containsAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003788 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003789 if containsResponses[ i ] == main.ERROR:
3790 containsResults = main.FALSE
3791 else:
3792 containsResults = containsResults and\
3793 containsResponses[ i ][ 1 ]
3794 utilities.assert_equals( expect=main.TRUE,
3795 actual=containsAllResults,
3796 onpass="Set containsAll is functional",
3797 onfail="Set containsAll failed" )
3798
3799 main.step( "Distributed Set remove()" )
3800 onosSet.remove( addValue )
3801 removeResponses = []
3802 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003803 for i in range( main.numCtrls ):
3804 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall5cf14d52015-07-16 12:15:19 -07003805 name="setTestRemove-" + str( i ),
3806 args=[ onosSetName, addValue ] )
3807 threads.append( t )
3808 t.start()
3809 for t in threads:
3810 t.join()
3811 removeResponses.append( t.result )
3812
3813 # main.TRUE = successfully changed the set
3814 # main.FALSE = action resulted in no change in set
3815 # main.ERROR - Some error in executing the function
3816 removeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003817 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003818 if removeResponses[ i ] == main.TRUE:
3819 # All is well
3820 pass
3821 elif removeResponses[ i ] == main.FALSE:
3822 # not in set, probably fine
3823 pass
3824 elif removeResponses[ i ] == main.ERROR:
3825 # Error in execution
3826 removeResults = main.FALSE
3827 else:
3828 # unexpected result
3829 removeResults = main.FALSE
3830 if removeResults != main.TRUE:
3831 main.log.error( "Error executing set remove" )
3832
3833 # Check if set is still correct
3834 size = len( onosSet )
3835 getResponses = []
3836 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003837 for i in range( main.numCtrls ):
3838 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003839 name="setTestGet-" + str( i ),
3840 args=[ onosSetName ] )
3841 threads.append( t )
3842 t.start()
3843 for t in threads:
3844 t.join()
3845 getResponses.append( t.result )
3846 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003847 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003848 if isinstance( getResponses[ i ], list):
3849 current = set( getResponses[ i ] )
3850 if len( current ) == len( getResponses[ i ] ):
3851 # no repeats
3852 if onosSet != current:
3853 main.log.error( "ONOS" + str( i + 1 ) +
3854 " has incorrect view" +
3855 " of set " + onosSetName + ":\n" +
3856 str( getResponses[ i ] ) )
3857 main.log.debug( "Expected: " + str( onosSet ) )
3858 main.log.debug( "Actual: " + str( current ) )
3859 getResults = main.FALSE
3860 else:
3861 # error, set is not a set
3862 main.log.error( "ONOS" + str( i + 1 ) +
3863 " has repeat elements in" +
3864 " set " + onosSetName + ":\n" +
3865 str( getResponses[ i ] ) )
3866 getResults = main.FALSE
3867 elif getResponses[ i ] == main.ERROR:
3868 getResults = main.FALSE
3869 sizeResponses = []
3870 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003871 for i in range( main.numCtrls ):
3872 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003873 name="setTestSize-" + str( i ),
3874 args=[ onosSetName ] )
3875 threads.append( t )
3876 t.start()
3877 for t in threads:
3878 t.join()
3879 sizeResponses.append( t.result )
3880 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003881 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003882 if size != sizeResponses[ i ]:
3883 sizeResults = main.FALSE
3884 main.log.error( "ONOS" + str( i + 1 ) +
3885 " expected a size of " + str( size ) +
3886 " for set " + onosSetName +
3887 " but got " + str( sizeResponses[ i ] ) )
3888 removeResults = removeResults and getResults and sizeResults
3889 utilities.assert_equals( expect=main.TRUE,
3890 actual=removeResults,
3891 onpass="Set remove correct",
3892 onfail="Set remove was incorrect" )
3893
3894 main.step( "Distributed Set removeAll()" )
3895 onosSet.difference_update( addAllValue.split() )
3896 removeAllResponses = []
3897 threads = []
3898 try:
Jon Halle1a3b752015-07-22 13:02:46 -07003899 for i in range( main.numCtrls ):
3900 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall5cf14d52015-07-16 12:15:19 -07003901 name="setTestRemoveAll-" + str( i ),
3902 args=[ onosSetName, addAllValue ] )
3903 threads.append( t )
3904 t.start()
3905 for t in threads:
3906 t.join()
3907 removeAllResponses.append( t.result )
3908 except Exception, e:
3909 main.log.exception(e)
3910
3911 # main.TRUE = successfully changed the set
3912 # main.FALSE = action resulted in no change in set
3913 # main.ERROR - Some error in executing the function
3914 removeAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003915 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003916 if removeAllResponses[ i ] == main.TRUE:
3917 # All is well
3918 pass
3919 elif removeAllResponses[ i ] == main.FALSE:
3920 # not in set, probably fine
3921 pass
3922 elif removeAllResponses[ i ] == main.ERROR:
3923 # Error in execution
3924 removeAllResults = main.FALSE
3925 else:
3926 # unexpected result
3927 removeAllResults = main.FALSE
3928 if removeAllResults != main.TRUE:
3929 main.log.error( "Error executing set removeAll" )
3930
3931 # Check if set is still correct
3932 size = len( onosSet )
3933 getResponses = []
3934 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003935 for i in range( main.numCtrls ):
3936 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003937 name="setTestGet-" + str( i ),
3938 args=[ onosSetName ] )
3939 threads.append( t )
3940 t.start()
3941 for t in threads:
3942 t.join()
3943 getResponses.append( t.result )
3944 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003945 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003946 if isinstance( getResponses[ i ], list):
3947 current = set( getResponses[ i ] )
3948 if len( current ) == len( getResponses[ i ] ):
3949 # no repeats
3950 if onosSet != current:
3951 main.log.error( "ONOS" + str( i + 1 ) +
3952 " has incorrect view" +
3953 " of set " + onosSetName + ":\n" +
3954 str( getResponses[ i ] ) )
3955 main.log.debug( "Expected: " + str( onosSet ) )
3956 main.log.debug( "Actual: " + str( current ) )
3957 getResults = main.FALSE
3958 else:
3959 # error, set is not a set
3960 main.log.error( "ONOS" + str( i + 1 ) +
3961 " has repeat elements in" +
3962 " set " + onosSetName + ":\n" +
3963 str( getResponses[ i ] ) )
3964 getResults = main.FALSE
3965 elif getResponses[ i ] == main.ERROR:
3966 getResults = main.FALSE
3967 sizeResponses = []
3968 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003969 for i in range( main.numCtrls ):
3970 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003971 name="setTestSize-" + str( i ),
3972 args=[ onosSetName ] )
3973 threads.append( t )
3974 t.start()
3975 for t in threads:
3976 t.join()
3977 sizeResponses.append( t.result )
3978 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003979 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003980 if size != sizeResponses[ i ]:
3981 sizeResults = main.FALSE
3982 main.log.error( "ONOS" + str( i + 1 ) +
3983 " expected a size of " + str( size ) +
3984 " for set " + onosSetName +
3985 " but got " + str( sizeResponses[ i ] ) )
3986 removeAllResults = removeAllResults and getResults and sizeResults
3987 utilities.assert_equals( expect=main.TRUE,
3988 actual=removeAllResults,
3989 onpass="Set removeAll correct",
3990 onfail="Set removeAll was incorrect" )
3991
3992 main.step( "Distributed Set addAll()" )
3993 onosSet.update( addAllValue.split() )
3994 addResponses = []
3995 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003996 for i in range( main.numCtrls ):
3997 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall5cf14d52015-07-16 12:15:19 -07003998 name="setTestAddAll-" + str( i ),
3999 args=[ onosSetName, addAllValue ] )
4000 threads.append( t )
4001 t.start()
4002 for t in threads:
4003 t.join()
4004 addResponses.append( t.result )
4005
4006 # main.TRUE = successfully changed the set
4007 # main.FALSE = action resulted in no change in set
4008 # main.ERROR - Some error in executing the function
4009 addAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004010 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004011 if addResponses[ i ] == main.TRUE:
4012 # All is well
4013 pass
4014 elif addResponses[ i ] == main.FALSE:
4015 # Already in set, probably fine
4016 pass
4017 elif addResponses[ i ] == main.ERROR:
4018 # Error in execution
4019 addAllResults = main.FALSE
4020 else:
4021 # unexpected result
4022 addAllResults = main.FALSE
4023 if addAllResults != main.TRUE:
4024 main.log.error( "Error executing set addAll" )
4025
4026 # Check if set is still correct
4027 size = len( onosSet )
4028 getResponses = []
4029 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004030 for i in range( main.numCtrls ):
4031 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07004032 name="setTestGet-" + str( i ),
4033 args=[ onosSetName ] )
4034 threads.append( t )
4035 t.start()
4036 for t in threads:
4037 t.join()
4038 getResponses.append( t.result )
4039 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004040 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004041 if isinstance( getResponses[ i ], list):
4042 current = set( getResponses[ i ] )
4043 if len( current ) == len( getResponses[ i ] ):
4044 # no repeats
4045 if onosSet != current:
4046 main.log.error( "ONOS" + str( i + 1 ) +
4047 " has incorrect view" +
4048 " of set " + onosSetName + ":\n" +
4049 str( getResponses[ i ] ) )
4050 main.log.debug( "Expected: " + str( onosSet ) )
4051 main.log.debug( "Actual: " + str( current ) )
4052 getResults = main.FALSE
4053 else:
4054 # error, set is not a set
4055 main.log.error( "ONOS" + str( i + 1 ) +
4056 " has repeat elements in" +
4057 " set " + onosSetName + ":\n" +
4058 str( getResponses[ i ] ) )
4059 getResults = main.FALSE
4060 elif getResponses[ i ] == main.ERROR:
4061 getResults = main.FALSE
4062 sizeResponses = []
4063 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004064 for i in range( main.numCtrls ):
4065 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07004066 name="setTestSize-" + str( i ),
4067 args=[ onosSetName ] )
4068 threads.append( t )
4069 t.start()
4070 for t in threads:
4071 t.join()
4072 sizeResponses.append( t.result )
4073 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004074 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004075 if size != sizeResponses[ i ]:
4076 sizeResults = main.FALSE
4077 main.log.error( "ONOS" + str( i + 1 ) +
4078 " expected a size of " + str( size ) +
4079 " for set " + onosSetName +
4080 " but got " + str( sizeResponses[ i ] ) )
4081 addAllResults = addAllResults and getResults and sizeResults
4082 utilities.assert_equals( expect=main.TRUE,
4083 actual=addAllResults,
4084 onpass="Set addAll correct",
4085 onfail="Set addAll was incorrect" )
4086
4087 main.step( "Distributed Set clear()" )
4088 onosSet.clear()
4089 clearResponses = []
4090 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004091 for i in range( main.numCtrls ):
4092 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall5cf14d52015-07-16 12:15:19 -07004093 name="setTestClear-" + str( i ),
4094 args=[ onosSetName, " "], # Values doesn't matter
4095 kwargs={ "clear": True } )
4096 threads.append( t )
4097 t.start()
4098 for t in threads:
4099 t.join()
4100 clearResponses.append( t.result )
4101
4102 # main.TRUE = successfully changed the set
4103 # main.FALSE = action resulted in no change in set
4104 # main.ERROR - Some error in executing the function
4105 clearResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004106 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004107 if clearResponses[ i ] == main.TRUE:
4108 # All is well
4109 pass
4110 elif clearResponses[ i ] == main.FALSE:
4111 # Nothing set, probably fine
4112 pass
4113 elif clearResponses[ i ] == main.ERROR:
4114 # Error in execution
4115 clearResults = main.FALSE
4116 else:
4117 # unexpected result
4118 clearResults = main.FALSE
4119 if clearResults != main.TRUE:
4120 main.log.error( "Error executing set clear" )
4121
4122 # Check if set is still correct
4123 size = len( onosSet )
4124 getResponses = []
4125 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004126 for i in range( main.numCtrls ):
4127 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07004128 name="setTestGet-" + str( i ),
4129 args=[ onosSetName ] )
4130 threads.append( t )
4131 t.start()
4132 for t in threads:
4133 t.join()
4134 getResponses.append( t.result )
4135 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004136 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004137 if isinstance( getResponses[ i ], list):
4138 current = set( getResponses[ i ] )
4139 if len( current ) == len( getResponses[ i ] ):
4140 # no repeats
4141 if onosSet != current:
4142 main.log.error( "ONOS" + str( i + 1 ) +
4143 " has incorrect view" +
4144 " of set " + onosSetName + ":\n" +
4145 str( getResponses[ i ] ) )
4146 main.log.debug( "Expected: " + str( onosSet ) )
4147 main.log.debug( "Actual: " + str( current ) )
4148 getResults = main.FALSE
4149 else:
4150 # error, set is not a set
4151 main.log.error( "ONOS" + str( i + 1 ) +
4152 " has repeat elements in" +
4153 " set " + onosSetName + ":\n" +
4154 str( getResponses[ i ] ) )
4155 getResults = main.FALSE
4156 elif getResponses[ i ] == main.ERROR:
4157 getResults = main.FALSE
4158 sizeResponses = []
4159 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004160 for i in range( main.numCtrls ):
4161 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07004162 name="setTestSize-" + str( i ),
4163 args=[ onosSetName ] )
4164 threads.append( t )
4165 t.start()
4166 for t in threads:
4167 t.join()
4168 sizeResponses.append( t.result )
4169 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004170 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004171 if size != sizeResponses[ i ]:
4172 sizeResults = main.FALSE
4173 main.log.error( "ONOS" + str( i + 1 ) +
4174 " expected a size of " + str( size ) +
4175 " for set " + onosSetName +
4176 " but got " + str( sizeResponses[ i ] ) )
4177 clearResults = clearResults and getResults and sizeResults
4178 utilities.assert_equals( expect=main.TRUE,
4179 actual=clearResults,
4180 onpass="Set clear correct",
4181 onfail="Set clear was incorrect" )
4182
4183 main.step( "Distributed Set addAll()" )
4184 onosSet.update( addAllValue.split() )
4185 addResponses = []
4186 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004187 for i in range( main.numCtrls ):
4188 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall5cf14d52015-07-16 12:15:19 -07004189 name="setTestAddAll-" + str( i ),
4190 args=[ onosSetName, addAllValue ] )
4191 threads.append( t )
4192 t.start()
4193 for t in threads:
4194 t.join()
4195 addResponses.append( t.result )
4196
4197 # main.TRUE = successfully changed the set
4198 # main.FALSE = action resulted in no change in set
4199 # main.ERROR - Some error in executing the function
4200 addAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004201 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004202 if addResponses[ i ] == main.TRUE:
4203 # All is well
4204 pass
4205 elif addResponses[ i ] == main.FALSE:
4206 # Already in set, probably fine
4207 pass
4208 elif addResponses[ i ] == main.ERROR:
4209 # Error in execution
4210 addAllResults = main.FALSE
4211 else:
4212 # unexpected result
4213 addAllResults = main.FALSE
4214 if addAllResults != main.TRUE:
4215 main.log.error( "Error executing set addAll" )
4216
4217 # Check if set is still correct
4218 size = len( onosSet )
4219 getResponses = []
4220 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004221 for i in range( main.numCtrls ):
4222 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07004223 name="setTestGet-" + str( i ),
4224 args=[ onosSetName ] )
4225 threads.append( t )
4226 t.start()
4227 for t in threads:
4228 t.join()
4229 getResponses.append( t.result )
4230 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004231 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004232 if isinstance( getResponses[ i ], list):
4233 current = set( getResponses[ i ] )
4234 if len( current ) == len( getResponses[ i ] ):
4235 # no repeats
4236 if onosSet != current:
4237 main.log.error( "ONOS" + str( i + 1 ) +
4238 " has incorrect view" +
4239 " of set " + onosSetName + ":\n" +
4240 str( getResponses[ i ] ) )
4241 main.log.debug( "Expected: " + str( onosSet ) )
4242 main.log.debug( "Actual: " + str( current ) )
4243 getResults = main.FALSE
4244 else:
4245 # error, set is not a set
4246 main.log.error( "ONOS" + str( i + 1 ) +
4247 " has repeat elements in" +
4248 " set " + onosSetName + ":\n" +
4249 str( getResponses[ i ] ) )
4250 getResults = main.FALSE
4251 elif getResponses[ i ] == main.ERROR:
4252 getResults = main.FALSE
4253 sizeResponses = []
4254 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004255 for i in range( main.numCtrls ):
4256 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07004257 name="setTestSize-" + str( i ),
4258 args=[ onosSetName ] )
4259 threads.append( t )
4260 t.start()
4261 for t in threads:
4262 t.join()
4263 sizeResponses.append( t.result )
4264 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004265 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004266 if size != sizeResponses[ i ]:
4267 sizeResults = main.FALSE
4268 main.log.error( "ONOS" + str( i + 1 ) +
4269 " expected a size of " + str( size ) +
4270 " for set " + onosSetName +
4271 " but got " + str( sizeResponses[ i ] ) )
4272 addAllResults = addAllResults and getResults and sizeResults
4273 utilities.assert_equals( expect=main.TRUE,
4274 actual=addAllResults,
4275 onpass="Set addAll correct",
4276 onfail="Set addAll was incorrect" )
4277
4278 main.step( "Distributed Set retain()" )
4279 onosSet.intersection_update( retainValue.split() )
4280 retainResponses = []
4281 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004282 for i in range( main.numCtrls ):
4283 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall5cf14d52015-07-16 12:15:19 -07004284 name="setTestRetain-" + str( i ),
4285 args=[ onosSetName, retainValue ],
4286 kwargs={ "retain": True } )
4287 threads.append( t )
4288 t.start()
4289 for t in threads:
4290 t.join()
4291 retainResponses.append( t.result )
4292
4293 # main.TRUE = successfully changed the set
4294 # main.FALSE = action resulted in no change in set
4295 # main.ERROR - Some error in executing the function
4296 retainResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004297 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004298 if retainResponses[ i ] == main.TRUE:
4299 # All is well
4300 pass
4301 elif retainResponses[ i ] == main.FALSE:
4302 # Already in set, probably fine
4303 pass
4304 elif retainResponses[ i ] == main.ERROR:
4305 # Error in execution
4306 retainResults = main.FALSE
4307 else:
4308 # unexpected result
4309 retainResults = main.FALSE
4310 if retainResults != main.TRUE:
4311 main.log.error( "Error executing set retain" )
4312
4313 # Check if set is still correct
4314 size = len( onosSet )
4315 getResponses = []
4316 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004317 for i in range( main.numCtrls ):
4318 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07004319 name="setTestGet-" + str( i ),
4320 args=[ onosSetName ] )
4321 threads.append( t )
4322 t.start()
4323 for t in threads:
4324 t.join()
4325 getResponses.append( t.result )
4326 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004327 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004328 if isinstance( getResponses[ i ], list):
4329 current = set( getResponses[ i ] )
4330 if len( current ) == len( getResponses[ i ] ):
4331 # no repeats
4332 if onosSet != current:
4333 main.log.error( "ONOS" + str( i + 1 ) +
4334 " has incorrect view" +
4335 " of set " + onosSetName + ":\n" +
4336 str( getResponses[ i ] ) )
4337 main.log.debug( "Expected: " + str( onosSet ) )
4338 main.log.debug( "Actual: " + str( current ) )
4339 getResults = main.FALSE
4340 else:
4341 # error, set is not a set
4342 main.log.error( "ONOS" + str( i + 1 ) +
4343 " has repeat elements in" +
4344 " set " + onosSetName + ":\n" +
4345 str( getResponses[ i ] ) )
4346 getResults = main.FALSE
4347 elif getResponses[ i ] == main.ERROR:
4348 getResults = main.FALSE
4349 sizeResponses = []
4350 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004351 for i in range( main.numCtrls ):
4352 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07004353 name="setTestSize-" + str( i ),
4354 args=[ onosSetName ] )
4355 threads.append( t )
4356 t.start()
4357 for t in threads:
4358 t.join()
4359 sizeResponses.append( t.result )
4360 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004361 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004362 if size != sizeResponses[ i ]:
4363 sizeResults = main.FALSE
4364 main.log.error( "ONOS" + str( i + 1 ) +
4365 " expected a size of " +
4366 str( size ) + " for set " + onosSetName +
4367 " but got " + str( sizeResponses[ i ] ) )
4368 retainResults = retainResults and getResults and sizeResults
4369 utilities.assert_equals( expect=main.TRUE,
4370 actual=retainResults,
4371 onpass="Set retain correct",
4372 onfail="Set retain was incorrect" )
4373
Jon Hall2a5002c2015-08-21 16:49:11 -07004374 # Transactional maps
4375 main.step( "Partitioned Transactional maps put" )
4376 tMapValue = "Testing"
4377 numKeys = 100
4378 putResult = True
4379 putResponses = main.CLIs[ 0 ].transactionalMapPut( numKeys, tMapValue )
4380 if len( putResponses ) == 100:
4381 for i in putResponses:
4382 if putResponses[ i ][ 'value' ] != tMapValue:
4383 putResult = False
4384 else:
4385 putResult = False
4386 if not putResult:
4387 main.log.debug( "Put response values: " + str( putResponses ) )
4388 utilities.assert_equals( expect=True,
4389 actual=putResult,
4390 onpass="Partitioned Transactional Map put successful",
4391 onfail="Partitioned Transactional Map put values are incorrect" )
4392
4393 main.step( "Partitioned Transactional maps get" )
4394 getCheck = True
4395 for n in range( 1, numKeys + 1 ):
4396 getResponses = []
4397 threads = []
4398 valueCheck = True
4399 for i in range( main.numCtrls ):
4400 t = main.Thread( target=main.CLIs[i].transactionalMapGet,
4401 name="TMap-get-" + str( i ),
4402 args=[ "Key" + str ( n ) ] )
4403 threads.append( t )
4404 t.start()
4405 for t in threads:
4406 t.join()
4407 getResponses.append( t.result )
4408 for node in getResponses:
4409 if node != tMapValue:
4410 valueCheck = False
4411 if not valueCheck:
4412 main.log.warn( "Values for key 'Key" + str( n ) + "' do not match:" )
4413 main.log.warn( getResponses )
4414 getCheck = getCheck and valueCheck
4415 utilities.assert_equals( expect=True,
4416 actual=getCheck,
4417 onpass="Partitioned Transactional Map get values were correct",
4418 onfail="Partitioned Transactional Map values incorrect" )
4419
4420 main.step( "In-memory Transactional maps put" )
4421 tMapValue = "Testing"
4422 numKeys = 100
4423 putResult = True
4424 putResponses = main.CLIs[ 0 ].transactionalMapPut( numKeys, tMapValue, inMemory=True )
4425 if len( putResponses ) == 100:
4426 for i in putResponses:
4427 if putResponses[ i ][ 'value' ] != tMapValue:
4428 putResult = False
4429 else:
4430 putResult = False
4431 if not putResult:
4432 main.log.debug( "Put response values: " + str( putResponses ) )
4433 utilities.assert_equals( expect=True,
4434 actual=putResult,
4435 onpass="In-Memory Transactional Map put successful",
4436 onfail="In-Memory Transactional Map put values are incorrect" )
4437
4438 main.step( "In-Memory Transactional maps get" )
4439 getCheck = True
4440 for n in range( 1, numKeys + 1 ):
4441 getResponses = []
4442 threads = []
4443 valueCheck = True
4444 for i in range( main.numCtrls ):
4445 t = main.Thread( target=main.CLIs[i].transactionalMapGet,
4446 name="TMap-get-" + str( i ),
4447 args=[ "Key" + str ( n ) ],
4448 kwargs={ "inMemory": True } )
4449 threads.append( t )
4450 t.start()
4451 for t in threads:
4452 t.join()
4453 getResponses.append( t.result )
4454 for node in getResponses:
4455 if node != tMapValue:
4456 valueCheck = False
4457 if not valueCheck:
4458 main.log.warn( "Values for key 'Key" + str( n ) + "' do not match:" )
4459 main.log.warn( getResponses )
4460 getCheck = getCheck and valueCheck
4461 utilities.assert_equals( expect=True,
4462 actual=getCheck,
4463 onpass="In-Memory Transactional Map get values were correct",
4464 onfail="In-Memory Transactional Map values incorrect" )