blob: de14bf97a26bf23b21d42560ca6b71b15f2e0eed [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 Halla440e872016-03-31 15:15:50 -07002182 if newLeaders[ 0 ][ 0 ] == 'none':
2183 main.log.error( "No leader was elected on at least 1 node" )
2184 if not expectNoLeader:
2185 newLeaderResult = False
2186 if newLeaderResult:
2187 newLeader = newLeaders[ 0 ][ 0 ]
acsmars71adceb2015-08-31 15:09:26 -07002188 else:
Jon Halla440e872016-03-31 15:15:50 -07002189 newLeader = None
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 Halla440e872016-03-31 15:15:50 -07002252 if oldLeader != reRunLeaders[ 0 ][ -1 ]:
2253 main.log.error( "Old Leader ({}) not in the proper position: {} ".format( str( oldLeader),
2254 str( reRunLeaders[ 0 ] ) ) )
acsmars71adceb2015-08-31 15:09:26 -07002255 positionResult = main.FALSE
Jon Hall85794ff2015-07-08 14:12:30 -07002256
2257 utilities.assert_equals(
Jon Halla440e872016-03-31 15:15:50 -07002258 expect=True,
acsmars71adceb2015-08-31 15:09:26 -07002259 actual=positionResult,
Jon Hall85794ff2015-07-08 14:12:30 -07002260 onpass="Old leader successfully re-ran for election",
2261 onfail="Something went wrong with Leadership election after " +
2262 "the old leader re-ran for election" )
2263
2264 def CASE16( self, main ):
2265 """
2266 Install Distributed Primitives app
2267 """
Jon Halla440e872016-03-31 15:15:50 -07002268 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002269 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07002270 assert main, "main not defined"
2271 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002272 assert main.CLIs, "main.CLIs not defined"
2273 assert main.nodes, "main.nodes not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07002274
2275 # Variables for the distributed primitives tests
2276 global pCounterName
Jon Hall85794ff2015-07-08 14:12:30 -07002277 global pCounterValue
Jon Hall85794ff2015-07-08 14:12:30 -07002278 global onosSet
2279 global onosSetName
2280 pCounterName = "TestON-Partitions"
Jon Hall85794ff2015-07-08 14:12:30 -07002281 pCounterValue = 0
Jon Hall85794ff2015-07-08 14:12:30 -07002282 onosSet = set([])
2283 onosSetName = "TestON-set"
2284
2285 description = "Install Primitives app"
2286 main.case( description )
2287 main.step( "Install Primitives app" )
2288 appName = "org.onosproject.distributedprimitives"
Jon Halla440e872016-03-31 15:15:50 -07002289 node = main.activeNodes[0]
2290 appResults = main.CLIs[node].activateApp( appName )
Jon Hall85794ff2015-07-08 14:12:30 -07002291 utilities.assert_equals( expect=main.TRUE,
2292 actual=appResults,
2293 onpass="Primitives app activated",
2294 onfail="Primitives app not activated" )
Jon Halla440e872016-03-31 15:15:50 -07002295 time.sleep( 5 ) # To allow all nodes to activate
Jon Hall85794ff2015-07-08 14:12:30 -07002296
2297 def CASE17( self, main ):
2298 """
2299 Check for basic functionality with distributed primitives
2300 """
Jon Hall85794ff2015-07-08 14:12:30 -07002301 # Make sure variables are defined/set
Jon Halle1a3b752015-07-22 13:02:46 -07002302 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07002303 assert main, "main not defined"
2304 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002305 assert main.CLIs, "main.CLIs not defined"
2306 assert main.nodes, "main.nodes not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07002307 assert pCounterName, "pCounterName not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07002308 assert onosSetName, "onosSetName not defined"
2309 # NOTE: assert fails if value is 0/None/Empty/False
2310 try:
2311 pCounterValue
2312 except NameError:
2313 main.log.error( "pCounterValue not defined, setting to 0" )
2314 pCounterValue = 0
2315 try:
Jon Hall85794ff2015-07-08 14:12:30 -07002316 onosSet
2317 except NameError:
2318 main.log.error( "onosSet not defined, setting to empty Set" )
2319 onosSet = set([])
2320 # Variables for the distributed primitives tests. These are local only
2321 addValue = "a"
2322 addAllValue = "a b c d e f"
2323 retainValue = "c d e f"
2324
2325 description = "Check for basic functionality with distributed " +\
2326 "primitives"
2327 main.case( description )
Jon Halle1a3b752015-07-22 13:02:46 -07002328 main.caseExplanation = "Test the methods of the distributed " +\
2329 "primitives (counters and sets) throught the cli"
Jon Hall85794ff2015-07-08 14:12:30 -07002330 # DISTRIBUTED ATOMIC COUNTERS
Jon Halle1a3b752015-07-22 13:02:46 -07002331 # Partitioned counters
2332 main.step( "Increment then get a default counter on each node" )
Jon Hall85794ff2015-07-08 14:12:30 -07002333 pCounters = []
2334 threads = []
2335 addedPValues = []
Jon Halla440e872016-03-31 15:15:50 -07002336 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002337 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
2338 name="counterAddAndGet-" + str( i ),
Jon Hall85794ff2015-07-08 14:12:30 -07002339 args=[ pCounterName ] )
2340 pCounterValue += 1
2341 addedPValues.append( pCounterValue )
2342 threads.append( t )
2343 t.start()
2344
2345 for t in threads:
2346 t.join()
2347 pCounters.append( t.result )
2348 # Check that counter incremented numController times
2349 pCounterResults = True
2350 for i in addedPValues:
2351 tmpResult = i in pCounters
2352 pCounterResults = pCounterResults and tmpResult
2353 if not tmpResult:
2354 main.log.error( str( i ) + " is not in partitioned "
2355 "counter incremented results" )
2356 utilities.assert_equals( expect=True,
2357 actual=pCounterResults,
2358 onpass="Default counter incremented",
2359 onfail="Error incrementing default" +
2360 " counter" )
2361
Jon Halle1a3b752015-07-22 13:02:46 -07002362 main.step( "Get then Increment a default counter on each node" )
2363 pCounters = []
2364 threads = []
2365 addedPValues = []
Jon Halla440e872016-03-31 15:15:50 -07002366 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002367 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
2368 name="counterGetAndAdd-" + str( i ),
2369 args=[ pCounterName ] )
2370 addedPValues.append( pCounterValue )
2371 pCounterValue += 1
2372 threads.append( t )
2373 t.start()
2374
2375 for t in threads:
2376 t.join()
2377 pCounters.append( t.result )
2378 # Check that counter incremented numController times
2379 pCounterResults = True
2380 for i in addedPValues:
2381 tmpResult = i in pCounters
2382 pCounterResults = pCounterResults and tmpResult
2383 if not tmpResult:
2384 main.log.error( str( i ) + " is not in partitioned "
2385 "counter incremented results" )
2386 utilities.assert_equals( expect=True,
2387 actual=pCounterResults,
2388 onpass="Default counter incremented",
2389 onfail="Error incrementing default" +
2390 " counter" )
2391
2392 main.step( "Counters we added have the correct values" )
Jon Hall41d39f12016-04-11 22:54:35 -07002393 incrementCheck = main.HA.counterCheck( pCounterName, pCounterValue )
Jon Halle1a3b752015-07-22 13:02:46 -07002394 utilities.assert_equals( expect=main.TRUE,
2395 actual=incrementCheck,
2396 onpass="Added counters are correct",
2397 onfail="Added counters are incorrect" )
2398
2399 main.step( "Add -8 to then get a default counter on each node" )
2400 pCounters = []
2401 threads = []
2402 addedPValues = []
Jon Halla440e872016-03-31 15:15:50 -07002403 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002404 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
2405 name="counterIncrement-" + str( i ),
2406 args=[ pCounterName ],
2407 kwargs={ "delta": -8 } )
2408 pCounterValue += -8
2409 addedPValues.append( pCounterValue )
2410 threads.append( t )
2411 t.start()
2412
2413 for t in threads:
2414 t.join()
2415 pCounters.append( t.result )
2416 # Check that counter incremented numController times
2417 pCounterResults = True
2418 for i in addedPValues:
2419 tmpResult = i in pCounters
2420 pCounterResults = pCounterResults and tmpResult
2421 if not tmpResult:
2422 main.log.error( str( i ) + " is not in partitioned "
2423 "counter incremented results" )
2424 utilities.assert_equals( expect=True,
2425 actual=pCounterResults,
2426 onpass="Default counter incremented",
2427 onfail="Error incrementing default" +
2428 " counter" )
2429
2430 main.step( "Add 5 to then get a default counter on each node" )
2431 pCounters = []
2432 threads = []
2433 addedPValues = []
Jon Halla440e872016-03-31 15:15:50 -07002434 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002435 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
2436 name="counterIncrement-" + str( i ),
2437 args=[ pCounterName ],
2438 kwargs={ "delta": 5 } )
2439 pCounterValue += 5
2440 addedPValues.append( pCounterValue )
2441 threads.append( t )
2442 t.start()
2443
2444 for t in threads:
2445 t.join()
2446 pCounters.append( t.result )
2447 # Check that counter incremented numController times
2448 pCounterResults = True
2449 for i in addedPValues:
2450 tmpResult = i in pCounters
2451 pCounterResults = pCounterResults and tmpResult
2452 if not tmpResult:
2453 main.log.error( str( i ) + " is not in partitioned "
2454 "counter incremented results" )
2455 utilities.assert_equals( expect=True,
2456 actual=pCounterResults,
2457 onpass="Default counter incremented",
2458 onfail="Error incrementing default" +
2459 " counter" )
2460
2461 main.step( "Get then add 5 to a default counter on each node" )
2462 pCounters = []
2463 threads = []
2464 addedPValues = []
Jon Halla440e872016-03-31 15:15:50 -07002465 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002466 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
2467 name="counterIncrement-" + str( i ),
2468 args=[ pCounterName ],
2469 kwargs={ "delta": 5 } )
2470 addedPValues.append( pCounterValue )
2471 pCounterValue += 5
2472 threads.append( t )
2473 t.start()
2474
2475 for t in threads:
2476 t.join()
2477 pCounters.append( t.result )
2478 # Check that counter incremented numController times
2479 pCounterResults = True
2480 for i in addedPValues:
2481 tmpResult = i in pCounters
2482 pCounterResults = pCounterResults and tmpResult
2483 if not tmpResult:
2484 main.log.error( str( i ) + " is not in partitioned "
2485 "counter incremented results" )
2486 utilities.assert_equals( expect=True,
2487 actual=pCounterResults,
2488 onpass="Default counter incremented",
2489 onfail="Error incrementing default" +
2490 " counter" )
2491
2492 main.step( "Counters we added have the correct values" )
Jon Hall41d39f12016-04-11 22:54:35 -07002493 incrementCheck = main.HA.counterCheck( pCounterName, pCounterValue )
Jon Halle1a3b752015-07-22 13:02:46 -07002494 utilities.assert_equals( expect=main.TRUE,
2495 actual=incrementCheck,
2496 onpass="Added counters are correct",
2497 onfail="Added counters are incorrect" )
2498
Jon Hall85794ff2015-07-08 14:12:30 -07002499 # DISTRIBUTED SETS
2500 main.step( "Distributed Set get" )
2501 size = len( onosSet )
2502 getResponses = []
2503 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002504 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002505 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07002506 name="setTestGet-" + str( i ),
2507 args=[ onosSetName ] )
2508 threads.append( t )
2509 t.start()
2510 for t in threads:
2511 t.join()
2512 getResponses.append( t.result )
2513
2514 getResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002515 for i in range( len( main.activeNodes ) ):
2516 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07002517 if isinstance( getResponses[ i ], list):
2518 current = set( getResponses[ i ] )
2519 if len( current ) == len( getResponses[ i ] ):
2520 # no repeats
2521 if onosSet != current:
Jon Halla440e872016-03-31 15:15:50 -07002522 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07002523 " has incorrect view" +
2524 " of set " + onosSetName + ":\n" +
2525 str( getResponses[ i ] ) )
2526 main.log.debug( "Expected: " + str( onosSet ) )
2527 main.log.debug( "Actual: " + str( current ) )
2528 getResults = main.FALSE
2529 else:
2530 # error, set is not a set
Jon Halla440e872016-03-31 15:15:50 -07002531 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07002532 " has repeat elements in" +
2533 " set " + onosSetName + ":\n" +
2534 str( getResponses[ i ] ) )
2535 getResults = main.FALSE
2536 elif getResponses[ i ] == main.ERROR:
2537 getResults = main.FALSE
2538 utilities.assert_equals( expect=main.TRUE,
2539 actual=getResults,
2540 onpass="Set elements are correct",
2541 onfail="Set elements are incorrect" )
2542
2543 main.step( "Distributed Set size" )
2544 sizeResponses = []
2545 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002546 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002547 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall85794ff2015-07-08 14:12:30 -07002548 name="setTestSize-" + str( i ),
2549 args=[ onosSetName ] )
2550 threads.append( t )
2551 t.start()
2552 for t in threads:
2553 t.join()
2554 sizeResponses.append( t.result )
2555
2556 sizeResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002557 for i in range( len( main.activeNodes ) ):
2558 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07002559 if size != sizeResponses[ i ]:
2560 sizeResults = main.FALSE
Jon Halla440e872016-03-31 15:15:50 -07002561 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07002562 " expected a size of " + str( size ) +
2563 " for set " + onosSetName +
2564 " but got " + str( sizeResponses[ i ] ) )
2565 utilities.assert_equals( expect=main.TRUE,
2566 actual=sizeResults,
2567 onpass="Set sizes are correct",
2568 onfail="Set sizes are incorrect" )
2569
2570 main.step( "Distributed Set add()" )
2571 onosSet.add( addValue )
2572 addResponses = []
2573 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002574 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002575 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall85794ff2015-07-08 14:12:30 -07002576 name="setTestAdd-" + str( i ),
2577 args=[ onosSetName, addValue ] )
2578 threads.append( t )
2579 t.start()
2580 for t in threads:
2581 t.join()
2582 addResponses.append( t.result )
2583
2584 # main.TRUE = successfully changed the set
2585 # main.FALSE = action resulted in no change in set
2586 # main.ERROR - Some error in executing the function
2587 addResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002588 for i in range( len( main.activeNodes ) ):
Jon Hall85794ff2015-07-08 14:12:30 -07002589 if addResponses[ i ] == main.TRUE:
2590 # All is well
2591 pass
2592 elif addResponses[ i ] == main.FALSE:
2593 # Already in set, probably fine
2594 pass
2595 elif addResponses[ i ] == main.ERROR:
2596 # Error in execution
2597 addResults = main.FALSE
2598 else:
2599 # unexpected result
2600 addResults = main.FALSE
2601 if addResults != main.TRUE:
2602 main.log.error( "Error executing set add" )
2603
2604 # Check if set is still correct
2605 size = len( onosSet )
2606 getResponses = []
2607 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002608 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002609 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07002610 name="setTestGet-" + str( i ),
2611 args=[ onosSetName ] )
2612 threads.append( t )
2613 t.start()
2614 for t in threads:
2615 t.join()
2616 getResponses.append( t.result )
2617 getResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002618 for i in range( len( main.activeNodes ) ):
2619 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07002620 if isinstance( getResponses[ i ], list):
2621 current = set( getResponses[ i ] )
2622 if len( current ) == len( getResponses[ i ] ):
2623 # no repeats
2624 if onosSet != current:
Jon Halla440e872016-03-31 15:15:50 -07002625 main.log.error( "ONOS" + node + " has incorrect view" +
Jon Hall85794ff2015-07-08 14:12:30 -07002626 " of set " + onosSetName + ":\n" +
2627 str( getResponses[ i ] ) )
2628 main.log.debug( "Expected: " + str( onosSet ) )
2629 main.log.debug( "Actual: " + str( current ) )
2630 getResults = main.FALSE
2631 else:
2632 # error, set is not a set
Jon Halla440e872016-03-31 15:15:50 -07002633 main.log.error( "ONOS" + node + " has repeat elements in" +
Jon Hall85794ff2015-07-08 14:12:30 -07002634 " set " + onosSetName + ":\n" +
2635 str( getResponses[ i ] ) )
2636 getResults = main.FALSE
2637 elif getResponses[ i ] == main.ERROR:
2638 getResults = main.FALSE
2639 sizeResponses = []
2640 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002641 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002642 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall85794ff2015-07-08 14:12:30 -07002643 name="setTestSize-" + str( i ),
2644 args=[ onosSetName ] )
2645 threads.append( t )
2646 t.start()
2647 for t in threads:
2648 t.join()
2649 sizeResponses.append( t.result )
2650 sizeResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002651 for i in range( len( main.activeNodes ) ):
2652 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07002653 if size != sizeResponses[ i ]:
2654 sizeResults = main.FALSE
Jon Halla440e872016-03-31 15:15:50 -07002655 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07002656 " expected a size of " + str( size ) +
2657 " for set " + onosSetName +
2658 " but got " + str( sizeResponses[ i ] ) )
2659 addResults = addResults and getResults and sizeResults
2660 utilities.assert_equals( expect=main.TRUE,
2661 actual=addResults,
2662 onpass="Set add correct",
2663 onfail="Set add was incorrect" )
2664
2665 main.step( "Distributed Set addAll()" )
2666 onosSet.update( addAllValue.split() )
2667 addResponses = []
2668 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002669 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002670 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall85794ff2015-07-08 14:12:30 -07002671 name="setTestAddAll-" + str( i ),
2672 args=[ onosSetName, addAllValue ] )
2673 threads.append( t )
2674 t.start()
2675 for t in threads:
2676 t.join()
2677 addResponses.append( t.result )
2678
2679 # main.TRUE = successfully changed the set
2680 # main.FALSE = action resulted in no change in set
2681 # main.ERROR - Some error in executing the function
2682 addAllResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002683 for i in range( len( main.activeNodes ) ):
Jon Hall85794ff2015-07-08 14:12:30 -07002684 if addResponses[ i ] == main.TRUE:
2685 # All is well
2686 pass
2687 elif addResponses[ i ] == main.FALSE:
2688 # Already in set, probably fine
2689 pass
2690 elif addResponses[ i ] == main.ERROR:
2691 # Error in execution
2692 addAllResults = main.FALSE
2693 else:
2694 # unexpected result
2695 addAllResults = main.FALSE
2696 if addAllResults != main.TRUE:
2697 main.log.error( "Error executing set addAll" )
2698
2699 # Check if set is still correct
2700 size = len( onosSet )
2701 getResponses = []
2702 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002703 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002704 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07002705 name="setTestGet-" + str( i ),
2706 args=[ onosSetName ] )
2707 threads.append( t )
2708 t.start()
2709 for t in threads:
2710 t.join()
2711 getResponses.append( t.result )
2712 getResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002713 for i in range( len( main.activeNodes ) ):
2714 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07002715 if isinstance( getResponses[ i ], list):
2716 current = set( getResponses[ i ] )
2717 if len( current ) == len( getResponses[ i ] ):
2718 # no repeats
2719 if onosSet != current:
Jon Halla440e872016-03-31 15:15:50 -07002720 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07002721 " has incorrect view" +
2722 " of set " + onosSetName + ":\n" +
2723 str( getResponses[ i ] ) )
2724 main.log.debug( "Expected: " + str( onosSet ) )
2725 main.log.debug( "Actual: " + str( current ) )
2726 getResults = main.FALSE
2727 else:
2728 # error, set is not a set
Jon Halla440e872016-03-31 15:15:50 -07002729 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07002730 " has repeat elements in" +
2731 " set " + onosSetName + ":\n" +
2732 str( getResponses[ i ] ) )
2733 getResults = main.FALSE
2734 elif getResponses[ i ] == main.ERROR:
2735 getResults = main.FALSE
2736 sizeResponses = []
2737 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002738 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002739 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall85794ff2015-07-08 14:12:30 -07002740 name="setTestSize-" + str( i ),
2741 args=[ onosSetName ] )
2742 threads.append( t )
2743 t.start()
2744 for t in threads:
2745 t.join()
2746 sizeResponses.append( t.result )
2747 sizeResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002748 for i in range( len( main.activeNodes ) ):
2749 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07002750 if size != sizeResponses[ i ]:
2751 sizeResults = main.FALSE
Jon Halla440e872016-03-31 15:15:50 -07002752 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07002753 " expected a size of " + str( size ) +
2754 " for set " + onosSetName +
2755 " but got " + str( sizeResponses[ i ] ) )
2756 addAllResults = addAllResults and getResults and sizeResults
2757 utilities.assert_equals( expect=main.TRUE,
2758 actual=addAllResults,
2759 onpass="Set addAll correct",
2760 onfail="Set addAll was incorrect" )
2761
2762 main.step( "Distributed Set contains()" )
2763 containsResponses = []
2764 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002765 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002766 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07002767 name="setContains-" + str( i ),
2768 args=[ onosSetName ],
2769 kwargs={ "values": addValue } )
2770 threads.append( t )
2771 t.start()
2772 for t in threads:
2773 t.join()
2774 # NOTE: This is the tuple
2775 containsResponses.append( t.result )
2776
2777 containsResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002778 for i in range( len( main.activeNodes ) ):
Jon Hall85794ff2015-07-08 14:12:30 -07002779 if containsResponses[ i ] == main.ERROR:
2780 containsResults = main.FALSE
2781 else:
2782 containsResults = containsResults and\
2783 containsResponses[ i ][ 1 ]
2784 utilities.assert_equals( expect=main.TRUE,
2785 actual=containsResults,
2786 onpass="Set contains is functional",
2787 onfail="Set contains failed" )
2788
2789 main.step( "Distributed Set containsAll()" )
2790 containsAllResponses = []
2791 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002792 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002793 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07002794 name="setContainsAll-" + str( i ),
2795 args=[ onosSetName ],
2796 kwargs={ "values": addAllValue } )
2797 threads.append( t )
2798 t.start()
2799 for t in threads:
2800 t.join()
2801 # NOTE: This is the tuple
2802 containsAllResponses.append( t.result )
2803
2804 containsAllResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002805 for i in range( len( main.activeNodes ) ):
Jon Hall85794ff2015-07-08 14:12:30 -07002806 if containsResponses[ i ] == main.ERROR:
2807 containsResults = main.FALSE
2808 else:
2809 containsResults = containsResults and\
2810 containsResponses[ i ][ 1 ]
2811 utilities.assert_equals( expect=main.TRUE,
2812 actual=containsAllResults,
2813 onpass="Set containsAll is functional",
2814 onfail="Set containsAll failed" )
2815
2816 main.step( "Distributed Set remove()" )
2817 onosSet.remove( addValue )
2818 removeResponses = []
2819 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002820 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002821 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall85794ff2015-07-08 14:12:30 -07002822 name="setTestRemove-" + str( i ),
2823 args=[ onosSetName, addValue ] )
2824 threads.append( t )
2825 t.start()
2826 for t in threads:
2827 t.join()
2828 removeResponses.append( t.result )
2829
2830 # main.TRUE = successfully changed the set
2831 # main.FALSE = action resulted in no change in set
2832 # main.ERROR - Some error in executing the function
2833 removeResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002834 for i in range( len( main.activeNodes ) ):
Jon Hall85794ff2015-07-08 14:12:30 -07002835 if removeResponses[ i ] == main.TRUE:
2836 # All is well
2837 pass
2838 elif removeResponses[ i ] == main.FALSE:
2839 # not in set, probably fine
2840 pass
2841 elif removeResponses[ i ] == main.ERROR:
2842 # Error in execution
2843 removeResults = main.FALSE
2844 else:
2845 # unexpected result
2846 removeResults = main.FALSE
2847 if removeResults != main.TRUE:
2848 main.log.error( "Error executing set remove" )
2849
2850 # Check if set is still correct
2851 size = len( onosSet )
2852 getResponses = []
2853 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002854 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002855 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07002856 name="setTestGet-" + str( i ),
2857 args=[ onosSetName ] )
2858 threads.append( t )
2859 t.start()
2860 for t in threads:
2861 t.join()
2862 getResponses.append( t.result )
2863 getResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002864 for i in range( len( main.activeNodes ) ):
2865 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07002866 if isinstance( getResponses[ i ], list):
2867 current = set( getResponses[ i ] )
2868 if len( current ) == len( getResponses[ i ] ):
2869 # no repeats
2870 if onosSet != current:
Jon Halla440e872016-03-31 15:15:50 -07002871 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07002872 " has incorrect view" +
2873 " of set " + onosSetName + ":\n" +
2874 str( getResponses[ i ] ) )
2875 main.log.debug( "Expected: " + str( onosSet ) )
2876 main.log.debug( "Actual: " + str( current ) )
2877 getResults = main.FALSE
2878 else:
2879 # error, set is not a set
Jon Halla440e872016-03-31 15:15:50 -07002880 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07002881 " has repeat elements in" +
2882 " set " + onosSetName + ":\n" +
2883 str( getResponses[ i ] ) )
2884 getResults = main.FALSE
2885 elif getResponses[ i ] == main.ERROR:
2886 getResults = main.FALSE
2887 sizeResponses = []
2888 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002889 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002890 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall85794ff2015-07-08 14:12:30 -07002891 name="setTestSize-" + str( i ),
2892 args=[ onosSetName ] )
2893 threads.append( t )
2894 t.start()
2895 for t in threads:
2896 t.join()
2897 sizeResponses.append( t.result )
2898 sizeResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002899 for i in range( len( main.activeNodes ) ):
2900 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07002901 if size != sizeResponses[ i ]:
2902 sizeResults = main.FALSE
Jon Halla440e872016-03-31 15:15:50 -07002903 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07002904 " expected a size of " + str( size ) +
2905 " for set " + onosSetName +
2906 " but got " + str( sizeResponses[ i ] ) )
2907 removeResults = removeResults and getResults and sizeResults
2908 utilities.assert_equals( expect=main.TRUE,
2909 actual=removeResults,
2910 onpass="Set remove correct",
2911 onfail="Set remove was incorrect" )
2912
2913 main.step( "Distributed Set removeAll()" )
2914 onosSet.difference_update( addAllValue.split() )
2915 removeAllResponses = []
2916 threads = []
2917 try:
Jon Halla440e872016-03-31 15:15:50 -07002918 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002919 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall85794ff2015-07-08 14:12:30 -07002920 name="setTestRemoveAll-" + str( i ),
2921 args=[ onosSetName, addAllValue ] )
2922 threads.append( t )
2923 t.start()
2924 for t in threads:
2925 t.join()
2926 removeAllResponses.append( t.result )
2927 except Exception, e:
2928 main.log.exception(e)
2929
2930 # main.TRUE = successfully changed the set
2931 # main.FALSE = action resulted in no change in set
2932 # main.ERROR - Some error in executing the function
2933 removeAllResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002934 for i in range( len( main.activeNodes ) ):
Jon Hall85794ff2015-07-08 14:12:30 -07002935 if removeAllResponses[ i ] == main.TRUE:
2936 # All is well
2937 pass
2938 elif removeAllResponses[ i ] == main.FALSE:
2939 # not in set, probably fine
2940 pass
2941 elif removeAllResponses[ i ] == main.ERROR:
2942 # Error in execution
2943 removeAllResults = main.FALSE
2944 else:
2945 # unexpected result
2946 removeAllResults = main.FALSE
2947 if removeAllResults != main.TRUE:
2948 main.log.error( "Error executing set removeAll" )
2949
2950 # Check if set is still correct
2951 size = len( onosSet )
2952 getResponses = []
2953 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002954 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002955 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07002956 name="setTestGet-" + str( i ),
2957 args=[ onosSetName ] )
2958 threads.append( t )
2959 t.start()
2960 for t in threads:
2961 t.join()
2962 getResponses.append( t.result )
2963 getResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002964 for i in range( len( main.activeNodes ) ):
2965 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07002966 if isinstance( getResponses[ i ], list):
2967 current = set( getResponses[ i ] )
2968 if len( current ) == len( getResponses[ i ] ):
2969 # no repeats
2970 if onosSet != current:
Jon Halla440e872016-03-31 15:15:50 -07002971 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07002972 " has incorrect view" +
2973 " of set " + onosSetName + ":\n" +
2974 str( getResponses[ i ] ) )
2975 main.log.debug( "Expected: " + str( onosSet ) )
2976 main.log.debug( "Actual: " + str( current ) )
2977 getResults = main.FALSE
2978 else:
2979 # error, set is not a set
Jon Halla440e872016-03-31 15:15:50 -07002980 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07002981 " has repeat elements in" +
2982 " set " + onosSetName + ":\n" +
2983 str( getResponses[ i ] ) )
2984 getResults = main.FALSE
2985 elif getResponses[ i ] == main.ERROR:
2986 getResults = main.FALSE
2987 sizeResponses = []
2988 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002989 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002990 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall85794ff2015-07-08 14:12:30 -07002991 name="setTestSize-" + str( i ),
2992 args=[ onosSetName ] )
2993 threads.append( t )
2994 t.start()
2995 for t in threads:
2996 t.join()
2997 sizeResponses.append( t.result )
2998 sizeResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002999 for i in range( len( main.activeNodes ) ):
3000 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07003001 if size != sizeResponses[ i ]:
3002 sizeResults = main.FALSE
Jon Halla440e872016-03-31 15:15:50 -07003003 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07003004 " expected a size of " + str( size ) +
3005 " for set " + onosSetName +
3006 " but got " + str( sizeResponses[ i ] ) )
3007 removeAllResults = removeAllResults and getResults and sizeResults
3008 utilities.assert_equals( expect=main.TRUE,
3009 actual=removeAllResults,
3010 onpass="Set removeAll correct",
3011 onfail="Set removeAll was incorrect" )
3012
3013 main.step( "Distributed Set addAll()" )
3014 onosSet.update( addAllValue.split() )
3015 addResponses = []
3016 threads = []
Jon Halla440e872016-03-31 15:15:50 -07003017 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07003018 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall85794ff2015-07-08 14:12:30 -07003019 name="setTestAddAll-" + str( i ),
3020 args=[ onosSetName, addAllValue ] )
3021 threads.append( t )
3022 t.start()
3023 for t in threads:
3024 t.join()
3025 addResponses.append( t.result )
3026
3027 # main.TRUE = successfully changed the set
3028 # main.FALSE = action resulted in no change in set
3029 # main.ERROR - Some error in executing the function
3030 addAllResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07003031 for i in range( len( main.activeNodes ) ):
Jon Hall85794ff2015-07-08 14:12:30 -07003032 if addResponses[ i ] == main.TRUE:
3033 # All is well
3034 pass
3035 elif addResponses[ i ] == main.FALSE:
3036 # Already in set, probably fine
3037 pass
3038 elif addResponses[ i ] == main.ERROR:
3039 # Error in execution
3040 addAllResults = main.FALSE
3041 else:
3042 # unexpected result
3043 addAllResults = main.FALSE
3044 if addAllResults != main.TRUE:
3045 main.log.error( "Error executing set addAll" )
3046
3047 # Check if set is still correct
3048 size = len( onosSet )
3049 getResponses = []
3050 threads = []
Jon Halla440e872016-03-31 15:15:50 -07003051 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07003052 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07003053 name="setTestGet-" + str( i ),
3054 args=[ onosSetName ] )
3055 threads.append( t )
3056 t.start()
3057 for t in threads:
3058 t.join()
3059 getResponses.append( t.result )
3060 getResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07003061 for i in range( len( main.activeNodes ) ):
3062 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07003063 if isinstance( getResponses[ i ], list):
3064 current = set( getResponses[ i ] )
3065 if len( current ) == len( getResponses[ i ] ):
3066 # no repeats
3067 if onosSet != current:
Jon Halla440e872016-03-31 15:15:50 -07003068 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07003069 " has incorrect view" +
3070 " of set " + onosSetName + ":\n" +
3071 str( getResponses[ i ] ) )
3072 main.log.debug( "Expected: " + str( onosSet ) )
3073 main.log.debug( "Actual: " + str( current ) )
3074 getResults = main.FALSE
3075 else:
3076 # error, set is not a set
Jon Halla440e872016-03-31 15:15:50 -07003077 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07003078 " has repeat elements in" +
3079 " set " + onosSetName + ":\n" +
3080 str( getResponses[ i ] ) )
3081 getResults = main.FALSE
3082 elif getResponses[ i ] == main.ERROR:
3083 getResults = main.FALSE
3084 sizeResponses = []
3085 threads = []
Jon Halla440e872016-03-31 15:15:50 -07003086 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07003087 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall85794ff2015-07-08 14:12:30 -07003088 name="setTestSize-" + str( i ),
3089 args=[ onosSetName ] )
3090 threads.append( t )
3091 t.start()
3092 for t in threads:
3093 t.join()
3094 sizeResponses.append( t.result )
3095 sizeResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07003096 for i in range( len( main.activeNodes ) ):
3097 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07003098 if size != sizeResponses[ i ]:
3099 sizeResults = main.FALSE
Jon Halla440e872016-03-31 15:15:50 -07003100 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07003101 " expected a size of " + str( size ) +
3102 " for set " + onosSetName +
3103 " but got " + str( sizeResponses[ i ] ) )
3104 addAllResults = addAllResults and getResults and sizeResults
3105 utilities.assert_equals( expect=main.TRUE,
3106 actual=addAllResults,
3107 onpass="Set addAll correct",
3108 onfail="Set addAll was incorrect" )
3109
3110 main.step( "Distributed Set clear()" )
3111 onosSet.clear()
3112 clearResponses = []
3113 threads = []
Jon Halla440e872016-03-31 15:15:50 -07003114 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07003115 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall85794ff2015-07-08 14:12:30 -07003116 name="setTestClear-" + str( i ),
3117 args=[ onosSetName, " "], # Values doesn't matter
3118 kwargs={ "clear": True } )
3119 threads.append( t )
3120 t.start()
3121 for t in threads:
3122 t.join()
3123 clearResponses.append( t.result )
3124
3125 # main.TRUE = successfully changed the set
3126 # main.FALSE = action resulted in no change in set
3127 # main.ERROR - Some error in executing the function
3128 clearResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07003129 for i in range( len( main.activeNodes ) ):
Jon Hall85794ff2015-07-08 14:12:30 -07003130 if clearResponses[ i ] == main.TRUE:
3131 # All is well
3132 pass
3133 elif clearResponses[ i ] == main.FALSE:
3134 # Nothing set, probably fine
3135 pass
3136 elif clearResponses[ i ] == main.ERROR:
3137 # Error in execution
3138 clearResults = main.FALSE
3139 else:
3140 # unexpected result
3141 clearResults = main.FALSE
3142 if clearResults != main.TRUE:
3143 main.log.error( "Error executing set clear" )
3144
3145 # Check if set is still correct
3146 size = len( onosSet )
3147 getResponses = []
3148 threads = []
Jon Halla440e872016-03-31 15:15:50 -07003149 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07003150 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07003151 name="setTestGet-" + str( i ),
3152 args=[ onosSetName ] )
3153 threads.append( t )
3154 t.start()
3155 for t in threads:
3156 t.join()
3157 getResponses.append( t.result )
3158 getResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07003159 for i in range( len( main.activeNodes ) ):
3160 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07003161 if isinstance( getResponses[ i ], list):
3162 current = set( getResponses[ i ] )
3163 if len( current ) == len( getResponses[ i ] ):
3164 # no repeats
3165 if onosSet != current:
Jon Halla440e872016-03-31 15:15:50 -07003166 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07003167 " has incorrect view" +
3168 " of set " + onosSetName + ":\n" +
3169 str( getResponses[ i ] ) )
3170 main.log.debug( "Expected: " + str( onosSet ) )
3171 main.log.debug( "Actual: " + str( current ) )
3172 getResults = main.FALSE
3173 else:
3174 # error, set is not a set
Jon Halla440e872016-03-31 15:15:50 -07003175 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07003176 " has repeat elements in" +
3177 " set " + onosSetName + ":\n" +
3178 str( getResponses[ i ] ) )
3179 getResults = main.FALSE
3180 elif getResponses[ i ] == main.ERROR:
3181 getResults = main.FALSE
3182 sizeResponses = []
3183 threads = []
Jon Halla440e872016-03-31 15:15:50 -07003184 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07003185 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall85794ff2015-07-08 14:12:30 -07003186 name="setTestSize-" + str( i ),
3187 args=[ onosSetName ] )
3188 threads.append( t )
3189 t.start()
3190 for t in threads:
3191 t.join()
3192 sizeResponses.append( t.result )
3193 sizeResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07003194 for i in range( len( main.activeNodes ) ):
3195 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07003196 if size != sizeResponses[ i ]:
3197 sizeResults = main.FALSE
Jon Halla440e872016-03-31 15:15:50 -07003198 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07003199 " expected a size of " + str( size ) +
3200 " for set " + onosSetName +
3201 " but got " + str( sizeResponses[ i ] ) )
3202 clearResults = clearResults and getResults and sizeResults
3203 utilities.assert_equals( expect=main.TRUE,
3204 actual=clearResults,
3205 onpass="Set clear correct",
3206 onfail="Set clear was incorrect" )
3207
3208 main.step( "Distributed Set addAll()" )
3209 onosSet.update( addAllValue.split() )
3210 addResponses = []
3211 threads = []
Jon Halla440e872016-03-31 15:15:50 -07003212 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07003213 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall85794ff2015-07-08 14:12:30 -07003214 name="setTestAddAll-" + str( i ),
3215 args=[ onosSetName, addAllValue ] )
3216 threads.append( t )
3217 t.start()
3218 for t in threads:
3219 t.join()
3220 addResponses.append( t.result )
3221
3222 # main.TRUE = successfully changed the set
3223 # main.FALSE = action resulted in no change in set
3224 # main.ERROR - Some error in executing the function
3225 addAllResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07003226 for i in range( len( main.activeNodes ) ):
Jon Hall85794ff2015-07-08 14:12:30 -07003227 if addResponses[ i ] == main.TRUE:
3228 # All is well
3229 pass
3230 elif addResponses[ i ] == main.FALSE:
3231 # Already in set, probably fine
3232 pass
3233 elif addResponses[ i ] == main.ERROR:
3234 # Error in execution
3235 addAllResults = main.FALSE
3236 else:
3237 # unexpected result
3238 addAllResults = main.FALSE
3239 if addAllResults != main.TRUE:
3240 main.log.error( "Error executing set addAll" )
3241
3242 # Check if set is still correct
3243 size = len( onosSet )
3244 getResponses = []
3245 threads = []
Jon Halla440e872016-03-31 15:15:50 -07003246 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07003247 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07003248 name="setTestGet-" + str( i ),
3249 args=[ onosSetName ] )
3250 threads.append( t )
3251 t.start()
3252 for t in threads:
3253 t.join()
3254 getResponses.append( t.result )
3255 getResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07003256 for i in range( len( main.activeNodes ) ):
3257 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07003258 if isinstance( getResponses[ i ], list):
3259 current = set( getResponses[ i ] )
3260 if len( current ) == len( getResponses[ i ] ):
3261 # no repeats
3262 if onosSet != current:
Jon Halla440e872016-03-31 15:15:50 -07003263 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07003264 " has incorrect view" +
3265 " of set " + onosSetName + ":\n" +
3266 str( getResponses[ i ] ) )
3267 main.log.debug( "Expected: " + str( onosSet ) )
3268 main.log.debug( "Actual: " + str( current ) )
3269 getResults = main.FALSE
3270 else:
3271 # error, set is not a set
Jon Halla440e872016-03-31 15:15:50 -07003272 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07003273 " has repeat elements in" +
3274 " set " + onosSetName + ":\n" +
3275 str( getResponses[ i ] ) )
3276 getResults = main.FALSE
3277 elif getResponses[ i ] == main.ERROR:
3278 getResults = main.FALSE
3279 sizeResponses = []
3280 threads = []
Jon Halla440e872016-03-31 15:15:50 -07003281 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07003282 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall85794ff2015-07-08 14:12:30 -07003283 name="setTestSize-" + str( i ),
3284 args=[ onosSetName ] )
3285 threads.append( t )
3286 t.start()
3287 for t in threads:
3288 t.join()
3289 sizeResponses.append( t.result )
3290 sizeResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07003291 for i in range( len( main.activeNodes ) ):
3292 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07003293 if size != sizeResponses[ i ]:
3294 sizeResults = main.FALSE
Jon Halla440e872016-03-31 15:15:50 -07003295 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07003296 " expected a size of " + str( size ) +
3297 " for set " + onosSetName +
3298 " but got " + str( sizeResponses[ i ] ) )
3299 addAllResults = addAllResults and getResults and sizeResults
3300 utilities.assert_equals( expect=main.TRUE,
3301 actual=addAllResults,
3302 onpass="Set addAll correct",
3303 onfail="Set addAll was incorrect" )
3304
3305 main.step( "Distributed Set retain()" )
3306 onosSet.intersection_update( retainValue.split() )
3307 retainResponses = []
3308 threads = []
Jon Halla440e872016-03-31 15:15:50 -07003309 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07003310 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall85794ff2015-07-08 14:12:30 -07003311 name="setTestRetain-" + str( i ),
3312 args=[ onosSetName, retainValue ],
3313 kwargs={ "retain": True } )
3314 threads.append( t )
3315 t.start()
3316 for t in threads:
3317 t.join()
3318 retainResponses.append( t.result )
3319
3320 # main.TRUE = successfully changed the set
3321 # main.FALSE = action resulted in no change in set
3322 # main.ERROR - Some error in executing the function
3323 retainResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07003324 for i in range( len( main.activeNodes ) ):
Jon Hall85794ff2015-07-08 14:12:30 -07003325 if retainResponses[ i ] == main.TRUE:
3326 # All is well
3327 pass
3328 elif retainResponses[ i ] == main.FALSE:
3329 # Already in set, probably fine
3330 pass
3331 elif retainResponses[ i ] == main.ERROR:
3332 # Error in execution
3333 retainResults = main.FALSE
3334 else:
3335 # unexpected result
3336 retainResults = main.FALSE
3337 if retainResults != main.TRUE:
3338 main.log.error( "Error executing set retain" )
3339
3340 # Check if set is still correct
3341 size = len( onosSet )
3342 getResponses = []
3343 threads = []
Jon Halla440e872016-03-31 15:15:50 -07003344 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07003345 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07003346 name="setTestGet-" + str( i ),
3347 args=[ onosSetName ] )
3348 threads.append( t )
3349 t.start()
3350 for t in threads:
3351 t.join()
3352 getResponses.append( t.result )
3353 getResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07003354 for i in range( len( main.activeNodes ) ):
3355 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07003356 if isinstance( getResponses[ i ], list):
3357 current = set( getResponses[ i ] )
3358 if len( current ) == len( getResponses[ i ] ):
3359 # no repeats
3360 if onosSet != current:
Jon Halla440e872016-03-31 15:15:50 -07003361 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07003362 " has incorrect view" +
3363 " of set " + onosSetName + ":\n" +
3364 str( getResponses[ i ] ) )
3365 main.log.debug( "Expected: " + str( onosSet ) )
3366 main.log.debug( "Actual: " + str( current ) )
3367 getResults = main.FALSE
3368 else:
3369 # error, set is not a set
Jon Halla440e872016-03-31 15:15:50 -07003370 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07003371 " has repeat elements in" +
3372 " set " + onosSetName + ":\n" +
3373 str( getResponses[ i ] ) )
3374 getResults = main.FALSE
3375 elif getResponses[ i ] == main.ERROR:
3376 getResults = main.FALSE
3377 sizeResponses = []
3378 threads = []
Jon Halla440e872016-03-31 15:15:50 -07003379 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07003380 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall85794ff2015-07-08 14:12:30 -07003381 name="setTestSize-" + str( i ),
3382 args=[ onosSetName ] )
3383 threads.append( t )
3384 t.start()
3385 for t in threads:
3386 t.join()
3387 sizeResponses.append( t.result )
3388 sizeResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07003389 for i in range( len( main.activeNodes ) ):
3390 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07003391 if size != sizeResponses[ i ]:
3392 sizeResults = main.FALSE
Jon Halla440e872016-03-31 15:15:50 -07003393 main.log.error( "ONOS" + node + " expected a size of " +
Jon Hall85794ff2015-07-08 14:12:30 -07003394 str( size ) + " for set " + onosSetName +
3395 " but got " + str( sizeResponses[ i ] ) )
3396 retainResults = retainResults and getResults and sizeResults
3397 utilities.assert_equals( expect=main.TRUE,
3398 actual=retainResults,
3399 onpass="Set retain correct",
3400 onfail="Set retain was incorrect" )
3401
Jon Hall2a5002c2015-08-21 16:49:11 -07003402 # Transactional maps
3403 main.step( "Partitioned Transactional maps put" )
3404 tMapValue = "Testing"
3405 numKeys = 100
3406 putResult = True
Jon Halla440e872016-03-31 15:15:50 -07003407 node = main.activeNodes[0]
3408 putResponses = main.CLIs[node].transactionalMapPut( numKeys, tMapValue )
3409 if putResponses and len( putResponses ) == 100:
Jon Hall2a5002c2015-08-21 16:49:11 -07003410 for i in putResponses:
3411 if putResponses[ i ][ 'value' ] != tMapValue:
3412 putResult = False
3413 else:
3414 putResult = False
3415 if not putResult:
3416 main.log.debug( "Put response values: " + str( putResponses ) )
3417 utilities.assert_equals( expect=True,
3418 actual=putResult,
3419 onpass="Partitioned Transactional Map put successful",
3420 onfail="Partitioned Transactional Map put values are incorrect" )
3421
3422 main.step( "Partitioned Transactional maps get" )
3423 getCheck = True
3424 for n in range( 1, numKeys + 1 ):
3425 getResponses = []
3426 threads = []
3427 valueCheck = True
Jon Halla440e872016-03-31 15:15:50 -07003428 for i in main.activeNodes:
Jon Hall2a5002c2015-08-21 16:49:11 -07003429 t = main.Thread( target=main.CLIs[i].transactionalMapGet,
3430 name="TMap-get-" + str( i ),
Jon Halla440e872016-03-31 15:15:50 -07003431 args=[ "Key" + str( n ) ] )
Jon Hall2a5002c2015-08-21 16:49:11 -07003432 threads.append( t )
3433 t.start()
3434 for t in threads:
3435 t.join()
3436 getResponses.append( t.result )
3437 for node in getResponses:
3438 if node != tMapValue:
3439 valueCheck = False
3440 if not valueCheck:
3441 main.log.warn( "Values for key 'Key" + str( n ) + "' do not match:" )
3442 main.log.warn( getResponses )
3443 getCheck = getCheck and valueCheck
3444 utilities.assert_equals( expect=True,
3445 actual=getCheck,
3446 onpass="Partitioned Transactional Map get values were correct",
3447 onfail="Partitioned Transactional Map values incorrect" )