blob: ee24c9709e75fae0ff0b02fd46d9c612094a4a64 [file] [log] [blame]
Jon Hall85794ff2015-07-08 14:12:30 -07001"""
2Description: This test is to determine if a single
3 instance ONOS 'cluster' can handle a restart
4
5List of test cases:
6CASE1: Compile ONOS and push it to the test machines
7CASE2: Assign devices to controllers
8CASE21: Assign mastership to controllers
9CASE3: Assign intents
10CASE4: Ping across added host intents
11CASE5: Reading state of ONOS
12CASE6: The Failure case.
13CASE7: Check state after control plane failure
14CASE8: Compare topo
15CASE9: Link s3-s28 down
16CASE10: Link s3-s28 up
17CASE11: Switch down
18CASE12: Switch up
19CASE13: Clean up
20CASE14: start election app on all onos nodes
21CASE15: Check that Leadership Election is still functional
22CASE16: Install Distributed Primitives app
23CASE17: Check for basic functionality with distributed primitives
24"""
25
26
27class HAsingleInstanceRestart:
28
29 def __init__( self ):
30 self.default = ''
31
32 def CASE1( self, main ):
33 """
34 CASE1 is to compile ONOS and push it to the test machines
35
36 Startup sequence:
37 cell <name>
38 onos-verify-cell
39 NOTE: temporary - onos-remove-raft-logs
40 onos-uninstall
41 start mininet
42 git pull
43 mvn clean install
44 onos-package
45 onos-install -f
46 onos-wait-for-start
47 start cli sessions
48 start tcpdump
49 """
Jon Halle1a3b752015-07-22 13:02:46 -070050 import imp
Jon Hallf3d16e72015-12-16 17:45:08 -080051 import time
Jon Halla440e872016-03-31 15:15:50 -070052 import json
Jon Hall85794ff2015-07-08 14:12:30 -070053 main.log.info( "ONOS Single node cluster restart " +
54 "HA test - initialization" )
55 main.case( "Setting up test environment" )
Jon Hall783bbf92015-07-23 14:33:19 -070056 main.caseExplanation = "Setup the test environment including " +\
Jon Hall85794ff2015-07-08 14:12:30 -070057 "installing ONOS, starting Mininet and ONOS" +\
58 "cli sessions."
Jon Hall85794ff2015-07-08 14:12:30 -070059
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 Hall85794ff2015-07-08 14:12:30 -070071
Jon Halle1a3b752015-07-22 13:02:46 -070072 try:
Jon Hall41d39f12016-04-11 22:54:35 -070073 from tests.HAsanity.dependencies.HA import HA
74 main.HA = HA()
Jon Halle1a3b752015-07-22 13:02:46 -070075 except Exception as e:
76 main.log.exception( e )
77 main.cleanup()
78 main.exit()
79
80 main.CLIs = []
81 main.nodes = []
Jon Hall5cf14d52015-07-16 12:15:19 -070082 ipList = []
83 for i in range( 1, int( main.ONOSbench.maxNodes ) + 1 ):
84 try:
Jon Halle1a3b752015-07-22 13:02:46 -070085 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
86 main.nodes.append( getattr( main, 'ONOS' + str( i ) ) )
87 ipList.append( main.nodes[ -1 ].ip_address )
Jon Hall5cf14d52015-07-16 12:15:19 -070088 except AttributeError:
89 break
Jon Hall85794ff2015-07-08 14:12:30 -070090
Jon Hall5cf14d52015-07-16 12:15:19 -070091 main.step( "Create cell file" )
92 cellAppString = main.params[ 'ENV' ][ 'appString' ]
93 main.ONOSbench.createCellFile( main.ONOSbench.ip_address, cellName,
94 main.Mininet1.ip_address,
95 cellAppString, ipList )
Jon Hall85794ff2015-07-08 14:12:30 -070096 main.step( "Applying cell variable to environment" )
97 cellResult = main.ONOSbench.setCell( cellName )
98 verifyResult = main.ONOSbench.verifyCell()
99
100 # FIXME:this is short term fix
101 main.log.info( "Removing raft logs" )
102 main.ONOSbench.onosRemoveRaftLogs()
103
104 main.log.info( "Uninstalling ONOS" )
Jon Halle1a3b752015-07-22 13:02:46 -0700105 for node in main.nodes:
Jon Hall85794ff2015-07-08 14:12:30 -0700106 main.ONOSbench.onosUninstall( node.ip_address )
107
108 # Make sure ONOS is DEAD
109 main.log.info( "Killing any ONOS processes" )
110 killResults = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -0700111 for node in main.nodes:
Jon Hall85794ff2015-07-08 14:12:30 -0700112 killed = main.ONOSbench.onosKill( node.ip_address )
113 killResults = killResults and killed
114
115 cleanInstallResult = main.TRUE
116 gitPullResult = main.TRUE
117
118 main.step( "Starting Mininet" )
119 # scp topo file to mininet
120 # TODO: move to params?
121 topoName = "obelisk.py"
122 filePath = main.ONOSbench.home + "/tools/test/topos/"
kelvin-onlabd9e23de2015-08-06 10:34:44 -0700123 main.ONOSbench.scp( main.Mininet1,
124 filePath + topoName,
125 main.Mininet1.home,
126 direction="to" )
Jon Hall85794ff2015-07-08 14:12:30 -0700127 mnResult = main.Mininet1.startNet( )
128 utilities.assert_equals( expect=main.TRUE, actual=mnResult,
129 onpass="Mininet Started",
130 onfail="Error starting Mininet" )
131
132 main.step( "Git checkout and pull " + gitBranch )
133 if PULLCODE:
134 main.ONOSbench.gitCheckout( gitBranch )
135 gitPullResult = main.ONOSbench.gitPull()
136 # values of 1 or 3 are good
137 utilities.assert_lesser( expect=0, actual=gitPullResult,
138 onpass="Git pull successful",
139 onfail="Git pull failed" )
140 main.ONOSbench.getVersion( report=True )
141
142 main.step( "Using mvn clean install" )
143 cleanInstallResult = main.TRUE
144 if PULLCODE and gitPullResult == main.TRUE:
145 cleanInstallResult = main.ONOSbench.cleanInstall()
146 else:
147 main.log.warn( "Did not pull new code so skipping mvn " +
148 "clean install" )
149 utilities.assert_equals( expect=main.TRUE,
150 actual=cleanInstallResult,
151 onpass="MCI successful",
152 onfail="MCI failed" )
153 # GRAPHS
154 # NOTE: important params here:
155 # job = name of Jenkins job
156 # Plot Name = Plot-HA, only can be used if multiple plots
157 # index = The number of the graph under plot name
Jon Hall5cf14d52015-07-16 12:15:19 -0700158 job = "HAsingleInstanceRestart"
Jon Hall85794ff2015-07-08 14:12:30 -0700159 plotName = "Plot-HA"
Jon Hall843f8bc2016-03-18 14:28:13 -0700160 index = "2"
Jon Hall85794ff2015-07-08 14:12:30 -0700161 graphs = '<ac:structured-macro ac:name="html">\n'
162 graphs += '<ac:plain-text-body><![CDATA[\n'
163 graphs += '<iframe src="https://onos-jenkins.onlab.us/job/' + job +\
Jon Halla9845df2016-01-15 14:55:58 -0800164 '/plot/' + plotName + '/getPlot?index=' + index +\
Jon Hall85794ff2015-07-08 14:12:30 -0700165 '&width=500&height=300"' +\
166 'noborder="0" width="500" height="300" scrolling="yes" ' +\
167 'seamless="seamless"></iframe>\n'
168 graphs += ']]></ac:plain-text-body>\n'
169 graphs += '</ac:structured-macro>\n'
170 main.log.wiki(graphs)
171
Jon Halle1a3b752015-07-22 13:02:46 -0700172 main.CLIs = []
173 main.nodes = []
Jon Hall5cf14d52015-07-16 12:15:19 -0700174 ipList = []
Jon Halle1a3b752015-07-22 13:02:46 -0700175 for i in range( 1, main.numCtrls + 1 ):
176 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
177 main.nodes.append( getattr( main, 'ONOS' + str( i ) ) )
178 ipList.append( main.nodes[ -1 ].ip_address )
Jon Hall5cf14d52015-07-16 12:15:19 -0700179
180 main.ONOSbench.createCellFile( main.ONOSbench.ip_address, "SingleHA",
181 main.Mininet1.ip_address,
182 cellAppString, ipList[ 0 ] )
Jon Hall85794ff2015-07-08 14:12:30 -0700183 cellResult = main.ONOSbench.setCell( "SingleHA" )
184 verifyResult = main.ONOSbench.verifyCell()
185 main.step( "Creating ONOS package" )
186 packageResult = main.ONOSbench.onosPackage()
187 utilities.assert_equals( expect=main.TRUE, actual=packageResult,
188 onpass="ONOS package successful",
189 onfail="ONOS package failed" )
190
191 main.step( "Installing ONOS package" )
Jon Halla440e872016-03-31 15:15:50 -0700192 onosInstallResult = main.TRUE
193 for node in main.nodes:
194 tmpResult = main.ONOSbench.onosInstall( options="-f",
195 node=node.ip_address )
196 onosInstallResult = onosInstallResult and tmpResult
Jon Hall85794ff2015-07-08 14:12:30 -0700197 utilities.assert_equals( expect=main.TRUE, actual=onosInstallResult,
198 onpass="ONOS install successful",
199 onfail="ONOS install failed" )
200
201 main.step( "Checking if ONOS is up yet" )
202 for i in range( 2 ):
Jon Halla440e872016-03-31 15:15:50 -0700203 onosIsupResult = main.TRUE
204 for node in main.nodes:
205 started = main.ONOSbench.isup( node.ip_address )
206 if not started:
207 main.log.error( node.name + " hasn't started" )
208 onosIsupResult = onosIsupResult and started
209 if onosIsupResult == main.TRUE:
Jon Hall85794ff2015-07-08 14:12:30 -0700210 break
Jon Halla440e872016-03-31 15:15:50 -0700211 utilities.assert_equals( expect=main.TRUE, actual=onosIsupResult,
Jon Hall85794ff2015-07-08 14:12:30 -0700212 onpass="ONOS startup successful",
213 onfail="ONOS startup failed" )
214
215 main.log.step( "Starting ONOS CLI sessions" )
Jon Halla440e872016-03-31 15:15:50 -0700216 cliResults = main.TRUE
217 threads = []
218 for i in range( main.numCtrls ):
219 t = main.Thread( target=main.CLIs[i].startOnosCli,
220 name="startOnosCli-" + str( i ),
221 args=[main.nodes[i].ip_address] )
222 threads.append( t )
223 t.start()
224
225 for t in threads:
226 t.join()
227 cliResults = cliResults and t.result
Jon Hall85794ff2015-07-08 14:12:30 -0700228 utilities.assert_equals( expect=main.TRUE, actual=cliResults,
229 onpass="ONOS cli startup successful",
230 onfail="ONOS cli startup failed" )
231
Jon Halla440e872016-03-31 15:15:50 -0700232 # Create a list of active nodes for use when some nodes are stopped
233 main.activeNodes = [ i for i in range( 0, len( main.CLIs ) ) ]
234
Jon Hall85794ff2015-07-08 14:12:30 -0700235 if main.params[ 'tcpdump' ].lower() == "true":
236 main.step( "Start Packet Capture MN" )
237 main.Mininet2.startTcpdump(
238 str( main.params[ 'MNtcpdump' ][ 'folder' ] ) + str( main.TEST )
239 + "-MN.pcap",
240 intf=main.params[ 'MNtcpdump' ][ 'intf' ],
241 port=main.params[ 'MNtcpdump' ][ 'port' ] )
242
Jon Halla440e872016-03-31 15:15:50 -0700243 main.step( "Checking ONOS nodes" )
Jon Hall41d39f12016-04-11 22:54:35 -0700244 nodeResults = utilities.retry( main.HA.nodesCheck,
245 False,
246 args=[main.activeNodes],
247 attempts=5 )
Jon Halla440e872016-03-31 15:15:50 -0700248
Jon Hall41d39f12016-04-11 22:54:35 -0700249 utilities.assert_equals( expect=True, actual=nodeResults,
Jon Halla440e872016-03-31 15:15:50 -0700250 onpass="Nodes check successful",
251 onfail="Nodes check NOT successful" )
252
253 if not nodeResults:
254 for cli in main.CLIs:
255 main.log.debug( "{} components not ACTIVE: \n{}".format(
256 cli.name,
257 cli.sendline( "scr:list | grep -v ACTIVE" ) ) )
258
Jon Hall85794ff2015-07-08 14:12:30 -0700259 if cliResults == main.FALSE:
260 main.log.error( "Failed to start ONOS, stopping test" )
261 main.cleanup()
262 main.exit()
263
Jon Hall172b7ba2016-04-07 18:12:20 -0700264 main.step( "Activate apps defined in the params file" )
265 # get data from the params
266 apps = main.params.get( 'apps' )
267 if apps:
268 apps = apps.split(',')
269 main.log.warn( apps )
270 activateResult = True
271 for app in apps:
272 main.CLIs[ 0 ].app( app, "Activate" )
273 # TODO: check this worked
274 time.sleep( 10 ) # wait for apps to activate
275 for app in apps:
276 state = main.CLIs[ 0 ].appStatus( app )
277 if state == "ACTIVE":
278 activateResult = activeResult and True
279 else:
280 main.log.error( "{} is in {} state".format( app, state ) )
281 activeResult = False
282 utilities.assert_equals( expect=True,
283 actual=activateResult,
284 onpass="Successfully activated apps",
285 onfail="Failed to activate apps" )
286 else:
287 main.log.warn( "No apps were specified to be loaded after startup" )
288
289 main.step( "Set ONOS configurations" )
290 config = main.params.get( 'ONOS_Configuration' )
291 if config:
292 main.log.debug( config )
293 checkResult = main.TRUE
294 for component in config:
295 for setting in config[component]:
296 value = config[component][setting]
297 check = main.CLIs[ 0 ].setCfg( component, setting, value )
298 main.log.info( "Value was changed? {}".format( main.TRUE == check ) )
299 checkResult = check and checkResult
300 utilities.assert_equals( expect=main.TRUE,
301 actual=checkResult,
302 onpass="Successfully set config",
303 onfail="Failed to set config" )
304 else:
305 main.log.warn( "No configurations were specified to be changed after startup" )
306
Jon Hall9d2dcad2016-04-08 10:15:20 -0700307 main.step( "App Ids check" )
308 appCheck = main.TRUE
309 threads = []
310 for i in main.activeNodes:
311 t = main.Thread( target=main.CLIs[i].appToIDCheck,
312 name="appToIDCheck-" + str( i ),
313 args=[] )
314 threads.append( t )
315 t.start()
316
317 for t in threads:
318 t.join()
319 appCheck = appCheck and t.result
320 if appCheck != main.TRUE:
321 node = main.activeNodes[0]
322 main.log.warn( main.CLIs[node].apps() )
323 main.log.warn( main.CLIs[node].appIDs() )
324 utilities.assert_equals( expect=main.TRUE, actual=appCheck,
325 onpass="App Ids seem to be correct",
326 onfail="Something is wrong with app Ids" )
327
Jon Hall85794ff2015-07-08 14:12:30 -0700328 def CASE2( self, main ):
329 """
330 Assign devices to controllers
331 """
332 import re
Jon Halle1a3b752015-07-22 13:02:46 -0700333 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall85794ff2015-07-08 14:12:30 -0700334 assert main, "main not defined"
335 assert utilities.assert_equals, "utilities.assert_equals not defined"
336
337 main.case( "Assigning devices to controllers" )
Jon Hall783bbf92015-07-23 14:33:19 -0700338 main.caseExplanation = "Assign switches to ONOS using 'ovs-vsctl' " +\
Jon Hall85794ff2015-07-08 14:12:30 -0700339 "and check that an ONOS node becomes the " +\
340 "master of the device."
341 main.step( "Assign switches to controllers" )
342
343 ipList = []
Jon Halle1a3b752015-07-22 13:02:46 -0700344 for i in range( main.numCtrls ):
345 ipList.append( main.nodes[ i ].ip_address )
Jon Hall85794ff2015-07-08 14:12:30 -0700346 swList = []
347 for i in range( 1, 29 ):
348 swList.append( "s" + str( i ) )
349 main.Mininet1.assignSwController( sw=swList, ip=ipList )
350
351 mastershipCheck = main.TRUE
352 for i in range( 1, 29 ):
353 response = main.Mininet1.getSwController( "s" + str( i ) )
354 try:
355 main.log.info( str( response ) )
356 except Exception:
357 main.log.info( repr( response ) )
Jon Halla440e872016-03-31 15:15:50 -0700358 for node in main.nodes:
359 if re.search( "tcp:" + node.ip_address, response ):
360 mastershipCheck = mastershipCheck and main.TRUE
361 else:
362 main.log.error( "Error, node " + node.ip_address + " is " +
363 "not in the list of controllers s" +
364 str( i ) + " is connecting to." )
365 mastershipCheck = main.FALSE
Jon Hall85794ff2015-07-08 14:12:30 -0700366 utilities.assert_equals(
367 expect=main.TRUE,
368 actual=mastershipCheck,
369 onpass="Switch mastership assigned correctly",
370 onfail="Switches not assigned correctly to controllers" )
371
372 def CASE21( self, main ):
373 """
374 Assign mastership to controllers
375 """
Jon Halle1a3b752015-07-22 13:02:46 -0700376 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall85794ff2015-07-08 14:12:30 -0700377 assert main, "main not defined"
378 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -0700379 assert main.CLIs, "main.CLIs not defined"
380 assert main.nodes, "main.nodes not defined"
Jon Hall85794ff2015-07-08 14:12:30 -0700381
382 main.case( "Assigning Controller roles for switches" )
Jon Hall783bbf92015-07-23 14:33:19 -0700383 main.caseExplanation = "Check that ONOS is connected to each " +\
Jon Hall85794ff2015-07-08 14:12:30 -0700384 "device. Then manually assign" +\
385 " mastership to specific ONOS nodes using" +\
386 " 'device-role'"
387 main.step( "Assign mastership of switches to specific controllers" )
Jon Halla440e872016-03-31 15:15:50 -0700388 # Manually assign mastership to the controller we want
Jon Hall85794ff2015-07-08 14:12:30 -0700389 roleCall = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -0700390
391 ipList = [ ]
392 deviceList = []
393 onosCli = main.CLIs[ main.activeNodes[0] ]
Jon Hall85794ff2015-07-08 14:12:30 -0700394 try:
Jon Halla440e872016-03-31 15:15:50 -0700395 # Assign mastership to specific controllers. This assignment was
396 # determined for a 7 node cluser, but will work with any sized
397 # cluster
Jon Hall85794ff2015-07-08 14:12:30 -0700398 for i in range( 1, 29 ): # switches 1 through 28
Jon Hall85794ff2015-07-08 14:12:30 -0700399 # set up correct variables:
400 if i == 1:
Jon Halla440e872016-03-31 15:15:50 -0700401 c = 0
402 ip = main.nodes[ c ].ip_address # ONOS1
403 deviceId = onosCli.getDevice( "1000" ).get( 'id' )
Jon Hall85794ff2015-07-08 14:12:30 -0700404 elif i == 2:
Jon Halla440e872016-03-31 15:15:50 -0700405 c = 1 % main.numCtrls
406 ip = main.nodes[ c ].ip_address # ONOS2
407 deviceId = onosCli.getDevice( "2000" ).get( 'id' )
Jon Hall85794ff2015-07-08 14:12:30 -0700408 elif i == 3:
Jon Halla440e872016-03-31 15:15:50 -0700409 c = 1 % main.numCtrls
410 ip = main.nodes[ c ].ip_address # ONOS2
411 deviceId = onosCli.getDevice( "3000" ).get( 'id' )
Jon Hall85794ff2015-07-08 14:12:30 -0700412 elif i == 4:
Jon Halla440e872016-03-31 15:15:50 -0700413 c = 3 % main.numCtrls
414 ip = main.nodes[ c ].ip_address # ONOS4
415 deviceId = onosCli.getDevice( "3004" ).get( 'id' )
Jon Hall85794ff2015-07-08 14:12:30 -0700416 elif i == 5:
Jon Halla440e872016-03-31 15:15:50 -0700417 c = 2 % main.numCtrls
418 ip = main.nodes[ c ].ip_address # ONOS3
419 deviceId = onosCli.getDevice( "5000" ).get( 'id' )
Jon Hall85794ff2015-07-08 14:12:30 -0700420 elif i == 6:
Jon Halla440e872016-03-31 15:15:50 -0700421 c = 2 % main.numCtrls
422 ip = main.nodes[ c ].ip_address # ONOS3
423 deviceId = onosCli.getDevice( "6000" ).get( 'id' )
Jon Hall85794ff2015-07-08 14:12:30 -0700424 elif i == 7:
Jon Halla440e872016-03-31 15:15:50 -0700425 c = 5 % main.numCtrls
426 ip = main.nodes[ c ].ip_address # ONOS6
427 deviceId = onosCli.getDevice( "6007" ).get( 'id' )
Jon Hall85794ff2015-07-08 14:12:30 -0700428 elif i >= 8 and i <= 17:
Jon Halla440e872016-03-31 15:15:50 -0700429 c = 4 % main.numCtrls
430 ip = main.nodes[ c ].ip_address # ONOS5
Jon Hall85794ff2015-07-08 14:12:30 -0700431 dpid = '3' + str( i ).zfill( 3 )
Jon Halla440e872016-03-31 15:15:50 -0700432 deviceId = onosCli.getDevice( dpid ).get( 'id' )
Jon Hall85794ff2015-07-08 14:12:30 -0700433 elif i >= 18 and i <= 27:
Jon Halla440e872016-03-31 15:15:50 -0700434 c = 6 % main.numCtrls
435 ip = main.nodes[ c ].ip_address # ONOS7
Jon Hall85794ff2015-07-08 14:12:30 -0700436 dpid = '6' + str( i ).zfill( 3 )
Jon Halla440e872016-03-31 15:15:50 -0700437 deviceId = onosCli.getDevice( dpid ).get( 'id' )
Jon Hall85794ff2015-07-08 14:12:30 -0700438 elif i == 28:
Jon Halla440e872016-03-31 15:15:50 -0700439 c = 0
440 ip = main.nodes[ c ].ip_address # ONOS1
441 deviceId = onosCli.getDevice( "2800" ).get( 'id' )
Jon Hall85794ff2015-07-08 14:12:30 -0700442 else:
443 main.log.error( "You didn't write an else statement for " +
444 "switch s" + str( i ) )
Jon Halla440e872016-03-31 15:15:50 -0700445 roleCall = main.FALSE
Jon Hall85794ff2015-07-08 14:12:30 -0700446 # Assign switch
447 assert deviceId, "No device id for s" + str( i ) + " in ONOS"
448 # TODO: make this controller dynamic
Jon Halla440e872016-03-31 15:15:50 -0700449 roleCall = roleCall and onosCli.deviceRole( deviceId, ip )
450 ipList.append( ip )
451 deviceList.append( deviceId )
Jon Hall85794ff2015-07-08 14:12:30 -0700452 except ( AttributeError, AssertionError ):
453 main.log.exception( "Something is wrong with ONOS device view" )
Jon Halla440e872016-03-31 15:15:50 -0700454 main.log.info( onosCli.devices() )
Jon Hall85794ff2015-07-08 14:12:30 -0700455 utilities.assert_equals(
456 expect=main.TRUE,
457 actual=roleCall,
458 onpass="Re-assigned switch mastership to designated controller",
459 onfail="Something wrong with deviceRole calls" )
460
461 main.step( "Check mastership was correctly assigned" )
Jon Halla440e872016-03-31 15:15:50 -0700462 roleCheck = main.TRUE
463 # NOTE: This is due to the fact that device mastership change is not
464 # atomic and is actually a multi step process
465 time.sleep( 5 )
466 for i in range( len( ipList ) ):
467 ip = ipList[i]
468 deviceId = deviceList[i]
469 # Check assignment
470 master = onosCli.getRole( deviceId ).get( 'master' )
471 if ip in master:
472 roleCheck = roleCheck and main.TRUE
473 else:
474 roleCheck = roleCheck and main.FALSE
475 main.log.error( "Error, controller " + ip + " is not" +
476 " master " + "of device " +
477 str( deviceId ) + ". Master is " +
478 repr( master ) + "." )
Jon Hall85794ff2015-07-08 14:12:30 -0700479 utilities.assert_equals(
480 expect=main.TRUE,
481 actual=roleCheck,
482 onpass="Switches were successfully reassigned to designated " +
483 "controller",
484 onfail="Switches were not successfully reassigned" )
485
486 def CASE3( self, main ):
487 """
488 Assign intents
489 """
490 import time
491 import json
Jon Halle1a3b752015-07-22 13:02:46 -0700492 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall85794ff2015-07-08 14:12:30 -0700493 assert main, "main not defined"
494 assert utilities.assert_equals, "utilities.assert_equals not defined"
495 # NOTE: we must reinstall intents until we have a persistant intent
496 # datastore!
497 main.case( "Adding host Intents" )
Jon Hall783bbf92015-07-23 14:33:19 -0700498 main.caseExplanation = "Discover hosts by using pingall then " +\
Jon Hall85794ff2015-07-08 14:12:30 -0700499 "assign predetermined host-to-host intents." +\
500 " After installation, check that the intent" +\
501 " is distributed to all nodes and the state" +\
502 " is INSTALLED"
503
504 # install onos-app-fwd
505 main.step( "Install reactive forwarding app" )
Jon Halla440e872016-03-31 15:15:50 -0700506 onosCli = main.CLIs[ main.activeNodes[0] ]
507 installResults = onosCli.activateApp( "org.onosproject.fwd" )
Jon Hall85794ff2015-07-08 14:12:30 -0700508 utilities.assert_equals( expect=main.TRUE, actual=installResults,
509 onpass="Install fwd successful",
510 onfail="Install fwd failed" )
511
512 main.step( "Check app ids" )
Jon Halla440e872016-03-31 15:15:50 -0700513 appCheck = main.TRUE
514 threads = []
515 for i in main.activeNodes:
516 t = main.Thread( target=main.CLIs[i].appToIDCheck,
517 name="appToIDCheck-" + str( i ),
518 args=[] )
519 threads.append( t )
520 t.start()
521
522 for t in threads:
523 t.join()
524 appCheck = appCheck and t.result
Jon Hall85794ff2015-07-08 14:12:30 -0700525 if appCheck != main.TRUE:
Jon Halla440e872016-03-31 15:15:50 -0700526 main.log.warn( onosCli.apps() )
527 main.log.warn( onosCli.appIDs() )
Jon Hall85794ff2015-07-08 14:12:30 -0700528 utilities.assert_equals( expect=main.TRUE, actual=appCheck,
529 onpass="App Ids seem to be correct",
530 onfail="Something is wrong with app Ids" )
531
532 main.step( "Discovering Hosts( Via pingall for now )" )
533 # FIXME: Once we have a host discovery mechanism, use that instead
534 # REACTIVE FWD test
535 pingResult = main.FALSE
Jon Hall96091e62015-09-21 17:34:17 -0700536 passMsg = "Reactive Pingall test passed"
537 time1 = time.time()
538 pingResult = main.Mininet1.pingall()
539 time2 = time.time()
540 if not pingResult:
541 main.log.warn("First pingall failed. Trying again...")
Jon Hall85794ff2015-07-08 14:12:30 -0700542 pingResult = main.Mininet1.pingall()
Jon Hall96091e62015-09-21 17:34:17 -0700543 passMsg += " on the second try"
544 utilities.assert_equals(
545 expect=main.TRUE,
546 actual=pingResult,
547 onpass= passMsg,
548 onfail="Reactive Pingall failed, " +
549 "one or more ping pairs failed" )
550 main.log.info( "Time for pingall: %2f seconds" %
551 ( time2 - time1 ) )
Jon Hall85794ff2015-07-08 14:12:30 -0700552 # timeout for fwd flows
553 time.sleep( 11 )
554 # uninstall onos-app-fwd
555 main.step( "Uninstall reactive forwarding app" )
Jon Halla440e872016-03-31 15:15:50 -0700556 node = main.activeNodes[0]
557 uninstallResult = main.CLIs[node].deactivateApp( "org.onosproject.fwd" )
Jon Hall85794ff2015-07-08 14:12:30 -0700558 utilities.assert_equals( expect=main.TRUE, actual=uninstallResult,
559 onpass="Uninstall fwd successful",
560 onfail="Uninstall fwd failed" )
561
562 main.step( "Check app ids" )
Jon Halla440e872016-03-31 15:15:50 -0700563 threads = []
564 appCheck2 = main.TRUE
565 for i in main.activeNodes:
566 t = main.Thread( target=main.CLIs[i].appToIDCheck,
567 name="appToIDCheck-" + str( i ),
568 args=[] )
569 threads.append( t )
570 t.start()
571
572 for t in threads:
573 t.join()
574 appCheck2 = appCheck2 and t.result
Jon Hall85794ff2015-07-08 14:12:30 -0700575 if appCheck2 != main.TRUE:
Jon Halla440e872016-03-31 15:15:50 -0700576 node = main.activeNodes[0]
577 main.log.warn( main.CLIs[node].apps() )
578 main.log.warn( main.CLIs[node].appIDs() )
Jon Hall85794ff2015-07-08 14:12:30 -0700579 utilities.assert_equals( expect=main.TRUE, actual=appCheck2,
580 onpass="App Ids seem to be correct",
581 onfail="Something is wrong with app Ids" )
582
583 main.step( "Add host intents via cli" )
584 intentIds = []
Jon Halla440e872016-03-31 15:15:50 -0700585 # TODO: move the host numbers to params
586 # Maybe look at all the paths we ping?
Jon Hall85794ff2015-07-08 14:12:30 -0700587 intentAddResult = True
588 hostResult = main.TRUE
589 for i in range( 8, 18 ):
590 main.log.info( "Adding host intent between h" + str( i ) +
591 " and h" + str( i + 10 ) )
592 host1 = "00:00:00:00:00:" + \
593 str( hex( i )[ 2: ] ).zfill( 2 ).upper()
594 host2 = "00:00:00:00:00:" + \
595 str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper()
596 # NOTE: getHost can return None
Jon Halla440e872016-03-31 15:15:50 -0700597 host1Dict = onosCli.getHost( host1 )
598 host2Dict = onosCli.getHost( host2 )
Jon Hall85794ff2015-07-08 14:12:30 -0700599 host1Id = None
600 host2Id = None
601 if host1Dict and host2Dict:
602 host1Id = host1Dict.get( 'id', None )
603 host2Id = host2Dict.get( 'id', None )
604 if host1Id and host2Id:
Jon Halla440e872016-03-31 15:15:50 -0700605 nodeNum = ( i % len( main.activeNodes ) )
606 node = main.activeNodes[nodeNum]
607 tmpId = main.CLIs[node].addHostIntent( host1Id, host2Id )
Jon Hall85794ff2015-07-08 14:12:30 -0700608 if tmpId:
609 main.log.info( "Added intent with id: " + tmpId )
610 intentIds.append( tmpId )
611 else:
612 main.log.error( "addHostIntent returned: " +
613 repr( tmpId ) )
614 else:
615 main.log.error( "Error, getHost() failed for h" + str( i ) +
616 " and/or h" + str( i + 10 ) )
Jon Halla440e872016-03-31 15:15:50 -0700617 node = main.activeNodes[0]
618 hosts = main.CLIs[node].hosts()
Jon Hall85794ff2015-07-08 14:12:30 -0700619 main.log.warn( "Hosts output: " )
620 try:
621 main.log.warn( json.dumps( json.loads( hosts ),
622 sort_keys=True,
623 indent=4,
624 separators=( ',', ': ' ) ) )
625 except ( ValueError, TypeError ):
626 main.log.warn( repr( hosts ) )
627 hostResult = main.FALSE
628 utilities.assert_equals( expect=main.TRUE, actual=hostResult,
629 onpass="Found a host id for each host",
630 onfail="Error looking up host ids" )
631
632 intentStart = time.time()
Jon Halla440e872016-03-31 15:15:50 -0700633 onosIds = onosCli.getAllIntentsId()
Jon Hall85794ff2015-07-08 14:12:30 -0700634 main.log.info( "Submitted intents: " + str( intentIds ) )
635 main.log.info( "Intents in ONOS: " + str( onosIds ) )
636 for intent in intentIds:
637 if intent in onosIds:
638 pass # intent submitted is in onos
639 else:
640 intentAddResult = False
641 if intentAddResult:
642 intentStop = time.time()
643 else:
644 intentStop = None
645 # Print the intent states
Jon Halla440e872016-03-31 15:15:50 -0700646 intents = onosCli.intents()
Jon Hall85794ff2015-07-08 14:12:30 -0700647 intentStates = []
648 installedCheck = True
649 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
650 count = 0
651 try:
652 for intent in json.loads( intents ):
653 state = intent.get( 'state', None )
654 if "INSTALLED" not in state:
655 installedCheck = False
656 intentId = intent.get( 'id', None )
657 intentStates.append( ( intentId, state ) )
658 except ( ValueError, TypeError ):
659 main.log.exception( "Error parsing intents" )
660 # add submitted intents not in the store
661 tmplist = [ i for i, s in intentStates ]
662 missingIntents = False
663 for i in intentIds:
664 if i not in tmplist:
665 intentStates.append( ( i, " - " ) )
666 missingIntents = True
667 intentStates.sort()
668 for i, s in intentStates:
669 count += 1
670 main.log.info( "%-6s%-15s%-15s" %
671 ( str( count ), str( i ), str( s ) ) )
Jon Halla440e872016-03-31 15:15:50 -0700672 leaders = onosCli.leaders()
Jon Hall85794ff2015-07-08 14:12:30 -0700673 try:
674 missing = False
675 if leaders:
676 parsedLeaders = json.loads( leaders )
677 main.log.warn( json.dumps( parsedLeaders,
678 sort_keys=True,
679 indent=4,
680 separators=( ',', ': ' ) ) )
681 # check for all intent partitions
682 topics = []
683 for i in range( 14 ):
684 topics.append( "intent-partition-" + str( i ) )
685 main.log.debug( topics )
686 ONOStopics = [ j['topic'] for j in parsedLeaders ]
687 for topic in topics:
688 if topic not in ONOStopics:
689 main.log.error( "Error: " + topic +
690 " not in leaders" )
691 missing = True
692 else:
693 main.log.error( "leaders() returned None" )
694 except ( ValueError, TypeError ):
695 main.log.exception( "Error parsing leaders" )
696 main.log.error( repr( leaders ) )
697 # Check all nodes
698 if missing:
Jon Halla440e872016-03-31 15:15:50 -0700699 for i in main.activeNodes:
700 response = main.CLIs[i].leaders( jsonFormat=False)
701 main.log.warn( str( main.CLIs[i].name ) + " leaders output: \n" +
702 str( response ) )
Jon Hall85794ff2015-07-08 14:12:30 -0700703
Jon Halla440e872016-03-31 15:15:50 -0700704 partitions = onosCli.partitions()
Jon Hall85794ff2015-07-08 14:12:30 -0700705 try:
706 if partitions :
707 parsedPartitions = json.loads( partitions )
708 main.log.warn( json.dumps( parsedPartitions,
709 sort_keys=True,
710 indent=4,
711 separators=( ',', ': ' ) ) )
712 # TODO check for a leader in all paritions
713 # TODO check for consistency among nodes
714 else:
715 main.log.error( "partitions() returned None" )
716 except ( ValueError, TypeError ):
717 main.log.exception( "Error parsing partitions" )
718 main.log.error( repr( partitions ) )
Jon Halla440e872016-03-31 15:15:50 -0700719 pendingMap = onosCli.pendingMap()
Jon Hall85794ff2015-07-08 14:12:30 -0700720 try:
721 if pendingMap :
722 parsedPending = json.loads( pendingMap )
723 main.log.warn( json.dumps( parsedPending,
724 sort_keys=True,
725 indent=4,
726 separators=( ',', ': ' ) ) )
727 # TODO check something here?
728 else:
729 main.log.error( "pendingMap() returned None" )
730 except ( ValueError, TypeError ):
731 main.log.exception( "Error parsing pending map" )
732 main.log.error( repr( pendingMap ) )
733
734 intentAddResult = bool( intentAddResult and not missingIntents and
735 installedCheck )
736 if not intentAddResult:
737 main.log.error( "Error in pushing host intents to ONOS" )
738
739 main.step( "Intent Anti-Entropy dispersion" )
Jon Halla440e872016-03-31 15:15:50 -0700740 for j in range(100):
Jon Hall85794ff2015-07-08 14:12:30 -0700741 correct = True
742 main.log.info( "Submitted intents: " + str( sorted( intentIds ) ) )
Jon Halla440e872016-03-31 15:15:50 -0700743 for i in main.activeNodes:
Jon Hall85794ff2015-07-08 14:12:30 -0700744 onosIds = []
Jon Halla440e872016-03-31 15:15:50 -0700745 ids = main.CLIs[i].getAllIntentsId()
Jon Hall85794ff2015-07-08 14:12:30 -0700746 onosIds.append( ids )
Jon Halla440e872016-03-31 15:15:50 -0700747 main.log.debug( "Intents in " + main.CLIs[i].name + ": " +
Jon Hall85794ff2015-07-08 14:12:30 -0700748 str( sorted( onosIds ) ) )
749 if sorted( ids ) != sorted( intentIds ):
750 main.log.warn( "Set of intent IDs doesn't match" )
751 correct = False
752 break
753 else:
Jon Halla440e872016-03-31 15:15:50 -0700754 intents = json.loads( main.CLIs[i].intents() )
Jon Hall85794ff2015-07-08 14:12:30 -0700755 for intent in intents:
756 if intent[ 'state' ] != "INSTALLED":
757 main.log.warn( "Intent " + intent[ 'id' ] +
758 " is " + intent[ 'state' ] )
759 correct = False
760 break
761 if correct:
762 break
763 else:
764 time.sleep(1)
765 if not intentStop:
766 intentStop = time.time()
767 global gossipTime
768 gossipTime = intentStop - intentStart
769 main.log.info( "It took about " + str( gossipTime ) +
770 " seconds for all intents to appear in each node" )
Jon Hallb3ed8ed2015-10-28 16:43:55 -0700771 gossipPeriod = int( main.params['timers']['gossip'] )
Jon Halla440e872016-03-31 15:15:50 -0700772 maxGossipTime = gossipPeriod * len( main.activeNodes )
Jon Hall85794ff2015-07-08 14:12:30 -0700773 utilities.assert_greater_equals(
Jon Hallb3ed8ed2015-10-28 16:43:55 -0700774 expect=maxGossipTime, actual=gossipTime,
Jon Hall85794ff2015-07-08 14:12:30 -0700775 onpass="ECM anti-entropy for intents worked within " +
776 "expected time",
Jon Hallb3ed8ed2015-10-28 16:43:55 -0700777 onfail="Intent ECM anti-entropy took too long. " +
778 "Expected time:{}, Actual time:{}".format( maxGossipTime,
779 gossipTime ) )
780 if gossipTime <= maxGossipTime:
Jon Hall85794ff2015-07-08 14:12:30 -0700781 intentAddResult = True
782
783 if not intentAddResult or "key" in pendingMap:
784 import time
785 installedCheck = True
786 main.log.info( "Sleeping 60 seconds to see if intents are found" )
787 time.sleep( 60 )
Jon Halla440e872016-03-31 15:15:50 -0700788 onosIds = onosCli.getAllIntentsId()
Jon Hall85794ff2015-07-08 14:12:30 -0700789 main.log.info( "Submitted intents: " + str( intentIds ) )
790 main.log.info( "Intents in ONOS: " + str( onosIds ) )
791 # Print the intent states
Jon Halla440e872016-03-31 15:15:50 -0700792 intents = onosCli.intents()
Jon Hall85794ff2015-07-08 14:12:30 -0700793 intentStates = []
794 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
795 count = 0
796 try:
797 for intent in json.loads( intents ):
798 # Iter through intents of a node
799 state = intent.get( 'state', None )
800 if "INSTALLED" not in state:
801 installedCheck = False
802 intentId = intent.get( 'id', None )
803 intentStates.append( ( intentId, state ) )
804 except ( ValueError, TypeError ):
805 main.log.exception( "Error parsing intents" )
806 # add submitted intents not in the store
807 tmplist = [ i for i, s in intentStates ]
808 for i in intentIds:
809 if i not in tmplist:
810 intentStates.append( ( i, " - " ) )
811 intentStates.sort()
812 for i, s in intentStates:
813 count += 1
814 main.log.info( "%-6s%-15s%-15s" %
815 ( str( count ), str( i ), str( s ) ) )
Jon Halla440e872016-03-31 15:15:50 -0700816 leaders = onosCli.leaders()
Jon Hall85794ff2015-07-08 14:12:30 -0700817 try:
818 missing = False
819 if leaders:
820 parsedLeaders = json.loads( leaders )
821 main.log.warn( json.dumps( parsedLeaders,
822 sort_keys=True,
823 indent=4,
824 separators=( ',', ': ' ) ) )
825 # check for all intent partitions
826 # check for election
827 topics = []
828 for i in range( 14 ):
829 topics.append( "intent-partition-" + str( i ) )
830 # FIXME: this should only be after we start the app
831 topics.append( "org.onosproject.election" )
832 main.log.debug( topics )
833 ONOStopics = [ j['topic'] for j in parsedLeaders ]
834 for topic in topics:
835 if topic not in ONOStopics:
836 main.log.error( "Error: " + topic +
837 " not in leaders" )
838 missing = True
839 else:
840 main.log.error( "leaders() returned None" )
841 except ( ValueError, TypeError ):
842 main.log.exception( "Error parsing leaders" )
843 main.log.error( repr( leaders ) )
844 # Check all nodes
845 if missing:
Jon Halla440e872016-03-31 15:15:50 -0700846 for i in main.activeNodes:
847 node = main.CLIs[i]
848 response = node.leaders( jsonFormat=False)
849 main.log.warn( str( node.name ) + " leaders output: \n" +
850 str( response ) )
851
852 partitions = onosCli.partitions()
Jon Hall85794ff2015-07-08 14:12:30 -0700853 try:
854 if partitions :
855 parsedPartitions = json.loads( partitions )
856 main.log.warn( json.dumps( parsedPartitions,
857 sort_keys=True,
858 indent=4,
859 separators=( ',', ': ' ) ) )
860 # TODO check for a leader in all paritions
861 # TODO check for consistency among nodes
862 else:
863 main.log.error( "partitions() returned None" )
864 except ( ValueError, TypeError ):
865 main.log.exception( "Error parsing partitions" )
866 main.log.error( repr( partitions ) )
Jon Halla440e872016-03-31 15:15:50 -0700867 pendingMap = onosCli.pendingMap()
Jon Hall85794ff2015-07-08 14:12:30 -0700868 try:
869 if pendingMap :
870 parsedPending = json.loads( pendingMap )
871 main.log.warn( json.dumps( parsedPending,
872 sort_keys=True,
873 indent=4,
874 separators=( ',', ': ' ) ) )
875 # TODO check something here?
876 else:
877 main.log.error( "pendingMap() returned None" )
878 except ( ValueError, TypeError ):
879 main.log.exception( "Error parsing pending map" )
880 main.log.error( repr( pendingMap ) )
881
882 def CASE4( self, main ):
883 """
884 Ping across added host intents
885 """
886 import json
887 import time
Jon Halle1a3b752015-07-22 13:02:46 -0700888 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall85794ff2015-07-08 14:12:30 -0700889 assert main, "main not defined"
890 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halla440e872016-03-31 15:15:50 -0700891 main.case( "Verify connectivity by sending traffic across Intents" )
Jon Hall783bbf92015-07-23 14:33:19 -0700892 main.caseExplanation = "Ping across added host intents to check " +\
Jon Hall85794ff2015-07-08 14:12:30 -0700893 "functionality and check the state of " +\
894 "the intent"
Jon Hall9d2dcad2016-04-08 10:15:20 -0700895
Jon Hall41d39f12016-04-11 22:54:35 -0700896 onosCli = main.CLIs[ main.activeNodes[0] ]
Jon Hall9d2dcad2016-04-08 10:15:20 -0700897 main.step( "Check Intent state" )
898 installedCheck = True
899 # Print the intent states
900 intents = main.ONOScli1.intents()
901 intentStates = []
902 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
903 count = 0
904 # Iter through intents of a node
905 try:
906 for intent in json.loads( intents ):
907 state = intent.get( 'state', None )
908 if "INSTALLED" not in state:
909 installedCheck = False
910 intentId = intent.get( 'id', None )
911 intentStates.append( ( intentId, state ) )
912 except ( ValueError, TypeError ):
913 main.log.exception( "Error parsing intents." )
914 # Print states
915 intentStates.sort()
916 for i, s in intentStates:
917 count += 1
918 main.log.info( "%-6s%-15s%-15s" %
919 ( str( count ), str( i ), str( s ) ) )
920 utilities.assert_equals( expect=True, actual=installedCheck,
921 onpass="Intents are all INSTALLED",
922 onfail="Intents are not all in " +
923 "INSTALLED state" )
924
Jon Hall85794ff2015-07-08 14:12:30 -0700925 main.step( "Ping across added host intents" )
926 PingResult = main.TRUE
927 for i in range( 8, 18 ):
928 ping = main.Mininet1.pingHost( src="h" + str( i ),
929 target="h" + str( i + 10 ) )
930 PingResult = PingResult and ping
931 if ping == main.FALSE:
932 main.log.warn( "Ping failed between h" + str( i ) +
933 " and h" + str( i + 10 ) )
934 elif ping == main.TRUE:
935 main.log.info( "Ping test passed!" )
936 # Don't set PingResult or you'd override failures
937 if PingResult == main.FALSE:
938 main.log.error(
939 "Intents have not been installed correctly, pings failed." )
940 # TODO: pretty print
941 main.log.warn( "ONOS1 intents: " )
942 try:
Jon Halla440e872016-03-31 15:15:50 -0700943 tmpIntents = onosCli.intents()
Jon Hall85794ff2015-07-08 14:12:30 -0700944 main.log.warn( json.dumps( json.loads( tmpIntents ),
945 sort_keys=True,
946 indent=4,
947 separators=( ',', ': ' ) ) )
948 except ( ValueError, TypeError ):
949 main.log.warn( repr( tmpIntents ) )
950 utilities.assert_equals(
951 expect=main.TRUE,
952 actual=PingResult,
953 onpass="Intents have been installed correctly and pings work",
954 onfail="Intents have not been installed correctly, pings failed." )
955
Jon Hall85794ff2015-07-08 14:12:30 -0700956 main.step( "Check leadership of topics" )
Jon Halla440e872016-03-31 15:15:50 -0700957 leaders = onosCli.leaders()
Jon Hall85794ff2015-07-08 14:12:30 -0700958 topicCheck = main.TRUE
959 try:
960 if leaders:
961 parsedLeaders = json.loads( leaders )
962 main.log.warn( json.dumps( parsedLeaders,
963 sort_keys=True,
964 indent=4,
965 separators=( ',', ': ' ) ) )
966 # check for all intent partitions
967 # check for election
968 # TODO: Look at Devices as topics now that it uses this system
969 topics = []
970 for i in range( 14 ):
971 topics.append( "intent-partition-" + str( i ) )
972 # FIXME: this should only be after we start the app
973 # FIXME: topics.append( "org.onosproject.election" )
974 # Print leaders output
975 main.log.debug( topics )
976 ONOStopics = [ j['topic'] for j in parsedLeaders ]
977 for topic in topics:
978 if topic not in ONOStopics:
979 main.log.error( "Error: " + topic +
980 " not in leaders" )
981 topicCheck = main.FALSE
982 else:
983 main.log.error( "leaders() returned None" )
984 topicCheck = main.FALSE
985 except ( ValueError, TypeError ):
986 topicCheck = main.FALSE
987 main.log.exception( "Error parsing leaders" )
988 main.log.error( repr( leaders ) )
989 # TODO: Check for a leader of these topics
Jon Halla440e872016-03-31 15:15:50 -0700990 # Check all nodes
991 if topicCheck:
992 for i in main.activeNodes:
993 node = main.CLIs[i]
994 response = node.leaders( jsonFormat=False)
995 main.log.warn( str( node.name ) + " leaders output: \n" +
996 str( response ) )
997
Jon Hall85794ff2015-07-08 14:12:30 -0700998 utilities.assert_equals( expect=main.TRUE, actual=topicCheck,
999 onpass="intent Partitions is in leaders",
1000 onfail="Some topics were lost " )
1001 # Print partitions
Jon Halla440e872016-03-31 15:15:50 -07001002 partitions = onosCli.partitions()
Jon Hall85794ff2015-07-08 14:12:30 -07001003 try:
1004 if partitions :
1005 parsedPartitions = json.loads( partitions )
1006 main.log.warn( json.dumps( parsedPartitions,
1007 sort_keys=True,
1008 indent=4,
1009 separators=( ',', ': ' ) ) )
1010 # TODO check for a leader in all paritions
1011 # TODO check for consistency among nodes
1012 else:
1013 main.log.error( "partitions() returned None" )
1014 except ( ValueError, TypeError ):
1015 main.log.exception( "Error parsing partitions" )
1016 main.log.error( repr( partitions ) )
1017 # Print Pending Map
Jon Halla440e872016-03-31 15:15:50 -07001018 pendingMap = onosCli.pendingMap()
Jon Hall85794ff2015-07-08 14:12:30 -07001019 try:
1020 if pendingMap :
1021 parsedPending = json.loads( pendingMap )
1022 main.log.warn( json.dumps( parsedPending,
1023 sort_keys=True,
1024 indent=4,
1025 separators=( ',', ': ' ) ) )
1026 # TODO check something here?
1027 else:
1028 main.log.error( "pendingMap() returned None" )
1029 except ( ValueError, TypeError ):
1030 main.log.exception( "Error parsing pending map" )
1031 main.log.error( repr( pendingMap ) )
1032
1033 if not installedCheck:
1034 main.log.info( "Waiting 60 seconds to see if the state of " +
1035 "intents change" )
1036 time.sleep( 60 )
1037 # Print the intent states
Jon Halla440e872016-03-31 15:15:50 -07001038 intents = onosCli.intents()
Jon Hall85794ff2015-07-08 14:12:30 -07001039 intentStates = []
1040 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
1041 count = 0
1042 # Iter through intents of a node
1043 try:
1044 for intent in json.loads( intents ):
1045 state = intent.get( 'state', None )
1046 if "INSTALLED" not in state:
1047 installedCheck = False
1048 intentId = intent.get( 'id', None )
1049 intentStates.append( ( intentId, state ) )
1050 except ( ValueError, TypeError ):
1051 main.log.exception( "Error parsing intents." )
1052 intentStates.sort()
1053 for i, s in intentStates:
1054 count += 1
1055 main.log.info( "%-6s%-15s%-15s" %
1056 ( str( count ), str( i ), str( s ) ) )
Jon Halla440e872016-03-31 15:15:50 -07001057 leaders = onosCli.leaders()
Jon Hall85794ff2015-07-08 14:12:30 -07001058 try:
1059 missing = False
1060 if leaders:
1061 parsedLeaders = json.loads( leaders )
1062 main.log.warn( json.dumps( parsedLeaders,
1063 sort_keys=True,
1064 indent=4,
1065 separators=( ',', ': ' ) ) )
1066 # check for all intent partitions
1067 # check for election
1068 topics = []
1069 for i in range( 14 ):
1070 topics.append( "intent-partition-" + str( i ) )
1071 # FIXME: this should only be after we start the app
1072 topics.append( "org.onosproject.election" )
1073 main.log.debug( topics )
1074 ONOStopics = [ j['topic'] for j in parsedLeaders ]
1075 for topic in topics:
1076 if topic not in ONOStopics:
1077 main.log.error( "Error: " + topic +
1078 " not in leaders" )
1079 missing = True
1080 else:
1081 main.log.error( "leaders() returned None" )
1082 except ( ValueError, TypeError ):
1083 main.log.exception( "Error parsing leaders" )
1084 main.log.error( repr( leaders ) )
1085 if missing:
Jon Halla440e872016-03-31 15:15:50 -07001086 for i in main.activeNodes:
1087 node = main.CLIs[i]
1088 response = node.leaders( jsonFormat=False)
1089 main.log.warn( str( node.name ) + " leaders output: \n" +
1090 str( response ) )
1091
1092 partitions = onosCli.partitions()
Jon Hall85794ff2015-07-08 14:12:30 -07001093 try:
1094 if partitions :
1095 parsedPartitions = json.loads( partitions )
1096 main.log.warn( json.dumps( parsedPartitions,
1097 sort_keys=True,
1098 indent=4,
1099 separators=( ',', ': ' ) ) )
1100 # TODO check for a leader in all paritions
1101 # TODO check for consistency among nodes
1102 else:
1103 main.log.error( "partitions() returned None" )
1104 except ( ValueError, TypeError ):
1105 main.log.exception( "Error parsing partitions" )
1106 main.log.error( repr( partitions ) )
Jon Halla440e872016-03-31 15:15:50 -07001107 pendingMap = onosCli.pendingMap()
Jon Hall85794ff2015-07-08 14:12:30 -07001108 try:
1109 if pendingMap :
1110 parsedPending = json.loads( pendingMap )
1111 main.log.warn( json.dumps( parsedPending,
1112 sort_keys=True,
1113 indent=4,
1114 separators=( ',', ': ' ) ) )
1115 # TODO check something here?
1116 else:
1117 main.log.error( "pendingMap() returned None" )
1118 except ( ValueError, TypeError ):
1119 main.log.exception( "Error parsing pending map" )
1120 main.log.error( repr( pendingMap ) )
1121 # Print flowrules
Jon Halla440e872016-03-31 15:15:50 -07001122 node = main.activeNodes[0]
1123 main.log.debug( main.CLIs[node].flows( jsonFormat=False ) )
Jon Hall85794ff2015-07-08 14:12:30 -07001124 main.step( "Wait a minute then ping again" )
1125 # the wait is above
1126 PingResult = main.TRUE
1127 for i in range( 8, 18 ):
1128 ping = main.Mininet1.pingHost( src="h" + str( i ),
1129 target="h" + str( i + 10 ) )
1130 PingResult = PingResult and ping
1131 if ping == main.FALSE:
1132 main.log.warn( "Ping failed between h" + str( i ) +
1133 " and h" + str( i + 10 ) )
1134 elif ping == main.TRUE:
1135 main.log.info( "Ping test passed!" )
1136 # Don't set PingResult or you'd override failures
1137 if PingResult == main.FALSE:
1138 main.log.error(
1139 "Intents have not been installed correctly, pings failed." )
1140 # TODO: pretty print
1141 main.log.warn( "ONOS1 intents: " )
1142 try:
Jon Halla440e872016-03-31 15:15:50 -07001143 tmpIntents = onosCli.intents()
Jon Hall85794ff2015-07-08 14:12:30 -07001144 main.log.warn( json.dumps( json.loads( tmpIntents ),
1145 sort_keys=True,
1146 indent=4,
1147 separators=( ',', ': ' ) ) )
1148 except ( ValueError, TypeError ):
1149 main.log.warn( repr( tmpIntents ) )
1150 utilities.assert_equals(
1151 expect=main.TRUE,
1152 actual=PingResult,
1153 onpass="Intents have been installed correctly and pings work",
1154 onfail="Intents have not been installed correctly, pings failed." )
1155
1156 def CASE5( self, main ):
1157 """
1158 Reading state of ONOS
1159 """
1160 import json
Jon Halle1a3b752015-07-22 13:02:46 -07001161 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07001162 assert main, "main not defined"
1163 assert utilities.assert_equals, "utilities.assert_equals not defined"
1164
1165 main.case( "Setting up and gathering data for current state" )
1166 # The general idea for this test case is to pull the state of
1167 # ( intents,flows, topology,... ) from each ONOS node
1168 # We can then compare them with each other and also with past states
1169
1170 main.step( "Check that each switch has a master" )
1171 global mastershipState
1172 mastershipState = '[]'
1173
1174 # Assert that each device has a master
Jon Halla440e872016-03-31 15:15:50 -07001175 rolesNotNull = main.TRUE
1176 threads = []
1177 for i in main.activeNodes:
1178 t = main.Thread( target=main.CLIs[i].rolesNotNull,
1179 name="rolesNotNull-" + str( i ),
1180 args=[] )
1181 threads.append( t )
1182 t.start()
1183
1184 for t in threads:
1185 t.join()
1186 rolesNotNull = rolesNotNull and t.result
Jon Hall85794ff2015-07-08 14:12:30 -07001187 utilities.assert_equals(
1188 expect=main.TRUE,
1189 actual=rolesNotNull,
1190 onpass="Each device has a master",
1191 onfail="Some devices don't have a master assigned" )
1192
1193 main.step( "Get the Mastership of each switch" )
1194 ONOS1Mastership = main.ONOScli1.roles()
1195 # TODO: Make this a meaningful check
1196 if "Error" in ONOS1Mastership or not ONOS1Mastership:
1197 main.log.error( "Error in getting ONOS roles" )
1198 main.log.warn(
1199 "ONOS1 mastership response: " +
1200 repr( ONOS1Mastership ) )
1201 consistentMastership = main.FALSE
1202 else:
1203 mastershipState = ONOS1Mastership
1204 consistentMastership = main.TRUE
1205
1206 main.step( "Get the intents from each controller" )
1207 global intentState
1208 intentState = []
1209 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
1210 intentCheck = main.FALSE
1211 if "Error" in ONOS1Intents or not ONOS1Intents:
1212 main.log.error( "Error in getting ONOS intents" )
1213 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
1214 else:
1215 intentCheck = main.TRUE
1216
1217 main.step( "Get the flows from each controller" )
1218 global flowState
1219 flowState = []
1220 flowCheck = main.FALSE
1221 ONOS1Flows = main.ONOScli1.flows( jsonFormat=True )
1222 if "Error" in ONOS1Flows or not ONOS1Flows:
1223 main.log.error( "Error in getting ONOS flows" )
1224 main.log.warn( "ONOS1 flows repsponse: " + ONOS1Flows )
1225 else:
1226 # TODO: Do a better check, maybe compare flows on switches?
1227 flowState = ONOS1Flows
1228 flowCheck = main.TRUE
1229
1230 main.step( "Get the OF Table entries" )
1231 global flows
1232 flows = []
1233 for i in range( 1, 29 ):
GlennRC68467eb2015-11-16 18:01:01 -08001234 flows.append( main.Mininet1.getFlowTable( "s" + str( i ), version="1.3", debug=False ) )
Jon Hall85794ff2015-07-08 14:12:30 -07001235 if flowCheck == main.FALSE:
1236 for table in flows:
1237 main.log.warn( table )
1238 # TODO: Compare switch flow tables with ONOS flow tables
1239
1240 main.step( "Collecting topology information from ONOS" )
1241 devices = []
1242 devices.append( main.ONOScli1.devices() )
1243 hosts = []
1244 hosts.append( json.loads( main.ONOScli1.hosts() ) )
1245 ports = []
1246 ports.append( main.ONOScli1.ports() )
1247 links = []
1248 links.append( main.ONOScli1.links() )
1249 clusters = []
1250 clusters.append( main.ONOScli1.clusters() )
1251
1252 main.step( "Each host has an IP address" )
1253 ipResult = main.TRUE
1254 for controller in range( 0, len( hosts ) ):
Jon Halla440e872016-03-31 15:15:50 -07001255 controllerStr = str( main.activeNodes[controller] + 1 )
1256 if hosts[ controller ]:
1257 for host in hosts[ controller ]:
1258 if not host.get( 'ipAddresses', [ ] ):
1259 main.log.error( "Error with host ips on controller" +
1260 controllerStr + ": " + str( host ) )
1261 ipResult = main.FALSE
Jon Hall85794ff2015-07-08 14:12:30 -07001262 utilities.assert_equals(
1263 expect=main.TRUE,
1264 actual=ipResult,
1265 onpass="The ips of the hosts aren't empty",
1266 onfail="The ip of at least one host is missing" )
1267
1268 # there should always only be one cluster
1269 main.step( "There is only one dataplane cluster" )
1270 try:
1271 numClusters = len( json.loads( clusters[ 0 ] ) )
1272 except ( ValueError, TypeError ):
1273 main.log.exception( "Error parsing clusters[0]: " +
1274 repr( clusters[ 0 ] ) )
Jon Hall6e709752016-02-01 13:38:46 -08001275 numClusters = "ERROR"
Jon Hall85794ff2015-07-08 14:12:30 -07001276 clusterResults = main.FALSE
1277 if numClusters == 1:
1278 clusterResults = main.TRUE
1279 utilities.assert_equals(
1280 expect=1,
1281 actual=numClusters,
1282 onpass="ONOS shows 1 SCC",
1283 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
1284
1285 main.step( "Comparing ONOS topology to MN" )
1286 devicesResults = main.TRUE
1287 linksResults = main.TRUE
1288 hostsResults = main.TRUE
1289 mnSwitches = main.Mininet1.getSwitches()
1290 mnLinks = main.Mininet1.getLinks()
1291 mnHosts = main.Mininet1.getHosts()
Jon Halla440e872016-03-31 15:15:50 -07001292 for controller in main.activeNodes:
1293 controllerStr = str( main.activeNodes[controller] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07001294 if devices[ controller ] and ports[ controller ] and\
1295 "Error" not in devices[ controller ] and\
1296 "Error" not in ports[ controller ]:
Jon Hall6e709752016-02-01 13:38:46 -08001297 currentDevicesResult = main.Mininet1.compareSwitches(
1298 mnSwitches,
1299 json.loads( devices[ controller ] ),
1300 json.loads( ports[ controller ] ) )
Jon Hall85794ff2015-07-08 14:12:30 -07001301 else:
1302 currentDevicesResult = main.FALSE
1303 utilities.assert_equals( expect=main.TRUE,
1304 actual=currentDevicesResult,
1305 onpass="ONOS" + controllerStr +
1306 " Switches view is correct",
1307 onfail="ONOS" + controllerStr +
1308 " Switches view is incorrect" )
1309 if links[ controller ] and "Error" not in links[ controller ]:
1310 currentLinksResult = main.Mininet1.compareLinks(
1311 mnSwitches, mnLinks,
1312 json.loads( links[ controller ] ) )
1313 else:
1314 currentLinksResult = main.FALSE
1315 utilities.assert_equals( expect=main.TRUE,
1316 actual=currentLinksResult,
1317 onpass="ONOS" + controllerStr +
1318 " links view is correct",
1319 onfail="ONOS" + controllerStr +
1320 " links view is incorrect" )
1321
Jon Halla440e872016-03-31 15:15:50 -07001322 if hosts[ controller ] and "Error" not in hosts[ controller ]:
Jon Hall85794ff2015-07-08 14:12:30 -07001323 currentHostsResult = main.Mininet1.compareHosts(
1324 mnHosts,
1325 hosts[ controller ] )
1326 else:
1327 currentHostsResult = main.FALSE
1328 utilities.assert_equals( expect=main.TRUE,
1329 actual=currentHostsResult,
1330 onpass="ONOS" + controllerStr +
1331 " hosts exist in Mininet",
1332 onfail="ONOS" + controllerStr +
1333 " hosts don't match Mininet" )
1334
1335 devicesResults = devicesResults and currentDevicesResult
1336 linksResults = linksResults and currentLinksResult
1337 hostsResults = hostsResults and currentHostsResult
1338
1339 main.step( "Device information is correct" )
1340 utilities.assert_equals(
1341 expect=main.TRUE,
1342 actual=devicesResults,
1343 onpass="Device information is correct",
1344 onfail="Device information is incorrect" )
1345
1346 main.step( "Links are correct" )
1347 utilities.assert_equals(
1348 expect=main.TRUE,
1349 actual=linksResults,
1350 onpass="Link are correct",
1351 onfail="Links are incorrect" )
1352
1353 main.step( "Hosts are correct" )
1354 utilities.assert_equals(
1355 expect=main.TRUE,
1356 actual=hostsResults,
1357 onpass="Hosts are correct",
1358 onfail="Hosts are incorrect" )
1359
1360 def CASE6( self, main ):
1361 """
1362 The Failure case.
1363 """
1364 import time
Jon Halle1a3b752015-07-22 13:02:46 -07001365 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07001366 assert main, "main not defined"
1367 assert utilities.assert_equals, "utilities.assert_equals not defined"
1368
1369 # Reset non-persistent variables
1370 try:
1371 iCounterValue = 0
1372 except NameError:
1373 main.log.error( "iCounterValue not defined, setting to 0" )
1374 iCounterValue = 0
1375
1376 main.case( "Restart ONOS node" )
Jon Hall783bbf92015-07-23 14:33:19 -07001377 main.caseExplanation = "Killing ONOS process and restart cli " +\
Jon Hall85794ff2015-07-08 14:12:30 -07001378 "sessions once onos is up."
Jon Hall96091e62015-09-21 17:34:17 -07001379
1380 main.step( "Checking ONOS Logs for errors" )
1381 for node in main.nodes:
1382 main.log.debug( "Checking logs for errors on " + node.name + ":" )
1383 main.log.warn( main.ONOSbench.checkLogs( node.ip_address ) )
1384
Jon Hall85794ff2015-07-08 14:12:30 -07001385 main.step( "Killing ONOS processes" )
Jon Halle1a3b752015-07-22 13:02:46 -07001386 killResult = main.ONOSbench.onosKill( main.nodes[0].ip_address )
Jon Hall85794ff2015-07-08 14:12:30 -07001387 start = time.time()
1388 utilities.assert_equals( expect=main.TRUE, actual=killResult,
1389 onpass="ONOS Killed",
1390 onfail="Error killing ONOS" )
1391
1392 main.step( "Checking if ONOS is up yet" )
1393 count = 0
1394 while count < 10:
Jon Halle1a3b752015-07-22 13:02:46 -07001395 onos1Isup = main.ONOSbench.isup( main.nodes[0].ip_address )
Jon Hall85794ff2015-07-08 14:12:30 -07001396 if onos1Isup == main.TRUE:
1397 elapsed = time.time() - start
1398 break
1399 else:
1400 count = count + 1
1401 utilities.assert_equals( expect=main.TRUE, actual=onos1Isup,
1402 onpass="ONOS is back up",
1403 onfail="ONOS failed to start" )
1404
1405 main.log.step( "Starting ONOS CLI sessions" )
Jon Halle1a3b752015-07-22 13:02:46 -07001406 cliResults = main.ONOScli1.startOnosCli( main.nodes[0].ip_address )
Jon Hall85794ff2015-07-08 14:12:30 -07001407 utilities.assert_equals( expect=main.TRUE, actual=cliResults,
1408 onpass="ONOS cli startup successful",
1409 onfail="ONOS cli startup failed" )
1410
1411 if elapsed:
1412 main.log.info( "ESTIMATE: ONOS took %s seconds to restart" %
1413 str( elapsed ) )
1414 main.restartTime = elapsed
1415 else:
1416 main.restartTime = -1
1417 time.sleep( 5 )
1418 # rerun on election apps
1419 main.ONOScli1.electionTestRun()
1420
1421 def CASE7( self, main ):
1422 """
1423 Check state after ONOS failure
1424 """
1425 import json
Jon Halle1a3b752015-07-22 13:02:46 -07001426 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07001427 assert main, "main not defined"
1428 assert utilities.assert_equals, "utilities.assert_equals not defined"
1429 main.case( "Running ONOS Constant State Tests" )
Jon Hall6e709752016-02-01 13:38:46 -08001430
Jon Hall85794ff2015-07-08 14:12:30 -07001431 main.step( "Check that each switch has a master" )
1432 # Assert that each device has a master
Jon Halla440e872016-03-31 15:15:50 -07001433 rolesNotNull = main.TRUE
1434 threads = []
1435 for i in main.activeNodes:
1436 t = main.Thread( target=main.CLIs[i].rolesNotNull,
1437 name="rolesNotNull-" + str( i ),
1438 args=[ ] )
1439 threads.append( t )
1440 t.start()
1441
1442 for t in threads:
1443 t.join()
1444 rolesNotNull = rolesNotNull and t.result
Jon Hall85794ff2015-07-08 14:12:30 -07001445 utilities.assert_equals(
1446 expect=main.TRUE,
1447 actual=rolesNotNull,
1448 onpass="Each device has a master",
1449 onfail="Some devices don't have a master assigned" )
1450
1451 main.step( "Check if switch roles are consistent across all nodes" )
1452 ONOS1Mastership = main.ONOScli1.roles()
1453 # FIXME: Refactor this whole case for single instance
1454 if "Error" in ONOS1Mastership or not ONOS1Mastership:
1455 main.log.error( "Error in getting ONOS mastership" )
1456 main.log.warn( "ONOS1 mastership response: " +
1457 repr( ONOS1Mastership ) )
1458 consistentMastership = main.FALSE
1459 else:
1460 consistentMastership = main.TRUE
1461 utilities.assert_equals(
1462 expect=main.TRUE,
1463 actual=consistentMastership,
1464 onpass="Switch roles are consistent across all ONOS nodes",
1465 onfail="ONOS nodes have different views of switch roles" )
1466
1467 description2 = "Compare switch roles from before failure"
1468 main.step( description2 )
1469
1470 currentJson = json.loads( ONOS1Mastership )
1471 oldJson = json.loads( mastershipState )
1472 mastershipCheck = main.TRUE
1473 for i in range( 1, 29 ):
1474 switchDPID = str(
1475 main.Mininet1.getSwitchDPID( switch="s" + str( i ) ) )
1476
1477 current = [ switch[ 'master' ] for switch in currentJson
1478 if switchDPID in switch[ 'id' ] ]
1479 old = [ switch[ 'master' ] for switch in oldJson
1480 if switchDPID in switch[ 'id' ] ]
1481 if current == old:
1482 mastershipCheck = mastershipCheck and main.TRUE
1483 else:
1484 main.log.warn( "Mastership of switch %s changed" % switchDPID )
1485 mastershipCheck = main.FALSE
1486 utilities.assert_equals(
1487 expect=main.TRUE,
1488 actual=mastershipCheck,
1489 onpass="Mastership of Switches was not changed",
1490 onfail="Mastership of some switches changed" )
1491 mastershipCheck = mastershipCheck and consistentMastership
1492
1493 main.step( "Get the intents and compare across all nodes" )
1494 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
1495 intentCheck = main.FALSE
1496 if "Error" in ONOS1Intents or not ONOS1Intents:
1497 main.log.error( "Error in getting ONOS intents" )
1498 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
1499 else:
1500 intentCheck = main.TRUE
1501 utilities.assert_equals(
1502 expect=main.TRUE,
1503 actual=intentCheck,
1504 onpass="Intents are consistent across all ONOS nodes",
1505 onfail="ONOS nodes have different views of intents" )
1506 # Print the intent states
1507 intents = []
1508 intents.append( ONOS1Intents )
1509 intentStates = []
1510 for node in intents: # Iter through ONOS nodes
1511 nodeStates = []
1512 # Iter through intents of a node
1513 for intent in json.loads( node ):
1514 nodeStates.append( intent[ 'state' ] )
1515 intentStates.append( nodeStates )
1516 out = [ (i, nodeStates.count( i ) ) for i in set( nodeStates ) ]
1517 main.log.info( dict( out ) )
1518
1519 # NOTE: Store has no durability, so intents are lost across system
1520 # restarts
1521 """
1522 main.step( "Compare current intents with intents before the failure" )
1523 # NOTE: this requires case 5 to pass for intentState to be set.
1524 # maybe we should stop the test if that fails?
1525 sameIntents = main.FALSE
Jon Halla440e872016-03-31 15:15:50 -07001526 try:
1527 intentState
1528 except NameError:
1529 main.log.warn( "No previous intent state was saved" )
1530 else:
1531 if intentState and intentState == ONOSIntents[ 0 ]:
1532 sameIntents = main.TRUE
1533 main.log.info( "Intents are consistent with before failure" )
1534 # TODO: possibly the states have changed? we may need to figure out
1535 # what the acceptable states are
1536 elif len( intentState ) == len( ONOSIntents[ 0 ] ):
1537 sameIntents = main.TRUE
1538 try:
1539 before = json.loads( intentState )
1540 after = json.loads( ONOSIntents[ 0 ] )
1541 for intent in before:
1542 if intent not in after:
1543 sameIntents = main.FALSE
1544 main.log.debug( "Intent is not currently in ONOS " +
1545 "(at least in the same form):" )
1546 main.log.debug( json.dumps( intent ) )
1547 except ( ValueError, TypeError ):
1548 main.log.exception( "Exception printing intents" )
1549 main.log.debug( repr( ONOSIntents[0] ) )
1550 main.log.debug( repr( intentState ) )
1551 if sameIntents == main.FALSE:
1552 try:
1553 main.log.debug( "ONOS intents before: " )
1554 main.log.debug( json.dumps( json.loads( intentState ),
1555 sort_keys=True, indent=4,
1556 separators=( ',', ': ' ) ) )
1557 main.log.debug( "Current ONOS intents: " )
1558 main.log.debug( json.dumps( json.loads( ONOSIntents[ 0 ] ),
1559 sort_keys=True, indent=4,
1560 separators=( ',', ': ' ) ) )
1561 except ( ValueError, TypeError ):
1562 main.log.exception( "Exception printing intents" )
1563 main.log.debug( repr( ONOSIntents[0] ) )
1564 main.log.debug( repr( intentState ) )
1565 utilities.assert_equals(
1566 expect=main.TRUE,
1567 actual=sameIntents,
1568 onpass="Intents are consistent with before failure",
1569 onfail="The Intents changed during failure" )
Jon Hall85794ff2015-07-08 14:12:30 -07001570 intentCheck = intentCheck and sameIntents
1571 """
1572 main.step( "Get the OF Table entries and compare to before " +
1573 "component failure" )
1574 FlowTables = main.TRUE
Jon Hall85794ff2015-07-08 14:12:30 -07001575 for i in range( 28 ):
1576 main.log.info( "Checking flow table on s" + str( i + 1 ) )
GlennRC68467eb2015-11-16 18:01:01 -08001577 tmpFlows = main.Mininet1.getFlowTable( "s" + str( i + 1 ), version="1.3", debug=False )
Jon Hall41d39f12016-04-11 22:54:35 -07001578 curSwitch = main.Mininet1.flowTableComp( flows[i], tmpFlows )
1579 FlowTables = FlowTables and curSwitch
1580 if curSwitch == main.FALSE:
GlennRC68467eb2015-11-16 18:01:01 -08001581 main.log.warn( "Differences in flow table for switch: s{}".format( i + 1 ) )
Jon Hall85794ff2015-07-08 14:12:30 -07001582 utilities.assert_equals(
1583 expect=main.TRUE,
1584 actual=FlowTables,
1585 onpass="No changes were found in the flow tables",
1586 onfail="Changes were found in the flow tables" )
1587
1588 main.step( "Leadership Election is still functional" )
1589 # Test of LeadershipElection
1590
Jon Halla440e872016-03-31 15:15:50 -07001591 leader = main.nodes[ main.activeNodes[ 0 ] ].ip_address
Jon Hall85794ff2015-07-08 14:12:30 -07001592 leaderResult = main.TRUE
Jon Halle1a3b752015-07-22 13:02:46 -07001593 for controller in range( 1, main.numCtrls + 1 ):
Jon Hall85794ff2015-07-08 14:12:30 -07001594 # loop through ONOScli handlers
1595 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
1596 leaderN = node.electionTestLeader()
1597 # verify leader is ONOS1
1598 # NOTE even though we restarted ONOS, it is the only one so onos 1
1599 # must be leader
1600 if leaderN == leader:
1601 # all is well
1602 pass
1603 elif leaderN == main.FALSE:
1604 # error in response
1605 main.log.error( "Something is wrong with " +
1606 "electionTestLeader function, check the" +
1607 " error logs" )
1608 leaderResult = main.FALSE
1609 elif leader != leaderN:
1610 leaderResult = main.FALSE
1611 main.log.error( "ONOS" + str( controller ) + " sees " +
1612 str( leaderN ) +
1613 " as the leader of the election app. " +
1614 "Leader should be " + str( leader ) )
1615 utilities.assert_equals(
1616 expect=main.TRUE,
1617 actual=leaderResult,
1618 onpass="Leadership election passed",
1619 onfail="Something went wrong with Leadership election" )
1620
1621 def CASE8( self, main ):
1622 """
1623 Compare topo
1624 """
1625 import json
1626 import time
Jon Halle1a3b752015-07-22 13:02:46 -07001627 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07001628 assert main, "main not defined"
1629 assert utilities.assert_equals, "utilities.assert_equals not defined"
1630
1631 main.case( "Compare ONOS Topology view to Mininet topology" )
Jon Hall783bbf92015-07-23 14:33:19 -07001632 main.caseExplanation = "Compare topology objects between Mininet" +\
Jon Hall85794ff2015-07-08 14:12:30 -07001633 " and ONOS"
Jon Hall85794ff2015-07-08 14:12:30 -07001634 topoResult = main.FALSE
1635 elapsed = 0
1636 count = 0
Jon Halle9b1fa32015-12-08 15:32:21 -08001637 main.step( "Comparing ONOS topology to MN topology" )
Jon Hall85794ff2015-07-08 14:12:30 -07001638 startTime = time.time()
1639 # Give time for Gossip to work
Jon Halle9b1fa32015-12-08 15:32:21 -08001640 while topoResult == main.FALSE and ( elapsed < 60 or count < 3 ):
Jon Hall96091e62015-09-21 17:34:17 -07001641 devicesResults = main.TRUE
1642 linksResults = main.TRUE
1643 hostsResults = main.TRUE
1644 hostAttachmentResults = True
Jon Hall85794ff2015-07-08 14:12:30 -07001645 count += 1
1646 cliStart = time.time()
1647 devices = []
1648 devices.append( main.ONOScli1.devices() )
1649 hosts = []
1650 hosts.append( json.loads( main.ONOScli1.hosts() ) )
1651 ipResult = main.TRUE
1652 for controller in range( 0, len( hosts ) ):
1653 controllerStr = str( controller + 1 )
1654 for host in hosts[ controller ]:
1655 if host is None or host.get( 'ipAddresses', [] ) == []:
1656 main.log.error(
1657 "DEBUG:Error with host ips on controller" +
1658 controllerStr + ": " + str( host ) )
1659 ipResult = main.FALSE
1660 ports = []
1661 ports.append( main.ONOScli1.ports() )
1662 links = []
1663 links.append( main.ONOScli1.links() )
1664 clusters = []
1665 clusters.append( main.ONOScli1.clusters() )
1666
1667 elapsed = time.time() - startTime
1668 cliTime = time.time() - cliStart
1669 print "CLI time: " + str( cliTime )
1670
1671 mnSwitches = main.Mininet1.getSwitches()
1672 mnLinks = main.Mininet1.getLinks()
1673 mnHosts = main.Mininet1.getHosts()
Jon Halle1a3b752015-07-22 13:02:46 -07001674 for controller in range( main.numCtrls ):
Jon Hall85794ff2015-07-08 14:12:30 -07001675 controllerStr = str( controller + 1 )
1676 if devices[ controller ] and ports[ controller ] and\
1677 "Error" not in devices[ controller ] and\
1678 "Error" not in ports[ controller ]:
1679
Jon Hallc6793552016-01-19 14:18:37 -08001680 try:
1681 currentDevicesResult = main.Mininet1.compareSwitches(
1682 mnSwitches,
1683 json.loads( devices[ controller ] ),
1684 json.loads( ports[ controller ] ) )
1685 except ( TypeError, ValueError ) as e:
1686 main.log.exception( "Object not as expected; devices={!r}\nports={!r}".format(
1687 devices[ controller ], ports[ controller ] ) )
Jon Hall85794ff2015-07-08 14:12:30 -07001688 else:
1689 currentDevicesResult = main.FALSE
1690 utilities.assert_equals( expect=main.TRUE,
1691 actual=currentDevicesResult,
1692 onpass="ONOS" + controllerStr +
1693 " Switches view is correct",
1694 onfail="ONOS" + controllerStr +
1695 " Switches view is incorrect" )
1696
1697 if links[ controller ] and "Error" not in links[ controller ]:
1698 currentLinksResult = main.Mininet1.compareLinks(
1699 mnSwitches, mnLinks,
1700 json.loads( links[ controller ] ) )
1701 else:
1702 currentLinksResult = main.FALSE
1703 utilities.assert_equals( expect=main.TRUE,
1704 actual=currentLinksResult,
1705 onpass="ONOS" + controllerStr +
1706 " links view is correct",
1707 onfail="ONOS" + controllerStr +
1708 " links view is incorrect" )
1709
1710 if hosts[ controller ] or "Error" not in hosts[ controller ]:
1711 currentHostsResult = main.Mininet1.compareHosts(
1712 mnHosts,
1713 hosts[ controller ] )
1714 else:
1715 currentHostsResult = main.FALSE
1716 utilities.assert_equals( expect=main.TRUE,
1717 actual=currentHostsResult,
1718 onpass="ONOS" + controllerStr +
1719 " hosts exist in Mininet",
1720 onfail="ONOS" + controllerStr +
1721 " hosts don't match Mininet" )
1722 # CHECKING HOST ATTACHMENT POINTS
1723 hostAttachment = True
1724 zeroHosts = False
1725 # FIXME: topo-HA/obelisk specific mappings:
1726 # key is mac and value is dpid
1727 mappings = {}
1728 for i in range( 1, 29 ): # hosts 1 through 28
1729 # set up correct variables:
1730 macId = "00:" * 5 + hex( i ).split( "0x" )[1].upper().zfill(2)
1731 if i == 1:
1732 deviceId = "1000".zfill(16)
1733 elif i == 2:
1734 deviceId = "2000".zfill(16)
1735 elif i == 3:
1736 deviceId = "3000".zfill(16)
1737 elif i == 4:
1738 deviceId = "3004".zfill(16)
1739 elif i == 5:
1740 deviceId = "5000".zfill(16)
1741 elif i == 6:
1742 deviceId = "6000".zfill(16)
1743 elif i == 7:
1744 deviceId = "6007".zfill(16)
1745 elif i >= 8 and i <= 17:
1746 dpid = '3' + str( i ).zfill( 3 )
1747 deviceId = dpid.zfill(16)
1748 elif i >= 18 and i <= 27:
1749 dpid = '6' + str( i ).zfill( 3 )
1750 deviceId = dpid.zfill(16)
1751 elif i == 28:
1752 deviceId = "2800".zfill(16)
1753 mappings[ macId ] = deviceId
1754 if hosts[ controller ] or "Error" not in hosts[ controller ]:
1755 if hosts[ controller ] == []:
1756 main.log.warn( "There are no hosts discovered" )
1757 zeroHosts = True
1758 else:
1759 for host in hosts[ controller ]:
1760 mac = None
1761 location = None
1762 device = None
1763 port = None
1764 try:
1765 mac = host.get( 'mac' )
1766 assert mac, "mac field could not be found for this host object"
1767
1768 location = host.get( 'location' )
1769 assert location, "location field could not be found for this host object"
1770
1771 # Trim the protocol identifier off deviceId
1772 device = str( location.get( 'elementId' ) ).split(':')[1]
1773 assert device, "elementId field could not be found for this host location object"
1774
1775 port = location.get( 'port' )
1776 assert port, "port field could not be found for this host location object"
1777
1778 # Now check if this matches where they should be
1779 if mac and device and port:
1780 if str( port ) != "1":
1781 main.log.error( "The attachment port is incorrect for " +
1782 "host " + str( mac ) +
1783 ". Expected: 1 Actual: " + str( port) )
1784 hostAttachment = False
1785 if device != mappings[ str( mac ) ]:
1786 main.log.error( "The attachment device is incorrect for " +
1787 "host " + str( mac ) +
1788 ". Expected: " + mappings[ str( mac ) ] +
1789 " Actual: " + device )
1790 hostAttachment = False
1791 else:
1792 hostAttachment = False
1793 except AssertionError:
1794 main.log.exception( "Json object not as expected" )
1795 main.log.error( repr( host ) )
1796 hostAttachment = False
1797 else:
1798 main.log.error( "No hosts json output or \"Error\"" +
1799 " in output. hosts = " +
1800 repr( hosts[ controller ] ) )
1801 if zeroHosts is False:
1802 hostAttachment = True
1803
Jon Hall85794ff2015-07-08 14:12:30 -07001804 devicesResults = devicesResults and currentDevicesResult
1805 linksResults = linksResults and currentLinksResult
1806 hostsResults = hostsResults and currentHostsResult
1807 hostAttachmentResults = hostAttachmentResults and\
1808 hostAttachment
1809
Jon Halla440e872016-03-31 15:15:50 -07001810 # "consistent" results don't make sense for single instance
Jon Hall85794ff2015-07-08 14:12:30 -07001811 # there should always only be one cluster
Jon Hall85794ff2015-07-08 14:12:30 -07001812 clusterResults = main.FALSE
Jon Halla440e872016-03-31 15:15:50 -07001813 try:
1814 numClusters = len( json.loads( clusters[ 0 ] ) )
1815 except ( ValueError, TypeError ):
1816 main.log.exception( "Error parsing clusters[0]: " +
1817 repr( clusters[0] ) )
1818 numClusters = "ERROR"
1819 clusterResults = main.FALSE
Jon Hall85794ff2015-07-08 14:12:30 -07001820 if numClusters == 1:
1821 clusterResults = main.TRUE
1822 utilities.assert_equals(
1823 expect=1,
1824 actual=numClusters,
1825 onpass="ONOS shows 1 SCC",
1826 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
1827
1828 topoResult = ( devicesResults and linksResults
1829 and hostsResults and ipResult and clusterResults and
1830 hostAttachmentResults )
1831
1832 topoResult = topoResult and int( count <= 2 )
1833 note = "note it takes about " + str( int( cliTime ) ) + \
1834 " seconds for the test to make all the cli calls to fetch " +\
1835 "the topology from each ONOS instance"
1836 main.log.info(
1837 "Very crass estimate for topology discovery/convergence( " +
1838 str( note ) + " ): " + str( elapsed ) + " seconds, " +
1839 str( count ) + " tries" )
1840 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
1841 onpass="Topology Check Test successful",
1842 onfail="Topology Check Test NOT successful" )
Jon Hall41d39f12016-04-11 22:54:35 -07001843 main.step( "Checking ONOS nodes" )
1844 nodeResults = utilities.retry( main.HA.nodesCheck,
1845 False,
1846 args=[main.activeNodes],
1847 attempts=5 )
1848
1849 utilities.assert_equals( expect=True, actual=nodeResults,
1850 onpass="Nodes check successful",
1851 onfail="Nodes check NOT successful" )
1852 if not nodeResults:
1853 for i in main.activeNodes:
1854 main.log.debug( "{} components not ACTIVE: \n{}".format(
1855 main.CLIs[i].name,
1856 main.CLIs[i].sendline( "scr:list | grep -v ACTIVE" ) ) )
Jon Hall85794ff2015-07-08 14:12:30 -07001857
1858 def CASE9( self, main ):
1859 """
1860 Link s3-s28 down
1861 """
1862 import time
Jon Halle1a3b752015-07-22 13:02:46 -07001863 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07001864 assert main, "main not defined"
1865 assert utilities.assert_equals, "utilities.assert_equals not defined"
1866 # NOTE: You should probably run a topology check after this
1867
1868 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
1869
1870 description = "Turn off a link to ensure that Link Discovery " +\
1871 "is working properly"
1872 main.case( description )
1873
1874 main.step( "Kill Link between s3 and s28" )
1875 LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" )
1876 main.log.info( "Waiting " + str( linkSleep ) +
1877 " seconds for link down to be discovered" )
1878 time.sleep( linkSleep )
1879 utilities.assert_equals( expect=main.TRUE, actual=LinkDown,
1880 onpass="Link down successful",
1881 onfail="Failed to bring link down" )
1882 # TODO do some sort of check here
1883
1884 def CASE10( self, main ):
1885 """
1886 Link s3-s28 up
1887 """
1888 import time
Jon Halle1a3b752015-07-22 13:02:46 -07001889 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07001890 assert main, "main not defined"
1891 assert utilities.assert_equals, "utilities.assert_equals not defined"
1892 # NOTE: You should probably run a topology check after this
1893
1894 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
1895
1896 description = "Restore a link to ensure that Link Discovery is " + \
1897 "working properly"
1898 main.case( description )
1899
1900 main.step( "Bring link between s3 and s28 back up" )
1901 LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" )
1902 main.log.info( "Waiting " + str( linkSleep ) +
1903 " seconds for link up to be discovered" )
1904 time.sleep( linkSleep )
1905 utilities.assert_equals( expect=main.TRUE, actual=LinkUp,
1906 onpass="Link up successful",
1907 onfail="Failed to bring link up" )
1908 # TODO do some sort of check here
1909
1910 def CASE11( self, main ):
1911 """
1912 Switch Down
1913 """
1914 # NOTE: You should probably run a topology check after this
1915 import time
Jon Halle1a3b752015-07-22 13:02:46 -07001916 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07001917 assert main, "main not defined"
1918 assert utilities.assert_equals, "utilities.assert_equals not defined"
1919
1920 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
1921
1922 description = "Killing a switch to ensure it is discovered correctly"
Jon Halla440e872016-03-31 15:15:50 -07001923 onosCli = main.CLIs[ main.activeNodes[0] ]
Jon Hall85794ff2015-07-08 14:12:30 -07001924 main.case( description )
1925 switch = main.params[ 'kill' ][ 'switch' ]
1926 switchDPID = main.params[ 'kill' ][ 'dpid' ]
1927
1928 # TODO: Make this switch parameterizable
1929 main.step( "Kill " + switch )
1930 main.log.info( "Deleting " + switch )
1931 main.Mininet1.delSwitch( switch )
1932 main.log.info( "Waiting " + str( switchSleep ) +
1933 " seconds for switch down to be discovered" )
1934 time.sleep( switchSleep )
Jon Halla440e872016-03-31 15:15:50 -07001935 device = onosCli.getDevice( dpid=switchDPID )
Jon Hall85794ff2015-07-08 14:12:30 -07001936 # Peek at the deleted switch
1937 main.log.warn( str( device ) )
1938 result = main.FALSE
1939 if device and device[ 'available' ] is False:
1940 result = main.TRUE
1941 utilities.assert_equals( expect=main.TRUE, actual=result,
1942 onpass="Kill switch successful",
1943 onfail="Failed to kill switch?" )
1944
1945 def CASE12( self, main ):
1946 """
1947 Switch Up
1948 """
1949 # NOTE: You should probably run a topology check after this
1950 import time
Jon Halle1a3b752015-07-22 13:02:46 -07001951 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07001952 assert main, "main not defined"
1953 assert utilities.assert_equals, "utilities.assert_equals not defined"
1954
1955 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
1956 switch = main.params[ 'kill' ][ 'switch' ]
1957 switchDPID = main.params[ 'kill' ][ 'dpid' ]
1958 links = main.params[ 'kill' ][ 'links' ].split()
Jon Halla440e872016-03-31 15:15:50 -07001959 onosCli = main.CLIs[ main.activeNodes[0] ]
Jon Hall85794ff2015-07-08 14:12:30 -07001960 description = "Adding a switch to ensure it is discovered correctly"
1961 main.case( description )
1962
1963 main.step( "Add back " + switch )
1964 main.Mininet1.addSwitch( switch, dpid=switchDPID )
1965 for peer in links:
1966 main.Mininet1.addLink( switch, peer )
Jon Halla440e872016-03-31 15:15:50 -07001967 ipList = [ node.ip_address for node in main.nodes ]
Jon Hall85794ff2015-07-08 14:12:30 -07001968 main.Mininet1.assignSwController( sw=switch, ip=ipList )
1969 main.log.info( "Waiting " + str( switchSleep ) +
1970 " seconds for switch up to be discovered" )
1971 time.sleep( switchSleep )
Jon Halla440e872016-03-31 15:15:50 -07001972 device = onosCli.getDevice( dpid=switchDPID )
Jon Hall85794ff2015-07-08 14:12:30 -07001973 # Peek at the deleted switch
1974 main.log.warn( str( device ) )
1975 result = main.FALSE
1976 if device and device[ 'available' ]:
1977 result = main.TRUE
1978 utilities.assert_equals( expect=main.TRUE, actual=result,
1979 onpass="add switch successful",
1980 onfail="Failed to add switch?" )
1981
1982 def CASE13( self, main ):
1983 """
1984 Clean up
1985 """
1986 import os
1987 import time
Jon Halle1a3b752015-07-22 13:02:46 -07001988 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07001989 assert main, "main not defined"
1990 assert utilities.assert_equals, "utilities.assert_equals not defined"
1991 # printing colors to terminal
1992 colors = { 'cyan': '\033[96m', 'purple': '\033[95m',
1993 'blue': '\033[94m', 'green': '\033[92m',
1994 'yellow': '\033[93m', 'red': '\033[91m', 'end': '\033[0m' }
1995 main.case( "Test Cleanup" )
1996 main.step( "Killing tcpdumps" )
1997 main.Mininet2.stopTcpdump()
1998
1999 testname = main.TEST
Jon Hall96091e62015-09-21 17:34:17 -07002000 if main.params[ 'BACKUP' ][ 'ENABLED' ] == "True":
Jon Hall85794ff2015-07-08 14:12:30 -07002001 main.step( "Copying MN pcap and ONOS log files to test station" )
2002 teststationUser = main.params[ 'BACKUP' ][ 'TESTONUSER' ]
2003 teststationIP = main.params[ 'BACKUP' ][ 'TESTONIP' ]
Jon Hall96091e62015-09-21 17:34:17 -07002004 # NOTE: MN Pcap file is being saved to logdir.
2005 # We scp this file as MN and TestON aren't necessarily the same vm
2006
2007 # FIXME: To be replaced with a Jenkin's post script
Jon Hall85794ff2015-07-08 14:12:30 -07002008 # TODO: Load these from params
2009 # NOTE: must end in /
2010 logFolder = "/opt/onos/log/"
2011 logFiles = [ "karaf.log", "karaf.log.1" ]
2012 # NOTE: must end in /
Jon Hall85794ff2015-07-08 14:12:30 -07002013 for f in logFiles:
Jon Hall96091e62015-09-21 17:34:17 -07002014 for node in main.nodes:
Jon Halla440e872016-03-31 15:15:50 -07002015 dstName = main.logdir + "/" + node.name + "-" + f
Jon Hall96091e62015-09-21 17:34:17 -07002016 main.ONOSbench.secureCopy( node.user_name, node.ip_address,
2017 logFolder + f, dstName )
Jon Hall85794ff2015-07-08 14:12:30 -07002018 # std*.log's
2019 # NOTE: must end in /
2020 logFolder = "/opt/onos/var/"
2021 logFiles = [ "stderr.log", "stdout.log" ]
2022 # NOTE: must end in /
Jon Hall85794ff2015-07-08 14:12:30 -07002023 for f in logFiles:
Jon Hall96091e62015-09-21 17:34:17 -07002024 for node in main.nodes:
Jon Halla440e872016-03-31 15:15:50 -07002025 dstName = main.logdir + "/" + node.name + "-" + f
Jon Hall96091e62015-09-21 17:34:17 -07002026 main.ONOSbench.secureCopy( node.user_name, node.ip_address,
2027 logFolder + f, dstName )
2028 else:
2029 main.log.debug( "skipping saving log files" )
Jon Hall85794ff2015-07-08 14:12:30 -07002030
Jon Hall85794ff2015-07-08 14:12:30 -07002031 main.step( "Stopping Mininet" )
2032 mnResult = main.Mininet1.stopNet()
2033 utilities.assert_equals( expect=main.TRUE, actual=mnResult,
2034 onpass="Mininet stopped",
2035 onfail="MN cleanup NOT successful" )
2036
2037 main.step( "Checking ONOS Logs for errors" )
Jon Hall96091e62015-09-21 17:34:17 -07002038 for node in main.nodes:
2039 main.log.debug( "Checking logs for errors on " + node.name + ":" )
2040 main.log.warn( main.ONOSbench.checkLogs( node.ip_address ) )
Jon Hall85794ff2015-07-08 14:12:30 -07002041
2042 try:
2043 timerLog = open( main.logdir + "/Timers.csv", 'w')
2044 # Overwrite with empty line and close
2045 labels = "Gossip Intents, Restart"
2046 data = str( gossipTime ) + ", " + str( main.restartTime )
2047 timerLog.write( labels + "\n" + data )
2048 timerLog.close()
2049 except NameError, e:
2050 main.log.exception(e)
2051
2052 def CASE14( self, main ):
2053 """
2054 start election app on all onos nodes
2055 """
Jon Halle1a3b752015-07-22 13:02:46 -07002056 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07002057 assert main, "main not defined"
2058 assert utilities.assert_equals, "utilities.assert_equals not defined"
2059
2060 main.case("Start Leadership Election app")
2061 main.step( "Install leadership election app" )
Jon Halla440e872016-03-31 15:15:50 -07002062 onosCli = main.CLIs[ main.activeNodes[0] ]
2063 appResult = onosCli.activateApp( "org.onosproject.election" )
Jon Hall85794ff2015-07-08 14:12:30 -07002064 utilities.assert_equals(
2065 expect=main.TRUE,
2066 actual=appResult,
2067 onpass="Election app installed",
2068 onfail="Something went wrong with installing Leadership election" )
2069
2070 main.step( "Run for election on each node" )
Jon Halla440e872016-03-31 15:15:50 -07002071 leaderResult = main.TRUE
2072 leaders = []
2073 for i in main.activeNodes:
2074 main.CLIs[i].electionTestRun()
2075 for i in main.activeNodes:
2076 cli = main.CLIs[i]
2077 leader = cli.electionTestLeader()
2078 if leader is None or leader == main.FALSE:
2079 main.log.error( cli.name + ": Leader for the election app " +
2080 "should be an ONOS node, instead got '" +
2081 str( leader ) + "'" )
2082 leaderResult = main.FALSE
2083 leaders.append( leader )
Jon Hall85794ff2015-07-08 14:12:30 -07002084 utilities.assert_equals(
2085 expect=main.TRUE,
2086 actual=leaderResult,
2087 onpass="Successfully ran for leadership",
2088 onfail="Failed to run for leadership" )
2089
2090 def CASE15( self, main ):
2091 """
2092 Check that Leadership Election is still functional
acsmars71adceb2015-08-31 15:09:26 -07002093 15.1 Run election on each node
2094 15.2 Check that each node has the same leaders and candidates
2095 15.3 Find current leader and withdraw
2096 15.4 Check that a new node was elected leader
2097 15.5 Check that that new leader was the candidate of old leader
2098 15.6 Run for election on old leader
2099 15.7 Check that oldLeader is a candidate, and leader if only 1 node
2100 15.8 Make sure that the old leader was added to the candidate list
2101
2102 old and new variable prefixes refer to data from before vs after
2103 withdrawl and later before withdrawl vs after re-election
Jon Hall85794ff2015-07-08 14:12:30 -07002104 """
acsmars71adceb2015-08-31 15:09:26 -07002105 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002106 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07002107 assert main, "main not defined"
2108 assert utilities.assert_equals, "utilities.assert_equals not defined"
acsmars71adceb2015-08-31 15:09:26 -07002109 assert main.CLIs, "main.CLIs not defined"
2110 assert main.nodes, "main.nodes not defined"
2111
Jon Hall85794ff2015-07-08 14:12:30 -07002112 description = "Check that Leadership Election is still functional"
2113 main.case( description )
Jon Halla440e872016-03-31 15:15:50 -07002114 # NOTE: Need to re-run after restarts since being a canidate is not persistant
acsmars2c2fcdd2015-08-25 17:14:13 -07002115
Jon Halla440e872016-03-31 15:15:50 -07002116 oldLeaders = [] # list of lists of each nodes' candidates before
2117 newLeaders = [] # list of lists of each nodes' candidates after
acsmars71adceb2015-08-31 15:09:26 -07002118 oldLeader = '' # the old leader from oldLeaders, None if not same
2119 newLeader = '' # the new leaders fron newLoeaders, None if not same
2120 oldLeaderCLI = None # the CLI of the old leader used for re-electing
2121 expectNoLeader = False # True when there is only one leader
2122 if main.numCtrls == 1:
2123 expectNoLeader = True
acsmars2c2fcdd2015-08-25 17:14:13 -07002124
acsmars71adceb2015-08-31 15:09:26 -07002125 main.step( "Run for election on each node" )
2126 electionResult = main.TRUE
2127
Jon Halla440e872016-03-31 15:15:50 -07002128 for i in main.activeNodes: # run test election on each node
2129 if main.CLIs[i].electionTestRun() == main.FALSE:
acsmars71adceb2015-08-31 15:09:26 -07002130 electionResult = main.FALSE
acsmars71adceb2015-08-31 15:09:26 -07002131 utilities.assert_equals(
2132 expect=main.TRUE,
2133 actual=electionResult,
2134 onpass="All nodes successfully ran for leadership",
2135 onfail="At least one node failed to run for leadership" )
2136
acsmars3a72bde2015-09-02 14:16:22 -07002137 if electionResult == main.FALSE:
2138 main.log.error(
2139 "Skipping Test Case because Election Test App isn't loaded" )
2140 main.skipCase()
2141
acsmars71adceb2015-08-31 15:09:26 -07002142 main.step( "Check that each node shows the same leader and candidates" )
Jon Halla440e872016-03-31 15:15:50 -07002143 failMessage = "Nodes have different leaderboards"
Jon Halla440e872016-03-31 15:15:50 -07002144 activeCLIs = [ main.CLIs[i] for i in main.activeNodes ]
Jon Hall41d39f12016-04-11 22:54:35 -07002145 sameResult, oldLeaders = main.HA.consistentLeaderboards( activeCLIs )
Jon Halla440e872016-03-31 15:15:50 -07002146 if sameResult:
2147 oldLeader = oldLeaders[ 0 ][ 0 ]
2148 main.log.warn( oldLeader )
Jon Hall85794ff2015-07-08 14:12:30 -07002149 else:
Jon Halla440e872016-03-31 15:15:50 -07002150 oldLeader = None
acsmars71adceb2015-08-31 15:09:26 -07002151 utilities.assert_equals(
Jon Halla440e872016-03-31 15:15:50 -07002152 expect=True,
acsmars71adceb2015-08-31 15:09:26 -07002153 actual=sameResult,
Jon Halla440e872016-03-31 15:15:50 -07002154 onpass="Leaderboards are consistent for the election topic",
acsmars71adceb2015-08-31 15:09:26 -07002155 onfail=failMessage )
2156
2157 main.step( "Find current leader and withdraw" )
2158 withdrawResult = main.TRUE
2159 # do some sanity checking on leader before using it
2160 if oldLeader is None:
2161 main.log.error( "Leadership isn't consistent." )
2162 withdrawResult = main.FALSE
2163 # Get the CLI of the oldLeader
Jon Halla440e872016-03-31 15:15:50 -07002164 for i in main.activeNodes:
acsmars71adceb2015-08-31 15:09:26 -07002165 if oldLeader == main.nodes[ i ].ip_address:
2166 oldLeaderCLI = main.CLIs[ i ]
2167 break
2168 else: # FOR/ELSE statement
2169 main.log.error( "Leader election, could not find current leader" )
Jon Hall85794ff2015-07-08 14:12:30 -07002170 if oldLeader:
acsmars71adceb2015-08-31 15:09:26 -07002171 withdrawResult = oldLeaderCLI.electionTestWithdraw()
Jon Hall85794ff2015-07-08 14:12:30 -07002172 utilities.assert_equals(
2173 expect=main.TRUE,
2174 actual=withdrawResult,
2175 onpass="Node was withdrawn from election",
2176 onfail="Node was not withdrawn from election" )
2177
acsmars71adceb2015-08-31 15:09:26 -07002178 main.step( "Check that a new node was elected leader" )
acsmars71adceb2015-08-31 15:09:26 -07002179 failMessage = "Nodes have different leaders"
acsmars71adceb2015-08-31 15:09:26 -07002180 # Get new leaders and candidates
Jon Hall41d39f12016-04-11 22:54:35 -07002181 newLeaderResult, newLeaders = main.HA.consistentLeaderboards( activeCLIs )
Jon Hall3a7843a2016-04-12 03:01:09 -07002182 newLeader = None
Jon Halla440e872016-03-31 15:15:50 -07002183 if newLeaderResult:
Jon Hall3a7843a2016-04-12 03:01:09 -07002184 if newLeaders[ 0 ][ 0 ] == 'none':
2185 main.log.error( "No leader was elected on at least 1 node" )
2186 if not expectNoLeader:
2187 newLeaderResult = False
2188 else:
2189 newLeader = newLeaders[ 0 ][ 0 ]
acsmars71adceb2015-08-31 15:09:26 -07002190
2191 # Check that the new leader is not the older leader, which was withdrawn
2192 if newLeader == oldLeader:
Jon Halla440e872016-03-31 15:15:50 -07002193 newLeaderResult = False
2194 main.log.error( "All nodes still see old leader: " + str( oldLeader ) +
acsmars71adceb2015-08-31 15:09:26 -07002195 " as the current leader" )
Jon Hall85794ff2015-07-08 14:12:30 -07002196 utilities.assert_equals(
Jon Halla440e872016-03-31 15:15:50 -07002197 expect=True,
acsmars71adceb2015-08-31 15:09:26 -07002198 actual=newLeaderResult,
2199 onpass="Leadership election passed",
2200 onfail="Something went wrong with Leadership election" )
Jon Hall85794ff2015-07-08 14:12:30 -07002201
Jon Halla440e872016-03-31 15:15:50 -07002202 main.step( "Check that that new leader was the candidate of old leader" )
2203 # candidates[ 2 ] should become the top candidate after withdrawl
acsmars71adceb2015-08-31 15:09:26 -07002204 correctCandidateResult = main.TRUE
2205 if expectNoLeader:
2206 if newLeader == 'none':
2207 main.log.info( "No leader expected. None found. Pass" )
2208 correctCandidateResult = main.TRUE
2209 else:
2210 main.log.info( "Expected no leader, got: " + str( newLeader ) )
2211 correctCandidateResult = main.FALSE
Jon Halla440e872016-03-31 15:15:50 -07002212 elif len( oldLeaders[0] ) >= 3:
2213 if newLeader == oldLeaders[ 0 ][ 2 ]:
2214 # correct leader was elected
2215 correctCandidateResult = main.TRUE
2216 else:
2217 correctCandidateResult = main.FALSE
2218 main.log.error( "Candidate {} was elected. {} should have had priority.".format(
2219 newLeader, oldLeaders[ 0 ][ 2 ] ) )
2220 else:
2221 main.log.warn( "Could not determine who should be the correct leader" )
2222 main.log.debug( oldLeaders[ 0 ] )
acsmars71adceb2015-08-31 15:09:26 -07002223 correctCandidateResult = main.FALSE
acsmars71adceb2015-08-31 15:09:26 -07002224 utilities.assert_equals(
2225 expect=main.TRUE,
2226 actual=correctCandidateResult,
2227 onpass="Correct Candidate Elected",
2228 onfail="Incorrect Candidate Elected" )
2229
Jon Hall85794ff2015-07-08 14:12:30 -07002230 main.step( "Run for election on old leader( just so everyone " +
2231 "is in the hat )" )
acsmars71adceb2015-08-31 15:09:26 -07002232 if oldLeaderCLI is not None:
2233 runResult = oldLeaderCLI.electionTestRun()
Jon Hall85794ff2015-07-08 14:12:30 -07002234 else:
acsmars71adceb2015-08-31 15:09:26 -07002235 main.log.error( "No old leader to re-elect" )
Jon Hall85794ff2015-07-08 14:12:30 -07002236 runResult = main.FALSE
2237 utilities.assert_equals(
2238 expect=main.TRUE,
2239 actual=runResult,
2240 onpass="App re-ran for election",
2241 onfail="App failed to run for election" )
Jon Halla440e872016-03-31 15:15:50 -07002242
acsmars71adceb2015-08-31 15:09:26 -07002243 main.step(
2244 "Check that oldLeader is a candidate, and leader if only 1 node" )
2245 # verify leader didn't just change
Jon Halla440e872016-03-31 15:15:50 -07002246 # Get new leaders and candidates
2247 reRunLeaders = []
2248 time.sleep( 5 ) # Paremterize
Jon Hall41d39f12016-04-11 22:54:35 -07002249 positionResult, reRunLeaders = main.HA.consistentLeaderboards( activeCLIs )
acsmars71adceb2015-08-31 15:09:26 -07002250
2251 # Check that the re-elected node is last on the candidate List
Jon Hall3a7843a2016-04-12 03:01:09 -07002252 if not reRunLeaders[0]:
2253 positionResult = main.FALSE
2254 elif oldLeader != reRunLeaders[ 0 ][ -1 ]:
Jon Halla440e872016-03-31 15:15:50 -07002255 main.log.error( "Old Leader ({}) not in the proper position: {} ".format( str( oldLeader),
2256 str( reRunLeaders[ 0 ] ) ) )
acsmars71adceb2015-08-31 15:09:26 -07002257 positionResult = main.FALSE
Jon Hall85794ff2015-07-08 14:12:30 -07002258 utilities.assert_equals(
Jon Halla440e872016-03-31 15:15:50 -07002259 expect=True,
acsmars71adceb2015-08-31 15:09:26 -07002260 actual=positionResult,
Jon Hall85794ff2015-07-08 14:12:30 -07002261 onpass="Old leader successfully re-ran for election",
2262 onfail="Something went wrong with Leadership election after " +
2263 "the old leader re-ran for election" )
2264
2265 def CASE16( self, main ):
2266 """
2267 Install Distributed Primitives app
2268 """
Jon Halla440e872016-03-31 15:15:50 -07002269 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002270 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07002271 assert main, "main not defined"
2272 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002273 assert main.CLIs, "main.CLIs not defined"
2274 assert main.nodes, "main.nodes not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07002275
2276 # Variables for the distributed primitives tests
2277 global pCounterName
Jon Hall85794ff2015-07-08 14:12:30 -07002278 global pCounterValue
Jon Hall85794ff2015-07-08 14:12:30 -07002279 global onosSet
2280 global onosSetName
2281 pCounterName = "TestON-Partitions"
Jon Hall85794ff2015-07-08 14:12:30 -07002282 pCounterValue = 0
Jon Hall85794ff2015-07-08 14:12:30 -07002283 onosSet = set([])
2284 onosSetName = "TestON-set"
2285
2286 description = "Install Primitives app"
2287 main.case( description )
2288 main.step( "Install Primitives app" )
2289 appName = "org.onosproject.distributedprimitives"
Jon Halla440e872016-03-31 15:15:50 -07002290 node = main.activeNodes[0]
2291 appResults = main.CLIs[node].activateApp( appName )
Jon Hall85794ff2015-07-08 14:12:30 -07002292 utilities.assert_equals( expect=main.TRUE,
2293 actual=appResults,
2294 onpass="Primitives app activated",
2295 onfail="Primitives app not activated" )
Jon Halla440e872016-03-31 15:15:50 -07002296 time.sleep( 5 ) # To allow all nodes to activate
Jon Hall85794ff2015-07-08 14:12:30 -07002297
2298 def CASE17( self, main ):
2299 """
2300 Check for basic functionality with distributed primitives
2301 """
Jon Hall85794ff2015-07-08 14:12:30 -07002302 # Make sure variables are defined/set
Jon Halle1a3b752015-07-22 13:02:46 -07002303 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07002304 assert main, "main not defined"
2305 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002306 assert main.CLIs, "main.CLIs not defined"
2307 assert main.nodes, "main.nodes not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07002308 assert pCounterName, "pCounterName not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07002309 assert onosSetName, "onosSetName not defined"
2310 # NOTE: assert fails if value is 0/None/Empty/False
2311 try:
2312 pCounterValue
2313 except NameError:
2314 main.log.error( "pCounterValue not defined, setting to 0" )
2315 pCounterValue = 0
2316 try:
Jon Hall85794ff2015-07-08 14:12:30 -07002317 onosSet
2318 except NameError:
2319 main.log.error( "onosSet not defined, setting to empty Set" )
2320 onosSet = set([])
2321 # Variables for the distributed primitives tests. These are local only
2322 addValue = "a"
2323 addAllValue = "a b c d e f"
2324 retainValue = "c d e f"
2325
2326 description = "Check for basic functionality with distributed " +\
2327 "primitives"
2328 main.case( description )
Jon Halle1a3b752015-07-22 13:02:46 -07002329 main.caseExplanation = "Test the methods of the distributed " +\
2330 "primitives (counters and sets) throught the cli"
Jon Hall85794ff2015-07-08 14:12:30 -07002331 # DISTRIBUTED ATOMIC COUNTERS
Jon Halle1a3b752015-07-22 13:02:46 -07002332 # Partitioned counters
2333 main.step( "Increment then get a default counter on each node" )
Jon Hall85794ff2015-07-08 14:12:30 -07002334 pCounters = []
2335 threads = []
2336 addedPValues = []
Jon Halla440e872016-03-31 15:15:50 -07002337 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002338 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
2339 name="counterAddAndGet-" + str( i ),
Jon Hall85794ff2015-07-08 14:12:30 -07002340 args=[ pCounterName ] )
2341 pCounterValue += 1
2342 addedPValues.append( pCounterValue )
2343 threads.append( t )
2344 t.start()
2345
2346 for t in threads:
2347 t.join()
2348 pCounters.append( t.result )
2349 # Check that counter incremented numController times
2350 pCounterResults = True
2351 for i in addedPValues:
2352 tmpResult = i in pCounters
2353 pCounterResults = pCounterResults and tmpResult
2354 if not tmpResult:
2355 main.log.error( str( i ) + " is not in partitioned "
2356 "counter incremented results" )
2357 utilities.assert_equals( expect=True,
2358 actual=pCounterResults,
2359 onpass="Default counter incremented",
2360 onfail="Error incrementing default" +
2361 " counter" )
2362
Jon Halle1a3b752015-07-22 13:02:46 -07002363 main.step( "Get then Increment a default counter on each node" )
2364 pCounters = []
2365 threads = []
2366 addedPValues = []
Jon Halla440e872016-03-31 15:15:50 -07002367 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002368 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
2369 name="counterGetAndAdd-" + str( i ),
2370 args=[ pCounterName ] )
2371 addedPValues.append( pCounterValue )
2372 pCounterValue += 1
2373 threads.append( t )
2374 t.start()
2375
2376 for t in threads:
2377 t.join()
2378 pCounters.append( t.result )
2379 # Check that counter incremented numController times
2380 pCounterResults = True
2381 for i in addedPValues:
2382 tmpResult = i in pCounters
2383 pCounterResults = pCounterResults and tmpResult
2384 if not tmpResult:
2385 main.log.error( str( i ) + " is not in partitioned "
2386 "counter incremented results" )
2387 utilities.assert_equals( expect=True,
2388 actual=pCounterResults,
2389 onpass="Default counter incremented",
2390 onfail="Error incrementing default" +
2391 " counter" )
2392
2393 main.step( "Counters we added have the correct values" )
Jon Hall41d39f12016-04-11 22:54:35 -07002394 incrementCheck = main.HA.counterCheck( pCounterName, pCounterValue )
Jon Halle1a3b752015-07-22 13:02:46 -07002395 utilities.assert_equals( expect=main.TRUE,
2396 actual=incrementCheck,
2397 onpass="Added counters are correct",
2398 onfail="Added counters are incorrect" )
2399
2400 main.step( "Add -8 to then get a default counter on each node" )
2401 pCounters = []
2402 threads = []
2403 addedPValues = []
Jon Halla440e872016-03-31 15:15:50 -07002404 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002405 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
2406 name="counterIncrement-" + str( i ),
2407 args=[ pCounterName ],
2408 kwargs={ "delta": -8 } )
2409 pCounterValue += -8
2410 addedPValues.append( pCounterValue )
2411 threads.append( t )
2412 t.start()
2413
2414 for t in threads:
2415 t.join()
2416 pCounters.append( t.result )
2417 # Check that counter incremented numController times
2418 pCounterResults = True
2419 for i in addedPValues:
2420 tmpResult = i in pCounters
2421 pCounterResults = pCounterResults and tmpResult
2422 if not tmpResult:
2423 main.log.error( str( i ) + " is not in partitioned "
2424 "counter incremented results" )
2425 utilities.assert_equals( expect=True,
2426 actual=pCounterResults,
2427 onpass="Default counter incremented",
2428 onfail="Error incrementing default" +
2429 " counter" )
2430
2431 main.step( "Add 5 to then get a default counter on each node" )
2432 pCounters = []
2433 threads = []
2434 addedPValues = []
Jon Halla440e872016-03-31 15:15:50 -07002435 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002436 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
2437 name="counterIncrement-" + str( i ),
2438 args=[ pCounterName ],
2439 kwargs={ "delta": 5 } )
2440 pCounterValue += 5
2441 addedPValues.append( pCounterValue )
2442 threads.append( t )
2443 t.start()
2444
2445 for t in threads:
2446 t.join()
2447 pCounters.append( t.result )
2448 # Check that counter incremented numController times
2449 pCounterResults = True
2450 for i in addedPValues:
2451 tmpResult = i in pCounters
2452 pCounterResults = pCounterResults and tmpResult
2453 if not tmpResult:
2454 main.log.error( str( i ) + " is not in partitioned "
2455 "counter incremented results" )
2456 utilities.assert_equals( expect=True,
2457 actual=pCounterResults,
2458 onpass="Default counter incremented",
2459 onfail="Error incrementing default" +
2460 " counter" )
2461
2462 main.step( "Get then add 5 to a default counter on each node" )
2463 pCounters = []
2464 threads = []
2465 addedPValues = []
Jon Halla440e872016-03-31 15:15:50 -07002466 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002467 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
2468 name="counterIncrement-" + str( i ),
2469 args=[ pCounterName ],
2470 kwargs={ "delta": 5 } )
2471 addedPValues.append( pCounterValue )
2472 pCounterValue += 5
2473 threads.append( t )
2474 t.start()
2475
2476 for t in threads:
2477 t.join()
2478 pCounters.append( t.result )
2479 # Check that counter incremented numController times
2480 pCounterResults = True
2481 for i in addedPValues:
2482 tmpResult = i in pCounters
2483 pCounterResults = pCounterResults and tmpResult
2484 if not tmpResult:
2485 main.log.error( str( i ) + " is not in partitioned "
2486 "counter incremented results" )
2487 utilities.assert_equals( expect=True,
2488 actual=pCounterResults,
2489 onpass="Default counter incremented",
2490 onfail="Error incrementing default" +
2491 " counter" )
2492
2493 main.step( "Counters we added have the correct values" )
Jon Hall41d39f12016-04-11 22:54:35 -07002494 incrementCheck = main.HA.counterCheck( pCounterName, pCounterValue )
Jon Halle1a3b752015-07-22 13:02:46 -07002495 utilities.assert_equals( expect=main.TRUE,
2496 actual=incrementCheck,
2497 onpass="Added counters are correct",
2498 onfail="Added counters are incorrect" )
2499
Jon Hall85794ff2015-07-08 14:12:30 -07002500 # DISTRIBUTED SETS
2501 main.step( "Distributed Set get" )
2502 size = len( onosSet )
2503 getResponses = []
2504 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002505 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002506 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07002507 name="setTestGet-" + str( i ),
2508 args=[ onosSetName ] )
2509 threads.append( t )
2510 t.start()
2511 for t in threads:
2512 t.join()
2513 getResponses.append( t.result )
2514
2515 getResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002516 for i in range( len( main.activeNodes ) ):
2517 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07002518 if isinstance( getResponses[ i ], list):
2519 current = set( getResponses[ i ] )
2520 if len( current ) == len( getResponses[ i ] ):
2521 # no repeats
2522 if onosSet != current:
Jon Halla440e872016-03-31 15:15:50 -07002523 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07002524 " has incorrect view" +
2525 " of set " + onosSetName + ":\n" +
2526 str( getResponses[ i ] ) )
2527 main.log.debug( "Expected: " + str( onosSet ) )
2528 main.log.debug( "Actual: " + str( current ) )
2529 getResults = main.FALSE
2530 else:
2531 # error, set is not a set
Jon Halla440e872016-03-31 15:15:50 -07002532 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07002533 " has repeat elements in" +
2534 " set " + onosSetName + ":\n" +
2535 str( getResponses[ i ] ) )
2536 getResults = main.FALSE
2537 elif getResponses[ i ] == main.ERROR:
2538 getResults = main.FALSE
2539 utilities.assert_equals( expect=main.TRUE,
2540 actual=getResults,
2541 onpass="Set elements are correct",
2542 onfail="Set elements are incorrect" )
2543
2544 main.step( "Distributed Set size" )
2545 sizeResponses = []
2546 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002547 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002548 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall85794ff2015-07-08 14:12:30 -07002549 name="setTestSize-" + str( i ),
2550 args=[ onosSetName ] )
2551 threads.append( t )
2552 t.start()
2553 for t in threads:
2554 t.join()
2555 sizeResponses.append( t.result )
2556
2557 sizeResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002558 for i in range( len( main.activeNodes ) ):
2559 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07002560 if size != sizeResponses[ i ]:
2561 sizeResults = main.FALSE
Jon Halla440e872016-03-31 15:15:50 -07002562 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07002563 " expected a size of " + str( size ) +
2564 " for set " + onosSetName +
2565 " but got " + str( sizeResponses[ i ] ) )
2566 utilities.assert_equals( expect=main.TRUE,
2567 actual=sizeResults,
2568 onpass="Set sizes are correct",
2569 onfail="Set sizes are incorrect" )
2570
2571 main.step( "Distributed Set add()" )
2572 onosSet.add( addValue )
2573 addResponses = []
2574 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002575 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002576 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall85794ff2015-07-08 14:12:30 -07002577 name="setTestAdd-" + str( i ),
2578 args=[ onosSetName, addValue ] )
2579 threads.append( t )
2580 t.start()
2581 for t in threads:
2582 t.join()
2583 addResponses.append( t.result )
2584
2585 # main.TRUE = successfully changed the set
2586 # main.FALSE = action resulted in no change in set
2587 # main.ERROR - Some error in executing the function
2588 addResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002589 for i in range( len( main.activeNodes ) ):
Jon Hall85794ff2015-07-08 14:12:30 -07002590 if addResponses[ i ] == main.TRUE:
2591 # All is well
2592 pass
2593 elif addResponses[ i ] == main.FALSE:
2594 # Already in set, probably fine
2595 pass
2596 elif addResponses[ i ] == main.ERROR:
2597 # Error in execution
2598 addResults = main.FALSE
2599 else:
2600 # unexpected result
2601 addResults = main.FALSE
2602 if addResults != main.TRUE:
2603 main.log.error( "Error executing set add" )
2604
2605 # Check if set is still correct
2606 size = len( onosSet )
2607 getResponses = []
2608 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002609 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002610 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07002611 name="setTestGet-" + str( i ),
2612 args=[ onosSetName ] )
2613 threads.append( t )
2614 t.start()
2615 for t in threads:
2616 t.join()
2617 getResponses.append( t.result )
2618 getResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002619 for i in range( len( main.activeNodes ) ):
2620 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07002621 if isinstance( getResponses[ i ], list):
2622 current = set( getResponses[ i ] )
2623 if len( current ) == len( getResponses[ i ] ):
2624 # no repeats
2625 if onosSet != current:
Jon Halla440e872016-03-31 15:15:50 -07002626 main.log.error( "ONOS" + node + " has incorrect view" +
Jon Hall85794ff2015-07-08 14:12:30 -07002627 " of set " + onosSetName + ":\n" +
2628 str( getResponses[ i ] ) )
2629 main.log.debug( "Expected: " + str( onosSet ) )
2630 main.log.debug( "Actual: " + str( current ) )
2631 getResults = main.FALSE
2632 else:
2633 # error, set is not a set
Jon Halla440e872016-03-31 15:15:50 -07002634 main.log.error( "ONOS" + node + " has repeat elements in" +
Jon Hall85794ff2015-07-08 14:12:30 -07002635 " set " + onosSetName + ":\n" +
2636 str( getResponses[ i ] ) )
2637 getResults = main.FALSE
2638 elif getResponses[ i ] == main.ERROR:
2639 getResults = main.FALSE
2640 sizeResponses = []
2641 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002642 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002643 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall85794ff2015-07-08 14:12:30 -07002644 name="setTestSize-" + str( i ),
2645 args=[ onosSetName ] )
2646 threads.append( t )
2647 t.start()
2648 for t in threads:
2649 t.join()
2650 sizeResponses.append( t.result )
2651 sizeResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002652 for i in range( len( main.activeNodes ) ):
2653 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07002654 if size != sizeResponses[ i ]:
2655 sizeResults = main.FALSE
Jon Halla440e872016-03-31 15:15:50 -07002656 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07002657 " expected a size of " + str( size ) +
2658 " for set " + onosSetName +
2659 " but got " + str( sizeResponses[ i ] ) )
2660 addResults = addResults and getResults and sizeResults
2661 utilities.assert_equals( expect=main.TRUE,
2662 actual=addResults,
2663 onpass="Set add correct",
2664 onfail="Set add was incorrect" )
2665
2666 main.step( "Distributed Set addAll()" )
2667 onosSet.update( addAllValue.split() )
2668 addResponses = []
2669 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002670 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002671 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall85794ff2015-07-08 14:12:30 -07002672 name="setTestAddAll-" + str( i ),
2673 args=[ onosSetName, addAllValue ] )
2674 threads.append( t )
2675 t.start()
2676 for t in threads:
2677 t.join()
2678 addResponses.append( t.result )
2679
2680 # main.TRUE = successfully changed the set
2681 # main.FALSE = action resulted in no change in set
2682 # main.ERROR - Some error in executing the function
2683 addAllResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002684 for i in range( len( main.activeNodes ) ):
Jon Hall85794ff2015-07-08 14:12:30 -07002685 if addResponses[ i ] == main.TRUE:
2686 # All is well
2687 pass
2688 elif addResponses[ i ] == main.FALSE:
2689 # Already in set, probably fine
2690 pass
2691 elif addResponses[ i ] == main.ERROR:
2692 # Error in execution
2693 addAllResults = main.FALSE
2694 else:
2695 # unexpected result
2696 addAllResults = main.FALSE
2697 if addAllResults != main.TRUE:
2698 main.log.error( "Error executing set addAll" )
2699
2700 # Check if set is still correct
2701 size = len( onosSet )
2702 getResponses = []
2703 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002704 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002705 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07002706 name="setTestGet-" + str( i ),
2707 args=[ onosSetName ] )
2708 threads.append( t )
2709 t.start()
2710 for t in threads:
2711 t.join()
2712 getResponses.append( t.result )
2713 getResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002714 for i in range( len( main.activeNodes ) ):
2715 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07002716 if isinstance( getResponses[ i ], list):
2717 current = set( getResponses[ i ] )
2718 if len( current ) == len( getResponses[ i ] ):
2719 # no repeats
2720 if onosSet != current:
Jon Halla440e872016-03-31 15:15:50 -07002721 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07002722 " has incorrect view" +
2723 " of set " + onosSetName + ":\n" +
2724 str( getResponses[ i ] ) )
2725 main.log.debug( "Expected: " + str( onosSet ) )
2726 main.log.debug( "Actual: " + str( current ) )
2727 getResults = main.FALSE
2728 else:
2729 # error, set is not a set
Jon Halla440e872016-03-31 15:15:50 -07002730 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07002731 " has repeat elements in" +
2732 " set " + onosSetName + ":\n" +
2733 str( getResponses[ i ] ) )
2734 getResults = main.FALSE
2735 elif getResponses[ i ] == main.ERROR:
2736 getResults = main.FALSE
2737 sizeResponses = []
2738 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002739 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002740 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall85794ff2015-07-08 14:12:30 -07002741 name="setTestSize-" + str( i ),
2742 args=[ onosSetName ] )
2743 threads.append( t )
2744 t.start()
2745 for t in threads:
2746 t.join()
2747 sizeResponses.append( t.result )
2748 sizeResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002749 for i in range( len( main.activeNodes ) ):
2750 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07002751 if size != sizeResponses[ i ]:
2752 sizeResults = main.FALSE
Jon Halla440e872016-03-31 15:15:50 -07002753 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07002754 " expected a size of " + str( size ) +
2755 " for set " + onosSetName +
2756 " but got " + str( sizeResponses[ i ] ) )
2757 addAllResults = addAllResults and getResults and sizeResults
2758 utilities.assert_equals( expect=main.TRUE,
2759 actual=addAllResults,
2760 onpass="Set addAll correct",
2761 onfail="Set addAll was incorrect" )
2762
2763 main.step( "Distributed Set contains()" )
2764 containsResponses = []
2765 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002766 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002767 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07002768 name="setContains-" + str( i ),
2769 args=[ onosSetName ],
2770 kwargs={ "values": addValue } )
2771 threads.append( t )
2772 t.start()
2773 for t in threads:
2774 t.join()
2775 # NOTE: This is the tuple
2776 containsResponses.append( t.result )
2777
2778 containsResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002779 for i in range( len( main.activeNodes ) ):
Jon Hall85794ff2015-07-08 14:12:30 -07002780 if containsResponses[ i ] == main.ERROR:
2781 containsResults = main.FALSE
2782 else:
2783 containsResults = containsResults and\
2784 containsResponses[ i ][ 1 ]
2785 utilities.assert_equals( expect=main.TRUE,
2786 actual=containsResults,
2787 onpass="Set contains is functional",
2788 onfail="Set contains failed" )
2789
2790 main.step( "Distributed Set containsAll()" )
2791 containsAllResponses = []
2792 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002793 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002794 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07002795 name="setContainsAll-" + str( i ),
2796 args=[ onosSetName ],
2797 kwargs={ "values": addAllValue } )
2798 threads.append( t )
2799 t.start()
2800 for t in threads:
2801 t.join()
2802 # NOTE: This is the tuple
2803 containsAllResponses.append( t.result )
2804
2805 containsAllResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002806 for i in range( len( main.activeNodes ) ):
Jon Hall85794ff2015-07-08 14:12:30 -07002807 if containsResponses[ i ] == main.ERROR:
2808 containsResults = main.FALSE
2809 else:
2810 containsResults = containsResults and\
2811 containsResponses[ i ][ 1 ]
2812 utilities.assert_equals( expect=main.TRUE,
2813 actual=containsAllResults,
2814 onpass="Set containsAll is functional",
2815 onfail="Set containsAll failed" )
2816
2817 main.step( "Distributed Set remove()" )
2818 onosSet.remove( addValue )
2819 removeResponses = []
2820 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002821 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002822 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall85794ff2015-07-08 14:12:30 -07002823 name="setTestRemove-" + str( i ),
2824 args=[ onosSetName, addValue ] )
2825 threads.append( t )
2826 t.start()
2827 for t in threads:
2828 t.join()
2829 removeResponses.append( t.result )
2830
2831 # main.TRUE = successfully changed the set
2832 # main.FALSE = action resulted in no change in set
2833 # main.ERROR - Some error in executing the function
2834 removeResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002835 for i in range( len( main.activeNodes ) ):
Jon Hall85794ff2015-07-08 14:12:30 -07002836 if removeResponses[ i ] == main.TRUE:
2837 # All is well
2838 pass
2839 elif removeResponses[ i ] == main.FALSE:
2840 # not in set, probably fine
2841 pass
2842 elif removeResponses[ i ] == main.ERROR:
2843 # Error in execution
2844 removeResults = main.FALSE
2845 else:
2846 # unexpected result
2847 removeResults = main.FALSE
2848 if removeResults != main.TRUE:
2849 main.log.error( "Error executing set remove" )
2850
2851 # Check if set is still correct
2852 size = len( onosSet )
2853 getResponses = []
2854 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002855 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002856 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07002857 name="setTestGet-" + str( i ),
2858 args=[ onosSetName ] )
2859 threads.append( t )
2860 t.start()
2861 for t in threads:
2862 t.join()
2863 getResponses.append( t.result )
2864 getResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002865 for i in range( len( main.activeNodes ) ):
2866 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07002867 if isinstance( getResponses[ i ], list):
2868 current = set( getResponses[ i ] )
2869 if len( current ) == len( getResponses[ i ] ):
2870 # no repeats
2871 if onosSet != current:
Jon Halla440e872016-03-31 15:15:50 -07002872 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07002873 " has incorrect view" +
2874 " of set " + onosSetName + ":\n" +
2875 str( getResponses[ i ] ) )
2876 main.log.debug( "Expected: " + str( onosSet ) )
2877 main.log.debug( "Actual: " + str( current ) )
2878 getResults = main.FALSE
2879 else:
2880 # error, set is not a set
Jon Halla440e872016-03-31 15:15:50 -07002881 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07002882 " has repeat elements in" +
2883 " set " + onosSetName + ":\n" +
2884 str( getResponses[ i ] ) )
2885 getResults = main.FALSE
2886 elif getResponses[ i ] == main.ERROR:
2887 getResults = main.FALSE
2888 sizeResponses = []
2889 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002890 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002891 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall85794ff2015-07-08 14:12:30 -07002892 name="setTestSize-" + str( i ),
2893 args=[ onosSetName ] )
2894 threads.append( t )
2895 t.start()
2896 for t in threads:
2897 t.join()
2898 sizeResponses.append( t.result )
2899 sizeResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002900 for i in range( len( main.activeNodes ) ):
2901 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07002902 if size != sizeResponses[ i ]:
2903 sizeResults = main.FALSE
Jon Halla440e872016-03-31 15:15:50 -07002904 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07002905 " expected a size of " + str( size ) +
2906 " for set " + onosSetName +
2907 " but got " + str( sizeResponses[ i ] ) )
2908 removeResults = removeResults and getResults and sizeResults
2909 utilities.assert_equals( expect=main.TRUE,
2910 actual=removeResults,
2911 onpass="Set remove correct",
2912 onfail="Set remove was incorrect" )
2913
2914 main.step( "Distributed Set removeAll()" )
2915 onosSet.difference_update( addAllValue.split() )
2916 removeAllResponses = []
2917 threads = []
2918 try:
Jon Halla440e872016-03-31 15:15:50 -07002919 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002920 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall85794ff2015-07-08 14:12:30 -07002921 name="setTestRemoveAll-" + str( i ),
2922 args=[ onosSetName, addAllValue ] )
2923 threads.append( t )
2924 t.start()
2925 for t in threads:
2926 t.join()
2927 removeAllResponses.append( t.result )
2928 except Exception, e:
2929 main.log.exception(e)
2930
2931 # main.TRUE = successfully changed the set
2932 # main.FALSE = action resulted in no change in set
2933 # main.ERROR - Some error in executing the function
2934 removeAllResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002935 for i in range( len( main.activeNodes ) ):
Jon Hall85794ff2015-07-08 14:12:30 -07002936 if removeAllResponses[ i ] == main.TRUE:
2937 # All is well
2938 pass
2939 elif removeAllResponses[ i ] == main.FALSE:
2940 # not in set, probably fine
2941 pass
2942 elif removeAllResponses[ i ] == main.ERROR:
2943 # Error in execution
2944 removeAllResults = main.FALSE
2945 else:
2946 # unexpected result
2947 removeAllResults = main.FALSE
2948 if removeAllResults != main.TRUE:
2949 main.log.error( "Error executing set removeAll" )
2950
2951 # Check if set is still correct
2952 size = len( onosSet )
2953 getResponses = []
2954 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002955 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002956 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07002957 name="setTestGet-" + str( i ),
2958 args=[ onosSetName ] )
2959 threads.append( t )
2960 t.start()
2961 for t in threads:
2962 t.join()
2963 getResponses.append( t.result )
2964 getResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002965 for i in range( len( main.activeNodes ) ):
2966 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07002967 if isinstance( getResponses[ i ], list):
2968 current = set( getResponses[ i ] )
2969 if len( current ) == len( getResponses[ i ] ):
2970 # no repeats
2971 if onosSet != current:
Jon Halla440e872016-03-31 15:15:50 -07002972 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07002973 " has incorrect view" +
2974 " of set " + onosSetName + ":\n" +
2975 str( getResponses[ i ] ) )
2976 main.log.debug( "Expected: " + str( onosSet ) )
2977 main.log.debug( "Actual: " + str( current ) )
2978 getResults = main.FALSE
2979 else:
2980 # error, set is not a set
Jon Halla440e872016-03-31 15:15:50 -07002981 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07002982 " has repeat elements in" +
2983 " set " + onosSetName + ":\n" +
2984 str( getResponses[ i ] ) )
2985 getResults = main.FALSE
2986 elif getResponses[ i ] == main.ERROR:
2987 getResults = main.FALSE
2988 sizeResponses = []
2989 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002990 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002991 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall85794ff2015-07-08 14:12:30 -07002992 name="setTestSize-" + str( i ),
2993 args=[ onosSetName ] )
2994 threads.append( t )
2995 t.start()
2996 for t in threads:
2997 t.join()
2998 sizeResponses.append( t.result )
2999 sizeResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07003000 for i in range( len( main.activeNodes ) ):
3001 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07003002 if size != sizeResponses[ i ]:
3003 sizeResults = main.FALSE
Jon Halla440e872016-03-31 15:15:50 -07003004 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07003005 " expected a size of " + str( size ) +
3006 " for set " + onosSetName +
3007 " but got " + str( sizeResponses[ i ] ) )
3008 removeAllResults = removeAllResults and getResults and sizeResults
3009 utilities.assert_equals( expect=main.TRUE,
3010 actual=removeAllResults,
3011 onpass="Set removeAll correct",
3012 onfail="Set removeAll was incorrect" )
3013
3014 main.step( "Distributed Set addAll()" )
3015 onosSet.update( addAllValue.split() )
3016 addResponses = []
3017 threads = []
Jon Halla440e872016-03-31 15:15:50 -07003018 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07003019 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall85794ff2015-07-08 14:12:30 -07003020 name="setTestAddAll-" + str( i ),
3021 args=[ onosSetName, addAllValue ] )
3022 threads.append( t )
3023 t.start()
3024 for t in threads:
3025 t.join()
3026 addResponses.append( t.result )
3027
3028 # main.TRUE = successfully changed the set
3029 # main.FALSE = action resulted in no change in set
3030 # main.ERROR - Some error in executing the function
3031 addAllResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07003032 for i in range( len( main.activeNodes ) ):
Jon Hall85794ff2015-07-08 14:12:30 -07003033 if addResponses[ i ] == main.TRUE:
3034 # All is well
3035 pass
3036 elif addResponses[ i ] == main.FALSE:
3037 # Already in set, probably fine
3038 pass
3039 elif addResponses[ i ] == main.ERROR:
3040 # Error in execution
3041 addAllResults = main.FALSE
3042 else:
3043 # unexpected result
3044 addAllResults = main.FALSE
3045 if addAllResults != main.TRUE:
3046 main.log.error( "Error executing set addAll" )
3047
3048 # Check if set is still correct
3049 size = len( onosSet )
3050 getResponses = []
3051 threads = []
Jon Halla440e872016-03-31 15:15:50 -07003052 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07003053 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07003054 name="setTestGet-" + str( i ),
3055 args=[ onosSetName ] )
3056 threads.append( t )
3057 t.start()
3058 for t in threads:
3059 t.join()
3060 getResponses.append( t.result )
3061 getResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07003062 for i in range( len( main.activeNodes ) ):
3063 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07003064 if isinstance( getResponses[ i ], list):
3065 current = set( getResponses[ i ] )
3066 if len( current ) == len( getResponses[ i ] ):
3067 # no repeats
3068 if onosSet != current:
Jon Halla440e872016-03-31 15:15:50 -07003069 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07003070 " has incorrect view" +
3071 " of set " + onosSetName + ":\n" +
3072 str( getResponses[ i ] ) )
3073 main.log.debug( "Expected: " + str( onosSet ) )
3074 main.log.debug( "Actual: " + str( current ) )
3075 getResults = main.FALSE
3076 else:
3077 # error, set is not a set
Jon Halla440e872016-03-31 15:15:50 -07003078 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07003079 " has repeat elements in" +
3080 " set " + onosSetName + ":\n" +
3081 str( getResponses[ i ] ) )
3082 getResults = main.FALSE
3083 elif getResponses[ i ] == main.ERROR:
3084 getResults = main.FALSE
3085 sizeResponses = []
3086 threads = []
Jon Halla440e872016-03-31 15:15:50 -07003087 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07003088 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall85794ff2015-07-08 14:12:30 -07003089 name="setTestSize-" + str( i ),
3090 args=[ onosSetName ] )
3091 threads.append( t )
3092 t.start()
3093 for t in threads:
3094 t.join()
3095 sizeResponses.append( t.result )
3096 sizeResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07003097 for i in range( len( main.activeNodes ) ):
3098 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07003099 if size != sizeResponses[ i ]:
3100 sizeResults = main.FALSE
Jon Halla440e872016-03-31 15:15:50 -07003101 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07003102 " expected a size of " + str( size ) +
3103 " for set " + onosSetName +
3104 " but got " + str( sizeResponses[ i ] ) )
3105 addAllResults = addAllResults and getResults and sizeResults
3106 utilities.assert_equals( expect=main.TRUE,
3107 actual=addAllResults,
3108 onpass="Set addAll correct",
3109 onfail="Set addAll was incorrect" )
3110
3111 main.step( "Distributed Set clear()" )
3112 onosSet.clear()
3113 clearResponses = []
3114 threads = []
Jon Halla440e872016-03-31 15:15:50 -07003115 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07003116 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall85794ff2015-07-08 14:12:30 -07003117 name="setTestClear-" + str( i ),
3118 args=[ onosSetName, " "], # Values doesn't matter
3119 kwargs={ "clear": True } )
3120 threads.append( t )
3121 t.start()
3122 for t in threads:
3123 t.join()
3124 clearResponses.append( t.result )
3125
3126 # main.TRUE = successfully changed the set
3127 # main.FALSE = action resulted in no change in set
3128 # main.ERROR - Some error in executing the function
3129 clearResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07003130 for i in range( len( main.activeNodes ) ):
Jon Hall85794ff2015-07-08 14:12:30 -07003131 if clearResponses[ i ] == main.TRUE:
3132 # All is well
3133 pass
3134 elif clearResponses[ i ] == main.FALSE:
3135 # Nothing set, probably fine
3136 pass
3137 elif clearResponses[ i ] == main.ERROR:
3138 # Error in execution
3139 clearResults = main.FALSE
3140 else:
3141 # unexpected result
3142 clearResults = main.FALSE
3143 if clearResults != main.TRUE:
3144 main.log.error( "Error executing set clear" )
3145
3146 # Check if set is still correct
3147 size = len( onosSet )
3148 getResponses = []
3149 threads = []
Jon Halla440e872016-03-31 15:15:50 -07003150 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07003151 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07003152 name="setTestGet-" + str( i ),
3153 args=[ onosSetName ] )
3154 threads.append( t )
3155 t.start()
3156 for t in threads:
3157 t.join()
3158 getResponses.append( t.result )
3159 getResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07003160 for i in range( len( main.activeNodes ) ):
3161 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07003162 if isinstance( getResponses[ i ], list):
3163 current = set( getResponses[ i ] )
3164 if len( current ) == len( getResponses[ i ] ):
3165 # no repeats
3166 if onosSet != current:
Jon Halla440e872016-03-31 15:15:50 -07003167 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07003168 " has incorrect view" +
3169 " of set " + onosSetName + ":\n" +
3170 str( getResponses[ i ] ) )
3171 main.log.debug( "Expected: " + str( onosSet ) )
3172 main.log.debug( "Actual: " + str( current ) )
3173 getResults = main.FALSE
3174 else:
3175 # error, set is not a set
Jon Halla440e872016-03-31 15:15:50 -07003176 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07003177 " has repeat elements in" +
3178 " set " + onosSetName + ":\n" +
3179 str( getResponses[ i ] ) )
3180 getResults = main.FALSE
3181 elif getResponses[ i ] == main.ERROR:
3182 getResults = main.FALSE
3183 sizeResponses = []
3184 threads = []
Jon Halla440e872016-03-31 15:15:50 -07003185 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07003186 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall85794ff2015-07-08 14:12:30 -07003187 name="setTestSize-" + str( i ),
3188 args=[ onosSetName ] )
3189 threads.append( t )
3190 t.start()
3191 for t in threads:
3192 t.join()
3193 sizeResponses.append( t.result )
3194 sizeResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07003195 for i in range( len( main.activeNodes ) ):
3196 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07003197 if size != sizeResponses[ i ]:
3198 sizeResults = main.FALSE
Jon Halla440e872016-03-31 15:15:50 -07003199 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07003200 " expected a size of " + str( size ) +
3201 " for set " + onosSetName +
3202 " but got " + str( sizeResponses[ i ] ) )
3203 clearResults = clearResults and getResults and sizeResults
3204 utilities.assert_equals( expect=main.TRUE,
3205 actual=clearResults,
3206 onpass="Set clear correct",
3207 onfail="Set clear was incorrect" )
3208
3209 main.step( "Distributed Set addAll()" )
3210 onosSet.update( addAllValue.split() )
3211 addResponses = []
3212 threads = []
Jon Halla440e872016-03-31 15:15:50 -07003213 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07003214 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall85794ff2015-07-08 14:12:30 -07003215 name="setTestAddAll-" + str( i ),
3216 args=[ onosSetName, addAllValue ] )
3217 threads.append( t )
3218 t.start()
3219 for t in threads:
3220 t.join()
3221 addResponses.append( t.result )
3222
3223 # main.TRUE = successfully changed the set
3224 # main.FALSE = action resulted in no change in set
3225 # main.ERROR - Some error in executing the function
3226 addAllResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07003227 for i in range( len( main.activeNodes ) ):
Jon Hall85794ff2015-07-08 14:12:30 -07003228 if addResponses[ i ] == main.TRUE:
3229 # All is well
3230 pass
3231 elif addResponses[ i ] == main.FALSE:
3232 # Already in set, probably fine
3233 pass
3234 elif addResponses[ i ] == main.ERROR:
3235 # Error in execution
3236 addAllResults = main.FALSE
3237 else:
3238 # unexpected result
3239 addAllResults = main.FALSE
3240 if addAllResults != main.TRUE:
3241 main.log.error( "Error executing set addAll" )
3242
3243 # Check if set is still correct
3244 size = len( onosSet )
3245 getResponses = []
3246 threads = []
Jon Halla440e872016-03-31 15:15:50 -07003247 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07003248 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07003249 name="setTestGet-" + str( i ),
3250 args=[ onosSetName ] )
3251 threads.append( t )
3252 t.start()
3253 for t in threads:
3254 t.join()
3255 getResponses.append( t.result )
3256 getResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07003257 for i in range( len( main.activeNodes ) ):
3258 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07003259 if isinstance( getResponses[ i ], list):
3260 current = set( getResponses[ i ] )
3261 if len( current ) == len( getResponses[ i ] ):
3262 # no repeats
3263 if onosSet != current:
Jon Halla440e872016-03-31 15:15:50 -07003264 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07003265 " has incorrect view" +
3266 " of set " + onosSetName + ":\n" +
3267 str( getResponses[ i ] ) )
3268 main.log.debug( "Expected: " + str( onosSet ) )
3269 main.log.debug( "Actual: " + str( current ) )
3270 getResults = main.FALSE
3271 else:
3272 # error, set is not a set
Jon Halla440e872016-03-31 15:15:50 -07003273 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07003274 " has repeat elements in" +
3275 " set " + onosSetName + ":\n" +
3276 str( getResponses[ i ] ) )
3277 getResults = main.FALSE
3278 elif getResponses[ i ] == main.ERROR:
3279 getResults = main.FALSE
3280 sizeResponses = []
3281 threads = []
Jon Halla440e872016-03-31 15:15:50 -07003282 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07003283 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall85794ff2015-07-08 14:12:30 -07003284 name="setTestSize-" + str( i ),
3285 args=[ onosSetName ] )
3286 threads.append( t )
3287 t.start()
3288 for t in threads:
3289 t.join()
3290 sizeResponses.append( t.result )
3291 sizeResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07003292 for i in range( len( main.activeNodes ) ):
3293 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07003294 if size != sizeResponses[ i ]:
3295 sizeResults = main.FALSE
Jon Halla440e872016-03-31 15:15:50 -07003296 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07003297 " expected a size of " + str( size ) +
3298 " for set " + onosSetName +
3299 " but got " + str( sizeResponses[ i ] ) )
3300 addAllResults = addAllResults and getResults and sizeResults
3301 utilities.assert_equals( expect=main.TRUE,
3302 actual=addAllResults,
3303 onpass="Set addAll correct",
3304 onfail="Set addAll was incorrect" )
3305
3306 main.step( "Distributed Set retain()" )
3307 onosSet.intersection_update( retainValue.split() )
3308 retainResponses = []
3309 threads = []
Jon Halla440e872016-03-31 15:15:50 -07003310 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07003311 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall85794ff2015-07-08 14:12:30 -07003312 name="setTestRetain-" + str( i ),
3313 args=[ onosSetName, retainValue ],
3314 kwargs={ "retain": True } )
3315 threads.append( t )
3316 t.start()
3317 for t in threads:
3318 t.join()
3319 retainResponses.append( t.result )
3320
3321 # main.TRUE = successfully changed the set
3322 # main.FALSE = action resulted in no change in set
3323 # main.ERROR - Some error in executing the function
3324 retainResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07003325 for i in range( len( main.activeNodes ) ):
Jon Hall85794ff2015-07-08 14:12:30 -07003326 if retainResponses[ i ] == main.TRUE:
3327 # All is well
3328 pass
3329 elif retainResponses[ i ] == main.FALSE:
3330 # Already in set, probably fine
3331 pass
3332 elif retainResponses[ i ] == main.ERROR:
3333 # Error in execution
3334 retainResults = main.FALSE
3335 else:
3336 # unexpected result
3337 retainResults = main.FALSE
3338 if retainResults != main.TRUE:
3339 main.log.error( "Error executing set retain" )
3340
3341 # Check if set is still correct
3342 size = len( onosSet )
3343 getResponses = []
3344 threads = []
Jon Halla440e872016-03-31 15:15:50 -07003345 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07003346 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07003347 name="setTestGet-" + str( i ),
3348 args=[ onosSetName ] )
3349 threads.append( t )
3350 t.start()
3351 for t in threads:
3352 t.join()
3353 getResponses.append( t.result )
3354 getResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07003355 for i in range( len( main.activeNodes ) ):
3356 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07003357 if isinstance( getResponses[ i ], list):
3358 current = set( getResponses[ i ] )
3359 if len( current ) == len( getResponses[ i ] ):
3360 # no repeats
3361 if onosSet != current:
Jon Halla440e872016-03-31 15:15:50 -07003362 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07003363 " has incorrect view" +
3364 " of set " + onosSetName + ":\n" +
3365 str( getResponses[ i ] ) )
3366 main.log.debug( "Expected: " + str( onosSet ) )
3367 main.log.debug( "Actual: " + str( current ) )
3368 getResults = main.FALSE
3369 else:
3370 # error, set is not a set
Jon Halla440e872016-03-31 15:15:50 -07003371 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07003372 " has repeat elements in" +
3373 " set " + onosSetName + ":\n" +
3374 str( getResponses[ i ] ) )
3375 getResults = main.FALSE
3376 elif getResponses[ i ] == main.ERROR:
3377 getResults = main.FALSE
3378 sizeResponses = []
3379 threads = []
Jon Halla440e872016-03-31 15:15:50 -07003380 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07003381 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall85794ff2015-07-08 14:12:30 -07003382 name="setTestSize-" + str( i ),
3383 args=[ onosSetName ] )
3384 threads.append( t )
3385 t.start()
3386 for t in threads:
3387 t.join()
3388 sizeResponses.append( t.result )
3389 sizeResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07003390 for i in range( len( main.activeNodes ) ):
3391 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07003392 if size != sizeResponses[ i ]:
3393 sizeResults = main.FALSE
Jon Halla440e872016-03-31 15:15:50 -07003394 main.log.error( "ONOS" + node + " expected a size of " +
Jon Hall85794ff2015-07-08 14:12:30 -07003395 str( size ) + " for set " + onosSetName +
3396 " but got " + str( sizeResponses[ i ] ) )
3397 retainResults = retainResults and getResults and sizeResults
3398 utilities.assert_equals( expect=main.TRUE,
3399 actual=retainResults,
3400 onpass="Set retain correct",
3401 onfail="Set retain was incorrect" )
3402
Jon Hall2a5002c2015-08-21 16:49:11 -07003403 # Transactional maps
3404 main.step( "Partitioned Transactional maps put" )
3405 tMapValue = "Testing"
3406 numKeys = 100
3407 putResult = True
Jon Halla440e872016-03-31 15:15:50 -07003408 node = main.activeNodes[0]
3409 putResponses = main.CLIs[node].transactionalMapPut( numKeys, tMapValue )
3410 if putResponses and len( putResponses ) == 100:
Jon Hall2a5002c2015-08-21 16:49:11 -07003411 for i in putResponses:
3412 if putResponses[ i ][ 'value' ] != tMapValue:
3413 putResult = False
3414 else:
3415 putResult = False
3416 if not putResult:
3417 main.log.debug( "Put response values: " + str( putResponses ) )
3418 utilities.assert_equals( expect=True,
3419 actual=putResult,
3420 onpass="Partitioned Transactional Map put successful",
3421 onfail="Partitioned Transactional Map put values are incorrect" )
3422
3423 main.step( "Partitioned Transactional maps get" )
3424 getCheck = True
3425 for n in range( 1, numKeys + 1 ):
3426 getResponses = []
3427 threads = []
3428 valueCheck = True
Jon Halla440e872016-03-31 15:15:50 -07003429 for i in main.activeNodes:
Jon Hall2a5002c2015-08-21 16:49:11 -07003430 t = main.Thread( target=main.CLIs[i].transactionalMapGet,
3431 name="TMap-get-" + str( i ),
Jon Halla440e872016-03-31 15:15:50 -07003432 args=[ "Key" + str( n ) ] )
Jon Hall2a5002c2015-08-21 16:49:11 -07003433 threads.append( t )
3434 t.start()
3435 for t in threads:
3436 t.join()
3437 getResponses.append( t.result )
3438 for node in getResponses:
3439 if node != tMapValue:
3440 valueCheck = False
3441 if not valueCheck:
3442 main.log.warn( "Values for key 'Key" + str( n ) + "' do not match:" )
3443 main.log.warn( getResponses )
3444 getCheck = getCheck and valueCheck
3445 utilities.assert_equals( expect=True,
3446 actual=getCheck,
3447 onpass="Partitioned Transactional Map get values were correct",
3448 onfail="Partitioned Transactional Map values incorrect" )