blob: 39ce920b152cdc4cefb166d357bcc6b921db592f [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:
34 git pull
35 mvn clean install
36 onos-package
37 cell <name>
38 onos-verify-cell
39 NOTE: temporary - onos-remove-raft-logs
40 onos-install -f
41 onos-wait-for-start
Jon Hall6aec96b2015-01-19 14:49:31 -080042 """
43 main.log.report( "ONOS Single node cluster restart " +
44 "HA test - initialization" )
45 main.case( "Setting up test environment" )
46 # TODO: save all the timers and output them for plotting
Jon Hall73cf9cc2014-11-20 22:28:38 -080047
48 # load some vairables from the params file
Jon Hall8f89dda2015-01-22 16:03:33 -080049 PULLCODE = False
Jon Hall6aec96b2015-01-19 14:49:31 -080050 if main.params[ 'Git' ] == 'True':
Jon Hall8f89dda2015-01-22 16:03:33 -080051 PULLCODE = True
Jon Hall529a37f2015-01-28 10:02:00 -080052 gitBranch = main.params[ 'branch' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080053 cellName = main.params[ 'ENV' ][ 'cellName' ]
Jon Hall6aec96b2015-01-19 14:49:31 -080054
55 # set global variables
Jon Hall8f89dda2015-01-22 16:03:33 -080056 global ONOS1Ip
57 global ONOS1Port
58 global ONOS2Ip
59 global ONOS2Port
60 global ONOS3Ip
61 global ONOS3Port
62 global ONOS4Ip
63 global ONOS4Port
64 global ONOS5Ip
65 global ONOS5Port
66 global ONOS6Ip
67 global ONOS6Port
68 global ONOS7Ip
69 global ONOS7Port
70 global numControllers
Jon Hall73cf9cc2014-11-20 22:28:38 -080071
Jon Hall8f89dda2015-01-22 16:03:33 -080072 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
73 ONOS1Port = main.params[ 'CTRL' ][ 'port1' ]
74 ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
75 ONOS2Port = main.params[ 'CTRL' ][ 'port2' ]
76 ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ]
77 ONOS3Port = main.params[ 'CTRL' ][ 'port3' ]
78 ONOS4Ip = main.params[ 'CTRL' ][ 'ip4' ]
79 ONOS4Port = main.params[ 'CTRL' ][ 'port4' ]
80 ONOS5Ip = main.params[ 'CTRL' ][ 'ip5' ]
81 ONOS5Port = main.params[ 'CTRL' ][ 'port5' ]
82 ONOS6Ip = main.params[ 'CTRL' ][ 'ip6' ]
83 ONOS6Port = main.params[ 'CTRL' ][ 'port6' ]
84 ONOS7Ip = main.params[ 'CTRL' ][ 'ip7' ]
85 ONOS7Port = main.params[ 'CTRL' ][ 'port7' ]
86 numControllers = int( main.params[ 'num_controllers' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -080087
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 Hall6aec96b2015-01-19 14:49:31 -080095 main.log.report( "Uninstalling ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -080096 main.ONOSbench.onosUninstall( ONOS1Ip )
97 main.ONOSbench.onosUninstall( ONOS2Ip )
98 main.ONOSbench.onosUninstall( ONOS3Ip )
99 main.ONOSbench.onosUninstall( ONOS4Ip )
100 main.ONOSbench.onosUninstall( ONOS5Ip )
101 main.ONOSbench.onosUninstall( ONOS6Ip )
102 main.ONOSbench.onosUninstall( ONOS7Ip )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800103
Jon Hall8f89dda2015-01-22 16:03:33 -0800104 cleanInstallResult = main.TRUE
105 gitPullResult = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800106
Jon Hall6aec96b2015-01-19 14:49:31 -0800107 main.step( "Compiling the latest version of ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800108 if PULLCODE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800109 # TODO Configure branch in params
110 main.step( "Git checkout and pull master" )
Jon Hall529a37f2015-01-28 10:02:00 -0800111 main.ONOSbench.gitCheckout( gitBranch )
Jon Hall8f89dda2015-01-22 16:03:33 -0800112 gitPullResult = main.ONOSbench.gitPull()
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" )
131 # TODO check bundle:list?
132 for i in range( 2 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800133 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
134 if onos1Isup:
Jon Hall94fd0472014-12-08 11:52:42 -0800135 break
Jon Hall8f89dda2015-01-22 16:03:33 -0800136 if not onos1Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800137 main.log.report( "ONOS1 didn't start!" )
Jon Hall94fd0472014-12-08 11:52:42 -0800138
Jon Hall8f89dda2015-01-22 16:03:33 -0800139 cliResult = main.ONOScli1.startOnosCli( ONOS1Ip )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800140
Jon Hall6aec96b2015-01-19 14:49:31 -0800141 main.step( "Start Packet Capture MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800142 main.Mininet2.startTcpdump(
Jon Hall6aec96b2015-01-19 14:49:31 -0800143 str( main.params[ 'MNtcpdump' ][ 'folder' ] ) + str( main.TEST )
144 + "-MN.pcap",
145 intf=main.params[ 'MNtcpdump' ][ 'intf' ],
146 port=main.params[ 'MNtcpdump' ][ 'port' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800147
Jon Hall8f89dda2015-01-22 16:03:33 -0800148 case1Result = ( cleanInstallResult and packageResult and
149 cellResult and verifyResult and onos1InstallResult
150 and onos1Isup and cliResult )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800151
Jon Hall8f89dda2015-01-22 16:03:33 -0800152 utilities.assert_equals( expect=main.TRUE, actual=case1Result,
153 onpass="Test startup successful",
154 onfail="Test startup NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800155
Jon Hall8f89dda2015-01-22 16:03:33 -0800156 if case1Result == main.FALSE:
Jon Hall73cf9cc2014-11-20 22:28:38 -0800157 main.cleanup()
158 main.exit()
159
Jon Hall6aec96b2015-01-19 14:49:31 -0800160 def CASE2( self, main ):
161 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800162 Assign mastership to controllers
Jon Hall6aec96b2015-01-19 14:49:31 -0800163 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800164 import re
165
Jon Hall6aec96b2015-01-19 14:49:31 -0800166 main.log.report( "Assigning switches to controllers" )
167 main.case( "Assigning Controllers" )
168 main.step( "Assign switches to controllers" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800169
Jon Hall6aec96b2015-01-19 14:49:31 -0800170 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800171 main.Mininet1.assignSwController(
Jon Hall6aec96b2015-01-19 14:49:31 -0800172 sw=str( i ),
Jon Hall8f89dda2015-01-22 16:03:33 -0800173 ip1=ONOS1Ip, port1=ONOS1Port )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800174
Jon Hall8f89dda2015-01-22 16:03:33 -0800175 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800176 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800177 response = main.Mininet1.getSwController( "s" + str( i ) )
Jon Hallffb386d2014-11-21 13:43:38 -0800178 try:
Jon Hall6aec96b2015-01-19 14:49:31 -0800179 main.log.info( str( response ) )
Jon Hallffb386d2014-11-21 13:43:38 -0800180 except:
Jon Hall6aec96b2015-01-19 14:49:31 -0800181 main.log.info( repr( response ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800182 if re.search( "tcp:" + ONOS1Ip, response ):
183 mastershipCheck = mastershipCheck and main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800184 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800185 mastershipCheck = main.FALSE
186 if mastershipCheck == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800187 main.log.report( "Switch mastership assigned correctly" )
188 utilities.assert_equals(
189 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800190 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800191 onpass="Switch mastership assigned correctly",
192 onfail="Switches not assigned correctly to controllers" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800193
Jon Hall6aec96b2015-01-19 14:49:31 -0800194 def CASE3( self, main ):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800195 """
196 Assign intents
Jon Hall73cf9cc2014-11-20 22:28:38 -0800197 """
Jon Hall6aec96b2015-01-19 14:49:31 -0800198 # FIXME: we must reinstall intents until we have a persistant
199 # datastore!
Jon Hall73cf9cc2014-11-20 22:28:38 -0800200 import time
Jon Hall6aec96b2015-01-19 14:49:31 -0800201 main.log.report( "Adding host intents" )
202 main.case( "Adding host Intents" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800203
Jon Hall8f89dda2015-01-22 16:03:33 -0800204 main.step( "Discovering Hosts( Via pingall for now )" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800205 # FIXME: Once we have a host discovery mechanism, use that instead
Jon Hall73cf9cc2014-11-20 22:28:38 -0800206
Jon Hall6aec96b2015-01-19 14:49:31 -0800207 # install onos-app-fwd
208 main.log.info( "Install reactive forwarding app" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800209 main.ONOScli1.featureInstall( "onos-app-fwd" )
Jon Hall94fd0472014-12-08 11:52:42 -0800210
Jon Hall6aec96b2015-01-19 14:49:31 -0800211 # REACTIVE FWD test
Jon Hall8f89dda2015-01-22 16:03:33 -0800212 pingResult = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800213 time1 = time.time()
Jon Hall8f89dda2015-01-22 16:03:33 -0800214 pingResult = main.Mininet1.pingall()
Jon Hall529a37f2015-01-28 10:02:00 -0800215 utilities.assert_equals(
216 expect=main.TRUE,
217 actual=pingResult,
218 onpass="Reactive Pingall test passed",
219 onfail="Reactive Pingall failed, one or more ping pairs failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800220 time2 = time.time()
Jon Hall6aec96b2015-01-19 14:49:31 -0800221 main.log.info( "Time for pingall: %2f seconds" % ( time2 - time1 ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800222
Jon Hall6aec96b2015-01-19 14:49:31 -0800223 # uninstall onos-app-fwd
224 main.log.info( "Uninstall reactive forwarding app" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800225 main.ONOScli1.featureUninstall( "onos-app-fwd" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800226 # timeout for fwd flows
227 time.sleep( 10 )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800228
Jon Hall6aec96b2015-01-19 14:49:31 -0800229 main.step( "Add host intents" )
230 # TODO: move the host numbers to params
Jon Hall8f89dda2015-01-22 16:03:33 -0800231 intentAddResult = True
Jon Hall6aec96b2015-01-19 14:49:31 -0800232 for i in range( 8, 18 ):
233 main.log.info( "Adding host intent between h" + str( i ) +
234 " and h" + str( i + 10 ) )
235 host1 = "00:00:00:00:00:" + \
236 str( hex( i )[ 2: ] ).zfill( 2 ).upper()
237 host2 = "00:00:00:00:00:" + \
238 str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper()
Jon Hall8f89dda2015-01-22 16:03:33 -0800239 host1Id = main.ONOScli1.getHost( host1 )[ 'id' ]
240 host2Id = main.ONOScli1.getHost( host2 )[ 'id' ]
Jon Hall6aec96b2015-01-19 14:49:31 -0800241 # NOTE: get host can return None
Jon Hall8f89dda2015-01-22 16:03:33 -0800242 if host1Id and host2Id:
243 tmpResult = main.ONOScli1.addHostIntent(
244 host1Id,
245 host2Id )
Jon Hall669173b2014-12-17 11:36:30 -0800246 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800247 main.log.error( "Error, getHost() failed" )
248 tmpResult = main.FALSE
249 intentAddResult = bool( pingResult and intentAddResult
250 and tmpResult )
Jon Hall529a37f2015-01-28 10:02:00 -0800251 # TODO Check that intents were added?
Jon Hall6aec96b2015-01-19 14:49:31 -0800252 utilities.assert_equals(
253 expect=True,
Jon Hall8f89dda2015-01-22 16:03:33 -0800254 actual=intentAddResult,
Jon Hall529a37f2015-01-28 10:02:00 -0800255 onpass="Pushed host intents to ONOS",
256 onfail="Error in pushing host intents to ONOS" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800257 # TODO Check if intents all exist in datastore
Jon Hall73cf9cc2014-11-20 22:28:38 -0800258
Jon Hall6aec96b2015-01-19 14:49:31 -0800259 def CASE4( self, main ):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800260 """
261 Ping across added host intents
262 """
263 description = " Ping across added host intents"
Jon Hall6aec96b2015-01-19 14:49:31 -0800264 main.log.report( description )
265 main.case( description )
Jon Hall8f89dda2015-01-22 16:03:33 -0800266 PingResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800267 for i in range( 8, 18 ):
268 ping = main.Mininet1.pingHost(
269 src="h" + str( i ), target="h" + str( i + 10 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800270 PingResult = PingResult and ping
Jon Hall6aec96b2015-01-19 14:49:31 -0800271 if ping == main.FALSE:
272 main.log.warn( "Ping failed between h" + str( i ) +
273 " and h" + str( i + 10 ) )
274 elif ping == main.TRUE:
275 main.log.info( "Ping test passed!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800276 PingResult = main.TRUE
277 if PingResult == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800278 main.log.report(
279 "Intents have not been installed correctly, pings failed." )
Jon Hall529a37f2015-01-28 10:02:00 -0800280 #TODO: pretty print
281 main.log.warn( "ONSO1 intents: " )
282 main.log.warn( json.dumps( json.loads( main.ONOScli1.intents() ),
283 sort_keys=True,
284 indent=4,
285 separators=( ',', ': ' ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800286 if PingResult == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800287 main.log.report(
288 "Intents have been installed correctly and verified by pings" )
289 utilities.assert_equals(
290 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800291 actual=PingResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800292 onpass="Intents have been installed correctly and pings work",
293 onfail="Intents have not been installed correctly, pings failed." )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800294
Jon Hall6aec96b2015-01-19 14:49:31 -0800295 def CASE5( self, main ):
296 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800297 Reading state of ONOS
Jon Hall6aec96b2015-01-19 14:49:31 -0800298 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800299 import json
Jon Hall6aec96b2015-01-19 14:49:31 -0800300 # assumes that sts is already in you PYTHONPATH
301 from sts.topology.teston_topology import TestONTopology
Jon Hall73cf9cc2014-11-20 22:28:38 -0800302
Jon Hall6aec96b2015-01-19 14:49:31 -0800303 main.log.report( "Setting up and gathering data for current state" )
304 main.case( "Setting up and gathering data for current state" )
305 # The general idea for this test case is to pull the state of
306 # ( intents,flows, topology,... ) from each ONOS node
307 # We can then compare them with eachother and also with past states
Jon Hall73cf9cc2014-11-20 22:28:38 -0800308
Jon Hall6aec96b2015-01-19 14:49:31 -0800309 main.step( "Get the Mastership of each switch from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800310 global mastershipState
311 mastershipState = []
Jon Hall94fd0472014-12-08 11:52:42 -0800312
Jon Hall6aec96b2015-01-19 14:49:31 -0800313 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -0800314 rolesNotNull = main.ONOScli1.rolesNotNull()
Jon Hall6aec96b2015-01-19 14:49:31 -0800315 utilities.assert_equals(
316 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800317 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -0800318 onpass="Each device has a master",
319 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -0800320
Jon Hall8f89dda2015-01-22 16:03:33 -0800321 ONOS1Mastership = main.ONOScli1.roles()
Jon Hall6aec96b2015-01-19 14:49:31 -0800322 # TODO: Make this a meaningful check
Jon Hall8f89dda2015-01-22 16:03:33 -0800323 if "Error" in ONOS1Mastership or not ONOS1Mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -0800324 main.log.report( "Error in getting ONOS roles" )
325 main.log.warn(
326 "ONOS1 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800327 repr( ONOS1Mastership ) )
328 consistentMastership = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800329 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800330 mastershipState = ONOS1Mastership
331 consistentMastership = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800332
Jon Hall6aec96b2015-01-19 14:49:31 -0800333 main.step( "Get the intents from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800334 global intentState
335 intentState = []
336 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
337 intentCheck = main.FALSE
338 if "Error" in ONOS1Intents or not ONOS1Intents:
Jon Hall6aec96b2015-01-19 14:49:31 -0800339 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800340 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800341 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800342 intentCheck = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800343
Jon Hall6aec96b2015-01-19 14:49:31 -0800344 main.step( "Get the flows from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800345 global flowState
346 flowState = []
347 ONOS1Flows = main.ONOScli1.flows( jsonFormat=True )
348 flowCheck = main.FALSE
349 if "Error" in ONOS1Flows or not ONOS1Flows:
Jon Hall6aec96b2015-01-19 14:49:31 -0800350 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800351 main.log.warn( "ONOS1 flows repsponse: " + ONOS1Flows )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800352 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800353 # TODO: Do a better check, maybe compare flows on switches?
Jon Hall8f89dda2015-01-22 16:03:33 -0800354 flowState = ONOS1Flows
355 flowCheck = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800356
Jon Hall6aec96b2015-01-19 14:49:31 -0800357 main.step( "Get the OF Table entries" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800358 global flows
Jon Hall6aec96b2015-01-19 14:49:31 -0800359 flows = []
360 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800361 flows.append( main.Mininet2.getFlowTable( 1.3, "s" + str( i ) ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800362
Jon Hall6aec96b2015-01-19 14:49:31 -0800363 # TODO: Compare switch flow tables with ONOS flow tables
Jon Hall73cf9cc2014-11-20 22:28:38 -0800364
Jon Hall6aec96b2015-01-19 14:49:31 -0800365 main.step( "Create TestONTopology object" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800366 ctrls = []
367 count = 1
368 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -0800369 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
370 temp = temp + ( "ONOS" + str( count ), )
371 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
372 temp = temp + \
373 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
374 ctrls.append( temp )
375 MNTopo = TestONTopology(
376 main.Mininet1,
377 ctrls ) # can also add Intent API info for intent operations
Jon Hall73cf9cc2014-11-20 22:28:38 -0800378
Jon Hall6aec96b2015-01-19 14:49:31 -0800379 main.step( "Collecting topology information from ONOS" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800380 devices = []
381 devices.append( main.ONOScli1.devices() )
Jon Hall6aec96b2015-01-19 14:49:31 -0800382 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800383 hosts = []
384 hosts.append( main.ONOScli1.hosts() )
Jon Hall6aec96b2015-01-19 14:49:31 -0800385 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800386 ports = []
387 ports.append( main.ONOScli1.ports() )
388 links = []
389 links.append( main.ONOScli1.links() )
390
Jon Hall6aec96b2015-01-19 14:49:31 -0800391 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800392 devicesResults = main.TRUE
393 portsResults = main.TRUE
394 linksResults = main.TRUE
395 for controller in range( numControllers ):
396 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -0800397 if devices[ controller ] or "Error" not in devices[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -0800398 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -0800399 MNTopo,
400 json.loads(
401 devices[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800402 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800403 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800404 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800405 actual=currentDevicesResult,
406 onpass="ONOS" + controllerStr +
407 " Switches view is correct",
408 onfail="ONOS" + controllerStr +
409 " Switches view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800410
Jon Hall6aec96b2015-01-19 14:49:31 -0800411 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -0800412 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -0800413 MNTopo,
414 json.loads(
415 ports[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800416 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800417 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800418 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800419 actual=currentPortsResult,
420 onpass="ONOS" + controllerStr +
421 " ports view is correct",
422 onfail="ONOS" + controllerStr +
423 " ports view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800424
Jon Hall6aec96b2015-01-19 14:49:31 -0800425 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -0800426 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -0800427 MNTopo,
428 json.loads(
429 links[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800430 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800431 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800432 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800433 actual=currentLinksResult,
434 onpass="ONOS" + controllerStr +
435 " links view is correct",
436 onfail="ONOS" + controllerStr +
437 " links view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800438
Jon Hall8f89dda2015-01-22 16:03:33 -0800439 devicesResults = devicesResults and currentDevicesResult
440 portsResults = portsResults and currentPortsResult
441 linksResults = linksResults and currentLinksResult
Jon Hall73cf9cc2014-11-20 22:28:38 -0800442
Jon Hall8f89dda2015-01-22 16:03:33 -0800443 topoResult = devicesResults and portsResults and linksResults
444 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
445 onpass="Topology Check Test successful",
446 onfail="Topology Check Test NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800447
Jon Hall8f89dda2015-01-22 16:03:33 -0800448 finalAssert = main.TRUE
449 finalAssert = finalAssert and topoResult and flowCheck \
450 and intentCheck and consistentMastership and rolesNotNull
451 utilities.assert_equals( expect=main.TRUE, actual=finalAssert,
452 onpass="State check successful",
453 onfail="State check NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800454
Jon Hall6aec96b2015-01-19 14:49:31 -0800455 def CASE6( self, main ):
456 """
Jon Hallffb386d2014-11-21 13:43:38 -0800457 The Failure case.
Jon Hall6aec96b2015-01-19 14:49:31 -0800458 """
Jon Hallffb386d2014-11-21 13:43:38 -0800459 import time
Jon Hall73cf9cc2014-11-20 22:28:38 -0800460
Jon Hall6aec96b2015-01-19 14:49:31 -0800461 main.log.report( "Restart ONOS node" )
462 main.log.case( "Restart ONOS node" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800463 main.ONOSbench.onosKill( ONOS1Ip )
Jon Hallffb386d2014-11-21 13:43:38 -0800464 start = time.time()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800465
Jon Hall6aec96b2015-01-19 14:49:31 -0800466 main.step( "Checking if ONOS is up yet" )
Jon Hallffb386d2014-11-21 13:43:38 -0800467 count = 0
Jon Hall94fd0472014-12-08 11:52:42 -0800468 while count < 10:
Jon Hall8f89dda2015-01-22 16:03:33 -0800469 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
470 if onos1Isup == main.TRUE:
Jon Hallffb386d2014-11-21 13:43:38 -0800471 elapsed = time.time() - start
472 break
473 else:
474 count = count + 1
Jon Hall73cf9cc2014-11-20 22:28:38 -0800475
Jon Hall8f89dda2015-01-22 16:03:33 -0800476 cliResult = main.ONOScli1.startOnosCli( ONOS1Ip )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800477
Jon Hall8f89dda2015-01-22 16:03:33 -0800478 caseResults = main.TRUE and onos1Isup and cliResult
479 utilities.assert_equals( expect=main.TRUE, actual=caseResults,
480 onpass="ONOS restart successful",
481 onfail="ONOS restart NOT successful" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800482 main.log.info(
483 "ESTIMATE: ONOS took %s seconds to restart" %
484 str( elapsed ) )
485 time.sleep( 5 )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800486
Jon Hall6aec96b2015-01-19 14:49:31 -0800487 def CASE7( self, main ):
488 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800489 Check state after ONOS failure
Jon Hall6aec96b2015-01-19 14:49:31 -0800490 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800491 import json
Jon Hall6aec96b2015-01-19 14:49:31 -0800492 main.case( "Running ONOS Constant State Tests" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800493
Jon Hall6aec96b2015-01-19 14:49:31 -0800494 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -0800495 rolesNotNull = main.ONOScli1.rolesNotNull()
Jon Hall6aec96b2015-01-19 14:49:31 -0800496 utilities.assert_equals(
497 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800498 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -0800499 onpass="Each device has a master",
500 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -0800501
Jon Hall6aec96b2015-01-19 14:49:31 -0800502 main.step( "Check if switch roles are consistent across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800503 ONOS1Mastership = main.ONOScli1.roles()
Jon Hall6aec96b2015-01-19 14:49:31 -0800504 # FIXME: Refactor this whole case for single instance
Jon Hall8f89dda2015-01-22 16:03:33 -0800505 if "Error" in ONOS1Mastership or not ONOS1Mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -0800506 main.log.report( "Error in getting ONOS mastership" )
507 main.log.warn(
508 "ONOS1 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800509 repr( ONOS1Mastership ) )
510 consistentMastership = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800511 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800512 consistentMastership = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800513 main.log.report(
514 "Switch roles are consistent across all ONOS nodes" )
515 utilities.assert_equals(
516 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800517 actual=consistentMastership,
Jon Hall6aec96b2015-01-19 14:49:31 -0800518 onpass="Switch roles are consistent across all ONOS nodes",
519 onfail="ONOS nodes have different views of switch roles" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800520
521 description2 = "Compare switch roles from before failure"
Jon Hall6aec96b2015-01-19 14:49:31 -0800522 main.step( description2 )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800523
Jon Hall8f89dda2015-01-22 16:03:33 -0800524 currentJson = json.loads( ONOS1Mastership )
525 oldJson = json.loads( mastershipState )
526 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800527 for i in range( 1, 29 ):
528 switchDPID = str(
529 main.Mininet1.getSwitchDPID(
530 switch="s" +
531 str( i ) ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800532
Jon Hall8f89dda2015-01-22 16:03:33 -0800533 current = [ switch[ 'master' ] for switch in currentJson
Jon Hall6aec96b2015-01-19 14:49:31 -0800534 if switchDPID in switch[ 'id' ] ]
Jon Hall8f89dda2015-01-22 16:03:33 -0800535 old = [ switch[ 'master' ] for switch in oldJson
Jon Hall6aec96b2015-01-19 14:49:31 -0800536 if switchDPID in switch[ 'id' ] ]
Jon Hall73cf9cc2014-11-20 22:28:38 -0800537 if current == old:
Jon Hall8f89dda2015-01-22 16:03:33 -0800538 mastershipCheck = mastershipCheck and main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800539 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800540 main.log.warn( "Mastership of switch %s changed" % switchDPID )
Jon Hall8f89dda2015-01-22 16:03:33 -0800541 mastershipCheck = main.FALSE
542 if mastershipCheck == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800543 main.log.report( "Mastership of Switches was not changed" )
544 utilities.assert_equals(
545 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800546 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800547 onpass="Mastership of Switches was not changed",
548 onfail="Mastership of some switches changed" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800549 mastershipCheck = mastershipCheck and consistentMastership
Jon Hall73cf9cc2014-11-20 22:28:38 -0800550
Jon Hall6aec96b2015-01-19 14:49:31 -0800551 main.step( "Get the intents and compare across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800552 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
553 intentCheck = main.FALSE
554 if "Error" in ONOS1Intents or not ONOS1Intents:
Jon Hall6aec96b2015-01-19 14:49:31 -0800555 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800556 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800557 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800558 intentCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800559 main.log.report( "Intents are consistent across all ONOS nodes" )
560 utilities.assert_equals(
561 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800562 actual=intentCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800563 onpass="Intents are consistent across all ONOS nodes",
564 onfail="ONOS nodes have different views of intents" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800565
Jon Hall6aec96b2015-01-19 14:49:31 -0800566 # NOTE: Hazelcast has no durability, so intents are lost across system
567 # restarts
568 """
569 main.step( "Compare current intents with intents before the failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800570 # NOTE: this requires case 5 to pass for intentState to be set.
Jon Hall6aec96b2015-01-19 14:49:31 -0800571 # maybe we should stop the test if that fails?
Jon Hall8f89dda2015-01-22 16:03:33 -0800572 if intentState == ONOS1Intents:
573 sameIntents = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800574 main.log.report( "Intents are consistent with before failure" )
575 # TODO: possibly the states have changed? we may need to figure out
576 # what the aceptable states are
Jon Hall73cf9cc2014-11-20 22:28:38 -0800577 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800578 try:
579 main.log.warn( "ONOS1 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -0800580 print json.dumps( json.loads( ONOS1Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800581 sort_keys=True, indent=4,
582 separators=( ',', ': ' ) )
583 except:
584 pass
Jon Hall8f89dda2015-01-22 16:03:33 -0800585 sameIntents = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800586 utilities.assert_equals(
587 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800588 actual=sameIntents,
Jon Hall6aec96b2015-01-19 14:49:31 -0800589 onpass="Intents are consistent with before failure",
590 onfail="The Intents changed during failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800591 intentCheck = intentCheck and sameIntents
Jon Hall6aec96b2015-01-19 14:49:31 -0800592 """
593 main.step( "Get the OF Table entries and compare to before " +
594 "component failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800595 FlowTables = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800596 flows2 = []
597 for i in range( 28 ):
598 main.log.info( "Checking flow table on s" + str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800599 tmpFlows = main.Mininet2.getFlowTable( 1.3, "s" + str( i + 1 ) )
600 flows2.append( tmpFlows )
601 tempResult = main.Mininet2.flowComp(
Jon Hall6aec96b2015-01-19 14:49:31 -0800602 flow1=flows[ i ],
Jon Hall8f89dda2015-01-22 16:03:33 -0800603 flow2=tmpFlows )
604 FlowTables = FlowTables and tempResult
605 if FlowTables == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800606 main.log.info( "Differences in flow table for switch: s" +
607 str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800608 if FlowTables == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800609 main.log.report( "No changes were found in the flow tables" )
610 utilities.assert_equals(
611 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800612 actual=FlowTables,
Jon Hall6aec96b2015-01-19 14:49:31 -0800613 onpass="No changes were found in the flow tables",
614 onfail="Changes were found in the flow tables" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800615
Jon Hall6aec96b2015-01-19 14:49:31 -0800616 # Test of LeadershipElection
Jon Hall669173b2014-12-17 11:36:30 -0800617
Jon Hall8f89dda2015-01-22 16:03:33 -0800618 leader = ONOS1Ip
619 leaderResult = main.TRUE
620 for controller in range( 1, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -0800621 # loop through ONOScli handlers
622 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800623 leaderN = node.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -0800624 # verify leader is ONOS1
625 # NOTE even though we restarted ONOS, it is the only one so onos 1
626 # must be leader
Jon Hall669173b2014-12-17 11:36:30 -0800627 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -0800628 # all is well
Jon Hall669173b2014-12-17 11:36:30 -0800629 pass
630 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800631 # error in response
632 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800633 "electionTestLeader function, check the" +
Jon Hall6aec96b2015-01-19 14:49:31 -0800634 " error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800635 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -0800636 elif leader != leaderN:
Jon Hall8f89dda2015-01-22 16:03:33 -0800637 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800638 main.log.report( "ONOS" + str( controller ) +
639 " sees " + str( leaderN ) +
640 " as the leader of the election app." +
641 " Leader should be " + str( leader ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800642 if leaderResult:
643 main.log.report( "Leadership election tests passed( consistent " +
Jon Hall6aec96b2015-01-19 14:49:31 -0800644 "view of leader across listeners and a new " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800645 "leader was re-elected if applicable )" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800646 utilities.assert_equals(
647 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800648 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800649 onpass="Leadership election passed",
650 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -0800651
Jon Hall8f89dda2015-01-22 16:03:33 -0800652 result = ( mastershipCheck and intentCheck and FlowTables and
653 rolesNotNull and leaderResult )
Jon Hall6aec96b2015-01-19 14:49:31 -0800654 result = int( result )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800655 if result == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800656 main.log.report( "Constant State Tests Passed" )
657 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall8f89dda2015-01-22 16:03:33 -0800658 onpass="Constant State Tests Passed",
659 onfail="Constant state tests failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800660
Jon Hall6aec96b2015-01-19 14:49:31 -0800661 def CASE8( self, main ):
662 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800663 Compare topo
Jon Hall6aec96b2015-01-19 14:49:31 -0800664 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800665 import sys
Jon Hall6aec96b2015-01-19 14:49:31 -0800666 # FIXME add this path to params
667 sys.path.append( "/home/admin/sts" )
668 # assumes that sts is already in you PYTHONPATH
669 from sts.topology.teston_topology import TestONTopology
Jon Hall73cf9cc2014-11-20 22:28:38 -0800670 import json
671 import time
672
Jon Hall6aec96b2015-01-19 14:49:31 -0800673 description = "Compare ONOS Topology view to Mininet topology"
674 main.case( description )
675 main.log.report( description )
676 main.step( "Create TestONTopology object" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800677 ctrls = []
678 count = 1
679 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -0800680 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
681 temp = temp + ( "ONOS" + str( count ), )
682 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
683 temp = temp + \
684 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
685 ctrls.append( temp )
686 MNTopo = TestONTopology(
687 main.Mininet1,
688 ctrls ) # can also add Intent API info for intent operations
Jon Hall73cf9cc2014-11-20 22:28:38 -0800689
Jon Hall6aec96b2015-01-19 14:49:31 -0800690 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800691 devicesResults = main.TRUE
692 portsResults = main.TRUE
693 linksResults = main.TRUE
694 topoResult = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800695 elapsed = 0
Jon Hallffb386d2014-11-21 13:43:38 -0800696 count = 0
Jon Hall6aec96b2015-01-19 14:49:31 -0800697 main.step( "Collecting topology information from ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800698 startTime = time.time()
699 while topoResult == main.FALSE and elapsed < 60:
Jon Hallffb386d2014-11-21 13:43:38 -0800700 count = count + 1
Jon Hall94fd0472014-12-08 11:52:42 -0800701 if count > 1:
Jon Hall6aec96b2015-01-19 14:49:31 -0800702 MNTopo = TestONTopology(
703 main.Mininet1,
704 ctrls )
Jon Hall8f89dda2015-01-22 16:03:33 -0800705 cliStart = time.time()
Jon Hall94fd0472014-12-08 11:52:42 -0800706 devices = []
707 devices.append( main.ONOScli1.devices() )
Jon Hall6aec96b2015-01-19 14:49:31 -0800708 """
Jon Hall94fd0472014-12-08 11:52:42 -0800709 hosts = []
710 hosts.append( main.ONOScli1.hosts() )
Jon Hall6aec96b2015-01-19 14:49:31 -0800711 """
Jon Hall94fd0472014-12-08 11:52:42 -0800712 ports = []
713 ports.append( main.ONOScli1.ports() )
714 links = []
715 links.append( main.ONOScli1.links() )
Jon Hall8f89dda2015-01-22 16:03:33 -0800716 elapsed = time.time() - startTime
717 cliTime = time.time() - cliStart
718 print "CLI time: " + str( cliTime )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800719
Jon Hall8f89dda2015-01-22 16:03:33 -0800720 for controller in range( numControllers ):
721 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -0800722 if devices[ controller ] or "Error" not in devices[
723 controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -0800724 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -0800725 MNTopo,
726 json.loads(
727 devices[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800728 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800729 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800730 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800731 actual=currentDevicesResult,
732 onpass="ONOS" + controllerStr +
733 " Switches view is correct",
734 onfail="ONOS" + controllerStr +
735 " Switches view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800736
Jon Hall6aec96b2015-01-19 14:49:31 -0800737 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -0800738 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -0800739 MNTopo,
740 json.loads(
741 ports[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800742 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800743 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800744 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800745 actual=currentPortsResult,
746 onpass="ONOS" + controllerStr +
747 " ports view is correct",
748 onfail="ONOS" + controllerStr +
749 " ports view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800750
Jon Hall6aec96b2015-01-19 14:49:31 -0800751 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -0800752 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -0800753 MNTopo,
754 json.loads(
755 links[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800756 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800757 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800758 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800759 actual=currentLinksResult,
760 onpass="ONOS" + controllerStr +
761 " links view is correct",
762 onfail="ONOS" + controllerStr +
763 " links view is incorrect" )
764 devicesResults = devicesResults and currentDevicesResult
765 portsResults = portsResults and currentPortsResult
766 linksResults = linksResults and currentLinksResult
767 topoResult = devicesResults and portsResults and linksResults
Jon Hall94fd0472014-12-08 11:52:42 -0800768
Jon Hall8f89dda2015-01-22 16:03:33 -0800769 topoResult = topoResult and int( count <= 2 )
770 note = "note it takes about " + str( int( cliTime ) ) + \
771 " seconds for the test to make all the cli calls to fetch " +\
772 "the topology from each ONOS instance"
Jon Hall6aec96b2015-01-19 14:49:31 -0800773 main.log.report(
Jon Hall8f89dda2015-01-22 16:03:33 -0800774 "Very crass estimate for topology discovery/convergence( " +
775 str( note ) + " ): " + str( elapsed ) + " seconds, " +
Jon Hall6aec96b2015-01-19 14:49:31 -0800776 str( count ) + " tries" )
Jon Hall94fd0472014-12-08 11:52:42 -0800777 if elapsed > 60:
Jon Hall6aec96b2015-01-19 14:49:31 -0800778 main.log.report( "Giving up on topology convergence" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800779 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
780 onpass="Topology Check Test successful",
781 onfail="Topology Check Test NOT successful" )
782 if topoResult == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800783 main.log.report( "ONOS topology view matches Mininet topology" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800784
Jon Hall6aec96b2015-01-19 14:49:31 -0800785 def CASE9( self, main ):
786 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800787 Link s3-s28 down
Jon Hall6aec96b2015-01-19 14:49:31 -0800788 """
789 import time
790 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -0800791
Jon Hall8f89dda2015-01-22 16:03:33 -0800792 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800793
Jon Hall6aec96b2015-01-19 14:49:31 -0800794 description = "Turn off a link to ensure that Link Discovery " +\
Jon Hall8f89dda2015-01-22 16:03:33 -0800795 "is working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -0800796 main.log.report( description )
797 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800798
Jon Hall6aec96b2015-01-19 14:49:31 -0800799 main.step( "Kill Link between s3 and s28" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800800 LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800801 main.log.info(
802 "Waiting " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800803 str( linkSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -0800804 " seconds for link down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800805 time.sleep( linkSleep )
806 utilities.assert_equals( expect=main.TRUE, actual=LinkDown,
807 onpass="Link down succesful",
808 onfail="Failed to bring link down" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800809 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -0800810
Jon Hall6aec96b2015-01-19 14:49:31 -0800811 def CASE10( self, main ):
812 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800813 Link s3-s28 up
Jon Hall6aec96b2015-01-19 14:49:31 -0800814 """
815 import time
816 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -0800817
Jon Hall8f89dda2015-01-22 16:03:33 -0800818 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800819
Jon Hall6aec96b2015-01-19 14:49:31 -0800820 description = "Restore a link to ensure that Link Discovery is " + \
Jon Hall8f89dda2015-01-22 16:03:33 -0800821 "working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -0800822 main.log.report( description )
823 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800824
Jon Hall6aec96b2015-01-19 14:49:31 -0800825 main.step( "Bring link between s3 and s28 back up" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800826 LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800827 main.log.info(
828 "Waiting " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800829 str( linkSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -0800830 " seconds for link up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800831 time.sleep( linkSleep )
832 utilities.assert_equals( expect=main.TRUE, actual=LinkUp,
833 onpass="Link up succesful",
834 onfail="Failed to bring link up" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800835 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -0800836
Jon Hall6aec96b2015-01-19 14:49:31 -0800837 def CASE11( self, main ):
838 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800839 Switch Down
Jon Hall6aec96b2015-01-19 14:49:31 -0800840 """
841 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -0800842 import time
843
Jon Hall8f89dda2015-01-22 16:03:33 -0800844 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800845
846 description = "Killing a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -0800847 main.log.report( description )
848 main.case( description )
849 switch = main.params[ 'kill' ][ 'switch' ]
850 switchDPID = main.params[ 'kill' ][ 'dpid' ]
Jon Hall73cf9cc2014-11-20 22:28:38 -0800851
Jon Hall6aec96b2015-01-19 14:49:31 -0800852 # TODO: Make this switch parameterizable
853 main.step( "Kill " + switch )
854 main.log.report( "Deleting " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -0800855 main.Mininet1.delSwitch( switch )
856 main.log.info( "Waiting " + str( switchSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -0800857 " seconds for switch down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800858 time.sleep( switchSleep )
859 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -0800860 # Peek at the deleted switch
861 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800862 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800863 if device and device[ 'available' ] is False:
Jon Hall94fd0472014-12-08 11:52:42 -0800864 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800865 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall8f89dda2015-01-22 16:03:33 -0800866 onpass="Kill switch succesful",
867 onfail="Failed to kill switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800868
Jon Hall6aec96b2015-01-19 14:49:31 -0800869 def CASE12( self, main ):
870 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800871 Switch Up
Jon Hall6aec96b2015-01-19 14:49:31 -0800872 """
873 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -0800874 import time
Jon Hall669173b2014-12-17 11:36:30 -0800875
Jon Hall8f89dda2015-01-22 16:03:33 -0800876 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall6aec96b2015-01-19 14:49:31 -0800877 switch = main.params[ 'kill' ][ 'switch' ]
878 switchDPID = main.params[ 'kill' ][ 'dpid' ]
879 links = main.params[ 'kill' ][ 'links' ].split()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800880 description = "Adding a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -0800881 main.log.report( description )
882 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800883
Jon Hall6aec96b2015-01-19 14:49:31 -0800884 main.step( "Add back " + switch )
885 main.log.report( "Adding back " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -0800886 main.Mininet1.addSwitch( switch, dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -0800887 # TODO: New dpid or same? Ask Thomas?
888 for peer in links:
Jon Hall8f89dda2015-01-22 16:03:33 -0800889 main.Mininet1.addLink( switch, peer )
890 main.Mininet1.assignSwController( sw=switch.split( 's' )[ 1 ],
891 ip1=ONOS1Ip, port1=ONOS1Port )
Jon Hall6aec96b2015-01-19 14:49:31 -0800892 main.log.info(
893 "Waiting " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800894 str( switchSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -0800895 " seconds for switch up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800896 time.sleep( switchSleep )
897 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -0800898 # Peek at the deleted switch
899 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800900 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800901 if device and device[ 'available' ]:
Jon Hall94fd0472014-12-08 11:52:42 -0800902 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800903 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall8f89dda2015-01-22 16:03:33 -0800904 onpass="add switch succesful",
905 onfail="Failed to add switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800906
Jon Hall6aec96b2015-01-19 14:49:31 -0800907 def CASE13( self, main ):
908 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800909 Clean up
Jon Hall6aec96b2015-01-19 14:49:31 -0800910 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800911 import os
912 import time
Jon Hall6aec96b2015-01-19 14:49:31 -0800913 # printing colors to terminal
Jon Hall669173b2014-12-17 11:36:30 -0800914 colors = {}
Jon Hall6aec96b2015-01-19 14:49:31 -0800915 colors[ 'cyan' ] = '\033[96m'
916 colors[ 'purple' ] = '\033[95m'
917 colors[ 'blue' ] = '\033[94m'
918 colors[ 'green' ] = '\033[92m'
919 colors[ 'yellow' ] = '\033[93m'
920 colors[ 'red' ] = '\033[91m'
921 colors[ 'end' ] = '\033[0m'
Jon Hall73cf9cc2014-11-20 22:28:38 -0800922 description = "Test Cleanup"
Jon Hall6aec96b2015-01-19 14:49:31 -0800923 main.log.report( description )
924 main.case( description )
925 main.step( "Killing tcpdumps" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800926 main.Mininet2.stopTcpdump()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800927
Jon Hall6aec96b2015-01-19 14:49:31 -0800928 main.step( "Checking ONOS Logs for errors" )
929 print colors[ 'purple' ] + "Checking logs for errors on ONOS1:" + \
Jon Hall8f89dda2015-01-22 16:03:33 -0800930 colors[ 'end' ]
931 print main.ONOSbench.checkLogs( ONOS1Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800932 main.step( "Copying MN pcap and ONOS log files to test station" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800933 testname = main.TEST
Jon Hall8f89dda2015-01-22 16:03:33 -0800934 teststationUser = main.params[ 'TESTONUSER' ]
935 teststationIP = main.params[ 'TESTONIP' ]
Jon Hall6aec96b2015-01-19 14:49:31 -0800936 # NOTE: MN Pcap file is being saved to ~/packet_captures
Jon Hall73cf9cc2014-11-20 22:28:38 -0800937 # scp this file as MN and TestON aren't necessarily the same vm
Jon Hall6aec96b2015-01-19 14:49:31 -0800938 # FIXME: scp
939 # mn files
940 # TODO: Load these from params
941 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -0800942 logFolder = "/opt/onos/log/"
943 logFiles = [ "karaf.log", "karaf.log.1" ]
Jon Hall6aec96b2015-01-19 14:49:31 -0800944 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -0800945 dstDir = "~/packet_captures/"
946 for f in logFiles:
947 main.ONOSbench.handle.sendline( "scp sdn@" + ONOS1Ip + ":" +
948 logFolder + f + " " +
949 teststationUser + "@" +
950 teststationIP + ":" + dstDir +
Jon Hall6aec96b2015-01-19 14:49:31 -0800951 str( testname ) + "-ONOS1-" + f )
952 main.ONOSbench.handle.expect( "\$" )
Jon Hall94fd0472014-12-08 11:52:42 -0800953 print main.ONOSbench.handle.before
Jon Hall73cf9cc2014-11-20 22:28:38 -0800954
Jon Hall6aec96b2015-01-19 14:49:31 -0800955 # std*.log's
956 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -0800957 logFolder = "/opt/onos/var/"
958 logFiles = [ "stderr.log", "stdout.log" ]
Jon Hall6aec96b2015-01-19 14:49:31 -0800959 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -0800960 dstDir = "~/packet_captures/"
961 for f in logFiles:
962 main.ONOSbench.handle.sendline( "scp sdn@" + ONOS1Ip + ":" +
963 logFolder + f + " " +
964 teststationUser + "@" +
965 teststationIP + ":" + dstDir +
Jon Hall6aec96b2015-01-19 14:49:31 -0800966 str( testname ) + "-ONOS1-" + f )
967 # sleep so scp can finish
968 time.sleep( 10 )
969 main.step( "Packing and rotating pcap archives" )
970 os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800971
Jon Hall6aec96b2015-01-19 14:49:31 -0800972 # TODO: actually check something here
973 utilities.assert_equals( expect=main.TRUE, actual=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800974 onpass="Test cleanup successful",
975 onfail="Test cleanup NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800976
Jon Hall6aec96b2015-01-19 14:49:31 -0800977 def CASE14( self, main ):
978 """
Jon Hall669173b2014-12-17 11:36:30 -0800979 start election app on all onos nodes
Jon Hall6aec96b2015-01-19 14:49:31 -0800980 """
Jon Hall8f89dda2015-01-22 16:03:33 -0800981 leaderResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800982 # install app on onos 1
983 main.log.info( "Install leadership election app" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800984 main.ONOScli1.featureInstall( "onos-app-election" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800985 # wait for election
986 # check for leader
Jon Hall8f89dda2015-01-22 16:03:33 -0800987 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -0800988 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -0800989 if leader == ONOS1Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -0800990 # all is well
Jon Hall669173b2014-12-17 11:36:30 -0800991 pass
Jon Hall6aec96b2015-01-19 14:49:31 -0800992 elif leader is None:
993 # No leader elected
994 main.log.report( "No leader was elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800995 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -0800996 elif leader == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800997 # error in response
998 # TODO: add check for "Command not found:" in the driver, this
999 # means the app isn't loaded
Jon Hall8f89dda2015-01-22 16:03:33 -08001000 main.log.report( "Something is wrong with electionTestLeader" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001001 " function, check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001002 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001003 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001004 # error in response
1005 main.log.report(
Jon Hall8f89dda2015-01-22 16:03:33 -08001006 "Unexpected response from electionTestLeader function:'" +
1007 str( leader ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001008 "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001009 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001010
Jon Hall6aec96b2015-01-19 14:49:31 -08001011 # install on other nodes and check for leader.
1012 # Should be onos1 and each app should show the same leader
Jon Hall8f89dda2015-01-22 16:03:33 -08001013 for controller in range( 2, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001014 # loop through ONOScli handlers
1015 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001016 node.featureInstall( "onos-app-election" )
1017 leaderN = node.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001018 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08001019 if leaderN == ONOS1Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08001020 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001021 pass
1022 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001023 # error in response
1024 # TODO: add check for "Command not found:" in the driver, this
1025 # means the app isn't loaded
1026 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001027 "electionTestLeader function, check the" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001028 " error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001029 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001030 elif leader != leaderN:
Jon Hall8f89dda2015-01-22 16:03:33 -08001031 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001032 main.log.report( "ONOS" + str( controller ) + " sees " +
1033 str( leaderN ) +
1034 " as the leader of the election app. Leader" +
1035 " should be " +
1036 str( leader ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001037 if leaderResult:
Jon Hall6aec96b2015-01-19 14:49:31 -08001038 main.log.report( "Leadership election tests passed( consistent " +
1039 "view of leader across listeners and a leader " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001040 "was elected )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001041 utilities.assert_equals(
1042 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001043 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001044 onpass="Leadership election passed",
1045 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08001046
Jon Hall6aec96b2015-01-19 14:49:31 -08001047 def CASE15( self, main ):
1048 """
Jon Hall669173b2014-12-17 11:36:30 -08001049 Check that Leadership Election is still functional
Jon Hall6aec96b2015-01-19 14:49:31 -08001050 """
Jon Hall8f89dda2015-01-22 16:03:33 -08001051 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08001052 description = "Check that Leadership Election is still functional"
Jon Hall6aec96b2015-01-19 14:49:31 -08001053 main.log.report( description )
1054 main.case( description )
1055 main.step( "Find current leader and withdraw" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001056 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001057 # TODO: do some sanity checking on leader before using it
Jon Hall8f89dda2015-01-22 16:03:33 -08001058 withdrawResult = main.FALSE
1059 if leader == ONOS1Ip:
1060 oldLeader = getattr( main, "ONOScli1" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001061 elif leader is None or leader == main.FALSE:
1062 main.log.report(
1063 "Leader for the election app should be an ONOS node," +
1064 "instead got '" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001065 str( leader ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001066 "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001067 leaderResult = main.FALSE
1068 withdrawResult = oldLeader.electionTestWithdraw()
Jon Hall6aec96b2015-01-19 14:49:31 -08001069 utilities.assert_equals(
1070 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001071 actual=withdrawResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001072 onpass="App was withdrawn from election",
1073 onfail="App was not withdrawn from election" )
Jon Hall669173b2014-12-17 11:36:30 -08001074
Jon Hall6aec96b2015-01-19 14:49:31 -08001075 main.step( "Make sure new leader is elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001076 leaderList = []
1077 leaderN = main.ONOScli1.electionTestLeader()
Jon Hall669173b2014-12-17 11:36:30 -08001078 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08001079 main.log.report( "ONOS still sees " + str( leaderN ) +
1080 " as leader after they withdrew" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001081 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001082 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001083 # error in response
1084 # TODO: add check for "Command not found:" in the driver, this
1085 # means the app isn't loaded
Jon Hall8f89dda2015-01-22 16:03:33 -08001086 main.log.report( "Something is wrong with electionTestLeader " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001087 "function, check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001088 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001089 elif leaderN is None:
1090 main.log.info(
1091 "There is no leader after the app withdrew from election" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001092 if leaderResult:
1093 main.log.report( "Leadership election tests passed( There is no " +
1094 "leader after the old leader resigned )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001095 utilities.assert_equals(
1096 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001097 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001098 onpass="Leadership election passed",
1099 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08001100
Jon Hall6aec96b2015-01-19 14:49:31 -08001101 main.step(
Jon Hall8f89dda2015-01-22 16:03:33 -08001102 "Run for election on old leader( just so everyone is in the hat )" )
1103 runResult = oldLeader.electionTestRun()
Jon Hall6aec96b2015-01-19 14:49:31 -08001104 utilities.assert_equals(
1105 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001106 actual=runResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001107 onpass="App re-ran for election",
1108 onfail="App failed to run for election" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001109 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001110 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08001111 if leader == ONOS1Ip:
1112 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08001113 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001114 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001115 # TODO: assert on run and withdraw results?
Jon Hall669173b2014-12-17 11:36:30 -08001116
Jon Hall6aec96b2015-01-19 14:49:31 -08001117 utilities.assert_equals(
1118 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001119 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001120 onpass="Leadership election passed",
1121 onfail="ONOS1's election app was not leader after it re-ran " +
1122 "for election" )