blob: 1f41027d33248112516ba9476b582c832dabdf20 [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 all 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 HATestClusterRestart:
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( "ONOS HA test: Restart all ONOS nodes - " +
48 "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 Hall8f89dda2015-01-22 16:03:33 -0800121 cleanInstallResult = main.ONOSbench.cleanInstall()
Jon Hall6aec96b2015-01-19 14:49:31 -0800122 else:
123 main.log.warn( "Did not pull new code so skipping mvn " +
124 "clean install" )
Jon Hall1b8f54a2015-02-04 13:24:20 -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 """
Jon Hall6aec96b2015-01-19 14:49:31 -0800418 # FIXME: we must reinstall intents until we have a persistant
419 # datastore!
Jon Hall73cf9cc2014-11-20 22:28:38 -0800420 import time
Jon Hall58c76b72015-02-23 11:09:24 -0800421 import json
Jon Hall6aec96b2015-01-19 14:49:31 -0800422 main.log.report( "Adding host intents" )
423 main.case( "Adding host Intents" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800424
Jon Hall8f89dda2015-01-22 16:03:33 -0800425 main.step( "Discovering Hosts( Via pingall for now )" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800426 # FIXME: Once we have a host discovery mechanism, use that instead
Jon Hall73cf9cc2014-11-20 22:28:38 -0800427
Jon Hall6aec96b2015-01-19 14:49:31 -0800428 # install onos-app-fwd
429 main.log.info( "Install reactive forwarding app" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800430 main.ONOScli1.featureInstall( "onos-app-fwd" )
431 main.ONOScli2.featureInstall( "onos-app-fwd" )
432 main.ONOScli3.featureInstall( "onos-app-fwd" )
433 main.ONOScli4.featureInstall( "onos-app-fwd" )
434 main.ONOScli5.featureInstall( "onos-app-fwd" )
435 main.ONOScli6.featureInstall( "onos-app-fwd" )
436 main.ONOScli7.featureInstall( "onos-app-fwd" )
Jon Hall94fd0472014-12-08 11:52:42 -0800437
Jon Hall6aec96b2015-01-19 14:49:31 -0800438 # REACTIVE FWD test
Jon Hall8f89dda2015-01-22 16:03:33 -0800439 pingResult = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800440 time1 = time.time()
Jon Hall8f89dda2015-01-22 16:03:33 -0800441 pingResult = main.Mininet1.pingall()
Jon Hall529a37f2015-01-28 10:02:00 -0800442 utilities.assert_equals(
443 expect=main.TRUE,
444 actual=pingResult,
445 onpass="Reactive Pingall test passed",
446 onfail="Reactive Pingall failed, one or more ping pairs failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800447 time2 = time.time()
Jon Hall6aec96b2015-01-19 14:49:31 -0800448 main.log.info( "Time for pingall: %2f seconds" % ( time2 - time1 ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800449
Jon Hall6aec96b2015-01-19 14:49:31 -0800450 # uninstall onos-app-fwd
451 main.log.info( "Uninstall reactive forwarding app" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800452 main.ONOScli1.featureUninstall( "onos-app-fwd" )
453 main.ONOScli2.featureUninstall( "onos-app-fwd" )
454 main.ONOScli3.featureUninstall( "onos-app-fwd" )
455 main.ONOScli4.featureUninstall( "onos-app-fwd" )
456 main.ONOScli5.featureUninstall( "onos-app-fwd" )
457 main.ONOScli6.featureUninstall( "onos-app-fwd" )
458 main.ONOScli7.featureUninstall( "onos-app-fwd" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800459 # timeout for fwd flows
460 time.sleep( 10 )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800461
Jon Hall6aec96b2015-01-19 14:49:31 -0800462 main.step( "Add host intents" )
Jon Hall58c76b72015-02-23 11:09:24 -0800463 intentIds = []
Jon Hall6aec96b2015-01-19 14:49:31 -0800464 # TODO: move the host numbers to params
Jon Hall58c76b72015-02-23 11:09:24 -0800465 # Maybe look at all the paths we ping?
Jon Hall8f89dda2015-01-22 16:03:33 -0800466 intentAddResult = True
Jon Hall58c76b72015-02-23 11:09:24 -0800467 hostResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800468 for i in range( 8, 18 ):
469 main.log.info( "Adding host intent between h" + str( i ) +
470 " and h" + str( i + 10 ) )
471 host1 = "00:00:00:00:00:" + \
472 str( hex( i )[ 2: ] ).zfill( 2 ).upper()
473 host2 = "00:00:00:00:00:" + \
474 str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper()
Jon Hall1b8f54a2015-02-04 13:24:20 -0800475 # NOTE: getHost can return None
476 host1Dict = main.ONOScli1.getHost( host1 )
477 host2Dict = main.ONOScli1.getHost( host2 )
478 host1Id = None
479 host2Id = None
480 if host1Dict and host2Dict:
481 host1Id = host1Dict.get( 'id', None )
482 host2Id = host2Dict.get( 'id', None )
Jon Hall8f89dda2015-01-22 16:03:33 -0800483 if host1Id and host2Id:
Jon Hall21270ac2015-02-16 17:59:55 -0800484
Jon Hall58c76b72015-02-23 11:09:24 -0800485 tmpId = main.ONOScli1.addHostIntent(
Jon Hall8f89dda2015-01-22 16:03:33 -0800486 host1Id,
487 host2Id )
Jon Hall58c76b72015-02-23 11:09:24 -0800488 main.log.info( "Added intent with id: " + tmpId )
489 intentIds.append( tmpId )
Jon Hall669173b2014-12-17 11:36:30 -0800490 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800491 main.log.error( "Error, getHost() failed" )
Jon Hall1b8f54a2015-02-04 13:24:20 -0800492 main.log.warn( json.dumps( json.loads( main.ONOScli1.hosts() ),
493 sort_keys=True,
494 indent=4,
495 separators=( ',', ': ' ) ) )
Jon Hall58c76b72015-02-23 11:09:24 -0800496 hostResult = main.FALSE
497 onosIds = main.ONOScli1.getAllIntentsId()
498 main.log.info( "Submitted intents: " + str( intentIds ) )
499 main.log.info( "Intents in ONOS: " + str( onosIds ) )
500 for intent in intentIds:
501 if intent in onosIds:
502 pass # intent submitted is still in onos
503 else:
504 intentAddResult = False
Jon Hall1b8f54a2015-02-04 13:24:20 -0800505 # Print the intent states
Jon Hall58c76b72015-02-23 11:09:24 -0800506 intents = main.ONOScli1.intents()
Jon Hall1b8f54a2015-02-04 13:24:20 -0800507 intentStates = []
Jon Hall58c76b72015-02-23 11:09:24 -0800508 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
509 count = 0
Jon Hall1b8f54a2015-02-04 13:24:20 -0800510 for intent in json.loads( intents ): # Iter through intents of a node
Jon Hall58c76b72015-02-23 11:09:24 -0800511 state = intent.get( 'state', None )
512 intentId = intent.get( 'id', None )
513 intentStates.append( ( intentId, state ) )
514 # add submitted intents not in the store
515 tmplist = [ i for i, s in intentStates ]
516 missingIntents = False
517 for i in intentIds:
518 if i not in tmplist:
519 intentStates.append( ( i, " - " ) )
520 missingIntents = True
521 intentStates.sort()
522 for i, s in intentStates:
523 count += 1
524 main.log.info( "%-6s%-15s%-15s" %
525 ( str( count ), str( i ), str( s ) ) )
526 intentAddResult = bool( pingResult and hostResult and intentAddResult
527 and not missingIntents)
Jon Hall6aec96b2015-01-19 14:49:31 -0800528 utilities.assert_equals(
529 expect=True,
Jon Hall8f89dda2015-01-22 16:03:33 -0800530 actual=intentAddResult,
Jon Hall529a37f2015-01-28 10:02:00 -0800531 onpass="Pushed host intents to ONOS",
532 onfail="Error in pushing host intents to ONOS" )
Jon Hall58c76b72015-02-23 11:09:24 -0800533
534 if not intentAddResult:
535 import time
536 main.log.info( "Sleeping 60 seconds to see if intents are found" )
537 time.sleep( 60 )
538 onosIds = main.ONOScli1.getAllIntentsId()
539 main.log.info( "Submitted intents: " + str( intentIds ) )
540 main.log.info( "Intents in ONOS: " + str( onosIds ) )
541 # Print the intent states
542 intents = main.ONOScli1.intents()
543 intentStates = []
544 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
545 count = 0
546 for intent in json.loads( intents ):
547 # Iter through intents of a node
548 state = intent.get( 'state', None )
549 intentId = intent.get( 'id', None )
550 intentStates.append( ( intentId, state ) )
551 # add submitted intents not in the store
552 tmplist = [ i for i, s in intentStates ]
553 for i in intentIds:
554 if i not in tmplist:
555 intentStates.append( ( i, " - " ) )
556 intentStates.sort()
557 for i, s in intentStates:
558 count += 1
559 main.log.info( "%-6s%-15s%-15s" %
560 ( str( count ), str( i ), str( s ) ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800561
Jon Hall6aec96b2015-01-19 14:49:31 -0800562 def CASE4( self, main ):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800563 """
564 Ping across added host intents
565 """
Jon Hall58c76b72015-02-23 11:09:24 -0800566 import json
Jon Hall73cf9cc2014-11-20 22:28:38 -0800567 description = " Ping across added host intents"
Jon Hall6aec96b2015-01-19 14:49:31 -0800568 main.log.report( description )
569 main.case( description )
Jon Hall8f89dda2015-01-22 16:03:33 -0800570 PingResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800571 for i in range( 8, 18 ):
Jon Hall58c76b72015-02-23 11:09:24 -0800572 ping = main.Mininet1.pingHost( src="h" + str( i ),
573 target="h" + str( i + 10 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800574 PingResult = PingResult and ping
Jon Hall6aec96b2015-01-19 14:49:31 -0800575 if ping == main.FALSE:
576 main.log.warn( "Ping failed between h" + str( i ) +
577 " and h" + str( i + 10 ) )
578 elif ping == main.TRUE:
579 main.log.info( "Ping test passed!" )
Jon Hall21270ac2015-02-16 17:59:55 -0800580 # Don't set PingResult or you'd override failures
Jon Hall8f89dda2015-01-22 16:03:33 -0800581 if PingResult == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800582 main.log.report(
583 "Intents have not been installed correctly, pings failed." )
Jon Hall58c76b72015-02-23 11:09:24 -0800584 # TODO: pretty print
Jon Hall529a37f2015-01-28 10:02:00 -0800585 main.log.warn( "ONSO1 intents: " )
586 main.log.warn( json.dumps( json.loads( main.ONOScli1.intents() ),
587 sort_keys=True,
588 indent=4,
589 separators=( ',', ': ' ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800590 if PingResult == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800591 main.log.report(
592 "Intents have been installed correctly and verified by pings" )
593 utilities.assert_equals(
594 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800595 actual=PingResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800596 onpass="Intents have been installed correctly and pings work",
597 onfail="Intents have not been installed correctly, pings failed." )
Jon Hall58c76b72015-02-23 11:09:24 -0800598 if PingResult is not main.TRUE:
599 # Print the intent states
600 intents = main.ONOScli1.intents()
601 intentStates = []
602 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
603 count = 0
604 # Iter through intents of a node
605 for intent in json.loads( intents ):
606 state = intent.get( 'state', None )
607 intentId = intent.get( 'id', None )
608 intentStates.append( ( intentId, state ) )
609 intentStates.sort()
610 for i, s in intentStates:
611 count += 1
612 main.log.info( "%-6s%-15s%-15s" %
613 ( str( count ), str( i ), str( s ) ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800614
Jon Hall6aec96b2015-01-19 14:49:31 -0800615 def CASE5( self, main ):
616 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800617 Reading state of ONOS
Jon Hall6aec96b2015-01-19 14:49:31 -0800618 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800619 import json
Jon Hall6aec96b2015-01-19 14:49:31 -0800620 # assumes that sts is already in you PYTHONPATH
621 from sts.topology.teston_topology import TestONTopology
Jon Hall73cf9cc2014-11-20 22:28:38 -0800622
Jon Hall6aec96b2015-01-19 14:49:31 -0800623 main.log.report( "Setting up and gathering data for current state" )
624 main.case( "Setting up and gathering data for current state" )
625 # The general idea for this test case is to pull the state of
626 # ( intents,flows, topology,... ) from each ONOS node
627 # We can then compare them with eachother and also with past states
Jon Hall73cf9cc2014-11-20 22:28:38 -0800628
Jon Hall6aec96b2015-01-19 14:49:31 -0800629 main.step( "Get the Mastership of each switch from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800630 global mastershipState
631 mastershipState = []
Jon Hall94fd0472014-12-08 11:52:42 -0800632
Jon Hall6aec96b2015-01-19 14:49:31 -0800633 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -0800634 ONOS1MasterNotNull = main.ONOScli1.rolesNotNull()
635 ONOS2MasterNotNull = main.ONOScli2.rolesNotNull()
636 ONOS3MasterNotNull = main.ONOScli3.rolesNotNull()
637 ONOS4MasterNotNull = main.ONOScli4.rolesNotNull()
638 ONOS5MasterNotNull = main.ONOScli5.rolesNotNull()
639 ONOS6MasterNotNull = main.ONOScli6.rolesNotNull()
640 ONOS7MasterNotNull = main.ONOScli7.rolesNotNull()
641 rolesNotNull = ONOS1MasterNotNull and ONOS2MasterNotNull and\
642 ONOS3MasterNotNull and ONOS4MasterNotNull and\
643 ONOS5MasterNotNull and ONOS6MasterNotNull and\
644 ONOS7MasterNotNull
Jon Hall6aec96b2015-01-19 14:49:31 -0800645 utilities.assert_equals(
646 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800647 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -0800648 onpass="Each device has a master",
649 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -0800650
Jon Hall8f89dda2015-01-22 16:03:33 -0800651 ONOS1Mastership = main.ONOScli1.roles()
652 ONOS2Mastership = main.ONOScli2.roles()
653 ONOS3Mastership = main.ONOScli3.roles()
654 ONOS4Mastership = main.ONOScli4.roles()
655 ONOS5Mastership = main.ONOScli5.roles()
656 ONOS6Mastership = main.ONOScli6.roles()
657 ONOS7Mastership = main.ONOScli7.roles()
658 if "Error" in ONOS1Mastership or not ONOS1Mastership\
659 or "Error" in ONOS2Mastership or not ONOS2Mastership\
660 or "Error" in ONOS3Mastership or not ONOS3Mastership\
661 or "Error" in ONOS4Mastership or not ONOS4Mastership\
662 or "Error" in ONOS5Mastership or not ONOS5Mastership\
663 or "Error" in ONOS6Mastership or not ONOS6Mastership\
664 or "Error" in ONOS7Mastership or not ONOS7Mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -0800665 main.log.report( "Error in getting ONOS roles" )
666 main.log.warn(
667 "ONOS1 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800668 repr( ONOS1Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800669 main.log.warn(
670 "ONOS2 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800671 repr( ONOS2Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800672 main.log.warn(
673 "ONOS3 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800674 repr( ONOS3Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800675 main.log.warn(
676 "ONOS4 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800677 repr( ONOS4Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800678 main.log.warn(
679 "ONOS5 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800680 repr( ONOS5Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800681 main.log.warn(
682 "ONOS6 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800683 repr( ONOS6Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800684 main.log.warn(
685 "ONOS7 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800686 repr( ONOS7Mastership ) )
687 consistentMastership = main.FALSE
688 elif ONOS1Mastership == ONOS2Mastership\
689 and ONOS1Mastership == ONOS3Mastership\
690 and ONOS1Mastership == ONOS4Mastership\
691 and ONOS1Mastership == ONOS5Mastership\
692 and ONOS1Mastership == ONOS6Mastership\
693 and ONOS1Mastership == ONOS7Mastership:
694 mastershipState = ONOS1Mastership
695 consistentMastership = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800696 main.log.report(
697 "Switch roles are consistent across all ONOS nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800698 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800699 main.log.warn(
700 "ONOS1 roles: ",
701 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800702 json.loads( ONOS1Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800703 sort_keys=True,
704 indent=4,
705 separators=(
706 ',',
707 ': ' ) ) )
708 main.log.warn(
709 "ONOS2 roles: ",
710 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800711 json.loads( ONOS2Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800712 sort_keys=True,
713 indent=4,
714 separators=(
715 ',',
716 ': ' ) ) )
717 main.log.warn(
718 "ONOS3 roles: ",
719 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800720 json.loads( ONOS3Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800721 sort_keys=True,
722 indent=4,
723 separators=(
724 ',',
725 ': ' ) ) )
726 main.log.warn(
727 "ONOS4 roles: ",
728 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800729 json.loads( ONOS4Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800730 sort_keys=True,
731 indent=4,
732 separators=(
733 ',',
734 ': ' ) ) )
735 main.log.warn(
736 "ONOS5 roles: ",
737 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800738 json.loads( ONOS5Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800739 sort_keys=True,
740 indent=4,
741 separators=(
742 ',',
743 ': ' ) ) )
744 main.log.warn(
745 "ONOS6 roles: ",
746 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800747 json.loads( ONOS6Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800748 sort_keys=True,
749 indent=4,
750 separators=(
751 ',',
752 ': ' ) ) )
753 main.log.warn(
754 "ONOS7 roles: ",
755 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800756 json.loads( ONOS7Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800757 sort_keys=True,
758 indent=4,
759 separators=(
760 ',',
761 ': ' ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800762 consistentMastership = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800763 utilities.assert_equals(
764 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800765 actual=consistentMastership,
Jon Hall6aec96b2015-01-19 14:49:31 -0800766 onpass="Switch roles are consistent across all ONOS nodes",
767 onfail="ONOS nodes have different views of switch roles" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800768
Jon Hall6aec96b2015-01-19 14:49:31 -0800769 main.step( "Get the intents from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800770 global intentState
771 intentState = []
772 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
773 ONOS2Intents = main.ONOScli2.intents( jsonFormat=True )
774 ONOS3Intents = main.ONOScli3.intents( jsonFormat=True )
775 ONOS4Intents = main.ONOScli4.intents( jsonFormat=True )
776 ONOS5Intents = main.ONOScli5.intents( jsonFormat=True )
777 ONOS6Intents = main.ONOScli6.intents( jsonFormat=True )
778 ONOS7Intents = main.ONOScli7.intents( jsonFormat=True )
779 intentCheck = main.FALSE
780 if "Error" in ONOS1Intents or not ONOS1Intents\
781 or "Error" in ONOS2Intents or not ONOS2Intents\
782 or "Error" in ONOS3Intents or not ONOS3Intents\
783 or "Error" in ONOS4Intents or not ONOS4Intents\
784 or "Error" in ONOS5Intents or not ONOS5Intents\
785 or "Error" in ONOS6Intents or not ONOS6Intents\
786 or "Error" in ONOS7Intents or not ONOS7Intents:
Jon Hall6aec96b2015-01-19 14:49:31 -0800787 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800788 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
789 main.log.warn( "ONOS2 intents response: " + repr( ONOS2Intents ) )
790 main.log.warn( "ONOS3 intents response: " + repr( ONOS3Intents ) )
791 main.log.warn( "ONOS4 intents response: " + repr( ONOS4Intents ) )
792 main.log.warn( "ONOS5 intents response: " + repr( ONOS5Intents ) )
793 main.log.warn( "ONOS6 intents response: " + repr( ONOS6Intents ) )
794 main.log.warn( "ONOS7 intents response: " + repr( ONOS7Intents ) )
795 elif ONOS1Intents == ONOS2Intents\
796 and ONOS1Intents == ONOS3Intents\
797 and ONOS1Intents == ONOS4Intents\
798 and ONOS1Intents == ONOS5Intents\
799 and ONOS1Intents == ONOS6Intents\
800 and ONOS1Intents == ONOS7Intents:
801 intentState = ONOS1Intents
802 intentCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800803 main.log.report( "Intents are consistent across all ONOS nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800804 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800805 main.log.warn(
806 "ONOS1 intents: ",
807 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800808 json.loads( ONOS1Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800809 sort_keys=True,
810 indent=4,
811 separators=(
812 ',',
813 ': ' ) ) )
814 main.log.warn(
815 "ONOS2 intents: ",
816 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800817 json.loads( ONOS2Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800818 sort_keys=True,
819 indent=4,
820 separators=(
821 ',',
822 ': ' ) ) )
823 main.log.warn(
824 "ONOS3 intents: ",
825 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800826 json.loads( ONOS3Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800827 sort_keys=True,
828 indent=4,
829 separators=(
830 ',',
831 ': ' ) ) )
832 main.log.warn(
833 "ONOS4 intents: ",
834 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800835 json.loads( ONOS4Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800836 sort_keys=True,
837 indent=4,
838 separators=(
839 ',',
840 ': ' ) ) )
841 main.log.warn(
842 "ONOS5 intents: ",
843 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800844 json.loads( ONOS5Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800845 sort_keys=True,
846 indent=4,
847 separators=(
848 ',',
849 ': ' ) ) )
850 main.log.warn(
851 "ONOS6 intents: ",
852 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800853 json.loads( ONOS6Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800854 sort_keys=True,
855 indent=4,
856 separators=(
857 ',',
858 ': ' ) ) )
859 main.log.warn(
860 "ONOS7 intents: ",
861 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800862 json.loads( ONOS7Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800863 sort_keys=True,
864 indent=4,
865 separators=(
866 ',',
867 ': ' ) ) )
868 utilities.assert_equals(
869 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800870 actual=intentCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800871 onpass="Intents are consistent across all ONOS nodes",
872 onfail="ONOS nodes have different views of intents" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800873
Jon Hall6aec96b2015-01-19 14:49:31 -0800874 main.step( "Get the flows from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800875 global flowState
876 flowState = []
Jon Hall8f89dda2015-01-22 16:03:33 -0800877 flowCheck = main.FALSE
Jon Hall58c76b72015-02-23 11:09:24 -0800878 try:
879 ONOS1Flows = main.ONOScli1.flows( jsonFormat=True )
880 ONOS2Flows = main.ONOScli2.flows( jsonFormat=True )
881 ONOS3Flows = main.ONOScli3.flows( jsonFormat=True )
882 ONOS4Flows = main.ONOScli4.flows( jsonFormat=True )
883 ONOS5Flows = main.ONOScli5.flows( jsonFormat=True )
884 ONOS6Flows = main.ONOScli6.flows( jsonFormat=True )
885 ONOS7Flows = main.ONOScli7.flows( jsonFormat=True )
886 assert ONOS1Flows, "ONOS1 Flows should not be empty"
887 assert ONOS2Flows, "ONOS2 Flows should not be empty"
888 assert ONOS3Flows, "ONOS3 Flows should not be empty"
889 assert ONOS4Flows, "ONOS4 Flows should not be empty"
890 assert ONOS5Flows, "ONOS5 Flows should not be empty"
891 assert ONOS6Flows, "ONOS6 Flows should not be empty"
892 assert ONOS7Flows, "ONOS7 Flows should not be empty"
893 assert "Error" not in ONOS1Flows, "ONOS1 Flows contains 'Error'"
894 assert "Error" not in ONOS2Flows, "ONOS2 Flows contains 'Error'"
895 assert "Error" not in ONOS3Flows, "ONOS3 Flows contains 'Error'"
896 assert "Error" not in ONOS4Flows, "ONOS4 Flows contains 'Error'"
897 assert "Error" not in ONOS5Flows, "ONOS5 Flows contains 'Error'"
898 assert "Error" not in ONOS6Flows, "ONOS6 Flows contains 'Error'"
899 assert "Error" not in ONOS7Flows, "ONOS7 Flows contains 'Error'"
900 ONOS1FlowsJson = json.loads( ONOS1Flows )
901 ONOS2FlowsJson = json.loads( ONOS2Flows )
902 ONOS3FlowsJson = json.loads( ONOS3Flows )
903 ONOS4FlowsJson = json.loads( ONOS4Flows )
904 ONOS5FlowsJson = json.loads( ONOS5Flows )
905 ONOS6FlowsJson = json.loads( ONOS6Flows )
906 ONOS7FlowsJson = json.loads( ONOS7Flows )
907 except ( ValueError, AssertionError ): # From json.loads, or asserts
908 main.log.exception( "One or more 'flows' responses from " +
909 "ONOS couldn't be decoded." )
Jon Hall8f89dda2015-01-22 16:03:33 -0800910 main.log.warn( "ONOS1 flows repsponse: " + ONOS1Flows )
911 main.log.warn( "ONOS2 flows repsponse: " + ONOS2Flows )
912 main.log.warn( "ONOS3 flows repsponse: " + ONOS3Flows )
913 main.log.warn( "ONOS4 flows repsponse: " + ONOS4Flows )
914 main.log.warn( "ONOS5 flows repsponse: " + ONOS5Flows )
915 main.log.warn( "ONOS6 flows repsponse: " + ONOS6Flows )
916 main.log.warn( "ONOS7 flows repsponse: " + ONOS7Flows )
Jon Hall58c76b72015-02-23 11:09:24 -0800917 else: # No exceptions
918 if len( ONOS1FlowsJson ) == len( ONOS2FlowsJson )\
919 and len( ONOS1FlowsJson ) == len( ONOS3FlowsJson )\
920 and len( ONOS1FlowsJson ) == len( ONOS4FlowsJson )\
921 and len( ONOS1FlowsJson ) == len( ONOS5FlowsJson )\
922 and len( ONOS1FlowsJson ) == len( ONOS6FlowsJson )\
923 and len( ONOS1FlowsJson ) == len( ONOS7FlowsJson ):
Jon Hall6aec96b2015-01-19 14:49:31 -0800924 # TODO: Do a better check, maybe compare flows on switches?
Jon Hall58c76b72015-02-23 11:09:24 -0800925 # NOTE Possible issue with this not always being set?
926 flowState = ONOS1Flows
927 flowCheck = main.TRUE
928 main.log.report( "Flow count is consistent across all" +
929 " ONOS nodes" )
930 else:
931 main.log.warn( "ONOS1 flows: " +
932 json.dumps( ONOS1FlowsJson, sort_keys=True,
933 indent=4,
934 separators=( ',', ': ' ) ) )
935 main.log.warn( "ONOS2 flows: " +
936 json.dumps( ONOS2FlowsJson, sort_keys=True,
937 indent=4,
938 separators=( ',', ': ' ) ) )
939 main.log.warn( "ONOS3 flows: " +
940 json.dumps( ONOS3FlowsJson, sort_keys=True,
941 indent=4,
942 separators=( ',', ': ' ) ) )
943 main.log.warn( "ONOS4 flows: " +
944 json.dumps( ONOS4FlowsJson, sort_keys=True,
945 indent=4,
946 separators=( ',', ': ' ) ) )
947 main.log.warn( "ONOS5 flows: " +
948 json.dumps( ONOS5FlowsJson, sort_keys=True,
949 indent=4,
950 separators=( ',', ': ' ) ) )
951 main.log.warn( "ONOS6 flows: " +
952 json.dumps( ONOS6FlowsJson, sort_keys=True,
953 indent=4,
954 separators=( ',', ': ' ) ) )
955 main.log.warn( "ONOS7 flows: " +
956 json.dumps( ONOS7FlowsJson, sort_keys=True,
957 indent=4,
958 separators=( ',', ': ' ) ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800959 utilities.assert_equals(
960 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800961 actual=flowCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800962 onpass="The flow count is consistent across all ONOS nodes",
963 onfail="ONOS nodes have different flow counts" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800964
Jon Hall6aec96b2015-01-19 14:49:31 -0800965 main.step( "Get the OF Table entries" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800966 global flows
Jon Hall6aec96b2015-01-19 14:49:31 -0800967 flows = []
968 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800969 flows.append( main.Mininet2.getFlowTable( 1.3, "s" + str( i ) ) )
Jon Hall58c76b72015-02-23 11:09:24 -0800970 if flowCheck == main.FALSE:
971 for table in flows:
972 main.log.warn( table )
Jon Hall6aec96b2015-01-19 14:49:31 -0800973 # TODO: Compare switch flow tables with ONOS flow tables
Jon Hall73cf9cc2014-11-20 22:28:38 -0800974
Jon Hall6aec96b2015-01-19 14:49:31 -0800975 main.step( "Start continuous pings" )
976 main.Mininet2.pingLong(
977 src=main.params[ 'PING' ][ 'source1' ],
978 target=main.params[ 'PING' ][ 'target1' ],
979 pingTime=500 )
980 main.Mininet2.pingLong(
981 src=main.params[ 'PING' ][ 'source2' ],
982 target=main.params[ 'PING' ][ 'target2' ],
983 pingTime=500 )
984 main.Mininet2.pingLong(
985 src=main.params[ 'PING' ][ 'source3' ],
986 target=main.params[ 'PING' ][ 'target3' ],
987 pingTime=500 )
988 main.Mininet2.pingLong(
989 src=main.params[ 'PING' ][ 'source4' ],
990 target=main.params[ 'PING' ][ 'target4' ],
991 pingTime=500 )
992 main.Mininet2.pingLong(
993 src=main.params[ 'PING' ][ 'source5' ],
994 target=main.params[ 'PING' ][ 'target5' ],
995 pingTime=500 )
996 main.Mininet2.pingLong(
997 src=main.params[ 'PING' ][ 'source6' ],
998 target=main.params[ 'PING' ][ 'target6' ],
999 pingTime=500 )
1000 main.Mininet2.pingLong(
1001 src=main.params[ 'PING' ][ 'source7' ],
1002 target=main.params[ 'PING' ][ 'target7' ],
1003 pingTime=500 )
1004 main.Mininet2.pingLong(
1005 src=main.params[ 'PING' ][ 'source8' ],
1006 target=main.params[ 'PING' ][ 'target8' ],
1007 pingTime=500 )
1008 main.Mininet2.pingLong(
1009 src=main.params[ 'PING' ][ 'source9' ],
1010 target=main.params[ 'PING' ][ 'target9' ],
1011 pingTime=500 )
1012 main.Mininet2.pingLong(
1013 src=main.params[ 'PING' ][ 'source10' ],
1014 target=main.params[ 'PING' ][ 'target10' ],
1015 pingTime=500 )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001016
Jon Hall6aec96b2015-01-19 14:49:31 -08001017 main.step( "Create TestONTopology object" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001018 ctrls = []
1019 count = 1
1020 while True:
1021 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -08001022 if ( 'ip' + str( count ) ) in main.params[ 'CTRL' ]:
1023 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
1024 temp = temp + ( "ONOS" + str( count ), )
1025 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
1026 temp = temp + \
1027 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
1028 ctrls.append( temp )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001029 count = count + 1
1030 else:
1031 break
Jon Hall6aec96b2015-01-19 14:49:31 -08001032 MNTopo = TestONTopology(
1033 main.Mininet1,
1034 ctrls ) # can also add Intent API info for intent operations
Jon Hall73cf9cc2014-11-20 22:28:38 -08001035
Jon Hall6aec96b2015-01-19 14:49:31 -08001036 main.step( "Collecting topology information from ONOS" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001037 devices = []
1038 devices.append( main.ONOScli1.devices() )
1039 devices.append( main.ONOScli2.devices() )
1040 devices.append( main.ONOScli3.devices() )
1041 devices.append( main.ONOScli4.devices() )
1042 devices.append( main.ONOScli5.devices() )
1043 devices.append( main.ONOScli6.devices() )
1044 devices.append( main.ONOScli7.devices() )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001045 hosts = []
Jon Hall58c76b72015-02-23 11:09:24 -08001046 hosts.append( json.loads( main.ONOScli1.hosts() ) )
1047 hosts.append( json.loads( main.ONOScli2.hosts() ) )
1048 hosts.append( json.loads( main.ONOScli3.hosts() ) )
1049 hosts.append( json.loads( main.ONOScli4.hosts() ) )
1050 hosts.append( json.loads( main.ONOScli5.hosts() ) )
1051 hosts.append( json.loads( main.ONOScli6.hosts() ) )
1052 hosts.append( json.loads( main.ONOScli7.hosts() ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001053 ports = []
1054 ports.append( main.ONOScli1.ports() )
1055 ports.append( main.ONOScli2.ports() )
1056 ports.append( main.ONOScli3.ports() )
1057 ports.append( main.ONOScli4.ports() )
1058 ports.append( main.ONOScli5.ports() )
1059 ports.append( main.ONOScli6.ports() )
1060 ports.append( main.ONOScli7.ports() )
1061 links = []
1062 links.append( main.ONOScli1.links() )
1063 links.append( main.ONOScli2.links() )
1064 links.append( main.ONOScli3.links() )
1065 links.append( main.ONOScli4.links() )
1066 links.append( main.ONOScli5.links() )
1067 links.append( main.ONOScli6.links() )
1068 links.append( main.ONOScli7.links() )
Jon Hall94fd0472014-12-08 11:52:42 -08001069 clusters = []
1070 clusters.append( main.ONOScli1.clusters() )
1071 clusters.append( main.ONOScli2.clusters() )
1072 clusters.append( main.ONOScli3.clusters() )
1073 clusters.append( main.ONOScli4.clusters() )
1074 clusters.append( main.ONOScli5.clusters() )
1075 clusters.append( main.ONOScli6.clusters() )
1076 clusters.append( main.ONOScli7.clusters() )
Jon Hall529a37f2015-01-28 10:02:00 -08001077 # Compare json objects for hosts and dataplane clusters
Jon Hall94fd0472014-12-08 11:52:42 -08001078
Jon Hall6aec96b2015-01-19 14:49:31 -08001079 # hosts
Jon Hall8f89dda2015-01-22 16:03:33 -08001080 consistentHostsResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -08001081 for controller in range( len( hosts ) ):
Jon Hall8f89dda2015-01-22 16:03:33 -08001082 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001083 if "Error" not in hosts[ controller ]:
1084 if hosts[ controller ] == hosts[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001085 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001086 else: # hosts not consistent
1087 main.log.report( "hosts from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001088 controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001089 " is inconsistent with ONOS1" )
1090 main.log.warn( repr( hosts[ controller ] ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001091 consistentHostsResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001092
1093 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001094 main.log.report( "Error in getting ONOS hosts from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001095 controllerStr )
1096 consistentHostsResult = main.FALSE
1097 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001098 " hosts response: " +
1099 repr( hosts[ controller ] ) )
1100 utilities.assert_equals(
1101 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001102 actual=consistentHostsResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001103 onpass="Hosts view is consistent across all ONOS nodes",
1104 onfail="ONOS nodes have different views of hosts" )
Jon Hall94fd0472014-12-08 11:52:42 -08001105
Jon Hall58c76b72015-02-23 11:09:24 -08001106 ipResult = main.TRUE
1107 for controller in range( 0, len( hosts ) ):
1108 controllerStr = str( controller + 1 )
1109 for host in hosts[ controller ]:
1110 if host.get( 'ips', [] ) == []:
1111 main.log.error(
1112 "DEBUG:Error with host ips on controller" +
1113 controllerStr + ": " + str( host ) )
1114 ipResult = main.FALSE
1115 utilities.assert_equals(
1116 expect=main.TRUE,
1117 actual=ipResult,
1118 onpass="The ips of the hosts aren't empty",
1119 onfail="The ip of at least one host is missing" )
1120
Jon Hall6aec96b2015-01-19 14:49:31 -08001121 # Strongly connected clusters of devices
Jon Hall8f89dda2015-01-22 16:03:33 -08001122 consistentClustersResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -08001123 for controller in range( len( clusters ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001124 if "Error" not in clusters[ controller ]:
1125 if clusters[ controller ] == clusters[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001126 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001127 else: # clusters not consistent
1128 main.log.report( "clusters from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001129 controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001130 " is inconsistent with ONOS1" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001131 consistentClustersResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001132
1133 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001134 main.log.report( "Error in getting dataplane clusters " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001135 "from ONOS" + controllerStr )
1136 consistentClustersResult = main.FALSE
1137 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001138 " clusters response: " +
1139 repr( clusters[ controller ] ) )
1140 utilities.assert_equals(
1141 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001142 actual=consistentClustersResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001143 onpass="Clusters view is consistent across all ONOS nodes",
1144 onfail="ONOS nodes have different views of clusters" )
1145 # there should always only be one cluster
Jon Hall8f89dda2015-01-22 16:03:33 -08001146 numClusters = len( json.loads( clusters[ 0 ] ) )
Jon Hall58c76b72015-02-23 11:09:24 -08001147 clusterResults = main.FALSE
1148 if numClusters == 1:
1149 clusterResults = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001150 utilities.assert_equals(
1151 expect=1,
Jon Hall8f89dda2015-01-22 16:03:33 -08001152 actual=numClusters,
Jon Hall6aec96b2015-01-19 14:49:31 -08001153 onpass="ONOS shows 1 SCC",
Jon Hall58c76b72015-02-23 11:09:24 -08001154 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
Jon Hall94fd0472014-12-08 11:52:42 -08001155
Jon Hall6aec96b2015-01-19 14:49:31 -08001156 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001157 devicesResults = main.TRUE
1158 portsResults = main.TRUE
1159 linksResults = main.TRUE
1160 for controller in range( numControllers ):
1161 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001162 if devices[ controller ] or "Error" not in devices[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001163 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -08001164 MNTopo,
1165 json.loads(
1166 devices[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001167 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001168 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001169 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001170 actual=currentDevicesResult,
1171 onpass="ONOS" + controllerStr +
1172 " Switches view is correct",
1173 onfail="ONOS" + controllerStr +
1174 " Switches view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001175
Jon Hall6aec96b2015-01-19 14:49:31 -08001176 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001177 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -08001178 MNTopo,
1179 json.loads(
1180 ports[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001181 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001182 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001183 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001184 actual=currentPortsResult,
1185 onpass="ONOS" + controllerStr +
1186 " ports view is correct",
1187 onfail="ONOS" + controllerStr +
1188 " ports view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001189
Jon Hall6aec96b2015-01-19 14:49:31 -08001190 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001191 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -08001192 MNTopo,
1193 json.loads(
1194 links[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001195 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001196 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001197 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001198 actual=currentLinksResult,
1199 onpass="ONOS" + controllerStr +
1200 " links view is correct",
1201 onfail="ONOS" + controllerStr +
1202 " links view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001203
Jon Hall8f89dda2015-01-22 16:03:33 -08001204 devicesResults = devicesResults and currentDevicesResult
1205 portsResults = portsResults and currentPortsResult
1206 linksResults = linksResults and currentLinksResult
Jon Hall73cf9cc2014-11-20 22:28:38 -08001207
Jon Hall8f89dda2015-01-22 16:03:33 -08001208 topoResult = devicesResults and portsResults and linksResults\
Jon Hall58c76b72015-02-23 11:09:24 -08001209 and consistentHostsResult and consistentClustersResult\
1210 and clusterResults and ipResult
Jon Hall8f89dda2015-01-22 16:03:33 -08001211 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
Jon Hall58c76b72015-02-23 11:09:24 -08001212 onpass="Topology Check Test successful",
1213 onfail="Topology Check Test NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001214
Jon Hall8f89dda2015-01-22 16:03:33 -08001215 finalAssert = main.TRUE
1216 finalAssert = finalAssert and topoResult and flowCheck \
Jon Hall58c76b72015-02-23 11:09:24 -08001217 and intentCheck and consistentMastership and rolesNotNull
Jon Hall8f89dda2015-01-22 16:03:33 -08001218 utilities.assert_equals( expect=main.TRUE, actual=finalAssert,
Jon Hall58c76b72015-02-23 11:09:24 -08001219 onpass="State check successful",
1220 onfail="State check NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001221
Jon Hall6aec96b2015-01-19 14:49:31 -08001222 def CASE6( self, main ):
1223 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001224 The Failure case.
Jon Hall6aec96b2015-01-19 14:49:31 -08001225 """
1226 main.log.report( "Restart entire ONOS cluster" )
1227 main.log.case( "Restart entire ONOS cluster" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001228 main.ONOSbench.onosKill( ONOS1Ip )
1229 main.ONOSbench.onosKill( ONOS2Ip )
1230 main.ONOSbench.onosKill( ONOS3Ip )
1231 main.ONOSbench.onosKill( ONOS4Ip )
1232 main.ONOSbench.onosKill( ONOS5Ip )
1233 main.ONOSbench.onosKill( ONOS6Ip )
1234 main.ONOSbench.onosKill( ONOS7Ip )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001235
Jon Hall6aec96b2015-01-19 14:49:31 -08001236 main.step( "Checking if ONOS is up yet" )
Jon Hallffb386d2014-11-21 13:43:38 -08001237 count = 0
Jon Hall8f89dda2015-01-22 16:03:33 -08001238 onosIsupResult = main.FALSE
1239 while onosIsupResult == main.FALSE and count < 10:
1240 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
1241 onos2Isup = main.ONOSbench.isup( ONOS2Ip )
1242 onos3Isup = main.ONOSbench.isup( ONOS3Ip )
1243 onos4Isup = main.ONOSbench.isup( ONOS4Ip )
1244 onos5Isup = main.ONOSbench.isup( ONOS5Ip )
1245 onos6Isup = main.ONOSbench.isup( ONOS6Ip )
1246 onos7Isup = main.ONOSbench.isup( ONOS7Ip )
1247 onosIsupResult = onos1Isup and onos2Isup and onos3Isup\
1248 and onos4Isup and onos5Isup and onos6Isup and onos7Isup
Jon Hallffb386d2014-11-21 13:43:38 -08001249 count = count + 1
Jon Hall73cf9cc2014-11-20 22:28:38 -08001250 # TODO: if it becomes an issue, we can retry this step a few times
1251
Jon Hall8f89dda2015-01-22 16:03:33 -08001252 cliResult1 = main.ONOScli1.startOnosCli( ONOS1Ip )
1253 cliResult2 = main.ONOScli2.startOnosCli( ONOS2Ip )
1254 cliResult3 = main.ONOScli3.startOnosCli( ONOS3Ip )
1255 cliResult4 = main.ONOScli4.startOnosCli( ONOS4Ip )
1256 cliResult5 = main.ONOScli5.startOnosCli( ONOS5Ip )
1257 cliResult6 = main.ONOScli6.startOnosCli( ONOS6Ip )
1258 cliResult7 = main.ONOScli7.startOnosCli( ONOS7Ip )
1259 cliResults = cliResult1 and cliResult2 and cliResult3\
1260 and cliResult4 and cliResult5 and cliResult6\
1261 and cliResult7
Jon Hall73cf9cc2014-11-20 22:28:38 -08001262
Jon Hall8f89dda2015-01-22 16:03:33 -08001263 caseResults = main.TRUE and onosIsupResult and cliResults
1264 utilities.assert_equals( expect=main.TRUE, actual=caseResults,
Jon Hall58c76b72015-02-23 11:09:24 -08001265 onpass="ONOS restart successful",
1266 onfail="ONOS restart NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001267
Jon Hall6aec96b2015-01-19 14:49:31 -08001268 def CASE7( self, main ):
1269 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001270 Check state after ONOS failure
Jon Hall6aec96b2015-01-19 14:49:31 -08001271 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001272 import json
Jon Hall6aec96b2015-01-19 14:49:31 -08001273 main.case( "Running ONOS Constant State Tests" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001274
Jon Hall6aec96b2015-01-19 14:49:31 -08001275 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -08001276 ONOS1MasterNotNull = main.ONOScli1.rolesNotNull()
1277 ONOS2MasterNotNull = main.ONOScli2.rolesNotNull()
1278 ONOS3MasterNotNull = main.ONOScli3.rolesNotNull()
1279 ONOS4MasterNotNull = main.ONOScli4.rolesNotNull()
1280 ONOS5MasterNotNull = main.ONOScli5.rolesNotNull()
1281 ONOS6MasterNotNull = main.ONOScli6.rolesNotNull()
1282 ONOS7MasterNotNull = main.ONOScli7.rolesNotNull()
1283 rolesNotNull = ONOS1MasterNotNull and ONOS2MasterNotNull and\
1284 ONOS3MasterNotNull and ONOS4MasterNotNull and\
1285 ONOS5MasterNotNull and ONOS6MasterNotNull and\
1286 ONOS7MasterNotNull
Jon Hall6aec96b2015-01-19 14:49:31 -08001287 utilities.assert_equals(
1288 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001289 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -08001290 onpass="Each device has a master",
1291 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -08001292
Jon Hall6aec96b2015-01-19 14:49:31 -08001293 main.step( "Check if switch roles are consistent across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001294 ONOS1Mastership = main.ONOScli1.roles()
1295 ONOS2Mastership = main.ONOScli2.roles()
1296 ONOS3Mastership = main.ONOScli3.roles()
1297 ONOS4Mastership = main.ONOScli4.roles()
1298 ONOS5Mastership = main.ONOScli5.roles()
1299 ONOS6Mastership = main.ONOScli6.roles()
1300 ONOS7Mastership = main.ONOScli7.roles()
1301 if "Error" in ONOS1Mastership or not ONOS1Mastership\
1302 or "Error" in ONOS2Mastership or not ONOS2Mastership\
1303 or "Error" in ONOS3Mastership or not ONOS3Mastership\
1304 or "Error" in ONOS4Mastership or not ONOS4Mastership\
1305 or "Error" in ONOS5Mastership or not ONOS5Mastership\
1306 or "Error" in ONOS6Mastership or not ONOS6Mastership\
1307 or "Error" in ONOS7Mastership or not ONOS7Mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -08001308 main.log.error( "Error in getting ONOS mastership" )
1309 main.log.warn( "ONOS1 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001310 repr( ONOS1Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001311 main.log.warn( "ONOS2 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001312 repr( ONOS2Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001313 main.log.warn( "ONOS3 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001314 repr( ONOS3Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001315 main.log.warn( "ONOS4 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001316 repr( ONOS4Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001317 main.log.warn( "ONOS5 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001318 repr( ONOS5Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001319 main.log.warn( "ONOS6 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001320 repr( ONOS6Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001321 main.log.warn( "ONOS7 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001322 repr( ONOS7Mastership ) )
1323 consistentMastership = main.FALSE
1324 elif ONOS1Mastership == ONOS2Mastership\
1325 and ONOS1Mastership == ONOS3Mastership\
1326 and ONOS1Mastership == ONOS4Mastership\
1327 and ONOS1Mastership == ONOS5Mastership\
1328 and ONOS1Mastership == ONOS6Mastership\
1329 and ONOS1Mastership == ONOS7Mastership:
1330 consistentMastership = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001331 main.log.report(
1332 "Switch roles are consistent across all ONOS nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001333 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001334 main.log.warn( "ONOS1 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001335 json.loads( ONOS1Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001336 separators=( ',', ': ' ) ) )
1337 main.log.warn( "ONOS2 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001338 json.loads( ONOS2Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001339 separators=( ',', ': ' ) ) )
1340 main.log.warn( "ONOS3 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001341 json.loads( ONOS3Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001342 separators=( ',', ': ' ) ) )
1343 main.log.warn( "ONOS4 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001344 json.loads( ONOS4Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001345 separators=( ',', ': ' ) ) )
1346 main.log.warn( "ONOS5 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001347 json.loads( ONOS5Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001348 separators=( ',', ': ' ) ) )
1349 main.log.warn( "ONOS6 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001350 json.loads( ONOS6Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001351 separators=( ',', ': ' ) ) )
1352 main.log.warn( "ONOS7 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001353 json.loads( ONOS7Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001354 separators=( ',', ': ' ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001355 consistentMastership = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001356 utilities.assert_equals(
1357 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001358 actual=consistentMastership,
Jon Hall6aec96b2015-01-19 14:49:31 -08001359 onpass="Switch roles are consistent across all ONOS nodes",
1360 onfail="ONOS nodes have different views of switch roles" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001361
1362 description2 = "Compare switch roles from before failure"
Jon Hall6aec96b2015-01-19 14:49:31 -08001363 main.step( description2 )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001364
Jon Hall8f89dda2015-01-22 16:03:33 -08001365 currentJson = json.loads( ONOS1Mastership )
1366 oldJson = json.loads( mastershipState )
1367 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001368 for i in range( 1, 29 ):
1369 switchDPID = str(
1370 main.Mininet1.getSwitchDPID(
1371 switch="s" +
1372 str( i ) ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001373
Jon Hall8f89dda2015-01-22 16:03:33 -08001374 current = [ switch[ 'master' ] for switch in currentJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001375 if switchDPID in switch[ 'id' ] ]
Jon Hall8f89dda2015-01-22 16:03:33 -08001376 old = [ switch[ 'master' ] for switch in oldJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001377 if switchDPID in switch[ 'id' ] ]
Jon Hall73cf9cc2014-11-20 22:28:38 -08001378 if current == old:
Jon Hall8f89dda2015-01-22 16:03:33 -08001379 mastershipCheck = mastershipCheck and main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001380 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001381 main.log.warn( "Mastership of switch %s changed" % switchDPID )
Jon Hall8f89dda2015-01-22 16:03:33 -08001382 mastershipCheck = main.FALSE
1383 if mastershipCheck == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001384 main.log.report( "Mastership of Switches was not changed" )
1385 utilities.assert_equals(
1386 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001387 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -08001388 onpass="Mastership of Switches was not changed",
1389 onfail="Mastership of some switches changed" )
1390 # NOTE: we expect mastership to change on controller failure
Jon Hall8f89dda2015-01-22 16:03:33 -08001391 mastershipCheck = mastershipCheck and consistentMastership
Jon Hall73cf9cc2014-11-20 22:28:38 -08001392
Jon Hall6aec96b2015-01-19 14:49:31 -08001393 main.step( "Get the intents and compare across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001394 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
1395 ONOS2Intents = main.ONOScli2.intents( jsonFormat=True )
1396 ONOS3Intents = main.ONOScli3.intents( jsonFormat=True )
1397 ONOS4Intents = main.ONOScli4.intents( jsonFormat=True )
1398 ONOS5Intents = main.ONOScli5.intents( jsonFormat=True )
1399 ONOS6Intents = main.ONOScli6.intents( jsonFormat=True )
1400 ONOS7Intents = main.ONOScli7.intents( jsonFormat=True )
1401 intentCheck = main.FALSE
1402 if "Error" in ONOS1Intents or not ONOS1Intents\
1403 or "Error" in ONOS2Intents or not ONOS2Intents\
1404 or "Error" in ONOS3Intents or not ONOS3Intents\
1405 or "Error" in ONOS4Intents or not ONOS4Intents\
1406 or "Error" in ONOS5Intents or not ONOS5Intents\
1407 or "Error" in ONOS6Intents or not ONOS6Intents\
1408 or "Error" in ONOS7Intents or not ONOS7Intents:
Jon Hall6aec96b2015-01-19 14:49:31 -08001409 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001410 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
1411 main.log.warn( "ONOS2 intents response: " + repr( ONOS2Intents ) )
1412 main.log.warn( "ONOS3 intents response: " + repr( ONOS3Intents ) )
1413 main.log.warn( "ONOS4 intents response: " + repr( ONOS4Intents ) )
1414 main.log.warn( "ONOS5 intents response: " + repr( ONOS5Intents ) )
1415 main.log.warn( "ONOS6 intents response: " + repr( ONOS6Intents ) )
1416 main.log.warn( "ONOS7 intents response: " + repr( ONOS7Intents ) )
1417 elif ONOS1Intents == ONOS2Intents\
1418 and ONOS1Intents == ONOS3Intents\
1419 and ONOS1Intents == ONOS4Intents\
1420 and ONOS1Intents == ONOS5Intents\
1421 and ONOS1Intents == ONOS6Intents\
1422 and ONOS1Intents == ONOS7Intents:
1423 intentCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001424 main.log.report( "Intents are consistent across all ONOS nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001425 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001426 main.log.warn( "ONOS1 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001427 print json.dumps( json.loads( ONOS1Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001428 indent=4, separators=( ',', ': ' ) )
1429 main.log.warn( "ONOS2 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001430 print json.dumps( json.loads( ONOS2Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001431 indent=4, separators=( ',', ': ' ) )
1432 main.log.warn( "ONOS3 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001433 print json.dumps( json.loads( ONOS3Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001434 indent=4, separators=( ',', ': ' ) )
1435 main.log.warn( "ONOS4 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001436 print json.dumps( json.loads( ONOS4Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001437 indent=4, separators=( ',', ': ' ) )
1438 main.log.warn( "ONOS5 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001439 print json.dumps( json.loads( ONOS5Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001440 indent=4, separators=( ',', ': ' ) )
1441 main.log.warn( "ONOS6 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001442 print json.dumps( json.loads( ONOS6Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001443 indent=4, separators=( ',', ': ' ) )
1444 main.log.warn( "ONOS7 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001445 print json.dumps( json.loads( ONOS7Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001446 indent=4, separators=( ',', ': ' ) )
1447 utilities.assert_equals(
1448 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001449 actual=intentCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -08001450 onpass="Intents are consistent across all ONOS nodes",
1451 onfail="ONOS nodes have different views of intents" )
Jon Hall1b8f54a2015-02-04 13:24:20 -08001452 # Print the intent states
1453 intents = []
1454 intents.append( ONOS1Intents )
1455 intents.append( ONOS2Intents )
1456 intents.append( ONOS3Intents )
1457 intents.append( ONOS4Intents )
1458 intents.append( ONOS5Intents )
1459 intents.append( ONOS6Intents )
1460 intents.append( ONOS7Intents )
1461 intentStates = []
1462 for node in intents: # Iter through ONOS nodes
1463 nodeStates = []
Jon Hall58c76b72015-02-23 11:09:24 -08001464 # Iter through intents of a node
1465 for intent in json.loads( node ):
Jon Hall1b8f54a2015-02-04 13:24:20 -08001466 nodeStates.append( intent[ 'state' ] )
1467 intentStates.append( nodeStates )
1468 out = [ (i, nodeStates.count( i ) ) for i in set( nodeStates ) ]
1469 main.log.info( dict( out ) )
1470
Jon Hall58c76b72015-02-23 11:09:24 -08001471 # NOTE: Store has no durability, so intents are lost across system
1472 # restarts
Jon Hall6aec96b2015-01-19 14:49:31 -08001473 """
1474 main.step( "Compare current intents with intents before the failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001475 # NOTE: this requires case 5 to pass for intentState to be set.
Jon Hall94fd0472014-12-08 11:52:42 -08001476 # maybe we should stop the test if that fails?
Jon Hall1b8f54a2015-02-04 13:24:20 -08001477 sameIntents = main.TRUE
1478 if intentState and intentState == ONOS1Intents:
Jon Hall8f89dda2015-01-22 16:03:33 -08001479 sameIntents = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001480 main.log.report( "Intents are consistent with before failure" )
1481 # TODO: possibly the states have changed? we may need to figure out
1482 # what the aceptable states are
Jon Hall73cf9cc2014-11-20 22:28:38 -08001483 else:
Jon Hall669173b2014-12-17 11:36:30 -08001484 try:
Jon Hall6aec96b2015-01-19 14:49:31 -08001485 main.log.warn( "ONOS1 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001486 print json.dumps( json.loads( ONOS1Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -08001487 sort_keys=True, indent=4,
1488 separators=( ',', ': ' ) )
Jon Hall669173b2014-12-17 11:36:30 -08001489 except:
1490 pass
Jon Hall8f89dda2015-01-22 16:03:33 -08001491 sameIntents = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001492 utilities.assert_equals(
1493 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001494 actual=sameIntents,
Jon Hall6aec96b2015-01-19 14:49:31 -08001495 onpass="Intents are consistent with before failure",
1496 onfail="The Intents changed during failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001497 intentCheck = intentCheck and sameIntents
Jon Hall6aec96b2015-01-19 14:49:31 -08001498 """
1499 main.step( "Get the OF Table entries and compare to before " +
1500 "component failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001501 FlowTables = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001502 flows2 = []
1503 for i in range( 28 ):
1504 main.log.info( "Checking flow table on s" + str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001505 tmpFlows = main.Mininet2.getFlowTable( 1.3, "s" + str( i + 1 ) )
1506 flows2.append( tmpFlows )
1507 tempResult = main.Mininet2.flowComp(
Jon Hall6aec96b2015-01-19 14:49:31 -08001508 flow1=flows[ i ],
Jon Hall8f89dda2015-01-22 16:03:33 -08001509 flow2=tmpFlows )
1510 FlowTables = FlowTables and tempResult
1511 if FlowTables == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001512 main.log.info( "Differences in flow table for switch: s" +
1513 str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001514 if FlowTables == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001515 main.log.report( "No changes were found in the flow tables" )
1516 utilities.assert_equals(
1517 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001518 actual=FlowTables,
Jon Hall6aec96b2015-01-19 14:49:31 -08001519 onpass="No changes were found in the flow tables",
1520 onfail="Changes were found in the flow tables" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001521
Jon Hall6aec96b2015-01-19 14:49:31 -08001522 main.step( "Check the continuous pings to ensure that no packets " +
1523 "were dropped during component failure" )
1524 # FIXME: This check is always failing. Investigate cause
1525 # NOTE: this may be something to do with file permsissions
Jon Hall73cf9cc2014-11-20 22:28:38 -08001526 # or slight change in format
Jon Hall6aec96b2015-01-19 14:49:31 -08001527 main.Mininet2.pingKill(
1528 main.params[ 'TESTONUSER' ],
1529 main.params[ 'TESTONIP' ] )
Jon Hall8f89dda2015-01-22 16:03:33 -08001530 LossInPings = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001531 # NOTE: checkForLoss returns main.FALSE with 0% packet loss
1532 for i in range( 8, 18 ):
1533 main.log.info(
1534 "Checking for a loss in pings along flow from s" +
1535 str( i ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001536 LossInPings = main.Mininet2.checkForLoss(
Jon Hall6aec96b2015-01-19 14:49:31 -08001537 "/tmp/ping.h" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001538 str( i ) ) or LossInPings
1539 if LossInPings == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001540 main.log.info( "Loss in ping detected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001541 elif LossInPings == main.ERROR:
Jon Hall6aec96b2015-01-19 14:49:31 -08001542 main.log.info( "There are multiple mininet process running" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001543 elif LossInPings == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001544 main.log.info( "No Loss in the pings" )
1545 main.log.report( "No loss of dataplane connectivity" )
1546 utilities.assert_equals(
1547 expect=main.FALSE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001548 actual=LossInPings,
Jon Hall6aec96b2015-01-19 14:49:31 -08001549 onpass="No Loss of connectivity",
1550 onfail="Loss of dataplane connectivity detected" )
Jon Hall58c76b72015-02-23 11:09:24 -08001551 # NOTE: Since intents are not persisted with IntnentStore,
1552 # we expect loss in dataplane connectivity
Jon Hall8f89dda2015-01-22 16:03:33 -08001553 LossInPings = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001554
Jon Hall6aec96b2015-01-19 14:49:31 -08001555 # Test of LeadershipElection
Jon Hall8f89dda2015-01-22 16:03:33 -08001556 leaderList = []
1557 leaderResult = main.TRUE
1558 for controller in range( 1, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001559 # loop through ONOScli handlers
1560 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001561 leaderN = node.electionTestLeader()
1562 leaderList.append( leaderN )
Jon Hall669173b2014-12-17 11:36:30 -08001563 if leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001564 # error in response
1565 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001566 "electionTestLeader function, check the" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001567 " error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001568 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001569 elif leaderN is None:
1570 main.log.report( "ONOS" + str( controller ) +
1571 " shows no leader for the election-app was" +
1572 " elected after the old one died" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001573 leaderResult = main.FALSE
1574 if len( set( leaderList ) ) != 1:
1575 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001576 main.log.error(
1577 "Inconsistent view of leader for the election test app" )
1578 # TODO: print the list
Jon Hall8f89dda2015-01-22 16:03:33 -08001579 if leaderResult:
1580 main.log.report( "Leadership election tests passed( consistent " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001581 "view of leader across listeners and a new " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001582 "leader was re-elected if applicable )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001583 utilities.assert_equals(
1584 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001585 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001586 onpass="Leadership election passed",
1587 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08001588
Jon Hall8f89dda2015-01-22 16:03:33 -08001589 result = ( mastershipCheck and intentCheck and FlowTables and
1590 ( not LossInPings ) and rolesNotNull and leaderResult )
Jon Hall6aec96b2015-01-19 14:49:31 -08001591 result = int( result )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001592 if result == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001593 main.log.report( "Constant State Tests Passed" )
1594 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall58c76b72015-02-23 11:09:24 -08001595 onpass="Constant State Tests Passed",
1596 onfail="Constant state tests failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001597
Jon Hall6aec96b2015-01-19 14:49:31 -08001598 def CASE8( self, main ):
1599 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001600 Compare topo
Jon Hall6aec96b2015-01-19 14:49:31 -08001601 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001602 import sys
Jon Hall6aec96b2015-01-19 14:49:31 -08001603 # FIXME add this path to params
1604 sys.path.append( "/home/admin/sts" )
1605 # assumes that sts is already in you PYTHONPATH
1606 from sts.topology.teston_topology import TestONTopology
Jon Hall73cf9cc2014-11-20 22:28:38 -08001607 import json
1608 import time
1609
Jon Hall6aec96b2015-01-19 14:49:31 -08001610 description = "Compare ONOS Topology view to Mininet topology"
1611 main.case( description )
1612 main.log.report( description )
1613 main.step( "Create TestONTopology object" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001614 ctrls = []
1615 count = 1
1616 while True:
1617 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -08001618 if ( 'ip' + str( count ) ) in main.params[ 'CTRL' ]:
1619 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
1620 temp = temp + ( "ONOS" + str( count ), )
1621 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
1622 temp = temp + \
1623 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
1624 ctrls.append( temp )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001625 count = count + 1
1626 else:
1627 break
Jon Hall6aec96b2015-01-19 14:49:31 -08001628 MNTopo = TestONTopology(
1629 main.Mininet1,
1630 ctrls ) # can also add Intent API info for intent operations
Jon Hall73cf9cc2014-11-20 22:28:38 -08001631
Jon Hall6aec96b2015-01-19 14:49:31 -08001632 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001633 devicesResults = main.TRUE
1634 portsResults = main.TRUE
1635 linksResults = main.TRUE
Jon Hall58c76b72015-02-23 11:09:24 -08001636 hostsResults = main.TRUE
Jon Hall8f89dda2015-01-22 16:03:33 -08001637 topoResult = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001638 elapsed = 0
Jon Hallffb386d2014-11-21 13:43:38 -08001639 count = 0
Jon Hall6aec96b2015-01-19 14:49:31 -08001640 main.step( "Collecting topology information from ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001641 startTime = time.time()
Jon Hall21270ac2015-02-16 17:59:55 -08001642 # Give time for Gossip to work
Jon Hall8f89dda2015-01-22 16:03:33 -08001643 while topoResult == main.FALSE and elapsed < 60:
Jon Hallffb386d2014-11-21 13:43:38 -08001644 count = count + 1
Jon Hall94fd0472014-12-08 11:52:42 -08001645 if count > 1:
Jon Hall6aec96b2015-01-19 14:49:31 -08001646 # TODO: Depricate STS usage
Jon Hall58c76b72015-02-23 11:09:24 -08001647 MNTopo = TestONTopology( main.Mininet1, ctrls )
Jon Hall8f89dda2015-01-22 16:03:33 -08001648 cliStart = time.time()
Jon Hall94fd0472014-12-08 11:52:42 -08001649 devices = []
1650 devices.append( main.ONOScli1.devices() )
1651 devices.append( main.ONOScli2.devices() )
1652 devices.append( main.ONOScli3.devices() )
1653 devices.append( main.ONOScli4.devices() )
1654 devices.append( main.ONOScli5.devices() )
1655 devices.append( main.ONOScli6.devices() )
1656 devices.append( main.ONOScli7.devices() )
1657 hosts = []
Jon Hall529a37f2015-01-28 10:02:00 -08001658 hosts.append( json.loads( main.ONOScli1.hosts() ) )
1659 hosts.append( json.loads( main.ONOScli2.hosts() ) )
1660 hosts.append( json.loads( main.ONOScli3.hosts() ) )
1661 hosts.append( json.loads( main.ONOScli4.hosts() ) )
1662 hosts.append( json.loads( main.ONOScli5.hosts() ) )
1663 hosts.append( json.loads( main.ONOScli6.hosts() ) )
1664 hosts.append( json.loads( main.ONOScli7.hosts() ) )
Jon Hall58c76b72015-02-23 11:09:24 -08001665 ipResult = main.TRUE
Jon Hall529a37f2015-01-28 10:02:00 -08001666 for controller in range( 0, len( hosts ) ):
1667 controllerStr = str( controller + 1 )
1668 for host in hosts[ controller ]:
Jon Hall58c76b72015-02-23 11:09:24 -08001669 if host is None or host.get( 'ips', [] ) == []:
Jon Hall529a37f2015-01-28 10:02:00 -08001670 main.log.error(
1671 "DEBUG:Error with host ips on controller" +
1672 controllerStr + ": " + str( host ) )
Jon Hall58c76b72015-02-23 11:09:24 -08001673 ipResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001674 ports = []
1675 ports.append( main.ONOScli1.ports() )
1676 ports.append( main.ONOScli2.ports() )
1677 ports.append( main.ONOScli3.ports() )
1678 ports.append( main.ONOScli4.ports() )
1679 ports.append( main.ONOScli5.ports() )
1680 ports.append( main.ONOScli6.ports() )
1681 ports.append( main.ONOScli7.ports() )
1682 links = []
1683 links.append( main.ONOScli1.links() )
1684 links.append( main.ONOScli2.links() )
1685 links.append( main.ONOScli3.links() )
1686 links.append( main.ONOScli4.links() )
1687 links.append( main.ONOScli5.links() )
1688 links.append( main.ONOScli6.links() )
1689 links.append( main.ONOScli7.links() )
1690 clusters = []
1691 clusters.append( main.ONOScli1.clusters() )
1692 clusters.append( main.ONOScli2.clusters() )
1693 clusters.append( main.ONOScli3.clusters() )
1694 clusters.append( main.ONOScli4.clusters() )
1695 clusters.append( main.ONOScli5.clusters() )
1696 clusters.append( main.ONOScli6.clusters() )
1697 clusters.append( main.ONOScli7.clusters() )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001698
Jon Hall8f89dda2015-01-22 16:03:33 -08001699 elapsed = time.time() - startTime
1700 cliTime = time.time() - cliStart
1701 print "CLI time: " + str( cliTime )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001702
Jon Hall8f89dda2015-01-22 16:03:33 -08001703 for controller in range( numControllers ):
1704 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001705 if devices[ controller ] or "Error" not in devices[
1706 controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001707 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -08001708 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001709 json.loads( devices[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001710 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001711 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001712 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001713 actual=currentDevicesResult,
1714 onpass="ONOS" + controllerStr +
1715 " Switches view is correct",
1716 onfail="ONOS" + controllerStr +
1717 " Switches view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001718
Jon Hall6aec96b2015-01-19 14:49:31 -08001719 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001720 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -08001721 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001722 json.loads( ports[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001723 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001724 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001725 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001726 actual=currentPortsResult,
1727 onpass="ONOS" + controllerStr +
1728 " ports view is correct",
1729 onfail="ONOS" + controllerStr +
1730 " ports view is incorrect" )
Jon Hall94fd0472014-12-08 11:52:42 -08001731
Jon Hall6aec96b2015-01-19 14:49:31 -08001732 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001733 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -08001734 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001735 json.loads( links[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001736 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001737 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001738 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001739 actual=currentLinksResult,
1740 onpass="ONOS" + controllerStr +
1741 " links view is correct",
1742 onfail="ONOS" + controllerStr +
1743 " links view is incorrect" )
1744
1745 if hosts[ controller ] or "Error" not in hosts[ controller ]:
1746 currentHostsResult = main.Mininet1.compareHosts(
1747 MNTopo, hosts[ controller ] )
1748 else:
1749 currentHostsResult = main.FALSE
1750 utilities.assert_equals( expect=main.TRUE,
1751 actual=currentHostsResult,
1752 onpass="ONOS" + controllerStr +
1753 " hosts exist in Mininet",
1754 onfail="ONOS" + controllerStr +
1755 " hosts don't match Mininet" )
1756
1757 devicesResults = devicesResults and currentDevicesResult
1758 portsResults = portsResults and currentPortsResult
1759 linksResults = linksResults and currentLinksResult
1760 hostsResults = hostsResults and currentHostsResult
Jon Hall94fd0472014-12-08 11:52:42 -08001761
Jon Hall529a37f2015-01-28 10:02:00 -08001762 # Compare json objects for hosts and dataplane clusters
Jon Hall94fd0472014-12-08 11:52:42 -08001763
Jon Hall6aec96b2015-01-19 14:49:31 -08001764 # hosts
Jon Hall8f89dda2015-01-22 16:03:33 -08001765 consistentHostsResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -08001766 for controller in range( len( hosts ) ):
Jon Hall8f89dda2015-01-22 16:03:33 -08001767 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001768 if "Error" not in hosts[ controller ]:
1769 if hosts[ controller ] == hosts[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001770 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001771 else: # hosts not consistent
Jon Hall8f89dda2015-01-22 16:03:33 -08001772 main.log.report( "hosts from ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001773 " is inconsistent with ONOS1" )
1774 main.log.warn( repr( hosts[ controller ] ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001775 consistentHostsResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001776
1777 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001778 main.log.report( "Error in getting ONOS hosts from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001779 controllerStr )
1780 consistentHostsResult = main.FALSE
1781 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001782 " hosts response: " +
1783 repr( hosts[ controller ] ) )
1784 utilities.assert_equals(
1785 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001786 actual=consistentHostsResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001787 onpass="Hosts view is consistent across all ONOS nodes",
1788 onfail="ONOS nodes have different views of hosts" )
Jon Hall94fd0472014-12-08 11:52:42 -08001789
Jon Hall6aec96b2015-01-19 14:49:31 -08001790 # Strongly connected clusters of devices
Jon Hall8f89dda2015-01-22 16:03:33 -08001791 consistentClustersResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -08001792 for controller in range( len( clusters ) ):
Jon Hall8f89dda2015-01-22 16:03:33 -08001793 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001794 if "Error" not in clusters[ controller ]:
1795 if clusters[ controller ] == clusters[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001796 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001797 else: # clusters not consistent
1798 main.log.report( "clusters from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001799 controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001800 " is inconsistent with ONOS1" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001801 consistentClustersResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001802
1803 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001804 main.log.report( "Error in getting dataplane clusters " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001805 "from ONOS" + controllerStr )
1806 consistentClustersResult = main.FALSE
1807 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001808 " clusters response: " +
1809 repr( clusters[ controller ] ) )
1810 utilities.assert_equals(
1811 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001812 actual=consistentClustersResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001813 onpass="Clusters view is consistent across all ONOS nodes",
1814 onfail="ONOS nodes have different views of clusters" )
1815 # there should always only be one cluster
Jon Hall8f89dda2015-01-22 16:03:33 -08001816 numClusters = len( json.loads( clusters[ 0 ] ) )
Jon Hall58c76b72015-02-23 11:09:24 -08001817 clusterResults = main.FALSE
1818 if numClusters == 1:
1819 clusterResults = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001820 utilities.assert_equals(
1821 expect=1,
Jon Hall8f89dda2015-01-22 16:03:33 -08001822 actual=numClusters,
Jon Hall6aec96b2015-01-19 14:49:31 -08001823 onpass="ONOS shows 1 SCC",
Jon Hall58c76b72015-02-23 11:09:24 -08001824 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
Jon Hall94fd0472014-12-08 11:52:42 -08001825
Jon Hall8f89dda2015-01-22 16:03:33 -08001826 topoResult = ( devicesResults and portsResults and linksResults
Jon Hall58c76b72015-02-23 11:09:24 -08001827 and hostsResults and consistentHostsResult
1828 and consistentClustersResult and clusterResults
1829 and ipResult )
Jon Hall94fd0472014-12-08 11:52:42 -08001830
Jon Hall8f89dda2015-01-22 16:03:33 -08001831 topoResult = topoResult and int( count <= 2 )
1832 note = "note it takes about " + str( int( cliTime ) ) + \
1833 " seconds for the test to make all the cli calls to fetch " +\
1834 "the topology from each ONOS instance"
Jon Hall1b8f54a2015-02-04 13:24:20 -08001835 main.log.info(
Jon Hall8f89dda2015-01-22 16:03:33 -08001836 "Very crass estimate for topology discovery/convergence( " +
1837 str( note ) + " ): " + str( elapsed ) + " seconds, " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001838 str( count ) + " tries" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001839 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
Jon Hall58c76b72015-02-23 11:09:24 -08001840 onpass="Topology Check Test successful",
1841 onfail="Topology Check Test NOT successful" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001842 if topoResult == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001843 main.log.report( "ONOS topology view matches Mininet topology" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001844
Jon Hall6aec96b2015-01-19 14:49:31 -08001845 def CASE9( self, main ):
1846 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001847 Link s3-s28 down
Jon Hall6aec96b2015-01-19 14:49:31 -08001848 """
1849 import time
1850 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001851
Jon Hall8f89dda2015-01-22 16:03:33 -08001852 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001853
Jon Hall6aec96b2015-01-19 14:49:31 -08001854 description = "Turn off a link to ensure that Link Discovery " +\
Jon Hall58c76b72015-02-23 11:09:24 -08001855 "is working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001856 main.log.report( description )
1857 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001858
Jon Hall6aec96b2015-01-19 14:49:31 -08001859 main.step( "Kill Link between s3 and s28" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001860 LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" )
Jon Hall58c76b72015-02-23 11:09:24 -08001861 main.log.info( "Waiting " + str( linkSleep ) +
1862 " seconds for link down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001863 time.sleep( linkSleep )
1864 utilities.assert_equals( expect=main.TRUE, actual=LinkDown,
Jon Hall58c76b72015-02-23 11:09:24 -08001865 onpass="Link down succesful",
1866 onfail="Failed to bring link down" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001867 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -08001868
Jon Hall6aec96b2015-01-19 14:49:31 -08001869 def CASE10( self, main ):
1870 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001871 Link s3-s28 up
Jon Hall6aec96b2015-01-19 14:49:31 -08001872 """
1873 import time
1874 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001875
Jon Hall8f89dda2015-01-22 16:03:33 -08001876 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001877
Jon Hall6aec96b2015-01-19 14:49:31 -08001878 description = "Restore a link to ensure that Link Discovery is " + \
Jon Hall8f89dda2015-01-22 16:03:33 -08001879 "working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001880 main.log.report( description )
1881 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001882
Jon Hall6aec96b2015-01-19 14:49:31 -08001883 main.step( "Bring link between s3 and s28 back up" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001884 LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" )
Jon Hall58c76b72015-02-23 11:09:24 -08001885 main.log.info( "Waiting " + str( linkSleep ) +
1886 " seconds for link up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001887 time.sleep( linkSleep )
1888 utilities.assert_equals( expect=main.TRUE, actual=LinkUp,
Jon Hall58c76b72015-02-23 11:09:24 -08001889 onpass="Link up succesful",
1890 onfail="Failed to bring link up" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001891 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -08001892
Jon Hall6aec96b2015-01-19 14:49:31 -08001893 def CASE11( self, main ):
1894 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001895 Switch Down
Jon Hall6aec96b2015-01-19 14:49:31 -08001896 """
1897 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001898 import time
1899
Jon Hall8f89dda2015-01-22 16:03:33 -08001900 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001901
1902 description = "Killing a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001903 main.log.report( description )
1904 main.case( description )
1905 switch = main.params[ 'kill' ][ 'switch' ]
1906 switchDPID = main.params[ 'kill' ][ 'dpid' ]
Jon Hall73cf9cc2014-11-20 22:28:38 -08001907
Jon Hall6aec96b2015-01-19 14:49:31 -08001908 # TODO: Make this switch parameterizable
1909 main.step( "Kill " + switch )
1910 main.log.report( "Deleting " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001911 main.Mininet1.delSwitch( switch )
1912 main.log.info( "Waiting " + str( switchSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001913 " seconds for switch down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001914 time.sleep( switchSleep )
1915 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001916 # Peek at the deleted switch
1917 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001918 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001919 if device and device[ 'available' ] is False:
Jon Hall94fd0472014-12-08 11:52:42 -08001920 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001921 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall58c76b72015-02-23 11:09:24 -08001922 onpass="Kill switch succesful",
1923 onfail="Failed to kill switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001924
Jon Hall6aec96b2015-01-19 14:49:31 -08001925 def CASE12( self, main ):
1926 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001927 Switch Up
Jon Hall6aec96b2015-01-19 14:49:31 -08001928 """
1929 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001930 import time
Jon Hall669173b2014-12-17 11:36:30 -08001931
Jon Hall8f89dda2015-01-22 16:03:33 -08001932 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall6aec96b2015-01-19 14:49:31 -08001933 switch = main.params[ 'kill' ][ 'switch' ]
1934 switchDPID = main.params[ 'kill' ][ 'dpid' ]
1935 links = main.params[ 'kill' ][ 'links' ].split()
Jon Hall73cf9cc2014-11-20 22:28:38 -08001936 description = "Adding a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001937 main.log.report( description )
1938 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001939
Jon Hall6aec96b2015-01-19 14:49:31 -08001940 main.step( "Add back " + switch )
1941 main.log.report( "Adding back " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001942 main.Mininet1.addSwitch( switch, dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001943 # TODO: New dpid or same? Ask Thomas?
1944 for peer in links:
Jon Hall8f89dda2015-01-22 16:03:33 -08001945 main.Mininet1.addLink( switch, peer )
Jon Hall58c76b72015-02-23 11:09:24 -08001946 main.Mininet1.assignSwController( sw=switch.split( 's' )[ 1 ],
1947 count=numControllers,
1948 ip1=ONOS1Ip,
1949 port1=ONOS1Port,
1950 ip2=ONOS2Ip,
1951 port2=ONOS2Port,
1952 ip3=ONOS3Ip,
1953 port3=ONOS3Port,
1954 ip4=ONOS4Ip,
1955 port4=ONOS4Port,
1956 ip5=ONOS5Ip,
1957 port5=ONOS5Port,
1958 ip6=ONOS6Ip,
1959 port6=ONOS6Port,
1960 ip7=ONOS7Ip,
1961 port7=ONOS7Port )
1962 main.log.info( "Waiting " + str( switchSleep ) +
1963 " seconds for switch up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001964 time.sleep( switchSleep )
1965 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001966 # Peek at the deleted switch
1967 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001968 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001969 if device and device[ 'available' ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001970 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001971 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall58c76b72015-02-23 11:09:24 -08001972 onpass="add switch succesful",
1973 onfail="Failed to add switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001974
Jon Hall6aec96b2015-01-19 14:49:31 -08001975 def CASE13( self, main ):
1976 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001977 Clean up
Jon Hall6aec96b2015-01-19 14:49:31 -08001978 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001979 import os
1980 import time
Jon Hall6aec96b2015-01-19 14:49:31 -08001981 # TODO: make use of this elsewhere
1982 ips = []
Jon Hall8f89dda2015-01-22 16:03:33 -08001983 ips.append( ONOS1Ip )
1984 ips.append( ONOS2Ip )
1985 ips.append( ONOS3Ip )
1986 ips.append( ONOS4Ip )
1987 ips.append( ONOS5Ip )
1988 ips.append( ONOS6Ip )
1989 ips.append( ONOS7Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -08001990
1991 # printing colors to terminal
Jon Hall669173b2014-12-17 11:36:30 -08001992 colors = {}
Jon Hall6aec96b2015-01-19 14:49:31 -08001993 colors[ 'cyan' ] = '\033[96m'
1994 colors[ 'purple' ] = '\033[95m'
1995 colors[ 'blue' ] = '\033[94m'
1996 colors[ 'green' ] = '\033[92m'
1997 colors[ 'yellow' ] = '\033[93m'
1998 colors[ 'red' ] = '\033[91m'
1999 colors[ 'end' ] = '\033[0m'
Jon Hall73cf9cc2014-11-20 22:28:38 -08002000 description = "Test Cleanup"
Jon Hall6aec96b2015-01-19 14:49:31 -08002001 main.log.report( description )
2002 main.case( description )
2003 main.step( "Killing tcpdumps" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002004 main.Mininet2.stopTcpdump()
Jon Hall73cf9cc2014-11-20 22:28:38 -08002005
Jon Hall6aec96b2015-01-19 14:49:31 -08002006 main.step( "Checking ONOS Logs for errors" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002007 for i in range( 7 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08002008 print colors[ 'purple' ] + "Checking logs for errors on " + \
Jon Hall8f89dda2015-01-22 16:03:33 -08002009 "ONOS" + str( i + 1 ) + ":" + colors[ 'end' ]
2010 print main.ONOSbench.checkLogs( ips[ i ] )
Jon Hall94fd0472014-12-08 11:52:42 -08002011
Jon Hall6aec96b2015-01-19 14:49:31 -08002012 main.step( "Copying MN pcap and ONOS log files to test station" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08002013 testname = main.TEST
Jon Hall8f89dda2015-01-22 16:03:33 -08002014 teststationUser = main.params[ 'TESTONUSER' ]
2015 teststationIP = main.params[ 'TESTONIP' ]
Jon Hall6aec96b2015-01-19 14:49:31 -08002016 # NOTE: MN Pcap file is being saved to ~/packet_captures
Jon Hall73cf9cc2014-11-20 22:28:38 -08002017 # scp this file as MN and TestON aren't necessarily the same vm
Jon Hall6aec96b2015-01-19 14:49:31 -08002018 # FIXME: scp
2019 # mn files
2020 # TODO: Load these from params
2021 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08002022 logFolder = "/opt/onos/log/"
2023 logFiles = [ "karaf.log", "karaf.log.1" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08002024 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08002025 dstDir = "~/packet_captures/"
2026 for f in logFiles:
2027 for i in range( 7 ):
2028 main.ONOSbench.handle.sendline( "scp sdn@" + ips[ i ] + ":" +
2029 logFolder + f + " " +
2030 teststationUser + "@" +
2031 teststationIP + ":" +
2032 dstDir + str( testname ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08002033 "-ONOS" + str( i + 1 ) + "-" +
2034 f )
Jon Hall58c76b72015-02-23 11:09:24 -08002035 main.ONOSbench.handle.expect( "\$" )
2036
Jon Hall6aec96b2015-01-19 14:49:31 -08002037 # std*.log's
2038 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08002039 logFolder = "/opt/onos/var/"
2040 logFiles = [ "stderr.log", "stdout.log" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08002041 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08002042 dstDir = "~/packet_captures/"
2043 for f in logFiles:
2044 for i in range( 7 ):
2045 main.ONOSbench.handle.sendline( "scp sdn@" + ips[ i ] + ":" +
2046 logFolder + f + " " +
2047 teststationUser + "@" +
2048 teststationIP + ":" +
2049 dstDir + str( testname ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08002050 "-ONOS" + str( i + 1 ) + "-" +
2051 f )
Jon Hall58c76b72015-02-23 11:09:24 -08002052 main.ONOSbench.handle.expect( "\$" )
Jon Hall6aec96b2015-01-19 14:49:31 -08002053 # sleep so scp can finish
2054 time.sleep( 10 )
Jon Hall58c76b72015-02-23 11:09:24 -08002055 main.Mininet1.stopNet()
Jon Hall6aec96b2015-01-19 14:49:31 -08002056 main.step( "Packing and rotating pcap archives" )
2057 os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08002058
Jon Hall6aec96b2015-01-19 14:49:31 -08002059 # TODO: actually check something here
2060 utilities.assert_equals( expect=main.TRUE, actual=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08002061 onpass="Test cleanup successful",
2062 onfail="Test cleanup NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08002063
Jon Hall6aec96b2015-01-19 14:49:31 -08002064 def CASE14( self, main ):
2065 """
Jon Hall669173b2014-12-17 11:36:30 -08002066 start election app on all onos nodes
Jon Hall6aec96b2015-01-19 14:49:31 -08002067 """
Jon Hall8f89dda2015-01-22 16:03:33 -08002068 leaderResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08002069 # install app on onos 1
2070 main.log.info( "Install leadership election app" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002071 main.ONOScli1.featureInstall( "onos-app-election" )
Jon Hall6aec96b2015-01-19 14:49:31 -08002072 # wait for election
2073 # check for leader
Jon Hall8f89dda2015-01-22 16:03:33 -08002074 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08002075 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08002076 if leader == ONOS1Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08002077 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08002078 pass
Jon Hall6aec96b2015-01-19 14:49:31 -08002079 elif leader is None:
2080 # No leader elected
2081 main.log.report( "No leader was elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002082 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08002083 elif leader == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08002084 # error in response
2085 # TODO: add check for "Command not found:" in the driver, this
2086 # means the app isn't loaded
Jon Hall8f89dda2015-01-22 16:03:33 -08002087 main.log.report( "Something is wrong with electionTestLeader" +
Jon Hall6aec96b2015-01-19 14:49:31 -08002088 " function, check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002089 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08002090 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08002091 # error in response
2092 main.log.report(
Jon Hall8f89dda2015-01-22 16:03:33 -08002093 "Unexpected response from electionTestLeader function:'" +
2094 str( leader ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08002095 "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002096 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08002097
Jon Hall6aec96b2015-01-19 14:49:31 -08002098 # install on other nodes and check for leader.
2099 # Should be onos1 and each app should show the same leader
Jon Hall8f89dda2015-01-22 16:03:33 -08002100 for controller in range( 2, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08002101 # loop through ONOScli handlers
2102 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08002103 node.featureInstall( "onos-app-election" )
2104 leaderN = node.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08002105 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08002106 if leaderN == ONOS1Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08002107 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08002108 pass
2109 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08002110 # error in response
2111 # TODO: add check for "Command not found:" in the driver, this
2112 # means the app isn't loaded
2113 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002114 "electionTestLeader function, check the" +
Jon Hall6aec96b2015-01-19 14:49:31 -08002115 " error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002116 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08002117 elif leader != leaderN:
Jon Hall8f89dda2015-01-22 16:03:33 -08002118 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08002119 main.log.report( "ONOS" + str( controller ) + " sees " +
2120 str( leaderN ) +
2121 " as the leader of the election app. Leader" +
2122 " should be " +
2123 str( leader ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08002124 if leaderResult:
Jon Hall6aec96b2015-01-19 14:49:31 -08002125 main.log.report( "Leadership election tests passed( consistent " +
2126 "view of leader across listeners and a leader " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002127 "was elected )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08002128 utilities.assert_equals(
2129 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002130 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002131 onpass="Leadership election passed",
2132 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08002133
Jon Hall6aec96b2015-01-19 14:49:31 -08002134 def CASE15( self, main ):
2135 """
Jon Hall669173b2014-12-17 11:36:30 -08002136 Check that Leadership Election is still functional
Jon Hall6aec96b2015-01-19 14:49:31 -08002137 """
Jon Hall8f89dda2015-01-22 16:03:33 -08002138 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08002139 description = "Check that Leadership Election is still functional"
Jon Hall6aec96b2015-01-19 14:49:31 -08002140 main.log.report( description )
2141 main.case( description )
2142 main.step( "Find current leader and withdraw" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002143 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08002144 # TODO: do some sanity checking on leader before using it
Jon Hall8f89dda2015-01-22 16:03:33 -08002145 withdrawResult = main.FALSE
2146 if leader == ONOS1Ip:
2147 oldLeader = getattr( main, "ONOScli1" )
2148 elif leader == ONOS2Ip:
2149 oldLeader = getattr( main, "ONOScli2" )
2150 elif leader == ONOS3Ip:
2151 oldLeader = getattr( main, "ONOScli3" )
2152 elif leader == ONOS4Ip:
2153 oldLeader = getattr( main, "ONOScli4" )
2154 elif leader == ONOS5Ip:
2155 oldLeader = getattr( main, "ONOScli5" )
2156 elif leader == ONOS6Ip:
2157 oldLeader = getattr( main, "ONOScli6" )
2158 elif leader == ONOS7Ip:
2159 oldLeader = getattr( main, "ONOScli7" )
Jon Hall6aec96b2015-01-19 14:49:31 -08002160 elif leader is None or leader == main.FALSE:
2161 main.log.report(
2162 "Leader for the election app should be an ONOS node," +
Jon Hall58c76b72015-02-23 11:09:24 -08002163 "instead got '" + str( leader ) + "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002164 leaderResult = main.FALSE
2165 withdrawResult = oldLeader.electionTestWithdraw()
Jon Hall6aec96b2015-01-19 14:49:31 -08002166 utilities.assert_equals(
2167 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002168 actual=withdrawResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002169 onpass="App was withdrawn from election",
2170 onfail="App was not withdrawn from election" )
Jon Hall669173b2014-12-17 11:36:30 -08002171
Jon Hall6aec96b2015-01-19 14:49:31 -08002172 main.step( "Make sure new leader is elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002173 leaderList = []
2174 for controller in range( 1, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08002175 # loop through ONOScli handlers
2176 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08002177 leaderList.append( node.electionTestLeader() )
2178 for leaderN in leaderList:
Jon Hall669173b2014-12-17 11:36:30 -08002179 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08002180 main.log.report(
Jon Hall58c76b72015-02-23 11:09:24 -08002181 "ONOS" + str( controller ) +
2182 " still sees " + str( leader ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08002183 " as leader after they withdrew" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002184 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08002185 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08002186 # error in response
2187 # TODO: add check for "Command not found:" in the driver, this
2188 # means the app isn't loaded
2189 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002190 "electionTestLeader function, " +
Jon Hall6aec96b2015-01-19 14:49:31 -08002191 "check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002192 leaderResult = main.FALSE
2193 consistentLeader = main.FALSE
2194 if len( set( leaderList ) ) == 1:
Jon Hall6aec96b2015-01-19 14:49:31 -08002195 main.log.info( "Each Election-app sees '" +
Jon Hall8f89dda2015-01-22 16:03:33 -08002196 str( leaderList[ 0 ] ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08002197 "' as the leader" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002198 consistentLeader = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08002199 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08002200 main.log.report(
2201 "Inconsistent responses for leader of Election-app:" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002202 for n in range( len( leaderList ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -08002203 main.log.report( "ONOS" + str( n + 1 ) + " response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002204 str( leaderList[ n ] ) )
2205 if leaderResult:
2206 main.log.report( "Leadership election tests passed( consistent " +
Jon Hall6aec96b2015-01-19 14:49:31 -08002207 "view of leader across listeners and a new " +
2208 "leader was elected when the old leader " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002209 "resigned )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08002210 utilities.assert_equals(
2211 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002212 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002213 onpass="Leadership election passed",
2214 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08002215
Jon Hall58c76b72015-02-23 11:09:24 -08002216 main.step( "Run for election on old leader( just so everyone " +
2217 "is in the hat )" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002218 runResult = oldLeader.electionTestRun()
Jon Hall6aec96b2015-01-19 14:49:31 -08002219 utilities.assert_equals(
2220 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002221 actual=runResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002222 onpass="App re-ran for election",
2223 onfail="App failed to run for election" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002224 if consistentLeader == main.TRUE:
2225 afterRun = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08002226 # verify leader didn't just change
Jon Hall8f89dda2015-01-22 16:03:33 -08002227 if afterRun == leaderList[ 0 ]:
2228 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08002229 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08002230 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08002231 # TODO: assert on run and withdraw results?
Jon Hall669173b2014-12-17 11:36:30 -08002232
Jon Hall6aec96b2015-01-19 14:49:31 -08002233 utilities.assert_equals(
2234 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002235 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002236 onpass="Leadership election passed",
2237 onfail="Something went wrong with Leadership election after " +
2238 "the old leader re-ran for election" )