blob: d2f0bc9afb2232f7327a973dd93a2424ebdc5317 [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 Hall6aec96b2015-01-19 14:49:31 -080021"""
Jon Hall8f89dda2015-01-22 16:03:33 -080022
23
Jon Hall48cf3ce2015-01-12 15:43:18 -080024class HATestSingleInstanceRestart:
Jon Hall73cf9cc2014-11-20 22:28:38 -080025
Jon Hall6aec96b2015-01-19 14:49:31 -080026 def __init__( self ):
Jon Hall73cf9cc2014-11-20 22:28:38 -080027 self.default = ''
28
Jon Hall6aec96b2015-01-19 14:49:31 -080029 def CASE1( self, main ):
30 """
Jon Hall73cf9cc2014-11-20 22:28:38 -080031 CASE1 is to compile ONOS and push it to the test machines
32
33 Startup sequence:
Jon Hall73cf9cc2014-11-20 22:28:38 -080034 cell <name>
35 onos-verify-cell
36 NOTE: temporary - onos-remove-raft-logs
Jon Hall58c76b72015-02-23 11:09:24 -080037 onos-uninstall
38 start mininet
39 git pull
40 mvn clean install
41 onos-package
Jon Hall73cf9cc2014-11-20 22:28:38 -080042 onos-install -f
43 onos-wait-for-start
Jon Hall58c76b72015-02-23 11:09:24 -080044 start cli sessions
45 start tcpdump
Jon Hall6aec96b2015-01-19 14:49:31 -080046 """
47 main.log.report( "ONOS Single node cluster restart " +
48 "HA test - initialization" )
49 main.case( "Setting up test environment" )
50 # TODO: save all the timers and output them for plotting
Jon Hall73cf9cc2014-11-20 22:28:38 -080051
Jon Hall5cfd23c2015-03-19 11:40:57 -070052 # load some variables from the params file
Jon Hall8f89dda2015-01-22 16:03:33 -080053 PULLCODE = False
Jon Hall6aec96b2015-01-19 14:49:31 -080054 if main.params[ 'Git' ] == 'True':
Jon Hall8f89dda2015-01-22 16:03:33 -080055 PULLCODE = True
Jon Hall529a37f2015-01-28 10:02:00 -080056 gitBranch = main.params[ 'branch' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080057 cellName = main.params[ 'ENV' ][ 'cellName' ]
Jon Hall6aec96b2015-01-19 14:49:31 -080058
59 # set global variables
Jon Hall8f89dda2015-01-22 16:03:33 -080060 global ONOS1Ip
61 global ONOS1Port
Jon Hall8f89dda2015-01-22 16:03:33 -080062 global ONOS2Port
Jon Hall8f89dda2015-01-22 16:03:33 -080063 global ONOS3Port
Jon Hall8f89dda2015-01-22 16:03:33 -080064 global ONOS4Port
Jon Hall8f89dda2015-01-22 16:03:33 -080065 global ONOS5Port
Jon Hall8f89dda2015-01-22 16:03:33 -080066 global ONOS6Port
Jon Hall8f89dda2015-01-22 16:03:33 -080067 global ONOS7Port
68 global numControllers
Jon Hall5cfd23c2015-03-19 11:40:57 -070069 numControllers = int( main.params[ 'num_controllers' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -080070
Jon Hall8f89dda2015-01-22 16:03:33 -080071 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
72 ONOS1Port = main.params[ 'CTRL' ][ 'port1' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080073 ONOS2Port = main.params[ 'CTRL' ][ 'port2' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080074 ONOS3Port = main.params[ 'CTRL' ][ 'port3' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080075 ONOS4Port = main.params[ 'CTRL' ][ 'port4' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080076 ONOS5Port = main.params[ 'CTRL' ][ 'port5' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080077 ONOS6Port = main.params[ 'CTRL' ][ 'port6' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080078 ONOS7Port = main.params[ 'CTRL' ][ 'port7' ]
Jon Hall73cf9cc2014-11-20 22:28:38 -080079
Jon Halla9d26da2015-03-30 16:45:32 -070080 global CLIs
81 CLIs = []
82 global nodes
83 nodes = []
84 for i in range( 1, numControllers + 1 ):
85 CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
86 nodes.append( getattr( main, 'ONOS' + str( i ) ) )
87
Jon Hall6aec96b2015-01-19 14:49:31 -080088 main.step( "Applying cell variable to environment" )
Jon Hall8f89dda2015-01-22 16:03:33 -080089 cellResult = main.ONOSbench.setCell( cellName )
90 verifyResult = main.ONOSbench.verifyCell()
Jon Hall73cf9cc2014-11-20 22:28:38 -080091
Jon Hall6aec96b2015-01-19 14:49:31 -080092 # FIXME:this is short term fix
93 main.log.report( "Removing raft logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -080094 main.ONOSbench.onosRemoveRaftLogs()
Jon Halla9d26da2015-03-30 16:45:32 -070095
Jon Hall6aec96b2015-01-19 14:49:31 -080096 main.log.report( "Uninstalling ONOS" )
Jon Halla9d26da2015-03-30 16:45:32 -070097 for node in nodes:
98 main.ONOSbench.onosUninstall( node.ip_address )
Jon Hall73cf9cc2014-11-20 22:28:38 -080099
Jon Hall8f89dda2015-01-22 16:03:33 -0800100 cleanInstallResult = main.TRUE
101 gitPullResult = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800102
Jon Hall97f31752015-02-04 12:01:04 -0800103 main.step( "Starting Mininet" )
104 main.Mininet1.startNet( )
105
Jon Hall6aec96b2015-01-19 14:49:31 -0800106 main.step( "Compiling the latest version of ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800107 if PULLCODE:
Jon Hall58c76b72015-02-23 11:09:24 -0800108 main.step( "Git checkout and pull " + gitBranch )
Jon Hall529a37f2015-01-28 10:02:00 -0800109 main.ONOSbench.gitCheckout( gitBranch )
Jon Hall8f89dda2015-01-22 16:03:33 -0800110 gitPullResult = main.ONOSbench.gitPull()
Jon Halla9d26da2015-03-30 16:45:32 -0700111 if gitPullResult == main.ERROR:
112 main.log.error( "Error pulling git branch" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800113
Jon Hall6aec96b2015-01-19 14:49:31 -0800114 main.step( "Using mvn clean & install" )
Jon Hall529a37f2015-01-28 10:02:00 -0800115 cleanInstallResult = main.ONOSbench.cleanInstall()
116 else:
117 main.log.warn( "Did not pull new code so skipping mvn " +
118 "clean install" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800119 main.ONOSbench.getVersion( report=True )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800120
Jon Hall8f89dda2015-01-22 16:03:33 -0800121 cellResult = main.ONOSbench.setCell( "SingleHA" )
122 verifyResult = main.ONOSbench.verifyCell()
Jon Hall6aec96b2015-01-19 14:49:31 -0800123 main.step( "Creating ONOS package" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800124 packageResult = main.ONOSbench.onosPackage()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800125
Jon Hall6aec96b2015-01-19 14:49:31 -0800126 main.step( "Installing ONOS package" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800127 onos1InstallResult = main.ONOSbench.onosInstall( options="-f",
128 node=ONOS1Ip )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800129
Jon Hall6aec96b2015-01-19 14:49:31 -0800130 main.step( "Checking if ONOS is up yet" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800131 for i in range( 2 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800132 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
133 if onos1Isup:
Jon Hall94fd0472014-12-08 11:52:42 -0800134 break
Jon Hall8f89dda2015-01-22 16:03:33 -0800135 if not onos1Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800136 main.log.report( "ONOS1 didn't start!" )
Jon Hall94fd0472014-12-08 11:52:42 -0800137
Jon Hall8f89dda2015-01-22 16:03:33 -0800138 cliResult = main.ONOScli1.startOnosCli( ONOS1Ip )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800139
Jon Hall6aec96b2015-01-19 14:49:31 -0800140 main.step( "Start Packet Capture MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800141 main.Mininet2.startTcpdump(
Jon Hall6aec96b2015-01-19 14:49:31 -0800142 str( main.params[ 'MNtcpdump' ][ 'folder' ] ) + str( main.TEST )
143 + "-MN.pcap",
144 intf=main.params[ 'MNtcpdump' ][ 'intf' ],
145 port=main.params[ 'MNtcpdump' ][ 'port' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800146
Jon Hall8f89dda2015-01-22 16:03:33 -0800147 case1Result = ( cleanInstallResult and packageResult and
148 cellResult and verifyResult and onos1InstallResult
149 and onos1Isup and cliResult )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800150
Jon Hall8f89dda2015-01-22 16:03:33 -0800151 utilities.assert_equals( expect=main.TRUE, actual=case1Result,
Jon Hall58c76b72015-02-23 11:09:24 -0800152 onpass="Test startup successful",
153 onfail="Test startup NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800154
Jon Hall8f89dda2015-01-22 16:03:33 -0800155 if case1Result == main.FALSE:
Jon Hall73cf9cc2014-11-20 22:28:38 -0800156 main.cleanup()
157 main.exit()
158
Jon Hall6aec96b2015-01-19 14:49:31 -0800159 def CASE2( self, main ):
160 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800161 Assign mastership to controllers
Jon Hall6aec96b2015-01-19 14:49:31 -0800162 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800163 import re
Jon Hall5cfd23c2015-03-19 11:40:57 -0700164 assert numControllers, "numControllers not defined"
165 assert main, "main not defined"
166 assert utilities.assert_equals, "utilities.assert_equals not defined"
167 assert ONOS1Port, "ONOS1Port not defined"
168 assert ONOS2Port, "ONOS2Port not defined"
169 assert ONOS3Port, "ONOS3Port not defined"
170 assert ONOS4Port, "ONOS4Port not defined"
171 assert ONOS5Port, "ONOS5Port not defined"
172 assert ONOS6Port, "ONOS6Port not defined"
173 assert ONOS7Port, "ONOS7Port not defined"
Jon Hall73cf9cc2014-11-20 22:28:38 -0800174
Jon Hall6aec96b2015-01-19 14:49:31 -0800175 main.log.report( "Assigning switches to controllers" )
176 main.case( "Assigning Controllers" )
177 main.step( "Assign switches to controllers" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800178
Jon Hall6aec96b2015-01-19 14:49:31 -0800179 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800180 main.Mininet1.assignSwController(
Jon Hall6aec96b2015-01-19 14:49:31 -0800181 sw=str( i ),
Jon Hall8f89dda2015-01-22 16:03:33 -0800182 ip1=ONOS1Ip, port1=ONOS1Port )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800183
Jon Hall8f89dda2015-01-22 16:03:33 -0800184 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800185 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800186 response = main.Mininet1.getSwController( "s" + str( i ) )
Jon Hallffb386d2014-11-21 13:43:38 -0800187 try:
Jon Hall6aec96b2015-01-19 14:49:31 -0800188 main.log.info( str( response ) )
Jon Hallfebb1c72015-03-05 13:30:09 -0800189 except Exception:
Jon Hall6aec96b2015-01-19 14:49:31 -0800190 main.log.info( repr( response ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800191 if re.search( "tcp:" + ONOS1Ip, response ):
192 mastershipCheck = mastershipCheck and main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800193 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800194 mastershipCheck = main.FALSE
195 if mastershipCheck == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800196 main.log.report( "Switch mastership assigned correctly" )
197 utilities.assert_equals(
198 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800199 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800200 onpass="Switch mastership assigned correctly",
201 onfail="Switches not assigned correctly to controllers" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800202
Jon Halla9d26da2015-03-30 16:45:32 -0700203 roleCall = main.TRUE
204 roleCheck = main.TRUE
205 try:
206 for i in range( 1, 29 ): # switches 1 through 28
207 ip = nodes[ 0 ].ip_address # ONOS1
208 # set up correct variables:
209 if i == 1:
210 deviceId = main.ONOScli1.getDevice( "1000" ).get( 'id' )
211 elif i == 2:
212 deviceId = main.ONOScli1.getDevice( "2000" ).get( 'id' )
213 elif i == 3:
214 deviceId = main.ONOScli1.getDevice( "3000" ).get( 'id' )
215 elif i == 4:
216 deviceId = main.ONOScli1.getDevice( "3004" ).get( 'id' )
217 elif i == 5:
218 deviceId = main.ONOScli1.getDevice( "5000" ).get( 'id' )
219 elif i == 6:
220 deviceId = main.ONOScli1.getDevice( "6000" ).get( 'id' )
221 elif i == 7:
222 deviceId = main.ONOScli1.getDevice( "6007" ).get( 'id' )
223 elif i >= 8 and i <= 17:
224 dpid = '3' + str( i ).zfill( 3 )
225 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
226 elif i >= 18 and i <= 27:
227 dpid = '6' + str( i ).zfill( 3 )
228 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
229 elif i == 28:
230 deviceId = main.ONOScli1.getDevice( "2800" ).get( 'id' )
231 else:
232 main.log.error( "You didn't write an else statement for " +
233 "switch s" + str( i ) )
234 # Assign switch
235 assert deviceId, "No device id for s" + str( i ) + " in ONOS"
236 # TODO: make this controller dynamic
237 roleCall = roleCall and main.ONOScli1.deviceRole( deviceId,
238 ip )
239 # Check assignment
Jon Hall678f4512015-03-31 09:48:31 -0700240 master = main.ONOScli1.getRole( deviceId ).get( 'master' )
241 if ip in master:
Jon Halla9d26da2015-03-30 16:45:32 -0700242 roleCheck = roleCheck and main.TRUE
243 else:
244 roleCheck = roleCheck and main.FALSE
245 main.log.error( "Error, controller " + ip + " is not" +
246 " master " + "of device " +
Jon Hall678f4512015-03-31 09:48:31 -0700247 str( deviceId ) + ". Master is " +
248 repr( master ) + "." )
Jon Halla9d26da2015-03-30 16:45:32 -0700249 except ( AttributeError, AssertionError ):
250 main.log.exception( "Something is wrong with ONOS device view" )
251 main.log.info( main.ONOScli1.devices() )
252 utilities.assert_equals(
253 expect=main.TRUE,
254 actual=roleCall,
255 onpass="Re-assigned switch mastership to designated controller",
256 onfail="Something wrong with deviceRole calls" )
257
258 utilities.assert_equals(
259 expect=main.TRUE,
260 actual=roleCheck,
261 onpass="Switches were successfully reassigned to designated " +
262 "controller",
263 onfail="Switches were not successfully reassigned" )
264 mastershipCheck = mastershipCheck and roleCall and roleCheck
265 utilities.assert_equals( expect=main.TRUE, actual=mastershipCheck,
266 onpass="Switch mastership correctly assigned",
267 onfail="Error in (re)assigning switch" +
268 " mastership" )
269
Jon Hall6aec96b2015-01-19 14:49:31 -0800270 def CASE3( self, main ):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800271 """
272 Assign intents
Jon Hall73cf9cc2014-11-20 22:28:38 -0800273 """
274 import time
Jon Hallfebb1c72015-03-05 13:30:09 -0800275 import json
Jon Hall5cfd23c2015-03-19 11:40:57 -0700276 assert numControllers, "numControllers not defined"
277 assert main, "main not defined"
278 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall73cf9cc2014-11-20 22:28:38 -0800279 # FIXME: we must reinstall intents until we have a persistant
280 # datastore!
Jon Hall6aec96b2015-01-19 14:49:31 -0800281 main.log.report( "Adding host intents" )
282 main.case( "Adding host Intents" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800283
Jon Hall8f89dda2015-01-22 16:03:33 -0800284 main.step( "Discovering Hosts( Via pingall for now )" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800285 # FIXME: Once we have a host discovery mechanism, use that instead
Jon Hall73cf9cc2014-11-20 22:28:38 -0800286
Jon Hall6aec96b2015-01-19 14:49:31 -0800287 # install onos-app-fwd
288 main.log.info( "Install reactive forwarding app" )
Jon Halla9d26da2015-03-30 16:45:32 -0700289 appResults = main.ONOScli1.activateApp( "org.onosproject.fwd" )
290
291 # FIXME: add this to asserts
292 appCheck = main.ONOScli1.appToIDCheck()
293 if appCheck != main.TRUE:
294 main.log.warn( CLIs[0].apps() )
295 main.log.warn( CLIs[0].appIDs() )
Jon Hall94fd0472014-12-08 11:52:42 -0800296
Jon Hall6aec96b2015-01-19 14:49:31 -0800297 # REACTIVE FWD test
Jon Hall8f89dda2015-01-22 16:03:33 -0800298 pingResult = main.FALSE
Jon Hall5cfd23c2015-03-19 11:40:57 -0700299 for i in range(2): # Retry if pingall fails first time
300 time1 = time.time()
301 pingResult = main.Mininet1.pingall()
302 utilities.assert_equals(
303 expect=main.TRUE,
304 actual=pingResult,
305 onpass="Reactive Pingall test passed",
306 onfail="Reactive Pingall failed, one or more ping pairs failed" )
307 time2 = time.time()
308 main.log.info( "Time for pingall: %2f seconds" % ( time2 - time1 ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800309
Jon Hall6aec96b2015-01-19 14:49:31 -0800310 # uninstall onos-app-fwd
311 main.log.info( "Uninstall reactive forwarding app" )
Jon Halla9d26da2015-03-30 16:45:32 -0700312 appResults = appResults and main.ONOScli1.deactivateApp( "org.onosproject.fwd" )
313 appCheck2 = main.ONOScli1.appToIDCheck()
314 if appCheck2 != main.TRUE:
315 main.log.warn( CLIs[0].apps() )
316 main.log.warn( CLIs[0].appIDs() )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800317
Jon Halla9d26da2015-03-30 16:45:32 -0700318 # timeout for fwd flows
319 time.sleep( 11 )
320
321 main.step( "Add host intents" )
Jon Hall58c76b72015-02-23 11:09:24 -0800322 intentIds = []
Jon Hall6aec96b2015-01-19 14:49:31 -0800323 # TODO: move the host numbers to params
Jon Hall58c76b72015-02-23 11:09:24 -0800324 # Maybe look at all the paths we ping?
Jon Hall8f89dda2015-01-22 16:03:33 -0800325 intentAddResult = True
Jon Hall58c76b72015-02-23 11:09:24 -0800326 hostResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800327 for i in range( 8, 18 ):
328 main.log.info( "Adding host intent between h" + str( i ) +
329 " and h" + str( i + 10 ) )
330 host1 = "00:00:00:00:00:" + \
331 str( hex( i )[ 2: ] ).zfill( 2 ).upper()
332 host2 = "00:00:00:00:00:" + \
333 str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper()
Jon Hall1b8f54a2015-02-04 13:24:20 -0800334 # NOTE: getHost can return None
335 host1Dict = main.ONOScli1.getHost( host1 )
336 host2Dict = main.ONOScli1.getHost( host2 )
337 host1Id = None
338 host2Id = None
339 if host1Dict and host2Dict:
340 host1Id = host1Dict.get( 'id', None )
341 host2Id = host2Dict.get( 'id', None )
Jon Hall8f89dda2015-01-22 16:03:33 -0800342 if host1Id and host2Id:
Jon Halla9d26da2015-03-30 16:45:32 -0700343 tmpId = main.ONOScli1.addHostIntent( host1Id, host2Id )
Jon Hall63604932015-02-26 17:09:50 -0800344 if tmpId:
345 main.log.info( "Added intent with id: " + tmpId )
346 intentIds.append( tmpId )
347 else:
Jon Halla9d26da2015-03-30 16:45:32 -0700348 main.log.error( "addHostIntent returned: " +
349 repr( tmpId ) )
Jon Hall669173b2014-12-17 11:36:30 -0800350 else:
Jon Halla9d26da2015-03-30 16:45:32 -0700351 main.log.error( "Error, getHost() failed for h" + str( i ) +
352 " and/or h" + str( i + 10 ) )
353 hosts = main.ONOScli1.hosts()
354 main.log.warn( "Hosts output: " )
355 try:
356 main.log.warn( json.dumps( json.loads( hosts ),
357 sort_keys=True,
358 indent=4,
359 separators=( ',', ': ' ) ) )
360 except ( ValueError, TypeError ):
361 main.log.warn( repr( hosts ) )
Jon Hall58c76b72015-02-23 11:09:24 -0800362 hostResult = main.FALSE
Jon Halla9d26da2015-03-30 16:45:32 -0700363 # FIXME: DEBUG
364 intentStart = time.time()
Jon Hall58c76b72015-02-23 11:09:24 -0800365 onosIds = main.ONOScli1.getAllIntentsId()
366 main.log.info( "Submitted intents: " + str( intentIds ) )
367 main.log.info( "Intents in ONOS: " + str( onosIds ) )
368 for intent in intentIds:
369 if intent in onosIds:
Jon Halla9d26da2015-03-30 16:45:32 -0700370 pass # intent submitted is in onos
Jon Hall58c76b72015-02-23 11:09:24 -0800371 else:
372 intentAddResult = False
Jon Halla9d26da2015-03-30 16:45:32 -0700373 # FIXME: DEBUG
374 if intentAddResult:
375 intentStop = time.time()
376 else:
377 intentStop = None
Jon Hall1b8f54a2015-02-04 13:24:20 -0800378 # Print the intent states
Jon Hall58c76b72015-02-23 11:09:24 -0800379 intents = main.ONOScli1.intents()
Jon Hall1b8f54a2015-02-04 13:24:20 -0800380 intentStates = []
Jon Halla9d26da2015-03-30 16:45:32 -0700381 installedCheck = True
Jon Hall58c76b72015-02-23 11:09:24 -0800382 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
383 count = 0
Jon Hall5cfd23c2015-03-19 11:40:57 -0700384 try:
385 for intent in json.loads( intents ):
386 state = intent.get( 'state', None )
387 if "INSTALLED" not in state:
388 installedCheck = False
389 intentId = intent.get( 'id', None )
390 intentStates.append( ( intentId, state ) )
391 except ( ValueError, TypeError ):
392 main.log.exception( "Error parsing intents" )
Jon Hall58c76b72015-02-23 11:09:24 -0800393 # add submitted intents not in the store
394 tmplist = [ i for i, s in intentStates ]
395 missingIntents = False
396 for i in intentIds:
397 if i not in tmplist:
398 intentStates.append( ( i, " - " ) )
399 missingIntents = True
400 intentStates.sort()
401 for i, s in intentStates:
402 count += 1
403 main.log.info( "%-6s%-15s%-15s" %
404 ( str( count ), str( i ), str( s ) ) )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700405 leaders = main.ONOScli1.leaders()
406 try:
407 if leaders:
408 parsedLeaders = json.loads( leaders )
409 main.log.warn( json.dumps( parsedLeaders,
410 sort_keys=True,
411 indent=4,
412 separators=( ',', ': ' ) ) )
413 # check for all intent partitions
Jon Hall5cfd23c2015-03-19 11:40:57 -0700414 topics = []
415 for i in range( 14 ):
416 topics.append( "intent-partition-" + str( i ) )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700417 main.log.debug( topics )
418 ONOStopics = [ j['topic'] for j in parsedLeaders ]
419 for topic in topics:
420 if topic not in ONOStopics:
421 main.log.error( "Error: " + topic +
422 " not in leaders" )
423 else:
424 main.log.error( "leaders() returned None" )
425 except ( ValueError, TypeError ):
426 main.log.exception( "Error parsing leaders" )
427 main.log.error( repr( leaders ) )
428 partitions = main.ONOScli1.partitions()
429 try:
430 if partitions :
431 parsedPartitions = json.loads( partitions )
432 main.log.warn( json.dumps( parsedPartitions,
433 sort_keys=True,
434 indent=4,
435 separators=( ',', ': ' ) ) )
436 # TODO check for a leader in all paritions
437 # TODO check for consistency among nodes
438 else:
439 main.log.error( "partitions() returned None" )
440 except ( ValueError, TypeError ):
441 main.log.exception( "Error parsing partitions" )
442 main.log.error( repr( partitions ) )
Jon Hall63604932015-02-26 17:09:50 -0800443 pendingMap = main.ONOScli1.pendingMap()
Jon Hall5cfd23c2015-03-19 11:40:57 -0700444 try:
445 if pendingMap :
446 parsedPending = json.loads( pendingMap )
447 main.log.warn( json.dumps( parsedPending,
448 sort_keys=True,
449 indent=4,
450 separators=( ',', ': ' ) ) )
451 # TODO check something here?
452 else:
453 main.log.error( "pendingMap() returned None" )
454 except ( ValueError, TypeError ):
455 main.log.exception( "Error parsing pending map" )
456 main.log.error( repr( pendingMap ) )
457
Jon Hall58c76b72015-02-23 11:09:24 -0800458 intentAddResult = bool( pingResult and hostResult and intentAddResult
Jon Hall63604932015-02-26 17:09:50 -0800459 and not missingIntents and installedCheck )
Jon Hall6aec96b2015-01-19 14:49:31 -0800460 utilities.assert_equals(
461 expect=True,
Jon Hall8f89dda2015-01-22 16:03:33 -0800462 actual=intentAddResult,
Jon Hall529a37f2015-01-28 10:02:00 -0800463 onpass="Pushed host intents to ONOS",
464 onfail="Error in pushing host intents to ONOS" )
Jon Hall58c76b72015-02-23 11:09:24 -0800465
Jon Hall63604932015-02-26 17:09:50 -0800466 if not intentAddResult or "key" in pendingMap:
Jon Hall58c76b72015-02-23 11:09:24 -0800467 import time
Jon Hall63604932015-02-26 17:09:50 -0800468 installedCheck = True
Jon Hall58c76b72015-02-23 11:09:24 -0800469 main.log.info( "Sleeping 60 seconds to see if intents are found" )
470 time.sleep( 60 )
471 onosIds = main.ONOScli1.getAllIntentsId()
472 main.log.info( "Submitted intents: " + str( intentIds ) )
473 main.log.info( "Intents in ONOS: " + str( onosIds ) )
474 # Print the intent states
475 intents = main.ONOScli1.intents()
476 intentStates = []
477 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
478 count = 0
Jon Hall5cfd23c2015-03-19 11:40:57 -0700479 try:
480 for intent in json.loads( intents ):
481 # Iter through intents of a node
482 state = intent.get( 'state', None )
483 if "INSTALLED" not in state:
484 installedCheck = False
485 intentId = intent.get( 'id', None )
486 intentStates.append( ( intentId, state ) )
487 except ( ValueError, TypeError ):
488 main.log.exception( "Error parsing intents" )
Jon Hall58c76b72015-02-23 11:09:24 -0800489 # add submitted intents not in the store
490 tmplist = [ i for i, s in intentStates ]
491 for i in intentIds:
492 if i not in tmplist:
493 intentStates.append( ( i, " - " ) )
494 intentStates.sort()
495 for i, s in intentStates:
496 count += 1
497 main.log.info( "%-6s%-15s%-15s" %
498 ( str( count ), str( i ), str( s ) ) )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700499 leaders = main.ONOScli1.leaders()
500 try:
501 if leaders:
502 parsedLeaders = json.loads( leaders )
503 main.log.warn( json.dumps( parsedLeaders,
504 sort_keys=True,
505 indent=4,
506 separators=( ',', ': ' ) ) )
507 # check for all intent partitions
508 # check for election
509 topics = []
510 for i in range( 14 ):
511 topics.append( "intent-partition-" + str( i ) )
512 # FIXME: this should only be after we start the app
513 topics.append( "org.onosproject.election" )
514 main.log.debug( topics )
515 ONOStopics = [ j['topic'] for j in parsedLeaders ]
516 for topic in topics:
517 if topic not in ONOStopics:
518 main.log.error( "Error: " + topic +
519 " not in leaders" )
520 else:
521 main.log.error( "leaders() returned None" )
522 except ( ValueError, TypeError ):
523 main.log.exception( "Error parsing leaders" )
524 main.log.error( repr( leaders ) )
525 partitions = main.ONOScli1.partitions()
526 try:
527 if partitions :
528 parsedPartitions = json.loads( partitions )
529 main.log.warn( json.dumps( parsedPartitions,
530 sort_keys=True,
531 indent=4,
532 separators=( ',', ': ' ) ) )
533 # TODO check for a leader in all paritions
534 # TODO check for consistency among nodes
535 else:
536 main.log.error( "partitions() returned None" )
537 except ( ValueError, TypeError ):
538 main.log.exception( "Error parsing partitions" )
539 main.log.error( repr( partitions ) )
540 pendingMap = main.ONOScli1.pendingMap()
541 try:
542 if pendingMap :
543 parsedPending = json.loads( pendingMap )
544 main.log.warn( json.dumps( parsedPending,
545 sort_keys=True,
546 indent=4,
547 separators=( ',', ': ' ) ) )
548 # TODO check something here?
549 else:
550 main.log.error( "pendingMap() returned None" )
551 except ( ValueError, TypeError ):
552 main.log.exception( "Error parsing pending map" )
553 main.log.error( repr( pendingMap ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800554
Jon Hall6aec96b2015-01-19 14:49:31 -0800555 def CASE4( self, main ):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800556 """
557 Ping across added host intents
558 """
Jon Hallfebb1c72015-03-05 13:30:09 -0800559 import json
Jon Halla9d26da2015-03-30 16:45:32 -0700560 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -0700561 assert numControllers, "numControllers not defined"
562 assert main, "main not defined"
563 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall73cf9cc2014-11-20 22:28:38 -0800564 description = " Ping across added host intents"
Jon Hall6aec96b2015-01-19 14:49:31 -0800565 main.log.report( description )
566 main.case( description )
Jon Hall8f89dda2015-01-22 16:03:33 -0800567 PingResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800568 for i in range( 8, 18 ):
Jon Hall58c76b72015-02-23 11:09:24 -0800569 ping = main.Mininet1.pingHost( src="h" + str( i ),
570 target="h" + str( i + 10 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800571 PingResult = PingResult and ping
Jon Hall6aec96b2015-01-19 14:49:31 -0800572 if ping == main.FALSE:
573 main.log.warn( "Ping failed between h" + str( i ) +
574 " and h" + str( i + 10 ) )
575 elif ping == main.TRUE:
576 main.log.info( "Ping test passed!" )
Jon Hall21270ac2015-02-16 17:59:55 -0800577 # Don't set PingResult or you'd override failures
Jon Hall8f89dda2015-01-22 16:03:33 -0800578 if PingResult == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800579 main.log.report(
580 "Intents have not been installed correctly, pings failed." )
Jon Hall58c76b72015-02-23 11:09:24 -0800581 # TODO: pretty print
Jon Hall5cfd23c2015-03-19 11:40:57 -0700582 main.log.warn( "ONOS1 intents: " )
583 try:
584 tmpIntents = main.ONOScli1.intents()
585 main.log.warn( json.dumps( json.loads( tmpIntents ),
586 sort_keys=True,
587 indent=4,
588 separators=( ',', ': ' ) ) )
589 except ( ValueError, TypeError ):
590 main.log.warn( repr( tmpIntents ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800591 if PingResult == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800592 main.log.report(
593 "Intents have been installed correctly and verified by pings" )
594 utilities.assert_equals(
595 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800596 actual=PingResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800597 onpass="Intents have been installed correctly and pings work",
598 onfail="Intents have not been installed correctly, pings failed." )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800599
Jon Hall63604932015-02-26 17:09:50 -0800600 installedCheck = True
Jon Hall58c76b72015-02-23 11:09:24 -0800601 if PingResult is not main.TRUE:
602 # Print the intent states
603 intents = main.ONOScli1.intents()
604 intentStates = []
605 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
606 count = 0
607 # Iter through intents of a node
Jon Hall5cfd23c2015-03-19 11:40:57 -0700608 try:
609 for intent in json.loads( intents ):
610 state = intent.get( 'state', None )
611 if "INSTALLED" not in state:
612 installedCheck = False
613 intentId = intent.get( 'id', None )
614 intentStates.append( ( intentId, state ) )
615 except ( ValueError, TypeError ):
616 main.log.exception( "Error parsing intents." )
Jon Hall58c76b72015-02-23 11:09:24 -0800617 intentStates.sort()
618 for i, s in intentStates:
619 count += 1
620 main.log.info( "%-6s%-15s%-15s" %
621 ( str( count ), str( i ), str( s ) ) )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700622 leaders = main.ONOScli1.leaders()
623 try:
624 if leaders:
625 parsedLeaders = json.loads( leaders )
626 main.log.warn( json.dumps( parsedLeaders,
627 sort_keys=True,
628 indent=4,
629 separators=( ',', ': ' ) ) )
630 # check for all intent partitions
631 # check for election
632 topics = []
633 for i in range( 14 ):
634 topics.append( "intent-partition-" + str( i ) )
635 # FIXME: this should only be after we start the app
636 topics.append( "org.onosproject.election" )
637 main.log.debug( topics )
638 ONOStopics = [ j['topic'] for j in parsedLeaders ]
639 for topic in topics:
640 if topic not in ONOStopics:
641 main.log.error( "Error: " + topic +
642 " not in leaders" )
643 else:
644 main.log.error( "leaders() returned None" )
645 except ( ValueError, TypeError ):
646 main.log.exception( "Error parsing leaders" )
647 main.log.error( repr( leaders ) )
648 partitions = main.ONOScli1.partitions()
649 try:
650 if partitions :
651 parsedPartitions = json.loads( partitions )
652 main.log.warn( json.dumps( parsedPartitions,
653 sort_keys=True,
654 indent=4,
655 separators=( ',', ': ' ) ) )
656 # TODO check for a leader in all paritions
657 # TODO check for consistency among nodes
658 else:
659 main.log.error( "partitions() returned None" )
660 except ( ValueError, TypeError ):
661 main.log.exception( "Error parsing partitions" )
662 main.log.error( repr( partitions ) )
663 pendingMap = main.ONOScli1.pendingMap()
664 try:
665 if pendingMap :
666 parsedPending = json.loads( pendingMap )
667 main.log.warn( json.dumps( parsedPending,
668 sort_keys=True,
669 indent=4,
670 separators=( ',', ': ' ) ) )
671 # TODO check something here?
672 else:
673 main.log.error( "pendingMap() returned None" )
674 except ( ValueError, TypeError ):
675 main.log.exception( "Error parsing pending map" )
676 main.log.error( repr( pendingMap ) )
677
Jon Hall63604932015-02-26 17:09:50 -0800678 if not installedCheck:
Jon Hall5cfd23c2015-03-19 11:40:57 -0700679 main.log.info( "Waiting 60 seconds to see if the state of " +
680 "intents change" )
Jon Hall63604932015-02-26 17:09:50 -0800681 time.sleep( 60 )
682 # Print the intent states
683 intents = main.ONOScli1.intents()
684 intentStates = []
685 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
686 count = 0
687 # Iter through intents of a node
Jon Hall5cfd23c2015-03-19 11:40:57 -0700688 try:
689 for intent in json.loads( intents ):
690 state = intent.get( 'state', None )
691 if "INSTALLED" not in state:
692 installedCheck = False
693 intentId = intent.get( 'id', None )
694 intentStates.append( ( intentId, state ) )
695 except ( ValueError, TypeError ):
696 main.log.exception( "Error parsing intents." )
Jon Hall63604932015-02-26 17:09:50 -0800697 intentStates.sort()
698 for i, s in intentStates:
699 count += 1
700 main.log.info( "%-6s%-15s%-15s" %
701 ( str( count ), str( i ), str( s ) ) )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700702 leaders = main.ONOScli1.leaders()
703 try:
704 if leaders:
705 parsedLeaders = json.loads( leaders )
706 main.log.warn( json.dumps( parsedLeaders,
707 sort_keys=True,
708 indent=4,
709 separators=( ',', ': ' ) ) )
710 # check for all intent partitions
711 # check for election
712 topics = []
713 for i in range( 14 ):
714 topics.append( "intent-partition-" + str( i ) )
715 # FIXME: this should only be after we start the app
716 topics.append( "org.onosproject.election" )
717 main.log.debug( topics )
718 ONOStopics = [ j['topic'] for j in parsedLeaders ]
719 for topic in topics:
720 if topic not in ONOStopics:
721 main.log.error( "Error: " + topic +
722 " not in leaders" )
723 else:
724 main.log.error( "leaders() returned None" )
725 except ( ValueError, TypeError ):
726 main.log.exception( "Error parsing leaders" )
727 main.log.error( repr( leaders ) )
728 partitions = main.ONOScli1.partitions()
729 try:
730 if partitions :
731 parsedPartitions = json.loads( partitions )
732 main.log.warn( json.dumps( parsedPartitions,
733 sort_keys=True,
734 indent=4,
735 separators=( ',', ': ' ) ) )
736 # TODO check for a leader in all paritions
737 # TODO check for consistency among nodes
738 else:
739 main.log.error( "partitions() returned None" )
740 except ( ValueError, TypeError ):
741 main.log.exception( "Error parsing partitions" )
742 main.log.error( repr( partitions ) )
743 pendingMap = main.ONOScli1.pendingMap()
744 try:
745 if pendingMap :
746 parsedPending = json.loads( pendingMap )
747 main.log.warn( json.dumps( parsedPending,
748 sort_keys=True,
749 indent=4,
750 separators=( ',', ': ' ) ) )
751 # TODO check something here?
752 else:
753 main.log.error( "pendingMap() returned None" )
754 except ( ValueError, TypeError ):
755 main.log.exception( "Error parsing pending map" )
756 main.log.error( repr( pendingMap ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800757
Jon Hall6aec96b2015-01-19 14:49:31 -0800758 def CASE5( self, main ):
759 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800760 Reading state of ONOS
Jon Hall6aec96b2015-01-19 14:49:31 -0800761 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800762 import json
Jon Hall5cfd23c2015-03-19 11:40:57 -0700763 assert numControllers, "numControllers not defined"
764 assert main, "main not defined"
765 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -0800766 # assumes that sts is already in you PYTHONPATH
767 from sts.topology.teston_topology import TestONTopology
Jon Hall73cf9cc2014-11-20 22:28:38 -0800768
Jon Hall6aec96b2015-01-19 14:49:31 -0800769 main.log.report( "Setting up and gathering data for current state" )
770 main.case( "Setting up and gathering data for current state" )
771 # The general idea for this test case is to pull the state of
772 # ( intents,flows, topology,... ) from each ONOS node
Jon Hall5cfd23c2015-03-19 11:40:57 -0700773 # We can then compare them with each other and also with past states
Jon Hall73cf9cc2014-11-20 22:28:38 -0800774
Jon Halla9d26da2015-03-30 16:45:32 -0700775 main.step( "Check that each switch has a master" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800776 global mastershipState
Jon Halla9d26da2015-03-30 16:45:32 -0700777 mastershipState = '[]'
Jon Hall94fd0472014-12-08 11:52:42 -0800778
Jon Hall6aec96b2015-01-19 14:49:31 -0800779 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -0800780 rolesNotNull = main.ONOScli1.rolesNotNull()
Jon Hall6aec96b2015-01-19 14:49:31 -0800781 utilities.assert_equals(
782 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800783 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -0800784 onpass="Each device has a master",
785 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -0800786
Jon Hall8f89dda2015-01-22 16:03:33 -0800787 ONOS1Mastership = main.ONOScli1.roles()
Jon Hall6aec96b2015-01-19 14:49:31 -0800788 # TODO: Make this a meaningful check
Jon Hall8f89dda2015-01-22 16:03:33 -0800789 if "Error" in ONOS1Mastership or not ONOS1Mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -0800790 main.log.report( "Error in getting ONOS roles" )
791 main.log.warn(
792 "ONOS1 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800793 repr( ONOS1Mastership ) )
794 consistentMastership = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800795 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800796 mastershipState = ONOS1Mastership
797 consistentMastership = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800798
Jon Hall6aec96b2015-01-19 14:49:31 -0800799 main.step( "Get the intents from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800800 global intentState
801 intentState = []
802 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
803 intentCheck = main.FALSE
804 if "Error" in ONOS1Intents or not ONOS1Intents:
Jon Hall6aec96b2015-01-19 14:49:31 -0800805 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800806 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800807 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800808 intentCheck = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800809
Jon Hall6aec96b2015-01-19 14:49:31 -0800810 main.step( "Get the flows from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800811 global flowState
812 flowState = []
Jon Hall8f89dda2015-01-22 16:03:33 -0800813 flowCheck = main.FALSE
Jon Hall58c76b72015-02-23 11:09:24 -0800814 ONOS1Flows = main.ONOScli1.flows( jsonFormat=True )
Jon Hall8f89dda2015-01-22 16:03:33 -0800815 if "Error" in ONOS1Flows or not ONOS1Flows:
Jon Hall58c76b72015-02-23 11:09:24 -0800816 main.log.report( "Error in getting ONOS flows" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800817 main.log.warn( "ONOS1 flows repsponse: " + ONOS1Flows )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800818 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800819 # TODO: Do a better check, maybe compare flows on switches?
Jon Hall8f89dda2015-01-22 16:03:33 -0800820 flowState = ONOS1Flows
821 flowCheck = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800822
Jon Hall6aec96b2015-01-19 14:49:31 -0800823 main.step( "Get the OF Table entries" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800824 global flows
Jon Hall6aec96b2015-01-19 14:49:31 -0800825 flows = []
826 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800827 flows.append( main.Mininet2.getFlowTable( 1.3, "s" + str( i ) ) )
Jon Hall58c76b72015-02-23 11:09:24 -0800828 if flowCheck == main.FALSE:
829 for table in flows:
830 main.log.warn( table )
Jon Hall6aec96b2015-01-19 14:49:31 -0800831 # TODO: Compare switch flow tables with ONOS flow tables
Jon Hall73cf9cc2014-11-20 22:28:38 -0800832
Jon Hall6aec96b2015-01-19 14:49:31 -0800833 main.step( "Create TestONTopology object" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800834 ctrls = []
835 count = 1
836 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -0800837 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
838 temp = temp + ( "ONOS" + str( count ), )
839 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
840 temp = temp + \
841 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
842 ctrls.append( temp )
843 MNTopo = TestONTopology(
844 main.Mininet1,
845 ctrls ) # can also add Intent API info for intent operations
Jon Hall73cf9cc2014-11-20 22:28:38 -0800846
Jon Hall6aec96b2015-01-19 14:49:31 -0800847 main.step( "Collecting topology information from ONOS" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800848 devices = []
849 devices.append( main.ONOScli1.devices() )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800850 hosts = []
Jon Hall58c76b72015-02-23 11:09:24 -0800851 hosts.append( json.loads( main.ONOScli1.hosts() ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800852 ports = []
853 ports.append( main.ONOScli1.ports() )
854 links = []
855 links.append( main.ONOScli1.links() )
Jon Hall58c76b72015-02-23 11:09:24 -0800856 clusters = []
857 clusters.append( main.ONOScli1.clusters() )
858 ipResult = main.TRUE
859 for controller in range( 0, len( hosts ) ):
860 controllerStr = str( controller + 1 )
861 for host in hosts[ controller ]:
862 if host is None or host.get( 'ips', [] ) == []:
863 main.log.error(
864 "DEBUG:Error with host ips on controller" +
865 controllerStr + ": " + str( host ) )
866 ipResult = main.FALSE
867
868 # there should always only be one cluster
869 numClusters = len( json.loads( clusters[ 0 ] ) )
870 clusterResults = main.FALSE
871 if numClusters == 1:
872 clusterResults = main.TRUE
873 utilities.assert_equals(
874 expect=1,
875 actual=numClusters,
876 onpass="ONOS shows 1 SCC",
877 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800878
Jon Hall6aec96b2015-01-19 14:49:31 -0800879 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800880 devicesResults = main.TRUE
881 portsResults = main.TRUE
882 linksResults = main.TRUE
Jon Hall58c76b72015-02-23 11:09:24 -0800883 hostsResults = main.TRUE
Jon Hall8f89dda2015-01-22 16:03:33 -0800884 for controller in range( numControllers ):
885 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -0800886 if devices[ controller ] or "Error" not in devices[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -0800887 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -0800888 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -0800889 json.loads( devices[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800890 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800891 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800892 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -0800893 actual=currentDevicesResult,
894 onpass="ONOS" + controllerStr +
895 " Switches view is correct",
896 onfail="ONOS" + controllerStr +
897 " Switches view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800898
Jon Hall6aec96b2015-01-19 14:49:31 -0800899 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -0800900 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -0800901 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -0800902 json.loads( ports[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800903 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800904 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800905 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -0800906 actual=currentPortsResult,
907 onpass="ONOS" + controllerStr +
908 " ports view is correct",
909 onfail="ONOS" + controllerStr +
910 " ports view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800911
Jon Hall6aec96b2015-01-19 14:49:31 -0800912 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -0800913 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -0800914 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -0800915 json.loads( links[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800916 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800917 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800918 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -0800919 actual=currentLinksResult,
920 onpass="ONOS" + controllerStr +
921 " links view is correct",
922 onfail="ONOS" + controllerStr +
923 " links view is incorrect" )
924
925 if hosts[ controller ] or "Error" not in hosts[ controller ]:
926 currentHostsResult = main.Mininet1.compareHosts(
927 MNTopo, hosts[ controller ] )
928 else:
929 currentHostsResult = main.FALSE
930 utilities.assert_equals( expect=main.TRUE,
931 actual=currentHostsResult,
932 onpass="ONOS" + controllerStr +
933 " hosts exist in Mininet",
934 onfail="ONOS" + controllerStr +
935 " hosts don't match Mininet" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800936
Jon Hall8f89dda2015-01-22 16:03:33 -0800937 devicesResults = devicesResults and currentDevicesResult
938 portsResults = portsResults and currentPortsResult
939 linksResults = linksResults and currentLinksResult
Jon Hall58c76b72015-02-23 11:09:24 -0800940 hostsResults = hostsResults and currentHostsResult
Jon Hall73cf9cc2014-11-20 22:28:38 -0800941
Jon Hall58c76b72015-02-23 11:09:24 -0800942 topoResult = devicesResults and portsResults and linksResults\
943 and clusterResults and ipResult and hostsResults
Jon Hall8f89dda2015-01-22 16:03:33 -0800944 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
Jon Hall58c76b72015-02-23 11:09:24 -0800945 onpass="Topology Check Test successful",
946 onfail="Topology Check Test NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800947
Jon Hall8f89dda2015-01-22 16:03:33 -0800948 finalAssert = main.TRUE
949 finalAssert = finalAssert and topoResult and flowCheck \
Jon Hall58c76b72015-02-23 11:09:24 -0800950 and intentCheck and consistentMastership and rolesNotNull
Jon Hall8f89dda2015-01-22 16:03:33 -0800951 utilities.assert_equals( expect=main.TRUE, actual=finalAssert,
Jon Hall58c76b72015-02-23 11:09:24 -0800952 onpass="State check successful",
953 onfail="State check NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800954
Jon Hall6aec96b2015-01-19 14:49:31 -0800955 def CASE6( self, main ):
956 """
Jon Hallffb386d2014-11-21 13:43:38 -0800957 The Failure case.
Jon Hall6aec96b2015-01-19 14:49:31 -0800958 """
Jon Hallffb386d2014-11-21 13:43:38 -0800959 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -0700960 assert numControllers, "numControllers not defined"
961 assert main, "main not defined"
962 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall73cf9cc2014-11-20 22:28:38 -0800963
Jon Hall6aec96b2015-01-19 14:49:31 -0800964 main.log.report( "Restart ONOS node" )
965 main.log.case( "Restart ONOS node" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800966 main.ONOSbench.onosKill( ONOS1Ip )
Jon Hallffb386d2014-11-21 13:43:38 -0800967 start = time.time()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800968
Jon Hall6aec96b2015-01-19 14:49:31 -0800969 main.step( "Checking if ONOS is up yet" )
Jon Hallffb386d2014-11-21 13:43:38 -0800970 count = 0
Jon Hall94fd0472014-12-08 11:52:42 -0800971 while count < 10:
Jon Hall8f89dda2015-01-22 16:03:33 -0800972 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
973 if onos1Isup == main.TRUE:
Jon Hallffb386d2014-11-21 13:43:38 -0800974 elapsed = time.time() - start
975 break
976 else:
977 count = count + 1
Jon Hall73cf9cc2014-11-20 22:28:38 -0800978
Jon Hall8f89dda2015-01-22 16:03:33 -0800979 cliResult = main.ONOScli1.startOnosCli( ONOS1Ip )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800980
Jon Hall8f89dda2015-01-22 16:03:33 -0800981 caseResults = main.TRUE and onos1Isup and cliResult
982 utilities.assert_equals( expect=main.TRUE, actual=caseResults,
Jon Hall58c76b72015-02-23 11:09:24 -0800983 onpass="ONOS restart successful",
984 onfail="ONOS restart NOT successful" )
Jon Hallfebb1c72015-03-05 13:30:09 -0800985 if elapsed:
986 main.log.info( "ESTIMATE: ONOS took %s seconds to restart" %
987 str( elapsed ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800988 time.sleep( 5 )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800989
Jon Hall6aec96b2015-01-19 14:49:31 -0800990 def CASE7( self, main ):
991 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800992 Check state after ONOS failure
Jon Hall6aec96b2015-01-19 14:49:31 -0800993 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800994 import json
Jon Hall5cfd23c2015-03-19 11:40:57 -0700995 assert numControllers, "numControllers not defined"
996 assert main, "main not defined"
997 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -0800998 main.case( "Running ONOS Constant State Tests" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800999
Jon Hall6aec96b2015-01-19 14:49:31 -08001000 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -08001001 rolesNotNull = main.ONOScli1.rolesNotNull()
Jon Hall6aec96b2015-01-19 14:49:31 -08001002 utilities.assert_equals(
1003 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001004 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -08001005 onpass="Each device has a master",
1006 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -08001007
Jon Hall6aec96b2015-01-19 14:49:31 -08001008 main.step( "Check if switch roles are consistent across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001009 ONOS1Mastership = main.ONOScli1.roles()
Jon Hall6aec96b2015-01-19 14:49:31 -08001010 # FIXME: Refactor this whole case for single instance
Jon Hall8f89dda2015-01-22 16:03:33 -08001011 if "Error" in ONOS1Mastership or not ONOS1Mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -08001012 main.log.report( "Error in getting ONOS mastership" )
Jon Hall58c76b72015-02-23 11:09:24 -08001013 main.log.warn( "ONOS1 mastership response: " +
1014 repr( ONOS1Mastership ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001015 consistentMastership = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001016 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001017 consistentMastership = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001018 main.log.report(
1019 "Switch roles are consistent across all ONOS nodes" )
1020 utilities.assert_equals(
1021 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001022 actual=consistentMastership,
Jon Hall6aec96b2015-01-19 14:49:31 -08001023 onpass="Switch roles are consistent across all ONOS nodes",
1024 onfail="ONOS nodes have different views of switch roles" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001025
1026 description2 = "Compare switch roles from before failure"
Jon Hall6aec96b2015-01-19 14:49:31 -08001027 main.step( description2 )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001028
Jon Hall8f89dda2015-01-22 16:03:33 -08001029 currentJson = json.loads( ONOS1Mastership )
1030 oldJson = json.loads( mastershipState )
1031 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001032 for i in range( 1, 29 ):
1033 switchDPID = str(
Jon Hall58c76b72015-02-23 11:09:24 -08001034 main.Mininet1.getSwitchDPID( switch="s" + str( i ) ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001035
Jon Hall8f89dda2015-01-22 16:03:33 -08001036 current = [ switch[ 'master' ] for switch in currentJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001037 if switchDPID in switch[ 'id' ] ]
Jon Hall8f89dda2015-01-22 16:03:33 -08001038 old = [ switch[ 'master' ] for switch in oldJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001039 if switchDPID in switch[ 'id' ] ]
Jon Hall73cf9cc2014-11-20 22:28:38 -08001040 if current == old:
Jon Hall8f89dda2015-01-22 16:03:33 -08001041 mastershipCheck = mastershipCheck and main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001042 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001043 main.log.warn( "Mastership of switch %s changed" % switchDPID )
Jon Hall8f89dda2015-01-22 16:03:33 -08001044 mastershipCheck = main.FALSE
1045 if mastershipCheck == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001046 main.log.report( "Mastership of Switches was not changed" )
1047 utilities.assert_equals(
1048 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001049 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -08001050 onpass="Mastership of Switches was not changed",
1051 onfail="Mastership of some switches changed" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001052 mastershipCheck = mastershipCheck and consistentMastership
Jon Hall73cf9cc2014-11-20 22:28:38 -08001053
Jon Hall6aec96b2015-01-19 14:49:31 -08001054 main.step( "Get the intents and compare across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001055 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
1056 intentCheck = main.FALSE
1057 if "Error" in ONOS1Intents or not ONOS1Intents:
Jon Hall6aec96b2015-01-19 14:49:31 -08001058 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001059 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001060 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001061 intentCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001062 main.log.report( "Intents are consistent across all ONOS nodes" )
1063 utilities.assert_equals(
1064 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001065 actual=intentCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -08001066 onpass="Intents are consistent across all ONOS nodes",
1067 onfail="ONOS nodes have different views of intents" )
Jon Hall1b8f54a2015-02-04 13:24:20 -08001068 # Print the intent states
1069 intents = []
1070 intents.append( ONOS1Intents )
1071 intentStates = []
1072 for node in intents: # Iter through ONOS nodes
1073 nodeStates = []
Jon Hall58c76b72015-02-23 11:09:24 -08001074 # Iter through intents of a node
1075 for intent in json.loads( node ):
Jon Hall1b8f54a2015-02-04 13:24:20 -08001076 nodeStates.append( intent[ 'state' ] )
1077 intentStates.append( nodeStates )
1078 out = [ (i, nodeStates.count( i ) ) for i in set( nodeStates ) ]
1079 main.log.info( dict( out ) )
1080
Jon Hall58c76b72015-02-23 11:09:24 -08001081 # NOTE: Store has no durability, so intents are lost across system
1082 # restarts
Jon Hall6aec96b2015-01-19 14:49:31 -08001083 """
1084 main.step( "Compare current intents with intents before the failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001085 # NOTE: this requires case 5 to pass for intentState to be set.
Jon Hall6aec96b2015-01-19 14:49:31 -08001086 # maybe we should stop the test if that fails?
Jon Hall1b8f54a2015-02-04 13:24:20 -08001087 sameIntents = main.TRUE
1088 if intentState and intentState == ONOS1Intents:
Jon Hall8f89dda2015-01-22 16:03:33 -08001089 sameIntents = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001090 main.log.report( "Intents are consistent with before failure" )
1091 # TODO: possibly the states have changed? we may need to figure out
1092 # what the aceptable states are
Jon Hall73cf9cc2014-11-20 22:28:38 -08001093 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001094 try:
1095 main.log.warn( "ONOS1 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001096 print json.dumps( json.loads( ONOS1Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -08001097 sort_keys=True, indent=4,
1098 separators=( ',', ': ' ) )
Jon Hallfebb1c72015-03-05 13:30:09 -08001099 except Exception:
Jon Hall6aec96b2015-01-19 14:49:31 -08001100 pass
Jon Hall8f89dda2015-01-22 16:03:33 -08001101 sameIntents = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001102 utilities.assert_equals(
1103 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001104 actual=sameIntents,
Jon Hall6aec96b2015-01-19 14:49:31 -08001105 onpass="Intents are consistent with before failure",
1106 onfail="The Intents changed during failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001107 intentCheck = intentCheck and sameIntents
Jon Hall6aec96b2015-01-19 14:49:31 -08001108 """
1109 main.step( "Get the OF Table entries and compare to before " +
1110 "component failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001111 FlowTables = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001112 flows2 = []
1113 for i in range( 28 ):
1114 main.log.info( "Checking flow table on s" + str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001115 tmpFlows = main.Mininet2.getFlowTable( 1.3, "s" + str( i + 1 ) )
1116 flows2.append( tmpFlows )
1117 tempResult = main.Mininet2.flowComp(
Jon Hall6aec96b2015-01-19 14:49:31 -08001118 flow1=flows[ i ],
Jon Hall8f89dda2015-01-22 16:03:33 -08001119 flow2=tmpFlows )
1120 FlowTables = FlowTables and tempResult
1121 if FlowTables == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001122 main.log.info( "Differences in flow table for switch: s" +
1123 str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001124 if FlowTables == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001125 main.log.report( "No changes were found in the flow tables" )
1126 utilities.assert_equals(
1127 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001128 actual=FlowTables,
Jon Hall6aec96b2015-01-19 14:49:31 -08001129 onpass="No changes were found in the flow tables",
1130 onfail="Changes were found in the flow tables" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001131
Jon Hall6aec96b2015-01-19 14:49:31 -08001132 # Test of LeadershipElection
Jon Hall669173b2014-12-17 11:36:30 -08001133
Jon Hall8f89dda2015-01-22 16:03:33 -08001134 leader = ONOS1Ip
1135 leaderResult = main.TRUE
1136 for controller in range( 1, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001137 # loop through ONOScli handlers
1138 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001139 leaderN = node.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001140 # verify leader is ONOS1
1141 # NOTE even though we restarted ONOS, it is the only one so onos 1
1142 # must be leader
Jon Hall669173b2014-12-17 11:36:30 -08001143 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08001144 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001145 pass
1146 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001147 # error in response
1148 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001149 "electionTestLeader function, check the" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001150 " error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001151 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001152 elif leader != leaderN:
Jon Hall8f89dda2015-01-22 16:03:33 -08001153 leaderResult = main.FALSE
Jon Hall58c76b72015-02-23 11:09:24 -08001154 main.log.report( "ONOS" + str( controller ) + " sees " +
1155 str( leaderN ) +
1156 " as the leader of the election app. " +
1157 "Leader should be " + str( leader ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001158 if leaderResult:
1159 main.log.report( "Leadership election tests passed( consistent " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001160 "view of leader across listeners and a new " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001161 "leader was re-elected if applicable )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001162 utilities.assert_equals(
1163 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001164 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001165 onpass="Leadership election passed",
1166 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08001167
Jon Hall8f89dda2015-01-22 16:03:33 -08001168 result = ( mastershipCheck and intentCheck and FlowTables and
1169 rolesNotNull and leaderResult )
Jon Hall6aec96b2015-01-19 14:49:31 -08001170 result = int( result )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001171 if result == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001172 main.log.report( "Constant State Tests Passed" )
1173 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall58c76b72015-02-23 11:09:24 -08001174 onpass="Constant State Tests Passed",
1175 onfail="Constant state tests failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001176
Jon Hall6aec96b2015-01-19 14:49:31 -08001177 def CASE8( self, main ):
1178 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001179 Compare topo
Jon Hall6aec96b2015-01-19 14:49:31 -08001180 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001181 import sys
Jon Hall6aec96b2015-01-19 14:49:31 -08001182 # FIXME add this path to params
1183 sys.path.append( "/home/admin/sts" )
1184 # assumes that sts is already in you PYTHONPATH
1185 from sts.topology.teston_topology import TestONTopology
Jon Hall73cf9cc2014-11-20 22:28:38 -08001186 import json
1187 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001188 assert numControllers, "numControllers not defined"
1189 assert main, "main not defined"
1190 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall73cf9cc2014-11-20 22:28:38 -08001191
Jon Hall6aec96b2015-01-19 14:49:31 -08001192 description = "Compare ONOS Topology view to Mininet topology"
1193 main.case( description )
1194 main.log.report( description )
1195 main.step( "Create TestONTopology object" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001196 ctrls = []
Jon Halla9d26da2015-03-30 16:45:32 -07001197 node = main.ONOS1
1198 temp = ( node, node.name, node.ip_address, 6633 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001199 ctrls.append( temp )
Jon Halla9d26da2015-03-30 16:45:32 -07001200 MNTopo = TestONTopology( main.Mininet1, ctrls )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001201
Jon Hall6aec96b2015-01-19 14:49:31 -08001202 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001203 devicesResults = main.TRUE
1204 portsResults = main.TRUE
1205 linksResults = main.TRUE
Jon Hall58c76b72015-02-23 11:09:24 -08001206 hostsResults = main.TRUE
Jon Hall8f89dda2015-01-22 16:03:33 -08001207 topoResult = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001208 elapsed = 0
Jon Hallffb386d2014-11-21 13:43:38 -08001209 count = 0
Jon Hall6aec96b2015-01-19 14:49:31 -08001210 main.step( "Collecting topology information from ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001211 startTime = time.time()
Jon Hall58c76b72015-02-23 11:09:24 -08001212 # Give time for Gossip to work
Jon Hall8f89dda2015-01-22 16:03:33 -08001213 while topoResult == main.FALSE and elapsed < 60:
Jon Halla9d26da2015-03-30 16:45:32 -07001214 count += 1
Jon Hall94fd0472014-12-08 11:52:42 -08001215 if count > 1:
Jon Halla9d26da2015-03-30 16:45:32 -07001216 # TODO: Deprecate STS usage
Jon Hall58c76b72015-02-23 11:09:24 -08001217 MNTopo = TestONTopology( main.Mininet1, ctrls )
Jon Hall8f89dda2015-01-22 16:03:33 -08001218 cliStart = time.time()
Jon Hall94fd0472014-12-08 11:52:42 -08001219 devices = []
1220 devices.append( main.ONOScli1.devices() )
Jon Hall94fd0472014-12-08 11:52:42 -08001221 hosts = []
Jon Hall58c76b72015-02-23 11:09:24 -08001222 hosts.append( json.loads( main.ONOScli1.hosts() ) )
1223 ipResult = main.TRUE
1224 for controller in range( 0, len( hosts ) ):
1225 controllerStr = str( controller + 1 )
1226 for host in hosts[ controller ]:
1227 if host is None or host.get( 'ips', [] ) == []:
1228 main.log.error(
1229 "DEBUG:Error with host ips on controller" +
1230 controllerStr + ": " + str( host ) )
1231 ipResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001232 ports = []
1233 ports.append( main.ONOScli1.ports() )
1234 links = []
1235 links.append( main.ONOScli1.links() )
Jon Hall58c76b72015-02-23 11:09:24 -08001236 clusters = []
1237 clusters.append( main.ONOScli1.clusters() )
1238
Jon Hall8f89dda2015-01-22 16:03:33 -08001239 elapsed = time.time() - startTime
1240 cliTime = time.time() - cliStart
1241 print "CLI time: " + str( cliTime )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001242
Jon Hall8f89dda2015-01-22 16:03:33 -08001243 for controller in range( numControllers ):
1244 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001245 if devices[ controller ] or "Error" not in devices[
1246 controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001247 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -08001248 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001249 json.loads( devices[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001250 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001251 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001252 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001253 actual=currentDevicesResult,
1254 onpass="ONOS" + controllerStr +
1255 " Switches view is correct",
1256 onfail="ONOS" + controllerStr +
1257 " Switches view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001258
Jon Hall6aec96b2015-01-19 14:49:31 -08001259 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001260 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -08001261 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001262 json.loads( ports[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001263 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001264 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001265 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001266 actual=currentPortsResult,
1267 onpass="ONOS" + controllerStr +
1268 " ports view is correct",
1269 onfail="ONOS" + controllerStr +
1270 " ports view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001271
Jon Hall6aec96b2015-01-19 14:49:31 -08001272 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001273 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -08001274 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001275 json.loads( links[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001276 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001277 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001278 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001279 actual=currentLinksResult,
1280 onpass="ONOS" + controllerStr +
1281 " links view is correct",
1282 onfail="ONOS" + controllerStr +
1283 " links view is incorrect" )
1284
1285 if hosts[ controller ] or "Error" not in hosts[ controller ]:
1286 currentHostsResult = main.Mininet1.compareHosts(
1287 MNTopo, hosts[ controller ] )
1288 else:
1289 currentHostsResult = main.FALSE
1290 utilities.assert_equals( expect=main.TRUE,
1291 actual=currentHostsResult,
1292 onpass="ONOS" + controllerStr +
1293 " hosts exist in Mininet",
1294 onfail="ONOS" + controllerStr +
1295 " hosts don't match Mininet" )
1296
1297 devicesResults = devicesResults and currentDevicesResult
1298 portsResults = portsResults and currentPortsResult
1299 linksResults = linksResults and currentLinksResult
1300 hostsResults = hostsResults and currentHostsResult
1301
Jon Hall63604932015-02-26 17:09:50 -08001302 # "consistent" results don't make sense for single instance
Jon Hall58c76b72015-02-23 11:09:24 -08001303 # there should always only be one cluster
1304 numClusters = len( json.loads( clusters[ 0 ] ) )
1305 clusterResults = main.FALSE
1306 if numClusters == 1:
1307 clusterResults = main.TRUE
1308 utilities.assert_equals(
1309 expect=1,
1310 actual=numClusters,
1311 onpass="ONOS shows 1 SCC",
1312 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
1313
1314 topoResult = ( devicesResults and portsResults and linksResults
1315 and hostsResults and ipResult and clusterResults )
Jon Hall94fd0472014-12-08 11:52:42 -08001316
Jon Hall8f89dda2015-01-22 16:03:33 -08001317 topoResult = topoResult and int( count <= 2 )
1318 note = "note it takes about " + str( int( cliTime ) ) + \
1319 " seconds for the test to make all the cli calls to fetch " +\
1320 "the topology from each ONOS instance"
Jon Hall1b8f54a2015-02-04 13:24:20 -08001321 main.log.info(
Jon Hall8f89dda2015-01-22 16:03:33 -08001322 "Very crass estimate for topology discovery/convergence( " +
1323 str( note ) + " ): " + str( elapsed ) + " seconds, " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001324 str( count ) + " tries" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001325 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
Jon Hall58c76b72015-02-23 11:09:24 -08001326 onpass="Topology Check Test successful",
1327 onfail="Topology Check Test NOT successful" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001328 if topoResult == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001329 main.log.report( "ONOS topology view matches Mininet topology" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001330
Jon Hall6aec96b2015-01-19 14:49:31 -08001331 def CASE9( self, main ):
1332 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001333 Link s3-s28 down
Jon Hall6aec96b2015-01-19 14:49:31 -08001334 """
1335 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001336 assert numControllers, "numControllers not defined"
1337 assert main, "main not defined"
1338 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -08001339 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001340
Jon Hall8f89dda2015-01-22 16:03:33 -08001341 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001342
Jon Hall6aec96b2015-01-19 14:49:31 -08001343 description = "Turn off a link to ensure that Link Discovery " +\
Jon Hall58c76b72015-02-23 11:09:24 -08001344 "is working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001345 main.log.report( description )
1346 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001347
Jon Hall6aec96b2015-01-19 14:49:31 -08001348 main.step( "Kill Link between s3 and s28" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001349 LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" )
Jon Hall58c76b72015-02-23 11:09:24 -08001350 main.log.info( "Waiting " + str( linkSleep ) +
1351 " seconds for link down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001352 time.sleep( linkSleep )
1353 utilities.assert_equals( expect=main.TRUE, actual=LinkDown,
Jon Halla9d26da2015-03-30 16:45:32 -07001354 onpass="Link down successful",
Jon Hall58c76b72015-02-23 11:09:24 -08001355 onfail="Failed to bring link down" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001356 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -08001357
Jon Hall6aec96b2015-01-19 14:49:31 -08001358 def CASE10( self, main ):
1359 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001360 Link s3-s28 up
Jon Hall6aec96b2015-01-19 14:49:31 -08001361 """
1362 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001363 assert numControllers, "numControllers not defined"
1364 assert main, "main not defined"
1365 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -08001366 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001367
Jon Hall8f89dda2015-01-22 16:03:33 -08001368 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001369
Jon Hall6aec96b2015-01-19 14:49:31 -08001370 description = "Restore a link to ensure that Link Discovery is " + \
Jon Hall58c76b72015-02-23 11:09:24 -08001371 "working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001372 main.log.report( description )
1373 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001374
Jon Hall6aec96b2015-01-19 14:49:31 -08001375 main.step( "Bring link between s3 and s28 back up" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001376 LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" )
Jon Hall58c76b72015-02-23 11:09:24 -08001377 main.log.info( "Waiting " + str( linkSleep ) +
1378 " seconds for link up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001379 time.sleep( linkSleep )
1380 utilities.assert_equals( expect=main.TRUE, actual=LinkUp,
Jon Halla9d26da2015-03-30 16:45:32 -07001381 onpass="Link up successful",
Jon Hall58c76b72015-02-23 11:09:24 -08001382 onfail="Failed to bring link up" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001383 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -08001384
Jon Hall6aec96b2015-01-19 14:49:31 -08001385 def CASE11( self, main ):
1386 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001387 Switch Down
Jon Hall6aec96b2015-01-19 14:49:31 -08001388 """
1389 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001390 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001391 assert numControllers, "numControllers not defined"
1392 assert main, "main not defined"
1393 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall73cf9cc2014-11-20 22:28:38 -08001394
Jon Hall8f89dda2015-01-22 16:03:33 -08001395 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001396
1397 description = "Killing a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001398 main.log.report( description )
1399 main.case( description )
1400 switch = main.params[ 'kill' ][ 'switch' ]
1401 switchDPID = main.params[ 'kill' ][ 'dpid' ]
Jon Hall73cf9cc2014-11-20 22:28:38 -08001402
Jon Hall6aec96b2015-01-19 14:49:31 -08001403 # TODO: Make this switch parameterizable
1404 main.step( "Kill " + switch )
1405 main.log.report( "Deleting " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001406 main.Mininet1.delSwitch( switch )
1407 main.log.info( "Waiting " + str( switchSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001408 " seconds for switch down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001409 time.sleep( switchSleep )
1410 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001411 # Peek at the deleted switch
1412 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001413 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001414 if device and device[ 'available' ] is False:
Jon Hall94fd0472014-12-08 11:52:42 -08001415 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001416 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Halla9d26da2015-03-30 16:45:32 -07001417 onpass="Kill switch successful",
Jon Hall58c76b72015-02-23 11:09:24 -08001418 onfail="Failed to kill switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001419
Jon Hall6aec96b2015-01-19 14:49:31 -08001420 def CASE12( self, main ):
1421 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001422 Switch Up
Jon Hall6aec96b2015-01-19 14:49:31 -08001423 """
1424 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001425 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001426 assert numControllers, "numControllers not defined"
1427 assert main, "main not defined"
1428 assert utilities.assert_equals, "utilities.assert_equals not defined"
1429 assert ONOS1Port, "ONOS1Port not defined"
1430 assert ONOS2Port, "ONOS2Port not defined"
1431 assert ONOS3Port, "ONOS3Port not defined"
1432 assert ONOS4Port, "ONOS4Port not defined"
1433 assert ONOS5Port, "ONOS5Port not defined"
1434 assert ONOS6Port, "ONOS6Port not defined"
1435 assert ONOS7Port, "ONOS7Port not defined"
Jon Hall669173b2014-12-17 11:36:30 -08001436
Jon Hall8f89dda2015-01-22 16:03:33 -08001437 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall6aec96b2015-01-19 14:49:31 -08001438 switch = main.params[ 'kill' ][ 'switch' ]
1439 switchDPID = main.params[ 'kill' ][ 'dpid' ]
1440 links = main.params[ 'kill' ][ 'links' ].split()
Jon Hall73cf9cc2014-11-20 22:28:38 -08001441 description = "Adding a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001442 main.log.report( description )
1443 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001444
Jon Hall6aec96b2015-01-19 14:49:31 -08001445 main.step( "Add back " + switch )
1446 main.log.report( "Adding back " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001447 main.Mininet1.addSwitch( switch, dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001448 for peer in links:
Jon Hall8f89dda2015-01-22 16:03:33 -08001449 main.Mininet1.addLink( switch, peer )
1450 main.Mininet1.assignSwController( sw=switch.split( 's' )[ 1 ],
Jon Hall58c76b72015-02-23 11:09:24 -08001451 ip1=ONOS1Ip,
1452 port1=ONOS1Port )
1453 main.log.info( "Waiting " + str( switchSleep ) +
1454 " seconds for switch up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001455 time.sleep( switchSleep )
1456 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001457 # Peek at the deleted switch
1458 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001459 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001460 if device and device[ 'available' ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001461 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001462 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Halla9d26da2015-03-30 16:45:32 -07001463 onpass="add switch successful",
Jon Hall58c76b72015-02-23 11:09:24 -08001464 onfail="Failed to add switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001465
Jon Hall6aec96b2015-01-19 14:49:31 -08001466 def CASE13( self, main ):
1467 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001468 Clean up
Jon Hall6aec96b2015-01-19 14:49:31 -08001469 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001470 import os
1471 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001472 assert numControllers, "numControllers not defined"
1473 assert main, "main not defined"
1474 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -08001475 # printing colors to terminal
Jon Halla9d26da2015-03-30 16:45:32 -07001476 colors = { 'cyan': '\033[96m', 'purple': '\033[95m',
1477 'blue': '\033[94m', 'green': '\033[92m',
1478 'yellow': '\033[93m', 'red': '\033[91m', 'end': '\033[0m' }
Jon Hall73cf9cc2014-11-20 22:28:38 -08001479 description = "Test Cleanup"
Jon Hall6aec96b2015-01-19 14:49:31 -08001480 main.log.report( description )
1481 main.case( description )
1482 main.step( "Killing tcpdumps" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001483 main.Mininet2.stopTcpdump()
Jon Hall73cf9cc2014-11-20 22:28:38 -08001484
Jon Hall6aec96b2015-01-19 14:49:31 -08001485 main.step( "Copying MN pcap and ONOS log files to test station" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001486 testname = main.TEST
Jon Hall8f89dda2015-01-22 16:03:33 -08001487 teststationUser = main.params[ 'TESTONUSER' ]
1488 teststationIP = main.params[ 'TESTONIP' ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001489 # NOTE: MN Pcap file is being saved to ~/packet_captures
Jon Hall73cf9cc2014-11-20 22:28:38 -08001490 # scp this file as MN and TestON aren't necessarily the same vm
Jon Hall6aec96b2015-01-19 14:49:31 -08001491 # FIXME: scp
1492 # mn files
1493 # TODO: Load these from params
1494 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001495 logFolder = "/opt/onos/log/"
1496 logFiles = [ "karaf.log", "karaf.log.1" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001497 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001498 dstDir = "~/packet_captures/"
1499 for f in logFiles:
1500 main.ONOSbench.handle.sendline( "scp sdn@" + ONOS1Ip + ":" +
1501 logFolder + f + " " +
1502 teststationUser + "@" +
1503 teststationIP + ":" + dstDir +
Jon Hall6aec96b2015-01-19 14:49:31 -08001504 str( testname ) + "-ONOS1-" + f )
1505 main.ONOSbench.handle.expect( "\$" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001506
Jon Hall6aec96b2015-01-19 14:49:31 -08001507 # std*.log's
1508 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001509 logFolder = "/opt/onos/var/"
1510 logFiles = [ "stderr.log", "stdout.log" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001511 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001512 dstDir = "~/packet_captures/"
1513 for f in logFiles:
1514 main.ONOSbench.handle.sendline( "scp sdn@" + ONOS1Ip + ":" +
1515 logFolder + f + " " +
1516 teststationUser + "@" +
1517 teststationIP + ":" + dstDir +
Jon Hall6aec96b2015-01-19 14:49:31 -08001518 str( testname ) + "-ONOS1-" + f )
Jon Hall58c76b72015-02-23 11:09:24 -08001519 main.ONOSbench.handle.expect( "\$" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001520 # sleep so scp can finish
1521 time.sleep( 10 )
Jon Halla9d26da2015-03-30 16:45:32 -07001522
1523 main.step( "Stopping Mininet" )
Jon Hall58c76b72015-02-23 11:09:24 -08001524 main.Mininet1.stopNet()
Jon Halla9d26da2015-03-30 16:45:32 -07001525
1526 main.step( "Checking ONOS Logs for errors" )
1527 print colors[ 'purple' ] + "Checking logs for errors on ONOS1:" + \
1528 colors[ 'end' ]
1529 print main.ONOSbench.checkLogs( ONOS1Ip )
1530
Jon Hall6aec96b2015-01-19 14:49:31 -08001531 main.step( "Packing and rotating pcap archives" )
1532 os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001533
Jon Hall6aec96b2015-01-19 14:49:31 -08001534 # TODO: actually check something here
1535 utilities.assert_equals( expect=main.TRUE, actual=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001536 onpass="Test cleanup successful",
1537 onfail="Test cleanup NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001538
Jon Hall6aec96b2015-01-19 14:49:31 -08001539 def CASE14( self, main ):
1540 """
Jon Hall669173b2014-12-17 11:36:30 -08001541 start election app on all onos nodes
Jon Hall6aec96b2015-01-19 14:49:31 -08001542 """
Jon Hall5cfd23c2015-03-19 11:40:57 -07001543 assert numControllers, "numControllers not defined"
1544 assert main, "main not defined"
1545 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halla9d26da2015-03-30 16:45:32 -07001546
Jon Hall8f89dda2015-01-22 16:03:33 -08001547 leaderResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001548 main.log.info( "Install leadership election app" )
Jon Halla9d26da2015-03-30 16:45:32 -07001549 main.ONOScli1.activateApp( "org.onosproject.election" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001550 # check for leader
Jon Hall8f89dda2015-01-22 16:03:33 -08001551 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001552 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08001553 if leader == ONOS1Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08001554 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001555 pass
Jon Hall6aec96b2015-01-19 14:49:31 -08001556 elif leader is None:
1557 # No leader elected
1558 main.log.report( "No leader was elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001559 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001560 elif leader == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001561 # error in response
1562 # TODO: add check for "Command not found:" in the driver, this
1563 # means the app isn't loaded
Jon Hall8f89dda2015-01-22 16:03:33 -08001564 main.log.report( "Something is wrong with electionTestLeader" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001565 " function, check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001566 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001567 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001568 # error in response
1569 main.log.report(
Jon Hall8f89dda2015-01-22 16:03:33 -08001570 "Unexpected response from electionTestLeader function:'" +
1571 str( leader ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001572 "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001573 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001574
Jon Hall8f89dda2015-01-22 16:03:33 -08001575 if leaderResult:
Jon Hall6aec96b2015-01-19 14:49:31 -08001576 main.log.report( "Leadership election tests passed( consistent " +
1577 "view of leader across listeners and a leader " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001578 "was elected )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001579 utilities.assert_equals(
1580 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001581 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001582 onpass="Leadership election passed",
1583 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08001584
Jon Hall6aec96b2015-01-19 14:49:31 -08001585 def CASE15( self, main ):
1586 """
Jon Hall669173b2014-12-17 11:36:30 -08001587 Check that Leadership Election is still functional
Jon Hall6aec96b2015-01-19 14:49:31 -08001588 """
Jon Hall5cfd23c2015-03-19 11:40:57 -07001589 assert numControllers, "numControllers not defined"
1590 assert main, "main not defined"
1591 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall8f89dda2015-01-22 16:03:33 -08001592 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08001593 description = "Check that Leadership Election is still functional"
Jon Hall6aec96b2015-01-19 14:49:31 -08001594 main.log.report( description )
1595 main.case( description )
1596 main.step( "Find current leader and withdraw" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001597 leader = main.ONOScli1.electionTestLeader()
Jon Halla9d26da2015-03-30 16:45:32 -07001598 # do some sanity checking on leader before using it
Jon Hall8f89dda2015-01-22 16:03:33 -08001599 withdrawResult = main.FALSE
1600 if leader == ONOS1Ip:
1601 oldLeader = getattr( main, "ONOScli1" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001602 elif leader is None or leader == main.FALSE:
1603 main.log.report(
1604 "Leader for the election app should be an ONOS node," +
Jon Hall58c76b72015-02-23 11:09:24 -08001605 "instead got '" + str( leader ) + "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001606 leaderResult = main.FALSE
Jon Hall63604932015-02-26 17:09:50 -08001607 oldLeader = None
1608 else:
1609 main.log.error( "Leader election --- why am I HERE?!?")
1610 if oldLeader:
1611 withdrawResult = oldLeader.electionTestWithdraw()
Jon Hall6aec96b2015-01-19 14:49:31 -08001612 utilities.assert_equals(
1613 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001614 actual=withdrawResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001615 onpass="App was withdrawn from election",
1616 onfail="App was not withdrawn from election" )
Jon Hall669173b2014-12-17 11:36:30 -08001617
Jon Hall6aec96b2015-01-19 14:49:31 -08001618 main.step( "Make sure new leader is elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001619 leaderN = main.ONOScli1.electionTestLeader()
Jon Hall669173b2014-12-17 11:36:30 -08001620 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08001621 main.log.report( "ONOS still sees " + str( leaderN ) +
1622 " as leader after they withdrew" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001623 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001624 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001625 # error in response
1626 # TODO: add check for "Command not found:" in the driver, this
1627 # means the app isn't loaded
Jon Hall8f89dda2015-01-22 16:03:33 -08001628 main.log.report( "Something is wrong with electionTestLeader " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001629 "function, check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001630 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001631 elif leaderN is None:
1632 main.log.info(
1633 "There is no leader after the app withdrew from election" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001634 if leaderResult:
1635 main.log.report( "Leadership election tests passed( There is no " +
1636 "leader after the old leader resigned )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001637 utilities.assert_equals(
1638 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001639 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001640 onpass="Leadership election passed",
1641 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08001642
Jon Hall58c76b72015-02-23 11:09:24 -08001643 main.step( "Run for election on old leader( just so everyone " +
1644 "is in the hat )" )
Jon Hall63604932015-02-26 17:09:50 -08001645 if oldLeader:
1646 runResult = oldLeader.electionTestRun()
1647 else:
1648 runResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001649 utilities.assert_equals(
1650 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001651 actual=runResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001652 onpass="App re-ran for election",
1653 onfail="App failed to run for election" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001654 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001655 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08001656 if leader == ONOS1Ip:
1657 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08001658 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001659 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001660 # TODO: assert on run and withdraw results?
Jon Hall669173b2014-12-17 11:36:30 -08001661
Jon Hall6aec96b2015-01-19 14:49:31 -08001662 utilities.assert_equals(
1663 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001664 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001665 onpass="Leadership election passed",
1666 onfail="ONOS1's election app was not leader after it re-ran " +
1667 "for election" )