blob: 0f68a023c1bfaba53dd45c7ee59cc966040a8e70 [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
Jon Hall390696c2015-05-05 17:13:41 -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
Jon Hall58c76b72015-02-23 11:09:24 -080039 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
Jon Hall58c76b72015-02-23 11:09:24 -080046 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" )
52 # TODO: save all the timers and output them for plotting
Jon Hall73cf9cc2014-11-20 22:28:38 -080053
Jon Hall5cfd23c2015-03-19 11:40:57 -070054 # load some variables from the params file
Jon Hall8f89dda2015-01-22 16:03:33 -080055 PULLCODE = False
Jon Hall6aec96b2015-01-19 14:49:31 -080056 if main.params[ 'Git' ] == 'True':
Jon Hall8f89dda2015-01-22 16:03:33 -080057 PULLCODE = True
Jon Hall529a37f2015-01-28 10:02:00 -080058 gitBranch = main.params[ 'branch' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080059 cellName = main.params[ 'ENV' ][ 'cellName' ]
Jon Hall6aec96b2015-01-19 14:49:31 -080060
61 # set global variables
Jon Hall8f89dda2015-01-22 16:03:33 -080062 global ONOS1Ip
63 global ONOS1Port
Jon Hall8f89dda2015-01-22 16:03:33 -080064 global ONOS2Port
Jon Hall8f89dda2015-01-22 16:03:33 -080065 global ONOS3Port
Jon Hall8f89dda2015-01-22 16:03:33 -080066 global ONOS4Port
Jon Hall8f89dda2015-01-22 16:03:33 -080067 global ONOS5Port
Jon Hall8f89dda2015-01-22 16:03:33 -080068 global ONOS6Port
Jon Hall8f89dda2015-01-22 16:03:33 -080069 global ONOS7Port
70 global numControllers
Jon Hall5cfd23c2015-03-19 11:40:57 -070071 numControllers = int( main.params[ 'num_controllers' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -080072
Jon Hall8f89dda2015-01-22 16:03:33 -080073 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
74 ONOS1Port = main.params[ 'CTRL' ][ 'port1' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080075 ONOS2Port = main.params[ 'CTRL' ][ 'port2' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080076 ONOS3Port = main.params[ 'CTRL' ][ 'port3' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080077 ONOS4Port = main.params[ 'CTRL' ][ 'port4' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080078 ONOS5Port = main.params[ 'CTRL' ][ 'port5' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080079 ONOS6Port = main.params[ 'CTRL' ][ 'port6' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080080 ONOS7Port = main.params[ 'CTRL' ][ 'port7' ]
Jon Hall73cf9cc2014-11-20 22:28:38 -080081
Jon Halla9d26da2015-03-30 16:45:32 -070082 global CLIs
83 CLIs = []
84 global nodes
85 nodes = []
86 for i in range( 1, numControllers + 1 ):
87 CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
88 nodes.append( getattr( main, 'ONOS' + str( i ) ) )
89
Jon Hall6aec96b2015-01-19 14:49:31 -080090 main.step( "Applying cell variable to environment" )
Jon Hall8f89dda2015-01-22 16:03:33 -080091 cellResult = main.ONOSbench.setCell( cellName )
92 verifyResult = main.ONOSbench.verifyCell()
Jon Hall73cf9cc2014-11-20 22:28:38 -080093
Jon Hall6aec96b2015-01-19 14:49:31 -080094 # FIXME:this is short term fix
95 main.log.report( "Removing raft logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -080096 main.ONOSbench.onosRemoveRaftLogs()
Jon Halla9d26da2015-03-30 16:45:32 -070097
Jon Hall6aec96b2015-01-19 14:49:31 -080098 main.log.report( "Uninstalling ONOS" )
Jon Halla9d26da2015-03-30 16:45:32 -070099 for node in nodes:
100 main.ONOSbench.onosUninstall( node.ip_address )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800101
Jon Hall390696c2015-05-05 17:13:41 -0700102 # Make sure ONOS is DEAD
103 main.log.report( "Killing any ONOS processes" )
104 killResults = main.TRUE
105 for node in nodes:
106 killed = main.ONOSbench.onosKill( node.ip_address )
107 killResults = killResults and killed
108
Jon Hall8f89dda2015-01-22 16:03:33 -0800109 cleanInstallResult = main.TRUE
110 gitPullResult = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800111
Jon Hall97f31752015-02-04 12:01:04 -0800112 main.step( "Starting Mininet" )
Jon Hall390696c2015-05-05 17:13:41 -0700113 mnResult = main.Mininet1.startNet( )
114 utilities.assert_equals( expect=main.TRUE, actual=mnResult,
115 onpass="Mininet Started",
116 onfail="Error starting Mininet" )
Jon Hall97f31752015-02-04 12:01:04 -0800117
Jon Hall6aec96b2015-01-19 14:49:31 -0800118 main.step( "Compiling the latest version of ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800119 if PULLCODE:
Jon Hall58c76b72015-02-23 11:09:24 -0800120 main.step( "Git checkout and pull " + gitBranch )
Jon Hall529a37f2015-01-28 10:02:00 -0800121 main.ONOSbench.gitCheckout( gitBranch )
Jon Hall8f89dda2015-01-22 16:03:33 -0800122 gitPullResult = main.ONOSbench.gitPull()
Jon Hall390696c2015-05-05 17:13:41 -0700123 # values of 1 or 3 are good
124 utilities.assert_lesser( expect=0, actual=gitPullResult,
125 onpass="Git pull successful",
126 onfail="Git pull failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800127
Jon Hall390696c2015-05-05 17:13:41 -0700128 main.step( "Using mvn clean and install" )
Jon Hall529a37f2015-01-28 10:02:00 -0800129 cleanInstallResult = main.ONOSbench.cleanInstall()
Jon Hall390696c2015-05-05 17:13:41 -0700130 utilities.assert_equals( expect=main.TRUE,
131 actual=cleanInstallResult,
132 onpass="MCI successful",
133 onfail="MCI failed" )
Jon Hall529a37f2015-01-28 10:02:00 -0800134 else:
135 main.log.warn( "Did not pull new code so skipping mvn " +
136 "clean install" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800137 main.ONOSbench.getVersion( report=True )
Jon Hall390696c2015-05-05 17:13:41 -0700138 # GRAPHS
139 # NOTE: important params here:
140 # job = name of Jenkins job
141 # Plot Name = Plot-HA, only can be used if multiple plots
142 # index = The number of the graph under plot name
143 job = "HASingleInstanceRestart"
144 graphs = '<ac:structured-macro ac:name="html">\n'
145 graphs += '<ac:plain-text-body><![CDATA[\n'
146 graphs += '<iframe src="https://onos-jenkins.onlab.us/job/' + job +\
147 '/plot/getPlot?index=0&width=500&height=300"' +\
148 'noborder="0" width="500" height="300" scrolling="yes" ' +\
149 'seamless="seamless"></iframe>\n'
150 graphs += ']]></ac:plain-text-body>\n'
151 graphs += '</ac:structured-macro>\n'
152 main.log.wiki(graphs)
Jon Hall73cf9cc2014-11-20 22:28:38 -0800153
Jon Hall8f89dda2015-01-22 16:03:33 -0800154 cellResult = main.ONOSbench.setCell( "SingleHA" )
155 verifyResult = main.ONOSbench.verifyCell()
Jon Hall6aec96b2015-01-19 14:49:31 -0800156 main.step( "Creating ONOS package" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800157 packageResult = main.ONOSbench.onosPackage()
Jon Hall390696c2015-05-05 17:13:41 -0700158 utilities.assert_equals( expect=main.TRUE, actual=packageResult,
159 onpass="ONOS package successful",
160 onfail="ONOS package failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800161
Jon Hall6aec96b2015-01-19 14:49:31 -0800162 main.step( "Installing ONOS package" )
Jon Hall390696c2015-05-05 17:13:41 -0700163 onosInstallResult = main.ONOSbench.onosInstall( options="-f",
Jon Hall8f89dda2015-01-22 16:03:33 -0800164 node=ONOS1Ip )
Jon Hall390696c2015-05-05 17:13:41 -0700165 utilities.assert_equals( expect=main.TRUE, actual=onosInstallResult,
166 onpass="ONOS install successful",
167 onfail="ONOS install failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800168
Jon Hall6aec96b2015-01-19 14:49:31 -0800169 main.step( "Checking if ONOS is up yet" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800170 for i in range( 2 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800171 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
172 if onos1Isup:
Jon Hall94fd0472014-12-08 11:52:42 -0800173 break
Jon Hall8f89dda2015-01-22 16:03:33 -0800174 if not onos1Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800175 main.log.report( "ONOS1 didn't start!" )
Jon Hall390696c2015-05-05 17:13:41 -0700176 utilities.assert_equals( expect=main.TRUE, actual=onos1Isup,
177 onpass="ONOS startup successful",
178 onfail="ONOS startup failed" )
Jon Hall94fd0472014-12-08 11:52:42 -0800179
Jon Hall390696c2015-05-05 17:13:41 -0700180 main.log.step( "Starting ONOS CLI sessions" )
181 cliResults = main.ONOScli1.startOnosCli( ONOS1Ip )
182 utilities.assert_equals( expect=main.TRUE, actual=cliResults,
183 onpass="ONOS cli startup successful",
184 onfail="ONOS cli startup failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800185
Jon Hall6aec96b2015-01-19 14:49:31 -0800186 main.step( "Start Packet Capture MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800187 main.Mininet2.startTcpdump(
Jon Hall6aec96b2015-01-19 14:49:31 -0800188 str( main.params[ 'MNtcpdump' ][ 'folder' ] ) + str( main.TEST )
189 + "-MN.pcap",
190 intf=main.params[ 'MNtcpdump' ][ 'intf' ],
191 port=main.params[ 'MNtcpdump' ][ 'port' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800192
Jon Hall390696c2015-05-05 17:13:41 -0700193 main.step( "App Ids check" )
194 appCheck = main.TRUE
195 threads = []
196 for i in range( numControllers ):
197 t = main.Thread( target=CLIs[i].appToIDCheck,
198 name="appToIDCheck-" + str( i ),
199 args=[] )
200 threads.append( t )
201 t.start()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800202
Jon Hall390696c2015-05-05 17:13:41 -0700203 for t in threads:
204 t.join()
205 appCheck = appCheck and t.result
206 if appCheck != main.TRUE:
207 main.log.warn( CLIs[0].apps() )
208 main.log.warn( CLIs[0].appIDs() )
209 utilities.assert_equals( expect=main.TRUE, actual=appCheck,
210 onpass="App Ids seem to be correct",
211 onfail="Something is wrong with app Ids" )
212
213 case1Result = ( cleanInstallResult and packageResult and
214 cellResult and verifyResult and onosInstallResult
215 and onos1Isup and cliResults )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800216
Jon Hall8f89dda2015-01-22 16:03:33 -0800217 if case1Result == main.FALSE:
Jon Hall73cf9cc2014-11-20 22:28:38 -0800218 main.cleanup()
219 main.exit()
220
Jon Hall6aec96b2015-01-19 14:49:31 -0800221 def CASE2( self, main ):
222 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800223 Assign mastership to controllers
Jon Hall6aec96b2015-01-19 14:49:31 -0800224 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800225 import re
Jon Hall5cfd23c2015-03-19 11:40:57 -0700226 assert numControllers, "numControllers not defined"
227 assert main, "main not defined"
228 assert utilities.assert_equals, "utilities.assert_equals not defined"
229 assert ONOS1Port, "ONOS1Port not defined"
230 assert ONOS2Port, "ONOS2Port not defined"
231 assert ONOS3Port, "ONOS3Port not defined"
232 assert ONOS4Port, "ONOS4Port not defined"
233 assert ONOS5Port, "ONOS5Port not defined"
234 assert ONOS6Port, "ONOS6Port not defined"
235 assert ONOS7Port, "ONOS7Port not defined"
Jon Hall73cf9cc2014-11-20 22:28:38 -0800236
Jon Hall6aec96b2015-01-19 14:49:31 -0800237 main.log.report( "Assigning switches to controllers" )
238 main.case( "Assigning Controllers" )
239 main.step( "Assign switches to controllers" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800240
Jon Hall6aec96b2015-01-19 14:49:31 -0800241 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800242 main.Mininet1.assignSwController(
Jon Hall6aec96b2015-01-19 14:49:31 -0800243 sw=str( i ),
Jon Hall8f89dda2015-01-22 16:03:33 -0800244 ip1=ONOS1Ip, port1=ONOS1Port )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800245
Jon Hall8f89dda2015-01-22 16:03:33 -0800246 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800247 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800248 response = main.Mininet1.getSwController( "s" + str( i ) )
Jon Hallffb386d2014-11-21 13:43:38 -0800249 try:
Jon Hall6aec96b2015-01-19 14:49:31 -0800250 main.log.info( str( response ) )
Jon Hallfebb1c72015-03-05 13:30:09 -0800251 except Exception:
Jon Hall6aec96b2015-01-19 14:49:31 -0800252 main.log.info( repr( response ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800253 if re.search( "tcp:" + ONOS1Ip, response ):
254 mastershipCheck = mastershipCheck and main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800255 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800256 mastershipCheck = main.FALSE
257 if mastershipCheck == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800258 main.log.report( "Switch mastership assigned correctly" )
259 utilities.assert_equals(
260 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800261 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800262 onpass="Switch mastership assigned correctly",
263 onfail="Switches not assigned correctly to controllers" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800264
Jon Hall390696c2015-05-05 17:13:41 -0700265 main.step( "Assign mastership of switches to specific controllers" )
Jon Halla9d26da2015-03-30 16:45:32 -0700266 roleCall = main.TRUE
267 roleCheck = main.TRUE
268 try:
269 for i in range( 1, 29 ): # switches 1 through 28
270 ip = nodes[ 0 ].ip_address # ONOS1
271 # set up correct variables:
272 if i == 1:
273 deviceId = main.ONOScli1.getDevice( "1000" ).get( 'id' )
274 elif i == 2:
275 deviceId = main.ONOScli1.getDevice( "2000" ).get( 'id' )
276 elif i == 3:
277 deviceId = main.ONOScli1.getDevice( "3000" ).get( 'id' )
278 elif i == 4:
279 deviceId = main.ONOScli1.getDevice( "3004" ).get( 'id' )
280 elif i == 5:
281 deviceId = main.ONOScli1.getDevice( "5000" ).get( 'id' )
282 elif i == 6:
283 deviceId = main.ONOScli1.getDevice( "6000" ).get( 'id' )
284 elif i == 7:
285 deviceId = main.ONOScli1.getDevice( "6007" ).get( 'id' )
286 elif i >= 8 and i <= 17:
287 dpid = '3' + str( i ).zfill( 3 )
288 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
289 elif i >= 18 and i <= 27:
290 dpid = '6' + str( i ).zfill( 3 )
291 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
292 elif i == 28:
293 deviceId = main.ONOScli1.getDevice( "2800" ).get( 'id' )
294 else:
295 main.log.error( "You didn't write an else statement for " +
296 "switch s" + str( i ) )
297 # Assign switch
298 assert deviceId, "No device id for s" + str( i ) + " in ONOS"
299 # TODO: make this controller dynamic
300 roleCall = roleCall and main.ONOScli1.deviceRole( deviceId,
301 ip )
302 # Check assignment
Jon Hall390696c2015-05-05 17:13:41 -0700303 master = main.ONOScli1.getRole( deviceId ).get( 'master' )
Jon Hall678f4512015-03-31 09:48:31 -0700304 if ip in master:
Jon Halla9d26da2015-03-30 16:45:32 -0700305 roleCheck = roleCheck and main.TRUE
306 else:
307 roleCheck = roleCheck and main.FALSE
308 main.log.error( "Error, controller " + ip + " is not" +
309 " master " + "of device " +
Jon Hall678f4512015-03-31 09:48:31 -0700310 str( deviceId ) + ". Master is " +
311 repr( master ) + "." )
Jon Halla9d26da2015-03-30 16:45:32 -0700312 except ( AttributeError, AssertionError ):
313 main.log.exception( "Something is wrong with ONOS device view" )
314 main.log.info( main.ONOScli1.devices() )
315 utilities.assert_equals(
316 expect=main.TRUE,
317 actual=roleCall,
318 onpass="Re-assigned switch mastership to designated controller",
319 onfail="Something wrong with deviceRole calls" )
320
Jon Hall390696c2015-05-05 17:13:41 -0700321 main.step( "Check mastership was correctly assigned" )
Jon Halla9d26da2015-03-30 16:45:32 -0700322 utilities.assert_equals(
323 expect=main.TRUE,
324 actual=roleCheck,
325 onpass="Switches were successfully reassigned to designated " +
326 "controller",
327 onfail="Switches were not successfully reassigned" )
328 mastershipCheck = mastershipCheck and roleCall and roleCheck
329 utilities.assert_equals( expect=main.TRUE, actual=mastershipCheck,
330 onpass="Switch mastership correctly assigned",
331 onfail="Error in (re)assigning switch" +
332 " mastership" )
333
Jon Hall6aec96b2015-01-19 14:49:31 -0800334 def CASE3( self, main ):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800335 """
336 Assign intents
Jon Hall73cf9cc2014-11-20 22:28:38 -0800337 """
338 import time
Jon Hallfebb1c72015-03-05 13:30:09 -0800339 import json
Jon Hall5cfd23c2015-03-19 11:40:57 -0700340 assert numControllers, "numControllers not defined"
341 assert main, "main not defined"
342 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall73cf9cc2014-11-20 22:28:38 -0800343 # FIXME: we must reinstall intents until we have a persistant
344 # datastore!
Jon Hall6aec96b2015-01-19 14:49:31 -0800345 main.log.report( "Adding host intents" )
346 main.case( "Adding host Intents" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800347
Jon Hall390696c2015-05-05 17:13:41 -0700348 main.step( "Discovering Hosts( Via pingall for now )" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800349 # FIXME: Once we have a host discovery mechanism, use that instead
Jon Hall73cf9cc2014-11-20 22:28:38 -0800350
Jon Hall6aec96b2015-01-19 14:49:31 -0800351 # install onos-app-fwd
Jon Hall390696c2015-05-05 17:13:41 -0700352 main.step( "Install reactive forwarding app" )
353 installResults = CLIs[0].activateApp( "org.onosproject.fwd" )
354 utilities.assert_equals( expect=main.TRUE, actual=installResults,
355 onpass="Install fwd successful",
356 onfail="Install fwd failed" )
Jon Halla9d26da2015-03-30 16:45:32 -0700357
Jon Halla9d26da2015-03-30 16:45:32 -0700358 appCheck = main.ONOScli1.appToIDCheck()
359 if appCheck != main.TRUE:
360 main.log.warn( CLIs[0].apps() )
361 main.log.warn( CLIs[0].appIDs() )
Jon Hall390696c2015-05-05 17:13:41 -0700362 utilities.assert_equals( expect=main.TRUE, actual=appCheck,
363 onpass="App Ids seem to be correct",
364 onfail="Something is wrong with app Ids" )
Jon Hall94fd0472014-12-08 11:52:42 -0800365
Jon Hall6aec96b2015-01-19 14:49:31 -0800366 # REACTIVE FWD test
Jon Hall8f89dda2015-01-22 16:03:33 -0800367 pingResult = main.FALSE
Jon Hall5cfd23c2015-03-19 11:40:57 -0700368 for i in range(2): # Retry if pingall fails first time
369 time1 = time.time()
370 pingResult = main.Mininet1.pingall()
371 utilities.assert_equals(
372 expect=main.TRUE,
373 actual=pingResult,
374 onpass="Reactive Pingall test passed",
Jon Hall390696c2015-05-05 17:13:41 -0700375 onfail="Reactive Pingall failed, " +
376 "one or more ping pairs failed" )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700377 time2 = time.time()
Jon Hall390696c2015-05-05 17:13:41 -0700378 main.log.info( "Time for pingall: %2f seconds" %
379 ( time2 - time1 ) )
380 # timeout for fwd flows
381 time.sleep( 11 )
Jon Hall6aec96b2015-01-19 14:49:31 -0800382 # uninstall onos-app-fwd
Jon Hall390696c2015-05-05 17:13:41 -0700383 main.step( "Uninstall reactive forwarding app" )
384 uninstallResult = CLIs[0].deactivateApp( "org.onosproject.fwd" )
385 utilities.assert_equals( expect=main.TRUE, actual=uninstallResult,
386 onpass="Uninstall fwd successful",
387 onfail="Uninstall fwd failed" )
Jon Halla9d26da2015-03-30 16:45:32 -0700388 appCheck2 = main.ONOScli1.appToIDCheck()
389 if appCheck2 != main.TRUE:
390 main.log.warn( CLIs[0].apps() )
391 main.log.warn( CLIs[0].appIDs() )
Jon Hall390696c2015-05-05 17:13:41 -0700392 utilities.assert_equals( expect=main.TRUE, actual=appCheck2,
393 onpass="App Ids seem to be correct",
394 onfail="Something is wrong with app Ids" )
Jon Halla9d26da2015-03-30 16:45:32 -0700395
396 main.step( "Add host intents" )
Jon Hall58c76b72015-02-23 11:09:24 -0800397 intentIds = []
Jon Hall6aec96b2015-01-19 14:49:31 -0800398 # TODO: move the host numbers to params
Jon Hall58c76b72015-02-23 11:09:24 -0800399 # Maybe look at all the paths we ping?
Jon Hall8f89dda2015-01-22 16:03:33 -0800400 intentAddResult = True
Jon Hall58c76b72015-02-23 11:09:24 -0800401 hostResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800402 for i in range( 8, 18 ):
403 main.log.info( "Adding host intent between h" + str( i ) +
404 " and h" + str( i + 10 ) )
405 host1 = "00:00:00:00:00:" + \
406 str( hex( i )[ 2: ] ).zfill( 2 ).upper()
407 host2 = "00:00:00:00:00:" + \
408 str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper()
Jon Hall1b8f54a2015-02-04 13:24:20 -0800409 # NOTE: getHost can return None
410 host1Dict = main.ONOScli1.getHost( host1 )
411 host2Dict = main.ONOScli1.getHost( host2 )
412 host1Id = None
413 host2Id = None
414 if host1Dict and host2Dict:
415 host1Id = host1Dict.get( 'id', None )
416 host2Id = host2Dict.get( 'id', None )
Jon Hall8f89dda2015-01-22 16:03:33 -0800417 if host1Id and host2Id:
Jon Halla9d26da2015-03-30 16:45:32 -0700418 tmpId = main.ONOScli1.addHostIntent( host1Id, host2Id )
Jon Hall63604932015-02-26 17:09:50 -0800419 if tmpId:
420 main.log.info( "Added intent with id: " + tmpId )
421 intentIds.append( tmpId )
422 else:
Jon Halla9d26da2015-03-30 16:45:32 -0700423 main.log.error( "addHostIntent returned: " +
424 repr( tmpId ) )
Jon Hall669173b2014-12-17 11:36:30 -0800425 else:
Jon Halla9d26da2015-03-30 16:45:32 -0700426 main.log.error( "Error, getHost() failed for h" + str( i ) +
427 " and/or h" + str( i + 10 ) )
428 hosts = main.ONOScli1.hosts()
429 main.log.warn( "Hosts output: " )
430 try:
431 main.log.warn( json.dumps( json.loads( hosts ),
432 sort_keys=True,
433 indent=4,
434 separators=( ',', ': ' ) ) )
435 except ( ValueError, TypeError ):
436 main.log.warn( repr( hosts ) )
Jon Hall58c76b72015-02-23 11:09:24 -0800437 hostResult = main.FALSE
Jon Halla9d26da2015-03-30 16:45:32 -0700438 # FIXME: DEBUG
439 intentStart = time.time()
Jon Hall58c76b72015-02-23 11:09:24 -0800440 onosIds = main.ONOScli1.getAllIntentsId()
441 main.log.info( "Submitted intents: " + str( intentIds ) )
442 main.log.info( "Intents in ONOS: " + str( onosIds ) )
443 for intent in intentIds:
444 if intent in onosIds:
Jon Halla9d26da2015-03-30 16:45:32 -0700445 pass # intent submitted is in onos
Jon Hall58c76b72015-02-23 11:09:24 -0800446 else:
447 intentAddResult = False
Jon Halla9d26da2015-03-30 16:45:32 -0700448 # FIXME: DEBUG
449 if intentAddResult:
450 intentStop = time.time()
451 else:
452 intentStop = None
Jon Hall1b8f54a2015-02-04 13:24:20 -0800453 # Print the intent states
Jon Hall58c76b72015-02-23 11:09:24 -0800454 intents = main.ONOScli1.intents()
Jon Hall1b8f54a2015-02-04 13:24:20 -0800455 intentStates = []
Jon Halla9d26da2015-03-30 16:45:32 -0700456 installedCheck = True
Jon Hall58c76b72015-02-23 11:09:24 -0800457 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
458 count = 0
Jon Hall5cfd23c2015-03-19 11:40:57 -0700459 try:
460 for intent in json.loads( intents ):
461 state = intent.get( 'state', None )
462 if "INSTALLED" not in state:
463 installedCheck = False
464 intentId = intent.get( 'id', None )
465 intentStates.append( ( intentId, state ) )
466 except ( ValueError, TypeError ):
467 main.log.exception( "Error parsing intents" )
Jon Hall58c76b72015-02-23 11:09:24 -0800468 # add submitted intents not in the store
469 tmplist = [ i for i, s in intentStates ]
470 missingIntents = False
471 for i in intentIds:
472 if i not in tmplist:
473 intentStates.append( ( i, " - " ) )
474 missingIntents = True
475 intentStates.sort()
476 for i, s in intentStates:
477 count += 1
478 main.log.info( "%-6s%-15s%-15s" %
479 ( str( count ), str( i ), str( s ) ) )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700480 leaders = main.ONOScli1.leaders()
481 try:
482 if leaders:
483 parsedLeaders = json.loads( leaders )
484 main.log.warn( json.dumps( parsedLeaders,
485 sort_keys=True,
486 indent=4,
487 separators=( ',', ': ' ) ) )
488 # check for all intent partitions
Jon Hall5cfd23c2015-03-19 11:40:57 -0700489 topics = []
490 for i in range( 14 ):
491 topics.append( "intent-partition-" + str( i ) )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700492 main.log.debug( topics )
493 ONOStopics = [ j['topic'] for j in parsedLeaders ]
494 for topic in topics:
495 if topic not in ONOStopics:
496 main.log.error( "Error: " + topic +
497 " not in leaders" )
498 else:
499 main.log.error( "leaders() returned None" )
500 except ( ValueError, TypeError ):
501 main.log.exception( "Error parsing leaders" )
502 main.log.error( repr( leaders ) )
503 partitions = main.ONOScli1.partitions()
504 try:
505 if partitions :
506 parsedPartitions = json.loads( partitions )
507 main.log.warn( json.dumps( parsedPartitions,
508 sort_keys=True,
509 indent=4,
510 separators=( ',', ': ' ) ) )
511 # TODO check for a leader in all paritions
512 # TODO check for consistency among nodes
513 else:
514 main.log.error( "partitions() returned None" )
515 except ( ValueError, TypeError ):
516 main.log.exception( "Error parsing partitions" )
517 main.log.error( repr( partitions ) )
Jon Hall63604932015-02-26 17:09:50 -0800518 pendingMap = main.ONOScli1.pendingMap()
Jon Hall5cfd23c2015-03-19 11:40:57 -0700519 try:
520 if pendingMap :
521 parsedPending = json.loads( pendingMap )
522 main.log.warn( json.dumps( parsedPending,
523 sort_keys=True,
524 indent=4,
525 separators=( ',', ': ' ) ) )
526 # TODO check something here?
527 else:
528 main.log.error( "pendingMap() returned None" )
529 except ( ValueError, TypeError ):
530 main.log.exception( "Error parsing pending map" )
531 main.log.error( repr( pendingMap ) )
532
Jon Hall58c76b72015-02-23 11:09:24 -0800533 intentAddResult = bool( pingResult and hostResult and intentAddResult
Jon Hall63604932015-02-26 17:09:50 -0800534 and not missingIntents and installedCheck )
Jon Hall6aec96b2015-01-19 14:49:31 -0800535 utilities.assert_equals(
536 expect=True,
Jon Hall8f89dda2015-01-22 16:03:33 -0800537 actual=intentAddResult,
Jon Hall529a37f2015-01-28 10:02:00 -0800538 onpass="Pushed host intents to ONOS",
539 onfail="Error in pushing host intents to ONOS" )
Jon Hall390696c2015-05-05 17:13:41 -0700540 main.step( "Intent Anti-Entropy dispersion" )
541 for i in range(100):
542 correct = True
543 main.log.info( "Submitted intents: " + str( sorted( intentIds ) ) )
544 for cli in CLIs:
545 onosIds = []
546 ids = cli.getAllIntentsId()
547 onosIds.append( ids )
548 main.log.debug( "Intents in " + cli.name + ": " +
549 str( sorted( onosIds ) ) )
550 if sorted( ids ) != sorted( intentIds ):
551 correct = False
552 if correct:
553 break
554 else:
555 time.sleep(1)
556 if not intentStop:
557 intentStop = time.time()
558 global gossipTime
559 gossipTime = intentStop - intentStart
560 main.log.info( "It took about " + str( gossipTime ) +
561 " seconds for all intents to appear in each node" )
562 # FIXME: make this time configurable/calculate based off of number of
563 # nodes and gossip rounds
564 utilities.assert_greater_equals(
565 expect=40, actual=gossipTime,
566 onpass="ECM anti-entropy for intents worked within " +
567 "expected time",
568 onfail="Intent ECM anti-entropy took too long" )
569 if gossipTime <= 40:
570 intentAddResult = True
Jon Hall58c76b72015-02-23 11:09:24 -0800571
Jon Hall63604932015-02-26 17:09:50 -0800572 if not intentAddResult or "key" in pendingMap:
Jon Hall58c76b72015-02-23 11:09:24 -0800573 import time
Jon Hall63604932015-02-26 17:09:50 -0800574 installedCheck = True
Jon Hall58c76b72015-02-23 11:09:24 -0800575 main.log.info( "Sleeping 60 seconds to see if intents are found" )
576 time.sleep( 60 )
577 onosIds = main.ONOScli1.getAllIntentsId()
578 main.log.info( "Submitted intents: " + str( intentIds ) )
579 main.log.info( "Intents in ONOS: " + str( onosIds ) )
580 # Print the intent states
581 intents = main.ONOScli1.intents()
582 intentStates = []
583 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
584 count = 0
Jon Hall5cfd23c2015-03-19 11:40:57 -0700585 try:
586 for intent in json.loads( intents ):
587 # Iter through intents of a node
588 state = intent.get( 'state', None )
589 if "INSTALLED" not in state:
590 installedCheck = False
591 intentId = intent.get( 'id', None )
592 intentStates.append( ( intentId, state ) )
593 except ( ValueError, TypeError ):
594 main.log.exception( "Error parsing intents" )
Jon Hall58c76b72015-02-23 11:09:24 -0800595 # add submitted intents not in the store
596 tmplist = [ i for i, s in intentStates ]
597 for i in intentIds:
598 if i not in tmplist:
599 intentStates.append( ( i, " - " ) )
600 intentStates.sort()
601 for i, s in intentStates:
602 count += 1
603 main.log.info( "%-6s%-15s%-15s" %
604 ( str( count ), str( i ), str( s ) ) )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700605 leaders = main.ONOScli1.leaders()
606 try:
607 if leaders:
608 parsedLeaders = json.loads( leaders )
609 main.log.warn( json.dumps( parsedLeaders,
610 sort_keys=True,
611 indent=4,
612 separators=( ',', ': ' ) ) )
613 # check for all intent partitions
614 # check for election
615 topics = []
616 for i in range( 14 ):
617 topics.append( "intent-partition-" + str( i ) )
618 # FIXME: this should only be after we start the app
619 topics.append( "org.onosproject.election" )
620 main.log.debug( topics )
621 ONOStopics = [ j['topic'] for j in parsedLeaders ]
622 for topic in topics:
623 if topic not in ONOStopics:
624 main.log.error( "Error: " + topic +
625 " not in leaders" )
626 else:
627 main.log.error( "leaders() returned None" )
628 except ( ValueError, TypeError ):
629 main.log.exception( "Error parsing leaders" )
630 main.log.error( repr( leaders ) )
631 partitions = main.ONOScli1.partitions()
632 try:
633 if partitions :
634 parsedPartitions = json.loads( partitions )
635 main.log.warn( json.dumps( parsedPartitions,
636 sort_keys=True,
637 indent=4,
638 separators=( ',', ': ' ) ) )
639 # TODO check for a leader in all paritions
640 # TODO check for consistency among nodes
641 else:
642 main.log.error( "partitions() returned None" )
643 except ( ValueError, TypeError ):
644 main.log.exception( "Error parsing partitions" )
645 main.log.error( repr( partitions ) )
646 pendingMap = main.ONOScli1.pendingMap()
647 try:
648 if pendingMap :
649 parsedPending = json.loads( pendingMap )
650 main.log.warn( json.dumps( parsedPending,
651 sort_keys=True,
652 indent=4,
653 separators=( ',', ': ' ) ) )
654 # TODO check something here?
655 else:
656 main.log.error( "pendingMap() returned None" )
657 except ( ValueError, TypeError ):
658 main.log.exception( "Error parsing pending map" )
659 main.log.error( repr( pendingMap ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800660
Jon Hall6aec96b2015-01-19 14:49:31 -0800661 def CASE4( self, main ):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800662 """
663 Ping across added host intents
664 """
Jon Hallfebb1c72015-03-05 13:30:09 -0800665 import json
Jon Halla9d26da2015-03-30 16:45:32 -0700666 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -0700667 assert numControllers, "numControllers not defined"
668 assert main, "main not defined"
669 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall73cf9cc2014-11-20 22:28:38 -0800670 description = " Ping across added host intents"
Jon Hall6aec96b2015-01-19 14:49:31 -0800671 main.log.report( description )
672 main.case( description )
Jon Hall8f89dda2015-01-22 16:03:33 -0800673 PingResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800674 for i in range( 8, 18 ):
Jon Hall58c76b72015-02-23 11:09:24 -0800675 ping = main.Mininet1.pingHost( src="h" + str( i ),
676 target="h" + str( i + 10 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800677 PingResult = PingResult and ping
Jon Hall6aec96b2015-01-19 14:49:31 -0800678 if ping == main.FALSE:
679 main.log.warn( "Ping failed between h" + str( i ) +
680 " and h" + str( i + 10 ) )
681 elif ping == main.TRUE:
682 main.log.info( "Ping test passed!" )
Jon Hall21270ac2015-02-16 17:59:55 -0800683 # Don't set PingResult or you'd override failures
Jon Hall8f89dda2015-01-22 16:03:33 -0800684 if PingResult == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800685 main.log.report(
686 "Intents have not been installed correctly, pings failed." )
Jon Hall58c76b72015-02-23 11:09:24 -0800687 # TODO: pretty print
Jon Hall5cfd23c2015-03-19 11:40:57 -0700688 main.log.warn( "ONOS1 intents: " )
689 try:
690 tmpIntents = main.ONOScli1.intents()
691 main.log.warn( json.dumps( json.loads( tmpIntents ),
692 sort_keys=True,
693 indent=4,
694 separators=( ',', ': ' ) ) )
695 except ( ValueError, TypeError ):
696 main.log.warn( repr( tmpIntents ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800697 if PingResult == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800698 main.log.report(
699 "Intents have been installed correctly and verified by pings" )
700 utilities.assert_equals(
701 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800702 actual=PingResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800703 onpass="Intents have been installed correctly and pings work",
704 onfail="Intents have not been installed correctly, pings failed." )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800705
Jon Hall63604932015-02-26 17:09:50 -0800706 installedCheck = True
Jon Hall58c76b72015-02-23 11:09:24 -0800707 if PingResult is not main.TRUE:
708 # Print the intent states
709 intents = main.ONOScli1.intents()
710 intentStates = []
711 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
712 count = 0
713 # Iter through intents of a node
Jon Hall5cfd23c2015-03-19 11:40:57 -0700714 try:
715 for intent in json.loads( intents ):
716 state = intent.get( 'state', None )
717 if "INSTALLED" not in state:
718 installedCheck = False
719 intentId = intent.get( 'id', None )
720 intentStates.append( ( intentId, state ) )
721 except ( ValueError, TypeError ):
722 main.log.exception( "Error parsing intents." )
Jon Hall58c76b72015-02-23 11:09:24 -0800723 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 ) ) )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700728 leaders = main.ONOScli1.leaders()
729 try:
730 if leaders:
731 parsedLeaders = json.loads( leaders )
732 main.log.warn( json.dumps( parsedLeaders,
733 sort_keys=True,
734 indent=4,
735 separators=( ',', ': ' ) ) )
736 # check for all intent partitions
737 # check for election
738 topics = []
739 for i in range( 14 ):
740 topics.append( "intent-partition-" + str( i ) )
741 # FIXME: this should only be after we start the app
742 topics.append( "org.onosproject.election" )
743 main.log.debug( topics )
744 ONOStopics = [ j['topic'] for j in parsedLeaders ]
745 for topic in topics:
746 if topic not in ONOStopics:
747 main.log.error( "Error: " + topic +
748 " not in leaders" )
749 else:
750 main.log.error( "leaders() returned None" )
751 except ( ValueError, TypeError ):
752 main.log.exception( "Error parsing leaders" )
753 main.log.error( repr( leaders ) )
754 partitions = main.ONOScli1.partitions()
755 try:
756 if partitions :
757 parsedPartitions = json.loads( partitions )
758 main.log.warn( json.dumps( parsedPartitions,
759 sort_keys=True,
760 indent=4,
761 separators=( ',', ': ' ) ) )
762 # TODO check for a leader in all paritions
763 # TODO check for consistency among nodes
764 else:
765 main.log.error( "partitions() returned None" )
766 except ( ValueError, TypeError ):
767 main.log.exception( "Error parsing partitions" )
768 main.log.error( repr( partitions ) )
769 pendingMap = main.ONOScli1.pendingMap()
770 try:
771 if pendingMap :
772 parsedPending = json.loads( pendingMap )
773 main.log.warn( json.dumps( parsedPending,
774 sort_keys=True,
775 indent=4,
776 separators=( ',', ': ' ) ) )
777 # TODO check something here?
778 else:
779 main.log.error( "pendingMap() returned None" )
780 except ( ValueError, TypeError ):
781 main.log.exception( "Error parsing pending map" )
782 main.log.error( repr( pendingMap ) )
783
Jon Hall63604932015-02-26 17:09:50 -0800784 if not installedCheck:
Jon Hall5cfd23c2015-03-19 11:40:57 -0700785 main.log.info( "Waiting 60 seconds to see if the state of " +
786 "intents change" )
Jon Hall63604932015-02-26 17:09:50 -0800787 time.sleep( 60 )
788 # Print the intent states
789 intents = main.ONOScli1.intents()
790 intentStates = []
791 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
792 count = 0
793 # Iter through intents of a node
Jon Hall5cfd23c2015-03-19 11:40:57 -0700794 try:
795 for intent in json.loads( intents ):
796 state = intent.get( 'state', None )
797 if "INSTALLED" not in state:
798 installedCheck = False
799 intentId = intent.get( 'id', None )
800 intentStates.append( ( intentId, state ) )
801 except ( ValueError, TypeError ):
802 main.log.exception( "Error parsing intents." )
Jon Hall63604932015-02-26 17:09:50 -0800803 intentStates.sort()
804 for i, s in intentStates:
805 count += 1
806 main.log.info( "%-6s%-15s%-15s" %
807 ( str( count ), str( i ), str( s ) ) )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700808 leaders = main.ONOScli1.leaders()
809 try:
810 if leaders:
811 parsedLeaders = json.loads( leaders )
812 main.log.warn( json.dumps( parsedLeaders,
813 sort_keys=True,
814 indent=4,
815 separators=( ',', ': ' ) ) )
816 # check for all intent partitions
817 # check for election
818 topics = []
819 for i in range( 14 ):
820 topics.append( "intent-partition-" + str( i ) )
821 # FIXME: this should only be after we start the app
822 topics.append( "org.onosproject.election" )
823 main.log.debug( topics )
824 ONOStopics = [ j['topic'] for j in parsedLeaders ]
825 for topic in topics:
826 if topic not in ONOStopics:
827 main.log.error( "Error: " + topic +
828 " not in leaders" )
829 else:
830 main.log.error( "leaders() returned None" )
831 except ( ValueError, TypeError ):
832 main.log.exception( "Error parsing leaders" )
833 main.log.error( repr( leaders ) )
834 partitions = main.ONOScli1.partitions()
835 try:
836 if partitions :
837 parsedPartitions = json.loads( partitions )
838 main.log.warn( json.dumps( parsedPartitions,
839 sort_keys=True,
840 indent=4,
841 separators=( ',', ': ' ) ) )
842 # TODO check for a leader in all paritions
843 # TODO check for consistency among nodes
844 else:
845 main.log.error( "partitions() returned None" )
846 except ( ValueError, TypeError ):
847 main.log.exception( "Error parsing partitions" )
848 main.log.error( repr( partitions ) )
849 pendingMap = main.ONOScli1.pendingMap()
850 try:
851 if pendingMap :
852 parsedPending = json.loads( pendingMap )
853 main.log.warn( json.dumps( parsedPending,
854 sort_keys=True,
855 indent=4,
856 separators=( ',', ': ' ) ) )
857 # TODO check something here?
858 else:
859 main.log.error( "pendingMap() returned None" )
860 except ( ValueError, TypeError ):
861 main.log.exception( "Error parsing pending map" )
862 main.log.error( repr( pendingMap ) )
Jon Hall390696c2015-05-05 17:13:41 -0700863 main.log.debug( main.ONOScli1.flows( jsonFormat=False ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800864
Jon Hall6aec96b2015-01-19 14:49:31 -0800865 def CASE5( self, main ):
866 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800867 Reading state of ONOS
Jon Hall6aec96b2015-01-19 14:49:31 -0800868 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800869 import json
Jon Hall5cfd23c2015-03-19 11:40:57 -0700870 assert numControllers, "numControllers not defined"
871 assert main, "main not defined"
872 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -0800873 # assumes that sts is already in you PYTHONPATH
874 from sts.topology.teston_topology import TestONTopology
Jon Hall73cf9cc2014-11-20 22:28:38 -0800875
Jon Hall6aec96b2015-01-19 14:49:31 -0800876 main.log.report( "Setting up and gathering data for current state" )
877 main.case( "Setting up and gathering data for current state" )
878 # The general idea for this test case is to pull the state of
879 # ( intents,flows, topology,... ) from each ONOS node
Jon Hall5cfd23c2015-03-19 11:40:57 -0700880 # We can then compare them with each other and also with past states
Jon Hall73cf9cc2014-11-20 22:28:38 -0800881
Jon Halla9d26da2015-03-30 16:45:32 -0700882 main.step( "Check that each switch has a master" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800883 global mastershipState
Jon Halla9d26da2015-03-30 16:45:32 -0700884 mastershipState = '[]'
Jon Hall94fd0472014-12-08 11:52:42 -0800885
Jon Hall6aec96b2015-01-19 14:49:31 -0800886 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -0800887 rolesNotNull = main.ONOScli1.rolesNotNull()
Jon Hall6aec96b2015-01-19 14:49:31 -0800888 utilities.assert_equals(
889 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800890 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -0800891 onpass="Each device has a master",
892 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -0800893
Jon Hall390696c2015-05-05 17:13:41 -0700894 main.step( "Get the Mastership of each switch" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800895 ONOS1Mastership = main.ONOScli1.roles()
Jon Hall6aec96b2015-01-19 14:49:31 -0800896 # TODO: Make this a meaningful check
Jon Hall8f89dda2015-01-22 16:03:33 -0800897 if "Error" in ONOS1Mastership or not ONOS1Mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -0800898 main.log.report( "Error in getting ONOS roles" )
899 main.log.warn(
900 "ONOS1 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800901 repr( ONOS1Mastership ) )
902 consistentMastership = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800903 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800904 mastershipState = ONOS1Mastership
905 consistentMastership = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800906
Jon Hall6aec96b2015-01-19 14:49:31 -0800907 main.step( "Get the intents from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800908 global intentState
909 intentState = []
910 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
911 intentCheck = main.FALSE
912 if "Error" in ONOS1Intents or not ONOS1Intents:
Jon Hall6aec96b2015-01-19 14:49:31 -0800913 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800914 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800915 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800916 intentCheck = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800917
Jon Hall6aec96b2015-01-19 14:49:31 -0800918 main.step( "Get the flows from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800919 global flowState
920 flowState = []
Jon Hall8f89dda2015-01-22 16:03:33 -0800921 flowCheck = main.FALSE
Jon Hall58c76b72015-02-23 11:09:24 -0800922 ONOS1Flows = main.ONOScli1.flows( jsonFormat=True )
Jon Hall8f89dda2015-01-22 16:03:33 -0800923 if "Error" in ONOS1Flows or not ONOS1Flows:
Jon Hall58c76b72015-02-23 11:09:24 -0800924 main.log.report( "Error in getting ONOS flows" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800925 main.log.warn( "ONOS1 flows repsponse: " + ONOS1Flows )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800926 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800927 # TODO: Do a better check, maybe compare flows on switches?
Jon Hall8f89dda2015-01-22 16:03:33 -0800928 flowState = ONOS1Flows
929 flowCheck = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800930
Jon Hall6aec96b2015-01-19 14:49:31 -0800931 main.step( "Get the OF Table entries" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800932 global flows
Jon Hall6aec96b2015-01-19 14:49:31 -0800933 flows = []
934 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800935 flows.append( main.Mininet2.getFlowTable( 1.3, "s" + str( i ) ) )
Jon Hall58c76b72015-02-23 11:09:24 -0800936 if flowCheck == main.FALSE:
937 for table in flows:
938 main.log.warn( table )
Jon Hall6aec96b2015-01-19 14:49:31 -0800939 # TODO: Compare switch flow tables with ONOS flow tables
Jon Hall73cf9cc2014-11-20 22:28:38 -0800940
Jon Hall6aec96b2015-01-19 14:49:31 -0800941 main.step( "Create TestONTopology object" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800942 ctrls = []
Jon Hall390696c2015-05-05 17:13:41 -0700943 temp = ( nodes[0], nodes[0].name, nodes[0].ip_address, 6633 )
Jon Hall6aec96b2015-01-19 14:49:31 -0800944 ctrls.append( temp )
Jon Hall390696c2015-05-05 17:13:41 -0700945 MNTopo = TestONTopology( main.Mininet1, ctrls )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800946
Jon Hall6aec96b2015-01-19 14:49:31 -0800947 main.step( "Collecting topology information from ONOS" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800948 devices = []
949 devices.append( main.ONOScli1.devices() )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800950 hosts = []
Jon Hall58c76b72015-02-23 11:09:24 -0800951 hosts.append( json.loads( main.ONOScli1.hosts() ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800952 ports = []
953 ports.append( main.ONOScli1.ports() )
954 links = []
955 links.append( main.ONOScli1.links() )
Jon Hall58c76b72015-02-23 11:09:24 -0800956 clusters = []
957 clusters.append( main.ONOScli1.clusters() )
Jon Hall390696c2015-05-05 17:13:41 -0700958
959 main.step( "Each host has an IP address" )
Jon Hall58c76b72015-02-23 11:09:24 -0800960 ipResult = main.TRUE
961 for controller in range( 0, len( hosts ) ):
962 controllerStr = str( controller + 1 )
963 for host in hosts[ controller ]:
964 if host is None or host.get( 'ips', [] ) == []:
965 main.log.error(
966 "DEBUG:Error with host ips on controller" +
967 controllerStr + ": " + str( host ) )
968 ipResult = main.FALSE
Jon Hall390696c2015-05-05 17:13:41 -0700969 utilities.assert_equals(
970 expect=main.TRUE,
971 actual=ipResult,
972 onpass="The ips of the hosts aren't empty",
973 onfail="The ip of at least one host is missing" )
Jon Hall58c76b72015-02-23 11:09:24 -0800974
975 # there should always only be one cluster
Jon Hall390696c2015-05-05 17:13:41 -0700976 main.step( "There is only one dataplane cluster" )
977 try:
978 numClusters = len( json.loads( clusters[ 0 ] ) )
979 except ( ValueError, TypeError ):
980 main.log.exception( "Error parsing clusters[0]: " +
981 repr( clusters[ 0 ] ) )
Jon Hall58c76b72015-02-23 11:09:24 -0800982 clusterResults = main.FALSE
983 if numClusters == 1:
984 clusterResults = main.TRUE
985 utilities.assert_equals(
986 expect=1,
987 actual=numClusters,
988 onpass="ONOS shows 1 SCC",
989 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800990
Jon Hall6aec96b2015-01-19 14:49:31 -0800991 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800992 devicesResults = main.TRUE
993 portsResults = main.TRUE
994 linksResults = main.TRUE
Jon Hall58c76b72015-02-23 11:09:24 -0800995 hostsResults = main.TRUE
Jon Hall8f89dda2015-01-22 16:03:33 -0800996 for controller in range( numControllers ):
997 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -0800998 if devices[ controller ] or "Error" not in devices[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -0800999 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -08001000 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001001 json.loads( devices[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001002 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001003 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001004 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001005 actual=currentDevicesResult,
1006 onpass="ONOS" + controllerStr +
1007 " Switches view is correct",
1008 onfail="ONOS" + controllerStr +
1009 " Switches view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001010
Jon Hall6aec96b2015-01-19 14:49:31 -08001011 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001012 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -08001013 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001014 json.loads( ports[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001015 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001016 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001017 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001018 actual=currentPortsResult,
1019 onpass="ONOS" + controllerStr +
1020 " ports view is correct",
1021 onfail="ONOS" + controllerStr +
1022 " ports view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001023
Jon Hall6aec96b2015-01-19 14:49:31 -08001024 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001025 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -08001026 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001027 json.loads( links[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001028 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001029 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001030 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001031 actual=currentLinksResult,
1032 onpass="ONOS" + controllerStr +
1033 " links view is correct",
1034 onfail="ONOS" + controllerStr +
1035 " links view is incorrect" )
1036
1037 if hosts[ controller ] or "Error" not in hosts[ controller ]:
1038 currentHostsResult = main.Mininet1.compareHosts(
1039 MNTopo, hosts[ controller ] )
1040 else:
1041 currentHostsResult = main.FALSE
1042 utilities.assert_equals( expect=main.TRUE,
1043 actual=currentHostsResult,
1044 onpass="ONOS" + controllerStr +
1045 " hosts exist in Mininet",
1046 onfail="ONOS" + controllerStr +
1047 " hosts don't match Mininet" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001048
Jon Hall8f89dda2015-01-22 16:03:33 -08001049 devicesResults = devicesResults and currentDevicesResult
1050 portsResults = portsResults and currentPortsResult
1051 linksResults = linksResults and currentLinksResult
Jon Hall58c76b72015-02-23 11:09:24 -08001052 hostsResults = hostsResults and currentHostsResult
Jon Hall73cf9cc2014-11-20 22:28:38 -08001053
Jon Hall58c76b72015-02-23 11:09:24 -08001054 topoResult = devicesResults and portsResults and linksResults\
1055 and clusterResults and ipResult and hostsResults
Jon Hall8f89dda2015-01-22 16:03:33 -08001056 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
Jon Hall58c76b72015-02-23 11:09:24 -08001057 onpass="Topology Check Test successful",
1058 onfail="Topology Check Test NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001059
Jon Hall6aec96b2015-01-19 14:49:31 -08001060 def CASE6( self, main ):
1061 """
Jon Hallffb386d2014-11-21 13:43:38 -08001062 The Failure case.
Jon Hall6aec96b2015-01-19 14:49:31 -08001063 """
Jon Hallffb386d2014-11-21 13:43:38 -08001064 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001065 assert numControllers, "numControllers not defined"
1066 assert main, "main not defined"
1067 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall73cf9cc2014-11-20 22:28:38 -08001068
Jon Hall390696c2015-05-05 17:13:41 -07001069 # Reset non-persistent variables
1070 try:
1071 iCounterValue = 0
1072 except NameError:
1073 main.log.error( "iCounterValue not defined, setting to 0" )
1074 iCounterValue = 0
1075
Jon Hall6aec96b2015-01-19 14:49:31 -08001076 main.log.report( "Restart ONOS node" )
1077 main.log.case( "Restart ONOS node" )
Jon Hall390696c2015-05-05 17:13:41 -07001078 main.step( "Killing ONOS processes" )
1079 killResult = main.ONOSbench.onosKill( ONOS1Ip )
Jon Hallffb386d2014-11-21 13:43:38 -08001080 start = time.time()
Jon Hall390696c2015-05-05 17:13:41 -07001081 utilities.assert_equals( expect=main.TRUE, actual=killResult,
1082 onpass="ONOS Killed",
1083 onfail="Error killing ONOS" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001084
Jon Hall6aec96b2015-01-19 14:49:31 -08001085 main.step( "Checking if ONOS is up yet" )
Jon Hallffb386d2014-11-21 13:43:38 -08001086 count = 0
Jon Hall94fd0472014-12-08 11:52:42 -08001087 while count < 10:
Jon Hall8f89dda2015-01-22 16:03:33 -08001088 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
1089 if onos1Isup == main.TRUE:
Jon Hallffb386d2014-11-21 13:43:38 -08001090 elapsed = time.time() - start
1091 break
1092 else:
1093 count = count + 1
Jon Hall390696c2015-05-05 17:13:41 -07001094 utilities.assert_equals( expect=main.TRUE, actual=onos1Isup,
1095 onpass="ONOS is back up",
1096 onfail="ONOS failed to start" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001097
Jon Hall390696c2015-05-05 17:13:41 -07001098 main.log.step( "Starting ONOS CLI sessions" )
1099 cliResults = main.ONOScli1.startOnosCli( ONOS1Ip )
1100 utilities.assert_equals( expect=main.TRUE, actual=cliResults,
1101 onpass="ONOS cli startup successful",
1102 onfail="ONOS cli startup failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001103
Jon Hallfebb1c72015-03-05 13:30:09 -08001104 if elapsed:
1105 main.log.info( "ESTIMATE: ONOS took %s seconds to restart" %
1106 str( elapsed ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001107 time.sleep( 5 )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001108
Jon Hall6aec96b2015-01-19 14:49:31 -08001109 def CASE7( self, main ):
1110 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001111 Check state after ONOS failure
Jon Hall6aec96b2015-01-19 14:49:31 -08001112 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001113 import json
Jon Hall5cfd23c2015-03-19 11:40:57 -07001114 assert numControllers, "numControllers not defined"
1115 assert main, "main not defined"
1116 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -08001117 main.case( "Running ONOS Constant State Tests" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001118
Jon Hall390696c2015-05-05 17:13:41 -07001119 main.step( "Check that each switch has a master" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001120 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -08001121 rolesNotNull = main.ONOScli1.rolesNotNull()
Jon Hall6aec96b2015-01-19 14:49:31 -08001122 utilities.assert_equals(
1123 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001124 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -08001125 onpass="Each device has a master",
1126 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -08001127
Jon Hall6aec96b2015-01-19 14:49:31 -08001128 main.step( "Check if switch roles are consistent across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001129 ONOS1Mastership = main.ONOScli1.roles()
Jon Hall6aec96b2015-01-19 14:49:31 -08001130 # FIXME: Refactor this whole case for single instance
Jon Hall8f89dda2015-01-22 16:03:33 -08001131 if "Error" in ONOS1Mastership or not ONOS1Mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -08001132 main.log.report( "Error in getting ONOS mastership" )
Jon Hall58c76b72015-02-23 11:09:24 -08001133 main.log.warn( "ONOS1 mastership response: " +
1134 repr( ONOS1Mastership ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001135 consistentMastership = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001136 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001137 consistentMastership = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001138 main.log.report(
1139 "Switch roles are consistent across all ONOS nodes" )
1140 utilities.assert_equals(
1141 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001142 actual=consistentMastership,
Jon Hall6aec96b2015-01-19 14:49:31 -08001143 onpass="Switch roles are consistent across all ONOS nodes",
1144 onfail="ONOS nodes have different views of switch roles" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001145
1146 description2 = "Compare switch roles from before failure"
Jon Hall6aec96b2015-01-19 14:49:31 -08001147 main.step( description2 )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001148
Jon Hall8f89dda2015-01-22 16:03:33 -08001149 currentJson = json.loads( ONOS1Mastership )
1150 oldJson = json.loads( mastershipState )
1151 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001152 for i in range( 1, 29 ):
1153 switchDPID = str(
Jon Hall58c76b72015-02-23 11:09:24 -08001154 main.Mininet1.getSwitchDPID( switch="s" + str( i ) ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001155
Jon Hall8f89dda2015-01-22 16:03:33 -08001156 current = [ switch[ 'master' ] for switch in currentJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001157 if switchDPID in switch[ 'id' ] ]
Jon Hall8f89dda2015-01-22 16:03:33 -08001158 old = [ switch[ 'master' ] for switch in oldJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001159 if switchDPID in switch[ 'id' ] ]
Jon Hall73cf9cc2014-11-20 22:28:38 -08001160 if current == old:
Jon Hall8f89dda2015-01-22 16:03:33 -08001161 mastershipCheck = mastershipCheck and main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001162 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001163 main.log.warn( "Mastership of switch %s changed" % switchDPID )
Jon Hall8f89dda2015-01-22 16:03:33 -08001164 mastershipCheck = main.FALSE
1165 if mastershipCheck == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001166 main.log.report( "Mastership of Switches was not changed" )
1167 utilities.assert_equals(
1168 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001169 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -08001170 onpass="Mastership of Switches was not changed",
1171 onfail="Mastership of some switches changed" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001172 mastershipCheck = mastershipCheck and consistentMastership
Jon Hall73cf9cc2014-11-20 22:28:38 -08001173
Jon Hall6aec96b2015-01-19 14:49:31 -08001174 main.step( "Get the intents and compare across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001175 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
1176 intentCheck = main.FALSE
1177 if "Error" in ONOS1Intents or not ONOS1Intents:
Jon Hall6aec96b2015-01-19 14:49:31 -08001178 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001179 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001180 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001181 intentCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001182 main.log.report( "Intents are consistent across all ONOS nodes" )
1183 utilities.assert_equals(
1184 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001185 actual=intentCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -08001186 onpass="Intents are consistent across all ONOS nodes",
1187 onfail="ONOS nodes have different views of intents" )
Jon Hall1b8f54a2015-02-04 13:24:20 -08001188 # Print the intent states
1189 intents = []
1190 intents.append( ONOS1Intents )
1191 intentStates = []
1192 for node in intents: # Iter through ONOS nodes
1193 nodeStates = []
Jon Hall58c76b72015-02-23 11:09:24 -08001194 # Iter through intents of a node
1195 for intent in json.loads( node ):
Jon Hall1b8f54a2015-02-04 13:24:20 -08001196 nodeStates.append( intent[ 'state' ] )
1197 intentStates.append( nodeStates )
1198 out = [ (i, nodeStates.count( i ) ) for i in set( nodeStates ) ]
1199 main.log.info( dict( out ) )
1200
Jon Hall58c76b72015-02-23 11:09:24 -08001201 # NOTE: Store has no durability, so intents are lost across system
1202 # restarts
Jon Hall6aec96b2015-01-19 14:49:31 -08001203 """
1204 main.step( "Compare current intents with intents before the failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001205 # NOTE: this requires case 5 to pass for intentState to be set.
Jon Hall6aec96b2015-01-19 14:49:31 -08001206 # maybe we should stop the test if that fails?
Jon Hall1b8f54a2015-02-04 13:24:20 -08001207 sameIntents = main.TRUE
1208 if intentState and intentState == ONOS1Intents:
Jon Hall8f89dda2015-01-22 16:03:33 -08001209 sameIntents = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001210 main.log.report( "Intents are consistent with before failure" )
1211 # TODO: possibly the states have changed? we may need to figure out
1212 # what the aceptable states are
Jon Hall73cf9cc2014-11-20 22:28:38 -08001213 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001214 try:
1215 main.log.warn( "ONOS1 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001216 print json.dumps( json.loads( ONOS1Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -08001217 sort_keys=True, indent=4,
1218 separators=( ',', ': ' ) )
Jon Hallfebb1c72015-03-05 13:30:09 -08001219 except Exception:
Jon Hall6aec96b2015-01-19 14:49:31 -08001220 pass
Jon Hall8f89dda2015-01-22 16:03:33 -08001221 sameIntents = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001222 utilities.assert_equals(
1223 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001224 actual=sameIntents,
Jon Hall6aec96b2015-01-19 14:49:31 -08001225 onpass="Intents are consistent with before failure",
1226 onfail="The Intents changed during failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001227 intentCheck = intentCheck and sameIntents
Jon Hall6aec96b2015-01-19 14:49:31 -08001228 """
1229 main.step( "Get the OF Table entries and compare to before " +
1230 "component failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001231 FlowTables = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001232 flows2 = []
1233 for i in range( 28 ):
1234 main.log.info( "Checking flow table on s" + str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001235 tmpFlows = main.Mininet2.getFlowTable( 1.3, "s" + str( i + 1 ) )
1236 flows2.append( tmpFlows )
1237 tempResult = main.Mininet2.flowComp(
Jon Hall6aec96b2015-01-19 14:49:31 -08001238 flow1=flows[ i ],
Jon Hall8f89dda2015-01-22 16:03:33 -08001239 flow2=tmpFlows )
1240 FlowTables = FlowTables and tempResult
1241 if FlowTables == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001242 main.log.info( "Differences in flow table for switch: s" +
1243 str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001244 if FlowTables == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001245 main.log.report( "No changes were found in the flow tables" )
1246 utilities.assert_equals(
1247 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001248 actual=FlowTables,
Jon Hall6aec96b2015-01-19 14:49:31 -08001249 onpass="No changes were found in the flow tables",
1250 onfail="Changes were found in the flow tables" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001251
Jon Hall6aec96b2015-01-19 14:49:31 -08001252 # Test of LeadershipElection
Jon Hall669173b2014-12-17 11:36:30 -08001253
Jon Hall8f89dda2015-01-22 16:03:33 -08001254 leader = ONOS1Ip
1255 leaderResult = main.TRUE
1256 for controller in range( 1, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001257 # loop through ONOScli handlers
1258 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001259 leaderN = node.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001260 # verify leader is ONOS1
1261 # NOTE even though we restarted ONOS, it is the only one so onos 1
1262 # must be leader
Jon Hall669173b2014-12-17 11:36:30 -08001263 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08001264 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001265 pass
1266 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001267 # error in response
1268 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001269 "electionTestLeader function, check the" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001270 " error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001271 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001272 elif leader != leaderN:
Jon Hall8f89dda2015-01-22 16:03:33 -08001273 leaderResult = main.FALSE
Jon Hall58c76b72015-02-23 11:09:24 -08001274 main.log.report( "ONOS" + str( controller ) + " sees " +
1275 str( leaderN ) +
1276 " as the leader of the election app. " +
1277 "Leader should be " + str( leader ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001278 if leaderResult:
1279 main.log.report( "Leadership election tests passed( consistent " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001280 "view of leader across listeners and a new " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001281 "leader was re-elected if applicable )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001282 utilities.assert_equals(
1283 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001284 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001285 onpass="Leadership election passed",
1286 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08001287
Jon Hall8f89dda2015-01-22 16:03:33 -08001288 result = ( mastershipCheck and intentCheck and FlowTables and
1289 rolesNotNull and leaderResult )
Jon Hall6aec96b2015-01-19 14:49:31 -08001290 result = int( result )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001291 if result == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001292 main.log.report( "Constant State Tests Passed" )
1293 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall58c76b72015-02-23 11:09:24 -08001294 onpass="Constant State Tests Passed",
1295 onfail="Constant state tests failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001296
Jon Hall6aec96b2015-01-19 14:49:31 -08001297 def CASE8( self, main ):
1298 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001299 Compare topo
Jon Hall6aec96b2015-01-19 14:49:31 -08001300 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001301 import sys
Jon Hall6aec96b2015-01-19 14:49:31 -08001302 # FIXME add this path to params
1303 sys.path.append( "/home/admin/sts" )
1304 # assumes that sts is already in you PYTHONPATH
1305 from sts.topology.teston_topology import TestONTopology
Jon Hall73cf9cc2014-11-20 22:28:38 -08001306 import json
1307 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001308 assert numControllers, "numControllers not defined"
1309 assert main, "main not defined"
1310 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall73cf9cc2014-11-20 22:28:38 -08001311
Jon Hall6aec96b2015-01-19 14:49:31 -08001312 description = "Compare ONOS Topology view to Mininet topology"
1313 main.case( description )
1314 main.log.report( description )
1315 main.step( "Create TestONTopology object" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001316 ctrls = []
Jon Halla9d26da2015-03-30 16:45:32 -07001317 node = main.ONOS1
1318 temp = ( node, node.name, node.ip_address, 6633 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001319 ctrls.append( temp )
Jon Halla9d26da2015-03-30 16:45:32 -07001320 MNTopo = TestONTopology( main.Mininet1, ctrls )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001321
Jon Hall6aec96b2015-01-19 14:49:31 -08001322 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001323 devicesResults = main.TRUE
1324 portsResults = main.TRUE
1325 linksResults = main.TRUE
Jon Hall58c76b72015-02-23 11:09:24 -08001326 hostsResults = main.TRUE
Jon Hall8f89dda2015-01-22 16:03:33 -08001327 topoResult = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001328 elapsed = 0
Jon Hallffb386d2014-11-21 13:43:38 -08001329 count = 0
Jon Hall6aec96b2015-01-19 14:49:31 -08001330 main.step( "Collecting topology information from ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001331 startTime = time.time()
Jon Hall58c76b72015-02-23 11:09:24 -08001332 # Give time for Gossip to work
Jon Hall8f89dda2015-01-22 16:03:33 -08001333 while topoResult == main.FALSE and elapsed < 60:
Jon Halla9d26da2015-03-30 16:45:32 -07001334 count += 1
Jon Hall94fd0472014-12-08 11:52:42 -08001335 if count > 1:
Jon Halla9d26da2015-03-30 16:45:32 -07001336 # TODO: Deprecate STS usage
Jon Hall58c76b72015-02-23 11:09:24 -08001337 MNTopo = TestONTopology( main.Mininet1, ctrls )
Jon Hall8f89dda2015-01-22 16:03:33 -08001338 cliStart = time.time()
Jon Hall94fd0472014-12-08 11:52:42 -08001339 devices = []
1340 devices.append( main.ONOScli1.devices() )
Jon Hall94fd0472014-12-08 11:52:42 -08001341 hosts = []
Jon Hall58c76b72015-02-23 11:09:24 -08001342 hosts.append( json.loads( main.ONOScli1.hosts() ) )
1343 ipResult = main.TRUE
1344 for controller in range( 0, len( hosts ) ):
1345 controllerStr = str( controller + 1 )
1346 for host in hosts[ controller ]:
1347 if host is None or host.get( 'ips', [] ) == []:
1348 main.log.error(
1349 "DEBUG:Error with host ips on controller" +
1350 controllerStr + ": " + str( host ) )
1351 ipResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001352 ports = []
1353 ports.append( main.ONOScli1.ports() )
1354 links = []
1355 links.append( main.ONOScli1.links() )
Jon Hall58c76b72015-02-23 11:09:24 -08001356 clusters = []
1357 clusters.append( main.ONOScli1.clusters() )
1358
Jon Hall8f89dda2015-01-22 16:03:33 -08001359 elapsed = time.time() - startTime
1360 cliTime = time.time() - cliStart
1361 print "CLI time: " + str( cliTime )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001362
Jon Hall8f89dda2015-01-22 16:03:33 -08001363 for controller in range( numControllers ):
1364 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001365 if devices[ controller ] or "Error" not in devices[
1366 controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001367 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -08001368 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001369 json.loads( devices[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001370 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001371 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001372 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001373 actual=currentDevicesResult,
1374 onpass="ONOS" + controllerStr +
1375 " Switches view is correct",
1376 onfail="ONOS" + controllerStr +
1377 " Switches view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001378
Jon Hall6aec96b2015-01-19 14:49:31 -08001379 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001380 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -08001381 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001382 json.loads( ports[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001383 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001384 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001385 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001386 actual=currentPortsResult,
1387 onpass="ONOS" + controllerStr +
1388 " ports view is correct",
1389 onfail="ONOS" + controllerStr +
1390 " ports view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001391
Jon Hall6aec96b2015-01-19 14:49:31 -08001392 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001393 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -08001394 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001395 json.loads( links[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001396 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001397 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001398 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001399 actual=currentLinksResult,
1400 onpass="ONOS" + controllerStr +
1401 " links view is correct",
1402 onfail="ONOS" + controllerStr +
1403 " links view is incorrect" )
1404
1405 if hosts[ controller ] or "Error" not in hosts[ controller ]:
1406 currentHostsResult = main.Mininet1.compareHosts(
1407 MNTopo, hosts[ controller ] )
1408 else:
1409 currentHostsResult = main.FALSE
1410 utilities.assert_equals( expect=main.TRUE,
1411 actual=currentHostsResult,
1412 onpass="ONOS" + controllerStr +
1413 " hosts exist in Mininet",
1414 onfail="ONOS" + controllerStr +
1415 " hosts don't match Mininet" )
1416
1417 devicesResults = devicesResults and currentDevicesResult
1418 portsResults = portsResults and currentPortsResult
1419 linksResults = linksResults and currentLinksResult
1420 hostsResults = hostsResults and currentHostsResult
1421
Jon Hall63604932015-02-26 17:09:50 -08001422 # "consistent" results don't make sense for single instance
Jon Hall58c76b72015-02-23 11:09:24 -08001423 # there should always only be one cluster
1424 numClusters = len( json.loads( clusters[ 0 ] ) )
1425 clusterResults = main.FALSE
1426 if numClusters == 1:
1427 clusterResults = main.TRUE
1428 utilities.assert_equals(
1429 expect=1,
1430 actual=numClusters,
1431 onpass="ONOS shows 1 SCC",
1432 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
1433
1434 topoResult = ( devicesResults and portsResults and linksResults
1435 and hostsResults and ipResult and clusterResults )
Jon Hall94fd0472014-12-08 11:52:42 -08001436
Jon Hall8f89dda2015-01-22 16:03:33 -08001437 topoResult = topoResult and int( count <= 2 )
1438 note = "note it takes about " + str( int( cliTime ) ) + \
1439 " seconds for the test to make all the cli calls to fetch " +\
1440 "the topology from each ONOS instance"
Jon Hall1b8f54a2015-02-04 13:24:20 -08001441 main.log.info(
Jon Hall8f89dda2015-01-22 16:03:33 -08001442 "Very crass estimate for topology discovery/convergence( " +
1443 str( note ) + " ): " + str( elapsed ) + " seconds, " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001444 str( count ) + " tries" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001445 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
Jon Hall58c76b72015-02-23 11:09:24 -08001446 onpass="Topology Check Test successful",
1447 onfail="Topology Check Test NOT successful" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001448 if topoResult == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001449 main.log.report( "ONOS topology view matches Mininet topology" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001450
Jon Hall6aec96b2015-01-19 14:49:31 -08001451 def CASE9( self, main ):
1452 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001453 Link s3-s28 down
Jon Hall6aec96b2015-01-19 14:49:31 -08001454 """
1455 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001456 assert numControllers, "numControllers not defined"
1457 assert main, "main not defined"
1458 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -08001459 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001460
Jon Hall8f89dda2015-01-22 16:03:33 -08001461 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001462
Jon Hall6aec96b2015-01-19 14:49:31 -08001463 description = "Turn off a link to ensure that Link Discovery " +\
Jon Hall58c76b72015-02-23 11:09:24 -08001464 "is working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001465 main.log.report( description )
1466 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001467
Jon Hall6aec96b2015-01-19 14:49:31 -08001468 main.step( "Kill Link between s3 and s28" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001469 LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" )
Jon Hall58c76b72015-02-23 11:09:24 -08001470 main.log.info( "Waiting " + str( linkSleep ) +
1471 " seconds for link down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001472 time.sleep( linkSleep )
1473 utilities.assert_equals( expect=main.TRUE, actual=LinkDown,
Jon Halla9d26da2015-03-30 16:45:32 -07001474 onpass="Link down successful",
Jon Hall58c76b72015-02-23 11:09:24 -08001475 onfail="Failed to bring link down" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001476 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -08001477
Jon Hall6aec96b2015-01-19 14:49:31 -08001478 def CASE10( self, main ):
1479 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001480 Link s3-s28 up
Jon Hall6aec96b2015-01-19 14:49:31 -08001481 """
1482 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001483 assert numControllers, "numControllers not defined"
1484 assert main, "main not defined"
1485 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -08001486 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001487
Jon Hall8f89dda2015-01-22 16:03:33 -08001488 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001489
Jon Hall6aec96b2015-01-19 14:49:31 -08001490 description = "Restore a link to ensure that Link Discovery is " + \
Jon Hall58c76b72015-02-23 11:09:24 -08001491 "working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001492 main.log.report( description )
1493 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001494
Jon Hall6aec96b2015-01-19 14:49:31 -08001495 main.step( "Bring link between s3 and s28 back up" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001496 LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" )
Jon Hall58c76b72015-02-23 11:09:24 -08001497 main.log.info( "Waiting " + str( linkSleep ) +
1498 " seconds for link up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001499 time.sleep( linkSleep )
1500 utilities.assert_equals( expect=main.TRUE, actual=LinkUp,
Jon Halla9d26da2015-03-30 16:45:32 -07001501 onpass="Link up successful",
Jon Hall58c76b72015-02-23 11:09:24 -08001502 onfail="Failed to bring link up" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001503 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -08001504
Jon Hall6aec96b2015-01-19 14:49:31 -08001505 def CASE11( self, main ):
1506 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001507 Switch Down
Jon Hall6aec96b2015-01-19 14:49:31 -08001508 """
1509 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001510 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001511 assert numControllers, "numControllers not defined"
1512 assert main, "main not defined"
1513 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall73cf9cc2014-11-20 22:28:38 -08001514
Jon Hall8f89dda2015-01-22 16:03:33 -08001515 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001516
1517 description = "Killing a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001518 main.log.report( description )
1519 main.case( description )
1520 switch = main.params[ 'kill' ][ 'switch' ]
1521 switchDPID = main.params[ 'kill' ][ 'dpid' ]
Jon Hall73cf9cc2014-11-20 22:28:38 -08001522
Jon Hall6aec96b2015-01-19 14:49:31 -08001523 # TODO: Make this switch parameterizable
1524 main.step( "Kill " + switch )
1525 main.log.report( "Deleting " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001526 main.Mininet1.delSwitch( switch )
1527 main.log.info( "Waiting " + str( switchSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001528 " seconds for switch down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001529 time.sleep( switchSleep )
1530 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001531 # Peek at the deleted switch
1532 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001533 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001534 if device and device[ 'available' ] is False:
Jon Hall94fd0472014-12-08 11:52:42 -08001535 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001536 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Halla9d26da2015-03-30 16:45:32 -07001537 onpass="Kill switch successful",
Jon Hall58c76b72015-02-23 11:09:24 -08001538 onfail="Failed to kill switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001539
Jon Hall6aec96b2015-01-19 14:49:31 -08001540 def CASE12( self, main ):
1541 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001542 Switch Up
Jon Hall6aec96b2015-01-19 14:49:31 -08001543 """
1544 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001545 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001546 assert numControllers, "numControllers not defined"
1547 assert main, "main not defined"
1548 assert utilities.assert_equals, "utilities.assert_equals not defined"
1549 assert ONOS1Port, "ONOS1Port not defined"
1550 assert ONOS2Port, "ONOS2Port not defined"
1551 assert ONOS3Port, "ONOS3Port not defined"
1552 assert ONOS4Port, "ONOS4Port not defined"
1553 assert ONOS5Port, "ONOS5Port not defined"
1554 assert ONOS6Port, "ONOS6Port not defined"
1555 assert ONOS7Port, "ONOS7Port not defined"
Jon Hall669173b2014-12-17 11:36:30 -08001556
Jon Hall8f89dda2015-01-22 16:03:33 -08001557 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall6aec96b2015-01-19 14:49:31 -08001558 switch = main.params[ 'kill' ][ 'switch' ]
1559 switchDPID = main.params[ 'kill' ][ 'dpid' ]
1560 links = main.params[ 'kill' ][ 'links' ].split()
Jon Hall73cf9cc2014-11-20 22:28:38 -08001561 description = "Adding a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001562 main.log.report( description )
1563 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001564
Jon Hall6aec96b2015-01-19 14:49:31 -08001565 main.step( "Add back " + switch )
1566 main.log.report( "Adding back " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001567 main.Mininet1.addSwitch( switch, dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001568 for peer in links:
Jon Hall8f89dda2015-01-22 16:03:33 -08001569 main.Mininet1.addLink( switch, peer )
1570 main.Mininet1.assignSwController( sw=switch.split( 's' )[ 1 ],
Jon Hall58c76b72015-02-23 11:09:24 -08001571 ip1=ONOS1Ip,
1572 port1=ONOS1Port )
1573 main.log.info( "Waiting " + str( switchSleep ) +
1574 " seconds for switch up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001575 time.sleep( switchSleep )
1576 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001577 # Peek at the deleted switch
1578 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001579 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001580 if device and device[ 'available' ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001581 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001582 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Halla9d26da2015-03-30 16:45:32 -07001583 onpass="add switch successful",
Jon Hall58c76b72015-02-23 11:09:24 -08001584 onfail="Failed to add switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001585
Jon Hall6aec96b2015-01-19 14:49:31 -08001586 def CASE13( self, main ):
1587 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001588 Clean up
Jon Hall6aec96b2015-01-19 14:49:31 -08001589 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001590 import os
1591 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001592 assert numControllers, "numControllers not defined"
1593 assert main, "main not defined"
1594 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -08001595 # printing colors to terminal
Jon Halla9d26da2015-03-30 16:45:32 -07001596 colors = { 'cyan': '\033[96m', 'purple': '\033[95m',
1597 'blue': '\033[94m', 'green': '\033[92m',
1598 'yellow': '\033[93m', 'red': '\033[91m', 'end': '\033[0m' }
Jon Hall73cf9cc2014-11-20 22:28:38 -08001599 description = "Test Cleanup"
Jon Hall6aec96b2015-01-19 14:49:31 -08001600 main.log.report( description )
1601 main.case( description )
1602 main.step( "Killing tcpdumps" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001603 main.Mininet2.stopTcpdump()
Jon Hall73cf9cc2014-11-20 22:28:38 -08001604
Jon Hall6aec96b2015-01-19 14:49:31 -08001605 main.step( "Copying MN pcap and ONOS log files to test station" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001606 testname = main.TEST
Jon Hall8f89dda2015-01-22 16:03:33 -08001607 teststationUser = main.params[ 'TESTONUSER' ]
1608 teststationIP = main.params[ 'TESTONIP' ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001609 # NOTE: MN Pcap file is being saved to ~/packet_captures
Jon Hall73cf9cc2014-11-20 22:28:38 -08001610 # scp this file as MN and TestON aren't necessarily the same vm
Jon Hall6aec96b2015-01-19 14:49:31 -08001611 # FIXME: scp
1612 # mn files
1613 # TODO: Load these from params
1614 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001615 logFolder = "/opt/onos/log/"
1616 logFiles = [ "karaf.log", "karaf.log.1" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001617 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001618 dstDir = "~/packet_captures/"
1619 for f in logFiles:
1620 main.ONOSbench.handle.sendline( "scp sdn@" + ONOS1Ip + ":" +
1621 logFolder + f + " " +
1622 teststationUser + "@" +
1623 teststationIP + ":" + dstDir +
Jon Hall6aec96b2015-01-19 14:49:31 -08001624 str( testname ) + "-ONOS1-" + f )
1625 main.ONOSbench.handle.expect( "\$" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001626
Jon Hall6aec96b2015-01-19 14:49:31 -08001627 # std*.log's
1628 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001629 logFolder = "/opt/onos/var/"
1630 logFiles = [ "stderr.log", "stdout.log" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001631 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001632 dstDir = "~/packet_captures/"
1633 for f in logFiles:
1634 main.ONOSbench.handle.sendline( "scp sdn@" + ONOS1Ip + ":" +
1635 logFolder + f + " " +
1636 teststationUser + "@" +
1637 teststationIP + ":" + dstDir +
Jon Hall6aec96b2015-01-19 14:49:31 -08001638 str( testname ) + "-ONOS1-" + f )
Jon Hall58c76b72015-02-23 11:09:24 -08001639 main.ONOSbench.handle.expect( "\$" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001640 # sleep so scp can finish
1641 time.sleep( 10 )
Jon Halla9d26da2015-03-30 16:45:32 -07001642
1643 main.step( "Stopping Mininet" )
Jon Hall390696c2015-05-05 17:13:41 -07001644 mnResult = main.Mininet1.stopNet()
1645 utilities.assert_equals( expect=main.TRUE, actual=mnResult,
1646 onpass="Mininet stopped",
1647 onfail="MN cleanup NOT successful" )
Jon Halla9d26da2015-03-30 16:45:32 -07001648
1649 main.step( "Checking ONOS Logs for errors" )
1650 print colors[ 'purple' ] + "Checking logs for errors on ONOS1:" + \
1651 colors[ 'end' ]
1652 print main.ONOSbench.checkLogs( ONOS1Ip )
1653
Jon Hall6aec96b2015-01-19 14:49:31 -08001654 main.step( "Packing and rotating pcap archives" )
1655 os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001656
Jon Hall6aec96b2015-01-19 14:49:31 -08001657 def CASE14( self, main ):
1658 """
Jon Hall669173b2014-12-17 11:36:30 -08001659 start election app on all onos nodes
Jon Hall6aec96b2015-01-19 14:49:31 -08001660 """
Jon Hall5cfd23c2015-03-19 11:40:57 -07001661 assert numControllers, "numControllers not defined"
1662 assert main, "main not defined"
1663 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halla9d26da2015-03-30 16:45:32 -07001664
Jon Hall8f89dda2015-01-22 16:03:33 -08001665 leaderResult = main.TRUE
Jon Hall390696c2015-05-05 17:13:41 -07001666 main.case("Start Leadership Election app")
1667 main.step( "Install leadership election app" )
Jon Halla9d26da2015-03-30 16:45:32 -07001668 main.ONOScli1.activateApp( "org.onosproject.election" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001669 # check for leader
Jon Hall8f89dda2015-01-22 16:03:33 -08001670 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001671 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08001672 if leader == ONOS1Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08001673 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001674 pass
Jon Hall6aec96b2015-01-19 14:49:31 -08001675 elif leader is None:
1676 # No leader elected
1677 main.log.report( "No leader was elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001678 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001679 elif leader == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001680 # error in response
1681 # TODO: add check for "Command not found:" in the driver, this
1682 # means the app isn't loaded
Jon Hall8f89dda2015-01-22 16:03:33 -08001683 main.log.report( "Something is wrong with electionTestLeader" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001684 " function, check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001685 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001686 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001687 # error in response
1688 main.log.report(
Jon Hall8f89dda2015-01-22 16:03:33 -08001689 "Unexpected response from electionTestLeader function:'" +
1690 str( leader ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001691 "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001692 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001693
Jon Hall8f89dda2015-01-22 16:03:33 -08001694 if leaderResult:
Jon Hall6aec96b2015-01-19 14:49:31 -08001695 main.log.report( "Leadership election tests passed( consistent " +
1696 "view of leader across listeners and a leader " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001697 "was elected )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001698 utilities.assert_equals(
1699 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001700 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001701 onpass="Leadership election passed",
1702 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08001703
Jon Hall6aec96b2015-01-19 14:49:31 -08001704 def CASE15( self, main ):
1705 """
Jon Hall669173b2014-12-17 11:36:30 -08001706 Check that Leadership Election is still functional
Jon Hall6aec96b2015-01-19 14:49:31 -08001707 """
Jon Hall5cfd23c2015-03-19 11:40:57 -07001708 assert numControllers, "numControllers not defined"
1709 assert main, "main not defined"
1710 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall8f89dda2015-01-22 16:03:33 -08001711 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08001712 description = "Check that Leadership Election is still functional"
Jon Hall6aec96b2015-01-19 14:49:31 -08001713 main.log.report( description )
1714 main.case( description )
1715 main.step( "Find current leader and withdraw" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001716 leader = main.ONOScli1.electionTestLeader()
Jon Halla9d26da2015-03-30 16:45:32 -07001717 # do some sanity checking on leader before using it
Jon Hall8f89dda2015-01-22 16:03:33 -08001718 withdrawResult = main.FALSE
1719 if leader == ONOS1Ip:
1720 oldLeader = getattr( main, "ONOScli1" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001721 elif leader is None or leader == main.FALSE:
1722 main.log.report(
1723 "Leader for the election app should be an ONOS node," +
Jon Hall58c76b72015-02-23 11:09:24 -08001724 "instead got '" + str( leader ) + "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001725 leaderResult = main.FALSE
Jon Hall63604932015-02-26 17:09:50 -08001726 oldLeader = None
1727 else:
1728 main.log.error( "Leader election --- why am I HERE?!?")
1729 if oldLeader:
1730 withdrawResult = oldLeader.electionTestWithdraw()
Jon Hall6aec96b2015-01-19 14:49:31 -08001731 utilities.assert_equals(
1732 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001733 actual=withdrawResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001734 onpass="App was withdrawn from election",
1735 onfail="App was not withdrawn from election" )
Jon Hall669173b2014-12-17 11:36:30 -08001736
Jon Hall6aec96b2015-01-19 14:49:31 -08001737 main.step( "Make sure new leader is elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001738 leaderN = main.ONOScli1.electionTestLeader()
Jon Hall669173b2014-12-17 11:36:30 -08001739 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08001740 main.log.report( "ONOS still sees " + str( leaderN ) +
1741 " as leader after they withdrew" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001742 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001743 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001744 # error in response
1745 # TODO: add check for "Command not found:" in the driver, this
1746 # means the app isn't loaded
Jon Hall8f89dda2015-01-22 16:03:33 -08001747 main.log.report( "Something is wrong with electionTestLeader " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001748 "function, check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001749 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001750 elif leaderN is None:
1751 main.log.info(
1752 "There is no leader after the app withdrew from election" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001753 if leaderResult:
1754 main.log.report( "Leadership election tests passed( There is no " +
1755 "leader after the old leader resigned )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001756 utilities.assert_equals(
1757 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001758 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001759 onpass="Leadership election passed",
1760 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08001761
Jon Hall58c76b72015-02-23 11:09:24 -08001762 main.step( "Run for election on old leader( just so everyone " +
1763 "is in the hat )" )
Jon Hall63604932015-02-26 17:09:50 -08001764 if oldLeader:
1765 runResult = oldLeader.electionTestRun()
1766 else:
1767 runResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001768 utilities.assert_equals(
1769 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001770 actual=runResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001771 onpass="App re-ran for election",
1772 onfail="App failed to run for election" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001773 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001774 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08001775 if leader == ONOS1Ip:
1776 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08001777 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001778 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001779 # TODO: assert on run and withdraw results?
Jon Hall669173b2014-12-17 11:36:30 -08001780
Jon Hall6aec96b2015-01-19 14:49:31 -08001781 utilities.assert_equals(
1782 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001783 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001784 onpass="Leadership election passed",
1785 onfail="ONOS1's election app was not leader after it re-ran " +
1786 "for election" )
Jon Hall390696c2015-05-05 17:13:41 -07001787
1788 def CASE16( self, main ):
1789 """
1790 Install Distributed Primitives app
1791 """
1792 assert numControllers, "numControllers not defined"
1793 assert main, "main not defined"
1794 assert utilities.assert_equals, "utilities.assert_equals not defined"
1795 assert CLIs, "CLIs not defined"
1796 assert nodes, "nodes not defined"
1797
1798 # Variables for the distributed primitives tests
1799 global pCounterName
1800 global iCounterName
1801 global pCounterValue
1802 global iCounterValue
1803 global onosSet
1804 global onosSetName
1805 pCounterName = "TestON-Partitions"
1806 iCounterName = "TestON-inMemory"
1807 pCounterValue = 0
1808 iCounterValue = 0
1809 onosSet = set([])
1810 onosSetName = "TestON-set"
1811
1812 description = "Install Primitives app"
1813 main.case( description )
1814 main.step( "Install Primitives app" )
1815 appName = "org.onosproject.distributedprimitives"
1816 appResults = CLIs[0].activateApp( appName )
1817 utilities.assert_equals( expect=main.TRUE,
1818 actual=appResults,
1819 onpass="Primitives app activated",
1820 onfail="Primitives app not activated" )
1821
1822 def CASE17( self, main ):
1823 """
1824 Check for basic functionality with distributed primitives
1825 """
1826 # Make sure variables are defined/set
1827 assert numControllers, "numControllers not defined"
1828 assert main, "main not defined"
1829 assert utilities.assert_equals, "utilities.assert_equals not defined"
1830 assert CLIs, "CLIs not defined"
1831 assert nodes, "nodes not defined"
1832 assert pCounterName, "pCounterName not defined"
1833 assert iCounterName, "iCounterName not defined"
1834 assert onosSetName, "onosSetName not defined"
1835 # NOTE: assert fails if value is 0/None/Empty/False
1836 try:
1837 pCounterValue
1838 except NameError:
1839 main.log.error( "pCounterValue not defined, setting to 0" )
1840 pCounterValue = 0
1841 try:
1842 iCounterValue
1843 except NameError:
1844 main.log.error( "iCounterValue not defined, setting to 0" )
1845 iCounterValue = 0
1846 try:
1847 onosSet
1848 except NameError:
1849 main.log.error( "onosSet not defined, setting to empty Set" )
1850 onosSet = set([])
1851 # Variables for the distributed primitives tests. These are local only
1852 addValue = "a"
1853 addAllValue = "a b c d e f"
1854 retainValue = "c d e f"
1855
1856 description = "Check for basic functionality with distributed " +\
1857 "primitives"
1858 main.case( description )
1859 main.caseExplaination = "Test the methods of the distributed primitives (counters and sets) throught the cli"
1860 # DISTRIBUTED ATOMIC COUNTERS
1861 main.step( "Increment and get a default counter on each node" )
1862 pCounters = []
1863 threads = []
1864 for i in range( numControllers ):
1865 t = main.Thread( target=CLIs[i].counterTestIncrement,
1866 name="counterIncrement-" + str( i ),
1867 args=[ pCounterName ] )
1868 pCounterValue += 1
1869 threads.append( t )
1870 t.start()
1871
1872 for t in threads:
1873 t.join()
1874 pCounters.append( t.result )
1875 # Check that counter incremented numController times
1876 pCounterResults = True
1877 for i in range( numControllers ):
1878 pCounterResults and ( i + 1 ) in pCounters
1879 utilities.assert_equals( expect=True,
1880 actual=pCounterResults,
1881 onpass="Default counter incremented",
1882 onfail="Error incrementing default" +
1883 " counter" )
1884
1885 main.step( "Increment and get an in memory counter on each node" )
1886 iCounters = []
1887 threads = []
1888 for i in range( numControllers ):
1889 t = main.Thread( target=CLIs[i].counterTestIncrement,
1890 name="icounterIncrement-" + str( i ),
1891 args=[ iCounterName ],
1892 kwargs={ "inMemory": True } )
1893 iCounterValue += 1
1894 threads.append( t )
1895 t.start()
1896
1897 for t in threads:
1898 t.join()
1899 iCounters.append( t.result )
1900 # Check that counter incremented numController times
1901 iCounterResults = True
1902 for i in range( numControllers ):
1903 iCounterResults and ( i + 1 ) in iCounters
1904 utilities.assert_equals( expect=True,
1905 actual=iCounterResults,
1906 onpass="In memory counter incremented",
1907 onfail="Error incrementing in memory" +
1908 " counter" )
1909
1910 main.step( "Check counters are consistant across nodes" )
1911 onosCounters = []
1912 threads = []
1913 for i in range( numControllers ):
1914 t = main.Thread( target=CLIs[i].counters,
1915 name="counters-" + str( i ) )
1916 threads.append( t )
1917 t.start()
1918 for t in threads:
1919 t.join()
1920 onosCounters.append( t.result )
1921 tmp = [ i == onosCounters[ 0 ] for i in onosCounters ]
1922 if all( tmp ):
1923 main.log.info( "Counters are consistent across all nodes" )
1924 consistentCounterResults = main.TRUE
1925 else:
1926 main.log.error( "Counters are not consistent across all nodes" )
1927 consistentCounterResults = main.FALSE
1928 utilities.assert_equals( expect=main.TRUE,
1929 actual=consistentCounterResults,
1930 onpass="ONOS counters are consistent " +
1931 "across nodes",
1932 onfail="ONOS Counters are inconsistent " +
1933 "across nodes" )
1934
1935 main.step( "Counters we added have the correct values" )
1936 correctResults = main.TRUE
1937 for i in range( numControllers ):
1938 current = onosCounters[i]
1939 try:
1940 pValue = current.get( pCounterName )
1941 iValue = current.get( iCounterName )
1942 if pValue == pCounterValue:
1943 main.log.info( "Partitioned counter value is correct" )
1944 else:
1945 main.log.error( "Partitioned counter value is incorrect," +
1946 " expected value: " + str( pCounterValue )
1947 + " current value: " + str( pValue ) )
1948 correctResults = main.FALSE
1949 if iValue == iCounterValue:
1950 main.log.info( "In memory counter value is correct" )
1951 else:
1952 main.log.error( "In memory counter value is incorrect, " +
1953 "expected value: " + str( iCounterValue ) +
1954 " current value: " + str( iValue ) )
1955 correctResults = main.FALSE
1956 except AttributeError, e:
1957 main.log.error( "ONOS" + str( i + 1 ) + " counters result " +
1958 "is not as expected" )
1959 correctResults = main.FALSE
1960 utilities.assert_equals( expect=main.TRUE,
1961 actual=correctResults,
1962 onpass="Added counters are correct",
1963 onfail="Added counters are incorrect" )
1964 # DISTRIBUTED SETS
1965 main.step( "Distributed Set get" )
1966 size = len( onosSet )
1967 getResponses = []
1968 threads = []
1969 for i in range( numControllers ):
1970 t = main.Thread( target=CLIs[i].setTestGet,
1971 name="setTestGet-" + str( i ),
1972 args=[ onosSetName ] )
1973 threads.append( t )
1974 t.start()
1975 for t in threads:
1976 t.join()
1977 getResponses.append( t.result )
1978
1979 getResults = main.TRUE
1980 for i in range( numControllers ):
1981 if isinstance( getResponses[ i ], list):
1982 current = set( getResponses[ i ] )
1983 if len( current ) == len( getResponses[ i ] ):
1984 # no repeats
1985 if onosSet != current:
1986 main.log.error( "ONOS" + str( i + 1 ) +
1987 " has incorrect view" +
1988 " of set " + onosSetName + ":\n" +
1989 str( getResponses[ i ] ) )
1990 main.log.debug( "Expected: " + str( onosSet ) )
1991 main.log.debug( "Actual: " + str( current ) )
1992 getResults = main.FALSE
1993 else:
1994 # error, set is not a set
1995 main.log.error( "ONOS" + str( i + 1 ) +
1996 " has repeat elements in" +
1997 " set " + onosSetName + ":\n" +
1998 str( getResponses[ i ] ) )
1999 getResults = main.FALSE
2000 elif getResponses[ i ] == main.ERROR:
2001 getResults = main.FALSE
2002 utilities.assert_equals( expect=main.TRUE,
2003 actual=getResults,
2004 onpass="Set elements are correct",
2005 onfail="Set elements are incorrect" )
2006
2007 main.step( "Distributed Set size" )
2008 sizeResponses = []
2009 threads = []
2010 for i in range( numControllers ):
2011 t = main.Thread( target=CLIs[i].setTestSize,
2012 name="setTestSize-" + str( i ),
2013 args=[ onosSetName ] )
2014 threads.append( t )
2015 t.start()
2016 for t in threads:
2017 t.join()
2018 sizeResponses.append( t.result )
2019
2020 sizeResults = main.TRUE
2021 for i in range( numControllers ):
2022 if size != sizeResponses[ i ]:
2023 sizeResults = main.FALSE
2024 main.log.error( "ONOS" + str( i + 1 ) +
2025 " expected a size of " + str( size ) +
2026 " for set " + onosSetName +
2027 " but got " + str( sizeResponses[ i ] ) )
2028 utilities.assert_equals( expect=main.TRUE,
2029 actual=sizeResults,
2030 onpass="Set sizes are correct",
2031 onfail="Set sizes are incorrect" )
2032
2033 main.step( "Distributed Set add()" )
2034 onosSet.add( addValue )
2035 addResponses = []
2036 threads = []
2037 for i in range( numControllers ):
2038 t = main.Thread( target=CLIs[i].setTestAdd,
2039 name="setTestAdd-" + str( i ),
2040 args=[ onosSetName, addValue ] )
2041 threads.append( t )
2042 t.start()
2043 for t in threads:
2044 t.join()
2045 addResponses.append( t.result )
2046
2047 # main.TRUE = successfully changed the set
2048 # main.FALSE = action resulted in no change in set
2049 # main.ERROR - Some error in executing the function
2050 addResults = main.TRUE
2051 for i in range( numControllers ):
2052 if addResponses[ i ] == main.TRUE:
2053 # All is well
2054 pass
2055 elif addResponses[ i ] == main.FALSE:
2056 # Already in set, probably fine
2057 pass
2058 elif addResponses[ i ] == main.ERROR:
2059 # Error in execution
2060 addResults = main.FALSE
2061 else:
2062 # unexpected result
2063 addResults = main.FALSE
2064 if addResults != main.TRUE:
2065 main.log.error( "Error executing set add" )
2066
2067 # Check if set is still correct
2068 size = len( onosSet )
2069 getResponses = []
2070 threads = []
2071 for i in range( numControllers ):
2072 t = main.Thread( target=CLIs[i].setTestGet,
2073 name="setTestGet-" + str( i ),
2074 args=[ onosSetName ] )
2075 threads.append( t )
2076 t.start()
2077 for t in threads:
2078 t.join()
2079 getResponses.append( t.result )
2080 getResults = main.TRUE
2081 for i in range( numControllers ):
2082 if isinstance( getResponses[ i ], list):
2083 current = set( getResponses[ i ] )
2084 if len( current ) == len( getResponses[ i ] ):
2085 # no repeats
2086 if onosSet != current:
2087 main.log.error( "ONOS" + str( i + 1 ) +
2088 " has incorrect view" +
2089 " of set " + onosSetName + ":\n" +
2090 str( getResponses[ i ] ) )
2091 main.log.debug( "Expected: " + str( onosSet ) )
2092 main.log.debug( "Actual: " + str( current ) )
2093 getResults = main.FALSE
2094 else:
2095 # error, set is not a set
2096 main.log.error( "ONOS" + str( i + 1 ) +
2097 " has repeat elements in" +
2098 " set " + onosSetName + ":\n" +
2099 str( getResponses[ i ] ) )
2100 getResults = main.FALSE
2101 elif getResponses[ i ] == main.ERROR:
2102 getResults = main.FALSE
2103 sizeResponses = []
2104 threads = []
2105 for i in range( numControllers ):
2106 t = main.Thread( target=CLIs[i].setTestSize,
2107 name="setTestSize-" + str( i ),
2108 args=[ onosSetName ] )
2109 threads.append( t )
2110 t.start()
2111 for t in threads:
2112 t.join()
2113 sizeResponses.append( t.result )
2114 sizeResults = main.TRUE
2115 for i in range( numControllers ):
2116 if size != sizeResponses[ i ]:
2117 sizeResults = main.FALSE
2118 main.log.error( "ONOS" + str( i + 1 ) +
2119 " expected a size of " + str( size ) +
2120 " for set " + onosSetName +
2121 " but got " + str( sizeResponses[ i ] ) )
2122 addResults = addResults and getResults and sizeResults
2123 utilities.assert_equals( expect=main.TRUE,
2124 actual=addResults,
2125 onpass="Set add correct",
2126 onfail="Set add was incorrect" )
2127
2128 main.step( "Distributed Set addAll()" )
2129 onosSet.update( addAllValue.split() )
2130 addResponses = []
2131 threads = []
2132 for i in range( numControllers ):
2133 t = main.Thread( target=CLIs[i].setTestAdd,
2134 name="setTestAddAll-" + str( i ),
2135 args=[ onosSetName, addAllValue ] )
2136 threads.append( t )
2137 t.start()
2138 for t in threads:
2139 t.join()
2140 addResponses.append( t.result )
2141
2142 # main.TRUE = successfully changed the set
2143 # main.FALSE = action resulted in no change in set
2144 # main.ERROR - Some error in executing the function
2145 addAllResults = main.TRUE
2146 for i in range( numControllers ):
2147 if addResponses[ i ] == main.TRUE:
2148 # All is well
2149 pass
2150 elif addResponses[ i ] == main.FALSE:
2151 # Already in set, probably fine
2152 pass
2153 elif addResponses[ i ] == main.ERROR:
2154 # Error in execution
2155 addAllResults = main.FALSE
2156 else:
2157 # unexpected result
2158 addAllResults = main.FALSE
2159 if addAllResults != main.TRUE:
2160 main.log.error( "Error executing set addAll" )
2161
2162 # Check if set is still correct
2163 size = len( onosSet )
2164 getResponses = []
2165 threads = []
2166 for i in range( numControllers ):
2167 t = main.Thread( target=CLIs[i].setTestGet,
2168 name="setTestGet-" + str( i ),
2169 args=[ onosSetName ] )
2170 threads.append( t )
2171 t.start()
2172 for t in threads:
2173 t.join()
2174 getResponses.append( t.result )
2175 getResults = main.TRUE
2176 for i in range( numControllers ):
2177 if isinstance( getResponses[ i ], list):
2178 current = set( getResponses[ i ] )
2179 if len( current ) == len( getResponses[ i ] ):
2180 # no repeats
2181 if onosSet != current:
2182 main.log.error( "ONOS" + str( i + 1 ) +
2183 " has incorrect view" +
2184 " of set " + onosSetName + ":\n" +
2185 str( getResponses[ i ] ) )
2186 main.log.debug( "Expected: " + str( onosSet ) )
2187 main.log.debug( "Actual: " + str( current ) )
2188 getResults = main.FALSE
2189 else:
2190 # error, set is not a set
2191 main.log.error( "ONOS" + str( i + 1 ) +
2192 " has repeat elements in" +
2193 " set " + onosSetName + ":\n" +
2194 str( getResponses[ i ] ) )
2195 getResults = main.FALSE
2196 elif getResponses[ i ] == main.ERROR:
2197 getResults = main.FALSE
2198 sizeResponses = []
2199 threads = []
2200 for i in range( numControllers ):
2201 t = main.Thread( target=CLIs[i].setTestSize,
2202 name="setTestSize-" + str( i ),
2203 args=[ onosSetName ] )
2204 threads.append( t )
2205 t.start()
2206 for t in threads:
2207 t.join()
2208 sizeResponses.append( t.result )
2209 sizeResults = main.TRUE
2210 for i in range( numControllers ):
2211 if size != sizeResponses[ i ]:
2212 sizeResults = main.FALSE
2213 main.log.error( "ONOS" + str( i + 1 ) +
2214 " expected a size of " + str( size ) +
2215 " for set " + onosSetName +
2216 " but got " + str( sizeResponses[ i ] ) )
2217 addAllResults = addAllResults and getResults and sizeResults
2218 utilities.assert_equals( expect=main.TRUE,
2219 actual=addAllResults,
2220 onpass="Set addAll correct",
2221 onfail="Set addAll was incorrect" )
2222
2223 main.step( "Distributed Set contains()" )
2224 containsResponses = []
2225 threads = []
2226 for i in range( numControllers ):
2227 t = main.Thread( target=CLIs[i].setTestGet,
2228 name="setContains-" + str( i ),
2229 args=[ onosSetName ],
2230 kwargs={ "values": addValue } )
2231 threads.append( t )
2232 t.start()
2233 for t in threads:
2234 t.join()
2235 # NOTE: This is the tuple
2236 containsResponses.append( t.result )
2237
2238 containsResults = main.TRUE
2239 for i in range( numControllers ):
2240 if containsResponses[ i ] == main.ERROR:
2241 containsResults = main.FALSE
2242 else:
2243 containsResults = containsResults and\
2244 containsResponses[ i ][ 1 ]
2245 utilities.assert_equals( expect=main.TRUE,
2246 actual=containsResults,
2247 onpass="Set contains is functional",
2248 onfail="Set contains failed" )
2249
2250 main.step( "Distributed Set containsAll()" )
2251 containsAllResponses = []
2252 threads = []
2253 for i in range( numControllers ):
2254 t = main.Thread( target=CLIs[i].setTestGet,
2255 name="setContainsAll-" + str( i ),
2256 args=[ onosSetName ],
2257 kwargs={ "values": addAllValue } )
2258 threads.append( t )
2259 t.start()
2260 for t in threads:
2261 t.join()
2262 # NOTE: This is the tuple
2263 containsAllResponses.append( t.result )
2264
2265 containsAllResults = main.TRUE
2266 for i in range( numControllers ):
2267 if containsResponses[ i ] == main.ERROR:
2268 containsResults = main.FALSE
2269 else:
2270 containsResults = containsResults and\
2271 containsResponses[ i ][ 1 ]
2272 utilities.assert_equals( expect=main.TRUE,
2273 actual=containsAllResults,
2274 onpass="Set containsAll is functional",
2275 onfail="Set containsAll failed" )
2276
2277 main.step( "Distributed Set remove()" )
2278 onosSet.remove( addValue )
2279 removeResponses = []
2280 threads = []
2281 for i in range( numControllers ):
2282 t = main.Thread( target=CLIs[i].setTestRemove,
2283 name="setTestRemove-" + str( i ),
2284 args=[ onosSetName, addValue ] )
2285 threads.append( t )
2286 t.start()
2287 for t in threads:
2288 t.join()
2289 removeResponses.append( t.result )
2290
2291 # main.TRUE = successfully changed the set
2292 # main.FALSE = action resulted in no change in set
2293 # main.ERROR - Some error in executing the function
2294 removeResults = main.TRUE
2295 for i in range( numControllers ):
2296 if removeResponses[ i ] == main.TRUE:
2297 # All is well
2298 pass
2299 elif removeResponses[ i ] == main.FALSE:
2300 # not in set, probably fine
2301 pass
2302 elif removeResponses[ i ] == main.ERROR:
2303 # Error in execution
2304 removeResults = main.FALSE
2305 else:
2306 # unexpected result
2307 removeResults = main.FALSE
2308 if removeResults != main.TRUE:
2309 main.log.error( "Error executing set remove" )
2310
2311 # Check if set is still correct
2312 size = len( onosSet )
2313 getResponses = []
2314 threads = []
2315 for i in range( numControllers ):
2316 t = main.Thread( target=CLIs[i].setTestGet,
2317 name="setTestGet-" + str( i ),
2318 args=[ onosSetName ] )
2319 threads.append( t )
2320 t.start()
2321 for t in threads:
2322 t.join()
2323 getResponses.append( t.result )
2324 getResults = main.TRUE
2325 for i in range( numControllers ):
2326 if isinstance( getResponses[ i ], list):
2327 current = set( getResponses[ i ] )
2328 if len( current ) == len( getResponses[ i ] ):
2329 # no repeats
2330 if onosSet != current:
2331 main.log.error( "ONOS" + str( i + 1 ) +
2332 " has incorrect view" +
2333 " of set " + onosSetName + ":\n" +
2334 str( getResponses[ i ] ) )
2335 main.log.debug( "Expected: " + str( onosSet ) )
2336 main.log.debug( "Actual: " + str( current ) )
2337 getResults = main.FALSE
2338 else:
2339 # error, set is not a set
2340 main.log.error( "ONOS" + str( i + 1 ) +
2341 " has repeat elements in" +
2342 " set " + onosSetName + ":\n" +
2343 str( getResponses[ i ] ) )
2344 getResults = main.FALSE
2345 elif getResponses[ i ] == main.ERROR:
2346 getResults = main.FALSE
2347 sizeResponses = []
2348 threads = []
2349 for i in range( numControllers ):
2350 t = main.Thread( target=CLIs[i].setTestSize,
2351 name="setTestSize-" + str( i ),
2352 args=[ onosSetName ] )
2353 threads.append( t )
2354 t.start()
2355 for t in threads:
2356 t.join()
2357 sizeResponses.append( t.result )
2358 sizeResults = main.TRUE
2359 for i in range( numControllers ):
2360 if size != sizeResponses[ i ]:
2361 sizeResults = main.FALSE
2362 main.log.error( "ONOS" + str( i + 1 ) +
2363 " expected a size of " + str( size ) +
2364 " for set " + onosSetName +
2365 " but got " + str( sizeResponses[ i ] ) )
2366 removeResults = removeResults and getResults and sizeResults
2367 utilities.assert_equals( expect=main.TRUE,
2368 actual=removeResults,
2369 onpass="Set remove correct",
2370 onfail="Set remove was incorrect" )
2371
2372 main.step( "Distributed Set removeAll()" )
2373 onosSet.difference_update( addAllValue.split() )
2374 removeAllResponses = []
2375 threads = []
2376 try:
2377 for i in range( numControllers ):
2378 t = main.Thread( target=CLIs[i].setTestRemove,
2379 name="setTestRemoveAll-" + str( i ),
2380 args=[ onosSetName, addAllValue ] )
2381 threads.append( t )
2382 t.start()
2383 for t in threads:
2384 t.join()
2385 removeAllResponses.append( t.result )
2386 except Exception, e:
2387 main.log.exception(e)
2388
2389 # main.TRUE = successfully changed the set
2390 # main.FALSE = action resulted in no change in set
2391 # main.ERROR - Some error in executing the function
2392 removeAllResults = main.TRUE
2393 for i in range( numControllers ):
2394 if removeAllResponses[ i ] == main.TRUE:
2395 # All is well
2396 pass
2397 elif removeAllResponses[ i ] == main.FALSE:
2398 # not in set, probably fine
2399 pass
2400 elif removeAllResponses[ i ] == main.ERROR:
2401 # Error in execution
2402 removeAllResults = main.FALSE
2403 else:
2404 # unexpected result
2405 removeAllResults = main.FALSE
2406 if removeAllResults != main.TRUE:
2407 main.log.error( "Error executing set removeAll" )
2408
2409 # Check if set is still correct
2410 size = len( onosSet )
2411 getResponses = []
2412 threads = []
2413 for i in range( numControllers ):
2414 t = main.Thread( target=CLIs[i].setTestGet,
2415 name="setTestGet-" + str( i ),
2416 args=[ onosSetName ] )
2417 threads.append( t )
2418 t.start()
2419 for t in threads:
2420 t.join()
2421 getResponses.append( t.result )
2422 getResults = main.TRUE
2423 for i in range( numControllers ):
2424 if isinstance( getResponses[ i ], list):
2425 current = set( getResponses[ i ] )
2426 if len( current ) == len( getResponses[ i ] ):
2427 # no repeats
2428 if onosSet != current:
2429 main.log.error( "ONOS" + str( i + 1 ) +
2430 " has incorrect view" +
2431 " of set " + onosSetName + ":\n" +
2432 str( getResponses[ i ] ) )
2433 main.log.debug( "Expected: " + str( onosSet ) )
2434 main.log.debug( "Actual: " + str( current ) )
2435 getResults = main.FALSE
2436 else:
2437 # error, set is not a set
2438 main.log.error( "ONOS" + str( i + 1 ) +
2439 " has repeat elements in" +
2440 " set " + onosSetName + ":\n" +
2441 str( getResponses[ i ] ) )
2442 getResults = main.FALSE
2443 elif getResponses[ i ] == main.ERROR:
2444 getResults = main.FALSE
2445 sizeResponses = []
2446 threads = []
2447 for i in range( numControllers ):
2448 t = main.Thread( target=CLIs[i].setTestSize,
2449 name="setTestSize-" + str( i ),
2450 args=[ onosSetName ] )
2451 threads.append( t )
2452 t.start()
2453 for t in threads:
2454 t.join()
2455 sizeResponses.append( t.result )
2456 sizeResults = main.TRUE
2457 for i in range( numControllers ):
2458 if size != sizeResponses[ i ]:
2459 sizeResults = main.FALSE
2460 main.log.error( "ONOS" + str( i + 1 ) +
2461 " expected a size of " + str( size ) +
2462 " for set " + onosSetName +
2463 " but got " + str( sizeResponses[ i ] ) )
2464 removeAllResults = removeAllResults and getResults and sizeResults
2465 utilities.assert_equals( expect=main.TRUE,
2466 actual=removeAllResults,
2467 onpass="Set removeAll correct",
2468 onfail="Set removeAll was incorrect" )
2469
2470 main.step( "Distributed Set addAll()" )
2471 onosSet.update( addAllValue.split() )
2472 addResponses = []
2473 threads = []
2474 for i in range( numControllers ):
2475 t = main.Thread( target=CLIs[i].setTestAdd,
2476 name="setTestAddAll-" + str( i ),
2477 args=[ onosSetName, addAllValue ] )
2478 threads.append( t )
2479 t.start()
2480 for t in threads:
2481 t.join()
2482 addResponses.append( t.result )
2483
2484 # main.TRUE = successfully changed the set
2485 # main.FALSE = action resulted in no change in set
2486 # main.ERROR - Some error in executing the function
2487 addAllResults = main.TRUE
2488 for i in range( numControllers ):
2489 if addResponses[ i ] == main.TRUE:
2490 # All is well
2491 pass
2492 elif addResponses[ i ] == main.FALSE:
2493 # Already in set, probably fine
2494 pass
2495 elif addResponses[ i ] == main.ERROR:
2496 # Error in execution
2497 addAllResults = main.FALSE
2498 else:
2499 # unexpected result
2500 addAllResults = main.FALSE
2501 if addAllResults != main.TRUE:
2502 main.log.error( "Error executing set addAll" )
2503
2504 # Check if set is still correct
2505 size = len( onosSet )
2506 getResponses = []
2507 threads = []
2508 for i in range( numControllers ):
2509 t = main.Thread( target=CLIs[i].setTestGet,
2510 name="setTestGet-" + str( i ),
2511 args=[ onosSetName ] )
2512 threads.append( t )
2513 t.start()
2514 for t in threads:
2515 t.join()
2516 getResponses.append( t.result )
2517 getResults = main.TRUE
2518 for i in range( numControllers ):
2519 if isinstance( getResponses[ i ], list):
2520 current = set( getResponses[ i ] )
2521 if len( current ) == len( getResponses[ i ] ):
2522 # no repeats
2523 if onosSet != current:
2524 main.log.error( "ONOS" + str( i + 1 ) +
2525 " has incorrect view" +
2526 " of set " + onosSetName + ":\n" +
2527 str( getResponses[ i ] ) )
2528 main.log.debug( "Expected: " + str( onosSet ) )
2529 main.log.debug( "Actual: " + str( current ) )
2530 getResults = main.FALSE
2531 else:
2532 # error, set is not a set
2533 main.log.error( "ONOS" + str( i + 1 ) +
2534 " has repeat elements in" +
2535 " set " + onosSetName + ":\n" +
2536 str( getResponses[ i ] ) )
2537 getResults = main.FALSE
2538 elif getResponses[ i ] == main.ERROR:
2539 getResults = main.FALSE
2540 sizeResponses = []
2541 threads = []
2542 for i in range( numControllers ):
2543 t = main.Thread( target=CLIs[i].setTestSize,
2544 name="setTestSize-" + str( i ),
2545 args=[ onosSetName ] )
2546 threads.append( t )
2547 t.start()
2548 for t in threads:
2549 t.join()
2550 sizeResponses.append( t.result )
2551 sizeResults = main.TRUE
2552 for i in range( numControllers ):
2553 if size != sizeResponses[ i ]:
2554 sizeResults = main.FALSE
2555 main.log.error( "ONOS" + str( i + 1 ) +
2556 " expected a size of " + str( size ) +
2557 " for set " + onosSetName +
2558 " but got " + str( sizeResponses[ i ] ) )
2559 addAllResults = addAllResults and getResults and sizeResults
2560 utilities.assert_equals( expect=main.TRUE,
2561 actual=addAllResults,
2562 onpass="Set addAll correct",
2563 onfail="Set addAll was incorrect" )
2564
2565 main.step( "Distributed Set clear()" )
2566 onosSet.clear()
2567 clearResponses = []
2568 threads = []
2569 for i in range( numControllers ):
2570 t = main.Thread( target=CLIs[i].setTestRemove,
2571 name="setTestClear-" + str( i ),
2572 args=[ onosSetName, " "], # Values doesn't matter
2573 kwargs={ "clear": True } )
2574 threads.append( t )
2575 t.start()
2576 for t in threads:
2577 t.join()
2578 clearResponses.append( t.result )
2579
2580 # main.TRUE = successfully changed the set
2581 # main.FALSE = action resulted in no change in set
2582 # main.ERROR - Some error in executing the function
2583 clearResults = main.TRUE
2584 for i in range( numControllers ):
2585 if clearResponses[ i ] == main.TRUE:
2586 # All is well
2587 pass
2588 elif clearResponses[ i ] == main.FALSE:
2589 # Nothing set, probably fine
2590 pass
2591 elif clearResponses[ i ] == main.ERROR:
2592 # Error in execution
2593 clearResults = main.FALSE
2594 else:
2595 # unexpected result
2596 clearResults = main.FALSE
2597 if clearResults != main.TRUE:
2598 main.log.error( "Error executing set clear" )
2599
2600 # Check if set is still correct
2601 size = len( onosSet )
2602 getResponses = []
2603 threads = []
2604 for i in range( numControllers ):
2605 t = main.Thread( target=CLIs[i].setTestGet,
2606 name="setTestGet-" + str( i ),
2607 args=[ onosSetName ] )
2608 threads.append( t )
2609 t.start()
2610 for t in threads:
2611 t.join()
2612 getResponses.append( t.result )
2613 getResults = main.TRUE
2614 for i in range( numControllers ):
2615 if isinstance( getResponses[ i ], list):
2616 current = set( getResponses[ i ] )
2617 if len( current ) == len( getResponses[ i ] ):
2618 # no repeats
2619 if onosSet != current:
2620 main.log.error( "ONOS" + str( i + 1 ) +
2621 " has incorrect view" +
2622 " of set " + onosSetName + ":\n" +
2623 str( getResponses[ i ] ) )
2624 main.log.debug( "Expected: " + str( onosSet ) )
2625 main.log.debug( "Actual: " + str( current ) )
2626 getResults = main.FALSE
2627 else:
2628 # error, set is not a set
2629 main.log.error( "ONOS" + str( i + 1 ) +
2630 " has repeat elements in" +
2631 " set " + onosSetName + ":\n" +
2632 str( getResponses[ i ] ) )
2633 getResults = main.FALSE
2634 elif getResponses[ i ] == main.ERROR:
2635 getResults = main.FALSE
2636 sizeResponses = []
2637 threads = []
2638 for i in range( numControllers ):
2639 t = main.Thread( target=CLIs[i].setTestSize,
2640 name="setTestSize-" + str( i ),
2641 args=[ onosSetName ] )
2642 threads.append( t )
2643 t.start()
2644 for t in threads:
2645 t.join()
2646 sizeResponses.append( t.result )
2647 sizeResults = main.TRUE
2648 for i in range( numControllers ):
2649 if size != sizeResponses[ i ]:
2650 sizeResults = main.FALSE
2651 main.log.error( "ONOS" + str( i + 1 ) +
2652 " expected a size of " + str( size ) +
2653 " for set " + onosSetName +
2654 " but got " + str( sizeResponses[ i ] ) )
2655 clearResults = clearResults and getResults and sizeResults
2656 utilities.assert_equals( expect=main.TRUE,
2657 actual=clearResults,
2658 onpass="Set clear correct",
2659 onfail="Set clear was incorrect" )
2660
2661 main.step( "Distributed Set addAll()" )
2662 onosSet.update( addAllValue.split() )
2663 addResponses = []
2664 threads = []
2665 for i in range( numControllers ):
2666 t = main.Thread( target=CLIs[i].setTestAdd,
2667 name="setTestAddAll-" + str( i ),
2668 args=[ onosSetName, addAllValue ] )
2669 threads.append( t )
2670 t.start()
2671 for t in threads:
2672 t.join()
2673 addResponses.append( t.result )
2674
2675 # main.TRUE = successfully changed the set
2676 # main.FALSE = action resulted in no change in set
2677 # main.ERROR - Some error in executing the function
2678 addAllResults = main.TRUE
2679 for i in range( numControllers ):
2680 if addResponses[ i ] == main.TRUE:
2681 # All is well
2682 pass
2683 elif addResponses[ i ] == main.FALSE:
2684 # Already in set, probably fine
2685 pass
2686 elif addResponses[ i ] == main.ERROR:
2687 # Error in execution
2688 addAllResults = main.FALSE
2689 else:
2690 # unexpected result
2691 addAllResults = main.FALSE
2692 if addAllResults != main.TRUE:
2693 main.log.error( "Error executing set addAll" )
2694
2695 # Check if set is still correct
2696 size = len( onosSet )
2697 getResponses = []
2698 threads = []
2699 for i in range( numControllers ):
2700 t = main.Thread( target=CLIs[i].setTestGet,
2701 name="setTestGet-" + str( i ),
2702 args=[ onosSetName ] )
2703 threads.append( t )
2704 t.start()
2705 for t in threads:
2706 t.join()
2707 getResponses.append( t.result )
2708 getResults = main.TRUE
2709 for i in range( numControllers ):
2710 if isinstance( getResponses[ i ], list):
2711 current = set( getResponses[ i ] )
2712 if len( current ) == len( getResponses[ i ] ):
2713 # no repeats
2714 if onosSet != current:
2715 main.log.error( "ONOS" + str( i + 1 ) +
2716 " has incorrect view" +
2717 " of set " + onosSetName + ":\n" +
2718 str( getResponses[ i ] ) )
2719 main.log.debug( "Expected: " + str( onosSet ) )
2720 main.log.debug( "Actual: " + str( current ) )
2721 getResults = main.FALSE
2722 else:
2723 # error, set is not a set
2724 main.log.error( "ONOS" + str( i + 1 ) +
2725 " has repeat elements in" +
2726 " set " + onosSetName + ":\n" +
2727 str( getResponses[ i ] ) )
2728 getResults = main.FALSE
2729 elif getResponses[ i ] == main.ERROR:
2730 getResults = main.FALSE
2731 sizeResponses = []
2732 threads = []
2733 for i in range( numControllers ):
2734 t = main.Thread( target=CLIs[i].setTestSize,
2735 name="setTestSize-" + str( i ),
2736 args=[ onosSetName ] )
2737 threads.append( t )
2738 t.start()
2739 for t in threads:
2740 t.join()
2741 sizeResponses.append( t.result )
2742 sizeResults = main.TRUE
2743 for i in range( numControllers ):
2744 if size != sizeResponses[ i ]:
2745 sizeResults = main.FALSE
2746 main.log.error( "ONOS" + str( i + 1 ) +
2747 " expected a size of " + str( size ) +
2748 " for set " + onosSetName +
2749 " but got " + str( sizeResponses[ i ] ) )
2750 addAllResults = addAllResults and getResults and sizeResults
2751 utilities.assert_equals( expect=main.TRUE,
2752 actual=addAllResults,
2753 onpass="Set addAll correct",
2754 onfail="Set addAll was incorrect" )
2755
2756 main.step( "Distributed Set retain()" )
2757 onosSet.intersection_update( retainValue.split() )
2758 retainResponses = []
2759 threads = []
2760 for i in range( numControllers ):
2761 t = main.Thread( target=CLIs[i].setTestRemove,
2762 name="setTestRetain-" + str( i ),
2763 args=[ onosSetName, retainValue ],
2764 kwargs={ "retain": True } )
2765 threads.append( t )
2766 t.start()
2767 for t in threads:
2768 t.join()
2769 retainResponses.append( t.result )
2770
2771 # main.TRUE = successfully changed the set
2772 # main.FALSE = action resulted in no change in set
2773 # main.ERROR - Some error in executing the function
2774 retainResults = main.TRUE
2775 for i in range( numControllers ):
2776 if retainResponses[ i ] == main.TRUE:
2777 # All is well
2778 pass
2779 elif retainResponses[ i ] == main.FALSE:
2780 # Already in set, probably fine
2781 pass
2782 elif retainResponses[ i ] == main.ERROR:
2783 # Error in execution
2784 retainResults = main.FALSE
2785 else:
2786 # unexpected result
2787 retainResults = main.FALSE
2788 if retainResults != main.TRUE:
2789 main.log.error( "Error executing set retain" )
2790
2791 # Check if set is still correct
2792 size = len( onosSet )
2793 getResponses = []
2794 threads = []
2795 for i in range( numControllers ):
2796 t = main.Thread( target=CLIs[i].setTestGet,
2797 name="setTestGet-" + str( i ),
2798 args=[ onosSetName ] )
2799 threads.append( t )
2800 t.start()
2801 for t in threads:
2802 t.join()
2803 getResponses.append( t.result )
2804 getResults = main.TRUE
2805 for i in range( numControllers ):
2806 if isinstance( getResponses[ i ], list):
2807 current = set( getResponses[ i ] )
2808 if len( current ) == len( getResponses[ i ] ):
2809 # no repeats
2810 if onosSet != current:
2811 main.log.error( "ONOS" + str( i + 1 ) +
2812 " has incorrect view" +
2813 " of set " + onosSetName + ":\n" +
2814 str( getResponses[ i ] ) )
2815 main.log.debug( "Expected: " + str( onosSet ) )
2816 main.log.debug( "Actual: " + str( current ) )
2817 getResults = main.FALSE
2818 else:
2819 # error, set is not a set
2820 main.log.error( "ONOS" + str( i + 1 ) +
2821 " has repeat elements in" +
2822 " set " + onosSetName + ":\n" +
2823 str( getResponses[ i ] ) )
2824 getResults = main.FALSE
2825 elif getResponses[ i ] == main.ERROR:
2826 getResults = main.FALSE
2827 sizeResponses = []
2828 threads = []
2829 for i in range( numControllers ):
2830 t = main.Thread( target=CLIs[i].setTestSize,
2831 name="setTestSize-" + str( i ),
2832 args=[ onosSetName ] )
2833 threads.append( t )
2834 t.start()
2835 for t in threads:
2836 t.join()
2837 sizeResponses.append( t.result )
2838 sizeResults = main.TRUE
2839 for i in range( numControllers ):
2840 if size != sizeResponses[ i ]:
2841 sizeResults = main.FALSE
2842 main.log.error( "ONOS" + str( i + 1 ) +
2843 " expected a size of " +
2844 str( size ) + " for set " + onosSetName +
2845 " but got " + str( sizeResponses[ i ] ) )
2846 retainResults = retainResults and getResults and sizeResults
2847 utilities.assert_equals( expect=main.TRUE,
2848 actual=retainResults,
2849 onpass="Set retain correct",
2850 onfail="Set retain was incorrect" )
2851