blob: a87e8628057dd7999c85680e8ad163ef6bea2a86 [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 ONOS can handle
3 a minority of it's nodes restarting
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.
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 Hall73cf9cc2014-11-20 22:28:38 -080024class HATestMinorityRestart:
25
Jon Hall6aec96b2015-01-19 14:49:31 -080026 def __init__( self ):
Jon Hall73cf9cc2014-11-20 22:28:38 -080027 self.default = ''
28
Jon Hall6aec96b2015-01-19 14:49:31 -080029 def CASE1( self, main ):
30 """
Jon Hall73cf9cc2014-11-20 22:28:38 -080031 CASE1 is to compile ONOS and push it to the test machines
32
33 Startup sequence:
Jon Hall73cf9cc2014-11-20 22:28:38 -080034 cell <name>
35 onos-verify-cell
36 NOTE: temporary - onos-remove-raft-logs
Jon Hall58c76b72015-02-23 11:09:24 -080037 onos-uninstall
38 start mininet
39 git pull
40 mvn clean install
41 onos-package
Jon Hall73cf9cc2014-11-20 22:28:38 -080042 onos-install -f
43 onos-wait-for-start
Jon Hall58c76b72015-02-23 11:09:24 -080044 start cli sessions
45 start tcpdump
Jon Hall6aec96b2015-01-19 14:49:31 -080046 """
47 main.log.report(
48 "ONOS HA test: Restart minority of ONOS nodes - initialization" )
49 main.case( "Setting up test environment" )
50 # TODO: save all the timers and output them for plotting
Jon Hall73cf9cc2014-11-20 22:28:38 -080051
52 # load some vairables from the params file
Jon Hall8f89dda2015-01-22 16:03:33 -080053 PULLCODE = False
Jon Hall6aec96b2015-01-19 14:49:31 -080054 if main.params[ 'Git' ] == 'True':
Jon Hall8f89dda2015-01-22 16:03:33 -080055 PULLCODE = True
Jon Hall529a37f2015-01-28 10:02:00 -080056 gitBranch = main.params[ 'branch' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080057 cellName = main.params[ 'ENV' ][ 'cellName' ]
Jon Hall6aec96b2015-01-19 14:49:31 -080058
59 # set global variables
Jon Hall8f89dda2015-01-22 16:03:33 -080060 global ONOS1Ip
61 global ONOS1Port
62 global ONOS2Ip
63 global ONOS2Port
64 global ONOS3Ip
65 global ONOS3Port
66 global ONOS4Ip
67 global ONOS4Port
68 global ONOS5Ip
69 global ONOS5Port
70 global ONOS6Ip
71 global ONOS6Port
72 global ONOS7Ip
73 global ONOS7Port
74 global numControllers
Jon Hall73cf9cc2014-11-20 22:28:38 -080075
Jon Hall8f89dda2015-01-22 16:03:33 -080076 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
77 ONOS1Port = main.params[ 'CTRL' ][ 'port1' ]
78 ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
79 ONOS2Port = main.params[ 'CTRL' ][ 'port2' ]
80 ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ]
81 ONOS3Port = main.params[ 'CTRL' ][ 'port3' ]
82 ONOS4Ip = main.params[ 'CTRL' ][ 'ip4' ]
83 ONOS4Port = main.params[ 'CTRL' ][ 'port4' ]
84 ONOS5Ip = main.params[ 'CTRL' ][ 'ip5' ]
85 ONOS5Port = main.params[ 'CTRL' ][ 'port5' ]
86 ONOS6Ip = main.params[ 'CTRL' ][ 'ip6' ]
87 ONOS6Port = main.params[ 'CTRL' ][ 'port6' ]
88 ONOS7Ip = main.params[ 'CTRL' ][ 'ip7' ]
89 ONOS7Port = main.params[ 'CTRL' ][ 'port7' ]
90 numControllers = int( main.params[ 'num_controllers' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -080091
Jon Hall6aec96b2015-01-19 14:49:31 -080092 main.step( "Applying cell variable to environment" )
Jon Hall8f89dda2015-01-22 16:03:33 -080093 cellResult = main.ONOSbench.setCell( cellName )
94 verifyResult = main.ONOSbench.verifyCell()
Jon Hall73cf9cc2014-11-20 22:28:38 -080095
Jon Hall6aec96b2015-01-19 14:49:31 -080096 # FIXME:this is short term fix
97 main.log.report( "Removing raft logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -080098 main.ONOSbench.onosRemoveRaftLogs()
Jon Hall6aec96b2015-01-19 14:49:31 -080099 main.log.report( "Uninstalling ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800100 main.ONOSbench.onosUninstall( ONOS1Ip )
101 main.ONOSbench.onosUninstall( ONOS2Ip )
102 main.ONOSbench.onosUninstall( ONOS3Ip )
103 main.ONOSbench.onosUninstall( ONOS4Ip )
104 main.ONOSbench.onosUninstall( ONOS5Ip )
105 main.ONOSbench.onosUninstall( ONOS6Ip )
106 main.ONOSbench.onosUninstall( ONOS7Ip )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800107
Jon Hall8f89dda2015-01-22 16:03:33 -0800108 cleanInstallResult = main.TRUE
109 gitPullResult = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800110
Jon Hall97f31752015-02-04 12:01:04 -0800111 main.step( "Starting Mininet" )
112 main.Mininet1.startNet( )
113
Jon Hall6aec96b2015-01-19 14:49:31 -0800114 main.step( "Compiling the latest version of ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800115 if PULLCODE:
Jon Hall58c76b72015-02-23 11:09:24 -0800116 main.step( "Git checkout and pull " + gitBranch )
Jon Hall529a37f2015-01-28 10:02:00 -0800117 main.ONOSbench.gitCheckout( gitBranch )
Jon Hall8f89dda2015-01-22 16:03:33 -0800118 gitPullResult = main.ONOSbench.gitPull()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800119
Jon Hall6aec96b2015-01-19 14:49:31 -0800120 main.step( "Using mvn clean & install" )
Jon Hall529a37f2015-01-28 10:02:00 -0800121 cleanInstallResult = main.ONOSbench.cleanInstall()
122 else:
123 main.log.warn( "Did not pull new code so skipping mvn " +
124 "clean install" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800125 main.ONOSbench.getVersion( report=True )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800126
Jon Hall6aec96b2015-01-19 14:49:31 -0800127 main.step( "Creating ONOS package" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800128 packageResult = main.ONOSbench.onosPackage()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800129
Jon Hall6aec96b2015-01-19 14:49:31 -0800130 main.step( "Installing ONOS package" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800131 onos1InstallResult = main.ONOSbench.onosInstall( options="-f",
132 node=ONOS1Ip )
133 onos2InstallResult = main.ONOSbench.onosInstall( options="-f",
134 node=ONOS2Ip )
135 onos3InstallResult = main.ONOSbench.onosInstall( options="-f",
136 node=ONOS3Ip )
137 onos4InstallResult = main.ONOSbench.onosInstall( options="-f",
138 node=ONOS4Ip )
139 onos5InstallResult = main.ONOSbench.onosInstall( options="-f",
140 node=ONOS5Ip )
141 onos6InstallResult = main.ONOSbench.onosInstall( options="-f",
142 node=ONOS6Ip )
143 onos7InstallResult = main.ONOSbench.onosInstall( options="-f",
144 node=ONOS7Ip )
145 onosInstallResult = onos1InstallResult and onos2InstallResult\
146 and onos3InstallResult and onos4InstallResult\
147 and onos5InstallResult and onos6InstallResult\
148 and onos7InstallResult
Jon Hall73cf9cc2014-11-20 22:28:38 -0800149
Jon Hall6aec96b2015-01-19 14:49:31 -0800150 main.step( "Checking if ONOS is up yet" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800151 for i in range( 2 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800152 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
153 if not onos1Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800154 main.log.report( "ONOS1 didn't start!" )
Jon Hall21270ac2015-02-16 17:59:55 -0800155 main.ONOSbench.onosStop( ONOS1Ip )
156 main.ONOSbench.onosStart( ONOS1Ip )
Jon Hall8f89dda2015-01-22 16:03:33 -0800157 onos2Isup = main.ONOSbench.isup( ONOS2Ip )
158 if not onos2Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800159 main.log.report( "ONOS2 didn't start!" )
Jon Hall21270ac2015-02-16 17:59:55 -0800160 main.ONOSbench.onosStop( ONOS2Ip )
161 main.ONOSbench.onosStart( ONOS2Ip )
Jon Hall8f89dda2015-01-22 16:03:33 -0800162 onos3Isup = main.ONOSbench.isup( ONOS3Ip )
163 if not onos3Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800164 main.log.report( "ONOS3 didn't start!" )
Jon Hall21270ac2015-02-16 17:59:55 -0800165 main.ONOSbench.onosStop( ONOS3Ip )
166 main.ONOSbench.onosStart( ONOS3Ip )
Jon Hall8f89dda2015-01-22 16:03:33 -0800167 onos4Isup = main.ONOSbench.isup( ONOS4Ip )
168 if not onos4Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800169 main.log.report( "ONOS4 didn't start!" )
Jon Hall21270ac2015-02-16 17:59:55 -0800170 main.ONOSbench.onosStop( ONOS4Ip )
171 main.ONOSbench.onosStart( ONOS4Ip )
Jon Hall8f89dda2015-01-22 16:03:33 -0800172 onos5Isup = main.ONOSbench.isup( ONOS5Ip )
173 if not onos5Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800174 main.log.report( "ONOS5 didn't start!" )
Jon Hall21270ac2015-02-16 17:59:55 -0800175 main.ONOSbench.onosStop( ONOS5Ip )
176 main.ONOSbench.onosStart( ONOS5Ip )
Jon Hall8f89dda2015-01-22 16:03:33 -0800177 onos6Isup = main.ONOSbench.isup( ONOS6Ip )
178 if not onos6Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800179 main.log.report( "ONOS6 didn't start!" )
Jon Hall21270ac2015-02-16 17:59:55 -0800180 main.ONOSbench.onosStop( ONOS6Ip )
181 main.ONOSbench.onosStart( ONOS6Ip )
Jon Hall8f89dda2015-01-22 16:03:33 -0800182 onos7Isup = main.ONOSbench.isup( ONOS7Ip )
183 if not onos7Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800184 main.log.report( "ONOS7 didn't start!" )
Jon Hall21270ac2015-02-16 17:59:55 -0800185 main.ONOSbench.onosStop( ONOS7Ip )
186 main.ONOSbench.onosStart( ONOS7Ip )
Jon Hall8f89dda2015-01-22 16:03:33 -0800187 onosIsupResult = onos1Isup and onos2Isup and onos3Isup\
188 and onos4Isup and onos5Isup and onos6Isup and onos7Isup
189 if onosIsupResult == main.TRUE:
Jon Hall94fd0472014-12-08 11:52:42 -0800190 break
Jon Hall73cf9cc2014-11-20 22:28:38 -0800191
Jon Hall8f89dda2015-01-22 16:03:33 -0800192 cliResult1 = main.ONOScli1.startOnosCli( ONOS1Ip )
193 cliResult2 = main.ONOScli2.startOnosCli( ONOS2Ip )
194 cliResult3 = main.ONOScli3.startOnosCli( ONOS3Ip )
195 cliResult4 = main.ONOScli4.startOnosCli( ONOS4Ip )
196 cliResult5 = main.ONOScli5.startOnosCli( ONOS5Ip )
197 cliResult6 = main.ONOScli6.startOnosCli( ONOS6Ip )
198 cliResult7 = main.ONOScli7.startOnosCli( ONOS7Ip )
199 cliResults = cliResult1 and cliResult2 and cliResult3 and\
200 cliResult4 and cliResult5 and cliResult6 and cliResult7
Jon Hall73cf9cc2014-11-20 22:28:38 -0800201
Jon Hall6aec96b2015-01-19 14:49:31 -0800202 main.step( "Start Packet Capture MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800203 main.Mininet2.startTcpdump(
Jon Hall6aec96b2015-01-19 14:49:31 -0800204 str( main.params[ 'MNtcpdump' ][ 'folder' ] ) + str( main.TEST )
205 + "-MN.pcap",
206 intf=main.params[ 'MNtcpdump' ][ 'intf' ],
207 port=main.params[ 'MNtcpdump' ][ 'port' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800208
Jon Hall8f89dda2015-01-22 16:03:33 -0800209 case1Result = ( cleanInstallResult and packageResult and
210 cellResult and verifyResult and onosInstallResult
211 and onosIsupResult and cliResults )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800212
Jon Hall8f89dda2015-01-22 16:03:33 -0800213 utilities.assert_equals( expect=main.TRUE, actual=case1Result,
Jon Hall58c76b72015-02-23 11:09:24 -0800214 onpass="Test startup successful",
215 onfail="Test startup NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800216
Jon Hall8f89dda2015-01-22 16:03:33 -0800217 if case1Result == main.FALSE:
Jon Hall94fd0472014-12-08 11:52:42 -0800218 main.cleanup()
219 main.exit()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800220
Jon Hall6aec96b2015-01-19 14:49:31 -0800221 def CASE2( self, main ):
222 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800223 Assign mastership to controllers
Jon Hall6aec96b2015-01-19 14:49:31 -0800224 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800225 import re
226
Jon Hall6aec96b2015-01-19 14:49:31 -0800227 main.log.report( "Assigning switches to controllers" )
228 main.case( "Assigning Controllers" )
229 main.step( "Assign switches to controllers" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800230
Jon Hall6aec96b2015-01-19 14:49:31 -0800231 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800232 main.Mininet1.assignSwController(
Jon Hall6aec96b2015-01-19 14:49:31 -0800233 sw=str( i ),
Jon Hall8f89dda2015-01-22 16:03:33 -0800234 count=numControllers,
235 ip1=ONOS1Ip, port1=ONOS1Port,
236 ip2=ONOS2Ip, port2=ONOS2Port,
237 ip3=ONOS3Ip, port3=ONOS3Port,
238 ip4=ONOS4Ip, port4=ONOS4Port,
239 ip5=ONOS5Ip, port5=ONOS5Port,
240 ip6=ONOS6Ip, port6=ONOS6Port,
241 ip7=ONOS7Ip, port7=ONOS7Port )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800242
Jon Hall8f89dda2015-01-22 16:03:33 -0800243 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800244 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800245 response = main.Mininet1.getSwController( "s" + str( i ) )
Jon Hallffb386d2014-11-21 13:43:38 -0800246 try:
Jon Hall6aec96b2015-01-19 14:49:31 -0800247 main.log.info( str( response ) )
Jon Hallffb386d2014-11-21 13:43:38 -0800248 except:
Jon Hall6aec96b2015-01-19 14:49:31 -0800249 main.log.info( repr( response ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800250 if re.search( "tcp:" + ONOS1Ip, response )\
251 and re.search( "tcp:" + ONOS2Ip, response )\
252 and re.search( "tcp:" + ONOS3Ip, response )\
253 and re.search( "tcp:" + ONOS4Ip, response )\
254 and re.search( "tcp:" + ONOS5Ip, response )\
255 and re.search( "tcp:" + ONOS6Ip, response )\
256 and re.search( "tcp:" + ONOS7Ip, response ):
257 mastershipCheck = mastershipCheck and main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800258 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800259 mastershipCheck = main.FALSE
260 if mastershipCheck == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800261 main.log.report( "Switch mastership assigned correctly" )
262 utilities.assert_equals(
263 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800264 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800265 onpass="Switch mastership assigned correctly",
266 onfail="Switches not assigned correctly to controllers" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800267
Jon Hall6aec96b2015-01-19 14:49:31 -0800268 # Manually assign mastership to the controller we want
Jon Hall8f89dda2015-01-22 16:03:33 -0800269 roleCall = main.TRUE
270 roleCheck = main.TRUE
Jon Hall58c76b72015-02-23 11:09:24 -0800271 try:
272 # Assign switch
273 deviceId = main.ONOScli1.getDevice( "1000" ).get( 'id' )
274 assert deviceId, "No device id for s1 in ONOS"
Jon Hall8f89dda2015-01-22 16:03:33 -0800275 roleCall = roleCall and main.ONOScli1.deviceRole(
276 deviceId,
Jon Hall58c76b72015-02-23 11:09:24 -0800277 ONOS1Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800278 # Check assignment
Jon Hall58c76b72015-02-23 11:09:24 -0800279 if ONOS1Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800280 roleCheck = roleCheck and main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800281 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800282 roleCheck = roleCheck and main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800283
Jon Hall58c76b72015-02-23 11:09:24 -0800284 # Assign switch
285 deviceId = main.ONOScli1.getDevice( "2800" ).get( 'id' )
286 assert deviceId, "No device id for s28 in ONOS"
Jon Hall8f89dda2015-01-22 16:03:33 -0800287 roleCall = roleCall and main.ONOScli1.deviceRole(
288 deviceId,
Jon Hall58c76b72015-02-23 11:09:24 -0800289 ONOS1Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800290 # Check assignment
Jon Hall58c76b72015-02-23 11:09:24 -0800291 if ONOS1Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800292 roleCheck = roleCheck and main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800293 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800294 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800295
Jon Hall58c76b72015-02-23 11:09:24 -0800296 # Assign switch
297 deviceId = main.ONOScli1.getDevice( "2000" ).get( 'id' )
298 assert deviceId, "No device id for s2 in ONOS"
299 roleCall = roleCall and main.ONOScli1.deviceRole(
300 deviceId,
301 ONOS2Ip )
302 # Check assignment
303 if ONOS2Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
304 roleCheck = roleCheck and main.TRUE
305 else:
306 roleCheck = roleCheck and main.FALSE
307
308 # Assign switch
309 deviceId = main.ONOScli1.getDevice( "3000" ).get( 'id' )
310 assert deviceId, "No device id for s3 in ONOS"
311 roleCall = roleCall and main.ONOScli1.deviceRole(
312 deviceId,
313 ONOS2Ip )
314 # Check assignment
315 if ONOS2Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
316 roleCheck = roleCheck and main.TRUE
317 else:
318 roleCheck = roleCheck and main.FALSE
319
320 # Assign switch
321 deviceId = main.ONOScli1.getDevice( "5000" ).get( 'id' )
322 assert deviceId, "No device id for s5 in ONOS"
323 roleCall = roleCall and main.ONOScli1.deviceRole(
324 deviceId,
325 ONOS3Ip )
326 # Check assignment
327 if ONOS3Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
328 roleCheck = roleCheck and main.TRUE
329 else:
330 roleCheck = roleCheck and main.FALSE
331
332 # Assign switch
333 deviceId = main.ONOScli1.getDevice( "6000" ).get( 'id' )
334 assert deviceId, "No device id for s6 in ONOS"
335 roleCall = roleCall and main.ONOScli1.deviceRole(
336 deviceId,
337 ONOS3Ip )
338 # Check assignment
339 if ONOS3Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
340 roleCheck = roleCheck and main.TRUE
341 else:
342 roleCheck = roleCheck and main.FALSE
343
344 # Assign switch
345 deviceId = main.ONOScli1.getDevice( "3004" ).get( 'id' )
346 assert deviceId, "No device id for s4 in ONOS"
347 roleCall = roleCall and main.ONOScli1.deviceRole(
348 deviceId,
349 ONOS4Ip )
350 # Check assignment
351 if ONOS4Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
352 roleCheck = roleCheck and main.TRUE
353 else:
354 roleCheck = roleCheck and main.FALSE
355
356 for i in range( 8, 18 ):
357 dpid = '3' + str( i ).zfill( 3 )
358 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
359 assert deviceId, "No device id for s%i in ONOS" % i
360 roleCall = roleCall and main.ONOScli1.deviceRole(
361 deviceId,
362 ONOS5Ip )
363 # Check assignment
364 if ONOS5Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
365 roleCheck = roleCheck and main.TRUE
366 else:
367 roleCheck = roleCheck and main.FALSE
368
369 deviceId = main.ONOScli1.getDevice( "6007" ).get( 'id' )
370 assert deviceId, "No device id for s7 in ONOS"
371 roleCall = roleCall and main.ONOScli1.deviceRole(
372 deviceId,
373 ONOS6Ip )
374 # Check assignment
375 if ONOS6Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
376 roleCheck = roleCheck and main.TRUE
377 else:
378 roleCheck = roleCheck and main.FALSE
379
380 for i in range( 18, 28 ):
381 dpid = '6' + str( i ).zfill( 3 )
382 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
383 assert deviceId, "No device id for s%i in ONOS" % i
384 roleCall = roleCall and main.ONOScli1.deviceRole(
385 deviceId,
386 ONOS7Ip )
387 # Check assignment
388 if ONOS7Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
389 roleCheck = roleCheck and main.TRUE
390 else:
391 roleCheck = roleCheck and main.FALSE
392 except ( AttributeError, AssertionError ):
393 main.log.exception( "Something is wrong with ONOS device view" )
394 main.log.info( main.ONOScli1.devices() )
395
Jon Hall6aec96b2015-01-19 14:49:31 -0800396 utilities.assert_equals(
397 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800398 actual=roleCall,
Jon Hall6aec96b2015-01-19 14:49:31 -0800399 onpass="Re-assigned switch mastership to designated controller",
Jon Hall8f89dda2015-01-22 16:03:33 -0800400 onfail="Something wrong with deviceRole calls" )
Jon Hall94fd0472014-12-08 11:52:42 -0800401
Jon Hall6aec96b2015-01-19 14:49:31 -0800402 utilities.assert_equals(
403 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800404 actual=roleCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800405 onpass="Switches were successfully reassigned to designated " +
406 "controller",
407 onfail="Switches were not successfully reassigned" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800408 mastershipCheck = mastershipCheck and roleCall and roleCheck
409 utilities.assert_equals( expect=main.TRUE, actual=mastershipCheck,
Jon Hall21270ac2015-02-16 17:59:55 -0800410 onpass="Switch mastership correctly assigned",
411 onfail="Error in (re)assigning switch" +
412 " mastership" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800413
Jon Hall6aec96b2015-01-19 14:49:31 -0800414 def CASE3( self, main ):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800415 """
416 Assign intents
Jon Hall73cf9cc2014-11-20 22:28:38 -0800417 """
418 import time
Jon Hall58c76b72015-02-23 11:09:24 -0800419 import json
Jon Hall6aec96b2015-01-19 14:49:31 -0800420 main.log.report( "Adding host intents" )
421 main.case( "Adding host Intents" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800422
Jon Hall8f89dda2015-01-22 16:03:33 -0800423 main.step( "Discovering Hosts( Via pingall for now )" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800424 # FIXME: Once we have a host discovery mechanism, use that instead
Jon Hall73cf9cc2014-11-20 22:28:38 -0800425
Jon Hall6aec96b2015-01-19 14:49:31 -0800426 # install onos-app-fwd
427 main.log.info( "Install reactive forwarding app" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800428 main.ONOScli1.featureInstall( "onos-app-fwd" )
429 main.ONOScli2.featureInstall( "onos-app-fwd" )
430 main.ONOScli3.featureInstall( "onos-app-fwd" )
431 main.ONOScli4.featureInstall( "onos-app-fwd" )
432 main.ONOScli5.featureInstall( "onos-app-fwd" )
433 main.ONOScli6.featureInstall( "onos-app-fwd" )
434 main.ONOScli7.featureInstall( "onos-app-fwd" )
Jon Hall94fd0472014-12-08 11:52:42 -0800435
Jon Hall6aec96b2015-01-19 14:49:31 -0800436 # REACTIVE FWD test
Jon Hall8f89dda2015-01-22 16:03:33 -0800437 pingResult = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800438 time1 = time.time()
Jon Hall8f89dda2015-01-22 16:03:33 -0800439 pingResult = main.Mininet1.pingall()
Jon Hall529a37f2015-01-28 10:02:00 -0800440 utilities.assert_equals(
441 expect=main.TRUE,
442 actual=pingResult,
443 onpass="Reactive Pingall test passed",
444 onfail="Reactive Pingall failed, one or more ping pairs failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800445 time2 = time.time()
Jon Hall6aec96b2015-01-19 14:49:31 -0800446 main.log.info( "Time for pingall: %2f seconds" % ( time2 - time1 ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800447
Jon Hall6aec96b2015-01-19 14:49:31 -0800448 # uninstall onos-app-fwd
449 main.log.info( "Uninstall reactive forwarding app" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800450 main.ONOScli1.featureUninstall( "onos-app-fwd" )
451 main.ONOScli2.featureUninstall( "onos-app-fwd" )
452 main.ONOScli3.featureUninstall( "onos-app-fwd" )
453 main.ONOScli4.featureUninstall( "onos-app-fwd" )
454 main.ONOScli5.featureUninstall( "onos-app-fwd" )
455 main.ONOScli6.featureUninstall( "onos-app-fwd" )
456 main.ONOScli7.featureUninstall( "onos-app-fwd" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800457 # timeout for fwd flows
458 time.sleep( 10 )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800459
Jon Hall6aec96b2015-01-19 14:49:31 -0800460 main.step( "Add host intents" )
Jon Hall58c76b72015-02-23 11:09:24 -0800461 intentIds = []
Jon Hall6aec96b2015-01-19 14:49:31 -0800462 # TODO: move the host numbers to params
Jon Hall58c76b72015-02-23 11:09:24 -0800463 # Maybe look at all the paths we ping?
Jon Hall8f89dda2015-01-22 16:03:33 -0800464 intentAddResult = True
Jon Hall58c76b72015-02-23 11:09:24 -0800465 hostResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800466 for i in range( 8, 18 ):
467 main.log.info( "Adding host intent between h" + str( i ) +
468 " and h" + str( i + 10 ) )
469 host1 = "00:00:00:00:00:" + \
470 str( hex( i )[ 2: ] ).zfill( 2 ).upper()
471 host2 = "00:00:00:00:00:" + \
472 str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper()
Jon Hall1b8f54a2015-02-04 13:24:20 -0800473 # NOTE: getHost can return None
474 host1Dict = main.ONOScli1.getHost( host1 )
475 host2Dict = main.ONOScli1.getHost( host2 )
476 host1Id = None
477 host2Id = None
478 if host1Dict and host2Dict:
479 host1Id = host1Dict.get( 'id', None )
480 host2Id = host2Dict.get( 'id', None )
Jon Hall8f89dda2015-01-22 16:03:33 -0800481 if host1Id and host2Id:
Jon Hall58c76b72015-02-23 11:09:24 -0800482 # Changed onos node to test something
483 tmpId = main.ONOScli4.addHostIntent(
Jon Hall8f89dda2015-01-22 16:03:33 -0800484 host1Id,
485 host2Id )
Jon Hall58c76b72015-02-23 11:09:24 -0800486 main.log.info( "Added intent with id: " + tmpId )
487 intentIds.append( tmpId )
Jon Hall669173b2014-12-17 11:36:30 -0800488 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800489 main.log.error( "Error, getHost() failed" )
Jon Hall1b8f54a2015-02-04 13:24:20 -0800490 main.log.warn( json.dumps( json.loads( main.ONOScli1.hosts() ),
491 sort_keys=True,
492 indent=4,
493 separators=( ',', ': ' ) ) )
Jon Hall58c76b72015-02-23 11:09:24 -0800494 hostResult = main.FALSE
495 onosIds = main.ONOScli1.getAllIntentsId()
496 main.log.info( "Submitted intents: " + str( intentIds ) )
497 main.log.info( "Intents in ONOS: " + str( onosIds ) )
498 for intent in intentIds:
499 if intent in onosIds:
500 pass # intent submitted is still in onos
501 else:
502 intentAddResult = False
Jon Hall1b8f54a2015-02-04 13:24:20 -0800503 # Print the intent states
Jon Hall58c76b72015-02-23 11:09:24 -0800504 intents = main.ONOScli1.intents()
Jon Hall1b8f54a2015-02-04 13:24:20 -0800505 intentStates = []
Jon Hall58c76b72015-02-23 11:09:24 -0800506 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
507 count = 0
Jon Hall1b8f54a2015-02-04 13:24:20 -0800508 for intent in json.loads( intents ): # Iter through intents of a node
Jon Hall58c76b72015-02-23 11:09:24 -0800509 state = intent.get( 'state', None )
510 intentId = intent.get( 'id', None )
511 intentStates.append( ( intentId, state ) )
512 # add submitted intents not in the store
513 tmplist = [ i for i, s in intentStates ]
514 missingIntents = False
515 for i in intentIds:
516 if i not in tmplist:
517 intentStates.append( ( i, " - " ) )
518 missingIntents = True
519 intentStates.sort()
520 for i, s in intentStates:
521 count += 1
522 main.log.info( "%-6s%-15s%-15s" %
523 ( str( count ), str( i ), str( s ) ) )
524 intentAddResult = bool( pingResult and hostResult and intentAddResult
525 and not missingIntents)
Jon Hall6aec96b2015-01-19 14:49:31 -0800526 utilities.assert_equals(
527 expect=True,
Jon Hall8f89dda2015-01-22 16:03:33 -0800528 actual=intentAddResult,
Jon Hall529a37f2015-01-28 10:02:00 -0800529 onpass="Pushed host intents to ONOS",
530 onfail="Error in pushing host intents to ONOS" )
Jon Hall58c76b72015-02-23 11:09:24 -0800531
532 if not intentAddResult:
533 import time
534 main.log.info( "Sleeping 60 seconds to see if intents are found" )
535 time.sleep( 60 )
536 onosIds = main.ONOScli1.getAllIntentsId()
537 main.log.info( "Submitted intents: " + str( intentIds ) )
538 main.log.info( "Intents in ONOS: " + str( onosIds ) )
539 # Print the intent states
540 intents = main.ONOScli1.intents()
541 intentStates = []
542 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
543 count = 0
544 for intent in json.loads( intents ):
545 # Iter through intents of a node
546 state = intent.get( 'state', None )
547 intentId = intent.get( 'id', None )
548 intentStates.append( ( intentId, state ) )
549 # add submitted intents not in the store
550 tmplist = [ i for i, s in intentStates ]
551 for i in intentIds:
552 if i not in tmplist:
553 intentStates.append( ( i, " - " ) )
554 intentStates.sort()
555 for i, s in intentStates:
556 count += 1
557 main.log.info( "%-6s%-15s%-15s" %
558 ( str( count ), str( i ), str( s ) ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800559
Jon Hall6aec96b2015-01-19 14:49:31 -0800560 def CASE4( self, main ):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800561 """
562 Ping across added host intents
563 """
Jon Hall58c76b72015-02-23 11:09:24 -0800564 import json
Jon Hall73cf9cc2014-11-20 22:28:38 -0800565 description = " Ping across added host intents"
Jon Hall6aec96b2015-01-19 14:49:31 -0800566 main.log.report( description )
567 main.case( description )
Jon Hall8f89dda2015-01-22 16:03:33 -0800568 PingResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800569 for i in range( 8, 18 ):
Jon Hall21270ac2015-02-16 17:59:55 -0800570 ping = main.Mininet1.pingHost( src="h" + str( i ),
571 target="h" + str( i + 10 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800572 PingResult = PingResult and ping
Jon Hall6aec96b2015-01-19 14:49:31 -0800573 if ping == main.FALSE:
574 main.log.warn( "Ping failed between h" + str( i ) +
575 " and h" + str( i + 10 ) )
576 elif ping == main.TRUE:
577 main.log.info( "Ping test passed!" )
Jon Hall21270ac2015-02-16 17:59:55 -0800578 # Don't set PingResult or you'd override failures
Jon Hall8f89dda2015-01-22 16:03:33 -0800579 if PingResult == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800580 main.log.report(
581 "Intents have not been installed correctly, pings failed." )
Jon Hall58c76b72015-02-23 11:09:24 -0800582 # TODO: pretty print
Jon Hall529a37f2015-01-28 10:02:00 -0800583 main.log.warn( "ONSO1 intents: " )
584 main.log.warn( json.dumps( json.loads( main.ONOScli1.intents() ),
585 sort_keys=True,
586 indent=4,
587 separators=( ',', ': ' ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800588 if PingResult == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800589 main.log.report(
590 "Intents have been installed correctly and verified by pings" )
591 utilities.assert_equals(
592 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800593 actual=PingResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800594 onpass="Intents have been installed correctly and pings work",
595 onfail="Intents have not been installed correctly, pings failed." )
Jon Hall58c76b72015-02-23 11:09:24 -0800596 if PingResult is not main.TRUE:
597 # Print the intent states
598 intents = main.ONOScli1.intents()
599 intentStates = []
600 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
601 count = 0
602 # Iter through intents of a node
603 for intent in json.loads( intents ):
604 state = intent.get( 'state', None )
605 intentId = intent.get( 'id', None )
606 intentStates.append( ( intentId, state ) )
607 intentStates.sort()
608 for i, s in intentStates:
609 count += 1
610 main.log.info( "%-6s%-15s%-15s" %
611 ( str( count ), str( i ), str( s ) ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800612
Jon Hall6aec96b2015-01-19 14:49:31 -0800613 def CASE5( self, main ):
614 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800615 Reading state of ONOS
Jon Hall6aec96b2015-01-19 14:49:31 -0800616 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800617 import json
Jon Hall6aec96b2015-01-19 14:49:31 -0800618 # assumes that sts is already in you PYTHONPATH
619 from sts.topology.teston_topology import TestONTopology
Jon Hall73cf9cc2014-11-20 22:28:38 -0800620
Jon Hall6aec96b2015-01-19 14:49:31 -0800621 main.log.report( "Setting up and gathering data for current state" )
622 main.case( "Setting up and gathering data for current state" )
623 # The general idea for this test case is to pull the state of
624 # ( intents,flows, topology,... ) from each ONOS node
625 # We can then compare them with eachother and also with past states
Jon Hall73cf9cc2014-11-20 22:28:38 -0800626
Jon Hall6aec96b2015-01-19 14:49:31 -0800627 main.step( "Get the Mastership of each switch from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800628 global mastershipState
629 mastershipState = []
Jon Hall94fd0472014-12-08 11:52:42 -0800630
Jon Hall6aec96b2015-01-19 14:49:31 -0800631 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -0800632 ONOS1MasterNotNull = main.ONOScli1.rolesNotNull()
633 ONOS2MasterNotNull = main.ONOScli2.rolesNotNull()
634 ONOS3MasterNotNull = main.ONOScli3.rolesNotNull()
635 ONOS4MasterNotNull = main.ONOScli4.rolesNotNull()
636 ONOS5MasterNotNull = main.ONOScli5.rolesNotNull()
637 ONOS6MasterNotNull = main.ONOScli6.rolesNotNull()
638 ONOS7MasterNotNull = main.ONOScli7.rolesNotNull()
639 rolesNotNull = ONOS1MasterNotNull and ONOS2MasterNotNull and\
640 ONOS3MasterNotNull and ONOS4MasterNotNull and\
641 ONOS5MasterNotNull and ONOS6MasterNotNull and\
642 ONOS7MasterNotNull
Jon Hall6aec96b2015-01-19 14:49:31 -0800643 utilities.assert_equals(
644 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800645 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -0800646 onpass="Each device has a master",
647 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -0800648
Jon Hall8f89dda2015-01-22 16:03:33 -0800649 ONOS1Mastership = main.ONOScli1.roles()
650 ONOS2Mastership = main.ONOScli2.roles()
651 ONOS3Mastership = main.ONOScli3.roles()
652 ONOS4Mastership = main.ONOScli4.roles()
653 ONOS5Mastership = main.ONOScli5.roles()
654 ONOS6Mastership = main.ONOScli6.roles()
655 ONOS7Mastership = main.ONOScli7.roles()
656 if "Error" in ONOS1Mastership or not ONOS1Mastership\
657 or "Error" in ONOS2Mastership or not ONOS2Mastership\
658 or "Error" in ONOS3Mastership or not ONOS3Mastership\
659 or "Error" in ONOS4Mastership or not ONOS4Mastership\
660 or "Error" in ONOS5Mastership or not ONOS5Mastership\
661 or "Error" in ONOS6Mastership or not ONOS6Mastership\
662 or "Error" in ONOS7Mastership or not ONOS7Mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -0800663 main.log.report( "Error in getting ONOS roles" )
664 main.log.warn(
665 "ONOS1 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800666 repr( ONOS1Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800667 main.log.warn(
668 "ONOS2 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800669 repr( ONOS2Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800670 main.log.warn(
671 "ONOS3 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800672 repr( ONOS3Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800673 main.log.warn(
674 "ONOS4 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800675 repr( ONOS4Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800676 main.log.warn(
677 "ONOS5 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800678 repr( ONOS5Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800679 main.log.warn(
680 "ONOS6 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800681 repr( ONOS6Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800682 main.log.warn(
683 "ONOS7 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800684 repr( ONOS7Mastership ) )
685 consistentMastership = main.FALSE
686 elif ONOS1Mastership == ONOS2Mastership\
687 and ONOS1Mastership == ONOS3Mastership\
688 and ONOS1Mastership == ONOS4Mastership\
689 and ONOS1Mastership == ONOS5Mastership\
690 and ONOS1Mastership == ONOS6Mastership\
691 and ONOS1Mastership == ONOS7Mastership:
692 mastershipState = ONOS1Mastership
693 consistentMastership = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800694 main.log.report(
695 "Switch roles are consistent across all ONOS nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800696 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800697 main.log.warn(
698 "ONOS1 roles: ",
699 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800700 json.loads( ONOS1Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800701 sort_keys=True,
702 indent=4,
703 separators=(
704 ',',
705 ': ' ) ) )
706 main.log.warn(
707 "ONOS2 roles: ",
708 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800709 json.loads( ONOS2Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800710 sort_keys=True,
711 indent=4,
712 separators=(
713 ',',
714 ': ' ) ) )
715 main.log.warn(
716 "ONOS3 roles: ",
717 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800718 json.loads( ONOS3Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800719 sort_keys=True,
720 indent=4,
721 separators=(
722 ',',
723 ': ' ) ) )
724 main.log.warn(
725 "ONOS4 roles: ",
726 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800727 json.loads( ONOS4Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800728 sort_keys=True,
729 indent=4,
730 separators=(
731 ',',
732 ': ' ) ) )
733 main.log.warn(
734 "ONOS5 roles: ",
735 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800736 json.loads( ONOS5Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800737 sort_keys=True,
738 indent=4,
739 separators=(
740 ',',
741 ': ' ) ) )
742 main.log.warn(
743 "ONOS6 roles: ",
744 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800745 json.loads( ONOS6Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800746 sort_keys=True,
747 indent=4,
748 separators=(
749 ',',
750 ': ' ) ) )
751 main.log.warn(
752 "ONOS7 roles: ",
753 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800754 json.loads( ONOS7Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800755 sort_keys=True,
756 indent=4,
757 separators=(
758 ',',
759 ': ' ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800760 consistentMastership = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800761 utilities.assert_equals(
762 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800763 actual=consistentMastership,
Jon Hall6aec96b2015-01-19 14:49:31 -0800764 onpass="Switch roles are consistent across all ONOS nodes",
765 onfail="ONOS nodes have different views of switch roles" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800766
Jon Hall6aec96b2015-01-19 14:49:31 -0800767 main.step( "Get the intents from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800768 global intentState
769 intentState = []
770 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
771 ONOS2Intents = main.ONOScli2.intents( jsonFormat=True )
772 ONOS3Intents = main.ONOScli3.intents( jsonFormat=True )
773 ONOS4Intents = main.ONOScli4.intents( jsonFormat=True )
774 ONOS5Intents = main.ONOScli5.intents( jsonFormat=True )
775 ONOS6Intents = main.ONOScli6.intents( jsonFormat=True )
776 ONOS7Intents = main.ONOScli7.intents( jsonFormat=True )
777 intentCheck = main.FALSE
778 if "Error" in ONOS1Intents or not ONOS1Intents\
779 or "Error" in ONOS2Intents or not ONOS2Intents\
780 or "Error" in ONOS3Intents or not ONOS3Intents\
781 or "Error" in ONOS4Intents or not ONOS4Intents\
782 or "Error" in ONOS5Intents or not ONOS5Intents\
783 or "Error" in ONOS6Intents or not ONOS6Intents\
784 or "Error" in ONOS7Intents or not ONOS7Intents:
Jon Hall6aec96b2015-01-19 14:49:31 -0800785 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800786 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
787 main.log.warn( "ONOS2 intents response: " + repr( ONOS2Intents ) )
788 main.log.warn( "ONOS3 intents response: " + repr( ONOS3Intents ) )
789 main.log.warn( "ONOS4 intents response: " + repr( ONOS4Intents ) )
790 main.log.warn( "ONOS5 intents response: " + repr( ONOS5Intents ) )
791 main.log.warn( "ONOS6 intents response: " + repr( ONOS6Intents ) )
792 main.log.warn( "ONOS7 intents response: " + repr( ONOS7Intents ) )
793 elif ONOS1Intents == ONOS2Intents\
794 and ONOS1Intents == ONOS3Intents\
795 and ONOS1Intents == ONOS4Intents\
796 and ONOS1Intents == ONOS5Intents\
797 and ONOS1Intents == ONOS6Intents\
798 and ONOS1Intents == ONOS7Intents:
799 intentState = ONOS1Intents
800 intentCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800801 main.log.report( "Intents are consistent across all ONOS nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800802 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800803 main.log.warn(
804 "ONOS1 intents: ",
805 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800806 json.loads( ONOS1Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800807 sort_keys=True,
808 indent=4,
809 separators=(
810 ',',
811 ': ' ) ) )
812 main.log.warn(
813 "ONOS2 intents: ",
814 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800815 json.loads( ONOS2Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800816 sort_keys=True,
817 indent=4,
818 separators=(
819 ',',
820 ': ' ) ) )
821 main.log.warn(
822 "ONOS3 intents: ",
823 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800824 json.loads( ONOS3Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800825 sort_keys=True,
826 indent=4,
827 separators=(
828 ',',
829 ': ' ) ) )
830 main.log.warn(
831 "ONOS4 intents: ",
832 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800833 json.loads( ONOS4Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800834 sort_keys=True,
835 indent=4,
836 separators=(
837 ',',
838 ': ' ) ) )
839 main.log.warn(
840 "ONOS5 intents: ",
841 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800842 json.loads( ONOS5Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800843 sort_keys=True,
844 indent=4,
845 separators=(
846 ',',
847 ': ' ) ) )
848 main.log.warn(
849 "ONOS6 intents: ",
850 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800851 json.loads( ONOS6Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800852 sort_keys=True,
853 indent=4,
854 separators=(
855 ',',
856 ': ' ) ) )
857 main.log.warn(
858 "ONOS7 intents: ",
859 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800860 json.loads( ONOS7Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800861 sort_keys=True,
862 indent=4,
863 separators=(
864 ',',
865 ': ' ) ) )
866 utilities.assert_equals(
867 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800868 actual=intentCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800869 onpass="Intents are consistent across all ONOS nodes",
870 onfail="ONOS nodes have different views of intents" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800871
Jon Hall6aec96b2015-01-19 14:49:31 -0800872 main.step( "Get the flows from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800873 global flowState
874 flowState = []
Jon Hall8f89dda2015-01-22 16:03:33 -0800875 flowCheck = main.FALSE
Jon Hall58c76b72015-02-23 11:09:24 -0800876 try:
877 ONOS1Flows = main.ONOScli1.flows( jsonFormat=True )
878 ONOS2Flows = main.ONOScli2.flows( jsonFormat=True )
879 ONOS3Flows = main.ONOScli3.flows( jsonFormat=True )
880 ONOS4Flows = main.ONOScli4.flows( jsonFormat=True )
881 ONOS5Flows = main.ONOScli5.flows( jsonFormat=True )
882 ONOS6Flows = main.ONOScli6.flows( jsonFormat=True )
883 ONOS7Flows = main.ONOScli7.flows( jsonFormat=True )
884 assert ONOS1Flows, "ONOS1 Flows should not be empty"
885 assert ONOS2Flows, "ONOS2 Flows should not be empty"
886 assert ONOS3Flows, "ONOS3 Flows should not be empty"
887 assert ONOS4Flows, "ONOS4 Flows should not be empty"
888 assert ONOS5Flows, "ONOS5 Flows should not be empty"
889 assert ONOS6Flows, "ONOS6 Flows should not be empty"
890 assert ONOS7Flows, "ONOS7 Flows should not be empty"
891 assert "Error" not in ONOS1Flows, "ONOS1 Flows contains 'Error'"
892 assert "Error" not in ONOS2Flows, "ONOS2 Flows contains 'Error'"
893 assert "Error" not in ONOS3Flows, "ONOS3 Flows contains 'Error'"
894 assert "Error" not in ONOS4Flows, "ONOS4 Flows contains 'Error'"
895 assert "Error" not in ONOS5Flows, "ONOS5 Flows contains 'Error'"
896 assert "Error" not in ONOS6Flows, "ONOS6 Flows contains 'Error'"
897 assert "Error" not in ONOS7Flows, "ONOS7 Flows contains 'Error'"
898 ONOS1FlowsJson = json.loads( ONOS1Flows )
899 ONOS2FlowsJson = json.loads( ONOS2Flows )
900 ONOS3FlowsJson = json.loads( ONOS3Flows )
901 ONOS4FlowsJson = json.loads( ONOS4Flows )
902 ONOS5FlowsJson = json.loads( ONOS5Flows )
903 ONOS6FlowsJson = json.loads( ONOS6Flows )
904 ONOS7FlowsJson = json.loads( ONOS7Flows )
905 except ( ValueError, AssertionError ): # From json.loads, or asserts
906 main.log.exception( "One or more 'flows' responses from " +
907 "ONOS couldn't be decoded." )
Jon Hall8f89dda2015-01-22 16:03:33 -0800908 main.log.warn( "ONOS1 flows repsponse: " + ONOS1Flows )
909 main.log.warn( "ONOS2 flows repsponse: " + ONOS2Flows )
910 main.log.warn( "ONOS3 flows repsponse: " + ONOS3Flows )
911 main.log.warn( "ONOS4 flows repsponse: " + ONOS4Flows )
912 main.log.warn( "ONOS5 flows repsponse: " + ONOS5Flows )
913 main.log.warn( "ONOS6 flows repsponse: " + ONOS6Flows )
914 main.log.warn( "ONOS7 flows repsponse: " + ONOS7Flows )
Jon Hall58c76b72015-02-23 11:09:24 -0800915 else: # No exceptions
916 if len( ONOS1FlowsJson ) == len( ONOS2FlowsJson )\
917 and len( ONOS1FlowsJson ) == len( ONOS3FlowsJson )\
918 and len( ONOS1FlowsJson ) == len( ONOS4FlowsJson )\
919 and len( ONOS1FlowsJson ) == len( ONOS5FlowsJson )\
920 and len( ONOS1FlowsJson ) == len( ONOS6FlowsJson )\
921 and len( ONOS1FlowsJson ) == len( ONOS7FlowsJson ):
Jon Hall6aec96b2015-01-19 14:49:31 -0800922 # TODO: Do a better check, maybe compare flows on switches?
Jon Hall58c76b72015-02-23 11:09:24 -0800923 # NOTE Possible issue with this not always being set?
924 flowState = ONOS1Flows
925 flowCheck = main.TRUE
926 main.log.report( "Flow count is consistent across all" +
927 " ONOS nodes" )
928 else:
929 main.log.warn( "ONOS1 flows: " +
930 json.dumps( ONOS1FlowsJson, sort_keys=True,
931 indent=4,
932 separators=( ',', ': ' ) ) )
933 main.log.warn( "ONOS2 flows: " +
934 json.dumps( ONOS2FlowsJson, sort_keys=True,
935 indent=4,
936 separators=( ',', ': ' ) ) )
937 main.log.warn( "ONOS3 flows: " +
938 json.dumps( ONOS3FlowsJson, sort_keys=True,
939 indent=4,
940 separators=( ',', ': ' ) ) )
941 main.log.warn( "ONOS4 flows: " +
942 json.dumps( ONOS4FlowsJson, sort_keys=True,
943 indent=4,
944 separators=( ',', ': ' ) ) )
945 main.log.warn( "ONOS5 flows: " +
946 json.dumps( ONOS5FlowsJson, sort_keys=True,
947 indent=4,
948 separators=( ',', ': ' ) ) )
949 main.log.warn( "ONOS6 flows: " +
950 json.dumps( ONOS6FlowsJson, sort_keys=True,
951 indent=4,
952 separators=( ',', ': ' ) ) )
953 main.log.warn( "ONOS7 flows: " +
954 json.dumps( ONOS7FlowsJson, sort_keys=True,
955 indent=4,
956 separators=( ',', ': ' ) ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800957 utilities.assert_equals(
958 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800959 actual=flowCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800960 onpass="The flow count is consistent across all ONOS nodes",
961 onfail="ONOS nodes have different flow counts" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800962
Jon Hall6aec96b2015-01-19 14:49:31 -0800963 main.step( "Get the OF Table entries" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800964 global flows
Jon Hall6aec96b2015-01-19 14:49:31 -0800965 flows = []
966 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800967 flows.append( main.Mininet2.getFlowTable( 1.3, "s" + str( i ) ) )
Jon Hall58c76b72015-02-23 11:09:24 -0800968 if flowCheck == main.FALSE:
969 for table in flows:
970 main.log.warn( table )
Jon Hall6aec96b2015-01-19 14:49:31 -0800971 # TODO: Compare switch flow tables with ONOS flow tables
Jon Hall73cf9cc2014-11-20 22:28:38 -0800972
Jon Hall6aec96b2015-01-19 14:49:31 -0800973 main.step( "Start continuous pings" )
974 main.Mininet2.pingLong(
975 src=main.params[ 'PING' ][ 'source1' ],
976 target=main.params[ 'PING' ][ 'target1' ],
977 pingTime=500 )
978 main.Mininet2.pingLong(
979 src=main.params[ 'PING' ][ 'source2' ],
980 target=main.params[ 'PING' ][ 'target2' ],
981 pingTime=500 )
982 main.Mininet2.pingLong(
983 src=main.params[ 'PING' ][ 'source3' ],
984 target=main.params[ 'PING' ][ 'target3' ],
985 pingTime=500 )
986 main.Mininet2.pingLong(
987 src=main.params[ 'PING' ][ 'source4' ],
988 target=main.params[ 'PING' ][ 'target4' ],
989 pingTime=500 )
990 main.Mininet2.pingLong(
991 src=main.params[ 'PING' ][ 'source5' ],
992 target=main.params[ 'PING' ][ 'target5' ],
993 pingTime=500 )
994 main.Mininet2.pingLong(
995 src=main.params[ 'PING' ][ 'source6' ],
996 target=main.params[ 'PING' ][ 'target6' ],
997 pingTime=500 )
998 main.Mininet2.pingLong(
999 src=main.params[ 'PING' ][ 'source7' ],
1000 target=main.params[ 'PING' ][ 'target7' ],
1001 pingTime=500 )
1002 main.Mininet2.pingLong(
1003 src=main.params[ 'PING' ][ 'source8' ],
1004 target=main.params[ 'PING' ][ 'target8' ],
1005 pingTime=500 )
1006 main.Mininet2.pingLong(
1007 src=main.params[ 'PING' ][ 'source9' ],
1008 target=main.params[ 'PING' ][ 'target9' ],
1009 pingTime=500 )
1010 main.Mininet2.pingLong(
1011 src=main.params[ 'PING' ][ 'source10' ],
1012 target=main.params[ 'PING' ][ 'target10' ],
1013 pingTime=500 )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001014
Jon Hall6aec96b2015-01-19 14:49:31 -08001015 main.step( "Create TestONTopology object" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001016 ctrls = []
1017 count = 1
1018 while True:
1019 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -08001020 if ( 'ip' + str( count ) ) in main.params[ 'CTRL' ]:
1021 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
1022 temp = temp + ( "ONOS" + str( count ), )
1023 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
1024 temp = temp + \
1025 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
1026 ctrls.append( temp )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001027 count = count + 1
1028 else:
1029 break
Jon Hall6aec96b2015-01-19 14:49:31 -08001030 MNTopo = TestONTopology(
1031 main.Mininet1,
1032 ctrls ) # can also add Intent API info for intent operations
Jon Hall73cf9cc2014-11-20 22:28:38 -08001033
Jon Hall6aec96b2015-01-19 14:49:31 -08001034 main.step( "Collecting topology information from ONOS" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001035 devices = []
1036 devices.append( main.ONOScli1.devices() )
1037 devices.append( main.ONOScli2.devices() )
1038 devices.append( main.ONOScli3.devices() )
1039 devices.append( main.ONOScli4.devices() )
1040 devices.append( main.ONOScli5.devices() )
1041 devices.append( main.ONOScli6.devices() )
1042 devices.append( main.ONOScli7.devices() )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001043 hosts = []
Jon Hall58c76b72015-02-23 11:09:24 -08001044 hosts.append( json.loads( main.ONOScli1.hosts() ) )
1045 hosts.append( json.loads( main.ONOScli2.hosts() ) )
1046 hosts.append( json.loads( main.ONOScli3.hosts() ) )
1047 hosts.append( json.loads( main.ONOScli4.hosts() ) )
1048 hosts.append( json.loads( main.ONOScli5.hosts() ) )
1049 hosts.append( json.loads( main.ONOScli6.hosts() ) )
1050 hosts.append( json.loads( main.ONOScli7.hosts() ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001051 ports = []
1052 ports.append( main.ONOScli1.ports() )
1053 ports.append( main.ONOScli2.ports() )
1054 ports.append( main.ONOScli3.ports() )
1055 ports.append( main.ONOScli4.ports() )
1056 ports.append( main.ONOScli5.ports() )
1057 ports.append( main.ONOScli6.ports() )
1058 ports.append( main.ONOScli7.ports() )
1059 links = []
1060 links.append( main.ONOScli1.links() )
1061 links.append( main.ONOScli2.links() )
1062 links.append( main.ONOScli3.links() )
1063 links.append( main.ONOScli4.links() )
1064 links.append( main.ONOScli5.links() )
1065 links.append( main.ONOScli6.links() )
1066 links.append( main.ONOScli7.links() )
Jon Hall94fd0472014-12-08 11:52:42 -08001067 clusters = []
1068 clusters.append( main.ONOScli1.clusters() )
1069 clusters.append( main.ONOScli2.clusters() )
1070 clusters.append( main.ONOScli3.clusters() )
1071 clusters.append( main.ONOScli4.clusters() )
1072 clusters.append( main.ONOScli5.clusters() )
1073 clusters.append( main.ONOScli6.clusters() )
1074 clusters.append( main.ONOScli7.clusters() )
Jon Hall529a37f2015-01-28 10:02:00 -08001075 # Compare json objects for hosts and dataplane clusters
Jon Hall94fd0472014-12-08 11:52:42 -08001076
Jon Hall6aec96b2015-01-19 14:49:31 -08001077 # hosts
Jon Hall8f89dda2015-01-22 16:03:33 -08001078 consistentHostsResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -08001079 for controller in range( len( hosts ) ):
Jon Hall8f89dda2015-01-22 16:03:33 -08001080 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001081 if "Error" not in hosts[ controller ]:
1082 if hosts[ controller ] == hosts[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001083 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001084 else: # hosts not consistent
1085 main.log.report( "hosts from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001086 controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001087 " is inconsistent with ONOS1" )
1088 main.log.warn( repr( hosts[ controller ] ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001089 consistentHostsResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001090
1091 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001092 main.log.report( "Error in getting ONOS hosts from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001093 controllerStr )
1094 consistentHostsResult = main.FALSE
1095 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001096 " hosts response: " +
1097 repr( hosts[ controller ] ) )
1098 utilities.assert_equals(
1099 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001100 actual=consistentHostsResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001101 onpass="Hosts view is consistent across all ONOS nodes",
1102 onfail="ONOS nodes have different views of hosts" )
Jon Hall94fd0472014-12-08 11:52:42 -08001103
Jon Hall58c76b72015-02-23 11:09:24 -08001104 ipResult = main.TRUE
1105 for controller in range( 0, len( hosts ) ):
1106 controllerStr = str( controller + 1 )
1107 for host in hosts[ controller ]:
1108 if host.get( 'ips', [] ) == []:
1109 main.log.error(
1110 "DEBUG:Error with host ips on controller" +
1111 controllerStr + ": " + str( host ) )
1112 ipResult = main.FALSE
1113 utilities.assert_equals(
1114 expect=main.TRUE,
1115 actual=ipResult,
1116 onpass="The ips of the hosts aren't empty",
1117 onfail="The ip of at least one host is missing" )
1118
Jon Hall6aec96b2015-01-19 14:49:31 -08001119 # Strongly connected clusters of devices
Jon Hall8f89dda2015-01-22 16:03:33 -08001120 consistentClustersResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -08001121 for controller in range( len( clusters ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001122 if "Error" not in clusters[ controller ]:
1123 if clusters[ controller ] == clusters[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001124 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001125 else: # clusters not consistent
1126 main.log.report( "clusters from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001127 controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001128 " is inconsistent with ONOS1" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001129 consistentClustersResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001130
1131 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001132 main.log.report( "Error in getting dataplane clusters " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001133 "from ONOS" + controllerStr )
1134 consistentClustersResult = main.FALSE
1135 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001136 " clusters response: " +
1137 repr( clusters[ controller ] ) )
1138 utilities.assert_equals(
1139 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001140 actual=consistentClustersResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001141 onpass="Clusters view is consistent across all ONOS nodes",
1142 onfail="ONOS nodes have different views of clusters" )
1143 # there should always only be one cluster
Jon Hall8f89dda2015-01-22 16:03:33 -08001144 numClusters = len( json.loads( clusters[ 0 ] ) )
Jon Hall58c76b72015-02-23 11:09:24 -08001145 clusterResults = main.FALSE
1146 if numClusters == 1:
1147 clusterResults = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001148 utilities.assert_equals(
1149 expect=1,
Jon Hall8f89dda2015-01-22 16:03:33 -08001150 actual=numClusters,
Jon Hall6aec96b2015-01-19 14:49:31 -08001151 onpass="ONOS shows 1 SCC",
Jon Hall58c76b72015-02-23 11:09:24 -08001152 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
Jon Hall94fd0472014-12-08 11:52:42 -08001153
Jon Hall6aec96b2015-01-19 14:49:31 -08001154 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001155 devicesResults = main.TRUE
1156 portsResults = main.TRUE
1157 linksResults = main.TRUE
1158 for controller in range( numControllers ):
1159 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001160 if devices[ controller ] or "Error" not in devices[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001161 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -08001162 MNTopo,
1163 json.loads(
1164 devices[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001165 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001166 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001167 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001168 actual=currentDevicesResult,
1169 onpass="ONOS" + controllerStr +
1170 " Switches view is correct",
1171 onfail="ONOS" + controllerStr +
1172 " Switches view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001173
Jon Hall6aec96b2015-01-19 14:49:31 -08001174 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001175 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -08001176 MNTopo,
1177 json.loads(
1178 ports[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001179 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001180 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001181 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001182 actual=currentPortsResult,
1183 onpass="ONOS" + controllerStr +
1184 " ports view is correct",
1185 onfail="ONOS" + controllerStr +
1186 " ports view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001187
Jon Hall6aec96b2015-01-19 14:49:31 -08001188 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001189 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -08001190 MNTopo,
1191 json.loads(
1192 links[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001193 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001194 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001195 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001196 actual=currentLinksResult,
1197 onpass="ONOS" + controllerStr +
1198 " links view is correct",
1199 onfail="ONOS" + controllerStr +
1200 " links view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001201
Jon Hall8f89dda2015-01-22 16:03:33 -08001202 devicesResults = devicesResults and currentDevicesResult
1203 portsResults = portsResults and currentPortsResult
1204 linksResults = linksResults and currentLinksResult
Jon Hall73cf9cc2014-11-20 22:28:38 -08001205
Jon Hall8f89dda2015-01-22 16:03:33 -08001206 topoResult = devicesResults and portsResults and linksResults\
Jon Hall58c76b72015-02-23 11:09:24 -08001207 and consistentHostsResult and consistentClustersResult\
1208 and clusterResults and ipResult
Jon Hall8f89dda2015-01-22 16:03:33 -08001209 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
Jon Hall58c76b72015-02-23 11:09:24 -08001210 onpass="Topology Check Test successful",
1211 onfail="Topology Check Test NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001212
Jon Hall8f89dda2015-01-22 16:03:33 -08001213 finalAssert = main.TRUE
1214 finalAssert = finalAssert and topoResult and flowCheck \
Jon Hall58c76b72015-02-23 11:09:24 -08001215 and intentCheck and consistentMastership and rolesNotNull
Jon Hall8f89dda2015-01-22 16:03:33 -08001216 utilities.assert_equals( expect=main.TRUE, actual=finalAssert,
Jon Hall58c76b72015-02-23 11:09:24 -08001217 onpass="State check successful",
1218 onfail="State check NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001219
Jon Hall6aec96b2015-01-19 14:49:31 -08001220 def CASE6( self, main ):
1221 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001222 The Failure case.
Jon Hall6aec96b2015-01-19 14:49:31 -08001223 """
Jon Hall94fd0472014-12-08 11:52:42 -08001224 import time
Jon Hall6aec96b2015-01-19 14:49:31 -08001225 main.log.report( "Killing 3 ONOS nodes" )
1226 main.log.case( "Restart minority of ONOS nodes" )
1227 # TODO: Randomize these nodes
Jon Hall8f89dda2015-01-22 16:03:33 -08001228 main.ONOSbench.onosKill( ONOS1Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -08001229 time.sleep( 10 )
Jon Hall8f89dda2015-01-22 16:03:33 -08001230 main.ONOSbench.onosKill( ONOS2Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -08001231 time.sleep( 10 )
Jon Hall8f89dda2015-01-22 16:03:33 -08001232 main.ONOSbench.onosKill( ONOS3Ip )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001233
Jon Hall6aec96b2015-01-19 14:49:31 -08001234 main.step( "Checking if ONOS is up yet" )
Jon Hallffb386d2014-11-21 13:43:38 -08001235 count = 0
Jon Hall8f89dda2015-01-22 16:03:33 -08001236 onosIsupResult = main.FALSE
1237 while onosIsupResult == main.FALSE and count < 10:
1238 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
1239 onos2Isup = main.ONOSbench.isup( ONOS2Ip )
1240 onos3Isup = main.ONOSbench.isup( ONOS3Ip )
1241 onosIsupResult = onos1Isup and onos2Isup and onos3Isup
Jon Hallffb386d2014-11-21 13:43:38 -08001242 count = count + 1
Jon Hall73cf9cc2014-11-20 22:28:38 -08001243 # TODO: if it becomes an issue, we can retry this step a few times
1244
Jon Hall8f89dda2015-01-22 16:03:33 -08001245 cliResult1 = main.ONOScli1.startOnosCli( ONOS1Ip )
1246 cliResult2 = main.ONOScli2.startOnosCli( ONOS2Ip )
1247 cliResult3 = main.ONOScli3.startOnosCli( ONOS3Ip )
1248 cliResults = cliResult1 and cliResult2 and cliResult3
Jon Hall73cf9cc2014-11-20 22:28:38 -08001249
Jon Hall21270ac2015-02-16 17:59:55 -08001250 # Grab the time of restart so we chan check how long the gossip
1251 # protocol has had time to work
1252 main.restartTime = time.time()
Jon Hall8f89dda2015-01-22 16:03:33 -08001253 caseResults = main.TRUE and onosIsupResult and cliResults
1254 utilities.assert_equals( expect=main.TRUE, actual=caseResults,
Jon Hall58c76b72015-02-23 11:09:24 -08001255 onpass="ONOS restart successful",
1256 onfail="ONOS restart NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001257
Jon Hall6aec96b2015-01-19 14:49:31 -08001258 def CASE7( self, main ):
1259 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001260 Check state after ONOS failure
Jon Hall6aec96b2015-01-19 14:49:31 -08001261 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001262 import json
Jon Hall6aec96b2015-01-19 14:49:31 -08001263 main.case( "Running ONOS Constant State Tests" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001264
Jon Hall6aec96b2015-01-19 14:49:31 -08001265 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -08001266 ONOS1MasterNotNull = main.ONOScli1.rolesNotNull()
1267 ONOS2MasterNotNull = main.ONOScli2.rolesNotNull()
1268 ONOS3MasterNotNull = main.ONOScli3.rolesNotNull()
1269 ONOS4MasterNotNull = main.ONOScli4.rolesNotNull()
1270 ONOS5MasterNotNull = main.ONOScli5.rolesNotNull()
1271 ONOS6MasterNotNull = main.ONOScli6.rolesNotNull()
1272 ONOS7MasterNotNull = main.ONOScli7.rolesNotNull()
1273 rolesNotNull = ONOS1MasterNotNull and ONOS2MasterNotNull and\
1274 ONOS3MasterNotNull and ONOS4MasterNotNull and\
1275 ONOS5MasterNotNull and ONOS6MasterNotNull and\
1276 ONOS7MasterNotNull
Jon Hall6aec96b2015-01-19 14:49:31 -08001277 utilities.assert_equals(
1278 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001279 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -08001280 onpass="Each device has a master",
1281 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -08001282
Jon Hall6aec96b2015-01-19 14:49:31 -08001283 main.step( "Check if switch roles are consistent across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001284 ONOS1Mastership = main.ONOScli1.roles()
1285 ONOS2Mastership = main.ONOScli2.roles()
1286 ONOS3Mastership = main.ONOScli3.roles()
1287 ONOS4Mastership = main.ONOScli4.roles()
1288 ONOS5Mastership = main.ONOScli5.roles()
1289 ONOS6Mastership = main.ONOScli6.roles()
1290 ONOS7Mastership = main.ONOScli7.roles()
Jon Hall8f89dda2015-01-22 16:03:33 -08001291 if "Error" in ONOS1Mastership or not ONOS1Mastership\
1292 or "Error" in ONOS2Mastership or not ONOS2Mastership\
1293 or "Error" in ONOS3Mastership or not ONOS3Mastership\
1294 or "Error" in ONOS4Mastership or not ONOS4Mastership\
1295 or "Error" in ONOS5Mastership or not ONOS5Mastership\
1296 or "Error" in ONOS6Mastership or not ONOS6Mastership\
1297 or "Error" in ONOS7Mastership or not ONOS7Mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -08001298 main.log.error( "Error in getting ONOS mastership" )
1299 main.log.warn( "ONOS1 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001300 repr( ONOS1Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001301 main.log.warn( "ONOS2 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001302 repr( ONOS2Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001303 main.log.warn( "ONOS3 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001304 repr( ONOS3Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001305 main.log.warn( "ONOS4 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001306 repr( ONOS4Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001307 main.log.warn( "ONOS5 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001308 repr( ONOS5Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001309 main.log.warn( "ONOS6 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001310 repr( ONOS6Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001311 main.log.warn( "ONOS7 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001312 repr( ONOS7Mastership ) )
1313 consistentMastership = main.FALSE
1314 elif ONOS1Mastership == ONOS2Mastership\
1315 and ONOS1Mastership == ONOS3Mastership\
1316 and ONOS1Mastership == ONOS4Mastership\
1317 and ONOS1Mastership == ONOS5Mastership\
1318 and ONOS1Mastership == ONOS6Mastership\
1319 and ONOS1Mastership == ONOS7Mastership:
1320 consistentMastership = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001321 main.log.report(
1322 "Switch roles are consistent across all ONOS nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001323 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001324 main.log.warn( "ONOS1 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001325 json.loads( ONOS1Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001326 separators=( ',', ': ' ) ) )
1327 main.log.warn( "ONOS2 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001328 json.loads( ONOS2Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001329 separators=( ',', ': ' ) ) )
1330 main.log.warn( "ONOS3 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001331 json.loads( ONOS3Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001332 separators=( ',', ': ' ) ) )
1333 main.log.warn( "ONOS4 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001334 json.loads( ONOS4Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001335 separators=( ',', ': ' ) ) )
1336 main.log.warn( "ONOS5 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001337 json.loads( ONOS5Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001338 separators=( ',', ': ' ) ) )
1339 main.log.warn( "ONOS6 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001340 json.loads( ONOS6Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001341 separators=( ',', ': ' ) ) )
1342 main.log.warn( "ONOS7 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001343 json.loads( ONOS7Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001344 separators=( ',', ': ' ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001345 consistentMastership = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001346 utilities.assert_equals(
1347 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001348 actual=consistentMastership,
Jon Hall6aec96b2015-01-19 14:49:31 -08001349 onpass="Switch roles are consistent across all ONOS nodes",
1350 onfail="ONOS nodes have different views of switch roles" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001351
1352 description2 = "Compare switch roles from before failure"
Jon Hall6aec96b2015-01-19 14:49:31 -08001353 main.step( description2 )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001354
Jon Hall8f89dda2015-01-22 16:03:33 -08001355 currentJson = json.loads( ONOS1Mastership )
1356 oldJson = json.loads( mastershipState )
1357 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001358 for i in range( 1, 29 ):
1359 switchDPID = str(
1360 main.Mininet1.getSwitchDPID(
1361 switch="s" +
1362 str( i ) ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001363
Jon Hall8f89dda2015-01-22 16:03:33 -08001364 current = [ switch[ 'master' ] for switch in currentJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001365 if switchDPID in switch[ 'id' ] ]
Jon Hall8f89dda2015-01-22 16:03:33 -08001366 old = [ switch[ 'master' ] for switch in oldJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001367 if switchDPID in switch[ 'id' ] ]
Jon Hall73cf9cc2014-11-20 22:28:38 -08001368 if current == old:
Jon Hall8f89dda2015-01-22 16:03:33 -08001369 mastershipCheck = mastershipCheck and main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001370 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001371 main.log.warn( "Mastership of switch %s changed" % switchDPID )
Jon Hall8f89dda2015-01-22 16:03:33 -08001372 mastershipCheck = main.FALSE
1373 if mastershipCheck == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001374 main.log.report( "Mastership of Switches was not changed" )
1375 utilities.assert_equals(
1376 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001377 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -08001378 onpass="Mastership of Switches was not changed",
1379 onfail="Mastership of some switches changed" )
1380 # NOTE: we expect mastership to change on controller failure
Jon Hall8f89dda2015-01-22 16:03:33 -08001381 mastershipCheck = consistentMastership
Jon Hall73cf9cc2014-11-20 22:28:38 -08001382
Jon Hall58c76b72015-02-23 11:09:24 -08001383 main.step( "Get the intents and compare across all nodes" )
1384 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
1385 ONOS2Intents = main.ONOScli2.intents( jsonFormat=True )
1386 ONOS3Intents = main.ONOScli3.intents( jsonFormat=True )
1387 ONOS4Intents = main.ONOScli4.intents( jsonFormat=True )
1388 ONOS5Intents = main.ONOScli5.intents( jsonFormat=True )
1389 ONOS6Intents = main.ONOScli6.intents( jsonFormat=True )
1390 ONOS7Intents = main.ONOScli7.intents( jsonFormat=True )
1391 intentCheck = main.FALSE
1392 if "Error" in ONOS1Intents or not ONOS1Intents\
1393 or "Error" in ONOS2Intents or not ONOS2Intents\
1394 or "Error" in ONOS3Intents or not ONOS3Intents\
1395 or "Error" in ONOS4Intents or not ONOS4Intents\
1396 or "Error" in ONOS5Intents or not ONOS5Intents\
1397 or "Error" in ONOS6Intents or not ONOS6Intents\
1398 or "Error" in ONOS7Intents or not ONOS7Intents:
1399 main.log.report( "Error in getting ONOS intents" )
1400 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
1401 main.log.warn( "ONOS2 intents response: " + repr( ONOS2Intents ) )
1402 main.log.warn( "ONOS3 intents response: " + repr( ONOS3Intents ) )
1403 main.log.warn( "ONOS4 intents response: " + repr( ONOS4Intents ) )
1404 main.log.warn( "ONOS5 intents response: " + repr( ONOS5Intents ) )
1405 main.log.warn( "ONOS6 intents response: " + repr( ONOS6Intents ) )
1406 main.log.warn( "ONOS7 intents response: " + repr( ONOS7Intents ) )
1407 elif ONOS1Intents == ONOS2Intents\
1408 and ONOS1Intents == ONOS3Intents\
1409 and ONOS1Intents == ONOS4Intents\
1410 and ONOS1Intents == ONOS5Intents\
1411 and ONOS1Intents == ONOS6Intents\
1412 and ONOS1Intents == ONOS7Intents:
1413 intentCheck = main.TRUE
1414 main.log.report( "Intents are consistent across all ONOS nodes" )
1415 else:
1416 main.log.warn( "ONOS1 intents: " )
1417 print json.dumps( json.loads( ONOS1Intents ), sort_keys=True,
1418 indent=4, separators=( ',', ': ' ) )
1419 main.log.warn( "ONOS2 intents: " )
1420 print json.dumps( json.loads( ONOS2Intents ), sort_keys=True,
1421 indent=4, separators=( ',', ': ' ) )
1422 main.log.warn( "ONOS3 intents: " )
1423 print json.dumps( json.loads( ONOS3Intents ), sort_keys=True,
1424 indent=4, separators=( ',', ': ' ) )
1425 main.log.warn( "ONOS4 intents: " )
1426 print json.dumps( json.loads( ONOS4Intents ), sort_keys=True,
1427 indent=4, separators=( ',', ': ' ) )
1428 main.log.warn( "ONOS5 intents: " )
1429 print json.dumps( json.loads( ONOS5Intents ), sort_keys=True,
1430 indent=4, separators=( ',', ': ' ) )
1431 main.log.warn( "ONOS6 intents: " )
1432 print json.dumps( json.loads( ONOS6Intents ), sort_keys=True,
1433 indent=4, separators=( ',', ': ' ) )
1434 main.log.warn( "ONOS7 intents: " )
1435 print json.dumps( json.loads( ONOS7Intents ), sort_keys=True,
1436 indent=4, separators=( ',', ': ' ) )
1437 utilities.assert_equals(
1438 expect=main.TRUE,
1439 actual=intentCheck,
1440 onpass="Intents are consistent across all ONOS nodes",
1441 onfail="ONOS nodes have different views of intents" )
1442 # Print the intent states
1443 intents = []
1444 intents.append( ONOS1Intents )
1445 intents.append( ONOS2Intents )
1446 intents.append( ONOS3Intents )
1447 intents.append( ONOS4Intents )
1448 intents.append( ONOS5Intents )
1449 intents.append( ONOS6Intents )
1450 intents.append( ONOS7Intents )
1451 intentStates = []
1452 for node in intents: # Iter through ONOS nodes
1453 nodeStates = []
1454 # Iter through intents of a node
1455 for intent in json.loads( node ):
1456 nodeStates.append( intent[ 'state' ] )
1457 intentStates.append( nodeStates )
1458 out = [ (i, nodeStates.count( i ) ) for i in set( nodeStates ) ]
1459 main.log.info( dict( out ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001460
Jon Hall58c76b72015-02-23 11:09:24 -08001461 # NOTE: Store has no durability, so intents are lost across system
1462 # restarts
1463 main.step( "Compare current intents with intents before the failure" )
1464 # NOTE: this requires case 5 to pass for intentState to be set.
1465 # maybe we should stop the test if that fails?
1466 sameIntents = main.TRUE
1467 if intentState and intentState == ONOS1Intents:
Jon Hall21270ac2015-02-16 17:59:55 -08001468 sameIntents = main.TRUE
Jon Hall58c76b72015-02-23 11:09:24 -08001469 main.log.report( "Intents are consistent with before failure" )
1470 # TODO: possibly the states have changed? we may need to figure out
1471 # what the aceptable states are
1472 else:
1473 try:
1474 main.log.warn( "ONOS1 intents: " )
1475 print json.dumps( json.loads( ONOS1Intents ),
1476 sort_keys=True, indent=4,
1477 separators=( ',', ': ' ) )
1478 except:
1479 pass
1480 sameIntents = main.FALSE
1481 utilities.assert_equals(
1482 expect=main.TRUE,
1483 actual=sameIntents,
1484 onpass="Intents are consistent with before failure",
1485 onfail="The Intents changed during failure" )
1486 intentCheck = intentCheck and sameIntents
Jon Hall21270ac2015-02-16 17:59:55 -08001487
Jon Hall58c76b72015-02-23 11:09:24 -08001488 main.step( "Get the OF Table entries and compare to before " +
1489 "component failure" )
1490 FlowTables = main.TRUE
1491 flows2 = []
1492 for i in range( 28 ):
1493 main.log.info( "Checking flow table on s" + str( i + 1 ) )
1494 tmpFlows = main.Mininet2.getFlowTable( 1.3, "s" + str( i + 1 ) )
1495 flows2.append( tmpFlows )
1496 tempResult = main.Mininet2.flowComp(
1497 flow1=flows[ i ],
1498 flow2=tmpFlows )
1499 FlowTables = FlowTables and tempResult
1500 if FlowTables == main.FALSE:
1501 main.log.info( "Differences in flow table for switch: s" +
1502 str( i + 1 ) )
1503 if FlowTables == main.TRUE:
1504 main.log.report( "No changes were found in the flow tables" )
1505 utilities.assert_equals(
1506 expect=main.TRUE,
1507 actual=FlowTables,
1508 onpass="No changes were found in the flow tables",
1509 onfail="Changes were found in the flow tables" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001510
Jon Hall6aec96b2015-01-19 14:49:31 -08001511 main.step( "Check the continuous pings to ensure that no packets " +
1512 "were dropped during component failure" )
1513 # FIXME: This check is always failing. Investigate cause
1514 # NOTE: this may be something to do with file permsissions
Jon Hall73cf9cc2014-11-20 22:28:38 -08001515 # or slight change in format
Jon Hall6aec96b2015-01-19 14:49:31 -08001516 main.Mininet2.pingKill(
1517 main.params[ 'TESTONUSER' ],
1518 main.params[ 'TESTONIP' ] )
Jon Hall8f89dda2015-01-22 16:03:33 -08001519 LossInPings = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001520 # NOTE: checkForLoss returns main.FALSE with 0% packet loss
1521 for i in range( 8, 18 ):
1522 main.log.info(
1523 "Checking for a loss in pings along flow from s" +
1524 str( i ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001525 LossInPings = main.Mininet2.checkForLoss(
Jon Hall6aec96b2015-01-19 14:49:31 -08001526 "/tmp/ping.h" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001527 str( i ) ) or LossInPings
1528 if LossInPings == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001529 main.log.info( "Loss in ping detected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001530 elif LossInPings == main.ERROR:
Jon Hall6aec96b2015-01-19 14:49:31 -08001531 main.log.info( "There are multiple mininet process running" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001532 elif LossInPings == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001533 main.log.info( "No Loss in the pings" )
1534 main.log.report( "No loss of dataplane connectivity" )
1535 utilities.assert_equals(
1536 expect=main.FALSE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001537 actual=LossInPings,
Jon Hall6aec96b2015-01-19 14:49:31 -08001538 onpass="No Loss of connectivity",
1539 onfail="Loss of dataplane connectivity detected" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001540
Jon Hall6aec96b2015-01-19 14:49:31 -08001541 # Test of LeadershipElection
Jon Hall8f89dda2015-01-22 16:03:33 -08001542 leaderList = []
1543 leaderResult = main.TRUE
1544 for controller in range( 1, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001545 # loop through ONOScli handlers
1546 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001547 leaderN = node.electionTestLeader()
1548 leaderList.append( leaderN )
Jon Hall669173b2014-12-17 11:36:30 -08001549 if leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001550 # error in response
1551 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001552 "electionTestLeader function, check the" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001553 " error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001554 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001555 elif leaderN is None:
1556 main.log.report( "ONOS" + str( controller ) +
1557 " shows no leader for the election-app was" +
1558 " elected after the old one died" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001559 leaderResult = main.FALSE
1560 elif leaderN == ONOS1Ip or leaderN == ONOS2Ip or\
1561 leaderN == ONOS3Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08001562 main.log.report( "ONOS" + str( controller ) +
1563 " shows " + str( leaderN ) +
1564 " as leader for the election-app, but it " +
1565 "was restarted" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001566 leaderResult = main.FALSE
1567 if len( set( leaderList ) ) != 1:
1568 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001569 main.log.error(
1570 "Inconsistent view of leader for the election test app" )
1571 # TODO: print the list
Jon Hall8f89dda2015-01-22 16:03:33 -08001572 if leaderResult:
1573 main.log.report( "Leadership election tests passed( consistent " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001574 "view of leader across listeners and a new " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001575 "leader was re-elected if applicable )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001576 utilities.assert_equals(
1577 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001578 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001579 onpass="Leadership election passed",
1580 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08001581
Jon Hall58c76b72015-02-23 11:09:24 -08001582 result = ( mastershipCheck and intentCheck and FlowTables and
1583 ( not LossInPings ) and rolesNotNull and leaderResult )
Jon Hall6aec96b2015-01-19 14:49:31 -08001584 result = int( result )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001585 if result == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001586 main.log.report( "Constant State Tests Passed" )
1587 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall58c76b72015-02-23 11:09:24 -08001588 onpass="Constant State Tests Passed",
1589 onfail="Constant state tests failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001590
Jon Hall6aec96b2015-01-19 14:49:31 -08001591 def CASE8( self, main ):
1592 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001593 Compare topo
Jon Hall6aec96b2015-01-19 14:49:31 -08001594 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001595 import sys
Jon Hall6aec96b2015-01-19 14:49:31 -08001596 # FIXME add this path to params
1597 sys.path.append( "/home/admin/sts" )
1598 # assumes that sts is already in you PYTHONPATH
1599 from sts.topology.teston_topology import TestONTopology
Jon Hall73cf9cc2014-11-20 22:28:38 -08001600 import json
1601 import time
1602
Jon Hall6aec96b2015-01-19 14:49:31 -08001603 description = "Compare ONOS Topology view to Mininet topology"
1604 main.case( description )
1605 main.log.report( description )
1606 main.step( "Create TestONTopology object" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001607 ctrls = []
1608 count = 1
1609 while True:
1610 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -08001611 if ( 'ip' + str( count ) ) in main.params[ 'CTRL' ]:
1612 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
1613 temp = temp + ( "ONOS" + str( count ), )
1614 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
1615 temp = temp + \
1616 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
1617 ctrls.append( temp )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001618 count = count + 1
1619 else:
1620 break
Jon Hall6aec96b2015-01-19 14:49:31 -08001621 MNTopo = TestONTopology(
1622 main.Mininet1,
1623 ctrls ) # can also add Intent API info for intent operations
Jon Hall73cf9cc2014-11-20 22:28:38 -08001624
Jon Hall6aec96b2015-01-19 14:49:31 -08001625 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001626 devicesResults = main.TRUE
1627 portsResults = main.TRUE
1628 linksResults = main.TRUE
Jon Hall58c76b72015-02-23 11:09:24 -08001629 hostsResults = main.TRUE
Jon Hall8f89dda2015-01-22 16:03:33 -08001630 topoResult = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001631 elapsed = 0
Jon Hallffb386d2014-11-21 13:43:38 -08001632 count = 0
Jon Hall6aec96b2015-01-19 14:49:31 -08001633 main.step( "Collecting topology information from ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001634 startTime = time.time()
Jon Hall21270ac2015-02-16 17:59:55 -08001635 # Give time for Gossip to work
Jon Hall8f89dda2015-01-22 16:03:33 -08001636 while topoResult == main.FALSE and elapsed < 60:
Jon Hallffb386d2014-11-21 13:43:38 -08001637 count = count + 1
Jon Hall94fd0472014-12-08 11:52:42 -08001638 if count > 1:
Jon Hall6aec96b2015-01-19 14:49:31 -08001639 # TODO: Depricate STS usage
Jon Hall58c76b72015-02-23 11:09:24 -08001640 MNTopo = TestONTopology( main.Mininet1, ctrls )
Jon Hall8f89dda2015-01-22 16:03:33 -08001641 cliStart = time.time()
Jon Hall94fd0472014-12-08 11:52:42 -08001642 devices = []
1643 devices.append( main.ONOScli1.devices() )
1644 devices.append( main.ONOScli2.devices() )
1645 devices.append( main.ONOScli3.devices() )
1646 devices.append( main.ONOScli4.devices() )
1647 devices.append( main.ONOScli5.devices() )
1648 devices.append( main.ONOScli6.devices() )
1649 devices.append( main.ONOScli7.devices() )
1650 hosts = []
Jon Hall669173b2014-12-17 11:36:30 -08001651 hosts.append( json.loads( main.ONOScli1.hosts() ) )
1652 hosts.append( json.loads( main.ONOScli2.hosts() ) )
1653 hosts.append( json.loads( main.ONOScli3.hosts() ) )
1654 hosts.append( json.loads( main.ONOScli4.hosts() ) )
1655 hosts.append( json.loads( main.ONOScli5.hosts() ) )
1656 hosts.append( json.loads( main.ONOScli6.hosts() ) )
1657 hosts.append( json.loads( main.ONOScli7.hosts() ) )
Jon Hall58c76b72015-02-23 11:09:24 -08001658 ipResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001659 for controller in range( 0, len( hosts ) ):
Jon Hall8f89dda2015-01-22 16:03:33 -08001660 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001661 for host in hosts[ controller ]:
Jon Hall58c76b72015-02-23 11:09:24 -08001662 if host is None or host.get( 'ips', [] ) == []:
Jon Hall6aec96b2015-01-19 14:49:31 -08001663 main.log.error(
1664 "DEBUG:Error with host ips on controller" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001665 controllerStr + ": " + str( host ) )
Jon Hall58c76b72015-02-23 11:09:24 -08001666 ipResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001667 ports = []
1668 ports.append( main.ONOScli1.ports() )
1669 ports.append( main.ONOScli2.ports() )
1670 ports.append( main.ONOScli3.ports() )
1671 ports.append( main.ONOScli4.ports() )
1672 ports.append( main.ONOScli5.ports() )
1673 ports.append( main.ONOScli6.ports() )
1674 ports.append( main.ONOScli7.ports() )
1675 links = []
1676 links.append( main.ONOScli1.links() )
1677 links.append( main.ONOScli2.links() )
1678 links.append( main.ONOScli3.links() )
1679 links.append( main.ONOScli4.links() )
1680 links.append( main.ONOScli5.links() )
1681 links.append( main.ONOScli6.links() )
1682 links.append( main.ONOScli7.links() )
1683 clusters = []
1684 clusters.append( main.ONOScli1.clusters() )
1685 clusters.append( main.ONOScli2.clusters() )
1686 clusters.append( main.ONOScli3.clusters() )
1687 clusters.append( main.ONOScli4.clusters() )
1688 clusters.append( main.ONOScli5.clusters() )
1689 clusters.append( main.ONOScli6.clusters() )
1690 clusters.append( main.ONOScli7.clusters() )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001691
Jon Hall8f89dda2015-01-22 16:03:33 -08001692 elapsed = time.time() - startTime
1693 cliTime = time.time() - cliStart
1694 print "CLI time: " + str( cliTime )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001695
Jon Hall8f89dda2015-01-22 16:03:33 -08001696 for controller in range( numControllers ):
1697 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001698 if devices[ controller ] or "Error" not in devices[
1699 controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001700 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -08001701 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001702 json.loads( devices[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001703 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001704 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001705 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001706 actual=currentDevicesResult,
1707 onpass="ONOS" + controllerStr +
1708 " Switches view is correct",
1709 onfail="ONOS" + controllerStr +
1710 " Switches view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001711
Jon Hall6aec96b2015-01-19 14:49:31 -08001712 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001713 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -08001714 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001715 json.loads( ports[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001716 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001717 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001718 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001719 actual=currentPortsResult,
1720 onpass="ONOS" + controllerStr +
1721 " ports view is correct",
1722 onfail="ONOS" + controllerStr +
1723 " ports view is incorrect" )
Jon Hall94fd0472014-12-08 11:52:42 -08001724
Jon Hall6aec96b2015-01-19 14:49:31 -08001725 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001726 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -08001727 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001728 json.loads( links[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001729 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001730 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001731 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001732 actual=currentLinksResult,
1733 onpass="ONOS" + controllerStr +
1734 " links view is correct",
1735 onfail="ONOS" + controllerStr +
1736 " links view is incorrect" )
1737
1738 if hosts[ controller ] or "Error" not in hosts[ controller ]:
1739 currentHostsResult = main.Mininet1.compareHosts(
1740 MNTopo, hosts[ controller ] )
1741 else:
1742 currentHostsResult = main.FALSE
1743 utilities.assert_equals( expect=main.TRUE,
1744 actual=currentHostsResult,
1745 onpass="ONOS" + controllerStr +
1746 " hosts exist in Mininet",
1747 onfail="ONOS" + controllerStr +
1748 " hosts don't match Mininet" )
1749
1750 devicesResults = devicesResults and currentDevicesResult
1751 portsResults = portsResults and currentPortsResult
1752 linksResults = linksResults and currentLinksResult
1753 hostsResults = hostsResults and currentHostsResult
Jon Hall94fd0472014-12-08 11:52:42 -08001754
Jon Hall529a37f2015-01-28 10:02:00 -08001755 # Compare json objects for hosts and dataplane clusters
Jon Hall94fd0472014-12-08 11:52:42 -08001756
Jon Hall6aec96b2015-01-19 14:49:31 -08001757 # hosts
Jon Hall8f89dda2015-01-22 16:03:33 -08001758 consistentHostsResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -08001759 for controller in range( len( hosts ) ):
Jon Hall8f89dda2015-01-22 16:03:33 -08001760 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001761 if "Error" not in hosts[ controller ]:
1762 if hosts[ controller ] == hosts[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001763 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001764 else: # hosts not consistent
Jon Hall8f89dda2015-01-22 16:03:33 -08001765 main.log.report( "hosts from ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001766 " is inconsistent with ONOS1" )
1767 main.log.warn( repr( hosts[ controller ] ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001768 consistentHostsResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001769
1770 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001771 main.log.report( "Error in getting ONOS hosts from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001772 controllerStr )
1773 consistentHostsResult = main.FALSE
1774 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001775 " hosts response: " +
1776 repr( hosts[ controller ] ) )
1777 utilities.assert_equals(
1778 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001779 actual=consistentHostsResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001780 onpass="Hosts view is consistent across all ONOS nodes",
1781 onfail="ONOS nodes have different views of hosts" )
Jon Hall94fd0472014-12-08 11:52:42 -08001782
Jon Hall6aec96b2015-01-19 14:49:31 -08001783 # Strongly connected clusters of devices
Jon Hall8f89dda2015-01-22 16:03:33 -08001784 consistentClustersResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -08001785 for controller in range( len( clusters ) ):
Jon Hall8f89dda2015-01-22 16:03:33 -08001786 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001787 if "Error" not in clusters[ controller ]:
1788 if clusters[ controller ] == clusters[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001789 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001790 else: # clusters not consistent
1791 main.log.report( "clusters from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001792 controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001793 " is inconsistent with ONOS1" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001794 consistentClustersResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001795
1796 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001797 main.log.report( "Error in getting dataplane clusters " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001798 "from ONOS" + controllerStr )
1799 consistentClustersResult = main.FALSE
1800 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001801 " clusters response: " +
1802 repr( clusters[ controller ] ) )
1803 utilities.assert_equals(
1804 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001805 actual=consistentClustersResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001806 onpass="Clusters view is consistent across all ONOS nodes",
1807 onfail="ONOS nodes have different views of clusters" )
1808 # there should always only be one cluster
Jon Hall8f89dda2015-01-22 16:03:33 -08001809 numClusters = len( json.loads( clusters[ 0 ] ) )
Jon Hall58c76b72015-02-23 11:09:24 -08001810 clusterResults = main.FALSE
1811 if numClusters == 1:
1812 clusterResults = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001813 utilities.assert_equals(
1814 expect=1,
Jon Hall8f89dda2015-01-22 16:03:33 -08001815 actual=numClusters,
Jon Hall6aec96b2015-01-19 14:49:31 -08001816 onpass="ONOS shows 1 SCC",
Jon Hall58c76b72015-02-23 11:09:24 -08001817 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
Jon Hall94fd0472014-12-08 11:52:42 -08001818
Jon Hall8f89dda2015-01-22 16:03:33 -08001819 topoResult = ( devicesResults and portsResults and linksResults
Jon Hall58c76b72015-02-23 11:09:24 -08001820 and hostsResults and consistentHostsResult
1821 and consistentClustersResult and clusterResults
1822 and ipResult )
Jon Hall94fd0472014-12-08 11:52:42 -08001823
Jon Hall8f89dda2015-01-22 16:03:33 -08001824 topoResult = topoResult and int( count <= 2 )
1825 note = "note it takes about " + str( int( cliTime ) ) + \
1826 " seconds for the test to make all the cli calls to fetch " +\
1827 "the topology from each ONOS instance"
Jon Hall1b8f54a2015-02-04 13:24:20 -08001828 main.log.info(
Jon Hall8f89dda2015-01-22 16:03:33 -08001829 "Very crass estimate for topology discovery/convergence( " +
1830 str( note ) + " ): " + str( elapsed ) + " seconds, " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001831 str( count ) + " tries" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001832 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
Jon Hall58c76b72015-02-23 11:09:24 -08001833 onpass="Topology Check Test successful",
1834 onfail="Topology Check Test NOT successful" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001835 if topoResult == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001836 main.log.report( "ONOS topology view matches Mininet topology" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001837
Jon Hall6aec96b2015-01-19 14:49:31 -08001838 def CASE9( self, main ):
1839 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001840 Link s3-s28 down
Jon Hall6aec96b2015-01-19 14:49:31 -08001841 """
1842 import time
1843 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001844
Jon Hall8f89dda2015-01-22 16:03:33 -08001845 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001846
Jon Hall6aec96b2015-01-19 14:49:31 -08001847 description = "Turn off a link to ensure that Link Discovery " +\
Jon Hall58c76b72015-02-23 11:09:24 -08001848 "is working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001849 main.log.report( description )
1850 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001851
Jon Hall6aec96b2015-01-19 14:49:31 -08001852 main.step( "Kill Link between s3 and s28" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001853 LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" )
Jon Hall58c76b72015-02-23 11:09:24 -08001854 main.log.info( "Waiting " + str( linkSleep ) +
1855 " seconds for link down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001856 time.sleep( linkSleep )
1857 utilities.assert_equals( expect=main.TRUE, actual=LinkDown,
Jon Hall58c76b72015-02-23 11:09:24 -08001858 onpass="Link down succesful",
1859 onfail="Failed to bring link down" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001860 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -08001861
Jon Hall6aec96b2015-01-19 14:49:31 -08001862 def CASE10( self, main ):
1863 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001864 Link s3-s28 up
Jon Hall6aec96b2015-01-19 14:49:31 -08001865 """
1866 import time
1867 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001868
Jon Hall8f89dda2015-01-22 16:03:33 -08001869 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001870
Jon Hall6aec96b2015-01-19 14:49:31 -08001871 description = "Restore a link to ensure that Link Discovery is " + \
Jon Hall8f89dda2015-01-22 16:03:33 -08001872 "working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001873 main.log.report( description )
1874 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001875
Jon Hall6aec96b2015-01-19 14:49:31 -08001876 main.step( "Bring link between s3 and s28 back up" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001877 LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" )
Jon Hall58c76b72015-02-23 11:09:24 -08001878 main.log.info( "Waiting " + str( linkSleep ) +
1879 " seconds for link up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001880 time.sleep( linkSleep )
1881 utilities.assert_equals( expect=main.TRUE, actual=LinkUp,
Jon Hall58c76b72015-02-23 11:09:24 -08001882 onpass="Link up succesful",
1883 onfail="Failed to bring link up" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001884 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -08001885
Jon Hall6aec96b2015-01-19 14:49:31 -08001886 def CASE11( self, main ):
1887 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001888 Switch Down
Jon Hall6aec96b2015-01-19 14:49:31 -08001889 """
1890 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001891 import time
1892
Jon Hall8f89dda2015-01-22 16:03:33 -08001893 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001894
1895 description = "Killing a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001896 main.log.report( description )
1897 main.case( description )
1898 switch = main.params[ 'kill' ][ 'switch' ]
1899 switchDPID = main.params[ 'kill' ][ 'dpid' ]
Jon Hall73cf9cc2014-11-20 22:28:38 -08001900
Jon Hall6aec96b2015-01-19 14:49:31 -08001901 # TODO: Make this switch parameterizable
1902 main.step( "Kill " + switch )
1903 main.log.report( "Deleting " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001904 main.Mininet1.delSwitch( switch )
1905 main.log.info( "Waiting " + str( switchSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001906 " seconds for switch down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001907 time.sleep( switchSleep )
1908 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001909 # Peek at the deleted switch
1910 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001911 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001912 if device and device[ 'available' ] is False:
Jon Hall94fd0472014-12-08 11:52:42 -08001913 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001914 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall58c76b72015-02-23 11:09:24 -08001915 onpass="Kill switch succesful",
1916 onfail="Failed to kill switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001917
Jon Hall6aec96b2015-01-19 14:49:31 -08001918 def CASE12( self, main ):
1919 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001920 Switch Up
Jon Hall6aec96b2015-01-19 14:49:31 -08001921 """
1922 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001923 import time
Jon Hall669173b2014-12-17 11:36:30 -08001924
Jon Hall8f89dda2015-01-22 16:03:33 -08001925 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall6aec96b2015-01-19 14:49:31 -08001926 switch = main.params[ 'kill' ][ 'switch' ]
1927 switchDPID = main.params[ 'kill' ][ 'dpid' ]
1928 links = main.params[ 'kill' ][ 'links' ].split()
Jon Hall73cf9cc2014-11-20 22:28:38 -08001929 description = "Adding a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001930 main.log.report( description )
1931 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001932
Jon Hall6aec96b2015-01-19 14:49:31 -08001933 main.step( "Add back " + switch )
1934 main.log.report( "Adding back " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001935 main.Mininet1.addSwitch( switch, dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001936 # TODO: New dpid or same? Ask Thomas?
1937 for peer in links:
Jon Hall8f89dda2015-01-22 16:03:33 -08001938 main.Mininet1.addLink( switch, peer )
Jon Hall58c76b72015-02-23 11:09:24 -08001939 main.Mininet1.assignSwController( sw=switch.split( 's' )[ 1 ],
1940 count=numControllers,
1941 ip1=ONOS1Ip,
1942 port1=ONOS1Port,
1943 ip2=ONOS2Ip,
1944 port2=ONOS2Port,
1945 ip3=ONOS3Ip,
1946 port3=ONOS3Port,
1947 ip4=ONOS4Ip,
1948 port4=ONOS4Port,
1949 ip5=ONOS5Ip,
1950 port5=ONOS5Port,
1951 ip6=ONOS6Ip,
1952 port6=ONOS6Port,
1953 ip7=ONOS7Ip,
1954 port7=ONOS7Port )
1955 main.log.info( "Waiting " + str( switchSleep ) +
1956 " seconds for switch up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001957 time.sleep( switchSleep )
1958 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001959 # Peek at the deleted switch
1960 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001961 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001962 if device and device[ 'available' ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001963 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001964 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall58c76b72015-02-23 11:09:24 -08001965 onpass="add switch succesful",
1966 onfail="Failed to add switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001967
Jon Hall6aec96b2015-01-19 14:49:31 -08001968 def CASE13( self, main ):
1969 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001970 Clean up
Jon Hall6aec96b2015-01-19 14:49:31 -08001971 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001972 import os
1973 import time
Jon Hall6aec96b2015-01-19 14:49:31 -08001974 # TODO: make use of this elsewhere
1975 ips = []
Jon Hall8f89dda2015-01-22 16:03:33 -08001976 ips.append( ONOS1Ip )
1977 ips.append( ONOS2Ip )
1978 ips.append( ONOS3Ip )
1979 ips.append( ONOS4Ip )
1980 ips.append( ONOS5Ip )
1981 ips.append( ONOS6Ip )
1982 ips.append( ONOS7Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -08001983
1984 # printing colors to terminal
Jon Hall669173b2014-12-17 11:36:30 -08001985 colors = {}
Jon Hall6aec96b2015-01-19 14:49:31 -08001986 colors[ 'cyan' ] = '\033[96m'
1987 colors[ 'purple' ] = '\033[95m'
1988 colors[ 'blue' ] = '\033[94m'
1989 colors[ 'green' ] = '\033[92m'
1990 colors[ 'yellow' ] = '\033[93m'
1991 colors[ 'red' ] = '\033[91m'
1992 colors[ 'end' ] = '\033[0m'
Jon Hall73cf9cc2014-11-20 22:28:38 -08001993 description = "Test Cleanup"
Jon Hall6aec96b2015-01-19 14:49:31 -08001994 main.log.report( description )
1995 main.case( description )
1996 main.step( "Killing tcpdumps" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001997 main.Mininet2.stopTcpdump()
Jon Hall73cf9cc2014-11-20 22:28:38 -08001998
Jon Hall6aec96b2015-01-19 14:49:31 -08001999 main.step( "Checking ONOS Logs for errors" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002000 for i in range( 7 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08002001 print colors[ 'purple' ] + "Checking logs for errors on " + \
Jon Hall8f89dda2015-01-22 16:03:33 -08002002 "ONOS" + str( i + 1 ) + ":" + colors[ 'end' ]
2003 print main.ONOSbench.checkLogs( ips[ i ] )
Jon Hall94fd0472014-12-08 11:52:42 -08002004
Jon Hall6aec96b2015-01-19 14:49:31 -08002005 main.step( "Copying MN pcap and ONOS log files to test station" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08002006 testname = main.TEST
Jon Hall8f89dda2015-01-22 16:03:33 -08002007 teststationUser = main.params[ 'TESTONUSER' ]
2008 teststationIP = main.params[ 'TESTONIP' ]
Jon Hall6aec96b2015-01-19 14:49:31 -08002009 # NOTE: MN Pcap file is being saved to ~/packet_captures
Jon Hall73cf9cc2014-11-20 22:28:38 -08002010 # scp this file as MN and TestON aren't necessarily the same vm
Jon Hall6aec96b2015-01-19 14:49:31 -08002011 # FIXME: scp
2012 # mn files
2013 # TODO: Load these from params
2014 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08002015 logFolder = "/opt/onos/log/"
2016 logFiles = [ "karaf.log", "karaf.log.1" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08002017 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08002018 dstDir = "~/packet_captures/"
2019 for f in logFiles:
2020 for i in range( 7 ):
2021 main.ONOSbench.handle.sendline( "scp sdn@" + ips[ i ] + ":" +
2022 logFolder + f + " " +
2023 teststationUser + "@" +
2024 teststationIP + ":" +
2025 dstDir + str( testname ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08002026 "-ONOS" + str( i + 1 ) + "-" +
2027 f )
Jon Hall58c76b72015-02-23 11:09:24 -08002028 main.ONOSbench.handle.expect( "\$" )
2029
Jon Hall6aec96b2015-01-19 14:49:31 -08002030 # std*.log's
2031 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08002032 logFolder = "/opt/onos/var/"
2033 logFiles = [ "stderr.log", "stdout.log" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08002034 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08002035 dstDir = "~/packet_captures/"
2036 for f in logFiles:
2037 for i in range( 7 ):
2038 main.ONOSbench.handle.sendline( "scp sdn@" + ips[ i ] + ":" +
2039 logFolder + f + " " +
2040 teststationUser + "@" +
2041 teststationIP + ":" +
2042 dstDir + str( testname ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08002043 "-ONOS" + str( i + 1 ) + "-" +
2044 f )
Jon Hall58c76b72015-02-23 11:09:24 -08002045 main.ONOSbench.handle.expect( "\$" )
Jon Hall6aec96b2015-01-19 14:49:31 -08002046 # sleep so scp can finish
2047 time.sleep( 10 )
Jon Hall58c76b72015-02-23 11:09:24 -08002048 main.Mininet1.stopNet()
Jon Hall6aec96b2015-01-19 14:49:31 -08002049 main.step( "Packing and rotating pcap archives" )
2050 os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08002051
Jon Hall6aec96b2015-01-19 14:49:31 -08002052 # TODO: actually check something here
2053 utilities.assert_equals( expect=main.TRUE, actual=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08002054 onpass="Test cleanup successful",
2055 onfail="Test cleanup NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08002056
Jon Hall6aec96b2015-01-19 14:49:31 -08002057 def CASE14( self, main ):
2058 """
Jon Hall669173b2014-12-17 11:36:30 -08002059 start election app on all onos nodes
Jon Hall6aec96b2015-01-19 14:49:31 -08002060 """
Jon Hall8f89dda2015-01-22 16:03:33 -08002061 leaderResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08002062 # install app on onos 1
2063 main.log.info( "Install leadership election app" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002064 main.ONOScli1.featureInstall( "onos-app-election" )
Jon Hall6aec96b2015-01-19 14:49:31 -08002065 # wait for election
2066 # check for leader
Jon Hall8f89dda2015-01-22 16:03:33 -08002067 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08002068 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08002069 if leader == ONOS1Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08002070 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08002071 pass
Jon Hall6aec96b2015-01-19 14:49:31 -08002072 elif leader is None:
2073 # No leader elected
2074 main.log.report( "No leader was elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002075 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08002076 elif leader == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08002077 # error in response
2078 # TODO: add check for "Command not found:" in the driver, this
2079 # means the app isn't loaded
Jon Hall8f89dda2015-01-22 16:03:33 -08002080 main.log.report( "Something is wrong with electionTestLeader" +
Jon Hall6aec96b2015-01-19 14:49:31 -08002081 " function, check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002082 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08002083 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08002084 # error in response
2085 main.log.report(
Jon Hall8f89dda2015-01-22 16:03:33 -08002086 "Unexpected response from electionTestLeader function:'" +
2087 str( leader ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08002088 "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002089 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08002090
Jon Hall6aec96b2015-01-19 14:49:31 -08002091 # install on other nodes and check for leader.
2092 # Should be onos1 and each app should show the same leader
Jon Hall8f89dda2015-01-22 16:03:33 -08002093 for controller in range( 2, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08002094 # loop through ONOScli handlers
2095 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08002096 node.featureInstall( "onos-app-election" )
2097 leaderN = node.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08002098 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08002099 if leaderN == ONOS1Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08002100 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08002101 pass
2102 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08002103 # error in response
2104 # TODO: add check for "Command not found:" in the driver, this
2105 # means the app isn't loaded
2106 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002107 "electionTestLeader function, check the" +
Jon Hall6aec96b2015-01-19 14:49:31 -08002108 " error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002109 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08002110 elif leader != leaderN:
Jon Hall8f89dda2015-01-22 16:03:33 -08002111 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08002112 main.log.report( "ONOS" + str( controller ) + " sees " +
2113 str( leaderN ) +
2114 " as the leader of the election app. Leader" +
2115 " should be " +
2116 str( leader ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08002117 if leaderResult:
Jon Hall6aec96b2015-01-19 14:49:31 -08002118 main.log.report( "Leadership election tests passed( consistent " +
2119 "view of leader across listeners and a leader " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002120 "was elected )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08002121 utilities.assert_equals(
2122 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002123 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002124 onpass="Leadership election passed",
2125 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08002126
Jon Hall6aec96b2015-01-19 14:49:31 -08002127 def CASE15( self, main ):
2128 """
Jon Hall669173b2014-12-17 11:36:30 -08002129 Check that Leadership Election is still functional
Jon Hall6aec96b2015-01-19 14:49:31 -08002130 """
Jon Hall8f89dda2015-01-22 16:03:33 -08002131 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08002132 description = "Check that Leadership Election is still functional"
Jon Hall6aec96b2015-01-19 14:49:31 -08002133 main.log.report( description )
2134 main.case( description )
2135 main.step( "Find current leader and withdraw" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002136 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08002137 # TODO: do some sanity checking on leader before using it
Jon Hall8f89dda2015-01-22 16:03:33 -08002138 withdrawResult = main.FALSE
2139 if leader == ONOS1Ip:
2140 oldLeader = getattr( main, "ONOScli1" )
2141 elif leader == ONOS2Ip:
2142 oldLeader = getattr( main, "ONOScli2" )
2143 elif leader == ONOS3Ip:
2144 oldLeader = getattr( main, "ONOScli3" )
2145 elif leader == ONOS4Ip:
2146 oldLeader = getattr( main, "ONOScli4" )
2147 elif leader == ONOS5Ip:
2148 oldLeader = getattr( main, "ONOScli5" )
2149 elif leader == ONOS6Ip:
2150 oldLeader = getattr( main, "ONOScli6" )
2151 elif leader == ONOS7Ip:
2152 oldLeader = getattr( main, "ONOScli7" )
Jon Hall6aec96b2015-01-19 14:49:31 -08002153 elif leader is None or leader == main.FALSE:
2154 main.log.report(
2155 "Leader for the election app should be an ONOS node," +
Jon Hall58c76b72015-02-23 11:09:24 -08002156 "instead got '" + str( leader ) + "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002157 leaderResult = main.FALSE
2158 withdrawResult = oldLeader.electionTestWithdraw()
Jon Hall6aec96b2015-01-19 14:49:31 -08002159 utilities.assert_equals(
2160 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002161 actual=withdrawResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002162 onpass="App was withdrawn from election",
2163 onfail="App was not withdrawn from election" )
Jon Hall669173b2014-12-17 11:36:30 -08002164
Jon Hall6aec96b2015-01-19 14:49:31 -08002165 main.step( "Make sure new leader is elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002166 leaderList = []
2167 for controller in range( 1, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08002168 # loop through ONOScli handlers
2169 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08002170 leaderList.append( node.electionTestLeader() )
2171 for leaderN in leaderList:
Jon Hall669173b2014-12-17 11:36:30 -08002172 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08002173 main.log.report(
Jon Hall58c76b72015-02-23 11:09:24 -08002174 "ONOS" + str( controller ) +
2175 " still sees " + str( leader ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08002176 " as leader after they withdrew" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002177 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08002178 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08002179 # error in response
2180 # TODO: add check for "Command not found:" in the driver, this
2181 # means the app isn't loaded
2182 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002183 "electionTestLeader function, " +
Jon Hall6aec96b2015-01-19 14:49:31 -08002184 "check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002185 leaderResult = main.FALSE
2186 consistentLeader = main.FALSE
2187 if len( set( leaderList ) ) == 1:
Jon Hall6aec96b2015-01-19 14:49:31 -08002188 main.log.info( "Each Election-app sees '" +
Jon Hall8f89dda2015-01-22 16:03:33 -08002189 str( leaderList[ 0 ] ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08002190 "' as the leader" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002191 consistentLeader = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08002192 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08002193 main.log.report(
2194 "Inconsistent responses for leader of Election-app:" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002195 for n in range( len( leaderList ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -08002196 main.log.report( "ONOS" + str( n + 1 ) + " response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002197 str( leaderList[ n ] ) )
2198 if leaderResult:
2199 main.log.report( "Leadership election tests passed( consistent " +
Jon Hall6aec96b2015-01-19 14:49:31 -08002200 "view of leader across listeners and a new " +
2201 "leader was elected when the old leader " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002202 "resigned )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08002203 utilities.assert_equals(
2204 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002205 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002206 onpass="Leadership election passed",
2207 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08002208
Jon Hall58c76b72015-02-23 11:09:24 -08002209 main.step( "Run for election on old leader( just so everyone " +
2210 "is in the hat )" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002211 runResult = oldLeader.electionTestRun()
Jon Hall6aec96b2015-01-19 14:49:31 -08002212 utilities.assert_equals(
2213 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002214 actual=runResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002215 onpass="App re-ran for election",
2216 onfail="App failed to run for election" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002217 if consistentLeader == main.TRUE:
2218 afterRun = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08002219 # verify leader didn't just change
Jon Hall8f89dda2015-01-22 16:03:33 -08002220 if afterRun == leaderList[ 0 ]:
2221 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08002222 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08002223 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08002224 # TODO: assert on run and withdraw results?
Jon Hall669173b2014-12-17 11:36:30 -08002225
Jon Hall6aec96b2015-01-19 14:49:31 -08002226 utilities.assert_equals(
2227 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002228 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002229 onpass="Leadership election passed",
2230 onfail="Something went wrong with Leadership election after " +
2231 "the old leader re-ran for election" )