blob: d6e3daf182906d027b08dde7f48be1351e4fd7a4 [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
62 global ONOS2Ip
63 global ONOS2Port
64 global ONOS3Ip
65 global ONOS3Port
66 global ONOS4Ip
67 global ONOS4Port
68 global ONOS5Ip
69 global ONOS5Port
70 global ONOS6Ip
71 global ONOS6Port
72 global ONOS7Ip
73 global ONOS7Port
74 global numControllers
Jon Hall5cfd23c2015-03-19 11:40:57 -070075 numControllers = int( main.params[ 'num_controllers' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -080076
Jon Hall8f89dda2015-01-22 16:03:33 -080077 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
78 ONOS1Port = main.params[ 'CTRL' ][ 'port1' ]
79 ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
80 ONOS2Port = main.params[ 'CTRL' ][ 'port2' ]
81 ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ]
82 ONOS3Port = main.params[ 'CTRL' ][ 'port3' ]
83 ONOS4Ip = main.params[ 'CTRL' ][ 'ip4' ]
84 ONOS4Port = main.params[ 'CTRL' ][ 'port4' ]
85 ONOS5Ip = main.params[ 'CTRL' ][ 'ip5' ]
86 ONOS5Port = main.params[ 'CTRL' ][ 'port5' ]
87 ONOS6Ip = main.params[ 'CTRL' ][ 'ip6' ]
88 ONOS6Port = main.params[ 'CTRL' ][ 'port6' ]
89 ONOS7Ip = main.params[ 'CTRL' ][ 'ip7' ]
90 ONOS7Port = main.params[ 'CTRL' ][ 'port7' ]
Jon Hall73cf9cc2014-11-20 22:28:38 -080091
Jon Hall6aec96b2015-01-19 14:49:31 -080092 main.step( "Applying cell variable to environment" )
Jon Hall8f89dda2015-01-22 16:03:33 -080093 cellResult = main.ONOSbench.setCell( cellName )
94 verifyResult = main.ONOSbench.verifyCell()
Jon Hall73cf9cc2014-11-20 22:28:38 -080095
Jon Hall6aec96b2015-01-19 14:49:31 -080096 # FIXME:this is short term fix
97 main.log.report( "Removing raft logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -080098 main.ONOSbench.onosRemoveRaftLogs()
Jon Hall6aec96b2015-01-19 14:49:31 -080099 main.log.report( "Uninstalling ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800100 main.ONOSbench.onosUninstall( ONOS1Ip )
101 main.ONOSbench.onosUninstall( ONOS2Ip )
102 main.ONOSbench.onosUninstall( ONOS3Ip )
103 main.ONOSbench.onosUninstall( ONOS4Ip )
104 main.ONOSbench.onosUninstall( ONOS5Ip )
105 main.ONOSbench.onosUninstall( ONOS6Ip )
106 main.ONOSbench.onosUninstall( ONOS7Ip )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800107
Jon Hall8f89dda2015-01-22 16:03:33 -0800108 cleanInstallResult = main.TRUE
109 gitPullResult = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800110
Jon Hall97f31752015-02-04 12:01:04 -0800111 main.step( "Starting Mininet" )
112 main.Mininet1.startNet( )
113
Jon Hall6aec96b2015-01-19 14:49:31 -0800114 main.step( "Compiling the latest version of ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800115 if PULLCODE:
Jon Hall58c76b72015-02-23 11:09:24 -0800116 main.step( "Git checkout and pull " + gitBranch )
Jon Hall529a37f2015-01-28 10:02:00 -0800117 main.ONOSbench.gitCheckout( gitBranch )
Jon Hall8f89dda2015-01-22 16:03:33 -0800118 gitPullResult = main.ONOSbench.gitPull()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800119
Jon Hall6aec96b2015-01-19 14:49:31 -0800120 main.step( "Using mvn clean & install" )
Jon Hall529a37f2015-01-28 10:02:00 -0800121 cleanInstallResult = main.ONOSbench.cleanInstall()
122 else:
123 main.log.warn( "Did not pull new code so skipping mvn " +
124 "clean install" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800125 main.ONOSbench.getVersion( report=True )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800126
Jon Hall8f89dda2015-01-22 16:03:33 -0800127 cellResult = main.ONOSbench.setCell( "SingleHA" )
128 verifyResult = main.ONOSbench.verifyCell()
Jon Hall6aec96b2015-01-19 14:49:31 -0800129 main.step( "Creating ONOS package" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800130 packageResult = main.ONOSbench.onosPackage()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800131
Jon Hall6aec96b2015-01-19 14:49:31 -0800132 main.step( "Installing ONOS package" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800133 onos1InstallResult = main.ONOSbench.onosInstall( options="-f",
134 node=ONOS1Ip )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800135
Jon Hall6aec96b2015-01-19 14:49:31 -0800136 main.step( "Checking if ONOS is up yet" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800137 for i in range( 2 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800138 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
139 if onos1Isup:
Jon Hall94fd0472014-12-08 11:52:42 -0800140 break
Jon Hall8f89dda2015-01-22 16:03:33 -0800141 if not onos1Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800142 main.log.report( "ONOS1 didn't start!" )
Jon Hall94fd0472014-12-08 11:52:42 -0800143
Jon Hall8f89dda2015-01-22 16:03:33 -0800144 cliResult = main.ONOScli1.startOnosCli( ONOS1Ip )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800145
Jon Hall6aec96b2015-01-19 14:49:31 -0800146 main.step( "Start Packet Capture MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800147 main.Mininet2.startTcpdump(
Jon Hall6aec96b2015-01-19 14:49:31 -0800148 str( main.params[ 'MNtcpdump' ][ 'folder' ] ) + str( main.TEST )
149 + "-MN.pcap",
150 intf=main.params[ 'MNtcpdump' ][ 'intf' ],
151 port=main.params[ 'MNtcpdump' ][ 'port' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800152
Jon Hall8f89dda2015-01-22 16:03:33 -0800153 case1Result = ( cleanInstallResult and packageResult and
154 cellResult and verifyResult and onos1InstallResult
155 and onos1Isup and cliResult )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800156
Jon Hall8f89dda2015-01-22 16:03:33 -0800157 utilities.assert_equals( expect=main.TRUE, actual=case1Result,
Jon Hall58c76b72015-02-23 11:09:24 -0800158 onpass="Test startup successful",
159 onfail="Test startup NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800160
Jon Hall8f89dda2015-01-22 16:03:33 -0800161 if case1Result == main.FALSE:
Jon Hall73cf9cc2014-11-20 22:28:38 -0800162 main.cleanup()
163 main.exit()
164
Jon Hall6aec96b2015-01-19 14:49:31 -0800165 def CASE2( self, main ):
166 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800167 Assign mastership to controllers
Jon Hall6aec96b2015-01-19 14:49:31 -0800168 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800169 import re
Jon Hall5cfd23c2015-03-19 11:40:57 -0700170 assert numControllers, "numControllers not defined"
171 assert main, "main not defined"
172 assert utilities.assert_equals, "utilities.assert_equals not defined"
173 assert ONOS1Port, "ONOS1Port not defined"
174 assert ONOS2Port, "ONOS2Port not defined"
175 assert ONOS3Port, "ONOS3Port not defined"
176 assert ONOS4Port, "ONOS4Port not defined"
177 assert ONOS5Port, "ONOS5Port not defined"
178 assert ONOS6Port, "ONOS6Port not defined"
179 assert ONOS7Port, "ONOS7Port not defined"
Jon Hall73cf9cc2014-11-20 22:28:38 -0800180
Jon Hall6aec96b2015-01-19 14:49:31 -0800181 main.log.report( "Assigning switches to controllers" )
182 main.case( "Assigning Controllers" )
183 main.step( "Assign switches to controllers" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800184
Jon Hall6aec96b2015-01-19 14:49:31 -0800185 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800186 main.Mininet1.assignSwController(
Jon Hall6aec96b2015-01-19 14:49:31 -0800187 sw=str( i ),
Jon Hall8f89dda2015-01-22 16:03:33 -0800188 ip1=ONOS1Ip, port1=ONOS1Port )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800189
Jon Hall8f89dda2015-01-22 16:03:33 -0800190 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800191 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800192 response = main.Mininet1.getSwController( "s" + str( i ) )
Jon Hallffb386d2014-11-21 13:43:38 -0800193 try:
Jon Hall6aec96b2015-01-19 14:49:31 -0800194 main.log.info( str( response ) )
Jon Hallfebb1c72015-03-05 13:30:09 -0800195 except Exception:
Jon Hall6aec96b2015-01-19 14:49:31 -0800196 main.log.info( repr( response ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800197 if re.search( "tcp:" + ONOS1Ip, response ):
198 mastershipCheck = mastershipCheck and main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800199 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800200 mastershipCheck = main.FALSE
201 if mastershipCheck == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800202 main.log.report( "Switch mastership assigned correctly" )
203 utilities.assert_equals(
204 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800205 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800206 onpass="Switch mastership assigned correctly",
207 onfail="Switches not assigned correctly to controllers" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800208
Jon Hall6aec96b2015-01-19 14:49:31 -0800209 def CASE3( self, main ):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800210 """
211 Assign intents
Jon Hall73cf9cc2014-11-20 22:28:38 -0800212 """
213 import time
Jon Hallfebb1c72015-03-05 13:30:09 -0800214 import json
Jon Hall5cfd23c2015-03-19 11:40:57 -0700215 assert numControllers, "numControllers not defined"
216 assert main, "main not defined"
217 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall73cf9cc2014-11-20 22:28:38 -0800218 # FIXME: we must reinstall intents until we have a persistant
219 # datastore!
Jon Hall6aec96b2015-01-19 14:49:31 -0800220 main.log.report( "Adding host intents" )
221 main.case( "Adding host Intents" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800222
Jon Hall8f89dda2015-01-22 16:03:33 -0800223 main.step( "Discovering Hosts( Via pingall for now )" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800224 # FIXME: Once we have a host discovery mechanism, use that instead
Jon Hall73cf9cc2014-11-20 22:28:38 -0800225
Jon Hall6aec96b2015-01-19 14:49:31 -0800226 # install onos-app-fwd
227 main.log.info( "Install reactive forwarding app" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800228 main.ONOScli1.featureInstall( "onos-app-fwd" )
Jon Hall94fd0472014-12-08 11:52:42 -0800229
Jon Hall6aec96b2015-01-19 14:49:31 -0800230 # REACTIVE FWD test
Jon Hall8f89dda2015-01-22 16:03:33 -0800231 pingResult = main.FALSE
Jon Hall5cfd23c2015-03-19 11:40:57 -0700232 for i in range(2): # Retry if pingall fails first time
233 time1 = time.time()
234 pingResult = main.Mininet1.pingall()
235 utilities.assert_equals(
236 expect=main.TRUE,
237 actual=pingResult,
238 onpass="Reactive Pingall test passed",
239 onfail="Reactive Pingall failed, one or more ping pairs failed" )
240 time2 = time.time()
241 main.log.info( "Time for pingall: %2f seconds" % ( time2 - time1 ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800242
Jon Hall6aec96b2015-01-19 14:49:31 -0800243 # uninstall onos-app-fwd
244 main.log.info( "Uninstall reactive forwarding app" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800245 main.ONOScli1.featureUninstall( "onos-app-fwd" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800246 # timeout for fwd flows
247 time.sleep( 10 )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800248
Jon Hall6aec96b2015-01-19 14:49:31 -0800249 main.step( "Add host intents" )
Jon Hall58c76b72015-02-23 11:09:24 -0800250 intentIds = []
Jon Hall6aec96b2015-01-19 14:49:31 -0800251 # TODO: move the host numbers to params
Jon Hall58c76b72015-02-23 11:09:24 -0800252 # Maybe look at all the paths we ping?
Jon Hall8f89dda2015-01-22 16:03:33 -0800253 intentAddResult = True
Jon Hall58c76b72015-02-23 11:09:24 -0800254 hostResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800255 for i in range( 8, 18 ):
256 main.log.info( "Adding host intent between h" + str( i ) +
257 " and h" + str( i + 10 ) )
258 host1 = "00:00:00:00:00:" + \
259 str( hex( i )[ 2: ] ).zfill( 2 ).upper()
260 host2 = "00:00:00:00:00:" + \
261 str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper()
Jon Hall1b8f54a2015-02-04 13:24:20 -0800262 # NOTE: getHost can return None
263 host1Dict = main.ONOScli1.getHost( host1 )
264 host2Dict = main.ONOScli1.getHost( host2 )
265 host1Id = None
266 host2Id = None
267 if host1Dict and host2Dict:
268 host1Id = host1Dict.get( 'id', None )
269 host2Id = host2Dict.get( 'id', None )
Jon Hall8f89dda2015-01-22 16:03:33 -0800270 if host1Id and host2Id:
Jon Hall58c76b72015-02-23 11:09:24 -0800271 tmpId = main.ONOScli1.addHostIntent(
Jon Hall8f89dda2015-01-22 16:03:33 -0800272 host1Id,
273 host2Id )
Jon Hall63604932015-02-26 17:09:50 -0800274 if tmpId:
275 main.log.info( "Added intent with id: " + tmpId )
276 intentIds.append( tmpId )
277 else:
278 main.log.error( "addHostIntent reutrned None" )
Jon Hall669173b2014-12-17 11:36:30 -0800279 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800280 main.log.error( "Error, getHost() failed" )
Jon Hall1b8f54a2015-02-04 13:24:20 -0800281 main.log.warn( json.dumps( json.loads( main.ONOScli1.hosts() ),
282 sort_keys=True,
283 indent=4,
284 separators=( ',', ': ' ) ) )
Jon Hall58c76b72015-02-23 11:09:24 -0800285 hostResult = main.FALSE
286 onosIds = main.ONOScli1.getAllIntentsId()
287 main.log.info( "Submitted intents: " + str( intentIds ) )
288 main.log.info( "Intents in ONOS: " + str( onosIds ) )
289 for intent in intentIds:
290 if intent in onosIds:
291 pass # intent submitted is still in onos
292 else:
293 intentAddResult = False
Jon Hall1b8f54a2015-02-04 13:24:20 -0800294 # Print the intent states
Jon Hall58c76b72015-02-23 11:09:24 -0800295 intents = main.ONOScli1.intents()
Jon Hall1b8f54a2015-02-04 13:24:20 -0800296 intentStates = []
Jon Hall63604932015-02-26 17:09:50 -0800297 installedCheck = True
Jon Hall58c76b72015-02-23 11:09:24 -0800298 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
299 count = 0
Jon Hall5cfd23c2015-03-19 11:40:57 -0700300 try:
301 for intent in json.loads( intents ):
302 state = intent.get( 'state', None )
303 if "INSTALLED" not in state:
304 installedCheck = False
305 intentId = intent.get( 'id', None )
306 intentStates.append( ( intentId, state ) )
307 except ( ValueError, TypeError ):
308 main.log.exception( "Error parsing intents" )
Jon Hall58c76b72015-02-23 11:09:24 -0800309 # add submitted intents not in the store
310 tmplist = [ i for i, s in intentStates ]
311 missingIntents = False
312 for i in intentIds:
313 if i not in tmplist:
314 intentStates.append( ( i, " - " ) )
315 missingIntents = True
316 intentStates.sort()
317 for i, s in intentStates:
318 count += 1
319 main.log.info( "%-6s%-15s%-15s" %
320 ( str( count ), str( i ), str( s ) ) )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700321 leaders = main.ONOScli1.leaders()
322 try:
323 if leaders:
324 parsedLeaders = json.loads( leaders )
325 main.log.warn( json.dumps( parsedLeaders,
326 sort_keys=True,
327 indent=4,
328 separators=( ',', ': ' ) ) )
329 # check for all intent partitions
330 # check for election
331 topics = []
332 for i in range( 14 ):
333 topics.append( "intent-partition-" + str( i ) )
334 # FIXME: this should only be after we start the app
335 topics.append( "org.onosproject.election" )
336 main.log.debug( topics )
337 ONOStopics = [ j['topic'] for j in parsedLeaders ]
338 for topic in topics:
339 if topic not in ONOStopics:
340 main.log.error( "Error: " + topic +
341 " not in leaders" )
342 else:
343 main.log.error( "leaders() returned None" )
344 except ( ValueError, TypeError ):
345 main.log.exception( "Error parsing leaders" )
346 main.log.error( repr( leaders ) )
347 partitions = main.ONOScli1.partitions()
348 try:
349 if partitions :
350 parsedPartitions = json.loads( partitions )
351 main.log.warn( json.dumps( parsedPartitions,
352 sort_keys=True,
353 indent=4,
354 separators=( ',', ': ' ) ) )
355 # TODO check for a leader in all paritions
356 # TODO check for consistency among nodes
357 else:
358 main.log.error( "partitions() returned None" )
359 except ( ValueError, TypeError ):
360 main.log.exception( "Error parsing partitions" )
361 main.log.error( repr( partitions ) )
Jon Hall63604932015-02-26 17:09:50 -0800362 pendingMap = main.ONOScli1.pendingMap()
Jon Hall5cfd23c2015-03-19 11:40:57 -0700363 try:
364 if pendingMap :
365 parsedPending = json.loads( pendingMap )
366 main.log.warn( json.dumps( parsedPending,
367 sort_keys=True,
368 indent=4,
369 separators=( ',', ': ' ) ) )
370 # TODO check something here?
371 else:
372 main.log.error( "pendingMap() returned None" )
373 except ( ValueError, TypeError ):
374 main.log.exception( "Error parsing pending map" )
375 main.log.error( repr( pendingMap ) )
376
Jon Hall58c76b72015-02-23 11:09:24 -0800377 intentAddResult = bool( pingResult and hostResult and intentAddResult
Jon Hall63604932015-02-26 17:09:50 -0800378 and not missingIntents and installedCheck )
Jon Hall6aec96b2015-01-19 14:49:31 -0800379 utilities.assert_equals(
380 expect=True,
Jon Hall8f89dda2015-01-22 16:03:33 -0800381 actual=intentAddResult,
Jon Hall529a37f2015-01-28 10:02:00 -0800382 onpass="Pushed host intents to ONOS",
383 onfail="Error in pushing host intents to ONOS" )
Jon Hall58c76b72015-02-23 11:09:24 -0800384
Jon Hall63604932015-02-26 17:09:50 -0800385 if not intentAddResult or "key" in pendingMap:
Jon Hall58c76b72015-02-23 11:09:24 -0800386 import time
Jon Hall63604932015-02-26 17:09:50 -0800387 installedCheck = True
Jon Hall58c76b72015-02-23 11:09:24 -0800388 main.log.info( "Sleeping 60 seconds to see if intents are found" )
389 time.sleep( 60 )
390 onosIds = main.ONOScli1.getAllIntentsId()
391 main.log.info( "Submitted intents: " + str( intentIds ) )
392 main.log.info( "Intents in ONOS: " + str( onosIds ) )
393 # Print the intent states
394 intents = main.ONOScli1.intents()
395 intentStates = []
396 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
397 count = 0
Jon Hall5cfd23c2015-03-19 11:40:57 -0700398 try:
399 for intent in json.loads( intents ):
400 # Iter through intents of a node
401 state = intent.get( 'state', None )
402 if "INSTALLED" not in state:
403 installedCheck = False
404 intentId = intent.get( 'id', None )
405 intentStates.append( ( intentId, state ) )
406 except ( ValueError, TypeError ):
407 main.log.exception( "Error parsing intents" )
Jon Hall58c76b72015-02-23 11:09:24 -0800408 # add submitted intents not in the store
409 tmplist = [ i for i, s in intentStates ]
410 for i in intentIds:
411 if i not in tmplist:
412 intentStates.append( ( i, " - " ) )
413 intentStates.sort()
414 for i, s in intentStates:
415 count += 1
416 main.log.info( "%-6s%-15s%-15s" %
417 ( str( count ), str( i ), str( s ) ) )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700418 leaders = main.ONOScli1.leaders()
419 try:
420 if leaders:
421 parsedLeaders = json.loads( leaders )
422 main.log.warn( json.dumps( parsedLeaders,
423 sort_keys=True,
424 indent=4,
425 separators=( ',', ': ' ) ) )
426 # check for all intent partitions
427 # check for election
428 topics = []
429 for i in range( 14 ):
430 topics.append( "intent-partition-" + str( i ) )
431 # FIXME: this should only be after we start the app
432 topics.append( "org.onosproject.election" )
433 main.log.debug( topics )
434 ONOStopics = [ j['topic'] for j in parsedLeaders ]
435 for topic in topics:
436 if topic not in ONOStopics:
437 main.log.error( "Error: " + topic +
438 " not in leaders" )
439 else:
440 main.log.error( "leaders() returned None" )
441 except ( ValueError, TypeError ):
442 main.log.exception( "Error parsing leaders" )
443 main.log.error( repr( leaders ) )
444 partitions = main.ONOScli1.partitions()
445 try:
446 if partitions :
447 parsedPartitions = json.loads( partitions )
448 main.log.warn( json.dumps( parsedPartitions,
449 sort_keys=True,
450 indent=4,
451 separators=( ',', ': ' ) ) )
452 # TODO check for a leader in all paritions
453 # TODO check for consistency among nodes
454 else:
455 main.log.error( "partitions() returned None" )
456 except ( ValueError, TypeError ):
457 main.log.exception( "Error parsing partitions" )
458 main.log.error( repr( partitions ) )
459 pendingMap = main.ONOScli1.pendingMap()
460 try:
461 if pendingMap :
462 parsedPending = json.loads( pendingMap )
463 main.log.warn( json.dumps( parsedPending,
464 sort_keys=True,
465 indent=4,
466 separators=( ',', ': ' ) ) )
467 # TODO check something here?
468 else:
469 main.log.error( "pendingMap() returned None" )
470 except ( ValueError, TypeError ):
471 main.log.exception( "Error parsing pending map" )
472 main.log.error( repr( pendingMap ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800473
Jon Hall6aec96b2015-01-19 14:49:31 -0800474 def CASE4( self, main ):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800475 """
476 Ping across added host intents
477 """
Jon Hallfebb1c72015-03-05 13:30:09 -0800478 import json
Jon Hall5cfd23c2015-03-19 11:40:57 -0700479 assert numControllers, "numControllers not defined"
480 assert main, "main not defined"
481 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall73cf9cc2014-11-20 22:28:38 -0800482 description = " Ping across added host intents"
Jon Hall6aec96b2015-01-19 14:49:31 -0800483 main.log.report( description )
484 main.case( description )
Jon Hall8f89dda2015-01-22 16:03:33 -0800485 PingResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800486 for i in range( 8, 18 ):
Jon Hall58c76b72015-02-23 11:09:24 -0800487 ping = main.Mininet1.pingHost( src="h" + str( i ),
488 target="h" + str( i + 10 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800489 PingResult = PingResult and ping
Jon Hall6aec96b2015-01-19 14:49:31 -0800490 if ping == main.FALSE:
491 main.log.warn( "Ping failed between h" + str( i ) +
492 " and h" + str( i + 10 ) )
493 elif ping == main.TRUE:
494 main.log.info( "Ping test passed!" )
Jon Hall21270ac2015-02-16 17:59:55 -0800495 # Don't set PingResult or you'd override failures
Jon Hall8f89dda2015-01-22 16:03:33 -0800496 if PingResult == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800497 main.log.report(
498 "Intents have not been installed correctly, pings failed." )
Jon Hall58c76b72015-02-23 11:09:24 -0800499 # TODO: pretty print
Jon Hall5cfd23c2015-03-19 11:40:57 -0700500 main.log.warn( "ONOS1 intents: " )
501 try:
502 tmpIntents = main.ONOScli1.intents()
503 main.log.warn( json.dumps( json.loads( tmpIntents ),
504 sort_keys=True,
505 indent=4,
506 separators=( ',', ': ' ) ) )
507 except ( ValueError, TypeError ):
508 main.log.warn( repr( tmpIntents ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800509 if PingResult == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800510 main.log.report(
511 "Intents have been installed correctly and verified by pings" )
512 utilities.assert_equals(
513 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800514 actual=PingResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800515 onpass="Intents have been installed correctly and pings work",
516 onfail="Intents have not been installed correctly, pings failed." )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800517
Jon Hall63604932015-02-26 17:09:50 -0800518 installedCheck = True
Jon Hall58c76b72015-02-23 11:09:24 -0800519 if PingResult is not main.TRUE:
520 # Print the intent states
521 intents = main.ONOScli1.intents()
522 intentStates = []
523 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
524 count = 0
525 # Iter through intents of a node
Jon Hall5cfd23c2015-03-19 11:40:57 -0700526 try:
527 for intent in json.loads( intents ):
528 state = intent.get( 'state', None )
529 if "INSTALLED" not in state:
530 installedCheck = False
531 intentId = intent.get( 'id', None )
532 intentStates.append( ( intentId, state ) )
533 except ( ValueError, TypeError ):
534 main.log.exception( "Error parsing intents." )
Jon Hall58c76b72015-02-23 11:09:24 -0800535 intentStates.sort()
536 for i, s in intentStates:
537 count += 1
538 main.log.info( "%-6s%-15s%-15s" %
539 ( str( count ), str( i ), str( s ) ) )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700540 leaders = main.ONOScli1.leaders()
541 try:
542 if leaders:
543 parsedLeaders = json.loads( leaders )
544 main.log.warn( json.dumps( parsedLeaders,
545 sort_keys=True,
546 indent=4,
547 separators=( ',', ': ' ) ) )
548 # check for all intent partitions
549 # check for election
550 topics = []
551 for i in range( 14 ):
552 topics.append( "intent-partition-" + str( i ) )
553 # FIXME: this should only be after we start the app
554 topics.append( "org.onosproject.election" )
555 main.log.debug( topics )
556 ONOStopics = [ j['topic'] for j in parsedLeaders ]
557 for topic in topics:
558 if topic not in ONOStopics:
559 main.log.error( "Error: " + topic +
560 " not in leaders" )
561 else:
562 main.log.error( "leaders() returned None" )
563 except ( ValueError, TypeError ):
564 main.log.exception( "Error parsing leaders" )
565 main.log.error( repr( leaders ) )
566 partitions = main.ONOScli1.partitions()
567 try:
568 if partitions :
569 parsedPartitions = json.loads( partitions )
570 main.log.warn( json.dumps( parsedPartitions,
571 sort_keys=True,
572 indent=4,
573 separators=( ',', ': ' ) ) )
574 # TODO check for a leader in all paritions
575 # TODO check for consistency among nodes
576 else:
577 main.log.error( "partitions() returned None" )
578 except ( ValueError, TypeError ):
579 main.log.exception( "Error parsing partitions" )
580 main.log.error( repr( partitions ) )
581 pendingMap = main.ONOScli1.pendingMap()
582 try:
583 if pendingMap :
584 parsedPending = json.loads( pendingMap )
585 main.log.warn( json.dumps( parsedPending,
586 sort_keys=True,
587 indent=4,
588 separators=( ',', ': ' ) ) )
589 # TODO check something here?
590 else:
591 main.log.error( "pendingMap() returned None" )
592 except ( ValueError, TypeError ):
593 main.log.exception( "Error parsing pending map" )
594 main.log.error( repr( pendingMap ) )
595
Jon Hall63604932015-02-26 17:09:50 -0800596 if not installedCheck:
Jon Hall5cfd23c2015-03-19 11:40:57 -0700597 main.log.info( "Waiting 60 seconds to see if the state of " +
598 "intents change" )
Jon Hall63604932015-02-26 17:09:50 -0800599 time.sleep( 60 )
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 Hall63604932015-02-26 17:09:50 -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 ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800675
Jon Hall6aec96b2015-01-19 14:49:31 -0800676 def CASE5( self, main ):
677 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800678 Reading state of ONOS
Jon Hall6aec96b2015-01-19 14:49:31 -0800679 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800680 import json
Jon Hall5cfd23c2015-03-19 11:40:57 -0700681 import time
682 assert numControllers, "numControllers not defined"
683 assert main, "main not defined"
684 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -0800685 # assumes that sts is already in you PYTHONPATH
686 from sts.topology.teston_topology import TestONTopology
Jon Hall73cf9cc2014-11-20 22:28:38 -0800687
Jon Hall6aec96b2015-01-19 14:49:31 -0800688 main.log.report( "Setting up and gathering data for current state" )
689 main.case( "Setting up and gathering data for current state" )
690 # The general idea for this test case is to pull the state of
691 # ( intents,flows, topology,... ) from each ONOS node
Jon Hall5cfd23c2015-03-19 11:40:57 -0700692 # We can then compare them with each other and also with past states
Jon Hall73cf9cc2014-11-20 22:28:38 -0800693
Jon Hall6aec96b2015-01-19 14:49:31 -0800694 main.step( "Get the Mastership of each switch from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800695 global mastershipState
696 mastershipState = []
Jon Hall94fd0472014-12-08 11:52:42 -0800697
Jon Hall6aec96b2015-01-19 14:49:31 -0800698 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -0800699 rolesNotNull = main.ONOScli1.rolesNotNull()
Jon Hall6aec96b2015-01-19 14:49:31 -0800700 utilities.assert_equals(
701 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800702 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -0800703 onpass="Each device has a master",
704 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -0800705
Jon Hall8f89dda2015-01-22 16:03:33 -0800706 ONOS1Mastership = main.ONOScli1.roles()
Jon Hall6aec96b2015-01-19 14:49:31 -0800707 # TODO: Make this a meaningful check
Jon Hall8f89dda2015-01-22 16:03:33 -0800708 if "Error" in ONOS1Mastership or not ONOS1Mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -0800709 main.log.report( "Error in getting ONOS roles" )
710 main.log.warn(
711 "ONOS1 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800712 repr( ONOS1Mastership ) )
713 consistentMastership = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800714 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800715 mastershipState = ONOS1Mastership
716 consistentMastership = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800717
Jon Hall6aec96b2015-01-19 14:49:31 -0800718 main.step( "Get the intents from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800719 global intentState
720 intentState = []
721 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
722 intentCheck = main.FALSE
723 if "Error" in ONOS1Intents or not ONOS1Intents:
Jon Hall6aec96b2015-01-19 14:49:31 -0800724 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800725 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800726 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800727 intentCheck = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800728
Jon Hall6aec96b2015-01-19 14:49:31 -0800729 main.step( "Get the flows from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800730 global flowState
731 flowState = []
Jon Hall8f89dda2015-01-22 16:03:33 -0800732 flowCheck = main.FALSE
Jon Hall58c76b72015-02-23 11:09:24 -0800733 ONOS1Flows = main.ONOScli1.flows( jsonFormat=True )
Jon Hall8f89dda2015-01-22 16:03:33 -0800734 if "Error" in ONOS1Flows or not ONOS1Flows:
Jon Hall58c76b72015-02-23 11:09:24 -0800735 main.log.report( "Error in getting ONOS flows" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800736 main.log.warn( "ONOS1 flows repsponse: " + ONOS1Flows )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800737 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800738 # TODO: Do a better check, maybe compare flows on switches?
Jon Hall8f89dda2015-01-22 16:03:33 -0800739 flowState = ONOS1Flows
740 flowCheck = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800741
Jon Hall6aec96b2015-01-19 14:49:31 -0800742 main.step( "Get the OF Table entries" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800743 global flows
Jon Hall6aec96b2015-01-19 14:49:31 -0800744 flows = []
745 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800746 flows.append( main.Mininet2.getFlowTable( 1.3, "s" + str( i ) ) )
Jon Hall58c76b72015-02-23 11:09:24 -0800747 if flowCheck == main.FALSE:
748 for table in flows:
749 main.log.warn( table )
Jon Hall6aec96b2015-01-19 14:49:31 -0800750 # TODO: Compare switch flow tables with ONOS flow tables
Jon Hall73cf9cc2014-11-20 22:28:38 -0800751
Jon Hall6aec96b2015-01-19 14:49:31 -0800752 main.step( "Create TestONTopology object" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800753 ctrls = []
754 count = 1
755 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -0800756 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
757 temp = temp + ( "ONOS" + str( count ), )
758 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
759 temp = temp + \
760 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
761 ctrls.append( temp )
762 MNTopo = TestONTopology(
763 main.Mininet1,
764 ctrls ) # can also add Intent API info for intent operations
Jon Hall73cf9cc2014-11-20 22:28:38 -0800765
Jon Hall6aec96b2015-01-19 14:49:31 -0800766 main.step( "Collecting topology information from ONOS" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800767 devices = []
768 devices.append( main.ONOScli1.devices() )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800769 hosts = []
Jon Hall58c76b72015-02-23 11:09:24 -0800770 hosts.append( json.loads( main.ONOScli1.hosts() ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800771 ports = []
772 ports.append( main.ONOScli1.ports() )
773 links = []
774 links.append( main.ONOScli1.links() )
Jon Hall58c76b72015-02-23 11:09:24 -0800775 clusters = []
776 clusters.append( main.ONOScli1.clusters() )
777 ipResult = main.TRUE
778 for controller in range( 0, len( hosts ) ):
779 controllerStr = str( controller + 1 )
780 for host in hosts[ controller ]:
781 if host is None or host.get( 'ips', [] ) == []:
782 main.log.error(
783 "DEBUG:Error with host ips on controller" +
784 controllerStr + ": " + str( host ) )
785 ipResult = main.FALSE
786
787 # there should always only be one cluster
788 numClusters = len( json.loads( clusters[ 0 ] ) )
789 clusterResults = main.FALSE
790 if numClusters == 1:
791 clusterResults = main.TRUE
792 utilities.assert_equals(
793 expect=1,
794 actual=numClusters,
795 onpass="ONOS shows 1 SCC",
796 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800797
Jon Hall6aec96b2015-01-19 14:49:31 -0800798 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800799 devicesResults = main.TRUE
800 portsResults = main.TRUE
801 linksResults = main.TRUE
Jon Hall58c76b72015-02-23 11:09:24 -0800802 hostsResults = main.TRUE
Jon Hall8f89dda2015-01-22 16:03:33 -0800803 for controller in range( numControllers ):
804 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -0800805 if devices[ controller ] or "Error" not in devices[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -0800806 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -0800807 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -0800808 json.loads( devices[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800809 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800810 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800811 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -0800812 actual=currentDevicesResult,
813 onpass="ONOS" + controllerStr +
814 " Switches view is correct",
815 onfail="ONOS" + controllerStr +
816 " Switches view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800817
Jon Hall6aec96b2015-01-19 14:49:31 -0800818 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -0800819 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -0800820 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -0800821 json.loads( ports[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800822 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800823 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800824 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -0800825 actual=currentPortsResult,
826 onpass="ONOS" + controllerStr +
827 " ports view is correct",
828 onfail="ONOS" + controllerStr +
829 " ports view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800830
Jon Hall6aec96b2015-01-19 14:49:31 -0800831 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -0800832 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -0800833 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -0800834 json.loads( links[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800835 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800836 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800837 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -0800838 actual=currentLinksResult,
839 onpass="ONOS" + controllerStr +
840 " links view is correct",
841 onfail="ONOS" + controllerStr +
842 " links view is incorrect" )
843
844 if hosts[ controller ] or "Error" not in hosts[ controller ]:
845 currentHostsResult = main.Mininet1.compareHosts(
846 MNTopo, hosts[ controller ] )
847 else:
848 currentHostsResult = main.FALSE
849 utilities.assert_equals( expect=main.TRUE,
850 actual=currentHostsResult,
851 onpass="ONOS" + controllerStr +
852 " hosts exist in Mininet",
853 onfail="ONOS" + controllerStr +
854 " hosts don't match Mininet" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800855
Jon Hall8f89dda2015-01-22 16:03:33 -0800856 devicesResults = devicesResults and currentDevicesResult
857 portsResults = portsResults and currentPortsResult
858 linksResults = linksResults and currentLinksResult
Jon Hall58c76b72015-02-23 11:09:24 -0800859 hostsResults = hostsResults and currentHostsResult
Jon Hall73cf9cc2014-11-20 22:28:38 -0800860
Jon Hall58c76b72015-02-23 11:09:24 -0800861 topoResult = devicesResults and portsResults and linksResults\
862 and clusterResults and ipResult and hostsResults
Jon Hall8f89dda2015-01-22 16:03:33 -0800863 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
Jon Hall58c76b72015-02-23 11:09:24 -0800864 onpass="Topology Check Test successful",
865 onfail="Topology Check Test NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800866
Jon Hall8f89dda2015-01-22 16:03:33 -0800867 finalAssert = main.TRUE
868 finalAssert = finalAssert and topoResult and flowCheck \
Jon Hall58c76b72015-02-23 11:09:24 -0800869 and intentCheck and consistentMastership and rolesNotNull
Jon Hall8f89dda2015-01-22 16:03:33 -0800870 utilities.assert_equals( expect=main.TRUE, actual=finalAssert,
Jon Hall58c76b72015-02-23 11:09:24 -0800871 onpass="State check successful",
872 onfail="State check NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800873
Jon Hall6aec96b2015-01-19 14:49:31 -0800874 def CASE6( self, main ):
875 """
Jon Hallffb386d2014-11-21 13:43:38 -0800876 The Failure case.
Jon Hall6aec96b2015-01-19 14:49:31 -0800877 """
Jon Hallffb386d2014-11-21 13:43:38 -0800878 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -0700879 assert numControllers, "numControllers not defined"
880 assert main, "main not defined"
881 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall73cf9cc2014-11-20 22:28:38 -0800882
Jon Hall6aec96b2015-01-19 14:49:31 -0800883 main.log.report( "Restart ONOS node" )
884 main.log.case( "Restart ONOS node" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800885 main.ONOSbench.onosKill( ONOS1Ip )
Jon Hallffb386d2014-11-21 13:43:38 -0800886 start = time.time()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800887
Jon Hall6aec96b2015-01-19 14:49:31 -0800888 main.step( "Checking if ONOS is up yet" )
Jon Hallffb386d2014-11-21 13:43:38 -0800889 count = 0
Jon Hall94fd0472014-12-08 11:52:42 -0800890 while count < 10:
Jon Hall8f89dda2015-01-22 16:03:33 -0800891 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
892 if onos1Isup == main.TRUE:
Jon Hallffb386d2014-11-21 13:43:38 -0800893 elapsed = time.time() - start
894 break
895 else:
896 count = count + 1
Jon Hall73cf9cc2014-11-20 22:28:38 -0800897
Jon Hall8f89dda2015-01-22 16:03:33 -0800898 cliResult = main.ONOScli1.startOnosCli( ONOS1Ip )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800899
Jon Hall8f89dda2015-01-22 16:03:33 -0800900 caseResults = main.TRUE and onos1Isup and cliResult
901 utilities.assert_equals( expect=main.TRUE, actual=caseResults,
Jon Hall58c76b72015-02-23 11:09:24 -0800902 onpass="ONOS restart successful",
903 onfail="ONOS restart NOT successful" )
Jon Hallfebb1c72015-03-05 13:30:09 -0800904 if elapsed:
905 main.log.info( "ESTIMATE: ONOS took %s seconds to restart" %
906 str( elapsed ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800907 time.sleep( 5 )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800908
Jon Hall6aec96b2015-01-19 14:49:31 -0800909 def CASE7( self, main ):
910 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800911 Check state after ONOS failure
Jon Hall6aec96b2015-01-19 14:49:31 -0800912 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800913 import json
Jon Hall5cfd23c2015-03-19 11:40:57 -0700914 assert numControllers, "numControllers not defined"
915 assert main, "main not defined"
916 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -0800917 main.case( "Running ONOS Constant State Tests" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800918
Jon Hall6aec96b2015-01-19 14:49:31 -0800919 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -0800920 rolesNotNull = main.ONOScli1.rolesNotNull()
Jon Hall6aec96b2015-01-19 14:49:31 -0800921 utilities.assert_equals(
922 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800923 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -0800924 onpass="Each device has a master",
925 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -0800926
Jon Hall6aec96b2015-01-19 14:49:31 -0800927 main.step( "Check if switch roles are consistent across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800928 ONOS1Mastership = main.ONOScli1.roles()
Jon Hall6aec96b2015-01-19 14:49:31 -0800929 # FIXME: Refactor this whole case for single instance
Jon Hall8f89dda2015-01-22 16:03:33 -0800930 if "Error" in ONOS1Mastership or not ONOS1Mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -0800931 main.log.report( "Error in getting ONOS mastership" )
Jon Hall58c76b72015-02-23 11:09:24 -0800932 main.log.warn( "ONOS1 mastership response: " +
933 repr( ONOS1Mastership ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800934 consistentMastership = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800935 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800936 consistentMastership = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800937 main.log.report(
938 "Switch roles are consistent across all ONOS nodes" )
939 utilities.assert_equals(
940 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800941 actual=consistentMastership,
Jon Hall6aec96b2015-01-19 14:49:31 -0800942 onpass="Switch roles are consistent across all ONOS nodes",
943 onfail="ONOS nodes have different views of switch roles" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800944
945 description2 = "Compare switch roles from before failure"
Jon Hall6aec96b2015-01-19 14:49:31 -0800946 main.step( description2 )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800947
Jon Hall8f89dda2015-01-22 16:03:33 -0800948 currentJson = json.loads( ONOS1Mastership )
949 oldJson = json.loads( mastershipState )
950 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800951 for i in range( 1, 29 ):
952 switchDPID = str(
Jon Hall58c76b72015-02-23 11:09:24 -0800953 main.Mininet1.getSwitchDPID( switch="s" + str( i ) ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800954
Jon Hall8f89dda2015-01-22 16:03:33 -0800955 current = [ switch[ 'master' ] for switch in currentJson
Jon Hall6aec96b2015-01-19 14:49:31 -0800956 if switchDPID in switch[ 'id' ] ]
Jon Hall8f89dda2015-01-22 16:03:33 -0800957 old = [ switch[ 'master' ] for switch in oldJson
Jon Hall6aec96b2015-01-19 14:49:31 -0800958 if switchDPID in switch[ 'id' ] ]
Jon Hall73cf9cc2014-11-20 22:28:38 -0800959 if current == old:
Jon Hall8f89dda2015-01-22 16:03:33 -0800960 mastershipCheck = mastershipCheck and main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800961 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800962 main.log.warn( "Mastership of switch %s changed" % switchDPID )
Jon Hall8f89dda2015-01-22 16:03:33 -0800963 mastershipCheck = main.FALSE
964 if mastershipCheck == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800965 main.log.report( "Mastership of Switches was not changed" )
966 utilities.assert_equals(
967 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800968 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800969 onpass="Mastership of Switches was not changed",
970 onfail="Mastership of some switches changed" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800971 mastershipCheck = mastershipCheck and consistentMastership
Jon Hall73cf9cc2014-11-20 22:28:38 -0800972
Jon Hall6aec96b2015-01-19 14:49:31 -0800973 main.step( "Get the intents and compare across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800974 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
975 intentCheck = main.FALSE
976 if "Error" in ONOS1Intents or not ONOS1Intents:
Jon Hall6aec96b2015-01-19 14:49:31 -0800977 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800978 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800979 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800980 intentCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800981 main.log.report( "Intents are consistent across all ONOS nodes" )
982 utilities.assert_equals(
983 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800984 actual=intentCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800985 onpass="Intents are consistent across all ONOS nodes",
986 onfail="ONOS nodes have different views of intents" )
Jon Hall1b8f54a2015-02-04 13:24:20 -0800987 # Print the intent states
988 intents = []
989 intents.append( ONOS1Intents )
990 intentStates = []
991 for node in intents: # Iter through ONOS nodes
992 nodeStates = []
Jon Hall58c76b72015-02-23 11:09:24 -0800993 # Iter through intents of a node
994 for intent in json.loads( node ):
Jon Hall1b8f54a2015-02-04 13:24:20 -0800995 nodeStates.append( intent[ 'state' ] )
996 intentStates.append( nodeStates )
997 out = [ (i, nodeStates.count( i ) ) for i in set( nodeStates ) ]
998 main.log.info( dict( out ) )
999
Jon Hall58c76b72015-02-23 11:09:24 -08001000 # NOTE: Store has no durability, so intents are lost across system
1001 # restarts
Jon Hall6aec96b2015-01-19 14:49:31 -08001002 """
1003 main.step( "Compare current intents with intents before the failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001004 # NOTE: this requires case 5 to pass for intentState to be set.
Jon Hall6aec96b2015-01-19 14:49:31 -08001005 # maybe we should stop the test if that fails?
Jon Hall1b8f54a2015-02-04 13:24:20 -08001006 sameIntents = main.TRUE
1007 if intentState and intentState == ONOS1Intents:
Jon Hall8f89dda2015-01-22 16:03:33 -08001008 sameIntents = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001009 main.log.report( "Intents are consistent with before failure" )
1010 # TODO: possibly the states have changed? we may need to figure out
1011 # what the aceptable states are
Jon Hall73cf9cc2014-11-20 22:28:38 -08001012 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001013 try:
1014 main.log.warn( "ONOS1 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001015 print json.dumps( json.loads( ONOS1Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -08001016 sort_keys=True, indent=4,
1017 separators=( ',', ': ' ) )
Jon Hallfebb1c72015-03-05 13:30:09 -08001018 except Exception:
Jon Hall6aec96b2015-01-19 14:49:31 -08001019 pass
Jon Hall8f89dda2015-01-22 16:03:33 -08001020 sameIntents = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001021 utilities.assert_equals(
1022 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001023 actual=sameIntents,
Jon Hall6aec96b2015-01-19 14:49:31 -08001024 onpass="Intents are consistent with before failure",
1025 onfail="The Intents changed during failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001026 intentCheck = intentCheck and sameIntents
Jon Hall6aec96b2015-01-19 14:49:31 -08001027 """
1028 main.step( "Get the OF Table entries and compare to before " +
1029 "component failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001030 FlowTables = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001031 flows2 = []
1032 for i in range( 28 ):
1033 main.log.info( "Checking flow table on s" + str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001034 tmpFlows = main.Mininet2.getFlowTable( 1.3, "s" + str( i + 1 ) )
1035 flows2.append( tmpFlows )
1036 tempResult = main.Mininet2.flowComp(
Jon Hall6aec96b2015-01-19 14:49:31 -08001037 flow1=flows[ i ],
Jon Hall8f89dda2015-01-22 16:03:33 -08001038 flow2=tmpFlows )
1039 FlowTables = FlowTables and tempResult
1040 if FlowTables == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001041 main.log.info( "Differences in flow table for switch: s" +
1042 str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001043 if FlowTables == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001044 main.log.report( "No changes were found in the flow tables" )
1045 utilities.assert_equals(
1046 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001047 actual=FlowTables,
Jon Hall6aec96b2015-01-19 14:49:31 -08001048 onpass="No changes were found in the flow tables",
1049 onfail="Changes were found in the flow tables" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001050
Jon Hall6aec96b2015-01-19 14:49:31 -08001051 # Test of LeadershipElection
Jon Hall669173b2014-12-17 11:36:30 -08001052
Jon Hall8f89dda2015-01-22 16:03:33 -08001053 leader = ONOS1Ip
1054 leaderResult = main.TRUE
1055 for controller in range( 1, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001056 # loop through ONOScli handlers
1057 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001058 leaderN = node.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001059 # verify leader is ONOS1
1060 # NOTE even though we restarted ONOS, it is the only one so onos 1
1061 # must be leader
Jon Hall669173b2014-12-17 11:36:30 -08001062 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08001063 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001064 pass
1065 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001066 # error in response
1067 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001068 "electionTestLeader function, check the" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001069 " error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001070 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001071 elif leader != leaderN:
Jon Hall8f89dda2015-01-22 16:03:33 -08001072 leaderResult = main.FALSE
Jon Hall58c76b72015-02-23 11:09:24 -08001073 main.log.report( "ONOS" + str( controller ) + " sees " +
1074 str( leaderN ) +
1075 " as the leader of the election app. " +
1076 "Leader should be " + str( leader ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001077 if leaderResult:
1078 main.log.report( "Leadership election tests passed( consistent " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001079 "view of leader across listeners and a new " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001080 "leader was re-elected if applicable )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001081 utilities.assert_equals(
1082 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001083 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001084 onpass="Leadership election passed",
1085 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08001086
Jon Hall8f89dda2015-01-22 16:03:33 -08001087 result = ( mastershipCheck and intentCheck and FlowTables and
1088 rolesNotNull and leaderResult )
Jon Hall6aec96b2015-01-19 14:49:31 -08001089 result = int( result )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001090 if result == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001091 main.log.report( "Constant State Tests Passed" )
1092 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall58c76b72015-02-23 11:09:24 -08001093 onpass="Constant State Tests Passed",
1094 onfail="Constant state tests failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001095
Jon Hall6aec96b2015-01-19 14:49:31 -08001096 def CASE8( self, main ):
1097 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001098 Compare topo
Jon Hall6aec96b2015-01-19 14:49:31 -08001099 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001100 import sys
Jon Hall6aec96b2015-01-19 14:49:31 -08001101 # FIXME add this path to params
1102 sys.path.append( "/home/admin/sts" )
1103 # assumes that sts is already in you PYTHONPATH
1104 from sts.topology.teston_topology import TestONTopology
Jon Hall73cf9cc2014-11-20 22:28:38 -08001105 import json
1106 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001107 assert numControllers, "numControllers not defined"
1108 assert main, "main not defined"
1109 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall73cf9cc2014-11-20 22:28:38 -08001110
Jon Hall6aec96b2015-01-19 14:49:31 -08001111 description = "Compare ONOS Topology view to Mininet topology"
1112 main.case( description )
1113 main.log.report( description )
1114 main.step( "Create TestONTopology object" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001115 ctrls = []
1116 count = 1
1117 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -08001118 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
1119 temp = temp + ( "ONOS" + str( count ), )
1120 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
1121 temp = temp + \
1122 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
1123 ctrls.append( temp )
1124 MNTopo = TestONTopology(
1125 main.Mininet1,
1126 ctrls ) # can also add Intent API info for intent operations
Jon Hall73cf9cc2014-11-20 22:28:38 -08001127
Jon Hall6aec96b2015-01-19 14:49:31 -08001128 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001129 devicesResults = main.TRUE
1130 portsResults = main.TRUE
1131 linksResults = main.TRUE
Jon Hall58c76b72015-02-23 11:09:24 -08001132 hostsResults = main.TRUE
Jon Hall8f89dda2015-01-22 16:03:33 -08001133 topoResult = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001134 elapsed = 0
Jon Hallffb386d2014-11-21 13:43:38 -08001135 count = 0
Jon Hall6aec96b2015-01-19 14:49:31 -08001136 main.step( "Collecting topology information from ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001137 startTime = time.time()
Jon Hall58c76b72015-02-23 11:09:24 -08001138 # Give time for Gossip to work
Jon Hall8f89dda2015-01-22 16:03:33 -08001139 while topoResult == main.FALSE and elapsed < 60:
Jon Hallffb386d2014-11-21 13:43:38 -08001140 count = count + 1
Jon Hall94fd0472014-12-08 11:52:42 -08001141 if count > 1:
Jon Hall58c76b72015-02-23 11:09:24 -08001142 # TODO: Depricate STS usage
1143 MNTopo = TestONTopology( main.Mininet1, ctrls )
Jon Hall8f89dda2015-01-22 16:03:33 -08001144 cliStart = time.time()
Jon Hall94fd0472014-12-08 11:52:42 -08001145 devices = []
1146 devices.append( main.ONOScli1.devices() )
Jon Hall94fd0472014-12-08 11:52:42 -08001147 hosts = []
Jon Hall58c76b72015-02-23 11:09:24 -08001148 hosts.append( json.loads( main.ONOScli1.hosts() ) )
1149 ipResult = main.TRUE
1150 for controller in range( 0, len( hosts ) ):
1151 controllerStr = str( controller + 1 )
1152 for host in hosts[ controller ]:
1153 if host is None or host.get( 'ips', [] ) == []:
1154 main.log.error(
1155 "DEBUG:Error with host ips on controller" +
1156 controllerStr + ": " + str( host ) )
1157 ipResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001158 ports = []
1159 ports.append( main.ONOScli1.ports() )
1160 links = []
1161 links.append( main.ONOScli1.links() )
Jon Hall58c76b72015-02-23 11:09:24 -08001162 clusters = []
1163 clusters.append( main.ONOScli1.clusters() )
1164
Jon Hall8f89dda2015-01-22 16:03:33 -08001165 elapsed = time.time() - startTime
1166 cliTime = time.time() - cliStart
1167 print "CLI time: " + str( cliTime )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001168
Jon Hall8f89dda2015-01-22 16:03:33 -08001169 for controller in range( numControllers ):
1170 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001171 if devices[ controller ] or "Error" not in devices[
1172 controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001173 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -08001174 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001175 json.loads( devices[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001176 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001177 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001178 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001179 actual=currentDevicesResult,
1180 onpass="ONOS" + controllerStr +
1181 " Switches view is correct",
1182 onfail="ONOS" + controllerStr +
1183 " Switches view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001184
Jon Hall6aec96b2015-01-19 14:49:31 -08001185 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001186 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -08001187 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001188 json.loads( ports[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001189 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001190 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001191 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001192 actual=currentPortsResult,
1193 onpass="ONOS" + controllerStr +
1194 " ports view is correct",
1195 onfail="ONOS" + controllerStr +
1196 " ports view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001197
Jon Hall6aec96b2015-01-19 14:49:31 -08001198 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001199 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -08001200 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001201 json.loads( links[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001202 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001203 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001204 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001205 actual=currentLinksResult,
1206 onpass="ONOS" + controllerStr +
1207 " links view is correct",
1208 onfail="ONOS" + controllerStr +
1209 " links view is incorrect" )
1210
1211 if hosts[ controller ] or "Error" not in hosts[ controller ]:
1212 currentHostsResult = main.Mininet1.compareHosts(
1213 MNTopo, hosts[ controller ] )
1214 else:
1215 currentHostsResult = main.FALSE
1216 utilities.assert_equals( expect=main.TRUE,
1217 actual=currentHostsResult,
1218 onpass="ONOS" + controllerStr +
1219 " hosts exist in Mininet",
1220 onfail="ONOS" + controllerStr +
1221 " hosts don't match Mininet" )
1222
1223 devicesResults = devicesResults and currentDevicesResult
1224 portsResults = portsResults and currentPortsResult
1225 linksResults = linksResults and currentLinksResult
1226 hostsResults = hostsResults and currentHostsResult
1227
Jon Hall63604932015-02-26 17:09:50 -08001228 # "consistent" results don't make sense for single instance
Jon Hall58c76b72015-02-23 11:09:24 -08001229 # there should always only be one cluster
1230 numClusters = len( json.loads( clusters[ 0 ] ) )
1231 clusterResults = main.FALSE
1232 if numClusters == 1:
1233 clusterResults = main.TRUE
1234 utilities.assert_equals(
1235 expect=1,
1236 actual=numClusters,
1237 onpass="ONOS shows 1 SCC",
1238 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
1239
1240 topoResult = ( devicesResults and portsResults and linksResults
1241 and hostsResults and ipResult and clusterResults )
Jon Hall94fd0472014-12-08 11:52:42 -08001242
Jon Hall8f89dda2015-01-22 16:03:33 -08001243 topoResult = topoResult and int( count <= 2 )
1244 note = "note it takes about " + str( int( cliTime ) ) + \
1245 " seconds for the test to make all the cli calls to fetch " +\
1246 "the topology from each ONOS instance"
Jon Hall1b8f54a2015-02-04 13:24:20 -08001247 main.log.info(
Jon Hall8f89dda2015-01-22 16:03:33 -08001248 "Very crass estimate for topology discovery/convergence( " +
1249 str( note ) + " ): " + str( elapsed ) + " seconds, " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001250 str( count ) + " tries" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001251 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
Jon Hall58c76b72015-02-23 11:09:24 -08001252 onpass="Topology Check Test successful",
1253 onfail="Topology Check Test NOT successful" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001254 if topoResult == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001255 main.log.report( "ONOS topology view matches Mininet topology" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001256
Jon Hall6aec96b2015-01-19 14:49:31 -08001257 def CASE9( self, main ):
1258 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001259 Link s3-s28 down
Jon Hall6aec96b2015-01-19 14:49:31 -08001260 """
1261 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001262 assert numControllers, "numControllers not defined"
1263 assert main, "main not defined"
1264 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -08001265 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001266
Jon Hall8f89dda2015-01-22 16:03:33 -08001267 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001268
Jon Hall6aec96b2015-01-19 14:49:31 -08001269 description = "Turn off a link to ensure that Link Discovery " +\
Jon Hall58c76b72015-02-23 11:09:24 -08001270 "is working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001271 main.log.report( description )
1272 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001273
Jon Hall6aec96b2015-01-19 14:49:31 -08001274 main.step( "Kill Link between s3 and s28" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001275 LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" )
Jon Hall58c76b72015-02-23 11:09:24 -08001276 main.log.info( "Waiting " + str( linkSleep ) +
1277 " seconds for link down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001278 time.sleep( linkSleep )
1279 utilities.assert_equals( expect=main.TRUE, actual=LinkDown,
Jon Hall58c76b72015-02-23 11:09:24 -08001280 onpass="Link down succesful",
1281 onfail="Failed to bring link down" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001282 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -08001283
Jon Hall6aec96b2015-01-19 14:49:31 -08001284 def CASE10( self, main ):
1285 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001286 Link s3-s28 up
Jon Hall6aec96b2015-01-19 14:49:31 -08001287 """
1288 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001289 assert numControllers, "numControllers not defined"
1290 assert main, "main not defined"
1291 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -08001292 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001293
Jon Hall8f89dda2015-01-22 16:03:33 -08001294 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001295
Jon Hall6aec96b2015-01-19 14:49:31 -08001296 description = "Restore a link to ensure that Link Discovery is " + \
Jon Hall58c76b72015-02-23 11:09:24 -08001297 "working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001298 main.log.report( description )
1299 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001300
Jon Hall6aec96b2015-01-19 14:49:31 -08001301 main.step( "Bring link between s3 and s28 back up" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001302 LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" )
Jon Hall58c76b72015-02-23 11:09:24 -08001303 main.log.info( "Waiting " + str( linkSleep ) +
1304 " seconds for link up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001305 time.sleep( linkSleep )
1306 utilities.assert_equals( expect=main.TRUE, actual=LinkUp,
Jon Hall58c76b72015-02-23 11:09:24 -08001307 onpass="Link up succesful",
1308 onfail="Failed to bring link up" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001309 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -08001310
Jon Hall6aec96b2015-01-19 14:49:31 -08001311 def CASE11( self, main ):
1312 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001313 Switch Down
Jon Hall6aec96b2015-01-19 14:49:31 -08001314 """
1315 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001316 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001317 assert numControllers, "numControllers not defined"
1318 assert main, "main not defined"
1319 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall73cf9cc2014-11-20 22:28:38 -08001320
Jon Hall8f89dda2015-01-22 16:03:33 -08001321 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001322
1323 description = "Killing a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001324 main.log.report( description )
1325 main.case( description )
1326 switch = main.params[ 'kill' ][ 'switch' ]
1327 switchDPID = main.params[ 'kill' ][ 'dpid' ]
Jon Hall73cf9cc2014-11-20 22:28:38 -08001328
Jon Hall6aec96b2015-01-19 14:49:31 -08001329 # TODO: Make this switch parameterizable
1330 main.step( "Kill " + switch )
1331 main.log.report( "Deleting " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001332 main.Mininet1.delSwitch( switch )
1333 main.log.info( "Waiting " + str( switchSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001334 " seconds for switch down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001335 time.sleep( switchSleep )
1336 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001337 # Peek at the deleted switch
1338 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001339 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001340 if device and device[ 'available' ] is False:
Jon Hall94fd0472014-12-08 11:52:42 -08001341 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001342 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall58c76b72015-02-23 11:09:24 -08001343 onpass="Kill switch succesful",
1344 onfail="Failed to kill switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001345
Jon Hall6aec96b2015-01-19 14:49:31 -08001346 def CASE12( self, main ):
1347 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001348 Switch Up
Jon Hall6aec96b2015-01-19 14:49:31 -08001349 """
1350 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001351 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001352 assert numControllers, "numControllers not defined"
1353 assert main, "main not defined"
1354 assert utilities.assert_equals, "utilities.assert_equals not defined"
1355 assert ONOS1Port, "ONOS1Port not defined"
1356 assert ONOS2Port, "ONOS2Port not defined"
1357 assert ONOS3Port, "ONOS3Port not defined"
1358 assert ONOS4Port, "ONOS4Port not defined"
1359 assert ONOS5Port, "ONOS5Port not defined"
1360 assert ONOS6Port, "ONOS6Port not defined"
1361 assert ONOS7Port, "ONOS7Port not defined"
Jon Hall669173b2014-12-17 11:36:30 -08001362
Jon Hall8f89dda2015-01-22 16:03:33 -08001363 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall6aec96b2015-01-19 14:49:31 -08001364 switch = main.params[ 'kill' ][ 'switch' ]
1365 switchDPID = main.params[ 'kill' ][ 'dpid' ]
1366 links = main.params[ 'kill' ][ 'links' ].split()
Jon Hall73cf9cc2014-11-20 22:28:38 -08001367 description = "Adding a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001368 main.log.report( description )
1369 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001370
Jon Hall6aec96b2015-01-19 14:49:31 -08001371 main.step( "Add back " + switch )
1372 main.log.report( "Adding back " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001373 main.Mininet1.addSwitch( switch, dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001374 # TODO: New dpid or same? Ask Thomas?
1375 for peer in links:
Jon Hall8f89dda2015-01-22 16:03:33 -08001376 main.Mininet1.addLink( switch, peer )
1377 main.Mininet1.assignSwController( sw=switch.split( 's' )[ 1 ],
Jon Hall58c76b72015-02-23 11:09:24 -08001378 ip1=ONOS1Ip,
1379 port1=ONOS1Port )
1380 main.log.info( "Waiting " + str( switchSleep ) +
1381 " seconds for switch up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001382 time.sleep( switchSleep )
1383 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001384 # Peek at the deleted switch
1385 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001386 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001387 if device and device[ 'available' ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001388 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001389 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall58c76b72015-02-23 11:09:24 -08001390 onpass="add switch succesful",
1391 onfail="Failed to add switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001392
Jon Hall6aec96b2015-01-19 14:49:31 -08001393 def CASE13( self, main ):
1394 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001395 Clean up
Jon Hall6aec96b2015-01-19 14:49:31 -08001396 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001397 import os
1398 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001399 assert numControllers, "numControllers not defined"
1400 assert main, "main not defined"
1401 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -08001402 # printing colors to terminal
Jon Hall669173b2014-12-17 11:36:30 -08001403 colors = {}
Jon Hall6aec96b2015-01-19 14:49:31 -08001404 colors[ 'cyan' ] = '\033[96m'
1405 colors[ 'purple' ] = '\033[95m'
1406 colors[ 'blue' ] = '\033[94m'
1407 colors[ 'green' ] = '\033[92m'
1408 colors[ 'yellow' ] = '\033[93m'
1409 colors[ 'red' ] = '\033[91m'
1410 colors[ 'end' ] = '\033[0m'
Jon Hall73cf9cc2014-11-20 22:28:38 -08001411 description = "Test Cleanup"
Jon Hall6aec96b2015-01-19 14:49:31 -08001412 main.log.report( description )
1413 main.case( description )
1414 main.step( "Killing tcpdumps" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001415 main.Mininet2.stopTcpdump()
Jon Hall73cf9cc2014-11-20 22:28:38 -08001416
Jon Hall6aec96b2015-01-19 14:49:31 -08001417 main.step( "Checking ONOS Logs for errors" )
1418 print colors[ 'purple' ] + "Checking logs for errors on ONOS1:" + \
Jon Hall8f89dda2015-01-22 16:03:33 -08001419 colors[ 'end' ]
1420 print main.ONOSbench.checkLogs( ONOS1Ip )
Jon Hall5cfd23c2015-03-19 11:40:57 -07001421
Jon Hall6aec96b2015-01-19 14:49:31 -08001422 main.step( "Copying MN pcap and ONOS log files to test station" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001423 testname = main.TEST
Jon Hall8f89dda2015-01-22 16:03:33 -08001424 teststationUser = main.params[ 'TESTONUSER' ]
1425 teststationIP = main.params[ 'TESTONIP' ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001426 # NOTE: MN Pcap file is being saved to ~/packet_captures
Jon Hall73cf9cc2014-11-20 22:28:38 -08001427 # scp this file as MN and TestON aren't necessarily the same vm
Jon Hall6aec96b2015-01-19 14:49:31 -08001428 # FIXME: scp
1429 # mn files
1430 # TODO: Load these from params
1431 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001432 logFolder = "/opt/onos/log/"
1433 logFiles = [ "karaf.log", "karaf.log.1" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001434 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001435 dstDir = "~/packet_captures/"
1436 for f in logFiles:
1437 main.ONOSbench.handle.sendline( "scp sdn@" + ONOS1Ip + ":" +
1438 logFolder + f + " " +
1439 teststationUser + "@" +
1440 teststationIP + ":" + dstDir +
Jon Hall6aec96b2015-01-19 14:49:31 -08001441 str( testname ) + "-ONOS1-" + f )
1442 main.ONOSbench.handle.expect( "\$" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001443
Jon Hall6aec96b2015-01-19 14:49:31 -08001444 # std*.log's
1445 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001446 logFolder = "/opt/onos/var/"
1447 logFiles = [ "stderr.log", "stdout.log" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001448 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001449 dstDir = "~/packet_captures/"
1450 for f in logFiles:
1451 main.ONOSbench.handle.sendline( "scp sdn@" + ONOS1Ip + ":" +
1452 logFolder + f + " " +
1453 teststationUser + "@" +
1454 teststationIP + ":" + dstDir +
Jon Hall6aec96b2015-01-19 14:49:31 -08001455 str( testname ) + "-ONOS1-" + f )
Jon Hall58c76b72015-02-23 11:09:24 -08001456 main.ONOSbench.handle.expect( "\$" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001457 # sleep so scp can finish
1458 time.sleep( 10 )
Jon Hall58c76b72015-02-23 11:09:24 -08001459 main.Mininet1.stopNet()
Jon Hall6aec96b2015-01-19 14:49:31 -08001460 main.step( "Packing and rotating pcap archives" )
1461 os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001462
Jon Hall6aec96b2015-01-19 14:49:31 -08001463 # TODO: actually check something here
1464 utilities.assert_equals( expect=main.TRUE, actual=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001465 onpass="Test cleanup successful",
1466 onfail="Test cleanup NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001467
Jon Hall6aec96b2015-01-19 14:49:31 -08001468 def CASE14( self, main ):
1469 """
Jon Hall669173b2014-12-17 11:36:30 -08001470 start election app on all onos nodes
Jon Hall6aec96b2015-01-19 14:49:31 -08001471 """
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 Hall8f89dda2015-01-22 16:03:33 -08001475 leaderResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001476 # install app on onos 1
1477 main.log.info( "Install leadership election app" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001478 main.ONOScli1.featureInstall( "onos-app-election" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001479 # wait for election
1480 # check for leader
Jon Hall8f89dda2015-01-22 16:03:33 -08001481 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001482 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08001483 if leader == ONOS1Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08001484 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001485 pass
Jon Hall6aec96b2015-01-19 14:49:31 -08001486 elif leader is None:
1487 # No leader elected
1488 main.log.report( "No leader was elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001489 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001490 elif leader == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001491 # error in response
1492 # TODO: add check for "Command not found:" in the driver, this
1493 # means the app isn't loaded
Jon Hall8f89dda2015-01-22 16:03:33 -08001494 main.log.report( "Something is wrong with electionTestLeader" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001495 " function, check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001496 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001497 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001498 # error in response
1499 main.log.report(
Jon Hall8f89dda2015-01-22 16:03:33 -08001500 "Unexpected response from electionTestLeader function:'" +
1501 str( leader ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001502 "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001503 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001504
Jon Hall6aec96b2015-01-19 14:49:31 -08001505 # install on other nodes and check for leader.
1506 # Should be onos1 and each app should show the same leader
Jon Hall8f89dda2015-01-22 16:03:33 -08001507 for controller in range( 2, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001508 # loop through ONOScli handlers
1509 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001510 node.featureInstall( "onos-app-election" )
1511 leaderN = node.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001512 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08001513 if leaderN == ONOS1Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08001514 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001515 pass
1516 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001517 # error in response
1518 # TODO: add check for "Command not found:" in the driver, this
1519 # means the app isn't loaded
1520 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001521 "electionTestLeader function, check the" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001522 " error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001523 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001524 elif leader != leaderN:
Jon Hall8f89dda2015-01-22 16:03:33 -08001525 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001526 main.log.report( "ONOS" + str( controller ) + " sees " +
1527 str( leaderN ) +
1528 " as the leader of the election app. Leader" +
1529 " should be " +
1530 str( leader ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001531 if leaderResult:
Jon Hall6aec96b2015-01-19 14:49:31 -08001532 main.log.report( "Leadership election tests passed( consistent " +
1533 "view of leader across listeners and a leader " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001534 "was elected )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001535 utilities.assert_equals(
1536 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001537 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001538 onpass="Leadership election passed",
1539 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08001540
Jon Hall6aec96b2015-01-19 14:49:31 -08001541 def CASE15( self, main ):
1542 """
Jon Hall669173b2014-12-17 11:36:30 -08001543 Check that Leadership Election is still functional
Jon Hall6aec96b2015-01-19 14:49:31 -08001544 """
Jon Hall5cfd23c2015-03-19 11:40:57 -07001545 assert numControllers, "numControllers not defined"
1546 assert main, "main not defined"
1547 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall8f89dda2015-01-22 16:03:33 -08001548 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08001549 description = "Check that Leadership Election is still functional"
Jon Hall6aec96b2015-01-19 14:49:31 -08001550 main.log.report( description )
1551 main.case( description )
1552 main.step( "Find current leader and withdraw" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001553 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001554 # TODO: do some sanity checking on leader before using it
Jon Hall8f89dda2015-01-22 16:03:33 -08001555 withdrawResult = main.FALSE
1556 if leader == ONOS1Ip:
1557 oldLeader = getattr( main, "ONOScli1" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001558 elif leader is None or leader == main.FALSE:
1559 main.log.report(
1560 "Leader for the election app should be an ONOS node," +
Jon Hall58c76b72015-02-23 11:09:24 -08001561 "instead got '" + str( leader ) + "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001562 leaderResult = main.FALSE
Jon Hall63604932015-02-26 17:09:50 -08001563 oldLeader = None
1564 else:
1565 main.log.error( "Leader election --- why am I HERE?!?")
1566 if oldLeader:
1567 withdrawResult = oldLeader.electionTestWithdraw()
Jon Hall6aec96b2015-01-19 14:49:31 -08001568 utilities.assert_equals(
1569 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001570 actual=withdrawResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001571 onpass="App was withdrawn from election",
1572 onfail="App was not withdrawn from election" )
Jon Hall669173b2014-12-17 11:36:30 -08001573
Jon Hall6aec96b2015-01-19 14:49:31 -08001574 main.step( "Make sure new leader is elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001575 leaderList = []
1576 leaderN = main.ONOScli1.electionTestLeader()
Jon Hall669173b2014-12-17 11:36:30 -08001577 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08001578 main.log.report( "ONOS still sees " + str( leaderN ) +
1579 " as leader after they withdrew" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001580 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001581 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001582 # error in response
1583 # TODO: add check for "Command not found:" in the driver, this
1584 # means the app isn't loaded
Jon Hall8f89dda2015-01-22 16:03:33 -08001585 main.log.report( "Something is wrong with electionTestLeader " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001586 "function, check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001587 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001588 elif leaderN is None:
1589 main.log.info(
1590 "There is no leader after the app withdrew from election" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001591 if leaderResult:
1592 main.log.report( "Leadership election tests passed( There is no " +
1593 "leader after the old leader resigned )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001594 utilities.assert_equals(
1595 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001596 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001597 onpass="Leadership election passed",
1598 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08001599
Jon Hall58c76b72015-02-23 11:09:24 -08001600 main.step( "Run for election on old leader( just so everyone " +
1601 "is in the hat )" )
Jon Hall63604932015-02-26 17:09:50 -08001602 if oldLeader:
1603 runResult = oldLeader.electionTestRun()
1604 else:
1605 runResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001606 utilities.assert_equals(
1607 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001608 actual=runResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001609 onpass="App re-ran for election",
1610 onfail="App failed to run for election" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001611 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001612 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08001613 if leader == ONOS1Ip:
1614 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08001615 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001616 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001617 # TODO: assert on run and withdraw results?
Jon Hall669173b2014-12-17 11:36:30 -08001618
Jon Hall6aec96b2015-01-19 14:49:31 -08001619 utilities.assert_equals(
1620 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001621 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001622 onpass="Leadership election passed",
1623 onfail="ONOS1's election app was not leader after it re-ran " +
1624 "for election" )