blob: 7de57b59f13d7b90c8caf20e3e95f6b48ea745f6 [file] [log] [blame]
Jon Hall5cf14d52015-07-16 12:15:19 -07001"""
2Description: This test is to determine if the HA test setup is
3 working correctly. There are no failures so this test should
4 have a 100% pass rate
5
6List of test cases:
7CASE1: Compile ONOS and push it to the test machines
8CASE2: Assign devices to controllers
9CASE21: Assign mastership to controllers
10CASE3: Assign intents
11CASE4: Ping across added host intents
12CASE5: Reading state of ONOS
13CASE6: The Failure case. Since this is the Sanity test, we do nothing.
14CASE7: Check state after control plane failure
15CASE8: Compare topo
16CASE9: Link s3-s28 down
17CASE10: Link s3-s28 up
18CASE11: Switch down
19CASE12: Switch up
20CASE13: Clean up
21CASE14: start election app on all onos nodes
22CASE15: Check that Leadership Election is still functional
23CASE16: Install Distributed Primitives app
24CASE17: Check for basic functionality with distributed primitives
25"""
26
27
28class HAsanity:
29
30 def __init__( self ):
31 self.default = ''
32
33 def CASE1( self, main ):
34 """
35 CASE1 is to compile ONOS and push it to the test machines
36
37 Startup sequence:
38 cell <name>
39 onos-verify-cell
40 NOTE: temporary - onos-remove-raft-logs
41 onos-uninstall
42 start mininet
43 git pull
44 mvn clean install
45 onos-package
46 onos-install -f
47 onos-wait-for-start
48 start cli sessions
49 start tcpdump
50 """
Jon Halle1a3b752015-07-22 13:02:46 -070051 import imp
Jon Hall5cf14d52015-07-16 12:15:19 -070052 main.log.info( "ONOS HA Sanity test - initialization" )
53 main.case( "Setting up test environment" )
Jon Hall783bbf92015-07-23 14:33:19 -070054 main.caseExplanation = "Setup the test environment including " +\
Jon Hall5cf14d52015-07-16 12:15:19 -070055 "installing ONOS, starting Mininet and ONOS" +\
56 "cli sessions."
57 # TODO: save all the timers and output them for plotting
58
59 # load some variables from the params file
60 PULLCODE = False
61 if main.params[ 'Git' ] == 'True':
62 PULLCODE = True
63 gitBranch = main.params[ 'branch' ]
64 cellName = main.params[ 'ENV' ][ 'cellName' ]
65
Jon Halle1a3b752015-07-22 13:02:46 -070066 main.numCtrls = int( main.params[ 'num_controllers' ] )
Jon Hall5cf14d52015-07-16 12:15:19 -070067 if main.ONOSbench.maxNodes:
Jon Halle1a3b752015-07-22 13:02:46 -070068 if main.ONOSbench.maxNodes < main.numCtrls:
69 main.numCtrls = int( main.ONOSbench.maxNodes )
Jon Hall5cf14d52015-07-16 12:15:19 -070070 # TODO: refactor how to get onos port, maybe put into component tag?
Jon Halle1a3b752015-07-22 13:02:46 -070071 # 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
80 # FIXME: just get controller port from params?
81 # TODO: do we really need all these?
82 ONOS1Port = main.params[ 'CTRL' ][ 'port1' ]
83 ONOS2Port = main.params[ 'CTRL' ][ 'port2' ]
84 ONOS3Port = main.params[ 'CTRL' ][ 'port3' ]
85 ONOS4Port = main.params[ 'CTRL' ][ 'port4' ]
86 ONOS5Port = main.params[ 'CTRL' ][ 'port5' ]
87 ONOS6Port = main.params[ 'CTRL' ][ 'port6' ]
88 ONOS7Port = main.params[ 'CTRL' ][ 'port7' ]
89
Jon Halle1a3b752015-07-22 13:02:46 -070090 try:
91 fileName = "Counters"
92 path = main.params[ 'imports' ][ 'path' ]
93 main.Counters = imp.load_source( fileName,
94 path + fileName + ".py" )
95 except Exception as e:
96 main.log.exception( e )
97 main.cleanup()
98 main.exit()
99
100 main.CLIs = []
101 main.nodes = []
Jon Hall5cf14d52015-07-16 12:15:19 -0700102 ipList = []
Jon Halle1a3b752015-07-22 13:02:46 -0700103 for i in range( 1, main.numCtrls + 1 ):
104 try:
105 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
106 main.nodes.append( getattr( main, 'ONOS' + str( i ) ) )
107 ipList.append( main.nodes[ -1 ].ip_address )
108 except AttributeError:
109 break
Jon Hall5cf14d52015-07-16 12:15:19 -0700110
111 main.step( "Create cell file" )
112 cellAppString = main.params[ 'ENV' ][ 'appString' ]
113 main.ONOSbench.createCellFile( main.ONOSbench.ip_address, cellName,
114 main.Mininet1.ip_address,
115 cellAppString, ipList )
116 main.step( "Applying cell variable to environment" )
117 cellResult = main.ONOSbench.setCell( cellName )
118 verifyResult = main.ONOSbench.verifyCell()
119
120 # FIXME:this is short term fix
121 main.log.info( "Removing raft logs" )
122 main.ONOSbench.onosRemoveRaftLogs()
123
124 main.log.info( "Uninstalling ONOS" )
Jon Halle1a3b752015-07-22 13:02:46 -0700125 for node in main.nodes:
Jon Hall5cf14d52015-07-16 12:15:19 -0700126 main.ONOSbench.onosUninstall( node.ip_address )
127
128 # Make sure ONOS is DEAD
129 main.log.info( "Killing any ONOS processes" )
130 killResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -0700131 for node in main.nodes:
Jon Hall5cf14d52015-07-16 12:15:19 -0700132 killed = main.ONOSbench.onosKill( node.ip_address )
133 killResults = killResults and killed
134
135 cleanInstallResult = main.TRUE
136 gitPullResult = main.TRUE
137
138 main.step( "Starting Mininet" )
139 # scp topo file to mininet
140 # TODO: move to params?
141 topoName = "obelisk.py"
142 filePath = main.ONOSbench.home + "/tools/test/topos/"
kelvin-onlabd9e23de2015-08-06 10:34:44 -0700143 main.ONOSbench.scp( main.Mininet1,
144 filePath + topoName,
145 main.Mininet1.home,
146 direction="to" )
Jon Hall5cf14d52015-07-16 12:15:19 -0700147 mnResult = main.Mininet1.startNet( )
148 utilities.assert_equals( expect=main.TRUE, actual=mnResult,
149 onpass="Mininet Started",
150 onfail="Error starting Mininet" )
151
152 main.step( "Git checkout and pull " + gitBranch )
153 if PULLCODE:
154 main.ONOSbench.gitCheckout( gitBranch )
155 gitPullResult = main.ONOSbench.gitPull()
156 # values of 1 or 3 are good
157 utilities.assert_lesser( expect=0, actual=gitPullResult,
158 onpass="Git pull successful",
159 onfail="Git pull failed" )
160 main.ONOSbench.getVersion( report=True )
161
162 main.step( "Using mvn clean install" )
163 cleanInstallResult = main.TRUE
164 if PULLCODE and gitPullResult == main.TRUE:
165 cleanInstallResult = main.ONOSbench.cleanInstall()
166 else:
167 main.log.warn( "Did not pull new code so skipping mvn " +
168 "clean install" )
169 utilities.assert_equals( expect=main.TRUE,
170 actual=cleanInstallResult,
171 onpass="MCI successful",
172 onfail="MCI failed" )
173 # GRAPHS
174 # NOTE: important params here:
175 # job = name of Jenkins job
176 # Plot Name = Plot-HA, only can be used if multiple plots
177 # index = The number of the graph under plot name
178 job = "HAsanity"
179 plotName = "Plot-HA"
180 graphs = '<ac:structured-macro ac:name="html">\n'
181 graphs += '<ac:plain-text-body><![CDATA[\n'
182 graphs += '<iframe src="https://onos-jenkins.onlab.us/job/' + job +\
183 '/plot/' + plotName + '/getPlot?index=0' +\
184 '&width=500&height=300"' +\
185 'noborder="0" width="500" height="300" scrolling="yes" ' +\
186 'seamless="seamless"></iframe>\n'
187 graphs += ']]></ac:plain-text-body>\n'
188 graphs += '</ac:structured-macro>\n'
189 main.log.wiki(graphs)
190
191 main.step( "Creating ONOS package" )
192 packageResult = main.ONOSbench.onosPackage()
193 utilities.assert_equals( expect=main.TRUE, actual=packageResult,
194 onpass="ONOS package successful",
195 onfail="ONOS package failed" )
196
197 main.step( "Installing ONOS package" )
198 onosInstallResult = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -0700199 for node in main.nodes:
Jon Hall5cf14d52015-07-16 12:15:19 -0700200 tmpResult = main.ONOSbench.onosInstall( options="-f",
201 node=node.ip_address )
202 onosInstallResult = onosInstallResult and tmpResult
203 utilities.assert_equals( expect=main.TRUE, actual=onosInstallResult,
204 onpass="ONOS install successful",
205 onfail="ONOS install failed" )
206
207 main.step( "Checking if ONOS is up yet" )
208 for i in range( 2 ):
209 onosIsupResult = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -0700210 for node in main.nodes:
Jon Hall5cf14d52015-07-16 12:15:19 -0700211 started = main.ONOSbench.isup( node.ip_address )
212 if not started:
213 main.log.error( node.name + " didn't start!" )
214 main.ONOSbench.onosStop( node.ip_address )
215 main.ONOSbench.onosStart( node.ip_address )
216 onosIsupResult = onosIsupResult and started
217 if onosIsupResult == main.TRUE:
218 break
219 utilities.assert_equals( expect=main.TRUE, actual=onosIsupResult,
220 onpass="ONOS startup successful",
221 onfail="ONOS startup failed" )
222
223 main.log.step( "Starting ONOS CLI sessions" )
224 cliResults = main.TRUE
225 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -0700226 for i in range( main.numCtrls ):
227 t = main.Thread( target=main.CLIs[i].startOnosCli,
Jon Hall5cf14d52015-07-16 12:15:19 -0700228 name="startOnosCli-" + str( i ),
Jon Halle1a3b752015-07-22 13:02:46 -0700229 args=[main.nodes[i].ip_address] )
Jon Hall5cf14d52015-07-16 12:15:19 -0700230 threads.append( t )
231 t.start()
232
233 for t in threads:
234 t.join()
235 cliResults = cliResults and t.result
236 utilities.assert_equals( expect=main.TRUE, actual=cliResults,
237 onpass="ONOS cli startup successful",
238 onfail="ONOS cli startup failed" )
239
240 if main.params[ 'tcpdump' ].lower() == "true":
241 main.step( "Start Packet Capture MN" )
242 main.Mininet2.startTcpdump(
243 str( main.params[ 'MNtcpdump' ][ 'folder' ] ) + str( main.TEST )
244 + "-MN.pcap",
245 intf=main.params[ 'MNtcpdump' ][ 'intf' ],
246 port=main.params[ 'MNtcpdump' ][ 'port' ] )
247
248 main.step( "App Ids check" )
249 appCheck = main.TRUE
250 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -0700251 for i in range( main.numCtrls ):
252 t = main.Thread( target=main.CLIs[i].appToIDCheck,
Jon Hall5cf14d52015-07-16 12:15:19 -0700253 name="appToIDCheck-" + str( i ),
254 args=[] )
255 threads.append( t )
256 t.start()
257
258 for t in threads:
259 t.join()
260 appCheck = appCheck and t.result
261 if appCheck != main.TRUE:
Jon Halle1a3b752015-07-22 13:02:46 -0700262 main.log.warn( main.CLIs[0].apps() )
263 main.log.warn( main.CLIs[0].appIDs() )
Jon Hall5cf14d52015-07-16 12:15:19 -0700264 utilities.assert_equals( expect=main.TRUE, actual=appCheck,
265 onpass="App Ids seem to be correct",
266 onfail="Something is wrong with app Ids" )
267
268 if cliResults == main.FALSE:
269 main.log.error( "Failed to start ONOS, stopping test" )
270 main.cleanup()
271 main.exit()
272
273 def CASE2( self, main ):
274 """
275 Assign devices to controllers
276 """
277 import re
Jon Halle1a3b752015-07-22 13:02:46 -0700278 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -0700279 assert main, "main not defined"
280 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -0700281 assert main.CLIs, "main.CLIs not defined"
282 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -0700283 assert ONOS1Port, "ONOS1Port not defined"
284 assert ONOS2Port, "ONOS2Port not defined"
285 assert ONOS3Port, "ONOS3Port not defined"
286 assert ONOS4Port, "ONOS4Port not defined"
287 assert ONOS5Port, "ONOS5Port not defined"
288 assert ONOS6Port, "ONOS6Port not defined"
289 assert ONOS7Port, "ONOS7Port not defined"
290
291 main.case( "Assigning devices to controllers" )
Jon Hall783bbf92015-07-23 14:33:19 -0700292 main.caseExplanation = "Assign switches to ONOS using 'ovs-vsctl' " +\
Jon Hall5cf14d52015-07-16 12:15:19 -0700293 "and check that an ONOS node becomes the " +\
294 "master of the device."
295 main.step( "Assign switches to controllers" )
296
297 ipList = []
Jon Halle1a3b752015-07-22 13:02:46 -0700298 for i in range( main.numCtrls ):
299 ipList.append( main.nodes[ i ].ip_address )
Jon Hall5cf14d52015-07-16 12:15:19 -0700300 swList = []
301 for i in range( 1, 29 ):
302 swList.append( "s" + str( i ) )
303 main.Mininet1.assignSwController( sw=swList, ip=ipList )
304
305 mastershipCheck = main.TRUE
306 for i in range( 1, 29 ):
307 response = main.Mininet1.getSwController( "s" + str( i ) )
308 try:
309 main.log.info( str( response ) )
310 except Exception:
311 main.log.info( repr( response ) )
Jon Halle1a3b752015-07-22 13:02:46 -0700312 for node in main.nodes:
Jon Hall5cf14d52015-07-16 12:15:19 -0700313 if re.search( "tcp:" + node.ip_address, response ):
314 mastershipCheck = mastershipCheck and main.TRUE
315 else:
316 main.log.error( "Error, node " + node.ip_address + " is " +
317 "not in the list of controllers s" +
318 str( i ) + " is connecting to." )
319 mastershipCheck = main.FALSE
320 utilities.assert_equals(
321 expect=main.TRUE,
322 actual=mastershipCheck,
323 onpass="Switch mastership assigned correctly",
324 onfail="Switches not assigned correctly to controllers" )
325
326 def CASE21( self, main ):
327 """
328 Assign mastership to controllers
329 """
Jon Hall5cf14d52015-07-16 12:15:19 -0700330 import time
Jon Halle1a3b752015-07-22 13:02:46 -0700331 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -0700332 assert main, "main not defined"
333 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -0700334 assert main.CLIs, "main.CLIs not defined"
335 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -0700336 assert ONOS1Port, "ONOS1Port not defined"
337 assert ONOS2Port, "ONOS2Port not defined"
338 assert ONOS3Port, "ONOS3Port not defined"
339 assert ONOS4Port, "ONOS4Port not defined"
340 assert ONOS5Port, "ONOS5Port not defined"
341 assert ONOS6Port, "ONOS6Port not defined"
342 assert ONOS7Port, "ONOS7Port not defined"
343
344 main.case( "Assigning Controller roles for switches" )
Jon Hall783bbf92015-07-23 14:33:19 -0700345 main.caseExplanation = "Check that ONOS is connected to each " +\
Jon Hall5cf14d52015-07-16 12:15:19 -0700346 "device. Then manually assign" +\
347 " mastership to specific ONOS nodes using" +\
348 " 'device-role'"
349 main.step( "Assign mastership of switches to specific controllers" )
350 # Manually assign mastership to the controller we want
351 roleCall = main.TRUE
352
353 ipList = [ ]
354 deviceList = []
355 try:
356 # Assign mastership to specific controllers. This assignment was
357 # determined for a 7 node cluser, but will work with any sized
358 # cluster
359 for i in range( 1, 29 ): # switches 1 through 28
360 # set up correct variables:
361 if i == 1:
362 c = 0
Jon Halle1a3b752015-07-22 13:02:46 -0700363 ip = main.nodes[ c ].ip_address # ONOS1
Jon Hall5cf14d52015-07-16 12:15:19 -0700364 deviceId = main.ONOScli1.getDevice( "1000" ).get( 'id' )
365 elif i == 2:
Jon Halle1a3b752015-07-22 13:02:46 -0700366 c = 1 % main.numCtrls
367 ip = main.nodes[ c ].ip_address # ONOS2
Jon Hall5cf14d52015-07-16 12:15:19 -0700368 deviceId = main.ONOScli1.getDevice( "2000" ).get( 'id' )
369 elif i == 3:
Jon Halle1a3b752015-07-22 13:02:46 -0700370 c = 1 % main.numCtrls
371 ip = main.nodes[ c ].ip_address # ONOS2
Jon Hall5cf14d52015-07-16 12:15:19 -0700372 deviceId = main.ONOScli1.getDevice( "3000" ).get( 'id' )
373 elif i == 4:
Jon Halle1a3b752015-07-22 13:02:46 -0700374 c = 3 % main.numCtrls
375 ip = main.nodes[ c ].ip_address # ONOS4
Jon Hall5cf14d52015-07-16 12:15:19 -0700376 deviceId = main.ONOScli1.getDevice( "3004" ).get( 'id' )
377 elif i == 5:
Jon Halle1a3b752015-07-22 13:02:46 -0700378 c = 2 % main.numCtrls
379 ip = main.nodes[ c ].ip_address # ONOS3
Jon Hall5cf14d52015-07-16 12:15:19 -0700380 deviceId = main.ONOScli1.getDevice( "5000" ).get( 'id' )
381 elif i == 6:
Jon Halle1a3b752015-07-22 13:02:46 -0700382 c = 2 % main.numCtrls
383 ip = main.nodes[ c ].ip_address # ONOS3
Jon Hall5cf14d52015-07-16 12:15:19 -0700384 deviceId = main.ONOScli1.getDevice( "6000" ).get( 'id' )
385 elif i == 7:
Jon Halle1a3b752015-07-22 13:02:46 -0700386 c = 5 % main.numCtrls
387 ip = main.nodes[ c ].ip_address # ONOS6
Jon Hall5cf14d52015-07-16 12:15:19 -0700388 deviceId = main.ONOScli1.getDevice( "6007" ).get( 'id' )
389 elif i >= 8 and i <= 17:
Jon Halle1a3b752015-07-22 13:02:46 -0700390 c = 4 % main.numCtrls
391 ip = main.nodes[ c ].ip_address # ONOS5
Jon Hall5cf14d52015-07-16 12:15:19 -0700392 dpid = '3' + str( i ).zfill( 3 )
393 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
394 elif i >= 18 and i <= 27:
Jon Halle1a3b752015-07-22 13:02:46 -0700395 c = 6 % main.numCtrls
396 ip = main.nodes[ c ].ip_address # ONOS7
Jon Hall5cf14d52015-07-16 12:15:19 -0700397 dpid = '6' + str( i ).zfill( 3 )
398 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
399 elif i == 28:
400 c = 0
Jon Halle1a3b752015-07-22 13:02:46 -0700401 ip = main.nodes[ c ].ip_address # ONOS1
Jon Hall5cf14d52015-07-16 12:15:19 -0700402 deviceId = main.ONOScli1.getDevice( "2800" ).get( 'id' )
403 else:
404 main.log.error( "You didn't write an else statement for " +
405 "switch s" + str( i ) )
406 roleCall = main.FALSE
407 # Assign switch
408 assert deviceId, "No device id for s" + str( i ) + " in ONOS"
409 # TODO: make this controller dynamic
410 roleCall = roleCall and main.ONOScli1.deviceRole( deviceId,
411 ip )
412 ipList.append( ip )
413 deviceList.append( deviceId )
414 except ( AttributeError, AssertionError ):
415 main.log.exception( "Something is wrong with ONOS device view" )
416 main.log.info( main.ONOScli1.devices() )
417 utilities.assert_equals(
418 expect=main.TRUE,
419 actual=roleCall,
420 onpass="Re-assigned switch mastership to designated controller",
421 onfail="Something wrong with deviceRole calls" )
422
423 main.step( "Check mastership was correctly assigned" )
424 roleCheck = main.TRUE
425 # NOTE: This is due to the fact that device mastership change is not
426 # atomic and is actually a multi step process
427 time.sleep( 5 )
428 for i in range( len( ipList ) ):
429 ip = ipList[i]
430 deviceId = deviceList[i]
431 # Check assignment
432 master = main.ONOScli1.getRole( deviceId ).get( 'master' )
433 if ip in master:
434 roleCheck = roleCheck and main.TRUE
435 else:
436 roleCheck = roleCheck and main.FALSE
437 main.log.error( "Error, controller " + ip + " is not" +
438 " master " + "of device " +
439 str( deviceId ) + ". Master is " +
440 repr( master ) + "." )
441 utilities.assert_equals(
442 expect=main.TRUE,
443 actual=roleCheck,
444 onpass="Switches were successfully reassigned to designated " +
445 "controller",
446 onfail="Switches were not successfully reassigned" )
447
448 def CASE3( self, main ):
449 """
450 Assign intents
451 """
452 import time
453 import json
Jon Halle1a3b752015-07-22 13:02:46 -0700454 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -0700455 assert main, "main not defined"
456 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -0700457 assert main.CLIs, "main.CLIs not defined"
458 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -0700459 main.case( "Adding host Intents" )
Jon Hall783bbf92015-07-23 14:33:19 -0700460 main.caseExplanation = "Discover hosts by using pingall then " +\
Jon Hall5cf14d52015-07-16 12:15:19 -0700461 "assign predetermined host-to-host intents." +\
462 " After installation, check that the intent" +\
463 " is distributed to all nodes and the state" +\
464 " is INSTALLED"
465
466 # install onos-app-fwd
467 main.step( "Install reactive forwarding app" )
Jon Halle1a3b752015-07-22 13:02:46 -0700468 installResults = main.CLIs[0].activateApp( "org.onosproject.fwd" )
Jon Hall5cf14d52015-07-16 12:15:19 -0700469 utilities.assert_equals( expect=main.TRUE, actual=installResults,
470 onpass="Install fwd successful",
471 onfail="Install fwd failed" )
472
473 main.step( "Check app ids" )
474 appCheck = main.TRUE
475 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -0700476 for i in range( main.numCtrls ):
477 t = main.Thread( target=main.CLIs[i].appToIDCheck,
Jon Hall5cf14d52015-07-16 12:15:19 -0700478 name="appToIDCheck-" + str( i ),
479 args=[] )
480 threads.append( t )
481 t.start()
482
483 for t in threads:
484 t.join()
485 appCheck = appCheck and t.result
486 if appCheck != main.TRUE:
Jon Halle1a3b752015-07-22 13:02:46 -0700487 main.log.warn( main.CLIs[0].apps() )
488 main.log.warn( main.CLIs[0].appIDs() )
Jon Hall5cf14d52015-07-16 12:15:19 -0700489 utilities.assert_equals( expect=main.TRUE, actual=appCheck,
490 onpass="App Ids seem to be correct",
491 onfail="Something is wrong with app Ids" )
492
493 main.step( "Discovering Hosts( Via pingall for now )" )
494 # FIXME: Once we have a host discovery mechanism, use that instead
495 # REACTIVE FWD test
496 pingResult = main.FALSE
Jon Hall96091e62015-09-21 17:34:17 -0700497 passMsg = "Reactive Pingall test passed"
498 time1 = time.time()
499 pingResult = main.Mininet1.pingall()
500 time2 = time.time()
501 if not pingResult:
502 main.log.warn("First pingall failed. Trying again...")
Jon Hall5cf14d52015-07-16 12:15:19 -0700503 pingResult = main.Mininet1.pingall()
Jon Hall96091e62015-09-21 17:34:17 -0700504 passMsg += " on the second try"
505 utilities.assert_equals(
506 expect=main.TRUE,
507 actual=pingResult,
508 onpass= passMsg,
509 onfail="Reactive Pingall failed, " +
510 "one or more ping pairs failed" )
511 main.log.info( "Time for pingall: %2f seconds" %
512 ( time2 - time1 ) )
Jon Hall5cf14d52015-07-16 12:15:19 -0700513 # timeout for fwd flows
514 time.sleep( 11 )
515 # uninstall onos-app-fwd
516 main.step( "Uninstall reactive forwarding app" )
Jon Halle1a3b752015-07-22 13:02:46 -0700517 uninstallResult = main.CLIs[0].deactivateApp( "org.onosproject.fwd" )
Jon Hall5cf14d52015-07-16 12:15:19 -0700518 utilities.assert_equals( expect=main.TRUE, actual=uninstallResult,
519 onpass="Uninstall fwd successful",
520 onfail="Uninstall fwd failed" )
Jon Hall5cf14d52015-07-16 12:15:19 -0700521
522 main.step( "Check app ids" )
523 threads = []
524 appCheck2 = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -0700525 for i in range( main.numCtrls ):
526 t = main.Thread( target=main.CLIs[i].appToIDCheck,
Jon Hall5cf14d52015-07-16 12:15:19 -0700527 name="appToIDCheck-" + str( i ),
528 args=[] )
529 threads.append( t )
530 t.start()
531
532 for t in threads:
533 t.join()
534 appCheck2 = appCheck2 and t.result
535 if appCheck2 != main.TRUE:
Jon Halle1a3b752015-07-22 13:02:46 -0700536 main.log.warn( main.CLIs[0].apps() )
537 main.log.warn( main.CLIs[0].appIDs() )
Jon Hall5cf14d52015-07-16 12:15:19 -0700538 utilities.assert_equals( expect=main.TRUE, actual=appCheck2,
539 onpass="App Ids seem to be correct",
540 onfail="Something is wrong with app Ids" )
541
542 main.step( "Add host intents via cli" )
543 intentIds = []
544 # TODO: move the host numbers to params
545 # Maybe look at all the paths we ping?
546 intentAddResult = True
547 hostResult = main.TRUE
548 for i in range( 8, 18 ):
549 main.log.info( "Adding host intent between h" + str( i ) +
550 " and h" + str( i + 10 ) )
551 host1 = "00:00:00:00:00:" + \
552 str( hex( i )[ 2: ] ).zfill( 2 ).upper()
553 host2 = "00:00:00:00:00:" + \
554 str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper()
555 # NOTE: getHost can return None
556 host1Dict = main.ONOScli1.getHost( host1 )
557 host2Dict = main.ONOScli1.getHost( host2 )
558 host1Id = None
559 host2Id = None
560 if host1Dict and host2Dict:
561 host1Id = host1Dict.get( 'id', None )
562 host2Id = host2Dict.get( 'id', None )
563 if host1Id and host2Id:
Jon Halle1a3b752015-07-22 13:02:46 -0700564 nodeNum = ( i % main.numCtrls )
565 tmpId = main.CLIs[ nodeNum ].addHostIntent( host1Id, host2Id )
Jon Hall5cf14d52015-07-16 12:15:19 -0700566 if tmpId:
567 main.log.info( "Added intent with id: " + tmpId )
568 intentIds.append( tmpId )
569 else:
570 main.log.error( "addHostIntent returned: " +
571 repr( tmpId ) )
572 else:
573 main.log.error( "Error, getHost() failed for h" + str( i ) +
574 " and/or h" + str( i + 10 ) )
Jon Halle1a3b752015-07-22 13:02:46 -0700575 hosts = main.CLIs[ 0 ].hosts()
Jon Hall5cf14d52015-07-16 12:15:19 -0700576 main.log.warn( "Hosts output: " )
577 try:
578 main.log.warn( json.dumps( json.loads( hosts ),
579 sort_keys=True,
580 indent=4,
581 separators=( ',', ': ' ) ) )
582 except ( ValueError, TypeError ):
583 main.log.warn( repr( hosts ) )
584 hostResult = main.FALSE
585 utilities.assert_equals( expect=main.TRUE, actual=hostResult,
586 onpass="Found a host id for each host",
587 onfail="Error looking up host ids" )
588
589 intentStart = time.time()
590 onosIds = main.ONOScli1.getAllIntentsId()
591 main.log.info( "Submitted intents: " + str( intentIds ) )
592 main.log.info( "Intents in ONOS: " + str( onosIds ) )
593 for intent in intentIds:
594 if intent in onosIds:
595 pass # intent submitted is in onos
596 else:
597 intentAddResult = False
598 if intentAddResult:
599 intentStop = time.time()
600 else:
601 intentStop = None
602 # Print the intent states
603 intents = main.ONOScli1.intents()
604 intentStates = []
605 installedCheck = True
606 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
607 count = 0
608 try:
609 for intent in json.loads( intents ):
610 state = intent.get( 'state', None )
611 if "INSTALLED" not in state:
612 installedCheck = False
613 intentId = intent.get( 'id', None )
614 intentStates.append( ( intentId, state ) )
615 except ( ValueError, TypeError ):
616 main.log.exception( "Error parsing intents" )
617 # add submitted intents not in the store
618 tmplist = [ i for i, s in intentStates ]
619 missingIntents = False
620 for i in intentIds:
621 if i not in tmplist:
622 intentStates.append( ( i, " - " ) )
623 missingIntents = True
624 intentStates.sort()
625 for i, s in intentStates:
626 count += 1
627 main.log.info( "%-6s%-15s%-15s" %
628 ( str( count ), str( i ), str( s ) ) )
629 leaders = main.ONOScli1.leaders()
630 try:
631 missing = False
632 if leaders:
633 parsedLeaders = json.loads( leaders )
634 main.log.warn( json.dumps( parsedLeaders,
635 sort_keys=True,
636 indent=4,
637 separators=( ',', ': ' ) ) )
638 # check for all intent partitions
639 topics = []
640 for i in range( 14 ):
641 topics.append( "intent-partition-" + str( i ) )
642 main.log.debug( topics )
643 ONOStopics = [ j['topic'] for j in parsedLeaders ]
644 for topic in topics:
645 if topic not in ONOStopics:
646 main.log.error( "Error: " + topic +
647 " not in leaders" )
648 missing = True
649 else:
650 main.log.error( "leaders() returned None" )
651 except ( ValueError, TypeError ):
652 main.log.exception( "Error parsing leaders" )
653 main.log.error( repr( leaders ) )
654 # Check all nodes
655 if missing:
Jon Halle1a3b752015-07-22 13:02:46 -0700656 for node in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -0700657 response = node.leaders( jsonFormat=False)
658 main.log.warn( str( node.name ) + " leaders output: \n" +
659 str( response ) )
660
661 partitions = main.ONOScli1.partitions()
662 try:
663 if partitions :
664 parsedPartitions = json.loads( partitions )
665 main.log.warn( json.dumps( parsedPartitions,
666 sort_keys=True,
667 indent=4,
668 separators=( ',', ': ' ) ) )
669 # TODO check for a leader in all paritions
670 # TODO check for consistency among nodes
671 else:
672 main.log.error( "partitions() returned None" )
673 except ( ValueError, TypeError ):
674 main.log.exception( "Error parsing partitions" )
675 main.log.error( repr( partitions ) )
676 pendingMap = main.ONOScli1.pendingMap()
677 try:
678 if pendingMap :
679 parsedPending = json.loads( pendingMap )
680 main.log.warn( json.dumps( parsedPending,
681 sort_keys=True,
682 indent=4,
683 separators=( ',', ': ' ) ) )
684 # TODO check something here?
685 else:
686 main.log.error( "pendingMap() returned None" )
687 except ( ValueError, TypeError ):
688 main.log.exception( "Error parsing pending map" )
689 main.log.error( repr( pendingMap ) )
690
691 intentAddResult = bool( intentAddResult and not missingIntents and
692 installedCheck )
693 if not intentAddResult:
694 main.log.error( "Error in pushing host intents to ONOS" )
695
696 main.step( "Intent Anti-Entropy dispersion" )
697 for i in range(100):
698 correct = True
699 main.log.info( "Submitted intents: " + str( sorted( intentIds ) ) )
Jon Halle1a3b752015-07-22 13:02:46 -0700700 for cli in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -0700701 onosIds = []
702 ids = cli.getAllIntentsId()
703 onosIds.append( ids )
704 main.log.debug( "Intents in " + cli.name + ": " +
705 str( sorted( onosIds ) ) )
706 if sorted( ids ) != sorted( intentIds ):
707 main.log.warn( "Set of intent IDs doesn't match" )
708 correct = False
709 break
710 else:
711 intents = json.loads( cli.intents() )
712 for intent in intents:
713 if intent[ 'state' ] != "INSTALLED":
714 main.log.warn( "Intent " + intent[ 'id' ] +
715 " is " + intent[ 'state' ] )
716 correct = False
717 break
718 if correct:
719 break
720 else:
721 time.sleep(1)
722 if not intentStop:
723 intentStop = time.time()
724 global gossipTime
725 gossipTime = intentStop - intentStart
726 main.log.info( "It took about " + str( gossipTime ) +
727 " seconds for all intents to appear in each node" )
Jon Hallb3ed8ed2015-10-28 16:43:55 -0700728 gossipPeriod = int( main.params['timers']['gossip'] )
729 maxGossipTime = gossipPeriod * len( main.nodes )
Jon Hall5cf14d52015-07-16 12:15:19 -0700730 utilities.assert_greater_equals(
Jon Hallb3ed8ed2015-10-28 16:43:55 -0700731 expect=maxGossipTime, actual=gossipTime,
Jon Hall5cf14d52015-07-16 12:15:19 -0700732 onpass="ECM anti-entropy for intents worked within " +
733 "expected time",
Jon Hallb3ed8ed2015-10-28 16:43:55 -0700734 onfail="Intent ECM anti-entropy took too long. " +
735 "Expected time:{}, Actual time:{}".format( maxGossipTime,
736 gossipTime ) )
737 if gossipTime <= maxGossipTime:
Jon Hall5cf14d52015-07-16 12:15:19 -0700738 intentAddResult = True
739
740 if not intentAddResult or "key" in pendingMap:
741 import time
742 installedCheck = True
743 main.log.info( "Sleeping 60 seconds to see if intents are found" )
744 time.sleep( 60 )
745 onosIds = main.ONOScli1.getAllIntentsId()
746 main.log.info( "Submitted intents: " + str( intentIds ) )
747 main.log.info( "Intents in ONOS: " + str( onosIds ) )
748 # Print the intent states
749 intents = main.ONOScli1.intents()
750 intentStates = []
751 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
752 count = 0
753 try:
754 for intent in json.loads( intents ):
755 # Iter through intents of a node
756 state = intent.get( 'state', None )
757 if "INSTALLED" not in state:
758 installedCheck = False
759 intentId = intent.get( 'id', None )
760 intentStates.append( ( intentId, state ) )
761 except ( ValueError, TypeError ):
762 main.log.exception( "Error parsing intents" )
763 # add submitted intents not in the store
764 tmplist = [ i for i, s in intentStates ]
765 for i in intentIds:
766 if i not in tmplist:
767 intentStates.append( ( i, " - " ) )
768 intentStates.sort()
769 for i, s in intentStates:
770 count += 1
771 main.log.info( "%-6s%-15s%-15s" %
772 ( str( count ), str( i ), str( s ) ) )
773 leaders = main.ONOScli1.leaders()
774 try:
775 missing = False
776 if leaders:
777 parsedLeaders = json.loads( leaders )
778 main.log.warn( json.dumps( parsedLeaders,
779 sort_keys=True,
780 indent=4,
781 separators=( ',', ': ' ) ) )
782 # check for all intent partitions
783 # check for election
784 topics = []
785 for i in range( 14 ):
786 topics.append( "intent-partition-" + str( i ) )
787 # FIXME: this should only be after we start the app
788 topics.append( "org.onosproject.election" )
789 main.log.debug( topics )
790 ONOStopics = [ j['topic'] for j in parsedLeaders ]
791 for topic in topics:
792 if topic not in ONOStopics:
793 main.log.error( "Error: " + topic +
794 " not in leaders" )
795 missing = True
796 else:
797 main.log.error( "leaders() returned None" )
798 except ( ValueError, TypeError ):
799 main.log.exception( "Error parsing leaders" )
800 main.log.error( repr( leaders ) )
801 # Check all nodes
802 if missing:
Jon Halle1a3b752015-07-22 13:02:46 -0700803 for node in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -0700804 response = node.leaders( jsonFormat=False)
805 main.log.warn( str( node.name ) + " leaders output: \n" +
806 str( response ) )
807
808 partitions = main.ONOScli1.partitions()
809 try:
810 if partitions :
811 parsedPartitions = json.loads( partitions )
812 main.log.warn( json.dumps( parsedPartitions,
813 sort_keys=True,
814 indent=4,
815 separators=( ',', ': ' ) ) )
816 # TODO check for a leader in all paritions
817 # TODO check for consistency among nodes
818 else:
819 main.log.error( "partitions() returned None" )
820 except ( ValueError, TypeError ):
821 main.log.exception( "Error parsing partitions" )
822 main.log.error( repr( partitions ) )
823 pendingMap = main.ONOScli1.pendingMap()
824 try:
825 if pendingMap :
826 parsedPending = json.loads( pendingMap )
827 main.log.warn( json.dumps( parsedPending,
828 sort_keys=True,
829 indent=4,
830 separators=( ',', ': ' ) ) )
831 # TODO check something here?
832 else:
833 main.log.error( "pendingMap() returned None" )
834 except ( ValueError, TypeError ):
835 main.log.exception( "Error parsing pending map" )
836 main.log.error( repr( pendingMap ) )
837
838 def CASE4( self, main ):
839 """
840 Ping across added host intents
841 """
842 import json
843 import time
Jon Halle1a3b752015-07-22 13:02:46 -0700844 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -0700845 assert main, "main not defined"
846 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -0700847 assert main.CLIs, "main.CLIs not defined"
848 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -0700849 main.case( "Verify connectivity by sendind traffic across Intents" )
Jon Hall783bbf92015-07-23 14:33:19 -0700850 main.caseExplanation = "Ping across added host intents to check " +\
Jon Hall5cf14d52015-07-16 12:15:19 -0700851 "functionality and check the state of " +\
852 "the intent"
853 main.step( "Ping across added host intents" )
854 PingResult = main.TRUE
855 for i in range( 8, 18 ):
856 ping = main.Mininet1.pingHost( src="h" + str( i ),
857 target="h" + str( i + 10 ) )
858 PingResult = PingResult and ping
859 if ping == main.FALSE:
860 main.log.warn( "Ping failed between h" + str( i ) +
861 " and h" + str( i + 10 ) )
862 elif ping == main.TRUE:
863 main.log.info( "Ping test passed!" )
864 # Don't set PingResult or you'd override failures
865 if PingResult == main.FALSE:
866 main.log.error(
867 "Intents have not been installed correctly, pings failed." )
868 # TODO: pretty print
869 main.log.warn( "ONOS1 intents: " )
870 try:
871 tmpIntents = main.ONOScli1.intents()
872 main.log.warn( json.dumps( json.loads( tmpIntents ),
873 sort_keys=True,
874 indent=4,
875 separators=( ',', ': ' ) ) )
876 except ( ValueError, TypeError ):
877 main.log.warn( repr( tmpIntents ) )
878 utilities.assert_equals(
879 expect=main.TRUE,
880 actual=PingResult,
881 onpass="Intents have been installed correctly and pings work",
882 onfail="Intents have not been installed correctly, pings failed." )
883
884 main.step( "Check Intent state" )
885 installedCheck = False
886 loopCount = 0
887 while not installedCheck and loopCount < 40:
888 installedCheck = True
889 # Print the intent states
890 intents = main.ONOScli1.intents()
891 intentStates = []
892 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
893 count = 0
894 # Iter through intents of a node
895 try:
896 for intent in json.loads( intents ):
897 state = intent.get( 'state', None )
898 if "INSTALLED" not in state:
899 installedCheck = False
900 intentId = intent.get( 'id', None )
901 intentStates.append( ( intentId, state ) )
902 except ( ValueError, TypeError ):
903 main.log.exception( "Error parsing intents." )
904 # Print states
905 intentStates.sort()
906 for i, s in intentStates:
907 count += 1
908 main.log.info( "%-6s%-15s%-15s" %
909 ( str( count ), str( i ), str( s ) ) )
910 if not installedCheck:
911 time.sleep( 1 )
912 loopCount += 1
913 utilities.assert_equals( expect=True, actual=installedCheck,
914 onpass="Intents are all INSTALLED",
915 onfail="Intents are not all in " +
916 "INSTALLED state" )
917
918 main.step( "Check leadership of topics" )
919 leaders = main.ONOScli1.leaders()
920 topicCheck = main.TRUE
921 try:
922 if leaders:
923 parsedLeaders = json.loads( leaders )
924 main.log.warn( json.dumps( parsedLeaders,
925 sort_keys=True,
926 indent=4,
927 separators=( ',', ': ' ) ) )
928 # check for all intent partitions
929 # check for election
930 # TODO: Look at Devices as topics now that it uses this system
931 topics = []
932 for i in range( 14 ):
933 topics.append( "intent-partition-" + str( i ) )
934 # FIXME: this should only be after we start the app
935 # FIXME: topics.append( "org.onosproject.election" )
936 # Print leaders output
937 main.log.debug( topics )
938 ONOStopics = [ j['topic'] for j in parsedLeaders ]
939 for topic in topics:
940 if topic not in ONOStopics:
941 main.log.error( "Error: " + topic +
942 " not in leaders" )
943 topicCheck = main.FALSE
944 else:
945 main.log.error( "leaders() returned None" )
946 topicCheck = main.FALSE
947 except ( ValueError, TypeError ):
948 topicCheck = main.FALSE
949 main.log.exception( "Error parsing leaders" )
950 main.log.error( repr( leaders ) )
951 # TODO: Check for a leader of these topics
952 # Check all nodes
953 if topicCheck:
Jon Halle1a3b752015-07-22 13:02:46 -0700954 for node in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -0700955 response = node.leaders( jsonFormat=False)
956 main.log.warn( str( node.name ) + " leaders output: \n" +
957 str( response ) )
958
959 utilities.assert_equals( expect=main.TRUE, actual=topicCheck,
960 onpass="intent Partitions is in leaders",
961 onfail="Some topics were lost " )
962 # Print partitions
963 partitions = main.ONOScli1.partitions()
964 try:
965 if partitions :
966 parsedPartitions = json.loads( partitions )
967 main.log.warn( json.dumps( parsedPartitions,
968 sort_keys=True,
969 indent=4,
970 separators=( ',', ': ' ) ) )
971 # TODO check for a leader in all paritions
972 # TODO check for consistency among nodes
973 else:
974 main.log.error( "partitions() returned None" )
975 except ( ValueError, TypeError ):
976 main.log.exception( "Error parsing partitions" )
977 main.log.error( repr( partitions ) )
978 # Print Pending Map
979 pendingMap = main.ONOScli1.pendingMap()
980 try:
981 if pendingMap :
982 parsedPending = json.loads( pendingMap )
983 main.log.warn( json.dumps( parsedPending,
984 sort_keys=True,
985 indent=4,
986 separators=( ',', ': ' ) ) )
987 # TODO check something here?
988 else:
989 main.log.error( "pendingMap() returned None" )
990 except ( ValueError, TypeError ):
991 main.log.exception( "Error parsing pending map" )
992 main.log.error( repr( pendingMap ) )
993
994 if not installedCheck:
995 main.log.info( "Waiting 60 seconds to see if the state of " +
996 "intents change" )
997 time.sleep( 60 )
998 # Print the intent states
999 intents = main.ONOScli1.intents()
1000 intentStates = []
1001 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
1002 count = 0
1003 # Iter through intents of a node
1004 try:
1005 for intent in json.loads( intents ):
1006 state = intent.get( 'state', None )
1007 if "INSTALLED" not in state:
1008 installedCheck = False
1009 intentId = intent.get( 'id', None )
1010 intentStates.append( ( intentId, state ) )
1011 except ( ValueError, TypeError ):
1012 main.log.exception( "Error parsing intents." )
1013 intentStates.sort()
1014 for i, s in intentStates:
1015 count += 1
1016 main.log.info( "%-6s%-15s%-15s" %
1017 ( str( count ), str( i ), str( s ) ) )
1018 leaders = main.ONOScli1.leaders()
1019 try:
1020 missing = False
1021 if leaders:
1022 parsedLeaders = json.loads( leaders )
1023 main.log.warn( json.dumps( parsedLeaders,
1024 sort_keys=True,
1025 indent=4,
1026 separators=( ',', ': ' ) ) )
1027 # check for all intent partitions
1028 # check for election
1029 topics = []
1030 for i in range( 14 ):
1031 topics.append( "intent-partition-" + str( i ) )
1032 # FIXME: this should only be after we start the app
1033 topics.append( "org.onosproject.election" )
1034 main.log.debug( topics )
1035 ONOStopics = [ j['topic'] for j in parsedLeaders ]
1036 for topic in topics:
1037 if topic not in ONOStopics:
1038 main.log.error( "Error: " + topic +
1039 " not in leaders" )
1040 missing = True
1041 else:
1042 main.log.error( "leaders() returned None" )
1043 except ( ValueError, TypeError ):
1044 main.log.exception( "Error parsing leaders" )
1045 main.log.error( repr( leaders ) )
1046 if missing:
Jon Halle1a3b752015-07-22 13:02:46 -07001047 for node in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -07001048 response = node.leaders( jsonFormat=False)
1049 main.log.warn( str( node.name ) + " leaders output: \n" +
1050 str( response ) )
1051
1052 partitions = main.ONOScli1.partitions()
1053 try:
1054 if partitions :
1055 parsedPartitions = json.loads( partitions )
1056 main.log.warn( json.dumps( parsedPartitions,
1057 sort_keys=True,
1058 indent=4,
1059 separators=( ',', ': ' ) ) )
1060 # TODO check for a leader in all paritions
1061 # TODO check for consistency among nodes
1062 else:
1063 main.log.error( "partitions() returned None" )
1064 except ( ValueError, TypeError ):
1065 main.log.exception( "Error parsing partitions" )
1066 main.log.error( repr( partitions ) )
1067 pendingMap = main.ONOScli1.pendingMap()
1068 try:
1069 if pendingMap :
1070 parsedPending = json.loads( pendingMap )
1071 main.log.warn( json.dumps( parsedPending,
1072 sort_keys=True,
1073 indent=4,
1074 separators=( ',', ': ' ) ) )
1075 # TODO check something here?
1076 else:
1077 main.log.error( "pendingMap() returned None" )
1078 except ( ValueError, TypeError ):
1079 main.log.exception( "Error parsing pending map" )
1080 main.log.error( repr( pendingMap ) )
1081 # Print flowrules
Jon Halle1a3b752015-07-22 13:02:46 -07001082 main.log.debug( main.CLIs[0].flows( jsonFormat=False ) )
Jon Hall5cf14d52015-07-16 12:15:19 -07001083 main.step( "Wait a minute then ping again" )
1084 # the wait is above
1085 PingResult = main.TRUE
1086 for i in range( 8, 18 ):
1087 ping = main.Mininet1.pingHost( src="h" + str( i ),
1088 target="h" + str( i + 10 ) )
1089 PingResult = PingResult and ping
1090 if ping == main.FALSE:
1091 main.log.warn( "Ping failed between h" + str( i ) +
1092 " and h" + str( i + 10 ) )
1093 elif ping == main.TRUE:
1094 main.log.info( "Ping test passed!" )
1095 # Don't set PingResult or you'd override failures
1096 if PingResult == main.FALSE:
1097 main.log.error(
1098 "Intents have not been installed correctly, pings failed." )
1099 # TODO: pretty print
1100 main.log.warn( "ONOS1 intents: " )
1101 try:
1102 tmpIntents = main.ONOScli1.intents()
1103 main.log.warn( json.dumps( json.loads( tmpIntents ),
1104 sort_keys=True,
1105 indent=4,
1106 separators=( ',', ': ' ) ) )
1107 except ( ValueError, TypeError ):
1108 main.log.warn( repr( tmpIntents ) )
1109 utilities.assert_equals(
1110 expect=main.TRUE,
1111 actual=PingResult,
1112 onpass="Intents have been installed correctly and pings work",
1113 onfail="Intents have not been installed correctly, pings failed." )
1114
1115 def CASE5( self, main ):
1116 """
1117 Reading state of ONOS
1118 """
1119 import json
1120 import time
Jon Halle1a3b752015-07-22 13:02:46 -07001121 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07001122 assert main, "main not defined"
1123 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07001124 assert main.CLIs, "main.CLIs not defined"
1125 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07001126
1127 main.case( "Setting up and gathering data for current state" )
1128 # The general idea for this test case is to pull the state of
1129 # ( intents,flows, topology,... ) from each ONOS node
1130 # We can then compare them with each other and also with past states
1131
1132 main.step( "Check that each switch has a master" )
1133 global mastershipState
1134 mastershipState = '[]'
1135
1136 # Assert that each device has a master
1137 rolesNotNull = main.TRUE
1138 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001139 for i in range( main.numCtrls ):
1140 t = main.Thread( target=main.CLIs[i].rolesNotNull,
Jon Hall5cf14d52015-07-16 12:15:19 -07001141 name="rolesNotNull-" + str( i ),
1142 args=[] )
1143 threads.append( t )
1144 t.start()
1145
1146 for t in threads:
1147 t.join()
1148 rolesNotNull = rolesNotNull and t.result
1149 utilities.assert_equals(
1150 expect=main.TRUE,
1151 actual=rolesNotNull,
1152 onpass="Each device has a master",
1153 onfail="Some devices don't have a master assigned" )
1154
1155 main.step( "Get the Mastership of each switch from each controller" )
1156 ONOSMastership = []
1157 mastershipCheck = main.FALSE
1158 consistentMastership = True
1159 rolesResults = True
1160 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001161 for i in range( main.numCtrls ):
1162 t = main.Thread( target=main.CLIs[i].roles,
Jon Hall5cf14d52015-07-16 12:15:19 -07001163 name="roles-" + str( i ),
1164 args=[] )
1165 threads.append( t )
1166 t.start()
1167
1168 for t in threads:
1169 t.join()
1170 ONOSMastership.append( t.result )
1171
Jon Halle1a3b752015-07-22 13:02:46 -07001172 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001173 if not ONOSMastership[i] or "Error" in ONOSMastership[i]:
1174 main.log.error( "Error in getting ONOS" + str( i + 1 ) +
1175 " roles" )
1176 main.log.warn(
1177 "ONOS" + str( i + 1 ) + " mastership response: " +
1178 repr( ONOSMastership[i] ) )
1179 rolesResults = False
1180 utilities.assert_equals(
1181 expect=True,
1182 actual=rolesResults,
1183 onpass="No error in reading roles output",
1184 onfail="Error in reading roles from ONOS" )
1185
1186 main.step( "Check for consistency in roles from each controller" )
1187 if all([ i == ONOSMastership[ 0 ] for i in ONOSMastership ] ):
1188 main.log.info(
1189 "Switch roles are consistent across all ONOS nodes" )
1190 else:
1191 consistentMastership = False
1192 utilities.assert_equals(
1193 expect=True,
1194 actual=consistentMastership,
1195 onpass="Switch roles are consistent across all ONOS nodes",
1196 onfail="ONOS nodes have different views of switch roles" )
1197
1198 if rolesResults and not consistentMastership:
Jon Halle1a3b752015-07-22 13:02:46 -07001199 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001200 try:
1201 main.log.warn(
1202 "ONOS" + str( i + 1 ) + " roles: ",
1203 json.dumps(
1204 json.loads( ONOSMastership[ i ] ),
1205 sort_keys=True,
1206 indent=4,
1207 separators=( ',', ': ' ) ) )
1208 except ( ValueError, TypeError ):
1209 main.log.warn( repr( ONOSMastership[ i ] ) )
1210 elif rolesResults and consistentMastership:
1211 mastershipCheck = main.TRUE
1212 mastershipState = ONOSMastership[ 0 ]
1213
1214 main.step( "Get the intents from each controller" )
1215 global intentState
1216 intentState = []
1217 ONOSIntents = []
1218 intentCheck = main.FALSE
1219 consistentIntents = True
1220 intentsResults = True
1221 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001222 for i in range( main.numCtrls ):
1223 t = main.Thread( target=main.CLIs[i].intents,
Jon Hall5cf14d52015-07-16 12:15:19 -07001224 name="intents-" + str( i ),
1225 args=[],
1226 kwargs={ 'jsonFormat': True } )
1227 threads.append( t )
1228 t.start()
1229
1230 for t in threads:
1231 t.join()
1232 ONOSIntents.append( t.result )
1233
Jon Halle1a3b752015-07-22 13:02:46 -07001234 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001235 if not ONOSIntents[ i ] or "Error" in ONOSIntents[ i ]:
1236 main.log.error( "Error in getting ONOS" + str( i + 1 ) +
1237 " intents" )
1238 main.log.warn( "ONOS" + str( i + 1 ) + " intents response: " +
1239 repr( ONOSIntents[ i ] ) )
1240 intentsResults = False
1241 utilities.assert_equals(
1242 expect=True,
1243 actual=intentsResults,
1244 onpass="No error in reading intents output",
1245 onfail="Error in reading intents from ONOS" )
1246
1247 main.step( "Check for consistency in Intents from each controller" )
1248 if all([ sorted( i ) == sorted( ONOSIntents[ 0 ] ) for i in ONOSIntents ] ):
1249 main.log.info( "Intents are consistent across all ONOS " +
1250 "nodes" )
1251 else:
1252 consistentIntents = False
1253 main.log.error( "Intents not consistent" )
1254 utilities.assert_equals(
1255 expect=True,
1256 actual=consistentIntents,
1257 onpass="Intents are consistent across all ONOS nodes",
1258 onfail="ONOS nodes have different views of intents" )
1259
1260 if intentsResults:
1261 # Try to make it easy to figure out what is happening
1262 #
1263 # Intent ONOS1 ONOS2 ...
1264 # 0x01 INSTALLED INSTALLING
1265 # ... ... ...
1266 # ... ... ...
1267 title = " Id"
Jon Halle1a3b752015-07-22 13:02:46 -07001268 for n in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001269 title += " " * 10 + "ONOS" + str( n + 1 )
1270 main.log.warn( title )
Jon Halle1a3b752015-07-22 13:02:46 -07001271 # get all intent keys in the cluster
Jon Hall5cf14d52015-07-16 12:15:19 -07001272 keys = []
1273 try:
1274 # Get the set of all intent keys
1275 for nodeStr in ONOSIntents:
1276 node = json.loads( nodeStr )
1277 for intent in node:
1278 keys.append( intent.get( 'id' ) )
1279 keys = set( keys )
1280 # For each intent key, print the state on each node
1281 for key in keys:
1282 row = "%-13s" % key
1283 for nodeStr in ONOSIntents:
1284 node = json.loads( nodeStr )
1285 for intent in node:
1286 if intent.get( 'id', "Error" ) == key:
1287 row += "%-15s" % intent.get( 'state' )
1288 main.log.warn( row )
1289 # End of intent state table
1290 except ValueError as e:
1291 main.log.exception( e )
1292 main.log.debug( "nodeStr was: " + repr( nodeStr ) )
1293
1294 if intentsResults and not consistentIntents:
1295 # print the json objects
1296 n = len(ONOSIntents)
1297 main.log.debug( "ONOS" + str( n ) + " intents: " )
1298 main.log.debug( json.dumps( json.loads( ONOSIntents[ -1 ] ),
1299 sort_keys=True,
1300 indent=4,
1301 separators=( ',', ': ' ) ) )
Jon Halle1a3b752015-07-22 13:02:46 -07001302 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001303 if ONOSIntents[ i ] != ONOSIntents[ -1 ]:
1304 main.log.debug( "ONOS" + str( i + 1 ) + " intents: " )
1305 main.log.debug( json.dumps( json.loads( ONOSIntents[i] ),
1306 sort_keys=True,
1307 indent=4,
1308 separators=( ',', ': ' ) ) )
1309 else:
Jon Halle1a3b752015-07-22 13:02:46 -07001310 main.log.debug( main.nodes[ i ].name + " intents match ONOS" +
Jon Hall5cf14d52015-07-16 12:15:19 -07001311 str( n ) + " intents" )
1312 elif intentsResults and consistentIntents:
1313 intentCheck = main.TRUE
1314 intentState = ONOSIntents[ 0 ]
1315
1316 main.step( "Get the flows from each controller" )
1317 global flowState
1318 flowState = []
1319 ONOSFlows = []
1320 ONOSFlowsJson = []
1321 flowCheck = main.FALSE
1322 consistentFlows = True
1323 flowsResults = True
1324 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001325 for i in range( main.numCtrls ):
1326 t = main.Thread( target=main.CLIs[i].flows,
Jon Hall5cf14d52015-07-16 12:15:19 -07001327 name="flows-" + str( i ),
1328 args=[],
1329 kwargs={ 'jsonFormat': True } )
1330 threads.append( t )
1331 t.start()
1332
1333 # NOTE: Flows command can take some time to run
1334 time.sleep(30)
1335 for t in threads:
1336 t.join()
1337 result = t.result
1338 ONOSFlows.append( result )
1339
Jon Halle1a3b752015-07-22 13:02:46 -07001340 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001341 num = str( i + 1 )
1342 if not ONOSFlows[ i ] or "Error" in ONOSFlows[ i ]:
1343 main.log.error( "Error in getting ONOS" + num + " flows" )
1344 main.log.warn( "ONOS" + num + " flows response: " +
1345 repr( ONOSFlows[ i ] ) )
1346 flowsResults = False
1347 ONOSFlowsJson.append( None )
1348 else:
1349 try:
1350 ONOSFlowsJson.append( json.loads( ONOSFlows[ i ] ) )
1351 except ( ValueError, TypeError ):
1352 # FIXME: change this to log.error?
1353 main.log.exception( "Error in parsing ONOS" + num +
1354 " response as json." )
1355 main.log.error( repr( ONOSFlows[ i ] ) )
1356 ONOSFlowsJson.append( None )
1357 flowsResults = False
1358 utilities.assert_equals(
1359 expect=True,
1360 actual=flowsResults,
1361 onpass="No error in reading flows output",
1362 onfail="Error in reading flows from ONOS" )
1363
1364 main.step( "Check for consistency in Flows from each controller" )
1365 tmp = [ len( i ) == len( ONOSFlowsJson[ 0 ] ) for i in ONOSFlowsJson ]
1366 if all( tmp ):
1367 main.log.info( "Flow count is consistent across all ONOS nodes" )
1368 else:
1369 consistentFlows = False
1370 utilities.assert_equals(
1371 expect=True,
1372 actual=consistentFlows,
1373 onpass="The flow count is consistent across all ONOS nodes",
1374 onfail="ONOS nodes have different flow counts" )
1375
1376 if flowsResults and not consistentFlows:
Jon Halle1a3b752015-07-22 13:02:46 -07001377 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001378 try:
1379 main.log.warn(
1380 "ONOS" + str( i + 1 ) + " flows: " +
1381 json.dumps( json.loads( ONOSFlows[i] ), sort_keys=True,
1382 indent=4, separators=( ',', ': ' ) ) )
1383 except ( ValueError, TypeError ):
1384 main.log.warn(
1385 "ONOS" + str( i + 1 ) + " flows: " +
1386 repr( ONOSFlows[ i ] ) )
1387 elif flowsResults and consistentFlows:
1388 flowCheck = main.TRUE
1389 flowState = ONOSFlows[ 0 ]
1390
1391 main.step( "Get the OF Table entries" )
1392 global flows
1393 flows = []
1394 for i in range( 1, 29 ):
GlennRC68467eb2015-11-16 18:01:01 -08001395 flows.append( main.Mininet1.getFlowTable( "s" + str( i ), version="1.3", debug=False ) )
Jon Hall5cf14d52015-07-16 12:15:19 -07001396 if flowCheck == main.FALSE:
1397 for table in flows:
1398 main.log.warn( table )
GlennRC68467eb2015-11-16 18:01:01 -08001399
Jon Hall5cf14d52015-07-16 12:15:19 -07001400 # TODO: Compare switch flow tables with ONOS flow tables
1401
1402 main.step( "Start continuous pings" )
1403 main.Mininet2.pingLong(
1404 src=main.params[ 'PING' ][ 'source1' ],
1405 target=main.params[ 'PING' ][ 'target1' ],
1406 pingTime=500 )
1407 main.Mininet2.pingLong(
1408 src=main.params[ 'PING' ][ 'source2' ],
1409 target=main.params[ 'PING' ][ 'target2' ],
1410 pingTime=500 )
1411 main.Mininet2.pingLong(
1412 src=main.params[ 'PING' ][ 'source3' ],
1413 target=main.params[ 'PING' ][ 'target3' ],
1414 pingTime=500 )
1415 main.Mininet2.pingLong(
1416 src=main.params[ 'PING' ][ 'source4' ],
1417 target=main.params[ 'PING' ][ 'target4' ],
1418 pingTime=500 )
1419 main.Mininet2.pingLong(
1420 src=main.params[ 'PING' ][ 'source5' ],
1421 target=main.params[ 'PING' ][ 'target5' ],
1422 pingTime=500 )
1423 main.Mininet2.pingLong(
1424 src=main.params[ 'PING' ][ 'source6' ],
1425 target=main.params[ 'PING' ][ 'target6' ],
1426 pingTime=500 )
1427 main.Mininet2.pingLong(
1428 src=main.params[ 'PING' ][ 'source7' ],
1429 target=main.params[ 'PING' ][ 'target7' ],
1430 pingTime=500 )
1431 main.Mininet2.pingLong(
1432 src=main.params[ 'PING' ][ 'source8' ],
1433 target=main.params[ 'PING' ][ 'target8' ],
1434 pingTime=500 )
1435 main.Mininet2.pingLong(
1436 src=main.params[ 'PING' ][ 'source9' ],
1437 target=main.params[ 'PING' ][ 'target9' ],
1438 pingTime=500 )
1439 main.Mininet2.pingLong(
1440 src=main.params[ 'PING' ][ 'source10' ],
1441 target=main.params[ 'PING' ][ 'target10' ],
1442 pingTime=500 )
1443
1444 main.step( "Collecting topology information from ONOS" )
1445 devices = []
1446 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001447 for i in range( main.numCtrls ):
1448 t = main.Thread( target=main.CLIs[i].devices,
Jon Hall5cf14d52015-07-16 12:15:19 -07001449 name="devices-" + str( i ),
1450 args=[ ] )
1451 threads.append( t )
1452 t.start()
1453
1454 for t in threads:
1455 t.join()
1456 devices.append( t.result )
1457 hosts = []
1458 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001459 for i in range( main.numCtrls ):
1460 t = main.Thread( target=main.CLIs[i].hosts,
Jon Hall5cf14d52015-07-16 12:15:19 -07001461 name="hosts-" + str( i ),
1462 args=[ ] )
1463 threads.append( t )
1464 t.start()
1465
1466 for t in threads:
1467 t.join()
1468 try:
1469 hosts.append( json.loads( t.result ) )
1470 except ( ValueError, TypeError ):
1471 # FIXME: better handling of this, print which node
1472 # Maybe use thread name?
1473 main.log.exception( "Error parsing json output of hosts" )
1474 # FIXME: should this be an empty json object instead?
1475 hosts.append( None )
1476
1477 ports = []
1478 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001479 for i in range( main.numCtrls ):
1480 t = main.Thread( target=main.CLIs[i].ports,
Jon Hall5cf14d52015-07-16 12:15:19 -07001481 name="ports-" + str( i ),
1482 args=[ ] )
1483 threads.append( t )
1484 t.start()
1485
1486 for t in threads:
1487 t.join()
1488 ports.append( t.result )
1489 links = []
1490 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001491 for i in range( main.numCtrls ):
1492 t = main.Thread( target=main.CLIs[i].links,
Jon Hall5cf14d52015-07-16 12:15:19 -07001493 name="links-" + str( i ),
1494 args=[ ] )
1495 threads.append( t )
1496 t.start()
1497
1498 for t in threads:
1499 t.join()
1500 links.append( t.result )
1501 clusters = []
1502 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001503 for i in range( main.numCtrls ):
1504 t = main.Thread( target=main.CLIs[i].clusters,
Jon Hall5cf14d52015-07-16 12:15:19 -07001505 name="clusters-" + str( i ),
1506 args=[ ] )
1507 threads.append( t )
1508 t.start()
1509
1510 for t in threads:
1511 t.join()
1512 clusters.append( t.result )
1513 # Compare json objects for hosts and dataplane clusters
1514
1515 # hosts
1516 main.step( "Host view is consistent across ONOS nodes" )
1517 consistentHostsResult = main.TRUE
1518 for controller in range( len( hosts ) ):
1519 controllerStr = str( controller + 1 )
1520 if "Error" not in hosts[ controller ]:
1521 if hosts[ controller ] == hosts[ 0 ]:
1522 continue
1523 else: # hosts not consistent
1524 main.log.error( "hosts from ONOS" +
1525 controllerStr +
1526 " is inconsistent with ONOS1" )
1527 main.log.warn( repr( hosts[ controller ] ) )
1528 consistentHostsResult = main.FALSE
1529
1530 else:
1531 main.log.error( "Error in getting ONOS hosts from ONOS" +
1532 controllerStr )
1533 consistentHostsResult = main.FALSE
1534 main.log.warn( "ONOS" + controllerStr +
1535 " hosts response: " +
1536 repr( hosts[ controller ] ) )
1537 utilities.assert_equals(
1538 expect=main.TRUE,
1539 actual=consistentHostsResult,
1540 onpass="Hosts view is consistent across all ONOS nodes",
1541 onfail="ONOS nodes have different views of hosts" )
1542
1543 main.step( "Each host has an IP address" )
1544 ipResult = main.TRUE
1545 for controller in range( 0, len( hosts ) ):
1546 controllerStr = str( controller + 1 )
1547 for host in hosts[ controller ]:
1548 if not host.get( 'ipAddresses', [ ] ):
1549 main.log.error( "DEBUG:Error with host ips on controller" +
1550 controllerStr + ": " + str( host ) )
1551 ipResult = main.FALSE
1552 utilities.assert_equals(
1553 expect=main.TRUE,
1554 actual=ipResult,
1555 onpass="The ips of the hosts aren't empty",
1556 onfail="The ip of at least one host is missing" )
1557
1558 # Strongly connected clusters of devices
1559 main.step( "Cluster view is consistent across ONOS nodes" )
1560 consistentClustersResult = main.TRUE
1561 for controller in range( len( clusters ) ):
1562 controllerStr = str( controller + 1 )
1563 if "Error" not in clusters[ controller ]:
1564 if clusters[ controller ] == clusters[ 0 ]:
1565 continue
1566 else: # clusters not consistent
1567 main.log.error( "clusters from ONOS" + controllerStr +
1568 " is inconsistent with ONOS1" )
1569 consistentClustersResult = main.FALSE
1570
1571 else:
1572 main.log.error( "Error in getting dataplane clusters " +
1573 "from ONOS" + controllerStr )
1574 consistentClustersResult = main.FALSE
1575 main.log.warn( "ONOS" + controllerStr +
1576 " clusters response: " +
1577 repr( clusters[ controller ] ) )
1578 utilities.assert_equals(
1579 expect=main.TRUE,
1580 actual=consistentClustersResult,
1581 onpass="Clusters view is consistent across all ONOS nodes",
1582 onfail="ONOS nodes have different views of clusters" )
1583 # there should always only be one cluster
1584 main.step( "Cluster view correct across ONOS nodes" )
1585 try:
1586 numClusters = len( json.loads( clusters[ 0 ] ) )
1587 except ( ValueError, TypeError ):
1588 main.log.exception( "Error parsing clusters[0]: " +
1589 repr( clusters[ 0 ] ) )
1590 clusterResults = main.FALSE
1591 if numClusters == 1:
1592 clusterResults = main.TRUE
1593 utilities.assert_equals(
1594 expect=1,
1595 actual=numClusters,
1596 onpass="ONOS shows 1 SCC",
1597 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
1598
1599 main.step( "Comparing ONOS topology to MN" )
1600 devicesResults = main.TRUE
1601 linksResults = main.TRUE
1602 hostsResults = main.TRUE
1603 mnSwitches = main.Mininet1.getSwitches()
1604 mnLinks = main.Mininet1.getLinks()
1605 mnHosts = main.Mininet1.getHosts()
Jon Halle1a3b752015-07-22 13:02:46 -07001606 for controller in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001607 controllerStr = str( controller + 1 )
1608 if devices[ controller ] and ports[ controller ] and\
1609 "Error" not in devices[ controller ] and\
1610 "Error" not in ports[ controller ]:
1611
1612 currentDevicesResult = main.Mininet1.compareSwitches(
1613 mnSwitches,
1614 json.loads( devices[ controller ] ),
1615 json.loads( ports[ controller ] ) )
1616 else:
1617 currentDevicesResult = main.FALSE
1618 utilities.assert_equals( expect=main.TRUE,
1619 actual=currentDevicesResult,
1620 onpass="ONOS" + controllerStr +
1621 " Switches view is correct",
1622 onfail="ONOS" + controllerStr +
1623 " Switches view is incorrect" )
1624 if links[ controller ] and "Error" not in links[ controller ]:
1625 currentLinksResult = main.Mininet1.compareLinks(
1626 mnSwitches, mnLinks,
1627 json.loads( links[ controller ] ) )
1628 else:
1629 currentLinksResult = main.FALSE
1630 utilities.assert_equals( expect=main.TRUE,
1631 actual=currentLinksResult,
1632 onpass="ONOS" + controllerStr +
1633 " links view is correct",
1634 onfail="ONOS" + controllerStr +
1635 " links view is incorrect" )
1636
1637 if hosts[ controller ] or "Error" not in hosts[ controller ]:
1638 currentHostsResult = main.Mininet1.compareHosts(
1639 mnHosts,
1640 hosts[ controller ] )
1641 else:
1642 currentHostsResult = main.FALSE
1643 utilities.assert_equals( expect=main.TRUE,
1644 actual=currentHostsResult,
1645 onpass="ONOS" + controllerStr +
1646 " hosts exist in Mininet",
1647 onfail="ONOS" + controllerStr +
1648 " hosts don't match Mininet" )
1649
1650 devicesResults = devicesResults and currentDevicesResult
1651 linksResults = linksResults and currentLinksResult
1652 hostsResults = hostsResults and currentHostsResult
1653
1654 main.step( "Device information is correct" )
1655 utilities.assert_equals(
1656 expect=main.TRUE,
1657 actual=devicesResults,
1658 onpass="Device information is correct",
1659 onfail="Device information is incorrect" )
1660
1661 main.step( "Links are correct" )
1662 utilities.assert_equals(
1663 expect=main.TRUE,
1664 actual=linksResults,
1665 onpass="Link are correct",
1666 onfail="Links are incorrect" )
1667
1668 main.step( "Hosts are correct" )
1669 utilities.assert_equals(
1670 expect=main.TRUE,
1671 actual=hostsResults,
1672 onpass="Hosts are correct",
1673 onfail="Hosts are incorrect" )
1674
1675 def CASE6( self, main ):
1676 """
1677 The Failure case. Since this is the Sanity test, we do nothing.
1678 """
1679 import time
Jon Halle1a3b752015-07-22 13:02:46 -07001680 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07001681 assert main, "main not defined"
1682 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07001683 assert main.CLIs, "main.CLIs not defined"
1684 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07001685 main.case( "Wait 60 seconds instead of inducing a failure" )
1686 time.sleep( 60 )
1687 utilities.assert_equals(
1688 expect=main.TRUE,
1689 actual=main.TRUE,
1690 onpass="Sleeping 60 seconds",
1691 onfail="Something is terribly wrong with my math" )
1692
1693 def CASE7( self, main ):
1694 """
1695 Check state after ONOS failure
1696 """
1697 import json
Jon Halle1a3b752015-07-22 13:02:46 -07001698 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07001699 assert main, "main not defined"
1700 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07001701 assert main.CLIs, "main.CLIs not defined"
1702 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07001703 main.case( "Running ONOS Constant State Tests" )
1704
1705 main.step( "Check that each switch has a master" )
1706 # Assert that each device has a master
1707 rolesNotNull = main.TRUE
1708 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001709 for i in range( main.numCtrls ):
1710 t = main.Thread( target=main.CLIs[i].rolesNotNull,
Jon Hall5cf14d52015-07-16 12:15:19 -07001711 name="rolesNotNull-" + str( i ),
1712 args=[ ] )
1713 threads.append( t )
1714 t.start()
1715
1716 for t in threads:
1717 t.join()
1718 rolesNotNull = rolesNotNull and t.result
1719 utilities.assert_equals(
1720 expect=main.TRUE,
1721 actual=rolesNotNull,
1722 onpass="Each device has a master",
1723 onfail="Some devices don't have a master assigned" )
1724
1725 main.step( "Read device roles from ONOS" )
1726 ONOSMastership = []
1727 mastershipCheck = main.FALSE
1728 consistentMastership = True
1729 rolesResults = True
1730 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001731 for i in range( main.numCtrls ):
1732 t = main.Thread( target=main.CLIs[i].roles,
Jon Hall5cf14d52015-07-16 12:15:19 -07001733 name="roles-" + str( i ),
1734 args=[] )
1735 threads.append( t )
1736 t.start()
1737
1738 for t in threads:
1739 t.join()
1740 ONOSMastership.append( t.result )
1741
Jon Halle1a3b752015-07-22 13:02:46 -07001742 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001743 if not ONOSMastership[i] or "Error" in ONOSMastership[i]:
1744 main.log.error( "Error in getting ONOS" + str( i + 1 ) +
1745 " roles" )
1746 main.log.warn(
1747 "ONOS" + str( i + 1 ) + " mastership response: " +
1748 repr( ONOSMastership[i] ) )
1749 rolesResults = False
1750 utilities.assert_equals(
1751 expect=True,
1752 actual=rolesResults,
1753 onpass="No error in reading roles output",
1754 onfail="Error in reading roles from ONOS" )
1755
1756 main.step( "Check for consistency in roles from each controller" )
1757 if all([ i == ONOSMastership[ 0 ] for i in ONOSMastership ] ):
1758 main.log.info(
1759 "Switch roles are consistent across all ONOS nodes" )
1760 else:
1761 consistentMastership = False
1762 utilities.assert_equals(
1763 expect=True,
1764 actual=consistentMastership,
1765 onpass="Switch roles are consistent across all ONOS nodes",
1766 onfail="ONOS nodes have different views of switch roles" )
1767
1768 if rolesResults and not consistentMastership:
Jon Halle1a3b752015-07-22 13:02:46 -07001769 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001770 main.log.warn(
1771 "ONOS" + str( i + 1 ) + " roles: ",
1772 json.dumps(
1773 json.loads( ONOSMastership[ i ] ),
1774 sort_keys=True,
1775 indent=4,
1776 separators=( ',', ': ' ) ) )
1777 elif rolesResults and not consistentMastership:
1778 mastershipCheck = main.TRUE
1779
1780 description2 = "Compare switch roles from before failure"
1781 main.step( description2 )
1782 try:
1783 currentJson = json.loads( ONOSMastership[0] )
1784 oldJson = json.loads( mastershipState )
1785 except ( ValueError, TypeError ):
1786 main.log.exception( "Something is wrong with parsing " +
1787 "ONOSMastership[0] or mastershipState" )
1788 main.log.error( "ONOSMastership[0]: " + repr( ONOSMastership[0] ) )
1789 main.log.error( "mastershipState" + repr( mastershipState ) )
1790 main.cleanup()
1791 main.exit()
1792 mastershipCheck = main.TRUE
1793 for i in range( 1, 29 ):
1794 switchDPID = str(
1795 main.Mininet1.getSwitchDPID( switch="s" + str( i ) ) )
1796 current = [ switch[ 'master' ] for switch in currentJson
1797 if switchDPID in switch[ 'id' ] ]
1798 old = [ switch[ 'master' ] for switch in oldJson
1799 if switchDPID in switch[ 'id' ] ]
1800 if current == old:
1801 mastershipCheck = mastershipCheck and main.TRUE
1802 else:
1803 main.log.warn( "Mastership of switch %s changed" % switchDPID )
1804 mastershipCheck = main.FALSE
1805 utilities.assert_equals(
1806 expect=main.TRUE,
1807 actual=mastershipCheck,
1808 onpass="Mastership of Switches was not changed",
1809 onfail="Mastership of some switches changed" )
1810 mastershipCheck = mastershipCheck and consistentMastership
1811
1812 main.step( "Get the intents and compare across all nodes" )
1813 ONOSIntents = []
1814 intentCheck = main.FALSE
1815 consistentIntents = True
1816 intentsResults = True
1817 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001818 for i in range( main.numCtrls ):
1819 t = main.Thread( target=main.CLIs[i].intents,
Jon Hall5cf14d52015-07-16 12:15:19 -07001820 name="intents-" + str( i ),
1821 args=[],
1822 kwargs={ 'jsonFormat': True } )
1823 threads.append( t )
1824 t.start()
1825
1826 for t in threads:
1827 t.join()
1828 ONOSIntents.append( t.result )
1829
Jon Halle1a3b752015-07-22 13:02:46 -07001830 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001831 if not ONOSIntents[ i ] or "Error" in ONOSIntents[ i ]:
1832 main.log.error( "Error in getting ONOS" + str( i + 1 ) +
1833 " intents" )
1834 main.log.warn( "ONOS" + str( i + 1 ) + " intents response: " +
1835 repr( ONOSIntents[ i ] ) )
1836 intentsResults = False
1837 utilities.assert_equals(
1838 expect=True,
1839 actual=intentsResults,
1840 onpass="No error in reading intents output",
1841 onfail="Error in reading intents from ONOS" )
1842
1843 main.step( "Check for consistency in Intents from each controller" )
1844 if all([ sorted( i ) == sorted( ONOSIntents[ 0 ] ) for i in ONOSIntents ] ):
1845 main.log.info( "Intents are consistent across all ONOS " +
1846 "nodes" )
1847 else:
1848 consistentIntents = False
1849
1850 # Try to make it easy to figure out what is happening
1851 #
1852 # Intent ONOS1 ONOS2 ...
1853 # 0x01 INSTALLED INSTALLING
1854 # ... ... ...
1855 # ... ... ...
1856 title = " ID"
Jon Halle1a3b752015-07-22 13:02:46 -07001857 for n in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001858 title += " " * 10 + "ONOS" + str( n + 1 )
1859 main.log.warn( title )
1860 # get all intent keys in the cluster
1861 keys = []
1862 for nodeStr in ONOSIntents:
1863 node = json.loads( nodeStr )
1864 for intent in node:
1865 keys.append( intent.get( 'id' ) )
1866 keys = set( keys )
1867 for key in keys:
1868 row = "%-13s" % key
1869 for nodeStr in ONOSIntents:
1870 node = json.loads( nodeStr )
1871 for intent in node:
1872 if intent.get( 'id' ) == key:
1873 row += "%-15s" % intent.get( 'state' )
1874 main.log.warn( row )
1875 # End table view
1876
1877 utilities.assert_equals(
1878 expect=True,
1879 actual=consistentIntents,
1880 onpass="Intents are consistent across all ONOS nodes",
1881 onfail="ONOS nodes have different views of intents" )
1882 intentStates = []
1883 for node in ONOSIntents: # Iter through ONOS nodes
1884 nodeStates = []
1885 # Iter through intents of a node
1886 try:
1887 for intent in json.loads( node ):
1888 nodeStates.append( intent[ 'state' ] )
1889 except ( ValueError, TypeError ):
1890 main.log.exception( "Error in parsing intents" )
1891 main.log.error( repr( node ) )
1892 intentStates.append( nodeStates )
1893 out = [ (i, nodeStates.count( i ) ) for i in set( nodeStates ) ]
1894 main.log.info( dict( out ) )
1895
1896 if intentsResults and not consistentIntents:
Jon Halle1a3b752015-07-22 13:02:46 -07001897 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001898 main.log.warn( "ONOS" + str( i + 1 ) + " intents: " )
1899 main.log.warn( json.dumps(
1900 json.loads( ONOSIntents[ i ] ),
1901 sort_keys=True,
1902 indent=4,
1903 separators=( ',', ': ' ) ) )
1904 elif intentsResults and consistentIntents:
1905 intentCheck = main.TRUE
1906
1907 # NOTE: Store has no durability, so intents are lost across system
1908 # restarts
1909 main.step( "Compare current intents with intents before the failure" )
1910 # NOTE: this requires case 5 to pass for intentState to be set.
1911 # maybe we should stop the test if that fails?
1912 sameIntents = main.FALSE
1913 if intentState and intentState == ONOSIntents[ 0 ]:
1914 sameIntents = main.TRUE
1915 main.log.info( "Intents are consistent with before failure" )
1916 # TODO: possibly the states have changed? we may need to figure out
1917 # what the acceptable states are
1918 elif len( intentState ) == len( ONOSIntents[ 0 ] ):
1919 sameIntents = main.TRUE
1920 try:
1921 before = json.loads( intentState )
1922 after = json.loads( ONOSIntents[ 0 ] )
1923 for intent in before:
1924 if intent not in after:
1925 sameIntents = main.FALSE
1926 main.log.debug( "Intent is not currently in ONOS " +
1927 "(at least in the same form):" )
1928 main.log.debug( json.dumps( intent ) )
1929 except ( ValueError, TypeError ):
1930 main.log.exception( "Exception printing intents" )
1931 main.log.debug( repr( ONOSIntents[0] ) )
1932 main.log.debug( repr( intentState ) )
1933 if sameIntents == main.FALSE:
1934 try:
1935 main.log.debug( "ONOS intents before: " )
1936 main.log.debug( json.dumps( json.loads( intentState ),
1937 sort_keys=True, indent=4,
1938 separators=( ',', ': ' ) ) )
1939 main.log.debug( "Current ONOS intents: " )
1940 main.log.debug( json.dumps( json.loads( ONOSIntents[ 0 ] ),
1941 sort_keys=True, indent=4,
1942 separators=( ',', ': ' ) ) )
1943 except ( ValueError, TypeError ):
1944 main.log.exception( "Exception printing intents" )
1945 main.log.debug( repr( ONOSIntents[0] ) )
1946 main.log.debug( repr( intentState ) )
1947 utilities.assert_equals(
1948 expect=main.TRUE,
1949 actual=sameIntents,
1950 onpass="Intents are consistent with before failure",
1951 onfail="The Intents changed during failure" )
1952 intentCheck = intentCheck and sameIntents
1953
1954 main.step( "Get the OF Table entries and compare to before " +
1955 "component failure" )
1956 FlowTables = main.TRUE
Jon Hall5cf14d52015-07-16 12:15:19 -07001957 for i in range( 28 ):
1958 main.log.info( "Checking flow table on s" + str( i + 1 ) )
GlennRC68467eb2015-11-16 18:01:01 -08001959 tmpFlows = main.Mininet1.getFlowTable( "s" + str( i + 1 ), version="1.3", debug=False )
1960 FlowTables = FlowTables and main.Mininet1.flowTableComp( flows[i], tmpFlows )
Jon Hall5cf14d52015-07-16 12:15:19 -07001961 if FlowTables == main.FALSE:
GlennRC68467eb2015-11-16 18:01:01 -08001962 main.log.warn( "Differences in flow table for switch: s{}".format( i + 1 ) )
1963
Jon Hall5cf14d52015-07-16 12:15:19 -07001964 utilities.assert_equals(
1965 expect=main.TRUE,
1966 actual=FlowTables,
1967 onpass="No changes were found in the flow tables",
1968 onfail="Changes were found in the flow tables" )
1969
1970 main.Mininet2.pingLongKill()
1971 '''
1972 main.step( "Check the continuous pings to ensure that no packets " +
1973 "were dropped during component failure" )
1974 main.Mininet2.pingKill( main.params[ 'TESTONUSER' ],
1975 main.params[ 'TESTONIP' ] )
1976 LossInPings = main.FALSE
1977 # NOTE: checkForLoss returns main.FALSE with 0% packet loss
1978 for i in range( 8, 18 ):
1979 main.log.info(
1980 "Checking for a loss in pings along flow from s" +
1981 str( i ) )
1982 LossInPings = main.Mininet2.checkForLoss(
1983 "/tmp/ping.h" +
1984 str( i ) ) or LossInPings
1985 if LossInPings == main.TRUE:
1986 main.log.info( "Loss in ping detected" )
1987 elif LossInPings == main.ERROR:
1988 main.log.info( "There are multiple mininet process running" )
1989 elif LossInPings == main.FALSE:
1990 main.log.info( "No Loss in the pings" )
1991 main.log.info( "No loss of dataplane connectivity" )
1992 utilities.assert_equals(
1993 expect=main.FALSE,
1994 actual=LossInPings,
1995 onpass="No Loss of connectivity",
1996 onfail="Loss of dataplane connectivity detected" )
1997 '''
1998
1999 main.step( "Leadership Election is still functional" )
2000 # Test of LeadershipElection
2001 # NOTE: this only works for the sanity test. In case of failures,
2002 # leader will likely change
Jon Halle1a3b752015-07-22 13:02:46 -07002003 leader = main.nodes[ 0 ].ip_address
Jon Hall5cf14d52015-07-16 12:15:19 -07002004 leaderResult = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07002005 for cli in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -07002006 leaderN = cli.electionTestLeader()
2007 # verify leader is ONOS1
2008 if leaderN == leader:
2009 # all is well
2010 # NOTE: In failure scenario, this could be a new node, maybe
2011 # check != ONOS1
2012 pass
2013 elif leaderN == main.FALSE:
2014 # error in response
2015 main.log.error( "Something is wrong with " +
2016 "electionTestLeader function, check the" +
2017 " error logs" )
2018 leaderResult = main.FALSE
2019 elif leader != leaderN:
2020 leaderResult = main.FALSE
2021 main.log.error( cli.name + " sees " + str( leaderN ) +
2022 " as the leader of the election app. " +
2023 "Leader should be " + str( leader ) )
2024 utilities.assert_equals(
2025 expect=main.TRUE,
2026 actual=leaderResult,
2027 onpass="Leadership election passed",
2028 onfail="Something went wrong with Leadership election" )
2029
2030 def CASE8( self, main ):
2031 """
2032 Compare topo
2033 """
2034 import json
2035 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002036 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002037 assert main, "main not defined"
2038 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002039 assert main.CLIs, "main.CLIs not defined"
2040 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002041
2042 main.case( "Compare ONOS Topology view to Mininet topology" )
Jon Hall783bbf92015-07-23 14:33:19 -07002043 main.caseExplanation = "Compare topology objects between Mininet" +\
Jon Hall5cf14d52015-07-16 12:15:19 -07002044 " and ONOS"
2045
2046 main.step( "Comparing ONOS topology to MN" )
Jon Hall5cf14d52015-07-16 12:15:19 -07002047 topoResult = main.FALSE
2048 elapsed = 0
2049 count = 0
2050 main.step( "Collecting topology information from ONOS" )
2051 startTime = time.time()
2052 # Give time for Gossip to work
2053 while topoResult == main.FALSE and elapsed < 60:
Jon Hall96091e62015-09-21 17:34:17 -07002054 devicesResults = main.TRUE
2055 linksResults = main.TRUE
2056 hostsResults = main.TRUE
2057 hostAttachmentResults = True
Jon Hall5cf14d52015-07-16 12:15:19 -07002058 count += 1
2059 cliStart = time.time()
2060 devices = []
2061 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002062 for i in range( main.numCtrls ):
2063 t = main.Thread( target=main.CLIs[i].devices,
Jon Hall5cf14d52015-07-16 12:15:19 -07002064 name="devices-" + str( i ),
2065 args=[ ] )
2066 threads.append( t )
2067 t.start()
2068
2069 for t in threads:
2070 t.join()
2071 devices.append( t.result )
2072 hosts = []
2073 ipResult = main.TRUE
2074 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002075 for i in range( main.numCtrls ):
2076 t = main.Thread( target=main.CLIs[i].hosts,
Jon Hall5cf14d52015-07-16 12:15:19 -07002077 name="hosts-" + str( i ),
2078 args=[ ] )
2079 threads.append( t )
2080 t.start()
2081
2082 for t in threads:
2083 t.join()
2084 try:
2085 hosts.append( json.loads( t.result ) )
2086 except ( ValueError, TypeError ):
2087 main.log.exception( "Error parsing hosts results" )
2088 main.log.error( repr( t.result ) )
2089 for controller in range( 0, len( hosts ) ):
2090 controllerStr = str( controller + 1 )
2091 for host in hosts[ controller ]:
2092 if host is None or host.get( 'ipAddresses', [] ) == []:
2093 main.log.error(
2094 "DEBUG:Error with host ipAddresses on controller" +
2095 controllerStr + ": " + str( host ) )
2096 ipResult = main.FALSE
2097 ports = []
2098 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002099 for i in range( main.numCtrls ):
2100 t = main.Thread( target=main.CLIs[i].ports,
Jon Hall5cf14d52015-07-16 12:15:19 -07002101 name="ports-" + str( i ),
2102 args=[ ] )
2103 threads.append( t )
2104 t.start()
2105
2106 for t in threads:
2107 t.join()
2108 ports.append( t.result )
2109 links = []
2110 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002111 for i in range( main.numCtrls ):
2112 t = main.Thread( target=main.CLIs[i].links,
Jon Hall5cf14d52015-07-16 12:15:19 -07002113 name="links-" + str( i ),
2114 args=[ ] )
2115 threads.append( t )
2116 t.start()
2117
2118 for t in threads:
2119 t.join()
2120 links.append( t.result )
2121 clusters = []
2122 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002123 for i in range( main.numCtrls ):
2124 t = main.Thread( target=main.CLIs[i].clusters,
Jon Hall5cf14d52015-07-16 12:15:19 -07002125 name="clusters-" + str( i ),
2126 args=[ ] )
2127 threads.append( t )
2128 t.start()
2129
2130 for t in threads:
2131 t.join()
2132 clusters.append( t.result )
2133
2134 elapsed = time.time() - startTime
2135 cliTime = time.time() - cliStart
2136 print "Elapsed time: " + str( elapsed )
2137 print "CLI time: " + str( cliTime )
2138
2139 mnSwitches = main.Mininet1.getSwitches()
2140 mnLinks = main.Mininet1.getLinks()
2141 mnHosts = main.Mininet1.getHosts()
Jon Halle1a3b752015-07-22 13:02:46 -07002142 for controller in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07002143 controllerStr = str( controller + 1 )
2144 if devices[ controller ] and ports[ controller ] and\
2145 "Error" not in devices[ controller ] and\
2146 "Error" not in ports[ controller ]:
2147
2148 currentDevicesResult = main.Mininet1.compareSwitches(
2149 mnSwitches,
2150 json.loads( devices[ controller ] ),
2151 json.loads( ports[ controller ] ) )
2152 else:
2153 currentDevicesResult = main.FALSE
2154 utilities.assert_equals( expect=main.TRUE,
2155 actual=currentDevicesResult,
2156 onpass="ONOS" + controllerStr +
2157 " Switches view is correct",
2158 onfail="ONOS" + controllerStr +
2159 " Switches view is incorrect" )
2160
2161 if links[ controller ] and "Error" not in links[ controller ]:
2162 currentLinksResult = main.Mininet1.compareLinks(
2163 mnSwitches, mnLinks,
2164 json.loads( links[ controller ] ) )
2165 else:
2166 currentLinksResult = main.FALSE
2167 utilities.assert_equals( expect=main.TRUE,
2168 actual=currentLinksResult,
2169 onpass="ONOS" + controllerStr +
2170 " links view is correct",
2171 onfail="ONOS" + controllerStr +
2172 " links view is incorrect" )
2173
2174 if hosts[ controller ] or "Error" not in hosts[ controller ]:
2175 currentHostsResult = main.Mininet1.compareHosts(
2176 mnHosts,
2177 hosts[ controller ] )
2178 else:
2179 currentHostsResult = main.FALSE
2180 utilities.assert_equals( expect=main.TRUE,
2181 actual=currentHostsResult,
2182 onpass="ONOS" + controllerStr +
2183 " hosts exist in Mininet",
2184 onfail="ONOS" + controllerStr +
2185 " hosts don't match Mininet" )
2186 # CHECKING HOST ATTACHMENT POINTS
2187 hostAttachment = True
2188 zeroHosts = False
2189 # FIXME: topo-HA/obelisk specific mappings:
2190 # key is mac and value is dpid
2191 mappings = {}
2192 for i in range( 1, 29 ): # hosts 1 through 28
2193 # set up correct variables:
2194 macId = "00:" * 5 + hex( i ).split( "0x" )[1].upper().zfill(2)
2195 if i == 1:
2196 deviceId = "1000".zfill(16)
2197 elif i == 2:
2198 deviceId = "2000".zfill(16)
2199 elif i == 3:
2200 deviceId = "3000".zfill(16)
2201 elif i == 4:
2202 deviceId = "3004".zfill(16)
2203 elif i == 5:
2204 deviceId = "5000".zfill(16)
2205 elif i == 6:
2206 deviceId = "6000".zfill(16)
2207 elif i == 7:
2208 deviceId = "6007".zfill(16)
2209 elif i >= 8 and i <= 17:
2210 dpid = '3' + str( i ).zfill( 3 )
2211 deviceId = dpid.zfill(16)
2212 elif i >= 18 and i <= 27:
2213 dpid = '6' + str( i ).zfill( 3 )
2214 deviceId = dpid.zfill(16)
2215 elif i == 28:
2216 deviceId = "2800".zfill(16)
2217 mappings[ macId ] = deviceId
2218 if hosts[ controller ] or "Error" not in hosts[ controller ]:
2219 if hosts[ controller ] == []:
2220 main.log.warn( "There are no hosts discovered" )
2221 zeroHosts = True
2222 else:
2223 for host in hosts[ controller ]:
2224 mac = None
2225 location = None
2226 device = None
2227 port = None
2228 try:
2229 mac = host.get( 'mac' )
2230 assert mac, "mac field could not be found for this host object"
2231
2232 location = host.get( 'location' )
2233 assert location, "location field could not be found for this host object"
2234
2235 # Trim the protocol identifier off deviceId
2236 device = str( location.get( 'elementId' ) ).split(':')[1]
2237 assert device, "elementId field could not be found for this host location object"
2238
2239 port = location.get( 'port' )
2240 assert port, "port field could not be found for this host location object"
2241
2242 # Now check if this matches where they should be
2243 if mac and device and port:
2244 if str( port ) != "1":
2245 main.log.error( "The attachment port is incorrect for " +
2246 "host " + str( mac ) +
2247 ". Expected: 1 Actual: " + str( port) )
2248 hostAttachment = False
2249 if device != mappings[ str( mac ) ]:
2250 main.log.error( "The attachment device is incorrect for " +
2251 "host " + str( mac ) +
2252 ". Expected: " + mappings[ str( mac ) ] +
2253 " Actual: " + device )
2254 hostAttachment = False
2255 else:
2256 hostAttachment = False
2257 except AssertionError:
2258 main.log.exception( "Json object not as expected" )
2259 main.log.error( repr( host ) )
2260 hostAttachment = False
2261 else:
2262 main.log.error( "No hosts json output or \"Error\"" +
2263 " in output. hosts = " +
2264 repr( hosts[ controller ] ) )
2265 if zeroHosts is False:
2266 hostAttachment = True
2267
2268 # END CHECKING HOST ATTACHMENT POINTS
2269 devicesResults = devicesResults and currentDevicesResult
2270 linksResults = linksResults and currentLinksResult
2271 hostsResults = hostsResults and currentHostsResult
2272 hostAttachmentResults = hostAttachmentResults and\
2273 hostAttachment
2274 topoResult = ( devicesResults and linksResults
2275 and hostsResults and ipResult and
2276 hostAttachmentResults )
2277
2278 # Compare json objects for hosts and dataplane clusters
2279
2280 # hosts
2281 main.step( "Hosts view is consistent across all ONOS nodes" )
2282 consistentHostsResult = main.TRUE
2283 for controller in range( len( hosts ) ):
2284 controllerStr = str( controller + 1 )
2285 if "Error" not in hosts[ controller ]:
2286 if hosts[ controller ] == hosts[ 0 ]:
2287 continue
2288 else: # hosts not consistent
2289 main.log.error( "hosts from ONOS" + controllerStr +
2290 " is inconsistent with ONOS1" )
2291 main.log.warn( repr( hosts[ controller ] ) )
2292 consistentHostsResult = main.FALSE
2293
2294 else:
2295 main.log.error( "Error in getting ONOS hosts from ONOS" +
2296 controllerStr )
2297 consistentHostsResult = main.FALSE
2298 main.log.warn( "ONOS" + controllerStr +
2299 " hosts response: " +
2300 repr( hosts[ controller ] ) )
2301 utilities.assert_equals(
2302 expect=main.TRUE,
2303 actual=consistentHostsResult,
2304 onpass="Hosts view is consistent across all ONOS nodes",
2305 onfail="ONOS nodes have different views of hosts" )
2306
2307 main.step( "Hosts information is correct" )
2308 hostsResults = hostsResults and ipResult
2309 utilities.assert_equals(
2310 expect=main.TRUE,
2311 actual=hostsResults,
2312 onpass="Host information is correct",
2313 onfail="Host information is incorrect" )
2314
2315 main.step( "Host attachment points to the network" )
2316 utilities.assert_equals(
2317 expect=True,
2318 actual=hostAttachmentResults,
2319 onpass="Hosts are correctly attached to the network",
2320 onfail="ONOS did not correctly attach hosts to the network" )
2321
2322 # Strongly connected clusters of devices
2323 main.step( "Clusters view is consistent across all ONOS nodes" )
2324 consistentClustersResult = main.TRUE
2325 for controller in range( len( clusters ) ):
2326 controllerStr = str( controller + 1 )
2327 if "Error" not in clusters[ controller ]:
2328 if clusters[ controller ] == clusters[ 0 ]:
2329 continue
2330 else: # clusters not consistent
2331 main.log.error( "clusters from ONOS" +
2332 controllerStr +
2333 " is inconsistent with ONOS1" )
2334 consistentClustersResult = main.FALSE
2335
2336 else:
2337 main.log.error( "Error in getting dataplane clusters " +
2338 "from ONOS" + controllerStr )
2339 consistentClustersResult = main.FALSE
2340 main.log.warn( "ONOS" + controllerStr +
2341 " clusters response: " +
2342 repr( clusters[ controller ] ) )
2343 utilities.assert_equals(
2344 expect=main.TRUE,
2345 actual=consistentClustersResult,
2346 onpass="Clusters view is consistent across all ONOS nodes",
2347 onfail="ONOS nodes have different views of clusters" )
2348
2349 main.step( "There is only one SCC" )
2350 # there should always only be one cluster
2351 try:
2352 numClusters = len( json.loads( clusters[ 0 ] ) )
2353 except ( ValueError, TypeError ):
2354 main.log.exception( "Error parsing clusters[0]: " +
2355 repr( clusters[0] ) )
2356 clusterResults = main.FALSE
2357 if numClusters == 1:
2358 clusterResults = main.TRUE
2359 utilities.assert_equals(
2360 expect=1,
2361 actual=numClusters,
2362 onpass="ONOS shows 1 SCC",
2363 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
2364
2365 topoResult = ( devicesResults and linksResults
2366 and hostsResults and consistentHostsResult
2367 and consistentClustersResult and clusterResults
2368 and ipResult and hostAttachmentResults )
2369
2370 topoResult = topoResult and int( count <= 2 )
2371 note = "note it takes about " + str( int( cliTime ) ) + \
2372 " seconds for the test to make all the cli calls to fetch " +\
2373 "the topology from each ONOS instance"
2374 main.log.info(
2375 "Very crass estimate for topology discovery/convergence( " +
2376 str( note ) + " ): " + str( elapsed ) + " seconds, " +
2377 str( count ) + " tries" )
2378
2379 main.step( "Device information is correct" )
2380 utilities.assert_equals(
2381 expect=main.TRUE,
2382 actual=devicesResults,
2383 onpass="Device information is correct",
2384 onfail="Device information is incorrect" )
2385
2386 main.step( "Links are correct" )
2387 utilities.assert_equals(
2388 expect=main.TRUE,
2389 actual=linksResults,
2390 onpass="Link are correct",
2391 onfail="Links are incorrect" )
2392
2393 main.step( "Hosts are correct" )
2394 utilities.assert_equals(
2395 expect=main.TRUE,
2396 actual=hostsResults,
2397 onpass="Hosts are correct",
2398 onfail="Hosts are incorrect" )
2399
2400 # FIXME: move this to an ONOS state case
2401 main.step( "Checking ONOS nodes" )
2402 nodesOutput = []
2403 nodeResults = main.TRUE
2404 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002405 for i in range( main.numCtrls ):
2406 t = main.Thread( target=main.CLIs[i].nodes,
Jon Hall5cf14d52015-07-16 12:15:19 -07002407 name="nodes-" + str( i ),
2408 args=[ ] )
2409 threads.append( t )
2410 t.start()
2411
2412 for t in threads:
2413 t.join()
2414 nodesOutput.append( t.result )
Jon Halle1a3b752015-07-22 13:02:46 -07002415 ips = [ node.ip_address for node in main.nodes ]
Jon Hall5cf14d52015-07-16 12:15:19 -07002416 for i in nodesOutput:
2417 try:
2418 current = json.loads( i )
2419 for node in current:
2420 currentResult = main.FALSE
2421 if node['ip'] in ips: # node in nodes() output is in cell
2422 if node['state'] == 'ACTIVE':
2423 currentResult = main.TRUE
2424 else:
2425 main.log.error( "Error in ONOS node availability" )
2426 main.log.error(
2427 json.dumps( current,
2428 sort_keys=True,
2429 indent=4,
2430 separators=( ',', ': ' ) ) )
2431 break
2432 nodeResults = nodeResults and currentResult
2433 except ( ValueError, TypeError ):
2434 main.log.error( "Error parsing nodes output" )
2435 main.log.warn( repr( i ) )
2436 utilities.assert_equals( expect=main.TRUE, actual=nodeResults,
2437 onpass="Nodes check successful",
2438 onfail="Nodes check NOT successful" )
2439
2440 def CASE9( self, main ):
2441 """
2442 Link s3-s28 down
2443 """
2444 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002445 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002446 assert main, "main not defined"
2447 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002448 assert main.CLIs, "main.CLIs not defined"
2449 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002450 # NOTE: You should probably run a topology check after this
2451
2452 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
2453
2454 description = "Turn off a link to ensure that Link Discovery " +\
2455 "is working properly"
2456 main.case( description )
2457
2458 main.step( "Kill Link between s3 and s28" )
2459 LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" )
2460 main.log.info( "Waiting " + str( linkSleep ) +
2461 " seconds for link down to be discovered" )
2462 time.sleep( linkSleep )
2463 utilities.assert_equals( expect=main.TRUE, actual=LinkDown,
2464 onpass="Link down successful",
2465 onfail="Failed to bring link down" )
2466 # TODO do some sort of check here
2467
2468 def CASE10( self, main ):
2469 """
2470 Link s3-s28 up
2471 """
2472 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002473 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002474 assert main, "main not defined"
2475 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002476 assert main.CLIs, "main.CLIs not defined"
2477 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002478 # NOTE: You should probably run a topology check after this
2479
2480 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
2481
2482 description = "Restore a link to ensure that Link Discovery is " + \
2483 "working properly"
2484 main.case( description )
2485
2486 main.step( "Bring link between s3 and s28 back up" )
2487 LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" )
2488 main.log.info( "Waiting " + str( linkSleep ) +
2489 " seconds for link up to be discovered" )
2490 time.sleep( linkSleep )
2491 utilities.assert_equals( expect=main.TRUE, actual=LinkUp,
2492 onpass="Link up successful",
2493 onfail="Failed to bring link up" )
2494 # TODO do some sort of check here
2495
2496 def CASE11( self, main ):
2497 """
2498 Switch Down
2499 """
2500 # NOTE: You should probably run a topology check after this
2501 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002502 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002503 assert main, "main not defined"
2504 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002505 assert main.CLIs, "main.CLIs not defined"
2506 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002507
2508 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
2509
2510 description = "Killing a switch to ensure it is discovered correctly"
2511 main.case( description )
2512 switch = main.params[ 'kill' ][ 'switch' ]
2513 switchDPID = main.params[ 'kill' ][ 'dpid' ]
2514
2515 # TODO: Make this switch parameterizable
2516 main.step( "Kill " + switch )
2517 main.log.info( "Deleting " + switch )
2518 main.Mininet1.delSwitch( switch )
2519 main.log.info( "Waiting " + str( switchSleep ) +
2520 " seconds for switch down to be discovered" )
2521 time.sleep( switchSleep )
2522 device = main.ONOScli1.getDevice( dpid=switchDPID )
2523 # Peek at the deleted switch
2524 main.log.warn( str( device ) )
2525 result = main.FALSE
2526 if device and device[ 'available' ] is False:
2527 result = main.TRUE
2528 utilities.assert_equals( expect=main.TRUE, actual=result,
2529 onpass="Kill switch successful",
2530 onfail="Failed to kill switch?" )
2531
2532 def CASE12( self, main ):
2533 """
2534 Switch Up
2535 """
2536 # NOTE: You should probably run a topology check after this
2537 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002538 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002539 assert main, "main not defined"
2540 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002541 assert main.CLIs, "main.CLIs not defined"
2542 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002543 assert ONOS1Port, "ONOS1Port not defined"
2544 assert ONOS2Port, "ONOS2Port not defined"
2545 assert ONOS3Port, "ONOS3Port not defined"
2546 assert ONOS4Port, "ONOS4Port not defined"
2547 assert ONOS5Port, "ONOS5Port not defined"
2548 assert ONOS6Port, "ONOS6Port not defined"
2549 assert ONOS7Port, "ONOS7Port not defined"
2550
2551 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
2552 switch = main.params[ 'kill' ][ 'switch' ]
2553 switchDPID = main.params[ 'kill' ][ 'dpid' ]
2554 links = main.params[ 'kill' ][ 'links' ].split()
2555 description = "Adding a switch to ensure it is discovered correctly"
2556 main.case( description )
2557
2558 main.step( "Add back " + switch )
2559 main.Mininet1.addSwitch( switch, dpid=switchDPID )
2560 for peer in links:
2561 main.Mininet1.addLink( switch, peer )
2562 ipList = []
Jon Halle1a3b752015-07-22 13:02:46 -07002563 for i in range( main.numCtrls ):
2564 ipList.append( main.nodes[ i ].ip_address )
Jon Hall5cf14d52015-07-16 12:15:19 -07002565 main.Mininet1.assignSwController( sw=switch, ip=ipList )
2566 main.log.info( "Waiting " + str( switchSleep ) +
2567 " seconds for switch up to be discovered" )
2568 time.sleep( switchSleep )
2569 device = main.ONOScli1.getDevice( dpid=switchDPID )
2570 # Peek at the deleted switch
2571 main.log.warn( str( device ) )
2572 result = main.FALSE
2573 if device and device[ 'available' ]:
2574 result = main.TRUE
2575 utilities.assert_equals( expect=main.TRUE, actual=result,
2576 onpass="add switch successful",
2577 onfail="Failed to add switch?" )
2578
2579 def CASE13( self, main ):
2580 """
2581 Clean up
2582 """
2583 import os
2584 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002585 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002586 assert main, "main not defined"
2587 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002588 assert main.CLIs, "main.CLIs not defined"
2589 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002590
2591 # printing colors to terminal
2592 colors = { 'cyan': '\033[96m', 'purple': '\033[95m',
2593 'blue': '\033[94m', 'green': '\033[92m',
2594 'yellow': '\033[93m', 'red': '\033[91m', 'end': '\033[0m' }
2595 main.case( "Test Cleanup" )
2596 main.step( "Killing tcpdumps" )
2597 main.Mininet2.stopTcpdump()
2598
2599 testname = main.TEST
Jon Hall96091e62015-09-21 17:34:17 -07002600 if main.params[ 'BACKUP' ][ 'ENABLED' ] == "True":
Jon Hall5cf14d52015-07-16 12:15:19 -07002601 main.step( "Copying MN pcap and ONOS log files to test station" )
2602 teststationUser = main.params[ 'BACKUP' ][ 'TESTONUSER' ]
2603 teststationIP = main.params[ 'BACKUP' ][ 'TESTONIP' ]
Jon Hall96091e62015-09-21 17:34:17 -07002604 # NOTE: MN Pcap file is being saved to logdir.
2605 # We scp this file as MN and TestON aren't necessarily the same vm
2606
2607 # FIXME: To be replaced with a Jenkin's post script
Jon Hall5cf14d52015-07-16 12:15:19 -07002608 # TODO: Load these from params
2609 # NOTE: must end in /
2610 logFolder = "/opt/onos/log/"
2611 logFiles = [ "karaf.log", "karaf.log.1" ]
2612 # NOTE: must end in /
Jon Hall5cf14d52015-07-16 12:15:19 -07002613 for f in logFiles:
Jon Halle1a3b752015-07-22 13:02:46 -07002614 for node in main.nodes:
Jon Hall96091e62015-09-21 17:34:17 -07002615 dstName = main.logdir + "/" + node.name + "-" + f
2616 main.ONOSbench.secureCopy( node.user_name, node.ip_address,
2617 logFolder + f, dstName )
Jon Hall5cf14d52015-07-16 12:15:19 -07002618 # std*.log's
2619 # NOTE: must end in /
2620 logFolder = "/opt/onos/var/"
2621 logFiles = [ "stderr.log", "stdout.log" ]
2622 # NOTE: must end in /
Jon Hall5cf14d52015-07-16 12:15:19 -07002623 for f in logFiles:
Jon Halle1a3b752015-07-22 13:02:46 -07002624 for node in main.nodes:
Jon Hall96091e62015-09-21 17:34:17 -07002625 dstName = main.logdir + "/" + node.name + "-" + f
2626 main.ONOSbench.secureCopy( node.user_name, node.ip_address,
2627 logFolder + f, dstName )
2628 else:
2629 main.log.debug( "skipping saving log files" )
Jon Hall5cf14d52015-07-16 12:15:19 -07002630
2631 main.step( "Stopping Mininet" )
2632 mnResult = main.Mininet1.stopNet()
2633 utilities.assert_equals( expect=main.TRUE, actual=mnResult,
2634 onpass="Mininet stopped",
2635 onfail="MN cleanup NOT successful" )
2636
2637 main.step( "Checking ONOS Logs for errors" )
Jon Halle1a3b752015-07-22 13:02:46 -07002638 for node in main.nodes:
Jon Hall96091e62015-09-21 17:34:17 -07002639 main.log.debug( "Checking logs for errors on " + node.name + ":" )
2640 main.log.warn( main.ONOSbench.checkLogs( node.ip_address ) )
Jon Hall5cf14d52015-07-16 12:15:19 -07002641
2642 try:
2643 timerLog = open( main.logdir + "/Timers.csv", 'w')
2644 # Overwrite with empty line and close
2645 labels = "Gossip Intents"
2646 data = str( gossipTime )
2647 timerLog.write( labels + "\n" + data )
2648 timerLog.close()
2649 except NameError, e:
2650 main.log.exception(e)
2651
2652 def CASE14( self, main ):
2653 """
2654 start election app on all onos nodes
2655 """
Jon Halle1a3b752015-07-22 13:02:46 -07002656 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002657 assert main, "main not defined"
2658 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002659 assert main.CLIs, "main.CLIs not defined"
2660 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002661
2662 main.case("Start Leadership Election app")
2663 main.step( "Install leadership election app" )
2664 appResult = main.ONOScli1.activateApp( "org.onosproject.election" )
2665 utilities.assert_equals(
2666 expect=main.TRUE,
2667 actual=appResult,
2668 onpass="Election app installed",
2669 onfail="Something went wrong with installing Leadership election" )
2670
2671 main.step( "Run for election on each node" )
2672 leaderResult = main.TRUE
2673 leaders = []
Jon Halle1a3b752015-07-22 13:02:46 -07002674 for cli in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -07002675 cli.electionTestRun()
Jon Halle1a3b752015-07-22 13:02:46 -07002676 for cli in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -07002677 leader = cli.electionTestLeader()
2678 if leader is None or leader == main.FALSE:
2679 main.log.error( cli.name + ": Leader for the election app " +
2680 "should be an ONOS node, instead got '" +
2681 str( leader ) + "'" )
2682 leaderResult = main.FALSE
2683 leaders.append( leader )
2684 utilities.assert_equals(
2685 expect=main.TRUE,
2686 actual=leaderResult,
2687 onpass="Successfully ran for leadership",
2688 onfail="Failed to run for leadership" )
2689
2690 main.step( "Check that each node shows the same leader" )
2691 sameLeader = main.TRUE
2692 if len( set( leaders ) ) != 1:
2693 sameLeader = main.FALSE
Jon Halle1a3b752015-07-22 13:02:46 -07002694 main.log.error( "Results of electionTestLeader is order of main.CLIs:" +
Jon Hall5cf14d52015-07-16 12:15:19 -07002695 str( leaders ) )
2696 utilities.assert_equals(
2697 expect=main.TRUE,
2698 actual=sameLeader,
2699 onpass="Leadership is consistent for the election topic",
2700 onfail="Nodes have different leaders" )
2701
2702 def CASE15( self, main ):
2703 """
2704 Check that Leadership Election is still functional
acsmars71adceb2015-08-31 15:09:26 -07002705 15.1 Run election on each node
2706 15.2 Check that each node has the same leaders and candidates
2707 15.3 Find current leader and withdraw
2708 15.4 Check that a new node was elected leader
2709 15.5 Check that that new leader was the candidate of old leader
2710 15.6 Run for election on old leader
2711 15.7 Check that oldLeader is a candidate, and leader if only 1 node
2712 15.8 Make sure that the old leader was added to the candidate list
2713
2714 old and new variable prefixes refer to data from before vs after
2715 withdrawl and later before withdrawl vs after re-election
Jon Hall5cf14d52015-07-16 12:15:19 -07002716 """
2717 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002718 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002719 assert main, "main not defined"
2720 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002721 assert main.CLIs, "main.CLIs not defined"
2722 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002723
acsmars3a72bde2015-09-02 14:16:22 -07002724 description = "Check that Leadership Election App is still functional"
Jon Hall5cf14d52015-07-16 12:15:19 -07002725 main.case( description )
acsmars71adceb2015-08-31 15:09:26 -07002726 # NOTE: Need to re-run since being a canidate is not persistant
2727 # TODO: add check for "Command not found:" in the driver, this
2728 # means the election test app isn't loaded
Jon Hall5cf14d52015-07-16 12:15:19 -07002729
acsmars71adceb2015-08-31 15:09:26 -07002730 oldLeaders = [] # leaders by node before withdrawl from candidates
2731 newLeaders = [] # leaders by node after withdrawl from candidates
2732 oldAllCandidates = [] # list of lists of each nodes' candidates before
2733 newAllCandidates = [] # list of lists of each nodes' candidates after
2734 oldCandidates = [] # list of candidates from node 0 before withdrawl
2735 newCandidates = [] # list of candidates from node 0 after withdrawl
2736 oldLeader = '' # the old leader from oldLeaders, None if not same
2737 newLeader = '' # the new leaders fron newLoeaders, None if not same
2738 oldLeaderCLI = None # the CLI of the old leader used for re-electing
2739 expectNoLeader = False # True when there is only one leader
2740 if main.numCtrls == 1:
2741 expectNoLeader = True
2742
2743 main.step( "Run for election on each node" )
2744 electionResult = main.TRUE
2745
2746 for cli in main.CLIs: # run test election on each node
2747 if cli.electionTestRun() == main.FALSE:
2748 electionResult = main.FALSE
2749
Jon Hall5cf14d52015-07-16 12:15:19 -07002750 utilities.assert_equals(
2751 expect=main.TRUE,
acsmars71adceb2015-08-31 15:09:26 -07002752 actual=electionResult,
2753 onpass="All nodes successfully ran for leadership",
2754 onfail="At least one node failed to run for leadership" )
2755
acsmars3a72bde2015-09-02 14:16:22 -07002756 if electionResult == main.FALSE:
2757 main.log.error(
2758 "Skipping Test Case because Election Test isn't loaded" )
2759 main.skipCase()
2760
acsmars71adceb2015-08-31 15:09:26 -07002761 main.step( "Check that each node shows the same leader and candidates" )
2762 sameResult = main.TRUE
2763 failMessage = "Nodes have different leaders"
2764 for cli in main.CLIs:
2765 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
2766 oldAllCandidates.append( node )
2767 oldLeaders.append( node[ 0 ] )
2768 oldCandidates = oldAllCandidates[ 0 ]
2769
2770 # Check that each node has the same leader. Defines oldLeader
2771 if len( set( oldLeaders ) ) != 1:
2772 sameResult = main.FALSE
2773 main.log.error( "More than one leader present:" + str( oldLeaders ) )
2774 oldLeader = None
2775 else:
2776 oldLeader = oldLeaders[ 0 ]
2777
2778 # Check that each node's candidate list is the same
acsmars29233db2015-11-04 11:15:00 -08002779 candidateDiscrepancy = False # Boolean of candidate mismatches
acsmars71adceb2015-08-31 15:09:26 -07002780 for candidates in oldAllCandidates:
2781 if set( candidates ) != set( oldCandidates ):
2782 sameResult = main.FALSE
acsmars29233db2015-11-04 11:15:00 -08002783 candidateDiscrepancy = True
2784
2785 if candidateDiscrepancy:
2786 failMessage += " and candidates"
acsmars71adceb2015-08-31 15:09:26 -07002787
2788 utilities.assert_equals(
2789 expect=main.TRUE,
2790 actual=sameResult,
Jon Hall5cf14d52015-07-16 12:15:19 -07002791 onpass="Leadership is consistent for the election topic",
acsmars71adceb2015-08-31 15:09:26 -07002792 onfail=failMessage )
Jon Hall5cf14d52015-07-16 12:15:19 -07002793
2794 main.step( "Find current leader and withdraw" )
acsmars71adceb2015-08-31 15:09:26 -07002795 withdrawResult = main.TRUE
Jon Hall5cf14d52015-07-16 12:15:19 -07002796 # do some sanity checking on leader before using it
acsmars71adceb2015-08-31 15:09:26 -07002797 if oldLeader is None:
2798 main.log.error( "Leadership isn't consistent." )
2799 withdrawResult = main.FALSE
2800 # Get the CLI of the oldLeader
Jon Halle1a3b752015-07-22 13:02:46 -07002801 for i in range( len( main.CLIs ) ):
acsmars71adceb2015-08-31 15:09:26 -07002802 if oldLeader == main.nodes[ i ].ip_address:
2803 oldLeaderCLI = main.CLIs[ i ]
Jon Hall5cf14d52015-07-16 12:15:19 -07002804 break
2805 else: # FOR/ELSE statement
2806 main.log.error( "Leader election, could not find current leader" )
2807 if oldLeader:
acsmars71adceb2015-08-31 15:09:26 -07002808 withdrawResult = oldLeaderCLI.electionTestWithdraw()
Jon Hall5cf14d52015-07-16 12:15:19 -07002809 utilities.assert_equals(
2810 expect=main.TRUE,
2811 actual=withdrawResult,
2812 onpass="Node was withdrawn from election",
2813 onfail="Node was not withdrawn from election" )
2814
acsmars71adceb2015-08-31 15:09:26 -07002815 main.step( "Check that a new node was elected leader" )
2816
Jon Hall5cf14d52015-07-16 12:15:19 -07002817 # FIXME: use threads
acsmars71adceb2015-08-31 15:09:26 -07002818 newLeaderResult = main.TRUE
2819 failMessage = "Nodes have different leaders"
2820
2821 # Get new leaders and candidates
Jon Halle1a3b752015-07-22 13:02:46 -07002822 for cli in main.CLIs:
acsmars71adceb2015-08-31 15:09:26 -07002823 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
2824 # elections might no have finished yet
2825 if node[ 0 ] == 'none' and not expectNoLeader:
2826 main.log.info( "Node has no leader, waiting 5 seconds to be " +
2827 "sure elections are complete." )
2828 time.sleep(5)
2829 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
2830 # election still isn't done or there is a problem
2831 if node[ 0 ] == 'none':
2832 main.log.error( "No leader was elected on at least 1 node" )
2833 newLeaderResult = main.FALSE
2834 newAllCandidates.append( node )
2835 newLeaders.append( node[ 0 ] )
2836 newCandidates = newAllCandidates[ 0 ]
2837
2838 # Check that each node has the same leader. Defines newLeader
2839 if len( set( newLeaders ) ) != 1:
2840 newLeaderResult = main.FALSE
2841 main.log.error( "Nodes have different leaders: " +
2842 str( newLeaders ) )
2843 newLeader = None
Jon Hall5cf14d52015-07-16 12:15:19 -07002844 else:
acsmars71adceb2015-08-31 15:09:26 -07002845 newLeader = newLeaders[ 0 ]
2846
2847 # Check that each node's candidate list is the same
2848 for candidates in newAllCandidates:
2849 if set( candidates ) != set( newCandidates ):
2850 newLeaderResult = main.FALSE
Jon Hallceb4abb2015-09-25 12:03:06 -07002851 main.log.error( "Discrepancy in candidate lists detected" )
acsmars71adceb2015-08-31 15:09:26 -07002852
2853 # Check that the new leader is not the older leader, which was withdrawn
2854 if newLeader == oldLeader:
2855 newLeaderResult = main.FALSE
2856 main.log.error( "All nodes still see old leader: " + oldLeader +
2857 " as the current leader" )
2858
Jon Hall5cf14d52015-07-16 12:15:19 -07002859 utilities.assert_equals(
2860 expect=main.TRUE,
acsmars71adceb2015-08-31 15:09:26 -07002861 actual=newLeaderResult,
Jon Hall5cf14d52015-07-16 12:15:19 -07002862 onpass="Leadership election passed",
2863 onfail="Something went wrong with Leadership election" )
2864
acsmars71adceb2015-08-31 15:09:26 -07002865 main.step( "Check that that new leader was the candidate of old leader")
2866 # candidates[ 2 ] should be come the top candidate after withdrawl
2867 correctCandidateResult = main.TRUE
2868 if expectNoLeader:
2869 if newLeader == 'none':
2870 main.log.info( "No leader expected. None found. Pass" )
2871 correctCandidateResult = main.TRUE
2872 else:
2873 main.log.info( "Expected no leader, got: " + str( newLeader ) )
2874 correctCandidateResult = main.FALSE
2875 elif newLeader != oldCandidates[ 2 ]:
2876 correctCandidateResult = main.FALSE
2877 main.log.error( "Candidate " + newLeader + " was elected. " +
2878 oldCandidates[ 2 ] + " should have had priority." )
2879
2880 utilities.assert_equals(
2881 expect=main.TRUE,
2882 actual=correctCandidateResult,
2883 onpass="Correct Candidate Elected",
2884 onfail="Incorrect Candidate Elected" )
2885
Jon Hall5cf14d52015-07-16 12:15:19 -07002886 main.step( "Run for election on old leader( just so everyone " +
2887 "is in the hat )" )
acsmars71adceb2015-08-31 15:09:26 -07002888 if oldLeaderCLI is not None:
2889 runResult = oldLeaderCLI.electionTestRun()
Jon Hall5cf14d52015-07-16 12:15:19 -07002890 else:
acsmars71adceb2015-08-31 15:09:26 -07002891 main.log.error( "No old leader to re-elect" )
Jon Hall5cf14d52015-07-16 12:15:19 -07002892 runResult = main.FALSE
2893 utilities.assert_equals(
2894 expect=main.TRUE,
2895 actual=runResult,
2896 onpass="App re-ran for election",
2897 onfail="App failed to run for election" )
acsmars71adceb2015-08-31 15:09:26 -07002898 main.step(
2899 "Check that oldLeader is a candidate, and leader if only 1 node" )
Jon Hall5cf14d52015-07-16 12:15:19 -07002900 # verify leader didn't just change
acsmars71adceb2015-08-31 15:09:26 -07002901 positionResult = main.TRUE
2902 # Get new leaders and candidates, wait if oldLeader is not a candidate yet
2903
2904 # Reset and reuse the new candidate and leaders lists
2905 newAllCandidates = []
2906 newCandidates = []
2907 newLeaders = []
2908 for cli in main.CLIs:
2909 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
2910 if oldLeader not in node: # election might no have finished yet
2911 main.log.info( "Old Leader not elected, waiting 5 seconds to " +
2912 "be sure elections are complete" )
2913 time.sleep(5)
2914 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
2915 if oldLeader not in node: # election still isn't done, errors
2916 main.log.error(
2917 "Old leader was not elected on at least one node" )
2918 positionResult = main.FALSE
2919 newAllCandidates.append( node )
2920 newLeaders.append( node[ 0 ] )
2921 newCandidates = newAllCandidates[ 0 ]
2922
2923 # Check that each node has the same leader. Defines newLeader
2924 if len( set( newLeaders ) ) != 1:
2925 positionResult = main.FALSE
2926 main.log.error( "Nodes have different leaders: " +
2927 str( newLeaders ) )
2928 newLeader = None
Jon Hall5cf14d52015-07-16 12:15:19 -07002929 else:
acsmars71adceb2015-08-31 15:09:26 -07002930 newLeader = newLeaders[ 0 ]
2931
2932 # Check that each node's candidate list is the same
2933 for candidates in newAllCandidates:
2934 if set( candidates ) != set( newCandidates ):
2935 newLeaderResult = main.FALSE
Jon Hallceb4abb2015-09-25 12:03:06 -07002936 main.log.error( "Discrepancy in candidate lists detected" )
acsmars71adceb2015-08-31 15:09:26 -07002937
2938 # Check that the re-elected node is last on the candidate List
2939 if oldLeader != newCandidates[ -1 ]:
2940 main.log.error( "Old Leader (" + oldLeader + ") not in the proper position " +
2941 str( newCandidates ) )
2942 positionResult = main.FALSE
Jon Hall5cf14d52015-07-16 12:15:19 -07002943
2944 utilities.assert_equals(
2945 expect=main.TRUE,
acsmars71adceb2015-08-31 15:09:26 -07002946 actual=positionResult,
Jon Hall5cf14d52015-07-16 12:15:19 -07002947 onpass="Old leader successfully re-ran for election",
2948 onfail="Something went wrong with Leadership election after " +
2949 "the old leader re-ran for election" )
2950
2951 def CASE16( self, main ):
2952 """
2953 Install Distributed Primitives app
2954 """
2955 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002956 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002957 assert main, "main not defined"
2958 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002959 assert main.CLIs, "main.CLIs not defined"
2960 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002961
2962 # Variables for the distributed primitives tests
2963 global pCounterName
2964 global iCounterName
2965 global pCounterValue
2966 global iCounterValue
2967 global onosSet
2968 global onosSetName
2969 pCounterName = "TestON-Partitions"
2970 iCounterName = "TestON-inMemory"
2971 pCounterValue = 0
2972 iCounterValue = 0
2973 onosSet = set([])
2974 onosSetName = "TestON-set"
2975
2976 description = "Install Primitives app"
2977 main.case( description )
2978 main.step( "Install Primitives app" )
2979 appName = "org.onosproject.distributedprimitives"
Jon Halle1a3b752015-07-22 13:02:46 -07002980 appResults = main.CLIs[0].activateApp( appName )
Jon Hall5cf14d52015-07-16 12:15:19 -07002981 utilities.assert_equals( expect=main.TRUE,
2982 actual=appResults,
2983 onpass="Primitives app activated",
2984 onfail="Primitives app not activated" )
2985 time.sleep( 5 ) # To allow all nodes to activate
2986
2987 def CASE17( self, main ):
2988 """
2989 Check for basic functionality with distributed primitives
2990 """
Jon Hall5cf14d52015-07-16 12:15:19 -07002991 # Make sure variables are defined/set
Jon Halle1a3b752015-07-22 13:02:46 -07002992 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002993 assert main, "main not defined"
2994 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002995 assert main.CLIs, "main.CLIs not defined"
2996 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002997 assert pCounterName, "pCounterName not defined"
2998 assert iCounterName, "iCounterName not defined"
2999 assert onosSetName, "onosSetName not defined"
3000 # NOTE: assert fails if value is 0/None/Empty/False
3001 try:
3002 pCounterValue
3003 except NameError:
3004 main.log.error( "pCounterValue not defined, setting to 0" )
3005 pCounterValue = 0
3006 try:
3007 iCounterValue
3008 except NameError:
3009 main.log.error( "iCounterValue not defined, setting to 0" )
3010 iCounterValue = 0
3011 try:
3012 onosSet
3013 except NameError:
3014 main.log.error( "onosSet not defined, setting to empty Set" )
3015 onosSet = set([])
3016 # Variables for the distributed primitives tests. These are local only
3017 addValue = "a"
3018 addAllValue = "a b c d e f"
3019 retainValue = "c d e f"
3020
3021 description = "Check for basic functionality with distributed " +\
3022 "primitives"
3023 main.case( description )
Jon Halle1a3b752015-07-22 13:02:46 -07003024 main.caseExplanation = "Test the methods of the distributed " +\
3025 "primitives (counters and sets) throught the cli"
Jon Hall5cf14d52015-07-16 12:15:19 -07003026 # DISTRIBUTED ATOMIC COUNTERS
Jon Halle1a3b752015-07-22 13:02:46 -07003027 # Partitioned counters
3028 main.step( "Increment then get a default counter on each node" )
Jon Hall5cf14d52015-07-16 12:15:19 -07003029 pCounters = []
3030 threads = []
3031 addedPValues = []
Jon Halle1a3b752015-07-22 13:02:46 -07003032 for i in range( main.numCtrls ):
3033 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
3034 name="counterAddAndGet-" + str( i ),
Jon Hall5cf14d52015-07-16 12:15:19 -07003035 args=[ pCounterName ] )
3036 pCounterValue += 1
3037 addedPValues.append( pCounterValue )
3038 threads.append( t )
3039 t.start()
3040
3041 for t in threads:
3042 t.join()
3043 pCounters.append( t.result )
3044 # Check that counter incremented numController times
3045 pCounterResults = True
3046 for i in addedPValues:
3047 tmpResult = i in pCounters
3048 pCounterResults = pCounterResults and tmpResult
3049 if not tmpResult:
3050 main.log.error( str( i ) + " is not in partitioned "
3051 "counter incremented results" )
3052 utilities.assert_equals( expect=True,
3053 actual=pCounterResults,
3054 onpass="Default counter incremented",
3055 onfail="Error incrementing default" +
3056 " counter" )
3057
Jon Halle1a3b752015-07-22 13:02:46 -07003058 main.step( "Get then Increment a default counter on each node" )
3059 pCounters = []
3060 threads = []
3061 addedPValues = []
3062 for i in range( main.numCtrls ):
3063 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
3064 name="counterGetAndAdd-" + str( i ),
3065 args=[ pCounterName ] )
3066 addedPValues.append( pCounterValue )
3067 pCounterValue += 1
3068 threads.append( t )
3069 t.start()
3070
3071 for t in threads:
3072 t.join()
3073 pCounters.append( t.result )
3074 # Check that counter incremented numController times
3075 pCounterResults = True
3076 for i in addedPValues:
3077 tmpResult = i in pCounters
3078 pCounterResults = pCounterResults and tmpResult
3079 if not tmpResult:
3080 main.log.error( str( i ) + " is not in partitioned "
3081 "counter incremented results" )
3082 utilities.assert_equals( expect=True,
3083 actual=pCounterResults,
3084 onpass="Default counter incremented",
3085 onfail="Error incrementing default" +
3086 " counter" )
3087
3088 main.step( "Counters we added have the correct values" )
3089 incrementCheck = main.Counters.counterCheck( pCounterName, pCounterValue )
3090 utilities.assert_equals( expect=main.TRUE,
3091 actual=incrementCheck,
3092 onpass="Added counters are correct",
3093 onfail="Added counters are incorrect" )
3094
3095 main.step( "Add -8 to then get a default counter on each node" )
3096 pCounters = []
3097 threads = []
3098 addedPValues = []
3099 for i in range( main.numCtrls ):
3100 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
3101 name="counterIncrement-" + str( i ),
3102 args=[ pCounterName ],
3103 kwargs={ "delta": -8 } )
3104 pCounterValue += -8
3105 addedPValues.append( pCounterValue )
3106 threads.append( t )
3107 t.start()
3108
3109 for t in threads:
3110 t.join()
3111 pCounters.append( t.result )
3112 # Check that counter incremented numController times
3113 pCounterResults = True
3114 for i in addedPValues:
3115 tmpResult = i in pCounters
3116 pCounterResults = pCounterResults and tmpResult
3117 if not tmpResult:
3118 main.log.error( str( i ) + " is not in partitioned "
3119 "counter incremented results" )
3120 utilities.assert_equals( expect=True,
3121 actual=pCounterResults,
3122 onpass="Default counter incremented",
3123 onfail="Error incrementing default" +
3124 " counter" )
3125
3126 main.step( "Add 5 to then get a default counter on each node" )
3127 pCounters = []
3128 threads = []
3129 addedPValues = []
3130 for i in range( main.numCtrls ):
3131 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
3132 name="counterIncrement-" + str( i ),
3133 args=[ pCounterName ],
3134 kwargs={ "delta": 5 } )
3135 pCounterValue += 5
3136 addedPValues.append( pCounterValue )
3137 threads.append( t )
3138 t.start()
3139
3140 for t in threads:
3141 t.join()
3142 pCounters.append( t.result )
3143 # Check that counter incremented numController times
3144 pCounterResults = True
3145 for i in addedPValues:
3146 tmpResult = i in pCounters
3147 pCounterResults = pCounterResults and tmpResult
3148 if not tmpResult:
3149 main.log.error( str( i ) + " is not in partitioned "
3150 "counter incremented results" )
3151 utilities.assert_equals( expect=True,
3152 actual=pCounterResults,
3153 onpass="Default counter incremented",
3154 onfail="Error incrementing default" +
3155 " counter" )
3156
3157 main.step( "Get then add 5 to a default counter on each node" )
3158 pCounters = []
3159 threads = []
3160 addedPValues = []
3161 for i in range( main.numCtrls ):
3162 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
3163 name="counterIncrement-" + str( i ),
3164 args=[ pCounterName ],
3165 kwargs={ "delta": 5 } )
3166 addedPValues.append( pCounterValue )
3167 pCounterValue += 5
3168 threads.append( t )
3169 t.start()
3170
3171 for t in threads:
3172 t.join()
3173 pCounters.append( t.result )
3174 # Check that counter incremented numController times
3175 pCounterResults = True
3176 for i in addedPValues:
3177 tmpResult = i in pCounters
3178 pCounterResults = pCounterResults and tmpResult
3179 if not tmpResult:
3180 main.log.error( str( i ) + " is not in partitioned "
3181 "counter incremented results" )
3182 utilities.assert_equals( expect=True,
3183 actual=pCounterResults,
3184 onpass="Default counter incremented",
3185 onfail="Error incrementing default" +
3186 " counter" )
3187
3188 main.step( "Counters we added have the correct values" )
3189 incrementCheck = main.Counters.counterCheck( pCounterName, pCounterValue )
3190 utilities.assert_equals( expect=main.TRUE,
3191 actual=incrementCheck,
3192 onpass="Added counters are correct",
3193 onfail="Added counters are incorrect" )
3194
3195 # In-Memory counters
3196 main.step( "Increment and get an in-memory counter on each node" )
Jon Hall5cf14d52015-07-16 12:15:19 -07003197 iCounters = []
3198 addedIValues = []
3199 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003200 for i in range( main.numCtrls ):
3201 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003202 name="icounterIncrement-" + str( i ),
3203 args=[ iCounterName ],
3204 kwargs={ "inMemory": True } )
3205 iCounterValue += 1
3206 addedIValues.append( iCounterValue )
3207 threads.append( t )
3208 t.start()
3209
3210 for t in threads:
3211 t.join()
3212 iCounters.append( t.result )
3213 # Check that counter incremented numController times
3214 iCounterResults = True
3215 for i in addedIValues:
3216 tmpResult = i in iCounters
3217 iCounterResults = iCounterResults and tmpResult
3218 if not tmpResult:
3219 main.log.error( str( i ) + " is not in the in-memory "
3220 "counter incremented results" )
3221 utilities.assert_equals( expect=True,
3222 actual=iCounterResults,
Jon Halle1a3b752015-07-22 13:02:46 -07003223 onpass="In-memory counter incremented",
3224 onfail="Error incrementing in-memory" +
Jon Hall5cf14d52015-07-16 12:15:19 -07003225 " counter" )
3226
Jon Halle1a3b752015-07-22 13:02:46 -07003227 main.step( "Get then Increment a in-memory counter on each node" )
3228 iCounters = []
3229 threads = []
3230 addedIValues = []
3231 for i in range( main.numCtrls ):
3232 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
3233 name="counterGetAndAdd-" + str( i ),
3234 args=[ iCounterName ],
3235 kwargs={ "inMemory": True } )
3236 addedIValues.append( iCounterValue )
3237 iCounterValue += 1
3238 threads.append( t )
3239 t.start()
3240
3241 for t in threads:
3242 t.join()
3243 iCounters.append( t.result )
3244 # Check that counter incremented numController times
3245 iCounterResults = True
3246 for i in addedIValues:
3247 tmpResult = i in iCounters
3248 iCounterResults = iCounterResults and tmpResult
3249 if not tmpResult:
3250 main.log.error( str( i ) + " is not in in-memory "
3251 "counter incremented results" )
3252 utilities.assert_equals( expect=True,
3253 actual=iCounterResults,
3254 onpass="In-memory counter incremented",
3255 onfail="Error incrementing in-memory" +
3256 " counter" )
3257
3258 main.step( "Counters we added have the correct values" )
3259 incrementCheck = main.Counters.counterCheck( iCounterName, iCounterValue )
3260 utilities.assert_equals( expect=main.TRUE,
3261 actual=incrementCheck,
3262 onpass="Added counters are correct",
3263 onfail="Added counters are incorrect" )
3264
3265 main.step( "Add -8 to then get a in-memory counter on each node" )
3266 iCounters = []
3267 threads = []
3268 addedIValues = []
3269 for i in range( main.numCtrls ):
3270 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
3271 name="counterIncrement-" + str( i ),
3272 args=[ iCounterName ],
3273 kwargs={ "delta": -8, "inMemory": True } )
3274 iCounterValue += -8
3275 addedIValues.append( iCounterValue )
3276 threads.append( t )
3277 t.start()
3278
3279 for t in threads:
3280 t.join()
3281 iCounters.append( t.result )
3282 # Check that counter incremented numController times
3283 iCounterResults = True
3284 for i in addedIValues:
3285 tmpResult = i in iCounters
3286 iCounterResults = iCounterResults and tmpResult
3287 if not tmpResult:
3288 main.log.error( str( i ) + " is not in in-memory "
3289 "counter incremented results" )
3290 utilities.assert_equals( expect=True,
3291 actual=pCounterResults,
3292 onpass="In-memory counter incremented",
3293 onfail="Error incrementing in-memory" +
3294 " counter" )
3295
3296 main.step( "Add 5 to then get a in-memory counter on each node" )
3297 iCounters = []
3298 threads = []
3299 addedIValues = []
3300 for i in range( main.numCtrls ):
3301 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
3302 name="counterIncrement-" + str( i ),
3303 args=[ iCounterName ],
3304 kwargs={ "delta": 5, "inMemory": True } )
3305 iCounterValue += 5
3306 addedIValues.append( iCounterValue )
3307 threads.append( t )
3308 t.start()
3309
3310 for t in threads:
3311 t.join()
3312 iCounters.append( t.result )
3313 # Check that counter incremented numController times
3314 iCounterResults = True
3315 for i in addedIValues:
3316 tmpResult = i in iCounters
3317 iCounterResults = iCounterResults and tmpResult
3318 if not tmpResult:
3319 main.log.error( str( i ) + " is not in in-memory "
3320 "counter incremented results" )
3321 utilities.assert_equals( expect=True,
3322 actual=pCounterResults,
3323 onpass="In-memory counter incremented",
3324 onfail="Error incrementing in-memory" +
3325 " counter" )
3326
3327 main.step( "Get then add 5 to a in-memory counter on each node" )
3328 iCounters = []
3329 threads = []
3330 addedIValues = []
3331 for i in range( main.numCtrls ):
3332 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
3333 name="counterIncrement-" + str( i ),
3334 args=[ iCounterName ],
3335 kwargs={ "delta": 5, "inMemory": True } )
3336 addedIValues.append( iCounterValue )
3337 iCounterValue += 5
3338 threads.append( t )
3339 t.start()
3340
3341 for t in threads:
3342 t.join()
3343 iCounters.append( t.result )
3344 # Check that counter incremented numController times
3345 iCounterResults = True
3346 for i in addedIValues:
3347 tmpResult = i in iCounters
3348 iCounterResults = iCounterResults and tmpResult
3349 if not tmpResult:
3350 main.log.error( str( i ) + " is not in in-memory "
3351 "counter incremented results" )
3352 utilities.assert_equals( expect=True,
3353 actual=iCounterResults,
3354 onpass="In-memory counter incremented",
3355 onfail="Error incrementing in-memory" +
3356 " counter" )
3357
3358 main.step( "Counters we added have the correct values" )
3359 incrementCheck = main.Counters.counterCheck( iCounterName, iCounterValue )
3360 utilities.assert_equals( expect=main.TRUE,
3361 actual=incrementCheck,
3362 onpass="Added counters are correct",
3363 onfail="Added counters are incorrect" )
3364
Jon Hall5cf14d52015-07-16 12:15:19 -07003365 main.step( "Check counters are consistant across nodes" )
Jon Hall57b50432015-10-22 10:20:10 -07003366 onosCounters, consistentCounterResults = main.Counters.consistentCheck()
Jon Hall5cf14d52015-07-16 12:15:19 -07003367 utilities.assert_equals( expect=main.TRUE,
3368 actual=consistentCounterResults,
3369 onpass="ONOS counters are consistent " +
3370 "across nodes",
3371 onfail="ONOS Counters are inconsistent " +
3372 "across nodes" )
3373
3374 main.step( "Counters we added have the correct values" )
Jon Halle1a3b752015-07-22 13:02:46 -07003375 incrementCheck = main.Counters.counterCheck( iCounterName, iCounterValue )
3376 incrementCheck = incrementCheck and \
3377 main.Counters.counterCheck( iCounterName, iCounterValue )
Jon Hall5cf14d52015-07-16 12:15:19 -07003378 utilities.assert_equals( expect=main.TRUE,
Jon Halle1a3b752015-07-22 13:02:46 -07003379 actual=incrementCheck,
Jon Hall5cf14d52015-07-16 12:15:19 -07003380 onpass="Added counters are correct",
3381 onfail="Added counters are incorrect" )
3382 # DISTRIBUTED SETS
3383 main.step( "Distributed Set get" )
3384 size = len( onosSet )
3385 getResponses = []
3386 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003387 for i in range( main.numCtrls ):
3388 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003389 name="setTestGet-" + str( i ),
3390 args=[ onosSetName ] )
3391 threads.append( t )
3392 t.start()
3393 for t in threads:
3394 t.join()
3395 getResponses.append( t.result )
3396
3397 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003398 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003399 if isinstance( getResponses[ i ], list):
3400 current = set( getResponses[ i ] )
3401 if len( current ) == len( getResponses[ i ] ):
3402 # no repeats
3403 if onosSet != current:
3404 main.log.error( "ONOS" + str( i + 1 ) +
3405 " has incorrect view" +
3406 " of set " + onosSetName + ":\n" +
3407 str( getResponses[ i ] ) )
3408 main.log.debug( "Expected: " + str( onosSet ) )
3409 main.log.debug( "Actual: " + str( current ) )
3410 getResults = main.FALSE
3411 else:
3412 # error, set is not a set
3413 main.log.error( "ONOS" + str( i + 1 ) +
3414 " has repeat elements in" +
3415 " set " + onosSetName + ":\n" +
3416 str( getResponses[ i ] ) )
3417 getResults = main.FALSE
3418 elif getResponses[ i ] == main.ERROR:
3419 getResults = main.FALSE
3420 utilities.assert_equals( expect=main.TRUE,
3421 actual=getResults,
3422 onpass="Set elements are correct",
3423 onfail="Set elements are incorrect" )
3424
3425 main.step( "Distributed Set size" )
3426 sizeResponses = []
3427 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003428 for i in range( main.numCtrls ):
3429 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003430 name="setTestSize-" + str( i ),
3431 args=[ onosSetName ] )
3432 threads.append( t )
3433 t.start()
3434 for t in threads:
3435 t.join()
3436 sizeResponses.append( t.result )
3437
3438 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003439 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003440 if size != sizeResponses[ i ]:
3441 sizeResults = main.FALSE
3442 main.log.error( "ONOS" + str( i + 1 ) +
3443 " expected a size of " + str( size ) +
3444 " for set " + onosSetName +
3445 " but got " + str( sizeResponses[ i ] ) )
3446 utilities.assert_equals( expect=main.TRUE,
3447 actual=sizeResults,
3448 onpass="Set sizes are correct",
3449 onfail="Set sizes are incorrect" )
3450
3451 main.step( "Distributed Set add()" )
3452 onosSet.add( addValue )
3453 addResponses = []
3454 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003455 for i in range( main.numCtrls ):
3456 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall5cf14d52015-07-16 12:15:19 -07003457 name="setTestAdd-" + str( i ),
3458 args=[ onosSetName, addValue ] )
3459 threads.append( t )
3460 t.start()
3461 for t in threads:
3462 t.join()
3463 addResponses.append( t.result )
3464
3465 # main.TRUE = successfully changed the set
3466 # main.FALSE = action resulted in no change in set
3467 # main.ERROR - Some error in executing the function
3468 addResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003469 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003470 if addResponses[ i ] == main.TRUE:
3471 # All is well
3472 pass
3473 elif addResponses[ i ] == main.FALSE:
3474 # Already in set, probably fine
3475 pass
3476 elif addResponses[ i ] == main.ERROR:
3477 # Error in execution
3478 addResults = main.FALSE
3479 else:
3480 # unexpected result
3481 addResults = main.FALSE
3482 if addResults != main.TRUE:
3483 main.log.error( "Error executing set add" )
3484
3485 # Check if set is still correct
3486 size = len( onosSet )
3487 getResponses = []
3488 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003489 for i in range( main.numCtrls ):
3490 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003491 name="setTestGet-" + str( i ),
3492 args=[ onosSetName ] )
3493 threads.append( t )
3494 t.start()
3495 for t in threads:
3496 t.join()
3497 getResponses.append( t.result )
3498 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003499 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003500 if isinstance( getResponses[ i ], list):
3501 current = set( getResponses[ i ] )
3502 if len( current ) == len( getResponses[ i ] ):
3503 # no repeats
3504 if onosSet != current:
3505 main.log.error( "ONOS" + str( i + 1 ) +
3506 " has incorrect view" +
3507 " of set " + onosSetName + ":\n" +
3508 str( getResponses[ i ] ) )
3509 main.log.debug( "Expected: " + str( onosSet ) )
3510 main.log.debug( "Actual: " + str( current ) )
3511 getResults = main.FALSE
3512 else:
3513 # error, set is not a set
3514 main.log.error( "ONOS" + str( i + 1 ) +
3515 " has repeat elements in" +
3516 " set " + onosSetName + ":\n" +
3517 str( getResponses[ i ] ) )
3518 getResults = main.FALSE
3519 elif getResponses[ i ] == main.ERROR:
3520 getResults = main.FALSE
3521 sizeResponses = []
3522 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003523 for i in range( main.numCtrls ):
3524 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003525 name="setTestSize-" + str( i ),
3526 args=[ onosSetName ] )
3527 threads.append( t )
3528 t.start()
3529 for t in threads:
3530 t.join()
3531 sizeResponses.append( t.result )
3532 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003533 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003534 if size != sizeResponses[ i ]:
3535 sizeResults = main.FALSE
3536 main.log.error( "ONOS" + str( i + 1 ) +
3537 " expected a size of " + str( size ) +
3538 " for set " + onosSetName +
3539 " but got " + str( sizeResponses[ i ] ) )
3540 addResults = addResults and getResults and sizeResults
3541 utilities.assert_equals( expect=main.TRUE,
3542 actual=addResults,
3543 onpass="Set add correct",
3544 onfail="Set add was incorrect" )
3545
3546 main.step( "Distributed Set addAll()" )
3547 onosSet.update( addAllValue.split() )
3548 addResponses = []
3549 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003550 for i in range( main.numCtrls ):
3551 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall5cf14d52015-07-16 12:15:19 -07003552 name="setTestAddAll-" + str( i ),
3553 args=[ onosSetName, addAllValue ] )
3554 threads.append( t )
3555 t.start()
3556 for t in threads:
3557 t.join()
3558 addResponses.append( t.result )
3559
3560 # main.TRUE = successfully changed the set
3561 # main.FALSE = action resulted in no change in set
3562 # main.ERROR - Some error in executing the function
3563 addAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003564 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003565 if addResponses[ i ] == main.TRUE:
3566 # All is well
3567 pass
3568 elif addResponses[ i ] == main.FALSE:
3569 # Already in set, probably fine
3570 pass
3571 elif addResponses[ i ] == main.ERROR:
3572 # Error in execution
3573 addAllResults = main.FALSE
3574 else:
3575 # unexpected result
3576 addAllResults = main.FALSE
3577 if addAllResults != main.TRUE:
3578 main.log.error( "Error executing set addAll" )
3579
3580 # Check if set is still correct
3581 size = len( onosSet )
3582 getResponses = []
3583 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003584 for i in range( main.numCtrls ):
3585 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003586 name="setTestGet-" + str( i ),
3587 args=[ onosSetName ] )
3588 threads.append( t )
3589 t.start()
3590 for t in threads:
3591 t.join()
3592 getResponses.append( t.result )
3593 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003594 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003595 if isinstance( getResponses[ i ], list):
3596 current = set( getResponses[ i ] )
3597 if len( current ) == len( getResponses[ i ] ):
3598 # no repeats
3599 if onosSet != current:
3600 main.log.error( "ONOS" + str( i + 1 ) +
3601 " has incorrect view" +
3602 " of set " + onosSetName + ":\n" +
3603 str( getResponses[ i ] ) )
3604 main.log.debug( "Expected: " + str( onosSet ) )
3605 main.log.debug( "Actual: " + str( current ) )
3606 getResults = main.FALSE
3607 else:
3608 # error, set is not a set
3609 main.log.error( "ONOS" + str( i + 1 ) +
3610 " has repeat elements in" +
3611 " set " + onosSetName + ":\n" +
3612 str( getResponses[ i ] ) )
3613 getResults = main.FALSE
3614 elif getResponses[ i ] == main.ERROR:
3615 getResults = main.FALSE
3616 sizeResponses = []
3617 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003618 for i in range( main.numCtrls ):
3619 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003620 name="setTestSize-" + str( i ),
3621 args=[ onosSetName ] )
3622 threads.append( t )
3623 t.start()
3624 for t in threads:
3625 t.join()
3626 sizeResponses.append( t.result )
3627 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003628 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003629 if size != sizeResponses[ i ]:
3630 sizeResults = main.FALSE
3631 main.log.error( "ONOS" + str( i + 1 ) +
3632 " expected a size of " + str( size ) +
3633 " for set " + onosSetName +
3634 " but got " + str( sizeResponses[ i ] ) )
3635 addAllResults = addAllResults and getResults and sizeResults
3636 utilities.assert_equals( expect=main.TRUE,
3637 actual=addAllResults,
3638 onpass="Set addAll correct",
3639 onfail="Set addAll was incorrect" )
3640
3641 main.step( "Distributed Set contains()" )
3642 containsResponses = []
3643 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003644 for i in range( main.numCtrls ):
3645 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003646 name="setContains-" + str( i ),
3647 args=[ onosSetName ],
3648 kwargs={ "values": addValue } )
3649 threads.append( t )
3650 t.start()
3651 for t in threads:
3652 t.join()
3653 # NOTE: This is the tuple
3654 containsResponses.append( t.result )
3655
3656 containsResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003657 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003658 if containsResponses[ i ] == main.ERROR:
3659 containsResults = main.FALSE
3660 else:
3661 containsResults = containsResults and\
3662 containsResponses[ i ][ 1 ]
3663 utilities.assert_equals( expect=main.TRUE,
3664 actual=containsResults,
3665 onpass="Set contains is functional",
3666 onfail="Set contains failed" )
3667
3668 main.step( "Distributed Set containsAll()" )
3669 containsAllResponses = []
3670 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003671 for i in range( main.numCtrls ):
3672 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003673 name="setContainsAll-" + str( i ),
3674 args=[ onosSetName ],
3675 kwargs={ "values": addAllValue } )
3676 threads.append( t )
3677 t.start()
3678 for t in threads:
3679 t.join()
3680 # NOTE: This is the tuple
3681 containsAllResponses.append( t.result )
3682
3683 containsAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003684 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003685 if containsResponses[ i ] == main.ERROR:
3686 containsResults = main.FALSE
3687 else:
3688 containsResults = containsResults and\
3689 containsResponses[ i ][ 1 ]
3690 utilities.assert_equals( expect=main.TRUE,
3691 actual=containsAllResults,
3692 onpass="Set containsAll is functional",
3693 onfail="Set containsAll failed" )
3694
3695 main.step( "Distributed Set remove()" )
3696 onosSet.remove( addValue )
3697 removeResponses = []
3698 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003699 for i in range( main.numCtrls ):
3700 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall5cf14d52015-07-16 12:15:19 -07003701 name="setTestRemove-" + str( i ),
3702 args=[ onosSetName, addValue ] )
3703 threads.append( t )
3704 t.start()
3705 for t in threads:
3706 t.join()
3707 removeResponses.append( t.result )
3708
3709 # main.TRUE = successfully changed the set
3710 # main.FALSE = action resulted in no change in set
3711 # main.ERROR - Some error in executing the function
3712 removeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003713 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003714 if removeResponses[ i ] == main.TRUE:
3715 # All is well
3716 pass
3717 elif removeResponses[ i ] == main.FALSE:
3718 # not in set, probably fine
3719 pass
3720 elif removeResponses[ i ] == main.ERROR:
3721 # Error in execution
3722 removeResults = main.FALSE
3723 else:
3724 # unexpected result
3725 removeResults = main.FALSE
3726 if removeResults != main.TRUE:
3727 main.log.error( "Error executing set remove" )
3728
3729 # Check if set is still correct
3730 size = len( onosSet )
3731 getResponses = []
3732 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003733 for i in range( main.numCtrls ):
3734 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003735 name="setTestGet-" + str( i ),
3736 args=[ onosSetName ] )
3737 threads.append( t )
3738 t.start()
3739 for t in threads:
3740 t.join()
3741 getResponses.append( t.result )
3742 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003743 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003744 if isinstance( getResponses[ i ], list):
3745 current = set( getResponses[ i ] )
3746 if len( current ) == len( getResponses[ i ] ):
3747 # no repeats
3748 if onosSet != current:
3749 main.log.error( "ONOS" + str( i + 1 ) +
3750 " has incorrect view" +
3751 " of set " + onosSetName + ":\n" +
3752 str( getResponses[ i ] ) )
3753 main.log.debug( "Expected: " + str( onosSet ) )
3754 main.log.debug( "Actual: " + str( current ) )
3755 getResults = main.FALSE
3756 else:
3757 # error, set is not a set
3758 main.log.error( "ONOS" + str( i + 1 ) +
3759 " has repeat elements in" +
3760 " set " + onosSetName + ":\n" +
3761 str( getResponses[ i ] ) )
3762 getResults = main.FALSE
3763 elif getResponses[ i ] == main.ERROR:
3764 getResults = main.FALSE
3765 sizeResponses = []
3766 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003767 for i in range( main.numCtrls ):
3768 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003769 name="setTestSize-" + str( i ),
3770 args=[ onosSetName ] )
3771 threads.append( t )
3772 t.start()
3773 for t in threads:
3774 t.join()
3775 sizeResponses.append( t.result )
3776 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003777 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003778 if size != sizeResponses[ i ]:
3779 sizeResults = main.FALSE
3780 main.log.error( "ONOS" + str( i + 1 ) +
3781 " expected a size of " + str( size ) +
3782 " for set " + onosSetName +
3783 " but got " + str( sizeResponses[ i ] ) )
3784 removeResults = removeResults and getResults and sizeResults
3785 utilities.assert_equals( expect=main.TRUE,
3786 actual=removeResults,
3787 onpass="Set remove correct",
3788 onfail="Set remove was incorrect" )
3789
3790 main.step( "Distributed Set removeAll()" )
3791 onosSet.difference_update( addAllValue.split() )
3792 removeAllResponses = []
3793 threads = []
3794 try:
Jon Halle1a3b752015-07-22 13:02:46 -07003795 for i in range( main.numCtrls ):
3796 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall5cf14d52015-07-16 12:15:19 -07003797 name="setTestRemoveAll-" + str( i ),
3798 args=[ onosSetName, addAllValue ] )
3799 threads.append( t )
3800 t.start()
3801 for t in threads:
3802 t.join()
3803 removeAllResponses.append( t.result )
3804 except Exception, e:
3805 main.log.exception(e)
3806
3807 # main.TRUE = successfully changed the set
3808 # main.FALSE = action resulted in no change in set
3809 # main.ERROR - Some error in executing the function
3810 removeAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003811 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003812 if removeAllResponses[ i ] == main.TRUE:
3813 # All is well
3814 pass
3815 elif removeAllResponses[ i ] == main.FALSE:
3816 # not in set, probably fine
3817 pass
3818 elif removeAllResponses[ i ] == main.ERROR:
3819 # Error in execution
3820 removeAllResults = main.FALSE
3821 else:
3822 # unexpected result
3823 removeAllResults = main.FALSE
3824 if removeAllResults != main.TRUE:
3825 main.log.error( "Error executing set removeAll" )
3826
3827 # Check if set is still correct
3828 size = len( onosSet )
3829 getResponses = []
3830 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003831 for i in range( main.numCtrls ):
3832 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003833 name="setTestGet-" + str( i ),
3834 args=[ onosSetName ] )
3835 threads.append( t )
3836 t.start()
3837 for t in threads:
3838 t.join()
3839 getResponses.append( t.result )
3840 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003841 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003842 if isinstance( getResponses[ i ], list):
3843 current = set( getResponses[ i ] )
3844 if len( current ) == len( getResponses[ i ] ):
3845 # no repeats
3846 if onosSet != current:
3847 main.log.error( "ONOS" + str( i + 1 ) +
3848 " has incorrect view" +
3849 " of set " + onosSetName + ":\n" +
3850 str( getResponses[ i ] ) )
3851 main.log.debug( "Expected: " + str( onosSet ) )
3852 main.log.debug( "Actual: " + str( current ) )
3853 getResults = main.FALSE
3854 else:
3855 # error, set is not a set
3856 main.log.error( "ONOS" + str( i + 1 ) +
3857 " has repeat elements in" +
3858 " set " + onosSetName + ":\n" +
3859 str( getResponses[ i ] ) )
3860 getResults = main.FALSE
3861 elif getResponses[ i ] == main.ERROR:
3862 getResults = main.FALSE
3863 sizeResponses = []
3864 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003865 for i in range( main.numCtrls ):
3866 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003867 name="setTestSize-" + str( i ),
3868 args=[ onosSetName ] )
3869 threads.append( t )
3870 t.start()
3871 for t in threads:
3872 t.join()
3873 sizeResponses.append( t.result )
3874 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003875 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003876 if size != sizeResponses[ i ]:
3877 sizeResults = main.FALSE
3878 main.log.error( "ONOS" + str( i + 1 ) +
3879 " expected a size of " + str( size ) +
3880 " for set " + onosSetName +
3881 " but got " + str( sizeResponses[ i ] ) )
3882 removeAllResults = removeAllResults and getResults and sizeResults
3883 utilities.assert_equals( expect=main.TRUE,
3884 actual=removeAllResults,
3885 onpass="Set removeAll correct",
3886 onfail="Set removeAll was incorrect" )
3887
3888 main.step( "Distributed Set addAll()" )
3889 onosSet.update( addAllValue.split() )
3890 addResponses = []
3891 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003892 for i in range( main.numCtrls ):
3893 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall5cf14d52015-07-16 12:15:19 -07003894 name="setTestAddAll-" + str( i ),
3895 args=[ onosSetName, addAllValue ] )
3896 threads.append( t )
3897 t.start()
3898 for t in threads:
3899 t.join()
3900 addResponses.append( t.result )
3901
3902 # main.TRUE = successfully changed the set
3903 # main.FALSE = action resulted in no change in set
3904 # main.ERROR - Some error in executing the function
3905 addAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003906 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003907 if addResponses[ i ] == main.TRUE:
3908 # All is well
3909 pass
3910 elif addResponses[ i ] == main.FALSE:
3911 # Already in set, probably fine
3912 pass
3913 elif addResponses[ i ] == main.ERROR:
3914 # Error in execution
3915 addAllResults = main.FALSE
3916 else:
3917 # unexpected result
3918 addAllResults = main.FALSE
3919 if addAllResults != main.TRUE:
3920 main.log.error( "Error executing set addAll" )
3921
3922 # Check if set is still correct
3923 size = len( onosSet )
3924 getResponses = []
3925 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003926 for i in range( main.numCtrls ):
3927 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003928 name="setTestGet-" + str( i ),
3929 args=[ onosSetName ] )
3930 threads.append( t )
3931 t.start()
3932 for t in threads:
3933 t.join()
3934 getResponses.append( t.result )
3935 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003936 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003937 if isinstance( getResponses[ i ], list):
3938 current = set( getResponses[ i ] )
3939 if len( current ) == len( getResponses[ i ] ):
3940 # no repeats
3941 if onosSet != current:
3942 main.log.error( "ONOS" + str( i + 1 ) +
3943 " has incorrect view" +
3944 " of set " + onosSetName + ":\n" +
3945 str( getResponses[ i ] ) )
3946 main.log.debug( "Expected: " + str( onosSet ) )
3947 main.log.debug( "Actual: " + str( current ) )
3948 getResults = main.FALSE
3949 else:
3950 # error, set is not a set
3951 main.log.error( "ONOS" + str( i + 1 ) +
3952 " has repeat elements in" +
3953 " set " + onosSetName + ":\n" +
3954 str( getResponses[ i ] ) )
3955 getResults = main.FALSE
3956 elif getResponses[ i ] == main.ERROR:
3957 getResults = main.FALSE
3958 sizeResponses = []
3959 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003960 for i in range( main.numCtrls ):
3961 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003962 name="setTestSize-" + str( i ),
3963 args=[ onosSetName ] )
3964 threads.append( t )
3965 t.start()
3966 for t in threads:
3967 t.join()
3968 sizeResponses.append( t.result )
3969 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003970 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003971 if size != sizeResponses[ i ]:
3972 sizeResults = main.FALSE
3973 main.log.error( "ONOS" + str( i + 1 ) +
3974 " expected a size of " + str( size ) +
3975 " for set " + onosSetName +
3976 " but got " + str( sizeResponses[ i ] ) )
3977 addAllResults = addAllResults and getResults and sizeResults
3978 utilities.assert_equals( expect=main.TRUE,
3979 actual=addAllResults,
3980 onpass="Set addAll correct",
3981 onfail="Set addAll was incorrect" )
3982
3983 main.step( "Distributed Set clear()" )
3984 onosSet.clear()
3985 clearResponses = []
3986 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003987 for i in range( main.numCtrls ):
3988 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall5cf14d52015-07-16 12:15:19 -07003989 name="setTestClear-" + str( i ),
3990 args=[ onosSetName, " "], # Values doesn't matter
3991 kwargs={ "clear": True } )
3992 threads.append( t )
3993 t.start()
3994 for t in threads:
3995 t.join()
3996 clearResponses.append( t.result )
3997
3998 # main.TRUE = successfully changed the set
3999 # main.FALSE = action resulted in no change in set
4000 # main.ERROR - Some error in executing the function
4001 clearResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004002 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004003 if clearResponses[ i ] == main.TRUE:
4004 # All is well
4005 pass
4006 elif clearResponses[ i ] == main.FALSE:
4007 # Nothing set, probably fine
4008 pass
4009 elif clearResponses[ i ] == main.ERROR:
4010 # Error in execution
4011 clearResults = main.FALSE
4012 else:
4013 # unexpected result
4014 clearResults = main.FALSE
4015 if clearResults != main.TRUE:
4016 main.log.error( "Error executing set clear" )
4017
4018 # Check if set is still correct
4019 size = len( onosSet )
4020 getResponses = []
4021 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004022 for i in range( main.numCtrls ):
4023 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07004024 name="setTestGet-" + str( i ),
4025 args=[ onosSetName ] )
4026 threads.append( t )
4027 t.start()
4028 for t in threads:
4029 t.join()
4030 getResponses.append( t.result )
4031 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004032 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004033 if isinstance( getResponses[ i ], list):
4034 current = set( getResponses[ i ] )
4035 if len( current ) == len( getResponses[ i ] ):
4036 # no repeats
4037 if onosSet != current:
4038 main.log.error( "ONOS" + str( i + 1 ) +
4039 " has incorrect view" +
4040 " of set " + onosSetName + ":\n" +
4041 str( getResponses[ i ] ) )
4042 main.log.debug( "Expected: " + str( onosSet ) )
4043 main.log.debug( "Actual: " + str( current ) )
4044 getResults = main.FALSE
4045 else:
4046 # error, set is not a set
4047 main.log.error( "ONOS" + str( i + 1 ) +
4048 " has repeat elements in" +
4049 " set " + onosSetName + ":\n" +
4050 str( getResponses[ i ] ) )
4051 getResults = main.FALSE
4052 elif getResponses[ i ] == main.ERROR:
4053 getResults = main.FALSE
4054 sizeResponses = []
4055 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004056 for i in range( main.numCtrls ):
4057 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07004058 name="setTestSize-" + str( i ),
4059 args=[ onosSetName ] )
4060 threads.append( t )
4061 t.start()
4062 for t in threads:
4063 t.join()
4064 sizeResponses.append( t.result )
4065 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004066 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004067 if size != sizeResponses[ i ]:
4068 sizeResults = main.FALSE
4069 main.log.error( "ONOS" + str( i + 1 ) +
4070 " expected a size of " + str( size ) +
4071 " for set " + onosSetName +
4072 " but got " + str( sizeResponses[ i ] ) )
4073 clearResults = clearResults and getResults and sizeResults
4074 utilities.assert_equals( expect=main.TRUE,
4075 actual=clearResults,
4076 onpass="Set clear correct",
4077 onfail="Set clear was incorrect" )
4078
4079 main.step( "Distributed Set addAll()" )
4080 onosSet.update( addAllValue.split() )
4081 addResponses = []
4082 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004083 for i in range( main.numCtrls ):
4084 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall5cf14d52015-07-16 12:15:19 -07004085 name="setTestAddAll-" + str( i ),
4086 args=[ onosSetName, addAllValue ] )
4087 threads.append( t )
4088 t.start()
4089 for t in threads:
4090 t.join()
4091 addResponses.append( t.result )
4092
4093 # main.TRUE = successfully changed the set
4094 # main.FALSE = action resulted in no change in set
4095 # main.ERROR - Some error in executing the function
4096 addAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004097 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004098 if addResponses[ i ] == main.TRUE:
4099 # All is well
4100 pass
4101 elif addResponses[ i ] == main.FALSE:
4102 # Already in set, probably fine
4103 pass
4104 elif addResponses[ i ] == main.ERROR:
4105 # Error in execution
4106 addAllResults = main.FALSE
4107 else:
4108 # unexpected result
4109 addAllResults = main.FALSE
4110 if addAllResults != main.TRUE:
4111 main.log.error( "Error executing set addAll" )
4112
4113 # Check if set is still correct
4114 size = len( onosSet )
4115 getResponses = []
4116 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004117 for i in range( main.numCtrls ):
4118 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07004119 name="setTestGet-" + str( i ),
4120 args=[ onosSetName ] )
4121 threads.append( t )
4122 t.start()
4123 for t in threads:
4124 t.join()
4125 getResponses.append( t.result )
4126 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004127 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004128 if isinstance( getResponses[ i ], list):
4129 current = set( getResponses[ i ] )
4130 if len( current ) == len( getResponses[ i ] ):
4131 # no repeats
4132 if onosSet != current:
4133 main.log.error( "ONOS" + str( i + 1 ) +
4134 " has incorrect view" +
4135 " of set " + onosSetName + ":\n" +
4136 str( getResponses[ i ] ) )
4137 main.log.debug( "Expected: " + str( onosSet ) )
4138 main.log.debug( "Actual: " + str( current ) )
4139 getResults = main.FALSE
4140 else:
4141 # error, set is not a set
4142 main.log.error( "ONOS" + str( i + 1 ) +
4143 " has repeat elements in" +
4144 " set " + onosSetName + ":\n" +
4145 str( getResponses[ i ] ) )
4146 getResults = main.FALSE
4147 elif getResponses[ i ] == main.ERROR:
4148 getResults = main.FALSE
4149 sizeResponses = []
4150 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004151 for i in range( main.numCtrls ):
4152 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07004153 name="setTestSize-" + str( i ),
4154 args=[ onosSetName ] )
4155 threads.append( t )
4156 t.start()
4157 for t in threads:
4158 t.join()
4159 sizeResponses.append( t.result )
4160 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004161 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004162 if size != sizeResponses[ i ]:
4163 sizeResults = main.FALSE
4164 main.log.error( "ONOS" + str( i + 1 ) +
4165 " expected a size of " + str( size ) +
4166 " for set " + onosSetName +
4167 " but got " + str( sizeResponses[ i ] ) )
4168 addAllResults = addAllResults and getResults and sizeResults
4169 utilities.assert_equals( expect=main.TRUE,
4170 actual=addAllResults,
4171 onpass="Set addAll correct",
4172 onfail="Set addAll was incorrect" )
4173
4174 main.step( "Distributed Set retain()" )
4175 onosSet.intersection_update( retainValue.split() )
4176 retainResponses = []
4177 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004178 for i in range( main.numCtrls ):
4179 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall5cf14d52015-07-16 12:15:19 -07004180 name="setTestRetain-" + str( i ),
4181 args=[ onosSetName, retainValue ],
4182 kwargs={ "retain": True } )
4183 threads.append( t )
4184 t.start()
4185 for t in threads:
4186 t.join()
4187 retainResponses.append( t.result )
4188
4189 # main.TRUE = successfully changed the set
4190 # main.FALSE = action resulted in no change in set
4191 # main.ERROR - Some error in executing the function
4192 retainResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004193 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004194 if retainResponses[ i ] == main.TRUE:
4195 # All is well
4196 pass
4197 elif retainResponses[ i ] == main.FALSE:
4198 # Already in set, probably fine
4199 pass
4200 elif retainResponses[ i ] == main.ERROR:
4201 # Error in execution
4202 retainResults = main.FALSE
4203 else:
4204 # unexpected result
4205 retainResults = main.FALSE
4206 if retainResults != main.TRUE:
4207 main.log.error( "Error executing set retain" )
4208
4209 # Check if set is still correct
4210 size = len( onosSet )
4211 getResponses = []
4212 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004213 for i in range( main.numCtrls ):
4214 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07004215 name="setTestGet-" + str( i ),
4216 args=[ onosSetName ] )
4217 threads.append( t )
4218 t.start()
4219 for t in threads:
4220 t.join()
4221 getResponses.append( t.result )
4222 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004223 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004224 if isinstance( getResponses[ i ], list):
4225 current = set( getResponses[ i ] )
4226 if len( current ) == len( getResponses[ i ] ):
4227 # no repeats
4228 if onosSet != current:
4229 main.log.error( "ONOS" + str( i + 1 ) +
4230 " has incorrect view" +
4231 " of set " + onosSetName + ":\n" +
4232 str( getResponses[ i ] ) )
4233 main.log.debug( "Expected: " + str( onosSet ) )
4234 main.log.debug( "Actual: " + str( current ) )
4235 getResults = main.FALSE
4236 else:
4237 # error, set is not a set
4238 main.log.error( "ONOS" + str( i + 1 ) +
4239 " has repeat elements in" +
4240 " set " + onosSetName + ":\n" +
4241 str( getResponses[ i ] ) )
4242 getResults = main.FALSE
4243 elif getResponses[ i ] == main.ERROR:
4244 getResults = main.FALSE
4245 sizeResponses = []
4246 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004247 for i in range( main.numCtrls ):
4248 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07004249 name="setTestSize-" + str( i ),
4250 args=[ onosSetName ] )
4251 threads.append( t )
4252 t.start()
4253 for t in threads:
4254 t.join()
4255 sizeResponses.append( t.result )
4256 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004257 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004258 if size != sizeResponses[ i ]:
4259 sizeResults = main.FALSE
4260 main.log.error( "ONOS" + str( i + 1 ) +
4261 " expected a size of " +
4262 str( size ) + " for set " + onosSetName +
4263 " but got " + str( sizeResponses[ i ] ) )
4264 retainResults = retainResults and getResults and sizeResults
4265 utilities.assert_equals( expect=main.TRUE,
4266 actual=retainResults,
4267 onpass="Set retain correct",
4268 onfail="Set retain was incorrect" )
4269
Jon Hall2a5002c2015-08-21 16:49:11 -07004270 # Transactional maps
4271 main.step( "Partitioned Transactional maps put" )
4272 tMapValue = "Testing"
4273 numKeys = 100
4274 putResult = True
4275 putResponses = main.CLIs[ 0 ].transactionalMapPut( numKeys, tMapValue )
4276 if len( putResponses ) == 100:
4277 for i in putResponses:
4278 if putResponses[ i ][ 'value' ] != tMapValue:
4279 putResult = False
4280 else:
4281 putResult = False
4282 if not putResult:
4283 main.log.debug( "Put response values: " + str( putResponses ) )
4284 utilities.assert_equals( expect=True,
4285 actual=putResult,
4286 onpass="Partitioned Transactional Map put successful",
4287 onfail="Partitioned Transactional Map put values are incorrect" )
4288
4289 main.step( "Partitioned Transactional maps get" )
4290 getCheck = True
4291 for n in range( 1, numKeys + 1 ):
4292 getResponses = []
4293 threads = []
4294 valueCheck = True
4295 for i in range( main.numCtrls ):
4296 t = main.Thread( target=main.CLIs[i].transactionalMapGet,
4297 name="TMap-get-" + str( i ),
4298 args=[ "Key" + str ( n ) ] )
4299 threads.append( t )
4300 t.start()
4301 for t in threads:
4302 t.join()
4303 getResponses.append( t.result )
4304 for node in getResponses:
4305 if node != tMapValue:
4306 valueCheck = False
4307 if not valueCheck:
4308 main.log.warn( "Values for key 'Key" + str( n ) + "' do not match:" )
4309 main.log.warn( getResponses )
4310 getCheck = getCheck and valueCheck
4311 utilities.assert_equals( expect=True,
4312 actual=getCheck,
4313 onpass="Partitioned Transactional Map get values were correct",
4314 onfail="Partitioned Transactional Map values incorrect" )
4315
4316 main.step( "In-memory Transactional maps put" )
4317 tMapValue = "Testing"
4318 numKeys = 100
4319 putResult = True
4320 putResponses = main.CLIs[ 0 ].transactionalMapPut( numKeys, tMapValue, inMemory=True )
4321 if len( putResponses ) == 100:
4322 for i in putResponses:
4323 if putResponses[ i ][ 'value' ] != tMapValue:
4324 putResult = False
4325 else:
4326 putResult = False
4327 if not putResult:
4328 main.log.debug( "Put response values: " + str( putResponses ) )
4329 utilities.assert_equals( expect=True,
4330 actual=putResult,
4331 onpass="In-Memory Transactional Map put successful",
4332 onfail="In-Memory Transactional Map put values are incorrect" )
4333
4334 main.step( "In-Memory Transactional maps get" )
4335 getCheck = True
4336 for n in range( 1, numKeys + 1 ):
4337 getResponses = []
4338 threads = []
4339 valueCheck = True
4340 for i in range( main.numCtrls ):
4341 t = main.Thread( target=main.CLIs[i].transactionalMapGet,
4342 name="TMap-get-" + str( i ),
4343 args=[ "Key" + str ( n ) ],
4344 kwargs={ "inMemory": True } )
4345 threads.append( t )
4346 t.start()
4347 for t in threads:
4348 t.join()
4349 getResponses.append( t.result )
4350 for node in getResponses:
4351 if node != tMapValue:
4352 valueCheck = False
4353 if not valueCheck:
4354 main.log.warn( "Values for key 'Key" + str( n ) + "' do not match:" )
4355 main.log.warn( getResponses )
4356 getCheck = getCheck and valueCheck
4357 utilities.assert_equals( expect=True,
4358 actual=getCheck,
4359 onpass="In-Memory Transactional Map get values were correct",
4360 onfail="In-Memory Transactional Map values incorrect" )