blob: 340df871614899e4f273fb5b4d8a3f357c3bd592 [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
Jon Hall657cdf62015-12-17 14:40:51 -08001640 if hosts[ controller ] and "Error" not in hosts[ controller ]:
Jon Hall5cf14d52015-07-16 12:15:19 -07001641 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 ):
Jon Halld8f6de82015-12-17 17:04:34 -08002077 t = main.Thread( target=utilities.retry,
Jon Hall5cf14d52015-07-16 12:15:19 -07002078 name="hosts-" + str( i ),
Jon Halld8f6de82015-12-17 17:04:34 -08002079 args=[ main.CLIs[i].hosts, [ None ] ],
2080 kwargs= { 'sleep': 5, 'attempts': 5,
2081 'randomTime': True } )
Jon Hall5cf14d52015-07-16 12:15:19 -07002082 threads.append( t )
2083 t.start()
2084
2085 for t in threads:
2086 t.join()
2087 try:
2088 hosts.append( json.loads( t.result ) )
2089 except ( ValueError, TypeError ):
2090 main.log.exception( "Error parsing hosts results" )
2091 main.log.error( repr( t.result ) )
Jon Hallf3d16e72015-12-16 17:45:08 -08002092 hosts.append( None )
Jon Hall5cf14d52015-07-16 12:15:19 -07002093 for controller in range( 0, len( hosts ) ):
2094 controllerStr = str( controller + 1 )
Jon Hallacd1b182015-12-17 11:43:20 -08002095 if hosts[ controller ]:
2096 for host in hosts[ controller ]:
2097 if host is None or host.get( 'ipAddresses', [] ) == []:
2098 main.log.error(
2099 "Error with host ipAddresses on controller" +
2100 controllerStr + ": " + str( host ) )
2101 ipResult = main.FALSE
Jon Hall5cf14d52015-07-16 12:15:19 -07002102 ports = []
2103 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002104 for i in range( main.numCtrls ):
2105 t = main.Thread( target=main.CLIs[i].ports,
Jon Hall5cf14d52015-07-16 12:15:19 -07002106 name="ports-" + str( i ),
2107 args=[ ] )
2108 threads.append( t )
2109 t.start()
2110
2111 for t in threads:
2112 t.join()
2113 ports.append( t.result )
2114 links = []
2115 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002116 for i in range( main.numCtrls ):
2117 t = main.Thread( target=main.CLIs[i].links,
Jon Hall5cf14d52015-07-16 12:15:19 -07002118 name="links-" + str( i ),
2119 args=[ ] )
2120 threads.append( t )
2121 t.start()
2122
2123 for t in threads:
2124 t.join()
2125 links.append( t.result )
2126 clusters = []
2127 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002128 for i in range( main.numCtrls ):
2129 t = main.Thread( target=main.CLIs[i].clusters,
Jon Hall5cf14d52015-07-16 12:15:19 -07002130 name="clusters-" + str( i ),
2131 args=[ ] )
2132 threads.append( t )
2133 t.start()
2134
2135 for t in threads:
2136 t.join()
2137 clusters.append( t.result )
2138
2139 elapsed = time.time() - startTime
2140 cliTime = time.time() - cliStart
2141 print "Elapsed time: " + str( elapsed )
2142 print "CLI time: " + str( cliTime )
2143
2144 mnSwitches = main.Mininet1.getSwitches()
2145 mnLinks = main.Mininet1.getLinks()
2146 mnHosts = main.Mininet1.getHosts()
Jon Halle1a3b752015-07-22 13:02:46 -07002147 for controller in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07002148 controllerStr = str( controller + 1 )
2149 if devices[ controller ] and ports[ controller ] and\
2150 "Error" not in devices[ controller ] and\
2151 "Error" not in ports[ controller ]:
2152
2153 currentDevicesResult = main.Mininet1.compareSwitches(
2154 mnSwitches,
2155 json.loads( devices[ controller ] ),
2156 json.loads( ports[ controller ] ) )
2157 else:
2158 currentDevicesResult = main.FALSE
2159 utilities.assert_equals( expect=main.TRUE,
2160 actual=currentDevicesResult,
2161 onpass="ONOS" + controllerStr +
2162 " Switches view is correct",
2163 onfail="ONOS" + controllerStr +
2164 " Switches view is incorrect" )
2165
2166 if links[ controller ] and "Error" not in links[ controller ]:
2167 currentLinksResult = main.Mininet1.compareLinks(
2168 mnSwitches, mnLinks,
2169 json.loads( links[ controller ] ) )
2170 else:
2171 currentLinksResult = main.FALSE
2172 utilities.assert_equals( expect=main.TRUE,
2173 actual=currentLinksResult,
2174 onpass="ONOS" + controllerStr +
2175 " links view is correct",
2176 onfail="ONOS" + controllerStr +
2177 " links view is incorrect" )
Jon Hall657cdf62015-12-17 14:40:51 -08002178 if hosts[ controller ] and "Error" not in hosts[ controller ]:
Jon Hall5cf14d52015-07-16 12:15:19 -07002179 currentHostsResult = main.Mininet1.compareHosts(
2180 mnHosts,
2181 hosts[ controller ] )
2182 else:
2183 currentHostsResult = main.FALSE
2184 utilities.assert_equals( expect=main.TRUE,
2185 actual=currentHostsResult,
2186 onpass="ONOS" + controllerStr +
2187 " hosts exist in Mininet",
2188 onfail="ONOS" + controllerStr +
2189 " hosts don't match Mininet" )
2190 # CHECKING HOST ATTACHMENT POINTS
2191 hostAttachment = True
2192 zeroHosts = False
2193 # FIXME: topo-HA/obelisk specific mappings:
2194 # key is mac and value is dpid
2195 mappings = {}
2196 for i in range( 1, 29 ): # hosts 1 through 28
2197 # set up correct variables:
2198 macId = "00:" * 5 + hex( i ).split( "0x" )[1].upper().zfill(2)
2199 if i == 1:
2200 deviceId = "1000".zfill(16)
2201 elif i == 2:
2202 deviceId = "2000".zfill(16)
2203 elif i == 3:
2204 deviceId = "3000".zfill(16)
2205 elif i == 4:
2206 deviceId = "3004".zfill(16)
2207 elif i == 5:
2208 deviceId = "5000".zfill(16)
2209 elif i == 6:
2210 deviceId = "6000".zfill(16)
2211 elif i == 7:
2212 deviceId = "6007".zfill(16)
2213 elif i >= 8 and i <= 17:
2214 dpid = '3' + str( i ).zfill( 3 )
2215 deviceId = dpid.zfill(16)
2216 elif i >= 18 and i <= 27:
2217 dpid = '6' + str( i ).zfill( 3 )
2218 deviceId = dpid.zfill(16)
2219 elif i == 28:
2220 deviceId = "2800".zfill(16)
2221 mappings[ macId ] = deviceId
Jon Halld8f6de82015-12-17 17:04:34 -08002222 if hosts[ controller ] is not None and "Error" not in hosts[ controller ]:
Jon Hall5cf14d52015-07-16 12:15:19 -07002223 if hosts[ controller ] == []:
2224 main.log.warn( "There are no hosts discovered" )
2225 zeroHosts = True
2226 else:
2227 for host in hosts[ controller ]:
2228 mac = None
2229 location = None
2230 device = None
2231 port = None
2232 try:
2233 mac = host.get( 'mac' )
2234 assert mac, "mac field could not be found for this host object"
2235
2236 location = host.get( 'location' )
2237 assert location, "location field could not be found for this host object"
2238
2239 # Trim the protocol identifier off deviceId
2240 device = str( location.get( 'elementId' ) ).split(':')[1]
2241 assert device, "elementId field could not be found for this host location object"
2242
2243 port = location.get( 'port' )
2244 assert port, "port field could not be found for this host location object"
2245
2246 # Now check if this matches where they should be
2247 if mac and device and port:
2248 if str( port ) != "1":
2249 main.log.error( "The attachment port is incorrect for " +
2250 "host " + str( mac ) +
2251 ". Expected: 1 Actual: " + str( port) )
2252 hostAttachment = False
2253 if device != mappings[ str( mac ) ]:
2254 main.log.error( "The attachment device is incorrect for " +
2255 "host " + str( mac ) +
2256 ". Expected: " + mappings[ str( mac ) ] +
2257 " Actual: " + device )
2258 hostAttachment = False
2259 else:
2260 hostAttachment = False
2261 except AssertionError:
2262 main.log.exception( "Json object not as expected" )
2263 main.log.error( repr( host ) )
2264 hostAttachment = False
2265 else:
2266 main.log.error( "No hosts json output or \"Error\"" +
2267 " in output. hosts = " +
2268 repr( hosts[ controller ] ) )
2269 if zeroHosts is False:
2270 hostAttachment = True
2271
2272 # END CHECKING HOST ATTACHMENT POINTS
2273 devicesResults = devicesResults and currentDevicesResult
2274 linksResults = linksResults and currentLinksResult
2275 hostsResults = hostsResults and currentHostsResult
2276 hostAttachmentResults = hostAttachmentResults and\
2277 hostAttachment
2278 topoResult = ( devicesResults and linksResults
2279 and hostsResults and ipResult and
2280 hostAttachmentResults )
Jon Halle9b1fa32015-12-08 15:32:21 -08002281 utilities.assert_equals( expect=True,
2282 actual=topoResult,
2283 onpass="ONOS topology matches Mininet",
2284 onfail="ONOS topology don't match Mininet" )
2285 # End of While loop to pull ONOS state
Jon Hall5cf14d52015-07-16 12:15:19 -07002286
2287 # Compare json objects for hosts and dataplane clusters
2288
2289 # hosts
2290 main.step( "Hosts view is consistent across all ONOS nodes" )
2291 consistentHostsResult = main.TRUE
2292 for controller in range( len( hosts ) ):
2293 controllerStr = str( controller + 1 )
Jon Hall657cdf62015-12-17 14:40:51 -08002294 if hosts[ controller ] and "Error" not in hosts[ controller ]:
Jon Hall5cf14d52015-07-16 12:15:19 -07002295 if hosts[ controller ] == hosts[ 0 ]:
2296 continue
2297 else: # hosts not consistent
2298 main.log.error( "hosts from ONOS" + controllerStr +
2299 " is inconsistent with ONOS1" )
2300 main.log.warn( repr( hosts[ controller ] ) )
2301 consistentHostsResult = main.FALSE
2302
2303 else:
2304 main.log.error( "Error in getting ONOS hosts from ONOS" +
2305 controllerStr )
2306 consistentHostsResult = main.FALSE
2307 main.log.warn( "ONOS" + controllerStr +
2308 " hosts response: " +
2309 repr( hosts[ controller ] ) )
2310 utilities.assert_equals(
2311 expect=main.TRUE,
2312 actual=consistentHostsResult,
2313 onpass="Hosts view is consistent across all ONOS nodes",
2314 onfail="ONOS nodes have different views of hosts" )
2315
2316 main.step( "Hosts information is correct" )
2317 hostsResults = hostsResults and ipResult
2318 utilities.assert_equals(
2319 expect=main.TRUE,
2320 actual=hostsResults,
2321 onpass="Host information is correct",
2322 onfail="Host information is incorrect" )
2323
2324 main.step( "Host attachment points to the network" )
2325 utilities.assert_equals(
2326 expect=True,
2327 actual=hostAttachmentResults,
2328 onpass="Hosts are correctly attached to the network",
2329 onfail="ONOS did not correctly attach hosts to the network" )
2330
2331 # Strongly connected clusters of devices
2332 main.step( "Clusters view is consistent across all ONOS nodes" )
2333 consistentClustersResult = main.TRUE
2334 for controller in range( len( clusters ) ):
2335 controllerStr = str( controller + 1 )
2336 if "Error" not in clusters[ controller ]:
2337 if clusters[ controller ] == clusters[ 0 ]:
2338 continue
2339 else: # clusters not consistent
2340 main.log.error( "clusters from ONOS" +
2341 controllerStr +
2342 " is inconsistent with ONOS1" )
2343 consistentClustersResult = main.FALSE
2344
2345 else:
2346 main.log.error( "Error in getting dataplane clusters " +
2347 "from ONOS" + controllerStr )
2348 consistentClustersResult = main.FALSE
2349 main.log.warn( "ONOS" + controllerStr +
2350 " clusters response: " +
2351 repr( clusters[ controller ] ) )
2352 utilities.assert_equals(
2353 expect=main.TRUE,
2354 actual=consistentClustersResult,
2355 onpass="Clusters view is consistent across all ONOS nodes",
2356 onfail="ONOS nodes have different views of clusters" )
2357
2358 main.step( "There is only one SCC" )
2359 # there should always only be one cluster
2360 try:
2361 numClusters = len( json.loads( clusters[ 0 ] ) )
2362 except ( ValueError, TypeError ):
2363 main.log.exception( "Error parsing clusters[0]: " +
2364 repr( clusters[0] ) )
2365 clusterResults = main.FALSE
2366 if numClusters == 1:
2367 clusterResults = main.TRUE
2368 utilities.assert_equals(
2369 expect=1,
2370 actual=numClusters,
2371 onpass="ONOS shows 1 SCC",
2372 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
2373
2374 topoResult = ( devicesResults and linksResults
2375 and hostsResults and consistentHostsResult
2376 and consistentClustersResult and clusterResults
2377 and ipResult and hostAttachmentResults )
2378
2379 topoResult = topoResult and int( count <= 2 )
2380 note = "note it takes about " + str( int( cliTime ) ) + \
2381 " seconds for the test to make all the cli calls to fetch " +\
2382 "the topology from each ONOS instance"
2383 main.log.info(
2384 "Very crass estimate for topology discovery/convergence( " +
2385 str( note ) + " ): " + str( elapsed ) + " seconds, " +
2386 str( count ) + " tries" )
2387
2388 main.step( "Device information is correct" )
2389 utilities.assert_equals(
2390 expect=main.TRUE,
2391 actual=devicesResults,
2392 onpass="Device information is correct",
2393 onfail="Device information is incorrect" )
2394
2395 main.step( "Links are correct" )
2396 utilities.assert_equals(
2397 expect=main.TRUE,
2398 actual=linksResults,
2399 onpass="Link are correct",
2400 onfail="Links are incorrect" )
2401
2402 main.step( "Hosts are correct" )
2403 utilities.assert_equals(
2404 expect=main.TRUE,
2405 actual=hostsResults,
2406 onpass="Hosts are correct",
2407 onfail="Hosts are incorrect" )
2408
2409 # FIXME: move this to an ONOS state case
2410 main.step( "Checking ONOS nodes" )
2411 nodesOutput = []
2412 nodeResults = main.TRUE
2413 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07002414 for i in range( main.numCtrls ):
2415 t = main.Thread( target=main.CLIs[i].nodes,
Jon Hall5cf14d52015-07-16 12:15:19 -07002416 name="nodes-" + str( i ),
2417 args=[ ] )
2418 threads.append( t )
2419 t.start()
2420
2421 for t in threads:
2422 t.join()
2423 nodesOutput.append( t.result )
Jon Halle1a3b752015-07-22 13:02:46 -07002424 ips = [ node.ip_address for node in main.nodes ]
Jon Halle9b1fa32015-12-08 15:32:21 -08002425 ips.sort()
Jon Hall5cf14d52015-07-16 12:15:19 -07002426 for i in nodesOutput:
2427 try:
2428 current = json.loads( i )
Jon Halle9b1fa32015-12-08 15:32:21 -08002429 activeIps = []
2430 currentResult = main.FALSE
Jon Hall5cf14d52015-07-16 12:15:19 -07002431 for node in current:
Jon Halle9b1fa32015-12-08 15:32:21 -08002432 if node['state'] == 'ACTIVE':
2433 activeIps.append( node['ip'] )
2434 activeIps.sort()
2435 if ips == activeIps:
2436 currentResult = main.TRUE
Jon Hall5cf14d52015-07-16 12:15:19 -07002437 except ( ValueError, TypeError ):
2438 main.log.error( "Error parsing nodes output" )
2439 main.log.warn( repr( i ) )
Jon Halle9b1fa32015-12-08 15:32:21 -08002440 currentResult = main.FALSE
2441 nodeResults = nodeResults and currentResult
Jon Hall5cf14d52015-07-16 12:15:19 -07002442 utilities.assert_equals( expect=main.TRUE, actual=nodeResults,
2443 onpass="Nodes check successful",
2444 onfail="Nodes check NOT successful" )
2445
2446 def CASE9( self, main ):
2447 """
2448 Link s3-s28 down
2449 """
2450 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002451 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002452 assert main, "main not defined"
2453 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002454 assert main.CLIs, "main.CLIs not defined"
2455 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002456 # NOTE: You should probably run a topology check after this
2457
2458 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
2459
2460 description = "Turn off a link to ensure that Link Discovery " +\
2461 "is working properly"
2462 main.case( description )
2463
2464 main.step( "Kill Link between s3 and s28" )
2465 LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" )
2466 main.log.info( "Waiting " + str( linkSleep ) +
2467 " seconds for link down to be discovered" )
2468 time.sleep( linkSleep )
2469 utilities.assert_equals( expect=main.TRUE, actual=LinkDown,
2470 onpass="Link down successful",
2471 onfail="Failed to bring link down" )
2472 # TODO do some sort of check here
2473
2474 def CASE10( self, main ):
2475 """
2476 Link s3-s28 up
2477 """
2478 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002479 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002480 assert main, "main not defined"
2481 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002482 assert main.CLIs, "main.CLIs not defined"
2483 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002484 # NOTE: You should probably run a topology check after this
2485
2486 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
2487
2488 description = "Restore a link to ensure that Link Discovery is " + \
2489 "working properly"
2490 main.case( description )
2491
2492 main.step( "Bring link between s3 and s28 back up" )
2493 LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" )
2494 main.log.info( "Waiting " + str( linkSleep ) +
2495 " seconds for link up to be discovered" )
2496 time.sleep( linkSleep )
2497 utilities.assert_equals( expect=main.TRUE, actual=LinkUp,
2498 onpass="Link up successful",
2499 onfail="Failed to bring link up" )
2500 # TODO do some sort of check here
2501
2502 def CASE11( self, main ):
2503 """
2504 Switch Down
2505 """
2506 # NOTE: You should probably run a topology check after this
2507 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002508 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002509 assert main, "main not defined"
2510 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002511 assert main.CLIs, "main.CLIs not defined"
2512 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002513
2514 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
2515
2516 description = "Killing a switch to ensure it is discovered correctly"
2517 main.case( description )
2518 switch = main.params[ 'kill' ][ 'switch' ]
2519 switchDPID = main.params[ 'kill' ][ 'dpid' ]
2520
2521 # TODO: Make this switch parameterizable
2522 main.step( "Kill " + switch )
2523 main.log.info( "Deleting " + switch )
2524 main.Mininet1.delSwitch( switch )
2525 main.log.info( "Waiting " + str( switchSleep ) +
2526 " seconds for switch down to be discovered" )
2527 time.sleep( switchSleep )
2528 device = main.ONOScli1.getDevice( dpid=switchDPID )
2529 # Peek at the deleted switch
2530 main.log.warn( str( device ) )
2531 result = main.FALSE
2532 if device and device[ 'available' ] is False:
2533 result = main.TRUE
2534 utilities.assert_equals( expect=main.TRUE, actual=result,
2535 onpass="Kill switch successful",
2536 onfail="Failed to kill switch?" )
2537
2538 def CASE12( self, main ):
2539 """
2540 Switch Up
2541 """
2542 # NOTE: You should probably run a topology check after this
2543 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002544 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002545 assert main, "main not defined"
2546 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002547 assert main.CLIs, "main.CLIs not defined"
2548 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002549 assert ONOS1Port, "ONOS1Port not defined"
2550 assert ONOS2Port, "ONOS2Port not defined"
2551 assert ONOS3Port, "ONOS3Port not defined"
2552 assert ONOS4Port, "ONOS4Port not defined"
2553 assert ONOS5Port, "ONOS5Port not defined"
2554 assert ONOS6Port, "ONOS6Port not defined"
2555 assert ONOS7Port, "ONOS7Port not defined"
2556
2557 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
2558 switch = main.params[ 'kill' ][ 'switch' ]
2559 switchDPID = main.params[ 'kill' ][ 'dpid' ]
2560 links = main.params[ 'kill' ][ 'links' ].split()
2561 description = "Adding a switch to ensure it is discovered correctly"
2562 main.case( description )
2563
2564 main.step( "Add back " + switch )
2565 main.Mininet1.addSwitch( switch, dpid=switchDPID )
2566 for peer in links:
2567 main.Mininet1.addLink( switch, peer )
2568 ipList = []
Jon Halle1a3b752015-07-22 13:02:46 -07002569 for i in range( main.numCtrls ):
2570 ipList.append( main.nodes[ i ].ip_address )
Jon Hall5cf14d52015-07-16 12:15:19 -07002571 main.Mininet1.assignSwController( sw=switch, ip=ipList )
2572 main.log.info( "Waiting " + str( switchSleep ) +
2573 " seconds for switch up to be discovered" )
2574 time.sleep( switchSleep )
2575 device = main.ONOScli1.getDevice( dpid=switchDPID )
2576 # Peek at the deleted switch
2577 main.log.warn( str( device ) )
2578 result = main.FALSE
2579 if device and device[ 'available' ]:
2580 result = main.TRUE
2581 utilities.assert_equals( expect=main.TRUE, actual=result,
2582 onpass="add switch successful",
2583 onfail="Failed to add switch?" )
2584
2585 def CASE13( self, main ):
2586 """
2587 Clean up
2588 """
2589 import os
2590 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002591 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002592 assert main, "main not defined"
2593 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002594 assert main.CLIs, "main.CLIs not defined"
2595 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002596
2597 # printing colors to terminal
2598 colors = { 'cyan': '\033[96m', 'purple': '\033[95m',
2599 'blue': '\033[94m', 'green': '\033[92m',
2600 'yellow': '\033[93m', 'red': '\033[91m', 'end': '\033[0m' }
2601 main.case( "Test Cleanup" )
2602 main.step( "Killing tcpdumps" )
2603 main.Mininet2.stopTcpdump()
2604
2605 testname = main.TEST
Jon Hall96091e62015-09-21 17:34:17 -07002606 if main.params[ 'BACKUP' ][ 'ENABLED' ] == "True":
Jon Hall5cf14d52015-07-16 12:15:19 -07002607 main.step( "Copying MN pcap and ONOS log files to test station" )
2608 teststationUser = main.params[ 'BACKUP' ][ 'TESTONUSER' ]
2609 teststationIP = main.params[ 'BACKUP' ][ 'TESTONIP' ]
Jon Hall96091e62015-09-21 17:34:17 -07002610 # NOTE: MN Pcap file is being saved to logdir.
2611 # We scp this file as MN and TestON aren't necessarily the same vm
2612
2613 # FIXME: To be replaced with a Jenkin's post script
Jon Hall5cf14d52015-07-16 12:15:19 -07002614 # TODO: Load these from params
2615 # NOTE: must end in /
2616 logFolder = "/opt/onos/log/"
2617 logFiles = [ "karaf.log", "karaf.log.1" ]
2618 # NOTE: must end in /
Jon Hall5cf14d52015-07-16 12:15:19 -07002619 for f in logFiles:
Jon Halle1a3b752015-07-22 13:02:46 -07002620 for node in main.nodes:
Jon Hall96091e62015-09-21 17:34:17 -07002621 dstName = main.logdir + "/" + node.name + "-" + f
2622 main.ONOSbench.secureCopy( node.user_name, node.ip_address,
2623 logFolder + f, dstName )
Jon Hall5cf14d52015-07-16 12:15:19 -07002624 # std*.log's
2625 # NOTE: must end in /
2626 logFolder = "/opt/onos/var/"
2627 logFiles = [ "stderr.log", "stdout.log" ]
2628 # NOTE: must end in /
Jon Hall5cf14d52015-07-16 12:15:19 -07002629 for f in logFiles:
Jon Halle1a3b752015-07-22 13:02:46 -07002630 for node in main.nodes:
Jon Hall96091e62015-09-21 17:34:17 -07002631 dstName = main.logdir + "/" + node.name + "-" + f
2632 main.ONOSbench.secureCopy( node.user_name, node.ip_address,
2633 logFolder + f, dstName )
2634 else:
2635 main.log.debug( "skipping saving log files" )
Jon Hall5cf14d52015-07-16 12:15:19 -07002636
2637 main.step( "Stopping Mininet" )
2638 mnResult = main.Mininet1.stopNet()
2639 utilities.assert_equals( expect=main.TRUE, actual=mnResult,
2640 onpass="Mininet stopped",
2641 onfail="MN cleanup NOT successful" )
2642
2643 main.step( "Checking ONOS Logs for errors" )
Jon Halle1a3b752015-07-22 13:02:46 -07002644 for node in main.nodes:
Jon Hall96091e62015-09-21 17:34:17 -07002645 main.log.debug( "Checking logs for errors on " + node.name + ":" )
2646 main.log.warn( main.ONOSbench.checkLogs( node.ip_address ) )
Jon Hall5cf14d52015-07-16 12:15:19 -07002647
2648 try:
2649 timerLog = open( main.logdir + "/Timers.csv", 'w')
2650 # Overwrite with empty line and close
2651 labels = "Gossip Intents"
2652 data = str( gossipTime )
2653 timerLog.write( labels + "\n" + data )
2654 timerLog.close()
2655 except NameError, e:
2656 main.log.exception(e)
2657
2658 def CASE14( self, main ):
2659 """
2660 start election app on all onos nodes
2661 """
Jon Halle1a3b752015-07-22 13:02:46 -07002662 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002663 assert main, "main not defined"
2664 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002665 assert main.CLIs, "main.CLIs not defined"
2666 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002667
2668 main.case("Start Leadership Election app")
2669 main.step( "Install leadership election app" )
2670 appResult = main.ONOScli1.activateApp( "org.onosproject.election" )
2671 utilities.assert_equals(
2672 expect=main.TRUE,
2673 actual=appResult,
2674 onpass="Election app installed",
2675 onfail="Something went wrong with installing Leadership election" )
2676
2677 main.step( "Run for election on each node" )
2678 leaderResult = main.TRUE
2679 leaders = []
Jon Halle1a3b752015-07-22 13:02:46 -07002680 for cli in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -07002681 cli.electionTestRun()
Jon Halle1a3b752015-07-22 13:02:46 -07002682 for cli in main.CLIs:
Jon Hall5cf14d52015-07-16 12:15:19 -07002683 leader = cli.electionTestLeader()
2684 if leader is None or leader == main.FALSE:
2685 main.log.error( cli.name + ": Leader for the election app " +
2686 "should be an ONOS node, instead got '" +
2687 str( leader ) + "'" )
2688 leaderResult = main.FALSE
2689 leaders.append( leader )
2690 utilities.assert_equals(
2691 expect=main.TRUE,
2692 actual=leaderResult,
2693 onpass="Successfully ran for leadership",
2694 onfail="Failed to run for leadership" )
2695
2696 main.step( "Check that each node shows the same leader" )
2697 sameLeader = main.TRUE
2698 if len( set( leaders ) ) != 1:
2699 sameLeader = main.FALSE
Jon Halle1a3b752015-07-22 13:02:46 -07002700 main.log.error( "Results of electionTestLeader is order of main.CLIs:" +
Jon Hall5cf14d52015-07-16 12:15:19 -07002701 str( leaders ) )
2702 utilities.assert_equals(
2703 expect=main.TRUE,
2704 actual=sameLeader,
2705 onpass="Leadership is consistent for the election topic",
2706 onfail="Nodes have different leaders" )
2707
2708 def CASE15( self, main ):
2709 """
2710 Check that Leadership Election is still functional
acsmars71adceb2015-08-31 15:09:26 -07002711 15.1 Run election on each node
2712 15.2 Check that each node has the same leaders and candidates
2713 15.3 Find current leader and withdraw
2714 15.4 Check that a new node was elected leader
2715 15.5 Check that that new leader was the candidate of old leader
2716 15.6 Run for election on old leader
2717 15.7 Check that oldLeader is a candidate, and leader if only 1 node
2718 15.8 Make sure that the old leader was added to the candidate list
2719
2720 old and new variable prefixes refer to data from before vs after
2721 withdrawl and later before withdrawl vs after re-election
Jon Hall5cf14d52015-07-16 12:15:19 -07002722 """
2723 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002724 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002725 assert main, "main not defined"
2726 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002727 assert main.CLIs, "main.CLIs not defined"
2728 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002729
acsmars3a72bde2015-09-02 14:16:22 -07002730 description = "Check that Leadership Election App is still functional"
Jon Hall5cf14d52015-07-16 12:15:19 -07002731 main.case( description )
acsmars71adceb2015-08-31 15:09:26 -07002732 # NOTE: Need to re-run since being a canidate is not persistant
2733 # TODO: add check for "Command not found:" in the driver, this
2734 # means the election test app isn't loaded
Jon Hall5cf14d52015-07-16 12:15:19 -07002735
acsmars71adceb2015-08-31 15:09:26 -07002736 oldLeaders = [] # leaders by node before withdrawl from candidates
2737 newLeaders = [] # leaders by node after withdrawl from candidates
2738 oldAllCandidates = [] # list of lists of each nodes' candidates before
2739 newAllCandidates = [] # list of lists of each nodes' candidates after
2740 oldCandidates = [] # list of candidates from node 0 before withdrawl
2741 newCandidates = [] # list of candidates from node 0 after withdrawl
2742 oldLeader = '' # the old leader from oldLeaders, None if not same
2743 newLeader = '' # the new leaders fron newLoeaders, None if not same
2744 oldLeaderCLI = None # the CLI of the old leader used for re-electing
2745 expectNoLeader = False # True when there is only one leader
2746 if main.numCtrls == 1:
2747 expectNoLeader = True
2748
2749 main.step( "Run for election on each node" )
2750 electionResult = main.TRUE
2751
2752 for cli in main.CLIs: # run test election on each node
2753 if cli.electionTestRun() == main.FALSE:
2754 electionResult = main.FALSE
2755
Jon Hall5cf14d52015-07-16 12:15:19 -07002756 utilities.assert_equals(
2757 expect=main.TRUE,
acsmars71adceb2015-08-31 15:09:26 -07002758 actual=electionResult,
2759 onpass="All nodes successfully ran for leadership",
2760 onfail="At least one node failed to run for leadership" )
2761
acsmars3a72bde2015-09-02 14:16:22 -07002762 if electionResult == main.FALSE:
2763 main.log.error(
2764 "Skipping Test Case because Election Test isn't loaded" )
2765 main.skipCase()
2766
acsmars71adceb2015-08-31 15:09:26 -07002767 main.step( "Check that each node shows the same leader and candidates" )
2768 sameResult = main.TRUE
2769 failMessage = "Nodes have different leaders"
2770 for cli in main.CLIs:
2771 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
2772 oldAllCandidates.append( node )
2773 oldLeaders.append( node[ 0 ] )
2774 oldCandidates = oldAllCandidates[ 0 ]
2775
2776 # Check that each node has the same leader. Defines oldLeader
2777 if len( set( oldLeaders ) ) != 1:
2778 sameResult = main.FALSE
2779 main.log.error( "More than one leader present:" + str( oldLeaders ) )
2780 oldLeader = None
2781 else:
2782 oldLeader = oldLeaders[ 0 ]
2783
2784 # Check that each node's candidate list is the same
acsmars29233db2015-11-04 11:15:00 -08002785 candidateDiscrepancy = False # Boolean of candidate mismatches
acsmars71adceb2015-08-31 15:09:26 -07002786 for candidates in oldAllCandidates:
2787 if set( candidates ) != set( oldCandidates ):
2788 sameResult = main.FALSE
acsmars29233db2015-11-04 11:15:00 -08002789 candidateDiscrepancy = True
2790
2791 if candidateDiscrepancy:
2792 failMessage += " and candidates"
acsmars71adceb2015-08-31 15:09:26 -07002793
2794 utilities.assert_equals(
2795 expect=main.TRUE,
2796 actual=sameResult,
Jon Hall5cf14d52015-07-16 12:15:19 -07002797 onpass="Leadership is consistent for the election topic",
acsmars71adceb2015-08-31 15:09:26 -07002798 onfail=failMessage )
Jon Hall5cf14d52015-07-16 12:15:19 -07002799
2800 main.step( "Find current leader and withdraw" )
acsmars71adceb2015-08-31 15:09:26 -07002801 withdrawResult = main.TRUE
Jon Hall5cf14d52015-07-16 12:15:19 -07002802 # do some sanity checking on leader before using it
acsmars71adceb2015-08-31 15:09:26 -07002803 if oldLeader is None:
2804 main.log.error( "Leadership isn't consistent." )
2805 withdrawResult = main.FALSE
2806 # Get the CLI of the oldLeader
Jon Halle1a3b752015-07-22 13:02:46 -07002807 for i in range( len( main.CLIs ) ):
acsmars71adceb2015-08-31 15:09:26 -07002808 if oldLeader == main.nodes[ i ].ip_address:
2809 oldLeaderCLI = main.CLIs[ i ]
Jon Hall5cf14d52015-07-16 12:15:19 -07002810 break
2811 else: # FOR/ELSE statement
2812 main.log.error( "Leader election, could not find current leader" )
2813 if oldLeader:
acsmars71adceb2015-08-31 15:09:26 -07002814 withdrawResult = oldLeaderCLI.electionTestWithdraw()
Jon Hall5cf14d52015-07-16 12:15:19 -07002815 utilities.assert_equals(
2816 expect=main.TRUE,
2817 actual=withdrawResult,
2818 onpass="Node was withdrawn from election",
2819 onfail="Node was not withdrawn from election" )
2820
acsmars71adceb2015-08-31 15:09:26 -07002821 main.step( "Check that a new node was elected leader" )
2822
Jon Hall5cf14d52015-07-16 12:15:19 -07002823 # FIXME: use threads
acsmars71adceb2015-08-31 15:09:26 -07002824 newLeaderResult = main.TRUE
2825 failMessage = "Nodes have different leaders"
2826
2827 # Get new leaders and candidates
Jon Halle1a3b752015-07-22 13:02:46 -07002828 for cli in main.CLIs:
acsmars71adceb2015-08-31 15:09:26 -07002829 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
2830 # elections might no have finished yet
2831 if node[ 0 ] == 'none' and not expectNoLeader:
2832 main.log.info( "Node has no leader, waiting 5 seconds to be " +
2833 "sure elections are complete." )
2834 time.sleep(5)
2835 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
2836 # election still isn't done or there is a problem
2837 if node[ 0 ] == 'none':
2838 main.log.error( "No leader was elected on at least 1 node" )
2839 newLeaderResult = main.FALSE
2840 newAllCandidates.append( node )
2841 newLeaders.append( node[ 0 ] )
2842 newCandidates = newAllCandidates[ 0 ]
2843
2844 # Check that each node has the same leader. Defines newLeader
2845 if len( set( newLeaders ) ) != 1:
2846 newLeaderResult = main.FALSE
2847 main.log.error( "Nodes have different leaders: " +
2848 str( newLeaders ) )
2849 newLeader = None
Jon Hall5cf14d52015-07-16 12:15:19 -07002850 else:
acsmars71adceb2015-08-31 15:09:26 -07002851 newLeader = newLeaders[ 0 ]
2852
2853 # Check that each node's candidate list is the same
2854 for candidates in newAllCandidates:
2855 if set( candidates ) != set( newCandidates ):
2856 newLeaderResult = main.FALSE
Jon Hallceb4abb2015-09-25 12:03:06 -07002857 main.log.error( "Discrepancy in candidate lists detected" )
acsmars71adceb2015-08-31 15:09:26 -07002858
2859 # Check that the new leader is not the older leader, which was withdrawn
2860 if newLeader == oldLeader:
2861 newLeaderResult = main.FALSE
2862 main.log.error( "All nodes still see old leader: " + oldLeader +
2863 " as the current leader" )
2864
Jon Hall5cf14d52015-07-16 12:15:19 -07002865 utilities.assert_equals(
2866 expect=main.TRUE,
acsmars71adceb2015-08-31 15:09:26 -07002867 actual=newLeaderResult,
Jon Hall5cf14d52015-07-16 12:15:19 -07002868 onpass="Leadership election passed",
2869 onfail="Something went wrong with Leadership election" )
2870
acsmars71adceb2015-08-31 15:09:26 -07002871 main.step( "Check that that new leader was the candidate of old leader")
2872 # candidates[ 2 ] should be come the top candidate after withdrawl
2873 correctCandidateResult = main.TRUE
2874 if expectNoLeader:
2875 if newLeader == 'none':
2876 main.log.info( "No leader expected. None found. Pass" )
2877 correctCandidateResult = main.TRUE
2878 else:
2879 main.log.info( "Expected no leader, got: " + str( newLeader ) )
2880 correctCandidateResult = main.FALSE
2881 elif newLeader != oldCandidates[ 2 ]:
2882 correctCandidateResult = main.FALSE
2883 main.log.error( "Candidate " + newLeader + " was elected. " +
2884 oldCandidates[ 2 ] + " should have had priority." )
2885
2886 utilities.assert_equals(
2887 expect=main.TRUE,
2888 actual=correctCandidateResult,
2889 onpass="Correct Candidate Elected",
2890 onfail="Incorrect Candidate Elected" )
2891
Jon Hall5cf14d52015-07-16 12:15:19 -07002892 main.step( "Run for election on old leader( just so everyone " +
2893 "is in the hat )" )
acsmars71adceb2015-08-31 15:09:26 -07002894 if oldLeaderCLI is not None:
2895 runResult = oldLeaderCLI.electionTestRun()
Jon Hall5cf14d52015-07-16 12:15:19 -07002896 else:
acsmars71adceb2015-08-31 15:09:26 -07002897 main.log.error( "No old leader to re-elect" )
Jon Hall5cf14d52015-07-16 12:15:19 -07002898 runResult = main.FALSE
2899 utilities.assert_equals(
2900 expect=main.TRUE,
2901 actual=runResult,
2902 onpass="App re-ran for election",
2903 onfail="App failed to run for election" )
acsmars71adceb2015-08-31 15:09:26 -07002904 main.step(
2905 "Check that oldLeader is a candidate, and leader if only 1 node" )
Jon Hall5cf14d52015-07-16 12:15:19 -07002906 # verify leader didn't just change
acsmars71adceb2015-08-31 15:09:26 -07002907 positionResult = main.TRUE
2908 # Get new leaders and candidates, wait if oldLeader is not a candidate yet
2909
2910 # Reset and reuse the new candidate and leaders lists
2911 newAllCandidates = []
2912 newCandidates = []
2913 newLeaders = []
2914 for cli in main.CLIs:
2915 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
2916 if oldLeader not in node: # election might no have finished yet
2917 main.log.info( "Old Leader not elected, waiting 5 seconds to " +
2918 "be sure elections are complete" )
2919 time.sleep(5)
2920 node = cli.specificLeaderCandidate( 'org.onosproject.election' )
2921 if oldLeader not in node: # election still isn't done, errors
2922 main.log.error(
2923 "Old leader was not elected on at least one node" )
2924 positionResult = main.FALSE
2925 newAllCandidates.append( node )
2926 newLeaders.append( node[ 0 ] )
2927 newCandidates = newAllCandidates[ 0 ]
2928
2929 # Check that each node has the same leader. Defines newLeader
2930 if len( set( newLeaders ) ) != 1:
2931 positionResult = main.FALSE
2932 main.log.error( "Nodes have different leaders: " +
2933 str( newLeaders ) )
2934 newLeader = None
Jon Hall5cf14d52015-07-16 12:15:19 -07002935 else:
acsmars71adceb2015-08-31 15:09:26 -07002936 newLeader = newLeaders[ 0 ]
2937
2938 # Check that each node's candidate list is the same
2939 for candidates in newAllCandidates:
2940 if set( candidates ) != set( newCandidates ):
2941 newLeaderResult = main.FALSE
Jon Hallceb4abb2015-09-25 12:03:06 -07002942 main.log.error( "Discrepancy in candidate lists detected" )
acsmars71adceb2015-08-31 15:09:26 -07002943
2944 # Check that the re-elected node is last on the candidate List
2945 if oldLeader != newCandidates[ -1 ]:
2946 main.log.error( "Old Leader (" + oldLeader + ") not in the proper position " +
2947 str( newCandidates ) )
2948 positionResult = main.FALSE
Jon Hall5cf14d52015-07-16 12:15:19 -07002949
2950 utilities.assert_equals(
2951 expect=main.TRUE,
acsmars71adceb2015-08-31 15:09:26 -07002952 actual=positionResult,
Jon Hall5cf14d52015-07-16 12:15:19 -07002953 onpass="Old leader successfully re-ran for election",
2954 onfail="Something went wrong with Leadership election after " +
2955 "the old leader re-ran for election" )
2956
2957 def CASE16( self, main ):
2958 """
2959 Install Distributed Primitives app
2960 """
2961 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002962 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002963 assert main, "main not defined"
2964 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002965 assert main.CLIs, "main.CLIs not defined"
2966 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002967
2968 # Variables for the distributed primitives tests
2969 global pCounterName
2970 global iCounterName
2971 global pCounterValue
2972 global iCounterValue
2973 global onosSet
2974 global onosSetName
2975 pCounterName = "TestON-Partitions"
2976 iCounterName = "TestON-inMemory"
2977 pCounterValue = 0
2978 iCounterValue = 0
2979 onosSet = set([])
2980 onosSetName = "TestON-set"
2981
2982 description = "Install Primitives app"
2983 main.case( description )
2984 main.step( "Install Primitives app" )
2985 appName = "org.onosproject.distributedprimitives"
Jon Halle1a3b752015-07-22 13:02:46 -07002986 appResults = main.CLIs[0].activateApp( appName )
Jon Hall5cf14d52015-07-16 12:15:19 -07002987 utilities.assert_equals( expect=main.TRUE,
2988 actual=appResults,
2989 onpass="Primitives app activated",
2990 onfail="Primitives app not activated" )
2991 time.sleep( 5 ) # To allow all nodes to activate
2992
2993 def CASE17( self, main ):
2994 """
2995 Check for basic functionality with distributed primitives
2996 """
Jon Hall5cf14d52015-07-16 12:15:19 -07002997 # Make sure variables are defined/set
Jon Halle1a3b752015-07-22 13:02:46 -07002998 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07002999 assert main, "main not defined"
3000 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07003001 assert main.CLIs, "main.CLIs not defined"
3002 assert main.nodes, "main.nodes not defined"
Jon Hall5cf14d52015-07-16 12:15:19 -07003003 assert pCounterName, "pCounterName not defined"
3004 assert iCounterName, "iCounterName not defined"
3005 assert onosSetName, "onosSetName not defined"
3006 # NOTE: assert fails if value is 0/None/Empty/False
3007 try:
3008 pCounterValue
3009 except NameError:
3010 main.log.error( "pCounterValue not defined, setting to 0" )
3011 pCounterValue = 0
3012 try:
3013 iCounterValue
3014 except NameError:
3015 main.log.error( "iCounterValue not defined, setting to 0" )
3016 iCounterValue = 0
3017 try:
3018 onosSet
3019 except NameError:
3020 main.log.error( "onosSet not defined, setting to empty Set" )
3021 onosSet = set([])
3022 # Variables for the distributed primitives tests. These are local only
3023 addValue = "a"
3024 addAllValue = "a b c d e f"
3025 retainValue = "c d e f"
3026
3027 description = "Check for basic functionality with distributed " +\
3028 "primitives"
3029 main.case( description )
Jon Halle1a3b752015-07-22 13:02:46 -07003030 main.caseExplanation = "Test the methods of the distributed " +\
3031 "primitives (counters and sets) throught the cli"
Jon Hall5cf14d52015-07-16 12:15:19 -07003032 # DISTRIBUTED ATOMIC COUNTERS
Jon Halle1a3b752015-07-22 13:02:46 -07003033 # Partitioned counters
3034 main.step( "Increment then get a default counter on each node" )
Jon Hall5cf14d52015-07-16 12:15:19 -07003035 pCounters = []
3036 threads = []
3037 addedPValues = []
Jon Halle1a3b752015-07-22 13:02:46 -07003038 for i in range( main.numCtrls ):
3039 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
3040 name="counterAddAndGet-" + str( i ),
Jon Hall5cf14d52015-07-16 12:15:19 -07003041 args=[ pCounterName ] )
3042 pCounterValue += 1
3043 addedPValues.append( pCounterValue )
3044 threads.append( t )
3045 t.start()
3046
3047 for t in threads:
3048 t.join()
3049 pCounters.append( t.result )
3050 # Check that counter incremented numController times
3051 pCounterResults = True
3052 for i in addedPValues:
3053 tmpResult = i in pCounters
3054 pCounterResults = pCounterResults and tmpResult
3055 if not tmpResult:
3056 main.log.error( str( i ) + " is not in partitioned "
3057 "counter incremented results" )
3058 utilities.assert_equals( expect=True,
3059 actual=pCounterResults,
3060 onpass="Default counter incremented",
3061 onfail="Error incrementing default" +
3062 " counter" )
3063
Jon Halle1a3b752015-07-22 13:02:46 -07003064 main.step( "Get then Increment a default counter on each node" )
3065 pCounters = []
3066 threads = []
3067 addedPValues = []
3068 for i in range( main.numCtrls ):
3069 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
3070 name="counterGetAndAdd-" + str( i ),
3071 args=[ pCounterName ] )
3072 addedPValues.append( pCounterValue )
3073 pCounterValue += 1
3074 threads.append( t )
3075 t.start()
3076
3077 for t in threads:
3078 t.join()
3079 pCounters.append( t.result )
3080 # Check that counter incremented numController times
3081 pCounterResults = True
3082 for i in addedPValues:
3083 tmpResult = i in pCounters
3084 pCounterResults = pCounterResults and tmpResult
3085 if not tmpResult:
3086 main.log.error( str( i ) + " is not in partitioned "
3087 "counter incremented results" )
3088 utilities.assert_equals( expect=True,
3089 actual=pCounterResults,
3090 onpass="Default counter incremented",
3091 onfail="Error incrementing default" +
3092 " counter" )
3093
3094 main.step( "Counters we added have the correct values" )
3095 incrementCheck = main.Counters.counterCheck( pCounterName, pCounterValue )
3096 utilities.assert_equals( expect=main.TRUE,
3097 actual=incrementCheck,
3098 onpass="Added counters are correct",
3099 onfail="Added counters are incorrect" )
3100
3101 main.step( "Add -8 to then get a default counter on each node" )
3102 pCounters = []
3103 threads = []
3104 addedPValues = []
3105 for i in range( main.numCtrls ):
3106 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
3107 name="counterIncrement-" + str( i ),
3108 args=[ pCounterName ],
3109 kwargs={ "delta": -8 } )
3110 pCounterValue += -8
3111 addedPValues.append( pCounterValue )
3112 threads.append( t )
3113 t.start()
3114
3115 for t in threads:
3116 t.join()
3117 pCounters.append( t.result )
3118 # Check that counter incremented numController times
3119 pCounterResults = True
3120 for i in addedPValues:
3121 tmpResult = i in pCounters
3122 pCounterResults = pCounterResults and tmpResult
3123 if not tmpResult:
3124 main.log.error( str( i ) + " is not in partitioned "
3125 "counter incremented results" )
3126 utilities.assert_equals( expect=True,
3127 actual=pCounterResults,
3128 onpass="Default counter incremented",
3129 onfail="Error incrementing default" +
3130 " counter" )
3131
3132 main.step( "Add 5 to then get a default counter on each node" )
3133 pCounters = []
3134 threads = []
3135 addedPValues = []
3136 for i in range( main.numCtrls ):
3137 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
3138 name="counterIncrement-" + str( i ),
3139 args=[ pCounterName ],
3140 kwargs={ "delta": 5 } )
3141 pCounterValue += 5
3142 addedPValues.append( pCounterValue )
3143 threads.append( t )
3144 t.start()
3145
3146 for t in threads:
3147 t.join()
3148 pCounters.append( t.result )
3149 # Check that counter incremented numController times
3150 pCounterResults = True
3151 for i in addedPValues:
3152 tmpResult = i in pCounters
3153 pCounterResults = pCounterResults and tmpResult
3154 if not tmpResult:
3155 main.log.error( str( i ) + " is not in partitioned "
3156 "counter incremented results" )
3157 utilities.assert_equals( expect=True,
3158 actual=pCounterResults,
3159 onpass="Default counter incremented",
3160 onfail="Error incrementing default" +
3161 " counter" )
3162
3163 main.step( "Get then add 5 to a default counter on each node" )
3164 pCounters = []
3165 threads = []
3166 addedPValues = []
3167 for i in range( main.numCtrls ):
3168 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
3169 name="counterIncrement-" + str( i ),
3170 args=[ pCounterName ],
3171 kwargs={ "delta": 5 } )
3172 addedPValues.append( pCounterValue )
3173 pCounterValue += 5
3174 threads.append( t )
3175 t.start()
3176
3177 for t in threads:
3178 t.join()
3179 pCounters.append( t.result )
3180 # Check that counter incremented numController times
3181 pCounterResults = True
3182 for i in addedPValues:
3183 tmpResult = i in pCounters
3184 pCounterResults = pCounterResults and tmpResult
3185 if not tmpResult:
3186 main.log.error( str( i ) + " is not in partitioned "
3187 "counter incremented results" )
3188 utilities.assert_equals( expect=True,
3189 actual=pCounterResults,
3190 onpass="Default counter incremented",
3191 onfail="Error incrementing default" +
3192 " counter" )
3193
3194 main.step( "Counters we added have the correct values" )
3195 incrementCheck = main.Counters.counterCheck( pCounterName, pCounterValue )
3196 utilities.assert_equals( expect=main.TRUE,
3197 actual=incrementCheck,
3198 onpass="Added counters are correct",
3199 onfail="Added counters are incorrect" )
3200
3201 # In-Memory counters
3202 main.step( "Increment and get an in-memory counter on each node" )
Jon Hall5cf14d52015-07-16 12:15:19 -07003203 iCounters = []
3204 addedIValues = []
3205 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003206 for i in range( main.numCtrls ):
3207 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003208 name="icounterIncrement-" + str( i ),
3209 args=[ iCounterName ],
3210 kwargs={ "inMemory": True } )
3211 iCounterValue += 1
3212 addedIValues.append( iCounterValue )
3213 threads.append( t )
3214 t.start()
3215
3216 for t in threads:
3217 t.join()
3218 iCounters.append( t.result )
3219 # Check that counter incremented numController times
3220 iCounterResults = True
3221 for i in addedIValues:
3222 tmpResult = i in iCounters
3223 iCounterResults = iCounterResults and tmpResult
3224 if not tmpResult:
3225 main.log.error( str( i ) + " is not in the in-memory "
3226 "counter incremented results" )
3227 utilities.assert_equals( expect=True,
3228 actual=iCounterResults,
Jon Halle1a3b752015-07-22 13:02:46 -07003229 onpass="In-memory counter incremented",
3230 onfail="Error incrementing in-memory" +
Jon Hall5cf14d52015-07-16 12:15:19 -07003231 " counter" )
3232
Jon Halle1a3b752015-07-22 13:02:46 -07003233 main.step( "Get then Increment a in-memory counter on each node" )
3234 iCounters = []
3235 threads = []
3236 addedIValues = []
3237 for i in range( main.numCtrls ):
3238 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
3239 name="counterGetAndAdd-" + str( i ),
3240 args=[ iCounterName ],
3241 kwargs={ "inMemory": True } )
3242 addedIValues.append( iCounterValue )
3243 iCounterValue += 1
3244 threads.append( t )
3245 t.start()
3246
3247 for t in threads:
3248 t.join()
3249 iCounters.append( t.result )
3250 # Check that counter incremented numController times
3251 iCounterResults = True
3252 for i in addedIValues:
3253 tmpResult = i in iCounters
3254 iCounterResults = iCounterResults and tmpResult
3255 if not tmpResult:
3256 main.log.error( str( i ) + " is not in in-memory "
3257 "counter incremented results" )
3258 utilities.assert_equals( expect=True,
3259 actual=iCounterResults,
3260 onpass="In-memory counter incremented",
3261 onfail="Error incrementing in-memory" +
3262 " counter" )
3263
3264 main.step( "Counters we added have the correct values" )
3265 incrementCheck = main.Counters.counterCheck( iCounterName, iCounterValue )
3266 utilities.assert_equals( expect=main.TRUE,
3267 actual=incrementCheck,
3268 onpass="Added counters are correct",
3269 onfail="Added counters are incorrect" )
3270
3271 main.step( "Add -8 to then get a in-memory counter on each node" )
3272 iCounters = []
3273 threads = []
3274 addedIValues = []
3275 for i in range( main.numCtrls ):
3276 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
3277 name="counterIncrement-" + str( i ),
3278 args=[ iCounterName ],
3279 kwargs={ "delta": -8, "inMemory": True } )
3280 iCounterValue += -8
3281 addedIValues.append( iCounterValue )
3282 threads.append( t )
3283 t.start()
3284
3285 for t in threads:
3286 t.join()
3287 iCounters.append( t.result )
3288 # Check that counter incremented numController times
3289 iCounterResults = True
3290 for i in addedIValues:
3291 tmpResult = i in iCounters
3292 iCounterResults = iCounterResults and tmpResult
3293 if not tmpResult:
3294 main.log.error( str( i ) + " is not in in-memory "
3295 "counter incremented results" )
3296 utilities.assert_equals( expect=True,
3297 actual=pCounterResults,
3298 onpass="In-memory counter incremented",
3299 onfail="Error incrementing in-memory" +
3300 " counter" )
3301
3302 main.step( "Add 5 to then get a in-memory counter on each node" )
3303 iCounters = []
3304 threads = []
3305 addedIValues = []
3306 for i in range( main.numCtrls ):
3307 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
3308 name="counterIncrement-" + str( i ),
3309 args=[ iCounterName ],
3310 kwargs={ "delta": 5, "inMemory": True } )
3311 iCounterValue += 5
3312 addedIValues.append( iCounterValue )
3313 threads.append( t )
3314 t.start()
3315
3316 for t in threads:
3317 t.join()
3318 iCounters.append( t.result )
3319 # Check that counter incremented numController times
3320 iCounterResults = True
3321 for i in addedIValues:
3322 tmpResult = i in iCounters
3323 iCounterResults = iCounterResults and tmpResult
3324 if not tmpResult:
3325 main.log.error( str( i ) + " is not in in-memory "
3326 "counter incremented results" )
3327 utilities.assert_equals( expect=True,
3328 actual=pCounterResults,
3329 onpass="In-memory counter incremented",
3330 onfail="Error incrementing in-memory" +
3331 " counter" )
3332
3333 main.step( "Get then add 5 to a in-memory counter on each node" )
3334 iCounters = []
3335 threads = []
3336 addedIValues = []
3337 for i in range( main.numCtrls ):
3338 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
3339 name="counterIncrement-" + str( i ),
3340 args=[ iCounterName ],
3341 kwargs={ "delta": 5, "inMemory": True } )
3342 addedIValues.append( iCounterValue )
3343 iCounterValue += 5
3344 threads.append( t )
3345 t.start()
3346
3347 for t in threads:
3348 t.join()
3349 iCounters.append( t.result )
3350 # Check that counter incremented numController times
3351 iCounterResults = True
3352 for i in addedIValues:
3353 tmpResult = i in iCounters
3354 iCounterResults = iCounterResults and tmpResult
3355 if not tmpResult:
3356 main.log.error( str( i ) + " is not in in-memory "
3357 "counter incremented results" )
3358 utilities.assert_equals( expect=True,
3359 actual=iCounterResults,
3360 onpass="In-memory counter incremented",
3361 onfail="Error incrementing in-memory" +
3362 " counter" )
3363
3364 main.step( "Counters we added have the correct values" )
3365 incrementCheck = main.Counters.counterCheck( iCounterName, iCounterValue )
3366 utilities.assert_equals( expect=main.TRUE,
3367 actual=incrementCheck,
3368 onpass="Added counters are correct",
3369 onfail="Added counters are incorrect" )
3370
Jon Hall5cf14d52015-07-16 12:15:19 -07003371 main.step( "Check counters are consistant across nodes" )
Jon Hall57b50432015-10-22 10:20:10 -07003372 onosCounters, consistentCounterResults = main.Counters.consistentCheck()
Jon Hall5cf14d52015-07-16 12:15:19 -07003373 utilities.assert_equals( expect=main.TRUE,
3374 actual=consistentCounterResults,
3375 onpass="ONOS counters are consistent " +
3376 "across nodes",
3377 onfail="ONOS Counters are inconsistent " +
3378 "across nodes" )
3379
3380 main.step( "Counters we added have the correct values" )
Jon Halle1a3b752015-07-22 13:02:46 -07003381 incrementCheck = main.Counters.counterCheck( iCounterName, iCounterValue )
3382 incrementCheck = incrementCheck and \
3383 main.Counters.counterCheck( iCounterName, iCounterValue )
Jon Hall5cf14d52015-07-16 12:15:19 -07003384 utilities.assert_equals( expect=main.TRUE,
Jon Halle1a3b752015-07-22 13:02:46 -07003385 actual=incrementCheck,
Jon Hall5cf14d52015-07-16 12:15:19 -07003386 onpass="Added counters are correct",
3387 onfail="Added counters are incorrect" )
3388 # DISTRIBUTED SETS
3389 main.step( "Distributed Set get" )
3390 size = len( onosSet )
3391 getResponses = []
3392 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003393 for i in range( main.numCtrls ):
3394 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003395 name="setTestGet-" + str( i ),
3396 args=[ onosSetName ] )
3397 threads.append( t )
3398 t.start()
3399 for t in threads:
3400 t.join()
3401 getResponses.append( t.result )
3402
3403 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003404 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003405 if isinstance( getResponses[ i ], list):
3406 current = set( getResponses[ i ] )
3407 if len( current ) == len( getResponses[ i ] ):
3408 # no repeats
3409 if onosSet != current:
3410 main.log.error( "ONOS" + str( i + 1 ) +
3411 " has incorrect view" +
3412 " of set " + onosSetName + ":\n" +
3413 str( getResponses[ i ] ) )
3414 main.log.debug( "Expected: " + str( onosSet ) )
3415 main.log.debug( "Actual: " + str( current ) )
3416 getResults = main.FALSE
3417 else:
3418 # error, set is not a set
3419 main.log.error( "ONOS" + str( i + 1 ) +
3420 " has repeat elements in" +
3421 " set " + onosSetName + ":\n" +
3422 str( getResponses[ i ] ) )
3423 getResults = main.FALSE
3424 elif getResponses[ i ] == main.ERROR:
3425 getResults = main.FALSE
3426 utilities.assert_equals( expect=main.TRUE,
3427 actual=getResults,
3428 onpass="Set elements are correct",
3429 onfail="Set elements are incorrect" )
3430
3431 main.step( "Distributed Set size" )
3432 sizeResponses = []
3433 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003434 for i in range( main.numCtrls ):
3435 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003436 name="setTestSize-" + str( i ),
3437 args=[ onosSetName ] )
3438 threads.append( t )
3439 t.start()
3440 for t in threads:
3441 t.join()
3442 sizeResponses.append( t.result )
3443
3444 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003445 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003446 if size != sizeResponses[ i ]:
3447 sizeResults = main.FALSE
3448 main.log.error( "ONOS" + str( i + 1 ) +
3449 " expected a size of " + str( size ) +
3450 " for set " + onosSetName +
3451 " but got " + str( sizeResponses[ i ] ) )
3452 utilities.assert_equals( expect=main.TRUE,
3453 actual=sizeResults,
3454 onpass="Set sizes are correct",
3455 onfail="Set sizes are incorrect" )
3456
3457 main.step( "Distributed Set add()" )
3458 onosSet.add( addValue )
3459 addResponses = []
3460 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003461 for i in range( main.numCtrls ):
3462 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall5cf14d52015-07-16 12:15:19 -07003463 name="setTestAdd-" + str( i ),
3464 args=[ onosSetName, addValue ] )
3465 threads.append( t )
3466 t.start()
3467 for t in threads:
3468 t.join()
3469 addResponses.append( t.result )
3470
3471 # main.TRUE = successfully changed the set
3472 # main.FALSE = action resulted in no change in set
3473 # main.ERROR - Some error in executing the function
3474 addResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003475 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003476 if addResponses[ i ] == main.TRUE:
3477 # All is well
3478 pass
3479 elif addResponses[ i ] == main.FALSE:
3480 # Already in set, probably fine
3481 pass
3482 elif addResponses[ i ] == main.ERROR:
3483 # Error in execution
3484 addResults = main.FALSE
3485 else:
3486 # unexpected result
3487 addResults = main.FALSE
3488 if addResults != main.TRUE:
3489 main.log.error( "Error executing set add" )
3490
3491 # Check if set is still correct
3492 size = len( onosSet )
3493 getResponses = []
3494 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003495 for i in range( main.numCtrls ):
3496 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003497 name="setTestGet-" + str( i ),
3498 args=[ onosSetName ] )
3499 threads.append( t )
3500 t.start()
3501 for t in threads:
3502 t.join()
3503 getResponses.append( t.result )
3504 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003505 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003506 if isinstance( getResponses[ i ], list):
3507 current = set( getResponses[ i ] )
3508 if len( current ) == len( getResponses[ i ] ):
3509 # no repeats
3510 if onosSet != current:
3511 main.log.error( "ONOS" + str( i + 1 ) +
3512 " has incorrect view" +
3513 " of set " + onosSetName + ":\n" +
3514 str( getResponses[ i ] ) )
3515 main.log.debug( "Expected: " + str( onosSet ) )
3516 main.log.debug( "Actual: " + str( current ) )
3517 getResults = main.FALSE
3518 else:
3519 # error, set is not a set
3520 main.log.error( "ONOS" + str( i + 1 ) +
3521 " has repeat elements in" +
3522 " set " + onosSetName + ":\n" +
3523 str( getResponses[ i ] ) )
3524 getResults = main.FALSE
3525 elif getResponses[ i ] == main.ERROR:
3526 getResults = main.FALSE
3527 sizeResponses = []
3528 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003529 for i in range( main.numCtrls ):
3530 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003531 name="setTestSize-" + str( i ),
3532 args=[ onosSetName ] )
3533 threads.append( t )
3534 t.start()
3535 for t in threads:
3536 t.join()
3537 sizeResponses.append( t.result )
3538 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003539 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003540 if size != sizeResponses[ i ]:
3541 sizeResults = main.FALSE
3542 main.log.error( "ONOS" + str( i + 1 ) +
3543 " expected a size of " + str( size ) +
3544 " for set " + onosSetName +
3545 " but got " + str( sizeResponses[ i ] ) )
3546 addResults = addResults and getResults and sizeResults
3547 utilities.assert_equals( expect=main.TRUE,
3548 actual=addResults,
3549 onpass="Set add correct",
3550 onfail="Set add was incorrect" )
3551
3552 main.step( "Distributed Set addAll()" )
3553 onosSet.update( addAllValue.split() )
3554 addResponses = []
3555 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003556 for i in range( main.numCtrls ):
3557 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall5cf14d52015-07-16 12:15:19 -07003558 name="setTestAddAll-" + str( i ),
3559 args=[ onosSetName, addAllValue ] )
3560 threads.append( t )
3561 t.start()
3562 for t in threads:
3563 t.join()
3564 addResponses.append( t.result )
3565
3566 # main.TRUE = successfully changed the set
3567 # main.FALSE = action resulted in no change in set
3568 # main.ERROR - Some error in executing the function
3569 addAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003570 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003571 if addResponses[ i ] == main.TRUE:
3572 # All is well
3573 pass
3574 elif addResponses[ i ] == main.FALSE:
3575 # Already in set, probably fine
3576 pass
3577 elif addResponses[ i ] == main.ERROR:
3578 # Error in execution
3579 addAllResults = main.FALSE
3580 else:
3581 # unexpected result
3582 addAllResults = main.FALSE
3583 if addAllResults != main.TRUE:
3584 main.log.error( "Error executing set addAll" )
3585
3586 # Check if set is still correct
3587 size = len( onosSet )
3588 getResponses = []
3589 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003590 for i in range( main.numCtrls ):
3591 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003592 name="setTestGet-" + str( i ),
3593 args=[ onosSetName ] )
3594 threads.append( t )
3595 t.start()
3596 for t in threads:
3597 t.join()
3598 getResponses.append( t.result )
3599 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003600 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003601 if isinstance( getResponses[ i ], list):
3602 current = set( getResponses[ i ] )
3603 if len( current ) == len( getResponses[ i ] ):
3604 # no repeats
3605 if onosSet != current:
3606 main.log.error( "ONOS" + str( i + 1 ) +
3607 " has incorrect view" +
3608 " of set " + onosSetName + ":\n" +
3609 str( getResponses[ i ] ) )
3610 main.log.debug( "Expected: " + str( onosSet ) )
3611 main.log.debug( "Actual: " + str( current ) )
3612 getResults = main.FALSE
3613 else:
3614 # error, set is not a set
3615 main.log.error( "ONOS" + str( i + 1 ) +
3616 " has repeat elements in" +
3617 " set " + onosSetName + ":\n" +
3618 str( getResponses[ i ] ) )
3619 getResults = main.FALSE
3620 elif getResponses[ i ] == main.ERROR:
3621 getResults = main.FALSE
3622 sizeResponses = []
3623 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003624 for i in range( main.numCtrls ):
3625 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003626 name="setTestSize-" + str( i ),
3627 args=[ onosSetName ] )
3628 threads.append( t )
3629 t.start()
3630 for t in threads:
3631 t.join()
3632 sizeResponses.append( t.result )
3633 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003634 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003635 if size != sizeResponses[ i ]:
3636 sizeResults = main.FALSE
3637 main.log.error( "ONOS" + str( i + 1 ) +
3638 " expected a size of " + str( size ) +
3639 " for set " + onosSetName +
3640 " but got " + str( sizeResponses[ i ] ) )
3641 addAllResults = addAllResults and getResults and sizeResults
3642 utilities.assert_equals( expect=main.TRUE,
3643 actual=addAllResults,
3644 onpass="Set addAll correct",
3645 onfail="Set addAll was incorrect" )
3646
3647 main.step( "Distributed Set contains()" )
3648 containsResponses = []
3649 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003650 for i in range( main.numCtrls ):
3651 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003652 name="setContains-" + str( i ),
3653 args=[ onosSetName ],
3654 kwargs={ "values": addValue } )
3655 threads.append( t )
3656 t.start()
3657 for t in threads:
3658 t.join()
3659 # NOTE: This is the tuple
3660 containsResponses.append( t.result )
3661
3662 containsResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003663 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003664 if containsResponses[ i ] == main.ERROR:
3665 containsResults = main.FALSE
3666 else:
3667 containsResults = containsResults and\
3668 containsResponses[ i ][ 1 ]
3669 utilities.assert_equals( expect=main.TRUE,
3670 actual=containsResults,
3671 onpass="Set contains is functional",
3672 onfail="Set contains failed" )
3673
3674 main.step( "Distributed Set containsAll()" )
3675 containsAllResponses = []
3676 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003677 for i in range( main.numCtrls ):
3678 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003679 name="setContainsAll-" + str( i ),
3680 args=[ onosSetName ],
3681 kwargs={ "values": addAllValue } )
3682 threads.append( t )
3683 t.start()
3684 for t in threads:
3685 t.join()
3686 # NOTE: This is the tuple
3687 containsAllResponses.append( t.result )
3688
3689 containsAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003690 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003691 if containsResponses[ i ] == main.ERROR:
3692 containsResults = main.FALSE
3693 else:
3694 containsResults = containsResults and\
3695 containsResponses[ i ][ 1 ]
3696 utilities.assert_equals( expect=main.TRUE,
3697 actual=containsAllResults,
3698 onpass="Set containsAll is functional",
3699 onfail="Set containsAll failed" )
3700
3701 main.step( "Distributed Set remove()" )
3702 onosSet.remove( addValue )
3703 removeResponses = []
3704 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003705 for i in range( main.numCtrls ):
3706 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall5cf14d52015-07-16 12:15:19 -07003707 name="setTestRemove-" + str( i ),
3708 args=[ onosSetName, addValue ] )
3709 threads.append( t )
3710 t.start()
3711 for t in threads:
3712 t.join()
3713 removeResponses.append( t.result )
3714
3715 # main.TRUE = successfully changed the set
3716 # main.FALSE = action resulted in no change in set
3717 # main.ERROR - Some error in executing the function
3718 removeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003719 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003720 if removeResponses[ i ] == main.TRUE:
3721 # All is well
3722 pass
3723 elif removeResponses[ i ] == main.FALSE:
3724 # not in set, probably fine
3725 pass
3726 elif removeResponses[ i ] == main.ERROR:
3727 # Error in execution
3728 removeResults = main.FALSE
3729 else:
3730 # unexpected result
3731 removeResults = main.FALSE
3732 if removeResults != main.TRUE:
3733 main.log.error( "Error executing set remove" )
3734
3735 # Check if set is still correct
3736 size = len( onosSet )
3737 getResponses = []
3738 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003739 for i in range( main.numCtrls ):
3740 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003741 name="setTestGet-" + str( i ),
3742 args=[ onosSetName ] )
3743 threads.append( t )
3744 t.start()
3745 for t in threads:
3746 t.join()
3747 getResponses.append( t.result )
3748 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003749 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003750 if isinstance( getResponses[ i ], list):
3751 current = set( getResponses[ i ] )
3752 if len( current ) == len( getResponses[ i ] ):
3753 # no repeats
3754 if onosSet != current:
3755 main.log.error( "ONOS" + str( i + 1 ) +
3756 " has incorrect view" +
3757 " of set " + onosSetName + ":\n" +
3758 str( getResponses[ i ] ) )
3759 main.log.debug( "Expected: " + str( onosSet ) )
3760 main.log.debug( "Actual: " + str( current ) )
3761 getResults = main.FALSE
3762 else:
3763 # error, set is not a set
3764 main.log.error( "ONOS" + str( i + 1 ) +
3765 " has repeat elements in" +
3766 " set " + onosSetName + ":\n" +
3767 str( getResponses[ i ] ) )
3768 getResults = main.FALSE
3769 elif getResponses[ i ] == main.ERROR:
3770 getResults = main.FALSE
3771 sizeResponses = []
3772 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003773 for i in range( main.numCtrls ):
3774 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003775 name="setTestSize-" + str( i ),
3776 args=[ onosSetName ] )
3777 threads.append( t )
3778 t.start()
3779 for t in threads:
3780 t.join()
3781 sizeResponses.append( t.result )
3782 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003783 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003784 if size != sizeResponses[ i ]:
3785 sizeResults = main.FALSE
3786 main.log.error( "ONOS" + str( i + 1 ) +
3787 " expected a size of " + str( size ) +
3788 " for set " + onosSetName +
3789 " but got " + str( sizeResponses[ i ] ) )
3790 removeResults = removeResults and getResults and sizeResults
3791 utilities.assert_equals( expect=main.TRUE,
3792 actual=removeResults,
3793 onpass="Set remove correct",
3794 onfail="Set remove was incorrect" )
3795
3796 main.step( "Distributed Set removeAll()" )
3797 onosSet.difference_update( addAllValue.split() )
3798 removeAllResponses = []
3799 threads = []
3800 try:
Jon Halle1a3b752015-07-22 13:02:46 -07003801 for i in range( main.numCtrls ):
3802 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall5cf14d52015-07-16 12:15:19 -07003803 name="setTestRemoveAll-" + str( i ),
3804 args=[ onosSetName, addAllValue ] )
3805 threads.append( t )
3806 t.start()
3807 for t in threads:
3808 t.join()
3809 removeAllResponses.append( t.result )
3810 except Exception, e:
3811 main.log.exception(e)
3812
3813 # main.TRUE = successfully changed the set
3814 # main.FALSE = action resulted in no change in set
3815 # main.ERROR - Some error in executing the function
3816 removeAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003817 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003818 if removeAllResponses[ i ] == main.TRUE:
3819 # All is well
3820 pass
3821 elif removeAllResponses[ i ] == main.FALSE:
3822 # not in set, probably fine
3823 pass
3824 elif removeAllResponses[ i ] == main.ERROR:
3825 # Error in execution
3826 removeAllResults = main.FALSE
3827 else:
3828 # unexpected result
3829 removeAllResults = main.FALSE
3830 if removeAllResults != main.TRUE:
3831 main.log.error( "Error executing set removeAll" )
3832
3833 # Check if set is still correct
3834 size = len( onosSet )
3835 getResponses = []
3836 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003837 for i in range( main.numCtrls ):
3838 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003839 name="setTestGet-" + str( i ),
3840 args=[ onosSetName ] )
3841 threads.append( t )
3842 t.start()
3843 for t in threads:
3844 t.join()
3845 getResponses.append( t.result )
3846 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003847 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003848 if isinstance( getResponses[ i ], list):
3849 current = set( getResponses[ i ] )
3850 if len( current ) == len( getResponses[ i ] ):
3851 # no repeats
3852 if onosSet != current:
3853 main.log.error( "ONOS" + str( i + 1 ) +
3854 " has incorrect view" +
3855 " of set " + onosSetName + ":\n" +
3856 str( getResponses[ i ] ) )
3857 main.log.debug( "Expected: " + str( onosSet ) )
3858 main.log.debug( "Actual: " + str( current ) )
3859 getResults = main.FALSE
3860 else:
3861 # error, set is not a set
3862 main.log.error( "ONOS" + str( i + 1 ) +
3863 " has repeat elements in" +
3864 " set " + onosSetName + ":\n" +
3865 str( getResponses[ i ] ) )
3866 getResults = main.FALSE
3867 elif getResponses[ i ] == main.ERROR:
3868 getResults = main.FALSE
3869 sizeResponses = []
3870 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003871 for i in range( main.numCtrls ):
3872 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003873 name="setTestSize-" + str( i ),
3874 args=[ onosSetName ] )
3875 threads.append( t )
3876 t.start()
3877 for t in threads:
3878 t.join()
3879 sizeResponses.append( t.result )
3880 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003881 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003882 if size != sizeResponses[ i ]:
3883 sizeResults = main.FALSE
3884 main.log.error( "ONOS" + str( i + 1 ) +
3885 " expected a size of " + str( size ) +
3886 " for set " + onosSetName +
3887 " but got " + str( sizeResponses[ i ] ) )
3888 removeAllResults = removeAllResults and getResults and sizeResults
3889 utilities.assert_equals( expect=main.TRUE,
3890 actual=removeAllResults,
3891 onpass="Set removeAll correct",
3892 onfail="Set removeAll was incorrect" )
3893
3894 main.step( "Distributed Set addAll()" )
3895 onosSet.update( addAllValue.split() )
3896 addResponses = []
3897 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003898 for i in range( main.numCtrls ):
3899 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall5cf14d52015-07-16 12:15:19 -07003900 name="setTestAddAll-" + str( i ),
3901 args=[ onosSetName, addAllValue ] )
3902 threads.append( t )
3903 t.start()
3904 for t in threads:
3905 t.join()
3906 addResponses.append( t.result )
3907
3908 # main.TRUE = successfully changed the set
3909 # main.FALSE = action resulted in no change in set
3910 # main.ERROR - Some error in executing the function
3911 addAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003912 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003913 if addResponses[ i ] == main.TRUE:
3914 # All is well
3915 pass
3916 elif addResponses[ i ] == main.FALSE:
3917 # Already in set, probably fine
3918 pass
3919 elif addResponses[ i ] == main.ERROR:
3920 # Error in execution
3921 addAllResults = main.FALSE
3922 else:
3923 # unexpected result
3924 addAllResults = main.FALSE
3925 if addAllResults != main.TRUE:
3926 main.log.error( "Error executing set addAll" )
3927
3928 # Check if set is still correct
3929 size = len( onosSet )
3930 getResponses = []
3931 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003932 for i in range( main.numCtrls ):
3933 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07003934 name="setTestGet-" + str( i ),
3935 args=[ onosSetName ] )
3936 threads.append( t )
3937 t.start()
3938 for t in threads:
3939 t.join()
3940 getResponses.append( t.result )
3941 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003942 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003943 if isinstance( getResponses[ i ], list):
3944 current = set( getResponses[ i ] )
3945 if len( current ) == len( getResponses[ i ] ):
3946 # no repeats
3947 if onosSet != current:
3948 main.log.error( "ONOS" + str( i + 1 ) +
3949 " has incorrect view" +
3950 " of set " + onosSetName + ":\n" +
3951 str( getResponses[ i ] ) )
3952 main.log.debug( "Expected: " + str( onosSet ) )
3953 main.log.debug( "Actual: " + str( current ) )
3954 getResults = main.FALSE
3955 else:
3956 # error, set is not a set
3957 main.log.error( "ONOS" + str( i + 1 ) +
3958 " has repeat elements in" +
3959 " set " + onosSetName + ":\n" +
3960 str( getResponses[ i ] ) )
3961 getResults = main.FALSE
3962 elif getResponses[ i ] == main.ERROR:
3963 getResults = main.FALSE
3964 sizeResponses = []
3965 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003966 for i in range( main.numCtrls ):
3967 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07003968 name="setTestSize-" + str( i ),
3969 args=[ onosSetName ] )
3970 threads.append( t )
3971 t.start()
3972 for t in threads:
3973 t.join()
3974 sizeResponses.append( t.result )
3975 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07003976 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07003977 if size != sizeResponses[ i ]:
3978 sizeResults = main.FALSE
3979 main.log.error( "ONOS" + str( i + 1 ) +
3980 " expected a size of " + str( size ) +
3981 " for set " + onosSetName +
3982 " but got " + str( sizeResponses[ i ] ) )
3983 addAllResults = addAllResults and getResults and sizeResults
3984 utilities.assert_equals( expect=main.TRUE,
3985 actual=addAllResults,
3986 onpass="Set addAll correct",
3987 onfail="Set addAll was incorrect" )
3988
3989 main.step( "Distributed Set clear()" )
3990 onosSet.clear()
3991 clearResponses = []
3992 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07003993 for i in range( main.numCtrls ):
3994 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall5cf14d52015-07-16 12:15:19 -07003995 name="setTestClear-" + str( i ),
3996 args=[ onosSetName, " "], # Values doesn't matter
3997 kwargs={ "clear": True } )
3998 threads.append( t )
3999 t.start()
4000 for t in threads:
4001 t.join()
4002 clearResponses.append( t.result )
4003
4004 # main.TRUE = successfully changed the set
4005 # main.FALSE = action resulted in no change in set
4006 # main.ERROR - Some error in executing the function
4007 clearResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004008 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004009 if clearResponses[ i ] == main.TRUE:
4010 # All is well
4011 pass
4012 elif clearResponses[ i ] == main.FALSE:
4013 # Nothing set, probably fine
4014 pass
4015 elif clearResponses[ i ] == main.ERROR:
4016 # Error in execution
4017 clearResults = main.FALSE
4018 else:
4019 # unexpected result
4020 clearResults = main.FALSE
4021 if clearResults != main.TRUE:
4022 main.log.error( "Error executing set clear" )
4023
4024 # Check if set is still correct
4025 size = len( onosSet )
4026 getResponses = []
4027 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004028 for i in range( main.numCtrls ):
4029 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07004030 name="setTestGet-" + str( i ),
4031 args=[ onosSetName ] )
4032 threads.append( t )
4033 t.start()
4034 for t in threads:
4035 t.join()
4036 getResponses.append( t.result )
4037 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004038 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004039 if isinstance( getResponses[ i ], list):
4040 current = set( getResponses[ i ] )
4041 if len( current ) == len( getResponses[ i ] ):
4042 # no repeats
4043 if onosSet != current:
4044 main.log.error( "ONOS" + str( i + 1 ) +
4045 " has incorrect view" +
4046 " of set " + onosSetName + ":\n" +
4047 str( getResponses[ i ] ) )
4048 main.log.debug( "Expected: " + str( onosSet ) )
4049 main.log.debug( "Actual: " + str( current ) )
4050 getResults = main.FALSE
4051 else:
4052 # error, set is not a set
4053 main.log.error( "ONOS" + str( i + 1 ) +
4054 " has repeat elements in" +
4055 " set " + onosSetName + ":\n" +
4056 str( getResponses[ i ] ) )
4057 getResults = main.FALSE
4058 elif getResponses[ i ] == main.ERROR:
4059 getResults = main.FALSE
4060 sizeResponses = []
4061 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004062 for i in range( main.numCtrls ):
4063 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07004064 name="setTestSize-" + str( i ),
4065 args=[ onosSetName ] )
4066 threads.append( t )
4067 t.start()
4068 for t in threads:
4069 t.join()
4070 sizeResponses.append( t.result )
4071 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004072 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004073 if size != sizeResponses[ i ]:
4074 sizeResults = main.FALSE
4075 main.log.error( "ONOS" + str( i + 1 ) +
4076 " expected a size of " + str( size ) +
4077 " for set " + onosSetName +
4078 " but got " + str( sizeResponses[ i ] ) )
4079 clearResults = clearResults and getResults and sizeResults
4080 utilities.assert_equals( expect=main.TRUE,
4081 actual=clearResults,
4082 onpass="Set clear correct",
4083 onfail="Set clear was incorrect" )
4084
4085 main.step( "Distributed Set addAll()" )
4086 onosSet.update( addAllValue.split() )
4087 addResponses = []
4088 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004089 for i in range( main.numCtrls ):
4090 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall5cf14d52015-07-16 12:15:19 -07004091 name="setTestAddAll-" + str( i ),
4092 args=[ onosSetName, addAllValue ] )
4093 threads.append( t )
4094 t.start()
4095 for t in threads:
4096 t.join()
4097 addResponses.append( t.result )
4098
4099 # main.TRUE = successfully changed the set
4100 # main.FALSE = action resulted in no change in set
4101 # main.ERROR - Some error in executing the function
4102 addAllResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004103 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004104 if addResponses[ i ] == main.TRUE:
4105 # All is well
4106 pass
4107 elif addResponses[ i ] == main.FALSE:
4108 # Already in set, probably fine
4109 pass
4110 elif addResponses[ i ] == main.ERROR:
4111 # Error in execution
4112 addAllResults = main.FALSE
4113 else:
4114 # unexpected result
4115 addAllResults = main.FALSE
4116 if addAllResults != main.TRUE:
4117 main.log.error( "Error executing set addAll" )
4118
4119 # Check if set is still correct
4120 size = len( onosSet )
4121 getResponses = []
4122 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004123 for i in range( main.numCtrls ):
4124 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07004125 name="setTestGet-" + str( i ),
4126 args=[ onosSetName ] )
4127 threads.append( t )
4128 t.start()
4129 for t in threads:
4130 t.join()
4131 getResponses.append( t.result )
4132 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004133 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004134 if isinstance( getResponses[ i ], list):
4135 current = set( getResponses[ i ] )
4136 if len( current ) == len( getResponses[ i ] ):
4137 # no repeats
4138 if onosSet != current:
4139 main.log.error( "ONOS" + str( i + 1 ) +
4140 " has incorrect view" +
4141 " of set " + onosSetName + ":\n" +
4142 str( getResponses[ i ] ) )
4143 main.log.debug( "Expected: " + str( onosSet ) )
4144 main.log.debug( "Actual: " + str( current ) )
4145 getResults = main.FALSE
4146 else:
4147 # error, set is not a set
4148 main.log.error( "ONOS" + str( i + 1 ) +
4149 " has repeat elements in" +
4150 " set " + onosSetName + ":\n" +
4151 str( getResponses[ i ] ) )
4152 getResults = main.FALSE
4153 elif getResponses[ i ] == main.ERROR:
4154 getResults = main.FALSE
4155 sizeResponses = []
4156 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004157 for i in range( main.numCtrls ):
4158 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07004159 name="setTestSize-" + str( i ),
4160 args=[ onosSetName ] )
4161 threads.append( t )
4162 t.start()
4163 for t in threads:
4164 t.join()
4165 sizeResponses.append( t.result )
4166 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004167 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004168 if size != sizeResponses[ i ]:
4169 sizeResults = main.FALSE
4170 main.log.error( "ONOS" + str( i + 1 ) +
4171 " expected a size of " + str( size ) +
4172 " for set " + onosSetName +
4173 " but got " + str( sizeResponses[ i ] ) )
4174 addAllResults = addAllResults and getResults and sizeResults
4175 utilities.assert_equals( expect=main.TRUE,
4176 actual=addAllResults,
4177 onpass="Set addAll correct",
4178 onfail="Set addAll was incorrect" )
4179
4180 main.step( "Distributed Set retain()" )
4181 onosSet.intersection_update( retainValue.split() )
4182 retainResponses = []
4183 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004184 for i in range( main.numCtrls ):
4185 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall5cf14d52015-07-16 12:15:19 -07004186 name="setTestRetain-" + str( i ),
4187 args=[ onosSetName, retainValue ],
4188 kwargs={ "retain": True } )
4189 threads.append( t )
4190 t.start()
4191 for t in threads:
4192 t.join()
4193 retainResponses.append( t.result )
4194
4195 # main.TRUE = successfully changed the set
4196 # main.FALSE = action resulted in no change in set
4197 # main.ERROR - Some error in executing the function
4198 retainResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004199 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004200 if retainResponses[ i ] == main.TRUE:
4201 # All is well
4202 pass
4203 elif retainResponses[ i ] == main.FALSE:
4204 # Already in set, probably fine
4205 pass
4206 elif retainResponses[ i ] == main.ERROR:
4207 # Error in execution
4208 retainResults = main.FALSE
4209 else:
4210 # unexpected result
4211 retainResults = main.FALSE
4212 if retainResults != main.TRUE:
4213 main.log.error( "Error executing set retain" )
4214
4215 # Check if set is still correct
4216 size = len( onosSet )
4217 getResponses = []
4218 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004219 for i in range( main.numCtrls ):
4220 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall5cf14d52015-07-16 12:15:19 -07004221 name="setTestGet-" + str( i ),
4222 args=[ onosSetName ] )
4223 threads.append( t )
4224 t.start()
4225 for t in threads:
4226 t.join()
4227 getResponses.append( t.result )
4228 getResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004229 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004230 if isinstance( getResponses[ i ], list):
4231 current = set( getResponses[ i ] )
4232 if len( current ) == len( getResponses[ i ] ):
4233 # no repeats
4234 if onosSet != current:
4235 main.log.error( "ONOS" + str( i + 1 ) +
4236 " has incorrect view" +
4237 " of set " + onosSetName + ":\n" +
4238 str( getResponses[ i ] ) )
4239 main.log.debug( "Expected: " + str( onosSet ) )
4240 main.log.debug( "Actual: " + str( current ) )
4241 getResults = main.FALSE
4242 else:
4243 # error, set is not a set
4244 main.log.error( "ONOS" + str( i + 1 ) +
4245 " has repeat elements in" +
4246 " set " + onosSetName + ":\n" +
4247 str( getResponses[ i ] ) )
4248 getResults = main.FALSE
4249 elif getResponses[ i ] == main.ERROR:
4250 getResults = main.FALSE
4251 sizeResponses = []
4252 threads = []
Jon Halle1a3b752015-07-22 13:02:46 -07004253 for i in range( main.numCtrls ):
4254 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall5cf14d52015-07-16 12:15:19 -07004255 name="setTestSize-" + str( i ),
4256 args=[ onosSetName ] )
4257 threads.append( t )
4258 t.start()
4259 for t in threads:
4260 t.join()
4261 sizeResponses.append( t.result )
4262 sizeResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07004263 for i in range( main.numCtrls ):
Jon Hall5cf14d52015-07-16 12:15:19 -07004264 if size != sizeResponses[ i ]:
4265 sizeResults = main.FALSE
4266 main.log.error( "ONOS" + str( i + 1 ) +
4267 " expected a size of " +
4268 str( size ) + " for set " + onosSetName +
4269 " but got " + str( sizeResponses[ i ] ) )
4270 retainResults = retainResults and getResults and sizeResults
4271 utilities.assert_equals( expect=main.TRUE,
4272 actual=retainResults,
4273 onpass="Set retain correct",
4274 onfail="Set retain was incorrect" )
4275
Jon Hall2a5002c2015-08-21 16:49:11 -07004276 # Transactional maps
4277 main.step( "Partitioned Transactional maps put" )
4278 tMapValue = "Testing"
4279 numKeys = 100
4280 putResult = True
4281 putResponses = main.CLIs[ 0 ].transactionalMapPut( numKeys, tMapValue )
4282 if len( putResponses ) == 100:
4283 for i in putResponses:
4284 if putResponses[ i ][ 'value' ] != tMapValue:
4285 putResult = False
4286 else:
4287 putResult = False
4288 if not putResult:
4289 main.log.debug( "Put response values: " + str( putResponses ) )
4290 utilities.assert_equals( expect=True,
4291 actual=putResult,
4292 onpass="Partitioned Transactional Map put successful",
4293 onfail="Partitioned Transactional Map put values are incorrect" )
4294
4295 main.step( "Partitioned Transactional maps get" )
4296 getCheck = True
4297 for n in range( 1, numKeys + 1 ):
4298 getResponses = []
4299 threads = []
4300 valueCheck = True
4301 for i in range( main.numCtrls ):
4302 t = main.Thread( target=main.CLIs[i].transactionalMapGet,
4303 name="TMap-get-" + str( i ),
4304 args=[ "Key" + str ( n ) ] )
4305 threads.append( t )
4306 t.start()
4307 for t in threads:
4308 t.join()
4309 getResponses.append( t.result )
4310 for node in getResponses:
4311 if node != tMapValue:
4312 valueCheck = False
4313 if not valueCheck:
4314 main.log.warn( "Values for key 'Key" + str( n ) + "' do not match:" )
4315 main.log.warn( getResponses )
4316 getCheck = getCheck and valueCheck
4317 utilities.assert_equals( expect=True,
4318 actual=getCheck,
4319 onpass="Partitioned Transactional Map get values were correct",
4320 onfail="Partitioned Transactional Map values incorrect" )
4321
4322 main.step( "In-memory Transactional maps put" )
4323 tMapValue = "Testing"
4324 numKeys = 100
4325 putResult = True
4326 putResponses = main.CLIs[ 0 ].transactionalMapPut( numKeys, tMapValue, inMemory=True )
4327 if len( putResponses ) == 100:
4328 for i in putResponses:
4329 if putResponses[ i ][ 'value' ] != tMapValue:
4330 putResult = False
4331 else:
4332 putResult = False
4333 if not putResult:
4334 main.log.debug( "Put response values: " + str( putResponses ) )
4335 utilities.assert_equals( expect=True,
4336 actual=putResult,
4337 onpass="In-Memory Transactional Map put successful",
4338 onfail="In-Memory Transactional Map put values are incorrect" )
4339
4340 main.step( "In-Memory Transactional maps get" )
4341 getCheck = True
4342 for n in range( 1, numKeys + 1 ):
4343 getResponses = []
4344 threads = []
4345 valueCheck = True
4346 for i in range( main.numCtrls ):
4347 t = main.Thread( target=main.CLIs[i].transactionalMapGet,
4348 name="TMap-get-" + str( i ),
4349 args=[ "Key" + str ( n ) ],
4350 kwargs={ "inMemory": True } )
4351 threads.append( t )
4352 t.start()
4353 for t in threads:
4354 t.join()
4355 getResponses.append( t.result )
4356 for node in getResponses:
4357 if node != tMapValue:
4358 valueCheck = False
4359 if not valueCheck:
4360 main.log.warn( "Values for key 'Key" + str( n ) + "' do not match:" )
4361 main.log.warn( getResponses )
4362 getCheck = getCheck and valueCheck
4363 utilities.assert_equals( expect=True,
4364 actual=getCheck,
4365 onpass="In-Memory Transactional Map get values were correct",
4366 onfail="In-Memory Transactional Map values incorrect" )