blob: f312e23baca37d7842daa70a05cd4a9cd4302235 [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 Hall97f31752015-02-04 12:01:04 -0800107 main.step( "Starting Mininet" )
108 main.Mininet1.startNet( )
109
Jon Hall6aec96b2015-01-19 14:49:31 -0800110 main.step( "Compiling the latest version of ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800111 if PULLCODE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800112 # TODO Configure branch in params
113 main.step( "Git checkout and pull master" )
Jon Hall529a37f2015-01-28 10:02:00 -0800114 main.ONOSbench.gitCheckout( gitBranch )
Jon Hall8f89dda2015-01-22 16:03:33 -0800115 gitPullResult = main.ONOSbench.gitPull()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800116
Jon Hall6aec96b2015-01-19 14:49:31 -0800117 main.step( "Using mvn clean & install" )
Jon Hall529a37f2015-01-28 10:02:00 -0800118 cleanInstallResult = main.ONOSbench.cleanInstall()
119 else:
120 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
Jon Hall73cf9cc2014-11-20 22:28:38 -0800200 """
Jon Hall6aec96b2015-01-19 14:49:31 -0800201 # FIXME: we must reinstall intents until we have a persistant
202 # datastore!
Jon Hall73cf9cc2014-11-20 22:28:38 -0800203 import time
Jon Hall6aec96b2015-01-19 14:49:31 -0800204 main.log.report( "Adding host intents" )
205 main.case( "Adding host Intents" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800206
Jon Hall8f89dda2015-01-22 16:03:33 -0800207 main.step( "Discovering Hosts( Via pingall for now )" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800208 # FIXME: Once we have a host discovery mechanism, use that instead
Jon Hall73cf9cc2014-11-20 22:28:38 -0800209
Jon Hall6aec96b2015-01-19 14:49:31 -0800210 # install onos-app-fwd
211 main.log.info( "Install reactive forwarding app" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800212 main.ONOScli1.featureInstall( "onos-app-fwd" )
Jon Hall94fd0472014-12-08 11:52:42 -0800213
Jon Hall6aec96b2015-01-19 14:49:31 -0800214 # REACTIVE FWD test
Jon Hall8f89dda2015-01-22 16:03:33 -0800215 pingResult = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800216 time1 = time.time()
Jon Hall8f89dda2015-01-22 16:03:33 -0800217 pingResult = main.Mininet1.pingall()
Jon Hall529a37f2015-01-28 10:02:00 -0800218 utilities.assert_equals(
219 expect=main.TRUE,
220 actual=pingResult,
221 onpass="Reactive Pingall test passed",
222 onfail="Reactive Pingall failed, one or more ping pairs failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800223 time2 = time.time()
Jon Hall6aec96b2015-01-19 14:49:31 -0800224 main.log.info( "Time for pingall: %2f seconds" % ( time2 - time1 ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800225
Jon Hall6aec96b2015-01-19 14:49:31 -0800226 # uninstall onos-app-fwd
227 main.log.info( "Uninstall reactive forwarding app" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800228 main.ONOScli1.featureUninstall( "onos-app-fwd" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800229 # timeout for fwd flows
230 time.sleep( 10 )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800231
Jon Hall6aec96b2015-01-19 14:49:31 -0800232 main.step( "Add host intents" )
233 # TODO: move the host numbers to params
Jon Hall8f89dda2015-01-22 16:03:33 -0800234 intentAddResult = True
Jon Hall6aec96b2015-01-19 14:49:31 -0800235 for i in range( 8, 18 ):
236 main.log.info( "Adding host intent between h" + str( i ) +
237 " and h" + str( i + 10 ) )
238 host1 = "00:00:00:00:00:" + \
239 str( hex( i )[ 2: ] ).zfill( 2 ).upper()
240 host2 = "00:00:00:00:00:" + \
241 str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper()
Jon Hall8f89dda2015-01-22 16:03:33 -0800242 host1Id = main.ONOScli1.getHost( host1 )[ 'id' ]
243 host2Id = main.ONOScli1.getHost( host2 )[ 'id' ]
Jon Hall6aec96b2015-01-19 14:49:31 -0800244 # NOTE: get host can return None
Jon Hall8f89dda2015-01-22 16:03:33 -0800245 if host1Id and host2Id:
246 tmpResult = main.ONOScli1.addHostIntent(
247 host1Id,
248 host2Id )
Jon Hall669173b2014-12-17 11:36:30 -0800249 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800250 main.log.error( "Error, getHost() failed" )
251 tmpResult = main.FALSE
252 intentAddResult = bool( pingResult and intentAddResult
253 and tmpResult )
Jon Hall529a37f2015-01-28 10:02:00 -0800254 # TODO Check that intents were added?
Jon Hall6aec96b2015-01-19 14:49:31 -0800255 utilities.assert_equals(
256 expect=True,
Jon Hall8f89dda2015-01-22 16:03:33 -0800257 actual=intentAddResult,
Jon Hall529a37f2015-01-28 10:02:00 -0800258 onpass="Pushed host intents to ONOS",
259 onfail="Error in pushing host intents to ONOS" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800260 # TODO Check if intents all exist in datastore
Jon Hall73cf9cc2014-11-20 22:28:38 -0800261
Jon Hall6aec96b2015-01-19 14:49:31 -0800262 def CASE4( self, main ):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800263 """
264 Ping across added host intents
265 """
266 description = " Ping across added host intents"
Jon Hall6aec96b2015-01-19 14:49:31 -0800267 main.log.report( description )
268 main.case( description )
Jon Hall8f89dda2015-01-22 16:03:33 -0800269 PingResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800270 for i in range( 8, 18 ):
271 ping = main.Mininet1.pingHost(
272 src="h" + str( i ), target="h" + str( i + 10 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800273 PingResult = PingResult and ping
Jon Hall6aec96b2015-01-19 14:49:31 -0800274 if ping == main.FALSE:
275 main.log.warn( "Ping failed between h" + str( i ) +
276 " and h" + str( i + 10 ) )
277 elif ping == main.TRUE:
278 main.log.info( "Ping test passed!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800279 PingResult = main.TRUE
280 if PingResult == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800281 main.log.report(
282 "Intents have not been installed correctly, pings failed." )
Jon Hall529a37f2015-01-28 10:02:00 -0800283 #TODO: pretty print
284 main.log.warn( "ONSO1 intents: " )
285 main.log.warn( json.dumps( json.loads( main.ONOScli1.intents() ),
286 sort_keys=True,
287 indent=4,
288 separators=( ',', ': ' ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800289 if PingResult == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800290 main.log.report(
291 "Intents have been installed correctly and verified by pings" )
292 utilities.assert_equals(
293 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800294 actual=PingResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800295 onpass="Intents have been installed correctly and pings work",
296 onfail="Intents have not been installed correctly, pings failed." )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800297
Jon Hall6aec96b2015-01-19 14:49:31 -0800298 def CASE5( self, main ):
299 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800300 Reading state of ONOS
Jon Hall6aec96b2015-01-19 14:49:31 -0800301 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800302 import json
Jon Hall6aec96b2015-01-19 14:49:31 -0800303 # assumes that sts is already in you PYTHONPATH
304 from sts.topology.teston_topology import TestONTopology
Jon Hall73cf9cc2014-11-20 22:28:38 -0800305
Jon Hall6aec96b2015-01-19 14:49:31 -0800306 main.log.report( "Setting up and gathering data for current state" )
307 main.case( "Setting up and gathering data for current state" )
308 # The general idea for this test case is to pull the state of
309 # ( intents,flows, topology,... ) from each ONOS node
310 # We can then compare them with eachother and also with past states
Jon Hall73cf9cc2014-11-20 22:28:38 -0800311
Jon Hall6aec96b2015-01-19 14:49:31 -0800312 main.step( "Get the Mastership of each switch from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800313 global mastershipState
314 mastershipState = []
Jon Hall94fd0472014-12-08 11:52:42 -0800315
Jon Hall6aec96b2015-01-19 14:49:31 -0800316 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -0800317 rolesNotNull = main.ONOScli1.rolesNotNull()
Jon Hall6aec96b2015-01-19 14:49:31 -0800318 utilities.assert_equals(
319 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800320 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -0800321 onpass="Each device has a master",
322 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -0800323
Jon Hall8f89dda2015-01-22 16:03:33 -0800324 ONOS1Mastership = main.ONOScli1.roles()
Jon Hall6aec96b2015-01-19 14:49:31 -0800325 # TODO: Make this a meaningful check
Jon Hall8f89dda2015-01-22 16:03:33 -0800326 if "Error" in ONOS1Mastership or not ONOS1Mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -0800327 main.log.report( "Error in getting ONOS roles" )
328 main.log.warn(
329 "ONOS1 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800330 repr( ONOS1Mastership ) )
331 consistentMastership = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800332 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800333 mastershipState = ONOS1Mastership
334 consistentMastership = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800335
Jon Hall6aec96b2015-01-19 14:49:31 -0800336 main.step( "Get the intents from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800337 global intentState
338 intentState = []
339 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
340 intentCheck = main.FALSE
341 if "Error" in ONOS1Intents or not ONOS1Intents:
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 intents response: " + repr( ONOS1Intents ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800344 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800345 intentCheck = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800346
Jon Hall6aec96b2015-01-19 14:49:31 -0800347 main.step( "Get the flows from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800348 global flowState
349 flowState = []
350 ONOS1Flows = main.ONOScli1.flows( jsonFormat=True )
351 flowCheck = main.FALSE
352 if "Error" in ONOS1Flows or not ONOS1Flows:
Jon Hall6aec96b2015-01-19 14:49:31 -0800353 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800354 main.log.warn( "ONOS1 flows repsponse: " + ONOS1Flows )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800355 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800356 # TODO: Do a better check, maybe compare flows on switches?
Jon Hall8f89dda2015-01-22 16:03:33 -0800357 flowState = ONOS1Flows
358 flowCheck = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800359
Jon Hall6aec96b2015-01-19 14:49:31 -0800360 main.step( "Get the OF Table entries" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800361 global flows
Jon Hall6aec96b2015-01-19 14:49:31 -0800362 flows = []
363 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800364 flows.append( main.Mininet2.getFlowTable( 1.3, "s" + str( i ) ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800365
Jon Hall6aec96b2015-01-19 14:49:31 -0800366 # TODO: Compare switch flow tables with ONOS flow tables
Jon Hall73cf9cc2014-11-20 22:28:38 -0800367
Jon Hall6aec96b2015-01-19 14:49:31 -0800368 main.step( "Create TestONTopology object" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800369 ctrls = []
370 count = 1
371 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -0800372 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
373 temp = temp + ( "ONOS" + str( count ), )
374 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
375 temp = temp + \
376 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
377 ctrls.append( temp )
378 MNTopo = TestONTopology(
379 main.Mininet1,
380 ctrls ) # can also add Intent API info for intent operations
Jon Hall73cf9cc2014-11-20 22:28:38 -0800381
Jon Hall6aec96b2015-01-19 14:49:31 -0800382 main.step( "Collecting topology information from ONOS" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800383 devices = []
384 devices.append( main.ONOScli1.devices() )
Jon Hall6aec96b2015-01-19 14:49:31 -0800385 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800386 hosts = []
387 hosts.append( main.ONOScli1.hosts() )
Jon Hall6aec96b2015-01-19 14:49:31 -0800388 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800389 ports = []
390 ports.append( main.ONOScli1.ports() )
391 links = []
392 links.append( main.ONOScli1.links() )
393
Jon Hall6aec96b2015-01-19 14:49:31 -0800394 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800395 devicesResults = main.TRUE
396 portsResults = main.TRUE
397 linksResults = main.TRUE
398 for controller in range( numControllers ):
399 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -0800400 if devices[ controller ] or "Error" not in devices[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -0800401 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -0800402 MNTopo,
403 json.loads(
404 devices[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800405 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800406 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800407 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800408 actual=currentDevicesResult,
409 onpass="ONOS" + controllerStr +
410 " Switches view is correct",
411 onfail="ONOS" + controllerStr +
412 " Switches view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800413
Jon Hall6aec96b2015-01-19 14:49:31 -0800414 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -0800415 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -0800416 MNTopo,
417 json.loads(
418 ports[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800419 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800420 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800421 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800422 actual=currentPortsResult,
423 onpass="ONOS" + controllerStr +
424 " ports view is correct",
425 onfail="ONOS" + controllerStr +
426 " ports view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800427
Jon Hall6aec96b2015-01-19 14:49:31 -0800428 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -0800429 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -0800430 MNTopo,
431 json.loads(
432 links[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800433 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800434 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800435 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800436 actual=currentLinksResult,
437 onpass="ONOS" + controllerStr +
438 " links view is correct",
439 onfail="ONOS" + controllerStr +
440 " links view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800441
Jon Hall8f89dda2015-01-22 16:03:33 -0800442 devicesResults = devicesResults and currentDevicesResult
443 portsResults = portsResults and currentPortsResult
444 linksResults = linksResults and currentLinksResult
Jon Hall73cf9cc2014-11-20 22:28:38 -0800445
Jon Hall8f89dda2015-01-22 16:03:33 -0800446 topoResult = devicesResults and portsResults and linksResults
447 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
448 onpass="Topology Check Test successful",
449 onfail="Topology Check Test NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800450
Jon Hall8f89dda2015-01-22 16:03:33 -0800451 finalAssert = main.TRUE
452 finalAssert = finalAssert and topoResult and flowCheck \
453 and intentCheck and consistentMastership and rolesNotNull
454 utilities.assert_equals( expect=main.TRUE, actual=finalAssert,
455 onpass="State check successful",
456 onfail="State check NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800457
Jon Hall6aec96b2015-01-19 14:49:31 -0800458 def CASE6( self, main ):
459 """
Jon Hallffb386d2014-11-21 13:43:38 -0800460 The Failure case.
Jon Hall6aec96b2015-01-19 14:49:31 -0800461 """
Jon Hallffb386d2014-11-21 13:43:38 -0800462 import time
Jon Hall73cf9cc2014-11-20 22:28:38 -0800463
Jon Hall6aec96b2015-01-19 14:49:31 -0800464 main.log.report( "Restart ONOS node" )
465 main.log.case( "Restart ONOS node" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800466 main.ONOSbench.onosKill( ONOS1Ip )
Jon Hallffb386d2014-11-21 13:43:38 -0800467 start = time.time()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800468
Jon Hall6aec96b2015-01-19 14:49:31 -0800469 main.step( "Checking if ONOS is up yet" )
Jon Hallffb386d2014-11-21 13:43:38 -0800470 count = 0
Jon Hall94fd0472014-12-08 11:52:42 -0800471 while count < 10:
Jon Hall8f89dda2015-01-22 16:03:33 -0800472 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
473 if onos1Isup == main.TRUE:
Jon Hallffb386d2014-11-21 13:43:38 -0800474 elapsed = time.time() - start
475 break
476 else:
477 count = count + 1
Jon Hall73cf9cc2014-11-20 22:28:38 -0800478
Jon Hall8f89dda2015-01-22 16:03:33 -0800479 cliResult = main.ONOScli1.startOnosCli( ONOS1Ip )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800480
Jon Hall8f89dda2015-01-22 16:03:33 -0800481 caseResults = main.TRUE and onos1Isup and cliResult
482 utilities.assert_equals( expect=main.TRUE, actual=caseResults,
483 onpass="ONOS restart successful",
484 onfail="ONOS restart NOT successful" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800485 main.log.info(
486 "ESTIMATE: ONOS took %s seconds to restart" %
487 str( elapsed ) )
488 time.sleep( 5 )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800489
Jon Hall6aec96b2015-01-19 14:49:31 -0800490 def CASE7( self, main ):
491 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800492 Check state after ONOS failure
Jon Hall6aec96b2015-01-19 14:49:31 -0800493 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800494 import json
Jon Hall6aec96b2015-01-19 14:49:31 -0800495 main.case( "Running ONOS Constant State Tests" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800496
Jon Hall6aec96b2015-01-19 14:49:31 -0800497 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -0800498 rolesNotNull = main.ONOScli1.rolesNotNull()
Jon Hall6aec96b2015-01-19 14:49:31 -0800499 utilities.assert_equals(
500 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800501 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -0800502 onpass="Each device has a master",
503 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -0800504
Jon Hall6aec96b2015-01-19 14:49:31 -0800505 main.step( "Check if switch roles are consistent across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800506 ONOS1Mastership = main.ONOScli1.roles()
Jon Hall6aec96b2015-01-19 14:49:31 -0800507 # FIXME: Refactor this whole case for single instance
Jon Hall8f89dda2015-01-22 16:03:33 -0800508 if "Error" in ONOS1Mastership or not ONOS1Mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -0800509 main.log.report( "Error in getting ONOS mastership" )
510 main.log.warn(
511 "ONOS1 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800512 repr( ONOS1Mastership ) )
513 consistentMastership = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800514 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800515 consistentMastership = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800516 main.log.report(
517 "Switch roles are consistent across all ONOS nodes" )
518 utilities.assert_equals(
519 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800520 actual=consistentMastership,
Jon Hall6aec96b2015-01-19 14:49:31 -0800521 onpass="Switch roles are consistent across all ONOS nodes",
522 onfail="ONOS nodes have different views of switch roles" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800523
524 description2 = "Compare switch roles from before failure"
Jon Hall6aec96b2015-01-19 14:49:31 -0800525 main.step( description2 )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800526
Jon Hall8f89dda2015-01-22 16:03:33 -0800527 currentJson = json.loads( ONOS1Mastership )
528 oldJson = json.loads( mastershipState )
529 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800530 for i in range( 1, 29 ):
531 switchDPID = str(
532 main.Mininet1.getSwitchDPID(
533 switch="s" +
534 str( i ) ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800535
Jon Hall8f89dda2015-01-22 16:03:33 -0800536 current = [ switch[ 'master' ] for switch in currentJson
Jon Hall6aec96b2015-01-19 14:49:31 -0800537 if switchDPID in switch[ 'id' ] ]
Jon Hall8f89dda2015-01-22 16:03:33 -0800538 old = [ switch[ 'master' ] for switch in oldJson
Jon Hall6aec96b2015-01-19 14:49:31 -0800539 if switchDPID in switch[ 'id' ] ]
Jon Hall73cf9cc2014-11-20 22:28:38 -0800540 if current == old:
Jon Hall8f89dda2015-01-22 16:03:33 -0800541 mastershipCheck = mastershipCheck and main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800542 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800543 main.log.warn( "Mastership of switch %s changed" % switchDPID )
Jon Hall8f89dda2015-01-22 16:03:33 -0800544 mastershipCheck = main.FALSE
545 if mastershipCheck == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800546 main.log.report( "Mastership of Switches was not changed" )
547 utilities.assert_equals(
548 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800549 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800550 onpass="Mastership of Switches was not changed",
551 onfail="Mastership of some switches changed" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800552 mastershipCheck = mastershipCheck and consistentMastership
Jon Hall73cf9cc2014-11-20 22:28:38 -0800553
Jon Hall6aec96b2015-01-19 14:49:31 -0800554 main.step( "Get the intents and compare across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800555 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
556 intentCheck = main.FALSE
557 if "Error" in ONOS1Intents or not ONOS1Intents:
Jon Hall6aec96b2015-01-19 14:49:31 -0800558 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800559 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800560 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800561 intentCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800562 main.log.report( "Intents are consistent across all ONOS nodes" )
563 utilities.assert_equals(
564 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800565 actual=intentCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800566 onpass="Intents are consistent across all ONOS nodes",
567 onfail="ONOS nodes have different views of intents" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800568
Jon Hall6aec96b2015-01-19 14:49:31 -0800569 # NOTE: Hazelcast has no durability, so intents are lost across system
570 # restarts
571 """
572 main.step( "Compare current intents with intents before the failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800573 # NOTE: this requires case 5 to pass for intentState to be set.
Jon Hall6aec96b2015-01-19 14:49:31 -0800574 # maybe we should stop the test if that fails?
Jon Hall8f89dda2015-01-22 16:03:33 -0800575 if intentState == ONOS1Intents:
576 sameIntents = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800577 main.log.report( "Intents are consistent with before failure" )
578 # TODO: possibly the states have changed? we may need to figure out
579 # what the aceptable states are
Jon Hall73cf9cc2014-11-20 22:28:38 -0800580 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800581 try:
582 main.log.warn( "ONOS1 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -0800583 print json.dumps( json.loads( ONOS1Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800584 sort_keys=True, indent=4,
585 separators=( ',', ': ' ) )
586 except:
587 pass
Jon Hall8f89dda2015-01-22 16:03:33 -0800588 sameIntents = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800589 utilities.assert_equals(
590 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800591 actual=sameIntents,
Jon Hall6aec96b2015-01-19 14:49:31 -0800592 onpass="Intents are consistent with before failure",
593 onfail="The Intents changed during failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800594 intentCheck = intentCheck and sameIntents
Jon Hall6aec96b2015-01-19 14:49:31 -0800595 """
596 main.step( "Get the OF Table entries and compare to before " +
597 "component failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800598 FlowTables = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800599 flows2 = []
600 for i in range( 28 ):
601 main.log.info( "Checking flow table on s" + str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800602 tmpFlows = main.Mininet2.getFlowTable( 1.3, "s" + str( i + 1 ) )
603 flows2.append( tmpFlows )
604 tempResult = main.Mininet2.flowComp(
Jon Hall6aec96b2015-01-19 14:49:31 -0800605 flow1=flows[ i ],
Jon Hall8f89dda2015-01-22 16:03:33 -0800606 flow2=tmpFlows )
607 FlowTables = FlowTables and tempResult
608 if FlowTables == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800609 main.log.info( "Differences in flow table for switch: s" +
610 str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800611 if FlowTables == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800612 main.log.report( "No changes were found in the flow tables" )
613 utilities.assert_equals(
614 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800615 actual=FlowTables,
Jon Hall6aec96b2015-01-19 14:49:31 -0800616 onpass="No changes were found in the flow tables",
617 onfail="Changes were found in the flow tables" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800618
Jon Hall6aec96b2015-01-19 14:49:31 -0800619 # Test of LeadershipElection
Jon Hall669173b2014-12-17 11:36:30 -0800620
Jon Hall8f89dda2015-01-22 16:03:33 -0800621 leader = ONOS1Ip
622 leaderResult = main.TRUE
623 for controller in range( 1, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -0800624 # loop through ONOScli handlers
625 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800626 leaderN = node.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -0800627 # verify leader is ONOS1
628 # NOTE even though we restarted ONOS, it is the only one so onos 1
629 # must be leader
Jon Hall669173b2014-12-17 11:36:30 -0800630 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -0800631 # all is well
Jon Hall669173b2014-12-17 11:36:30 -0800632 pass
633 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800634 # error in response
635 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800636 "electionTestLeader function, check the" +
Jon Hall6aec96b2015-01-19 14:49:31 -0800637 " error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800638 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -0800639 elif leader != leaderN:
Jon Hall8f89dda2015-01-22 16:03:33 -0800640 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800641 main.log.report( "ONOS" + str( controller ) +
642 " sees " + str( leaderN ) +
643 " as the leader of the election app." +
644 " Leader should be " + str( leader ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800645 if leaderResult:
646 main.log.report( "Leadership election tests passed( consistent " +
Jon Hall6aec96b2015-01-19 14:49:31 -0800647 "view of leader across listeners and a new " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800648 "leader was re-elected if applicable )" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800649 utilities.assert_equals(
650 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800651 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800652 onpass="Leadership election passed",
653 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -0800654
Jon Hall8f89dda2015-01-22 16:03:33 -0800655 result = ( mastershipCheck and intentCheck and FlowTables and
656 rolesNotNull and leaderResult )
Jon Hall6aec96b2015-01-19 14:49:31 -0800657 result = int( result )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800658 if result == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800659 main.log.report( "Constant State Tests Passed" )
660 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall8f89dda2015-01-22 16:03:33 -0800661 onpass="Constant State Tests Passed",
662 onfail="Constant state tests failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800663
Jon Hall6aec96b2015-01-19 14:49:31 -0800664 def CASE8( self, main ):
665 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800666 Compare topo
Jon Hall6aec96b2015-01-19 14:49:31 -0800667 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800668 import sys
Jon Hall6aec96b2015-01-19 14:49:31 -0800669 # FIXME add this path to params
670 sys.path.append( "/home/admin/sts" )
671 # assumes that sts is already in you PYTHONPATH
672 from sts.topology.teston_topology import TestONTopology
Jon Hall73cf9cc2014-11-20 22:28:38 -0800673 import json
674 import time
675
Jon Hall6aec96b2015-01-19 14:49:31 -0800676 description = "Compare ONOS Topology view to Mininet topology"
677 main.case( description )
678 main.log.report( description )
679 main.step( "Create TestONTopology object" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800680 ctrls = []
681 count = 1
682 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -0800683 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
684 temp = temp + ( "ONOS" + str( count ), )
685 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
686 temp = temp + \
687 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
688 ctrls.append( temp )
689 MNTopo = TestONTopology(
690 main.Mininet1,
691 ctrls ) # can also add Intent API info for intent operations
Jon Hall73cf9cc2014-11-20 22:28:38 -0800692
Jon Hall6aec96b2015-01-19 14:49:31 -0800693 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800694 devicesResults = main.TRUE
695 portsResults = main.TRUE
696 linksResults = main.TRUE
697 topoResult = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800698 elapsed = 0
Jon Hallffb386d2014-11-21 13:43:38 -0800699 count = 0
Jon Hall6aec96b2015-01-19 14:49:31 -0800700 main.step( "Collecting topology information from ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800701 startTime = time.time()
702 while topoResult == main.FALSE and elapsed < 60:
Jon Hallffb386d2014-11-21 13:43:38 -0800703 count = count + 1
Jon Hall94fd0472014-12-08 11:52:42 -0800704 if count > 1:
Jon Hall6aec96b2015-01-19 14:49:31 -0800705 MNTopo = TestONTopology(
706 main.Mininet1,
707 ctrls )
Jon Hall8f89dda2015-01-22 16:03:33 -0800708 cliStart = time.time()
Jon Hall94fd0472014-12-08 11:52:42 -0800709 devices = []
710 devices.append( main.ONOScli1.devices() )
Jon Hall6aec96b2015-01-19 14:49:31 -0800711 """
Jon Hall94fd0472014-12-08 11:52:42 -0800712 hosts = []
713 hosts.append( main.ONOScli1.hosts() )
Jon Hall6aec96b2015-01-19 14:49:31 -0800714 """
Jon Hall94fd0472014-12-08 11:52:42 -0800715 ports = []
716 ports.append( main.ONOScli1.ports() )
717 links = []
718 links.append( main.ONOScli1.links() )
Jon Hall8f89dda2015-01-22 16:03:33 -0800719 elapsed = time.time() - startTime
720 cliTime = time.time() - cliStart
721 print "CLI time: " + str( cliTime )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800722
Jon Hall8f89dda2015-01-22 16:03:33 -0800723 for controller in range( numControllers ):
724 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -0800725 if devices[ controller ] or "Error" not in devices[
726 controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -0800727 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -0800728 MNTopo,
729 json.loads(
730 devices[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800731 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800732 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800733 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800734 actual=currentDevicesResult,
735 onpass="ONOS" + controllerStr +
736 " Switches view is correct",
737 onfail="ONOS" + controllerStr +
738 " Switches view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800739
Jon Hall6aec96b2015-01-19 14:49:31 -0800740 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -0800741 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -0800742 MNTopo,
743 json.loads(
744 ports[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800745 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800746 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800747 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800748 actual=currentPortsResult,
749 onpass="ONOS" + controllerStr +
750 " ports view is correct",
751 onfail="ONOS" + controllerStr +
752 " ports view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800753
Jon Hall6aec96b2015-01-19 14:49:31 -0800754 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -0800755 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -0800756 MNTopo,
757 json.loads(
758 links[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800759 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800760 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800761 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800762 actual=currentLinksResult,
763 onpass="ONOS" + controllerStr +
764 " links view is correct",
765 onfail="ONOS" + controllerStr +
766 " links view is incorrect" )
767 devicesResults = devicesResults and currentDevicesResult
768 portsResults = portsResults and currentPortsResult
769 linksResults = linksResults and currentLinksResult
770 topoResult = devicesResults and portsResults and linksResults
Jon Hall94fd0472014-12-08 11:52:42 -0800771
Jon Hall8f89dda2015-01-22 16:03:33 -0800772 topoResult = topoResult and int( count <= 2 )
773 note = "note it takes about " + str( int( cliTime ) ) + \
774 " seconds for the test to make all the cli calls to fetch " +\
775 "the topology from each ONOS instance"
Jon Hall6aec96b2015-01-19 14:49:31 -0800776 main.log.report(
Jon Hall8f89dda2015-01-22 16:03:33 -0800777 "Very crass estimate for topology discovery/convergence( " +
778 str( note ) + " ): " + str( elapsed ) + " seconds, " +
Jon Hall6aec96b2015-01-19 14:49:31 -0800779 str( count ) + " tries" )
Jon Hall94fd0472014-12-08 11:52:42 -0800780 if elapsed > 60:
Jon Hall6aec96b2015-01-19 14:49:31 -0800781 main.log.report( "Giving up on topology convergence" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800782 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
783 onpass="Topology Check Test successful",
784 onfail="Topology Check Test NOT successful" )
785 if topoResult == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800786 main.log.report( "ONOS topology view matches Mininet topology" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800787
Jon Hall6aec96b2015-01-19 14:49:31 -0800788 def CASE9( self, main ):
789 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800790 Link s3-s28 down
Jon Hall6aec96b2015-01-19 14:49:31 -0800791 """
792 import time
793 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -0800794
Jon Hall8f89dda2015-01-22 16:03:33 -0800795 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800796
Jon Hall6aec96b2015-01-19 14:49:31 -0800797 description = "Turn off a link to ensure that Link Discovery " +\
Jon Hall8f89dda2015-01-22 16:03:33 -0800798 "is working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -0800799 main.log.report( description )
800 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800801
Jon Hall6aec96b2015-01-19 14:49:31 -0800802 main.step( "Kill Link between s3 and s28" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800803 LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800804 main.log.info(
805 "Waiting " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800806 str( linkSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -0800807 " seconds for link down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800808 time.sleep( linkSleep )
809 utilities.assert_equals( expect=main.TRUE, actual=LinkDown,
810 onpass="Link down succesful",
811 onfail="Failed to bring link down" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800812 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -0800813
Jon Hall6aec96b2015-01-19 14:49:31 -0800814 def CASE10( self, main ):
815 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800816 Link s3-s28 up
Jon Hall6aec96b2015-01-19 14:49:31 -0800817 """
818 import time
819 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -0800820
Jon Hall8f89dda2015-01-22 16:03:33 -0800821 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800822
Jon Hall6aec96b2015-01-19 14:49:31 -0800823 description = "Restore a link to ensure that Link Discovery is " + \
Jon Hall8f89dda2015-01-22 16:03:33 -0800824 "working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -0800825 main.log.report( description )
826 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800827
Jon Hall6aec96b2015-01-19 14:49:31 -0800828 main.step( "Bring link between s3 and s28 back up" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800829 LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800830 main.log.info(
831 "Waiting " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800832 str( linkSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -0800833 " seconds for link up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800834 time.sleep( linkSleep )
835 utilities.assert_equals( expect=main.TRUE, actual=LinkUp,
836 onpass="Link up succesful",
837 onfail="Failed to bring link up" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800838 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -0800839
Jon Hall6aec96b2015-01-19 14:49:31 -0800840 def CASE11( self, main ):
841 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800842 Switch Down
Jon Hall6aec96b2015-01-19 14:49:31 -0800843 """
844 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -0800845 import time
846
Jon Hall8f89dda2015-01-22 16:03:33 -0800847 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800848
849 description = "Killing a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -0800850 main.log.report( description )
851 main.case( description )
852 switch = main.params[ 'kill' ][ 'switch' ]
853 switchDPID = main.params[ 'kill' ][ 'dpid' ]
Jon Hall73cf9cc2014-11-20 22:28:38 -0800854
Jon Hall6aec96b2015-01-19 14:49:31 -0800855 # TODO: Make this switch parameterizable
856 main.step( "Kill " + switch )
857 main.log.report( "Deleting " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -0800858 main.Mininet1.delSwitch( switch )
859 main.log.info( "Waiting " + str( switchSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -0800860 " seconds for switch down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800861 time.sleep( switchSleep )
862 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -0800863 # Peek at the deleted switch
864 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800865 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800866 if device and device[ 'available' ] is False:
Jon Hall94fd0472014-12-08 11:52:42 -0800867 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800868 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall8f89dda2015-01-22 16:03:33 -0800869 onpass="Kill switch succesful",
870 onfail="Failed to kill switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800871
Jon Hall6aec96b2015-01-19 14:49:31 -0800872 def CASE12( self, main ):
873 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800874 Switch Up
Jon Hall6aec96b2015-01-19 14:49:31 -0800875 """
876 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -0800877 import time
Jon Hall669173b2014-12-17 11:36:30 -0800878
Jon Hall8f89dda2015-01-22 16:03:33 -0800879 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall6aec96b2015-01-19 14:49:31 -0800880 switch = main.params[ 'kill' ][ 'switch' ]
881 switchDPID = main.params[ 'kill' ][ 'dpid' ]
882 links = main.params[ 'kill' ][ 'links' ].split()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800883 description = "Adding a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -0800884 main.log.report( description )
885 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800886
Jon Hall6aec96b2015-01-19 14:49:31 -0800887 main.step( "Add back " + switch )
888 main.log.report( "Adding back " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -0800889 main.Mininet1.addSwitch( switch, dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -0800890 # TODO: New dpid or same? Ask Thomas?
891 for peer in links:
Jon Hall8f89dda2015-01-22 16:03:33 -0800892 main.Mininet1.addLink( switch, peer )
893 main.Mininet1.assignSwController( sw=switch.split( 's' )[ 1 ],
894 ip1=ONOS1Ip, port1=ONOS1Port )
Jon Hall6aec96b2015-01-19 14:49:31 -0800895 main.log.info(
896 "Waiting " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800897 str( switchSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -0800898 " seconds for switch up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800899 time.sleep( switchSleep )
900 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -0800901 # Peek at the deleted switch
902 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800903 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800904 if device and device[ 'available' ]:
Jon Hall94fd0472014-12-08 11:52:42 -0800905 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800906 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall8f89dda2015-01-22 16:03:33 -0800907 onpass="add switch succesful",
908 onfail="Failed to add switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800909
Jon Hall6aec96b2015-01-19 14:49:31 -0800910 def CASE13( self, main ):
911 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800912 Clean up
Jon Hall6aec96b2015-01-19 14:49:31 -0800913 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800914 import os
915 import time
Jon Hall6aec96b2015-01-19 14:49:31 -0800916 # printing colors to terminal
Jon Hall669173b2014-12-17 11:36:30 -0800917 colors = {}
Jon Hall6aec96b2015-01-19 14:49:31 -0800918 colors[ 'cyan' ] = '\033[96m'
919 colors[ 'purple' ] = '\033[95m'
920 colors[ 'blue' ] = '\033[94m'
921 colors[ 'green' ] = '\033[92m'
922 colors[ 'yellow' ] = '\033[93m'
923 colors[ 'red' ] = '\033[91m'
924 colors[ 'end' ] = '\033[0m'
Jon Hall73cf9cc2014-11-20 22:28:38 -0800925 description = "Test Cleanup"
Jon Hall6aec96b2015-01-19 14:49:31 -0800926 main.log.report( description )
927 main.case( description )
928 main.step( "Killing tcpdumps" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800929 main.Mininet2.stopTcpdump()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800930
Jon Hall6aec96b2015-01-19 14:49:31 -0800931 main.step( "Checking ONOS Logs for errors" )
932 print colors[ 'purple' ] + "Checking logs for errors on ONOS1:" + \
Jon Hall8f89dda2015-01-22 16:03:33 -0800933 colors[ 'end' ]
934 print main.ONOSbench.checkLogs( ONOS1Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800935 main.step( "Copying MN pcap and ONOS log files to test station" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800936 testname = main.TEST
Jon Hall8f89dda2015-01-22 16:03:33 -0800937 teststationUser = main.params[ 'TESTONUSER' ]
938 teststationIP = main.params[ 'TESTONIP' ]
Jon Hall6aec96b2015-01-19 14:49:31 -0800939 # NOTE: MN Pcap file is being saved to ~/packet_captures
Jon Hall73cf9cc2014-11-20 22:28:38 -0800940 # scp this file as MN and TestON aren't necessarily the same vm
Jon Hall6aec96b2015-01-19 14:49:31 -0800941 # FIXME: scp
942 # mn files
943 # TODO: Load these from params
944 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -0800945 logFolder = "/opt/onos/log/"
946 logFiles = [ "karaf.log", "karaf.log.1" ]
Jon Hall6aec96b2015-01-19 14:49:31 -0800947 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -0800948 dstDir = "~/packet_captures/"
949 for f in logFiles:
950 main.ONOSbench.handle.sendline( "scp sdn@" + ONOS1Ip + ":" +
951 logFolder + f + " " +
952 teststationUser + "@" +
953 teststationIP + ":" + dstDir +
Jon Hall6aec96b2015-01-19 14:49:31 -0800954 str( testname ) + "-ONOS1-" + f )
955 main.ONOSbench.handle.expect( "\$" )
Jon Hall94fd0472014-12-08 11:52:42 -0800956 print main.ONOSbench.handle.before
Jon Hall73cf9cc2014-11-20 22:28:38 -0800957
Jon Hall6aec96b2015-01-19 14:49:31 -0800958 # std*.log's
959 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -0800960 logFolder = "/opt/onos/var/"
961 logFiles = [ "stderr.log", "stdout.log" ]
Jon Hall6aec96b2015-01-19 14:49:31 -0800962 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -0800963 dstDir = "~/packet_captures/"
964 for f in logFiles:
965 main.ONOSbench.handle.sendline( "scp sdn@" + ONOS1Ip + ":" +
966 logFolder + f + " " +
967 teststationUser + "@" +
968 teststationIP + ":" + dstDir +
Jon Hall6aec96b2015-01-19 14:49:31 -0800969 str( testname ) + "-ONOS1-" + f )
970 # sleep so scp can finish
971 time.sleep( 10 )
972 main.step( "Packing and rotating pcap archives" )
973 os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800974
Jon Hall6aec96b2015-01-19 14:49:31 -0800975 # TODO: actually check something here
976 utilities.assert_equals( expect=main.TRUE, actual=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800977 onpass="Test cleanup successful",
978 onfail="Test cleanup NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800979
Jon Hall6aec96b2015-01-19 14:49:31 -0800980 def CASE14( self, main ):
981 """
Jon Hall669173b2014-12-17 11:36:30 -0800982 start election app on all onos nodes
Jon Hall6aec96b2015-01-19 14:49:31 -0800983 """
Jon Hall8f89dda2015-01-22 16:03:33 -0800984 leaderResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800985 # install app on onos 1
986 main.log.info( "Install leadership election app" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800987 main.ONOScli1.featureInstall( "onos-app-election" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800988 # wait for election
989 # check for leader
Jon Hall8f89dda2015-01-22 16:03:33 -0800990 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -0800991 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -0800992 if leader == ONOS1Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -0800993 # all is well
Jon Hall669173b2014-12-17 11:36:30 -0800994 pass
Jon Hall6aec96b2015-01-19 14:49:31 -0800995 elif leader is None:
996 # No leader elected
997 main.log.report( "No leader was elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800998 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -0800999 elif leader == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001000 # error in response
1001 # TODO: add check for "Command not found:" in the driver, this
1002 # means the app isn't loaded
Jon Hall8f89dda2015-01-22 16:03:33 -08001003 main.log.report( "Something is wrong with electionTestLeader" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001004 " function, check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001005 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001006 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001007 # error in response
1008 main.log.report(
Jon Hall8f89dda2015-01-22 16:03:33 -08001009 "Unexpected response from electionTestLeader function:'" +
1010 str( leader ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001011 "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001012 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001013
Jon Hall6aec96b2015-01-19 14:49:31 -08001014 # install on other nodes and check for leader.
1015 # Should be onos1 and each app should show the same leader
Jon Hall8f89dda2015-01-22 16:03:33 -08001016 for controller in range( 2, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001017 # loop through ONOScli handlers
1018 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001019 node.featureInstall( "onos-app-election" )
1020 leaderN = node.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001021 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08001022 if leaderN == ONOS1Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08001023 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001024 pass
1025 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001026 # error in response
1027 # TODO: add check for "Command not found:" in the driver, this
1028 # means the app isn't loaded
1029 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001030 "electionTestLeader function, check the" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001031 " error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001032 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001033 elif leader != leaderN:
Jon Hall8f89dda2015-01-22 16:03:33 -08001034 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001035 main.log.report( "ONOS" + str( controller ) + " sees " +
1036 str( leaderN ) +
1037 " as the leader of the election app. Leader" +
1038 " should be " +
1039 str( leader ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001040 if leaderResult:
Jon Hall6aec96b2015-01-19 14:49:31 -08001041 main.log.report( "Leadership election tests passed( consistent " +
1042 "view of leader across listeners and a leader " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001043 "was elected )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001044 utilities.assert_equals(
1045 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001046 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001047 onpass="Leadership election passed",
1048 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08001049
Jon Hall6aec96b2015-01-19 14:49:31 -08001050 def CASE15( self, main ):
1051 """
Jon Hall669173b2014-12-17 11:36:30 -08001052 Check that Leadership Election is still functional
Jon Hall6aec96b2015-01-19 14:49:31 -08001053 """
Jon Hall8f89dda2015-01-22 16:03:33 -08001054 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08001055 description = "Check that Leadership Election is still functional"
Jon Hall6aec96b2015-01-19 14:49:31 -08001056 main.log.report( description )
1057 main.case( description )
1058 main.step( "Find current leader and withdraw" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001059 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001060 # TODO: do some sanity checking on leader before using it
Jon Hall8f89dda2015-01-22 16:03:33 -08001061 withdrawResult = main.FALSE
1062 if leader == ONOS1Ip:
1063 oldLeader = getattr( main, "ONOScli1" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001064 elif leader is None or leader == main.FALSE:
1065 main.log.report(
1066 "Leader for the election app should be an ONOS node," +
1067 "instead got '" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001068 str( leader ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001069 "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001070 leaderResult = main.FALSE
1071 withdrawResult = oldLeader.electionTestWithdraw()
Jon Hall6aec96b2015-01-19 14:49:31 -08001072 utilities.assert_equals(
1073 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001074 actual=withdrawResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001075 onpass="App was withdrawn from election",
1076 onfail="App was not withdrawn from election" )
Jon Hall669173b2014-12-17 11:36:30 -08001077
Jon Hall6aec96b2015-01-19 14:49:31 -08001078 main.step( "Make sure new leader is elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001079 leaderList = []
1080 leaderN = main.ONOScli1.electionTestLeader()
Jon Hall669173b2014-12-17 11:36:30 -08001081 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08001082 main.log.report( "ONOS still sees " + str( leaderN ) +
1083 " as leader after they withdrew" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001084 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001085 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001086 # error in response
1087 # TODO: add check for "Command not found:" in the driver, this
1088 # means the app isn't loaded
Jon Hall8f89dda2015-01-22 16:03:33 -08001089 main.log.report( "Something is wrong with electionTestLeader " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001090 "function, check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001091 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001092 elif leaderN is None:
1093 main.log.info(
1094 "There is no leader after the app withdrew from election" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001095 if leaderResult:
1096 main.log.report( "Leadership election tests passed( There is no " +
1097 "leader after the old leader resigned )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001098 utilities.assert_equals(
1099 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001100 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001101 onpass="Leadership election passed",
1102 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08001103
Jon Hall6aec96b2015-01-19 14:49:31 -08001104 main.step(
Jon Hall8f89dda2015-01-22 16:03:33 -08001105 "Run for election on old leader( just so everyone is in the hat )" )
1106 runResult = oldLeader.electionTestRun()
Jon Hall6aec96b2015-01-19 14:49:31 -08001107 utilities.assert_equals(
1108 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001109 actual=runResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001110 onpass="App re-ran for election",
1111 onfail="App failed to run for election" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001112 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001113 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08001114 if leader == ONOS1Ip:
1115 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08001116 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001117 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001118 # TODO: assert on run and withdraw results?
Jon Hall669173b2014-12-17 11:36:30 -08001119
Jon Hall6aec96b2015-01-19 14:49:31 -08001120 utilities.assert_equals(
1121 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001122 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001123 onpass="Leadership election passed",
1124 onfail="ONOS1's election app was not leader after it re-ran " +
1125 "for election" )