blob: 7194a3b4bf70140758c5aadcdc5af1eb27680854 [file] [log] [blame]
Jon Hall6aec96b2015-01-19 14:49:31 -08001"""
Jon Hall73cf9cc2014-11-20 22:28:38 -08002Description: 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 mastership to controllers
8CASE3: Assign intents
9CASE4: Ping across added host intents
10CASE5: Reading state of ONOS
11CASE6: The Failure case. Since this is the Sanity test, we do nothing.
12CASE7: Check state after control plane failure
13CASE8: Compare topo
14CASE9: Link s3-s28 down
15CASE10: Link s3-s28 up
16CASE11: Switch down
17CASE12: Switch up
18CASE13: Clean up
Jon Hall669173b2014-12-17 11:36:30 -080019CASE14: start election app on all onos nodes
20CASE15: Check that Leadership Election is still functional
pingping-lin763ee042015-05-20 17:45:30 -070021CASE16: Install Distributed Primitives app
22CASE17: Check for basic functionality with distributed primitives
Jon Hall6aec96b2015-01-19 14:49:31 -080023"""
Jon Hall8f89dda2015-01-22 16:03:33 -080024
25
Jon Hall48cf3ce2015-01-12 15:43:18 -080026class HATestSingleInstanceRestart:
Jon Hall73cf9cc2014-11-20 22:28:38 -080027
Jon Hall6aec96b2015-01-19 14:49:31 -080028 def __init__( self ):
Jon Hall73cf9cc2014-11-20 22:28:38 -080029 self.default = ''
30
Jon Hall6aec96b2015-01-19 14:49:31 -080031 def CASE1( self, main ):
32 """
Jon Hall73cf9cc2014-11-20 22:28:38 -080033 CASE1 is to compile ONOS and push it to the test machines
34
35 Startup sequence:
Jon Hall73cf9cc2014-11-20 22:28:38 -080036 cell <name>
37 onos-verify-cell
38 NOTE: temporary - onos-remove-raft-logs
pingping-lin763ee042015-05-20 17:45:30 -070039 onos-uninstall
40 start mininet
41 git pull
42 mvn clean install
43 onos-package
Jon Hall73cf9cc2014-11-20 22:28:38 -080044 onos-install -f
45 onos-wait-for-start
pingping-lin763ee042015-05-20 17:45:30 -070046 start cli sessions
47 start tcpdump
Jon Hall6aec96b2015-01-19 14:49:31 -080048 """
49 main.log.report( "ONOS Single node cluster restart " +
50 "HA test - initialization" )
51 main.case( "Setting up test environment" )
pingping-lin763ee042015-05-20 17:45:30 -070052 main.caseExplaination = "Setup the test environment including " +\
53 "installing ONOS, starting Mininet and ONOS" +\
54 "cli sessions."
Jon Hall6aec96b2015-01-19 14:49:31 -080055 # TODO: save all the timers and output them for plotting
Jon Hall73cf9cc2014-11-20 22:28:38 -080056
pingping-lin763ee042015-05-20 17:45:30 -070057 # load some variables from the params file
Jon Hall8f89dda2015-01-22 16:03:33 -080058 PULLCODE = False
Jon Hall6aec96b2015-01-19 14:49:31 -080059 if main.params[ 'Git' ] == 'True':
Jon Hall8f89dda2015-01-22 16:03:33 -080060 PULLCODE = True
Jon Hall529a37f2015-01-28 10:02:00 -080061 gitBranch = main.params[ 'branch' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080062 cellName = main.params[ 'ENV' ][ 'cellName' ]
Jon Hall6aec96b2015-01-19 14:49:31 -080063
64 # set global variables
Jon Hall8f89dda2015-01-22 16:03:33 -080065 global ONOS1Ip
66 global ONOS1Port
Jon Hall8f89dda2015-01-22 16:03:33 -080067 global ONOS2Port
Jon Hall8f89dda2015-01-22 16:03:33 -080068 global ONOS3Port
Jon Hall8f89dda2015-01-22 16:03:33 -080069 global ONOS4Port
Jon Hall8f89dda2015-01-22 16:03:33 -080070 global ONOS5Port
Jon Hall8f89dda2015-01-22 16:03:33 -080071 global ONOS6Port
Jon Hall8f89dda2015-01-22 16:03:33 -080072 global ONOS7Port
73 global numControllers
pingping-lin763ee042015-05-20 17:45:30 -070074 numControllers = int( main.params[ 'num_controllers' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -080075
Jon Hall8f89dda2015-01-22 16:03:33 -080076 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
77 ONOS1Port = main.params[ 'CTRL' ][ 'port1' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080078 ONOS2Port = main.params[ 'CTRL' ][ 'port2' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080079 ONOS3Port = main.params[ 'CTRL' ][ 'port3' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080080 ONOS4Port = main.params[ 'CTRL' ][ 'port4' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080081 ONOS5Port = main.params[ 'CTRL' ][ 'port5' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080082 ONOS6Port = main.params[ 'CTRL' ][ 'port6' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080083 ONOS7Port = main.params[ 'CTRL' ][ 'port7' ]
pingping-lin763ee042015-05-20 17:45:30 -070084
85 global CLIs
86 CLIs = []
87 global nodes
88 nodes = []
89 for i in range( 1, numControllers + 1 ):
90 CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
91 nodes.append( getattr( main, 'ONOS' + str( i ) ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -080092
Jon Hall6aec96b2015-01-19 14:49:31 -080093 main.step( "Applying cell variable to environment" )
Jon Hall8f89dda2015-01-22 16:03:33 -080094 cellResult = main.ONOSbench.setCell( cellName )
95 verifyResult = main.ONOSbench.verifyCell()
Jon Hall73cf9cc2014-11-20 22:28:38 -080096
Jon Hall6aec96b2015-01-19 14:49:31 -080097 # FIXME:this is short term fix
pingping-lin763ee042015-05-20 17:45:30 -070098 main.log.info( "Removing raft logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -080099 main.ONOSbench.onosRemoveRaftLogs()
pingping-lin763ee042015-05-20 17:45:30 -0700100
101 main.log.info( "Uninstalling ONOS" )
102 for node in nodes:
103 main.ONOSbench.onosUninstall( node.ip_address )
104
105 # Make sure ONOS is DEAD
106 main.log.info( "Killing any ONOS processes" )
107 killResults = main.TRUE
108 for node in nodes:
109 killed = main.ONOSbench.onosKill( node.ip_address )
110 killResults = killResults and killed
Jon Hall73cf9cc2014-11-20 22:28:38 -0800111
Jon Hall8f89dda2015-01-22 16:03:33 -0800112 cleanInstallResult = main.TRUE
113 gitPullResult = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800114
pingping-lin763ee042015-05-20 17:45:30 -0700115 main.step( "Starting Mininet" )
116 mnResult = main.Mininet1.startNet( )
117 utilities.assert_equals( expect=main.TRUE, actual=mnResult,
118 onpass="Mininet Started",
119 onfail="Error starting Mininet" )
120
121 main.step( "Git checkout and pull " + gitBranch )
Jon Hall8f89dda2015-01-22 16:03:33 -0800122 if PULLCODE:
Jon Hall529a37f2015-01-28 10:02:00 -0800123 main.ONOSbench.gitCheckout( gitBranch )
Jon Hall8f89dda2015-01-22 16:03:33 -0800124 gitPullResult = main.ONOSbench.gitPull()
pingping-lin763ee042015-05-20 17:45:30 -0700125 # values of 1 or 3 are good
126 utilities.assert_lesser( expect=0, actual=gitPullResult,
127 onpass="Git pull successful",
128 onfail="Git pull failed" )
Jon Hall529a37f2015-01-28 10:02:00 -0800129 else:
130 main.log.warn( "Did not pull new code so skipping mvn " +
131 "clean install" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800132 main.ONOSbench.getVersion( report=True )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800133
pingping-lin763ee042015-05-20 17:45:30 -0700134 main.step( "Using mvn clean install" )
135 cleanInstallResult = main.TRUE
136 if gitPullResult == main.TRUE:
137 cleanInstallResult = main.ONOSbench.cleanInstall()
138 utilities.assert_equals( expect=main.TRUE,
139 actual=cleanInstallResult,
140 onpass="MCI successful",
141 onfail="MCI failed" )
142 # GRAPHS
143 # NOTE: important params here:
144 # job = name of Jenkins job
145 # Plot Name = Plot-HA, only can be used if multiple plots
146 # index = The number of the graph under plot name
147 job = "HASingleInstanceRestart"
148 graphs = '<ac:structured-macro ac:name="html">\n'
149 graphs += '<ac:plain-text-body><![CDATA[\n'
150 graphs += '<iframe src="https://onos-jenkins.onlab.us/job/' + job +\
151 '/plot/getPlot?index=0&width=500&height=300"' +\
152 'noborder="0" width="500" height="300" scrolling="yes" ' +\
153 'seamless="seamless"></iframe>\n'
154 graphs += ']]></ac:plain-text-body>\n'
155 graphs += '</ac:structured-macro>\n'
156 main.log.wiki(graphs)
157
Jon Hall8f89dda2015-01-22 16:03:33 -0800158 cellResult = main.ONOSbench.setCell( "SingleHA" )
159 verifyResult = main.ONOSbench.verifyCell()
Jon Hall6aec96b2015-01-19 14:49:31 -0800160 main.step( "Creating ONOS package" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800161 packageResult = main.ONOSbench.onosPackage()
pingping-lin763ee042015-05-20 17:45:30 -0700162 utilities.assert_equals( expect=main.TRUE, actual=packageResult,
163 onpass="ONOS package successful",
164 onfail="ONOS package failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800165
Jon Hall6aec96b2015-01-19 14:49:31 -0800166 main.step( "Installing ONOS package" )
pingping-lin763ee042015-05-20 17:45:30 -0700167 onosInstallResult = main.ONOSbench.onosInstall( options="-f",
Jon Hall8f89dda2015-01-22 16:03:33 -0800168 node=ONOS1Ip )
pingping-lin763ee042015-05-20 17:45:30 -0700169 utilities.assert_equals( expect=main.TRUE, actual=onosInstallResult,
170 onpass="ONOS install successful",
171 onfail="ONOS install failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800172
Jon Hall6aec96b2015-01-19 14:49:31 -0800173 main.step( "Checking if ONOS is up yet" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800174 for i in range( 2 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800175 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
176 if onos1Isup:
Jon Hall94fd0472014-12-08 11:52:42 -0800177 break
pingping-lin763ee042015-05-20 17:45:30 -0700178 utilities.assert_equals( expect=main.TRUE, actual=onos1Isup,
179 onpass="ONOS startup successful",
180 onfail="ONOS startup failed" )
Jon Hall94fd0472014-12-08 11:52:42 -0800181
pingping-lin763ee042015-05-20 17:45:30 -0700182 main.log.step( "Starting ONOS CLI sessions" )
183 cliResults = main.ONOScli1.startOnosCli( ONOS1Ip )
184 utilities.assert_equals( expect=main.TRUE, actual=cliResults,
185 onpass="ONOS cli startup successful",
186 onfail="ONOS cli startup failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800187
Jon Hall6aec96b2015-01-19 14:49:31 -0800188 main.step( "Start Packet Capture MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800189 main.Mininet2.startTcpdump(
Jon Hall6aec96b2015-01-19 14:49:31 -0800190 str( main.params[ 'MNtcpdump' ][ 'folder' ] ) + str( main.TEST )
191 + "-MN.pcap",
192 intf=main.params[ 'MNtcpdump' ][ 'intf' ],
193 port=main.params[ 'MNtcpdump' ][ 'port' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800194
pingping-lin763ee042015-05-20 17:45:30 -0700195 main.step( "App Ids check" )
196 appCheck = main.ONOScli1.appToIDCheck()
197 if appCheck != main.TRUE:
198 main.log.warn( CLIs[0].apps() )
199 main.log.warn( CLIs[0].appIDs() )
200 utilities.assert_equals( expect=main.TRUE, actual=appCheck,
201 onpass="App Ids seem to be correct",
202 onfail="Something is wrong with app Ids" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800203
pingping-lin763ee042015-05-20 17:45:30 -0700204 if cliResults == main.FALSE:
205 main.log.error( "Failed to start ONOS, stopping test" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800206 main.cleanup()
207 main.exit()
208
Jon Hall6aec96b2015-01-19 14:49:31 -0800209 def CASE2( self, main ):
210 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800211 Assign mastership to controllers
Jon Hall6aec96b2015-01-19 14:49:31 -0800212 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800213 import re
pingping-lin763ee042015-05-20 17:45:30 -0700214 assert numControllers, "numControllers not defined"
215 assert main, "main not defined"
216 assert utilities.assert_equals, "utilities.assert_equals not defined"
217 assert ONOS1Port, "ONOS1Port not defined"
218 assert ONOS2Port, "ONOS2Port not defined"
219 assert ONOS3Port, "ONOS3Port not defined"
220 assert ONOS4Port, "ONOS4Port not defined"
221 assert ONOS5Port, "ONOS5Port not defined"
222 assert ONOS6Port, "ONOS6Port not defined"
223 assert ONOS7Port, "ONOS7Port not defined"
Jon Hall73cf9cc2014-11-20 22:28:38 -0800224
Jon Hall6aec96b2015-01-19 14:49:31 -0800225 main.case( "Assigning Controllers" )
pingping-lin763ee042015-05-20 17:45:30 -0700226 main.caseExplaination = "Assign switches to ONOS using 'ovs-vsctl' " +\
227 "and check that an ONOS node becomes the " +\
228 "master of the device."
Jon Hall6aec96b2015-01-19 14:49:31 -0800229 main.step( "Assign switches to controllers" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800230
Jon Hall6aec96b2015-01-19 14:49:31 -0800231 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800232 main.Mininet1.assignSwController(
Jon Hall6aec96b2015-01-19 14:49:31 -0800233 sw=str( i ),
Jon Hall8f89dda2015-01-22 16:03:33 -0800234 ip1=ONOS1Ip, port1=ONOS1Port )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800235
Jon Hall8f89dda2015-01-22 16:03:33 -0800236 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800237 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800238 response = main.Mininet1.getSwController( "s" + str( i ) )
Jon Hallffb386d2014-11-21 13:43:38 -0800239 try:
Jon Hall6aec96b2015-01-19 14:49:31 -0800240 main.log.info( str( response ) )
pingping-lin763ee042015-05-20 17:45:30 -0700241 except Exception:
Jon Hall6aec96b2015-01-19 14:49:31 -0800242 main.log.info( repr( response ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800243 if re.search( "tcp:" + ONOS1Ip, response ):
244 mastershipCheck = mastershipCheck and main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800245 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800246 mastershipCheck = main.FALSE
247 if mastershipCheck == main.TRUE:
pingping-lin763ee042015-05-20 17:45:30 -0700248 main.log.info( "Switch mastership assigned correctly" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800249 utilities.assert_equals(
250 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800251 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800252 onpass="Switch mastership assigned correctly",
253 onfail="Switches not assigned correctly to controllers" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800254
pingping-lin763ee042015-05-20 17:45:30 -0700255 main.step( "Assign mastership of switches to specific controllers" )
256 roleCall = main.TRUE
257 roleCheck = main.TRUE
258 try:
259 for i in range( 1, 29 ): # switches 1 through 28
260 ip = nodes[ 0 ].ip_address # ONOS1
261 # set up correct variables:
262 if i == 1:
263 deviceId = main.ONOScli1.getDevice( "1000" ).get( 'id' )
264 elif i == 2:
265 deviceId = main.ONOScli1.getDevice( "2000" ).get( 'id' )
266 elif i == 3:
267 deviceId = main.ONOScli1.getDevice( "3000" ).get( 'id' )
268 elif i == 4:
269 deviceId = main.ONOScli1.getDevice( "3004" ).get( 'id' )
270 elif i == 5:
271 deviceId = main.ONOScli1.getDevice( "5000" ).get( 'id' )
272 elif i == 6:
273 deviceId = main.ONOScli1.getDevice( "6000" ).get( 'id' )
274 elif i == 7:
275 deviceId = main.ONOScli1.getDevice( "6007" ).get( 'id' )
276 elif i >= 8 and i <= 17:
277 dpid = '3' + str( i ).zfill( 3 )
278 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
279 elif i >= 18 and i <= 27:
280 dpid = '6' + str( i ).zfill( 3 )
281 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
282 elif i == 28:
283 deviceId = main.ONOScli1.getDevice( "2800" ).get( 'id' )
284 else:
285 main.log.error( "You didn't write an else statement for " +
286 "switch s" + str( i ) )
287 # Assign switch
288 assert deviceId, "No device id for s" + str( i ) + " in ONOS"
289 # TODO: make this controller dynamic
290 roleCall = roleCall and main.ONOScli1.deviceRole( deviceId,
291 ip )
292 # Check assignment
293 master = main.ONOScli1.getRole( deviceId ).get( 'master' )
294 if ip in master:
295 roleCheck = roleCheck and main.TRUE
296 else:
297 roleCheck = roleCheck and main.FALSE
298 main.log.error( "Error, controller " + ip + " is not" +
299 " master " + "of device " +
300 str( deviceId ) + ". Master is " +
301 repr( master ) + "." )
302 except ( AttributeError, AssertionError ):
303 main.log.exception( "Something is wrong with ONOS device view" )
304 main.log.info( main.ONOScli1.devices() )
305 utilities.assert_equals(
306 expect=main.TRUE,
307 actual=roleCall,
308 onpass="Re-assigned switch mastership to designated controller",
309 onfail="Something wrong with deviceRole calls" )
310
311 main.step( "Check mastership was correctly assigned" )
312 utilities.assert_equals(
313 expect=main.TRUE,
314 actual=roleCheck,
315 onpass="Switches were successfully reassigned to designated " +
316 "controller",
317 onfail="Switches were not successfully reassigned" )
318 mastershipCheck = mastershipCheck and roleCall and roleCheck
319 utilities.assert_equals( expect=main.TRUE, actual=mastershipCheck,
320 onpass="Switch mastership correctly assigned",
321 onfail="Error in (re)assigning switch" +
322 " mastership" )
323
Jon Hall6aec96b2015-01-19 14:49:31 -0800324 def CASE3( self, main ):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800325 """
326 Assign intents
Jon Hall73cf9cc2014-11-20 22:28:38 -0800327 """
328 import time
pingping-lin763ee042015-05-20 17:45:30 -0700329 import json
330 assert numControllers, "numControllers not defined"
331 assert main, "main not defined"
332 assert utilities.assert_equals, "utilities.assert_equals not defined"
333 # NOTE: we must reinstall intents until we have a persistant intent
334 # datastore!
Jon Hall6aec96b2015-01-19 14:49:31 -0800335 main.case( "Adding host Intents" )
pingping-lin763ee042015-05-20 17:45:30 -0700336 main.caseExplaination = "Discover hosts by using pingall then " +\
337 "assign predetermined host-to-host intents." +\
338 " After installation, check that the intent" +\
339 " is distributed to all nodes and the state" +\
340 " is INSTALLED"
Jon Hall73cf9cc2014-11-20 22:28:38 -0800341
Jon Hall6aec96b2015-01-19 14:49:31 -0800342 # install onos-app-fwd
pingping-lin763ee042015-05-20 17:45:30 -0700343 main.step( "Install reactive forwarding app" )
344 installResults = CLIs[0].activateApp( "org.onosproject.fwd" )
345 utilities.assert_equals( expect=main.TRUE, actual=installResults,
346 onpass="Install fwd successful",
347 onfail="Install fwd failed" )
Jon Hall94fd0472014-12-08 11:52:42 -0800348
pingping-lin763ee042015-05-20 17:45:30 -0700349 main.step( "Check app ids" )
350 appCheck = main.ONOScli1.appToIDCheck()
351 if appCheck != main.TRUE:
352 main.log.warn( CLIs[0].apps() )
353 main.log.warn( CLIs[0].appIDs() )
354 utilities.assert_equals( expect=main.TRUE, actual=appCheck,
355 onpass="App Ids seem to be correct",
356 onfail="Something is wrong with app Ids" )
357
358 main.step( "Discovering Hosts( Via pingall for now )" )
359 # FIXME: Once we have a host discovery mechanism, use that instead
Jon Hall6aec96b2015-01-19 14:49:31 -0800360 # REACTIVE FWD test
Jon Hall8f89dda2015-01-22 16:03:33 -0800361 pingResult = main.FALSE
pingping-lin763ee042015-05-20 17:45:30 -0700362 for i in range(2): # Retry if pingall fails first time
363 time1 = time.time()
364 pingResult = main.Mininet1.pingall()
365 utilities.assert_equals(
366 expect=main.TRUE,
367 actual=pingResult,
368 onpass="Reactive Pingall test passed",
369 onfail="Reactive Pingall failed, " +
370 "one or more ping pairs failed" )
371 time2 = time.time()
372 main.log.info( "Time for pingall: %2f seconds" %
373 ( time2 - time1 ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800374 # timeout for fwd flows
pingping-lin763ee042015-05-20 17:45:30 -0700375 time.sleep( 11 )
376 # uninstall onos-app-fwd
377 main.step( "Uninstall reactive forwarding app" )
378 uninstallResult = CLIs[0].deactivateApp( "org.onosproject.fwd" )
379 utilities.assert_equals( expect=main.TRUE, actual=uninstallResult,
380 onpass="Uninstall fwd successful",
381 onfail="Uninstall fwd failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800382
pingping-lin763ee042015-05-20 17:45:30 -0700383 main.step( "Check app ids" )
384 appCheck2 = main.ONOScli1.appToIDCheck()
385 if appCheck2 != main.TRUE:
386 main.log.warn( CLIs[0].apps() )
387 main.log.warn( CLIs[0].appIDs() )
388 utilities.assert_equals( expect=main.TRUE, actual=appCheck2,
389 onpass="App Ids seem to be correct",
390 onfail="Something is wrong with app Ids" )
391
392 main.step( "Add host intents via cli" )
393 intentIds = []
Jon Hall6aec96b2015-01-19 14:49:31 -0800394 # TODO: move the host numbers to params
pingping-lin763ee042015-05-20 17:45:30 -0700395 # Maybe look at all the paths we ping?
Jon Hall8f89dda2015-01-22 16:03:33 -0800396 intentAddResult = True
pingping-lin763ee042015-05-20 17:45:30 -0700397 hostResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800398 for i in range( 8, 18 ):
399 main.log.info( "Adding host intent between h" + str( i ) +
400 " and h" + str( i + 10 ) )
401 host1 = "00:00:00:00:00:" + \
402 str( hex( i )[ 2: ] ).zfill( 2 ).upper()
403 host2 = "00:00:00:00:00:" + \
404 str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper()
pingping-lin763ee042015-05-20 17:45:30 -0700405 # NOTE: getHost can return None
406 host1Dict = main.ONOScli1.getHost( host1 )
407 host2Dict = main.ONOScli1.getHost( host2 )
408 host1Id = None
409 host2Id = None
410 if host1Dict and host2Dict:
411 host1Id = host1Dict.get( 'id', None )
412 host2Id = host2Dict.get( 'id', None )
Jon Hall8f89dda2015-01-22 16:03:33 -0800413 if host1Id and host2Id:
pingping-lin763ee042015-05-20 17:45:30 -0700414 tmpId = main.ONOScli1.addHostIntent( host1Id, host2Id )
415 if tmpId:
416 main.log.info( "Added intent with id: " + tmpId )
417 intentIds.append( tmpId )
418 else:
419 main.log.error( "addHostIntent returned: " +
420 repr( tmpId ) )
Jon Hall669173b2014-12-17 11:36:30 -0800421 else:
pingping-lin763ee042015-05-20 17:45:30 -0700422 main.log.error( "Error, getHost() failed for h" + str( i ) +
423 " and/or h" + str( i + 10 ) )
424 hosts = main.ONOScli1.hosts()
425 main.log.warn( "Hosts output: " )
426 try:
427 main.log.warn( json.dumps( json.loads( hosts ),
428 sort_keys=True,
429 indent=4,
430 separators=( ',', ': ' ) ) )
431 except ( ValueError, TypeError ):
432 main.log.warn( repr( hosts ) )
433 hostResult = main.FALSE
434 utilities.assert_equals( expect=main.TRUE, actual=hostResult,
435 onpass="Found a host id for each host",
436 onfail="Error looking up host ids" )
437
438 intentStart = time.time()
439 onosIds = main.ONOScli1.getAllIntentsId()
440 main.log.info( "Submitted intents: " + str( intentIds ) )
441 main.log.info( "Intents in ONOS: " + str( onosIds ) )
442 for intent in intentIds:
443 if intent in onosIds:
444 pass # intent submitted is in onos
445 else:
446 intentAddResult = False
447 # FIXME: DEBUG
448 if intentAddResult:
449 intentStop = time.time()
450 else:
451 intentStop = None
452 # Print the intent states
453 intents = main.ONOScli1.intents()
454 intentStates = []
455 installedCheck = True
456 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
457 count = 0
458 try:
459 for intent in json.loads( intents ):
460 state = intent.get( 'state', None )
461 if "INSTALLED" not in state:
462 installedCheck = False
463 intentId = intent.get( 'id', None )
464 intentStates.append( ( intentId, state ) )
465 except ( ValueError, TypeError ):
466 main.log.exception( "Error parsing intents" )
467 # add submitted intents not in the store
468 tmplist = [ i for i, s in intentStates ]
469 missingIntents = False
470 for i in intentIds:
471 if i not in tmplist:
472 intentStates.append( ( i, " - " ) )
473 missingIntents = True
474 intentStates.sort()
475 for i, s in intentStates:
476 count += 1
477 main.log.info( "%-6s%-15s%-15s" %
478 ( str( count ), str( i ), str( s ) ) )
479 leaders = main.ONOScli1.leaders()
480 try:
481 if leaders:
482 parsedLeaders = json.loads( leaders )
483 main.log.warn( json.dumps( parsedLeaders,
484 sort_keys=True,
485 indent=4,
486 separators=( ',', ': ' ) ) )
487 # check for all intent partitions
488 topics = []
489 for i in range( 14 ):
490 topics.append( "intent-partition-" + str( i ) )
491 main.log.debug( topics )
492 ONOStopics = [ j['topic'] for j in parsedLeaders ]
493 for topic in topics:
494 if topic not in ONOStopics:
495 main.log.error( "Error: " + topic +
496 " not in leaders" )
497 else:
498 main.log.error( "leaders() returned None" )
499 except ( ValueError, TypeError ):
500 main.log.exception( "Error parsing leaders" )
501 main.log.error( repr( leaders ) )
502 partitions = main.ONOScli1.partitions()
503 try:
504 if partitions :
505 parsedPartitions = json.loads( partitions )
506 main.log.warn( json.dumps( parsedPartitions,
507 sort_keys=True,
508 indent=4,
509 separators=( ',', ': ' ) ) )
510 # TODO check for a leader in all paritions
511 # TODO check for consistency among nodes
512 else:
513 main.log.error( "partitions() returned None" )
514 except ( ValueError, TypeError ):
515 main.log.exception( "Error parsing partitions" )
516 main.log.error( repr( partitions ) )
517 pendingMap = main.ONOScli1.pendingMap()
518 try:
519 if pendingMap :
520 parsedPending = json.loads( pendingMap )
521 main.log.warn( json.dumps( parsedPending,
522 sort_keys=True,
523 indent=4,
524 separators=( ',', ': ' ) ) )
525 # TODO check something here?
526 else:
527 main.log.error( "pendingMap() returned None" )
528 except ( ValueError, TypeError ):
529 main.log.exception( "Error parsing pending map" )
530 main.log.error( repr( pendingMap ) )
531
532 intentAddResult = bool( intentAddResult and not missingIntents and
533 installedCheck )
534 if not intentAddResult:
535 main.log.error( "Error in pushing host intents to ONOS" )
536
537 main.step( "Intent Anti-Entropy dispersion" )
538 for i in range(100):
539 correct = True
540 main.log.info( "Submitted intents: " + str( sorted( intentIds ) ) )
541 for cli in CLIs:
542 onosIds = []
543 ids = cli.getAllIntentsId()
544 onosIds.append( ids )
545 main.log.debug( "Intents in " + cli.name + ": " +
546 str( sorted( onosIds ) ) )
547 if sorted( ids ) != sorted( intentIds ):
548 correct = False
549 if correct:
550 break
551 else:
552 time.sleep(1)
553 if not intentStop:
554 intentStop = time.time()
555 global gossipTime
556 gossipTime = intentStop - intentStart
557 main.log.info( "It took about " + str( gossipTime ) +
558 " seconds for all intents to appear in each node" )
559 # FIXME: make this time configurable/calculate based off of number of
560 # nodes and gossip rounds
561 utilities.assert_greater_equals(
562 expect=40, actual=gossipTime,
563 onpass="ECM anti-entropy for intents worked within " +
564 "expected time",
565 onfail="Intent ECM anti-entropy took too long" )
566 if gossipTime <= 40:
567 intentAddResult = True
568
569 if not intentAddResult or "key" in pendingMap:
570 import time
571 installedCheck = True
572 main.log.info( "Sleeping 60 seconds to see if intents are found" )
573 time.sleep( 60 )
574 onosIds = main.ONOScli1.getAllIntentsId()
575 main.log.info( "Submitted intents: " + str( intentIds ) )
576 main.log.info( "Intents in ONOS: " + str( onosIds ) )
577 # Print the intent states
578 intents = main.ONOScli1.intents()
579 intentStates = []
580 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
581 count = 0
582 try:
583 for intent in json.loads( intents ):
584 # Iter through intents of a node
585 state = intent.get( 'state', None )
586 if "INSTALLED" not in state:
587 installedCheck = False
588 intentId = intent.get( 'id', None )
589 intentStates.append( ( intentId, state ) )
590 except ( ValueError, TypeError ):
591 main.log.exception( "Error parsing intents" )
592 # add submitted intents not in the store
593 tmplist = [ i for i, s in intentStates ]
594 for i in intentIds:
595 if i not in tmplist:
596 intentStates.append( ( i, " - " ) )
597 intentStates.sort()
598 for i, s in intentStates:
599 count += 1
600 main.log.info( "%-6s%-15s%-15s" %
601 ( str( count ), str( i ), str( s ) ) )
602 leaders = main.ONOScli1.leaders()
603 try:
604 if leaders:
605 parsedLeaders = json.loads( leaders )
606 main.log.warn( json.dumps( parsedLeaders,
607 sort_keys=True,
608 indent=4,
609 separators=( ',', ': ' ) ) )
610 # check for all intent partitions
611 # check for election
612 topics = []
613 for i in range( 14 ):
614 topics.append( "intent-partition-" + str( i ) )
615 # FIXME: this should only be after we start the app
616 topics.append( "org.onosproject.election" )
617 main.log.debug( topics )
618 ONOStopics = [ j['topic'] for j in parsedLeaders ]
619 for topic in topics:
620 if topic not in ONOStopics:
621 main.log.error( "Error: " + topic +
622 " not in leaders" )
623 else:
624 main.log.error( "leaders() returned None" )
625 except ( ValueError, TypeError ):
626 main.log.exception( "Error parsing leaders" )
627 main.log.error( repr( leaders ) )
628 partitions = main.ONOScli1.partitions()
629 try:
630 if partitions :
631 parsedPartitions = json.loads( partitions )
632 main.log.warn( json.dumps( parsedPartitions,
633 sort_keys=True,
634 indent=4,
635 separators=( ',', ': ' ) ) )
636 # TODO check for a leader in all paritions
637 # TODO check for consistency among nodes
638 else:
639 main.log.error( "partitions() returned None" )
640 except ( ValueError, TypeError ):
641 main.log.exception( "Error parsing partitions" )
642 main.log.error( repr( partitions ) )
643 pendingMap = main.ONOScli1.pendingMap()
644 try:
645 if pendingMap :
646 parsedPending = json.loads( pendingMap )
647 main.log.warn( json.dumps( parsedPending,
648 sort_keys=True,
649 indent=4,
650 separators=( ',', ': ' ) ) )
651 # TODO check something here?
652 else:
653 main.log.error( "pendingMap() returned None" )
654 except ( ValueError, TypeError ):
655 main.log.exception( "Error parsing pending map" )
656 main.log.error( repr( pendingMap ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800657
Jon Hall6aec96b2015-01-19 14:49:31 -0800658 def CASE4( self, main ):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800659 """
660 Ping across added host intents
661 """
pingping-lin763ee042015-05-20 17:45:30 -0700662 import json
663 import time
664 assert numControllers, "numControllers not defined"
665 assert main, "main not defined"
666 assert utilities.assert_equals, "utilities.assert_equals not defined"
667 main.case( "Verify connectivity by sendind traffic across Intents" )
668 main.caseExplaination = "Ping across added host intents to check " +\
669 "functionality and check the state of " +\
670 "the intent"
671 main.step( "Ping across added host intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800672 PingResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800673 for i in range( 8, 18 ):
pingping-lin763ee042015-05-20 17:45:30 -0700674 ping = main.Mininet1.pingHost( src="h" + str( i ),
675 target="h" + str( i + 10 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800676 PingResult = PingResult and ping
Jon Hall6aec96b2015-01-19 14:49:31 -0800677 if ping == main.FALSE:
678 main.log.warn( "Ping failed between h" + str( i ) +
679 " and h" + str( i + 10 ) )
680 elif ping == main.TRUE:
681 main.log.info( "Ping test passed!" )
pingping-lin763ee042015-05-20 17:45:30 -0700682 # Don't set PingResult or you'd override failures
Jon Hall8f89dda2015-01-22 16:03:33 -0800683 if PingResult == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800684 main.log.report(
685 "Intents have not been installed correctly, pings failed." )
pingping-lin763ee042015-05-20 17:45:30 -0700686 # TODO: pretty print
687 main.log.warn( "ONOS1 intents: " )
688 try:
689 tmpIntents = main.ONOScli1.intents()
690 main.log.warn( json.dumps( json.loads( tmpIntents ),
691 sort_keys=True,
692 indent=4,
693 separators=( ',', ': ' ) ) )
694 except ( ValueError, TypeError ):
695 main.log.warn( repr( tmpIntents ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800696 if PingResult == main.TRUE:
pingping-lin763ee042015-05-20 17:45:30 -0700697 main.log.info(
Jon Hall6aec96b2015-01-19 14:49:31 -0800698 "Intents have been installed correctly and verified by pings" )
699 utilities.assert_equals(
700 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800701 actual=PingResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800702 onpass="Intents have been installed correctly and pings work",
703 onfail="Intents have not been installed correctly, pings failed." )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800704
pingping-lin763ee042015-05-20 17:45:30 -0700705 main.step( "Check Intent state" )
706 installedCheck = True
707 # Print the intent states
708 intents = main.ONOScli1.intents()
709 intentStates = []
710 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
711 count = 0
712 # Iter through intents of a node
713 try:
714 for intent in json.loads( intents ):
715 state = intent.get( 'state', None )
716 if "INSTALLED" not in state:
717 installedCheck = False
718 intentId = intent.get( 'id', None )
719 intentStates.append( ( intentId, state ) )
720 except ( ValueError, TypeError ):
721 main.log.exception( "Error parsing intents." )
722 # Print states
723 intentStates.sort()
724 for i, s in intentStates:
725 count += 1
726 main.log.info( "%-6s%-15s%-15s" %
727 ( str( count ), str( i ), str( s ) ) )
728 utilities.assert_equals( expect=True, actual=installedCheck,
729 onpass="Intents are all INSTALLED",
730 onfail="Intents are not all in " +\
731 "INSTALLED state" )
732
733 main.step( "Check leadership of topics" )
734 leaders = main.ONOScli1.leaders()
735 topicCheck = main.TRUE
736 try:
737 if leaders:
738 parsedLeaders = json.loads( leaders )
739 main.log.warn( json.dumps( parsedLeaders,
740 sort_keys=True,
741 indent=4,
742 separators=( ',', ': ' ) ) )
743 # check for all intent partitions
744 # check for election
745 # TODO: Look at Devices as topics now that it uses this system
746 topics = []
747 for i in range( 14 ):
748 topics.append( "intent-partition-" + str( i ) )
749 # FIXME: this should only be after we start the app
750 # FIXME: topics.append( "org.onosproject.election" )
751 # Print leaders output
752 main.log.debug( topics )
753 ONOStopics = [ j['topic'] for j in parsedLeaders ]
754 for topic in topics:
755 if topic not in ONOStopics:
756 main.log.error( "Error: " + topic +
757 " not in leaders" )
758 topicCheck = main.FALSE
759 else:
760 main.log.error( "leaders() returned None" )
761 topicCheck = main.FALSE
762 except ( ValueError, TypeError ):
763 topicCheck = main.FALSE
764 main.log.exception( "Error parsing leaders" )
765 main.log.error( repr( leaders ) )
766 # TODO: Check for a leader of these topics
767 utilities.assert_equals( expect=main.TRUE, actual=topicCheck,
768 onpass="intent Partitions is in leaders",
769 onfail="Some topics were lost " )
770 # Print partitions
771 partitions = main.ONOScli1.partitions()
772 try:
773 if partitions :
774 parsedPartitions = json.loads( partitions )
775 main.log.warn( json.dumps( parsedPartitions,
776 sort_keys=True,
777 indent=4,
778 separators=( ',', ': ' ) ) )
779 # TODO check for a leader in all paritions
780 # TODO check for consistency among nodes
781 else:
782 main.log.error( "partitions() returned None" )
783 except ( ValueError, TypeError ):
784 main.log.exception( "Error parsing partitions" )
785 main.log.error( repr( partitions ) )
786 # Print Pending Map
787 pendingMap = main.ONOScli1.pendingMap()
788 try:
789 if pendingMap :
790 parsedPending = json.loads( pendingMap )
791 main.log.warn( json.dumps( parsedPending,
792 sort_keys=True,
793 indent=4,
794 separators=( ',', ': ' ) ) )
795 # TODO check something here?
796 else:
797 main.log.error( "pendingMap() returned None" )
798 except ( ValueError, TypeError ):
799 main.log.exception( "Error parsing pending map" )
800 main.log.error( repr( pendingMap ) )
801
802 if not installedCheck:
803 main.log.info( "Waiting 60 seconds to see if the state of " +
804 "intents change" )
805 time.sleep( 60 )
806 # Print the intent states
807 intents = main.ONOScli1.intents()
808 intentStates = []
809 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
810 count = 0
811 # Iter through intents of a node
812 try:
813 for intent in json.loads( intents ):
814 state = intent.get( 'state', None )
815 if "INSTALLED" not in state:
816 installedCheck = False
817 intentId = intent.get( 'id', None )
818 intentStates.append( ( intentId, state ) )
819 except ( ValueError, TypeError ):
820 main.log.exception( "Error parsing intents." )
821 intentStates.sort()
822 for i, s in intentStates:
823 count += 1
824 main.log.info( "%-6s%-15s%-15s" %
825 ( str( count ), str( i ), str( s ) ) )
826 leaders = main.ONOScli1.leaders()
827 try:
828 if leaders:
829 parsedLeaders = json.loads( leaders )
830 main.log.warn( json.dumps( parsedLeaders,
831 sort_keys=True,
832 indent=4,
833 separators=( ',', ': ' ) ) )
834 # check for all intent partitions
835 # check for election
836 topics = []
837 for i in range( 14 ):
838 topics.append( "intent-partition-" + str( i ) )
839 # FIXME: this should only be after we start the app
840 topics.append( "org.onosproject.election" )
841 main.log.debug( topics )
842 ONOStopics = [ j['topic'] for j in parsedLeaders ]
843 for topic in topics:
844 if topic not in ONOStopics:
845 main.log.error( "Error: " + topic +
846 " not in leaders" )
847 else:
848 main.log.error( "leaders() returned None" )
849 except ( ValueError, TypeError ):
850 main.log.exception( "Error parsing leaders" )
851 main.log.error( repr( leaders ) )
852 partitions = main.ONOScli1.partitions()
853 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 ) )
867 pendingMap = main.ONOScli1.pendingMap()
868 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 main.log.debug( main.ONOScli1.flows( jsonFormat=False ) )
882
883 main.step( "Wait a minute then ping again" )
884 PingResult = main.TRUE
885 for i in range( 8, 18 ):
886 ping = main.Mininet1.pingHost( src="h" + str( i ),
887 target="h" + str( i + 10 ) )
888 PingResult = PingResult and ping
889 if ping == main.FALSE:
890 main.log.warn( "Ping failed between h" + str( i ) +
891 " and h" + str( i + 10 ) )
892 elif ping == main.TRUE:
893 main.log.info( "Ping test passed!" )
894 # Don't set PingResult or you'd override failures
895 if PingResult == main.FALSE:
896 main.log.report(
897 "Intents have not been installed correctly, pings failed." )
898 # TODO: pretty print
899 main.log.warn( "ONOS1 intents: " )
900 try:
901 tmpIntents = main.ONOScli1.intents()
902 main.log.warn( json.dumps( json.loads( tmpIntents ),
903 sort_keys=True,
904 indent=4,
905 separators=( ',', ': ' ) ) )
906 except ( ValueError, TypeError ):
907 main.log.warn( repr( tmpIntents ) )
908 utilities.assert_equals(
909 expect=main.TRUE,
910 actual=PingResult,
911 onpass="Intents have been installed correctly and pings work",
912 onfail="Intents have not been installed correctly, pings failed." )
913
Jon Hall6aec96b2015-01-19 14:49:31 -0800914 def CASE5( self, main ):
915 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800916 Reading state of ONOS
Jon Hall6aec96b2015-01-19 14:49:31 -0800917 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800918 import json
pingping-lin763ee042015-05-20 17:45:30 -0700919 assert numControllers, "numControllers not defined"
920 assert main, "main not defined"
921 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -0800922 # assumes that sts is already in you PYTHONPATH
923 from sts.topology.teston_topology import TestONTopology
Jon Hall73cf9cc2014-11-20 22:28:38 -0800924
Jon Hall6aec96b2015-01-19 14:49:31 -0800925 main.case( "Setting up and gathering data for current state" )
926 # The general idea for this test case is to pull the state of
927 # ( intents,flows, topology,... ) from each ONOS node
pingping-lin763ee042015-05-20 17:45:30 -0700928 # We can then compare them with each other and also with past states
Jon Hall73cf9cc2014-11-20 22:28:38 -0800929
pingping-lin763ee042015-05-20 17:45:30 -0700930 main.step( "Check that each switch has a master" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800931 global mastershipState
pingping-lin763ee042015-05-20 17:45:30 -0700932 mastershipState = '[]'
Jon Hall94fd0472014-12-08 11:52:42 -0800933
Jon Hall6aec96b2015-01-19 14:49:31 -0800934 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -0800935 rolesNotNull = main.ONOScli1.rolesNotNull()
Jon Hall6aec96b2015-01-19 14:49:31 -0800936 utilities.assert_equals(
937 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800938 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -0800939 onpass="Each device has a master",
940 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -0800941
pingping-lin763ee042015-05-20 17:45:30 -0700942 main.step( "Get the Mastership of each switch" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800943 ONOS1Mastership = main.ONOScli1.roles()
Jon Hall6aec96b2015-01-19 14:49:31 -0800944 # TODO: Make this a meaningful check
Jon Hall8f89dda2015-01-22 16:03:33 -0800945 if "Error" in ONOS1Mastership or not ONOS1Mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -0800946 main.log.report( "Error in getting ONOS roles" )
947 main.log.warn(
948 "ONOS1 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800949 repr( ONOS1Mastership ) )
950 consistentMastership = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800951 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800952 mastershipState = ONOS1Mastership
953 consistentMastership = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800954
Jon Hall6aec96b2015-01-19 14:49:31 -0800955 main.step( "Get the intents from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800956 global intentState
957 intentState = []
958 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
959 intentCheck = main.FALSE
960 if "Error" in ONOS1Intents or not ONOS1Intents:
Jon Hall6aec96b2015-01-19 14:49:31 -0800961 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800962 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800963 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800964 intentCheck = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800965
Jon Hall6aec96b2015-01-19 14:49:31 -0800966 main.step( "Get the flows from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800967 global flowState
968 flowState = []
Jon Hall8f89dda2015-01-22 16:03:33 -0800969 flowCheck = main.FALSE
pingping-lin763ee042015-05-20 17:45:30 -0700970 ONOS1Flows = main.ONOScli1.flows( jsonFormat=True )
Jon Hall8f89dda2015-01-22 16:03:33 -0800971 if "Error" in ONOS1Flows or not ONOS1Flows:
pingping-lin763ee042015-05-20 17:45:30 -0700972 main.log.report( "Error in getting ONOS flows" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800973 main.log.warn( "ONOS1 flows repsponse: " + ONOS1Flows )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800974 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800975 # TODO: Do a better check, maybe compare flows on switches?
Jon Hall8f89dda2015-01-22 16:03:33 -0800976 flowState = ONOS1Flows
977 flowCheck = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800978
Jon Hall6aec96b2015-01-19 14:49:31 -0800979 main.step( "Get the OF Table entries" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800980 global flows
Jon Hall6aec96b2015-01-19 14:49:31 -0800981 flows = []
982 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800983 flows.append( main.Mininet2.getFlowTable( 1.3, "s" + str( i ) ) )
pingping-lin763ee042015-05-20 17:45:30 -0700984 if flowCheck == main.FALSE:
985 for table in flows:
986 main.log.warn( table )
Jon Hall6aec96b2015-01-19 14:49:31 -0800987 # TODO: Compare switch flow tables with ONOS flow tables
Jon Hall73cf9cc2014-11-20 22:28:38 -0800988
Jon Hall6aec96b2015-01-19 14:49:31 -0800989 main.step( "Create TestONTopology object" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800990 ctrls = []
pingping-lin763ee042015-05-20 17:45:30 -0700991 temp = ( nodes[0], nodes[0].name, nodes[0].ip_address, 6633 )
Jon Hall6aec96b2015-01-19 14:49:31 -0800992 ctrls.append( temp )
pingping-lin763ee042015-05-20 17:45:30 -0700993 MNTopo = TestONTopology( main.Mininet1, ctrls )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800994
Jon Hall6aec96b2015-01-19 14:49:31 -0800995 main.step( "Collecting topology information from ONOS" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800996 devices = []
997 devices.append( main.ONOScli1.devices() )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800998 hosts = []
pingping-lin763ee042015-05-20 17:45:30 -0700999 hosts.append( json.loads( main.ONOScli1.hosts() ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001000 ports = []
1001 ports.append( main.ONOScli1.ports() )
1002 links = []
1003 links.append( main.ONOScli1.links() )
pingping-lin763ee042015-05-20 17:45:30 -07001004 clusters = []
1005 clusters.append( main.ONOScli1.clusters() )
1006
1007 main.step( "Each host has an IP address" )
1008 ipResult = main.TRUE
1009 for controller in range( 0, len( hosts ) ):
1010 controllerStr = str( controller + 1 )
1011 for host in hosts[ controller ]:
1012 if host is None or host.get( 'ipAddresses', [] ) == []:
1013 main.log.error(
1014 "DEBUG:Error with host ips on controller" +
1015 controllerStr + ": " + str( host ) )
1016 ipResult = main.FALSE
1017 utilities.assert_equals(
1018 expect=main.TRUE,
1019 actual=ipResult,
1020 onpass="The ips of the hosts aren't empty",
1021 onfail="The ip of at least one host is missing" )
1022
1023 # there should always only be one cluster
1024 main.step( "There is only one dataplane cluster" )
1025 try:
1026 numClusters = len( json.loads( clusters[ 0 ] ) )
1027 except ( ValueError, TypeError ):
1028 main.log.exception( "Error parsing clusters[0]: " +
1029 repr( clusters[ 0 ] ) )
1030 clusterResults = main.FALSE
1031 if numClusters == 1:
1032 clusterResults = main.TRUE
1033 utilities.assert_equals(
1034 expect=1,
1035 actual=numClusters,
1036 onpass="ONOS shows 1 SCC",
1037 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001038
Jon Hall6aec96b2015-01-19 14:49:31 -08001039 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001040 devicesResults = main.TRUE
1041 portsResults = main.TRUE
1042 linksResults = main.TRUE
pingping-lin763ee042015-05-20 17:45:30 -07001043 hostsResults = main.TRUE
Jon Hall8f89dda2015-01-22 16:03:33 -08001044 for controller in range( numControllers ):
1045 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001046 if devices[ controller ] or "Error" not in devices[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001047 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -08001048 MNTopo,
pingping-lin763ee042015-05-20 17:45:30 -07001049 json.loads( devices[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001050 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001051 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001052 utilities.assert_equals( expect=main.TRUE,
pingping-lin763ee042015-05-20 17:45:30 -07001053 actual=currentDevicesResult,
1054 onpass="ONOS" + controllerStr +
1055 " Switches view is correct",
1056 onfail="ONOS" + controllerStr +
1057 " Switches view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001058
Jon Hall6aec96b2015-01-19 14:49:31 -08001059 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001060 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -08001061 MNTopo,
pingping-lin763ee042015-05-20 17:45:30 -07001062 json.loads( ports[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001063 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001064 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001065 utilities.assert_equals( expect=main.TRUE,
pingping-lin763ee042015-05-20 17:45:30 -07001066 actual=currentPortsResult,
1067 onpass="ONOS" + controllerStr +
1068 " ports view is correct",
1069 onfail="ONOS" + controllerStr +
1070 " ports view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001071
Jon Hall6aec96b2015-01-19 14:49:31 -08001072 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001073 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -08001074 MNTopo,
pingping-lin763ee042015-05-20 17:45:30 -07001075 json.loads( links[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001076 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001077 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001078 utilities.assert_equals( expect=main.TRUE,
pingping-lin763ee042015-05-20 17:45:30 -07001079 actual=currentLinksResult,
1080 onpass="ONOS" + controllerStr +
1081 " links view is correct",
1082 onfail="ONOS" + controllerStr +
1083 " links view is incorrect" )
1084
1085 if hosts[ controller ] or "Error" not in hosts[ controller ]:
1086 currentHostsResult = main.Mininet1.compareHosts(
1087 MNTopo, hosts[ controller ] )
1088 else:
1089 currentHostsResult = main.FALSE
1090 utilities.assert_equals( expect=main.TRUE,
1091 actual=currentHostsResult,
1092 onpass="ONOS" + controllerStr +
1093 " hosts exist in Mininet",
1094 onfail="ONOS" + controllerStr +
1095 " hosts don't match Mininet" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001096
Jon Hall8f89dda2015-01-22 16:03:33 -08001097 devicesResults = devicesResults and currentDevicesResult
1098 portsResults = portsResults and currentPortsResult
1099 linksResults = linksResults and currentLinksResult
pingping-lin763ee042015-05-20 17:45:30 -07001100 hostsResults = hostsResults and currentHostsResult
Jon Hall73cf9cc2014-11-20 22:28:38 -08001101
pingping-lin763ee042015-05-20 17:45:30 -07001102 topoResult = devicesResults and portsResults and linksResults\
1103 and clusterResults and ipResult and hostsResults
Jon Hall8f89dda2015-01-22 16:03:33 -08001104 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
pingping-lin763ee042015-05-20 17:45:30 -07001105 onpass="Topology Check Test successful",
1106 onfail="Topology Check Test NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001107
Jon Hall6aec96b2015-01-19 14:49:31 -08001108 def CASE6( self, main ):
1109 """
Jon Hallffb386d2014-11-21 13:43:38 -08001110 The Failure case.
Jon Hall6aec96b2015-01-19 14:49:31 -08001111 """
Jon Hallffb386d2014-11-21 13:43:38 -08001112 import time
pingping-lin763ee042015-05-20 17:45:30 -07001113 assert numControllers, "numControllers not defined"
1114 assert main, "main not defined"
1115 assert utilities.assert_equals, "utilities.assert_equals not defined"
1116
1117 # Reset non-persistent variables
1118 try:
1119 iCounterValue = 0
1120 except NameError:
1121 main.log.error( "iCounterValue not defined, setting to 0" )
1122 iCounterValue = 0
Jon Hall73cf9cc2014-11-20 22:28:38 -08001123
Jon Hall6aec96b2015-01-19 14:49:31 -08001124 main.log.report( "Restart ONOS node" )
pingping-lin763ee042015-05-20 17:45:30 -07001125 main.case( "Restart ONOS node" )
1126 main.caseExplaination = "Killing ONOS process and restart cli " +\
1127 "sessions once onos is up."
1128 main.step( "Killing ONOS processes" )
1129 killResult = main.ONOSbench.onosKill( ONOS1Ip )
Jon Hallffb386d2014-11-21 13:43:38 -08001130 start = time.time()
pingping-lin763ee042015-05-20 17:45:30 -07001131 utilities.assert_equals( expect=main.TRUE, actual=killResult,
1132 onpass="ONOS Killed",
1133 onfail="Error killing ONOS" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001134
Jon Hall6aec96b2015-01-19 14:49:31 -08001135 main.step( "Checking if ONOS is up yet" )
Jon Hallffb386d2014-11-21 13:43:38 -08001136 count = 0
Jon Hall94fd0472014-12-08 11:52:42 -08001137 while count < 10:
Jon Hall8f89dda2015-01-22 16:03:33 -08001138 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
1139 if onos1Isup == main.TRUE:
Jon Hallffb386d2014-11-21 13:43:38 -08001140 elapsed = time.time() - start
1141 break
1142 else:
1143 count = count + 1
pingping-lin763ee042015-05-20 17:45:30 -07001144 utilities.assert_equals( expect=main.TRUE, actual=onos1Isup,
1145 onpass="ONOS is back up",
1146 onfail="ONOS failed to start" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001147
pingping-lin763ee042015-05-20 17:45:30 -07001148 main.log.step( "Starting ONOS CLI sessions" )
1149 cliResults = main.ONOScli1.startOnosCli( ONOS1Ip )
1150 utilities.assert_equals( expect=main.TRUE, actual=cliResults,
1151 onpass="ONOS cli startup successful",
1152 onfail="ONOS cli startup failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001153
pingping-lin763ee042015-05-20 17:45:30 -07001154 if elapsed:
1155 main.log.info( "ESTIMATE: ONOS took %s seconds to restart" %
1156 str( elapsed ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001157 time.sleep( 5 )
pingping-lin763ee042015-05-20 17:45:30 -07001158 # rerun on election apps
1159 main.ONOScli1.electionTestRun()
Jon Hall73cf9cc2014-11-20 22:28:38 -08001160
Jon Hall6aec96b2015-01-19 14:49:31 -08001161 def CASE7( self, main ):
1162 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001163 Check state after ONOS failure
Jon Hall6aec96b2015-01-19 14:49:31 -08001164 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001165 import json
pingping-lin763ee042015-05-20 17:45:30 -07001166 assert numControllers, "numControllers not defined"
1167 assert main, "main not defined"
1168 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -08001169 main.case( "Running ONOS Constant State Tests" )
pingping-lin763ee042015-05-20 17:45:30 -07001170 main.step( "Check that each switch has a master" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001171 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -08001172 rolesNotNull = main.ONOScli1.rolesNotNull()
Jon Hall6aec96b2015-01-19 14:49:31 -08001173 utilities.assert_equals(
1174 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001175 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -08001176 onpass="Each device has a master",
1177 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -08001178
Jon Hall6aec96b2015-01-19 14:49:31 -08001179 main.step( "Check if switch roles are consistent across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001180 ONOS1Mastership = main.ONOScli1.roles()
Jon Hall6aec96b2015-01-19 14:49:31 -08001181 # FIXME: Refactor this whole case for single instance
Jon Hall8f89dda2015-01-22 16:03:33 -08001182 if "Error" in ONOS1Mastership or not ONOS1Mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -08001183 main.log.report( "Error in getting ONOS mastership" )
pingping-lin763ee042015-05-20 17:45:30 -07001184 main.log.warn( "ONOS1 mastership response: " +
1185 repr( ONOS1Mastership ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001186 consistentMastership = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001187 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001188 consistentMastership = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001189 main.log.report(
1190 "Switch roles are consistent across all ONOS nodes" )
1191 utilities.assert_equals(
1192 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001193 actual=consistentMastership,
Jon Hall6aec96b2015-01-19 14:49:31 -08001194 onpass="Switch roles are consistent across all ONOS nodes",
1195 onfail="ONOS nodes have different views of switch roles" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001196
1197 description2 = "Compare switch roles from before failure"
Jon Hall6aec96b2015-01-19 14:49:31 -08001198 main.step( description2 )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001199
Jon Hall8f89dda2015-01-22 16:03:33 -08001200 currentJson = json.loads( ONOS1Mastership )
1201 oldJson = json.loads( mastershipState )
1202 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001203 for i in range( 1, 29 ):
1204 switchDPID = str(
pingping-lin763ee042015-05-20 17:45:30 -07001205 main.Mininet1.getSwitchDPID( switch="s" + str( i ) ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001206
Jon Hall8f89dda2015-01-22 16:03:33 -08001207 current = [ switch[ 'master' ] for switch in currentJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001208 if switchDPID in switch[ 'id' ] ]
Jon Hall8f89dda2015-01-22 16:03:33 -08001209 old = [ switch[ 'master' ] for switch in oldJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001210 if switchDPID in switch[ 'id' ] ]
Jon Hall73cf9cc2014-11-20 22:28:38 -08001211 if current == old:
Jon Hall8f89dda2015-01-22 16:03:33 -08001212 mastershipCheck = mastershipCheck and main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001213 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001214 main.log.warn( "Mastership of switch %s changed" % switchDPID )
Jon Hall8f89dda2015-01-22 16:03:33 -08001215 mastershipCheck = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001216 utilities.assert_equals(
1217 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001218 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -08001219 onpass="Mastership of Switches was not changed",
1220 onfail="Mastership of some switches changed" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001221 mastershipCheck = mastershipCheck and consistentMastership
Jon Hall73cf9cc2014-11-20 22:28:38 -08001222
Jon Hall6aec96b2015-01-19 14:49:31 -08001223 main.step( "Get the intents and compare across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001224 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
1225 intentCheck = main.FALSE
1226 if "Error" in ONOS1Intents or not ONOS1Intents:
Jon Hall6aec96b2015-01-19 14:49:31 -08001227 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001228 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001229 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001230 intentCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001231 main.log.report( "Intents are consistent across all ONOS nodes" )
1232 utilities.assert_equals(
1233 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001234 actual=intentCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -08001235 onpass="Intents are consistent across all ONOS nodes",
1236 onfail="ONOS nodes have different views of intents" )
pingping-lin763ee042015-05-20 17:45:30 -07001237 # Print the intent states
1238 intents = []
1239 intents.append( ONOS1Intents )
1240 intentStates = []
1241 for node in intents: # Iter through ONOS nodes
1242 nodeStates = []
1243 # Iter through intents of a node
1244 for intent in json.loads( node ):
1245 nodeStates.append( intent[ 'state' ] )
1246 intentStates.append( nodeStates )
1247 out = [ (i, nodeStates.count( i ) ) for i in set( nodeStates ) ]
1248 main.log.info( dict( out ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001249
pingping-lin763ee042015-05-20 17:45:30 -07001250 # NOTE: Store has no durability, so intents are lost across system
1251 # restarts
Jon Hall6aec96b2015-01-19 14:49:31 -08001252 """
1253 main.step( "Compare current intents with intents before the failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001254 # NOTE: this requires case 5 to pass for intentState to be set.
Jon Hall6aec96b2015-01-19 14:49:31 -08001255 # maybe we should stop the test if that fails?
pingping-lin763ee042015-05-20 17:45:30 -07001256 sameIntents = main.TRUE
1257 if intentState and intentState == ONOS1Intents:
Jon Hall8f89dda2015-01-22 16:03:33 -08001258 sameIntents = main.TRUE
pingping-lin763ee042015-05-20 17:45:30 -07001259 main.log.info( "Intents are consistent with before failure" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001260 # TODO: possibly the states have changed? we may need to figure out
pingping-lin763ee042015-05-20 17:45:30 -07001261 # what the acceptable states are
Jon Hall73cf9cc2014-11-20 22:28:38 -08001262 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001263 try:
1264 main.log.warn( "ONOS1 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001265 print json.dumps( json.loads( ONOS1Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -08001266 sort_keys=True, indent=4,
1267 separators=( ',', ': ' ) )
pingping-lin763ee042015-05-20 17:45:30 -07001268 except Exception:
Jon Hall6aec96b2015-01-19 14:49:31 -08001269 pass
Jon Hall8f89dda2015-01-22 16:03:33 -08001270 sameIntents = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001271 utilities.assert_equals(
1272 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001273 actual=sameIntents,
Jon Hall6aec96b2015-01-19 14:49:31 -08001274 onpass="Intents are consistent with before failure",
1275 onfail="The Intents changed during failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001276 intentCheck = intentCheck and sameIntents
Jon Hall6aec96b2015-01-19 14:49:31 -08001277 """
1278 main.step( "Get the OF Table entries and compare to before " +
1279 "component failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001280 FlowTables = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001281 flows2 = []
1282 for i in range( 28 ):
1283 main.log.info( "Checking flow table on s" + str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001284 tmpFlows = main.Mininet2.getFlowTable( 1.3, "s" + str( i + 1 ) )
1285 flows2.append( tmpFlows )
1286 tempResult = main.Mininet2.flowComp(
Jon Hall6aec96b2015-01-19 14:49:31 -08001287 flow1=flows[ i ],
Jon Hall8f89dda2015-01-22 16:03:33 -08001288 flow2=tmpFlows )
1289 FlowTables = FlowTables and tempResult
1290 if FlowTables == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001291 main.log.info( "Differences in flow table for switch: s" +
1292 str( i + 1 ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001293 utilities.assert_equals(
1294 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001295 actual=FlowTables,
Jon Hall6aec96b2015-01-19 14:49:31 -08001296 onpass="No changes were found in the flow tables",
1297 onfail="Changes were found in the flow tables" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001298
pingping-lin763ee042015-05-20 17:45:30 -07001299 main.step( "Leadership Election is still functional" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001300 # Test of LeadershipElection
Jon Hall669173b2014-12-17 11:36:30 -08001301
Jon Hall8f89dda2015-01-22 16:03:33 -08001302 leader = ONOS1Ip
1303 leaderResult = main.TRUE
1304 for controller in range( 1, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001305 # loop through ONOScli handlers
1306 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001307 leaderN = node.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001308 # verify leader is ONOS1
1309 # NOTE even though we restarted ONOS, it is the only one so onos 1
1310 # must be leader
Jon Hall669173b2014-12-17 11:36:30 -08001311 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08001312 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001313 pass
1314 elif leaderN == main.FALSE:
pingping-lin763ee042015-05-20 17:45:30 -07001315 # error in response
Jon Hall6aec96b2015-01-19 14:49:31 -08001316 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001317 "electionTestLeader function, check the" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001318 " error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001319 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001320 elif leader != leaderN:
Jon Hall8f89dda2015-01-22 16:03:33 -08001321 leaderResult = main.FALSE
pingping-lin763ee042015-05-20 17:45:30 -07001322 main.log.report( "ONOS" + str( controller ) + " sees " +
1323 str( leaderN ) +
1324 " as the leader of the election app. " +
1325 "Leader should be " + str( leader ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001326 utilities.assert_equals(
1327 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001328 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001329 onpass="Leadership election passed",
1330 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08001331
Jon Hall6aec96b2015-01-19 14:49:31 -08001332 def CASE8( self, main ):
1333 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001334 Compare topo
Jon Hall6aec96b2015-01-19 14:49:31 -08001335 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001336 import sys
Jon Hall6aec96b2015-01-19 14:49:31 -08001337 # FIXME add this path to params
1338 sys.path.append( "/home/admin/sts" )
1339 # assumes that sts is already in you PYTHONPATH
1340 from sts.topology.teston_topology import TestONTopology
Jon Hall73cf9cc2014-11-20 22:28:38 -08001341 import json
1342 import time
pingping-lin763ee042015-05-20 17:45:30 -07001343 assert numControllers, "numControllers not defined"
1344 assert main, "main not defined"
1345 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall73cf9cc2014-11-20 22:28:38 -08001346
pingping-lin763ee042015-05-20 17:45:30 -07001347 main.case( "Compare ONOS Topology view to Mininet topology" )
1348 main.caseExplaination = "Compare topology objects between Mininet" +\
1349 " and ONOS"
Jon Hall6aec96b2015-01-19 14:49:31 -08001350 main.step( "Create TestONTopology object" )
pingping-lin763ee042015-05-20 17:45:30 -07001351 try:
1352 ctrls = []
1353 node = main.ONOS1
1354 temp = ( node, node.name, node.ip_address, 6633 )
1355 ctrls.append( temp )
1356 MNTopo = TestONTopology( main.Mininet1, ctrls )
1357 except Exception:
1358 objResult = main.FALSE
1359 else:
1360 objResult = main.TRUE
1361 utilities.assert_equals( expect=main.TRUE, actual=objResult,
1362 onpass="Created TestONTopology object",
1363 onfail="Exception while creating " +
1364 "TestONTopology object" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001365
Jon Hall6aec96b2015-01-19 14:49:31 -08001366 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001367 devicesResults = main.TRUE
1368 portsResults = main.TRUE
1369 linksResults = main.TRUE
pingping-lin763ee042015-05-20 17:45:30 -07001370 hostsResults = main.TRUE
Jon Hall8f89dda2015-01-22 16:03:33 -08001371 topoResult = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001372 elapsed = 0
Jon Hallffb386d2014-11-21 13:43:38 -08001373 count = 0
Jon Hall6aec96b2015-01-19 14:49:31 -08001374 main.step( "Collecting topology information from ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001375 startTime = time.time()
pingping-lin763ee042015-05-20 17:45:30 -07001376 # Give time for Gossip to work
Jon Hall8f89dda2015-01-22 16:03:33 -08001377 while topoResult == main.FALSE and elapsed < 60:
pingping-lin763ee042015-05-20 17:45:30 -07001378 count += 1
Jon Hall94fd0472014-12-08 11:52:42 -08001379 if count > 1:
pingping-lin763ee042015-05-20 17:45:30 -07001380 # TODO: Deprecate STS usage
1381 MNTopo = TestONTopology( main.Mininet1, ctrls )
Jon Hall8f89dda2015-01-22 16:03:33 -08001382 cliStart = time.time()
Jon Hall94fd0472014-12-08 11:52:42 -08001383 devices = []
1384 devices.append( main.ONOScli1.devices() )
Jon Hall94fd0472014-12-08 11:52:42 -08001385 hosts = []
pingping-lin763ee042015-05-20 17:45:30 -07001386 hosts.append( json.loads( main.ONOScli1.hosts() ) )
1387 ipResult = main.TRUE
1388 for controller in range( 0, len( hosts ) ):
1389 controllerStr = str( controller + 1 )
1390 for host in hosts[ controller ]:
1391 if host is None or host.get( 'ipAddresses', [] ) == []:
1392 main.log.error(
1393 "DEBUG:Error with host ips on controller" +
1394 controllerStr + ": " + str( host ) )
1395 ipResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001396 ports = []
1397 ports.append( main.ONOScli1.ports() )
1398 links = []
1399 links.append( main.ONOScli1.links() )
pingping-lin763ee042015-05-20 17:45:30 -07001400 clusters = []
1401 clusters.append( main.ONOScli1.clusters() )
1402
Jon Hall8f89dda2015-01-22 16:03:33 -08001403 elapsed = time.time() - startTime
1404 cliTime = time.time() - cliStart
1405 print "CLI time: " + str( cliTime )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001406
Jon Hall8f89dda2015-01-22 16:03:33 -08001407 for controller in range( numControllers ):
1408 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001409 if devices[ controller ] or "Error" not in devices[
1410 controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001411 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -08001412 MNTopo,
pingping-lin763ee042015-05-20 17:45:30 -07001413 json.loads( devices[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001414 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001415 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001416 utilities.assert_equals( expect=main.TRUE,
pingping-lin763ee042015-05-20 17:45:30 -07001417 actual=currentDevicesResult,
1418 onpass="ONOS" + controllerStr +
1419 " Switches view is correct",
1420 onfail="ONOS" + controllerStr +
1421 " Switches view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001422
Jon Hall6aec96b2015-01-19 14:49:31 -08001423 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001424 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -08001425 MNTopo,
pingping-lin763ee042015-05-20 17:45:30 -07001426 json.loads( ports[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001427 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001428 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001429 utilities.assert_equals( expect=main.TRUE,
pingping-lin763ee042015-05-20 17:45:30 -07001430 actual=currentPortsResult,
1431 onpass="ONOS" + controllerStr +
1432 " ports view is correct",
1433 onfail="ONOS" + controllerStr +
1434 " ports view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001435
Jon Hall6aec96b2015-01-19 14:49:31 -08001436 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001437 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -08001438 MNTopo,
pingping-lin763ee042015-05-20 17:45:30 -07001439 json.loads( links[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001440 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001441 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001442 utilities.assert_equals( expect=main.TRUE,
pingping-lin763ee042015-05-20 17:45:30 -07001443 actual=currentLinksResult,
1444 onpass="ONOS" + controllerStr +
1445 " links view is correct",
1446 onfail="ONOS" + controllerStr +
1447 " links view is incorrect" )
1448
1449 if hosts[ controller ] or "Error" not in hosts[ controller ]:
1450 currentHostsResult = main.Mininet1.compareHosts(
1451 MNTopo, hosts[ controller ] )
1452 else:
1453 currentHostsResult = main.FALSE
1454 utilities.assert_equals( expect=main.TRUE,
1455 actual=currentHostsResult,
1456 onpass="ONOS" + controllerStr +
1457 " hosts exist in Mininet",
1458 onfail="ONOS" + controllerStr +
1459 " hosts don't match Mininet" )
1460
1461 devicesResults = devicesResults and currentDevicesResult
1462 portsResults = portsResults and currentPortsResult
1463 linksResults = linksResults and currentLinksResult
1464 hostsResults = hostsResults and currentHostsResult
1465
1466 # "consistent" results don't make sense for single instance
1467 # there should always only be one cluster
1468 numClusters = len( json.loads( clusters[ 0 ] ) )
1469 clusterResults = main.FALSE
1470 if numClusters == 1:
1471 clusterResults = main.TRUE
1472 utilities.assert_equals(
1473 expect=1,
1474 actual=numClusters,
1475 onpass="ONOS shows 1 SCC",
1476 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
1477
1478 topoResult = ( devicesResults and portsResults and linksResults
1479 and hostsResults and ipResult and clusterResults )
Jon Hall94fd0472014-12-08 11:52:42 -08001480
Jon Hall8f89dda2015-01-22 16:03:33 -08001481 topoResult = topoResult and int( count <= 2 )
1482 note = "note it takes about " + str( int( cliTime ) ) + \
1483 " seconds for the test to make all the cli calls to fetch " +\
1484 "the topology from each ONOS instance"
pingping-lin763ee042015-05-20 17:45:30 -07001485 main.log.info(
Jon Hall8f89dda2015-01-22 16:03:33 -08001486 "Very crass estimate for topology discovery/convergence( " +
1487 str( note ) + " ): " + str( elapsed ) + " seconds, " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001488 str( count ) + " tries" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001489 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
pingping-lin763ee042015-05-20 17:45:30 -07001490 onpass="Topology Check Test successful",
1491 onfail="Topology Check Test NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001492
Jon Hall6aec96b2015-01-19 14:49:31 -08001493 def CASE9( self, main ):
1494 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001495 Link s3-s28 down
Jon Hall6aec96b2015-01-19 14:49:31 -08001496 """
1497 import time
pingping-lin763ee042015-05-20 17:45:30 -07001498 assert numControllers, "numControllers not defined"
1499 assert main, "main not defined"
1500 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -08001501 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001502
Jon Hall8f89dda2015-01-22 16:03:33 -08001503 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001504
Jon Hall6aec96b2015-01-19 14:49:31 -08001505 description = "Turn off a link to ensure that Link Discovery " +\
pingping-lin763ee042015-05-20 17:45:30 -07001506 "is working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001507 main.log.report( description )
1508 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001509
Jon Hall6aec96b2015-01-19 14:49:31 -08001510 main.step( "Kill Link between s3 and s28" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001511 LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" )
pingping-lin763ee042015-05-20 17:45:30 -07001512 main.log.info( "Waiting " + str( linkSleep ) +
1513 " seconds for link down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001514 time.sleep( linkSleep )
1515 utilities.assert_equals( expect=main.TRUE, actual=LinkDown,
pingping-lin763ee042015-05-20 17:45:30 -07001516 onpass="Link down successful",
1517 onfail="Failed to bring link down" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001518 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -08001519
Jon Hall6aec96b2015-01-19 14:49:31 -08001520 def CASE10( self, main ):
1521 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001522 Link s3-s28 up
Jon Hall6aec96b2015-01-19 14:49:31 -08001523 """
1524 import time
pingping-lin763ee042015-05-20 17:45:30 -07001525 assert numControllers, "numControllers not defined"
1526 assert main, "main not defined"
1527 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -08001528 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001529
Jon Hall8f89dda2015-01-22 16:03:33 -08001530 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001531
Jon Hall6aec96b2015-01-19 14:49:31 -08001532 description = "Restore a link to ensure that Link Discovery is " + \
pingping-lin763ee042015-05-20 17:45:30 -07001533 "working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001534 main.log.report( description )
1535 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001536
Jon Hall6aec96b2015-01-19 14:49:31 -08001537 main.step( "Bring link between s3 and s28 back up" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001538 LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" )
pingping-lin763ee042015-05-20 17:45:30 -07001539 main.log.info( "Waiting " + str( linkSleep ) +
1540 " seconds for link up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001541 time.sleep( linkSleep )
1542 utilities.assert_equals( expect=main.TRUE, actual=LinkUp,
pingping-lin763ee042015-05-20 17:45:30 -07001543 onpass="Link up successful",
1544 onfail="Failed to bring link up" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001545 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -08001546
Jon Hall6aec96b2015-01-19 14:49:31 -08001547 def CASE11( self, main ):
1548 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001549 Switch Down
Jon Hall6aec96b2015-01-19 14:49:31 -08001550 """
1551 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001552 import time
pingping-lin763ee042015-05-20 17:45:30 -07001553 assert numControllers, "numControllers not defined"
1554 assert main, "main not defined"
1555 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall73cf9cc2014-11-20 22:28:38 -08001556
Jon Hall8f89dda2015-01-22 16:03:33 -08001557 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001558
1559 description = "Killing a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001560 main.log.report( description )
1561 main.case( description )
1562 switch = main.params[ 'kill' ][ 'switch' ]
1563 switchDPID = main.params[ 'kill' ][ 'dpid' ]
Jon Hall73cf9cc2014-11-20 22:28:38 -08001564
Jon Hall6aec96b2015-01-19 14:49:31 -08001565 # TODO: Make this switch parameterizable
1566 main.step( "Kill " + switch )
1567 main.log.report( "Deleting " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001568 main.Mininet1.delSwitch( switch )
1569 main.log.info( "Waiting " + str( switchSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001570 " seconds for switch down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001571 time.sleep( switchSleep )
1572 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001573 # Peek at the deleted switch
1574 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001575 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001576 if device and device[ 'available' ] is False:
Jon Hall94fd0472014-12-08 11:52:42 -08001577 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001578 utilities.assert_equals( expect=main.TRUE, actual=result,
pingping-lin763ee042015-05-20 17:45:30 -07001579 onpass="Kill switch successful",
1580 onfail="Failed to kill switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001581
Jon Hall6aec96b2015-01-19 14:49:31 -08001582 def CASE12( self, main ):
1583 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001584 Switch Up
Jon Hall6aec96b2015-01-19 14:49:31 -08001585 """
1586 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001587 import time
pingping-lin763ee042015-05-20 17:45:30 -07001588 assert numControllers, "numControllers not defined"
1589 assert main, "main not defined"
1590 assert utilities.assert_equals, "utilities.assert_equals not defined"
1591 assert ONOS1Port, "ONOS1Port not defined"
1592 assert ONOS2Port, "ONOS2Port not defined"
1593 assert ONOS3Port, "ONOS3Port not defined"
1594 assert ONOS4Port, "ONOS4Port not defined"
1595 assert ONOS5Port, "ONOS5Port not defined"
1596 assert ONOS6Port, "ONOS6Port not defined"
1597 assert ONOS7Port, "ONOS7Port not defined"
Jon Hall669173b2014-12-17 11:36:30 -08001598
Jon Hall8f89dda2015-01-22 16:03:33 -08001599 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall6aec96b2015-01-19 14:49:31 -08001600 switch = main.params[ 'kill' ][ 'switch' ]
1601 switchDPID = main.params[ 'kill' ][ 'dpid' ]
1602 links = main.params[ 'kill' ][ 'links' ].split()
Jon Hall73cf9cc2014-11-20 22:28:38 -08001603 description = "Adding a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001604 main.log.report( description )
1605 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001606
Jon Hall6aec96b2015-01-19 14:49:31 -08001607 main.step( "Add back " + switch )
1608 main.log.report( "Adding back " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001609 main.Mininet1.addSwitch( switch, dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001610 for peer in links:
Jon Hall8f89dda2015-01-22 16:03:33 -08001611 main.Mininet1.addLink( switch, peer )
1612 main.Mininet1.assignSwController( sw=switch.split( 's' )[ 1 ],
pingping-lin763ee042015-05-20 17:45:30 -07001613 ip1=ONOS1Ip,
1614 port1=ONOS1Port )
1615 main.log.info( "Waiting " + str( switchSleep ) +
1616 " seconds for switch up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001617 time.sleep( switchSleep )
1618 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001619 # Peek at the deleted switch
1620 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001621 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001622 if device and device[ 'available' ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001623 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001624 utilities.assert_equals( expect=main.TRUE, actual=result,
pingping-lin763ee042015-05-20 17:45:30 -07001625 onpass="add switch successful",
1626 onfail="Failed to add switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001627
Jon Hall6aec96b2015-01-19 14:49:31 -08001628 def CASE13( self, main ):
1629 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001630 Clean up
Jon Hall6aec96b2015-01-19 14:49:31 -08001631 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001632 import os
1633 import time
pingping-lin763ee042015-05-20 17:45:30 -07001634 assert numControllers, "numControllers not defined"
1635 assert main, "main not defined"
1636 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -08001637 # printing colors to terminal
pingping-lin763ee042015-05-20 17:45:30 -07001638 colors = { 'cyan': '\033[96m', 'purple': '\033[95m',
1639 'blue': '\033[94m', 'green': '\033[92m',
1640 'yellow': '\033[93m', 'red': '\033[91m', 'end': '\033[0m' }
Jon Hall73cf9cc2014-11-20 22:28:38 -08001641 description = "Test Cleanup"
Jon Hall6aec96b2015-01-19 14:49:31 -08001642 main.log.report( description )
1643 main.case( description )
1644 main.step( "Killing tcpdumps" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001645 main.Mininet2.stopTcpdump()
Jon Hall73cf9cc2014-11-20 22:28:38 -08001646
Jon Hall6aec96b2015-01-19 14:49:31 -08001647 main.step( "Copying MN pcap and ONOS log files to test station" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001648 testname = main.TEST
Jon Hall8f89dda2015-01-22 16:03:33 -08001649 teststationUser = main.params[ 'TESTONUSER' ]
1650 teststationIP = main.params[ 'TESTONIP' ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001651 # NOTE: MN Pcap file is being saved to ~/packet_captures
Jon Hall73cf9cc2014-11-20 22:28:38 -08001652 # scp this file as MN and TestON aren't necessarily the same vm
Jon Hall6aec96b2015-01-19 14:49:31 -08001653 # FIXME: scp
1654 # mn files
1655 # TODO: Load these from params
1656 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001657 logFolder = "/opt/onos/log/"
1658 logFiles = [ "karaf.log", "karaf.log.1" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001659 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001660 dstDir = "~/packet_captures/"
1661 for f in logFiles:
1662 main.ONOSbench.handle.sendline( "scp sdn@" + ONOS1Ip + ":" +
1663 logFolder + f + " " +
1664 teststationUser + "@" +
1665 teststationIP + ":" + dstDir +
Jon Hall6aec96b2015-01-19 14:49:31 -08001666 str( testname ) + "-ONOS1-" + f )
1667 main.ONOSbench.handle.expect( "\$" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001668
Jon Hall6aec96b2015-01-19 14:49:31 -08001669 # std*.log's
1670 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001671 logFolder = "/opt/onos/var/"
1672 logFiles = [ "stderr.log", "stdout.log" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001673 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001674 dstDir = "~/packet_captures/"
1675 for f in logFiles:
1676 main.ONOSbench.handle.sendline( "scp sdn@" + ONOS1Ip + ":" +
1677 logFolder + f + " " +
1678 teststationUser + "@" +
1679 teststationIP + ":" + dstDir +
Jon Hall6aec96b2015-01-19 14:49:31 -08001680 str( testname ) + "-ONOS1-" + f )
pingping-lin763ee042015-05-20 17:45:30 -07001681 main.ONOSbench.handle.expect( "\$" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001682 # sleep so scp can finish
1683 time.sleep( 10 )
pingping-lin763ee042015-05-20 17:45:30 -07001684
1685 main.step( "Stopping Mininet" )
1686 mnResult = main.Mininet1.stopNet()
1687 utilities.assert_equals( expect=main.TRUE, actual=mnResult,
1688 onpass="Mininet stopped",
1689 onfail="MN cleanup NOT successful" )
1690
1691 main.step( "Checking ONOS Logs for errors" )
1692 print colors[ 'purple' ] + "Checking logs for errors on ONOS1:" + \
1693 colors[ 'end' ]
1694 print main.ONOSbench.checkLogs( ONOS1Ip )
1695
Jon Hall6aec96b2015-01-19 14:49:31 -08001696 main.step( "Packing and rotating pcap archives" )
1697 os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001698
Jon Hall6aec96b2015-01-19 14:49:31 -08001699 def CASE14( self, main ):
1700 """
Jon Hall669173b2014-12-17 11:36:30 -08001701 start election app on all onos nodes
Jon Hall6aec96b2015-01-19 14:49:31 -08001702 """
pingping-lin763ee042015-05-20 17:45:30 -07001703 assert numControllers, "numControllers not defined"
1704 assert main, "main not defined"
1705 assert utilities.assert_equals, "utilities.assert_equals not defined"
1706
1707 main.case("Start Leadership Election app")
1708 main.step( "Install leadership election app" )
1709 appResult = main.ONOScli1.activateApp( "org.onosproject.election" )
1710 utilities.assert_equals(
1711 expect=main.TRUE,
1712 actual=appResult,
1713 onpass="Election app installed",
1714 onfail="Something went wrong with installing Leadership election" )
1715
1716 main.step( "Run for election on each node" )
1717 leaderResult = main.ONOScli1.electionTestRun()
Jon Hall6aec96b2015-01-19 14:49:31 -08001718 # check for leader
Jon Hall8f89dda2015-01-22 16:03:33 -08001719 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001720 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08001721 if leader == ONOS1Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08001722 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001723 pass
Jon Hall6aec96b2015-01-19 14:49:31 -08001724 elif leader is None:
1725 # No leader elected
pingping-lin763ee042015-05-20 17:45:30 -07001726 main.log.error( "No leader was elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001727 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001728 elif leader == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001729 # error in response
1730 # TODO: add check for "Command not found:" in the driver, this
1731 # means the app isn't loaded
pingping-lin763ee042015-05-20 17:45:30 -07001732 main.log.error( "Something is wrong with electionTestLeader" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001733 " function, check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001734 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001735 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001736 # error in response
pingping-lin763ee042015-05-20 17:45:30 -07001737 main.log.error(
Jon Hall8f89dda2015-01-22 16:03:33 -08001738 "Unexpected response from electionTestLeader function:'" +
1739 str( leader ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001740 "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001741 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001742 utilities.assert_equals(
1743 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001744 actual=leaderResult,
pingping-lin763ee042015-05-20 17:45:30 -07001745 onpass="Successfully ran for leadership",
1746 onfail="Failed to run for leadership" )
Jon Hall669173b2014-12-17 11:36:30 -08001747
Jon Hall6aec96b2015-01-19 14:49:31 -08001748 def CASE15( self, main ):
1749 """
Jon Hall669173b2014-12-17 11:36:30 -08001750 Check that Leadership Election is still functional
Jon Hall6aec96b2015-01-19 14:49:31 -08001751 """
pingping-lin763ee042015-05-20 17:45:30 -07001752 assert numControllers, "numControllers not defined"
1753 assert main, "main not defined"
1754 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall8f89dda2015-01-22 16:03:33 -08001755 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08001756 description = "Check that Leadership Election is still functional"
Jon Hall6aec96b2015-01-19 14:49:31 -08001757 main.log.report( description )
1758 main.case( description )
1759 main.step( "Find current leader and withdraw" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001760 leader = main.ONOScli1.electionTestLeader()
pingping-lin763ee042015-05-20 17:45:30 -07001761 # do some sanity checking on leader before using it
Jon Hall8f89dda2015-01-22 16:03:33 -08001762 withdrawResult = main.FALSE
1763 if leader == ONOS1Ip:
1764 oldLeader = getattr( main, "ONOScli1" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001765 elif leader is None or leader == main.FALSE:
1766 main.log.report(
1767 "Leader for the election app should be an ONOS node," +
pingping-lin763ee042015-05-20 17:45:30 -07001768 "instead got '" + str( leader ) + "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001769 leaderResult = main.FALSE
pingping-lin763ee042015-05-20 17:45:30 -07001770 oldLeader = None
1771 else:
1772 main.log.error( "Leader election --- why am I HERE?!?")
1773 leaderResult = main.FALSE
1774 oldLeader = None
1775 if oldLeader:
1776 withdrawResult = oldLeader.electionTestWithdraw()
Jon Hall6aec96b2015-01-19 14:49:31 -08001777 utilities.assert_equals(
1778 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001779 actual=withdrawResult,
pingping-lin763ee042015-05-20 17:45:30 -07001780 onpass="Node was withdrawn from election",
1781 onfail="Node was not withdrawn from election" )
Jon Hall669173b2014-12-17 11:36:30 -08001782
Jon Hall6aec96b2015-01-19 14:49:31 -08001783 main.step( "Make sure new leader is elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001784 leaderN = main.ONOScli1.electionTestLeader()
Jon Hall669173b2014-12-17 11:36:30 -08001785 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08001786 main.log.report( "ONOS still sees " + str( leaderN ) +
1787 " as leader after they withdrew" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001788 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001789 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001790 # error in response
1791 # TODO: add check for "Command not found:" in the driver, this
1792 # means the app isn't loaded
Jon Hall8f89dda2015-01-22 16:03:33 -08001793 main.log.report( "Something is wrong with electionTestLeader " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001794 "function, check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001795 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001796 elif leaderN is None:
1797 main.log.info(
1798 "There is no leader after the app withdrew from election" )
pingping-lin763ee042015-05-20 17:45:30 -07001799 leaderResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001800 utilities.assert_equals(
1801 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001802 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001803 onpass="Leadership election passed",
1804 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08001805
pingping-lin763ee042015-05-20 17:45:30 -07001806 main.step( "Run for election on old leader( just so everyone " +
1807 "is in the hat )" )
1808 if oldLeader:
1809 runResult = oldLeader.electionTestRun()
1810 else:
1811 runResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001812 utilities.assert_equals(
1813 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001814 actual=runResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001815 onpass="App re-ran for election",
1816 onfail="App failed to run for election" )
pingping-lin763ee042015-05-20 17:45:30 -07001817
1818 main.step( "Node became leader when it ran for election" )
1819 afterRun = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001820 # verify leader is ONOS1
pingping-lin763ee042015-05-20 17:45:30 -07001821 if afterRun == ONOS1Ip:
1822 afterResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08001823 else:
pingping-lin763ee042015-05-20 17:45:30 -07001824 afterResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001825
Jon Hall6aec96b2015-01-19 14:49:31 -08001826 utilities.assert_equals(
1827 expect=main.TRUE,
pingping-lin763ee042015-05-20 17:45:30 -07001828 actual=afterResult,
1829 onpass="Old leader successfully re-ran for election",
1830 onfail="Something went wrong with Leadership election after " +
1831 "the old leader re-ran for election" )
1832
1833 def CASE16( self, main ):
1834 """
1835 Install Distributed Primitives app
1836 """
1837 assert numControllers, "numControllers not defined"
1838 assert main, "main not defined"
1839 assert utilities.assert_equals, "utilities.assert_equals not defined"
1840 assert CLIs, "CLIs not defined"
1841 assert nodes, "nodes not defined"
1842
1843 # Variables for the distributed primitives tests
1844 global pCounterName
1845 global iCounterName
1846 global pCounterValue
1847 global iCounterValue
1848 global onosSet
1849 global onosSetName
1850 pCounterName = "TestON-Partitions"
1851 iCounterName = "TestON-inMemory"
1852 pCounterValue = 0
1853 iCounterValue = 0
1854 onosSet = set([])
1855 onosSetName = "TestON-set"
1856
1857 description = "Install Primitives app"
1858 main.case( description )
1859 main.step( "Install Primitives app" )
1860 appName = "org.onosproject.distributedprimitives"
1861 appResults = CLIs[0].activateApp( appName )
1862 utilities.assert_equals( expect=main.TRUE,
1863 actual=appResults,
1864 onpass="Primitives app activated",
1865 onfail="Primitives app not activated" )
1866
1867 def CASE17( self, main ):
1868 """
1869 Check for basic functionality with distributed primitives
1870 """
1871 # Make sure variables are defined/set
1872 assert numControllers, "numControllers not defined"
1873 assert main, "main not defined"
1874 assert utilities.assert_equals, "utilities.assert_equals not defined"
1875 assert CLIs, "CLIs not defined"
1876 assert nodes, "nodes not defined"
1877 assert pCounterName, "pCounterName not defined"
1878 assert iCounterName, "iCounterName not defined"
1879 assert onosSetName, "onosSetName not defined"
1880 # NOTE: assert fails if value is 0/None/Empty/False
1881 try:
1882 pCounterValue
1883 except NameError:
1884 main.log.error( "pCounterValue not defined, setting to 0" )
1885 pCounterValue = 0
1886 try:
1887 iCounterValue
1888 except NameError:
1889 main.log.error( "iCounterValue not defined, setting to 0" )
1890 iCounterValue = 0
1891 try:
1892 onosSet
1893 except NameError:
1894 main.log.error( "onosSet not defined, setting to empty Set" )
1895 onosSet = set([])
1896 # Variables for the distributed primitives tests. These are local only
1897 addValue = "a"
1898 addAllValue = "a b c d e f"
1899 retainValue = "c d e f"
1900
1901 description = "Check for basic functionality with distributed " +\
1902 "primitives"
1903 main.case( description )
1904 main.caseExplaination = "Test the methods of the distributed primitives (counters and sets) throught the cli"
1905 # DISTRIBUTED ATOMIC COUNTERS
1906 main.step( "Increment and get a default counter on each node" )
1907 pCounters = []
1908 threads = []
1909 addedPValues = []
1910 for i in range( numControllers ):
1911 t = main.Thread( target=CLIs[i].counterTestIncrement,
1912 name="counterIncrement-" + str( i ),
1913 args=[ pCounterName ] )
1914 pCounterValue += 1
1915 addedPValues.append( pCounterValue )
1916 threads.append( t )
1917 t.start()
1918
1919 for t in threads:
1920 t.join()
1921 pCounters.append( t.result )
1922 # Check that counter incremented numController times
1923 pCounterResults = True
1924 for i in addedPValues:
1925 tmpResult = i in pCounters
1926 pCounterResults = pCounterResults and tmpResult
1927 if not tmpResult:
1928 main.log.error( str( i ) + " is not in partitioned "
1929 "counter incremented results" )
1930 utilities.assert_equals( expect=True,
1931 actual=pCounterResults,
1932 onpass="Default counter incremented",
1933 onfail="Error incrementing default" +
1934 " counter" )
1935
1936 main.step( "Increment and get an in memory counter on each node" )
1937 iCounters = []
1938 addedIValues = []
1939 threads = []
1940 for i in range( numControllers ):
1941 t = main.Thread( target=CLIs[i].counterTestIncrement,
1942 name="icounterIncrement-" + str( i ),
1943 args=[ iCounterName ],
1944 kwargs={ "inMemory": True } )
1945 iCounterValue += 1
1946 addedIValues.append( iCounterValue )
1947 threads.append( t )
1948 t.start()
1949
1950 for t in threads:
1951 t.join()
1952 iCounters.append( t.result )
1953 # Check that counter incremented numController times
1954 iCounterResults = True
1955 for i in addedIValues:
1956 tmpResult = i in iCounters
1957 iCounterResults = iCounterResults and tmpResult
1958 if not tmpResult:
1959 main.log.error( str( i ) + " is not in the in-memory "
1960 "counter incremented results" )
1961 utilities.assert_equals( expect=True,
1962 actual=iCounterResults,
1963 onpass="In memory counter incremented",
1964 onfail="Error incrementing in memory" +
1965 " counter" )
1966
1967 main.step( "Check counters are consistant across nodes" )
1968 onosCounters = []
1969 threads = []
1970 for i in range( numControllers ):
1971 t = main.Thread( target=CLIs[i].counters,
1972 name="counters-" + str( i ) )
1973 threads.append( t )
1974 t.start()
1975 for t in threads:
1976 t.join()
1977 onosCounters.append( t.result )
1978 tmp = [ i == onosCounters[ 0 ] for i in onosCounters ]
1979 if all( tmp ):
1980 main.log.info( "Counters are consistent across all nodes" )
1981 consistentCounterResults = main.TRUE
1982 else:
1983 main.log.error( "Counters are not consistent across all nodes" )
1984 consistentCounterResults = main.FALSE
1985 utilities.assert_equals( expect=main.TRUE,
1986 actual=consistentCounterResults,
1987 onpass="ONOS counters are consistent " +
1988 "across nodes",
1989 onfail="ONOS Counters are inconsistent " +
1990 "across nodes" )
1991
1992 main.step( "Counters we added have the correct values" )
1993 correctResults = main.TRUE
1994 for i in range( numControllers ):
1995 current = onosCounters[i]
1996 try:
1997 pValue = current.get( pCounterName )
1998 iValue = current.get( iCounterName )
1999 if pValue == pCounterValue:
2000 main.log.info( "Partitioned counter value is correct" )
2001 else:
2002 main.log.error( "Partitioned counter value is incorrect," +
2003 " expected value: " + str( pCounterValue )
2004 + " current value: " + str( pValue ) )
2005 correctResults = main.FALSE
2006 if iValue == iCounterValue:
2007 main.log.info( "In memory counter value is correct" )
2008 else:
2009 main.log.error( "In memory counter value is incorrect, " +
2010 "expected value: " + str( iCounterValue ) +
2011 " current value: " + str( iValue ) )
2012 correctResults = main.FALSE
2013 except AttributeError, e:
2014 main.log.error( "ONOS" + str( i + 1 ) + " counters result " +
2015 "is not as expected" )
2016 correctResults = main.FALSE
2017 utilities.assert_equals( expect=main.TRUE,
2018 actual=correctResults,
2019 onpass="Added counters are correct",
2020 onfail="Added counters are incorrect" )
2021 # DISTRIBUTED SETS
2022 main.step( "Distributed Set get" )
2023 size = len( onosSet )
2024 getResponses = []
2025 threads = []
2026 for i in range( numControllers ):
2027 t = main.Thread( target=CLIs[i].setTestGet,
2028 name="setTestGet-" + str( i ),
2029 args=[ onosSetName ] )
2030 threads.append( t )
2031 t.start()
2032 for t in threads:
2033 t.join()
2034 getResponses.append( t.result )
2035
2036 getResults = main.TRUE
2037 for i in range( numControllers ):
2038 if isinstance( getResponses[ i ], list):
2039 current = set( getResponses[ i ] )
2040 if len( current ) == len( getResponses[ i ] ):
2041 # no repeats
2042 if onosSet != current:
2043 main.log.error( "ONOS" + str( i + 1 ) +
2044 " has incorrect view" +
2045 " of set " + onosSetName + ":\n" +
2046 str( getResponses[ i ] ) )
2047 main.log.debug( "Expected: " + str( onosSet ) )
2048 main.log.debug( "Actual: " + str( current ) )
2049 getResults = main.FALSE
2050 else:
2051 # error, set is not a set
2052 main.log.error( "ONOS" + str( i + 1 ) +
2053 " has repeat elements in" +
2054 " set " + onosSetName + ":\n" +
2055 str( getResponses[ i ] ) )
2056 getResults = main.FALSE
2057 elif getResponses[ i ] == main.ERROR:
2058 getResults = main.FALSE
2059 utilities.assert_equals( expect=main.TRUE,
2060 actual=getResults,
2061 onpass="Set elements are correct",
2062 onfail="Set elements are incorrect" )
2063
2064 main.step( "Distributed Set size" )
2065 sizeResponses = []
2066 threads = []
2067 for i in range( numControllers ):
2068 t = main.Thread( target=CLIs[i].setTestSize,
2069 name="setTestSize-" + str( i ),
2070 args=[ onosSetName ] )
2071 threads.append( t )
2072 t.start()
2073 for t in threads:
2074 t.join()
2075 sizeResponses.append( t.result )
2076
2077 sizeResults = main.TRUE
2078 for i in range( numControllers ):
2079 if size != sizeResponses[ i ]:
2080 sizeResults = main.FALSE
2081 main.log.error( "ONOS" + str( i + 1 ) +
2082 " expected a size of " + str( size ) +
2083 " for set " + onosSetName +
2084 " but got " + str( sizeResponses[ i ] ) )
2085 utilities.assert_equals( expect=main.TRUE,
2086 actual=sizeResults,
2087 onpass="Set sizes are correct",
2088 onfail="Set sizes are incorrect" )
2089
2090 main.step( "Distributed Set add()" )
2091 onosSet.add( addValue )
2092 addResponses = []
2093 threads = []
2094 for i in range( numControllers ):
2095 t = main.Thread( target=CLIs[i].setTestAdd,
2096 name="setTestAdd-" + str( i ),
2097 args=[ onosSetName, addValue ] )
2098 threads.append( t )
2099 t.start()
2100 for t in threads:
2101 t.join()
2102 addResponses.append( t.result )
2103
2104 # main.TRUE = successfully changed the set
2105 # main.FALSE = action resulted in no change in set
2106 # main.ERROR - Some error in executing the function
2107 addResults = main.TRUE
2108 for i in range( numControllers ):
2109 if addResponses[ i ] == main.TRUE:
2110 # All is well
2111 pass
2112 elif addResponses[ i ] == main.FALSE:
2113 # Already in set, probably fine
2114 pass
2115 elif addResponses[ i ] == main.ERROR:
2116 # Error in execution
2117 addResults = main.FALSE
2118 else:
2119 # unexpected result
2120 addResults = main.FALSE
2121 if addResults != main.TRUE:
2122 main.log.error( "Error executing set add" )
2123
2124 # Check if set is still correct
2125 size = len( onosSet )
2126 getResponses = []
2127 threads = []
2128 for i in range( numControllers ):
2129 t = main.Thread( target=CLIs[i].setTestGet,
2130 name="setTestGet-" + str( i ),
2131 args=[ onosSetName ] )
2132 threads.append( t )
2133 t.start()
2134 for t in threads:
2135 t.join()
2136 getResponses.append( t.result )
2137 getResults = main.TRUE
2138 for i in range( numControllers ):
2139 if isinstance( getResponses[ i ], list):
2140 current = set( getResponses[ i ] )
2141 if len( current ) == len( getResponses[ i ] ):
2142 # no repeats
2143 if onosSet != current:
2144 main.log.error( "ONOS" + str( i + 1 ) +
2145 " has incorrect view" +
2146 " of set " + onosSetName + ":\n" +
2147 str( getResponses[ i ] ) )
2148 main.log.debug( "Expected: " + str( onosSet ) )
2149 main.log.debug( "Actual: " + str( current ) )
2150 getResults = main.FALSE
2151 else:
2152 # error, set is not a set
2153 main.log.error( "ONOS" + str( i + 1 ) +
2154 " has repeat elements in" +
2155 " set " + onosSetName + ":\n" +
2156 str( getResponses[ i ] ) )
2157 getResults = main.FALSE
2158 elif getResponses[ i ] == main.ERROR:
2159 getResults = main.FALSE
2160 sizeResponses = []
2161 threads = []
2162 for i in range( numControllers ):
2163 t = main.Thread( target=CLIs[i].setTestSize,
2164 name="setTestSize-" + str( i ),
2165 args=[ onosSetName ] )
2166 threads.append( t )
2167 t.start()
2168 for t in threads:
2169 t.join()
2170 sizeResponses.append( t.result )
2171 sizeResults = main.TRUE
2172 for i in range( numControllers ):
2173 if size != sizeResponses[ i ]:
2174 sizeResults = main.FALSE
2175 main.log.error( "ONOS" + str( i + 1 ) +
2176 " expected a size of " + str( size ) +
2177 " for set " + onosSetName +
2178 " but got " + str( sizeResponses[ i ] ) )
2179 addResults = addResults and getResults and sizeResults
2180 utilities.assert_equals( expect=main.TRUE,
2181 actual=addResults,
2182 onpass="Set add correct",
2183 onfail="Set add was incorrect" )
2184
2185 main.step( "Distributed Set addAll()" )
2186 onosSet.update( addAllValue.split() )
2187 addResponses = []
2188 threads = []
2189 for i in range( numControllers ):
2190 t = main.Thread( target=CLIs[i].setTestAdd,
2191 name="setTestAddAll-" + str( i ),
2192 args=[ onosSetName, addAllValue ] )
2193 threads.append( t )
2194 t.start()
2195 for t in threads:
2196 t.join()
2197 addResponses.append( t.result )
2198
2199 # main.TRUE = successfully changed the set
2200 # main.FALSE = action resulted in no change in set
2201 # main.ERROR - Some error in executing the function
2202 addAllResults = main.TRUE
2203 for i in range( numControllers ):
2204 if addResponses[ i ] == main.TRUE:
2205 # All is well
2206 pass
2207 elif addResponses[ i ] == main.FALSE:
2208 # Already in set, probably fine
2209 pass
2210 elif addResponses[ i ] == main.ERROR:
2211 # Error in execution
2212 addAllResults = main.FALSE
2213 else:
2214 # unexpected result
2215 addAllResults = main.FALSE
2216 if addAllResults != main.TRUE:
2217 main.log.error( "Error executing set addAll" )
2218
2219 # Check if set is still correct
2220 size = len( onosSet )
2221 getResponses = []
2222 threads = []
2223 for i in range( numControllers ):
2224 t = main.Thread( target=CLIs[i].setTestGet,
2225 name="setTestGet-" + str( i ),
2226 args=[ onosSetName ] )
2227 threads.append( t )
2228 t.start()
2229 for t in threads:
2230 t.join()
2231 getResponses.append( t.result )
2232 getResults = main.TRUE
2233 for i in range( numControllers ):
2234 if isinstance( getResponses[ i ], list):
2235 current = set( getResponses[ i ] )
2236 if len( current ) == len( getResponses[ i ] ):
2237 # no repeats
2238 if onosSet != current:
2239 main.log.error( "ONOS" + str( i + 1 ) +
2240 " has incorrect view" +
2241 " of set " + onosSetName + ":\n" +
2242 str( getResponses[ i ] ) )
2243 main.log.debug( "Expected: " + str( onosSet ) )
2244 main.log.debug( "Actual: " + str( current ) )
2245 getResults = main.FALSE
2246 else:
2247 # error, set is not a set
2248 main.log.error( "ONOS" + str( i + 1 ) +
2249 " has repeat elements in" +
2250 " set " + onosSetName + ":\n" +
2251 str( getResponses[ i ] ) )
2252 getResults = main.FALSE
2253 elif getResponses[ i ] == main.ERROR:
2254 getResults = main.FALSE
2255 sizeResponses = []
2256 threads = []
2257 for i in range( numControllers ):
2258 t = main.Thread( target=CLIs[i].setTestSize,
2259 name="setTestSize-" + str( i ),
2260 args=[ onosSetName ] )
2261 threads.append( t )
2262 t.start()
2263 for t in threads:
2264 t.join()
2265 sizeResponses.append( t.result )
2266 sizeResults = main.TRUE
2267 for i in range( numControllers ):
2268 if size != sizeResponses[ i ]:
2269 sizeResults = main.FALSE
2270 main.log.error( "ONOS" + str( i + 1 ) +
2271 " expected a size of " + str( size ) +
2272 " for set " + onosSetName +
2273 " but got " + str( sizeResponses[ i ] ) )
2274 addAllResults = addAllResults and getResults and sizeResults
2275 utilities.assert_equals( expect=main.TRUE,
2276 actual=addAllResults,
2277 onpass="Set addAll correct",
2278 onfail="Set addAll was incorrect" )
2279
2280 main.step( "Distributed Set contains()" )
2281 containsResponses = []
2282 threads = []
2283 for i in range( numControllers ):
2284 t = main.Thread( target=CLIs[i].setTestGet,
2285 name="setContains-" + str( i ),
2286 args=[ onosSetName ],
2287 kwargs={ "values": addValue } )
2288 threads.append( t )
2289 t.start()
2290 for t in threads:
2291 t.join()
2292 # NOTE: This is the tuple
2293 containsResponses.append( t.result )
2294
2295 containsResults = main.TRUE
2296 for i in range( numControllers ):
2297 if containsResponses[ i ] == main.ERROR:
2298 containsResults = main.FALSE
2299 else:
2300 containsResults = containsResults and\
2301 containsResponses[ i ][ 1 ]
2302 utilities.assert_equals( expect=main.TRUE,
2303 actual=containsResults,
2304 onpass="Set contains is functional",
2305 onfail="Set contains failed" )
2306
2307 main.step( "Distributed Set containsAll()" )
2308 containsAllResponses = []
2309 threads = []
2310 for i in range( numControllers ):
2311 t = main.Thread( target=CLIs[i].setTestGet,
2312 name="setContainsAll-" + str( i ),
2313 args=[ onosSetName ],
2314 kwargs={ "values": addAllValue } )
2315 threads.append( t )
2316 t.start()
2317 for t in threads:
2318 t.join()
2319 # NOTE: This is the tuple
2320 containsAllResponses.append( t.result )
2321
2322 containsAllResults = main.TRUE
2323 for i in range( numControllers ):
2324 if containsResponses[ i ] == main.ERROR:
2325 containsResults = main.FALSE
2326 else:
2327 containsResults = containsResults and\
2328 containsResponses[ i ][ 1 ]
2329 utilities.assert_equals( expect=main.TRUE,
2330 actual=containsAllResults,
2331 onpass="Set containsAll is functional",
2332 onfail="Set containsAll failed" )
2333
2334 main.step( "Distributed Set remove()" )
2335 onosSet.remove( addValue )
2336 removeResponses = []
2337 threads = []
2338 for i in range( numControllers ):
2339 t = main.Thread( target=CLIs[i].setTestRemove,
2340 name="setTestRemove-" + str( i ),
2341 args=[ onosSetName, addValue ] )
2342 threads.append( t )
2343 t.start()
2344 for t in threads:
2345 t.join()
2346 removeResponses.append( t.result )
2347
2348 # main.TRUE = successfully changed the set
2349 # main.FALSE = action resulted in no change in set
2350 # main.ERROR - Some error in executing the function
2351 removeResults = main.TRUE
2352 for i in range( numControllers ):
2353 if removeResponses[ i ] == main.TRUE:
2354 # All is well
2355 pass
2356 elif removeResponses[ i ] == main.FALSE:
2357 # not in set, probably fine
2358 pass
2359 elif removeResponses[ i ] == main.ERROR:
2360 # Error in execution
2361 removeResults = main.FALSE
2362 else:
2363 # unexpected result
2364 removeResults = main.FALSE
2365 if removeResults != main.TRUE:
2366 main.log.error( "Error executing set remove" )
2367
2368 # Check if set is still correct
2369 size = len( onosSet )
2370 getResponses = []
2371 threads = []
2372 for i in range( numControllers ):
2373 t = main.Thread( target=CLIs[i].setTestGet,
2374 name="setTestGet-" + str( i ),
2375 args=[ onosSetName ] )
2376 threads.append( t )
2377 t.start()
2378 for t in threads:
2379 t.join()
2380 getResponses.append( t.result )
2381 getResults = main.TRUE
2382 for i in range( numControllers ):
2383 if isinstance( getResponses[ i ], list):
2384 current = set( getResponses[ i ] )
2385 if len( current ) == len( getResponses[ i ] ):
2386 # no repeats
2387 if onosSet != current:
2388 main.log.error( "ONOS" + str( i + 1 ) +
2389 " has incorrect view" +
2390 " of set " + onosSetName + ":\n" +
2391 str( getResponses[ i ] ) )
2392 main.log.debug( "Expected: " + str( onosSet ) )
2393 main.log.debug( "Actual: " + str( current ) )
2394 getResults = main.FALSE
2395 else:
2396 # error, set is not a set
2397 main.log.error( "ONOS" + str( i + 1 ) +
2398 " has repeat elements in" +
2399 " set " + onosSetName + ":\n" +
2400 str( getResponses[ i ] ) )
2401 getResults = main.FALSE
2402 elif getResponses[ i ] == main.ERROR:
2403 getResults = main.FALSE
2404 sizeResponses = []
2405 threads = []
2406 for i in range( numControllers ):
2407 t = main.Thread( target=CLIs[i].setTestSize,
2408 name="setTestSize-" + str( i ),
2409 args=[ onosSetName ] )
2410 threads.append( t )
2411 t.start()
2412 for t in threads:
2413 t.join()
2414 sizeResponses.append( t.result )
2415 sizeResults = main.TRUE
2416 for i in range( numControllers ):
2417 if size != sizeResponses[ i ]:
2418 sizeResults = main.FALSE
2419 main.log.error( "ONOS" + str( i + 1 ) +
2420 " expected a size of " + str( size ) +
2421 " for set " + onosSetName +
2422 " but got " + str( sizeResponses[ i ] ) )
2423 removeResults = removeResults and getResults and sizeResults
2424 utilities.assert_equals( expect=main.TRUE,
2425 actual=removeResults,
2426 onpass="Set remove correct",
2427 onfail="Set remove was incorrect" )
2428
2429 main.step( "Distributed Set removeAll()" )
2430 onosSet.difference_update( addAllValue.split() )
2431 removeAllResponses = []
2432 threads = []
2433 try:
2434 for i in range( numControllers ):
2435 t = main.Thread( target=CLIs[i].setTestRemove,
2436 name="setTestRemoveAll-" + str( i ),
2437 args=[ onosSetName, addAllValue ] )
2438 threads.append( t )
2439 t.start()
2440 for t in threads:
2441 t.join()
2442 removeAllResponses.append( t.result )
2443 except Exception, e:
2444 main.log.exception(e)
2445
2446 # main.TRUE = successfully changed the set
2447 # main.FALSE = action resulted in no change in set
2448 # main.ERROR - Some error in executing the function
2449 removeAllResults = main.TRUE
2450 for i in range( numControllers ):
2451 if removeAllResponses[ i ] == main.TRUE:
2452 # All is well
2453 pass
2454 elif removeAllResponses[ i ] == main.FALSE:
2455 # not in set, probably fine
2456 pass
2457 elif removeAllResponses[ i ] == main.ERROR:
2458 # Error in execution
2459 removeAllResults = main.FALSE
2460 else:
2461 # unexpected result
2462 removeAllResults = main.FALSE
2463 if removeAllResults != main.TRUE:
2464 main.log.error( "Error executing set removeAll" )
2465
2466 # Check if set is still correct
2467 size = len( onosSet )
2468 getResponses = []
2469 threads = []
2470 for i in range( numControllers ):
2471 t = main.Thread( target=CLIs[i].setTestGet,
2472 name="setTestGet-" + str( i ),
2473 args=[ onosSetName ] )
2474 threads.append( t )
2475 t.start()
2476 for t in threads:
2477 t.join()
2478 getResponses.append( t.result )
2479 getResults = main.TRUE
2480 for i in range( numControllers ):
2481 if isinstance( getResponses[ i ], list):
2482 current = set( getResponses[ i ] )
2483 if len( current ) == len( getResponses[ i ] ):
2484 # no repeats
2485 if onosSet != current:
2486 main.log.error( "ONOS" + str( i + 1 ) +
2487 " has incorrect view" +
2488 " of set " + onosSetName + ":\n" +
2489 str( getResponses[ i ] ) )
2490 main.log.debug( "Expected: " + str( onosSet ) )
2491 main.log.debug( "Actual: " + str( current ) )
2492 getResults = main.FALSE
2493 else:
2494 # error, set is not a set
2495 main.log.error( "ONOS" + str( i + 1 ) +
2496 " has repeat elements in" +
2497 " set " + onosSetName + ":\n" +
2498 str( getResponses[ i ] ) )
2499 getResults = main.FALSE
2500 elif getResponses[ i ] == main.ERROR:
2501 getResults = main.FALSE
2502 sizeResponses = []
2503 threads = []
2504 for i in range( numControllers ):
2505 t = main.Thread( target=CLIs[i].setTestSize,
2506 name="setTestSize-" + str( i ),
2507 args=[ onosSetName ] )
2508 threads.append( t )
2509 t.start()
2510 for t in threads:
2511 t.join()
2512 sizeResponses.append( t.result )
2513 sizeResults = main.TRUE
2514 for i in range( numControllers ):
2515 if size != sizeResponses[ i ]:
2516 sizeResults = main.FALSE
2517 main.log.error( "ONOS" + str( i + 1 ) +
2518 " expected a size of " + str( size ) +
2519 " for set " + onosSetName +
2520 " but got " + str( sizeResponses[ i ] ) )
2521 removeAllResults = removeAllResults and getResults and sizeResults
2522 utilities.assert_equals( expect=main.TRUE,
2523 actual=removeAllResults,
2524 onpass="Set removeAll correct",
2525 onfail="Set removeAll was incorrect" )
2526
2527 main.step( "Distributed Set addAll()" )
2528 onosSet.update( addAllValue.split() )
2529 addResponses = []
2530 threads = []
2531 for i in range( numControllers ):
2532 t = main.Thread( target=CLIs[i].setTestAdd,
2533 name="setTestAddAll-" + str( i ),
2534 args=[ onosSetName, addAllValue ] )
2535 threads.append( t )
2536 t.start()
2537 for t in threads:
2538 t.join()
2539 addResponses.append( t.result )
2540
2541 # main.TRUE = successfully changed the set
2542 # main.FALSE = action resulted in no change in set
2543 # main.ERROR - Some error in executing the function
2544 addAllResults = main.TRUE
2545 for i in range( numControllers ):
2546 if addResponses[ i ] == main.TRUE:
2547 # All is well
2548 pass
2549 elif addResponses[ i ] == main.FALSE:
2550 # Already in set, probably fine
2551 pass
2552 elif addResponses[ i ] == main.ERROR:
2553 # Error in execution
2554 addAllResults = main.FALSE
2555 else:
2556 # unexpected result
2557 addAllResults = main.FALSE
2558 if addAllResults != main.TRUE:
2559 main.log.error( "Error executing set addAll" )
2560
2561 # Check if set is still correct
2562 size = len( onosSet )
2563 getResponses = []
2564 threads = []
2565 for i in range( numControllers ):
2566 t = main.Thread( target=CLIs[i].setTestGet,
2567 name="setTestGet-" + str( i ),
2568 args=[ onosSetName ] )
2569 threads.append( t )
2570 t.start()
2571 for t in threads:
2572 t.join()
2573 getResponses.append( t.result )
2574 getResults = main.TRUE
2575 for i in range( numControllers ):
2576 if isinstance( getResponses[ i ], list):
2577 current = set( getResponses[ i ] )
2578 if len( current ) == len( getResponses[ i ] ):
2579 # no repeats
2580 if onosSet != current:
2581 main.log.error( "ONOS" + str( i + 1 ) +
2582 " has incorrect view" +
2583 " of set " + onosSetName + ":\n" +
2584 str( getResponses[ i ] ) )
2585 main.log.debug( "Expected: " + str( onosSet ) )
2586 main.log.debug( "Actual: " + str( current ) )
2587 getResults = main.FALSE
2588 else:
2589 # error, set is not a set
2590 main.log.error( "ONOS" + str( i + 1 ) +
2591 " has repeat elements in" +
2592 " set " + onosSetName + ":\n" +
2593 str( getResponses[ i ] ) )
2594 getResults = main.FALSE
2595 elif getResponses[ i ] == main.ERROR:
2596 getResults = main.FALSE
2597 sizeResponses = []
2598 threads = []
2599 for i in range( numControllers ):
2600 t = main.Thread( target=CLIs[i].setTestSize,
2601 name="setTestSize-" + str( i ),
2602 args=[ onosSetName ] )
2603 threads.append( t )
2604 t.start()
2605 for t in threads:
2606 t.join()
2607 sizeResponses.append( t.result )
2608 sizeResults = main.TRUE
2609 for i in range( numControllers ):
2610 if size != sizeResponses[ i ]:
2611 sizeResults = main.FALSE
2612 main.log.error( "ONOS" + str( i + 1 ) +
2613 " expected a size of " + str( size ) +
2614 " for set " + onosSetName +
2615 " but got " + str( sizeResponses[ i ] ) )
2616 addAllResults = addAllResults and getResults and sizeResults
2617 utilities.assert_equals( expect=main.TRUE,
2618 actual=addAllResults,
2619 onpass="Set addAll correct",
2620 onfail="Set addAll was incorrect" )
2621
2622 main.step( "Distributed Set clear()" )
2623 onosSet.clear()
2624 clearResponses = []
2625 threads = []
2626 for i in range( numControllers ):
2627 t = main.Thread( target=CLIs[i].setTestRemove,
2628 name="setTestClear-" + str( i ),
2629 args=[ onosSetName, " "], # Values doesn't matter
2630 kwargs={ "clear": True } )
2631 threads.append( t )
2632 t.start()
2633 for t in threads:
2634 t.join()
2635 clearResponses.append( t.result )
2636
2637 # main.TRUE = successfully changed the set
2638 # main.FALSE = action resulted in no change in set
2639 # main.ERROR - Some error in executing the function
2640 clearResults = main.TRUE
2641 for i in range( numControllers ):
2642 if clearResponses[ i ] == main.TRUE:
2643 # All is well
2644 pass
2645 elif clearResponses[ i ] == main.FALSE:
2646 # Nothing set, probably fine
2647 pass
2648 elif clearResponses[ i ] == main.ERROR:
2649 # Error in execution
2650 clearResults = main.FALSE
2651 else:
2652 # unexpected result
2653 clearResults = main.FALSE
2654 if clearResults != main.TRUE:
2655 main.log.error( "Error executing set clear" )
2656
2657 # Check if set is still correct
2658 size = len( onosSet )
2659 getResponses = []
2660 threads = []
2661 for i in range( numControllers ):
2662 t = main.Thread( target=CLIs[i].setTestGet,
2663 name="setTestGet-" + str( i ),
2664 args=[ onosSetName ] )
2665 threads.append( t )
2666 t.start()
2667 for t in threads:
2668 t.join()
2669 getResponses.append( t.result )
2670 getResults = main.TRUE
2671 for i in range( numControllers ):
2672 if isinstance( getResponses[ i ], list):
2673 current = set( getResponses[ i ] )
2674 if len( current ) == len( getResponses[ i ] ):
2675 # no repeats
2676 if onosSet != current:
2677 main.log.error( "ONOS" + str( i + 1 ) +
2678 " has incorrect view" +
2679 " of set " + onosSetName + ":\n" +
2680 str( getResponses[ i ] ) )
2681 main.log.debug( "Expected: " + str( onosSet ) )
2682 main.log.debug( "Actual: " + str( current ) )
2683 getResults = main.FALSE
2684 else:
2685 # error, set is not a set
2686 main.log.error( "ONOS" + str( i + 1 ) +
2687 " has repeat elements in" +
2688 " set " + onosSetName + ":\n" +
2689 str( getResponses[ i ] ) )
2690 getResults = main.FALSE
2691 elif getResponses[ i ] == main.ERROR:
2692 getResults = main.FALSE
2693 sizeResponses = []
2694 threads = []
2695 for i in range( numControllers ):
2696 t = main.Thread( target=CLIs[i].setTestSize,
2697 name="setTestSize-" + str( i ),
2698 args=[ onosSetName ] )
2699 threads.append( t )
2700 t.start()
2701 for t in threads:
2702 t.join()
2703 sizeResponses.append( t.result )
2704 sizeResults = main.TRUE
2705 for i in range( numControllers ):
2706 if size != sizeResponses[ i ]:
2707 sizeResults = main.FALSE
2708 main.log.error( "ONOS" + str( i + 1 ) +
2709 " expected a size of " + str( size ) +
2710 " for set " + onosSetName +
2711 " but got " + str( sizeResponses[ i ] ) )
2712 clearResults = clearResults and getResults and sizeResults
2713 utilities.assert_equals( expect=main.TRUE,
2714 actual=clearResults,
2715 onpass="Set clear correct",
2716 onfail="Set clear was incorrect" )
2717
2718 main.step( "Distributed Set addAll()" )
2719 onosSet.update( addAllValue.split() )
2720 addResponses = []
2721 threads = []
2722 for i in range( numControllers ):
2723 t = main.Thread( target=CLIs[i].setTestAdd,
2724 name="setTestAddAll-" + str( i ),
2725 args=[ onosSetName, addAllValue ] )
2726 threads.append( t )
2727 t.start()
2728 for t in threads:
2729 t.join()
2730 addResponses.append( t.result )
2731
2732 # main.TRUE = successfully changed the set
2733 # main.FALSE = action resulted in no change in set
2734 # main.ERROR - Some error in executing the function
2735 addAllResults = main.TRUE
2736 for i in range( numControllers ):
2737 if addResponses[ i ] == main.TRUE:
2738 # All is well
2739 pass
2740 elif addResponses[ i ] == main.FALSE:
2741 # Already in set, probably fine
2742 pass
2743 elif addResponses[ i ] == main.ERROR:
2744 # Error in execution
2745 addAllResults = main.FALSE
2746 else:
2747 # unexpected result
2748 addAllResults = main.FALSE
2749 if addAllResults != main.TRUE:
2750 main.log.error( "Error executing set addAll" )
2751
2752 # Check if set is still correct
2753 size = len( onosSet )
2754 getResponses = []
2755 threads = []
2756 for i in range( numControllers ):
2757 t = main.Thread( target=CLIs[i].setTestGet,
2758 name="setTestGet-" + str( i ),
2759 args=[ onosSetName ] )
2760 threads.append( t )
2761 t.start()
2762 for t in threads:
2763 t.join()
2764 getResponses.append( t.result )
2765 getResults = main.TRUE
2766 for i in range( numControllers ):
2767 if isinstance( getResponses[ i ], list):
2768 current = set( getResponses[ i ] )
2769 if len( current ) == len( getResponses[ i ] ):
2770 # no repeats
2771 if onosSet != current:
2772 main.log.error( "ONOS" + str( i + 1 ) +
2773 " has incorrect view" +
2774 " of set " + onosSetName + ":\n" +
2775 str( getResponses[ i ] ) )
2776 main.log.debug( "Expected: " + str( onosSet ) )
2777 main.log.debug( "Actual: " + str( current ) )
2778 getResults = main.FALSE
2779 else:
2780 # error, set is not a set
2781 main.log.error( "ONOS" + str( i + 1 ) +
2782 " has repeat elements in" +
2783 " set " + onosSetName + ":\n" +
2784 str( getResponses[ i ] ) )
2785 getResults = main.FALSE
2786 elif getResponses[ i ] == main.ERROR:
2787 getResults = main.FALSE
2788 sizeResponses = []
2789 threads = []
2790 for i in range( numControllers ):
2791 t = main.Thread( target=CLIs[i].setTestSize,
2792 name="setTestSize-" + str( i ),
2793 args=[ onosSetName ] )
2794 threads.append( t )
2795 t.start()
2796 for t in threads:
2797 t.join()
2798 sizeResponses.append( t.result )
2799 sizeResults = main.TRUE
2800 for i in range( numControllers ):
2801 if size != sizeResponses[ i ]:
2802 sizeResults = main.FALSE
2803 main.log.error( "ONOS" + str( i + 1 ) +
2804 " expected a size of " + str( size ) +
2805 " for set " + onosSetName +
2806 " but got " + str( sizeResponses[ i ] ) )
2807 addAllResults = addAllResults and getResults and sizeResults
2808 utilities.assert_equals( expect=main.TRUE,
2809 actual=addAllResults,
2810 onpass="Set addAll correct",
2811 onfail="Set addAll was incorrect" )
2812
2813 main.step( "Distributed Set retain()" )
2814 onosSet.intersection_update( retainValue.split() )
2815 retainResponses = []
2816 threads = []
2817 for i in range( numControllers ):
2818 t = main.Thread( target=CLIs[i].setTestRemove,
2819 name="setTestRetain-" + str( i ),
2820 args=[ onosSetName, retainValue ],
2821 kwargs={ "retain": True } )
2822 threads.append( t )
2823 t.start()
2824 for t in threads:
2825 t.join()
2826 retainResponses.append( t.result )
2827
2828 # main.TRUE = successfully changed the set
2829 # main.FALSE = action resulted in no change in set
2830 # main.ERROR - Some error in executing the function
2831 retainResults = main.TRUE
2832 for i in range( numControllers ):
2833 if retainResponses[ i ] == main.TRUE:
2834 # All is well
2835 pass
2836 elif retainResponses[ i ] == main.FALSE:
2837 # Already in set, probably fine
2838 pass
2839 elif retainResponses[ i ] == main.ERROR:
2840 # Error in execution
2841 retainResults = main.FALSE
2842 else:
2843 # unexpected result
2844 retainResults = main.FALSE
2845 if retainResults != main.TRUE:
2846 main.log.error( "Error executing set retain" )
2847
2848 # Check if set is still correct
2849 size = len( onosSet )
2850 getResponses = []
2851 threads = []
2852 for i in range( numControllers ):
2853 t = main.Thread( target=CLIs[i].setTestGet,
2854 name="setTestGet-" + str( i ),
2855 args=[ onosSetName ] )
2856 threads.append( t )
2857 t.start()
2858 for t in threads:
2859 t.join()
2860 getResponses.append( t.result )
2861 getResults = main.TRUE
2862 for i in range( numControllers ):
2863 if isinstance( getResponses[ i ], list):
2864 current = set( getResponses[ i ] )
2865 if len( current ) == len( getResponses[ i ] ):
2866 # no repeats
2867 if onosSet != current:
2868 main.log.error( "ONOS" + str( i + 1 ) +
2869 " has incorrect view" +
2870 " of set " + onosSetName + ":\n" +
2871 str( getResponses[ i ] ) )
2872 main.log.debug( "Expected: " + str( onosSet ) )
2873 main.log.debug( "Actual: " + str( current ) )
2874 getResults = main.FALSE
2875 else:
2876 # error, set is not a set
2877 main.log.error( "ONOS" + str( i + 1 ) +
2878 " has repeat elements in" +
2879 " set " + onosSetName + ":\n" +
2880 str( getResponses[ i ] ) )
2881 getResults = main.FALSE
2882 elif getResponses[ i ] == main.ERROR:
2883 getResults = main.FALSE
2884 sizeResponses = []
2885 threads = []
2886 for i in range( numControllers ):
2887 t = main.Thread( target=CLIs[i].setTestSize,
2888 name="setTestSize-" + str( i ),
2889 args=[ onosSetName ] )
2890 threads.append( t )
2891 t.start()
2892 for t in threads:
2893 t.join()
2894 sizeResponses.append( t.result )
2895 sizeResults = main.TRUE
2896 for i in range( numControllers ):
2897 if size != sizeResponses[ i ]:
2898 sizeResults = main.FALSE
2899 main.log.error( "ONOS" + str( i + 1 ) +
2900 " expected a size of " +
2901 str( size ) + " for set " + onosSetName +
2902 " but got " + str( sizeResponses[ i ] ) )
2903 retainResults = retainResults and getResults and sizeResults
2904 utilities.assert_equals( expect=main.TRUE,
2905 actual=retainResults,
2906 onpass="Set retain correct",
2907 onfail="Set retain was incorrect" )
2908