blob: 85e4036ad603595840e9e195bdb5914e4efbc740 [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 for i in main.activeNodes:
2072 main.CLIs[i].electionTestRun()
Jon Hall25463a82016-04-13 14:03:52 -07002073 time.sleep(5)
2074 activeCLIs = [ main.CLIs[i] for i in main.activeNodes ]
2075 sameResult, leaders = main.HA.consistentLeaderboards( activeCLIs )
Jon Hall85794ff2015-07-08 14:12:30 -07002076 utilities.assert_equals(
Jon Hall25463a82016-04-13 14:03:52 -07002077 expect=True,
2078 actual=sameResult,
2079 onpass="All nodes see the same leaderboards",
2080 onfail="Inconsistent leaderboards" )
2081
2082 if sameResult:
2083 leader = leaders[ 0 ][ 0 ]
2084 if main.nodes[main.activeNodes[0]].ip_address in leader:
2085 correctLeader = True
2086 else:
2087 correctLeader = False
2088 main.step( "First node was elected leader" )
2089 utilities.assert_equals(
2090 expect=True,
2091 actual=correctLeader,
2092 onpass="Correct leader was elected",
2093 onfail="Incorrect leader" )
Jon Hall85794ff2015-07-08 14:12:30 -07002094
2095 def CASE15( self, main ):
2096 """
2097 Check that Leadership Election is still functional
acsmars71adceb2015-08-31 15:09:26 -07002098 15.1 Run election on each node
2099 15.2 Check that each node has the same leaders and candidates
2100 15.3 Find current leader and withdraw
2101 15.4 Check that a new node was elected leader
2102 15.5 Check that that new leader was the candidate of old leader
2103 15.6 Run for election on old leader
2104 15.7 Check that oldLeader is a candidate, and leader if only 1 node
2105 15.8 Make sure that the old leader was added to the candidate list
2106
2107 old and new variable prefixes refer to data from before vs after
2108 withdrawl and later before withdrawl vs after re-election
Jon Hall85794ff2015-07-08 14:12:30 -07002109 """
acsmars71adceb2015-08-31 15:09:26 -07002110 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002111 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07002112 assert main, "main not defined"
2113 assert utilities.assert_equals, "utilities.assert_equals not defined"
acsmars71adceb2015-08-31 15:09:26 -07002114 assert main.CLIs, "main.CLIs not defined"
2115 assert main.nodes, "main.nodes not defined"
2116
Jon Hall85794ff2015-07-08 14:12:30 -07002117 description = "Check that Leadership Election is still functional"
2118 main.case( description )
Jon Halla440e872016-03-31 15:15:50 -07002119 # NOTE: Need to re-run after restarts since being a canidate is not persistant
acsmars2c2fcdd2015-08-25 17:14:13 -07002120
Jon Halla440e872016-03-31 15:15:50 -07002121 oldLeaders = [] # list of lists of each nodes' candidates before
2122 newLeaders = [] # list of lists of each nodes' candidates after
acsmars71adceb2015-08-31 15:09:26 -07002123 oldLeader = '' # the old leader from oldLeaders, None if not same
2124 newLeader = '' # the new leaders fron newLoeaders, None if not same
2125 oldLeaderCLI = None # the CLI of the old leader used for re-electing
2126 expectNoLeader = False # True when there is only one leader
2127 if main.numCtrls == 1:
2128 expectNoLeader = True
acsmars2c2fcdd2015-08-25 17:14:13 -07002129
acsmars71adceb2015-08-31 15:09:26 -07002130 main.step( "Run for election on each node" )
2131 electionResult = main.TRUE
2132
Jon Halla440e872016-03-31 15:15:50 -07002133 for i in main.activeNodes: # run test election on each node
2134 if main.CLIs[i].electionTestRun() == main.FALSE:
acsmars71adceb2015-08-31 15:09:26 -07002135 electionResult = main.FALSE
acsmars71adceb2015-08-31 15:09:26 -07002136 utilities.assert_equals(
2137 expect=main.TRUE,
2138 actual=electionResult,
2139 onpass="All nodes successfully ran for leadership",
2140 onfail="At least one node failed to run for leadership" )
2141
acsmars3a72bde2015-09-02 14:16:22 -07002142 if electionResult == main.FALSE:
2143 main.log.error(
2144 "Skipping Test Case because Election Test App isn't loaded" )
2145 main.skipCase()
2146
acsmars71adceb2015-08-31 15:09:26 -07002147 main.step( "Check that each node shows the same leader and candidates" )
Jon Halla440e872016-03-31 15:15:50 -07002148 failMessage = "Nodes have different leaderboards"
Jon Halla440e872016-03-31 15:15:50 -07002149 activeCLIs = [ main.CLIs[i] for i in main.activeNodes ]
Jon Hall41d39f12016-04-11 22:54:35 -07002150 sameResult, oldLeaders = main.HA.consistentLeaderboards( activeCLIs )
Jon Halla440e872016-03-31 15:15:50 -07002151 if sameResult:
2152 oldLeader = oldLeaders[ 0 ][ 0 ]
2153 main.log.warn( oldLeader )
Jon Hall85794ff2015-07-08 14:12:30 -07002154 else:
Jon Halla440e872016-03-31 15:15:50 -07002155 oldLeader = None
acsmars71adceb2015-08-31 15:09:26 -07002156 utilities.assert_equals(
Jon Halla440e872016-03-31 15:15:50 -07002157 expect=True,
acsmars71adceb2015-08-31 15:09:26 -07002158 actual=sameResult,
Jon Halla440e872016-03-31 15:15:50 -07002159 onpass="Leaderboards are consistent for the election topic",
acsmars71adceb2015-08-31 15:09:26 -07002160 onfail=failMessage )
2161
2162 main.step( "Find current leader and withdraw" )
2163 withdrawResult = main.TRUE
2164 # do some sanity checking on leader before using it
2165 if oldLeader is None:
2166 main.log.error( "Leadership isn't consistent." )
2167 withdrawResult = main.FALSE
2168 # Get the CLI of the oldLeader
Jon Halla440e872016-03-31 15:15:50 -07002169 for i in main.activeNodes:
acsmars71adceb2015-08-31 15:09:26 -07002170 if oldLeader == main.nodes[ i ].ip_address:
2171 oldLeaderCLI = main.CLIs[ i ]
2172 break
2173 else: # FOR/ELSE statement
2174 main.log.error( "Leader election, could not find current leader" )
Jon Hall85794ff2015-07-08 14:12:30 -07002175 if oldLeader:
acsmars71adceb2015-08-31 15:09:26 -07002176 withdrawResult = oldLeaderCLI.electionTestWithdraw()
Jon Hall85794ff2015-07-08 14:12:30 -07002177 utilities.assert_equals(
2178 expect=main.TRUE,
2179 actual=withdrawResult,
2180 onpass="Node was withdrawn from election",
2181 onfail="Node was not withdrawn from election" )
2182
acsmars71adceb2015-08-31 15:09:26 -07002183 main.step( "Check that a new node was elected leader" )
acsmars71adceb2015-08-31 15:09:26 -07002184 failMessage = "Nodes have different leaders"
acsmars71adceb2015-08-31 15:09:26 -07002185 # Get new leaders and candidates
Jon Hall41d39f12016-04-11 22:54:35 -07002186 newLeaderResult, newLeaders = main.HA.consistentLeaderboards( activeCLIs )
Jon Hall3a7843a2016-04-12 03:01:09 -07002187 newLeader = None
Jon Halla440e872016-03-31 15:15:50 -07002188 if newLeaderResult:
Jon Hall3a7843a2016-04-12 03:01:09 -07002189 if newLeaders[ 0 ][ 0 ] == 'none':
2190 main.log.error( "No leader was elected on at least 1 node" )
2191 if not expectNoLeader:
2192 newLeaderResult = False
Jon Hall25463a82016-04-13 14:03:52 -07002193 newLeader = newLeaders[ 0 ][ 0 ]
acsmars71adceb2015-08-31 15:09:26 -07002194
2195 # Check that the new leader is not the older leader, which was withdrawn
2196 if newLeader == oldLeader:
Jon Halla440e872016-03-31 15:15:50 -07002197 newLeaderResult = False
2198 main.log.error( "All nodes still see old leader: " + str( oldLeader ) +
acsmars71adceb2015-08-31 15:09:26 -07002199 " as the current leader" )
Jon Hall85794ff2015-07-08 14:12:30 -07002200 utilities.assert_equals(
Jon Halla440e872016-03-31 15:15:50 -07002201 expect=True,
acsmars71adceb2015-08-31 15:09:26 -07002202 actual=newLeaderResult,
2203 onpass="Leadership election passed",
2204 onfail="Something went wrong with Leadership election" )
Jon Hall85794ff2015-07-08 14:12:30 -07002205
Jon Halla440e872016-03-31 15:15:50 -07002206 main.step( "Check that that new leader was the candidate of old leader" )
2207 # candidates[ 2 ] should become the top candidate after withdrawl
acsmars71adceb2015-08-31 15:09:26 -07002208 correctCandidateResult = main.TRUE
2209 if expectNoLeader:
2210 if newLeader == 'none':
2211 main.log.info( "No leader expected. None found. Pass" )
2212 correctCandidateResult = main.TRUE
2213 else:
2214 main.log.info( "Expected no leader, got: " + str( newLeader ) )
2215 correctCandidateResult = main.FALSE
Jon Halla440e872016-03-31 15:15:50 -07002216 elif len( oldLeaders[0] ) >= 3:
2217 if newLeader == oldLeaders[ 0 ][ 2 ]:
2218 # correct leader was elected
2219 correctCandidateResult = main.TRUE
2220 else:
2221 correctCandidateResult = main.FALSE
2222 main.log.error( "Candidate {} was elected. {} should have had priority.".format(
2223 newLeader, oldLeaders[ 0 ][ 2 ] ) )
2224 else:
2225 main.log.warn( "Could not determine who should be the correct leader" )
2226 main.log.debug( oldLeaders[ 0 ] )
acsmars71adceb2015-08-31 15:09:26 -07002227 correctCandidateResult = main.FALSE
acsmars71adceb2015-08-31 15:09:26 -07002228 utilities.assert_equals(
2229 expect=main.TRUE,
2230 actual=correctCandidateResult,
2231 onpass="Correct Candidate Elected",
2232 onfail="Incorrect Candidate Elected" )
2233
Jon Hall85794ff2015-07-08 14:12:30 -07002234 main.step( "Run for election on old leader( just so everyone " +
2235 "is in the hat )" )
acsmars71adceb2015-08-31 15:09:26 -07002236 if oldLeaderCLI is not None:
2237 runResult = oldLeaderCLI.electionTestRun()
Jon Hall85794ff2015-07-08 14:12:30 -07002238 else:
acsmars71adceb2015-08-31 15:09:26 -07002239 main.log.error( "No old leader to re-elect" )
Jon Hall85794ff2015-07-08 14:12:30 -07002240 runResult = main.FALSE
2241 utilities.assert_equals(
2242 expect=main.TRUE,
2243 actual=runResult,
2244 onpass="App re-ran for election",
2245 onfail="App failed to run for election" )
Jon Halla440e872016-03-31 15:15:50 -07002246
acsmars71adceb2015-08-31 15:09:26 -07002247 main.step(
2248 "Check that oldLeader is a candidate, and leader if only 1 node" )
2249 # verify leader didn't just change
Jon Halla440e872016-03-31 15:15:50 -07002250 # Get new leaders and candidates
2251 reRunLeaders = []
2252 time.sleep( 5 ) # Paremterize
Jon Hall41d39f12016-04-11 22:54:35 -07002253 positionResult, reRunLeaders = main.HA.consistentLeaderboards( activeCLIs )
acsmars71adceb2015-08-31 15:09:26 -07002254
2255 # Check that the re-elected node is last on the candidate List
Jon Hall3a7843a2016-04-12 03:01:09 -07002256 if not reRunLeaders[0]:
2257 positionResult = main.FALSE
2258 elif oldLeader != reRunLeaders[ 0 ][ -1 ]:
Jon Halla440e872016-03-31 15:15:50 -07002259 main.log.error( "Old Leader ({}) not in the proper position: {} ".format( str( oldLeader),
2260 str( reRunLeaders[ 0 ] ) ) )
acsmars71adceb2015-08-31 15:09:26 -07002261 positionResult = main.FALSE
Jon Hall85794ff2015-07-08 14:12:30 -07002262 utilities.assert_equals(
Jon Halla440e872016-03-31 15:15:50 -07002263 expect=True,
acsmars71adceb2015-08-31 15:09:26 -07002264 actual=positionResult,
Jon Hall85794ff2015-07-08 14:12:30 -07002265 onpass="Old leader successfully re-ran for election",
2266 onfail="Something went wrong with Leadership election after " +
2267 "the old leader re-ran for election" )
2268
2269 def CASE16( self, main ):
2270 """
2271 Install Distributed Primitives app
2272 """
Jon Halla440e872016-03-31 15:15:50 -07002273 import time
Jon Halle1a3b752015-07-22 13:02:46 -07002274 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07002275 assert main, "main not defined"
2276 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002277 assert main.CLIs, "main.CLIs not defined"
2278 assert main.nodes, "main.nodes not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07002279
2280 # Variables for the distributed primitives tests
2281 global pCounterName
Jon Hall85794ff2015-07-08 14:12:30 -07002282 global pCounterValue
Jon Hall85794ff2015-07-08 14:12:30 -07002283 global onosSet
2284 global onosSetName
2285 pCounterName = "TestON-Partitions"
Jon Hall85794ff2015-07-08 14:12:30 -07002286 pCounterValue = 0
Jon Hall85794ff2015-07-08 14:12:30 -07002287 onosSet = set([])
2288 onosSetName = "TestON-set"
2289
2290 description = "Install Primitives app"
2291 main.case( description )
2292 main.step( "Install Primitives app" )
2293 appName = "org.onosproject.distributedprimitives"
Jon Halla440e872016-03-31 15:15:50 -07002294 node = main.activeNodes[0]
2295 appResults = main.CLIs[node].activateApp( appName )
Jon Hall85794ff2015-07-08 14:12:30 -07002296 utilities.assert_equals( expect=main.TRUE,
2297 actual=appResults,
2298 onpass="Primitives app activated",
2299 onfail="Primitives app not activated" )
Jon Halla440e872016-03-31 15:15:50 -07002300 time.sleep( 5 ) # To allow all nodes to activate
Jon Hall85794ff2015-07-08 14:12:30 -07002301
2302 def CASE17( self, main ):
2303 """
2304 Check for basic functionality with distributed primitives
2305 """
Jon Hall85794ff2015-07-08 14:12:30 -07002306 # Make sure variables are defined/set
Jon Halle1a3b752015-07-22 13:02:46 -07002307 assert main.numCtrls, "main.numCtrls not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07002308 assert main, "main not defined"
2309 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halle1a3b752015-07-22 13:02:46 -07002310 assert main.CLIs, "main.CLIs not defined"
2311 assert main.nodes, "main.nodes not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07002312 assert pCounterName, "pCounterName not defined"
Jon Hall85794ff2015-07-08 14:12:30 -07002313 assert onosSetName, "onosSetName not defined"
2314 # NOTE: assert fails if value is 0/None/Empty/False
2315 try:
2316 pCounterValue
2317 except NameError:
2318 main.log.error( "pCounterValue not defined, setting to 0" )
2319 pCounterValue = 0
2320 try:
Jon Hall85794ff2015-07-08 14:12:30 -07002321 onosSet
2322 except NameError:
2323 main.log.error( "onosSet not defined, setting to empty Set" )
2324 onosSet = set([])
2325 # Variables for the distributed primitives tests. These are local only
2326 addValue = "a"
2327 addAllValue = "a b c d e f"
2328 retainValue = "c d e f"
2329
2330 description = "Check for basic functionality with distributed " +\
2331 "primitives"
2332 main.case( description )
Jon Halle1a3b752015-07-22 13:02:46 -07002333 main.caseExplanation = "Test the methods of the distributed " +\
2334 "primitives (counters and sets) throught the cli"
Jon Hall85794ff2015-07-08 14:12:30 -07002335 # DISTRIBUTED ATOMIC COUNTERS
Jon Halle1a3b752015-07-22 13:02:46 -07002336 # Partitioned counters
2337 main.step( "Increment then get a default counter on each node" )
Jon Hall85794ff2015-07-08 14:12:30 -07002338 pCounters = []
2339 threads = []
2340 addedPValues = []
Jon Halla440e872016-03-31 15:15:50 -07002341 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002342 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
2343 name="counterAddAndGet-" + str( i ),
Jon Hall85794ff2015-07-08 14:12:30 -07002344 args=[ pCounterName ] )
2345 pCounterValue += 1
2346 addedPValues.append( pCounterValue )
2347 threads.append( t )
2348 t.start()
2349
2350 for t in threads:
2351 t.join()
2352 pCounters.append( t.result )
2353 # Check that counter incremented numController times
2354 pCounterResults = True
2355 for i in addedPValues:
2356 tmpResult = i in pCounters
2357 pCounterResults = pCounterResults and tmpResult
2358 if not tmpResult:
2359 main.log.error( str( i ) + " is not in partitioned "
2360 "counter incremented results" )
2361 utilities.assert_equals( expect=True,
2362 actual=pCounterResults,
2363 onpass="Default counter incremented",
2364 onfail="Error incrementing default" +
2365 " counter" )
2366
Jon Halle1a3b752015-07-22 13:02:46 -07002367 main.step( "Get then Increment a default counter on each node" )
2368 pCounters = []
2369 threads = []
2370 addedPValues = []
Jon Halla440e872016-03-31 15:15:50 -07002371 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002372 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
2373 name="counterGetAndAdd-" + str( i ),
2374 args=[ pCounterName ] )
2375 addedPValues.append( pCounterValue )
2376 pCounterValue += 1
2377 threads.append( t )
2378 t.start()
2379
2380 for t in threads:
2381 t.join()
2382 pCounters.append( t.result )
2383 # Check that counter incremented numController times
2384 pCounterResults = True
2385 for i in addedPValues:
2386 tmpResult = i in pCounters
2387 pCounterResults = pCounterResults and tmpResult
2388 if not tmpResult:
2389 main.log.error( str( i ) + " is not in partitioned "
2390 "counter incremented results" )
2391 utilities.assert_equals( expect=True,
2392 actual=pCounterResults,
2393 onpass="Default counter incremented",
2394 onfail="Error incrementing default" +
2395 " counter" )
2396
2397 main.step( "Counters we added have the correct values" )
Jon Hall41d39f12016-04-11 22:54:35 -07002398 incrementCheck = main.HA.counterCheck( pCounterName, pCounterValue )
Jon Halle1a3b752015-07-22 13:02:46 -07002399 utilities.assert_equals( expect=main.TRUE,
2400 actual=incrementCheck,
2401 onpass="Added counters are correct",
2402 onfail="Added counters are incorrect" )
2403
2404 main.step( "Add -8 to then get a default counter on each node" )
2405 pCounters = []
2406 threads = []
2407 addedPValues = []
Jon Halla440e872016-03-31 15:15:50 -07002408 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002409 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
2410 name="counterIncrement-" + str( i ),
2411 args=[ pCounterName ],
2412 kwargs={ "delta": -8 } )
2413 pCounterValue += -8
2414 addedPValues.append( pCounterValue )
2415 threads.append( t )
2416 t.start()
2417
2418 for t in threads:
2419 t.join()
2420 pCounters.append( t.result )
2421 # Check that counter incremented numController times
2422 pCounterResults = True
2423 for i in addedPValues:
2424 tmpResult = i in pCounters
2425 pCounterResults = pCounterResults and tmpResult
2426 if not tmpResult:
2427 main.log.error( str( i ) + " is not in partitioned "
2428 "counter incremented results" )
2429 utilities.assert_equals( expect=True,
2430 actual=pCounterResults,
2431 onpass="Default counter incremented",
2432 onfail="Error incrementing default" +
2433 " counter" )
2434
2435 main.step( "Add 5 to then get a default counter on each node" )
2436 pCounters = []
2437 threads = []
2438 addedPValues = []
Jon Halla440e872016-03-31 15:15:50 -07002439 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002440 t = main.Thread( target=main.CLIs[i].counterTestAddAndGet,
2441 name="counterIncrement-" + str( i ),
2442 args=[ pCounterName ],
2443 kwargs={ "delta": 5 } )
2444 pCounterValue += 5
2445 addedPValues.append( pCounterValue )
2446 threads.append( t )
2447 t.start()
2448
2449 for t in threads:
2450 t.join()
2451 pCounters.append( t.result )
2452 # Check that counter incremented numController times
2453 pCounterResults = True
2454 for i in addedPValues:
2455 tmpResult = i in pCounters
2456 pCounterResults = pCounterResults and tmpResult
2457 if not tmpResult:
2458 main.log.error( str( i ) + " is not in partitioned "
2459 "counter incremented results" )
2460 utilities.assert_equals( expect=True,
2461 actual=pCounterResults,
2462 onpass="Default counter incremented",
2463 onfail="Error incrementing default" +
2464 " counter" )
2465
2466 main.step( "Get then add 5 to a default counter on each node" )
2467 pCounters = []
2468 threads = []
2469 addedPValues = []
Jon Halla440e872016-03-31 15:15:50 -07002470 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002471 t = main.Thread( target=main.CLIs[i].counterTestGetAndAdd,
2472 name="counterIncrement-" + str( i ),
2473 args=[ pCounterName ],
2474 kwargs={ "delta": 5 } )
2475 addedPValues.append( pCounterValue )
2476 pCounterValue += 5
2477 threads.append( t )
2478 t.start()
2479
2480 for t in threads:
2481 t.join()
2482 pCounters.append( t.result )
2483 # Check that counter incremented numController times
2484 pCounterResults = True
2485 for i in addedPValues:
2486 tmpResult = i in pCounters
2487 pCounterResults = pCounterResults and tmpResult
2488 if not tmpResult:
2489 main.log.error( str( i ) + " is not in partitioned "
2490 "counter incremented results" )
2491 utilities.assert_equals( expect=True,
2492 actual=pCounterResults,
2493 onpass="Default counter incremented",
2494 onfail="Error incrementing default" +
2495 " counter" )
2496
2497 main.step( "Counters we added have the correct values" )
Jon Hall41d39f12016-04-11 22:54:35 -07002498 incrementCheck = main.HA.counterCheck( pCounterName, pCounterValue )
Jon Halle1a3b752015-07-22 13:02:46 -07002499 utilities.assert_equals( expect=main.TRUE,
2500 actual=incrementCheck,
2501 onpass="Added counters are correct",
2502 onfail="Added counters are incorrect" )
2503
Jon Hall85794ff2015-07-08 14:12:30 -07002504 # DISTRIBUTED SETS
2505 main.step( "Distributed Set get" )
2506 size = len( onosSet )
2507 getResponses = []
2508 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002509 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002510 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07002511 name="setTestGet-" + str( i ),
2512 args=[ onosSetName ] )
2513 threads.append( t )
2514 t.start()
2515 for t in threads:
2516 t.join()
2517 getResponses.append( t.result )
2518
2519 getResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002520 for i in range( len( main.activeNodes ) ):
2521 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07002522 if isinstance( getResponses[ i ], list):
2523 current = set( getResponses[ i ] )
2524 if len( current ) == len( getResponses[ i ] ):
2525 # no repeats
2526 if onosSet != current:
Jon Halla440e872016-03-31 15:15:50 -07002527 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07002528 " has incorrect view" +
2529 " of set " + onosSetName + ":\n" +
2530 str( getResponses[ i ] ) )
2531 main.log.debug( "Expected: " + str( onosSet ) )
2532 main.log.debug( "Actual: " + str( current ) )
2533 getResults = main.FALSE
2534 else:
2535 # error, set is not a set
Jon Halla440e872016-03-31 15:15:50 -07002536 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07002537 " has repeat elements in" +
2538 " set " + onosSetName + ":\n" +
2539 str( getResponses[ i ] ) )
2540 getResults = main.FALSE
2541 elif getResponses[ i ] == main.ERROR:
2542 getResults = main.FALSE
2543 utilities.assert_equals( expect=main.TRUE,
2544 actual=getResults,
2545 onpass="Set elements are correct",
2546 onfail="Set elements are incorrect" )
2547
2548 main.step( "Distributed Set size" )
2549 sizeResponses = []
2550 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002551 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002552 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall85794ff2015-07-08 14:12:30 -07002553 name="setTestSize-" + str( i ),
2554 args=[ onosSetName ] )
2555 threads.append( t )
2556 t.start()
2557 for t in threads:
2558 t.join()
2559 sizeResponses.append( t.result )
2560
2561 sizeResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002562 for i in range( len( main.activeNodes ) ):
2563 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07002564 if size != sizeResponses[ i ]:
2565 sizeResults = main.FALSE
Jon Halla440e872016-03-31 15:15:50 -07002566 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07002567 " expected a size of " + str( size ) +
2568 " for set " + onosSetName +
2569 " but got " + str( sizeResponses[ i ] ) )
2570 utilities.assert_equals( expect=main.TRUE,
2571 actual=sizeResults,
2572 onpass="Set sizes are correct",
2573 onfail="Set sizes are incorrect" )
2574
2575 main.step( "Distributed Set add()" )
2576 onosSet.add( addValue )
2577 addResponses = []
2578 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002579 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002580 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall85794ff2015-07-08 14:12:30 -07002581 name="setTestAdd-" + str( i ),
2582 args=[ onosSetName, addValue ] )
2583 threads.append( t )
2584 t.start()
2585 for t in threads:
2586 t.join()
2587 addResponses.append( t.result )
2588
2589 # main.TRUE = successfully changed the set
2590 # main.FALSE = action resulted in no change in set
2591 # main.ERROR - Some error in executing the function
2592 addResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002593 for i in range( len( main.activeNodes ) ):
Jon Hall85794ff2015-07-08 14:12:30 -07002594 if addResponses[ i ] == main.TRUE:
2595 # All is well
2596 pass
2597 elif addResponses[ i ] == main.FALSE:
2598 # Already in set, probably fine
2599 pass
2600 elif addResponses[ i ] == main.ERROR:
2601 # Error in execution
2602 addResults = main.FALSE
2603 else:
2604 # unexpected result
2605 addResults = main.FALSE
2606 if addResults != main.TRUE:
2607 main.log.error( "Error executing set add" )
2608
2609 # Check if set is still correct
2610 size = len( onosSet )
2611 getResponses = []
2612 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002613 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002614 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07002615 name="setTestGet-" + str( i ),
2616 args=[ onosSetName ] )
2617 threads.append( t )
2618 t.start()
2619 for t in threads:
2620 t.join()
2621 getResponses.append( t.result )
2622 getResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002623 for i in range( len( main.activeNodes ) ):
2624 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07002625 if isinstance( getResponses[ i ], list):
2626 current = set( getResponses[ i ] )
2627 if len( current ) == len( getResponses[ i ] ):
2628 # no repeats
2629 if onosSet != current:
Jon Halla440e872016-03-31 15:15:50 -07002630 main.log.error( "ONOS" + node + " has incorrect view" +
Jon Hall85794ff2015-07-08 14:12:30 -07002631 " of set " + onosSetName + ":\n" +
2632 str( getResponses[ i ] ) )
2633 main.log.debug( "Expected: " + str( onosSet ) )
2634 main.log.debug( "Actual: " + str( current ) )
2635 getResults = main.FALSE
2636 else:
2637 # error, set is not a set
Jon Halla440e872016-03-31 15:15:50 -07002638 main.log.error( "ONOS" + node + " has repeat elements in" +
Jon Hall85794ff2015-07-08 14:12:30 -07002639 " set " + onosSetName + ":\n" +
2640 str( getResponses[ i ] ) )
2641 getResults = main.FALSE
2642 elif getResponses[ i ] == main.ERROR:
2643 getResults = main.FALSE
2644 sizeResponses = []
2645 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002646 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002647 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall85794ff2015-07-08 14:12:30 -07002648 name="setTestSize-" + str( i ),
2649 args=[ onosSetName ] )
2650 threads.append( t )
2651 t.start()
2652 for t in threads:
2653 t.join()
2654 sizeResponses.append( t.result )
2655 sizeResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002656 for i in range( len( main.activeNodes ) ):
2657 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07002658 if size != sizeResponses[ i ]:
2659 sizeResults = main.FALSE
Jon Halla440e872016-03-31 15:15:50 -07002660 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07002661 " expected a size of " + str( size ) +
2662 " for set " + onosSetName +
2663 " but got " + str( sizeResponses[ i ] ) )
2664 addResults = addResults and getResults and sizeResults
2665 utilities.assert_equals( expect=main.TRUE,
2666 actual=addResults,
2667 onpass="Set add correct",
2668 onfail="Set add was incorrect" )
2669
2670 main.step( "Distributed Set addAll()" )
2671 onosSet.update( addAllValue.split() )
2672 addResponses = []
2673 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002674 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002675 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall85794ff2015-07-08 14:12:30 -07002676 name="setTestAddAll-" + str( i ),
2677 args=[ onosSetName, addAllValue ] )
2678 threads.append( t )
2679 t.start()
2680 for t in threads:
2681 t.join()
2682 addResponses.append( t.result )
2683
2684 # main.TRUE = successfully changed the set
2685 # main.FALSE = action resulted in no change in set
2686 # main.ERROR - Some error in executing the function
2687 addAllResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002688 for i in range( len( main.activeNodes ) ):
Jon Hall85794ff2015-07-08 14:12:30 -07002689 if addResponses[ i ] == main.TRUE:
2690 # All is well
2691 pass
2692 elif addResponses[ i ] == main.FALSE:
2693 # Already in set, probably fine
2694 pass
2695 elif addResponses[ i ] == main.ERROR:
2696 # Error in execution
2697 addAllResults = main.FALSE
2698 else:
2699 # unexpected result
2700 addAllResults = main.FALSE
2701 if addAllResults != main.TRUE:
2702 main.log.error( "Error executing set addAll" )
2703
2704 # Check if set is still correct
2705 size = len( onosSet )
2706 getResponses = []
2707 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002708 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002709 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07002710 name="setTestGet-" + str( i ),
2711 args=[ onosSetName ] )
2712 threads.append( t )
2713 t.start()
2714 for t in threads:
2715 t.join()
2716 getResponses.append( t.result )
2717 getResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002718 for i in range( len( main.activeNodes ) ):
2719 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07002720 if isinstance( getResponses[ i ], list):
2721 current = set( getResponses[ i ] )
2722 if len( current ) == len( getResponses[ i ] ):
2723 # no repeats
2724 if onosSet != current:
Jon Halla440e872016-03-31 15:15:50 -07002725 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07002726 " has incorrect view" +
2727 " of set " + onosSetName + ":\n" +
2728 str( getResponses[ i ] ) )
2729 main.log.debug( "Expected: " + str( onosSet ) )
2730 main.log.debug( "Actual: " + str( current ) )
2731 getResults = main.FALSE
2732 else:
2733 # error, set is not a set
Jon Halla440e872016-03-31 15:15:50 -07002734 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07002735 " has repeat elements in" +
2736 " set " + onosSetName + ":\n" +
2737 str( getResponses[ i ] ) )
2738 getResults = main.FALSE
2739 elif getResponses[ i ] == main.ERROR:
2740 getResults = main.FALSE
2741 sizeResponses = []
2742 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002743 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002744 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall85794ff2015-07-08 14:12:30 -07002745 name="setTestSize-" + str( i ),
2746 args=[ onosSetName ] )
2747 threads.append( t )
2748 t.start()
2749 for t in threads:
2750 t.join()
2751 sizeResponses.append( t.result )
2752 sizeResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002753 for i in range( len( main.activeNodes ) ):
2754 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07002755 if size != sizeResponses[ i ]:
2756 sizeResults = main.FALSE
Jon Halla440e872016-03-31 15:15:50 -07002757 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07002758 " expected a size of " + str( size ) +
2759 " for set " + onosSetName +
2760 " but got " + str( sizeResponses[ i ] ) )
2761 addAllResults = addAllResults and getResults and sizeResults
2762 utilities.assert_equals( expect=main.TRUE,
2763 actual=addAllResults,
2764 onpass="Set addAll correct",
2765 onfail="Set addAll was incorrect" )
2766
2767 main.step( "Distributed Set contains()" )
2768 containsResponses = []
2769 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002770 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002771 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07002772 name="setContains-" + str( i ),
2773 args=[ onosSetName ],
2774 kwargs={ "values": addValue } )
2775 threads.append( t )
2776 t.start()
2777 for t in threads:
2778 t.join()
2779 # NOTE: This is the tuple
2780 containsResponses.append( t.result )
2781
2782 containsResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002783 for i in range( len( main.activeNodes ) ):
Jon Hall85794ff2015-07-08 14:12:30 -07002784 if containsResponses[ i ] == main.ERROR:
2785 containsResults = main.FALSE
2786 else:
2787 containsResults = containsResults and\
2788 containsResponses[ i ][ 1 ]
2789 utilities.assert_equals( expect=main.TRUE,
2790 actual=containsResults,
2791 onpass="Set contains is functional",
2792 onfail="Set contains failed" )
2793
2794 main.step( "Distributed Set containsAll()" )
2795 containsAllResponses = []
2796 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002797 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002798 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07002799 name="setContainsAll-" + str( i ),
2800 args=[ onosSetName ],
2801 kwargs={ "values": addAllValue } )
2802 threads.append( t )
2803 t.start()
2804 for t in threads:
2805 t.join()
2806 # NOTE: This is the tuple
2807 containsAllResponses.append( t.result )
2808
2809 containsAllResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002810 for i in range( len( main.activeNodes ) ):
Jon Hall85794ff2015-07-08 14:12:30 -07002811 if containsResponses[ i ] == main.ERROR:
2812 containsResults = main.FALSE
2813 else:
2814 containsResults = containsResults and\
2815 containsResponses[ i ][ 1 ]
2816 utilities.assert_equals( expect=main.TRUE,
2817 actual=containsAllResults,
2818 onpass="Set containsAll is functional",
2819 onfail="Set containsAll failed" )
2820
2821 main.step( "Distributed Set remove()" )
2822 onosSet.remove( addValue )
2823 removeResponses = []
2824 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002825 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002826 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall85794ff2015-07-08 14:12:30 -07002827 name="setTestRemove-" + str( i ),
2828 args=[ onosSetName, addValue ] )
2829 threads.append( t )
2830 t.start()
2831 for t in threads:
2832 t.join()
2833 removeResponses.append( t.result )
2834
2835 # main.TRUE = successfully changed the set
2836 # main.FALSE = action resulted in no change in set
2837 # main.ERROR - Some error in executing the function
2838 removeResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002839 for i in range( len( main.activeNodes ) ):
Jon Hall85794ff2015-07-08 14:12:30 -07002840 if removeResponses[ i ] == main.TRUE:
2841 # All is well
2842 pass
2843 elif removeResponses[ i ] == main.FALSE:
2844 # not in set, probably fine
2845 pass
2846 elif removeResponses[ i ] == main.ERROR:
2847 # Error in execution
2848 removeResults = main.FALSE
2849 else:
2850 # unexpected result
2851 removeResults = main.FALSE
2852 if removeResults != main.TRUE:
2853 main.log.error( "Error executing set remove" )
2854
2855 # Check if set is still correct
2856 size = len( onosSet )
2857 getResponses = []
2858 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002859 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002860 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07002861 name="setTestGet-" + str( i ),
2862 args=[ onosSetName ] )
2863 threads.append( t )
2864 t.start()
2865 for t in threads:
2866 t.join()
2867 getResponses.append( t.result )
2868 getResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002869 for i in range( len( main.activeNodes ) ):
2870 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07002871 if isinstance( getResponses[ i ], list):
2872 current = set( getResponses[ i ] )
2873 if len( current ) == len( getResponses[ i ] ):
2874 # no repeats
2875 if onosSet != current:
Jon Halla440e872016-03-31 15:15:50 -07002876 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07002877 " has incorrect view" +
2878 " of set " + onosSetName + ":\n" +
2879 str( getResponses[ i ] ) )
2880 main.log.debug( "Expected: " + str( onosSet ) )
2881 main.log.debug( "Actual: " + str( current ) )
2882 getResults = main.FALSE
2883 else:
2884 # error, set is not a set
Jon Halla440e872016-03-31 15:15:50 -07002885 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07002886 " has repeat elements in" +
2887 " set " + onosSetName + ":\n" +
2888 str( getResponses[ i ] ) )
2889 getResults = main.FALSE
2890 elif getResponses[ i ] == main.ERROR:
2891 getResults = main.FALSE
2892 sizeResponses = []
2893 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002894 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002895 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall85794ff2015-07-08 14:12:30 -07002896 name="setTestSize-" + str( i ),
2897 args=[ onosSetName ] )
2898 threads.append( t )
2899 t.start()
2900 for t in threads:
2901 t.join()
2902 sizeResponses.append( t.result )
2903 sizeResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002904 for i in range( len( main.activeNodes ) ):
2905 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07002906 if size != sizeResponses[ i ]:
2907 sizeResults = main.FALSE
Jon Halla440e872016-03-31 15:15:50 -07002908 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07002909 " expected a size of " + str( size ) +
2910 " for set " + onosSetName +
2911 " but got " + str( sizeResponses[ i ] ) )
2912 removeResults = removeResults and getResults and sizeResults
2913 utilities.assert_equals( expect=main.TRUE,
2914 actual=removeResults,
2915 onpass="Set remove correct",
2916 onfail="Set remove was incorrect" )
2917
2918 main.step( "Distributed Set removeAll()" )
2919 onosSet.difference_update( addAllValue.split() )
2920 removeAllResponses = []
2921 threads = []
2922 try:
Jon Halla440e872016-03-31 15:15:50 -07002923 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002924 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall85794ff2015-07-08 14:12:30 -07002925 name="setTestRemoveAll-" + str( i ),
2926 args=[ onosSetName, addAllValue ] )
2927 threads.append( t )
2928 t.start()
2929 for t in threads:
2930 t.join()
2931 removeAllResponses.append( t.result )
2932 except Exception, e:
2933 main.log.exception(e)
2934
2935 # main.TRUE = successfully changed the set
2936 # main.FALSE = action resulted in no change in set
2937 # main.ERROR - Some error in executing the function
2938 removeAllResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002939 for i in range( len( main.activeNodes ) ):
Jon Hall85794ff2015-07-08 14:12:30 -07002940 if removeAllResponses[ i ] == main.TRUE:
2941 # All is well
2942 pass
2943 elif removeAllResponses[ i ] == main.FALSE:
2944 # not in set, probably fine
2945 pass
2946 elif removeAllResponses[ i ] == main.ERROR:
2947 # Error in execution
2948 removeAllResults = main.FALSE
2949 else:
2950 # unexpected result
2951 removeAllResults = main.FALSE
2952 if removeAllResults != main.TRUE:
2953 main.log.error( "Error executing set removeAll" )
2954
2955 # Check if set is still correct
2956 size = len( onosSet )
2957 getResponses = []
2958 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002959 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002960 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07002961 name="setTestGet-" + str( i ),
2962 args=[ onosSetName ] )
2963 threads.append( t )
2964 t.start()
2965 for t in threads:
2966 t.join()
2967 getResponses.append( t.result )
2968 getResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07002969 for i in range( len( main.activeNodes ) ):
2970 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07002971 if isinstance( getResponses[ i ], list):
2972 current = set( getResponses[ i ] )
2973 if len( current ) == len( getResponses[ i ] ):
2974 # no repeats
2975 if onosSet != current:
Jon Halla440e872016-03-31 15:15:50 -07002976 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07002977 " has incorrect view" +
2978 " of set " + onosSetName + ":\n" +
2979 str( getResponses[ i ] ) )
2980 main.log.debug( "Expected: " + str( onosSet ) )
2981 main.log.debug( "Actual: " + str( current ) )
2982 getResults = main.FALSE
2983 else:
2984 # error, set is not a set
Jon Halla440e872016-03-31 15:15:50 -07002985 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07002986 " has repeat elements in" +
2987 " set " + onosSetName + ":\n" +
2988 str( getResponses[ i ] ) )
2989 getResults = main.FALSE
2990 elif getResponses[ i ] == main.ERROR:
2991 getResults = main.FALSE
2992 sizeResponses = []
2993 threads = []
Jon Halla440e872016-03-31 15:15:50 -07002994 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07002995 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall85794ff2015-07-08 14:12:30 -07002996 name="setTestSize-" + str( i ),
2997 args=[ onosSetName ] )
2998 threads.append( t )
2999 t.start()
3000 for t in threads:
3001 t.join()
3002 sizeResponses.append( t.result )
3003 sizeResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07003004 for i in range( len( main.activeNodes ) ):
3005 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07003006 if size != sizeResponses[ i ]:
3007 sizeResults = main.FALSE
Jon Halla440e872016-03-31 15:15:50 -07003008 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07003009 " expected a size of " + str( size ) +
3010 " for set " + onosSetName +
3011 " but got " + str( sizeResponses[ i ] ) )
3012 removeAllResults = removeAllResults and getResults and sizeResults
3013 utilities.assert_equals( expect=main.TRUE,
3014 actual=removeAllResults,
3015 onpass="Set removeAll correct",
3016 onfail="Set removeAll was incorrect" )
3017
3018 main.step( "Distributed Set addAll()" )
3019 onosSet.update( addAllValue.split() )
3020 addResponses = []
3021 threads = []
Jon Halla440e872016-03-31 15:15:50 -07003022 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07003023 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall85794ff2015-07-08 14:12:30 -07003024 name="setTestAddAll-" + str( i ),
3025 args=[ onosSetName, addAllValue ] )
3026 threads.append( t )
3027 t.start()
3028 for t in threads:
3029 t.join()
3030 addResponses.append( t.result )
3031
3032 # main.TRUE = successfully changed the set
3033 # main.FALSE = action resulted in no change in set
3034 # main.ERROR - Some error in executing the function
3035 addAllResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07003036 for i in range( len( main.activeNodes ) ):
Jon Hall85794ff2015-07-08 14:12:30 -07003037 if addResponses[ i ] == main.TRUE:
3038 # All is well
3039 pass
3040 elif addResponses[ i ] == main.FALSE:
3041 # Already in set, probably fine
3042 pass
3043 elif addResponses[ i ] == main.ERROR:
3044 # Error in execution
3045 addAllResults = main.FALSE
3046 else:
3047 # unexpected result
3048 addAllResults = main.FALSE
3049 if addAllResults != main.TRUE:
3050 main.log.error( "Error executing set addAll" )
3051
3052 # Check if set is still correct
3053 size = len( onosSet )
3054 getResponses = []
3055 threads = []
Jon Halla440e872016-03-31 15:15:50 -07003056 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07003057 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07003058 name="setTestGet-" + str( i ),
3059 args=[ onosSetName ] )
3060 threads.append( t )
3061 t.start()
3062 for t in threads:
3063 t.join()
3064 getResponses.append( t.result )
3065 getResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07003066 for i in range( len( main.activeNodes ) ):
3067 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07003068 if isinstance( getResponses[ i ], list):
3069 current = set( getResponses[ i ] )
3070 if len( current ) == len( getResponses[ i ] ):
3071 # no repeats
3072 if onosSet != current:
Jon Halla440e872016-03-31 15:15:50 -07003073 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07003074 " has incorrect view" +
3075 " of set " + onosSetName + ":\n" +
3076 str( getResponses[ i ] ) )
3077 main.log.debug( "Expected: " + str( onosSet ) )
3078 main.log.debug( "Actual: " + str( current ) )
3079 getResults = main.FALSE
3080 else:
3081 # error, set is not a set
Jon Halla440e872016-03-31 15:15:50 -07003082 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07003083 " has repeat elements in" +
3084 " set " + onosSetName + ":\n" +
3085 str( getResponses[ i ] ) )
3086 getResults = main.FALSE
3087 elif getResponses[ i ] == main.ERROR:
3088 getResults = main.FALSE
3089 sizeResponses = []
3090 threads = []
Jon Halla440e872016-03-31 15:15:50 -07003091 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07003092 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall85794ff2015-07-08 14:12:30 -07003093 name="setTestSize-" + str( i ),
3094 args=[ onosSetName ] )
3095 threads.append( t )
3096 t.start()
3097 for t in threads:
3098 t.join()
3099 sizeResponses.append( t.result )
3100 sizeResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07003101 for i in range( len( main.activeNodes ) ):
3102 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07003103 if size != sizeResponses[ i ]:
3104 sizeResults = main.FALSE
Jon Halla440e872016-03-31 15:15:50 -07003105 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07003106 " expected a size of " + str( size ) +
3107 " for set " + onosSetName +
3108 " but got " + str( sizeResponses[ i ] ) )
3109 addAllResults = addAllResults and getResults and sizeResults
3110 utilities.assert_equals( expect=main.TRUE,
3111 actual=addAllResults,
3112 onpass="Set addAll correct",
3113 onfail="Set addAll was incorrect" )
3114
3115 main.step( "Distributed Set clear()" )
3116 onosSet.clear()
3117 clearResponses = []
3118 threads = []
Jon Halla440e872016-03-31 15:15:50 -07003119 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07003120 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall85794ff2015-07-08 14:12:30 -07003121 name="setTestClear-" + str( i ),
3122 args=[ onosSetName, " "], # Values doesn't matter
3123 kwargs={ "clear": True } )
3124 threads.append( t )
3125 t.start()
3126 for t in threads:
3127 t.join()
3128 clearResponses.append( t.result )
3129
3130 # main.TRUE = successfully changed the set
3131 # main.FALSE = action resulted in no change in set
3132 # main.ERROR - Some error in executing the function
3133 clearResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07003134 for i in range( len( main.activeNodes ) ):
Jon Hall85794ff2015-07-08 14:12:30 -07003135 if clearResponses[ i ] == main.TRUE:
3136 # All is well
3137 pass
3138 elif clearResponses[ i ] == main.FALSE:
3139 # Nothing set, probably fine
3140 pass
3141 elif clearResponses[ i ] == main.ERROR:
3142 # Error in execution
3143 clearResults = main.FALSE
3144 else:
3145 # unexpected result
3146 clearResults = main.FALSE
3147 if clearResults != main.TRUE:
3148 main.log.error( "Error executing set clear" )
3149
3150 # Check if set is still correct
3151 size = len( onosSet )
3152 getResponses = []
3153 threads = []
Jon Halla440e872016-03-31 15:15:50 -07003154 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07003155 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07003156 name="setTestGet-" + str( i ),
3157 args=[ onosSetName ] )
3158 threads.append( t )
3159 t.start()
3160 for t in threads:
3161 t.join()
3162 getResponses.append( t.result )
3163 getResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07003164 for i in range( len( main.activeNodes ) ):
3165 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07003166 if isinstance( getResponses[ i ], list):
3167 current = set( getResponses[ i ] )
3168 if len( current ) == len( getResponses[ i ] ):
3169 # no repeats
3170 if onosSet != current:
Jon Halla440e872016-03-31 15:15:50 -07003171 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07003172 " has incorrect view" +
3173 " of set " + onosSetName + ":\n" +
3174 str( getResponses[ i ] ) )
3175 main.log.debug( "Expected: " + str( onosSet ) )
3176 main.log.debug( "Actual: " + str( current ) )
3177 getResults = main.FALSE
3178 else:
3179 # error, set is not a set
Jon Halla440e872016-03-31 15:15:50 -07003180 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07003181 " has repeat elements in" +
3182 " set " + onosSetName + ":\n" +
3183 str( getResponses[ i ] ) )
3184 getResults = main.FALSE
3185 elif getResponses[ i ] == main.ERROR:
3186 getResults = main.FALSE
3187 sizeResponses = []
3188 threads = []
Jon Halla440e872016-03-31 15:15:50 -07003189 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07003190 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall85794ff2015-07-08 14:12:30 -07003191 name="setTestSize-" + str( i ),
3192 args=[ onosSetName ] )
3193 threads.append( t )
3194 t.start()
3195 for t in threads:
3196 t.join()
3197 sizeResponses.append( t.result )
3198 sizeResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07003199 for i in range( len( main.activeNodes ) ):
3200 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07003201 if size != sizeResponses[ i ]:
3202 sizeResults = main.FALSE
Jon Halla440e872016-03-31 15:15:50 -07003203 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07003204 " expected a size of " + str( size ) +
3205 " for set " + onosSetName +
3206 " but got " + str( sizeResponses[ i ] ) )
3207 clearResults = clearResults and getResults and sizeResults
3208 utilities.assert_equals( expect=main.TRUE,
3209 actual=clearResults,
3210 onpass="Set clear correct",
3211 onfail="Set clear was incorrect" )
3212
3213 main.step( "Distributed Set addAll()" )
3214 onosSet.update( addAllValue.split() )
3215 addResponses = []
3216 threads = []
Jon Halla440e872016-03-31 15:15:50 -07003217 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07003218 t = main.Thread( target=main.CLIs[i].setTestAdd,
Jon Hall85794ff2015-07-08 14:12:30 -07003219 name="setTestAddAll-" + str( i ),
3220 args=[ onosSetName, addAllValue ] )
3221 threads.append( t )
3222 t.start()
3223 for t in threads:
3224 t.join()
3225 addResponses.append( t.result )
3226
3227 # main.TRUE = successfully changed the set
3228 # main.FALSE = action resulted in no change in set
3229 # main.ERROR - Some error in executing the function
3230 addAllResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07003231 for i in range( len( main.activeNodes ) ):
Jon Hall85794ff2015-07-08 14:12:30 -07003232 if addResponses[ i ] == main.TRUE:
3233 # All is well
3234 pass
3235 elif addResponses[ i ] == main.FALSE:
3236 # Already in set, probably fine
3237 pass
3238 elif addResponses[ i ] == main.ERROR:
3239 # Error in execution
3240 addAllResults = main.FALSE
3241 else:
3242 # unexpected result
3243 addAllResults = main.FALSE
3244 if addAllResults != main.TRUE:
3245 main.log.error( "Error executing set addAll" )
3246
3247 # Check if set is still correct
3248 size = len( onosSet )
3249 getResponses = []
3250 threads = []
Jon Halla440e872016-03-31 15:15:50 -07003251 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07003252 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07003253 name="setTestGet-" + str( i ),
3254 args=[ onosSetName ] )
3255 threads.append( t )
3256 t.start()
3257 for t in threads:
3258 t.join()
3259 getResponses.append( t.result )
3260 getResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07003261 for i in range( len( main.activeNodes ) ):
3262 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07003263 if isinstance( getResponses[ i ], list):
3264 current = set( getResponses[ i ] )
3265 if len( current ) == len( getResponses[ i ] ):
3266 # no repeats
3267 if onosSet != current:
Jon Halla440e872016-03-31 15:15:50 -07003268 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07003269 " has incorrect view" +
3270 " of set " + onosSetName + ":\n" +
3271 str( getResponses[ i ] ) )
3272 main.log.debug( "Expected: " + str( onosSet ) )
3273 main.log.debug( "Actual: " + str( current ) )
3274 getResults = main.FALSE
3275 else:
3276 # error, set is not a set
Jon Halla440e872016-03-31 15:15:50 -07003277 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07003278 " has repeat elements in" +
3279 " set " + onosSetName + ":\n" +
3280 str( getResponses[ i ] ) )
3281 getResults = main.FALSE
3282 elif getResponses[ i ] == main.ERROR:
3283 getResults = main.FALSE
3284 sizeResponses = []
3285 threads = []
Jon Halla440e872016-03-31 15:15:50 -07003286 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07003287 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall85794ff2015-07-08 14:12:30 -07003288 name="setTestSize-" + str( i ),
3289 args=[ onosSetName ] )
3290 threads.append( t )
3291 t.start()
3292 for t in threads:
3293 t.join()
3294 sizeResponses.append( t.result )
3295 sizeResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07003296 for i in range( len( main.activeNodes ) ):
3297 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07003298 if size != sizeResponses[ i ]:
3299 sizeResults = main.FALSE
Jon Halla440e872016-03-31 15:15:50 -07003300 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07003301 " expected a size of " + str( size ) +
3302 " for set " + onosSetName +
3303 " but got " + str( sizeResponses[ i ] ) )
3304 addAllResults = addAllResults and getResults and sizeResults
3305 utilities.assert_equals( expect=main.TRUE,
3306 actual=addAllResults,
3307 onpass="Set addAll correct",
3308 onfail="Set addAll was incorrect" )
3309
3310 main.step( "Distributed Set retain()" )
3311 onosSet.intersection_update( retainValue.split() )
3312 retainResponses = []
3313 threads = []
Jon Halla440e872016-03-31 15:15:50 -07003314 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07003315 t = main.Thread( target=main.CLIs[i].setTestRemove,
Jon Hall85794ff2015-07-08 14:12:30 -07003316 name="setTestRetain-" + str( i ),
3317 args=[ onosSetName, retainValue ],
3318 kwargs={ "retain": True } )
3319 threads.append( t )
3320 t.start()
3321 for t in threads:
3322 t.join()
3323 retainResponses.append( t.result )
3324
3325 # main.TRUE = successfully changed the set
3326 # main.FALSE = action resulted in no change in set
3327 # main.ERROR - Some error in executing the function
3328 retainResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07003329 for i in range( len( main.activeNodes ) ):
Jon Hall85794ff2015-07-08 14:12:30 -07003330 if retainResponses[ i ] == main.TRUE:
3331 # All is well
3332 pass
3333 elif retainResponses[ i ] == main.FALSE:
3334 # Already in set, probably fine
3335 pass
3336 elif retainResponses[ i ] == main.ERROR:
3337 # Error in execution
3338 retainResults = main.FALSE
3339 else:
3340 # unexpected result
3341 retainResults = main.FALSE
3342 if retainResults != main.TRUE:
3343 main.log.error( "Error executing set retain" )
3344
3345 # Check if set is still correct
3346 size = len( onosSet )
3347 getResponses = []
3348 threads = []
Jon Halla440e872016-03-31 15:15:50 -07003349 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07003350 t = main.Thread( target=main.CLIs[i].setTestGet,
Jon Hall85794ff2015-07-08 14:12:30 -07003351 name="setTestGet-" + str( i ),
3352 args=[ onosSetName ] )
3353 threads.append( t )
3354 t.start()
3355 for t in threads:
3356 t.join()
3357 getResponses.append( t.result )
3358 getResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07003359 for i in range( len( main.activeNodes ) ):
3360 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07003361 if isinstance( getResponses[ i ], list):
3362 current = set( getResponses[ i ] )
3363 if len( current ) == len( getResponses[ i ] ):
3364 # no repeats
3365 if onosSet != current:
Jon Halla440e872016-03-31 15:15:50 -07003366 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07003367 " has incorrect view" +
3368 " of set " + onosSetName + ":\n" +
3369 str( getResponses[ i ] ) )
3370 main.log.debug( "Expected: " + str( onosSet ) )
3371 main.log.debug( "Actual: " + str( current ) )
3372 getResults = main.FALSE
3373 else:
3374 # error, set is not a set
Jon Halla440e872016-03-31 15:15:50 -07003375 main.log.error( "ONOS" + node +
Jon Hall85794ff2015-07-08 14:12:30 -07003376 " has repeat elements in" +
3377 " set " + onosSetName + ":\n" +
3378 str( getResponses[ i ] ) )
3379 getResults = main.FALSE
3380 elif getResponses[ i ] == main.ERROR:
3381 getResults = main.FALSE
3382 sizeResponses = []
3383 threads = []
Jon Halla440e872016-03-31 15:15:50 -07003384 for i in main.activeNodes:
Jon Halle1a3b752015-07-22 13:02:46 -07003385 t = main.Thread( target=main.CLIs[i].setTestSize,
Jon Hall85794ff2015-07-08 14:12:30 -07003386 name="setTestSize-" + str( i ),
3387 args=[ onosSetName ] )
3388 threads.append( t )
3389 t.start()
3390 for t in threads:
3391 t.join()
3392 sizeResponses.append( t.result )
3393 sizeResults = main.TRUE
Jon Halla440e872016-03-31 15:15:50 -07003394 for i in range( len( main.activeNodes ) ):
3395 node = str( main.activeNodes[i] + 1 )
Jon Hall85794ff2015-07-08 14:12:30 -07003396 if size != sizeResponses[ i ]:
3397 sizeResults = main.FALSE
Jon Halla440e872016-03-31 15:15:50 -07003398 main.log.error( "ONOS" + node + " expected a size of " +
Jon Hall85794ff2015-07-08 14:12:30 -07003399 str( size ) + " for set " + onosSetName +
3400 " but got " + str( sizeResponses[ i ] ) )
3401 retainResults = retainResults and getResults and sizeResults
3402 utilities.assert_equals( expect=main.TRUE,
3403 actual=retainResults,
3404 onpass="Set retain correct",
3405 onfail="Set retain was incorrect" )
3406
Jon Hall2a5002c2015-08-21 16:49:11 -07003407 # Transactional maps
3408 main.step( "Partitioned Transactional maps put" )
3409 tMapValue = "Testing"
3410 numKeys = 100
3411 putResult = True
Jon Halla440e872016-03-31 15:15:50 -07003412 node = main.activeNodes[0]
3413 putResponses = main.CLIs[node].transactionalMapPut( numKeys, tMapValue )
3414 if putResponses and len( putResponses ) == 100:
Jon Hall2a5002c2015-08-21 16:49:11 -07003415 for i in putResponses:
3416 if putResponses[ i ][ 'value' ] != tMapValue:
3417 putResult = False
3418 else:
3419 putResult = False
3420 if not putResult:
3421 main.log.debug( "Put response values: " + str( putResponses ) )
3422 utilities.assert_equals( expect=True,
3423 actual=putResult,
3424 onpass="Partitioned Transactional Map put successful",
3425 onfail="Partitioned Transactional Map put values are incorrect" )
3426
3427 main.step( "Partitioned Transactional maps get" )
3428 getCheck = True
3429 for n in range( 1, numKeys + 1 ):
3430 getResponses = []
3431 threads = []
3432 valueCheck = True
Jon Halla440e872016-03-31 15:15:50 -07003433 for i in main.activeNodes:
Jon Hall2a5002c2015-08-21 16:49:11 -07003434 t = main.Thread( target=main.CLIs[i].transactionalMapGet,
3435 name="TMap-get-" + str( i ),
Jon Halla440e872016-03-31 15:15:50 -07003436 args=[ "Key" + str( n ) ] )
Jon Hall2a5002c2015-08-21 16:49:11 -07003437 threads.append( t )
3438 t.start()
3439 for t in threads:
3440 t.join()
3441 getResponses.append( t.result )
3442 for node in getResponses:
3443 if node != tMapValue:
3444 valueCheck = False
3445 if not valueCheck:
3446 main.log.warn( "Values for key 'Key" + str( n ) + "' do not match:" )
3447 main.log.warn( getResponses )
3448 getCheck = getCheck and valueCheck
3449 utilities.assert_equals( expect=True,
3450 actual=getCheck,
3451 onpass="Partitioned Transactional Map get values were correct",
3452 onfail="Partitioned Transactional Map values incorrect" )