blob: 2677b8d526be2a56744d2a15d5880fde49442608 [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
Jon Hall657cdf62015-12-17 14:40:51 -08001659 if hosts[ controller ] and "Error" not in hosts[ controller ]:
Jon Hall5cf14d52015-07-16 12:15:19 -07001660 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 ):
Jon Halld8f6de82015-12-17 17:04:34 -08002184 t = main.Thread( target=utilities.retry,
Jon Hall5cf14d52015-07-16 12:15:19 -07002185 name="hosts-" + str( i ),
Jon Halld8f6de82015-12-17 17:04:34 -08002186 args=[ main.CLIs[i].hosts, [ None ] ],
2187 kwargs= { 'sleep': 5, 'attempts': 5,
2188 'randomTime': True } )
Jon Hall5cf14d52015-07-16 12:15:19 -07002189 threads.append( t )
2190 t.start()
2191
2192 for t in threads:
2193 t.join()
2194 try:
2195 hosts.append( json.loads( t.result ) )
2196 except ( ValueError, TypeError ):
2197 main.log.exception( "Error parsing hosts results" )
2198 main.log.error( repr( t.result ) )
Jon Hall3afe4c92015-12-14 19:30:38 -08002199 hosts.append( None )
Jon Hall5cf14d52015-07-16 12:15:19 -07002200 for controller in range( 0, len( hosts ) ):
2201 controllerStr = str( controller + 1 )
Jon Hallacd1b182015-12-17 11:43:20 -08002202 if hosts[ controller ]:
2203 for host in hosts[ controller ]:
2204 if host is None or host.get( 'ipAddresses', [] ) == []:
2205 main.log.error(
2206 "Error with host ipAddresses on controller" +
2207 controllerStr + ": " + str( host ) )
2208 ipResult = main.FALSE
Jon Hall5cf14d52015-07-16 12:15:19 -07002209 ports = []
2210 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002211 for i in range( main.numCtrls ):
2212 t = main.Thread( target=main.CLIs[i].ports,
Jon Hall5cf14d52015-07-16 12:15:19 -07002213 name="ports-" + str( i ),
2214 args=[ ] )
2215 threads.append( t )
2216 t.start()
2217
2218 for t in threads:
2219 t.join()
2220 ports.append( t.result )
2221 links = []
2222 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002223 for i in range( main.numCtrls ):
2224 t = main.Thread( target=main.CLIs[i].links,
Jon Hall5cf14d52015-07-16 12:15:19 -07002225 name="links-" + str( i ),
2226 args=[ ] )
2227 threads.append( t )
2228 t.start()
2229
2230 for t in threads:
2231 t.join()
2232 links.append( t.result )
2233 clusters = []
2234 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002235 for i in range( main.numCtrls ):
2236 t = main.Thread( target=main.CLIs[i].clusters,
Jon Hall5cf14d52015-07-16 12:15:19 -07002237 name="clusters-" + str( i ),
2238 args=[ ] )
2239 threads.append( t )
2240 t.start()
2241
2242 for t in threads:
2243 t.join()
2244 clusters.append( t.result )
2245
2246 elapsed = time.time() - startTime
2247 cliTime = time.time() - cliStart
2248 print "Elapsed time: " + str( elapsed )
2249 print "CLI time: " + str( cliTime )
2250
2251 mnSwitches = main.Mininet1.getSwitches()
2252 mnLinks = main.Mininet1.getLinks()
2253 mnHosts = main.Mininet1.getHosts()
Jon Halle1a3b752015-07-22 13:02:46 -07002254 for controller in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07002255 controllerStr = str( controller + 1 )
2256 if devices[ controller ] and ports[ controller ] and\
2257 "Error" not in devices[ controller ] and\
2258 "Error" not in ports[ controller ]:
2259
2260 currentDevicesResult = main.Mininet1.compareSwitches(
2261 mnSwitches,
2262 json.loads( devices[ controller ] ),
2263 json.loads( ports[ controller ] ) )
2264 else:
2265 currentDevicesResult = main.FALSE
2266 utilities.assert_equals( expect=main.TRUE,
2267 actual=currentDevicesResult,
2268 onpass="ONOS" + controllerStr +
2269 " Switches view is correct",
2270 onfail="ONOS" + controllerStr +
2271 " Switches view is incorrect" )
2272
2273 if links[ controller ] and "Error" not in links[ controller ]:
2274 currentLinksResult = main.Mininet1.compareLinks(
2275 mnSwitches, mnLinks,
2276 json.loads( links[ controller ] ) )
2277 else:
2278 currentLinksResult = main.FALSE
2279 utilities.assert_equals( expect=main.TRUE,
2280 actual=currentLinksResult,
2281 onpass="ONOS" + controllerStr +
2282 " links view is correct",
2283 onfail="ONOS" + controllerStr +
2284 " links view is incorrect" )
Jon Hall657cdf62015-12-17 14:40:51 -08002285 if hosts[ controller ] and "Error" not in hosts[ controller ]:
Jon Hall5cf14d52015-07-16 12:15:19 -07002286 currentHostsResult = main.Mininet1.compareHosts(
2287 mnHosts,
2288 hosts[ controller ] )
2289 else:
2290 currentHostsResult = main.FALSE
2291 utilities.assert_equals( expect=main.TRUE,
2292 actual=currentHostsResult,
2293 onpass="ONOS" + controllerStr +
2294 " hosts exist in Mininet",
2295 onfail="ONOS" + controllerStr +
2296 " hosts don't match Mininet" )
2297 # CHECKING HOST ATTACHMENT POINTS
2298 hostAttachment = True
2299 noHosts = False
2300 # FIXME: topo-HA/obelisk specific mappings:
2301 # key is mac and value is dpid
2302 mappings = {}
2303 for i in range( 1, 29 ): # hosts 1 through 28
2304 # set up correct variables:
2305 macId = "00:" * 5 + hex( i ).split( "0x" )[1].upper().zfill(2)
2306 if i == 1:
2307 deviceId = "1000".zfill(16)
2308 elif i == 2:
2309 deviceId = "2000".zfill(16)
2310 elif i == 3:
2311 deviceId = "3000".zfill(16)
2312 elif i == 4:
2313 deviceId = "3004".zfill(16)
2314 elif i == 5:
2315 deviceId = "5000".zfill(16)
2316 elif i == 6:
2317 deviceId = "6000".zfill(16)
2318 elif i == 7:
2319 deviceId = "6007".zfill(16)
2320 elif i >= 8 and i <= 17:
2321 dpid = '3' + str( i ).zfill( 3 )
2322 deviceId = dpid.zfill(16)
2323 elif i >= 18 and i <= 27:
2324 dpid = '6' + str( i ).zfill( 3 )
2325 deviceId = dpid.zfill(16)
2326 elif i == 28:
2327 deviceId = "2800".zfill(16)
2328 mappings[ macId ] = deviceId
Jon Halld8f6de82015-12-17 17:04:34 -08002329 if hosts[ controller ] is not None and "Error" not in hosts[ controller ]:
Jon Hall5cf14d52015-07-16 12:15:19 -07002330 if hosts[ controller ] == []:
2331 main.log.warn( "There are no hosts discovered" )
2332 noHosts = True
2333 else:
2334 for host in hosts[ controller ]:
2335 mac = None
2336 location = None
2337 device = None
2338 port = None
2339 try:
2340 mac = host.get( 'mac' )
2341 assert mac, "mac field could not be found for this host object"
2342
2343 location = host.get( 'location' )
2344 assert location, "location field could not be found for this host object"
2345
2346 # Trim the protocol identifier off deviceId
2347 device = str( location.get( 'elementId' ) ).split(':')[1]
2348 assert device, "elementId field could not be found for this host location object"
2349
2350 port = location.get( 'port' )
2351 assert port, "port field could not be found for this host location object"
2352
2353 # Now check if this matches where they should be
2354 if mac and device and port:
2355 if str( port ) != "1":
2356 main.log.error( "The attachment port is incorrect for " +
2357 "host " + str( mac ) +
2358 ". Expected: 1 Actual: " + str( port) )
2359 hostAttachment = False
2360 if device != mappings[ str( mac ) ]:
2361 main.log.error( "The attachment device is incorrect for " +
2362 "host " + str( mac ) +
2363 ". Expected: " + mappings[ str( mac ) ] +
2364 " Actual: " + device )
2365 hostAttachment = False
2366 else:
2367 hostAttachment = False
2368 except AssertionError:
2369 main.log.exception( "Json object not as expected" )
2370 main.log.error( repr( host ) )
2371 hostAttachment = False
2372 else:
2373 main.log.error( "No hosts json output or \"Error\"" +
2374 " in output. hosts = " +
2375 repr( hosts[ controller ] ) )
2376 if noHosts is False:
2377 # TODO: Find a way to know if there should be hosts in a
2378 # given point of the test
2379 hostAttachment = True
2380
2381 # END CHECKING HOST ATTACHMENT POINTS
2382 devicesResults = devicesResults and currentDevicesResult
2383 linksResults = linksResults and currentLinksResult
2384 hostsResults = hostsResults and currentHostsResult
2385 hostAttachmentResults = hostAttachmentResults and\
2386 hostAttachment
2387 topoResult = ( devicesResults and linksResults
2388 and hostsResults and ipResult and
2389 hostAttachmentResults )
Jon Halle9b1fa32015-12-08 15:32:21 -08002390 utilities.assert_equals( expect=True,
2391 actual=topoResult,
2392 onpass="ONOS topology matches Mininet",
2393 onfail="ONOS topology don't match Mininet" )
2394 # End of While loop to pull ONOS state
Jon Hall5cf14d52015-07-16 12:15:19 -07002395
2396 # Compare json objects for hosts and dataplane clusters
2397
2398 # hosts
2399 main.step( "Hosts view is consistent across all ONOS nodes" )
2400 consistentHostsResult = main.TRUE
2401 for controller in range( len( hosts ) ):
2402 controllerStr = str( controller + 1 )
Jon Hall657cdf62015-12-17 14:40:51 -08002403 if hosts[ controller ] and "Error" not in hosts[ controller ]:
Jon Hall5cf14d52015-07-16 12:15:19 -07002404 if hosts[ controller ] == hosts[ 0 ]:
2405 continue
2406 else: # hosts not consistent
2407 main.log.error( "hosts from ONOS" + controllerStr +
2408 " is inconsistent with ONOS1" )
2409 main.log.warn( repr( hosts[ controller ] ) )
2410 consistentHostsResult = main.FALSE
2411
2412 else:
2413 main.log.error( "Error in getting ONOS hosts from ONOS" +
2414 controllerStr )
2415 consistentHostsResult = main.FALSE
2416 main.log.warn( "ONOS" + controllerStr +
2417 " hosts response: " +
2418 repr( hosts[ controller ] ) )
2419 utilities.assert_equals(
2420 expect=main.TRUE,
2421 actual=consistentHostsResult,
2422 onpass="Hosts view is consistent across all ONOS nodes",
2423 onfail="ONOS nodes have different views of hosts" )
2424
2425 main.step( "Hosts information is correct" )
2426 hostsResults = hostsResults and ipResult
2427 utilities.assert_equals(
2428 expect=main.TRUE,
2429 actual=hostsResults,
2430 onpass="Host information is correct",
2431 onfail="Host information is incorrect" )
2432
2433 main.step( "Host attachment points to the network" )
2434 utilities.assert_equals(
2435 expect=True,
2436 actual=hostAttachmentResults,
2437 onpass="Hosts are correctly attached to the network",
2438 onfail="ONOS did not correctly attach hosts to the network" )
2439
2440 # Strongly connected clusters of devices
2441 main.step( "Clusters view is consistent across all ONOS nodes" )
2442 consistentClustersResult = main.TRUE
2443 for controller in range( len( clusters ) ):
2444 controllerStr = str( controller + 1 )
2445 if "Error" not in clusters[ controller ]:
2446 if clusters[ controller ] == clusters[ 0 ]:
2447 continue
2448 else: # clusters not consistent
2449 main.log.error( "clusters from ONOS" +
2450 controllerStr +
2451 " is inconsistent with ONOS1" )
2452 consistentClustersResult = main.FALSE
2453
2454 else:
2455 main.log.error( "Error in getting dataplane clusters " +
2456 "from ONOS" + controllerStr )
2457 consistentClustersResult = main.FALSE
2458 main.log.warn( "ONOS" + controllerStr +
2459 " clusters response: " +
2460 repr( clusters[ controller ] ) )
2461 utilities.assert_equals(
2462 expect=main.TRUE,
2463 actual=consistentClustersResult,
2464 onpass="Clusters view is consistent across all ONOS nodes",
2465 onfail="ONOS nodes have different views of clusters" )
2466
2467 main.step( "There is only one SCC" )
2468 # there should always only be one cluster
2469 try:
2470 numClusters = len( json.loads( clusters[ 0 ] ) )
2471 except ( ValueError, TypeError ):
2472 main.log.exception( "Error parsing clusters[0]: " +
2473 repr( clusters[0] ) )
2474 clusterResults = main.FALSE
2475 if numClusters == 1:
2476 clusterResults = main.TRUE
2477 utilities.assert_equals(
2478 expect=1,
2479 actual=numClusters,
2480 onpass="ONOS shows 1 SCC",
2481 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
2482
2483 topoResult = ( devicesResults and linksResults
2484 and hostsResults and consistentHostsResult
2485 and consistentClustersResult and clusterResults
2486 and ipResult and hostAttachmentResults )
2487
2488 topoResult = topoResult and int( count <= 2 )
2489 note = "note it takes about " + str( int( cliTime ) ) + \
2490 " seconds for the test to make all the cli calls to fetch " +\
2491 "the topology from each ONOS instance"
2492 main.log.info(
2493 "Very crass estimate for topology discovery/convergence( " +
2494 str( note ) + " ): " + str( elapsed ) + " seconds, " +
2495 str( count ) + " tries" )
2496
2497 main.step( "Device information is correct" )
2498 utilities.assert_equals(
2499 expect=main.TRUE,
2500 actual=devicesResults,
2501 onpass="Device information is correct",
2502 onfail="Device information is incorrect" )
2503
2504 main.step( "Links are correct" )
2505 utilities.assert_equals(
2506 expect=main.TRUE,
2507 actual=linksResults,
2508 onpass="Link are correct",
2509 onfail="Links are incorrect" )
2510
2511 # FIXME: move this to an ONOS state case
2512 main.step( "Checking ONOS nodes" )
2513 nodesOutput = []
2514 nodeResults = main.TRUE
2515 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002516 for i in range( main.numCtrls ):
2517 t = main.Thread( target=main.CLIs[i].nodes,
Jon Hall5cf14d52015-07-16 12:15:19 -07002518 name="nodes-" + str( i ),
2519 args=[ ] )
2520 threads.append( t )
2521 t.start()
2522
2523 for t in threads:
2524 t.join()
2525 nodesOutput.append( t.result )
Jon Halle1a3b752015-07-22 13:02:46 -07002526 ips = [ node.ip_address for node in main.nodes ]
Jon Halle9b1fa32015-12-08 15:32:21 -08002527 ips.sort()
Jon Hall5cf14d52015-07-16 12:15:19 -07002528 for i in nodesOutput:
2529 try:
2530 current = json.loads( i )
Jon Halle9b1fa32015-12-08 15:32:21 -08002531 activeIps = []
2532 currentResult = main.FALSE
Jon Hall5cf14d52015-07-16 12:15:19 -07002533 for node in current:
Jon Halle9b1fa32015-12-08 15:32:21 -08002534 if node['state'] == 'ACTIVE':
2535 activeIps.append( node['ip'] )
2536 activeIps.sort()
2537 if ips == activeIps:
2538 currentResult = main.TRUE
Jon Hall5cf14d52015-07-16 12:15:19 -07002539 except ( ValueError, TypeError ):
2540 main.log.error( "Error parsing nodes output" )
2541 main.log.warn( repr( i ) )
Jon Halle9b1fa32015-12-08 15:32:21 -08002542 currentResult = main.FALSE
2543 nodeResults = nodeResults and currentResult
Jon Hall5cf14d52015-07-16 12:15:19 -07002544 utilities.assert_equals( expect=main.TRUE, actual=nodeResults,
2545 onpass="Nodes check successful",
2546 onfail="Nodes check NOT successful" )
2547
2548 def CASE9( self, main ):
2549 """
2550 Link s3-s28 down
2551 """
2552 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002553 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002554 assert main, "main not defined"
2555 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002556 assert main.CLIs, "main.CLIs not defined"
2557 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002558 # NOTE: You should probably run a topology check after this
2559
2560 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
2561
2562 description = "Turn off a link to ensure that Link Discovery " +\
2563 "is working properly"
2564 main.case( description )
2565
2566 main.step( "Kill Link between s3 and s28" )
2567 LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" )
2568 main.log.info( "Waiting " + str( linkSleep ) +
2569 " seconds for link down to be discovered" )
2570 time.sleep( linkSleep )
2571 utilities.assert_equals( expect=main.TRUE, actual=LinkDown,
2572 onpass="Link down successful",
2573 onfail="Failed to bring link down" )
2574 # TODO do some sort of check here
2575
2576 def CASE10( self, main ):
2577 """
2578 Link s3-s28 up
2579 """
2580 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002581 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002582 assert main, "main not defined"
2583 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002584 assert main.CLIs, "main.CLIs not defined"
2585 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002586 # NOTE: You should probably run a topology check after this
2587
2588 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
2589
2590 description = "Restore a link to ensure that Link Discovery is " + \
2591 "working properly"
2592 main.case( description )
2593
2594 main.step( "Bring link between s3 and s28 back up" )
2595 LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" )
2596 main.log.info( "Waiting " + str( linkSleep ) +
2597 " seconds for link up to be discovered" )
2598 time.sleep( linkSleep )
2599 utilities.assert_equals( expect=main.TRUE, actual=LinkUp,
2600 onpass="Link up successful",
2601 onfail="Failed to bring link up" )
2602 # TODO do some sort of check here
2603
2604 def CASE11( self, main ):
2605 """
2606 Switch Down
2607 """
2608 # NOTE: You should probably run a topology check after this
2609 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002610 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002611 assert main, "main not defined"
2612 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002613 assert main.CLIs, "main.CLIs not defined"
2614 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002615
2616 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
2617
2618 description = "Killing a switch to ensure it is discovered correctly"
2619 main.case( description )
2620 switch = main.params[ 'kill' ][ 'switch' ]
2621 switchDPID = main.params[ 'kill' ][ 'dpid' ]
2622
2623 # TODO: Make this switch parameterizable
2624 main.step( "Kill " + switch )
2625 main.log.info( "Deleting " + switch )
2626 main.Mininet1.delSwitch( switch )
2627 main.log.info( "Waiting " + str( switchSleep ) +
2628 " seconds for switch down to be discovered" )
2629 time.sleep( switchSleep )
2630 device = main.ONOScli1.getDevice( dpid=switchDPID )
2631 # Peek at the deleted switch
2632 main.log.warn( str( device ) )
2633 result = main.FALSE
2634 if device and device[ 'available' ] is False:
2635 result = main.TRUE
2636 utilities.assert_equals( expect=main.TRUE, actual=result,
2637 onpass="Kill switch successful",
2638 onfail="Failed to kill switch?" )
2639
2640 def CASE12( self, main ):
2641 """
2642 Switch Up
2643 """
2644 # NOTE: You should probably run a topology check after this
2645 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002646 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002647 assert main, "main not defined"
2648 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002649 assert main.CLIs, "main.CLIs not defined"
2650 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002651 assert ONOS1Port, "ONOS1Port not defined"
2652 assert ONOS2Port, "ONOS2Port not defined"
2653 assert ONOS3Port, "ONOS3Port not defined"
2654 assert ONOS4Port, "ONOS4Port not defined"
2655 assert ONOS5Port, "ONOS5Port not defined"
2656 assert ONOS6Port, "ONOS6Port not defined"
2657 assert ONOS7Port, "ONOS7Port not defined"
2658
2659 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
2660 switch = main.params[ 'kill' ][ 'switch' ]
2661 switchDPID = main.params[ 'kill' ][ 'dpid' ]
2662 links = main.params[ 'kill' ][ 'links' ].split()
2663 description = "Adding a switch to ensure it is discovered correctly"
2664 main.case( description )
2665
2666 main.step( "Add back " + switch )
2667 main.Mininet1.addSwitch( switch, dpid=switchDPID )
2668 for peer in links:
2669 main.Mininet1.addLink( switch, peer )
2670 ipList = []
Jon Halle1a3b752015-07-22 13:02:46 -07002671 for i in range( main.numCtrls ):
2672 ipList.append( main.nodes[ i ].ip_address )
Jon Hall5cf14d52015-07-16 12:15:19 -07002673 main.Mininet1.assignSwController( sw=switch, ip=ipList )
2674 main.log.info( "Waiting " + str( switchSleep ) +
2675 " seconds for switch up to be discovered" )
2676 time.sleep( switchSleep )
2677 device = main.ONOScli1.getDevice( dpid=switchDPID )
2678 # Peek at the deleted switch
2679 main.log.warn( str( device ) )
2680 result = main.FALSE
2681 if device and device[ 'available' ]:
2682 result = main.TRUE
2683 utilities.assert_equals( expect=main.TRUE, actual=result,
2684 onpass="add switch successful",
2685 onfail="Failed to add switch?" )
2686
2687 def CASE13( self, main ):
2688 """
2689 Clean up
2690 """
2691 import os
2692 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002693 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002694 assert main, "main not defined"
2695 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002696 assert main.CLIs, "main.CLIs not defined"
2697 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002698
2699 # printing colors to terminal
2700 colors = { 'cyan': '\033[96m', 'purple': '\033[95m',
2701 'blue': '\033[94m', 'green': '\033[92m',
2702 'yellow': '\033[93m', 'red': '\033[91m', 'end': '\033[0m' }
2703 main.case( "Test Cleanup" )
2704 main.step( "Killing tcpdumps" )
2705 main.Mininet2.stopTcpdump()
2706
2707 testname = main.TEST
Jon Hall5ec6b1b2015-09-17 18:20:14 -07002708 if main.params[ 'BACKUP' ][ 'ENABLED' ] == "True":
Jon Hall5cf14d52015-07-16 12:15:19 -07002709 main.step( "Copying MN pcap and ONOS log files to test station" )
2710 teststationUser = main.params[ 'BACKUP' ][ 'TESTONUSER' ]
2711 teststationIP = main.params[ 'BACKUP' ][ 'TESTONIP' ]
Jon Hall96091e62015-09-21 17:34:17 -07002712 # NOTE: MN Pcap file is being saved to logdir.
2713 # We scp this file as MN and TestON aren't necessarily the same vm
2714
2715 # FIXME: To be replaced with a Jenkin's post script
Jon Hall5cf14d52015-07-16 12:15:19 -07002716 # TODO: Load these from params
2717 # NOTE: must end in /
2718 logFolder = "/opt/onos/log/"
2719 logFiles = [ "karaf.log", "karaf.log.1" ]
2720 # NOTE: must end in /
Jon Hall5cf14d52015-07-16 12:15:19 -07002721 for f in logFiles:
Jon Halle1a3b752015-07-22 13:02:46 -07002722 for node in main.nodes:
Jon Hall96091e62015-09-21 17:34:17 -07002723 dstName = main.logdir + "/" + node.name + "-" + f
2724 main.ONOSbench.secureCopy( node.user_name, node.ip_address,
2725 logFolder + f, dstName )
Jon Hall5cf14d52015-07-16 12:15:19 -07002726 # std*.log's
2727 # NOTE: must end in /
2728 logFolder = "/opt/onos/var/"
2729 logFiles = [ "stderr.log", "stdout.log" ]
2730 # NOTE: must end in /
Jon Hall5cf14d52015-07-16 12:15:19 -07002731 for f in logFiles:
Jon Halle1a3b752015-07-22 13:02:46 -07002732 for node in main.nodes:
Jon Hall96091e62015-09-21 17:34:17 -07002733 dstName = main.logdir + "/" + node.name + "-" + f
2734 main.ONOSbench.secureCopy( node.user_name, node.ip_address,
2735 logFolder + f, dstName )
Jon Hall5ec6b1b2015-09-17 18:20:14 -07002736 else:
2737 main.log.debug( "skipping saving log files" )
Jon Hall5cf14d52015-07-16 12:15:19 -07002738
2739 main.step( "Stopping Mininet" )
2740 mnResult = main.Mininet1.stopNet()
2741 utilities.assert_equals( expect=main.TRUE, actual=mnResult,
2742 onpass="Mininet stopped",
2743 onfail="MN cleanup NOT successful" )
2744
2745 main.step( "Checking ONOS Logs for errors" )
Jon Halle1a3b752015-07-22 13:02:46 -07002746 for node in main.nodes:
Jon Hall5ec6b1b2015-09-17 18:20:14 -07002747 main.log.debug( "Checking logs for errors on " + node.name + ":" )
2748 main.log.warn( main.ONOSbench.checkLogs( node.ip_address ) )
Jon Hall5cf14d52015-07-16 12:15:19 -07002749
2750 try:
2751 timerLog = open( main.logdir + "/Timers.csv", 'w')
2752 main.log.error( ", ".join( labels ) + "\n" + ", ".join( data ) )
2753 timerLog.write( ", ".join( labels ) + "\n" + ", ".join( data ) )
2754 timerLog.close()
2755 except NameError, e:
2756 main.log.exception(e)
2757
2758 def CASE14( self, main ):
2759 """
2760 start election app on all onos nodes
2761 """
Jon Halle1a3b752015-07-22 13:02:46 -07002762 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002763 assert main, "main not defined"
2764 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002765 assert main.CLIs, "main.CLIs not defined"
2766 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002767
2768 main.case("Start Leadership Election app")
2769 main.step( "Install leadership election app" )
2770 appResult = main.ONOScli1.activateApp( "org.onosproject.election" )
2771 utilities.assert_equals(
2772 expect=main.TRUE,
2773 actual=appResult,
2774 onpass="Election app installed",
2775 onfail="Something went wrong with installing Leadership election" )
2776
2777 main.step( "Run for election on each node" )
2778 leaderResult = main.TRUE
2779 leaders = []
Jon Halle1a3b752015-07-22 13:02:46 -07002780 for cli in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -07002781 cli.electionTestRun()
Jon Halle1a3b752015-07-22 13:02:46 -07002782 for cli in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -07002783 leader = cli.electionTestLeader()
2784 if leader is None or leader == main.FALSE:
2785 main.log.error( cli.name + ": Leader for the election app " +
2786 "should be an ONOS node, instead got '" +
2787 str( leader ) + "'" )
2788 leaderResult = main.FALSE
2789 leaders.append( leader )
2790 utilities.assert_equals(
2791 expect=main.TRUE,
2792 actual=leaderResult,
2793 onpass="Successfully ran for leadership",
2794 onfail="Failed to run for leadership" )
2795
2796 main.step( "Check that each node shows the same leader" )
2797 sameLeader = main.TRUE
2798 if len( set( leaders ) ) != 1:
2799 sameLeader = main.FALSE
2800 main.log.error( "Results of electionTestLeader is order of CLIs:" +
2801 str( leaders ) )
2802 utilities.assert_equals(
2803 expect=main.TRUE,
2804 actual=sameLeader,
2805 onpass="Leadership is consistent for the election topic",
2806 onfail="Nodes have different leaders" )
2807
2808 def CASE15( self, main ):
2809 """
2810 Check that Leadership Election is still functional
acsmars9475b1c2015-08-28 18:02:08 -07002811 15.1 Run election on each node
2812 15.2 Check that each node has the same leaders and candidates
2813 15.3 Find current leader and withdraw
2814 15.4 Check that a new node was elected leader
2815 15.5 Check that that new leader was the candidate of old leader
2816 15.6 Run for election on old leader
2817 15.7 Check that oldLeader is a candidate, and leader if only 1 node
2818 15.8 Make sure that the old leader was added to the candidate list
2819
2820 old and new variable prefixes refer to data from before vs after
2821 withdrawl and later before withdrawl vs after re-election
Jon Hall5cf14d52015-07-16 12:15:19 -07002822 """
2823 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002824 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002825 assert main, "main not defined"
2826 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002827 assert main.CLIs, "main.CLIs not defined"
2828 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002829
Jon Hall5cf14d52015-07-16 12:15:19 -07002830 description = "Check that Leadership Election is still functional"
2831 main.case( description )
2832 # NOTE: Need to re-run since being a canidate is not persistant
acsmars9475b1c2015-08-28 18:02:08 -07002833 # TODO: add check for "Command not found:" in the driver, this
2834 # means the election test app isn't loaded
2835
2836 oldLeaders = [] # leaders by node before withdrawl from candidates
2837 newLeaders = [] # leaders by node after withdrawl from candidates
2838 oldAllCandidates = [] # list of lists of each nodes' candidates before
2839 newAllCandidates = [] # list of lists of each nodes' candidates after
2840 oldCandidates = [] # list of candidates from node 0 before withdrawl
2841 newCandidates = [] # list of candidates from node 0 after withdrawl
2842 oldLeader = '' # the old leader from oldLeaders, None if not same
2843 newLeader = '' # the new leaders fron newLoeaders, None if not same
2844 oldLeaderCLI = None # the CLI of the old leader used for re-electing
acsmars71adceb2015-08-31 15:09:26 -07002845 expectNoLeader = False # True when there is only one leader
2846 if main.numCtrls == 1:
2847 expectNoLeader = True
acsmars9475b1c2015-08-28 18:02:08 -07002848
Jon Hall5cf14d52015-07-16 12:15:19 -07002849 main.step( "Run for election on each node" )
acsmars9475b1c2015-08-28 18:02:08 -07002850 electionResult = main.TRUE
2851
2852 for cli in main.CLIs: # run test election on each node
2853 if cli.electionTestRun() == main.FALSE:
2854 electionResult = main.FALSE
2855
Jon Hall5cf14d52015-07-16 12:15:19 -07002856 utilities.assert_equals(
2857 expect=main.TRUE,
acsmars9475b1c2015-08-28 18:02:08 -07002858 actual=electionResult,
2859 onpass="All nodes successfully ran for leadership",
2860 onfail="At least one node failed to run for leadership" )
Jon Hall5cf14d52015-07-16 12:15:19 -07002861
acsmars3a72bde2015-09-02 14:16:22 -07002862 if electionResult == main.FALSE:
2863 main.log.error(
2864 "Skipping Test Case because Election Test App isn't loaded" )
2865 main.skipCase()
2866
acsmars9475b1c2015-08-28 18:02:08 -07002867 main.step( "Check that each node shows the same leader and candidates" )
2868 sameResult = main.TRUE
2869 failMessage = "Nodes have different leaders"
2870 for cli in main.CLIs:
2871 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
2872 oldAllCandidates.append( node )
2873 oldLeaders.append( node[ 0 ] )
2874 oldCandidates = oldAllCandidates[ 0 ]
2875
2876 # Check that each node has the same leader. Defines oldLeader
2877 if len( set( oldLeaders ) ) != 1:
2878 sameResult = main.FALSE
acsmars71adceb2015-08-31 15:09:26 -07002879 main.log.error( "More than one leader present:" + str( oldLeaders ) )
acsmars9475b1c2015-08-28 18:02:08 -07002880 oldLeader = None
2881 else:
2882 oldLeader = oldLeaders[ 0 ]
2883
2884 # Check that each node's candidate list is the same
acsmars29233db2015-11-04 11:15:00 -08002885 candidateDiscrepancy = False # Boolean of candidate mismatches
acsmars9475b1c2015-08-28 18:02:08 -07002886 for candidates in oldAllCandidates:
2887 if set( candidates ) != set( oldCandidates ):
2888 sameResult = main.FALSE
acsmars29233db2015-11-04 11:15:00 -08002889 candidateDiscrepancy = True
2890
2891 if candidateDiscrepancy:
2892 failMessage += " and candidates"
acsmars9475b1c2015-08-28 18:02:08 -07002893
Jon Hall5cf14d52015-07-16 12:15:19 -07002894 utilities.assert_equals(
2895 expect=main.TRUE,
acsmars71adceb2015-08-31 15:09:26 -07002896 actual=sameResult,
Jon Hall5cf14d52015-07-16 12:15:19 -07002897 onpass="Leadership is consistent for the election topic",
acsmars9475b1c2015-08-28 18:02:08 -07002898 onfail=failMessage )
Jon Hall5cf14d52015-07-16 12:15:19 -07002899
2900 main.step( "Find current leader and withdraw" )
acsmars9475b1c2015-08-28 18:02:08 -07002901 withdrawResult = main.TRUE
Jon Hall5cf14d52015-07-16 12:15:19 -07002902 # do some sanity checking on leader before using it
acsmars9475b1c2015-08-28 18:02:08 -07002903 if oldLeader is None:
2904 main.log.error( "Leadership isn't consistent." )
2905 withdrawResult = main.FALSE
2906 # Get the CLI of the oldLeader
Jon Halle1a3b752015-07-22 13:02:46 -07002907 for i in range( len( main.CLIs ) ):
acsmars9475b1c2015-08-28 18:02:08 -07002908 if oldLeader == main.nodes[ i ].ip_address:
2909 oldLeaderCLI = main.CLIs[ i ]
Jon Hall5cf14d52015-07-16 12:15:19 -07002910 break
2911 else: # FOR/ELSE statement
2912 main.log.error( "Leader election, could not find current leader" )
2913 if oldLeader:
acsmars9475b1c2015-08-28 18:02:08 -07002914 withdrawResult = oldLeaderCLI.electionTestWithdraw()
Jon Hall5cf14d52015-07-16 12:15:19 -07002915 utilities.assert_equals(
2916 expect=main.TRUE,
2917 actual=withdrawResult,
2918 onpass="Node was withdrawn from election",
2919 onfail="Node was not withdrawn from election" )
2920
acsmars9475b1c2015-08-28 18:02:08 -07002921 main.step( "Check that a new node was elected leader" )
acsmars71adceb2015-08-31 15:09:26 -07002922
Jon Hall5cf14d52015-07-16 12:15:19 -07002923 # FIXME: use threads
acsmars9475b1c2015-08-28 18:02:08 -07002924 newLeaderResult = main.TRUE
2925 failMessage = "Nodes have different leaders"
2926
2927 # Get new leaders and candidates
Jon Halle1a3b752015-07-22 13:02:46 -07002928 for cli in main.CLIs:
acsmars9475b1c2015-08-28 18:02:08 -07002929 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
acsmars71adceb2015-08-31 15:09:26 -07002930 # elections might no have finished yet
2931 if node[ 0 ] == 'none' and not expectNoLeader:
acsmars9475b1c2015-08-28 18:02:08 -07002932 main.log.info( "Node has no leader, waiting 5 seconds to be " +
2933 "sure elections are complete." )
2934 time.sleep(5)
2935 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
acsmars71adceb2015-08-31 15:09:26 -07002936 # election still isn't done or there is a problem
2937 if node[ 0 ] == 'none':
2938 main.log.error( "No leader was elected on at least 1 node" )
2939 newLeaderResult = main.FALSE
acsmars9475b1c2015-08-28 18:02:08 -07002940 newAllCandidates.append( node )
2941 newLeaders.append( node[ 0 ] )
2942 newCandidates = newAllCandidates[ 0 ]
2943
2944 # Check that each node has the same leader. Defines newLeader
2945 if len( set( newLeaders ) ) != 1:
2946 newLeaderResult = main.FALSE
2947 main.log.error( "Nodes have different leaders: " +
2948 str( newLeaders ) )
2949 newLeader = None
Jon Hall5cf14d52015-07-16 12:15:19 -07002950 else:
acsmars9475b1c2015-08-28 18:02:08 -07002951 newLeader = newLeaders[ 0 ]
2952
acsmars71adceb2015-08-31 15:09:26 -07002953 # Check that each node's candidate list is the same
2954 for candidates in newAllCandidates:
2955 if set( candidates ) != set( newCandidates ):
2956 newLeaderResult = main.FALSE
Jon Hallceb4abb2015-09-25 12:03:06 -07002957 main.log.error( "Discrepancy in candidate lists detected" )
acsmars71adceb2015-08-31 15:09:26 -07002958
acsmars9475b1c2015-08-28 18:02:08 -07002959 # Check that the new leader is not the older leader, which was withdrawn
2960 if newLeader == oldLeader:
2961 newLeaderResult = main.FALSE
2962 main.log.error( "All nodes still see old leader: " + oldLeader +
2963 " as the current leader" )
2964
Jon Hall5cf14d52015-07-16 12:15:19 -07002965 utilities.assert_equals(
2966 expect=main.TRUE,
acsmars9475b1c2015-08-28 18:02:08 -07002967 actual=newLeaderResult,
Jon Hall5cf14d52015-07-16 12:15:19 -07002968 onpass="Leadership election passed",
2969 onfail="Something went wrong with Leadership election" )
2970
acsmars9475b1c2015-08-28 18:02:08 -07002971 main.step( "Check that that new leader was the candidate of old leader")
2972 # candidates[ 2 ] should be come the top candidate after withdrawl
2973 correctCandidateResult = main.TRUE
acsmars71adceb2015-08-31 15:09:26 -07002974 if expectNoLeader:
2975 if newLeader == 'none':
2976 main.log.info( "No leader expected. None found. Pass" )
2977 correctCandidateResult = main.TRUE
2978 else:
2979 main.log.info( "Expected no leader, got: " + str( newLeader ) )
2980 correctCandidateResult = main.FALSE
2981 elif newLeader != oldCandidates[ 2 ]:
acsmars9475b1c2015-08-28 18:02:08 -07002982 correctCandidateResult = main.FALSE
2983 main.log.error( "Candidate " + newLeader + " was elected. " +
2984 oldCandidates[ 2 ] + " should have had priority." )
2985
2986 utilities.assert_equals(
2987 expect=main.TRUE,
2988 actual=correctCandidateResult,
2989 onpass="Correct Candidate Elected",
2990 onfail="Incorrect Candidate Elected" )
2991
Jon Hall5cf14d52015-07-16 12:15:19 -07002992 main.step( "Run for election on old leader( just so everyone " +
2993 "is in the hat )" )
acsmars9475b1c2015-08-28 18:02:08 -07002994 if oldLeaderCLI is not None:
2995 runResult = oldLeaderCLI.electionTestRun()
Jon Hall5cf14d52015-07-16 12:15:19 -07002996 else:
acsmars9475b1c2015-08-28 18:02:08 -07002997 main.log.error( "No old leader to re-elect" )
Jon Hall5cf14d52015-07-16 12:15:19 -07002998 runResult = main.FALSE
2999 utilities.assert_equals(
3000 expect=main.TRUE,
3001 actual=runResult,
3002 onpass="App re-ran for election",
3003 onfail="App failed to run for election" )
acsmars9475b1c2015-08-28 18:02:08 -07003004 main.step(
3005 "Check that oldLeader is a candidate, and leader if only 1 node" )
Jon Hall5cf14d52015-07-16 12:15:19 -07003006 # verify leader didn't just change
acsmars9475b1c2015-08-28 18:02:08 -07003007 positionResult = main.TRUE
3008 # Get new leaders and candidates, wait if oldLeader is not a candidate yet
3009
3010 # Reset and reuse the new candidate and leaders lists
3011 newAllCandidates = []
3012 newCandidates = []
3013 newLeaders = []
3014 for cli in main.CLIs:
3015 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
3016 if oldLeader not in node: # election might no have finished yet
3017 main.log.info( "Old Leader not elected, waiting 5 seconds to " +
3018 "be sure elections are complete" )
3019 time.sleep(5)
3020 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
3021 if oldLeader not in node: # election still isn't done, errors
3022 main.log.error(
3023 "Old leader was not elected on at least one node" )
3024 positionResult = main.FALSE
3025 newAllCandidates.append( node )
3026 newLeaders.append( node[ 0 ] )
3027 newCandidates = newAllCandidates[ 0 ]
3028
3029 # Check that each node has the same leader. Defines newLeader
3030 if len( set( newLeaders ) ) != 1:
3031 positionResult = main.FALSE
3032 main.log.error( "Nodes have different leaders: " +
3033 str( newLeaders ) )
3034 newLeader = None
Jon Hall5cf14d52015-07-16 12:15:19 -07003035 else:
acsmars9475b1c2015-08-28 18:02:08 -07003036 newLeader = newLeaders[ 0 ]
3037
acsmars71adceb2015-08-31 15:09:26 -07003038 # Check that each node's candidate list is the same
3039 for candidates in newAllCandidates:
3040 if set( candidates ) != set( newCandidates ):
3041 newLeaderResult = main.FALSE
Jon Hallceb4abb2015-09-25 12:03:06 -07003042 main.log.error( "Discrepancy in candidate lists detected" )
acsmars71adceb2015-08-31 15:09:26 -07003043
acsmars9475b1c2015-08-28 18:02:08 -07003044 # Check that the re-elected node is last on the candidate List
3045 if oldLeader != newCandidates[ -1 ]:
3046 main.log.error( "Old Leader (" + oldLeader + ") not in the proper position " +
3047 str( newCandidates ) )
3048 positionResult = main.FALSE
Jon Hall5cf14d52015-07-16 12:15:19 -07003049
3050 utilities.assert_equals(
3051 expect=main.TRUE,
acsmars9475b1c2015-08-28 18:02:08 -07003052 actual=positionResult,
Jon Hall5cf14d52015-07-16 12:15:19 -07003053 onpass="Old leader successfully re-ran for election",
3054 onfail="Something went wrong with Leadership election after " +
3055 "the old leader re-ran for election" )
3056
3057 def CASE16( self, main ):
3058 """
3059 Install Distributed Primitives app
3060 """
3061 import time
Jon Halle1a3b752015-07-22 13:02:46 -07003062 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07003063 assert main, "main not defined"
3064 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07003065 assert main.CLIs, "main.CLIs not defined"
3066 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07003067
3068 # Variables for the distributed primitives tests
3069 global pCounterName
3070 global iCounterName
3071 global pCounterValue
3072 global iCounterValue
3073 global onosSet
3074 global onosSetName
3075 pCounterName = "TestON-Partitions"
3076 iCounterName = "TestON-inMemory"
3077 pCounterValue = 0
3078 iCounterValue = 0
3079 onosSet = set([])
3080 onosSetName = "TestON-set"
3081
3082 description = "Install Primitives app"
3083 main.case( description )
3084 main.step( "Install Primitives app" )
3085 appName = "org.onosproject.distributedprimitives"
Jon Halle1a3b752015-07-22 13:02:46 -07003086 appResults = main.CLIs[0].activateApp( appName )
Jon Hall5cf14d52015-07-16 12:15:19 -07003087 utilities.assert_equals( expect=main.TRUE,
3088 actual=appResults,
3089 onpass="Primitives app activated",
3090 onfail="Primitives app not activated" )
3091 time.sleep( 5 ) # To allow all nodes to activate
3092
3093 def CASE17( self, main ):
3094 """
3095 Check for basic functionality with distributed primitives
3096 """
Jon Hall5cf14d52015-07-16 12:15:19 -07003097 # Make sure variables are defined/set
Jon Halle1a3b752015-07-22 13:02:46 -07003098 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07003099 assert main, "main not defined"
3100 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07003101 assert main.CLIs, "main.CLIs not defined"
3102 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07003103 assert pCounterName, "pCounterName not defined"
3104 assert iCounterName, "iCounterName not defined"
3105 assert onosSetName, "onosSetName not defined"
3106 # NOTE: assert fails if value is 0/None/Empty/False
3107 try:
3108 pCounterValue
3109 except NameError:
3110 main.log.error( "pCounterValue not defined, setting to 0" )
3111 pCounterValue = 0
3112 try:
3113 iCounterValue
3114 except NameError:
3115 main.log.error( "iCounterValue not defined, setting to 0" )
3116 iCounterValue = 0
3117 try:
3118 onosSet
3119 except NameError:
3120 main.log.error( "onosSet not defined, setting to empty Set" )
3121 onosSet = set([])
3122 # Variables for the distributed primitives tests. These are local only
3123 addValue = "a"
3124 addAllValue = "a b c d e f"
3125 retainValue = "c d e f"
3126
3127 description = "Check for basic functionality with distributed " +\
3128 "primitives"
3129 main.case( description )
Jon Halle1a3b752015-07-22 13:02:46 -07003130 main.caseExplanation = "Test the methods of the distributed " +\
3131 "primitives (counters and sets) throught the cli"
Jon Hall5cf14d52015-07-16 12:15:19 -07003132 # DISTRIBUTED ATOMIC COUNTERS
Jon Halle1a3b752015-07-22 13:02:46 -07003133 # Partitioned counters
3134 main.step( "Increment then get a default counter on each node" )
Jon Hall5cf14d52015-07-16 12:15:19 -07003135 pCounters = []
3136 threads = []
3137 addedPValues = []
Jon Halle1a3b752015-07-22 13:02:46 -07003138 for i in range( main.numCtrls ):
3139 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
3140 name="counterAddAndGet-" + str( i ),
Jon Hall5cf14d52015-07-16 12:15:19 -07003141 args=[ pCounterName ] )
3142 pCounterValue += 1
3143 addedPValues.append( pCounterValue )
3144 threads.append( t )
3145 t.start()
3146
3147 for t in threads:
3148 t.join()
3149 pCounters.append( t.result )
3150 # Check that counter incremented numController times
3151 pCounterResults = True
3152 for i in addedPValues:
3153 tmpResult = i in pCounters
3154 pCounterResults = pCounterResults and tmpResult
3155 if not tmpResult:
3156 main.log.error( str( i ) + " is not in partitioned "
3157 "counter incremented results" )
3158 utilities.assert_equals( expect=True,
3159 actual=pCounterResults,
3160 onpass="Default counter incremented",
3161 onfail="Error incrementing default" +
3162 " counter" )
3163
Jon Halle1a3b752015-07-22 13:02:46 -07003164 main.step( "Get then Increment a default counter on each node" )
3165 pCounters = []
3166 threads = []
3167 addedPValues = []
3168 for i in range( main.numCtrls ):
3169 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
3170 name="counterGetAndAdd-" + str( i ),
3171 args=[ pCounterName ] )
3172 addedPValues.append( pCounterValue )
3173 pCounterValue += 1
3174 threads.append( t )
3175 t.start()
3176
3177 for t in threads:
3178 t.join()
3179 pCounters.append( t.result )
3180 # Check that counter incremented numController times
3181 pCounterResults = True
3182 for i in addedPValues:
3183 tmpResult = i in pCounters
3184 pCounterResults = pCounterResults and tmpResult
3185 if not tmpResult:
3186 main.log.error( str( i ) + " is not in partitioned "
3187 "counter incremented results" )
3188 utilities.assert_equals( expect=True,
3189 actual=pCounterResults,
3190 onpass="Default counter incremented",
3191 onfail="Error incrementing default" +
3192 " counter" )
3193
3194 main.step( "Counters we added have the correct values" )
3195 incrementCheck = main.Counters.counterCheck( pCounterName, pCounterValue )
3196 utilities.assert_equals( expect=main.TRUE,
3197 actual=incrementCheck,
3198 onpass="Added counters are correct",
3199 onfail="Added counters are incorrect" )
3200
3201 main.step( "Add -8 to then get a default counter on each node" )
3202 pCounters = []
3203 threads = []
3204 addedPValues = []
3205 for i in range( main.numCtrls ):
3206 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
3207 name="counterIncrement-" + str( i ),
3208 args=[ pCounterName ],
3209 kwargs={ "delta": -8 } )
3210 pCounterValue += -8
3211 addedPValues.append( pCounterValue )
3212 threads.append( t )
3213 t.start()
3214
3215 for t in threads:
3216 t.join()
3217 pCounters.append( t.result )
3218 # Check that counter incremented numController times
3219 pCounterResults = True
3220 for i in addedPValues:
3221 tmpResult = i in pCounters
3222 pCounterResults = pCounterResults and tmpResult
3223 if not tmpResult:
3224 main.log.error( str( i ) + " is not in partitioned "
3225 "counter incremented results" )
3226 utilities.assert_equals( expect=True,
3227 actual=pCounterResults,
3228 onpass="Default counter incremented",
3229 onfail="Error incrementing default" +
3230 " counter" )
3231
3232 main.step( "Add 5 to then get a default counter on each node" )
3233 pCounters = []
3234 threads = []
3235 addedPValues = []
3236 for i in range( main.numCtrls ):
3237 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
3238 name="counterIncrement-" + str( i ),
3239 args=[ pCounterName ],
3240 kwargs={ "delta": 5 } )
3241 pCounterValue += 5
3242 addedPValues.append( pCounterValue )
3243 threads.append( t )
3244 t.start()
3245
3246 for t in threads:
3247 t.join()
3248 pCounters.append( t.result )
3249 # Check that counter incremented numController times
3250 pCounterResults = True
3251 for i in addedPValues:
3252 tmpResult = i in pCounters
3253 pCounterResults = pCounterResults and tmpResult
3254 if not tmpResult:
3255 main.log.error( str( i ) + " is not in partitioned "
3256 "counter incremented results" )
3257 utilities.assert_equals( expect=True,
3258 actual=pCounterResults,
3259 onpass="Default counter incremented",
3260 onfail="Error incrementing default" +
3261 " counter" )
3262
3263 main.step( "Get then add 5 to a default counter on each node" )
3264 pCounters = []
3265 threads = []
3266 addedPValues = []
3267 for i in range( main.numCtrls ):
3268 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
3269 name="counterIncrement-" + str( i ),
3270 args=[ pCounterName ],
3271 kwargs={ "delta": 5 } )
3272 addedPValues.append( pCounterValue )
3273 pCounterValue += 5
3274 threads.append( t )
3275 t.start()
3276
3277 for t in threads:
3278 t.join()
3279 pCounters.append( t.result )
3280 # Check that counter incremented numController times
3281 pCounterResults = True
3282 for i in addedPValues:
3283 tmpResult = i in pCounters
3284 pCounterResults = pCounterResults and tmpResult
3285 if not tmpResult:
3286 main.log.error( str( i ) + " is not in partitioned "
3287 "counter incremented results" )
3288 utilities.assert_equals( expect=True,
3289 actual=pCounterResults,
3290 onpass="Default counter incremented",
3291 onfail="Error incrementing default" +
3292 " counter" )
3293
3294 main.step( "Counters we added have the correct values" )
3295 incrementCheck = main.Counters.counterCheck( pCounterName, pCounterValue )
3296 utilities.assert_equals( expect=main.TRUE,
3297 actual=incrementCheck,
3298 onpass="Added counters are correct",
3299 onfail="Added counters are incorrect" )
3300
3301 # In-Memory counters
3302 main.step( "Increment and get an in-memory counter on each node" )
Jon Hall5cf14d52015-07-16 12:15:19 -07003303 iCounters = []
3304 addedIValues = []
3305 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003306 for i in range( main.numCtrls ):
3307 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003308 name="icounterIncrement-" + str( i ),
3309 args=[ iCounterName ],
3310 kwargs={ "inMemory": True } )
3311 iCounterValue += 1
3312 addedIValues.append( iCounterValue )
3313 threads.append( t )
3314 t.start()
3315
3316 for t in threads:
3317 t.join()
3318 iCounters.append( t.result )
3319 # Check that counter incremented numController times
3320 iCounterResults = True
3321 for i in addedIValues:
3322 tmpResult = i in iCounters
3323 iCounterResults = iCounterResults and tmpResult
3324 if not tmpResult:
3325 main.log.error( str( i ) + " is not in the in-memory "
3326 "counter incremented results" )
3327 utilities.assert_equals( expect=True,
3328 actual=iCounterResults,
Jon Halle1a3b752015-07-22 13:02:46 -07003329 onpass="In-memory counter incremented",
3330 onfail="Error incrementing in-memory" +
Jon Hall5cf14d52015-07-16 12:15:19 -07003331 " counter" )
3332
Jon Halle1a3b752015-07-22 13:02:46 -07003333 main.step( "Get then Increment a in-memory counter on each node" )
3334 iCounters = []
3335 threads = []
3336 addedIValues = []
3337 for i in range( main.numCtrls ):
3338 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
3339 name="counterGetAndAdd-" + str( i ),
3340 args=[ iCounterName ],
3341 kwargs={ "inMemory": True } )
3342 addedIValues.append( iCounterValue )
3343 iCounterValue += 1
3344 threads.append( t )
3345 t.start()
3346
3347 for t in threads:
3348 t.join()
3349 iCounters.append( t.result )
3350 # Check that counter incremented numController times
3351 iCounterResults = True
3352 for i in addedIValues:
3353 tmpResult = i in iCounters
3354 iCounterResults = iCounterResults and tmpResult
3355 if not tmpResult:
3356 main.log.error( str( i ) + " is not in in-memory "
3357 "counter incremented results" )
3358 utilities.assert_equals( expect=True,
3359 actual=iCounterResults,
3360 onpass="In-memory counter incremented",
3361 onfail="Error incrementing in-memory" +
3362 " counter" )
3363
3364 main.step( "Counters we added have the correct values" )
3365 incrementCheck = main.Counters.counterCheck( iCounterName, iCounterValue )
3366 utilities.assert_equals( expect=main.TRUE,
3367 actual=incrementCheck,
3368 onpass="Added counters are correct",
3369 onfail="Added counters are incorrect" )
3370
3371 main.step( "Add -8 to then get a in-memory counter on each node" )
3372 iCounters = []
3373 threads = []
3374 addedIValues = []
3375 for i in range( main.numCtrls ):
3376 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
3377 name="counterIncrement-" + str( i ),
3378 args=[ iCounterName ],
3379 kwargs={ "delta": -8, "inMemory": True } )
3380 iCounterValue += -8
3381 addedIValues.append( iCounterValue )
3382 threads.append( t )
3383 t.start()
3384
3385 for t in threads:
3386 t.join()
3387 iCounters.append( t.result )
3388 # Check that counter incremented numController times
3389 iCounterResults = True
3390 for i in addedIValues:
3391 tmpResult = i in iCounters
3392 iCounterResults = iCounterResults and tmpResult
3393 if not tmpResult:
3394 main.log.error( str( i ) + " is not in in-memory "
3395 "counter incremented results" )
3396 utilities.assert_equals( expect=True,
3397 actual=pCounterResults,
3398 onpass="In-memory counter incremented",
3399 onfail="Error incrementing in-memory" +
3400 " counter" )
3401
3402 main.step( "Add 5 to then get a in-memory counter on each node" )
3403 iCounters = []
3404 threads = []
3405 addedIValues = []
3406 for i in range( main.numCtrls ):
3407 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
3408 name="counterIncrement-" + str( i ),
3409 args=[ iCounterName ],
3410 kwargs={ "delta": 5, "inMemory": True } )
3411 iCounterValue += 5
3412 addedIValues.append( iCounterValue )
3413 threads.append( t )
3414 t.start()
3415
3416 for t in threads:
3417 t.join()
3418 iCounters.append( t.result )
3419 # Check that counter incremented numController times
3420 iCounterResults = True
3421 for i in addedIValues:
3422 tmpResult = i in iCounters
3423 iCounterResults = iCounterResults and tmpResult
3424 if not tmpResult:
3425 main.log.error( str( i ) + " is not in in-memory "
3426 "counter incremented results" )
3427 utilities.assert_equals( expect=True,
3428 actual=pCounterResults,
3429 onpass="In-memory counter incremented",
3430 onfail="Error incrementing in-memory" +
3431 " counter" )
3432
3433 main.step( "Get then add 5 to a in-memory counter on each node" )
3434 iCounters = []
3435 threads = []
3436 addedIValues = []
3437 for i in range( main.numCtrls ):
3438 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
3439 name="counterIncrement-" + str( i ),
3440 args=[ iCounterName ],
3441 kwargs={ "delta": 5, "inMemory": True } )
3442 addedIValues.append( iCounterValue )
3443 iCounterValue += 5
3444 threads.append( t )
3445 t.start()
3446
3447 for t in threads:
3448 t.join()
3449 iCounters.append( t.result )
3450 # Check that counter incremented numController times
3451 iCounterResults = True
3452 for i in addedIValues:
3453 tmpResult = i in iCounters
3454 iCounterResults = iCounterResults and tmpResult
3455 if not tmpResult:
3456 main.log.error( str( i ) + " is not in in-memory "
3457 "counter incremented results" )
3458 utilities.assert_equals( expect=True,
3459 actual=iCounterResults,
3460 onpass="In-memory counter incremented",
3461 onfail="Error incrementing in-memory" +
3462 " counter" )
3463
3464 main.step( "Counters we added have the correct values" )
3465 incrementCheck = main.Counters.counterCheck( iCounterName, iCounterValue )
3466 utilities.assert_equals( expect=main.TRUE,
3467 actual=incrementCheck,
3468 onpass="Added counters are correct",
3469 onfail="Added counters are incorrect" )
3470
Jon Hall5cf14d52015-07-16 12:15:19 -07003471 main.step( "Check counters are consistant across nodes" )
Jon Hall57b50432015-10-22 10:20:10 -07003472 onosCounters, consistentCounterResults = main.Counters.consistentCheck()
Jon Hall5cf14d52015-07-16 12:15:19 -07003473 utilities.assert_equals( expect=main.TRUE,
3474 actual=consistentCounterResults,
3475 onpass="ONOS counters are consistent " +
3476 "across nodes",
3477 onfail="ONOS Counters are inconsistent " +
3478 "across nodes" )
3479
3480 main.step( "Counters we added have the correct values" )
Jon Halle1a3b752015-07-22 13:02:46 -07003481 incrementCheck = main.Counters.counterCheck( iCounterName, iCounterValue )
3482 incrementCheck = incrementCheck and \
3483 main.Counters.counterCheck( iCounterName, iCounterValue )
Jon Hall5cf14d52015-07-16 12:15:19 -07003484 utilities.assert_equals( expect=main.TRUE,
Jon Halle1a3b752015-07-22 13:02:46 -07003485 actual=incrementCheck,
Jon Hall5cf14d52015-07-16 12:15:19 -07003486 onpass="Added counters are correct",
3487 onfail="Added counters are incorrect" )
3488 # DISTRIBUTED SETS
3489 main.step( "Distributed Set get" )
3490 size = len( onosSet )
3491 getResponses = []
3492 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003493 for i in range( main.numCtrls ):
3494 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003495 name="setTestGet-" + str( i ),
3496 args=[ onosSetName ] )
3497 threads.append( t )
3498 t.start()
3499 for t in threads:
3500 t.join()
3501 getResponses.append( t.result )
3502
3503 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003504 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003505 if isinstance( getResponses[ i ], list):
3506 current = set( getResponses[ i ] )
3507 if len( current ) == len( getResponses[ i ] ):
3508 # no repeats
3509 if onosSet != current:
3510 main.log.error( "ONOS" + str( i + 1 ) +
3511 " has incorrect view" +
3512 " of set " + onosSetName + ":\n" +
3513 str( getResponses[ i ] ) )
3514 main.log.debug( "Expected: " + str( onosSet ) )
3515 main.log.debug( "Actual: " + str( current ) )
3516 getResults = main.FALSE
3517 else:
3518 # error, set is not a set
3519 main.log.error( "ONOS" + str( i + 1 ) +
3520 " has repeat elements in" +
3521 " set " + onosSetName + ":\n" +
3522 str( getResponses[ i ] ) )
3523 getResults = main.FALSE
3524 elif getResponses[ i ] == main.ERROR:
3525 getResults = main.FALSE
3526 utilities.assert_equals( expect=main.TRUE,
3527 actual=getResults,
3528 onpass="Set elements are correct",
3529 onfail="Set elements are incorrect" )
3530
3531 main.step( "Distributed Set size" )
3532 sizeResponses = []
3533 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003534 for i in range( main.numCtrls ):
3535 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003536 name="setTestSize-" + str( i ),
3537 args=[ onosSetName ] )
3538 threads.append( t )
3539 t.start()
3540 for t in threads:
3541 t.join()
3542 sizeResponses.append( t.result )
3543
3544 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003545 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003546 if size != sizeResponses[ i ]:
3547 sizeResults = main.FALSE
3548 main.log.error( "ONOS" + str( i + 1 ) +
3549 " expected a size of " + str( size ) +
3550 " for set " + onosSetName +
3551 " but got " + str( sizeResponses[ i ] ) )
3552 utilities.assert_equals( expect=main.TRUE,
3553 actual=sizeResults,
3554 onpass="Set sizes are correct",
3555 onfail="Set sizes are incorrect" )
3556
3557 main.step( "Distributed Set add()" )
3558 onosSet.add( addValue )
3559 addResponses = []
3560 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003561 for i in range( main.numCtrls ):
3562 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall5cf14d52015-07-16 12:15:19 -07003563 name="setTestAdd-" + str( i ),
3564 args=[ onosSetName, addValue ] )
3565 threads.append( t )
3566 t.start()
3567 for t in threads:
3568 t.join()
3569 addResponses.append( t.result )
3570
3571 # main.TRUE = successfully changed the set
3572 # main.FALSE = action resulted in no change in set
3573 # main.ERROR - Some error in executing the function
3574 addResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003575 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003576 if addResponses[ i ] == main.TRUE:
3577 # All is well
3578 pass
3579 elif addResponses[ i ] == main.FALSE:
3580 # Already in set, probably fine
3581 pass
3582 elif addResponses[ i ] == main.ERROR:
3583 # Error in execution
3584 addResults = main.FALSE
3585 else:
3586 # unexpected result
3587 addResults = main.FALSE
3588 if addResults != main.TRUE:
3589 main.log.error( "Error executing set add" )
3590
3591 # Check if set is still correct
3592 size = len( onosSet )
3593 getResponses = []
3594 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003595 for i in range( main.numCtrls ):
3596 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003597 name="setTestGet-" + str( i ),
3598 args=[ onosSetName ] )
3599 threads.append( t )
3600 t.start()
3601 for t in threads:
3602 t.join()
3603 getResponses.append( t.result )
3604 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003605 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003606 if isinstance( getResponses[ i ], list):
3607 current = set( getResponses[ i ] )
3608 if len( current ) == len( getResponses[ i ] ):
3609 # no repeats
3610 if onosSet != current:
3611 main.log.error( "ONOS" + str( i + 1 ) +
3612 " has incorrect view" +
3613 " of set " + onosSetName + ":\n" +
3614 str( getResponses[ i ] ) )
3615 main.log.debug( "Expected: " + str( onosSet ) )
3616 main.log.debug( "Actual: " + str( current ) )
3617 getResults = main.FALSE
3618 else:
3619 # error, set is not a set
3620 main.log.error( "ONOS" + str( i + 1 ) +
3621 " has repeat elements in" +
3622 " set " + onosSetName + ":\n" +
3623 str( getResponses[ i ] ) )
3624 getResults = main.FALSE
3625 elif getResponses[ i ] == main.ERROR:
3626 getResults = main.FALSE
3627 sizeResponses = []
3628 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003629 for i in range( main.numCtrls ):
3630 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003631 name="setTestSize-" + str( i ),
3632 args=[ onosSetName ] )
3633 threads.append( t )
3634 t.start()
3635 for t in threads:
3636 t.join()
3637 sizeResponses.append( t.result )
3638 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003639 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003640 if size != sizeResponses[ i ]:
3641 sizeResults = main.FALSE
3642 main.log.error( "ONOS" + str( i + 1 ) +
3643 " expected a size of " + str( size ) +
3644 " for set " + onosSetName +
3645 " but got " + str( sizeResponses[ i ] ) )
3646 addResults = addResults and getResults and sizeResults
3647 utilities.assert_equals( expect=main.TRUE,
3648 actual=addResults,
3649 onpass="Set add correct",
3650 onfail="Set add was incorrect" )
3651
3652 main.step( "Distributed Set addAll()" )
3653 onosSet.update( addAllValue.split() )
3654 addResponses = []
3655 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003656 for i in range( main.numCtrls ):
3657 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall5cf14d52015-07-16 12:15:19 -07003658 name="setTestAddAll-" + str( i ),
3659 args=[ onosSetName, addAllValue ] )
3660 threads.append( t )
3661 t.start()
3662 for t in threads:
3663 t.join()
3664 addResponses.append( t.result )
3665
3666 # main.TRUE = successfully changed the set
3667 # main.FALSE = action resulted in no change in set
3668 # main.ERROR - Some error in executing the function
3669 addAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003670 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003671 if addResponses[ i ] == main.TRUE:
3672 # All is well
3673 pass
3674 elif addResponses[ i ] == main.FALSE:
3675 # Already in set, probably fine
3676 pass
3677 elif addResponses[ i ] == main.ERROR:
3678 # Error in execution
3679 addAllResults = main.FALSE
3680 else:
3681 # unexpected result
3682 addAllResults = main.FALSE
3683 if addAllResults != main.TRUE:
3684 main.log.error( "Error executing set addAll" )
3685
3686 # Check if set is still correct
3687 size = len( onosSet )
3688 getResponses = []
3689 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003690 for i in range( main.numCtrls ):
3691 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003692 name="setTestGet-" + str( i ),
3693 args=[ onosSetName ] )
3694 threads.append( t )
3695 t.start()
3696 for t in threads:
3697 t.join()
3698 getResponses.append( t.result )
3699 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003700 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003701 if isinstance( getResponses[ i ], list):
3702 current = set( getResponses[ i ] )
3703 if len( current ) == len( getResponses[ i ] ):
3704 # no repeats
3705 if onosSet != current:
3706 main.log.error( "ONOS" + str( i + 1 ) +
3707 " has incorrect view" +
3708 " of set " + onosSetName + ":\n" +
3709 str( getResponses[ i ] ) )
3710 main.log.debug( "Expected: " + str( onosSet ) )
3711 main.log.debug( "Actual: " + str( current ) )
3712 getResults = main.FALSE
3713 else:
3714 # error, set is not a set
3715 main.log.error( "ONOS" + str( i + 1 ) +
3716 " has repeat elements in" +
3717 " set " + onosSetName + ":\n" +
3718 str( getResponses[ i ] ) )
3719 getResults = main.FALSE
3720 elif getResponses[ i ] == main.ERROR:
3721 getResults = main.FALSE
3722 sizeResponses = []
3723 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003724 for i in range( main.numCtrls ):
3725 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003726 name="setTestSize-" + str( i ),
3727 args=[ onosSetName ] )
3728 threads.append( t )
3729 t.start()
3730 for t in threads:
3731 t.join()
3732 sizeResponses.append( t.result )
3733 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003734 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003735 if size != sizeResponses[ i ]:
3736 sizeResults = main.FALSE
3737 main.log.error( "ONOS" + str( i + 1 ) +
3738 " expected a size of " + str( size ) +
3739 " for set " + onosSetName +
3740 " but got " + str( sizeResponses[ i ] ) )
3741 addAllResults = addAllResults and getResults and sizeResults
3742 utilities.assert_equals( expect=main.TRUE,
3743 actual=addAllResults,
3744 onpass="Set addAll correct",
3745 onfail="Set addAll was incorrect" )
3746
3747 main.step( "Distributed Set contains()" )
3748 containsResponses = []
3749 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003750 for i in range( main.numCtrls ):
3751 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003752 name="setContains-" + str( i ),
3753 args=[ onosSetName ],
3754 kwargs={ "values": addValue } )
3755 threads.append( t )
3756 t.start()
3757 for t in threads:
3758 t.join()
3759 # NOTE: This is the tuple
3760 containsResponses.append( t.result )
3761
3762 containsResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003763 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003764 if containsResponses[ i ] == main.ERROR:
3765 containsResults = main.FALSE
3766 else:
3767 containsResults = containsResults and\
3768 containsResponses[ i ][ 1 ]
3769 utilities.assert_equals( expect=main.TRUE,
3770 actual=containsResults,
3771 onpass="Set contains is functional",
3772 onfail="Set contains failed" )
3773
3774 main.step( "Distributed Set containsAll()" )
3775 containsAllResponses = []
3776 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003777 for i in range( main.numCtrls ):
3778 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003779 name="setContainsAll-" + str( i ),
3780 args=[ onosSetName ],
3781 kwargs={ "values": addAllValue } )
3782 threads.append( t )
3783 t.start()
3784 for t in threads:
3785 t.join()
3786 # NOTE: This is the tuple
3787 containsAllResponses.append( t.result )
3788
3789 containsAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003790 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003791 if containsResponses[ i ] == main.ERROR:
3792 containsResults = main.FALSE
3793 else:
3794 containsResults = containsResults and\
3795 containsResponses[ i ][ 1 ]
3796 utilities.assert_equals( expect=main.TRUE,
3797 actual=containsAllResults,
3798 onpass="Set containsAll is functional",
3799 onfail="Set containsAll failed" )
3800
3801 main.step( "Distributed Set remove()" )
3802 onosSet.remove( addValue )
3803 removeResponses = []
3804 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003805 for i in range( main.numCtrls ):
3806 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall5cf14d52015-07-16 12:15:19 -07003807 name="setTestRemove-" + str( i ),
3808 args=[ onosSetName, addValue ] )
3809 threads.append( t )
3810 t.start()
3811 for t in threads:
3812 t.join()
3813 removeResponses.append( t.result )
3814
3815 # main.TRUE = successfully changed the set
3816 # main.FALSE = action resulted in no change in set
3817 # main.ERROR - Some error in executing the function
3818 removeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003819 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003820 if removeResponses[ i ] == main.TRUE:
3821 # All is well
3822 pass
3823 elif removeResponses[ i ] == main.FALSE:
3824 # not in set, probably fine
3825 pass
3826 elif removeResponses[ i ] == main.ERROR:
3827 # Error in execution
3828 removeResults = main.FALSE
3829 else:
3830 # unexpected result
3831 removeResults = main.FALSE
3832 if removeResults != main.TRUE:
3833 main.log.error( "Error executing set remove" )
3834
3835 # Check if set is still correct
3836 size = len( onosSet )
3837 getResponses = []
3838 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003839 for i in range( main.numCtrls ):
3840 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003841 name="setTestGet-" + str( i ),
3842 args=[ onosSetName ] )
3843 threads.append( t )
3844 t.start()
3845 for t in threads:
3846 t.join()
3847 getResponses.append( t.result )
3848 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003849 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003850 if isinstance( getResponses[ i ], list):
3851 current = set( getResponses[ i ] )
3852 if len( current ) == len( getResponses[ i ] ):
3853 # no repeats
3854 if onosSet != current:
3855 main.log.error( "ONOS" + str( i + 1 ) +
3856 " has incorrect view" +
3857 " of set " + onosSetName + ":\n" +
3858 str( getResponses[ i ] ) )
3859 main.log.debug( "Expected: " + str( onosSet ) )
3860 main.log.debug( "Actual: " + str( current ) )
3861 getResults = main.FALSE
3862 else:
3863 # error, set is not a set
3864 main.log.error( "ONOS" + str( i + 1 ) +
3865 " has repeat elements in" +
3866 " set " + onosSetName + ":\n" +
3867 str( getResponses[ i ] ) )
3868 getResults = main.FALSE
3869 elif getResponses[ i ] == main.ERROR:
3870 getResults = main.FALSE
3871 sizeResponses = []
3872 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003873 for i in range( main.numCtrls ):
3874 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003875 name="setTestSize-" + str( i ),
3876 args=[ onosSetName ] )
3877 threads.append( t )
3878 t.start()
3879 for t in threads:
3880 t.join()
3881 sizeResponses.append( t.result )
3882 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003883 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003884 if size != sizeResponses[ i ]:
3885 sizeResults = main.FALSE
3886 main.log.error( "ONOS" + str( i + 1 ) +
3887 " expected a size of " + str( size ) +
3888 " for set " + onosSetName +
3889 " but got " + str( sizeResponses[ i ] ) )
3890 removeResults = removeResults and getResults and sizeResults
3891 utilities.assert_equals( expect=main.TRUE,
3892 actual=removeResults,
3893 onpass="Set remove correct",
3894 onfail="Set remove was incorrect" )
3895
3896 main.step( "Distributed Set removeAll()" )
3897 onosSet.difference_update( addAllValue.split() )
3898 removeAllResponses = []
3899 threads = []
3900 try:
Jon Halle1a3b752015-07-22 13:02:46 -07003901 for i in range( main.numCtrls ):
3902 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall5cf14d52015-07-16 12:15:19 -07003903 name="setTestRemoveAll-" + str( i ),
3904 args=[ onosSetName, addAllValue ] )
3905 threads.append( t )
3906 t.start()
3907 for t in threads:
3908 t.join()
3909 removeAllResponses.append( t.result )
3910 except Exception, e:
3911 main.log.exception(e)
3912
3913 # main.TRUE = successfully changed the set
3914 # main.FALSE = action resulted in no change in set
3915 # main.ERROR - Some error in executing the function
3916 removeAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003917 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003918 if removeAllResponses[ i ] == main.TRUE:
3919 # All is well
3920 pass
3921 elif removeAllResponses[ i ] == main.FALSE:
3922 # not in set, probably fine
3923 pass
3924 elif removeAllResponses[ i ] == main.ERROR:
3925 # Error in execution
3926 removeAllResults = main.FALSE
3927 else:
3928 # unexpected result
3929 removeAllResults = main.FALSE
3930 if removeAllResults != main.TRUE:
3931 main.log.error( "Error executing set removeAll" )
3932
3933 # Check if set is still correct
3934 size = len( onosSet )
3935 getResponses = []
3936 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003937 for i in range( main.numCtrls ):
3938 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003939 name="setTestGet-" + str( i ),
3940 args=[ onosSetName ] )
3941 threads.append( t )
3942 t.start()
3943 for t in threads:
3944 t.join()
3945 getResponses.append( t.result )
3946 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003947 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003948 if isinstance( getResponses[ i ], list):
3949 current = set( getResponses[ i ] )
3950 if len( current ) == len( getResponses[ i ] ):
3951 # no repeats
3952 if onosSet != current:
3953 main.log.error( "ONOS" + str( i + 1 ) +
3954 " has incorrect view" +
3955 " of set " + onosSetName + ":\n" +
3956 str( getResponses[ i ] ) )
3957 main.log.debug( "Expected: " + str( onosSet ) )
3958 main.log.debug( "Actual: " + str( current ) )
3959 getResults = main.FALSE
3960 else:
3961 # error, set is not a set
3962 main.log.error( "ONOS" + str( i + 1 ) +
3963 " has repeat elements in" +
3964 " set " + onosSetName + ":\n" +
3965 str( getResponses[ i ] ) )
3966 getResults = main.FALSE
3967 elif getResponses[ i ] == main.ERROR:
3968 getResults = main.FALSE
3969 sizeResponses = []
3970 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003971 for i in range( main.numCtrls ):
3972 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003973 name="setTestSize-" + str( i ),
3974 args=[ onosSetName ] )
3975 threads.append( t )
3976 t.start()
3977 for t in threads:
3978 t.join()
3979 sizeResponses.append( t.result )
3980 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003981 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003982 if size != sizeResponses[ i ]:
3983 sizeResults = main.FALSE
3984 main.log.error( "ONOS" + str( i + 1 ) +
3985 " expected a size of " + str( size ) +
3986 " for set " + onosSetName +
3987 " but got " + str( sizeResponses[ i ] ) )
3988 removeAllResults = removeAllResults and getResults and sizeResults
3989 utilities.assert_equals( expect=main.TRUE,
3990 actual=removeAllResults,
3991 onpass="Set removeAll correct",
3992 onfail="Set removeAll was incorrect" )
3993
3994 main.step( "Distributed Set addAll()" )
3995 onosSet.update( addAllValue.split() )
3996 addResponses = []
3997 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003998 for i in range( main.numCtrls ):
3999 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall5cf14d52015-07-16 12:15:19 -07004000 name="setTestAddAll-" + str( i ),
4001 args=[ onosSetName, addAllValue ] )
4002 threads.append( t )
4003 t.start()
4004 for t in threads:
4005 t.join()
4006 addResponses.append( t.result )
4007
4008 # main.TRUE = successfully changed the set
4009 # main.FALSE = action resulted in no change in set
4010 # main.ERROR - Some error in executing the function
4011 addAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004012 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004013 if addResponses[ i ] == main.TRUE:
4014 # All is well
4015 pass
4016 elif addResponses[ i ] == main.FALSE:
4017 # Already in set, probably fine
4018 pass
4019 elif addResponses[ i ] == main.ERROR:
4020 # Error in execution
4021 addAllResults = main.FALSE
4022 else:
4023 # unexpected result
4024 addAllResults = main.FALSE
4025 if addAllResults != main.TRUE:
4026 main.log.error( "Error executing set addAll" )
4027
4028 # Check if set is still correct
4029 size = len( onosSet )
4030 getResponses = []
4031 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004032 for i in range( main.numCtrls ):
4033 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07004034 name="setTestGet-" + str( i ),
4035 args=[ onosSetName ] )
4036 threads.append( t )
4037 t.start()
4038 for t in threads:
4039 t.join()
4040 getResponses.append( t.result )
4041 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004042 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004043 if isinstance( getResponses[ i ], list):
4044 current = set( getResponses[ i ] )
4045 if len( current ) == len( getResponses[ i ] ):
4046 # no repeats
4047 if onosSet != current:
4048 main.log.error( "ONOS" + str( i + 1 ) +
4049 " has incorrect view" +
4050 " of set " + onosSetName + ":\n" +
4051 str( getResponses[ i ] ) )
4052 main.log.debug( "Expected: " + str( onosSet ) )
4053 main.log.debug( "Actual: " + str( current ) )
4054 getResults = main.FALSE
4055 else:
4056 # error, set is not a set
4057 main.log.error( "ONOS" + str( i + 1 ) +
4058 " has repeat elements in" +
4059 " set " + onosSetName + ":\n" +
4060 str( getResponses[ i ] ) )
4061 getResults = main.FALSE
4062 elif getResponses[ i ] == main.ERROR:
4063 getResults = main.FALSE
4064 sizeResponses = []
4065 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004066 for i in range( main.numCtrls ):
4067 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07004068 name="setTestSize-" + str( i ),
4069 args=[ onosSetName ] )
4070 threads.append( t )
4071 t.start()
4072 for t in threads:
4073 t.join()
4074 sizeResponses.append( t.result )
4075 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004076 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004077 if size != sizeResponses[ i ]:
4078 sizeResults = main.FALSE
4079 main.log.error( "ONOS" + str( i + 1 ) +
4080 " expected a size of " + str( size ) +
4081 " for set " + onosSetName +
4082 " but got " + str( sizeResponses[ i ] ) )
4083 addAllResults = addAllResults and getResults and sizeResults
4084 utilities.assert_equals( expect=main.TRUE,
4085 actual=addAllResults,
4086 onpass="Set addAll correct",
4087 onfail="Set addAll was incorrect" )
4088
4089 main.step( "Distributed Set clear()" )
4090 onosSet.clear()
4091 clearResponses = []
4092 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004093 for i in range( main.numCtrls ):
4094 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall5cf14d52015-07-16 12:15:19 -07004095 name="setTestClear-" + str( i ),
4096 args=[ onosSetName, " "], # Values doesn't matter
4097 kwargs={ "clear": True } )
4098 threads.append( t )
4099 t.start()
4100 for t in threads:
4101 t.join()
4102 clearResponses.append( t.result )
4103
4104 # main.TRUE = successfully changed the set
4105 # main.FALSE = action resulted in no change in set
4106 # main.ERROR - Some error in executing the function
4107 clearResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004108 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004109 if clearResponses[ i ] == main.TRUE:
4110 # All is well
4111 pass
4112 elif clearResponses[ i ] == main.FALSE:
4113 # Nothing set, probably fine
4114 pass
4115 elif clearResponses[ i ] == main.ERROR:
4116 # Error in execution
4117 clearResults = main.FALSE
4118 else:
4119 # unexpected result
4120 clearResults = main.FALSE
4121 if clearResults != main.TRUE:
4122 main.log.error( "Error executing set clear" )
4123
4124 # Check if set is still correct
4125 size = len( onosSet )
4126 getResponses = []
4127 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004128 for i in range( main.numCtrls ):
4129 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07004130 name="setTestGet-" + str( i ),
4131 args=[ onosSetName ] )
4132 threads.append( t )
4133 t.start()
4134 for t in threads:
4135 t.join()
4136 getResponses.append( t.result )
4137 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004138 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004139 if isinstance( getResponses[ i ], list):
4140 current = set( getResponses[ i ] )
4141 if len( current ) == len( getResponses[ i ] ):
4142 # no repeats
4143 if onosSet != current:
4144 main.log.error( "ONOS" + str( i + 1 ) +
4145 " has incorrect view" +
4146 " of set " + onosSetName + ":\n" +
4147 str( getResponses[ i ] ) )
4148 main.log.debug( "Expected: " + str( onosSet ) )
4149 main.log.debug( "Actual: " + str( current ) )
4150 getResults = main.FALSE
4151 else:
4152 # error, set is not a set
4153 main.log.error( "ONOS" + str( i + 1 ) +
4154 " has repeat elements in" +
4155 " set " + onosSetName + ":\n" +
4156 str( getResponses[ i ] ) )
4157 getResults = main.FALSE
4158 elif getResponses[ i ] == main.ERROR:
4159 getResults = main.FALSE
4160 sizeResponses = []
4161 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004162 for i in range( main.numCtrls ):
4163 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07004164 name="setTestSize-" + str( i ),
4165 args=[ onosSetName ] )
4166 threads.append( t )
4167 t.start()
4168 for t in threads:
4169 t.join()
4170 sizeResponses.append( t.result )
4171 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004172 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004173 if size != sizeResponses[ i ]:
4174 sizeResults = main.FALSE
4175 main.log.error( "ONOS" + str( i + 1 ) +
4176 " expected a size of " + str( size ) +
4177 " for set " + onosSetName +
4178 " but got " + str( sizeResponses[ i ] ) )
4179 clearResults = clearResults and getResults and sizeResults
4180 utilities.assert_equals( expect=main.TRUE,
4181 actual=clearResults,
4182 onpass="Set clear correct",
4183 onfail="Set clear was incorrect" )
4184
4185 main.step( "Distributed Set addAll()" )
4186 onosSet.update( addAllValue.split() )
4187 addResponses = []
4188 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004189 for i in range( main.numCtrls ):
4190 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall5cf14d52015-07-16 12:15:19 -07004191 name="setTestAddAll-" + str( i ),
4192 args=[ onosSetName, addAllValue ] )
4193 threads.append( t )
4194 t.start()
4195 for t in threads:
4196 t.join()
4197 addResponses.append( t.result )
4198
4199 # main.TRUE = successfully changed the set
4200 # main.FALSE = action resulted in no change in set
4201 # main.ERROR - Some error in executing the function
4202 addAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004203 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004204 if addResponses[ i ] == main.TRUE:
4205 # All is well
4206 pass
4207 elif addResponses[ i ] == main.FALSE:
4208 # Already in set, probably fine
4209 pass
4210 elif addResponses[ i ] == main.ERROR:
4211 # Error in execution
4212 addAllResults = main.FALSE
4213 else:
4214 # unexpected result
4215 addAllResults = main.FALSE
4216 if addAllResults != main.TRUE:
4217 main.log.error( "Error executing set addAll" )
4218
4219 # Check if set is still correct
4220 size = len( onosSet )
4221 getResponses = []
4222 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004223 for i in range( main.numCtrls ):
4224 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07004225 name="setTestGet-" + str( i ),
4226 args=[ onosSetName ] )
4227 threads.append( t )
4228 t.start()
4229 for t in threads:
4230 t.join()
4231 getResponses.append( t.result )
4232 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004233 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004234 if isinstance( getResponses[ i ], list):
4235 current = set( getResponses[ i ] )
4236 if len( current ) == len( getResponses[ i ] ):
4237 # no repeats
4238 if onosSet != current:
4239 main.log.error( "ONOS" + str( i + 1 ) +
4240 " has incorrect view" +
4241 " of set " + onosSetName + ":\n" +
4242 str( getResponses[ i ] ) )
4243 main.log.debug( "Expected: " + str( onosSet ) )
4244 main.log.debug( "Actual: " + str( current ) )
4245 getResults = main.FALSE
4246 else:
4247 # error, set is not a set
4248 main.log.error( "ONOS" + str( i + 1 ) +
4249 " has repeat elements in" +
4250 " set " + onosSetName + ":\n" +
4251 str( getResponses[ i ] ) )
4252 getResults = main.FALSE
4253 elif getResponses[ i ] == main.ERROR:
4254 getResults = main.FALSE
4255 sizeResponses = []
4256 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004257 for i in range( main.numCtrls ):
4258 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07004259 name="setTestSize-" + str( i ),
4260 args=[ onosSetName ] )
4261 threads.append( t )
4262 t.start()
4263 for t in threads:
4264 t.join()
4265 sizeResponses.append( t.result )
4266 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004267 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004268 if size != sizeResponses[ i ]:
4269 sizeResults = main.FALSE
4270 main.log.error( "ONOS" + str( i + 1 ) +
4271 " expected a size of " + str( size ) +
4272 " for set " + onosSetName +
4273 " but got " + str( sizeResponses[ i ] ) )
4274 addAllResults = addAllResults and getResults and sizeResults
4275 utilities.assert_equals( expect=main.TRUE,
4276 actual=addAllResults,
4277 onpass="Set addAll correct",
4278 onfail="Set addAll was incorrect" )
4279
4280 main.step( "Distributed Set retain()" )
4281 onosSet.intersection_update( retainValue.split() )
4282 retainResponses = []
4283 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004284 for i in range( main.numCtrls ):
4285 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall5cf14d52015-07-16 12:15:19 -07004286 name="setTestRetain-" + str( i ),
4287 args=[ onosSetName, retainValue ],
4288 kwargs={ "retain": True } )
4289 threads.append( t )
4290 t.start()
4291 for t in threads:
4292 t.join()
4293 retainResponses.append( t.result )
4294
4295 # main.TRUE = successfully changed the set
4296 # main.FALSE = action resulted in no change in set
4297 # main.ERROR - Some error in executing the function
4298 retainResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004299 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004300 if retainResponses[ i ] == main.TRUE:
4301 # All is well
4302 pass
4303 elif retainResponses[ i ] == main.FALSE:
4304 # Already in set, probably fine
4305 pass
4306 elif retainResponses[ i ] == main.ERROR:
4307 # Error in execution
4308 retainResults = main.FALSE
4309 else:
4310 # unexpected result
4311 retainResults = main.FALSE
4312 if retainResults != main.TRUE:
4313 main.log.error( "Error executing set retain" )
4314
4315 # Check if set is still correct
4316 size = len( onosSet )
4317 getResponses = []
4318 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004319 for i in range( main.numCtrls ):
4320 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07004321 name="setTestGet-" + str( i ),
4322 args=[ onosSetName ] )
4323 threads.append( t )
4324 t.start()
4325 for t in threads:
4326 t.join()
4327 getResponses.append( t.result )
4328 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004329 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004330 if isinstance( getResponses[ i ], list):
4331 current = set( getResponses[ i ] )
4332 if len( current ) == len( getResponses[ i ] ):
4333 # no repeats
4334 if onosSet != current:
4335 main.log.error( "ONOS" + str( i + 1 ) +
4336 " has incorrect view" +
4337 " of set " + onosSetName + ":\n" +
4338 str( getResponses[ i ] ) )
4339 main.log.debug( "Expected: " + str( onosSet ) )
4340 main.log.debug( "Actual: " + str( current ) )
4341 getResults = main.FALSE
4342 else:
4343 # error, set is not a set
4344 main.log.error( "ONOS" + str( i + 1 ) +
4345 " has repeat elements in" +
4346 " set " + onosSetName + ":\n" +
4347 str( getResponses[ i ] ) )
4348 getResults = main.FALSE
4349 elif getResponses[ i ] == main.ERROR:
4350 getResults = main.FALSE
4351 sizeResponses = []
4352 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004353 for i in range( main.numCtrls ):
4354 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07004355 name="setTestSize-" + str( i ),
4356 args=[ onosSetName ] )
4357 threads.append( t )
4358 t.start()
4359 for t in threads:
4360 t.join()
4361 sizeResponses.append( t.result )
4362 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004363 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004364 if size != sizeResponses[ i ]:
4365 sizeResults = main.FALSE
4366 main.log.error( "ONOS" + str( i + 1 ) +
4367 " expected a size of " +
4368 str( size ) + " for set " + onosSetName +
4369 " but got " + str( sizeResponses[ i ] ) )
4370 retainResults = retainResults and getResults and sizeResults
4371 utilities.assert_equals( expect=main.TRUE,
4372 actual=retainResults,
4373 onpass="Set retain correct",
4374 onfail="Set retain was incorrect" )
4375
Jon Hall2a5002c2015-08-21 16:49:11 -07004376 # Transactional maps
4377 main.step( "Partitioned Transactional maps put" )
4378 tMapValue = "Testing"
4379 numKeys = 100
4380 putResult = True
4381 putResponses = main.CLIs[ 0 ].transactionalMapPut( numKeys, tMapValue )
4382 if len( putResponses ) == 100:
4383 for i in putResponses:
4384 if putResponses[ i ][ 'value' ] != tMapValue:
4385 putResult = False
4386 else:
4387 putResult = False
4388 if not putResult:
4389 main.log.debug( "Put response values: " + str( putResponses ) )
4390 utilities.assert_equals( expect=True,
4391 actual=putResult,
4392 onpass="Partitioned Transactional Map put successful",
4393 onfail="Partitioned Transactional Map put values are incorrect" )
4394
4395 main.step( "Partitioned Transactional maps get" )
4396 getCheck = True
4397 for n in range( 1, numKeys + 1 ):
4398 getResponses = []
4399 threads = []
4400 valueCheck = True
4401 for i in range( main.numCtrls ):
4402 t = main.Thread( target=main.CLIs[i].transactionalMapGet,
4403 name="TMap-get-" + str( i ),
4404 args=[ "Key" + str ( n ) ] )
4405 threads.append( t )
4406 t.start()
4407 for t in threads:
4408 t.join()
4409 getResponses.append( t.result )
4410 for node in getResponses:
4411 if node != tMapValue:
4412 valueCheck = False
4413 if not valueCheck:
4414 main.log.warn( "Values for key 'Key" + str( n ) + "' do not match:" )
4415 main.log.warn( getResponses )
4416 getCheck = getCheck and valueCheck
4417 utilities.assert_equals( expect=True,
4418 actual=getCheck,
4419 onpass="Partitioned Transactional Map get values were correct",
4420 onfail="Partitioned Transactional Map values incorrect" )
4421
4422 main.step( "In-memory Transactional maps put" )
4423 tMapValue = "Testing"
4424 numKeys = 100
4425 putResult = True
4426 putResponses = main.CLIs[ 0 ].transactionalMapPut( numKeys, tMapValue, inMemory=True )
4427 if len( putResponses ) == 100:
4428 for i in putResponses:
4429 if putResponses[ i ][ 'value' ] != tMapValue:
4430 putResult = False
4431 else:
4432 putResult = False
4433 if not putResult:
4434 main.log.debug( "Put response values: " + str( putResponses ) )
4435 utilities.assert_equals( expect=True,
4436 actual=putResult,
4437 onpass="In-Memory Transactional Map put successful",
4438 onfail="In-Memory Transactional Map put values are incorrect" )
4439
4440 main.step( "In-Memory Transactional maps get" )
4441 getCheck = True
4442 for n in range( 1, numKeys + 1 ):
4443 getResponses = []
4444 threads = []
4445 valueCheck = True
4446 for i in range( main.numCtrls ):
4447 t = main.Thread( target=main.CLIs[i].transactionalMapGet,
4448 name="TMap-get-" + str( i ),
4449 args=[ "Key" + str ( n ) ],
4450 kwargs={ "inMemory": True } )
4451 threads.append( t )
4452 t.start()
4453 for t in threads:
4454 t.join()
4455 getResponses.append( t.result )
4456 for node in getResponses:
4457 if node != tMapValue:
4458 valueCheck = False
4459 if not valueCheck:
4460 main.log.warn( "Values for key 'Key" + str( n ) + "' do not match:" )
4461 main.log.warn( getResponses )
4462 getCheck = getCheck and valueCheck
4463 utilities.assert_equals( expect=True,
4464 actual=getCheck,
4465 onpass="In-Memory Transactional Map get values were correct",
4466 onfail="In-Memory Transactional Map values incorrect" )