blob: 8f3c60452edea7a439dcdaef7b567a90f3e8e63c [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 """
Jon Hall40d2cbd2015-06-03 16:24:29 -070049 main.log.info( "ONOS Single node cluster restart " +
Jon Hall6aec96b2015-01-19 14:49:31 -080050 "HA test - initialization" )
51 main.case( "Setting up test environment" )
Jon Hallfeff3082015-05-19 10:23:26 -070052 main.caseExplaination = "Setup the test environment including " +\
53 "installing ONOS, starting Mininet and ONOS" +\
54 "cli sessions."
Jon Hall6aec96b2015-01-19 14:49:31 -080055 # TODO: save all the timers and output them for plotting
Jon Hall73cf9cc2014-11-20 22:28:38 -080056
Jon Hall5cfd23c2015-03-19 11:40:57 -070057 # load some variables from the params file
Jon Hall8f89dda2015-01-22 16:03:33 -080058 PULLCODE = False
Jon Hall6aec96b2015-01-19 14:49:31 -080059 if main.params[ 'Git' ] == 'True':
Jon Hall8f89dda2015-01-22 16:03:33 -080060 PULLCODE = True
Jon Hall529a37f2015-01-28 10:02:00 -080061 gitBranch = main.params[ 'branch' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080062 cellName = main.params[ 'ENV' ][ 'cellName' ]
Jon Hall6aec96b2015-01-19 14:49:31 -080063
64 # set global variables
Jon Hall8f89dda2015-01-22 16:03:33 -080065 global ONOS1Ip
66 global ONOS1Port
Jon Hall8f89dda2015-01-22 16:03:33 -080067 global ONOS2Port
Jon Hall8f89dda2015-01-22 16:03:33 -080068 global ONOS3Port
Jon Hall8f89dda2015-01-22 16:03:33 -080069 global ONOS4Port
Jon Hall8f89dda2015-01-22 16:03:33 -080070 global ONOS5Port
Jon Hall8f89dda2015-01-22 16:03:33 -080071 global ONOS6Port
Jon Hall8f89dda2015-01-22 16:03:33 -080072 global ONOS7Port
73 global numControllers
Jon Hall5cfd23c2015-03-19 11:40:57 -070074 numControllers = int( main.params[ 'num_controllers' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -080075
Jon Hall8f89dda2015-01-22 16:03:33 -080076 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
77 ONOS1Port = main.params[ 'CTRL' ][ 'port1' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080078 ONOS2Port = main.params[ 'CTRL' ][ 'port2' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080079 ONOS3Port = main.params[ 'CTRL' ][ 'port3' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080080 ONOS4Port = main.params[ 'CTRL' ][ 'port4' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080081 ONOS5Port = main.params[ 'CTRL' ][ 'port5' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080082 ONOS6Port = main.params[ 'CTRL' ][ 'port6' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080083 ONOS7Port = main.params[ 'CTRL' ][ 'port7' ]
Jon Hall73cf9cc2014-11-20 22:28:38 -080084
Jon Halla9d26da2015-03-30 16:45:32 -070085 global CLIs
86 CLIs = []
87 global nodes
88 nodes = []
89 for i in range( 1, numControllers + 1 ):
90 CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
91 nodes.append( getattr( main, 'ONOS' + str( i ) ) )
92
Jon Hall6aec96b2015-01-19 14:49:31 -080093 main.step( "Applying cell variable to environment" )
Jon Hall8f89dda2015-01-22 16:03:33 -080094 cellResult = main.ONOSbench.setCell( cellName )
95 verifyResult = main.ONOSbench.verifyCell()
Jon Hall73cf9cc2014-11-20 22:28:38 -080096
Jon Hall6aec96b2015-01-19 14:49:31 -080097 # FIXME:this is short term fix
Jon Hallfeff3082015-05-19 10:23:26 -070098 main.log.info( "Removing raft logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -080099 main.ONOSbench.onosRemoveRaftLogs()
Jon Halla9d26da2015-03-30 16:45:32 -0700100
Jon Hallfeff3082015-05-19 10:23:26 -0700101 main.log.info( "Uninstalling ONOS" )
Jon Halla9d26da2015-03-30 16:45:32 -0700102 for node in nodes:
103 main.ONOSbench.onosUninstall( node.ip_address )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800104
Jon Hall390696c2015-05-05 17:13:41 -0700105 # Make sure ONOS is DEAD
Jon Hallfeff3082015-05-19 10:23:26 -0700106 main.log.info( "Killing any ONOS processes" )
Jon Hall390696c2015-05-05 17:13:41 -0700107 killResults = main.TRUE
108 for node in nodes:
109 killed = main.ONOSbench.onosKill( node.ip_address )
110 killResults = killResults and killed
111
Jon Hall8f89dda2015-01-22 16:03:33 -0800112 cleanInstallResult = main.TRUE
113 gitPullResult = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800114
Jon Hall97f31752015-02-04 12:01:04 -0800115 main.step( "Starting Mininet" )
Jon Hall390696c2015-05-05 17:13:41 -0700116 mnResult = main.Mininet1.startNet( )
117 utilities.assert_equals( expect=main.TRUE, actual=mnResult,
118 onpass="Mininet Started",
119 onfail="Error starting Mininet" )
Jon Hall97f31752015-02-04 12:01:04 -0800120
Jon Hallfeff3082015-05-19 10:23:26 -0700121 main.step( "Git checkout and pull " + gitBranch )
Jon Hall8f89dda2015-01-22 16:03:33 -0800122 if PULLCODE:
Jon Hall529a37f2015-01-28 10:02:00 -0800123 main.ONOSbench.gitCheckout( gitBranch )
Jon Hall8f89dda2015-01-22 16:03:33 -0800124 gitPullResult = main.ONOSbench.gitPull()
Jon Hall390696c2015-05-05 17:13:41 -0700125 # values of 1 or 3 are good
126 utilities.assert_lesser( expect=0, actual=gitPullResult,
127 onpass="Git pull successful",
128 onfail="Git pull failed" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800129 main.ONOSbench.getVersion( report=True )
Jon Hallfeff3082015-05-19 10:23:26 -0700130
131 main.step( "Using mvn clean install" )
132 cleanInstallResult = main.TRUE
Jon Hall40d2cbd2015-06-03 16:24:29 -0700133 if PULLCODE and gitPullResult == main.TRUE:
Jon Hallfeff3082015-05-19 10:23:26 -0700134 cleanInstallResult = main.ONOSbench.cleanInstall()
Jon Hall40d2cbd2015-06-03 16:24:29 -0700135 else:
136 main.log.warn( "Did not pull new code so skipping mvn " +
137 "clean install" )
Jon Hallfeff3082015-05-19 10:23:26 -0700138 utilities.assert_equals( expect=main.TRUE,
139 actual=cleanInstallResult,
140 onpass="MCI successful",
141 onfail="MCI failed" )
Jon Hall390696c2015-05-05 17:13:41 -0700142 # GRAPHS
143 # NOTE: important params here:
144 # job = name of Jenkins job
145 # Plot Name = Plot-HA, only can be used if multiple plots
146 # index = The number of the graph under plot name
147 job = "HASingleInstanceRestart"
Jon Hall40d2cbd2015-06-03 16:24:29 -0700148 plotName = "Plot-HA"
Jon Hall390696c2015-05-05 17:13:41 -0700149 graphs = '<ac:structured-macro ac:name="html">\n'
150 graphs += '<ac:plain-text-body><![CDATA[\n'
151 graphs += '<iframe src="https://onos-jenkins.onlab.us/job/' + job +\
Jon Hall40d2cbd2015-06-03 16:24:29 -0700152 '/plot/' + plotName + '/getPlot?index=0' +\
153 '&width=500&height=300"' +\
Jon Hall390696c2015-05-05 17:13:41 -0700154 'noborder="0" width="500" height="300" scrolling="yes" ' +\
155 'seamless="seamless"></iframe>\n'
156 graphs += ']]></ac:plain-text-body>\n'
157 graphs += '</ac:structured-macro>\n'
158 main.log.wiki(graphs)
Jon Hall73cf9cc2014-11-20 22:28:38 -0800159
Jon Hall8f89dda2015-01-22 16:03:33 -0800160 cellResult = main.ONOSbench.setCell( "SingleHA" )
161 verifyResult = main.ONOSbench.verifyCell()
Jon Hall6aec96b2015-01-19 14:49:31 -0800162 main.step( "Creating ONOS package" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800163 packageResult = main.ONOSbench.onosPackage()
Jon Hall390696c2015-05-05 17:13:41 -0700164 utilities.assert_equals( expect=main.TRUE, actual=packageResult,
165 onpass="ONOS package successful",
166 onfail="ONOS package failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800167
Jon Hall6aec96b2015-01-19 14:49:31 -0800168 main.step( "Installing ONOS package" )
Jon Hall390696c2015-05-05 17:13:41 -0700169 onosInstallResult = main.ONOSbench.onosInstall( options="-f",
Jon Hall8f89dda2015-01-22 16:03:33 -0800170 node=ONOS1Ip )
Jon Hall390696c2015-05-05 17:13:41 -0700171 utilities.assert_equals( expect=main.TRUE, actual=onosInstallResult,
172 onpass="ONOS install successful",
173 onfail="ONOS install failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800174
Jon Hall6aec96b2015-01-19 14:49:31 -0800175 main.step( "Checking if ONOS is up yet" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800176 for i in range( 2 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800177 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
178 if onos1Isup:
Jon Hall94fd0472014-12-08 11:52:42 -0800179 break
Jon Hall390696c2015-05-05 17:13:41 -0700180 utilities.assert_equals( expect=main.TRUE, actual=onos1Isup,
181 onpass="ONOS startup successful",
182 onfail="ONOS startup failed" )
Jon Hall94fd0472014-12-08 11:52:42 -0800183
Jon Hall390696c2015-05-05 17:13:41 -0700184 main.log.step( "Starting ONOS CLI sessions" )
185 cliResults = main.ONOScli1.startOnosCli( ONOS1Ip )
186 utilities.assert_equals( expect=main.TRUE, actual=cliResults,
187 onpass="ONOS cli startup successful",
188 onfail="ONOS cli startup failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800189
Jon Hall40d2cbd2015-06-03 16:24:29 -0700190 if main.params[ 'tcpdump' ].lower() == "true":
191 main.step( "Start Packet Capture MN" )
192 main.Mininet2.startTcpdump(
193 str( main.params[ 'MNtcpdump' ][ 'folder' ] ) + str( main.TEST )
194 + "-MN.pcap",
195 intf=main.params[ 'MNtcpdump' ][ 'intf' ],
196 port=main.params[ 'MNtcpdump' ][ 'port' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800197
Jon Hall390696c2015-05-05 17:13:41 -0700198 main.step( "App Ids check" )
Jon Hallfeff3082015-05-19 10:23:26 -0700199 appCheck = main.ONOScli1.appToIDCheck()
Jon Hall390696c2015-05-05 17:13:41 -0700200 if appCheck != main.TRUE:
201 main.log.warn( CLIs[0].apps() )
202 main.log.warn( CLIs[0].appIDs() )
203 utilities.assert_equals( expect=main.TRUE, actual=appCheck,
204 onpass="App Ids seem to be correct",
205 onfail="Something is wrong with app Ids" )
206
Jon Hallfeff3082015-05-19 10:23:26 -0700207 if cliResults == main.FALSE:
208 main.log.error( "Failed to start ONOS, stopping test" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800209 main.cleanup()
210 main.exit()
211
Jon Hall6aec96b2015-01-19 14:49:31 -0800212 def CASE2( self, main ):
213 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800214 Assign mastership to controllers
Jon Hall6aec96b2015-01-19 14:49:31 -0800215 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800216 import re
Jon Hall5cfd23c2015-03-19 11:40:57 -0700217 assert numControllers, "numControllers not defined"
218 assert main, "main not defined"
219 assert utilities.assert_equals, "utilities.assert_equals not defined"
220 assert ONOS1Port, "ONOS1Port not defined"
221 assert ONOS2Port, "ONOS2Port not defined"
222 assert ONOS3Port, "ONOS3Port not defined"
223 assert ONOS4Port, "ONOS4Port not defined"
224 assert ONOS5Port, "ONOS5Port not defined"
225 assert ONOS6Port, "ONOS6Port not defined"
226 assert ONOS7Port, "ONOS7Port not defined"
Jon Hall73cf9cc2014-11-20 22:28:38 -0800227
Jon Hall6aec96b2015-01-19 14:49:31 -0800228 main.case( "Assigning Controllers" )
Jon Hallfeff3082015-05-19 10:23:26 -0700229 main.caseExplaination = "Assign switches to ONOS using 'ovs-vsctl' " +\
230 "and check that an ONOS node becomes the " +\
231 "master of the device."
Jon Hall6aec96b2015-01-19 14:49:31 -0800232 main.step( "Assign switches to controllers" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800233
Jon Hall6aec96b2015-01-19 14:49:31 -0800234 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800235 main.Mininet1.assignSwController(
Jon Hall6aec96b2015-01-19 14:49:31 -0800236 sw=str( i ),
Jon Hall8f89dda2015-01-22 16:03:33 -0800237 ip1=ONOS1Ip, port1=ONOS1Port )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800238
Jon Hall8f89dda2015-01-22 16:03:33 -0800239 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800240 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800241 response = main.Mininet1.getSwController( "s" + str( i ) )
Jon Hallffb386d2014-11-21 13:43:38 -0800242 try:
Jon Hall6aec96b2015-01-19 14:49:31 -0800243 main.log.info( str( response ) )
Jon Hallfebb1c72015-03-05 13:30:09 -0800244 except Exception:
Jon Hall6aec96b2015-01-19 14:49:31 -0800245 main.log.info( repr( response ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800246 if re.search( "tcp:" + ONOS1Ip, response ):
247 mastershipCheck = mastershipCheck and main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800248 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800249 mastershipCheck = main.FALSE
250 if mastershipCheck == main.TRUE:
Jon Hallfeff3082015-05-19 10:23:26 -0700251 main.log.info( "Switch mastership assigned correctly" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800252 utilities.assert_equals(
253 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800254 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800255 onpass="Switch mastership assigned correctly",
256 onfail="Switches not assigned correctly to controllers" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800257
Jon Hall390696c2015-05-05 17:13:41 -0700258 main.step( "Assign mastership of switches to specific controllers" )
Jon Halla9d26da2015-03-30 16:45:32 -0700259 roleCall = main.TRUE
260 roleCheck = main.TRUE
261 try:
262 for i in range( 1, 29 ): # switches 1 through 28
263 ip = nodes[ 0 ].ip_address # ONOS1
264 # set up correct variables:
265 if i == 1:
266 deviceId = main.ONOScli1.getDevice( "1000" ).get( 'id' )
267 elif i == 2:
268 deviceId = main.ONOScli1.getDevice( "2000" ).get( 'id' )
269 elif i == 3:
270 deviceId = main.ONOScli1.getDevice( "3000" ).get( 'id' )
271 elif i == 4:
272 deviceId = main.ONOScli1.getDevice( "3004" ).get( 'id' )
273 elif i == 5:
274 deviceId = main.ONOScli1.getDevice( "5000" ).get( 'id' )
275 elif i == 6:
276 deviceId = main.ONOScli1.getDevice( "6000" ).get( 'id' )
277 elif i == 7:
278 deviceId = main.ONOScli1.getDevice( "6007" ).get( 'id' )
279 elif i >= 8 and i <= 17:
280 dpid = '3' + str( i ).zfill( 3 )
281 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
282 elif i >= 18 and i <= 27:
283 dpid = '6' + str( i ).zfill( 3 )
284 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
285 elif i == 28:
286 deviceId = main.ONOScli1.getDevice( "2800" ).get( 'id' )
287 else:
288 main.log.error( "You didn't write an else statement for " +
289 "switch s" + str( i ) )
290 # Assign switch
291 assert deviceId, "No device id for s" + str( i ) + " in ONOS"
292 # TODO: make this controller dynamic
293 roleCall = roleCall and main.ONOScli1.deviceRole( deviceId,
294 ip )
295 # Check assignment
Jon Hall390696c2015-05-05 17:13:41 -0700296 master = main.ONOScli1.getRole( deviceId ).get( 'master' )
Jon Hall678f4512015-03-31 09:48:31 -0700297 if ip in master:
Jon Halla9d26da2015-03-30 16:45:32 -0700298 roleCheck = roleCheck and main.TRUE
299 else:
300 roleCheck = roleCheck and main.FALSE
301 main.log.error( "Error, controller " + ip + " is not" +
302 " master " + "of device " +
Jon Hall678f4512015-03-31 09:48:31 -0700303 str( deviceId ) + ". Master is " +
304 repr( master ) + "." )
Jon Halla9d26da2015-03-30 16:45:32 -0700305 except ( AttributeError, AssertionError ):
306 main.log.exception( "Something is wrong with ONOS device view" )
307 main.log.info( main.ONOScli1.devices() )
308 utilities.assert_equals(
309 expect=main.TRUE,
310 actual=roleCall,
311 onpass="Re-assigned switch mastership to designated controller",
312 onfail="Something wrong with deviceRole calls" )
313
Jon Hall390696c2015-05-05 17:13:41 -0700314 main.step( "Check mastership was correctly assigned" )
Jon Halla9d26da2015-03-30 16:45:32 -0700315 utilities.assert_equals(
316 expect=main.TRUE,
317 actual=roleCheck,
318 onpass="Switches were successfully reassigned to designated " +
319 "controller",
320 onfail="Switches were not successfully reassigned" )
321 mastershipCheck = mastershipCheck and roleCall and roleCheck
322 utilities.assert_equals( expect=main.TRUE, actual=mastershipCheck,
323 onpass="Switch mastership correctly assigned",
324 onfail="Error in (re)assigning switch" +
325 " mastership" )
326
Jon Hall6aec96b2015-01-19 14:49:31 -0800327 def CASE3( self, main ):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800328 """
329 Assign intents
Jon Hall73cf9cc2014-11-20 22:28:38 -0800330 """
331 import time
Jon Hallfebb1c72015-03-05 13:30:09 -0800332 import json
Jon Hall5cfd23c2015-03-19 11:40:57 -0700333 assert numControllers, "numControllers not defined"
334 assert main, "main not defined"
335 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hallfeff3082015-05-19 10:23:26 -0700336 # NOTE: we must reinstall intents until we have a persistant intent
337 # datastore!
Jon Hall6aec96b2015-01-19 14:49:31 -0800338 main.case( "Adding host Intents" )
Jon Hallfeff3082015-05-19 10:23:26 -0700339 main.caseExplaination = "Discover hosts by using pingall then " +\
340 "assign predetermined host-to-host intents." +\
341 " After installation, check that the intent" +\
342 " is distributed to all nodes and the state" +\
343 " is INSTALLED"
Jon Hall73cf9cc2014-11-20 22:28:38 -0800344
Jon Hall6aec96b2015-01-19 14:49:31 -0800345 # install onos-app-fwd
Jon Hall390696c2015-05-05 17:13:41 -0700346 main.step( "Install reactive forwarding app" )
347 installResults = CLIs[0].activateApp( "org.onosproject.fwd" )
348 utilities.assert_equals( expect=main.TRUE, actual=installResults,
349 onpass="Install fwd successful",
350 onfail="Install fwd failed" )
Jon Halla9d26da2015-03-30 16:45:32 -0700351
Jon Hallfeff3082015-05-19 10:23:26 -0700352 main.step( "Check app ids" )
Jon Halla9d26da2015-03-30 16:45:32 -0700353 appCheck = main.ONOScli1.appToIDCheck()
354 if appCheck != main.TRUE:
355 main.log.warn( CLIs[0].apps() )
356 main.log.warn( CLIs[0].appIDs() )
Jon Hall390696c2015-05-05 17:13:41 -0700357 utilities.assert_equals( expect=main.TRUE, actual=appCheck,
358 onpass="App Ids seem to be correct",
359 onfail="Something is wrong with app Ids" )
Jon Hall94fd0472014-12-08 11:52:42 -0800360
Jon Hallfeff3082015-05-19 10:23:26 -0700361 main.step( "Discovering Hosts( Via pingall for now )" )
362 # FIXME: Once we have a host discovery mechanism, use that instead
Jon Hall6aec96b2015-01-19 14:49:31 -0800363 # REACTIVE FWD test
Jon Hall8f89dda2015-01-22 16:03:33 -0800364 pingResult = main.FALSE
Jon Hall5cfd23c2015-03-19 11:40:57 -0700365 for i in range(2): # Retry if pingall fails first time
366 time1 = time.time()
367 pingResult = main.Mininet1.pingall()
368 utilities.assert_equals(
369 expect=main.TRUE,
370 actual=pingResult,
371 onpass="Reactive Pingall test passed",
Jon Hall390696c2015-05-05 17:13:41 -0700372 onfail="Reactive Pingall failed, " +
373 "one or more ping pairs failed" )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700374 time2 = time.time()
Jon Hall390696c2015-05-05 17:13:41 -0700375 main.log.info( "Time for pingall: %2f seconds" %
376 ( time2 - time1 ) )
377 # timeout for fwd flows
378 time.sleep( 11 )
Jon Hall6aec96b2015-01-19 14:49:31 -0800379 # uninstall onos-app-fwd
Jon Hall390696c2015-05-05 17:13:41 -0700380 main.step( "Uninstall reactive forwarding app" )
381 uninstallResult = CLIs[0].deactivateApp( "org.onosproject.fwd" )
382 utilities.assert_equals( expect=main.TRUE, actual=uninstallResult,
383 onpass="Uninstall fwd successful",
384 onfail="Uninstall fwd failed" )
Jon Hallfeff3082015-05-19 10:23:26 -0700385
386 main.step( "Check app ids" )
Jon Halla9d26da2015-03-30 16:45:32 -0700387 appCheck2 = main.ONOScli1.appToIDCheck()
388 if appCheck2 != main.TRUE:
389 main.log.warn( CLIs[0].apps() )
390 main.log.warn( CLIs[0].appIDs() )
Jon Hall390696c2015-05-05 17:13:41 -0700391 utilities.assert_equals( expect=main.TRUE, actual=appCheck2,
392 onpass="App Ids seem to be correct",
393 onfail="Something is wrong with app Ids" )
Jon Halla9d26da2015-03-30 16:45:32 -0700394
Jon Hallfeff3082015-05-19 10:23:26 -0700395 main.step( "Add host intents via cli" )
Jon Hall58c76b72015-02-23 11:09:24 -0800396 intentIds = []
Jon Hall6aec96b2015-01-19 14:49:31 -0800397 # TODO: move the host numbers to params
Jon Hall58c76b72015-02-23 11:09:24 -0800398 # Maybe look at all the paths we ping?
Jon Hall8f89dda2015-01-22 16:03:33 -0800399 intentAddResult = True
Jon Hall58c76b72015-02-23 11:09:24 -0800400 hostResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800401 for i in range( 8, 18 ):
402 main.log.info( "Adding host intent between h" + str( i ) +
403 " and h" + str( i + 10 ) )
404 host1 = "00:00:00:00:00:" + \
405 str( hex( i )[ 2: ] ).zfill( 2 ).upper()
406 host2 = "00:00:00:00:00:" + \
407 str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper()
Jon Hall1b8f54a2015-02-04 13:24:20 -0800408 # NOTE: getHost can return None
409 host1Dict = main.ONOScli1.getHost( host1 )
410 host2Dict = main.ONOScli1.getHost( host2 )
411 host1Id = None
412 host2Id = None
413 if host1Dict and host2Dict:
414 host1Id = host1Dict.get( 'id', None )
415 host2Id = host2Dict.get( 'id', None )
Jon Hall8f89dda2015-01-22 16:03:33 -0800416 if host1Id and host2Id:
Jon Halla9d26da2015-03-30 16:45:32 -0700417 tmpId = main.ONOScli1.addHostIntent( host1Id, host2Id )
Jon Hall63604932015-02-26 17:09:50 -0800418 if tmpId:
419 main.log.info( "Added intent with id: " + tmpId )
420 intentIds.append( tmpId )
421 else:
Jon Halla9d26da2015-03-30 16:45:32 -0700422 main.log.error( "addHostIntent returned: " +
423 repr( tmpId ) )
Jon Hall669173b2014-12-17 11:36:30 -0800424 else:
Jon Halla9d26da2015-03-30 16:45:32 -0700425 main.log.error( "Error, getHost() failed for h" + str( i ) +
426 " and/or h" + str( i + 10 ) )
427 hosts = main.ONOScli1.hosts()
428 main.log.warn( "Hosts output: " )
429 try:
430 main.log.warn( json.dumps( json.loads( hosts ),
431 sort_keys=True,
432 indent=4,
433 separators=( ',', ': ' ) ) )
434 except ( ValueError, TypeError ):
435 main.log.warn( repr( hosts ) )
Jon Hall58c76b72015-02-23 11:09:24 -0800436 hostResult = main.FALSE
Jon Hallfeff3082015-05-19 10:23:26 -0700437 utilities.assert_equals( expect=main.TRUE, actual=hostResult,
438 onpass="Found a host id for each host",
439 onfail="Error looking up host ids" )
440
Jon Halla9d26da2015-03-30 16:45:32 -0700441 intentStart = time.time()
Jon Hall58c76b72015-02-23 11:09:24 -0800442 onosIds = main.ONOScli1.getAllIntentsId()
443 main.log.info( "Submitted intents: " + str( intentIds ) )
444 main.log.info( "Intents in ONOS: " + str( onosIds ) )
445 for intent in intentIds:
446 if intent in onosIds:
Jon Halla9d26da2015-03-30 16:45:32 -0700447 pass # intent submitted is in onos
Jon Hall58c76b72015-02-23 11:09:24 -0800448 else:
449 intentAddResult = False
Jon Halla9d26da2015-03-30 16:45:32 -0700450 # FIXME: DEBUG
451 if intentAddResult:
452 intentStop = time.time()
453 else:
454 intentStop = None
Jon Hall1b8f54a2015-02-04 13:24:20 -0800455 # Print the intent states
Jon Hall58c76b72015-02-23 11:09:24 -0800456 intents = main.ONOScli1.intents()
Jon Hall1b8f54a2015-02-04 13:24:20 -0800457 intentStates = []
Jon Halla9d26da2015-03-30 16:45:32 -0700458 installedCheck = True
Jon Hall58c76b72015-02-23 11:09:24 -0800459 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
460 count = 0
Jon Hall5cfd23c2015-03-19 11:40:57 -0700461 try:
462 for intent in json.loads( intents ):
463 state = intent.get( 'state', None )
464 if "INSTALLED" not in state:
465 installedCheck = False
466 intentId = intent.get( 'id', None )
467 intentStates.append( ( intentId, state ) )
468 except ( ValueError, TypeError ):
469 main.log.exception( "Error parsing intents" )
Jon Hall58c76b72015-02-23 11:09:24 -0800470 # add submitted intents not in the store
471 tmplist = [ i for i, s in intentStates ]
472 missingIntents = False
473 for i in intentIds:
474 if i not in tmplist:
475 intentStates.append( ( i, " - " ) )
476 missingIntents = True
477 intentStates.sort()
478 for i, s in intentStates:
479 count += 1
480 main.log.info( "%-6s%-15s%-15s" %
481 ( str( count ), str( i ), str( s ) ) )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700482 leaders = main.ONOScli1.leaders()
483 try:
484 if leaders:
485 parsedLeaders = json.loads( leaders )
486 main.log.warn( json.dumps( parsedLeaders,
487 sort_keys=True,
488 indent=4,
489 separators=( ',', ': ' ) ) )
490 # check for all intent partitions
Jon Hall5cfd23c2015-03-19 11:40:57 -0700491 topics = []
492 for i in range( 14 ):
493 topics.append( "intent-partition-" + str( i ) )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700494 main.log.debug( topics )
495 ONOStopics = [ j['topic'] for j in parsedLeaders ]
496 for topic in topics:
497 if topic not in ONOStopics:
498 main.log.error( "Error: " + topic +
499 " not in leaders" )
500 else:
501 main.log.error( "leaders() returned None" )
502 except ( ValueError, TypeError ):
503 main.log.exception( "Error parsing leaders" )
504 main.log.error( repr( leaders ) )
505 partitions = main.ONOScli1.partitions()
506 try:
507 if partitions :
508 parsedPartitions = json.loads( partitions )
509 main.log.warn( json.dumps( parsedPartitions,
510 sort_keys=True,
511 indent=4,
512 separators=( ',', ': ' ) ) )
513 # TODO check for a leader in all paritions
514 # TODO check for consistency among nodes
515 else:
516 main.log.error( "partitions() returned None" )
517 except ( ValueError, TypeError ):
518 main.log.exception( "Error parsing partitions" )
519 main.log.error( repr( partitions ) )
Jon Hall63604932015-02-26 17:09:50 -0800520 pendingMap = main.ONOScli1.pendingMap()
Jon Hall5cfd23c2015-03-19 11:40:57 -0700521 try:
522 if pendingMap :
523 parsedPending = json.loads( pendingMap )
524 main.log.warn( json.dumps( parsedPending,
525 sort_keys=True,
526 indent=4,
527 separators=( ',', ': ' ) ) )
528 # TODO check something here?
529 else:
530 main.log.error( "pendingMap() returned None" )
531 except ( ValueError, TypeError ):
532 main.log.exception( "Error parsing pending map" )
533 main.log.error( repr( pendingMap ) )
534
Jon Hallfeff3082015-05-19 10:23:26 -0700535 intentAddResult = bool( intentAddResult and not missingIntents and
536 installedCheck )
537 if not intentAddResult:
538 main.log.error( "Error in pushing host intents to ONOS" )
539
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 Hallfeff3082015-05-19 10:23:26 -0700670 main.case( "Verify connectivity by sendind traffic across Intents" )
671 main.caseExplaination = "Ping across added host intents to check " +\
672 "functionality and check the state of " +\
673 "the intent"
674 main.step( "Ping across added host intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800675 PingResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800676 for i in range( 8, 18 ):
Jon Hall58c76b72015-02-23 11:09:24 -0800677 ping = main.Mininet1.pingHost( src="h" + str( i ),
678 target="h" + str( i + 10 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800679 PingResult = PingResult and ping
Jon Hall6aec96b2015-01-19 14:49:31 -0800680 if ping == main.FALSE:
681 main.log.warn( "Ping failed between h" + str( i ) +
682 " and h" + str( i + 10 ) )
683 elif ping == main.TRUE:
684 main.log.info( "Ping test passed!" )
Jon Hall21270ac2015-02-16 17:59:55 -0800685 # Don't set PingResult or you'd override failures
Jon Hall8f89dda2015-01-22 16:03:33 -0800686 if PingResult == main.FALSE:
Jon Hall40d2cbd2015-06-03 16:24:29 -0700687 main.log.error(
Jon Hall6aec96b2015-01-19 14:49:31 -0800688 "Intents have not been installed correctly, pings failed." )
Jon Hall58c76b72015-02-23 11:09:24 -0800689 # TODO: pretty print
Jon Hall5cfd23c2015-03-19 11:40:57 -0700690 main.log.warn( "ONOS1 intents: " )
691 try:
692 tmpIntents = main.ONOScli1.intents()
693 main.log.warn( json.dumps( json.loads( tmpIntents ),
694 sort_keys=True,
695 indent=4,
696 separators=( ',', ': ' ) ) )
697 except ( ValueError, TypeError ):
698 main.log.warn( repr( tmpIntents ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800699 utilities.assert_equals(
700 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800701 actual=PingResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800702 onpass="Intents have been installed correctly and pings work",
703 onfail="Intents have not been installed correctly, pings failed." )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800704
Jon Hallfeff3082015-05-19 10:23:26 -0700705 main.step( "Check Intent state" )
Jon Hall63604932015-02-26 17:09:50 -0800706 installedCheck = True
Jon Hallfeff3082015-05-19 10:23:26 -0700707 # Print the intent states
708 intents = main.ONOScli1.intents()
709 intentStates = []
710 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
711 count = 0
712 # Iter through intents of a node
713 try:
714 for intent in json.loads( intents ):
715 state = intent.get( 'state', None )
716 if "INSTALLED" not in state:
717 installedCheck = False
718 intentId = intent.get( 'id', None )
719 intentStates.append( ( intentId, state ) )
720 except ( ValueError, TypeError ):
721 main.log.exception( "Error parsing intents." )
722 # Print states
723 intentStates.sort()
724 for i, s in intentStates:
725 count += 1
726 main.log.info( "%-6s%-15s%-15s" %
727 ( str( count ), str( i ), str( s ) ) )
728 utilities.assert_equals( expect=True, actual=installedCheck,
729 onpass="Intents are all INSTALLED",
Jon Hall40d2cbd2015-06-03 16:24:29 -0700730 onfail="Intents are not all in " +
Jon Hallfeff3082015-05-19 10:23:26 -0700731 "INSTALLED state" )
732
733 main.step( "Check leadership of topics" )
734 leaders = main.ONOScli1.leaders()
735 topicCheck = main.TRUE
736 try:
737 if leaders:
738 parsedLeaders = json.loads( leaders )
739 main.log.warn( json.dumps( parsedLeaders,
740 sort_keys=True,
741 indent=4,
742 separators=( ',', ': ' ) ) )
743 # check for all intent partitions
744 # check for election
745 # TODO: Look at Devices as topics now that it uses this system
746 topics = []
747 for i in range( 14 ):
748 topics.append( "intent-partition-" + str( i ) )
749 # FIXME: this should only be after we start the app
750 # FIXME: topics.append( "org.onosproject.election" )
751 # Print leaders output
752 main.log.debug( topics )
753 ONOStopics = [ j['topic'] for j in parsedLeaders ]
754 for topic in topics:
755 if topic not in ONOStopics:
756 main.log.error( "Error: " + topic +
757 " not in leaders" )
758 topicCheck = main.FALSE
759 else:
760 main.log.error( "leaders() returned None" )
761 topicCheck = main.FALSE
762 except ( ValueError, TypeError ):
763 topicCheck = main.FALSE
764 main.log.exception( "Error parsing leaders" )
765 main.log.error( repr( leaders ) )
766 # TODO: Check for a leader of these topics
767 utilities.assert_equals( expect=main.TRUE, actual=topicCheck,
768 onpass="intent Partitions is in leaders",
769 onfail="Some topics were lost " )
770 # Print partitions
771 partitions = main.ONOScli1.partitions()
772 try:
773 if partitions :
774 parsedPartitions = json.loads( partitions )
775 main.log.warn( json.dumps( parsedPartitions,
776 sort_keys=True,
777 indent=4,
778 separators=( ',', ': ' ) ) )
779 # TODO check for a leader in all paritions
780 # TODO check for consistency among nodes
781 else:
782 main.log.error( "partitions() returned None" )
783 except ( ValueError, TypeError ):
784 main.log.exception( "Error parsing partitions" )
785 main.log.error( repr( partitions ) )
786 # Print Pending Map
787 pendingMap = main.ONOScli1.pendingMap()
788 try:
789 if pendingMap :
790 parsedPending = json.loads( pendingMap )
791 main.log.warn( json.dumps( parsedPending,
792 sort_keys=True,
793 indent=4,
794 separators=( ',', ': ' ) ) )
795 # TODO check something here?
796 else:
797 main.log.error( "pendingMap() returned None" )
798 except ( ValueError, TypeError ):
799 main.log.exception( "Error parsing pending map" )
800 main.log.error( repr( pendingMap ) )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700801
Jon Hall63604932015-02-26 17:09:50 -0800802 if not installedCheck:
Jon Hall5cfd23c2015-03-19 11:40:57 -0700803 main.log.info( "Waiting 60 seconds to see if the state of " +
804 "intents change" )
Jon Hall63604932015-02-26 17:09:50 -0800805 time.sleep( 60 )
806 # Print the intent states
807 intents = main.ONOScli1.intents()
808 intentStates = []
809 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
810 count = 0
811 # Iter through intents of a node
Jon Hall5cfd23c2015-03-19 11:40:57 -0700812 try:
813 for intent in json.loads( intents ):
814 state = intent.get( 'state', None )
815 if "INSTALLED" not in state:
816 installedCheck = False
817 intentId = intent.get( 'id', None )
818 intentStates.append( ( intentId, state ) )
819 except ( ValueError, TypeError ):
820 main.log.exception( "Error parsing intents." )
Jon Hall63604932015-02-26 17:09:50 -0800821 intentStates.sort()
822 for i, s in intentStates:
823 count += 1
824 main.log.info( "%-6s%-15s%-15s" %
825 ( str( count ), str( i ), str( s ) ) )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700826 leaders = main.ONOScli1.leaders()
827 try:
828 if leaders:
829 parsedLeaders = json.loads( leaders )
830 main.log.warn( json.dumps( parsedLeaders,
831 sort_keys=True,
832 indent=4,
833 separators=( ',', ': ' ) ) )
834 # check for all intent partitions
835 # check for election
836 topics = []
837 for i in range( 14 ):
838 topics.append( "intent-partition-" + str( i ) )
839 # FIXME: this should only be after we start the app
840 topics.append( "org.onosproject.election" )
841 main.log.debug( topics )
842 ONOStopics = [ j['topic'] for j in parsedLeaders ]
843 for topic in topics:
844 if topic not in ONOStopics:
845 main.log.error( "Error: " + topic +
846 " not in leaders" )
847 else:
848 main.log.error( "leaders() returned None" )
849 except ( ValueError, TypeError ):
850 main.log.exception( "Error parsing leaders" )
851 main.log.error( repr( leaders ) )
852 partitions = main.ONOScli1.partitions()
853 try:
854 if partitions :
855 parsedPartitions = json.loads( partitions )
856 main.log.warn( json.dumps( parsedPartitions,
857 sort_keys=True,
858 indent=4,
859 separators=( ',', ': ' ) ) )
860 # TODO check for a leader in all paritions
861 # TODO check for consistency among nodes
862 else:
863 main.log.error( "partitions() returned None" )
864 except ( ValueError, TypeError ):
865 main.log.exception( "Error parsing partitions" )
866 main.log.error( repr( partitions ) )
867 pendingMap = main.ONOScli1.pendingMap()
868 try:
869 if pendingMap :
870 parsedPending = json.loads( pendingMap )
871 main.log.warn( json.dumps( parsedPending,
872 sort_keys=True,
873 indent=4,
874 separators=( ',', ': ' ) ) )
875 # TODO check something here?
876 else:
877 main.log.error( "pendingMap() returned None" )
878 except ( ValueError, TypeError ):
879 main.log.exception( "Error parsing pending map" )
880 main.log.error( repr( pendingMap ) )
Jon Hall40d2cbd2015-06-03 16:24:29 -0700881 # Print flowrules
882 main.log.debug( CLIs[0].flows( jsonFormat=False ) )
Jon Hallfeff3082015-05-19 10:23:26 -0700883 main.step( "Wait a minute then ping again" )
Jon Hall40d2cbd2015-06-03 16:24:29 -0700884 # the wait is above
Jon Hallfeff3082015-05-19 10:23:26 -0700885 PingResult = main.TRUE
886 for i in range( 8, 18 ):
887 ping = main.Mininet1.pingHost( src="h" + str( i ),
888 target="h" + str( i + 10 ) )
889 PingResult = PingResult and ping
890 if ping == main.FALSE:
891 main.log.warn( "Ping failed between h" + str( i ) +
892 " and h" + str( i + 10 ) )
893 elif ping == main.TRUE:
894 main.log.info( "Ping test passed!" )
895 # Don't set PingResult or you'd override failures
896 if PingResult == main.FALSE:
Jon Hall40d2cbd2015-06-03 16:24:29 -0700897 main.log.error(
Jon Hallfeff3082015-05-19 10:23:26 -0700898 "Intents have not been installed correctly, pings failed." )
899 # TODO: pretty print
900 main.log.warn( "ONOS1 intents: " )
901 try:
902 tmpIntents = main.ONOScli1.intents()
903 main.log.warn( json.dumps( json.loads( tmpIntents ),
904 sort_keys=True,
905 indent=4,
906 separators=( ',', ': ' ) ) )
907 except ( ValueError, TypeError ):
908 main.log.warn( repr( tmpIntents ) )
909 utilities.assert_equals(
910 expect=main.TRUE,
911 actual=PingResult,
912 onpass="Intents have been installed correctly and pings work",
913 onfail="Intents have not been installed correctly, pings failed." )
914
Jon Hall6aec96b2015-01-19 14:49:31 -0800915 def CASE5( self, main ):
916 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800917 Reading state of ONOS
Jon Hall6aec96b2015-01-19 14:49:31 -0800918 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800919 import json
Jon Hall5cfd23c2015-03-19 11:40:57 -0700920 assert numControllers, "numControllers not defined"
921 assert main, "main not defined"
922 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -0800923 # assumes that sts is already in you PYTHONPATH
924 from sts.topology.teston_topology import TestONTopology
Jon Hall73cf9cc2014-11-20 22:28:38 -0800925
Jon Hall6aec96b2015-01-19 14:49:31 -0800926 main.case( "Setting up and gathering data for current state" )
927 # The general idea for this test case is to pull the state of
928 # ( intents,flows, topology,... ) from each ONOS node
Jon Hall5cfd23c2015-03-19 11:40:57 -0700929 # We can then compare them with each other and also with past states
Jon Hall73cf9cc2014-11-20 22:28:38 -0800930
Jon Halla9d26da2015-03-30 16:45:32 -0700931 main.step( "Check that each switch has a master" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800932 global mastershipState
Jon Halla9d26da2015-03-30 16:45:32 -0700933 mastershipState = '[]'
Jon Hall94fd0472014-12-08 11:52:42 -0800934
Jon Hall6aec96b2015-01-19 14:49:31 -0800935 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -0800936 rolesNotNull = main.ONOScli1.rolesNotNull()
Jon Hall6aec96b2015-01-19 14:49:31 -0800937 utilities.assert_equals(
938 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800939 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -0800940 onpass="Each device has a master",
941 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -0800942
Jon Hall390696c2015-05-05 17:13:41 -0700943 main.step( "Get the Mastership of each switch" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800944 ONOS1Mastership = main.ONOScli1.roles()
Jon Hall6aec96b2015-01-19 14:49:31 -0800945 # TODO: Make this a meaningful check
Jon Hall8f89dda2015-01-22 16:03:33 -0800946 if "Error" in ONOS1Mastership or not ONOS1Mastership:
Jon Hall40d2cbd2015-06-03 16:24:29 -0700947 main.log.error( "Error in getting ONOS roles" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800948 main.log.warn(
949 "ONOS1 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800950 repr( ONOS1Mastership ) )
951 consistentMastership = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800952 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800953 mastershipState = ONOS1Mastership
954 consistentMastership = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800955
Jon Hall6aec96b2015-01-19 14:49:31 -0800956 main.step( "Get the intents from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800957 global intentState
958 intentState = []
959 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
960 intentCheck = main.FALSE
961 if "Error" in ONOS1Intents or not ONOS1Intents:
Jon Hall40d2cbd2015-06-03 16:24:29 -0700962 main.log.error( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800963 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800964 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800965 intentCheck = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800966
Jon Hall6aec96b2015-01-19 14:49:31 -0800967 main.step( "Get the flows from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800968 global flowState
969 flowState = []
Jon Hall8f89dda2015-01-22 16:03:33 -0800970 flowCheck = main.FALSE
Jon Hall58c76b72015-02-23 11:09:24 -0800971 ONOS1Flows = main.ONOScli1.flows( jsonFormat=True )
Jon Hall8f89dda2015-01-22 16:03:33 -0800972 if "Error" in ONOS1Flows or not ONOS1Flows:
Jon Hall40d2cbd2015-06-03 16:24:29 -0700973 main.log.error( "Error in getting ONOS flows" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800974 main.log.warn( "ONOS1 flows repsponse: " + ONOS1Flows )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800975 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800976 # TODO: Do a better check, maybe compare flows on switches?
Jon Hall8f89dda2015-01-22 16:03:33 -0800977 flowState = ONOS1Flows
978 flowCheck = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800979
Jon Hall6aec96b2015-01-19 14:49:31 -0800980 main.step( "Get the OF Table entries" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800981 global flows
Jon Hall6aec96b2015-01-19 14:49:31 -0800982 flows = []
983 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800984 flows.append( main.Mininet2.getFlowTable( 1.3, "s" + str( i ) ) )
Jon Hall58c76b72015-02-23 11:09:24 -0800985 if flowCheck == main.FALSE:
986 for table in flows:
987 main.log.warn( table )
Jon Hall6aec96b2015-01-19 14:49:31 -0800988 # TODO: Compare switch flow tables with ONOS flow tables
Jon Hall73cf9cc2014-11-20 22:28:38 -0800989
Jon Hall6aec96b2015-01-19 14:49:31 -0800990 main.step( "Create TestONTopology object" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800991 ctrls = []
Jon Hall390696c2015-05-05 17:13:41 -0700992 temp = ( nodes[0], nodes[0].name, nodes[0].ip_address, 6633 )
Jon Hall6aec96b2015-01-19 14:49:31 -0800993 ctrls.append( temp )
Jon Hall390696c2015-05-05 17:13:41 -0700994 MNTopo = TestONTopology( main.Mininet1, ctrls )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800995
Jon Hall6aec96b2015-01-19 14:49:31 -0800996 main.step( "Collecting topology information from ONOS" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800997 devices = []
998 devices.append( main.ONOScli1.devices() )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800999 hosts = []
Jon Hall58c76b72015-02-23 11:09:24 -08001000 hosts.append( json.loads( main.ONOScli1.hosts() ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001001 ports = []
1002 ports.append( main.ONOScli1.ports() )
1003 links = []
1004 links.append( main.ONOScli1.links() )
Jon Hall58c76b72015-02-23 11:09:24 -08001005 clusters = []
1006 clusters.append( main.ONOScli1.clusters() )
Jon Hall390696c2015-05-05 17:13:41 -07001007
1008 main.step( "Each host has an IP address" )
Jon Hall58c76b72015-02-23 11:09:24 -08001009 ipResult = main.TRUE
1010 for controller in range( 0, len( hosts ) ):
1011 controllerStr = str( controller + 1 )
1012 for host in hosts[ controller ]:
Jon Hallfeff3082015-05-19 10:23:26 -07001013 if host is None or host.get( 'ipAddresses', [] ) == []:
Jon Hall58c76b72015-02-23 11:09:24 -08001014 main.log.error(
1015 "DEBUG:Error with host ips on controller" +
1016 controllerStr + ": " + str( host ) )
1017 ipResult = main.FALSE
Jon Hall390696c2015-05-05 17:13:41 -07001018 utilities.assert_equals(
1019 expect=main.TRUE,
1020 actual=ipResult,
1021 onpass="The ips of the hosts aren't empty",
1022 onfail="The ip of at least one host is missing" )
Jon Hall58c76b72015-02-23 11:09:24 -08001023
1024 # there should always only be one cluster
Jon Hall390696c2015-05-05 17:13:41 -07001025 main.step( "There is only one dataplane cluster" )
1026 try:
1027 numClusters = len( json.loads( clusters[ 0 ] ) )
1028 except ( ValueError, TypeError ):
1029 main.log.exception( "Error parsing clusters[0]: " +
1030 repr( clusters[ 0 ] ) )
Jon Hall58c76b72015-02-23 11:09:24 -08001031 clusterResults = main.FALSE
1032 if numClusters == 1:
1033 clusterResults = main.TRUE
1034 utilities.assert_equals(
1035 expect=1,
1036 actual=numClusters,
1037 onpass="ONOS shows 1 SCC",
1038 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001039
Jon Hall6aec96b2015-01-19 14:49:31 -08001040 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001041 devicesResults = main.TRUE
1042 portsResults = main.TRUE
1043 linksResults = main.TRUE
Jon Hall58c76b72015-02-23 11:09:24 -08001044 hostsResults = main.TRUE
Jon Hall8f89dda2015-01-22 16:03:33 -08001045 for controller in range( numControllers ):
1046 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001047 if devices[ controller ] or "Error" not in devices[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001048 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -08001049 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001050 json.loads( devices[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001051 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001052 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001053 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001054 actual=currentDevicesResult,
1055 onpass="ONOS" + controllerStr +
1056 " Switches view is correct",
1057 onfail="ONOS" + controllerStr +
1058 " Switches view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001059
Jon Hall6aec96b2015-01-19 14:49:31 -08001060 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001061 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -08001062 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001063 json.loads( ports[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001064 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001065 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001066 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001067 actual=currentPortsResult,
1068 onpass="ONOS" + controllerStr +
1069 " ports view is correct",
1070 onfail="ONOS" + controllerStr +
1071 " ports view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001072
Jon Hall6aec96b2015-01-19 14:49:31 -08001073 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001074 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -08001075 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001076 json.loads( links[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001077 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001078 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001079 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001080 actual=currentLinksResult,
1081 onpass="ONOS" + controllerStr +
1082 " links view is correct",
1083 onfail="ONOS" + controllerStr +
1084 " links view is incorrect" )
1085
1086 if hosts[ controller ] or "Error" not in hosts[ controller ]:
1087 currentHostsResult = main.Mininet1.compareHosts(
1088 MNTopo, hosts[ controller ] )
1089 else:
1090 currentHostsResult = main.FALSE
1091 utilities.assert_equals( expect=main.TRUE,
1092 actual=currentHostsResult,
1093 onpass="ONOS" + controllerStr +
1094 " hosts exist in Mininet",
1095 onfail="ONOS" + controllerStr +
1096 " hosts don't match Mininet" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001097
Jon Hall8f89dda2015-01-22 16:03:33 -08001098 devicesResults = devicesResults and currentDevicesResult
1099 portsResults = portsResults and currentPortsResult
1100 linksResults = linksResults and currentLinksResult
Jon Hall58c76b72015-02-23 11:09:24 -08001101 hostsResults = hostsResults and currentHostsResult
Jon Hall73cf9cc2014-11-20 22:28:38 -08001102
Jon Hall58c76b72015-02-23 11:09:24 -08001103 topoResult = devicesResults and portsResults and linksResults\
1104 and clusterResults and ipResult and hostsResults
Jon Hall8f89dda2015-01-22 16:03:33 -08001105 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
Jon Hall58c76b72015-02-23 11:09:24 -08001106 onpass="Topology Check Test successful",
1107 onfail="Topology Check Test NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001108
Jon Hall6aec96b2015-01-19 14:49:31 -08001109 def CASE6( self, main ):
1110 """
Jon Hallffb386d2014-11-21 13:43:38 -08001111 The Failure case.
Jon Hall6aec96b2015-01-19 14:49:31 -08001112 """
Jon Hallffb386d2014-11-21 13:43:38 -08001113 import time
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 Hall73cf9cc2014-11-20 22:28:38 -08001117
Jon Hall390696c2015-05-05 17:13:41 -07001118 # Reset non-persistent variables
1119 try:
1120 iCounterValue = 0
1121 except NameError:
1122 main.log.error( "iCounterValue not defined, setting to 0" )
1123 iCounterValue = 0
1124
Jon Hallfeff3082015-05-19 10:23:26 -07001125 main.case( "Restart ONOS node" )
1126 main.caseExplaination = "Killing ONOS process and restart cli " +\
1127 "sessions once onos is up."
Jon Hall390696c2015-05-05 17:13:41 -07001128 main.step( "Killing ONOS processes" )
1129 killResult = main.ONOSbench.onosKill( ONOS1Ip )
Jon Hallffb386d2014-11-21 13:43:38 -08001130 start = time.time()
Jon Hall390696c2015-05-05 17:13:41 -07001131 utilities.assert_equals( expect=main.TRUE, actual=killResult,
1132 onpass="ONOS Killed",
1133 onfail="Error killing ONOS" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001134
Jon Hall6aec96b2015-01-19 14:49:31 -08001135 main.step( "Checking if ONOS is up yet" )
Jon Hallffb386d2014-11-21 13:43:38 -08001136 count = 0
Jon Hall94fd0472014-12-08 11:52:42 -08001137 while count < 10:
Jon Hall8f89dda2015-01-22 16:03:33 -08001138 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
1139 if onos1Isup == main.TRUE:
Jon Hallffb386d2014-11-21 13:43:38 -08001140 elapsed = time.time() - start
1141 break
1142 else:
1143 count = count + 1
Jon Hall390696c2015-05-05 17:13:41 -07001144 utilities.assert_equals( expect=main.TRUE, actual=onos1Isup,
1145 onpass="ONOS is back up",
1146 onfail="ONOS failed to start" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001147
Jon Hall390696c2015-05-05 17:13:41 -07001148 main.log.step( "Starting ONOS CLI sessions" )
1149 cliResults = main.ONOScli1.startOnosCli( ONOS1Ip )
1150 utilities.assert_equals( expect=main.TRUE, actual=cliResults,
1151 onpass="ONOS cli startup successful",
1152 onfail="ONOS cli startup failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001153
Jon Hallfebb1c72015-03-05 13:30:09 -08001154 if elapsed:
1155 main.log.info( "ESTIMATE: ONOS took %s seconds to restart" %
1156 str( elapsed ) )
Jon Hall40d2cbd2015-06-03 16:24:29 -07001157 main.restartTime = elapsed
1158 else:
1159 main.restartTime = -1
Jon Hall6aec96b2015-01-19 14:49:31 -08001160 time.sleep( 5 )
Jon Hallfeff3082015-05-19 10:23:26 -07001161 # rerun on election apps
1162 main.ONOScli1.electionTestRun()
Jon Hall73cf9cc2014-11-20 22:28:38 -08001163
Jon Hall6aec96b2015-01-19 14:49:31 -08001164 def CASE7( self, main ):
1165 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001166 Check state after ONOS failure
Jon Hall6aec96b2015-01-19 14:49:31 -08001167 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001168 import json
Jon Hall5cfd23c2015-03-19 11:40:57 -07001169 assert numControllers, "numControllers not defined"
1170 assert main, "main not defined"
1171 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -08001172 main.case( "Running ONOS Constant State Tests" )
Jon Hall390696c2015-05-05 17:13:41 -07001173 main.step( "Check that each switch has a master" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001174 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -08001175 rolesNotNull = main.ONOScli1.rolesNotNull()
Jon Hall6aec96b2015-01-19 14:49:31 -08001176 utilities.assert_equals(
1177 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001178 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -08001179 onpass="Each device has a master",
1180 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -08001181
Jon Hall6aec96b2015-01-19 14:49:31 -08001182 main.step( "Check if switch roles are consistent across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001183 ONOS1Mastership = main.ONOScli1.roles()
Jon Hall6aec96b2015-01-19 14:49:31 -08001184 # FIXME: Refactor this whole case for single instance
Jon Hall8f89dda2015-01-22 16:03:33 -08001185 if "Error" in ONOS1Mastership or not ONOS1Mastership:
Jon Hall40d2cbd2015-06-03 16:24:29 -07001186 main.log.error( "Error in getting ONOS mastership" )
Jon Hall58c76b72015-02-23 11:09:24 -08001187 main.log.warn( "ONOS1 mastership response: " +
1188 repr( ONOS1Mastership ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001189 consistentMastership = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001190 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001191 consistentMastership = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001192 utilities.assert_equals(
1193 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001194 actual=consistentMastership,
Jon Hall6aec96b2015-01-19 14:49:31 -08001195 onpass="Switch roles are consistent across all ONOS nodes",
1196 onfail="ONOS nodes have different views of switch roles" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001197
1198 description2 = "Compare switch roles from before failure"
Jon Hall6aec96b2015-01-19 14:49:31 -08001199 main.step( description2 )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001200
Jon Hall8f89dda2015-01-22 16:03:33 -08001201 currentJson = json.loads( ONOS1Mastership )
1202 oldJson = json.loads( mastershipState )
1203 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001204 for i in range( 1, 29 ):
1205 switchDPID = str(
Jon Hall58c76b72015-02-23 11:09:24 -08001206 main.Mininet1.getSwitchDPID( switch="s" + str( i ) ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001207
Jon Hall8f89dda2015-01-22 16:03:33 -08001208 current = [ switch[ 'master' ] for switch in currentJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001209 if switchDPID in switch[ 'id' ] ]
Jon Hall8f89dda2015-01-22 16:03:33 -08001210 old = [ switch[ 'master' ] for switch in oldJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001211 if switchDPID in switch[ 'id' ] ]
Jon Hall73cf9cc2014-11-20 22:28:38 -08001212 if current == old:
Jon Hall8f89dda2015-01-22 16:03:33 -08001213 mastershipCheck = mastershipCheck and main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001214 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001215 main.log.warn( "Mastership of switch %s changed" % switchDPID )
Jon Hall8f89dda2015-01-22 16:03:33 -08001216 mastershipCheck = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001217 utilities.assert_equals(
1218 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001219 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -08001220 onpass="Mastership of Switches was not changed",
1221 onfail="Mastership of some switches changed" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001222 mastershipCheck = mastershipCheck and consistentMastership
Jon Hall73cf9cc2014-11-20 22:28:38 -08001223
Jon Hall6aec96b2015-01-19 14:49:31 -08001224 main.step( "Get the intents and compare across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001225 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
1226 intentCheck = main.FALSE
1227 if "Error" in ONOS1Intents or not ONOS1Intents:
Jon Hall40d2cbd2015-06-03 16:24:29 -07001228 main.log.error( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001229 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001230 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001231 intentCheck = main.TRUE
Jon Hall40d2cbd2015-06-03 16:24:29 -07001232 main.log.error( "Intents are consistent across all ONOS nodes" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001233 utilities.assert_equals(
1234 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001235 actual=intentCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -08001236 onpass="Intents are consistent across all ONOS nodes",
1237 onfail="ONOS nodes have different views of intents" )
Jon Hall1b8f54a2015-02-04 13:24:20 -08001238 # Print the intent states
1239 intents = []
1240 intents.append( ONOS1Intents )
1241 intentStates = []
1242 for node in intents: # Iter through ONOS nodes
1243 nodeStates = []
Jon Hall58c76b72015-02-23 11:09:24 -08001244 # Iter through intents of a node
1245 for intent in json.loads( node ):
Jon Hall1b8f54a2015-02-04 13:24:20 -08001246 nodeStates.append( intent[ 'state' ] )
1247 intentStates.append( nodeStates )
1248 out = [ (i, nodeStates.count( i ) ) for i in set( nodeStates ) ]
1249 main.log.info( dict( out ) )
1250
Jon Hall58c76b72015-02-23 11:09:24 -08001251 # NOTE: Store has no durability, so intents are lost across system
1252 # restarts
Jon Hall6aec96b2015-01-19 14:49:31 -08001253 """
1254 main.step( "Compare current intents with intents before the failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001255 # NOTE: this requires case 5 to pass for intentState to be set.
Jon Hall6aec96b2015-01-19 14:49:31 -08001256 # maybe we should stop the test if that fails?
Jon Hall40d2cbd2015-06-03 16:24:29 -07001257 sameIntents = main.FALSE
1258 if intentState and intentState == ONOSIntents[ 0 ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001259 sameIntents = main.TRUE
Jon Hallfeff3082015-05-19 10:23:26 -07001260 main.log.info( "Intents are consistent with before failure" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001261 # TODO: possibly the states have changed? we may need to figure out
Jon Hallfeff3082015-05-19 10:23:26 -07001262 # what the acceptable states are
Jon Hall40d2cbd2015-06-03 16:24:29 -07001263 elif len( intentState ) == len( ONOSIntents[ 0 ] ):
1264 sameIntents = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001265 try:
Jon Hall40d2cbd2015-06-03 16:24:29 -07001266 before = json.loads( intentState )
1267 after = json.loads( ONOSIntents[ 0 ] )
1268 for intent in before:
1269 if intent not in after:
1270 sameIntents = main.FALSE
1271 main.log.debug( "Intent is not currently in ONOS " +\
1272 "(at least in the same form):" )
1273 main.log.debug( json.dumps( intent ) )
1274 except ( ValueError, TypeError ):
1275 main.log.exception( "Exception printing intents" )
1276 main.log.debug( repr( ONOSIntents[0] ) )
1277 main.log.debug( repr( intentState ) )
1278 if sameIntents == main.FALSE:
1279 try:
1280 main.log.debug( "ONOS intents before: " )
1281 main.log.debug( json.dumps( json.loads( intentState ),
1282 sort_keys=True, indent=4,
1283 separators=( ',', ': ' ) ) )
1284 main.log.debug( "Current ONOS intents: " )
1285 main.log.debug( json.dumps( json.loads( ONOSIntents[ 0 ] ),
1286 sort_keys=True, indent=4,
1287 separators=( ',', ': ' ) ) )
1288 except ( ValueError, TypeError ):
1289 main.log.exception( "Exception printing intents" )
1290 main.log.debug( repr( ONOSIntents[0] ) )
1291 main.log.debug( repr( intentState ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001292 utilities.assert_equals(
1293 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001294 actual=sameIntents,
Jon Hall6aec96b2015-01-19 14:49:31 -08001295 onpass="Intents are consistent with before failure",
1296 onfail="The Intents changed during failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001297 intentCheck = intentCheck and sameIntents
Jon Hall6aec96b2015-01-19 14:49:31 -08001298 """
1299 main.step( "Get the OF Table entries and compare to before " +
1300 "component failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001301 FlowTables = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001302 flows2 = []
1303 for i in range( 28 ):
1304 main.log.info( "Checking flow table on s" + str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001305 tmpFlows = main.Mininet2.getFlowTable( 1.3, "s" + str( i + 1 ) )
1306 flows2.append( tmpFlows )
1307 tempResult = main.Mininet2.flowComp(
Jon Hall6aec96b2015-01-19 14:49:31 -08001308 flow1=flows[ i ],
Jon Hall8f89dda2015-01-22 16:03:33 -08001309 flow2=tmpFlows )
1310 FlowTables = FlowTables and tempResult
1311 if FlowTables == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001312 main.log.info( "Differences in flow table for switch: s" +
1313 str( i + 1 ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001314 utilities.assert_equals(
1315 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001316 actual=FlowTables,
Jon Hall6aec96b2015-01-19 14:49:31 -08001317 onpass="No changes were found in the flow tables",
1318 onfail="Changes were found in the flow tables" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001319
Jon Hallfeff3082015-05-19 10:23:26 -07001320 main.step( "Leadership Election is still functional" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001321 # Test of LeadershipElection
Jon Hall669173b2014-12-17 11:36:30 -08001322
Jon Hall8f89dda2015-01-22 16:03:33 -08001323 leader = ONOS1Ip
1324 leaderResult = main.TRUE
1325 for controller in range( 1, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001326 # loop through ONOScli handlers
1327 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001328 leaderN = node.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001329 # verify leader is ONOS1
1330 # NOTE even though we restarted ONOS, it is the only one so onos 1
1331 # must be leader
Jon Hall669173b2014-12-17 11:36:30 -08001332 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08001333 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001334 pass
1335 elif leaderN == main.FALSE:
Jon Hallfeff3082015-05-19 10:23:26 -07001336 # error in response
Jon Hall40d2cbd2015-06-03 16:24:29 -07001337 main.log.error( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001338 "electionTestLeader function, check the" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001339 " error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001340 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001341 elif leader != leaderN:
Jon Hall8f89dda2015-01-22 16:03:33 -08001342 leaderResult = main.FALSE
Jon Hall40d2cbd2015-06-03 16:24:29 -07001343 main.log.error( "ONOS" + str( controller ) + " sees " +
Jon Hall58c76b72015-02-23 11:09:24 -08001344 str( leaderN ) +
1345 " as the leader of the election app. " +
1346 "Leader should be " + str( leader ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001347 utilities.assert_equals(
1348 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001349 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001350 onpass="Leadership election passed",
1351 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08001352
Jon Hall6aec96b2015-01-19 14:49:31 -08001353 def CASE8( self, main ):
1354 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001355 Compare topo
Jon Hall6aec96b2015-01-19 14:49:31 -08001356 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001357 import sys
Jon Hall6aec96b2015-01-19 14:49:31 -08001358 # FIXME add this path to params
1359 sys.path.append( "/home/admin/sts" )
1360 # assumes that sts is already in you PYTHONPATH
1361 from sts.topology.teston_topology import TestONTopology
Jon Hall73cf9cc2014-11-20 22:28:38 -08001362 import json
1363 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001364 assert numControllers, "numControllers not defined"
1365 assert main, "main not defined"
1366 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall73cf9cc2014-11-20 22:28:38 -08001367
Jon Hallfeff3082015-05-19 10:23:26 -07001368 main.case( "Compare ONOS Topology view to Mininet topology" )
1369 main.caseExplaination = "Compare topology objects between Mininet" +\
1370 " and ONOS"
Jon Hall6aec96b2015-01-19 14:49:31 -08001371 main.step( "Create TestONTopology object" )
Jon Hallfeff3082015-05-19 10:23:26 -07001372 try:
1373 ctrls = []
1374 node = main.ONOS1
1375 temp = ( node, node.name, node.ip_address, 6633 )
1376 ctrls.append( temp )
1377 MNTopo = TestONTopology( main.Mininet1, ctrls )
1378 except Exception:
1379 objResult = main.FALSE
1380 else:
1381 objResult = main.TRUE
1382 utilities.assert_equals( expect=main.TRUE, actual=objResult,
1383 onpass="Created TestONTopology object",
1384 onfail="Exception while creating " +
1385 "TestONTopology object" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001386
Jon Hall6aec96b2015-01-19 14:49:31 -08001387 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001388 devicesResults = main.TRUE
1389 portsResults = main.TRUE
1390 linksResults = main.TRUE
Jon Hall58c76b72015-02-23 11:09:24 -08001391 hostsResults = main.TRUE
Jon Hall8f89dda2015-01-22 16:03:33 -08001392 topoResult = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001393 elapsed = 0
Jon Hallffb386d2014-11-21 13:43:38 -08001394 count = 0
Jon Hall6aec96b2015-01-19 14:49:31 -08001395 main.step( "Collecting topology information from ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001396 startTime = time.time()
Jon Hall58c76b72015-02-23 11:09:24 -08001397 # Give time for Gossip to work
Jon Hall8f89dda2015-01-22 16:03:33 -08001398 while topoResult == main.FALSE and elapsed < 60:
Jon Halla9d26da2015-03-30 16:45:32 -07001399 count += 1
Jon Hall94fd0472014-12-08 11:52:42 -08001400 if count > 1:
Jon Halla9d26da2015-03-30 16:45:32 -07001401 # TODO: Deprecate STS usage
Jon Hall58c76b72015-02-23 11:09:24 -08001402 MNTopo = TestONTopology( main.Mininet1, ctrls )
Jon Hall8f89dda2015-01-22 16:03:33 -08001403 cliStart = time.time()
Jon Hall94fd0472014-12-08 11:52:42 -08001404 devices = []
1405 devices.append( main.ONOScli1.devices() )
Jon Hall94fd0472014-12-08 11:52:42 -08001406 hosts = []
Jon Hall58c76b72015-02-23 11:09:24 -08001407 hosts.append( json.loads( main.ONOScli1.hosts() ) )
1408 ipResult = main.TRUE
1409 for controller in range( 0, len( hosts ) ):
1410 controllerStr = str( controller + 1 )
1411 for host in hosts[ controller ]:
Jon Hallfeff3082015-05-19 10:23:26 -07001412 if host is None or host.get( 'ipAddresses', [] ) == []:
Jon Hall58c76b72015-02-23 11:09:24 -08001413 main.log.error(
1414 "DEBUG:Error with host ips on controller" +
1415 controllerStr + ": " + str( host ) )
1416 ipResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001417 ports = []
1418 ports.append( main.ONOScli1.ports() )
1419 links = []
1420 links.append( main.ONOScli1.links() )
Jon Hall58c76b72015-02-23 11:09:24 -08001421 clusters = []
1422 clusters.append( main.ONOScli1.clusters() )
1423
Jon Hall8f89dda2015-01-22 16:03:33 -08001424 elapsed = time.time() - startTime
1425 cliTime = time.time() - cliStart
1426 print "CLI time: " + str( cliTime )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001427
Jon Hall8f89dda2015-01-22 16:03:33 -08001428 for controller in range( numControllers ):
1429 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001430 if devices[ controller ] or "Error" not in devices[
1431 controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001432 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -08001433 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001434 json.loads( devices[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001435 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001436 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001437 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001438 actual=currentDevicesResult,
1439 onpass="ONOS" + controllerStr +
1440 " Switches view is correct",
1441 onfail="ONOS" + controllerStr +
1442 " Switches view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001443
Jon Hall6aec96b2015-01-19 14:49:31 -08001444 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001445 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -08001446 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001447 json.loads( ports[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001448 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001449 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001450 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001451 actual=currentPortsResult,
1452 onpass="ONOS" + controllerStr +
1453 " ports view is correct",
1454 onfail="ONOS" + controllerStr +
1455 " ports view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001456
Jon Hall6aec96b2015-01-19 14:49:31 -08001457 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001458 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -08001459 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001460 json.loads( links[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001461 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001462 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001463 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001464 actual=currentLinksResult,
1465 onpass="ONOS" + controllerStr +
1466 " links view is correct",
1467 onfail="ONOS" + controllerStr +
1468 " links view is incorrect" )
1469
1470 if hosts[ controller ] or "Error" not in hosts[ controller ]:
1471 currentHostsResult = main.Mininet1.compareHosts(
1472 MNTopo, hosts[ controller ] )
1473 else:
1474 currentHostsResult = main.FALSE
1475 utilities.assert_equals( expect=main.TRUE,
1476 actual=currentHostsResult,
1477 onpass="ONOS" + controllerStr +
1478 " hosts exist in Mininet",
1479 onfail="ONOS" + controllerStr +
1480 " hosts don't match Mininet" )
1481
1482 devicesResults = devicesResults and currentDevicesResult
1483 portsResults = portsResults and currentPortsResult
1484 linksResults = linksResults and currentLinksResult
1485 hostsResults = hostsResults and currentHostsResult
1486
Jon Hall63604932015-02-26 17:09:50 -08001487 # "consistent" results don't make sense for single instance
Jon Hall58c76b72015-02-23 11:09:24 -08001488 # there should always only be one cluster
1489 numClusters = len( json.loads( clusters[ 0 ] ) )
1490 clusterResults = main.FALSE
1491 if numClusters == 1:
1492 clusterResults = main.TRUE
1493 utilities.assert_equals(
1494 expect=1,
1495 actual=numClusters,
1496 onpass="ONOS shows 1 SCC",
1497 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
1498
1499 topoResult = ( devicesResults and portsResults and linksResults
1500 and hostsResults and ipResult and clusterResults )
Jon Hall94fd0472014-12-08 11:52:42 -08001501
Jon Hall8f89dda2015-01-22 16:03:33 -08001502 topoResult = topoResult and int( count <= 2 )
1503 note = "note it takes about " + str( int( cliTime ) ) + \
1504 " seconds for the test to make all the cli calls to fetch " +\
1505 "the topology from each ONOS instance"
Jon Hall1b8f54a2015-02-04 13:24:20 -08001506 main.log.info(
Jon Hall8f89dda2015-01-22 16:03:33 -08001507 "Very crass estimate for topology discovery/convergence( " +
1508 str( note ) + " ): " + str( elapsed ) + " seconds, " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001509 str( count ) + " tries" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001510 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
Jon Hall58c76b72015-02-23 11:09:24 -08001511 onpass="Topology Check Test successful",
1512 onfail="Topology Check Test NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001513
Jon Hall6aec96b2015-01-19 14:49:31 -08001514 def CASE9( self, main ):
1515 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001516 Link s3-s28 down
Jon Hall6aec96b2015-01-19 14:49:31 -08001517 """
1518 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001519 assert numControllers, "numControllers not defined"
1520 assert main, "main not defined"
1521 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -08001522 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001523
Jon Hall8f89dda2015-01-22 16:03:33 -08001524 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001525
Jon Hall6aec96b2015-01-19 14:49:31 -08001526 description = "Turn off a link to ensure that Link Discovery " +\
Jon Hall58c76b72015-02-23 11:09:24 -08001527 "is working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001528 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001529
Jon Hall6aec96b2015-01-19 14:49:31 -08001530 main.step( "Kill Link between s3 and s28" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001531 LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" )
Jon Hall58c76b72015-02-23 11:09:24 -08001532 main.log.info( "Waiting " + str( linkSleep ) +
1533 " seconds for link down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001534 time.sleep( linkSleep )
1535 utilities.assert_equals( expect=main.TRUE, actual=LinkDown,
Jon Halla9d26da2015-03-30 16:45:32 -07001536 onpass="Link down successful",
Jon Hall58c76b72015-02-23 11:09:24 -08001537 onfail="Failed to bring link down" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001538 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -08001539
Jon Hall6aec96b2015-01-19 14:49:31 -08001540 def CASE10( self, main ):
1541 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001542 Link s3-s28 up
Jon Hall6aec96b2015-01-19 14:49:31 -08001543 """
1544 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001545 assert numControllers, "numControllers not defined"
1546 assert main, "main not defined"
1547 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -08001548 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001549
Jon Hall8f89dda2015-01-22 16:03:33 -08001550 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001551
Jon Hall6aec96b2015-01-19 14:49:31 -08001552 description = "Restore a link to ensure that Link Discovery is " + \
Jon Hall58c76b72015-02-23 11:09:24 -08001553 "working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001554 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001555
Jon Hall6aec96b2015-01-19 14:49:31 -08001556 main.step( "Bring link between s3 and s28 back up" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001557 LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" )
Jon Hall58c76b72015-02-23 11:09:24 -08001558 main.log.info( "Waiting " + str( linkSleep ) +
1559 " seconds for link up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001560 time.sleep( linkSleep )
1561 utilities.assert_equals( expect=main.TRUE, actual=LinkUp,
Jon Halla9d26da2015-03-30 16:45:32 -07001562 onpass="Link up successful",
Jon Hall58c76b72015-02-23 11:09:24 -08001563 onfail="Failed to bring link up" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001564 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -08001565
Jon Hall6aec96b2015-01-19 14:49:31 -08001566 def CASE11( self, main ):
1567 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001568 Switch Down
Jon Hall6aec96b2015-01-19 14:49:31 -08001569 """
1570 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001571 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001572 assert numControllers, "numControllers not defined"
1573 assert main, "main not defined"
1574 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall73cf9cc2014-11-20 22:28:38 -08001575
Jon Hall8f89dda2015-01-22 16:03:33 -08001576 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001577
1578 description = "Killing a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001579 main.case( description )
1580 switch = main.params[ 'kill' ][ 'switch' ]
1581 switchDPID = main.params[ 'kill' ][ 'dpid' ]
Jon Hall73cf9cc2014-11-20 22:28:38 -08001582
Jon Hall6aec96b2015-01-19 14:49:31 -08001583 # TODO: Make this switch parameterizable
1584 main.step( "Kill " + switch )
Jon Hall40d2cbd2015-06-03 16:24:29 -07001585 main.log.info( "Deleting " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001586 main.Mininet1.delSwitch( switch )
1587 main.log.info( "Waiting " + str( switchSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001588 " seconds for switch down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001589 time.sleep( switchSleep )
1590 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001591 # Peek at the deleted switch
1592 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001593 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001594 if device and device[ 'available' ] is False:
Jon Hall94fd0472014-12-08 11:52:42 -08001595 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001596 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Halla9d26da2015-03-30 16:45:32 -07001597 onpass="Kill switch successful",
Jon Hall58c76b72015-02-23 11:09:24 -08001598 onfail="Failed to kill switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001599
Jon Hall6aec96b2015-01-19 14:49:31 -08001600 def CASE12( self, main ):
1601 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001602 Switch Up
Jon Hall6aec96b2015-01-19 14:49:31 -08001603 """
1604 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001605 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001606 assert numControllers, "numControllers not defined"
1607 assert main, "main not defined"
1608 assert utilities.assert_equals, "utilities.assert_equals not defined"
1609 assert ONOS1Port, "ONOS1Port not defined"
1610 assert ONOS2Port, "ONOS2Port not defined"
1611 assert ONOS3Port, "ONOS3Port not defined"
1612 assert ONOS4Port, "ONOS4Port not defined"
1613 assert ONOS5Port, "ONOS5Port not defined"
1614 assert ONOS6Port, "ONOS6Port not defined"
1615 assert ONOS7Port, "ONOS7Port not defined"
Jon Hall669173b2014-12-17 11:36:30 -08001616
Jon Hall8f89dda2015-01-22 16:03:33 -08001617 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall6aec96b2015-01-19 14:49:31 -08001618 switch = main.params[ 'kill' ][ 'switch' ]
1619 switchDPID = main.params[ 'kill' ][ 'dpid' ]
1620 links = main.params[ 'kill' ][ 'links' ].split()
Jon Hall73cf9cc2014-11-20 22:28:38 -08001621 description = "Adding a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001622 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001623
Jon Hall6aec96b2015-01-19 14:49:31 -08001624 main.step( "Add back " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001625 main.Mininet1.addSwitch( switch, dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001626 for peer in links:
Jon Hall8f89dda2015-01-22 16:03:33 -08001627 main.Mininet1.addLink( switch, peer )
1628 main.Mininet1.assignSwController( sw=switch.split( 's' )[ 1 ],
Jon Hall58c76b72015-02-23 11:09:24 -08001629 ip1=ONOS1Ip,
1630 port1=ONOS1Port )
1631 main.log.info( "Waiting " + str( switchSleep ) +
1632 " seconds for switch up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001633 time.sleep( switchSleep )
1634 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001635 # Peek at the deleted switch
1636 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001637 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001638 if device and device[ 'available' ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001639 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001640 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Halla9d26da2015-03-30 16:45:32 -07001641 onpass="add switch successful",
Jon Hall58c76b72015-02-23 11:09:24 -08001642 onfail="Failed to add switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001643
Jon Hall6aec96b2015-01-19 14:49:31 -08001644 def CASE13( self, main ):
1645 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001646 Clean up
Jon Hall6aec96b2015-01-19 14:49:31 -08001647 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001648 import os
1649 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001650 assert numControllers, "numControllers not defined"
1651 assert main, "main not defined"
1652 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -08001653 # printing colors to terminal
Jon Halla9d26da2015-03-30 16:45:32 -07001654 colors = { 'cyan': '\033[96m', 'purple': '\033[95m',
1655 'blue': '\033[94m', 'green': '\033[92m',
1656 'yellow': '\033[93m', 'red': '\033[91m', 'end': '\033[0m' }
Jon Hall40d2cbd2015-06-03 16:24:29 -07001657 main.case( "Test Cleanup" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001658 main.step( "Killing tcpdumps" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001659 main.Mininet2.stopTcpdump()
Jon Hall73cf9cc2014-11-20 22:28:38 -08001660
Jon Hall6aec96b2015-01-19 14:49:31 -08001661 main.step( "Copying MN pcap and ONOS log files to test station" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001662 testname = main.TEST
Jon Hall8f89dda2015-01-22 16:03:33 -08001663 teststationUser = main.params[ 'TESTONUSER' ]
1664 teststationIP = main.params[ 'TESTONIP' ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001665 # NOTE: MN Pcap file is being saved to ~/packet_captures
Jon Hall73cf9cc2014-11-20 22:28:38 -08001666 # scp this file as MN and TestON aren't necessarily the same vm
Jon Hall6aec96b2015-01-19 14:49:31 -08001667 # FIXME: scp
1668 # mn files
1669 # TODO: Load these from params
1670 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001671 logFolder = "/opt/onos/log/"
1672 logFiles = [ "karaf.log", "karaf.log.1" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001673 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001674 dstDir = "~/packet_captures/"
1675 for f in logFiles:
1676 main.ONOSbench.handle.sendline( "scp sdn@" + ONOS1Ip + ":" +
1677 logFolder + f + " " +
1678 teststationUser + "@" +
1679 teststationIP + ":" + dstDir +
Jon Hall6aec96b2015-01-19 14:49:31 -08001680 str( testname ) + "-ONOS1-" + f )
1681 main.ONOSbench.handle.expect( "\$" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001682
Jon Hall6aec96b2015-01-19 14:49:31 -08001683 # std*.log's
1684 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001685 logFolder = "/opt/onos/var/"
1686 logFiles = [ "stderr.log", "stdout.log" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001687 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001688 dstDir = "~/packet_captures/"
1689 for f in logFiles:
1690 main.ONOSbench.handle.sendline( "scp sdn@" + ONOS1Ip + ":" +
1691 logFolder + f + " " +
1692 teststationUser + "@" +
1693 teststationIP + ":" + dstDir +
Jon Hall6aec96b2015-01-19 14:49:31 -08001694 str( testname ) + "-ONOS1-" + f )
Jon Hall58c76b72015-02-23 11:09:24 -08001695 main.ONOSbench.handle.expect( "\$" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001696 # sleep so scp can finish
1697 time.sleep( 10 )
Jon Halla9d26da2015-03-30 16:45:32 -07001698
1699 main.step( "Stopping Mininet" )
Jon Hall390696c2015-05-05 17:13:41 -07001700 mnResult = main.Mininet1.stopNet()
1701 utilities.assert_equals( expect=main.TRUE, actual=mnResult,
1702 onpass="Mininet stopped",
1703 onfail="MN cleanup NOT successful" )
Jon Halla9d26da2015-03-30 16:45:32 -07001704
1705 main.step( "Checking ONOS Logs for errors" )
1706 print colors[ 'purple' ] + "Checking logs for errors on ONOS1:" + \
1707 colors[ 'end' ]
Jon Hall40d2cbd2015-06-03 16:24:29 -07001708 print main.ONOSbench.checkLogs( ONOS1Ip, restart=True )
Jon Halla9d26da2015-03-30 16:45:32 -07001709
Jon Hall6aec96b2015-01-19 14:49:31 -08001710 main.step( "Packing and rotating pcap archives" )
1711 os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001712
Jon Hall40d2cbd2015-06-03 16:24:29 -07001713 try:
1714 timerLog = open( main.logdir + "/Timers.csv", 'w')
1715 # Overwrite with empty line and close
1716 labels = "Gossip Intents, Restart"
1717 data = str( gossipTime ) + ", " + str( main.restartTime )
1718 timerLog.write( labels + "\n" + data )
1719 timerLog.close()
1720 except NameError, e:
1721 main.log.exception(e)
1722
Jon Hall6aec96b2015-01-19 14:49:31 -08001723 def CASE14( self, main ):
1724 """
Jon Hall669173b2014-12-17 11:36:30 -08001725 start election app on all onos nodes
Jon Hall6aec96b2015-01-19 14:49:31 -08001726 """
Jon Hall5cfd23c2015-03-19 11:40:57 -07001727 assert numControllers, "numControllers not defined"
1728 assert main, "main not defined"
1729 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halla9d26da2015-03-30 16:45:32 -07001730
Jon Hall390696c2015-05-05 17:13:41 -07001731 main.case("Start Leadership Election app")
1732 main.step( "Install leadership election app" )
Jon Hallfeff3082015-05-19 10:23:26 -07001733 appResult = main.ONOScli1.activateApp( "org.onosproject.election" )
1734 utilities.assert_equals(
1735 expect=main.TRUE,
1736 actual=appResult,
1737 onpass="Election app installed",
1738 onfail="Something went wrong with installing Leadership election" )
1739
1740 main.step( "Run for election on each node" )
1741 leaderResult = main.ONOScli1.electionTestRun()
Jon Hall6aec96b2015-01-19 14:49:31 -08001742 # check for leader
Jon Hall8f89dda2015-01-22 16:03:33 -08001743 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001744 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08001745 if leader == ONOS1Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08001746 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001747 pass
Jon Hall6aec96b2015-01-19 14:49:31 -08001748 elif leader is None:
1749 # No leader elected
Jon Hallfeff3082015-05-19 10:23:26 -07001750 main.log.error( "No leader was elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001751 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001752 elif leader == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001753 # error in response
1754 # TODO: add check for "Command not found:" in the driver, this
1755 # means the app isn't loaded
Jon Hallfeff3082015-05-19 10:23:26 -07001756 main.log.error( "Something is wrong with electionTestLeader" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001757 " function, check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001758 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001759 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001760 # error in response
Jon Hallfeff3082015-05-19 10:23:26 -07001761 main.log.error(
Jon Hall8f89dda2015-01-22 16:03:33 -08001762 "Unexpected response from electionTestLeader function:'" +
1763 str( leader ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001764 "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001765 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001766 utilities.assert_equals(
1767 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001768 actual=leaderResult,
Jon Hallfeff3082015-05-19 10:23:26 -07001769 onpass="Successfully ran for leadership",
1770 onfail="Failed to run for leadership" )
Jon Hall669173b2014-12-17 11:36:30 -08001771
Jon Hall6aec96b2015-01-19 14:49:31 -08001772 def CASE15( self, main ):
1773 """
Jon Hall669173b2014-12-17 11:36:30 -08001774 Check that Leadership Election is still functional
Jon Hall6aec96b2015-01-19 14:49:31 -08001775 """
Jon Hall5cfd23c2015-03-19 11:40:57 -07001776 assert numControllers, "numControllers not defined"
1777 assert main, "main not defined"
1778 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall8f89dda2015-01-22 16:03:33 -08001779 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08001780 description = "Check that Leadership Election is still functional"
Jon Hall6aec96b2015-01-19 14:49:31 -08001781 main.case( description )
1782 main.step( "Find current leader and withdraw" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001783 leader = main.ONOScli1.electionTestLeader()
Jon Halla9d26da2015-03-30 16:45:32 -07001784 # do some sanity checking on leader before using it
Jon Hall8f89dda2015-01-22 16:03:33 -08001785 withdrawResult = main.FALSE
1786 if leader == ONOS1Ip:
1787 oldLeader = getattr( main, "ONOScli1" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001788 elif leader is None or leader == main.FALSE:
Jon Hall40d2cbd2015-06-03 16:24:29 -07001789 main.log.error(
Jon Hall6aec96b2015-01-19 14:49:31 -08001790 "Leader for the election app should be an ONOS node," +
Jon Hall58c76b72015-02-23 11:09:24 -08001791 "instead got '" + str( leader ) + "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001792 leaderResult = main.FALSE
Jon Hall63604932015-02-26 17:09:50 -08001793 oldLeader = None
1794 else:
1795 main.log.error( "Leader election --- why am I HERE?!?")
Jon Hallfeff3082015-05-19 10:23:26 -07001796 leaderResult = main.FALSE
1797 oldLeader = None
Jon Hall63604932015-02-26 17:09:50 -08001798 if oldLeader:
1799 withdrawResult = oldLeader.electionTestWithdraw()
Jon Hall6aec96b2015-01-19 14:49:31 -08001800 utilities.assert_equals(
1801 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001802 actual=withdrawResult,
Jon Hallfeff3082015-05-19 10:23:26 -07001803 onpass="Node was withdrawn from election",
1804 onfail="Node was not withdrawn from election" )
Jon Hall669173b2014-12-17 11:36:30 -08001805
Jon Hall6aec96b2015-01-19 14:49:31 -08001806 main.step( "Make sure new leader is elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001807 leaderN = main.ONOScli1.electionTestLeader()
Jon Hall669173b2014-12-17 11:36:30 -08001808 if leaderN == leader:
Jon Hall40d2cbd2015-06-03 16:24:29 -07001809 main.log.error( "ONOS still sees " + str( leaderN ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001810 " as leader after they withdrew" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001811 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001812 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001813 # error in response
1814 # TODO: add check for "Command not found:" in the driver, this
1815 # means the app isn't loaded
Jon Hall40d2cbd2015-06-03 16:24:29 -07001816 main.log.error( "Something is wrong with electionTestLeader " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001817 "function, check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001818 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001819 elif leaderN is None:
1820 main.log.info(
1821 "There is no leader after the app withdrew from election" )
Jon Hallfeff3082015-05-19 10:23:26 -07001822 leaderResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001823 utilities.assert_equals(
1824 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001825 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001826 onpass="Leadership election passed",
1827 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08001828
Jon Hall58c76b72015-02-23 11:09:24 -08001829 main.step( "Run for election on old leader( just so everyone " +
1830 "is in the hat )" )
Jon Hall63604932015-02-26 17:09:50 -08001831 if oldLeader:
1832 runResult = oldLeader.electionTestRun()
1833 else:
1834 runResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001835 utilities.assert_equals(
1836 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001837 actual=runResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001838 onpass="App re-ran for election",
1839 onfail="App failed to run for election" )
Jon Hallfeff3082015-05-19 10:23:26 -07001840
1841 main.step( "Node became leader when it ran for election" )
1842 afterRun = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001843 # verify leader is ONOS1
Jon Hallfeff3082015-05-19 10:23:26 -07001844 if afterRun == ONOS1Ip:
1845 afterResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08001846 else:
Jon Hallfeff3082015-05-19 10:23:26 -07001847 afterResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001848
Jon Hall6aec96b2015-01-19 14:49:31 -08001849 utilities.assert_equals(
1850 expect=main.TRUE,
Jon Hallfeff3082015-05-19 10:23:26 -07001851 actual=afterResult,
1852 onpass="Old leader successfully re-ran for election",
1853 onfail="Something went wrong with Leadership election after " +
1854 "the old leader re-ran for election" )
Jon Hall390696c2015-05-05 17:13:41 -07001855
1856 def CASE16( self, main ):
1857 """
1858 Install Distributed Primitives app
1859 """
1860 assert numControllers, "numControllers not defined"
1861 assert main, "main not defined"
1862 assert utilities.assert_equals, "utilities.assert_equals not defined"
1863 assert CLIs, "CLIs not defined"
1864 assert nodes, "nodes not defined"
1865
1866 # Variables for the distributed primitives tests
1867 global pCounterName
1868 global iCounterName
1869 global pCounterValue
1870 global iCounterValue
1871 global onosSet
1872 global onosSetName
1873 pCounterName = "TestON-Partitions"
1874 iCounterName = "TestON-inMemory"
1875 pCounterValue = 0
1876 iCounterValue = 0
1877 onosSet = set([])
1878 onosSetName = "TestON-set"
1879
1880 description = "Install Primitives app"
1881 main.case( description )
1882 main.step( "Install Primitives app" )
1883 appName = "org.onosproject.distributedprimitives"
1884 appResults = CLIs[0].activateApp( appName )
1885 utilities.assert_equals( expect=main.TRUE,
1886 actual=appResults,
1887 onpass="Primitives app activated",
1888 onfail="Primitives app not activated" )
1889
1890 def CASE17( self, main ):
1891 """
1892 Check for basic functionality with distributed primitives
1893 """
Jon Hall40d2cbd2015-06-03 16:24:29 -07001894 import json
Jon Hall390696c2015-05-05 17:13:41 -07001895 # Make sure variables are defined/set
1896 assert numControllers, "numControllers not defined"
1897 assert main, "main not defined"
1898 assert utilities.assert_equals, "utilities.assert_equals not defined"
1899 assert CLIs, "CLIs not defined"
1900 assert nodes, "nodes not defined"
1901 assert pCounterName, "pCounterName not defined"
1902 assert iCounterName, "iCounterName not defined"
1903 assert onosSetName, "onosSetName not defined"
1904 # NOTE: assert fails if value is 0/None/Empty/False
1905 try:
1906 pCounterValue
1907 except NameError:
1908 main.log.error( "pCounterValue not defined, setting to 0" )
1909 pCounterValue = 0
1910 try:
1911 iCounterValue
1912 except NameError:
1913 main.log.error( "iCounterValue not defined, setting to 0" )
1914 iCounterValue = 0
1915 try:
1916 onosSet
1917 except NameError:
1918 main.log.error( "onosSet not defined, setting to empty Set" )
1919 onosSet = set([])
1920 # Variables for the distributed primitives tests. These are local only
1921 addValue = "a"
1922 addAllValue = "a b c d e f"
1923 retainValue = "c d e f"
1924
1925 description = "Check for basic functionality with distributed " +\
1926 "primitives"
1927 main.case( description )
1928 main.caseExplaination = "Test the methods of the distributed primitives (counters and sets) throught the cli"
1929 # DISTRIBUTED ATOMIC COUNTERS
1930 main.step( "Increment and get a default counter on each node" )
1931 pCounters = []
1932 threads = []
Jon Hallfeff3082015-05-19 10:23:26 -07001933 addedPValues = []
Jon Hall390696c2015-05-05 17:13:41 -07001934 for i in range( numControllers ):
1935 t = main.Thread( target=CLIs[i].counterTestIncrement,
1936 name="counterIncrement-" + str( i ),
1937 args=[ pCounterName ] )
1938 pCounterValue += 1
Jon Hallfeff3082015-05-19 10:23:26 -07001939 addedPValues.append( pCounterValue )
Jon Hall390696c2015-05-05 17:13:41 -07001940 threads.append( t )
1941 t.start()
1942
1943 for t in threads:
1944 t.join()
1945 pCounters.append( t.result )
1946 # Check that counter incremented numController times
1947 pCounterResults = True
Jon Hallfeff3082015-05-19 10:23:26 -07001948 for i in addedPValues:
Jon Hall40d2cbd2015-06-03 16:24:29 -07001949 tmpResult = i in pCounters
Jon Hallfeff3082015-05-19 10:23:26 -07001950 pCounterResults = pCounterResults and tmpResult
1951 if not tmpResult:
1952 main.log.error( str( i ) + " is not in partitioned "
1953 "counter incremented results" )
Jon Hall390696c2015-05-05 17:13:41 -07001954 utilities.assert_equals( expect=True,
1955 actual=pCounterResults,
1956 onpass="Default counter incremented",
1957 onfail="Error incrementing default" +
1958 " counter" )
1959
1960 main.step( "Increment and get an in memory counter on each node" )
1961 iCounters = []
Jon Hallfeff3082015-05-19 10:23:26 -07001962 addedIValues = []
Jon Hall390696c2015-05-05 17:13:41 -07001963 threads = []
1964 for i in range( numControllers ):
1965 t = main.Thread( target=CLIs[i].counterTestIncrement,
1966 name="icounterIncrement-" + str( i ),
1967 args=[ iCounterName ],
1968 kwargs={ "inMemory": True } )
1969 iCounterValue += 1
Jon Hallfeff3082015-05-19 10:23:26 -07001970 addedIValues.append( iCounterValue )
Jon Hall390696c2015-05-05 17:13:41 -07001971 threads.append( t )
1972 t.start()
1973
1974 for t in threads:
1975 t.join()
1976 iCounters.append( t.result )
1977 # Check that counter incremented numController times
1978 iCounterResults = True
Jon Hallfeff3082015-05-19 10:23:26 -07001979 for i in addedIValues:
1980 tmpResult = i in iCounters
1981 iCounterResults = iCounterResults and tmpResult
1982 if not tmpResult:
1983 main.log.error( str( i ) + " is not in the in-memory "
1984 "counter incremented results" )
Jon Hall390696c2015-05-05 17:13:41 -07001985 utilities.assert_equals( expect=True,
1986 actual=iCounterResults,
1987 onpass="In memory counter incremented",
1988 onfail="Error incrementing in memory" +
1989 " counter" )
1990
1991 main.step( "Check counters are consistant across nodes" )
1992 onosCounters = []
1993 threads = []
1994 for i in range( numControllers ):
1995 t = main.Thread( target=CLIs[i].counters,
1996 name="counters-" + str( i ) )
1997 threads.append( t )
1998 t.start()
1999 for t in threads:
2000 t.join()
2001 onosCounters.append( t.result )
2002 tmp = [ i == onosCounters[ 0 ] for i in onosCounters ]
2003 if all( tmp ):
2004 main.log.info( "Counters are consistent across all nodes" )
2005 consistentCounterResults = main.TRUE
2006 else:
2007 main.log.error( "Counters are not consistent across all nodes" )
2008 consistentCounterResults = main.FALSE
2009 utilities.assert_equals( expect=main.TRUE,
2010 actual=consistentCounterResults,
2011 onpass="ONOS counters are consistent " +
2012 "across nodes",
2013 onfail="ONOS Counters are inconsistent " +
2014 "across nodes" )
2015
2016 main.step( "Counters we added have the correct values" )
2017 correctResults = main.TRUE
2018 for i in range( numControllers ):
Jon Hall40d2cbd2015-06-03 16:24:29 -07002019 current = json.loads( onosCounters[i] )
2020 pValue = None
2021 iValue = None
Jon Hall390696c2015-05-05 17:13:41 -07002022 try:
Jon Hall40d2cbd2015-06-03 16:24:29 -07002023 for database in current:
2024 partitioned = database.get( 'partitionedDatabaseCounters' )
2025 if partitioned:
2026 for value in partitioned:
2027 if value.get( 'name' ) == pCounterName:
2028 pValue = value.get( 'value' )
2029 break
2030 inMemory = database.get( 'inMemoryDatabaseCounters' )
2031 if inMemory:
2032 for value in inMemory:
2033 if value.get( 'name' ) == iCounterName:
2034 iValue = value.get( 'value' )
2035 break
Jon Hall390696c2015-05-05 17:13:41 -07002036 except AttributeError, e:
2037 main.log.error( "ONOS" + str( i + 1 ) + " counters result " +
2038 "is not as expected" )
2039 correctResults = main.FALSE
Jon Hall40d2cbd2015-06-03 16:24:29 -07002040 if pValue == pCounterValue:
2041 main.log.info( "Partitioned counter value is correct" )
2042 else:
2043 main.log.error( "Partitioned counter value is incorrect," +
2044 " expected value: " + str( pCounterValue )
2045 + " current value: " + str( pValue ) )
2046 correctResults = main.FALSE
2047 if iValue == iCounterValue:
2048 main.log.info( "In memory counter value is correct" )
2049 else:
2050 main.log.error( "In memory counter value is incorrect, " +
2051 "expected value: " + str( iCounterValue ) +
2052 " current value: " + str( iValue ) )
2053 correctResults = main.FALSE
Jon Hall390696c2015-05-05 17:13:41 -07002054 utilities.assert_equals( expect=main.TRUE,
2055 actual=correctResults,
2056 onpass="Added counters are correct",
2057 onfail="Added counters are incorrect" )
2058 # DISTRIBUTED SETS
2059 main.step( "Distributed Set get" )
2060 size = len( onosSet )
2061 getResponses = []
2062 threads = []
2063 for i in range( numControllers ):
2064 t = main.Thread( target=CLIs[i].setTestGet,
2065 name="setTestGet-" + str( i ),
2066 args=[ onosSetName ] )
2067 threads.append( t )
2068 t.start()
2069 for t in threads:
2070 t.join()
2071 getResponses.append( t.result )
2072
2073 getResults = main.TRUE
2074 for i in range( numControllers ):
2075 if isinstance( getResponses[ i ], list):
2076 current = set( getResponses[ i ] )
2077 if len( current ) == len( getResponses[ i ] ):
2078 # no repeats
2079 if onosSet != current:
2080 main.log.error( "ONOS" + str( i + 1 ) +
2081 " has incorrect view" +
2082 " of set " + onosSetName + ":\n" +
2083 str( getResponses[ i ] ) )
2084 main.log.debug( "Expected: " + str( onosSet ) )
2085 main.log.debug( "Actual: " + str( current ) )
2086 getResults = main.FALSE
2087 else:
2088 # error, set is not a set
2089 main.log.error( "ONOS" + str( i + 1 ) +
2090 " has repeat elements in" +
2091 " set " + onosSetName + ":\n" +
2092 str( getResponses[ i ] ) )
2093 getResults = main.FALSE
2094 elif getResponses[ i ] == main.ERROR:
2095 getResults = main.FALSE
2096 utilities.assert_equals( expect=main.TRUE,
2097 actual=getResults,
2098 onpass="Set elements are correct",
2099 onfail="Set elements are incorrect" )
2100
2101 main.step( "Distributed Set size" )
2102 sizeResponses = []
2103 threads = []
2104 for i in range( numControllers ):
2105 t = main.Thread( target=CLIs[i].setTestSize,
2106 name="setTestSize-" + str( i ),
2107 args=[ onosSetName ] )
2108 threads.append( t )
2109 t.start()
2110 for t in threads:
2111 t.join()
2112 sizeResponses.append( t.result )
2113
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 utilities.assert_equals( expect=main.TRUE,
2123 actual=sizeResults,
2124 onpass="Set sizes are correct",
2125 onfail="Set sizes are incorrect" )
2126
2127 main.step( "Distributed Set add()" )
2128 onosSet.add( addValue )
2129 addResponses = []
2130 threads = []
2131 for i in range( numControllers ):
2132 t = main.Thread( target=CLIs[i].setTestAdd,
2133 name="setTestAdd-" + str( i ),
2134 args=[ onosSetName, addValue ] )
2135 threads.append( t )
2136 t.start()
2137 for t in threads:
2138 t.join()
2139 addResponses.append( t.result )
2140
2141 # main.TRUE = successfully changed the set
2142 # main.FALSE = action resulted in no change in set
2143 # main.ERROR - Some error in executing the function
2144 addResults = main.TRUE
2145 for i in range( numControllers ):
2146 if addResponses[ i ] == main.TRUE:
2147 # All is well
2148 pass
2149 elif addResponses[ i ] == main.FALSE:
2150 # Already in set, probably fine
2151 pass
2152 elif addResponses[ i ] == main.ERROR:
2153 # Error in execution
2154 addResults = main.FALSE
2155 else:
2156 # unexpected result
2157 addResults = main.FALSE
2158 if addResults != main.TRUE:
2159 main.log.error( "Error executing set add" )
2160
2161 # Check if set is still correct
2162 size = len( onosSet )
2163 getResponses = []
2164 threads = []
2165 for i in range( numControllers ):
2166 t = main.Thread( target=CLIs[i].setTestGet,
2167 name="setTestGet-" + str( i ),
2168 args=[ onosSetName ] )
2169 threads.append( t )
2170 t.start()
2171 for t in threads:
2172 t.join()
2173 getResponses.append( t.result )
2174 getResults = main.TRUE
2175 for i in range( numControllers ):
2176 if isinstance( getResponses[ i ], list):
2177 current = set( getResponses[ i ] )
2178 if len( current ) == len( getResponses[ i ] ):
2179 # no repeats
2180 if onosSet != current:
2181 main.log.error( "ONOS" + str( i + 1 ) +
2182 " has incorrect view" +
2183 " of set " + onosSetName + ":\n" +
2184 str( getResponses[ i ] ) )
2185 main.log.debug( "Expected: " + str( onosSet ) )
2186 main.log.debug( "Actual: " + str( current ) )
2187 getResults = main.FALSE
2188 else:
2189 # error, set is not a set
2190 main.log.error( "ONOS" + str( i + 1 ) +
2191 " has repeat elements in" +
2192 " set " + onosSetName + ":\n" +
2193 str( getResponses[ i ] ) )
2194 getResults = main.FALSE
2195 elif getResponses[ i ] == main.ERROR:
2196 getResults = main.FALSE
2197 sizeResponses = []
2198 threads = []
2199 for i in range( numControllers ):
2200 t = main.Thread( target=CLIs[i].setTestSize,
2201 name="setTestSize-" + str( i ),
2202 args=[ onosSetName ] )
2203 threads.append( t )
2204 t.start()
2205 for t in threads:
2206 t.join()
2207 sizeResponses.append( t.result )
2208 sizeResults = main.TRUE
2209 for i in range( numControllers ):
2210 if size != sizeResponses[ i ]:
2211 sizeResults = main.FALSE
2212 main.log.error( "ONOS" + str( i + 1 ) +
2213 " expected a size of " + str( size ) +
2214 " for set " + onosSetName +
2215 " but got " + str( sizeResponses[ i ] ) )
2216 addResults = addResults and getResults and sizeResults
2217 utilities.assert_equals( expect=main.TRUE,
2218 actual=addResults,
2219 onpass="Set add correct",
2220 onfail="Set add was incorrect" )
2221
2222 main.step( "Distributed Set addAll()" )
2223 onosSet.update( addAllValue.split() )
2224 addResponses = []
2225 threads = []
2226 for i in range( numControllers ):
2227 t = main.Thread( target=CLIs[i].setTestAdd,
2228 name="setTestAddAll-" + str( i ),
2229 args=[ onosSetName, addAllValue ] )
2230 threads.append( t )
2231 t.start()
2232 for t in threads:
2233 t.join()
2234 addResponses.append( t.result )
2235
2236 # main.TRUE = successfully changed the set
2237 # main.FALSE = action resulted in no change in set
2238 # main.ERROR - Some error in executing the function
2239 addAllResults = main.TRUE
2240 for i in range( numControllers ):
2241 if addResponses[ i ] == main.TRUE:
2242 # All is well
2243 pass
2244 elif addResponses[ i ] == main.FALSE:
2245 # Already in set, probably fine
2246 pass
2247 elif addResponses[ i ] == main.ERROR:
2248 # Error in execution
2249 addAllResults = main.FALSE
2250 else:
2251 # unexpected result
2252 addAllResults = main.FALSE
2253 if addAllResults != main.TRUE:
2254 main.log.error( "Error executing set addAll" )
2255
2256 # Check if set is still correct
2257 size = len( onosSet )
2258 getResponses = []
2259 threads = []
2260 for i in range( numControllers ):
2261 t = main.Thread( target=CLIs[i].setTestGet,
2262 name="setTestGet-" + str( i ),
2263 args=[ onosSetName ] )
2264 threads.append( t )
2265 t.start()
2266 for t in threads:
2267 t.join()
2268 getResponses.append( t.result )
2269 getResults = main.TRUE
2270 for i in range( numControllers ):
2271 if isinstance( getResponses[ i ], list):
2272 current = set( getResponses[ i ] )
2273 if len( current ) == len( getResponses[ i ] ):
2274 # no repeats
2275 if onosSet != current:
2276 main.log.error( "ONOS" + str( i + 1 ) +
2277 " has incorrect view" +
2278 " of set " + onosSetName + ":\n" +
2279 str( getResponses[ i ] ) )
2280 main.log.debug( "Expected: " + str( onosSet ) )
2281 main.log.debug( "Actual: " + str( current ) )
2282 getResults = main.FALSE
2283 else:
2284 # error, set is not a set
2285 main.log.error( "ONOS" + str( i + 1 ) +
2286 " has repeat elements in" +
2287 " set " + onosSetName + ":\n" +
2288 str( getResponses[ i ] ) )
2289 getResults = main.FALSE
2290 elif getResponses[ i ] == main.ERROR:
2291 getResults = main.FALSE
2292 sizeResponses = []
2293 threads = []
2294 for i in range( numControllers ):
2295 t = main.Thread( target=CLIs[i].setTestSize,
2296 name="setTestSize-" + str( i ),
2297 args=[ onosSetName ] )
2298 threads.append( t )
2299 t.start()
2300 for t in threads:
2301 t.join()
2302 sizeResponses.append( t.result )
2303 sizeResults = main.TRUE
2304 for i in range( numControllers ):
2305 if size != sizeResponses[ i ]:
2306 sizeResults = main.FALSE
2307 main.log.error( "ONOS" + str( i + 1 ) +
2308 " expected a size of " + str( size ) +
2309 " for set " + onosSetName +
2310 " but got " + str( sizeResponses[ i ] ) )
2311 addAllResults = addAllResults and getResults and sizeResults
2312 utilities.assert_equals( expect=main.TRUE,
2313 actual=addAllResults,
2314 onpass="Set addAll correct",
2315 onfail="Set addAll was incorrect" )
2316
2317 main.step( "Distributed Set contains()" )
2318 containsResponses = []
2319 threads = []
2320 for i in range( numControllers ):
2321 t = main.Thread( target=CLIs[i].setTestGet,
2322 name="setContains-" + str( i ),
2323 args=[ onosSetName ],
2324 kwargs={ "values": addValue } )
2325 threads.append( t )
2326 t.start()
2327 for t in threads:
2328 t.join()
2329 # NOTE: This is the tuple
2330 containsResponses.append( t.result )
2331
2332 containsResults = main.TRUE
2333 for i in range( numControllers ):
2334 if containsResponses[ i ] == main.ERROR:
2335 containsResults = main.FALSE
2336 else:
2337 containsResults = containsResults and\
2338 containsResponses[ i ][ 1 ]
2339 utilities.assert_equals( expect=main.TRUE,
2340 actual=containsResults,
2341 onpass="Set contains is functional",
2342 onfail="Set contains failed" )
2343
2344 main.step( "Distributed Set containsAll()" )
2345 containsAllResponses = []
2346 threads = []
2347 for i in range( numControllers ):
2348 t = main.Thread( target=CLIs[i].setTestGet,
2349 name="setContainsAll-" + str( i ),
2350 args=[ onosSetName ],
2351 kwargs={ "values": addAllValue } )
2352 threads.append( t )
2353 t.start()
2354 for t in threads:
2355 t.join()
2356 # NOTE: This is the tuple
2357 containsAllResponses.append( t.result )
2358
2359 containsAllResults = main.TRUE
2360 for i in range( numControllers ):
2361 if containsResponses[ i ] == main.ERROR:
2362 containsResults = main.FALSE
2363 else:
2364 containsResults = containsResults and\
2365 containsResponses[ i ][ 1 ]
2366 utilities.assert_equals( expect=main.TRUE,
2367 actual=containsAllResults,
2368 onpass="Set containsAll is functional",
2369 onfail="Set containsAll failed" )
2370
2371 main.step( "Distributed Set remove()" )
2372 onosSet.remove( addValue )
2373 removeResponses = []
2374 threads = []
2375 for i in range( numControllers ):
2376 t = main.Thread( target=CLIs[i].setTestRemove,
2377 name="setTestRemove-" + str( i ),
2378 args=[ onosSetName, addValue ] )
2379 threads.append( t )
2380 t.start()
2381 for t in threads:
2382 t.join()
2383 removeResponses.append( t.result )
2384
2385 # main.TRUE = successfully changed the set
2386 # main.FALSE = action resulted in no change in set
2387 # main.ERROR - Some error in executing the function
2388 removeResults = main.TRUE
2389 for i in range( numControllers ):
2390 if removeResponses[ i ] == main.TRUE:
2391 # All is well
2392 pass
2393 elif removeResponses[ i ] == main.FALSE:
2394 # not in set, probably fine
2395 pass
2396 elif removeResponses[ i ] == main.ERROR:
2397 # Error in execution
2398 removeResults = main.FALSE
2399 else:
2400 # unexpected result
2401 removeResults = main.FALSE
2402 if removeResults != main.TRUE:
2403 main.log.error( "Error executing set remove" )
2404
2405 # Check if set is still correct
2406 size = len( onosSet )
2407 getResponses = []
2408 threads = []
2409 for i in range( numControllers ):
2410 t = main.Thread( target=CLIs[i].setTestGet,
2411 name="setTestGet-" + str( i ),
2412 args=[ onosSetName ] )
2413 threads.append( t )
2414 t.start()
2415 for t in threads:
2416 t.join()
2417 getResponses.append( t.result )
2418 getResults = main.TRUE
2419 for i in range( numControllers ):
2420 if isinstance( getResponses[ i ], list):
2421 current = set( getResponses[ i ] )
2422 if len( current ) == len( getResponses[ i ] ):
2423 # no repeats
2424 if onosSet != current:
2425 main.log.error( "ONOS" + str( i + 1 ) +
2426 " has incorrect view" +
2427 " of set " + onosSetName + ":\n" +
2428 str( getResponses[ i ] ) )
2429 main.log.debug( "Expected: " + str( onosSet ) )
2430 main.log.debug( "Actual: " + str( current ) )
2431 getResults = main.FALSE
2432 else:
2433 # error, set is not a set
2434 main.log.error( "ONOS" + str( i + 1 ) +
2435 " has repeat elements in" +
2436 " set " + onosSetName + ":\n" +
2437 str( getResponses[ i ] ) )
2438 getResults = main.FALSE
2439 elif getResponses[ i ] == main.ERROR:
2440 getResults = main.FALSE
2441 sizeResponses = []
2442 threads = []
2443 for i in range( numControllers ):
2444 t = main.Thread( target=CLIs[i].setTestSize,
2445 name="setTestSize-" + str( i ),
2446 args=[ onosSetName ] )
2447 threads.append( t )
2448 t.start()
2449 for t in threads:
2450 t.join()
2451 sizeResponses.append( t.result )
2452 sizeResults = main.TRUE
2453 for i in range( numControllers ):
2454 if size != sizeResponses[ i ]:
2455 sizeResults = main.FALSE
2456 main.log.error( "ONOS" + str( i + 1 ) +
2457 " expected a size of " + str( size ) +
2458 " for set " + onosSetName +
2459 " but got " + str( sizeResponses[ i ] ) )
2460 removeResults = removeResults and getResults and sizeResults
2461 utilities.assert_equals( expect=main.TRUE,
2462 actual=removeResults,
2463 onpass="Set remove correct",
2464 onfail="Set remove was incorrect" )
2465
2466 main.step( "Distributed Set removeAll()" )
2467 onosSet.difference_update( addAllValue.split() )
2468 removeAllResponses = []
2469 threads = []
2470 try:
2471 for i in range( numControllers ):
2472 t = main.Thread( target=CLIs[i].setTestRemove,
2473 name="setTestRemoveAll-" + str( i ),
2474 args=[ onosSetName, addAllValue ] )
2475 threads.append( t )
2476 t.start()
2477 for t in threads:
2478 t.join()
2479 removeAllResponses.append( t.result )
2480 except Exception, e:
2481 main.log.exception(e)
2482
2483 # main.TRUE = successfully changed the set
2484 # main.FALSE = action resulted in no change in set
2485 # main.ERROR - Some error in executing the function
2486 removeAllResults = main.TRUE
2487 for i in range( numControllers ):
2488 if removeAllResponses[ i ] == main.TRUE:
2489 # All is well
2490 pass
2491 elif removeAllResponses[ i ] == main.FALSE:
2492 # not in set, probably fine
2493 pass
2494 elif removeAllResponses[ i ] == main.ERROR:
2495 # Error in execution
2496 removeAllResults = main.FALSE
2497 else:
2498 # unexpected result
2499 removeAllResults = main.FALSE
2500 if removeAllResults != main.TRUE:
2501 main.log.error( "Error executing set removeAll" )
2502
2503 # Check if set is still correct
2504 size = len( onosSet )
2505 getResponses = []
2506 threads = []
2507 for i in range( numControllers ):
2508 t = main.Thread( target=CLIs[i].setTestGet,
2509 name="setTestGet-" + str( i ),
2510 args=[ onosSetName ] )
2511 threads.append( t )
2512 t.start()
2513 for t in threads:
2514 t.join()
2515 getResponses.append( t.result )
2516 getResults = main.TRUE
2517 for i in range( numControllers ):
2518 if isinstance( getResponses[ i ], list):
2519 current = set( getResponses[ i ] )
2520 if len( current ) == len( getResponses[ i ] ):
2521 # no repeats
2522 if onosSet != current:
2523 main.log.error( "ONOS" + str( i + 1 ) +
2524 " has incorrect view" +
2525 " of set " + onosSetName + ":\n" +
2526 str( getResponses[ i ] ) )
2527 main.log.debug( "Expected: " + str( onosSet ) )
2528 main.log.debug( "Actual: " + str( current ) )
2529 getResults = main.FALSE
2530 else:
2531 # error, set is not a set
2532 main.log.error( "ONOS" + str( i + 1 ) +
2533 " has repeat elements in" +
2534 " set " + onosSetName + ":\n" +
2535 str( getResponses[ i ] ) )
2536 getResults = main.FALSE
2537 elif getResponses[ i ] == main.ERROR:
2538 getResults = main.FALSE
2539 sizeResponses = []
2540 threads = []
2541 for i in range( numControllers ):
2542 t = main.Thread( target=CLIs[i].setTestSize,
2543 name="setTestSize-" + str( i ),
2544 args=[ onosSetName ] )
2545 threads.append( t )
2546 t.start()
2547 for t in threads:
2548 t.join()
2549 sizeResponses.append( t.result )
2550 sizeResults = main.TRUE
2551 for i in range( numControllers ):
2552 if size != sizeResponses[ i ]:
2553 sizeResults = main.FALSE
2554 main.log.error( "ONOS" + str( i + 1 ) +
2555 " expected a size of " + str( size ) +
2556 " for set " + onosSetName +
2557 " but got " + str( sizeResponses[ i ] ) )
2558 removeAllResults = removeAllResults and getResults and sizeResults
2559 utilities.assert_equals( expect=main.TRUE,
2560 actual=removeAllResults,
2561 onpass="Set removeAll correct",
2562 onfail="Set removeAll was incorrect" )
2563
2564 main.step( "Distributed Set addAll()" )
2565 onosSet.update( addAllValue.split() )
2566 addResponses = []
2567 threads = []
2568 for i in range( numControllers ):
2569 t = main.Thread( target=CLIs[i].setTestAdd,
2570 name="setTestAddAll-" + str( i ),
2571 args=[ onosSetName, addAllValue ] )
2572 threads.append( t )
2573 t.start()
2574 for t in threads:
2575 t.join()
2576 addResponses.append( t.result )
2577
2578 # main.TRUE = successfully changed the set
2579 # main.FALSE = action resulted in no change in set
2580 # main.ERROR - Some error in executing the function
2581 addAllResults = main.TRUE
2582 for i in range( numControllers ):
2583 if addResponses[ i ] == main.TRUE:
2584 # All is well
2585 pass
2586 elif addResponses[ i ] == main.FALSE:
2587 # Already in set, probably fine
2588 pass
2589 elif addResponses[ i ] == main.ERROR:
2590 # Error in execution
2591 addAllResults = main.FALSE
2592 else:
2593 # unexpected result
2594 addAllResults = main.FALSE
2595 if addAllResults != main.TRUE:
2596 main.log.error( "Error executing set addAll" )
2597
2598 # Check if set is still correct
2599 size = len( onosSet )
2600 getResponses = []
2601 threads = []
2602 for i in range( numControllers ):
2603 t = main.Thread( target=CLIs[i].setTestGet,
2604 name="setTestGet-" + str( i ),
2605 args=[ onosSetName ] )
2606 threads.append( t )
2607 t.start()
2608 for t in threads:
2609 t.join()
2610 getResponses.append( t.result )
2611 getResults = main.TRUE
2612 for i in range( numControllers ):
2613 if isinstance( getResponses[ i ], list):
2614 current = set( getResponses[ i ] )
2615 if len( current ) == len( getResponses[ i ] ):
2616 # no repeats
2617 if onosSet != current:
2618 main.log.error( "ONOS" + str( i + 1 ) +
2619 " has incorrect view" +
2620 " of set " + onosSetName + ":\n" +
2621 str( getResponses[ i ] ) )
2622 main.log.debug( "Expected: " + str( onosSet ) )
2623 main.log.debug( "Actual: " + str( current ) )
2624 getResults = main.FALSE
2625 else:
2626 # error, set is not a set
2627 main.log.error( "ONOS" + str( i + 1 ) +
2628 " has repeat elements in" +
2629 " set " + onosSetName + ":\n" +
2630 str( getResponses[ i ] ) )
2631 getResults = main.FALSE
2632 elif getResponses[ i ] == main.ERROR:
2633 getResults = main.FALSE
2634 sizeResponses = []
2635 threads = []
2636 for i in range( numControllers ):
2637 t = main.Thread( target=CLIs[i].setTestSize,
2638 name="setTestSize-" + str( i ),
2639 args=[ onosSetName ] )
2640 threads.append( t )
2641 t.start()
2642 for t in threads:
2643 t.join()
2644 sizeResponses.append( t.result )
2645 sizeResults = main.TRUE
2646 for i in range( numControllers ):
2647 if size != sizeResponses[ i ]:
2648 sizeResults = main.FALSE
2649 main.log.error( "ONOS" + str( i + 1 ) +
2650 " expected a size of " + str( size ) +
2651 " for set " + onosSetName +
2652 " but got " + str( sizeResponses[ i ] ) )
2653 addAllResults = addAllResults and getResults and sizeResults
2654 utilities.assert_equals( expect=main.TRUE,
2655 actual=addAllResults,
2656 onpass="Set addAll correct",
2657 onfail="Set addAll was incorrect" )
2658
2659 main.step( "Distributed Set clear()" )
2660 onosSet.clear()
2661 clearResponses = []
2662 threads = []
2663 for i in range( numControllers ):
2664 t = main.Thread( target=CLIs[i].setTestRemove,
2665 name="setTestClear-" + str( i ),
2666 args=[ onosSetName, " "], # Values doesn't matter
2667 kwargs={ "clear": True } )
2668 threads.append( t )
2669 t.start()
2670 for t in threads:
2671 t.join()
2672 clearResponses.append( t.result )
2673
2674 # main.TRUE = successfully changed the set
2675 # main.FALSE = action resulted in no change in set
2676 # main.ERROR - Some error in executing the function
2677 clearResults = main.TRUE
2678 for i in range( numControllers ):
2679 if clearResponses[ i ] == main.TRUE:
2680 # All is well
2681 pass
2682 elif clearResponses[ i ] == main.FALSE:
2683 # Nothing set, probably fine
2684 pass
2685 elif clearResponses[ i ] == main.ERROR:
2686 # Error in execution
2687 clearResults = main.FALSE
2688 else:
2689 # unexpected result
2690 clearResults = main.FALSE
2691 if clearResults != main.TRUE:
2692 main.log.error( "Error executing set clear" )
2693
2694 # Check if set is still correct
2695 size = len( onosSet )
2696 getResponses = []
2697 threads = []
2698 for i in range( numControllers ):
2699 t = main.Thread( target=CLIs[i].setTestGet,
2700 name="setTestGet-" + str( i ),
2701 args=[ onosSetName ] )
2702 threads.append( t )
2703 t.start()
2704 for t in threads:
2705 t.join()
2706 getResponses.append( t.result )
2707 getResults = main.TRUE
2708 for i in range( numControllers ):
2709 if isinstance( getResponses[ i ], list):
2710 current = set( getResponses[ i ] )
2711 if len( current ) == len( getResponses[ i ] ):
2712 # no repeats
2713 if onosSet != current:
2714 main.log.error( "ONOS" + str( i + 1 ) +
2715 " has incorrect view" +
2716 " of set " + onosSetName + ":\n" +
2717 str( getResponses[ i ] ) )
2718 main.log.debug( "Expected: " + str( onosSet ) )
2719 main.log.debug( "Actual: " + str( current ) )
2720 getResults = main.FALSE
2721 else:
2722 # error, set is not a set
2723 main.log.error( "ONOS" + str( i + 1 ) +
2724 " has repeat elements in" +
2725 " set " + onosSetName + ":\n" +
2726 str( getResponses[ i ] ) )
2727 getResults = main.FALSE
2728 elif getResponses[ i ] == main.ERROR:
2729 getResults = main.FALSE
2730 sizeResponses = []
2731 threads = []
2732 for i in range( numControllers ):
2733 t = main.Thread( target=CLIs[i].setTestSize,
2734 name="setTestSize-" + str( i ),
2735 args=[ onosSetName ] )
2736 threads.append( t )
2737 t.start()
2738 for t in threads:
2739 t.join()
2740 sizeResponses.append( t.result )
2741 sizeResults = main.TRUE
2742 for i in range( numControllers ):
2743 if size != sizeResponses[ i ]:
2744 sizeResults = main.FALSE
2745 main.log.error( "ONOS" + str( i + 1 ) +
2746 " expected a size of " + str( size ) +
2747 " for set " + onosSetName +
2748 " but got " + str( sizeResponses[ i ] ) )
2749 clearResults = clearResults and getResults and sizeResults
2750 utilities.assert_equals( expect=main.TRUE,
2751 actual=clearResults,
2752 onpass="Set clear correct",
2753 onfail="Set clear was incorrect" )
2754
2755 main.step( "Distributed Set addAll()" )
2756 onosSet.update( addAllValue.split() )
2757 addResponses = []
2758 threads = []
2759 for i in range( numControllers ):
2760 t = main.Thread( target=CLIs[i].setTestAdd,
2761 name="setTestAddAll-" + str( i ),
2762 args=[ onosSetName, addAllValue ] )
2763 threads.append( t )
2764 t.start()
2765 for t in threads:
2766 t.join()
2767 addResponses.append( t.result )
2768
2769 # main.TRUE = successfully changed the set
2770 # main.FALSE = action resulted in no change in set
2771 # main.ERROR - Some error in executing the function
2772 addAllResults = main.TRUE
2773 for i in range( numControllers ):
2774 if addResponses[ i ] == main.TRUE:
2775 # All is well
2776 pass
2777 elif addResponses[ i ] == main.FALSE:
2778 # Already in set, probably fine
2779 pass
2780 elif addResponses[ i ] == main.ERROR:
2781 # Error in execution
2782 addAllResults = main.FALSE
2783 else:
2784 # unexpected result
2785 addAllResults = main.FALSE
2786 if addAllResults != main.TRUE:
2787 main.log.error( "Error executing set addAll" )
2788
2789 # Check if set is still correct
2790 size = len( onosSet )
2791 getResponses = []
2792 threads = []
2793 for i in range( numControllers ):
2794 t = main.Thread( target=CLIs[i].setTestGet,
2795 name="setTestGet-" + str( i ),
2796 args=[ onosSetName ] )
2797 threads.append( t )
2798 t.start()
2799 for t in threads:
2800 t.join()
2801 getResponses.append( t.result )
2802 getResults = main.TRUE
2803 for i in range( numControllers ):
2804 if isinstance( getResponses[ i ], list):
2805 current = set( getResponses[ i ] )
2806 if len( current ) == len( getResponses[ i ] ):
2807 # no repeats
2808 if onosSet != current:
2809 main.log.error( "ONOS" + str( i + 1 ) +
2810 " has incorrect view" +
2811 " of set " + onosSetName + ":\n" +
2812 str( getResponses[ i ] ) )
2813 main.log.debug( "Expected: " + str( onosSet ) )
2814 main.log.debug( "Actual: " + str( current ) )
2815 getResults = main.FALSE
2816 else:
2817 # error, set is not a set
2818 main.log.error( "ONOS" + str( i + 1 ) +
2819 " has repeat elements in" +
2820 " set " + onosSetName + ":\n" +
2821 str( getResponses[ i ] ) )
2822 getResults = main.FALSE
2823 elif getResponses[ i ] == main.ERROR:
2824 getResults = main.FALSE
2825 sizeResponses = []
2826 threads = []
2827 for i in range( numControllers ):
2828 t = main.Thread( target=CLIs[i].setTestSize,
2829 name="setTestSize-" + str( i ),
2830 args=[ onosSetName ] )
2831 threads.append( t )
2832 t.start()
2833 for t in threads:
2834 t.join()
2835 sizeResponses.append( t.result )
2836 sizeResults = main.TRUE
2837 for i in range( numControllers ):
2838 if size != sizeResponses[ i ]:
2839 sizeResults = main.FALSE
2840 main.log.error( "ONOS" + str( i + 1 ) +
2841 " expected a size of " + str( size ) +
2842 " for set " + onosSetName +
2843 " but got " + str( sizeResponses[ i ] ) )
2844 addAllResults = addAllResults and getResults and sizeResults
2845 utilities.assert_equals( expect=main.TRUE,
2846 actual=addAllResults,
2847 onpass="Set addAll correct",
2848 onfail="Set addAll was incorrect" )
2849
2850 main.step( "Distributed Set retain()" )
2851 onosSet.intersection_update( retainValue.split() )
2852 retainResponses = []
2853 threads = []
2854 for i in range( numControllers ):
2855 t = main.Thread( target=CLIs[i].setTestRemove,
2856 name="setTestRetain-" + str( i ),
2857 args=[ onosSetName, retainValue ],
2858 kwargs={ "retain": True } )
2859 threads.append( t )
2860 t.start()
2861 for t in threads:
2862 t.join()
2863 retainResponses.append( t.result )
2864
2865 # main.TRUE = successfully changed the set
2866 # main.FALSE = action resulted in no change in set
2867 # main.ERROR - Some error in executing the function
2868 retainResults = main.TRUE
2869 for i in range( numControllers ):
2870 if retainResponses[ i ] == main.TRUE:
2871 # All is well
2872 pass
2873 elif retainResponses[ i ] == main.FALSE:
2874 # Already in set, probably fine
2875 pass
2876 elif retainResponses[ i ] == main.ERROR:
2877 # Error in execution
2878 retainResults = main.FALSE
2879 else:
2880 # unexpected result
2881 retainResults = main.FALSE
2882 if retainResults != main.TRUE:
2883 main.log.error( "Error executing set retain" )
2884
2885 # Check if set is still correct
2886 size = len( onosSet )
2887 getResponses = []
2888 threads = []
2889 for i in range( numControllers ):
2890 t = main.Thread( target=CLIs[i].setTestGet,
2891 name="setTestGet-" + str( i ),
2892 args=[ onosSetName ] )
2893 threads.append( t )
2894 t.start()
2895 for t in threads:
2896 t.join()
2897 getResponses.append( t.result )
2898 getResults = main.TRUE
2899 for i in range( numControllers ):
2900 if isinstance( getResponses[ i ], list):
2901 current = set( getResponses[ i ] )
2902 if len( current ) == len( getResponses[ i ] ):
2903 # no repeats
2904 if onosSet != current:
2905 main.log.error( "ONOS" + str( i + 1 ) +
2906 " has incorrect view" +
2907 " of set " + onosSetName + ":\n" +
2908 str( getResponses[ i ] ) )
2909 main.log.debug( "Expected: " + str( onosSet ) )
2910 main.log.debug( "Actual: " + str( current ) )
2911 getResults = main.FALSE
2912 else:
2913 # error, set is not a set
2914 main.log.error( "ONOS" + str( i + 1 ) +
2915 " has repeat elements in" +
2916 " set " + onosSetName + ":\n" +
2917 str( getResponses[ i ] ) )
2918 getResults = main.FALSE
2919 elif getResponses[ i ] == main.ERROR:
2920 getResults = main.FALSE
2921 sizeResponses = []
2922 threads = []
2923 for i in range( numControllers ):
2924 t = main.Thread( target=CLIs[i].setTestSize,
2925 name="setTestSize-" + str( i ),
2926 args=[ onosSetName ] )
2927 threads.append( t )
2928 t.start()
2929 for t in threads:
2930 t.join()
2931 sizeResponses.append( t.result )
2932 sizeResults = main.TRUE
2933 for i in range( numControllers ):
2934 if size != sizeResponses[ i ]:
2935 sizeResults = main.FALSE
2936 main.log.error( "ONOS" + str( i + 1 ) +
2937 " expected a size of " +
2938 str( size ) + " for set " + onosSetName +
2939 " but got " + str( sizeResponses[ i ] ) )
2940 retainResults = retainResults and getResults and sizeResults
2941 utilities.assert_equals( expect=main.TRUE,
2942 actual=retainResults,
2943 onpass="Set retain correct",
2944 onfail="Set retain was incorrect" )
2945