blob: b3894b7ae7c0b73c197febb4ca326268d7d05f88 [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
240 if ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
241 roleCheck = roleCheck and main.TRUE
242 else:
243 roleCheck = roleCheck and main.FALSE
244 main.log.error( "Error, controller " + ip + " is not" +
245 " master " + "of device " +
246 str( deviceId ) )
247 except ( AttributeError, AssertionError ):
248 main.log.exception( "Something is wrong with ONOS device view" )
249 main.log.info( main.ONOScli1.devices() )
250 utilities.assert_equals(
251 expect=main.TRUE,
252 actual=roleCall,
253 onpass="Re-assigned switch mastership to designated controller",
254 onfail="Something wrong with deviceRole calls" )
255
256 utilities.assert_equals(
257 expect=main.TRUE,
258 actual=roleCheck,
259 onpass="Switches were successfully reassigned to designated " +
260 "controller",
261 onfail="Switches were not successfully reassigned" )
262 mastershipCheck = mastershipCheck and roleCall and roleCheck
263 utilities.assert_equals( expect=main.TRUE, actual=mastershipCheck,
264 onpass="Switch mastership correctly assigned",
265 onfail="Error in (re)assigning switch" +
266 " mastership" )
267
Jon Hall6aec96b2015-01-19 14:49:31 -0800268 def CASE3( self, main ):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800269 """
270 Assign intents
Jon Hall73cf9cc2014-11-20 22:28:38 -0800271 """
272 import time
Jon Hallfebb1c72015-03-05 13:30:09 -0800273 import json
Jon Hall5cfd23c2015-03-19 11:40:57 -0700274 assert numControllers, "numControllers not defined"
275 assert main, "main not defined"
276 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall73cf9cc2014-11-20 22:28:38 -0800277 # FIXME: we must reinstall intents until we have a persistant
278 # datastore!
Jon Hall6aec96b2015-01-19 14:49:31 -0800279 main.log.report( "Adding host intents" )
280 main.case( "Adding host Intents" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800281
Jon Hall8f89dda2015-01-22 16:03:33 -0800282 main.step( "Discovering Hosts( Via pingall for now )" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800283 # FIXME: Once we have a host discovery mechanism, use that instead
Jon Hall73cf9cc2014-11-20 22:28:38 -0800284
Jon Hall6aec96b2015-01-19 14:49:31 -0800285 # install onos-app-fwd
286 main.log.info( "Install reactive forwarding app" )
Jon Halla9d26da2015-03-30 16:45:32 -0700287 appResults = main.ONOScli1.activateApp( "org.onosproject.fwd" )
288
289 # FIXME: add this to asserts
290 appCheck = main.ONOScli1.appToIDCheck()
291 if appCheck != main.TRUE:
292 main.log.warn( CLIs[0].apps() )
293 main.log.warn( CLIs[0].appIDs() )
Jon Hall94fd0472014-12-08 11:52:42 -0800294
Jon Hall6aec96b2015-01-19 14:49:31 -0800295 # REACTIVE FWD test
Jon Hall8f89dda2015-01-22 16:03:33 -0800296 pingResult = main.FALSE
Jon Hall5cfd23c2015-03-19 11:40:57 -0700297 for i in range(2): # Retry if pingall fails first time
298 time1 = time.time()
299 pingResult = main.Mininet1.pingall()
300 utilities.assert_equals(
301 expect=main.TRUE,
302 actual=pingResult,
303 onpass="Reactive Pingall test passed",
304 onfail="Reactive Pingall failed, one or more ping pairs failed" )
305 time2 = time.time()
306 main.log.info( "Time for pingall: %2f seconds" % ( time2 - time1 ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800307
Jon Hall6aec96b2015-01-19 14:49:31 -0800308 # uninstall onos-app-fwd
309 main.log.info( "Uninstall reactive forwarding app" )
Jon Halla9d26da2015-03-30 16:45:32 -0700310 appResults = appResults and main.ONOScli1.deactivateApp( "org.onosproject.fwd" )
311 appCheck2 = main.ONOScli1.appToIDCheck()
312 if appCheck2 != main.TRUE:
313 main.log.warn( CLIs[0].apps() )
314 main.log.warn( CLIs[0].appIDs() )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800315
Jon Halla9d26da2015-03-30 16:45:32 -0700316 # timeout for fwd flows
317 time.sleep( 11 )
318
319 main.step( "Add host intents" )
Jon Hall58c76b72015-02-23 11:09:24 -0800320 intentIds = []
Jon Hall6aec96b2015-01-19 14:49:31 -0800321 # TODO: move the host numbers to params
Jon Hall58c76b72015-02-23 11:09:24 -0800322 # Maybe look at all the paths we ping?
Jon Hall8f89dda2015-01-22 16:03:33 -0800323 intentAddResult = True
Jon Hall58c76b72015-02-23 11:09:24 -0800324 hostResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800325 for i in range( 8, 18 ):
326 main.log.info( "Adding host intent between h" + str( i ) +
327 " and h" + str( i + 10 ) )
328 host1 = "00:00:00:00:00:" + \
329 str( hex( i )[ 2: ] ).zfill( 2 ).upper()
330 host2 = "00:00:00:00:00:" + \
331 str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper()
Jon Hall1b8f54a2015-02-04 13:24:20 -0800332 # NOTE: getHost can return None
333 host1Dict = main.ONOScli1.getHost( host1 )
334 host2Dict = main.ONOScli1.getHost( host2 )
335 host1Id = None
336 host2Id = None
337 if host1Dict and host2Dict:
338 host1Id = host1Dict.get( 'id', None )
339 host2Id = host2Dict.get( 'id', None )
Jon Hall8f89dda2015-01-22 16:03:33 -0800340 if host1Id and host2Id:
Jon Halla9d26da2015-03-30 16:45:32 -0700341 tmpId = main.ONOScli1.addHostIntent( host1Id, host2Id )
Jon Hall63604932015-02-26 17:09:50 -0800342 if tmpId:
343 main.log.info( "Added intent with id: " + tmpId )
344 intentIds.append( tmpId )
345 else:
Jon Halla9d26da2015-03-30 16:45:32 -0700346 main.log.error( "addHostIntent returned: " +
347 repr( tmpId ) )
Jon Hall669173b2014-12-17 11:36:30 -0800348 else:
Jon Halla9d26da2015-03-30 16:45:32 -0700349 main.log.error( "Error, getHost() failed for h" + str( i ) +
350 " and/or h" + str( i + 10 ) )
351 hosts = main.ONOScli1.hosts()
352 main.log.warn( "Hosts output: " )
353 try:
354 main.log.warn( json.dumps( json.loads( hosts ),
355 sort_keys=True,
356 indent=4,
357 separators=( ',', ': ' ) ) )
358 except ( ValueError, TypeError ):
359 main.log.warn( repr( hosts ) )
Jon Hall58c76b72015-02-23 11:09:24 -0800360 hostResult = main.FALSE
Jon Halla9d26da2015-03-30 16:45:32 -0700361 # FIXME: DEBUG
362 intentStart = time.time()
Jon Hall58c76b72015-02-23 11:09:24 -0800363 onosIds = main.ONOScli1.getAllIntentsId()
364 main.log.info( "Submitted intents: " + str( intentIds ) )
365 main.log.info( "Intents in ONOS: " + str( onosIds ) )
366 for intent in intentIds:
367 if intent in onosIds:
Jon Halla9d26da2015-03-30 16:45:32 -0700368 pass # intent submitted is in onos
Jon Hall58c76b72015-02-23 11:09:24 -0800369 else:
370 intentAddResult = False
Jon Halla9d26da2015-03-30 16:45:32 -0700371 # FIXME: DEBUG
372 if intentAddResult:
373 intentStop = time.time()
374 else:
375 intentStop = None
Jon Hall1b8f54a2015-02-04 13:24:20 -0800376 # Print the intent states
Jon Hall58c76b72015-02-23 11:09:24 -0800377 intents = main.ONOScli1.intents()
Jon Hall1b8f54a2015-02-04 13:24:20 -0800378 intentStates = []
Jon Halla9d26da2015-03-30 16:45:32 -0700379 installedCheck = True
Jon Hall58c76b72015-02-23 11:09:24 -0800380 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
381 count = 0
Jon Hall5cfd23c2015-03-19 11:40:57 -0700382 try:
383 for intent in json.loads( intents ):
384 state = intent.get( 'state', None )
385 if "INSTALLED" not in state:
386 installedCheck = False
387 intentId = intent.get( 'id', None )
388 intentStates.append( ( intentId, state ) )
389 except ( ValueError, TypeError ):
390 main.log.exception( "Error parsing intents" )
Jon Hall58c76b72015-02-23 11:09:24 -0800391 # add submitted intents not in the store
392 tmplist = [ i for i, s in intentStates ]
393 missingIntents = False
394 for i in intentIds:
395 if i not in tmplist:
396 intentStates.append( ( i, " - " ) )
397 missingIntents = True
398 intentStates.sort()
399 for i, s in intentStates:
400 count += 1
401 main.log.info( "%-6s%-15s%-15s" %
402 ( str( count ), str( i ), str( s ) ) )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700403 leaders = main.ONOScli1.leaders()
404 try:
405 if leaders:
406 parsedLeaders = json.loads( leaders )
407 main.log.warn( json.dumps( parsedLeaders,
408 sort_keys=True,
409 indent=4,
410 separators=( ',', ': ' ) ) )
411 # check for all intent partitions
Jon Hall5cfd23c2015-03-19 11:40:57 -0700412 topics = []
413 for i in range( 14 ):
414 topics.append( "intent-partition-" + str( i ) )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700415 main.log.debug( topics )
416 ONOStopics = [ j['topic'] for j in parsedLeaders ]
417 for topic in topics:
418 if topic not in ONOStopics:
419 main.log.error( "Error: " + topic +
420 " not in leaders" )
421 else:
422 main.log.error( "leaders() returned None" )
423 except ( ValueError, TypeError ):
424 main.log.exception( "Error parsing leaders" )
425 main.log.error( repr( leaders ) )
426 partitions = main.ONOScli1.partitions()
427 try:
428 if partitions :
429 parsedPartitions = json.loads( partitions )
430 main.log.warn( json.dumps( parsedPartitions,
431 sort_keys=True,
432 indent=4,
433 separators=( ',', ': ' ) ) )
434 # TODO check for a leader in all paritions
435 # TODO check for consistency among nodes
436 else:
437 main.log.error( "partitions() returned None" )
438 except ( ValueError, TypeError ):
439 main.log.exception( "Error parsing partitions" )
440 main.log.error( repr( partitions ) )
Jon Hall63604932015-02-26 17:09:50 -0800441 pendingMap = main.ONOScli1.pendingMap()
Jon Hall5cfd23c2015-03-19 11:40:57 -0700442 try:
443 if pendingMap :
444 parsedPending = json.loads( pendingMap )
445 main.log.warn( json.dumps( parsedPending,
446 sort_keys=True,
447 indent=4,
448 separators=( ',', ': ' ) ) )
449 # TODO check something here?
450 else:
451 main.log.error( "pendingMap() returned None" )
452 except ( ValueError, TypeError ):
453 main.log.exception( "Error parsing pending map" )
454 main.log.error( repr( pendingMap ) )
455
Jon Hall58c76b72015-02-23 11:09:24 -0800456 intentAddResult = bool( pingResult and hostResult and intentAddResult
Jon Hall63604932015-02-26 17:09:50 -0800457 and not missingIntents and installedCheck )
Jon Hall6aec96b2015-01-19 14:49:31 -0800458 utilities.assert_equals(
459 expect=True,
Jon Hall8f89dda2015-01-22 16:03:33 -0800460 actual=intentAddResult,
Jon Hall529a37f2015-01-28 10:02:00 -0800461 onpass="Pushed host intents to ONOS",
462 onfail="Error in pushing host intents to ONOS" )
Jon Hall58c76b72015-02-23 11:09:24 -0800463
Jon Hall63604932015-02-26 17:09:50 -0800464 if not intentAddResult or "key" in pendingMap:
Jon Hall58c76b72015-02-23 11:09:24 -0800465 import time
Jon Hall63604932015-02-26 17:09:50 -0800466 installedCheck = True
Jon Hall58c76b72015-02-23 11:09:24 -0800467 main.log.info( "Sleeping 60 seconds to see if intents are found" )
468 time.sleep( 60 )
469 onosIds = main.ONOScli1.getAllIntentsId()
470 main.log.info( "Submitted intents: " + str( intentIds ) )
471 main.log.info( "Intents in ONOS: " + str( onosIds ) )
472 # Print the intent states
473 intents = main.ONOScli1.intents()
474 intentStates = []
475 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
476 count = 0
Jon Hall5cfd23c2015-03-19 11:40:57 -0700477 try:
478 for intent in json.loads( intents ):
479 # Iter through intents of a node
480 state = intent.get( 'state', None )
481 if "INSTALLED" not in state:
482 installedCheck = False
483 intentId = intent.get( 'id', None )
484 intentStates.append( ( intentId, state ) )
485 except ( ValueError, TypeError ):
486 main.log.exception( "Error parsing intents" )
Jon Hall58c76b72015-02-23 11:09:24 -0800487 # add submitted intents not in the store
488 tmplist = [ i for i, s in intentStates ]
489 for i in intentIds:
490 if i not in tmplist:
491 intentStates.append( ( i, " - " ) )
492 intentStates.sort()
493 for i, s in intentStates:
494 count += 1
495 main.log.info( "%-6s%-15s%-15s" %
496 ( str( count ), str( i ), str( s ) ) )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700497 leaders = main.ONOScli1.leaders()
498 try:
499 if leaders:
500 parsedLeaders = json.loads( leaders )
501 main.log.warn( json.dumps( parsedLeaders,
502 sort_keys=True,
503 indent=4,
504 separators=( ',', ': ' ) ) )
505 # check for all intent partitions
506 # check for election
507 topics = []
508 for i in range( 14 ):
509 topics.append( "intent-partition-" + str( i ) )
510 # FIXME: this should only be after we start the app
511 topics.append( "org.onosproject.election" )
512 main.log.debug( topics )
513 ONOStopics = [ j['topic'] for j in parsedLeaders ]
514 for topic in topics:
515 if topic not in ONOStopics:
516 main.log.error( "Error: " + topic +
517 " not in leaders" )
518 else:
519 main.log.error( "leaders() returned None" )
520 except ( ValueError, TypeError ):
521 main.log.exception( "Error parsing leaders" )
522 main.log.error( repr( leaders ) )
523 partitions = main.ONOScli1.partitions()
524 try:
525 if partitions :
526 parsedPartitions = json.loads( partitions )
527 main.log.warn( json.dumps( parsedPartitions,
528 sort_keys=True,
529 indent=4,
530 separators=( ',', ': ' ) ) )
531 # TODO check for a leader in all paritions
532 # TODO check for consistency among nodes
533 else:
534 main.log.error( "partitions() returned None" )
535 except ( ValueError, TypeError ):
536 main.log.exception( "Error parsing partitions" )
537 main.log.error( repr( partitions ) )
538 pendingMap = main.ONOScli1.pendingMap()
539 try:
540 if pendingMap :
541 parsedPending = json.loads( pendingMap )
542 main.log.warn( json.dumps( parsedPending,
543 sort_keys=True,
544 indent=4,
545 separators=( ',', ': ' ) ) )
546 # TODO check something here?
547 else:
548 main.log.error( "pendingMap() returned None" )
549 except ( ValueError, TypeError ):
550 main.log.exception( "Error parsing pending map" )
551 main.log.error( repr( pendingMap ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800552
Jon Hall6aec96b2015-01-19 14:49:31 -0800553 def CASE4( self, main ):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800554 """
555 Ping across added host intents
556 """
Jon Hallfebb1c72015-03-05 13:30:09 -0800557 import json
Jon Halla9d26da2015-03-30 16:45:32 -0700558 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -0700559 assert numControllers, "numControllers not defined"
560 assert main, "main not defined"
561 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall73cf9cc2014-11-20 22:28:38 -0800562 description = " Ping across added host intents"
Jon Hall6aec96b2015-01-19 14:49:31 -0800563 main.log.report( description )
564 main.case( description )
Jon Hall8f89dda2015-01-22 16:03:33 -0800565 PingResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800566 for i in range( 8, 18 ):
Jon Hall58c76b72015-02-23 11:09:24 -0800567 ping = main.Mininet1.pingHost( src="h" + str( i ),
568 target="h" + str( i + 10 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800569 PingResult = PingResult and ping
Jon Hall6aec96b2015-01-19 14:49:31 -0800570 if ping == main.FALSE:
571 main.log.warn( "Ping failed between h" + str( i ) +
572 " and h" + str( i + 10 ) )
573 elif ping == main.TRUE:
574 main.log.info( "Ping test passed!" )
Jon Hall21270ac2015-02-16 17:59:55 -0800575 # Don't set PingResult or you'd override failures
Jon Hall8f89dda2015-01-22 16:03:33 -0800576 if PingResult == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800577 main.log.report(
578 "Intents have not been installed correctly, pings failed." )
Jon Hall58c76b72015-02-23 11:09:24 -0800579 # TODO: pretty print
Jon Hall5cfd23c2015-03-19 11:40:57 -0700580 main.log.warn( "ONOS1 intents: " )
581 try:
582 tmpIntents = main.ONOScli1.intents()
583 main.log.warn( json.dumps( json.loads( tmpIntents ),
584 sort_keys=True,
585 indent=4,
586 separators=( ',', ': ' ) ) )
587 except ( ValueError, TypeError ):
588 main.log.warn( repr( tmpIntents ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800589 if PingResult == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800590 main.log.report(
591 "Intents have been installed correctly and verified by pings" )
592 utilities.assert_equals(
593 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800594 actual=PingResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800595 onpass="Intents have been installed correctly and pings work",
596 onfail="Intents have not been installed correctly, pings failed." )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800597
Jon Hall63604932015-02-26 17:09:50 -0800598 installedCheck = True
Jon Hall58c76b72015-02-23 11:09:24 -0800599 if PingResult is not main.TRUE:
600 # Print the intent states
601 intents = main.ONOScli1.intents()
602 intentStates = []
603 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
604 count = 0
605 # Iter through intents of a node
Jon Hall5cfd23c2015-03-19 11:40:57 -0700606 try:
607 for intent in json.loads( intents ):
608 state = intent.get( 'state', None )
609 if "INSTALLED" not in state:
610 installedCheck = False
611 intentId = intent.get( 'id', None )
612 intentStates.append( ( intentId, state ) )
613 except ( ValueError, TypeError ):
614 main.log.exception( "Error parsing intents." )
Jon Hall58c76b72015-02-23 11:09:24 -0800615 intentStates.sort()
616 for i, s in intentStates:
617 count += 1
618 main.log.info( "%-6s%-15s%-15s" %
619 ( str( count ), str( i ), str( s ) ) )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700620 leaders = main.ONOScli1.leaders()
621 try:
622 if leaders:
623 parsedLeaders = json.loads( leaders )
624 main.log.warn( json.dumps( parsedLeaders,
625 sort_keys=True,
626 indent=4,
627 separators=( ',', ': ' ) ) )
628 # check for all intent partitions
629 # check for election
630 topics = []
631 for i in range( 14 ):
632 topics.append( "intent-partition-" + str( i ) )
633 # FIXME: this should only be after we start the app
634 topics.append( "org.onosproject.election" )
635 main.log.debug( topics )
636 ONOStopics = [ j['topic'] for j in parsedLeaders ]
637 for topic in topics:
638 if topic not in ONOStopics:
639 main.log.error( "Error: " + topic +
640 " not in leaders" )
641 else:
642 main.log.error( "leaders() returned None" )
643 except ( ValueError, TypeError ):
644 main.log.exception( "Error parsing leaders" )
645 main.log.error( repr( leaders ) )
646 partitions = main.ONOScli1.partitions()
647 try:
648 if partitions :
649 parsedPartitions = json.loads( partitions )
650 main.log.warn( json.dumps( parsedPartitions,
651 sort_keys=True,
652 indent=4,
653 separators=( ',', ': ' ) ) )
654 # TODO check for a leader in all paritions
655 # TODO check for consistency among nodes
656 else:
657 main.log.error( "partitions() returned None" )
658 except ( ValueError, TypeError ):
659 main.log.exception( "Error parsing partitions" )
660 main.log.error( repr( partitions ) )
661 pendingMap = main.ONOScli1.pendingMap()
662 try:
663 if pendingMap :
664 parsedPending = json.loads( pendingMap )
665 main.log.warn( json.dumps( parsedPending,
666 sort_keys=True,
667 indent=4,
668 separators=( ',', ': ' ) ) )
669 # TODO check something here?
670 else:
671 main.log.error( "pendingMap() returned None" )
672 except ( ValueError, TypeError ):
673 main.log.exception( "Error parsing pending map" )
674 main.log.error( repr( pendingMap ) )
675
Jon Hall63604932015-02-26 17:09:50 -0800676 if not installedCheck:
Jon Hall5cfd23c2015-03-19 11:40:57 -0700677 main.log.info( "Waiting 60 seconds to see if the state of " +
678 "intents change" )
Jon Hall63604932015-02-26 17:09:50 -0800679 time.sleep( 60 )
680 # Print the intent states
681 intents = main.ONOScli1.intents()
682 intentStates = []
683 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
684 count = 0
685 # Iter through intents of a node
Jon Hall5cfd23c2015-03-19 11:40:57 -0700686 try:
687 for intent in json.loads( intents ):
688 state = intent.get( 'state', None )
689 if "INSTALLED" not in state:
690 installedCheck = False
691 intentId = intent.get( 'id', None )
692 intentStates.append( ( intentId, state ) )
693 except ( ValueError, TypeError ):
694 main.log.exception( "Error parsing intents." )
Jon Hall63604932015-02-26 17:09:50 -0800695 intentStates.sort()
696 for i, s in intentStates:
697 count += 1
698 main.log.info( "%-6s%-15s%-15s" %
699 ( str( count ), str( i ), str( s ) ) )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700700 leaders = main.ONOScli1.leaders()
701 try:
702 if leaders:
703 parsedLeaders = json.loads( leaders )
704 main.log.warn( json.dumps( parsedLeaders,
705 sort_keys=True,
706 indent=4,
707 separators=( ',', ': ' ) ) )
708 # check for all intent partitions
709 # check for election
710 topics = []
711 for i in range( 14 ):
712 topics.append( "intent-partition-" + str( i ) )
713 # FIXME: this should only be after we start the app
714 topics.append( "org.onosproject.election" )
715 main.log.debug( topics )
716 ONOStopics = [ j['topic'] for j in parsedLeaders ]
717 for topic in topics:
718 if topic not in ONOStopics:
719 main.log.error( "Error: " + topic +
720 " not in leaders" )
721 else:
722 main.log.error( "leaders() returned None" )
723 except ( ValueError, TypeError ):
724 main.log.exception( "Error parsing leaders" )
725 main.log.error( repr( leaders ) )
726 partitions = main.ONOScli1.partitions()
727 try:
728 if partitions :
729 parsedPartitions = json.loads( partitions )
730 main.log.warn( json.dumps( parsedPartitions,
731 sort_keys=True,
732 indent=4,
733 separators=( ',', ': ' ) ) )
734 # TODO check for a leader in all paritions
735 # TODO check for consistency among nodes
736 else:
737 main.log.error( "partitions() returned None" )
738 except ( ValueError, TypeError ):
739 main.log.exception( "Error parsing partitions" )
740 main.log.error( repr( partitions ) )
741 pendingMap = main.ONOScli1.pendingMap()
742 try:
743 if pendingMap :
744 parsedPending = json.loads( pendingMap )
745 main.log.warn( json.dumps( parsedPending,
746 sort_keys=True,
747 indent=4,
748 separators=( ',', ': ' ) ) )
749 # TODO check something here?
750 else:
751 main.log.error( "pendingMap() returned None" )
752 except ( ValueError, TypeError ):
753 main.log.exception( "Error parsing pending map" )
754 main.log.error( repr( pendingMap ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800755
Jon Hall6aec96b2015-01-19 14:49:31 -0800756 def CASE5( self, main ):
757 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800758 Reading state of ONOS
Jon Hall6aec96b2015-01-19 14:49:31 -0800759 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800760 import json
Jon Hall5cfd23c2015-03-19 11:40:57 -0700761 assert numControllers, "numControllers not defined"
762 assert main, "main not defined"
763 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -0800764 # assumes that sts is already in you PYTHONPATH
765 from sts.topology.teston_topology import TestONTopology
Jon Hall73cf9cc2014-11-20 22:28:38 -0800766
Jon Hall6aec96b2015-01-19 14:49:31 -0800767 main.log.report( "Setting up and gathering data for current state" )
768 main.case( "Setting up and gathering data for current state" )
769 # The general idea for this test case is to pull the state of
770 # ( intents,flows, topology,... ) from each ONOS node
Jon Hall5cfd23c2015-03-19 11:40:57 -0700771 # We can then compare them with each other and also with past states
Jon Hall73cf9cc2014-11-20 22:28:38 -0800772
Jon Halla9d26da2015-03-30 16:45:32 -0700773 main.step( "Check that each switch has a master" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800774 global mastershipState
Jon Halla9d26da2015-03-30 16:45:32 -0700775 mastershipState = '[]'
Jon Hall94fd0472014-12-08 11:52:42 -0800776
Jon Hall6aec96b2015-01-19 14:49:31 -0800777 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -0800778 rolesNotNull = main.ONOScli1.rolesNotNull()
Jon Hall6aec96b2015-01-19 14:49:31 -0800779 utilities.assert_equals(
780 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800781 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -0800782 onpass="Each device has a master",
783 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -0800784
Jon Hall8f89dda2015-01-22 16:03:33 -0800785 ONOS1Mastership = main.ONOScli1.roles()
Jon Hall6aec96b2015-01-19 14:49:31 -0800786 # TODO: Make this a meaningful check
Jon Hall8f89dda2015-01-22 16:03:33 -0800787 if "Error" in ONOS1Mastership or not ONOS1Mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -0800788 main.log.report( "Error in getting ONOS roles" )
789 main.log.warn(
790 "ONOS1 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800791 repr( ONOS1Mastership ) )
792 consistentMastership = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800793 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800794 mastershipState = ONOS1Mastership
795 consistentMastership = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800796
Jon Hall6aec96b2015-01-19 14:49:31 -0800797 main.step( "Get the intents from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800798 global intentState
799 intentState = []
800 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
801 intentCheck = main.FALSE
802 if "Error" in ONOS1Intents or not ONOS1Intents:
Jon Hall6aec96b2015-01-19 14:49:31 -0800803 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800804 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800805 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800806 intentCheck = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800807
Jon Hall6aec96b2015-01-19 14:49:31 -0800808 main.step( "Get the flows from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800809 global flowState
810 flowState = []
Jon Hall8f89dda2015-01-22 16:03:33 -0800811 flowCheck = main.FALSE
Jon Hall58c76b72015-02-23 11:09:24 -0800812 ONOS1Flows = main.ONOScli1.flows( jsonFormat=True )
Jon Hall8f89dda2015-01-22 16:03:33 -0800813 if "Error" in ONOS1Flows or not ONOS1Flows:
Jon Hall58c76b72015-02-23 11:09:24 -0800814 main.log.report( "Error in getting ONOS flows" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800815 main.log.warn( "ONOS1 flows repsponse: " + ONOS1Flows )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800816 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800817 # TODO: Do a better check, maybe compare flows on switches?
Jon Hall8f89dda2015-01-22 16:03:33 -0800818 flowState = ONOS1Flows
819 flowCheck = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800820
Jon Hall6aec96b2015-01-19 14:49:31 -0800821 main.step( "Get the OF Table entries" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800822 global flows
Jon Hall6aec96b2015-01-19 14:49:31 -0800823 flows = []
824 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800825 flows.append( main.Mininet2.getFlowTable( 1.3, "s" + str( i ) ) )
Jon Hall58c76b72015-02-23 11:09:24 -0800826 if flowCheck == main.FALSE:
827 for table in flows:
828 main.log.warn( table )
Jon Hall6aec96b2015-01-19 14:49:31 -0800829 # TODO: Compare switch flow tables with ONOS flow tables
Jon Hall73cf9cc2014-11-20 22:28:38 -0800830
Jon Hall6aec96b2015-01-19 14:49:31 -0800831 main.step( "Create TestONTopology object" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800832 ctrls = []
833 count = 1
834 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -0800835 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
836 temp = temp + ( "ONOS" + str( count ), )
837 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
838 temp = temp + \
839 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
840 ctrls.append( temp )
841 MNTopo = TestONTopology(
842 main.Mininet1,
843 ctrls ) # can also add Intent API info for intent operations
Jon Hall73cf9cc2014-11-20 22:28:38 -0800844
Jon Hall6aec96b2015-01-19 14:49:31 -0800845 main.step( "Collecting topology information from ONOS" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800846 devices = []
847 devices.append( main.ONOScli1.devices() )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800848 hosts = []
Jon Hall58c76b72015-02-23 11:09:24 -0800849 hosts.append( json.loads( main.ONOScli1.hosts() ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800850 ports = []
851 ports.append( main.ONOScli1.ports() )
852 links = []
853 links.append( main.ONOScli1.links() )
Jon Hall58c76b72015-02-23 11:09:24 -0800854 clusters = []
855 clusters.append( main.ONOScli1.clusters() )
856 ipResult = main.TRUE
857 for controller in range( 0, len( hosts ) ):
858 controllerStr = str( controller + 1 )
859 for host in hosts[ controller ]:
860 if host is None or host.get( 'ips', [] ) == []:
861 main.log.error(
862 "DEBUG:Error with host ips on controller" +
863 controllerStr + ": " + str( host ) )
864 ipResult = main.FALSE
865
866 # there should always only be one cluster
867 numClusters = len( json.loads( clusters[ 0 ] ) )
868 clusterResults = main.FALSE
869 if numClusters == 1:
870 clusterResults = main.TRUE
871 utilities.assert_equals(
872 expect=1,
873 actual=numClusters,
874 onpass="ONOS shows 1 SCC",
875 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800876
Jon Hall6aec96b2015-01-19 14:49:31 -0800877 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800878 devicesResults = main.TRUE
879 portsResults = main.TRUE
880 linksResults = main.TRUE
Jon Hall58c76b72015-02-23 11:09:24 -0800881 hostsResults = main.TRUE
Jon Hall8f89dda2015-01-22 16:03:33 -0800882 for controller in range( numControllers ):
883 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -0800884 if devices[ controller ] or "Error" not in devices[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -0800885 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -0800886 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -0800887 json.loads( devices[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800888 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800889 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800890 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -0800891 actual=currentDevicesResult,
892 onpass="ONOS" + controllerStr +
893 " Switches view is correct",
894 onfail="ONOS" + controllerStr +
895 " Switches view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800896
Jon Hall6aec96b2015-01-19 14:49:31 -0800897 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -0800898 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -0800899 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -0800900 json.loads( ports[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800901 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800902 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800903 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -0800904 actual=currentPortsResult,
905 onpass="ONOS" + controllerStr +
906 " ports view is correct",
907 onfail="ONOS" + controllerStr +
908 " ports view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800909
Jon Hall6aec96b2015-01-19 14:49:31 -0800910 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -0800911 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -0800912 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -0800913 json.loads( links[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800914 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800915 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800916 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -0800917 actual=currentLinksResult,
918 onpass="ONOS" + controllerStr +
919 " links view is correct",
920 onfail="ONOS" + controllerStr +
921 " links view is incorrect" )
922
923 if hosts[ controller ] or "Error" not in hosts[ controller ]:
924 currentHostsResult = main.Mininet1.compareHosts(
925 MNTopo, hosts[ controller ] )
926 else:
927 currentHostsResult = main.FALSE
928 utilities.assert_equals( expect=main.TRUE,
929 actual=currentHostsResult,
930 onpass="ONOS" + controllerStr +
931 " hosts exist in Mininet",
932 onfail="ONOS" + controllerStr +
933 " hosts don't match Mininet" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800934
Jon Hall8f89dda2015-01-22 16:03:33 -0800935 devicesResults = devicesResults and currentDevicesResult
936 portsResults = portsResults and currentPortsResult
937 linksResults = linksResults and currentLinksResult
Jon Hall58c76b72015-02-23 11:09:24 -0800938 hostsResults = hostsResults and currentHostsResult
Jon Hall73cf9cc2014-11-20 22:28:38 -0800939
Jon Hall58c76b72015-02-23 11:09:24 -0800940 topoResult = devicesResults and portsResults and linksResults\
941 and clusterResults and ipResult and hostsResults
Jon Hall8f89dda2015-01-22 16:03:33 -0800942 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
Jon Hall58c76b72015-02-23 11:09:24 -0800943 onpass="Topology Check Test successful",
944 onfail="Topology Check Test NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800945
Jon Hall8f89dda2015-01-22 16:03:33 -0800946 finalAssert = main.TRUE
947 finalAssert = finalAssert and topoResult and flowCheck \
Jon Hall58c76b72015-02-23 11:09:24 -0800948 and intentCheck and consistentMastership and rolesNotNull
Jon Hall8f89dda2015-01-22 16:03:33 -0800949 utilities.assert_equals( expect=main.TRUE, actual=finalAssert,
Jon Hall58c76b72015-02-23 11:09:24 -0800950 onpass="State check successful",
951 onfail="State check NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800952
Jon Hall6aec96b2015-01-19 14:49:31 -0800953 def CASE6( self, main ):
954 """
Jon Hallffb386d2014-11-21 13:43:38 -0800955 The Failure case.
Jon Hall6aec96b2015-01-19 14:49:31 -0800956 """
Jon Hallffb386d2014-11-21 13:43:38 -0800957 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -0700958 assert numControllers, "numControllers not defined"
959 assert main, "main not defined"
960 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall73cf9cc2014-11-20 22:28:38 -0800961
Jon Hall6aec96b2015-01-19 14:49:31 -0800962 main.log.report( "Restart ONOS node" )
963 main.log.case( "Restart ONOS node" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800964 main.ONOSbench.onosKill( ONOS1Ip )
Jon Hallffb386d2014-11-21 13:43:38 -0800965 start = time.time()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800966
Jon Hall6aec96b2015-01-19 14:49:31 -0800967 main.step( "Checking if ONOS is up yet" )
Jon Hallffb386d2014-11-21 13:43:38 -0800968 count = 0
Jon Hall94fd0472014-12-08 11:52:42 -0800969 while count < 10:
Jon Hall8f89dda2015-01-22 16:03:33 -0800970 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
971 if onos1Isup == main.TRUE:
Jon Hallffb386d2014-11-21 13:43:38 -0800972 elapsed = time.time() - start
973 break
974 else:
975 count = count + 1
Jon Hall73cf9cc2014-11-20 22:28:38 -0800976
Jon Hall8f89dda2015-01-22 16:03:33 -0800977 cliResult = main.ONOScli1.startOnosCli( ONOS1Ip )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800978
Jon Hall8f89dda2015-01-22 16:03:33 -0800979 caseResults = main.TRUE and onos1Isup and cliResult
980 utilities.assert_equals( expect=main.TRUE, actual=caseResults,
Jon Hall58c76b72015-02-23 11:09:24 -0800981 onpass="ONOS restart successful",
982 onfail="ONOS restart NOT successful" )
Jon Hallfebb1c72015-03-05 13:30:09 -0800983 if elapsed:
984 main.log.info( "ESTIMATE: ONOS took %s seconds to restart" %
985 str( elapsed ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800986 time.sleep( 5 )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800987
Jon Hall6aec96b2015-01-19 14:49:31 -0800988 def CASE7( self, main ):
989 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800990 Check state after ONOS failure
Jon Hall6aec96b2015-01-19 14:49:31 -0800991 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800992 import json
Jon Hall5cfd23c2015-03-19 11:40:57 -0700993 assert numControllers, "numControllers not defined"
994 assert main, "main not defined"
995 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -0800996 main.case( "Running ONOS Constant State Tests" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800997
Jon Hall6aec96b2015-01-19 14:49:31 -0800998 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -0800999 rolesNotNull = main.ONOScli1.rolesNotNull()
Jon Hall6aec96b2015-01-19 14:49:31 -08001000 utilities.assert_equals(
1001 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001002 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -08001003 onpass="Each device has a master",
1004 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -08001005
Jon Hall6aec96b2015-01-19 14:49:31 -08001006 main.step( "Check if switch roles are consistent across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001007 ONOS1Mastership = main.ONOScli1.roles()
Jon Hall6aec96b2015-01-19 14:49:31 -08001008 # FIXME: Refactor this whole case for single instance
Jon Hall8f89dda2015-01-22 16:03:33 -08001009 if "Error" in ONOS1Mastership or not ONOS1Mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -08001010 main.log.report( "Error in getting ONOS mastership" )
Jon Hall58c76b72015-02-23 11:09:24 -08001011 main.log.warn( "ONOS1 mastership response: " +
1012 repr( ONOS1Mastership ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001013 consistentMastership = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001014 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001015 consistentMastership = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001016 main.log.report(
1017 "Switch roles are consistent across all ONOS nodes" )
1018 utilities.assert_equals(
1019 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001020 actual=consistentMastership,
Jon Hall6aec96b2015-01-19 14:49:31 -08001021 onpass="Switch roles are consistent across all ONOS nodes",
1022 onfail="ONOS nodes have different views of switch roles" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001023
1024 description2 = "Compare switch roles from before failure"
Jon Hall6aec96b2015-01-19 14:49:31 -08001025 main.step( description2 )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001026
Jon Hall8f89dda2015-01-22 16:03:33 -08001027 currentJson = json.loads( ONOS1Mastership )
1028 oldJson = json.loads( mastershipState )
1029 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001030 for i in range( 1, 29 ):
1031 switchDPID = str(
Jon Hall58c76b72015-02-23 11:09:24 -08001032 main.Mininet1.getSwitchDPID( switch="s" + str( i ) ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001033
Jon Hall8f89dda2015-01-22 16:03:33 -08001034 current = [ switch[ 'master' ] for switch in currentJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001035 if switchDPID in switch[ 'id' ] ]
Jon Hall8f89dda2015-01-22 16:03:33 -08001036 old = [ switch[ 'master' ] for switch in oldJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001037 if switchDPID in switch[ 'id' ] ]
Jon Hall73cf9cc2014-11-20 22:28:38 -08001038 if current == old:
Jon Hall8f89dda2015-01-22 16:03:33 -08001039 mastershipCheck = mastershipCheck and main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001040 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001041 main.log.warn( "Mastership of switch %s changed" % switchDPID )
Jon Hall8f89dda2015-01-22 16:03:33 -08001042 mastershipCheck = main.FALSE
1043 if mastershipCheck == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001044 main.log.report( "Mastership of Switches was not changed" )
1045 utilities.assert_equals(
1046 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001047 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -08001048 onpass="Mastership of Switches was not changed",
1049 onfail="Mastership of some switches changed" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001050 mastershipCheck = mastershipCheck and consistentMastership
Jon Hall73cf9cc2014-11-20 22:28:38 -08001051
Jon Hall6aec96b2015-01-19 14:49:31 -08001052 main.step( "Get the intents and compare across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001053 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
1054 intentCheck = main.FALSE
1055 if "Error" in ONOS1Intents or not ONOS1Intents:
Jon Hall6aec96b2015-01-19 14:49:31 -08001056 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001057 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001058 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001059 intentCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001060 main.log.report( "Intents are consistent across all ONOS nodes" )
1061 utilities.assert_equals(
1062 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001063 actual=intentCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -08001064 onpass="Intents are consistent across all ONOS nodes",
1065 onfail="ONOS nodes have different views of intents" )
Jon Hall1b8f54a2015-02-04 13:24:20 -08001066 # Print the intent states
1067 intents = []
1068 intents.append( ONOS1Intents )
1069 intentStates = []
1070 for node in intents: # Iter through ONOS nodes
1071 nodeStates = []
Jon Hall58c76b72015-02-23 11:09:24 -08001072 # Iter through intents of a node
1073 for intent in json.loads( node ):
Jon Hall1b8f54a2015-02-04 13:24:20 -08001074 nodeStates.append( intent[ 'state' ] )
1075 intentStates.append( nodeStates )
1076 out = [ (i, nodeStates.count( i ) ) for i in set( nodeStates ) ]
1077 main.log.info( dict( out ) )
1078
Jon Hall58c76b72015-02-23 11:09:24 -08001079 # NOTE: Store has no durability, so intents are lost across system
1080 # restarts
Jon Hall6aec96b2015-01-19 14:49:31 -08001081 """
1082 main.step( "Compare current intents with intents before the failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001083 # NOTE: this requires case 5 to pass for intentState to be set.
Jon Hall6aec96b2015-01-19 14:49:31 -08001084 # maybe we should stop the test if that fails?
Jon Hall1b8f54a2015-02-04 13:24:20 -08001085 sameIntents = main.TRUE
1086 if intentState and intentState == ONOS1Intents:
Jon Hall8f89dda2015-01-22 16:03:33 -08001087 sameIntents = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001088 main.log.report( "Intents are consistent with before failure" )
1089 # TODO: possibly the states have changed? we may need to figure out
1090 # what the aceptable states are
Jon Hall73cf9cc2014-11-20 22:28:38 -08001091 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001092 try:
1093 main.log.warn( "ONOS1 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001094 print json.dumps( json.loads( ONOS1Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -08001095 sort_keys=True, indent=4,
1096 separators=( ',', ': ' ) )
Jon Hallfebb1c72015-03-05 13:30:09 -08001097 except Exception:
Jon Hall6aec96b2015-01-19 14:49:31 -08001098 pass
Jon Hall8f89dda2015-01-22 16:03:33 -08001099 sameIntents = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001100 utilities.assert_equals(
1101 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001102 actual=sameIntents,
Jon Hall6aec96b2015-01-19 14:49:31 -08001103 onpass="Intents are consistent with before failure",
1104 onfail="The Intents changed during failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001105 intentCheck = intentCheck and sameIntents
Jon Hall6aec96b2015-01-19 14:49:31 -08001106 """
1107 main.step( "Get the OF Table entries and compare to before " +
1108 "component failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001109 FlowTables = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001110 flows2 = []
1111 for i in range( 28 ):
1112 main.log.info( "Checking flow table on s" + str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001113 tmpFlows = main.Mininet2.getFlowTable( 1.3, "s" + str( i + 1 ) )
1114 flows2.append( tmpFlows )
1115 tempResult = main.Mininet2.flowComp(
Jon Hall6aec96b2015-01-19 14:49:31 -08001116 flow1=flows[ i ],
Jon Hall8f89dda2015-01-22 16:03:33 -08001117 flow2=tmpFlows )
1118 FlowTables = FlowTables and tempResult
1119 if FlowTables == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001120 main.log.info( "Differences in flow table for switch: s" +
1121 str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001122 if FlowTables == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001123 main.log.report( "No changes were found in the flow tables" )
1124 utilities.assert_equals(
1125 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001126 actual=FlowTables,
Jon Hall6aec96b2015-01-19 14:49:31 -08001127 onpass="No changes were found in the flow tables",
1128 onfail="Changes were found in the flow tables" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001129
Jon Hall6aec96b2015-01-19 14:49:31 -08001130 # Test of LeadershipElection
Jon Hall669173b2014-12-17 11:36:30 -08001131
Jon Hall8f89dda2015-01-22 16:03:33 -08001132 leader = ONOS1Ip
1133 leaderResult = main.TRUE
1134 for controller in range( 1, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001135 # loop through ONOScli handlers
1136 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001137 leaderN = node.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001138 # verify leader is ONOS1
1139 # NOTE even though we restarted ONOS, it is the only one so onos 1
1140 # must be leader
Jon Hall669173b2014-12-17 11:36:30 -08001141 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08001142 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001143 pass
1144 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001145 # error in response
1146 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001147 "electionTestLeader function, check the" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001148 " error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001149 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001150 elif leader != leaderN:
Jon Hall8f89dda2015-01-22 16:03:33 -08001151 leaderResult = main.FALSE
Jon Hall58c76b72015-02-23 11:09:24 -08001152 main.log.report( "ONOS" + str( controller ) + " sees " +
1153 str( leaderN ) +
1154 " as the leader of the election app. " +
1155 "Leader should be " + str( leader ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001156 if leaderResult:
1157 main.log.report( "Leadership election tests passed( consistent " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001158 "view of leader across listeners and a new " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001159 "leader was re-elected if applicable )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001160 utilities.assert_equals(
1161 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001162 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001163 onpass="Leadership election passed",
1164 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08001165
Jon Hall8f89dda2015-01-22 16:03:33 -08001166 result = ( mastershipCheck and intentCheck and FlowTables and
1167 rolesNotNull and leaderResult )
Jon Hall6aec96b2015-01-19 14:49:31 -08001168 result = int( result )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001169 if result == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001170 main.log.report( "Constant State Tests Passed" )
1171 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall58c76b72015-02-23 11:09:24 -08001172 onpass="Constant State Tests Passed",
1173 onfail="Constant state tests failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001174
Jon Hall6aec96b2015-01-19 14:49:31 -08001175 def CASE8( self, main ):
1176 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001177 Compare topo
Jon Hall6aec96b2015-01-19 14:49:31 -08001178 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001179 import sys
Jon Hall6aec96b2015-01-19 14:49:31 -08001180 # FIXME add this path to params
1181 sys.path.append( "/home/admin/sts" )
1182 # assumes that sts is already in you PYTHONPATH
1183 from sts.topology.teston_topology import TestONTopology
Jon Hall73cf9cc2014-11-20 22:28:38 -08001184 import json
1185 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001186 assert numControllers, "numControllers not defined"
1187 assert main, "main not defined"
1188 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall73cf9cc2014-11-20 22:28:38 -08001189
Jon Hall6aec96b2015-01-19 14:49:31 -08001190 description = "Compare ONOS Topology view to Mininet topology"
1191 main.case( description )
1192 main.log.report( description )
1193 main.step( "Create TestONTopology object" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001194 ctrls = []
Jon Halla9d26da2015-03-30 16:45:32 -07001195 node = main.ONOS1
1196 temp = ( node, node.name, node.ip_address, 6633 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001197 ctrls.append( temp )
Jon Halla9d26da2015-03-30 16:45:32 -07001198 MNTopo = TestONTopology( main.Mininet1, ctrls )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001199
Jon Hall6aec96b2015-01-19 14:49:31 -08001200 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001201 devicesResults = main.TRUE
1202 portsResults = main.TRUE
1203 linksResults = main.TRUE
Jon Hall58c76b72015-02-23 11:09:24 -08001204 hostsResults = main.TRUE
Jon Hall8f89dda2015-01-22 16:03:33 -08001205 topoResult = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001206 elapsed = 0
Jon Hallffb386d2014-11-21 13:43:38 -08001207 count = 0
Jon Hall6aec96b2015-01-19 14:49:31 -08001208 main.step( "Collecting topology information from ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001209 startTime = time.time()
Jon Hall58c76b72015-02-23 11:09:24 -08001210 # Give time for Gossip to work
Jon Hall8f89dda2015-01-22 16:03:33 -08001211 while topoResult == main.FALSE and elapsed < 60:
Jon Halla9d26da2015-03-30 16:45:32 -07001212 count += 1
Jon Hall94fd0472014-12-08 11:52:42 -08001213 if count > 1:
Jon Halla9d26da2015-03-30 16:45:32 -07001214 # TODO: Deprecate STS usage
Jon Hall58c76b72015-02-23 11:09:24 -08001215 MNTopo = TestONTopology( main.Mininet1, ctrls )
Jon Hall8f89dda2015-01-22 16:03:33 -08001216 cliStart = time.time()
Jon Hall94fd0472014-12-08 11:52:42 -08001217 devices = []
1218 devices.append( main.ONOScli1.devices() )
Jon Hall94fd0472014-12-08 11:52:42 -08001219 hosts = []
Jon Hall58c76b72015-02-23 11:09:24 -08001220 hosts.append( json.loads( main.ONOScli1.hosts() ) )
1221 ipResult = main.TRUE
1222 for controller in range( 0, len( hosts ) ):
1223 controllerStr = str( controller + 1 )
1224 for host in hosts[ controller ]:
1225 if host is None or host.get( 'ips', [] ) == []:
1226 main.log.error(
1227 "DEBUG:Error with host ips on controller" +
1228 controllerStr + ": " + str( host ) )
1229 ipResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001230 ports = []
1231 ports.append( main.ONOScli1.ports() )
1232 links = []
1233 links.append( main.ONOScli1.links() )
Jon Hall58c76b72015-02-23 11:09:24 -08001234 clusters = []
1235 clusters.append( main.ONOScli1.clusters() )
1236
Jon Hall8f89dda2015-01-22 16:03:33 -08001237 elapsed = time.time() - startTime
1238 cliTime = time.time() - cliStart
1239 print "CLI time: " + str( cliTime )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001240
Jon Hall8f89dda2015-01-22 16:03:33 -08001241 for controller in range( numControllers ):
1242 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001243 if devices[ controller ] or "Error" not in devices[
1244 controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001245 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -08001246 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001247 json.loads( devices[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001248 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001249 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001250 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001251 actual=currentDevicesResult,
1252 onpass="ONOS" + controllerStr +
1253 " Switches view is correct",
1254 onfail="ONOS" + controllerStr +
1255 " Switches view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001256
Jon Hall6aec96b2015-01-19 14:49:31 -08001257 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001258 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -08001259 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001260 json.loads( ports[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001261 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001262 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001263 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001264 actual=currentPortsResult,
1265 onpass="ONOS" + controllerStr +
1266 " ports view is correct",
1267 onfail="ONOS" + controllerStr +
1268 " ports view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001269
Jon Hall6aec96b2015-01-19 14:49:31 -08001270 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001271 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -08001272 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001273 json.loads( links[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001274 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001275 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001276 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001277 actual=currentLinksResult,
1278 onpass="ONOS" + controllerStr +
1279 " links view is correct",
1280 onfail="ONOS" + controllerStr +
1281 " links view is incorrect" )
1282
1283 if hosts[ controller ] or "Error" not in hosts[ controller ]:
1284 currentHostsResult = main.Mininet1.compareHosts(
1285 MNTopo, hosts[ controller ] )
1286 else:
1287 currentHostsResult = main.FALSE
1288 utilities.assert_equals( expect=main.TRUE,
1289 actual=currentHostsResult,
1290 onpass="ONOS" + controllerStr +
1291 " hosts exist in Mininet",
1292 onfail="ONOS" + controllerStr +
1293 " hosts don't match Mininet" )
1294
1295 devicesResults = devicesResults and currentDevicesResult
1296 portsResults = portsResults and currentPortsResult
1297 linksResults = linksResults and currentLinksResult
1298 hostsResults = hostsResults and currentHostsResult
1299
Jon Hall63604932015-02-26 17:09:50 -08001300 # "consistent" results don't make sense for single instance
Jon Hall58c76b72015-02-23 11:09:24 -08001301 # there should always only be one cluster
1302 numClusters = len( json.loads( clusters[ 0 ] ) )
1303 clusterResults = main.FALSE
1304 if numClusters == 1:
1305 clusterResults = main.TRUE
1306 utilities.assert_equals(
1307 expect=1,
1308 actual=numClusters,
1309 onpass="ONOS shows 1 SCC",
1310 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
1311
1312 topoResult = ( devicesResults and portsResults and linksResults
1313 and hostsResults and ipResult and clusterResults )
Jon Hall94fd0472014-12-08 11:52:42 -08001314
Jon Hall8f89dda2015-01-22 16:03:33 -08001315 topoResult = topoResult and int( count <= 2 )
1316 note = "note it takes about " + str( int( cliTime ) ) + \
1317 " seconds for the test to make all the cli calls to fetch " +\
1318 "the topology from each ONOS instance"
Jon Hall1b8f54a2015-02-04 13:24:20 -08001319 main.log.info(
Jon Hall8f89dda2015-01-22 16:03:33 -08001320 "Very crass estimate for topology discovery/convergence( " +
1321 str( note ) + " ): " + str( elapsed ) + " seconds, " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001322 str( count ) + " tries" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001323 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
Jon Hall58c76b72015-02-23 11:09:24 -08001324 onpass="Topology Check Test successful",
1325 onfail="Topology Check Test NOT successful" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001326 if topoResult == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001327 main.log.report( "ONOS topology view matches Mininet topology" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001328
Jon Hall6aec96b2015-01-19 14:49:31 -08001329 def CASE9( self, main ):
1330 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001331 Link s3-s28 down
Jon Hall6aec96b2015-01-19 14:49:31 -08001332 """
1333 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001334 assert numControllers, "numControllers not defined"
1335 assert main, "main not defined"
1336 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -08001337 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001338
Jon Hall8f89dda2015-01-22 16:03:33 -08001339 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001340
Jon Hall6aec96b2015-01-19 14:49:31 -08001341 description = "Turn off a link to ensure that Link Discovery " +\
Jon Hall58c76b72015-02-23 11:09:24 -08001342 "is working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001343 main.log.report( description )
1344 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001345
Jon Hall6aec96b2015-01-19 14:49:31 -08001346 main.step( "Kill Link between s3 and s28" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001347 LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" )
Jon Hall58c76b72015-02-23 11:09:24 -08001348 main.log.info( "Waiting " + str( linkSleep ) +
1349 " seconds for link down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001350 time.sleep( linkSleep )
1351 utilities.assert_equals( expect=main.TRUE, actual=LinkDown,
Jon Halla9d26da2015-03-30 16:45:32 -07001352 onpass="Link down successful",
Jon Hall58c76b72015-02-23 11:09:24 -08001353 onfail="Failed to bring link down" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001354 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -08001355
Jon Hall6aec96b2015-01-19 14:49:31 -08001356 def CASE10( self, main ):
1357 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001358 Link s3-s28 up
Jon Hall6aec96b2015-01-19 14:49:31 -08001359 """
1360 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001361 assert numControllers, "numControllers not defined"
1362 assert main, "main not defined"
1363 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -08001364 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001365
Jon Hall8f89dda2015-01-22 16:03:33 -08001366 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001367
Jon Hall6aec96b2015-01-19 14:49:31 -08001368 description = "Restore a link to ensure that Link Discovery is " + \
Jon Hall58c76b72015-02-23 11:09:24 -08001369 "working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001370 main.log.report( description )
1371 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001372
Jon Hall6aec96b2015-01-19 14:49:31 -08001373 main.step( "Bring link between s3 and s28 back up" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001374 LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" )
Jon Hall58c76b72015-02-23 11:09:24 -08001375 main.log.info( "Waiting " + str( linkSleep ) +
1376 " seconds for link up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001377 time.sleep( linkSleep )
1378 utilities.assert_equals( expect=main.TRUE, actual=LinkUp,
Jon Halla9d26da2015-03-30 16:45:32 -07001379 onpass="Link up successful",
Jon Hall58c76b72015-02-23 11:09:24 -08001380 onfail="Failed to bring link up" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001381 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -08001382
Jon Hall6aec96b2015-01-19 14:49:31 -08001383 def CASE11( self, main ):
1384 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001385 Switch Down
Jon Hall6aec96b2015-01-19 14:49:31 -08001386 """
1387 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001388 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001389 assert numControllers, "numControllers not defined"
1390 assert main, "main not defined"
1391 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall73cf9cc2014-11-20 22:28:38 -08001392
Jon Hall8f89dda2015-01-22 16:03:33 -08001393 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001394
1395 description = "Killing a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001396 main.log.report( description )
1397 main.case( description )
1398 switch = main.params[ 'kill' ][ 'switch' ]
1399 switchDPID = main.params[ 'kill' ][ 'dpid' ]
Jon Hall73cf9cc2014-11-20 22:28:38 -08001400
Jon Hall6aec96b2015-01-19 14:49:31 -08001401 # TODO: Make this switch parameterizable
1402 main.step( "Kill " + switch )
1403 main.log.report( "Deleting " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001404 main.Mininet1.delSwitch( switch )
1405 main.log.info( "Waiting " + str( switchSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001406 " seconds for switch down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001407 time.sleep( switchSleep )
1408 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001409 # Peek at the deleted switch
1410 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001411 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001412 if device and device[ 'available' ] is False:
Jon Hall94fd0472014-12-08 11:52:42 -08001413 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001414 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Halla9d26da2015-03-30 16:45:32 -07001415 onpass="Kill switch successful",
Jon Hall58c76b72015-02-23 11:09:24 -08001416 onfail="Failed to kill switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001417
Jon Hall6aec96b2015-01-19 14:49:31 -08001418 def CASE12( self, main ):
1419 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001420 Switch Up
Jon Hall6aec96b2015-01-19 14:49:31 -08001421 """
1422 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001423 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001424 assert numControllers, "numControllers not defined"
1425 assert main, "main not defined"
1426 assert utilities.assert_equals, "utilities.assert_equals not defined"
1427 assert ONOS1Port, "ONOS1Port not defined"
1428 assert ONOS2Port, "ONOS2Port not defined"
1429 assert ONOS3Port, "ONOS3Port not defined"
1430 assert ONOS4Port, "ONOS4Port not defined"
1431 assert ONOS5Port, "ONOS5Port not defined"
1432 assert ONOS6Port, "ONOS6Port not defined"
1433 assert ONOS7Port, "ONOS7Port not defined"
Jon Hall669173b2014-12-17 11:36:30 -08001434
Jon Hall8f89dda2015-01-22 16:03:33 -08001435 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall6aec96b2015-01-19 14:49:31 -08001436 switch = main.params[ 'kill' ][ 'switch' ]
1437 switchDPID = main.params[ 'kill' ][ 'dpid' ]
1438 links = main.params[ 'kill' ][ 'links' ].split()
Jon Hall73cf9cc2014-11-20 22:28:38 -08001439 description = "Adding a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001440 main.log.report( description )
1441 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001442
Jon Hall6aec96b2015-01-19 14:49:31 -08001443 main.step( "Add back " + switch )
1444 main.log.report( "Adding back " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001445 main.Mininet1.addSwitch( switch, dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001446 for peer in links:
Jon Hall8f89dda2015-01-22 16:03:33 -08001447 main.Mininet1.addLink( switch, peer )
1448 main.Mininet1.assignSwController( sw=switch.split( 's' )[ 1 ],
Jon Hall58c76b72015-02-23 11:09:24 -08001449 ip1=ONOS1Ip,
1450 port1=ONOS1Port )
1451 main.log.info( "Waiting " + str( switchSleep ) +
1452 " seconds for switch up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001453 time.sleep( switchSleep )
1454 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001455 # Peek at the deleted switch
1456 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001457 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001458 if device and device[ 'available' ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001459 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001460 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Halla9d26da2015-03-30 16:45:32 -07001461 onpass="add switch successful",
Jon Hall58c76b72015-02-23 11:09:24 -08001462 onfail="Failed to add switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001463
Jon Hall6aec96b2015-01-19 14:49:31 -08001464 def CASE13( self, main ):
1465 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001466 Clean up
Jon Hall6aec96b2015-01-19 14:49:31 -08001467 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001468 import os
1469 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001470 assert numControllers, "numControllers not defined"
1471 assert main, "main not defined"
1472 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -08001473 # printing colors to terminal
Jon Halla9d26da2015-03-30 16:45:32 -07001474 colors = { 'cyan': '\033[96m', 'purple': '\033[95m',
1475 'blue': '\033[94m', 'green': '\033[92m',
1476 'yellow': '\033[93m', 'red': '\033[91m', 'end': '\033[0m' }
Jon Hall73cf9cc2014-11-20 22:28:38 -08001477 description = "Test Cleanup"
Jon Hall6aec96b2015-01-19 14:49:31 -08001478 main.log.report( description )
1479 main.case( description )
1480 main.step( "Killing tcpdumps" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001481 main.Mininet2.stopTcpdump()
Jon Hall73cf9cc2014-11-20 22:28:38 -08001482
Jon Hall6aec96b2015-01-19 14:49:31 -08001483 main.step( "Copying MN pcap and ONOS log files to test station" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001484 testname = main.TEST
Jon Hall8f89dda2015-01-22 16:03:33 -08001485 teststationUser = main.params[ 'TESTONUSER' ]
1486 teststationIP = main.params[ 'TESTONIP' ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001487 # NOTE: MN Pcap file is being saved to ~/packet_captures
Jon Hall73cf9cc2014-11-20 22:28:38 -08001488 # scp this file as MN and TestON aren't necessarily the same vm
Jon Hall6aec96b2015-01-19 14:49:31 -08001489 # FIXME: scp
1490 # mn files
1491 # TODO: Load these from params
1492 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001493 logFolder = "/opt/onos/log/"
1494 logFiles = [ "karaf.log", "karaf.log.1" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001495 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001496 dstDir = "~/packet_captures/"
1497 for f in logFiles:
1498 main.ONOSbench.handle.sendline( "scp sdn@" + ONOS1Ip + ":" +
1499 logFolder + f + " " +
1500 teststationUser + "@" +
1501 teststationIP + ":" + dstDir +
Jon Hall6aec96b2015-01-19 14:49:31 -08001502 str( testname ) + "-ONOS1-" + f )
1503 main.ONOSbench.handle.expect( "\$" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001504
Jon Hall6aec96b2015-01-19 14:49:31 -08001505 # std*.log's
1506 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001507 logFolder = "/opt/onos/var/"
1508 logFiles = [ "stderr.log", "stdout.log" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001509 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001510 dstDir = "~/packet_captures/"
1511 for f in logFiles:
1512 main.ONOSbench.handle.sendline( "scp sdn@" + ONOS1Ip + ":" +
1513 logFolder + f + " " +
1514 teststationUser + "@" +
1515 teststationIP + ":" + dstDir +
Jon Hall6aec96b2015-01-19 14:49:31 -08001516 str( testname ) + "-ONOS1-" + f )
Jon Hall58c76b72015-02-23 11:09:24 -08001517 main.ONOSbench.handle.expect( "\$" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001518 # sleep so scp can finish
1519 time.sleep( 10 )
Jon Halla9d26da2015-03-30 16:45:32 -07001520
1521 main.step( "Stopping Mininet" )
Jon Hall58c76b72015-02-23 11:09:24 -08001522 main.Mininet1.stopNet()
Jon Halla9d26da2015-03-30 16:45:32 -07001523
1524 main.step( "Checking ONOS Logs for errors" )
1525 print colors[ 'purple' ] + "Checking logs for errors on ONOS1:" + \
1526 colors[ 'end' ]
1527 print main.ONOSbench.checkLogs( ONOS1Ip )
1528
Jon Hall6aec96b2015-01-19 14:49:31 -08001529 main.step( "Packing and rotating pcap archives" )
1530 os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001531
Jon Hall6aec96b2015-01-19 14:49:31 -08001532 # TODO: actually check something here
1533 utilities.assert_equals( expect=main.TRUE, actual=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001534 onpass="Test cleanup successful",
1535 onfail="Test cleanup NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001536
Jon Hall6aec96b2015-01-19 14:49:31 -08001537 def CASE14( self, main ):
1538 """
Jon Hall669173b2014-12-17 11:36:30 -08001539 start election app on all onos nodes
Jon Hall6aec96b2015-01-19 14:49:31 -08001540 """
Jon Hall5cfd23c2015-03-19 11:40:57 -07001541 assert numControllers, "numControllers not defined"
1542 assert main, "main not defined"
1543 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halla9d26da2015-03-30 16:45:32 -07001544
Jon Hall8f89dda2015-01-22 16:03:33 -08001545 leaderResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001546 main.log.info( "Install leadership election app" )
Jon Halla9d26da2015-03-30 16:45:32 -07001547 main.ONOScli1.activateApp( "org.onosproject.election" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001548 # check for leader
Jon Hall8f89dda2015-01-22 16:03:33 -08001549 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001550 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08001551 if leader == ONOS1Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08001552 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001553 pass
Jon Hall6aec96b2015-01-19 14:49:31 -08001554 elif leader is None:
1555 # No leader elected
1556 main.log.report( "No leader was elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001557 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001558 elif leader == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001559 # error in response
1560 # TODO: add check for "Command not found:" in the driver, this
1561 # means the app isn't loaded
Jon Hall8f89dda2015-01-22 16:03:33 -08001562 main.log.report( "Something is wrong with electionTestLeader" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001563 " function, check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001564 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001565 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001566 # error in response
1567 main.log.report(
Jon Hall8f89dda2015-01-22 16:03:33 -08001568 "Unexpected response from electionTestLeader function:'" +
1569 str( leader ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001570 "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001571 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001572
Jon Hall8f89dda2015-01-22 16:03:33 -08001573 if leaderResult:
Jon Hall6aec96b2015-01-19 14:49:31 -08001574 main.log.report( "Leadership election tests passed( consistent " +
1575 "view of leader across listeners and a leader " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001576 "was elected )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001577 utilities.assert_equals(
1578 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001579 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001580 onpass="Leadership election passed",
1581 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08001582
Jon Hall6aec96b2015-01-19 14:49:31 -08001583 def CASE15( self, main ):
1584 """
Jon Hall669173b2014-12-17 11:36:30 -08001585 Check that Leadership Election is still functional
Jon Hall6aec96b2015-01-19 14:49:31 -08001586 """
Jon Hall5cfd23c2015-03-19 11:40:57 -07001587 assert numControllers, "numControllers not defined"
1588 assert main, "main not defined"
1589 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall8f89dda2015-01-22 16:03:33 -08001590 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08001591 description = "Check that Leadership Election is still functional"
Jon Hall6aec96b2015-01-19 14:49:31 -08001592 main.log.report( description )
1593 main.case( description )
1594 main.step( "Find current leader and withdraw" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001595 leader = main.ONOScli1.electionTestLeader()
Jon Halla9d26da2015-03-30 16:45:32 -07001596 # do some sanity checking on leader before using it
Jon Hall8f89dda2015-01-22 16:03:33 -08001597 withdrawResult = main.FALSE
1598 if leader == ONOS1Ip:
1599 oldLeader = getattr( main, "ONOScli1" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001600 elif leader is None or leader == main.FALSE:
1601 main.log.report(
1602 "Leader for the election app should be an ONOS node," +
Jon Hall58c76b72015-02-23 11:09:24 -08001603 "instead got '" + str( leader ) + "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001604 leaderResult = main.FALSE
Jon Hall63604932015-02-26 17:09:50 -08001605 oldLeader = None
1606 else:
1607 main.log.error( "Leader election --- why am I HERE?!?")
1608 if oldLeader:
1609 withdrawResult = oldLeader.electionTestWithdraw()
Jon Hall6aec96b2015-01-19 14:49:31 -08001610 utilities.assert_equals(
1611 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001612 actual=withdrawResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001613 onpass="App was withdrawn from election",
1614 onfail="App was not withdrawn from election" )
Jon Hall669173b2014-12-17 11:36:30 -08001615
Jon Hall6aec96b2015-01-19 14:49:31 -08001616 main.step( "Make sure new leader is elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001617 leaderN = main.ONOScli1.electionTestLeader()
Jon Hall669173b2014-12-17 11:36:30 -08001618 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08001619 main.log.report( "ONOS still sees " + str( leaderN ) +
1620 " as leader after they withdrew" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001621 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001622 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001623 # error in response
1624 # TODO: add check for "Command not found:" in the driver, this
1625 # means the app isn't loaded
Jon Hall8f89dda2015-01-22 16:03:33 -08001626 main.log.report( "Something is wrong with electionTestLeader " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001627 "function, check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001628 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001629 elif leaderN is None:
1630 main.log.info(
1631 "There is no leader after the app withdrew from election" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001632 if leaderResult:
1633 main.log.report( "Leadership election tests passed( There is no " +
1634 "leader after the old leader resigned )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001635 utilities.assert_equals(
1636 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001637 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001638 onpass="Leadership election passed",
1639 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08001640
Jon Hall58c76b72015-02-23 11:09:24 -08001641 main.step( "Run for election on old leader( just so everyone " +
1642 "is in the hat )" )
Jon Hall63604932015-02-26 17:09:50 -08001643 if oldLeader:
1644 runResult = oldLeader.electionTestRun()
1645 else:
1646 runResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001647 utilities.assert_equals(
1648 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001649 actual=runResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001650 onpass="App re-ran for election",
1651 onfail="App failed to run for election" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001652 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001653 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08001654 if leader == ONOS1Ip:
1655 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08001656 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001657 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001658 # TODO: assert on run and withdraw results?
Jon Hall669173b2014-12-17 11:36:30 -08001659
Jon Hall6aec96b2015-01-19 14:49:31 -08001660 utilities.assert_equals(
1661 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001662 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001663 onpass="Leadership election passed",
1664 onfail="ONOS1's election app was not leader after it re-ran " +
1665 "for election" )