blob: 5322a9af7f5ceefd0de516abb524b9ebe7b140cf [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 Hallf3d16e72015-12-16 17:45:08 -080052 import time
Jon Hall5cf14d52015-07-16 12:15:19 -070053 main.log.info( "ONOS HA Sanity test - initialization" )
54 main.case( "Setting up test environment" )
Jon Hall783bbf92015-07-23 14:33:19 -070055 main.caseExplanation = "Setup the test environment including " +\
Jon Hall5cf14d52015-07-16 12:15:19 -070056 "installing ONOS, starting Mininet and ONOS" +\
57 "cli sessions."
58 # TODO: save all the timers and output them for plotting
59
60 # load some variables from the params file
61 PULLCODE = False
62 if main.params[ 'Git' ] == 'True':
63 PULLCODE = True
64 gitBranch = main.params[ 'branch' ]
65 cellName = main.params[ 'ENV' ][ 'cellName' ]
66
Jon Halle1a3b752015-07-22 13:02:46 -070067 main.numCtrls = int( main.params[ 'num_controllers' ] )
Jon Hall5cf14d52015-07-16 12:15:19 -070068 if main.ONOSbench.maxNodes:
Jon Halle1a3b752015-07-22 13:02:46 -070069 if main.ONOSbench.maxNodes < main.numCtrls:
70 main.numCtrls = int( main.ONOSbench.maxNodes )
Jon Hall5cf14d52015-07-16 12:15:19 -070071 # TODO: refactor how to get onos port, maybe put into component tag?
Jon Halle1a3b752015-07-22 13:02:46 -070072 # set global variables
Jon Hall5cf14d52015-07-16 12:15:19 -070073 global ONOS1Port
74 global ONOS2Port
75 global ONOS3Port
76 global ONOS4Port
77 global ONOS5Port
78 global ONOS6Port
79 global ONOS7Port
80
81 # FIXME: just get controller port from params?
82 # TODO: do we really need all these?
83 ONOS1Port = main.params[ 'CTRL' ][ 'port1' ]
84 ONOS2Port = main.params[ 'CTRL' ][ 'port2' ]
85 ONOS3Port = main.params[ 'CTRL' ][ 'port3' ]
86 ONOS4Port = main.params[ 'CTRL' ][ 'port4' ]
87 ONOS5Port = main.params[ 'CTRL' ][ 'port5' ]
88 ONOS6Port = main.params[ 'CTRL' ][ 'port6' ]
89 ONOS7Port = main.params[ 'CTRL' ][ 'port7' ]
90
Jon Halle1a3b752015-07-22 13:02:46 -070091 try:
92 fileName = "Counters"
93 path = main.params[ 'imports' ][ 'path' ]
94 main.Counters = imp.load_source( fileName,
95 path + fileName + ".py" )
96 except Exception as e:
97 main.log.exception( e )
98 main.cleanup()
99 main.exit()
100
101 main.CLIs = []
102 main.nodes = []
Jon Hall5cf14d52015-07-16 12:15:19 -0700103 ipList = []
Jon Halle1a3b752015-07-22 13:02:46 -0700104 for i in range( 1, main.numCtrls + 1 ):
105 try:
106 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
107 main.nodes.append( getattr( main, 'ONOS' + str( i ) ) )
108 ipList.append( main.nodes[ -1 ].ip_address )
109 except AttributeError:
110 break
Jon Hall5cf14d52015-07-16 12:15:19 -0700111
112 main.step( "Create cell file" )
113 cellAppString = main.params[ 'ENV' ][ 'appString' ]
114 main.ONOSbench.createCellFile( main.ONOSbench.ip_address, cellName,
115 main.Mininet1.ip_address,
116 cellAppString, ipList )
117 main.step( "Applying cell variable to environment" )
118 cellResult = main.ONOSbench.setCell( cellName )
119 verifyResult = main.ONOSbench.verifyCell()
120
121 # FIXME:this is short term fix
122 main.log.info( "Removing raft logs" )
123 main.ONOSbench.onosRemoveRaftLogs()
124
125 main.log.info( "Uninstalling ONOS" )
Jon Halle1a3b752015-07-22 13:02:46 -0700126 for node in main.nodes:
Jon Hall5cf14d52015-07-16 12:15:19 -0700127 main.ONOSbench.onosUninstall( node.ip_address )
128
129 # Make sure ONOS is DEAD
130 main.log.info( "Killing any ONOS processes" )
131 killResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -0700132 for node in main.nodes:
Jon Hall5cf14d52015-07-16 12:15:19 -0700133 killed = main.ONOSbench.onosKill( node.ip_address )
134 killResults = killResults and killed
135
136 cleanInstallResult = main.TRUE
137 gitPullResult = main.TRUE
138
139 main.step( "Starting Mininet" )
140 # scp topo file to mininet
141 # TODO: move to params?
142 topoName = "obelisk.py"
143 filePath = main.ONOSbench.home + "/tools/test/topos/"
kelvin-onlabd9e23de2015-08-06 10:34:44 -0700144 main.ONOSbench.scp( main.Mininet1,
145 filePath + topoName,
146 main.Mininet1.home,
147 direction="to" )
Jon Hall5cf14d52015-07-16 12:15:19 -0700148 mnResult = main.Mininet1.startNet( )
149 utilities.assert_equals( expect=main.TRUE, actual=mnResult,
150 onpass="Mininet Started",
151 onfail="Error starting Mininet" )
152
153 main.step( "Git checkout and pull " + gitBranch )
154 if PULLCODE:
155 main.ONOSbench.gitCheckout( gitBranch )
156 gitPullResult = main.ONOSbench.gitPull()
157 # values of 1 or 3 are good
158 utilities.assert_lesser( expect=0, actual=gitPullResult,
159 onpass="Git pull successful",
160 onfail="Git pull failed" )
161 main.ONOSbench.getVersion( report=True )
162
163 main.step( "Using mvn clean install" )
164 cleanInstallResult = main.TRUE
165 if PULLCODE and gitPullResult == main.TRUE:
166 cleanInstallResult = main.ONOSbench.cleanInstall()
167 else:
168 main.log.warn( "Did not pull new code so skipping mvn " +
169 "clean install" )
170 utilities.assert_equals( expect=main.TRUE,
171 actual=cleanInstallResult,
172 onpass="MCI successful",
173 onfail="MCI failed" )
174 # GRAPHS
175 # NOTE: important params here:
176 # job = name of Jenkins job
177 # Plot Name = Plot-HA, only can be used if multiple plots
178 # index = The number of the graph under plot name
179 job = "HAsanity"
180 plotName = "Plot-HA"
181 graphs = '<ac:structured-macro ac:name="html">\n'
182 graphs += '<ac:plain-text-body><![CDATA[\n'
183 graphs += '<iframe src="https://onos-jenkins.onlab.us/job/' + job +\
184 '/plot/' + plotName + '/getPlot?index=0' +\
185 '&width=500&height=300"' +\
186 'noborder="0" width="500" height="300" scrolling="yes" ' +\
187 'seamless="seamless"></iframe>\n'
188 graphs += ']]></ac:plain-text-body>\n'
189 graphs += '</ac:structured-macro>\n'
190 main.log.wiki(graphs)
191
192 main.step( "Creating ONOS package" )
193 packageResult = main.ONOSbench.onosPackage()
194 utilities.assert_equals( expect=main.TRUE, actual=packageResult,
195 onpass="ONOS package successful",
196 onfail="ONOS package failed" )
197
198 main.step( "Installing ONOS package" )
199 onosInstallResult = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -0700200 for node in main.nodes:
Jon Hall5cf14d52015-07-16 12:15:19 -0700201 tmpResult = main.ONOSbench.onosInstall( options="-f",
202 node=node.ip_address )
203 onosInstallResult = onosInstallResult and tmpResult
204 utilities.assert_equals( expect=main.TRUE, actual=onosInstallResult,
205 onpass="ONOS install successful",
206 onfail="ONOS install failed" )
207
208 main.step( "Checking if ONOS is up yet" )
209 for i in range( 2 ):
210 onosIsupResult = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -0700211 for node in main.nodes:
Jon Hall5cf14d52015-07-16 12:15:19 -0700212 started = main.ONOSbench.isup( node.ip_address )
213 if not started:
214 main.log.error( node.name + " didn't start!" )
215 main.ONOSbench.onosStop( node.ip_address )
216 main.ONOSbench.onosStart( node.ip_address )
217 onosIsupResult = onosIsupResult and started
218 if onosIsupResult == main.TRUE:
219 break
220 utilities.assert_equals( expect=main.TRUE, actual=onosIsupResult,
221 onpass="ONOS startup successful",
222 onfail="ONOS startup failed" )
223
224 main.log.step( "Starting ONOS CLI sessions" )
225 cliResults = main.TRUE
226 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -0700227 for i in range( main.numCtrls ):
228 t = main.Thread( target=main.CLIs[i].startOnosCli,
Jon Hall5cf14d52015-07-16 12:15:19 -0700229 name="startOnosCli-" + str( i ),
Jon Halle1a3b752015-07-22 13:02:46 -0700230 args=[main.nodes[i].ip_address] )
Jon Hall5cf14d52015-07-16 12:15:19 -0700231 threads.append( t )
232 t.start()
233
234 for t in threads:
235 t.join()
236 cliResults = cliResults and t.result
237 utilities.assert_equals( expect=main.TRUE, actual=cliResults,
238 onpass="ONOS cli startup successful",
239 onfail="ONOS cli startup failed" )
240
241 if main.params[ 'tcpdump' ].lower() == "true":
242 main.step( "Start Packet Capture MN" )
243 main.Mininet2.startTcpdump(
244 str( main.params[ 'MNtcpdump' ][ 'folder' ] ) + str( main.TEST )
245 + "-MN.pcap",
246 intf=main.params[ 'MNtcpdump' ][ 'intf' ],
247 port=main.params[ 'MNtcpdump' ][ 'port' ] )
248
249 main.step( "App Ids check" )
Jon Hallf3d16e72015-12-16 17:45:08 -0800250 time.sleep(60)
Jon Hall5cf14d52015-07-16 12:15:19 -0700251 appCheck = main.TRUE
252 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -0700253 for i in range( main.numCtrls ):
254 t = main.Thread( target=main.CLIs[i].appToIDCheck,
Jon Hall5cf14d52015-07-16 12:15:19 -0700255 name="appToIDCheck-" + str( i ),
256 args=[] )
257 threads.append( t )
258 t.start()
259
260 for t in threads:
261 t.join()
262 appCheck = appCheck and t.result
263 if appCheck != main.TRUE:
Jon Halle1a3b752015-07-22 13:02:46 -0700264 main.log.warn( main.CLIs[0].apps() )
265 main.log.warn( main.CLIs[0].appIDs() )
Jon Hall5cf14d52015-07-16 12:15:19 -0700266 utilities.assert_equals( expect=main.TRUE, actual=appCheck,
267 onpass="App Ids seem to be correct",
268 onfail="Something is wrong with app Ids" )
269
270 if cliResults == main.FALSE:
271 main.log.error( "Failed to start ONOS, stopping test" )
272 main.cleanup()
273 main.exit()
274
275 def CASE2( self, main ):
276 """
277 Assign devices to controllers
278 """
279 import re
Jon Halle1a3b752015-07-22 13:02:46 -0700280 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -0700281 assert main, "main not defined"
282 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -0700283 assert main.CLIs, "main.CLIs not defined"
284 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -0700285 assert ONOS1Port, "ONOS1Port not defined"
286 assert ONOS2Port, "ONOS2Port not defined"
287 assert ONOS3Port, "ONOS3Port not defined"
288 assert ONOS4Port, "ONOS4Port not defined"
289 assert ONOS5Port, "ONOS5Port not defined"
290 assert ONOS6Port, "ONOS6Port not defined"
291 assert ONOS7Port, "ONOS7Port not defined"
292
293 main.case( "Assigning devices to controllers" )
Jon Hall783bbf92015-07-23 14:33:19 -0700294 main.caseExplanation = "Assign switches to ONOS using 'ovs-vsctl' " +\
Jon Hall5cf14d52015-07-16 12:15:19 -0700295 "and check that an ONOS node becomes the " +\
296 "master of the device."
297 main.step( "Assign switches to controllers" )
298
299 ipList = []
Jon Halle1a3b752015-07-22 13:02:46 -0700300 for i in range( main.numCtrls ):
301 ipList.append( main.nodes[ i ].ip_address )
Jon Hall5cf14d52015-07-16 12:15:19 -0700302 swList = []
303 for i in range( 1, 29 ):
304 swList.append( "s" + str( i ) )
305 main.Mininet1.assignSwController( sw=swList, ip=ipList )
306
307 mastershipCheck = main.TRUE
308 for i in range( 1, 29 ):
309 response = main.Mininet1.getSwController( "s" + str( i ) )
310 try:
311 main.log.info( str( response ) )
312 except Exception:
313 main.log.info( repr( response ) )
Jon Halle1a3b752015-07-22 13:02:46 -0700314 for node in main.nodes:
Jon Hall5cf14d52015-07-16 12:15:19 -0700315 if re.search( "tcp:" + node.ip_address, response ):
316 mastershipCheck = mastershipCheck and main.TRUE
317 else:
318 main.log.error( "Error, node " + node.ip_address + " is " +
319 "not in the list of controllers s" +
320 str( i ) + " is connecting to." )
321 mastershipCheck = main.FALSE
322 utilities.assert_equals(
323 expect=main.TRUE,
324 actual=mastershipCheck,
325 onpass="Switch mastership assigned correctly",
326 onfail="Switches not assigned correctly to controllers" )
327
328 def CASE21( self, main ):
329 """
330 Assign mastership to controllers
331 """
Jon Hall5cf14d52015-07-16 12:15:19 -0700332 import time
Jon Halle1a3b752015-07-22 13:02:46 -0700333 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -0700334 assert main, "main not defined"
335 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -0700336 assert main.CLIs, "main.CLIs not defined"
337 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -0700338 assert ONOS1Port, "ONOS1Port not defined"
339 assert ONOS2Port, "ONOS2Port not defined"
340 assert ONOS3Port, "ONOS3Port not defined"
341 assert ONOS4Port, "ONOS4Port not defined"
342 assert ONOS5Port, "ONOS5Port not defined"
343 assert ONOS6Port, "ONOS6Port not defined"
344 assert ONOS7Port, "ONOS7Port not defined"
345
346 main.case( "Assigning Controller roles for switches" )
Jon Hall783bbf92015-07-23 14:33:19 -0700347 main.caseExplanation = "Check that ONOS is connected to each " +\
Jon Hall5cf14d52015-07-16 12:15:19 -0700348 "device. Then manually assign" +\
349 " mastership to specific ONOS nodes using" +\
350 " 'device-role'"
351 main.step( "Assign mastership of switches to specific controllers" )
352 # Manually assign mastership to the controller we want
353 roleCall = main.TRUE
354
355 ipList = [ ]
356 deviceList = []
357 try:
358 # Assign mastership to specific controllers. This assignment was
359 # determined for a 7 node cluser, but will work with any sized
360 # cluster
361 for i in range( 1, 29 ): # switches 1 through 28
362 # set up correct variables:
363 if i == 1:
364 c = 0
Jon Halle1a3b752015-07-22 13:02:46 -0700365 ip = main.nodes[ c ].ip_address # ONOS1
Jon Hall5cf14d52015-07-16 12:15:19 -0700366 deviceId = main.ONOScli1.getDevice( "1000" ).get( 'id' )
367 elif i == 2:
Jon Halle1a3b752015-07-22 13:02:46 -0700368 c = 1 % main.numCtrls
369 ip = main.nodes[ c ].ip_address # ONOS2
Jon Hall5cf14d52015-07-16 12:15:19 -0700370 deviceId = main.ONOScli1.getDevice( "2000" ).get( 'id' )
371 elif i == 3:
Jon Halle1a3b752015-07-22 13:02:46 -0700372 c = 1 % main.numCtrls
373 ip = main.nodes[ c ].ip_address # ONOS2
Jon Hall5cf14d52015-07-16 12:15:19 -0700374 deviceId = main.ONOScli1.getDevice( "3000" ).get( 'id' )
375 elif i == 4:
Jon Halle1a3b752015-07-22 13:02:46 -0700376 c = 3 % main.numCtrls
377 ip = main.nodes[ c ].ip_address # ONOS4
Jon Hall5cf14d52015-07-16 12:15:19 -0700378 deviceId = main.ONOScli1.getDevice( "3004" ).get( 'id' )
379 elif i == 5:
Jon Halle1a3b752015-07-22 13:02:46 -0700380 c = 2 % main.numCtrls
381 ip = main.nodes[ c ].ip_address # ONOS3
Jon Hall5cf14d52015-07-16 12:15:19 -0700382 deviceId = main.ONOScli1.getDevice( "5000" ).get( 'id' )
383 elif i == 6:
Jon Halle1a3b752015-07-22 13:02:46 -0700384 c = 2 % main.numCtrls
385 ip = main.nodes[ c ].ip_address # ONOS3
Jon Hall5cf14d52015-07-16 12:15:19 -0700386 deviceId = main.ONOScli1.getDevice( "6000" ).get( 'id' )
387 elif i == 7:
Jon Halle1a3b752015-07-22 13:02:46 -0700388 c = 5 % main.numCtrls
389 ip = main.nodes[ c ].ip_address # ONOS6
Jon Hall5cf14d52015-07-16 12:15:19 -0700390 deviceId = main.ONOScli1.getDevice( "6007" ).get( 'id' )
391 elif i >= 8 and i <= 17:
Jon Halle1a3b752015-07-22 13:02:46 -0700392 c = 4 % main.numCtrls
393 ip = main.nodes[ c ].ip_address # ONOS5
Jon Hall5cf14d52015-07-16 12:15:19 -0700394 dpid = '3' + str( i ).zfill( 3 )
395 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
396 elif i >= 18 and i <= 27:
Jon Halle1a3b752015-07-22 13:02:46 -0700397 c = 6 % main.numCtrls
398 ip = main.nodes[ c ].ip_address # ONOS7
Jon Hall5cf14d52015-07-16 12:15:19 -0700399 dpid = '6' + str( i ).zfill( 3 )
400 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
401 elif i == 28:
402 c = 0
Jon Halle1a3b752015-07-22 13:02:46 -0700403 ip = main.nodes[ c ].ip_address # ONOS1
Jon Hall5cf14d52015-07-16 12:15:19 -0700404 deviceId = main.ONOScli1.getDevice( "2800" ).get( 'id' )
405 else:
406 main.log.error( "You didn't write an else statement for " +
407 "switch s" + str( i ) )
408 roleCall = main.FALSE
409 # Assign switch
410 assert deviceId, "No device id for s" + str( i ) + " in ONOS"
411 # TODO: make this controller dynamic
412 roleCall = roleCall and main.ONOScli1.deviceRole( deviceId,
413 ip )
414 ipList.append( ip )
415 deviceList.append( deviceId )
416 except ( AttributeError, AssertionError ):
417 main.log.exception( "Something is wrong with ONOS device view" )
418 main.log.info( main.ONOScli1.devices() )
419 utilities.assert_equals(
420 expect=main.TRUE,
421 actual=roleCall,
422 onpass="Re-assigned switch mastership to designated controller",
423 onfail="Something wrong with deviceRole calls" )
424
425 main.step( "Check mastership was correctly assigned" )
426 roleCheck = main.TRUE
427 # NOTE: This is due to the fact that device mastership change is not
428 # atomic and is actually a multi step process
429 time.sleep( 5 )
430 for i in range( len( ipList ) ):
431 ip = ipList[i]
432 deviceId = deviceList[i]
433 # Check assignment
434 master = main.ONOScli1.getRole( deviceId ).get( 'master' )
435 if ip in master:
436 roleCheck = roleCheck and main.TRUE
437 else:
438 roleCheck = roleCheck and main.FALSE
439 main.log.error( "Error, controller " + ip + " is not" +
440 " master " + "of device " +
441 str( deviceId ) + ". Master is " +
442 repr( master ) + "." )
443 utilities.assert_equals(
444 expect=main.TRUE,
445 actual=roleCheck,
446 onpass="Switches were successfully reassigned to designated " +
447 "controller",
448 onfail="Switches were not successfully reassigned" )
449
450 def CASE3( self, main ):
451 """
452 Assign intents
453 """
454 import time
455 import json
Jon Halle1a3b752015-07-22 13:02:46 -0700456 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -0700457 assert main, "main not defined"
458 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -0700459 assert main.CLIs, "main.CLIs not defined"
460 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -0700461 main.case( "Adding host Intents" )
Jon Hall783bbf92015-07-23 14:33:19 -0700462 main.caseExplanation = "Discover hosts by using pingall then " +\
Jon Hall5cf14d52015-07-16 12:15:19 -0700463 "assign predetermined host-to-host intents." +\
464 " After installation, check that the intent" +\
465 " is distributed to all nodes and the state" +\
466 " is INSTALLED"
467
468 # install onos-app-fwd
469 main.step( "Install reactive forwarding app" )
Jon Halle1a3b752015-07-22 13:02:46 -0700470 installResults = main.CLIs[0].activateApp( "org.onosproject.fwd" )
Jon Hall5cf14d52015-07-16 12:15:19 -0700471 utilities.assert_equals( expect=main.TRUE, actual=installResults,
472 onpass="Install fwd successful",
473 onfail="Install fwd failed" )
474
475 main.step( "Check app ids" )
476 appCheck = main.TRUE
477 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -0700478 for i in range( main.numCtrls ):
479 t = main.Thread( target=main.CLIs[i].appToIDCheck,
Jon Hall5cf14d52015-07-16 12:15:19 -0700480 name="appToIDCheck-" + str( i ),
481 args=[] )
482 threads.append( t )
483 t.start()
484
485 for t in threads:
486 t.join()
487 appCheck = appCheck and t.result
488 if appCheck != main.TRUE:
Jon Halle1a3b752015-07-22 13:02:46 -0700489 main.log.warn( main.CLIs[0].apps() )
490 main.log.warn( main.CLIs[0].appIDs() )
Jon Hall5cf14d52015-07-16 12:15:19 -0700491 utilities.assert_equals( expect=main.TRUE, actual=appCheck,
492 onpass="App Ids seem to be correct",
493 onfail="Something is wrong with app Ids" )
494
495 main.step( "Discovering Hosts( Via pingall for now )" )
496 # FIXME: Once we have a host discovery mechanism, use that instead
497 # REACTIVE FWD test
498 pingResult = main.FALSE
Jon Hall96091e62015-09-21 17:34:17 -0700499 passMsg = "Reactive Pingall test passed"
500 time1 = time.time()
501 pingResult = main.Mininet1.pingall()
502 time2 = time.time()
503 if not pingResult:
504 main.log.warn("First pingall failed. Trying again...")
Jon Hall5cf14d52015-07-16 12:15:19 -0700505 pingResult = main.Mininet1.pingall()
Jon Hall96091e62015-09-21 17:34:17 -0700506 passMsg += " on the second try"
507 utilities.assert_equals(
508 expect=main.TRUE,
509 actual=pingResult,
510 onpass= passMsg,
511 onfail="Reactive Pingall failed, " +
512 "one or more ping pairs failed" )
513 main.log.info( "Time for pingall: %2f seconds" %
514 ( time2 - time1 ) )
Jon Hall5cf14d52015-07-16 12:15:19 -0700515 # timeout for fwd flows
516 time.sleep( 11 )
517 # uninstall onos-app-fwd
518 main.step( "Uninstall reactive forwarding app" )
Jon Halle1a3b752015-07-22 13:02:46 -0700519 uninstallResult = main.CLIs[0].deactivateApp( "org.onosproject.fwd" )
Jon Hall5cf14d52015-07-16 12:15:19 -0700520 utilities.assert_equals( expect=main.TRUE, actual=uninstallResult,
521 onpass="Uninstall fwd successful",
522 onfail="Uninstall fwd failed" )
Jon Hall5cf14d52015-07-16 12:15:19 -0700523
524 main.step( "Check app ids" )
525 threads = []
526 appCheck2 = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -0700527 for i in range( main.numCtrls ):
528 t = main.Thread( target=main.CLIs[i].appToIDCheck,
Jon Hall5cf14d52015-07-16 12:15:19 -0700529 name="appToIDCheck-" + str( i ),
530 args=[] )
531 threads.append( t )
532 t.start()
533
534 for t in threads:
535 t.join()
536 appCheck2 = appCheck2 and t.result
537 if appCheck2 != main.TRUE:
Jon Halle1a3b752015-07-22 13:02:46 -0700538 main.log.warn( main.CLIs[0].apps() )
539 main.log.warn( main.CLIs[0].appIDs() )
Jon Hall5cf14d52015-07-16 12:15:19 -0700540 utilities.assert_equals( expect=main.TRUE, actual=appCheck2,
541 onpass="App Ids seem to be correct",
542 onfail="Something is wrong with app Ids" )
543
544 main.step( "Add host intents via cli" )
545 intentIds = []
546 # TODO: move the host numbers to params
547 # Maybe look at all the paths we ping?
548 intentAddResult = True
549 hostResult = main.TRUE
550 for i in range( 8, 18 ):
551 main.log.info( "Adding host intent between h" + str( i ) +
552 " and h" + str( i + 10 ) )
553 host1 = "00:00:00:00:00:" + \
554 str( hex( i )[ 2: ] ).zfill( 2 ).upper()
555 host2 = "00:00:00:00:00:" + \
556 str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper()
557 # NOTE: getHost can return None
558 host1Dict = main.ONOScli1.getHost( host1 )
559 host2Dict = main.ONOScli1.getHost( host2 )
560 host1Id = None
561 host2Id = None
562 if host1Dict and host2Dict:
563 host1Id = host1Dict.get( 'id', None )
564 host2Id = host2Dict.get( 'id', None )
565 if host1Id and host2Id:
Jon Halle1a3b752015-07-22 13:02:46 -0700566 nodeNum = ( i % main.numCtrls )
567 tmpId = main.CLIs[ nodeNum ].addHostIntent( host1Id, host2Id )
Jon Hall5cf14d52015-07-16 12:15:19 -0700568 if tmpId:
569 main.log.info( "Added intent with id: " + tmpId )
570 intentIds.append( tmpId )
571 else:
572 main.log.error( "addHostIntent returned: " +
573 repr( tmpId ) )
574 else:
575 main.log.error( "Error, getHost() failed for h" + str( i ) +
576 " and/or h" + str( i + 10 ) )
Jon Halle1a3b752015-07-22 13:02:46 -0700577 hosts = main.CLIs[ 0 ].hosts()
Jon Hall5cf14d52015-07-16 12:15:19 -0700578 main.log.warn( "Hosts output: " )
579 try:
580 main.log.warn( json.dumps( json.loads( hosts ),
581 sort_keys=True,
582 indent=4,
583 separators=( ',', ': ' ) ) )
584 except ( ValueError, TypeError ):
585 main.log.warn( repr( hosts ) )
586 hostResult = main.FALSE
587 utilities.assert_equals( expect=main.TRUE, actual=hostResult,
588 onpass="Found a host id for each host",
589 onfail="Error looking up host ids" )
590
591 intentStart = time.time()
592 onosIds = main.ONOScli1.getAllIntentsId()
593 main.log.info( "Submitted intents: " + str( intentIds ) )
594 main.log.info( "Intents in ONOS: " + str( onosIds ) )
595 for intent in intentIds:
596 if intent in onosIds:
597 pass # intent submitted is in onos
598 else:
599 intentAddResult = False
600 if intentAddResult:
601 intentStop = time.time()
602 else:
603 intentStop = None
604 # Print the intent states
605 intents = main.ONOScli1.intents()
606 intentStates = []
607 installedCheck = True
608 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
609 count = 0
610 try:
611 for intent in json.loads( intents ):
612 state = intent.get( 'state', None )
613 if "INSTALLED" not in state:
614 installedCheck = False
615 intentId = intent.get( 'id', None )
616 intentStates.append( ( intentId, state ) )
617 except ( ValueError, TypeError ):
618 main.log.exception( "Error parsing intents" )
619 # add submitted intents not in the store
620 tmplist = [ i for i, s in intentStates ]
621 missingIntents = False
622 for i in intentIds:
623 if i not in tmplist:
624 intentStates.append( ( i, " - " ) )
625 missingIntents = True
626 intentStates.sort()
627 for i, s in intentStates:
628 count += 1
629 main.log.info( "%-6s%-15s%-15s" %
630 ( str( count ), str( i ), str( s ) ) )
631 leaders = main.ONOScli1.leaders()
632 try:
633 missing = False
634 if leaders:
635 parsedLeaders = json.loads( leaders )
636 main.log.warn( json.dumps( parsedLeaders,
637 sort_keys=True,
638 indent=4,
639 separators=( ',', ': ' ) ) )
640 # check for all intent partitions
641 topics = []
642 for i in range( 14 ):
643 topics.append( "intent-partition-" + str( i ) )
644 main.log.debug( topics )
645 ONOStopics = [ j['topic'] for j in parsedLeaders ]
646 for topic in topics:
647 if topic not in ONOStopics:
648 main.log.error( "Error: " + topic +
649 " not in leaders" )
650 missing = True
651 else:
652 main.log.error( "leaders() returned None" )
653 except ( ValueError, TypeError ):
654 main.log.exception( "Error parsing leaders" )
655 main.log.error( repr( leaders ) )
656 # Check all nodes
657 if missing:
Jon Halle1a3b752015-07-22 13:02:46 -0700658 for node in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -0700659 response = node.leaders( jsonFormat=False)
660 main.log.warn( str( node.name ) + " leaders output: \n" +
661 str( response ) )
662
663 partitions = main.ONOScli1.partitions()
664 try:
665 if partitions :
666 parsedPartitions = json.loads( partitions )
667 main.log.warn( json.dumps( parsedPartitions,
668 sort_keys=True,
669 indent=4,
670 separators=( ',', ': ' ) ) )
671 # TODO check for a leader in all paritions
672 # TODO check for consistency among nodes
673 else:
674 main.log.error( "partitions() returned None" )
675 except ( ValueError, TypeError ):
676 main.log.exception( "Error parsing partitions" )
677 main.log.error( repr( partitions ) )
678 pendingMap = main.ONOScli1.pendingMap()
679 try:
680 if pendingMap :
681 parsedPending = json.loads( pendingMap )
682 main.log.warn( json.dumps( parsedPending,
683 sort_keys=True,
684 indent=4,
685 separators=( ',', ': ' ) ) )
686 # TODO check something here?
687 else:
688 main.log.error( "pendingMap() returned None" )
689 except ( ValueError, TypeError ):
690 main.log.exception( "Error parsing pending map" )
691 main.log.error( repr( pendingMap ) )
692
693 intentAddResult = bool( intentAddResult and not missingIntents and
694 installedCheck )
695 if not intentAddResult:
696 main.log.error( "Error in pushing host intents to ONOS" )
697
698 main.step( "Intent Anti-Entropy dispersion" )
699 for i in range(100):
700 correct = True
701 main.log.info( "Submitted intents: " + str( sorted( intentIds ) ) )
Jon Halle1a3b752015-07-22 13:02:46 -0700702 for cli in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -0700703 onosIds = []
704 ids = cli.getAllIntentsId()
705 onosIds.append( ids )
706 main.log.debug( "Intents in " + cli.name + ": " +
707 str( sorted( onosIds ) ) )
708 if sorted( ids ) != sorted( intentIds ):
709 main.log.warn( "Set of intent IDs doesn't match" )
710 correct = False
711 break
712 else:
713 intents = json.loads( cli.intents() )
714 for intent in intents:
715 if intent[ 'state' ] != "INSTALLED":
716 main.log.warn( "Intent " + intent[ 'id' ] +
717 " is " + intent[ 'state' ] )
718 correct = False
719 break
720 if correct:
721 break
722 else:
723 time.sleep(1)
724 if not intentStop:
725 intentStop = time.time()
726 global gossipTime
727 gossipTime = intentStop - intentStart
728 main.log.info( "It took about " + str( gossipTime ) +
729 " seconds for all intents to appear in each node" )
Jon Hallb3ed8ed2015-10-28 16:43:55 -0700730 gossipPeriod = int( main.params['timers']['gossip'] )
731 maxGossipTime = gossipPeriod * len( main.nodes )
Jon Hall5cf14d52015-07-16 12:15:19 -0700732 utilities.assert_greater_equals(
Jon Hallb3ed8ed2015-10-28 16:43:55 -0700733 expect=maxGossipTime, actual=gossipTime,
Jon Hall5cf14d52015-07-16 12:15:19 -0700734 onpass="ECM anti-entropy for intents worked within " +
735 "expected time",
Jon Hallb3ed8ed2015-10-28 16:43:55 -0700736 onfail="Intent ECM anti-entropy took too long. " +
737 "Expected time:{}, Actual time:{}".format( maxGossipTime,
738 gossipTime ) )
739 if gossipTime <= maxGossipTime:
Jon Hall5cf14d52015-07-16 12:15:19 -0700740 intentAddResult = True
741
742 if not intentAddResult or "key" in pendingMap:
743 import time
744 installedCheck = True
745 main.log.info( "Sleeping 60 seconds to see if intents are found" )
746 time.sleep( 60 )
747 onosIds = main.ONOScli1.getAllIntentsId()
748 main.log.info( "Submitted intents: " + str( intentIds ) )
749 main.log.info( "Intents in ONOS: " + str( onosIds ) )
750 # Print the intent states
751 intents = main.ONOScli1.intents()
752 intentStates = []
753 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
754 count = 0
755 try:
756 for intent in json.loads( intents ):
757 # Iter through intents of a node
758 state = intent.get( 'state', None )
759 if "INSTALLED" not in state:
760 installedCheck = False
761 intentId = intent.get( 'id', None )
762 intentStates.append( ( intentId, state ) )
763 except ( ValueError, TypeError ):
764 main.log.exception( "Error parsing intents" )
765 # add submitted intents not in the store
766 tmplist = [ i for i, s in intentStates ]
767 for i in intentIds:
768 if i not in tmplist:
769 intentStates.append( ( i, " - " ) )
770 intentStates.sort()
771 for i, s in intentStates:
772 count += 1
773 main.log.info( "%-6s%-15s%-15s" %
774 ( str( count ), str( i ), str( s ) ) )
775 leaders = main.ONOScli1.leaders()
776 try:
777 missing = False
778 if leaders:
779 parsedLeaders = json.loads( leaders )
780 main.log.warn( json.dumps( parsedLeaders,
781 sort_keys=True,
782 indent=4,
783 separators=( ',', ': ' ) ) )
784 # check for all intent partitions
785 # check for election
786 topics = []
787 for i in range( 14 ):
788 topics.append( "intent-partition-" + str( i ) )
789 # FIXME: this should only be after we start the app
790 topics.append( "org.onosproject.election" )
791 main.log.debug( topics )
792 ONOStopics = [ j['topic'] for j in parsedLeaders ]
793 for topic in topics:
794 if topic not in ONOStopics:
795 main.log.error( "Error: " + topic +
796 " not in leaders" )
797 missing = True
798 else:
799 main.log.error( "leaders() returned None" )
800 except ( ValueError, TypeError ):
801 main.log.exception( "Error parsing leaders" )
802 main.log.error( repr( leaders ) )
803 # Check all nodes
804 if missing:
Jon Halle1a3b752015-07-22 13:02:46 -0700805 for node in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -0700806 response = node.leaders( jsonFormat=False)
807 main.log.warn( str( node.name ) + " leaders output: \n" +
808 str( response ) )
809
810 partitions = main.ONOScli1.partitions()
811 try:
812 if partitions :
813 parsedPartitions = json.loads( partitions )
814 main.log.warn( json.dumps( parsedPartitions,
815 sort_keys=True,
816 indent=4,
817 separators=( ',', ': ' ) ) )
818 # TODO check for a leader in all paritions
819 # TODO check for consistency among nodes
820 else:
821 main.log.error( "partitions() returned None" )
822 except ( ValueError, TypeError ):
823 main.log.exception( "Error parsing partitions" )
824 main.log.error( repr( partitions ) )
825 pendingMap = main.ONOScli1.pendingMap()
826 try:
827 if pendingMap :
828 parsedPending = json.loads( pendingMap )
829 main.log.warn( json.dumps( parsedPending,
830 sort_keys=True,
831 indent=4,
832 separators=( ',', ': ' ) ) )
833 # TODO check something here?
834 else:
835 main.log.error( "pendingMap() returned None" )
836 except ( ValueError, TypeError ):
837 main.log.exception( "Error parsing pending map" )
838 main.log.error( repr( pendingMap ) )
839
840 def CASE4( self, main ):
841 """
842 Ping across added host intents
843 """
844 import json
845 import time
Jon Halle1a3b752015-07-22 13:02:46 -0700846 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -0700847 assert main, "main not defined"
848 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -0700849 assert main.CLIs, "main.CLIs not defined"
850 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -0700851 main.case( "Verify connectivity by sendind traffic across Intents" )
Jon Hall783bbf92015-07-23 14:33:19 -0700852 main.caseExplanation = "Ping across added host intents to check " +\
Jon Hall5cf14d52015-07-16 12:15:19 -0700853 "functionality and check the state of " +\
854 "the intent"
855 main.step( "Ping across added host intents" )
856 PingResult = main.TRUE
857 for i in range( 8, 18 ):
858 ping = main.Mininet1.pingHost( src="h" + str( i ),
859 target="h" + str( i + 10 ) )
860 PingResult = PingResult and ping
861 if ping == main.FALSE:
862 main.log.warn( "Ping failed between h" + str( i ) +
863 " and h" + str( i + 10 ) )
864 elif ping == main.TRUE:
865 main.log.info( "Ping test passed!" )
866 # Don't set PingResult or you'd override failures
867 if PingResult == main.FALSE:
868 main.log.error(
869 "Intents have not been installed correctly, pings failed." )
870 # TODO: pretty print
871 main.log.warn( "ONOS1 intents: " )
872 try:
873 tmpIntents = main.ONOScli1.intents()
874 main.log.warn( json.dumps( json.loads( tmpIntents ),
875 sort_keys=True,
876 indent=4,
877 separators=( ',', ': ' ) ) )
878 except ( ValueError, TypeError ):
879 main.log.warn( repr( tmpIntents ) )
880 utilities.assert_equals(
881 expect=main.TRUE,
882 actual=PingResult,
883 onpass="Intents have been installed correctly and pings work",
884 onfail="Intents have not been installed correctly, pings failed." )
885
886 main.step( "Check Intent state" )
887 installedCheck = False
888 loopCount = 0
889 while not installedCheck and loopCount < 40:
890 installedCheck = True
891 # Print the intent states
892 intents = main.ONOScli1.intents()
893 intentStates = []
894 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
895 count = 0
896 # Iter through intents of a node
897 try:
898 for intent in json.loads( intents ):
899 state = intent.get( 'state', None )
900 if "INSTALLED" not in state:
901 installedCheck = False
902 intentId = intent.get( 'id', None )
903 intentStates.append( ( intentId, state ) )
904 except ( ValueError, TypeError ):
905 main.log.exception( "Error parsing intents." )
906 # Print states
907 intentStates.sort()
908 for i, s in intentStates:
909 count += 1
910 main.log.info( "%-6s%-15s%-15s" %
911 ( str( count ), str( i ), str( s ) ) )
912 if not installedCheck:
913 time.sleep( 1 )
914 loopCount += 1
915 utilities.assert_equals( expect=True, actual=installedCheck,
916 onpass="Intents are all INSTALLED",
917 onfail="Intents are not all in " +
918 "INSTALLED state" )
919
920 main.step( "Check leadership of topics" )
921 leaders = main.ONOScli1.leaders()
922 topicCheck = main.TRUE
923 try:
924 if leaders:
925 parsedLeaders = json.loads( leaders )
926 main.log.warn( json.dumps( parsedLeaders,
927 sort_keys=True,
928 indent=4,
929 separators=( ',', ': ' ) ) )
930 # check for all intent partitions
931 # check for election
932 # TODO: Look at Devices as topics now that it uses this system
933 topics = []
934 for i in range( 14 ):
935 topics.append( "intent-partition-" + str( i ) )
936 # FIXME: this should only be after we start the app
937 # FIXME: topics.append( "org.onosproject.election" )
938 # Print leaders output
939 main.log.debug( topics )
940 ONOStopics = [ j['topic'] for j in parsedLeaders ]
941 for topic in topics:
942 if topic not in ONOStopics:
943 main.log.error( "Error: " + topic +
944 " not in leaders" )
945 topicCheck = main.FALSE
946 else:
947 main.log.error( "leaders() returned None" )
948 topicCheck = main.FALSE
949 except ( ValueError, TypeError ):
950 topicCheck = main.FALSE
951 main.log.exception( "Error parsing leaders" )
952 main.log.error( repr( leaders ) )
953 # TODO: Check for a leader of these topics
954 # Check all nodes
955 if topicCheck:
Jon Halle1a3b752015-07-22 13:02:46 -0700956 for node in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -0700957 response = node.leaders( jsonFormat=False)
958 main.log.warn( str( node.name ) + " leaders output: \n" +
959 str( response ) )
960
961 utilities.assert_equals( expect=main.TRUE, actual=topicCheck,
962 onpass="intent Partitions is in leaders",
963 onfail="Some topics were lost " )
964 # Print partitions
965 partitions = main.ONOScli1.partitions()
966 try:
967 if partitions :
968 parsedPartitions = json.loads( partitions )
969 main.log.warn( json.dumps( parsedPartitions,
970 sort_keys=True,
971 indent=4,
972 separators=( ',', ': ' ) ) )
973 # TODO check for a leader in all paritions
974 # TODO check for consistency among nodes
975 else:
976 main.log.error( "partitions() returned None" )
977 except ( ValueError, TypeError ):
978 main.log.exception( "Error parsing partitions" )
979 main.log.error( repr( partitions ) )
980 # Print Pending Map
981 pendingMap = main.ONOScli1.pendingMap()
982 try:
983 if pendingMap :
984 parsedPending = json.loads( pendingMap )
985 main.log.warn( json.dumps( parsedPending,
986 sort_keys=True,
987 indent=4,
988 separators=( ',', ': ' ) ) )
989 # TODO check something here?
990 else:
991 main.log.error( "pendingMap() returned None" )
992 except ( ValueError, TypeError ):
993 main.log.exception( "Error parsing pending map" )
994 main.log.error( repr( pendingMap ) )
995
996 if not installedCheck:
997 main.log.info( "Waiting 60 seconds to see if the state of " +
998 "intents change" )
999 time.sleep( 60 )
1000 # Print the intent states
1001 intents = main.ONOScli1.intents()
1002 intentStates = []
1003 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
1004 count = 0
1005 # Iter through intents of a node
1006 try:
1007 for intent in json.loads( intents ):
1008 state = intent.get( 'state', None )
1009 if "INSTALLED" not in state:
1010 installedCheck = False
1011 intentId = intent.get( 'id', None )
1012 intentStates.append( ( intentId, state ) )
1013 except ( ValueError, TypeError ):
1014 main.log.exception( "Error parsing intents." )
1015 intentStates.sort()
1016 for i, s in intentStates:
1017 count += 1
1018 main.log.info( "%-6s%-15s%-15s" %
1019 ( str( count ), str( i ), str( s ) ) )
1020 leaders = main.ONOScli1.leaders()
1021 try:
1022 missing = False
1023 if leaders:
1024 parsedLeaders = json.loads( leaders )
1025 main.log.warn( json.dumps( parsedLeaders,
1026 sort_keys=True,
1027 indent=4,
1028 separators=( ',', ': ' ) ) )
1029 # check for all intent partitions
1030 # check for election
1031 topics = []
1032 for i in range( 14 ):
1033 topics.append( "intent-partition-" + str( i ) )
1034 # FIXME: this should only be after we start the app
1035 topics.append( "org.onosproject.election" )
1036 main.log.debug( topics )
1037 ONOStopics = [ j['topic'] for j in parsedLeaders ]
1038 for topic in topics:
1039 if topic not in ONOStopics:
1040 main.log.error( "Error: " + topic +
1041 " not in leaders" )
1042 missing = True
1043 else:
1044 main.log.error( "leaders() returned None" )
1045 except ( ValueError, TypeError ):
1046 main.log.exception( "Error parsing leaders" )
1047 main.log.error( repr( leaders ) )
1048 if missing:
Jon Halle1a3b752015-07-22 13:02:46 -07001049 for node in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -07001050 response = node.leaders( jsonFormat=False)
1051 main.log.warn( str( node.name ) + " leaders output: \n" +
1052 str( response ) )
1053
1054 partitions = main.ONOScli1.partitions()
1055 try:
1056 if partitions :
1057 parsedPartitions = json.loads( partitions )
1058 main.log.warn( json.dumps( parsedPartitions,
1059 sort_keys=True,
1060 indent=4,
1061 separators=( ',', ': ' ) ) )
1062 # TODO check for a leader in all paritions
1063 # TODO check for consistency among nodes
1064 else:
1065 main.log.error( "partitions() returned None" )
1066 except ( ValueError, TypeError ):
1067 main.log.exception( "Error parsing partitions" )
1068 main.log.error( repr( partitions ) )
1069 pendingMap = main.ONOScli1.pendingMap()
1070 try:
1071 if pendingMap :
1072 parsedPending = json.loads( pendingMap )
1073 main.log.warn( json.dumps( parsedPending,
1074 sort_keys=True,
1075 indent=4,
1076 separators=( ',', ': ' ) ) )
1077 # TODO check something here?
1078 else:
1079 main.log.error( "pendingMap() returned None" )
1080 except ( ValueError, TypeError ):
1081 main.log.exception( "Error parsing pending map" )
1082 main.log.error( repr( pendingMap ) )
1083 # Print flowrules
Jon Halle1a3b752015-07-22 13:02:46 -07001084 main.log.debug( main.CLIs[0].flows( jsonFormat=False ) )
Jon Hall5cf14d52015-07-16 12:15:19 -07001085 main.step( "Wait a minute then ping again" )
1086 # the wait is above
1087 PingResult = main.TRUE
1088 for i in range( 8, 18 ):
1089 ping = main.Mininet1.pingHost( src="h" + str( i ),
1090 target="h" + str( i + 10 ) )
1091 PingResult = PingResult and ping
1092 if ping == main.FALSE:
1093 main.log.warn( "Ping failed between h" + str( i ) +
1094 " and h" + str( i + 10 ) )
1095 elif ping == main.TRUE:
1096 main.log.info( "Ping test passed!" )
1097 # Don't set PingResult or you'd override failures
1098 if PingResult == main.FALSE:
1099 main.log.error(
1100 "Intents have not been installed correctly, pings failed." )
1101 # TODO: pretty print
1102 main.log.warn( "ONOS1 intents: " )
1103 try:
1104 tmpIntents = main.ONOScli1.intents()
1105 main.log.warn( json.dumps( json.loads( tmpIntents ),
1106 sort_keys=True,
1107 indent=4,
1108 separators=( ',', ': ' ) ) )
1109 except ( ValueError, TypeError ):
1110 main.log.warn( repr( tmpIntents ) )
1111 utilities.assert_equals(
1112 expect=main.TRUE,
1113 actual=PingResult,
1114 onpass="Intents have been installed correctly and pings work",
1115 onfail="Intents have not been installed correctly, pings failed." )
1116
1117 def CASE5( self, main ):
1118 """
1119 Reading state of ONOS
1120 """
1121 import json
1122 import time
Jon Halle1a3b752015-07-22 13:02:46 -07001123 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07001124 assert main, "main not defined"
1125 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07001126 assert main.CLIs, "main.CLIs not defined"
1127 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07001128
1129 main.case( "Setting up and gathering data for current state" )
1130 # The general idea for this test case is to pull the state of
1131 # ( intents,flows, topology,... ) from each ONOS node
1132 # We can then compare them with each other and also with past states
1133
1134 main.step( "Check that each switch has a master" )
1135 global mastershipState
1136 mastershipState = '[]'
1137
1138 # Assert that each device has a master
1139 rolesNotNull = main.TRUE
1140 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001141 for i in range( main.numCtrls ):
1142 t = main.Thread( target=main.CLIs[i].rolesNotNull,
Jon Hall5cf14d52015-07-16 12:15:19 -07001143 name="rolesNotNull-" + str( i ),
1144 args=[] )
1145 threads.append( t )
1146 t.start()
1147
1148 for t in threads:
1149 t.join()
1150 rolesNotNull = rolesNotNull and t.result
1151 utilities.assert_equals(
1152 expect=main.TRUE,
1153 actual=rolesNotNull,
1154 onpass="Each device has a master",
1155 onfail="Some devices don't have a master assigned" )
1156
1157 main.step( "Get the Mastership of each switch from each controller" )
1158 ONOSMastership = []
1159 mastershipCheck = main.FALSE
1160 consistentMastership = True
1161 rolesResults = True
1162 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001163 for i in range( main.numCtrls ):
1164 t = main.Thread( target=main.CLIs[i].roles,
Jon Hall5cf14d52015-07-16 12:15:19 -07001165 name="roles-" + str( i ),
1166 args=[] )
1167 threads.append( t )
1168 t.start()
1169
1170 for t in threads:
1171 t.join()
1172 ONOSMastership.append( t.result )
1173
Jon Halle1a3b752015-07-22 13:02:46 -07001174 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001175 if not ONOSMastership[i] or "Error" in ONOSMastership[i]:
1176 main.log.error( "Error in getting ONOS" + str( i + 1 ) +
1177 " roles" )
1178 main.log.warn(
1179 "ONOS" + str( i + 1 ) + " mastership response: " +
1180 repr( ONOSMastership[i] ) )
1181 rolesResults = False
1182 utilities.assert_equals(
1183 expect=True,
1184 actual=rolesResults,
1185 onpass="No error in reading roles output",
1186 onfail="Error in reading roles from ONOS" )
1187
1188 main.step( "Check for consistency in roles from each controller" )
1189 if all([ i == ONOSMastership[ 0 ] for i in ONOSMastership ] ):
1190 main.log.info(
1191 "Switch roles are consistent across all ONOS nodes" )
1192 else:
1193 consistentMastership = False
1194 utilities.assert_equals(
1195 expect=True,
1196 actual=consistentMastership,
1197 onpass="Switch roles are consistent across all ONOS nodes",
1198 onfail="ONOS nodes have different views of switch roles" )
1199
1200 if rolesResults and not consistentMastership:
Jon Halle1a3b752015-07-22 13:02:46 -07001201 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001202 try:
1203 main.log.warn(
1204 "ONOS" + str( i + 1 ) + " roles: ",
1205 json.dumps(
1206 json.loads( ONOSMastership[ i ] ),
1207 sort_keys=True,
1208 indent=4,
1209 separators=( ',', ': ' ) ) )
1210 except ( ValueError, TypeError ):
1211 main.log.warn( repr( ONOSMastership[ i ] ) )
1212 elif rolesResults and consistentMastership:
1213 mastershipCheck = main.TRUE
1214 mastershipState = ONOSMastership[ 0 ]
1215
1216 main.step( "Get the intents from each controller" )
1217 global intentState
1218 intentState = []
1219 ONOSIntents = []
1220 intentCheck = main.FALSE
1221 consistentIntents = True
1222 intentsResults = True
1223 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001224 for i in range( main.numCtrls ):
1225 t = main.Thread( target=main.CLIs[i].intents,
Jon Hall5cf14d52015-07-16 12:15:19 -07001226 name="intents-" + str( i ),
1227 args=[],
1228 kwargs={ 'jsonFormat': True } )
1229 threads.append( t )
1230 t.start()
1231
1232 for t in threads:
1233 t.join()
1234 ONOSIntents.append( t.result )
1235
Jon Halle1a3b752015-07-22 13:02:46 -07001236 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001237 if not ONOSIntents[ i ] or "Error" in ONOSIntents[ i ]:
1238 main.log.error( "Error in getting ONOS" + str( i + 1 ) +
1239 " intents" )
1240 main.log.warn( "ONOS" + str( i + 1 ) + " intents response: " +
1241 repr( ONOSIntents[ i ] ) )
1242 intentsResults = False
1243 utilities.assert_equals(
1244 expect=True,
1245 actual=intentsResults,
1246 onpass="No error in reading intents output",
1247 onfail="Error in reading intents from ONOS" )
1248
1249 main.step( "Check for consistency in Intents from each controller" )
1250 if all([ sorted( i ) == sorted( ONOSIntents[ 0 ] ) for i in ONOSIntents ] ):
1251 main.log.info( "Intents are consistent across all ONOS " +
1252 "nodes" )
1253 else:
1254 consistentIntents = False
1255 main.log.error( "Intents not consistent" )
1256 utilities.assert_equals(
1257 expect=True,
1258 actual=consistentIntents,
1259 onpass="Intents are consistent across all ONOS nodes",
1260 onfail="ONOS nodes have different views of intents" )
1261
1262 if intentsResults:
1263 # Try to make it easy to figure out what is happening
1264 #
1265 # Intent ONOS1 ONOS2 ...
1266 # 0x01 INSTALLED INSTALLING
1267 # ... ... ...
1268 # ... ... ...
1269 title = " Id"
Jon Halle1a3b752015-07-22 13:02:46 -07001270 for n in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001271 title += " " * 10 + "ONOS" + str( n + 1 )
1272 main.log.warn( title )
Jon Halle1a3b752015-07-22 13:02:46 -07001273 # get all intent keys in the cluster
Jon Hall5cf14d52015-07-16 12:15:19 -07001274 keys = []
1275 try:
1276 # Get the set of all intent keys
1277 for nodeStr in ONOSIntents:
1278 node = json.loads( nodeStr )
1279 for intent in node:
1280 keys.append( intent.get( 'id' ) )
1281 keys = set( keys )
1282 # For each intent key, print the state on each node
1283 for key in keys:
1284 row = "%-13s" % key
1285 for nodeStr in ONOSIntents:
1286 node = json.loads( nodeStr )
1287 for intent in node:
1288 if intent.get( 'id', "Error" ) == key:
1289 row += "%-15s" % intent.get( 'state' )
1290 main.log.warn( row )
1291 # End of intent state table
1292 except ValueError as e:
1293 main.log.exception( e )
1294 main.log.debug( "nodeStr was: " + repr( nodeStr ) )
1295
1296 if intentsResults and not consistentIntents:
1297 # print the json objects
1298 n = len(ONOSIntents)
1299 main.log.debug( "ONOS" + str( n ) + " intents: " )
1300 main.log.debug( json.dumps( json.loads( ONOSIntents[ -1 ] ),
1301 sort_keys=True,
1302 indent=4,
1303 separators=( ',', ': ' ) ) )
Jon Halle1a3b752015-07-22 13:02:46 -07001304 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001305 if ONOSIntents[ i ] != ONOSIntents[ -1 ]:
1306 main.log.debug( "ONOS" + str( i + 1 ) + " intents: " )
1307 main.log.debug( json.dumps( json.loads( ONOSIntents[i] ),
1308 sort_keys=True,
1309 indent=4,
1310 separators=( ',', ': ' ) ) )
1311 else:
Jon Halle1a3b752015-07-22 13:02:46 -07001312 main.log.debug( main.nodes[ i ].name + " intents match ONOS" +
Jon Hall5cf14d52015-07-16 12:15:19 -07001313 str( n ) + " intents" )
1314 elif intentsResults and consistentIntents:
1315 intentCheck = main.TRUE
1316 intentState = ONOSIntents[ 0 ]
1317
1318 main.step( "Get the flows from each controller" )
1319 global flowState
1320 flowState = []
1321 ONOSFlows = []
1322 ONOSFlowsJson = []
1323 flowCheck = main.FALSE
1324 consistentFlows = True
1325 flowsResults = True
1326 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001327 for i in range( main.numCtrls ):
1328 t = main.Thread( target=main.CLIs[i].flows,
Jon Hall5cf14d52015-07-16 12:15:19 -07001329 name="flows-" + str( i ),
1330 args=[],
1331 kwargs={ 'jsonFormat': True } )
1332 threads.append( t )
1333 t.start()
1334
1335 # NOTE: Flows command can take some time to run
1336 time.sleep(30)
1337 for t in threads:
1338 t.join()
1339 result = t.result
1340 ONOSFlows.append( result )
1341
Jon Halle1a3b752015-07-22 13:02:46 -07001342 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001343 num = str( i + 1 )
1344 if not ONOSFlows[ i ] or "Error" in ONOSFlows[ i ]:
1345 main.log.error( "Error in getting ONOS" + num + " flows" )
1346 main.log.warn( "ONOS" + num + " flows response: " +
1347 repr( ONOSFlows[ i ] ) )
1348 flowsResults = False
1349 ONOSFlowsJson.append( None )
1350 else:
1351 try:
1352 ONOSFlowsJson.append( json.loads( ONOSFlows[ i ] ) )
1353 except ( ValueError, TypeError ):
1354 # FIXME: change this to log.error?
1355 main.log.exception( "Error in parsing ONOS" + num +
1356 " response as json." )
1357 main.log.error( repr( ONOSFlows[ i ] ) )
1358 ONOSFlowsJson.append( None )
1359 flowsResults = False
1360 utilities.assert_equals(
1361 expect=True,
1362 actual=flowsResults,
1363 onpass="No error in reading flows output",
1364 onfail="Error in reading flows from ONOS" )
1365
1366 main.step( "Check for consistency in Flows from each controller" )
1367 tmp = [ len( i ) == len( ONOSFlowsJson[ 0 ] ) for i in ONOSFlowsJson ]
1368 if all( tmp ):
1369 main.log.info( "Flow count is consistent across all ONOS nodes" )
1370 else:
1371 consistentFlows = False
1372 utilities.assert_equals(
1373 expect=True,
1374 actual=consistentFlows,
1375 onpass="The flow count is consistent across all ONOS nodes",
1376 onfail="ONOS nodes have different flow counts" )
1377
1378 if flowsResults and not consistentFlows:
Jon Halle1a3b752015-07-22 13:02:46 -07001379 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001380 try:
1381 main.log.warn(
1382 "ONOS" + str( i + 1 ) + " flows: " +
1383 json.dumps( json.loads( ONOSFlows[i] ), sort_keys=True,
1384 indent=4, separators=( ',', ': ' ) ) )
1385 except ( ValueError, TypeError ):
1386 main.log.warn(
1387 "ONOS" + str( i + 1 ) + " flows: " +
1388 repr( ONOSFlows[ i ] ) )
1389 elif flowsResults and consistentFlows:
1390 flowCheck = main.TRUE
1391 flowState = ONOSFlows[ 0 ]
1392
1393 main.step( "Get the OF Table entries" )
1394 global flows
1395 flows = []
1396 for i in range( 1, 29 ):
GlennRC68467eb2015-11-16 18:01:01 -08001397 flows.append( main.Mininet1.getFlowTable( "s" + str( i ), version="1.3", debug=False ) )
Jon Hall5cf14d52015-07-16 12:15:19 -07001398 if flowCheck == main.FALSE:
1399 for table in flows:
1400 main.log.warn( table )
GlennRC68467eb2015-11-16 18:01:01 -08001401
Jon Hall5cf14d52015-07-16 12:15:19 -07001402 # TODO: Compare switch flow tables with ONOS flow tables
1403
1404 main.step( "Start continuous pings" )
1405 main.Mininet2.pingLong(
1406 src=main.params[ 'PING' ][ 'source1' ],
1407 target=main.params[ 'PING' ][ 'target1' ],
1408 pingTime=500 )
1409 main.Mininet2.pingLong(
1410 src=main.params[ 'PING' ][ 'source2' ],
1411 target=main.params[ 'PING' ][ 'target2' ],
1412 pingTime=500 )
1413 main.Mininet2.pingLong(
1414 src=main.params[ 'PING' ][ 'source3' ],
1415 target=main.params[ 'PING' ][ 'target3' ],
1416 pingTime=500 )
1417 main.Mininet2.pingLong(
1418 src=main.params[ 'PING' ][ 'source4' ],
1419 target=main.params[ 'PING' ][ 'target4' ],
1420 pingTime=500 )
1421 main.Mininet2.pingLong(
1422 src=main.params[ 'PING' ][ 'source5' ],
1423 target=main.params[ 'PING' ][ 'target5' ],
1424 pingTime=500 )
1425 main.Mininet2.pingLong(
1426 src=main.params[ 'PING' ][ 'source6' ],
1427 target=main.params[ 'PING' ][ 'target6' ],
1428 pingTime=500 )
1429 main.Mininet2.pingLong(
1430 src=main.params[ 'PING' ][ 'source7' ],
1431 target=main.params[ 'PING' ][ 'target7' ],
1432 pingTime=500 )
1433 main.Mininet2.pingLong(
1434 src=main.params[ 'PING' ][ 'source8' ],
1435 target=main.params[ 'PING' ][ 'target8' ],
1436 pingTime=500 )
1437 main.Mininet2.pingLong(
1438 src=main.params[ 'PING' ][ 'source9' ],
1439 target=main.params[ 'PING' ][ 'target9' ],
1440 pingTime=500 )
1441 main.Mininet2.pingLong(
1442 src=main.params[ 'PING' ][ 'source10' ],
1443 target=main.params[ 'PING' ][ 'target10' ],
1444 pingTime=500 )
1445
1446 main.step( "Collecting topology information from ONOS" )
1447 devices = []
1448 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001449 for i in range( main.numCtrls ):
1450 t = main.Thread( target=main.CLIs[i].devices,
Jon Hall5cf14d52015-07-16 12:15:19 -07001451 name="devices-" + str( i ),
1452 args=[ ] )
1453 threads.append( t )
1454 t.start()
1455
1456 for t in threads:
1457 t.join()
1458 devices.append( t.result )
1459 hosts = []
1460 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001461 for i in range( main.numCtrls ):
1462 t = main.Thread( target=main.CLIs[i].hosts,
Jon Hall5cf14d52015-07-16 12:15:19 -07001463 name="hosts-" + str( i ),
1464 args=[ ] )
1465 threads.append( t )
1466 t.start()
1467
1468 for t in threads:
1469 t.join()
1470 try:
1471 hosts.append( json.loads( t.result ) )
1472 except ( ValueError, TypeError ):
1473 # FIXME: better handling of this, print which node
1474 # Maybe use thread name?
1475 main.log.exception( "Error parsing json output of hosts" )
Jon Hallf3d16e72015-12-16 17:45:08 -08001476 main.log.warn( repr( t.result ) )
Jon Hall5cf14d52015-07-16 12:15:19 -07001477 hosts.append( None )
1478
1479 ports = []
1480 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001481 for i in range( main.numCtrls ):
1482 t = main.Thread( target=main.CLIs[i].ports,
Jon Hall5cf14d52015-07-16 12:15:19 -07001483 name="ports-" + str( i ),
1484 args=[ ] )
1485 threads.append( t )
1486 t.start()
1487
1488 for t in threads:
1489 t.join()
1490 ports.append( t.result )
1491 links = []
1492 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001493 for i in range( main.numCtrls ):
1494 t = main.Thread( target=main.CLIs[i].links,
Jon Hall5cf14d52015-07-16 12:15:19 -07001495 name="links-" + str( i ),
1496 args=[ ] )
1497 threads.append( t )
1498 t.start()
1499
1500 for t in threads:
1501 t.join()
1502 links.append( t.result )
1503 clusters = []
1504 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001505 for i in range( main.numCtrls ):
1506 t = main.Thread( target=main.CLIs[i].clusters,
Jon Hall5cf14d52015-07-16 12:15:19 -07001507 name="clusters-" + str( i ),
1508 args=[ ] )
1509 threads.append( t )
1510 t.start()
1511
1512 for t in threads:
1513 t.join()
1514 clusters.append( t.result )
1515 # Compare json objects for hosts and dataplane clusters
1516
1517 # hosts
1518 main.step( "Host view is consistent across ONOS nodes" )
1519 consistentHostsResult = main.TRUE
1520 for controller in range( len( hosts ) ):
1521 controllerStr = str( controller + 1 )
Jon Hallf3d16e72015-12-16 17:45:08 -08001522 if hosts[ controller ] and "Error" not in hosts[ controller ]:
Jon Hall5cf14d52015-07-16 12:15:19 -07001523 if hosts[ controller ] == hosts[ 0 ]:
1524 continue
1525 else: # hosts not consistent
1526 main.log.error( "hosts from ONOS" +
1527 controllerStr +
1528 " is inconsistent with ONOS1" )
1529 main.log.warn( repr( hosts[ controller ] ) )
1530 consistentHostsResult = main.FALSE
1531
1532 else:
1533 main.log.error( "Error in getting ONOS hosts from ONOS" +
1534 controllerStr )
1535 consistentHostsResult = main.FALSE
1536 main.log.warn( "ONOS" + controllerStr +
1537 " hosts response: " +
1538 repr( hosts[ controller ] ) )
1539 utilities.assert_equals(
1540 expect=main.TRUE,
1541 actual=consistentHostsResult,
1542 onpass="Hosts view is consistent across all ONOS nodes",
1543 onfail="ONOS nodes have different views of hosts" )
1544
1545 main.step( "Each host has an IP address" )
1546 ipResult = main.TRUE
1547 for controller in range( 0, len( hosts ) ):
1548 controllerStr = str( controller + 1 )
Jon Hallf3d16e72015-12-16 17:45:08 -08001549 if hosts[ controller ]:
1550 for host in hosts[ controller ]:
1551 if not host.get( 'ipAddresses', [ ] ):
1552 main.log.error( "Error with host ips on controller" +
1553 controllerStr + ": " + str( host ) )
1554 ipResult = main.FALSE
Jon Hall5cf14d52015-07-16 12:15:19 -07001555 utilities.assert_equals(
1556 expect=main.TRUE,
1557 actual=ipResult,
1558 onpass="The ips of the hosts aren't empty",
1559 onfail="The ip of at least one host is missing" )
1560
1561 # Strongly connected clusters of devices
1562 main.step( "Cluster view is consistent across ONOS nodes" )
1563 consistentClustersResult = main.TRUE
1564 for controller in range( len( clusters ) ):
1565 controllerStr = str( controller + 1 )
1566 if "Error" not in clusters[ controller ]:
1567 if clusters[ controller ] == clusters[ 0 ]:
1568 continue
1569 else: # clusters not consistent
1570 main.log.error( "clusters from ONOS" + controllerStr +
1571 " is inconsistent with ONOS1" )
1572 consistentClustersResult = main.FALSE
1573
1574 else:
1575 main.log.error( "Error in getting dataplane clusters " +
1576 "from ONOS" + controllerStr )
1577 consistentClustersResult = main.FALSE
1578 main.log.warn( "ONOS" + controllerStr +
1579 " clusters response: " +
1580 repr( clusters[ controller ] ) )
1581 utilities.assert_equals(
1582 expect=main.TRUE,
1583 actual=consistentClustersResult,
1584 onpass="Clusters view is consistent across all ONOS nodes",
1585 onfail="ONOS nodes have different views of clusters" )
1586 # there should always only be one cluster
1587 main.step( "Cluster view correct across ONOS nodes" )
1588 try:
1589 numClusters = len( json.loads( clusters[ 0 ] ) )
1590 except ( ValueError, TypeError ):
1591 main.log.exception( "Error parsing clusters[0]: " +
1592 repr( clusters[ 0 ] ) )
1593 clusterResults = main.FALSE
1594 if numClusters == 1:
1595 clusterResults = main.TRUE
1596 utilities.assert_equals(
1597 expect=1,
1598 actual=numClusters,
1599 onpass="ONOS shows 1 SCC",
1600 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
1601
1602 main.step( "Comparing ONOS topology to MN" )
1603 devicesResults = main.TRUE
1604 linksResults = main.TRUE
1605 hostsResults = main.TRUE
1606 mnSwitches = main.Mininet1.getSwitches()
1607 mnLinks = main.Mininet1.getLinks()
1608 mnHosts = main.Mininet1.getHosts()
Jon Halle1a3b752015-07-22 13:02:46 -07001609 for controller in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001610 controllerStr = str( controller + 1 )
1611 if devices[ controller ] and ports[ controller ] and\
1612 "Error" not in devices[ controller ] and\
1613 "Error" not in ports[ controller ]:
1614
1615 currentDevicesResult = main.Mininet1.compareSwitches(
1616 mnSwitches,
1617 json.loads( devices[ controller ] ),
1618 json.loads( ports[ controller ] ) )
1619 else:
1620 currentDevicesResult = main.FALSE
1621 utilities.assert_equals( expect=main.TRUE,
1622 actual=currentDevicesResult,
1623 onpass="ONOS" + controllerStr +
1624 " Switches view is correct",
1625 onfail="ONOS" + controllerStr +
1626 " Switches view is incorrect" )
1627 if links[ controller ] and "Error" not in links[ controller ]:
1628 currentLinksResult = main.Mininet1.compareLinks(
1629 mnSwitches, mnLinks,
1630 json.loads( links[ controller ] ) )
1631 else:
1632 currentLinksResult = main.FALSE
1633 utilities.assert_equals( expect=main.TRUE,
1634 actual=currentLinksResult,
1635 onpass="ONOS" + controllerStr +
1636 " links view is correct",
1637 onfail="ONOS" + controllerStr +
1638 " links view is incorrect" )
1639
1640 if hosts[ controller ] or "Error" not in hosts[ controller ]:
1641 currentHostsResult = main.Mininet1.compareHosts(
1642 mnHosts,
1643 hosts[ controller ] )
1644 else:
1645 currentHostsResult = main.FALSE
1646 utilities.assert_equals( expect=main.TRUE,
1647 actual=currentHostsResult,
1648 onpass="ONOS" + controllerStr +
1649 " hosts exist in Mininet",
1650 onfail="ONOS" + controllerStr +
1651 " hosts don't match Mininet" )
1652
1653 devicesResults = devicesResults and currentDevicesResult
1654 linksResults = linksResults and currentLinksResult
1655 hostsResults = hostsResults and currentHostsResult
1656
1657 main.step( "Device information is correct" )
1658 utilities.assert_equals(
1659 expect=main.TRUE,
1660 actual=devicesResults,
1661 onpass="Device information is correct",
1662 onfail="Device information is incorrect" )
1663
1664 main.step( "Links are correct" )
1665 utilities.assert_equals(
1666 expect=main.TRUE,
1667 actual=linksResults,
1668 onpass="Link are correct",
1669 onfail="Links are incorrect" )
1670
1671 main.step( "Hosts are correct" )
1672 utilities.assert_equals(
1673 expect=main.TRUE,
1674 actual=hostsResults,
1675 onpass="Hosts are correct",
1676 onfail="Hosts are incorrect" )
1677
1678 def CASE6( self, main ):
1679 """
1680 The Failure case. Since this is the Sanity test, we do nothing.
1681 """
1682 import time
Jon Halle1a3b752015-07-22 13:02:46 -07001683 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07001684 assert main, "main not defined"
1685 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07001686 assert main.CLIs, "main.CLIs not defined"
1687 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07001688 main.case( "Wait 60 seconds instead of inducing a failure" )
1689 time.sleep( 60 )
1690 utilities.assert_equals(
1691 expect=main.TRUE,
1692 actual=main.TRUE,
1693 onpass="Sleeping 60 seconds",
1694 onfail="Something is terribly wrong with my math" )
1695
1696 def CASE7( self, main ):
1697 """
1698 Check state after ONOS failure
1699 """
1700 import json
Jon Halle1a3b752015-07-22 13:02:46 -07001701 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07001702 assert main, "main not defined"
1703 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07001704 assert main.CLIs, "main.CLIs not defined"
1705 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07001706 main.case( "Running ONOS Constant State Tests" )
1707
1708 main.step( "Check that each switch has a master" )
1709 # Assert that each device has a master
1710 rolesNotNull = main.TRUE
1711 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001712 for i in range( main.numCtrls ):
1713 t = main.Thread( target=main.CLIs[i].rolesNotNull,
Jon Hall5cf14d52015-07-16 12:15:19 -07001714 name="rolesNotNull-" + str( i ),
1715 args=[ ] )
1716 threads.append( t )
1717 t.start()
1718
1719 for t in threads:
1720 t.join()
1721 rolesNotNull = rolesNotNull and t.result
1722 utilities.assert_equals(
1723 expect=main.TRUE,
1724 actual=rolesNotNull,
1725 onpass="Each device has a master",
1726 onfail="Some devices don't have a master assigned" )
1727
1728 main.step( "Read device roles from ONOS" )
1729 ONOSMastership = []
1730 mastershipCheck = main.FALSE
1731 consistentMastership = True
1732 rolesResults = True
1733 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001734 for i in range( main.numCtrls ):
1735 t = main.Thread( target=main.CLIs[i].roles,
Jon Hall5cf14d52015-07-16 12:15:19 -07001736 name="roles-" + str( i ),
1737 args=[] )
1738 threads.append( t )
1739 t.start()
1740
1741 for t in threads:
1742 t.join()
1743 ONOSMastership.append( t.result )
1744
Jon Halle1a3b752015-07-22 13:02:46 -07001745 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001746 if not ONOSMastership[i] or "Error" in ONOSMastership[i]:
1747 main.log.error( "Error in getting ONOS" + str( i + 1 ) +
1748 " roles" )
1749 main.log.warn(
1750 "ONOS" + str( i + 1 ) + " mastership response: " +
1751 repr( ONOSMastership[i] ) )
1752 rolesResults = False
1753 utilities.assert_equals(
1754 expect=True,
1755 actual=rolesResults,
1756 onpass="No error in reading roles output",
1757 onfail="Error in reading roles from ONOS" )
1758
1759 main.step( "Check for consistency in roles from each controller" )
1760 if all([ i == ONOSMastership[ 0 ] for i in ONOSMastership ] ):
1761 main.log.info(
1762 "Switch roles are consistent across all ONOS nodes" )
1763 else:
1764 consistentMastership = False
1765 utilities.assert_equals(
1766 expect=True,
1767 actual=consistentMastership,
1768 onpass="Switch roles are consistent across all ONOS nodes",
1769 onfail="ONOS nodes have different views of switch roles" )
1770
1771 if rolesResults and not consistentMastership:
Jon Halle1a3b752015-07-22 13:02:46 -07001772 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001773 main.log.warn(
1774 "ONOS" + str( i + 1 ) + " roles: ",
1775 json.dumps(
1776 json.loads( ONOSMastership[ i ] ),
1777 sort_keys=True,
1778 indent=4,
1779 separators=( ',', ': ' ) ) )
1780 elif rolesResults and not consistentMastership:
1781 mastershipCheck = main.TRUE
1782
1783 description2 = "Compare switch roles from before failure"
1784 main.step( description2 )
1785 try:
1786 currentJson = json.loads( ONOSMastership[0] )
1787 oldJson = json.loads( mastershipState )
1788 except ( ValueError, TypeError ):
1789 main.log.exception( "Something is wrong with parsing " +
1790 "ONOSMastership[0] or mastershipState" )
1791 main.log.error( "ONOSMastership[0]: " + repr( ONOSMastership[0] ) )
1792 main.log.error( "mastershipState" + repr( mastershipState ) )
1793 main.cleanup()
1794 main.exit()
1795 mastershipCheck = main.TRUE
1796 for i in range( 1, 29 ):
1797 switchDPID = str(
1798 main.Mininet1.getSwitchDPID( switch="s" + str( i ) ) )
1799 current = [ switch[ 'master' ] for switch in currentJson
1800 if switchDPID in switch[ 'id' ] ]
1801 old = [ switch[ 'master' ] for switch in oldJson
1802 if switchDPID in switch[ 'id' ] ]
1803 if current == old:
1804 mastershipCheck = mastershipCheck and main.TRUE
1805 else:
1806 main.log.warn( "Mastership of switch %s changed" % switchDPID )
1807 mastershipCheck = main.FALSE
1808 utilities.assert_equals(
1809 expect=main.TRUE,
1810 actual=mastershipCheck,
1811 onpass="Mastership of Switches was not changed",
1812 onfail="Mastership of some switches changed" )
1813 mastershipCheck = mastershipCheck and consistentMastership
1814
1815 main.step( "Get the intents and compare across all nodes" )
1816 ONOSIntents = []
1817 intentCheck = main.FALSE
1818 consistentIntents = True
1819 intentsResults = True
1820 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07001821 for i in range( main.numCtrls ):
1822 t = main.Thread( target=main.CLIs[i].intents,
Jon Hall5cf14d52015-07-16 12:15:19 -07001823 name="intents-" + str( i ),
1824 args=[],
1825 kwargs={ 'jsonFormat': True } )
1826 threads.append( t )
1827 t.start()
1828
1829 for t in threads:
1830 t.join()
1831 ONOSIntents.append( t.result )
1832
Jon Halle1a3b752015-07-22 13:02:46 -07001833 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001834 if not ONOSIntents[ i ] or "Error" in ONOSIntents[ i ]:
1835 main.log.error( "Error in getting ONOS" + str( i + 1 ) +
1836 " intents" )
1837 main.log.warn( "ONOS" + str( i + 1 ) + " intents response: " +
1838 repr( ONOSIntents[ i ] ) )
1839 intentsResults = False
1840 utilities.assert_equals(
1841 expect=True,
1842 actual=intentsResults,
1843 onpass="No error in reading intents output",
1844 onfail="Error in reading intents from ONOS" )
1845
1846 main.step( "Check for consistency in Intents from each controller" )
1847 if all([ sorted( i ) == sorted( ONOSIntents[ 0 ] ) for i in ONOSIntents ] ):
1848 main.log.info( "Intents are consistent across all ONOS " +
1849 "nodes" )
1850 else:
1851 consistentIntents = False
1852
1853 # Try to make it easy to figure out what is happening
1854 #
1855 # Intent ONOS1 ONOS2 ...
1856 # 0x01 INSTALLED INSTALLING
1857 # ... ... ...
1858 # ... ... ...
1859 title = " ID"
Jon Halle1a3b752015-07-22 13:02:46 -07001860 for n in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001861 title += " " * 10 + "ONOS" + str( n + 1 )
1862 main.log.warn( title )
1863 # get all intent keys in the cluster
1864 keys = []
1865 for nodeStr in ONOSIntents:
1866 node = json.loads( nodeStr )
1867 for intent in node:
1868 keys.append( intent.get( 'id' ) )
1869 keys = set( keys )
1870 for key in keys:
1871 row = "%-13s" % key
1872 for nodeStr in ONOSIntents:
1873 node = json.loads( nodeStr )
1874 for intent in node:
1875 if intent.get( 'id' ) == key:
1876 row += "%-15s" % intent.get( 'state' )
1877 main.log.warn( row )
1878 # End table view
1879
1880 utilities.assert_equals(
1881 expect=True,
1882 actual=consistentIntents,
1883 onpass="Intents are consistent across all ONOS nodes",
1884 onfail="ONOS nodes have different views of intents" )
1885 intentStates = []
1886 for node in ONOSIntents: # Iter through ONOS nodes
1887 nodeStates = []
1888 # Iter through intents of a node
1889 try:
1890 for intent in json.loads( node ):
1891 nodeStates.append( intent[ 'state' ] )
1892 except ( ValueError, TypeError ):
1893 main.log.exception( "Error in parsing intents" )
1894 main.log.error( repr( node ) )
1895 intentStates.append( nodeStates )
1896 out = [ (i, nodeStates.count( i ) ) for i in set( nodeStates ) ]
1897 main.log.info( dict( out ) )
1898
1899 if intentsResults and not consistentIntents:
Jon Halle1a3b752015-07-22 13:02:46 -07001900 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07001901 main.log.warn( "ONOS" + str( i + 1 ) + " intents: " )
1902 main.log.warn( json.dumps(
1903 json.loads( ONOSIntents[ i ] ),
1904 sort_keys=True,
1905 indent=4,
1906 separators=( ',', ': ' ) ) )
1907 elif intentsResults and consistentIntents:
1908 intentCheck = main.TRUE
1909
1910 # NOTE: Store has no durability, so intents are lost across system
1911 # restarts
1912 main.step( "Compare current intents with intents before the failure" )
1913 # NOTE: this requires case 5 to pass for intentState to be set.
1914 # maybe we should stop the test if that fails?
1915 sameIntents = main.FALSE
1916 if intentState and intentState == ONOSIntents[ 0 ]:
1917 sameIntents = main.TRUE
1918 main.log.info( "Intents are consistent with before failure" )
1919 # TODO: possibly the states have changed? we may need to figure out
1920 # what the acceptable states are
1921 elif len( intentState ) == len( ONOSIntents[ 0 ] ):
1922 sameIntents = main.TRUE
1923 try:
1924 before = json.loads( intentState )
1925 after = json.loads( ONOSIntents[ 0 ] )
1926 for intent in before:
1927 if intent not in after:
1928 sameIntents = main.FALSE
1929 main.log.debug( "Intent is not currently in ONOS " +
1930 "(at least in the same form):" )
1931 main.log.debug( json.dumps( intent ) )
1932 except ( ValueError, TypeError ):
1933 main.log.exception( "Exception printing intents" )
1934 main.log.debug( repr( ONOSIntents[0] ) )
1935 main.log.debug( repr( intentState ) )
1936 if sameIntents == main.FALSE:
1937 try:
1938 main.log.debug( "ONOS intents before: " )
1939 main.log.debug( json.dumps( json.loads( intentState ),
1940 sort_keys=True, indent=4,
1941 separators=( ',', ': ' ) ) )
1942 main.log.debug( "Current ONOS intents: " )
1943 main.log.debug( json.dumps( json.loads( ONOSIntents[ 0 ] ),
1944 sort_keys=True, indent=4,
1945 separators=( ',', ': ' ) ) )
1946 except ( ValueError, TypeError ):
1947 main.log.exception( "Exception printing intents" )
1948 main.log.debug( repr( ONOSIntents[0] ) )
1949 main.log.debug( repr( intentState ) )
1950 utilities.assert_equals(
1951 expect=main.TRUE,
1952 actual=sameIntents,
1953 onpass="Intents are consistent with before failure",
1954 onfail="The Intents changed during failure" )
1955 intentCheck = intentCheck and sameIntents
1956
1957 main.step( "Get the OF Table entries and compare to before " +
1958 "component failure" )
1959 FlowTables = main.TRUE
Jon Hall5cf14d52015-07-16 12:15:19 -07001960 for i in range( 28 ):
1961 main.log.info( "Checking flow table on s" + str( i + 1 ) )
GlennRC68467eb2015-11-16 18:01:01 -08001962 tmpFlows = main.Mininet1.getFlowTable( "s" + str( i + 1 ), version="1.3", debug=False )
1963 FlowTables = FlowTables and main.Mininet1.flowTableComp( flows[i], tmpFlows )
Jon Hall5cf14d52015-07-16 12:15:19 -07001964 if FlowTables == main.FALSE:
GlennRC68467eb2015-11-16 18:01:01 -08001965 main.log.warn( "Differences in flow table for switch: s{}".format( i + 1 ) )
1966
Jon Hall5cf14d52015-07-16 12:15:19 -07001967 utilities.assert_equals(
1968 expect=main.TRUE,
1969 actual=FlowTables,
1970 onpass="No changes were found in the flow tables",
1971 onfail="Changes were found in the flow tables" )
1972
1973 main.Mininet2.pingLongKill()
1974 '''
1975 main.step( "Check the continuous pings to ensure that no packets " +
1976 "were dropped during component failure" )
1977 main.Mininet2.pingKill( main.params[ 'TESTONUSER' ],
1978 main.params[ 'TESTONIP' ] )
1979 LossInPings = main.FALSE
1980 # NOTE: checkForLoss returns main.FALSE with 0% packet loss
1981 for i in range( 8, 18 ):
1982 main.log.info(
1983 "Checking for a loss in pings along flow from s" +
1984 str( i ) )
1985 LossInPings = main.Mininet2.checkForLoss(
1986 "/tmp/ping.h" +
1987 str( i ) ) or LossInPings
1988 if LossInPings == main.TRUE:
1989 main.log.info( "Loss in ping detected" )
1990 elif LossInPings == main.ERROR:
1991 main.log.info( "There are multiple mininet process running" )
1992 elif LossInPings == main.FALSE:
1993 main.log.info( "No Loss in the pings" )
1994 main.log.info( "No loss of dataplane connectivity" )
1995 utilities.assert_equals(
1996 expect=main.FALSE,
1997 actual=LossInPings,
1998 onpass="No Loss of connectivity",
1999 onfail="Loss of dataplane connectivity detected" )
2000 '''
2001
2002 main.step( "Leadership Election is still functional" )
2003 # Test of LeadershipElection
2004 # NOTE: this only works for the sanity test. In case of failures,
2005 # leader will likely change
Jon Halle1a3b752015-07-22 13:02:46 -07002006 leader = main.nodes[ 0 ].ip_address
Jon Hall5cf14d52015-07-16 12:15:19 -07002007 leaderResult = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07002008 for cli in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -07002009 leaderN = cli.electionTestLeader()
2010 # verify leader is ONOS1
2011 if leaderN == leader:
2012 # all is well
2013 # NOTE: In failure scenario, this could be a new node, maybe
2014 # check != ONOS1
2015 pass
2016 elif leaderN == main.FALSE:
2017 # error in response
2018 main.log.error( "Something is wrong with " +
2019 "electionTestLeader function, check the" +
2020 " error logs" )
2021 leaderResult = main.FALSE
2022 elif leader != leaderN:
2023 leaderResult = main.FALSE
2024 main.log.error( cli.name + " sees " + str( leaderN ) +
2025 " as the leader of the election app. " +
2026 "Leader should be " + str( leader ) )
2027 utilities.assert_equals(
2028 expect=main.TRUE,
2029 actual=leaderResult,
2030 onpass="Leadership election passed",
2031 onfail="Something went wrong with Leadership election" )
2032
2033 def CASE8( self, main ):
2034 """
2035 Compare topo
2036 """
2037 import json
2038 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002039 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002040 assert main, "main not defined"
2041 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002042 assert main.CLIs, "main.CLIs not defined"
2043 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002044
2045 main.case( "Compare ONOS Topology view to Mininet topology" )
Jon Hall783bbf92015-07-23 14:33:19 -07002046 main.caseExplanation = "Compare topology objects between Mininet" +\
Jon Hall5cf14d52015-07-16 12:15:19 -07002047 " and ONOS"
Jon Hall5cf14d52015-07-16 12:15:19 -07002048 topoResult = main.FALSE
2049 elapsed = 0
2050 count = 0
Jon Halle9b1fa32015-12-08 15:32:21 -08002051 main.step( "Comparing ONOS topology to MN topology" )
Jon Hall5cf14d52015-07-16 12:15:19 -07002052 startTime = time.time()
2053 # Give time for Gossip to work
Jon Halle9b1fa32015-12-08 15:32:21 -08002054 while topoResult == main.FALSE and ( elapsed < 60 or count < 3 ):
Jon Hall96091e62015-09-21 17:34:17 -07002055 devicesResults = main.TRUE
2056 linksResults = main.TRUE
2057 hostsResults = main.TRUE
2058 hostAttachmentResults = True
Jon Hall5cf14d52015-07-16 12:15:19 -07002059 count += 1
2060 cliStart = time.time()
2061 devices = []
2062 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002063 for i in range( main.numCtrls ):
2064 t = main.Thread( target=main.CLIs[i].devices,
Jon Hall5cf14d52015-07-16 12:15:19 -07002065 name="devices-" + str( i ),
2066 args=[ ] )
2067 threads.append( t )
2068 t.start()
2069
2070 for t in threads:
2071 t.join()
2072 devices.append( t.result )
2073 hosts = []
2074 ipResult = main.TRUE
2075 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002076 for i in range( main.numCtrls ):
2077 t = main.Thread( target=main.CLIs[i].hosts,
Jon Hall5cf14d52015-07-16 12:15:19 -07002078 name="hosts-" + str( i ),
2079 args=[ ] )
2080 threads.append( t )
2081 t.start()
2082
2083 for t in threads:
2084 t.join()
2085 try:
2086 hosts.append( json.loads( t.result ) )
2087 except ( ValueError, TypeError ):
2088 main.log.exception( "Error parsing hosts results" )
2089 main.log.error( repr( t.result ) )
Jon Hallf3d16e72015-12-16 17:45:08 -08002090 hosts.append( None )
Jon Hall5cf14d52015-07-16 12:15:19 -07002091 for controller in range( 0, len( hosts ) ):
2092 controllerStr = str( controller + 1 )
Jon Hallacd1b182015-12-17 11:43:20 -08002093 if hosts[ controller ]:
2094 for host in hosts[ controller ]:
2095 if host is None or host.get( 'ipAddresses', [] ) == []:
2096 main.log.error(
2097 "Error with host ipAddresses on controller" +
2098 controllerStr + ": " + str( host ) )
2099 ipResult = main.FALSE
Jon Hall5cf14d52015-07-16 12:15:19 -07002100 ports = []
2101 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002102 for i in range( main.numCtrls ):
2103 t = main.Thread( target=main.CLIs[i].ports,
Jon Hall5cf14d52015-07-16 12:15:19 -07002104 name="ports-" + str( i ),
2105 args=[ ] )
2106 threads.append( t )
2107 t.start()
2108
2109 for t in threads:
2110 t.join()
2111 ports.append( t.result )
2112 links = []
2113 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002114 for i in range( main.numCtrls ):
2115 t = main.Thread( target=main.CLIs[i].links,
Jon Hall5cf14d52015-07-16 12:15:19 -07002116 name="links-" + str( i ),
2117 args=[ ] )
2118 threads.append( t )
2119 t.start()
2120
2121 for t in threads:
2122 t.join()
2123 links.append( t.result )
2124 clusters = []
2125 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002126 for i in range( main.numCtrls ):
2127 t = main.Thread( target=main.CLIs[i].clusters,
Jon Hall5cf14d52015-07-16 12:15:19 -07002128 name="clusters-" + str( i ),
2129 args=[ ] )
2130 threads.append( t )
2131 t.start()
2132
2133 for t in threads:
2134 t.join()
2135 clusters.append( t.result )
2136
2137 elapsed = time.time() - startTime
2138 cliTime = time.time() - cliStart
2139 print "Elapsed time: " + str( elapsed )
2140 print "CLI time: " + str( cliTime )
2141
2142 mnSwitches = main.Mininet1.getSwitches()
2143 mnLinks = main.Mininet1.getLinks()
2144 mnHosts = main.Mininet1.getHosts()
Jon Halle1a3b752015-07-22 13:02:46 -07002145 for controller in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07002146 controllerStr = str( controller + 1 )
2147 if devices[ controller ] and ports[ controller ] and\
2148 "Error" not in devices[ controller ] and\
2149 "Error" not in ports[ controller ]:
2150
2151 currentDevicesResult = main.Mininet1.compareSwitches(
2152 mnSwitches,
2153 json.loads( devices[ controller ] ),
2154 json.loads( ports[ controller ] ) )
2155 else:
2156 currentDevicesResult = main.FALSE
2157 utilities.assert_equals( expect=main.TRUE,
2158 actual=currentDevicesResult,
2159 onpass="ONOS" + controllerStr +
2160 " Switches view is correct",
2161 onfail="ONOS" + controllerStr +
2162 " Switches view is incorrect" )
2163
2164 if links[ controller ] and "Error" not in links[ controller ]:
2165 currentLinksResult = main.Mininet1.compareLinks(
2166 mnSwitches, mnLinks,
2167 json.loads( links[ controller ] ) )
2168 else:
2169 currentLinksResult = main.FALSE
2170 utilities.assert_equals( expect=main.TRUE,
2171 actual=currentLinksResult,
2172 onpass="ONOS" + controllerStr +
2173 " links view is correct",
2174 onfail="ONOS" + controllerStr +
2175 " links view is incorrect" )
2176
2177 if hosts[ controller ] or "Error" not in hosts[ controller ]:
2178 currentHostsResult = main.Mininet1.compareHosts(
2179 mnHosts,
2180 hosts[ controller ] )
2181 else:
2182 currentHostsResult = main.FALSE
2183 utilities.assert_equals( expect=main.TRUE,
2184 actual=currentHostsResult,
2185 onpass="ONOS" + controllerStr +
2186 " hosts exist in Mininet",
2187 onfail="ONOS" + controllerStr +
2188 " hosts don't match Mininet" )
2189 # CHECKING HOST ATTACHMENT POINTS
2190 hostAttachment = True
2191 zeroHosts = False
2192 # FIXME: topo-HA/obelisk specific mappings:
2193 # key is mac and value is dpid
2194 mappings = {}
2195 for i in range( 1, 29 ): # hosts 1 through 28
2196 # set up correct variables:
2197 macId = "00:" * 5 + hex( i ).split( "0x" )[1].upper().zfill(2)
2198 if i == 1:
2199 deviceId = "1000".zfill(16)
2200 elif i == 2:
2201 deviceId = "2000".zfill(16)
2202 elif i == 3:
2203 deviceId = "3000".zfill(16)
2204 elif i == 4:
2205 deviceId = "3004".zfill(16)
2206 elif i == 5:
2207 deviceId = "5000".zfill(16)
2208 elif i == 6:
2209 deviceId = "6000".zfill(16)
2210 elif i == 7:
2211 deviceId = "6007".zfill(16)
2212 elif i >= 8 and i <= 17:
2213 dpid = '3' + str( i ).zfill( 3 )
2214 deviceId = dpid.zfill(16)
2215 elif i >= 18 and i <= 27:
2216 dpid = '6' + str( i ).zfill( 3 )
2217 deviceId = dpid.zfill(16)
2218 elif i == 28:
2219 deviceId = "2800".zfill(16)
2220 mappings[ macId ] = deviceId
2221 if hosts[ controller ] or "Error" not in hosts[ controller ]:
2222 if hosts[ controller ] == []:
2223 main.log.warn( "There are no hosts discovered" )
2224 zeroHosts = True
2225 else:
2226 for host in hosts[ controller ]:
2227 mac = None
2228 location = None
2229 device = None
2230 port = None
2231 try:
2232 mac = host.get( 'mac' )
2233 assert mac, "mac field could not be found for this host object"
2234
2235 location = host.get( 'location' )
2236 assert location, "location field could not be found for this host object"
2237
2238 # Trim the protocol identifier off deviceId
2239 device = str( location.get( 'elementId' ) ).split(':')[1]
2240 assert device, "elementId field could not be found for this host location object"
2241
2242 port = location.get( 'port' )
2243 assert port, "port field could not be found for this host location object"
2244
2245 # Now check if this matches where they should be
2246 if mac and device and port:
2247 if str( port ) != "1":
2248 main.log.error( "The attachment port is incorrect for " +
2249 "host " + str( mac ) +
2250 ". Expected: 1 Actual: " + str( port) )
2251 hostAttachment = False
2252 if device != mappings[ str( mac ) ]:
2253 main.log.error( "The attachment device is incorrect for " +
2254 "host " + str( mac ) +
2255 ". Expected: " + mappings[ str( mac ) ] +
2256 " Actual: " + device )
2257 hostAttachment = False
2258 else:
2259 hostAttachment = False
2260 except AssertionError:
2261 main.log.exception( "Json object not as expected" )
2262 main.log.error( repr( host ) )
2263 hostAttachment = False
2264 else:
2265 main.log.error( "No hosts json output or \"Error\"" +
2266 " in output. hosts = " +
2267 repr( hosts[ controller ] ) )
2268 if zeroHosts is False:
2269 hostAttachment = True
2270
2271 # END CHECKING HOST ATTACHMENT POINTS
2272 devicesResults = devicesResults and currentDevicesResult
2273 linksResults = linksResults and currentLinksResult
2274 hostsResults = hostsResults and currentHostsResult
2275 hostAttachmentResults = hostAttachmentResults and\
2276 hostAttachment
2277 topoResult = ( devicesResults and linksResults
2278 and hostsResults and ipResult and
2279 hostAttachmentResults )
Jon Halle9b1fa32015-12-08 15:32:21 -08002280 utilities.assert_equals( expect=True,
2281 actual=topoResult,
2282 onpass="ONOS topology matches Mininet",
2283 onfail="ONOS topology don't match Mininet" )
2284 # End of While loop to pull ONOS state
Jon Hall5cf14d52015-07-16 12:15:19 -07002285
2286 # Compare json objects for hosts and dataplane clusters
2287
2288 # hosts
2289 main.step( "Hosts view is consistent across all ONOS nodes" )
2290 consistentHostsResult = main.TRUE
2291 for controller in range( len( hosts ) ):
2292 controllerStr = str( controller + 1 )
Jon Hallf3d16e72015-12-16 17:45:08 -08002293 if hosts[ controller ] or "Error" not in hosts[ controller ]:
Jon Hall5cf14d52015-07-16 12:15:19 -07002294 if hosts[ controller ] == hosts[ 0 ]:
2295 continue
2296 else: # hosts not consistent
2297 main.log.error( "hosts from ONOS" + controllerStr +
2298 " is inconsistent with ONOS1" )
2299 main.log.warn( repr( hosts[ controller ] ) )
2300 consistentHostsResult = main.FALSE
2301
2302 else:
2303 main.log.error( "Error in getting ONOS hosts from ONOS" +
2304 controllerStr )
2305 consistentHostsResult = main.FALSE
2306 main.log.warn( "ONOS" + controllerStr +
2307 " hosts response: " +
2308 repr( hosts[ controller ] ) )
2309 utilities.assert_equals(
2310 expect=main.TRUE,
2311 actual=consistentHostsResult,
2312 onpass="Hosts view is consistent across all ONOS nodes",
2313 onfail="ONOS nodes have different views of hosts" )
2314
2315 main.step( "Hosts information is correct" )
2316 hostsResults = hostsResults and ipResult
2317 utilities.assert_equals(
2318 expect=main.TRUE,
2319 actual=hostsResults,
2320 onpass="Host information is correct",
2321 onfail="Host information is incorrect" )
2322
2323 main.step( "Host attachment points to the network" )
2324 utilities.assert_equals(
2325 expect=True,
2326 actual=hostAttachmentResults,
2327 onpass="Hosts are correctly attached to the network",
2328 onfail="ONOS did not correctly attach hosts to the network" )
2329
2330 # Strongly connected clusters of devices
2331 main.step( "Clusters view is consistent across all ONOS nodes" )
2332 consistentClustersResult = main.TRUE
2333 for controller in range( len( clusters ) ):
2334 controllerStr = str( controller + 1 )
2335 if "Error" not in clusters[ controller ]:
2336 if clusters[ controller ] == clusters[ 0 ]:
2337 continue
2338 else: # clusters not consistent
2339 main.log.error( "clusters from ONOS" +
2340 controllerStr +
2341 " is inconsistent with ONOS1" )
2342 consistentClustersResult = main.FALSE
2343
2344 else:
2345 main.log.error( "Error in getting dataplane clusters " +
2346 "from ONOS" + controllerStr )
2347 consistentClustersResult = main.FALSE
2348 main.log.warn( "ONOS" + controllerStr +
2349 " clusters response: " +
2350 repr( clusters[ controller ] ) )
2351 utilities.assert_equals(
2352 expect=main.TRUE,
2353 actual=consistentClustersResult,
2354 onpass="Clusters view is consistent across all ONOS nodes",
2355 onfail="ONOS nodes have different views of clusters" )
2356
2357 main.step( "There is only one SCC" )
2358 # there should always only be one cluster
2359 try:
2360 numClusters = len( json.loads( clusters[ 0 ] ) )
2361 except ( ValueError, TypeError ):
2362 main.log.exception( "Error parsing clusters[0]: " +
2363 repr( clusters[0] ) )
2364 clusterResults = main.FALSE
2365 if numClusters == 1:
2366 clusterResults = main.TRUE
2367 utilities.assert_equals(
2368 expect=1,
2369 actual=numClusters,
2370 onpass="ONOS shows 1 SCC",
2371 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
2372
2373 topoResult = ( devicesResults and linksResults
2374 and hostsResults and consistentHostsResult
2375 and consistentClustersResult and clusterResults
2376 and ipResult and hostAttachmentResults )
2377
2378 topoResult = topoResult and int( count <= 2 )
2379 note = "note it takes about " + str( int( cliTime ) ) + \
2380 " seconds for the test to make all the cli calls to fetch " +\
2381 "the topology from each ONOS instance"
2382 main.log.info(
2383 "Very crass estimate for topology discovery/convergence( " +
2384 str( note ) + " ): " + str( elapsed ) + " seconds, " +
2385 str( count ) + " tries" )
2386
2387 main.step( "Device information is correct" )
2388 utilities.assert_equals(
2389 expect=main.TRUE,
2390 actual=devicesResults,
2391 onpass="Device information is correct",
2392 onfail="Device information is incorrect" )
2393
2394 main.step( "Links are correct" )
2395 utilities.assert_equals(
2396 expect=main.TRUE,
2397 actual=linksResults,
2398 onpass="Link are correct",
2399 onfail="Links are incorrect" )
2400
2401 main.step( "Hosts are correct" )
2402 utilities.assert_equals(
2403 expect=main.TRUE,
2404 actual=hostsResults,
2405 onpass="Hosts are correct",
2406 onfail="Hosts are incorrect" )
2407
2408 # FIXME: move this to an ONOS state case
2409 main.step( "Checking ONOS nodes" )
2410 nodesOutput = []
2411 nodeResults = main.TRUE
2412 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002413 for i in range( main.numCtrls ):
2414 t = main.Thread( target=main.CLIs[i].nodes,
Jon Hall5cf14d52015-07-16 12:15:19 -07002415 name="nodes-" + str( i ),
2416 args=[ ] )
2417 threads.append( t )
2418 t.start()
2419
2420 for t in threads:
2421 t.join()
2422 nodesOutput.append( t.result )
Jon Halle1a3b752015-07-22 13:02:46 -07002423 ips = [ node.ip_address for node in main.nodes ]
Jon Halle9b1fa32015-12-08 15:32:21 -08002424 ips.sort()
Jon Hall5cf14d52015-07-16 12:15:19 -07002425 for i in nodesOutput:
2426 try:
2427 current = json.loads( i )
Jon Halle9b1fa32015-12-08 15:32:21 -08002428 activeIps = []
2429 currentResult = main.FALSE
Jon Hall5cf14d52015-07-16 12:15:19 -07002430 for node in current:
Jon Halle9b1fa32015-12-08 15:32:21 -08002431 if node['state'] == 'ACTIVE':
2432 activeIps.append( node['ip'] )
2433 activeIps.sort()
2434 if ips == activeIps:
2435 currentResult = main.TRUE
Jon Hall5cf14d52015-07-16 12:15:19 -07002436 except ( ValueError, TypeError ):
2437 main.log.error( "Error parsing nodes output" )
2438 main.log.warn( repr( i ) )
Jon Halle9b1fa32015-12-08 15:32:21 -08002439 currentResult = main.FALSE
2440 nodeResults = nodeResults and currentResult
Jon Hall5cf14d52015-07-16 12:15:19 -07002441 utilities.assert_equals( expect=main.TRUE, actual=nodeResults,
2442 onpass="Nodes check successful",
2443 onfail="Nodes check NOT successful" )
2444
2445 def CASE9( self, main ):
2446 """
2447 Link s3-s28 down
2448 """
2449 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002450 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002451 assert main, "main not defined"
2452 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002453 assert main.CLIs, "main.CLIs not defined"
2454 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002455 # NOTE: You should probably run a topology check after this
2456
2457 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
2458
2459 description = "Turn off a link to ensure that Link Discovery " +\
2460 "is working properly"
2461 main.case( description )
2462
2463 main.step( "Kill Link between s3 and s28" )
2464 LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" )
2465 main.log.info( "Waiting " + str( linkSleep ) +
2466 " seconds for link down to be discovered" )
2467 time.sleep( linkSleep )
2468 utilities.assert_equals( expect=main.TRUE, actual=LinkDown,
2469 onpass="Link down successful",
2470 onfail="Failed to bring link down" )
2471 # TODO do some sort of check here
2472
2473 def CASE10( self, main ):
2474 """
2475 Link s3-s28 up
2476 """
2477 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002478 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002479 assert main, "main not defined"
2480 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002481 assert main.CLIs, "main.CLIs not defined"
2482 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002483 # NOTE: You should probably run a topology check after this
2484
2485 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
2486
2487 description = "Restore a link to ensure that Link Discovery is " + \
2488 "working properly"
2489 main.case( description )
2490
2491 main.step( "Bring link between s3 and s28 back up" )
2492 LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" )
2493 main.log.info( "Waiting " + str( linkSleep ) +
2494 " seconds for link up to be discovered" )
2495 time.sleep( linkSleep )
2496 utilities.assert_equals( expect=main.TRUE, actual=LinkUp,
2497 onpass="Link up successful",
2498 onfail="Failed to bring link up" )
2499 # TODO do some sort of check here
2500
2501 def CASE11( self, main ):
2502 """
2503 Switch Down
2504 """
2505 # NOTE: You should probably run a topology check after this
2506 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002507 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002508 assert main, "main not defined"
2509 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002510 assert main.CLIs, "main.CLIs not defined"
2511 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002512
2513 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
2514
2515 description = "Killing a switch to ensure it is discovered correctly"
2516 main.case( description )
2517 switch = main.params[ 'kill' ][ 'switch' ]
2518 switchDPID = main.params[ 'kill' ][ 'dpid' ]
2519
2520 # TODO: Make this switch parameterizable
2521 main.step( "Kill " + switch )
2522 main.log.info( "Deleting " + switch )
2523 main.Mininet1.delSwitch( switch )
2524 main.log.info( "Waiting " + str( switchSleep ) +
2525 " seconds for switch down to be discovered" )
2526 time.sleep( switchSleep )
2527 device = main.ONOScli1.getDevice( dpid=switchDPID )
2528 # Peek at the deleted switch
2529 main.log.warn( str( device ) )
2530 result = main.FALSE
2531 if device and device[ 'available' ] is False:
2532 result = main.TRUE
2533 utilities.assert_equals( expect=main.TRUE, actual=result,
2534 onpass="Kill switch successful",
2535 onfail="Failed to kill switch?" )
2536
2537 def CASE12( self, main ):
2538 """
2539 Switch Up
2540 """
2541 # NOTE: You should probably run a topology check after this
2542 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002543 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002544 assert main, "main not defined"
2545 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002546 assert main.CLIs, "main.CLIs not defined"
2547 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002548 assert ONOS1Port, "ONOS1Port not defined"
2549 assert ONOS2Port, "ONOS2Port not defined"
2550 assert ONOS3Port, "ONOS3Port not defined"
2551 assert ONOS4Port, "ONOS4Port not defined"
2552 assert ONOS5Port, "ONOS5Port not defined"
2553 assert ONOS6Port, "ONOS6Port not defined"
2554 assert ONOS7Port, "ONOS7Port not defined"
2555
2556 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
2557 switch = main.params[ 'kill' ][ 'switch' ]
2558 switchDPID = main.params[ 'kill' ][ 'dpid' ]
2559 links = main.params[ 'kill' ][ 'links' ].split()
2560 description = "Adding a switch to ensure it is discovered correctly"
2561 main.case( description )
2562
2563 main.step( "Add back " + switch )
2564 main.Mininet1.addSwitch( switch, dpid=switchDPID )
2565 for peer in links:
2566 main.Mininet1.addLink( switch, peer )
2567 ipList = []
Jon Halle1a3b752015-07-22 13:02:46 -07002568 for i in range( main.numCtrls ):
2569 ipList.append( main.nodes[ i ].ip_address )
Jon Hall5cf14d52015-07-16 12:15:19 -07002570 main.Mininet1.assignSwController( sw=switch, ip=ipList )
2571 main.log.info( "Waiting " + str( switchSleep ) +
2572 " seconds for switch up to be discovered" )
2573 time.sleep( switchSleep )
2574 device = main.ONOScli1.getDevice( dpid=switchDPID )
2575 # Peek at the deleted switch
2576 main.log.warn( str( device ) )
2577 result = main.FALSE
2578 if device and device[ 'available' ]:
2579 result = main.TRUE
2580 utilities.assert_equals( expect=main.TRUE, actual=result,
2581 onpass="add switch successful",
2582 onfail="Failed to add switch?" )
2583
2584 def CASE13( self, main ):
2585 """
2586 Clean up
2587 """
2588 import os
2589 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002590 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002591 assert main, "main not defined"
2592 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002593 assert main.CLIs, "main.CLIs not defined"
2594 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002595
2596 # printing colors to terminal
2597 colors = { 'cyan': '\033[96m', 'purple': '\033[95m',
2598 'blue': '\033[94m', 'green': '\033[92m',
2599 'yellow': '\033[93m', 'red': '\033[91m', 'end': '\033[0m' }
2600 main.case( "Test Cleanup" )
2601 main.step( "Killing tcpdumps" )
2602 main.Mininet2.stopTcpdump()
2603
2604 testname = main.TEST
Jon Hall96091e62015-09-21 17:34:17 -07002605 if main.params[ 'BACKUP' ][ 'ENABLED' ] == "True":
Jon Hall5cf14d52015-07-16 12:15:19 -07002606 main.step( "Copying MN pcap and ONOS log files to test station" )
2607 teststationUser = main.params[ 'BACKUP' ][ 'TESTONUSER' ]
2608 teststationIP = main.params[ 'BACKUP' ][ 'TESTONIP' ]
Jon Hall96091e62015-09-21 17:34:17 -07002609 # NOTE: MN Pcap file is being saved to logdir.
2610 # We scp this file as MN and TestON aren't necessarily the same vm
2611
2612 # FIXME: To be replaced with a Jenkin's post script
Jon Hall5cf14d52015-07-16 12:15:19 -07002613 # TODO: Load these from params
2614 # NOTE: must end in /
2615 logFolder = "/opt/onos/log/"
2616 logFiles = [ "karaf.log", "karaf.log.1" ]
2617 # NOTE: must end in /
Jon Hall5cf14d52015-07-16 12:15:19 -07002618 for f in logFiles:
Jon Halle1a3b752015-07-22 13:02:46 -07002619 for node in main.nodes:
Jon Hall96091e62015-09-21 17:34:17 -07002620 dstName = main.logdir + "/" + node.name + "-" + f
2621 main.ONOSbench.secureCopy( node.user_name, node.ip_address,
2622 logFolder + f, dstName )
Jon Hall5cf14d52015-07-16 12:15:19 -07002623 # std*.log's
2624 # NOTE: must end in /
2625 logFolder = "/opt/onos/var/"
2626 logFiles = [ "stderr.log", "stdout.log" ]
2627 # NOTE: must end in /
Jon Hall5cf14d52015-07-16 12:15:19 -07002628 for f in logFiles:
Jon Halle1a3b752015-07-22 13:02:46 -07002629 for node in main.nodes:
Jon Hall96091e62015-09-21 17:34:17 -07002630 dstName = main.logdir + "/" + node.name + "-" + f
2631 main.ONOSbench.secureCopy( node.user_name, node.ip_address,
2632 logFolder + f, dstName )
2633 else:
2634 main.log.debug( "skipping saving log files" )
Jon Hall5cf14d52015-07-16 12:15:19 -07002635
2636 main.step( "Stopping Mininet" )
2637 mnResult = main.Mininet1.stopNet()
2638 utilities.assert_equals( expect=main.TRUE, actual=mnResult,
2639 onpass="Mininet stopped",
2640 onfail="MN cleanup NOT successful" )
2641
2642 main.step( "Checking ONOS Logs for errors" )
Jon Halle1a3b752015-07-22 13:02:46 -07002643 for node in main.nodes:
Jon Hall96091e62015-09-21 17:34:17 -07002644 main.log.debug( "Checking logs for errors on " + node.name + ":" )
2645 main.log.warn( main.ONOSbench.checkLogs( node.ip_address ) )
Jon Hall5cf14d52015-07-16 12:15:19 -07002646
2647 try:
2648 timerLog = open( main.logdir + "/Timers.csv", 'w')
2649 # Overwrite with empty line and close
2650 labels = "Gossip Intents"
2651 data = str( gossipTime )
2652 timerLog.write( labels + "\n" + data )
2653 timerLog.close()
2654 except NameError, e:
2655 main.log.exception(e)
2656
2657 def CASE14( self, main ):
2658 """
2659 start election app on all onos nodes
2660 """
Jon Halle1a3b752015-07-22 13:02:46 -07002661 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002662 assert main, "main not defined"
2663 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002664 assert main.CLIs, "main.CLIs not defined"
2665 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002666
2667 main.case("Start Leadership Election app")
2668 main.step( "Install leadership election app" )
2669 appResult = main.ONOScli1.activateApp( "org.onosproject.election" )
2670 utilities.assert_equals(
2671 expect=main.TRUE,
2672 actual=appResult,
2673 onpass="Election app installed",
2674 onfail="Something went wrong with installing Leadership election" )
2675
2676 main.step( "Run for election on each node" )
2677 leaderResult = main.TRUE
2678 leaders = []
Jon Halle1a3b752015-07-22 13:02:46 -07002679 for cli in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -07002680 cli.electionTestRun()
Jon Halle1a3b752015-07-22 13:02:46 -07002681 for cli in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -07002682 leader = cli.electionTestLeader()
2683 if leader is None or leader == main.FALSE:
2684 main.log.error( cli.name + ": Leader for the election app " +
2685 "should be an ONOS node, instead got '" +
2686 str( leader ) + "'" )
2687 leaderResult = main.FALSE
2688 leaders.append( leader )
2689 utilities.assert_equals(
2690 expect=main.TRUE,
2691 actual=leaderResult,
2692 onpass="Successfully ran for leadership",
2693 onfail="Failed to run for leadership" )
2694
2695 main.step( "Check that each node shows the same leader" )
2696 sameLeader = main.TRUE
2697 if len( set( leaders ) ) != 1:
2698 sameLeader = main.FALSE
Jon Halle1a3b752015-07-22 13:02:46 -07002699 main.log.error( "Results of electionTestLeader is order of main.CLIs:" +
Jon Hall5cf14d52015-07-16 12:15:19 -07002700 str( leaders ) )
2701 utilities.assert_equals(
2702 expect=main.TRUE,
2703 actual=sameLeader,
2704 onpass="Leadership is consistent for the election topic",
2705 onfail="Nodes have different leaders" )
2706
2707 def CASE15( self, main ):
2708 """
2709 Check that Leadership Election is still functional
acsmars71adceb2015-08-31 15:09:26 -07002710 15.1 Run election on each node
2711 15.2 Check that each node has the same leaders and candidates
2712 15.3 Find current leader and withdraw
2713 15.4 Check that a new node was elected leader
2714 15.5 Check that that new leader was the candidate of old leader
2715 15.6 Run for election on old leader
2716 15.7 Check that oldLeader is a candidate, and leader if only 1 node
2717 15.8 Make sure that the old leader was added to the candidate list
2718
2719 old and new variable prefixes refer to data from before vs after
2720 withdrawl and later before withdrawl vs after re-election
Jon Hall5cf14d52015-07-16 12:15:19 -07002721 """
2722 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002723 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002724 assert main, "main not defined"
2725 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002726 assert main.CLIs, "main.CLIs not defined"
2727 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002728
acsmars3a72bde2015-09-02 14:16:22 -07002729 description = "Check that Leadership Election App is still functional"
Jon Hall5cf14d52015-07-16 12:15:19 -07002730 main.case( description )
acsmars71adceb2015-08-31 15:09:26 -07002731 # NOTE: Need to re-run since being a canidate is not persistant
2732 # TODO: add check for "Command not found:" in the driver, this
2733 # means the election test app isn't loaded
Jon Hall5cf14d52015-07-16 12:15:19 -07002734
acsmars71adceb2015-08-31 15:09:26 -07002735 oldLeaders = [] # leaders by node before withdrawl from candidates
2736 newLeaders = [] # leaders by node after withdrawl from candidates
2737 oldAllCandidates = [] # list of lists of each nodes' candidates before
2738 newAllCandidates = [] # list of lists of each nodes' candidates after
2739 oldCandidates = [] # list of candidates from node 0 before withdrawl
2740 newCandidates = [] # list of candidates from node 0 after withdrawl
2741 oldLeader = '' # the old leader from oldLeaders, None if not same
2742 newLeader = '' # the new leaders fron newLoeaders, None if not same
2743 oldLeaderCLI = None # the CLI of the old leader used for re-electing
2744 expectNoLeader = False # True when there is only one leader
2745 if main.numCtrls == 1:
2746 expectNoLeader = True
2747
2748 main.step( "Run for election on each node" )
2749 electionResult = main.TRUE
2750
2751 for cli in main.CLIs: # run test election on each node
2752 if cli.electionTestRun() == main.FALSE:
2753 electionResult = main.FALSE
2754
Jon Hall5cf14d52015-07-16 12:15:19 -07002755 utilities.assert_equals(
2756 expect=main.TRUE,
acsmars71adceb2015-08-31 15:09:26 -07002757 actual=electionResult,
2758 onpass="All nodes successfully ran for leadership",
2759 onfail="At least one node failed to run for leadership" )
2760
acsmars3a72bde2015-09-02 14:16:22 -07002761 if electionResult == main.FALSE:
2762 main.log.error(
2763 "Skipping Test Case because Election Test isn't loaded" )
2764 main.skipCase()
2765
acsmars71adceb2015-08-31 15:09:26 -07002766 main.step( "Check that each node shows the same leader and candidates" )
2767 sameResult = main.TRUE
2768 failMessage = "Nodes have different leaders"
2769 for cli in main.CLIs:
2770 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
2771 oldAllCandidates.append( node )
2772 oldLeaders.append( node[ 0 ] )
2773 oldCandidates = oldAllCandidates[ 0 ]
2774
2775 # Check that each node has the same leader. Defines oldLeader
2776 if len( set( oldLeaders ) ) != 1:
2777 sameResult = main.FALSE
2778 main.log.error( "More than one leader present:" + str( oldLeaders ) )
2779 oldLeader = None
2780 else:
2781 oldLeader = oldLeaders[ 0 ]
2782
2783 # Check that each node's candidate list is the same
acsmars29233db2015-11-04 11:15:00 -08002784 candidateDiscrepancy = False # Boolean of candidate mismatches
acsmars71adceb2015-08-31 15:09:26 -07002785 for candidates in oldAllCandidates:
2786 if set( candidates ) != set( oldCandidates ):
2787 sameResult = main.FALSE
acsmars29233db2015-11-04 11:15:00 -08002788 candidateDiscrepancy = True
2789
2790 if candidateDiscrepancy:
2791 failMessage += " and candidates"
acsmars71adceb2015-08-31 15:09:26 -07002792
2793 utilities.assert_equals(
2794 expect=main.TRUE,
2795 actual=sameResult,
Jon Hall5cf14d52015-07-16 12:15:19 -07002796 onpass="Leadership is consistent for the election topic",
acsmars71adceb2015-08-31 15:09:26 -07002797 onfail=failMessage )
Jon Hall5cf14d52015-07-16 12:15:19 -07002798
2799 main.step( "Find current leader and withdraw" )
acsmars71adceb2015-08-31 15:09:26 -07002800 withdrawResult = main.TRUE
Jon Hall5cf14d52015-07-16 12:15:19 -07002801 # do some sanity checking on leader before using it
acsmars71adceb2015-08-31 15:09:26 -07002802 if oldLeader is None:
2803 main.log.error( "Leadership isn't consistent." )
2804 withdrawResult = main.FALSE
2805 # Get the CLI of the oldLeader
Jon Halle1a3b752015-07-22 13:02:46 -07002806 for i in range( len( main.CLIs ) ):
acsmars71adceb2015-08-31 15:09:26 -07002807 if oldLeader == main.nodes[ i ].ip_address:
2808 oldLeaderCLI = main.CLIs[ i ]
Jon Hall5cf14d52015-07-16 12:15:19 -07002809 break
2810 else: # FOR/ELSE statement
2811 main.log.error( "Leader election, could not find current leader" )
2812 if oldLeader:
acsmars71adceb2015-08-31 15:09:26 -07002813 withdrawResult = oldLeaderCLI.electionTestWithdraw()
Jon Hall5cf14d52015-07-16 12:15:19 -07002814 utilities.assert_equals(
2815 expect=main.TRUE,
2816 actual=withdrawResult,
2817 onpass="Node was withdrawn from election",
2818 onfail="Node was not withdrawn from election" )
2819
acsmars71adceb2015-08-31 15:09:26 -07002820 main.step( "Check that a new node was elected leader" )
2821
Jon Hall5cf14d52015-07-16 12:15:19 -07002822 # FIXME: use threads
acsmars71adceb2015-08-31 15:09:26 -07002823 newLeaderResult = main.TRUE
2824 failMessage = "Nodes have different leaders"
2825
2826 # Get new leaders and candidates
Jon Halle1a3b752015-07-22 13:02:46 -07002827 for cli in main.CLIs:
acsmars71adceb2015-08-31 15:09:26 -07002828 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
2829 # elections might no have finished yet
2830 if node[ 0 ] == 'none' and not expectNoLeader:
2831 main.log.info( "Node has no leader, waiting 5 seconds to be " +
2832 "sure elections are complete." )
2833 time.sleep(5)
2834 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
2835 # election still isn't done or there is a problem
2836 if node[ 0 ] == 'none':
2837 main.log.error( "No leader was elected on at least 1 node" )
2838 newLeaderResult = main.FALSE
2839 newAllCandidates.append( node )
2840 newLeaders.append( node[ 0 ] )
2841 newCandidates = newAllCandidates[ 0 ]
2842
2843 # Check that each node has the same leader. Defines newLeader
2844 if len( set( newLeaders ) ) != 1:
2845 newLeaderResult = main.FALSE
2846 main.log.error( "Nodes have different leaders: " +
2847 str( newLeaders ) )
2848 newLeader = None
Jon Hall5cf14d52015-07-16 12:15:19 -07002849 else:
acsmars71adceb2015-08-31 15:09:26 -07002850 newLeader = newLeaders[ 0 ]
2851
2852 # Check that each node's candidate list is the same
2853 for candidates in newAllCandidates:
2854 if set( candidates ) != set( newCandidates ):
2855 newLeaderResult = main.FALSE
Jon Hallceb4abb2015-09-25 12:03:06 -07002856 main.log.error( "Discrepancy in candidate lists detected" )
acsmars71adceb2015-08-31 15:09:26 -07002857
2858 # Check that the new leader is not the older leader, which was withdrawn
2859 if newLeader == oldLeader:
2860 newLeaderResult = main.FALSE
2861 main.log.error( "All nodes still see old leader: " + oldLeader +
2862 " as the current leader" )
2863
Jon Hall5cf14d52015-07-16 12:15:19 -07002864 utilities.assert_equals(
2865 expect=main.TRUE,
acsmars71adceb2015-08-31 15:09:26 -07002866 actual=newLeaderResult,
Jon Hall5cf14d52015-07-16 12:15:19 -07002867 onpass="Leadership election passed",
2868 onfail="Something went wrong with Leadership election" )
2869
acsmars71adceb2015-08-31 15:09:26 -07002870 main.step( "Check that that new leader was the candidate of old leader")
2871 # candidates[ 2 ] should be come the top candidate after withdrawl
2872 correctCandidateResult = main.TRUE
2873 if expectNoLeader:
2874 if newLeader == 'none':
2875 main.log.info( "No leader expected. None found. Pass" )
2876 correctCandidateResult = main.TRUE
2877 else:
2878 main.log.info( "Expected no leader, got: " + str( newLeader ) )
2879 correctCandidateResult = main.FALSE
2880 elif newLeader != oldCandidates[ 2 ]:
2881 correctCandidateResult = main.FALSE
2882 main.log.error( "Candidate " + newLeader + " was elected. " +
2883 oldCandidates[ 2 ] + " should have had priority." )
2884
2885 utilities.assert_equals(
2886 expect=main.TRUE,
2887 actual=correctCandidateResult,
2888 onpass="Correct Candidate Elected",
2889 onfail="Incorrect Candidate Elected" )
2890
Jon Hall5cf14d52015-07-16 12:15:19 -07002891 main.step( "Run for election on old leader( just so everyone " +
2892 "is in the hat )" )
acsmars71adceb2015-08-31 15:09:26 -07002893 if oldLeaderCLI is not None:
2894 runResult = oldLeaderCLI.electionTestRun()
Jon Hall5cf14d52015-07-16 12:15:19 -07002895 else:
acsmars71adceb2015-08-31 15:09:26 -07002896 main.log.error( "No old leader to re-elect" )
Jon Hall5cf14d52015-07-16 12:15:19 -07002897 runResult = main.FALSE
2898 utilities.assert_equals(
2899 expect=main.TRUE,
2900 actual=runResult,
2901 onpass="App re-ran for election",
2902 onfail="App failed to run for election" )
acsmars71adceb2015-08-31 15:09:26 -07002903 main.step(
2904 "Check that oldLeader is a candidate, and leader if only 1 node" )
Jon Hall5cf14d52015-07-16 12:15:19 -07002905 # verify leader didn't just change
acsmars71adceb2015-08-31 15:09:26 -07002906 positionResult = main.TRUE
2907 # Get new leaders and candidates, wait if oldLeader is not a candidate yet
2908
2909 # Reset and reuse the new candidate and leaders lists
2910 newAllCandidates = []
2911 newCandidates = []
2912 newLeaders = []
2913 for cli in main.CLIs:
2914 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
2915 if oldLeader not in node: # election might no have finished yet
2916 main.log.info( "Old Leader not elected, waiting 5 seconds to " +
2917 "be sure elections are complete" )
2918 time.sleep(5)
2919 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
2920 if oldLeader not in node: # election still isn't done, errors
2921 main.log.error(
2922 "Old leader was not elected on at least one node" )
2923 positionResult = main.FALSE
2924 newAllCandidates.append( node )
2925 newLeaders.append( node[ 0 ] )
2926 newCandidates = newAllCandidates[ 0 ]
2927
2928 # Check that each node has the same leader. Defines newLeader
2929 if len( set( newLeaders ) ) != 1:
2930 positionResult = main.FALSE
2931 main.log.error( "Nodes have different leaders: " +
2932 str( newLeaders ) )
2933 newLeader = None
Jon Hall5cf14d52015-07-16 12:15:19 -07002934 else:
acsmars71adceb2015-08-31 15:09:26 -07002935 newLeader = newLeaders[ 0 ]
2936
2937 # Check that each node's candidate list is the same
2938 for candidates in newAllCandidates:
2939 if set( candidates ) != set( newCandidates ):
2940 newLeaderResult = main.FALSE
Jon Hallceb4abb2015-09-25 12:03:06 -07002941 main.log.error( "Discrepancy in candidate lists detected" )
acsmars71adceb2015-08-31 15:09:26 -07002942
2943 # Check that the re-elected node is last on the candidate List
2944 if oldLeader != newCandidates[ -1 ]:
2945 main.log.error( "Old Leader (" + oldLeader + ") not in the proper position " +
2946 str( newCandidates ) )
2947 positionResult = main.FALSE
Jon Hall5cf14d52015-07-16 12:15:19 -07002948
2949 utilities.assert_equals(
2950 expect=main.TRUE,
acsmars71adceb2015-08-31 15:09:26 -07002951 actual=positionResult,
Jon Hall5cf14d52015-07-16 12:15:19 -07002952 onpass="Old leader successfully re-ran for election",
2953 onfail="Something went wrong with Leadership election after " +
2954 "the old leader re-ran for election" )
2955
2956 def CASE16( self, main ):
2957 """
2958 Install Distributed Primitives app
2959 """
2960 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002961 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002962 assert main, "main not defined"
2963 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002964 assert main.CLIs, "main.CLIs not defined"
2965 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002966
2967 # Variables for the distributed primitives tests
2968 global pCounterName
2969 global iCounterName
2970 global pCounterValue
2971 global iCounterValue
2972 global onosSet
2973 global onosSetName
2974 pCounterName = "TestON-Partitions"
2975 iCounterName = "TestON-inMemory"
2976 pCounterValue = 0
2977 iCounterValue = 0
2978 onosSet = set([])
2979 onosSetName = "TestON-set"
2980
2981 description = "Install Primitives app"
2982 main.case( description )
2983 main.step( "Install Primitives app" )
2984 appName = "org.onosproject.distributedprimitives"
Jon Halle1a3b752015-07-22 13:02:46 -07002985 appResults = main.CLIs[0].activateApp( appName )
Jon Hall5cf14d52015-07-16 12:15:19 -07002986 utilities.assert_equals( expect=main.TRUE,
2987 actual=appResults,
2988 onpass="Primitives app activated",
2989 onfail="Primitives app not activated" )
2990 time.sleep( 5 ) # To allow all nodes to activate
2991
2992 def CASE17( self, main ):
2993 """
2994 Check for basic functionality with distributed primitives
2995 """
Jon Hall5cf14d52015-07-16 12:15:19 -07002996 # Make sure variables are defined/set
Jon Halle1a3b752015-07-22 13:02:46 -07002997 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002998 assert main, "main not defined"
2999 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07003000 assert main.CLIs, "main.CLIs not defined"
3001 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07003002 assert pCounterName, "pCounterName not defined"
3003 assert iCounterName, "iCounterName not defined"
3004 assert onosSetName, "onosSetName not defined"
3005 # NOTE: assert fails if value is 0/None/Empty/False
3006 try:
3007 pCounterValue
3008 except NameError:
3009 main.log.error( "pCounterValue not defined, setting to 0" )
3010 pCounterValue = 0
3011 try:
3012 iCounterValue
3013 except NameError:
3014 main.log.error( "iCounterValue not defined, setting to 0" )
3015 iCounterValue = 0
3016 try:
3017 onosSet
3018 except NameError:
3019 main.log.error( "onosSet not defined, setting to empty Set" )
3020 onosSet = set([])
3021 # Variables for the distributed primitives tests. These are local only
3022 addValue = "a"
3023 addAllValue = "a b c d e f"
3024 retainValue = "c d e f"
3025
3026 description = "Check for basic functionality with distributed " +\
3027 "primitives"
3028 main.case( description )
Jon Halle1a3b752015-07-22 13:02:46 -07003029 main.caseExplanation = "Test the methods of the distributed " +\
3030 "primitives (counters and sets) throught the cli"
Jon Hall5cf14d52015-07-16 12:15:19 -07003031 # DISTRIBUTED ATOMIC COUNTERS
Jon Halle1a3b752015-07-22 13:02:46 -07003032 # Partitioned counters
3033 main.step( "Increment then get a default counter on each node" )
Jon Hall5cf14d52015-07-16 12:15:19 -07003034 pCounters = []
3035 threads = []
3036 addedPValues = []
Jon Halle1a3b752015-07-22 13:02:46 -07003037 for i in range( main.numCtrls ):
3038 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
3039 name="counterAddAndGet-" + str( i ),
Jon Hall5cf14d52015-07-16 12:15:19 -07003040 args=[ pCounterName ] )
3041 pCounterValue += 1
3042 addedPValues.append( pCounterValue )
3043 threads.append( t )
3044 t.start()
3045
3046 for t in threads:
3047 t.join()
3048 pCounters.append( t.result )
3049 # Check that counter incremented numController times
3050 pCounterResults = True
3051 for i in addedPValues:
3052 tmpResult = i in pCounters
3053 pCounterResults = pCounterResults and tmpResult
3054 if not tmpResult:
3055 main.log.error( str( i ) + " is not in partitioned "
3056 "counter incremented results" )
3057 utilities.assert_equals( expect=True,
3058 actual=pCounterResults,
3059 onpass="Default counter incremented",
3060 onfail="Error incrementing default" +
3061 " counter" )
3062
Jon Halle1a3b752015-07-22 13:02:46 -07003063 main.step( "Get then Increment a default counter on each node" )
3064 pCounters = []
3065 threads = []
3066 addedPValues = []
3067 for i in range( main.numCtrls ):
3068 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
3069 name="counterGetAndAdd-" + str( i ),
3070 args=[ pCounterName ] )
3071 addedPValues.append( pCounterValue )
3072 pCounterValue += 1
3073 threads.append( t )
3074 t.start()
3075
3076 for t in threads:
3077 t.join()
3078 pCounters.append( t.result )
3079 # Check that counter incremented numController times
3080 pCounterResults = True
3081 for i in addedPValues:
3082 tmpResult = i in pCounters
3083 pCounterResults = pCounterResults and tmpResult
3084 if not tmpResult:
3085 main.log.error( str( i ) + " is not in partitioned "
3086 "counter incremented results" )
3087 utilities.assert_equals( expect=True,
3088 actual=pCounterResults,
3089 onpass="Default counter incremented",
3090 onfail="Error incrementing default" +
3091 " counter" )
3092
3093 main.step( "Counters we added have the correct values" )
3094 incrementCheck = main.Counters.counterCheck( pCounterName, pCounterValue )
3095 utilities.assert_equals( expect=main.TRUE,
3096 actual=incrementCheck,
3097 onpass="Added counters are correct",
3098 onfail="Added counters are incorrect" )
3099
3100 main.step( "Add -8 to then get a default counter on each node" )
3101 pCounters = []
3102 threads = []
3103 addedPValues = []
3104 for i in range( main.numCtrls ):
3105 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
3106 name="counterIncrement-" + str( i ),
3107 args=[ pCounterName ],
3108 kwargs={ "delta": -8 } )
3109 pCounterValue += -8
3110 addedPValues.append( pCounterValue )
3111 threads.append( t )
3112 t.start()
3113
3114 for t in threads:
3115 t.join()
3116 pCounters.append( t.result )
3117 # Check that counter incremented numController times
3118 pCounterResults = True
3119 for i in addedPValues:
3120 tmpResult = i in pCounters
3121 pCounterResults = pCounterResults and tmpResult
3122 if not tmpResult:
3123 main.log.error( str( i ) + " is not in partitioned "
3124 "counter incremented results" )
3125 utilities.assert_equals( expect=True,
3126 actual=pCounterResults,
3127 onpass="Default counter incremented",
3128 onfail="Error incrementing default" +
3129 " counter" )
3130
3131 main.step( "Add 5 to then get a default counter on each node" )
3132 pCounters = []
3133 threads = []
3134 addedPValues = []
3135 for i in range( main.numCtrls ):
3136 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
3137 name="counterIncrement-" + str( i ),
3138 args=[ pCounterName ],
3139 kwargs={ "delta": 5 } )
3140 pCounterValue += 5
3141 addedPValues.append( pCounterValue )
3142 threads.append( t )
3143 t.start()
3144
3145 for t in threads:
3146 t.join()
3147 pCounters.append( t.result )
3148 # Check that counter incremented numController times
3149 pCounterResults = True
3150 for i in addedPValues:
3151 tmpResult = i in pCounters
3152 pCounterResults = pCounterResults and tmpResult
3153 if not tmpResult:
3154 main.log.error( str( i ) + " is not in partitioned "
3155 "counter incremented results" )
3156 utilities.assert_equals( expect=True,
3157 actual=pCounterResults,
3158 onpass="Default counter incremented",
3159 onfail="Error incrementing default" +
3160 " counter" )
3161
3162 main.step( "Get then add 5 to a default counter on each node" )
3163 pCounters = []
3164 threads = []
3165 addedPValues = []
3166 for i in range( main.numCtrls ):
3167 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
3168 name="counterIncrement-" + str( i ),
3169 args=[ pCounterName ],
3170 kwargs={ "delta": 5 } )
3171 addedPValues.append( pCounterValue )
3172 pCounterValue += 5
3173 threads.append( t )
3174 t.start()
3175
3176 for t in threads:
3177 t.join()
3178 pCounters.append( t.result )
3179 # Check that counter incremented numController times
3180 pCounterResults = True
3181 for i in addedPValues:
3182 tmpResult = i in pCounters
3183 pCounterResults = pCounterResults and tmpResult
3184 if not tmpResult:
3185 main.log.error( str( i ) + " is not in partitioned "
3186 "counter incremented results" )
3187 utilities.assert_equals( expect=True,
3188 actual=pCounterResults,
3189 onpass="Default counter incremented",
3190 onfail="Error incrementing default" +
3191 " counter" )
3192
3193 main.step( "Counters we added have the correct values" )
3194 incrementCheck = main.Counters.counterCheck( pCounterName, pCounterValue )
3195 utilities.assert_equals( expect=main.TRUE,
3196 actual=incrementCheck,
3197 onpass="Added counters are correct",
3198 onfail="Added counters are incorrect" )
3199
3200 # In-Memory counters
3201 main.step( "Increment and get an in-memory counter on each node" )
Jon Hall5cf14d52015-07-16 12:15:19 -07003202 iCounters = []
3203 addedIValues = []
3204 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003205 for i in range( main.numCtrls ):
3206 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003207 name="icounterIncrement-" + str( i ),
3208 args=[ iCounterName ],
3209 kwargs={ "inMemory": True } )
3210 iCounterValue += 1
3211 addedIValues.append( iCounterValue )
3212 threads.append( t )
3213 t.start()
3214
3215 for t in threads:
3216 t.join()
3217 iCounters.append( t.result )
3218 # Check that counter incremented numController times
3219 iCounterResults = True
3220 for i in addedIValues:
3221 tmpResult = i in iCounters
3222 iCounterResults = iCounterResults and tmpResult
3223 if not tmpResult:
3224 main.log.error( str( i ) + " is not in the in-memory "
3225 "counter incremented results" )
3226 utilities.assert_equals( expect=True,
3227 actual=iCounterResults,
Jon Halle1a3b752015-07-22 13:02:46 -07003228 onpass="In-memory counter incremented",
3229 onfail="Error incrementing in-memory" +
Jon Hall5cf14d52015-07-16 12:15:19 -07003230 " counter" )
3231
Jon Halle1a3b752015-07-22 13:02:46 -07003232 main.step( "Get then Increment a in-memory counter on each node" )
3233 iCounters = []
3234 threads = []
3235 addedIValues = []
3236 for i in range( main.numCtrls ):
3237 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
3238 name="counterGetAndAdd-" + str( i ),
3239 args=[ iCounterName ],
3240 kwargs={ "inMemory": True } )
3241 addedIValues.append( iCounterValue )
3242 iCounterValue += 1
3243 threads.append( t )
3244 t.start()
3245
3246 for t in threads:
3247 t.join()
3248 iCounters.append( t.result )
3249 # Check that counter incremented numController times
3250 iCounterResults = True
3251 for i in addedIValues:
3252 tmpResult = i in iCounters
3253 iCounterResults = iCounterResults and tmpResult
3254 if not tmpResult:
3255 main.log.error( str( i ) + " is not in in-memory "
3256 "counter incremented results" )
3257 utilities.assert_equals( expect=True,
3258 actual=iCounterResults,
3259 onpass="In-memory counter incremented",
3260 onfail="Error incrementing in-memory" +
3261 " counter" )
3262
3263 main.step( "Counters we added have the correct values" )
3264 incrementCheck = main.Counters.counterCheck( iCounterName, iCounterValue )
3265 utilities.assert_equals( expect=main.TRUE,
3266 actual=incrementCheck,
3267 onpass="Added counters are correct",
3268 onfail="Added counters are incorrect" )
3269
3270 main.step( "Add -8 to then get a in-memory counter on each node" )
3271 iCounters = []
3272 threads = []
3273 addedIValues = []
3274 for i in range( main.numCtrls ):
3275 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
3276 name="counterIncrement-" + str( i ),
3277 args=[ iCounterName ],
3278 kwargs={ "delta": -8, "inMemory": True } )
3279 iCounterValue += -8
3280 addedIValues.append( iCounterValue )
3281 threads.append( t )
3282 t.start()
3283
3284 for t in threads:
3285 t.join()
3286 iCounters.append( t.result )
3287 # Check that counter incremented numController times
3288 iCounterResults = True
3289 for i in addedIValues:
3290 tmpResult = i in iCounters
3291 iCounterResults = iCounterResults and tmpResult
3292 if not tmpResult:
3293 main.log.error( str( i ) + " is not in in-memory "
3294 "counter incremented results" )
3295 utilities.assert_equals( expect=True,
3296 actual=pCounterResults,
3297 onpass="In-memory counter incremented",
3298 onfail="Error incrementing in-memory" +
3299 " counter" )
3300
3301 main.step( "Add 5 to then get a in-memory counter on each node" )
3302 iCounters = []
3303 threads = []
3304 addedIValues = []
3305 for i in range( main.numCtrls ):
3306 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
3307 name="counterIncrement-" + str( i ),
3308 args=[ iCounterName ],
3309 kwargs={ "delta": 5, "inMemory": True } )
3310 iCounterValue += 5
3311 addedIValues.append( iCounterValue )
3312 threads.append( t )
3313 t.start()
3314
3315 for t in threads:
3316 t.join()
3317 iCounters.append( t.result )
3318 # Check that counter incremented numController times
3319 iCounterResults = True
3320 for i in addedIValues:
3321 tmpResult = i in iCounters
3322 iCounterResults = iCounterResults and tmpResult
3323 if not tmpResult:
3324 main.log.error( str( i ) + " is not in in-memory "
3325 "counter incremented results" )
3326 utilities.assert_equals( expect=True,
3327 actual=pCounterResults,
3328 onpass="In-memory counter incremented",
3329 onfail="Error incrementing in-memory" +
3330 " counter" )
3331
3332 main.step( "Get then add 5 to a in-memory counter on each node" )
3333 iCounters = []
3334 threads = []
3335 addedIValues = []
3336 for i in range( main.numCtrls ):
3337 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
3338 name="counterIncrement-" + str( i ),
3339 args=[ iCounterName ],
3340 kwargs={ "delta": 5, "inMemory": True } )
3341 addedIValues.append( iCounterValue )
3342 iCounterValue += 5
3343 threads.append( t )
3344 t.start()
3345
3346 for t in threads:
3347 t.join()
3348 iCounters.append( t.result )
3349 # Check that counter incremented numController times
3350 iCounterResults = True
3351 for i in addedIValues:
3352 tmpResult = i in iCounters
3353 iCounterResults = iCounterResults and tmpResult
3354 if not tmpResult:
3355 main.log.error( str( i ) + " is not in in-memory "
3356 "counter incremented results" )
3357 utilities.assert_equals( expect=True,
3358 actual=iCounterResults,
3359 onpass="In-memory counter incremented",
3360 onfail="Error incrementing in-memory" +
3361 " counter" )
3362
3363 main.step( "Counters we added have the correct values" )
3364 incrementCheck = main.Counters.counterCheck( iCounterName, iCounterValue )
3365 utilities.assert_equals( expect=main.TRUE,
3366 actual=incrementCheck,
3367 onpass="Added counters are correct",
3368 onfail="Added counters are incorrect" )
3369
Jon Hall5cf14d52015-07-16 12:15:19 -07003370 main.step( "Check counters are consistant across nodes" )
Jon Hall57b50432015-10-22 10:20:10 -07003371 onosCounters, consistentCounterResults = main.Counters.consistentCheck()
Jon Hall5cf14d52015-07-16 12:15:19 -07003372 utilities.assert_equals( expect=main.TRUE,
3373 actual=consistentCounterResults,
3374 onpass="ONOS counters are consistent " +
3375 "across nodes",
3376 onfail="ONOS Counters are inconsistent " +
3377 "across nodes" )
3378
3379 main.step( "Counters we added have the correct values" )
Jon Halle1a3b752015-07-22 13:02:46 -07003380 incrementCheck = main.Counters.counterCheck( iCounterName, iCounterValue )
3381 incrementCheck = incrementCheck and \
3382 main.Counters.counterCheck( iCounterName, iCounterValue )
Jon Hall5cf14d52015-07-16 12:15:19 -07003383 utilities.assert_equals( expect=main.TRUE,
Jon Halle1a3b752015-07-22 13:02:46 -07003384 actual=incrementCheck,
Jon Hall5cf14d52015-07-16 12:15:19 -07003385 onpass="Added counters are correct",
3386 onfail="Added counters are incorrect" )
3387 # DISTRIBUTED SETS
3388 main.step( "Distributed Set get" )
3389 size = len( onosSet )
3390 getResponses = []
3391 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003392 for i in range( main.numCtrls ):
3393 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003394 name="setTestGet-" + str( i ),
3395 args=[ onosSetName ] )
3396 threads.append( t )
3397 t.start()
3398 for t in threads:
3399 t.join()
3400 getResponses.append( t.result )
3401
3402 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003403 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003404 if isinstance( getResponses[ i ], list):
3405 current = set( getResponses[ i ] )
3406 if len( current ) == len( getResponses[ i ] ):
3407 # no repeats
3408 if onosSet != current:
3409 main.log.error( "ONOS" + str( i + 1 ) +
3410 " has incorrect view" +
3411 " of set " + onosSetName + ":\n" +
3412 str( getResponses[ i ] ) )
3413 main.log.debug( "Expected: " + str( onosSet ) )
3414 main.log.debug( "Actual: " + str( current ) )
3415 getResults = main.FALSE
3416 else:
3417 # error, set is not a set
3418 main.log.error( "ONOS" + str( i + 1 ) +
3419 " has repeat elements in" +
3420 " set " + onosSetName + ":\n" +
3421 str( getResponses[ i ] ) )
3422 getResults = main.FALSE
3423 elif getResponses[ i ] == main.ERROR:
3424 getResults = main.FALSE
3425 utilities.assert_equals( expect=main.TRUE,
3426 actual=getResults,
3427 onpass="Set elements are correct",
3428 onfail="Set elements are incorrect" )
3429
3430 main.step( "Distributed Set size" )
3431 sizeResponses = []
3432 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003433 for i in range( main.numCtrls ):
3434 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003435 name="setTestSize-" + str( i ),
3436 args=[ onosSetName ] )
3437 threads.append( t )
3438 t.start()
3439 for t in threads:
3440 t.join()
3441 sizeResponses.append( t.result )
3442
3443 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003444 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003445 if size != sizeResponses[ i ]:
3446 sizeResults = main.FALSE
3447 main.log.error( "ONOS" + str( i + 1 ) +
3448 " expected a size of " + str( size ) +
3449 " for set " + onosSetName +
3450 " but got " + str( sizeResponses[ i ] ) )
3451 utilities.assert_equals( expect=main.TRUE,
3452 actual=sizeResults,
3453 onpass="Set sizes are correct",
3454 onfail="Set sizes are incorrect" )
3455
3456 main.step( "Distributed Set add()" )
3457 onosSet.add( addValue )
3458 addResponses = []
3459 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003460 for i in range( main.numCtrls ):
3461 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall5cf14d52015-07-16 12:15:19 -07003462 name="setTestAdd-" + str( i ),
3463 args=[ onosSetName, addValue ] )
3464 threads.append( t )
3465 t.start()
3466 for t in threads:
3467 t.join()
3468 addResponses.append( t.result )
3469
3470 # main.TRUE = successfully changed the set
3471 # main.FALSE = action resulted in no change in set
3472 # main.ERROR - Some error in executing the function
3473 addResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003474 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003475 if addResponses[ i ] == main.TRUE:
3476 # All is well
3477 pass
3478 elif addResponses[ i ] == main.FALSE:
3479 # Already in set, probably fine
3480 pass
3481 elif addResponses[ i ] == main.ERROR:
3482 # Error in execution
3483 addResults = main.FALSE
3484 else:
3485 # unexpected result
3486 addResults = main.FALSE
3487 if addResults != main.TRUE:
3488 main.log.error( "Error executing set add" )
3489
3490 # Check if set is still correct
3491 size = len( onosSet )
3492 getResponses = []
3493 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003494 for i in range( main.numCtrls ):
3495 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003496 name="setTestGet-" + str( i ),
3497 args=[ onosSetName ] )
3498 threads.append( t )
3499 t.start()
3500 for t in threads:
3501 t.join()
3502 getResponses.append( t.result )
3503 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003504 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003505 if isinstance( getResponses[ i ], list):
3506 current = set( getResponses[ i ] )
3507 if len( current ) == len( getResponses[ i ] ):
3508 # no repeats
3509 if onosSet != current:
3510 main.log.error( "ONOS" + str( i + 1 ) +
3511 " has incorrect view" +
3512 " of set " + onosSetName + ":\n" +
3513 str( getResponses[ i ] ) )
3514 main.log.debug( "Expected: " + str( onosSet ) )
3515 main.log.debug( "Actual: " + str( current ) )
3516 getResults = main.FALSE
3517 else:
3518 # error, set is not a set
3519 main.log.error( "ONOS" + str( i + 1 ) +
3520 " has repeat elements in" +
3521 " set " + onosSetName + ":\n" +
3522 str( getResponses[ i ] ) )
3523 getResults = main.FALSE
3524 elif getResponses[ i ] == main.ERROR:
3525 getResults = main.FALSE
3526 sizeResponses = []
3527 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003528 for i in range( main.numCtrls ):
3529 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003530 name="setTestSize-" + str( i ),
3531 args=[ onosSetName ] )
3532 threads.append( t )
3533 t.start()
3534 for t in threads:
3535 t.join()
3536 sizeResponses.append( t.result )
3537 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003538 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003539 if size != sizeResponses[ i ]:
3540 sizeResults = main.FALSE
3541 main.log.error( "ONOS" + str( i + 1 ) +
3542 " expected a size of " + str( size ) +
3543 " for set " + onosSetName +
3544 " but got " + str( sizeResponses[ i ] ) )
3545 addResults = addResults and getResults and sizeResults
3546 utilities.assert_equals( expect=main.TRUE,
3547 actual=addResults,
3548 onpass="Set add correct",
3549 onfail="Set add was incorrect" )
3550
3551 main.step( "Distributed Set addAll()" )
3552 onosSet.update( addAllValue.split() )
3553 addResponses = []
3554 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003555 for i in range( main.numCtrls ):
3556 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall5cf14d52015-07-16 12:15:19 -07003557 name="setTestAddAll-" + str( i ),
3558 args=[ onosSetName, addAllValue ] )
3559 threads.append( t )
3560 t.start()
3561 for t in threads:
3562 t.join()
3563 addResponses.append( t.result )
3564
3565 # main.TRUE = successfully changed the set
3566 # main.FALSE = action resulted in no change in set
3567 # main.ERROR - Some error in executing the function
3568 addAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003569 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003570 if addResponses[ i ] == main.TRUE:
3571 # All is well
3572 pass
3573 elif addResponses[ i ] == main.FALSE:
3574 # Already in set, probably fine
3575 pass
3576 elif addResponses[ i ] == main.ERROR:
3577 # Error in execution
3578 addAllResults = main.FALSE
3579 else:
3580 # unexpected result
3581 addAllResults = main.FALSE
3582 if addAllResults != main.TRUE:
3583 main.log.error( "Error executing set addAll" )
3584
3585 # Check if set is still correct
3586 size = len( onosSet )
3587 getResponses = []
3588 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003589 for i in range( main.numCtrls ):
3590 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003591 name="setTestGet-" + str( i ),
3592 args=[ onosSetName ] )
3593 threads.append( t )
3594 t.start()
3595 for t in threads:
3596 t.join()
3597 getResponses.append( t.result )
3598 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003599 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003600 if isinstance( getResponses[ i ], list):
3601 current = set( getResponses[ i ] )
3602 if len( current ) == len( getResponses[ i ] ):
3603 # no repeats
3604 if onosSet != current:
3605 main.log.error( "ONOS" + str( i + 1 ) +
3606 " has incorrect view" +
3607 " of set " + onosSetName + ":\n" +
3608 str( getResponses[ i ] ) )
3609 main.log.debug( "Expected: " + str( onosSet ) )
3610 main.log.debug( "Actual: " + str( current ) )
3611 getResults = main.FALSE
3612 else:
3613 # error, set is not a set
3614 main.log.error( "ONOS" + str( i + 1 ) +
3615 " has repeat elements in" +
3616 " set " + onosSetName + ":\n" +
3617 str( getResponses[ i ] ) )
3618 getResults = main.FALSE
3619 elif getResponses[ i ] == main.ERROR:
3620 getResults = main.FALSE
3621 sizeResponses = []
3622 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003623 for i in range( main.numCtrls ):
3624 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003625 name="setTestSize-" + str( i ),
3626 args=[ onosSetName ] )
3627 threads.append( t )
3628 t.start()
3629 for t in threads:
3630 t.join()
3631 sizeResponses.append( t.result )
3632 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003633 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003634 if size != sizeResponses[ i ]:
3635 sizeResults = main.FALSE
3636 main.log.error( "ONOS" + str( i + 1 ) +
3637 " expected a size of " + str( size ) +
3638 " for set " + onosSetName +
3639 " but got " + str( sizeResponses[ i ] ) )
3640 addAllResults = addAllResults and getResults and sizeResults
3641 utilities.assert_equals( expect=main.TRUE,
3642 actual=addAllResults,
3643 onpass="Set addAll correct",
3644 onfail="Set addAll was incorrect" )
3645
3646 main.step( "Distributed Set contains()" )
3647 containsResponses = []
3648 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003649 for i in range( main.numCtrls ):
3650 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003651 name="setContains-" + str( i ),
3652 args=[ onosSetName ],
3653 kwargs={ "values": addValue } )
3654 threads.append( t )
3655 t.start()
3656 for t in threads:
3657 t.join()
3658 # NOTE: This is the tuple
3659 containsResponses.append( t.result )
3660
3661 containsResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003662 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003663 if containsResponses[ i ] == main.ERROR:
3664 containsResults = main.FALSE
3665 else:
3666 containsResults = containsResults and\
3667 containsResponses[ i ][ 1 ]
3668 utilities.assert_equals( expect=main.TRUE,
3669 actual=containsResults,
3670 onpass="Set contains is functional",
3671 onfail="Set contains failed" )
3672
3673 main.step( "Distributed Set containsAll()" )
3674 containsAllResponses = []
3675 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003676 for i in range( main.numCtrls ):
3677 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003678 name="setContainsAll-" + str( i ),
3679 args=[ onosSetName ],
3680 kwargs={ "values": addAllValue } )
3681 threads.append( t )
3682 t.start()
3683 for t in threads:
3684 t.join()
3685 # NOTE: This is the tuple
3686 containsAllResponses.append( t.result )
3687
3688 containsAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003689 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003690 if containsResponses[ i ] == main.ERROR:
3691 containsResults = main.FALSE
3692 else:
3693 containsResults = containsResults and\
3694 containsResponses[ i ][ 1 ]
3695 utilities.assert_equals( expect=main.TRUE,
3696 actual=containsAllResults,
3697 onpass="Set containsAll is functional",
3698 onfail="Set containsAll failed" )
3699
3700 main.step( "Distributed Set remove()" )
3701 onosSet.remove( addValue )
3702 removeResponses = []
3703 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003704 for i in range( main.numCtrls ):
3705 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall5cf14d52015-07-16 12:15:19 -07003706 name="setTestRemove-" + str( i ),
3707 args=[ onosSetName, addValue ] )
3708 threads.append( t )
3709 t.start()
3710 for t in threads:
3711 t.join()
3712 removeResponses.append( t.result )
3713
3714 # main.TRUE = successfully changed the set
3715 # main.FALSE = action resulted in no change in set
3716 # main.ERROR - Some error in executing the function
3717 removeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003718 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003719 if removeResponses[ i ] == main.TRUE:
3720 # All is well
3721 pass
3722 elif removeResponses[ i ] == main.FALSE:
3723 # not in set, probably fine
3724 pass
3725 elif removeResponses[ i ] == main.ERROR:
3726 # Error in execution
3727 removeResults = main.FALSE
3728 else:
3729 # unexpected result
3730 removeResults = main.FALSE
3731 if removeResults != main.TRUE:
3732 main.log.error( "Error executing set remove" )
3733
3734 # Check if set is still correct
3735 size = len( onosSet )
3736 getResponses = []
3737 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003738 for i in range( main.numCtrls ):
3739 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003740 name="setTestGet-" + str( i ),
3741 args=[ onosSetName ] )
3742 threads.append( t )
3743 t.start()
3744 for t in threads:
3745 t.join()
3746 getResponses.append( t.result )
3747 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003748 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003749 if isinstance( getResponses[ i ], list):
3750 current = set( getResponses[ i ] )
3751 if len( current ) == len( getResponses[ i ] ):
3752 # no repeats
3753 if onosSet != current:
3754 main.log.error( "ONOS" + str( i + 1 ) +
3755 " has incorrect view" +
3756 " of set " + onosSetName + ":\n" +
3757 str( getResponses[ i ] ) )
3758 main.log.debug( "Expected: " + str( onosSet ) )
3759 main.log.debug( "Actual: " + str( current ) )
3760 getResults = main.FALSE
3761 else:
3762 # error, set is not a set
3763 main.log.error( "ONOS" + str( i + 1 ) +
3764 " has repeat elements in" +
3765 " set " + onosSetName + ":\n" +
3766 str( getResponses[ i ] ) )
3767 getResults = main.FALSE
3768 elif getResponses[ i ] == main.ERROR:
3769 getResults = main.FALSE
3770 sizeResponses = []
3771 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003772 for i in range( main.numCtrls ):
3773 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003774 name="setTestSize-" + str( i ),
3775 args=[ onosSetName ] )
3776 threads.append( t )
3777 t.start()
3778 for t in threads:
3779 t.join()
3780 sizeResponses.append( t.result )
3781 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003782 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003783 if size != sizeResponses[ i ]:
3784 sizeResults = main.FALSE
3785 main.log.error( "ONOS" + str( i + 1 ) +
3786 " expected a size of " + str( size ) +
3787 " for set " + onosSetName +
3788 " but got " + str( sizeResponses[ i ] ) )
3789 removeResults = removeResults and getResults and sizeResults
3790 utilities.assert_equals( expect=main.TRUE,
3791 actual=removeResults,
3792 onpass="Set remove correct",
3793 onfail="Set remove was incorrect" )
3794
3795 main.step( "Distributed Set removeAll()" )
3796 onosSet.difference_update( addAllValue.split() )
3797 removeAllResponses = []
3798 threads = []
3799 try:
Jon Halle1a3b752015-07-22 13:02:46 -07003800 for i in range( main.numCtrls ):
3801 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall5cf14d52015-07-16 12:15:19 -07003802 name="setTestRemoveAll-" + str( i ),
3803 args=[ onosSetName, addAllValue ] )
3804 threads.append( t )
3805 t.start()
3806 for t in threads:
3807 t.join()
3808 removeAllResponses.append( t.result )
3809 except Exception, e:
3810 main.log.exception(e)
3811
3812 # main.TRUE = successfully changed the set
3813 # main.FALSE = action resulted in no change in set
3814 # main.ERROR - Some error in executing the function
3815 removeAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003816 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003817 if removeAllResponses[ i ] == main.TRUE:
3818 # All is well
3819 pass
3820 elif removeAllResponses[ i ] == main.FALSE:
3821 # not in set, probably fine
3822 pass
3823 elif removeAllResponses[ i ] == main.ERROR:
3824 # Error in execution
3825 removeAllResults = main.FALSE
3826 else:
3827 # unexpected result
3828 removeAllResults = main.FALSE
3829 if removeAllResults != main.TRUE:
3830 main.log.error( "Error executing set removeAll" )
3831
3832 # Check if set is still correct
3833 size = len( onosSet )
3834 getResponses = []
3835 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003836 for i in range( main.numCtrls ):
3837 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003838 name="setTestGet-" + str( i ),
3839 args=[ onosSetName ] )
3840 threads.append( t )
3841 t.start()
3842 for t in threads:
3843 t.join()
3844 getResponses.append( t.result )
3845 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003846 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003847 if isinstance( getResponses[ i ], list):
3848 current = set( getResponses[ i ] )
3849 if len( current ) == len( getResponses[ i ] ):
3850 # no repeats
3851 if onosSet != current:
3852 main.log.error( "ONOS" + str( i + 1 ) +
3853 " has incorrect view" +
3854 " of set " + onosSetName + ":\n" +
3855 str( getResponses[ i ] ) )
3856 main.log.debug( "Expected: " + str( onosSet ) )
3857 main.log.debug( "Actual: " + str( current ) )
3858 getResults = main.FALSE
3859 else:
3860 # error, set is not a set
3861 main.log.error( "ONOS" + str( i + 1 ) +
3862 " has repeat elements in" +
3863 " set " + onosSetName + ":\n" +
3864 str( getResponses[ i ] ) )
3865 getResults = main.FALSE
3866 elif getResponses[ i ] == main.ERROR:
3867 getResults = main.FALSE
3868 sizeResponses = []
3869 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003870 for i in range( main.numCtrls ):
3871 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003872 name="setTestSize-" + str( i ),
3873 args=[ onosSetName ] )
3874 threads.append( t )
3875 t.start()
3876 for t in threads:
3877 t.join()
3878 sizeResponses.append( t.result )
3879 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003880 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003881 if size != sizeResponses[ i ]:
3882 sizeResults = main.FALSE
3883 main.log.error( "ONOS" + str( i + 1 ) +
3884 " expected a size of " + str( size ) +
3885 " for set " + onosSetName +
3886 " but got " + str( sizeResponses[ i ] ) )
3887 removeAllResults = removeAllResults and getResults and sizeResults
3888 utilities.assert_equals( expect=main.TRUE,
3889 actual=removeAllResults,
3890 onpass="Set removeAll correct",
3891 onfail="Set removeAll was incorrect" )
3892
3893 main.step( "Distributed Set addAll()" )
3894 onosSet.update( addAllValue.split() )
3895 addResponses = []
3896 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003897 for i in range( main.numCtrls ):
3898 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall5cf14d52015-07-16 12:15:19 -07003899 name="setTestAddAll-" + str( i ),
3900 args=[ onosSetName, addAllValue ] )
3901 threads.append( t )
3902 t.start()
3903 for t in threads:
3904 t.join()
3905 addResponses.append( t.result )
3906
3907 # main.TRUE = successfully changed the set
3908 # main.FALSE = action resulted in no change in set
3909 # main.ERROR - Some error in executing the function
3910 addAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003911 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003912 if addResponses[ i ] == main.TRUE:
3913 # All is well
3914 pass
3915 elif addResponses[ i ] == main.FALSE:
3916 # Already in set, probably fine
3917 pass
3918 elif addResponses[ i ] == main.ERROR:
3919 # Error in execution
3920 addAllResults = main.FALSE
3921 else:
3922 # unexpected result
3923 addAllResults = main.FALSE
3924 if addAllResults != main.TRUE:
3925 main.log.error( "Error executing set addAll" )
3926
3927 # Check if set is still correct
3928 size = len( onosSet )
3929 getResponses = []
3930 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003931 for i in range( main.numCtrls ):
3932 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003933 name="setTestGet-" + str( i ),
3934 args=[ onosSetName ] )
3935 threads.append( t )
3936 t.start()
3937 for t in threads:
3938 t.join()
3939 getResponses.append( t.result )
3940 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003941 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003942 if isinstance( getResponses[ i ], list):
3943 current = set( getResponses[ i ] )
3944 if len( current ) == len( getResponses[ i ] ):
3945 # no repeats
3946 if onosSet != current:
3947 main.log.error( "ONOS" + str( i + 1 ) +
3948 " has incorrect view" +
3949 " of set " + onosSetName + ":\n" +
3950 str( getResponses[ i ] ) )
3951 main.log.debug( "Expected: " + str( onosSet ) )
3952 main.log.debug( "Actual: " + str( current ) )
3953 getResults = main.FALSE
3954 else:
3955 # error, set is not a set
3956 main.log.error( "ONOS" + str( i + 1 ) +
3957 " has repeat elements in" +
3958 " set " + onosSetName + ":\n" +
3959 str( getResponses[ i ] ) )
3960 getResults = main.FALSE
3961 elif getResponses[ i ] == main.ERROR:
3962 getResults = main.FALSE
3963 sizeResponses = []
3964 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003965 for i in range( main.numCtrls ):
3966 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003967 name="setTestSize-" + str( i ),
3968 args=[ onosSetName ] )
3969 threads.append( t )
3970 t.start()
3971 for t in threads:
3972 t.join()
3973 sizeResponses.append( t.result )
3974 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003975 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003976 if size != sizeResponses[ i ]:
3977 sizeResults = main.FALSE
3978 main.log.error( "ONOS" + str( i + 1 ) +
3979 " expected a size of " + str( size ) +
3980 " for set " + onosSetName +
3981 " but got " + str( sizeResponses[ i ] ) )
3982 addAllResults = addAllResults and getResults and sizeResults
3983 utilities.assert_equals( expect=main.TRUE,
3984 actual=addAllResults,
3985 onpass="Set addAll correct",
3986 onfail="Set addAll was incorrect" )
3987
3988 main.step( "Distributed Set clear()" )
3989 onosSet.clear()
3990 clearResponses = []
3991 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003992 for i in range( main.numCtrls ):
3993 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall5cf14d52015-07-16 12:15:19 -07003994 name="setTestClear-" + str( i ),
3995 args=[ onosSetName, " "], # Values doesn't matter
3996 kwargs={ "clear": True } )
3997 threads.append( t )
3998 t.start()
3999 for t in threads:
4000 t.join()
4001 clearResponses.append( t.result )
4002
4003 # main.TRUE = successfully changed the set
4004 # main.FALSE = action resulted in no change in set
4005 # main.ERROR - Some error in executing the function
4006 clearResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004007 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004008 if clearResponses[ i ] == main.TRUE:
4009 # All is well
4010 pass
4011 elif clearResponses[ i ] == main.FALSE:
4012 # Nothing set, probably fine
4013 pass
4014 elif clearResponses[ i ] == main.ERROR:
4015 # Error in execution
4016 clearResults = main.FALSE
4017 else:
4018 # unexpected result
4019 clearResults = main.FALSE
4020 if clearResults != main.TRUE:
4021 main.log.error( "Error executing set clear" )
4022
4023 # Check if set is still correct
4024 size = len( onosSet )
4025 getResponses = []
4026 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004027 for i in range( main.numCtrls ):
4028 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07004029 name="setTestGet-" + str( i ),
4030 args=[ onosSetName ] )
4031 threads.append( t )
4032 t.start()
4033 for t in threads:
4034 t.join()
4035 getResponses.append( t.result )
4036 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004037 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004038 if isinstance( getResponses[ i ], list):
4039 current = set( getResponses[ i ] )
4040 if len( current ) == len( getResponses[ i ] ):
4041 # no repeats
4042 if onosSet != current:
4043 main.log.error( "ONOS" + str( i + 1 ) +
4044 " has incorrect view" +
4045 " of set " + onosSetName + ":\n" +
4046 str( getResponses[ i ] ) )
4047 main.log.debug( "Expected: " + str( onosSet ) )
4048 main.log.debug( "Actual: " + str( current ) )
4049 getResults = main.FALSE
4050 else:
4051 # error, set is not a set
4052 main.log.error( "ONOS" + str( i + 1 ) +
4053 " has repeat elements in" +
4054 " set " + onosSetName + ":\n" +
4055 str( getResponses[ i ] ) )
4056 getResults = main.FALSE
4057 elif getResponses[ i ] == main.ERROR:
4058 getResults = main.FALSE
4059 sizeResponses = []
4060 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004061 for i in range( main.numCtrls ):
4062 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07004063 name="setTestSize-" + str( i ),
4064 args=[ onosSetName ] )
4065 threads.append( t )
4066 t.start()
4067 for t in threads:
4068 t.join()
4069 sizeResponses.append( t.result )
4070 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004071 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004072 if size != sizeResponses[ i ]:
4073 sizeResults = main.FALSE
4074 main.log.error( "ONOS" + str( i + 1 ) +
4075 " expected a size of " + str( size ) +
4076 " for set " + onosSetName +
4077 " but got " + str( sizeResponses[ i ] ) )
4078 clearResults = clearResults and getResults and sizeResults
4079 utilities.assert_equals( expect=main.TRUE,
4080 actual=clearResults,
4081 onpass="Set clear correct",
4082 onfail="Set clear was incorrect" )
4083
4084 main.step( "Distributed Set addAll()" )
4085 onosSet.update( addAllValue.split() )
4086 addResponses = []
4087 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004088 for i in range( main.numCtrls ):
4089 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall5cf14d52015-07-16 12:15:19 -07004090 name="setTestAddAll-" + str( i ),
4091 args=[ onosSetName, addAllValue ] )
4092 threads.append( t )
4093 t.start()
4094 for t in threads:
4095 t.join()
4096 addResponses.append( t.result )
4097
4098 # main.TRUE = successfully changed the set
4099 # main.FALSE = action resulted in no change in set
4100 # main.ERROR - Some error in executing the function
4101 addAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004102 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004103 if addResponses[ i ] == main.TRUE:
4104 # All is well
4105 pass
4106 elif addResponses[ i ] == main.FALSE:
4107 # Already in set, probably fine
4108 pass
4109 elif addResponses[ i ] == main.ERROR:
4110 # Error in execution
4111 addAllResults = main.FALSE
4112 else:
4113 # unexpected result
4114 addAllResults = main.FALSE
4115 if addAllResults != main.TRUE:
4116 main.log.error( "Error executing set addAll" )
4117
4118 # Check if set is still correct
4119 size = len( onosSet )
4120 getResponses = []
4121 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004122 for i in range( main.numCtrls ):
4123 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07004124 name="setTestGet-" + str( i ),
4125 args=[ onosSetName ] )
4126 threads.append( t )
4127 t.start()
4128 for t in threads:
4129 t.join()
4130 getResponses.append( t.result )
4131 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004132 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004133 if isinstance( getResponses[ i ], list):
4134 current = set( getResponses[ i ] )
4135 if len( current ) == len( getResponses[ i ] ):
4136 # no repeats
4137 if onosSet != current:
4138 main.log.error( "ONOS" + str( i + 1 ) +
4139 " has incorrect view" +
4140 " of set " + onosSetName + ":\n" +
4141 str( getResponses[ i ] ) )
4142 main.log.debug( "Expected: " + str( onosSet ) )
4143 main.log.debug( "Actual: " + str( current ) )
4144 getResults = main.FALSE
4145 else:
4146 # error, set is not a set
4147 main.log.error( "ONOS" + str( i + 1 ) +
4148 " has repeat elements in" +
4149 " set " + onosSetName + ":\n" +
4150 str( getResponses[ i ] ) )
4151 getResults = main.FALSE
4152 elif getResponses[ i ] == main.ERROR:
4153 getResults = main.FALSE
4154 sizeResponses = []
4155 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004156 for i in range( main.numCtrls ):
4157 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07004158 name="setTestSize-" + str( i ),
4159 args=[ onosSetName ] )
4160 threads.append( t )
4161 t.start()
4162 for t in threads:
4163 t.join()
4164 sizeResponses.append( t.result )
4165 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004166 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004167 if size != sizeResponses[ i ]:
4168 sizeResults = main.FALSE
4169 main.log.error( "ONOS" + str( i + 1 ) +
4170 " expected a size of " + str( size ) +
4171 " for set " + onosSetName +
4172 " but got " + str( sizeResponses[ i ] ) )
4173 addAllResults = addAllResults and getResults and sizeResults
4174 utilities.assert_equals( expect=main.TRUE,
4175 actual=addAllResults,
4176 onpass="Set addAll correct",
4177 onfail="Set addAll was incorrect" )
4178
4179 main.step( "Distributed Set retain()" )
4180 onosSet.intersection_update( retainValue.split() )
4181 retainResponses = []
4182 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004183 for i in range( main.numCtrls ):
4184 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall5cf14d52015-07-16 12:15:19 -07004185 name="setTestRetain-" + str( i ),
4186 args=[ onosSetName, retainValue ],
4187 kwargs={ "retain": True } )
4188 threads.append( t )
4189 t.start()
4190 for t in threads:
4191 t.join()
4192 retainResponses.append( t.result )
4193
4194 # main.TRUE = successfully changed the set
4195 # main.FALSE = action resulted in no change in set
4196 # main.ERROR - Some error in executing the function
4197 retainResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004198 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004199 if retainResponses[ i ] == main.TRUE:
4200 # All is well
4201 pass
4202 elif retainResponses[ i ] == main.FALSE:
4203 # Already in set, probably fine
4204 pass
4205 elif retainResponses[ i ] == main.ERROR:
4206 # Error in execution
4207 retainResults = main.FALSE
4208 else:
4209 # unexpected result
4210 retainResults = main.FALSE
4211 if retainResults != main.TRUE:
4212 main.log.error( "Error executing set retain" )
4213
4214 # Check if set is still correct
4215 size = len( onosSet )
4216 getResponses = []
4217 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004218 for i in range( main.numCtrls ):
4219 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07004220 name="setTestGet-" + str( i ),
4221 args=[ onosSetName ] )
4222 threads.append( t )
4223 t.start()
4224 for t in threads:
4225 t.join()
4226 getResponses.append( t.result )
4227 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004228 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004229 if isinstance( getResponses[ i ], list):
4230 current = set( getResponses[ i ] )
4231 if len( current ) == len( getResponses[ i ] ):
4232 # no repeats
4233 if onosSet != current:
4234 main.log.error( "ONOS" + str( i + 1 ) +
4235 " has incorrect view" +
4236 " of set " + onosSetName + ":\n" +
4237 str( getResponses[ i ] ) )
4238 main.log.debug( "Expected: " + str( onosSet ) )
4239 main.log.debug( "Actual: " + str( current ) )
4240 getResults = main.FALSE
4241 else:
4242 # error, set is not a set
4243 main.log.error( "ONOS" + str( i + 1 ) +
4244 " has repeat elements in" +
4245 " set " + onosSetName + ":\n" +
4246 str( getResponses[ i ] ) )
4247 getResults = main.FALSE
4248 elif getResponses[ i ] == main.ERROR:
4249 getResults = main.FALSE
4250 sizeResponses = []
4251 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004252 for i in range( main.numCtrls ):
4253 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07004254 name="setTestSize-" + str( i ),
4255 args=[ onosSetName ] )
4256 threads.append( t )
4257 t.start()
4258 for t in threads:
4259 t.join()
4260 sizeResponses.append( t.result )
4261 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004262 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004263 if size != sizeResponses[ i ]:
4264 sizeResults = main.FALSE
4265 main.log.error( "ONOS" + str( i + 1 ) +
4266 " expected a size of " +
4267 str( size ) + " for set " + onosSetName +
4268 " but got " + str( sizeResponses[ i ] ) )
4269 retainResults = retainResults and getResults and sizeResults
4270 utilities.assert_equals( expect=main.TRUE,
4271 actual=retainResults,
4272 onpass="Set retain correct",
4273 onfail="Set retain was incorrect" )
4274
Jon Hall2a5002c2015-08-21 16:49:11 -07004275 # Transactional maps
4276 main.step( "Partitioned Transactional maps put" )
4277 tMapValue = "Testing"
4278 numKeys = 100
4279 putResult = True
4280 putResponses = main.CLIs[ 0 ].transactionalMapPut( numKeys, tMapValue )
4281 if len( putResponses ) == 100:
4282 for i in putResponses:
4283 if putResponses[ i ][ 'value' ] != tMapValue:
4284 putResult = False
4285 else:
4286 putResult = False
4287 if not putResult:
4288 main.log.debug( "Put response values: " + str( putResponses ) )
4289 utilities.assert_equals( expect=True,
4290 actual=putResult,
4291 onpass="Partitioned Transactional Map put successful",
4292 onfail="Partitioned Transactional Map put values are incorrect" )
4293
4294 main.step( "Partitioned Transactional maps get" )
4295 getCheck = True
4296 for n in range( 1, numKeys + 1 ):
4297 getResponses = []
4298 threads = []
4299 valueCheck = True
4300 for i in range( main.numCtrls ):
4301 t = main.Thread( target=main.CLIs[i].transactionalMapGet,
4302 name="TMap-get-" + str( i ),
4303 args=[ "Key" + str ( n ) ] )
4304 threads.append( t )
4305 t.start()
4306 for t in threads:
4307 t.join()
4308 getResponses.append( t.result )
4309 for node in getResponses:
4310 if node != tMapValue:
4311 valueCheck = False
4312 if not valueCheck:
4313 main.log.warn( "Values for key 'Key" + str( n ) + "' do not match:" )
4314 main.log.warn( getResponses )
4315 getCheck = getCheck and valueCheck
4316 utilities.assert_equals( expect=True,
4317 actual=getCheck,
4318 onpass="Partitioned Transactional Map get values were correct",
4319 onfail="Partitioned Transactional Map values incorrect" )
4320
4321 main.step( "In-memory Transactional maps put" )
4322 tMapValue = "Testing"
4323 numKeys = 100
4324 putResult = True
4325 putResponses = main.CLIs[ 0 ].transactionalMapPut( numKeys, tMapValue, inMemory=True )
4326 if len( putResponses ) == 100:
4327 for i in putResponses:
4328 if putResponses[ i ][ 'value' ] != tMapValue:
4329 putResult = False
4330 else:
4331 putResult = False
4332 if not putResult:
4333 main.log.debug( "Put response values: " + str( putResponses ) )
4334 utilities.assert_equals( expect=True,
4335 actual=putResult,
4336 onpass="In-Memory Transactional Map put successful",
4337 onfail="In-Memory Transactional Map put values are incorrect" )
4338
4339 main.step( "In-Memory Transactional maps get" )
4340 getCheck = True
4341 for n in range( 1, numKeys + 1 ):
4342 getResponses = []
4343 threads = []
4344 valueCheck = True
4345 for i in range( main.numCtrls ):
4346 t = main.Thread( target=main.CLIs[i].transactionalMapGet,
4347 name="TMap-get-" + str( i ),
4348 args=[ "Key" + str ( n ) ],
4349 kwargs={ "inMemory": True } )
4350 threads.append( t )
4351 t.start()
4352 for t in threads:
4353 t.join()
4354 getResponses.append( t.result )
4355 for node in getResponses:
4356 if node != tMapValue:
4357 valueCheck = False
4358 if not valueCheck:
4359 main.log.warn( "Values for key 'Key" + str( n ) + "' do not match:" )
4360 main.log.warn( getResponses )
4361 getCheck = getCheck and valueCheck
4362 utilities.assert_equals( expect=True,
4363 actual=getCheck,
4364 onpass="In-Memory Transactional Map get values were correct",
4365 onfail="In-Memory Transactional Map values incorrect" )