blob: 2aea5bf2105e4df95e7b3630c94fd3e3d9fb8769 [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 Hall73cf9cc2014-11-20 22:28:38 -080052
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 Hall8f89dda2015-01-22 16:03:33 -0800111 main.ONOSbench.gitCheckout( "master" )
112 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 Hall8f89dda2015-01-22 16:03:33 -0800115 cleanInstallResult = main.TRUE
116
117 if gitPullResult == main.TRUE:
118 cleanInstallResult = main.ONOSbench.cleanInstall()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800119 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800120 main.log.warn( "Did not pull new code so skipping mvn " +
121 "clean install" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800122 main.ONOSbench.getVersion( report=True )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800123
Jon Hall8f89dda2015-01-22 16:03:33 -0800124 cellResult = main.ONOSbench.setCell( "SingleHA" )
125 verifyResult = main.ONOSbench.verifyCell()
Jon Hall6aec96b2015-01-19 14:49:31 -0800126 main.step( "Creating ONOS package" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800127 packageResult = main.ONOSbench.onosPackage()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800128
Jon Hall6aec96b2015-01-19 14:49:31 -0800129 main.step( "Installing ONOS package" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800130 onos1InstallResult = main.ONOSbench.onosInstall( options="-f",
131 node=ONOS1Ip )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800132
Jon Hall6aec96b2015-01-19 14:49:31 -0800133 main.step( "Checking if ONOS is up yet" )
134 # TODO check bundle:list?
135 for i in range( 2 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800136 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
137 if onos1Isup:
Jon Hall94fd0472014-12-08 11:52:42 -0800138 break
Jon Hall8f89dda2015-01-22 16:03:33 -0800139 if not onos1Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800140 main.log.report( "ONOS1 didn't start!" )
Jon Hall94fd0472014-12-08 11:52:42 -0800141
Jon Hall8f89dda2015-01-22 16:03:33 -0800142 cliResult = main.ONOScli1.startOnosCli( ONOS1Ip )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800143
Jon Hall6aec96b2015-01-19 14:49:31 -0800144 main.step( "Start Packet Capture MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800145 main.Mininet2.startTcpdump(
Jon Hall6aec96b2015-01-19 14:49:31 -0800146 str( main.params[ 'MNtcpdump' ][ 'folder' ] ) + str( main.TEST )
147 + "-MN.pcap",
148 intf=main.params[ 'MNtcpdump' ][ 'intf' ],
149 port=main.params[ 'MNtcpdump' ][ 'port' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800150
Jon Hall8f89dda2015-01-22 16:03:33 -0800151 case1Result = ( cleanInstallResult and packageResult and
152 cellResult and verifyResult and onos1InstallResult
153 and onos1Isup and cliResult )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800154
Jon Hall8f89dda2015-01-22 16:03:33 -0800155 utilities.assert_equals( expect=main.TRUE, actual=case1Result,
156 onpass="Test startup successful",
157 onfail="Test startup NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800158
Jon Hall8f89dda2015-01-22 16:03:33 -0800159 if case1Result == main.FALSE:
Jon Hall73cf9cc2014-11-20 22:28:38 -0800160 main.cleanup()
161 main.exit()
162
Jon Hall6aec96b2015-01-19 14:49:31 -0800163 def CASE2( self, main ):
164 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800165 Assign mastership to controllers
Jon Hall6aec96b2015-01-19 14:49:31 -0800166 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800167 import re
168
Jon Hall6aec96b2015-01-19 14:49:31 -0800169 main.log.report( "Assigning switches to controllers" )
170 main.case( "Assigning Controllers" )
171 main.step( "Assign switches to controllers" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800172
Jon Hall6aec96b2015-01-19 14:49:31 -0800173 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800174 main.Mininet1.assignSwController(
Jon Hall6aec96b2015-01-19 14:49:31 -0800175 sw=str( i ),
Jon Hall8f89dda2015-01-22 16:03:33 -0800176 ip1=ONOS1Ip, port1=ONOS1Port )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800177
Jon Hall8f89dda2015-01-22 16:03:33 -0800178 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800179 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800180 response = main.Mininet1.getSwController( "s" + str( i ) )
Jon Hallffb386d2014-11-21 13:43:38 -0800181 try:
Jon Hall6aec96b2015-01-19 14:49:31 -0800182 main.log.info( str( response ) )
Jon Hallffb386d2014-11-21 13:43:38 -0800183 except:
Jon Hall6aec96b2015-01-19 14:49:31 -0800184 main.log.info( repr( response ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800185 if re.search( "tcp:" + ONOS1Ip, response ):
186 mastershipCheck = mastershipCheck and main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800187 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800188 mastershipCheck = main.FALSE
189 if mastershipCheck == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800190 main.log.report( "Switch mastership assigned correctly" )
191 utilities.assert_equals(
192 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800193 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800194 onpass="Switch mastership assigned correctly",
195 onfail="Switches not assigned correctly to controllers" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800196
Jon Hall6aec96b2015-01-19 14:49:31 -0800197 def CASE3( self, main ):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800198 """
199 Assign intents
200
201 """
Jon Hall6aec96b2015-01-19 14:49:31 -0800202 # FIXME: we must reinstall intents until we have a persistant
203 # datastore!
Jon Hall73cf9cc2014-11-20 22:28:38 -0800204 import time
Jon Hall6aec96b2015-01-19 14:49:31 -0800205 main.log.report( "Adding host intents" )
206 main.case( "Adding host Intents" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800207
Jon Hall8f89dda2015-01-22 16:03:33 -0800208 main.step( "Discovering Hosts( Via pingall for now )" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800209 # FIXME: Once we have a host discovery mechanism, use that instead
Jon Hall73cf9cc2014-11-20 22:28:38 -0800210
Jon Hall6aec96b2015-01-19 14:49:31 -0800211 # install onos-app-fwd
212 main.log.info( "Install reactive forwarding app" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800213 main.ONOScli1.featureInstall( "onos-app-fwd" )
Jon Hall94fd0472014-12-08 11:52:42 -0800214
Jon Hall6aec96b2015-01-19 14:49:31 -0800215 # REACTIVE FWD test
Jon Hall8f89dda2015-01-22 16:03:33 -0800216 pingResult = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800217 time1 = time.time()
Jon Hall8f89dda2015-01-22 16:03:33 -0800218 pingResult = main.Mininet1.pingall()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800219 time2 = time.time()
Jon Hall6aec96b2015-01-19 14:49:31 -0800220 main.log.info( "Time for pingall: %2f seconds" % ( time2 - time1 ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800221
Jon Hall6aec96b2015-01-19 14:49:31 -0800222 # uninstall onos-app-fwd
223 main.log.info( "Uninstall reactive forwarding app" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800224 main.ONOScli1.featureUninstall( "onos-app-fwd" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800225 # timeout for fwd flows
226 time.sleep( 10 )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800227
Jon Hall6aec96b2015-01-19 14:49:31 -0800228 main.step( "Add host intents" )
229 # TODO: move the host numbers to params
Jon Hall8f89dda2015-01-22 16:03:33 -0800230 intentAddResult = True
Jon Hall6aec96b2015-01-19 14:49:31 -0800231 for i in range( 8, 18 ):
232 main.log.info( "Adding host intent between h" + str( i ) +
233 " and h" + str( i + 10 ) )
234 host1 = "00:00:00:00:00:" + \
235 str( hex( i )[ 2: ] ).zfill( 2 ).upper()
236 host2 = "00:00:00:00:00:" + \
237 str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper()
Jon Hall8f89dda2015-01-22 16:03:33 -0800238 host1Id = main.ONOScli1.getHost( host1 )[ 'id' ]
239 host2Id = main.ONOScli1.getHost( host2 )[ 'id' ]
Jon Hall6aec96b2015-01-19 14:49:31 -0800240 # NOTE: get host can return None
Jon Hall8f89dda2015-01-22 16:03:33 -0800241 if host1Id and host2Id:
242 tmpResult = main.ONOScli1.addHostIntent(
243 host1Id,
244 host2Id )
Jon Hall669173b2014-12-17 11:36:30 -0800245 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800246 main.log.error( "Error, getHost() failed" )
247 tmpResult = main.FALSE
248 intentAddResult = bool( pingResult and intentAddResult
249 and tmpResult )
Jon Hall6aec96b2015-01-19 14:49:31 -0800250 utilities.assert_equals(
251 expect=True,
Jon Hall8f89dda2015-01-22 16:03:33 -0800252 actual=intentAddResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800253 onpass="Switch mastership correctly assigned",
Jon Hall8f89dda2015-01-22 16:03:33 -0800254 onfail="Error in ( re )assigning switch mastership" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800255 # TODO Check if intents all exist in datastore
Jon Hall73cf9cc2014-11-20 22:28:38 -0800256
Jon Hall6aec96b2015-01-19 14:49:31 -0800257 def CASE4( self, main ):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800258 """
259 Ping across added host intents
260 """
261 description = " Ping across added host intents"
Jon Hall6aec96b2015-01-19 14:49:31 -0800262 main.log.report( description )
263 main.case( description )
Jon Hall8f89dda2015-01-22 16:03:33 -0800264 PingResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800265 for i in range( 8, 18 ):
266 ping = main.Mininet1.pingHost(
267 src="h" + str( i ), target="h" + str( i + 10 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800268 PingResult = PingResult and ping
Jon Hall6aec96b2015-01-19 14:49:31 -0800269 if ping == main.FALSE:
270 main.log.warn( "Ping failed between h" + str( i ) +
271 " and h" + str( i + 10 ) )
272 elif ping == main.TRUE:
273 main.log.info( "Ping test passed!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800274 PingResult = main.TRUE
275 if PingResult == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800276 main.log.report(
277 "Intents have not been installed correctly, pings failed." )
Jon Hall8f89dda2015-01-22 16:03:33 -0800278 if PingResult == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800279 main.log.report(
280 "Intents have been installed correctly and verified by pings" )
281 utilities.assert_equals(
282 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800283 actual=PingResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800284 onpass="Intents have been installed correctly and pings work",
285 onfail="Intents have not been installed correctly, pings failed." )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800286
Jon Hall6aec96b2015-01-19 14:49:31 -0800287 def CASE5( self, main ):
288 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800289 Reading state of ONOS
Jon Hall6aec96b2015-01-19 14:49:31 -0800290 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800291 import json
Jon Hall6aec96b2015-01-19 14:49:31 -0800292 # assumes that sts is already in you PYTHONPATH
293 from sts.topology.teston_topology import TestONTopology
Jon Hall73cf9cc2014-11-20 22:28:38 -0800294
Jon Hall6aec96b2015-01-19 14:49:31 -0800295 main.log.report( "Setting up and gathering data for current state" )
296 main.case( "Setting up and gathering data for current state" )
297 # The general idea for this test case is to pull the state of
298 # ( intents,flows, topology,... ) from each ONOS node
299 # We can then compare them with eachother and also with past states
Jon Hall73cf9cc2014-11-20 22:28:38 -0800300
Jon Hall6aec96b2015-01-19 14:49:31 -0800301 main.step( "Get the Mastership of each switch from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800302 global mastershipState
303 mastershipState = []
Jon Hall94fd0472014-12-08 11:52:42 -0800304
Jon Hall6aec96b2015-01-19 14:49:31 -0800305 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -0800306 rolesNotNull = main.ONOScli1.rolesNotNull()
Jon Hall6aec96b2015-01-19 14:49:31 -0800307 utilities.assert_equals(
308 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800309 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -0800310 onpass="Each device has a master",
311 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -0800312
Jon Hall8f89dda2015-01-22 16:03:33 -0800313 ONOS1Mastership = main.ONOScli1.roles()
Jon Hall6aec96b2015-01-19 14:49:31 -0800314 # TODO: Make this a meaningful check
Jon Hall8f89dda2015-01-22 16:03:33 -0800315 if "Error" in ONOS1Mastership or not ONOS1Mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -0800316 main.log.report( "Error in getting ONOS roles" )
317 main.log.warn(
318 "ONOS1 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800319 repr( ONOS1Mastership ) )
320 consistentMastership = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800321 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800322 mastershipState = ONOS1Mastership
323 consistentMastership = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800324
Jon Hall6aec96b2015-01-19 14:49:31 -0800325 main.step( "Get the intents from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800326 global intentState
327 intentState = []
328 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
329 intentCheck = main.FALSE
330 if "Error" in ONOS1Intents or not ONOS1Intents:
Jon Hall6aec96b2015-01-19 14:49:31 -0800331 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800332 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800333 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800334 intentCheck = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800335
Jon Hall6aec96b2015-01-19 14:49:31 -0800336 main.step( "Get the flows from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800337 global flowState
338 flowState = []
339 ONOS1Flows = main.ONOScli1.flows( jsonFormat=True )
340 flowCheck = main.FALSE
341 if "Error" in ONOS1Flows or not ONOS1Flows:
Jon Hall6aec96b2015-01-19 14:49:31 -0800342 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800343 main.log.warn( "ONOS1 flows repsponse: " + ONOS1Flows )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800344 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800345 # TODO: Do a better check, maybe compare flows on switches?
Jon Hall8f89dda2015-01-22 16:03:33 -0800346 flowState = ONOS1Flows
347 flowCheck = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800348
Jon Hall6aec96b2015-01-19 14:49:31 -0800349 main.step( "Get the OF Table entries" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800350 global flows
Jon Hall6aec96b2015-01-19 14:49:31 -0800351 flows = []
352 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800353 flows.append( main.Mininet2.getFlowTable( 1.3, "s" + str( i ) ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800354
Jon Hall6aec96b2015-01-19 14:49:31 -0800355 # TODO: Compare switch flow tables with ONOS flow tables
Jon Hall73cf9cc2014-11-20 22:28:38 -0800356
Jon Hall6aec96b2015-01-19 14:49:31 -0800357 main.step( "Create TestONTopology object" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800358 ctrls = []
359 count = 1
360 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -0800361 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
362 temp = temp + ( "ONOS" + str( count ), )
363 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
364 temp = temp + \
365 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
366 ctrls.append( temp )
367 MNTopo = TestONTopology(
368 main.Mininet1,
369 ctrls ) # can also add Intent API info for intent operations
Jon Hall73cf9cc2014-11-20 22:28:38 -0800370
Jon Hall6aec96b2015-01-19 14:49:31 -0800371 main.step( "Collecting topology information from ONOS" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800372 devices = []
373 devices.append( main.ONOScli1.devices() )
Jon Hall6aec96b2015-01-19 14:49:31 -0800374 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800375 hosts = []
376 hosts.append( main.ONOScli1.hosts() )
Jon Hall6aec96b2015-01-19 14:49:31 -0800377 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800378 ports = []
379 ports.append( main.ONOScli1.ports() )
380 links = []
381 links.append( main.ONOScli1.links() )
382
Jon Hall6aec96b2015-01-19 14:49:31 -0800383 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800384 devicesResults = main.TRUE
385 portsResults = main.TRUE
386 linksResults = main.TRUE
387 for controller in range( numControllers ):
388 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -0800389 if devices[ controller ] or "Error" not in devices[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -0800390 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -0800391 MNTopo,
392 json.loads(
393 devices[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800394 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800395 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800396 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800397 actual=currentDevicesResult,
398 onpass="ONOS" + controllerStr +
399 " Switches view is correct",
400 onfail="ONOS" + controllerStr +
401 " Switches view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800402
Jon Hall6aec96b2015-01-19 14:49:31 -0800403 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -0800404 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -0800405 MNTopo,
406 json.loads(
407 ports[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800408 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800409 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800410 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800411 actual=currentPortsResult,
412 onpass="ONOS" + controllerStr +
413 " ports view is correct",
414 onfail="ONOS" + controllerStr +
415 " ports view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800416
Jon Hall6aec96b2015-01-19 14:49:31 -0800417 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -0800418 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -0800419 MNTopo,
420 json.loads(
421 links[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800422 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800423 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800424 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800425 actual=currentLinksResult,
426 onpass="ONOS" + controllerStr +
427 " links view is correct",
428 onfail="ONOS" + controllerStr +
429 " links view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800430
Jon Hall8f89dda2015-01-22 16:03:33 -0800431 devicesResults = devicesResults and currentDevicesResult
432 portsResults = portsResults and currentPortsResult
433 linksResults = linksResults and currentLinksResult
Jon Hall73cf9cc2014-11-20 22:28:38 -0800434
Jon Hall8f89dda2015-01-22 16:03:33 -0800435 topoResult = devicesResults and portsResults and linksResults
436 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
437 onpass="Topology Check Test successful",
438 onfail="Topology Check Test NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800439
Jon Hall8f89dda2015-01-22 16:03:33 -0800440 finalAssert = main.TRUE
441 finalAssert = finalAssert and topoResult and flowCheck \
442 and intentCheck and consistentMastership and rolesNotNull
443 utilities.assert_equals( expect=main.TRUE, actual=finalAssert,
444 onpass="State check successful",
445 onfail="State check NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800446
Jon Hall6aec96b2015-01-19 14:49:31 -0800447 def CASE6( self, main ):
448 """
Jon Hallffb386d2014-11-21 13:43:38 -0800449 The Failure case.
Jon Hall6aec96b2015-01-19 14:49:31 -0800450 """
Jon Hallffb386d2014-11-21 13:43:38 -0800451 import time
Jon Hall73cf9cc2014-11-20 22:28:38 -0800452
Jon Hall6aec96b2015-01-19 14:49:31 -0800453 main.log.report( "Restart ONOS node" )
454 main.log.case( "Restart ONOS node" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800455 main.ONOSbench.onosKill( ONOS1Ip )
Jon Hallffb386d2014-11-21 13:43:38 -0800456 start = time.time()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800457
Jon Hall6aec96b2015-01-19 14:49:31 -0800458 main.step( "Checking if ONOS is up yet" )
Jon Hallffb386d2014-11-21 13:43:38 -0800459 count = 0
Jon Hall94fd0472014-12-08 11:52:42 -0800460 while count < 10:
Jon Hall8f89dda2015-01-22 16:03:33 -0800461 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
462 if onos1Isup == main.TRUE:
Jon Hallffb386d2014-11-21 13:43:38 -0800463 elapsed = time.time() - start
464 break
465 else:
466 count = count + 1
Jon Hall73cf9cc2014-11-20 22:28:38 -0800467
Jon Hall8f89dda2015-01-22 16:03:33 -0800468 cliResult = main.ONOScli1.startOnosCli( ONOS1Ip )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800469
Jon Hall8f89dda2015-01-22 16:03:33 -0800470 caseResults = main.TRUE and onos1Isup and cliResult
471 utilities.assert_equals( expect=main.TRUE, actual=caseResults,
472 onpass="ONOS restart successful",
473 onfail="ONOS restart NOT successful" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800474 main.log.info(
475 "ESTIMATE: ONOS took %s seconds to restart" %
476 str( elapsed ) )
477 time.sleep( 5 )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800478
Jon Hall6aec96b2015-01-19 14:49:31 -0800479 def CASE7( self, main ):
480 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800481 Check state after ONOS failure
Jon Hall6aec96b2015-01-19 14:49:31 -0800482 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800483 import json
Jon Hall6aec96b2015-01-19 14:49:31 -0800484 main.case( "Running ONOS Constant State Tests" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800485
Jon Hall6aec96b2015-01-19 14:49:31 -0800486 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -0800487 rolesNotNull = main.ONOScli1.rolesNotNull()
Jon Hall6aec96b2015-01-19 14:49:31 -0800488 utilities.assert_equals(
489 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800490 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -0800491 onpass="Each device has a master",
492 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -0800493
Jon Hall6aec96b2015-01-19 14:49:31 -0800494 main.step( "Check if switch roles are consistent across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800495 ONOS1Mastership = main.ONOScli1.roles()
Jon Hall6aec96b2015-01-19 14:49:31 -0800496 # FIXME: Refactor this whole case for single instance
Jon Hall8f89dda2015-01-22 16:03:33 -0800497 if "Error" in ONOS1Mastership or not ONOS1Mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -0800498 main.log.report( "Error in getting ONOS mastership" )
499 main.log.warn(
500 "ONOS1 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800501 repr( ONOS1Mastership ) )
502 consistentMastership = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800503 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800504 consistentMastership = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800505 main.log.report(
506 "Switch roles are consistent across all ONOS nodes" )
507 utilities.assert_equals(
508 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800509 actual=consistentMastership,
Jon Hall6aec96b2015-01-19 14:49:31 -0800510 onpass="Switch roles are consistent across all ONOS nodes",
511 onfail="ONOS nodes have different views of switch roles" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800512
513 description2 = "Compare switch roles from before failure"
Jon Hall6aec96b2015-01-19 14:49:31 -0800514 main.step( description2 )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800515
Jon Hall8f89dda2015-01-22 16:03:33 -0800516 currentJson = json.loads( ONOS1Mastership )
517 oldJson = json.loads( mastershipState )
518 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800519 for i in range( 1, 29 ):
520 switchDPID = str(
521 main.Mininet1.getSwitchDPID(
522 switch="s" +
523 str( i ) ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800524
Jon Hall8f89dda2015-01-22 16:03:33 -0800525 current = [ switch[ 'master' ] for switch in currentJson
Jon Hall6aec96b2015-01-19 14:49:31 -0800526 if switchDPID in switch[ 'id' ] ]
Jon Hall8f89dda2015-01-22 16:03:33 -0800527 old = [ switch[ 'master' ] for switch in oldJson
Jon Hall6aec96b2015-01-19 14:49:31 -0800528 if switchDPID in switch[ 'id' ] ]
Jon Hall73cf9cc2014-11-20 22:28:38 -0800529 if current == old:
Jon Hall8f89dda2015-01-22 16:03:33 -0800530 mastershipCheck = mastershipCheck and main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800531 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800532 main.log.warn( "Mastership of switch %s changed" % switchDPID )
Jon Hall8f89dda2015-01-22 16:03:33 -0800533 mastershipCheck = main.FALSE
534 if mastershipCheck == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800535 main.log.report( "Mastership of Switches was not changed" )
536 utilities.assert_equals(
537 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800538 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800539 onpass="Mastership of Switches was not changed",
540 onfail="Mastership of some switches changed" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800541 mastershipCheck = mastershipCheck and consistentMastership
Jon Hall73cf9cc2014-11-20 22:28:38 -0800542
Jon Hall6aec96b2015-01-19 14:49:31 -0800543 main.step( "Get the intents and compare across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800544 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
545 intentCheck = main.FALSE
546 if "Error" in ONOS1Intents or not ONOS1Intents:
Jon Hall6aec96b2015-01-19 14:49:31 -0800547 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800548 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800549 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800550 intentCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800551 main.log.report( "Intents are consistent across all ONOS nodes" )
552 utilities.assert_equals(
553 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800554 actual=intentCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800555 onpass="Intents are consistent across all ONOS nodes",
556 onfail="ONOS nodes have different views of intents" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800557
Jon Hall6aec96b2015-01-19 14:49:31 -0800558 # NOTE: Hazelcast has no durability, so intents are lost across system
559 # restarts
560 """
561 main.step( "Compare current intents with intents before the failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800562 # NOTE: this requires case 5 to pass for intentState to be set.
Jon Hall6aec96b2015-01-19 14:49:31 -0800563 # maybe we should stop the test if that fails?
Jon Hall8f89dda2015-01-22 16:03:33 -0800564 if intentState == ONOS1Intents:
565 sameIntents = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800566 main.log.report( "Intents are consistent with before failure" )
567 # TODO: possibly the states have changed? we may need to figure out
568 # what the aceptable states are
Jon Hall73cf9cc2014-11-20 22:28:38 -0800569 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800570 try:
571 main.log.warn( "ONOS1 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -0800572 print json.dumps( json.loads( ONOS1Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800573 sort_keys=True, indent=4,
574 separators=( ',', ': ' ) )
575 except:
576 pass
Jon Hall8f89dda2015-01-22 16:03:33 -0800577 sameIntents = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800578 utilities.assert_equals(
579 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800580 actual=sameIntents,
Jon Hall6aec96b2015-01-19 14:49:31 -0800581 onpass="Intents are consistent with before failure",
582 onfail="The Intents changed during failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800583 intentCheck = intentCheck and sameIntents
Jon Hall6aec96b2015-01-19 14:49:31 -0800584 """
585 main.step( "Get the OF Table entries and compare to before " +
586 "component failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800587 FlowTables = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800588 flows2 = []
589 for i in range( 28 ):
590 main.log.info( "Checking flow table on s" + str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800591 tmpFlows = main.Mininet2.getFlowTable( 1.3, "s" + str( i + 1 ) )
592 flows2.append( tmpFlows )
593 tempResult = main.Mininet2.flowComp(
Jon Hall6aec96b2015-01-19 14:49:31 -0800594 flow1=flows[ i ],
Jon Hall8f89dda2015-01-22 16:03:33 -0800595 flow2=tmpFlows )
596 FlowTables = FlowTables and tempResult
597 if FlowTables == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800598 main.log.info( "Differences in flow table for switch: s" +
599 str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800600 if FlowTables == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800601 main.log.report( "No changes were found in the flow tables" )
602 utilities.assert_equals(
603 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800604 actual=FlowTables,
Jon Hall6aec96b2015-01-19 14:49:31 -0800605 onpass="No changes were found in the flow tables",
606 onfail="Changes were found in the flow tables" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800607
Jon Hall6aec96b2015-01-19 14:49:31 -0800608 # Test of LeadershipElection
Jon Hall669173b2014-12-17 11:36:30 -0800609
Jon Hall8f89dda2015-01-22 16:03:33 -0800610 leader = ONOS1Ip
611 leaderResult = main.TRUE
612 for controller in range( 1, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -0800613 # loop through ONOScli handlers
614 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800615 leaderN = node.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -0800616 # verify leader is ONOS1
617 # NOTE even though we restarted ONOS, it is the only one so onos 1
618 # must be leader
Jon Hall669173b2014-12-17 11:36:30 -0800619 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -0800620 # all is well
Jon Hall669173b2014-12-17 11:36:30 -0800621 pass
622 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800623 # error in response
624 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800625 "electionTestLeader function, check the" +
Jon Hall6aec96b2015-01-19 14:49:31 -0800626 " error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800627 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -0800628 elif leader != leaderN:
Jon Hall8f89dda2015-01-22 16:03:33 -0800629 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800630 main.log.report( "ONOS" + str( controller ) +
631 " sees " + str( leaderN ) +
632 " as the leader of the election app." +
633 " Leader should be " + str( leader ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800634 if leaderResult:
635 main.log.report( "Leadership election tests passed( consistent " +
Jon Hall6aec96b2015-01-19 14:49:31 -0800636 "view of leader across listeners and a new " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800637 "leader was re-elected if applicable )" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800638 utilities.assert_equals(
639 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800640 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800641 onpass="Leadership election passed",
642 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -0800643
Jon Hall8f89dda2015-01-22 16:03:33 -0800644 result = ( mastershipCheck and intentCheck and FlowTables and
645 rolesNotNull and leaderResult )
Jon Hall6aec96b2015-01-19 14:49:31 -0800646 result = int( result )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800647 if result == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800648 main.log.report( "Constant State Tests Passed" )
649 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall8f89dda2015-01-22 16:03:33 -0800650 onpass="Constant State Tests Passed",
651 onfail="Constant state tests failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800652
Jon Hall6aec96b2015-01-19 14:49:31 -0800653 def CASE8( self, main ):
654 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800655 Compare topo
Jon Hall6aec96b2015-01-19 14:49:31 -0800656 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800657 import sys
Jon Hall6aec96b2015-01-19 14:49:31 -0800658 # FIXME add this path to params
659 sys.path.append( "/home/admin/sts" )
660 # assumes that sts is already in you PYTHONPATH
661 from sts.topology.teston_topology import TestONTopology
Jon Hall73cf9cc2014-11-20 22:28:38 -0800662 import json
663 import time
664
Jon Hall6aec96b2015-01-19 14:49:31 -0800665 description = "Compare ONOS Topology view to Mininet topology"
666 main.case( description )
667 main.log.report( description )
668 main.step( "Create TestONTopology object" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800669 ctrls = []
670 count = 1
671 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -0800672 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
673 temp = temp + ( "ONOS" + str( count ), )
674 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
675 temp = temp + \
676 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
677 ctrls.append( temp )
678 MNTopo = TestONTopology(
679 main.Mininet1,
680 ctrls ) # can also add Intent API info for intent operations
Jon Hall73cf9cc2014-11-20 22:28:38 -0800681
Jon Hall6aec96b2015-01-19 14:49:31 -0800682 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800683 devicesResults = main.TRUE
684 portsResults = main.TRUE
685 linksResults = main.TRUE
686 topoResult = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800687 elapsed = 0
Jon Hallffb386d2014-11-21 13:43:38 -0800688 count = 0
Jon Hall6aec96b2015-01-19 14:49:31 -0800689 main.step( "Collecting topology information from ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800690 startTime = time.time()
691 while topoResult == main.FALSE and elapsed < 60:
Jon Hallffb386d2014-11-21 13:43:38 -0800692 count = count + 1
Jon Hall94fd0472014-12-08 11:52:42 -0800693 if count > 1:
Jon Hall6aec96b2015-01-19 14:49:31 -0800694 MNTopo = TestONTopology(
695 main.Mininet1,
696 ctrls )
Jon Hall8f89dda2015-01-22 16:03:33 -0800697 cliStart = time.time()
Jon Hall94fd0472014-12-08 11:52:42 -0800698 devices = []
699 devices.append( main.ONOScli1.devices() )
Jon Hall6aec96b2015-01-19 14:49:31 -0800700 """
Jon Hall94fd0472014-12-08 11:52:42 -0800701 hosts = []
702 hosts.append( main.ONOScli1.hosts() )
Jon Hall6aec96b2015-01-19 14:49:31 -0800703 """
Jon Hall94fd0472014-12-08 11:52:42 -0800704 ports = []
705 ports.append( main.ONOScli1.ports() )
706 links = []
707 links.append( main.ONOScli1.links() )
Jon Hall8f89dda2015-01-22 16:03:33 -0800708 elapsed = time.time() - startTime
709 cliTime = time.time() - cliStart
710 print "CLI time: " + str( cliTime )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800711
Jon Hall8f89dda2015-01-22 16:03:33 -0800712 for controller in range( numControllers ):
713 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -0800714 if devices[ controller ] or "Error" not in devices[
715 controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -0800716 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -0800717 MNTopo,
718 json.loads(
719 devices[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800720 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800721 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800722 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800723 actual=currentDevicesResult,
724 onpass="ONOS" + controllerStr +
725 " Switches view is correct",
726 onfail="ONOS" + controllerStr +
727 " Switches view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800728
Jon Hall6aec96b2015-01-19 14:49:31 -0800729 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -0800730 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -0800731 MNTopo,
732 json.loads(
733 ports[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800734 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800735 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800736 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800737 actual=currentPortsResult,
738 onpass="ONOS" + controllerStr +
739 " ports view is correct",
740 onfail="ONOS" + controllerStr +
741 " ports view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800742
Jon Hall6aec96b2015-01-19 14:49:31 -0800743 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -0800744 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -0800745 MNTopo,
746 json.loads(
747 links[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800748 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800749 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800750 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800751 actual=currentLinksResult,
752 onpass="ONOS" + controllerStr +
753 " links view is correct",
754 onfail="ONOS" + controllerStr +
755 " links view is incorrect" )
756 devicesResults = devicesResults and currentDevicesResult
757 portsResults = portsResults and currentPortsResult
758 linksResults = linksResults and currentLinksResult
759 topoResult = devicesResults and portsResults and linksResults
Jon Hall94fd0472014-12-08 11:52:42 -0800760
Jon Hall8f89dda2015-01-22 16:03:33 -0800761 topoResult = topoResult and int( count <= 2 )
762 note = "note it takes about " + str( int( cliTime ) ) + \
763 " seconds for the test to make all the cli calls to fetch " +\
764 "the topology from each ONOS instance"
Jon Hall6aec96b2015-01-19 14:49:31 -0800765 main.log.report(
Jon Hall8f89dda2015-01-22 16:03:33 -0800766 "Very crass estimate for topology discovery/convergence( " +
767 str( note ) + " ): " + str( elapsed ) + " seconds, " +
Jon Hall6aec96b2015-01-19 14:49:31 -0800768 str( count ) + " tries" )
Jon Hall94fd0472014-12-08 11:52:42 -0800769 if elapsed > 60:
Jon Hall6aec96b2015-01-19 14:49:31 -0800770 main.log.report( "Giving up on topology convergence" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800771 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
772 onpass="Topology Check Test successful",
773 onfail="Topology Check Test NOT successful" )
774 if topoResult == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800775 main.log.report( "ONOS topology view matches Mininet topology" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800776
Jon Hall6aec96b2015-01-19 14:49:31 -0800777 def CASE9( self, main ):
778 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800779 Link s3-s28 down
Jon Hall6aec96b2015-01-19 14:49:31 -0800780 """
781 import time
782 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -0800783
Jon Hall8f89dda2015-01-22 16:03:33 -0800784 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800785
Jon Hall6aec96b2015-01-19 14:49:31 -0800786 description = "Turn off a link to ensure that Link Discovery " +\
Jon Hall8f89dda2015-01-22 16:03:33 -0800787 "is working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -0800788 main.log.report( description )
789 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800790
Jon Hall6aec96b2015-01-19 14:49:31 -0800791 main.step( "Kill Link between s3 and s28" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800792 LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800793 main.log.info(
794 "Waiting " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800795 str( linkSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -0800796 " seconds for link down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800797 time.sleep( linkSleep )
798 utilities.assert_equals( expect=main.TRUE, actual=LinkDown,
799 onpass="Link down succesful",
800 onfail="Failed to bring link down" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800801 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -0800802
Jon Hall6aec96b2015-01-19 14:49:31 -0800803 def CASE10( self, main ):
804 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800805 Link s3-s28 up
Jon Hall6aec96b2015-01-19 14:49:31 -0800806 """
807 import time
808 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -0800809
Jon Hall8f89dda2015-01-22 16:03:33 -0800810 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800811
Jon Hall6aec96b2015-01-19 14:49:31 -0800812 description = "Restore a link to ensure that Link Discovery is " + \
Jon Hall8f89dda2015-01-22 16:03:33 -0800813 "working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -0800814 main.log.report( description )
815 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800816
Jon Hall6aec96b2015-01-19 14:49:31 -0800817 main.step( "Bring link between s3 and s28 back up" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800818 LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800819 main.log.info(
820 "Waiting " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800821 str( linkSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -0800822 " seconds for link up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800823 time.sleep( linkSleep )
824 utilities.assert_equals( expect=main.TRUE, actual=LinkUp,
825 onpass="Link up succesful",
826 onfail="Failed to bring link up" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800827 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -0800828
Jon Hall6aec96b2015-01-19 14:49:31 -0800829 def CASE11( self, main ):
830 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800831 Switch Down
Jon Hall6aec96b2015-01-19 14:49:31 -0800832 """
833 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -0800834 import time
835
Jon Hall8f89dda2015-01-22 16:03:33 -0800836 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800837
838 description = "Killing a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -0800839 main.log.report( description )
840 main.case( description )
841 switch = main.params[ 'kill' ][ 'switch' ]
842 switchDPID = main.params[ 'kill' ][ 'dpid' ]
Jon Hall73cf9cc2014-11-20 22:28:38 -0800843
Jon Hall6aec96b2015-01-19 14:49:31 -0800844 # TODO: Make this switch parameterizable
845 main.step( "Kill " + switch )
846 main.log.report( "Deleting " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -0800847 main.Mininet1.delSwitch( switch )
848 main.log.info( "Waiting " + str( switchSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -0800849 " seconds for switch down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800850 time.sleep( switchSleep )
851 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -0800852 # Peek at the deleted switch
853 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800854 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800855 if device and device[ 'available' ] is False:
Jon Hall94fd0472014-12-08 11:52:42 -0800856 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800857 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall8f89dda2015-01-22 16:03:33 -0800858 onpass="Kill switch succesful",
859 onfail="Failed to kill switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800860
Jon Hall6aec96b2015-01-19 14:49:31 -0800861 def CASE12( self, main ):
862 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800863 Switch Up
Jon Hall6aec96b2015-01-19 14:49:31 -0800864 """
865 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -0800866 import time
Jon Hall669173b2014-12-17 11:36:30 -0800867
Jon Hall8f89dda2015-01-22 16:03:33 -0800868 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall6aec96b2015-01-19 14:49:31 -0800869 switch = main.params[ 'kill' ][ 'switch' ]
870 switchDPID = main.params[ 'kill' ][ 'dpid' ]
871 links = main.params[ 'kill' ][ 'links' ].split()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800872 description = "Adding a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -0800873 main.log.report( description )
874 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800875
Jon Hall6aec96b2015-01-19 14:49:31 -0800876 main.step( "Add back " + switch )
877 main.log.report( "Adding back " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -0800878 main.Mininet1.addSwitch( switch, dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -0800879 # TODO: New dpid or same? Ask Thomas?
880 for peer in links:
Jon Hall8f89dda2015-01-22 16:03:33 -0800881 main.Mininet1.addLink( switch, peer )
882 main.Mininet1.assignSwController( sw=switch.split( 's' )[ 1 ],
883 ip1=ONOS1Ip, port1=ONOS1Port )
Jon Hall6aec96b2015-01-19 14:49:31 -0800884 main.log.info(
885 "Waiting " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800886 str( switchSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -0800887 " seconds for switch up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800888 time.sleep( switchSleep )
889 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -0800890 # Peek at the deleted switch
891 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800892 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800893 if device and device[ 'available' ]:
Jon Hall94fd0472014-12-08 11:52:42 -0800894 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800895 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall8f89dda2015-01-22 16:03:33 -0800896 onpass="add switch succesful",
897 onfail="Failed to add switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800898
Jon Hall6aec96b2015-01-19 14:49:31 -0800899 def CASE13( self, main ):
900 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800901 Clean up
Jon Hall6aec96b2015-01-19 14:49:31 -0800902 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800903 import os
904 import time
Jon Hall6aec96b2015-01-19 14:49:31 -0800905 # printing colors to terminal
Jon Hall669173b2014-12-17 11:36:30 -0800906 colors = {}
Jon Hall6aec96b2015-01-19 14:49:31 -0800907 colors[ 'cyan' ] = '\033[96m'
908 colors[ 'purple' ] = '\033[95m'
909 colors[ 'blue' ] = '\033[94m'
910 colors[ 'green' ] = '\033[92m'
911 colors[ 'yellow' ] = '\033[93m'
912 colors[ 'red' ] = '\033[91m'
913 colors[ 'end' ] = '\033[0m'
Jon Hall73cf9cc2014-11-20 22:28:38 -0800914 description = "Test Cleanup"
Jon Hall6aec96b2015-01-19 14:49:31 -0800915 main.log.report( description )
916 main.case( description )
917 main.step( "Killing tcpdumps" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800918 main.Mininet2.stopTcpdump()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800919
Jon Hall6aec96b2015-01-19 14:49:31 -0800920 main.step( "Checking ONOS Logs for errors" )
921 print colors[ 'purple' ] + "Checking logs for errors on ONOS1:" + \
Jon Hall8f89dda2015-01-22 16:03:33 -0800922 colors[ 'end' ]
923 print main.ONOSbench.checkLogs( ONOS1Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800924 main.step( "Copying MN pcap and ONOS log files to test station" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800925 testname = main.TEST
Jon Hall8f89dda2015-01-22 16:03:33 -0800926 teststationUser = main.params[ 'TESTONUSER' ]
927 teststationIP = main.params[ 'TESTONIP' ]
Jon Hall6aec96b2015-01-19 14:49:31 -0800928 # NOTE: MN Pcap file is being saved to ~/packet_captures
Jon Hall73cf9cc2014-11-20 22:28:38 -0800929 # scp this file as MN and TestON aren't necessarily the same vm
Jon Hall6aec96b2015-01-19 14:49:31 -0800930 # FIXME: scp
931 # mn files
932 # TODO: Load these from params
933 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -0800934 logFolder = "/opt/onos/log/"
935 logFiles = [ "karaf.log", "karaf.log.1" ]
Jon Hall6aec96b2015-01-19 14:49:31 -0800936 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -0800937 dstDir = "~/packet_captures/"
938 for f in logFiles:
939 main.ONOSbench.handle.sendline( "scp sdn@" + ONOS1Ip + ":" +
940 logFolder + f + " " +
941 teststationUser + "@" +
942 teststationIP + ":" + dstDir +
Jon Hall6aec96b2015-01-19 14:49:31 -0800943 str( testname ) + "-ONOS1-" + f )
944 main.ONOSbench.handle.expect( "\$" )
Jon Hall94fd0472014-12-08 11:52:42 -0800945 print main.ONOSbench.handle.before
Jon Hall73cf9cc2014-11-20 22:28:38 -0800946
Jon Hall6aec96b2015-01-19 14:49:31 -0800947 # std*.log's
948 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -0800949 logFolder = "/opt/onos/var/"
950 logFiles = [ "stderr.log", "stdout.log" ]
Jon Hall6aec96b2015-01-19 14:49:31 -0800951 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -0800952 dstDir = "~/packet_captures/"
953 for f in logFiles:
954 main.ONOSbench.handle.sendline( "scp sdn@" + ONOS1Ip + ":" +
955 logFolder + f + " " +
956 teststationUser + "@" +
957 teststationIP + ":" + dstDir +
Jon Hall6aec96b2015-01-19 14:49:31 -0800958 str( testname ) + "-ONOS1-" + f )
959 # sleep so scp can finish
960 time.sleep( 10 )
961 main.step( "Packing and rotating pcap archives" )
962 os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800963
Jon Hall6aec96b2015-01-19 14:49:31 -0800964 # TODO: actually check something here
965 utilities.assert_equals( expect=main.TRUE, actual=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800966 onpass="Test cleanup successful",
967 onfail="Test cleanup NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800968
Jon Hall6aec96b2015-01-19 14:49:31 -0800969 def CASE14( self, main ):
970 """
Jon Hall669173b2014-12-17 11:36:30 -0800971 start election app on all onos nodes
Jon Hall6aec96b2015-01-19 14:49:31 -0800972 """
Jon Hall8f89dda2015-01-22 16:03:33 -0800973 leaderResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800974 # install app on onos 1
975 main.log.info( "Install leadership election app" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800976 main.ONOScli1.featureInstall( "onos-app-election" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800977 # wait for election
978 # check for leader
Jon Hall8f89dda2015-01-22 16:03:33 -0800979 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -0800980 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -0800981 if leader == ONOS1Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -0800982 # all is well
Jon Hall669173b2014-12-17 11:36:30 -0800983 pass
Jon Hall6aec96b2015-01-19 14:49:31 -0800984 elif leader is None:
985 # No leader elected
986 main.log.report( "No leader was elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800987 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -0800988 elif leader == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800989 # error in response
990 # TODO: add check for "Command not found:" in the driver, this
991 # means the app isn't loaded
Jon Hall8f89dda2015-01-22 16:03:33 -0800992 main.log.report( "Something is wrong with electionTestLeader" +
Jon Hall6aec96b2015-01-19 14:49:31 -0800993 " function, check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800994 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -0800995 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800996 # error in response
997 main.log.report(
Jon Hall8f89dda2015-01-22 16:03:33 -0800998 "Unexpected response from electionTestLeader function:'" +
999 str( leader ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001000 "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001001 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001002
Jon Hall6aec96b2015-01-19 14:49:31 -08001003 # install on other nodes and check for leader.
1004 # Should be onos1 and each app should show the same leader
Jon Hall8f89dda2015-01-22 16:03:33 -08001005 for controller in range( 2, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001006 # loop through ONOScli handlers
1007 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001008 node.featureInstall( "onos-app-election" )
1009 leaderN = node.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001010 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08001011 if leaderN == ONOS1Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08001012 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001013 pass
1014 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001015 # error in response
1016 # TODO: add check for "Command not found:" in the driver, this
1017 # means the app isn't loaded
1018 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001019 "electionTestLeader function, check the" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001020 " error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001021 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001022 elif leader != leaderN:
Jon Hall8f89dda2015-01-22 16:03:33 -08001023 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001024 main.log.report( "ONOS" + str( controller ) + " sees " +
1025 str( leaderN ) +
1026 " as the leader of the election app. Leader" +
1027 " should be " +
1028 str( leader ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001029 if leaderResult:
Jon Hall6aec96b2015-01-19 14:49:31 -08001030 main.log.report( "Leadership election tests passed( consistent " +
1031 "view of leader across listeners and a leader " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001032 "was elected )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001033 utilities.assert_equals(
1034 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001035 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001036 onpass="Leadership election passed",
1037 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08001038
Jon Hall6aec96b2015-01-19 14:49:31 -08001039 def CASE15( self, main ):
1040 """
Jon Hall669173b2014-12-17 11:36:30 -08001041 Check that Leadership Election is still functional
Jon Hall6aec96b2015-01-19 14:49:31 -08001042 """
Jon Hall8f89dda2015-01-22 16:03:33 -08001043 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08001044 description = "Check that Leadership Election is still functional"
Jon Hall6aec96b2015-01-19 14:49:31 -08001045 main.log.report( description )
1046 main.case( description )
1047 main.step( "Find current leader and withdraw" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001048 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001049 # TODO: do some sanity checking on leader before using it
Jon Hall8f89dda2015-01-22 16:03:33 -08001050 withdrawResult = main.FALSE
1051 if leader == ONOS1Ip:
1052 oldLeader = getattr( main, "ONOScli1" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001053 elif leader is None or leader == main.FALSE:
1054 main.log.report(
1055 "Leader for the election app should be an ONOS node," +
1056 "instead got '" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001057 str( leader ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001058 "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001059 leaderResult = main.FALSE
1060 withdrawResult = oldLeader.electionTestWithdraw()
Jon Hall6aec96b2015-01-19 14:49:31 -08001061 utilities.assert_equals(
1062 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001063 actual=withdrawResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001064 onpass="App was withdrawn from election",
1065 onfail="App was not withdrawn from election" )
Jon Hall669173b2014-12-17 11:36:30 -08001066
Jon Hall6aec96b2015-01-19 14:49:31 -08001067 main.step( "Make sure new leader is elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001068 leaderList = []
1069 leaderN = main.ONOScli1.electionTestLeader()
Jon Hall669173b2014-12-17 11:36:30 -08001070 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08001071 main.log.report( "ONOS still sees " + str( leaderN ) +
1072 " as leader after they withdrew" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001073 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001074 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001075 # error in response
1076 # TODO: add check for "Command not found:" in the driver, this
1077 # means the app isn't loaded
Jon Hall8f89dda2015-01-22 16:03:33 -08001078 main.log.report( "Something is wrong with electionTestLeader " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001079 "function, check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001080 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001081 elif leaderN is None:
1082 main.log.info(
1083 "There is no leader after the app withdrew from election" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001084 if leaderResult:
1085 main.log.report( "Leadership election tests passed( There is no " +
1086 "leader after the old leader resigned )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001087 utilities.assert_equals(
1088 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001089 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001090 onpass="Leadership election passed",
1091 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08001092
Jon Hall6aec96b2015-01-19 14:49:31 -08001093 main.step(
Jon Hall8f89dda2015-01-22 16:03:33 -08001094 "Run for election on old leader( just so everyone is in the hat )" )
1095 runResult = oldLeader.electionTestRun()
Jon Hall6aec96b2015-01-19 14:49:31 -08001096 utilities.assert_equals(
1097 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001098 actual=runResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001099 onpass="App re-ran for election",
1100 onfail="App failed to run for election" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001101 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001102 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08001103 if leader == ONOS1Ip:
1104 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08001105 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001106 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001107 # TODO: assert on run and withdraw results?
Jon Hall669173b2014-12-17 11:36:30 -08001108
Jon Hall6aec96b2015-01-19 14:49:31 -08001109 utilities.assert_equals(
1110 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001111 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001112 onpass="Leadership election passed",
1113 onfail="ONOS1's election app was not leader after it re-ran " +
1114 "for election" )