blob: b1c0f77577b8c07815a52d6e5bb455ec66eb5cb1 [file] [log] [blame]
Jon Hall6aec96b2015-01-19 14:49:31 -08001"""
Jon Hall73cf9cc2014-11-20 22:28:38 -08002Description: This test is to determine if ONOS can handle
3 a minority of it's nodes restarting
4
5List of test cases:
6CASE1: Compile ONOS and push it to the test machines
7CASE2: Assign mastership to controllers
8CASE3: Assign intents
9CASE4: Ping across added host intents
10CASE5: Reading state of ONOS
11CASE6: The Failure case.
12CASE7: Check state after control plane failure
13CASE8: Compare topo
14CASE9: Link s3-s28 down
15CASE10: Link s3-s28 up
16CASE11: Switch down
17CASE12: Switch up
18CASE13: Clean up
Jon Hall669173b2014-12-17 11:36:30 -080019CASE14: start election app on all onos nodes
20CASE15: Check that Leadership Election is still functional
Jon Hall6aec96b2015-01-19 14:49:31 -080021"""
Jon Hall8f89dda2015-01-22 16:03:33 -080022
23
Jon Hall73cf9cc2014-11-20 22:28:38 -080024class HATestMinorityRestart:
25
Jon Hall6aec96b2015-01-19 14:49:31 -080026 def __init__( self ):
Jon Hall73cf9cc2014-11-20 22:28:38 -080027 self.default = ''
28
Jon Hall6aec96b2015-01-19 14:49:31 -080029 def CASE1( self, main ):
30 """
Jon Hall73cf9cc2014-11-20 22:28:38 -080031 CASE1 is to compile ONOS and push it to the test machines
32
33 Startup sequence:
Jon Hall73cf9cc2014-11-20 22:28:38 -080034 cell <name>
35 onos-verify-cell
36 NOTE: temporary - onos-remove-raft-logs
Jon Hall58c76b72015-02-23 11:09:24 -080037 onos-uninstall
38 start mininet
39 git pull
40 mvn clean install
41 onos-package
Jon Hall73cf9cc2014-11-20 22:28:38 -080042 onos-install -f
43 onos-wait-for-start
Jon Hall58c76b72015-02-23 11:09:24 -080044 start cli sessions
45 start tcpdump
Jon Hall6aec96b2015-01-19 14:49:31 -080046 """
47 main.log.report(
48 "ONOS HA test: Restart minority of ONOS nodes - initialization" )
49 main.case( "Setting up test environment" )
50 # TODO: save all the timers and output them for plotting
Jon Hall73cf9cc2014-11-20 22:28:38 -080051
52 # load some vairables from the params file
Jon Hall8f89dda2015-01-22 16:03:33 -080053 PULLCODE = False
Jon Hall6aec96b2015-01-19 14:49:31 -080054 if main.params[ 'Git' ] == 'True':
Jon Hall8f89dda2015-01-22 16:03:33 -080055 PULLCODE = True
Jon Hall529a37f2015-01-28 10:02:00 -080056 gitBranch = main.params[ 'branch' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080057 cellName = main.params[ 'ENV' ][ 'cellName' ]
Jon Hall6aec96b2015-01-19 14:49:31 -080058
59 # set global variables
Jon Hall8f89dda2015-01-22 16:03:33 -080060 global ONOS1Ip
61 global ONOS1Port
62 global ONOS2Ip
63 global ONOS2Port
64 global ONOS3Ip
65 global ONOS3Port
66 global ONOS4Ip
67 global ONOS4Port
68 global ONOS5Ip
69 global ONOS5Port
70 global ONOS6Ip
71 global ONOS6Port
72 global ONOS7Ip
73 global ONOS7Port
74 global numControllers
Jon Hall73cf9cc2014-11-20 22:28:38 -080075
Jon Hall8f89dda2015-01-22 16:03:33 -080076 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
77 ONOS1Port = main.params[ 'CTRL' ][ 'port1' ]
78 ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
79 ONOS2Port = main.params[ 'CTRL' ][ 'port2' ]
80 ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ]
81 ONOS3Port = main.params[ 'CTRL' ][ 'port3' ]
82 ONOS4Ip = main.params[ 'CTRL' ][ 'ip4' ]
83 ONOS4Port = main.params[ 'CTRL' ][ 'port4' ]
84 ONOS5Ip = main.params[ 'CTRL' ][ 'ip5' ]
85 ONOS5Port = main.params[ 'CTRL' ][ 'port5' ]
86 ONOS6Ip = main.params[ 'CTRL' ][ 'ip6' ]
87 ONOS6Port = main.params[ 'CTRL' ][ 'port6' ]
88 ONOS7Ip = main.params[ 'CTRL' ][ 'ip7' ]
89 ONOS7Port = main.params[ 'CTRL' ][ 'port7' ]
90 numControllers = int( main.params[ 'num_controllers' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -080091
Jon Hall6aec96b2015-01-19 14:49:31 -080092 main.step( "Applying cell variable to environment" )
Jon Hall8f89dda2015-01-22 16:03:33 -080093 cellResult = main.ONOSbench.setCell( cellName )
94 verifyResult = main.ONOSbench.verifyCell()
Jon Hall73cf9cc2014-11-20 22:28:38 -080095
Jon Hall6aec96b2015-01-19 14:49:31 -080096 # FIXME:this is short term fix
97 main.log.report( "Removing raft logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -080098 main.ONOSbench.onosRemoveRaftLogs()
Jon Hall6aec96b2015-01-19 14:49:31 -080099 main.log.report( "Uninstalling ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800100 main.ONOSbench.onosUninstall( ONOS1Ip )
101 main.ONOSbench.onosUninstall( ONOS2Ip )
102 main.ONOSbench.onosUninstall( ONOS3Ip )
103 main.ONOSbench.onosUninstall( ONOS4Ip )
104 main.ONOSbench.onosUninstall( ONOS5Ip )
105 main.ONOSbench.onosUninstall( ONOS6Ip )
106 main.ONOSbench.onosUninstall( ONOS7Ip )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800107
Jon Hall8f89dda2015-01-22 16:03:33 -0800108 cleanInstallResult = main.TRUE
109 gitPullResult = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800110
Jon Hall97f31752015-02-04 12:01:04 -0800111 main.step( "Starting Mininet" )
112 main.Mininet1.startNet( )
113
Jon Hall6aec96b2015-01-19 14:49:31 -0800114 main.step( "Compiling the latest version of ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800115 if PULLCODE:
Jon Hall58c76b72015-02-23 11:09:24 -0800116 main.step( "Git checkout and pull " + gitBranch )
Jon Hall529a37f2015-01-28 10:02:00 -0800117 main.ONOSbench.gitCheckout( gitBranch )
Jon Hall8f89dda2015-01-22 16:03:33 -0800118 gitPullResult = main.ONOSbench.gitPull()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800119
Jon Hall6aec96b2015-01-19 14:49:31 -0800120 main.step( "Using mvn clean & install" )
Jon Hall529a37f2015-01-28 10:02:00 -0800121 cleanInstallResult = main.ONOSbench.cleanInstall()
122 else:
123 main.log.warn( "Did not pull new code so skipping mvn " +
124 "clean install" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800125 main.ONOSbench.getVersion( report=True )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800126
Jon Hall6aec96b2015-01-19 14:49:31 -0800127 main.step( "Creating ONOS package" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800128 packageResult = main.ONOSbench.onosPackage()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800129
Jon Hall6aec96b2015-01-19 14:49:31 -0800130 main.step( "Installing ONOS package" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800131 onos1InstallResult = main.ONOSbench.onosInstall( options="-f",
132 node=ONOS1Ip )
133 onos2InstallResult = main.ONOSbench.onosInstall( options="-f",
134 node=ONOS2Ip )
135 onos3InstallResult = main.ONOSbench.onosInstall( options="-f",
136 node=ONOS3Ip )
137 onos4InstallResult = main.ONOSbench.onosInstall( options="-f",
138 node=ONOS4Ip )
139 onos5InstallResult = main.ONOSbench.onosInstall( options="-f",
140 node=ONOS5Ip )
141 onos6InstallResult = main.ONOSbench.onosInstall( options="-f",
142 node=ONOS6Ip )
143 onos7InstallResult = main.ONOSbench.onosInstall( options="-f",
144 node=ONOS7Ip )
145 onosInstallResult = onos1InstallResult and onos2InstallResult\
146 and onos3InstallResult and onos4InstallResult\
147 and onos5InstallResult and onos6InstallResult\
148 and onos7InstallResult
Jon Hall73cf9cc2014-11-20 22:28:38 -0800149
Jon Hall6aec96b2015-01-19 14:49:31 -0800150 main.step( "Checking if ONOS is up yet" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800151 for i in range( 2 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800152 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
153 if not onos1Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800154 main.log.report( "ONOS1 didn't start!" )
Jon Hall21270ac2015-02-16 17:59:55 -0800155 main.ONOSbench.onosStop( ONOS1Ip )
156 main.ONOSbench.onosStart( ONOS1Ip )
Jon Hall8f89dda2015-01-22 16:03:33 -0800157 onos2Isup = main.ONOSbench.isup( ONOS2Ip )
158 if not onos2Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800159 main.log.report( "ONOS2 didn't start!" )
Jon Hall21270ac2015-02-16 17:59:55 -0800160 main.ONOSbench.onosStop( ONOS2Ip )
161 main.ONOSbench.onosStart( ONOS2Ip )
Jon Hall8f89dda2015-01-22 16:03:33 -0800162 onos3Isup = main.ONOSbench.isup( ONOS3Ip )
163 if not onos3Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800164 main.log.report( "ONOS3 didn't start!" )
Jon Hall21270ac2015-02-16 17:59:55 -0800165 main.ONOSbench.onosStop( ONOS3Ip )
166 main.ONOSbench.onosStart( ONOS3Ip )
Jon Hall8f89dda2015-01-22 16:03:33 -0800167 onos4Isup = main.ONOSbench.isup( ONOS4Ip )
168 if not onos4Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800169 main.log.report( "ONOS4 didn't start!" )
Jon Hall21270ac2015-02-16 17:59:55 -0800170 main.ONOSbench.onosStop( ONOS4Ip )
171 main.ONOSbench.onosStart( ONOS4Ip )
Jon Hall8f89dda2015-01-22 16:03:33 -0800172 onos5Isup = main.ONOSbench.isup( ONOS5Ip )
173 if not onos5Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800174 main.log.report( "ONOS5 didn't start!" )
Jon Hall21270ac2015-02-16 17:59:55 -0800175 main.ONOSbench.onosStop( ONOS5Ip )
176 main.ONOSbench.onosStart( ONOS5Ip )
Jon Hall8f89dda2015-01-22 16:03:33 -0800177 onos6Isup = main.ONOSbench.isup( ONOS6Ip )
178 if not onos6Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800179 main.log.report( "ONOS6 didn't start!" )
Jon Hall21270ac2015-02-16 17:59:55 -0800180 main.ONOSbench.onosStop( ONOS6Ip )
181 main.ONOSbench.onosStart( ONOS6Ip )
Jon Hall8f89dda2015-01-22 16:03:33 -0800182 onos7Isup = main.ONOSbench.isup( ONOS7Ip )
183 if not onos7Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800184 main.log.report( "ONOS7 didn't start!" )
Jon Hall21270ac2015-02-16 17:59:55 -0800185 main.ONOSbench.onosStop( ONOS7Ip )
186 main.ONOSbench.onosStart( ONOS7Ip )
Jon Hall8f89dda2015-01-22 16:03:33 -0800187 onosIsupResult = onos1Isup and onos2Isup and onos3Isup\
188 and onos4Isup and onos5Isup and onos6Isup and onos7Isup
189 if onosIsupResult == main.TRUE:
Jon Hall94fd0472014-12-08 11:52:42 -0800190 break
Jon Hall73cf9cc2014-11-20 22:28:38 -0800191
Jon Hall8f89dda2015-01-22 16:03:33 -0800192 cliResult1 = main.ONOScli1.startOnosCli( ONOS1Ip )
193 cliResult2 = main.ONOScli2.startOnosCli( ONOS2Ip )
194 cliResult3 = main.ONOScli3.startOnosCli( ONOS3Ip )
195 cliResult4 = main.ONOScli4.startOnosCli( ONOS4Ip )
196 cliResult5 = main.ONOScli5.startOnosCli( ONOS5Ip )
197 cliResult6 = main.ONOScli6.startOnosCli( ONOS6Ip )
198 cliResult7 = main.ONOScli7.startOnosCli( ONOS7Ip )
199 cliResults = cliResult1 and cliResult2 and cliResult3 and\
200 cliResult4 and cliResult5 and cliResult6 and cliResult7
Jon Hall73cf9cc2014-11-20 22:28:38 -0800201
Jon Hall6aec96b2015-01-19 14:49:31 -0800202 main.step( "Start Packet Capture MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800203 main.Mininet2.startTcpdump(
Jon Hall6aec96b2015-01-19 14:49:31 -0800204 str( main.params[ 'MNtcpdump' ][ 'folder' ] ) + str( main.TEST )
205 + "-MN.pcap",
206 intf=main.params[ 'MNtcpdump' ][ 'intf' ],
207 port=main.params[ 'MNtcpdump' ][ 'port' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800208
Jon Hall8f89dda2015-01-22 16:03:33 -0800209 case1Result = ( cleanInstallResult and packageResult and
210 cellResult and verifyResult and onosInstallResult
211 and onosIsupResult and cliResults )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800212
Jon Hall8f89dda2015-01-22 16:03:33 -0800213 utilities.assert_equals( expect=main.TRUE, actual=case1Result,
Jon Hall58c76b72015-02-23 11:09:24 -0800214 onpass="Test startup successful",
215 onfail="Test startup NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800216
Jon Hall8f89dda2015-01-22 16:03:33 -0800217 if case1Result == main.FALSE:
Jon Hall94fd0472014-12-08 11:52:42 -0800218 main.cleanup()
219 main.exit()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800220
Jon Hall6aec96b2015-01-19 14:49:31 -0800221 def CASE2( self, main ):
222 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800223 Assign mastership to controllers
Jon Hall6aec96b2015-01-19 14:49:31 -0800224 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800225 import re
226
Jon Hall6aec96b2015-01-19 14:49:31 -0800227 main.log.report( "Assigning switches to controllers" )
228 main.case( "Assigning Controllers" )
229 main.step( "Assign switches to controllers" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800230
Jon Hall6aec96b2015-01-19 14:49:31 -0800231 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800232 main.Mininet1.assignSwController(
Jon Hall6aec96b2015-01-19 14:49:31 -0800233 sw=str( i ),
Jon Hall8f89dda2015-01-22 16:03:33 -0800234 count=numControllers,
235 ip1=ONOS1Ip, port1=ONOS1Port,
236 ip2=ONOS2Ip, port2=ONOS2Port,
237 ip3=ONOS3Ip, port3=ONOS3Port,
238 ip4=ONOS4Ip, port4=ONOS4Port,
239 ip5=ONOS5Ip, port5=ONOS5Port,
240 ip6=ONOS6Ip, port6=ONOS6Port,
241 ip7=ONOS7Ip, port7=ONOS7Port )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800242
Jon Hall8f89dda2015-01-22 16:03:33 -0800243 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800244 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800245 response = main.Mininet1.getSwController( "s" + str( i ) )
Jon Hallffb386d2014-11-21 13:43:38 -0800246 try:
Jon Hall6aec96b2015-01-19 14:49:31 -0800247 main.log.info( str( response ) )
Jon Hallffb386d2014-11-21 13:43:38 -0800248 except:
Jon Hall6aec96b2015-01-19 14:49:31 -0800249 main.log.info( repr( response ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800250 if re.search( "tcp:" + ONOS1Ip, response )\
251 and re.search( "tcp:" + ONOS2Ip, response )\
252 and re.search( "tcp:" + ONOS3Ip, response )\
253 and re.search( "tcp:" + ONOS4Ip, response )\
254 and re.search( "tcp:" + ONOS5Ip, response )\
255 and re.search( "tcp:" + ONOS6Ip, response )\
256 and re.search( "tcp:" + ONOS7Ip, response ):
257 mastershipCheck = mastershipCheck and main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800258 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800259 mastershipCheck = main.FALSE
260 if mastershipCheck == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800261 main.log.report( "Switch mastership assigned correctly" )
262 utilities.assert_equals(
263 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800264 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800265 onpass="Switch mastership assigned correctly",
266 onfail="Switches not assigned correctly to controllers" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800267
Jon Hall6aec96b2015-01-19 14:49:31 -0800268 # Manually assign mastership to the controller we want
Jon Hall8f89dda2015-01-22 16:03:33 -0800269 roleCall = main.TRUE
270 roleCheck = main.TRUE
Jon Hall58c76b72015-02-23 11:09:24 -0800271 try:
272 # Assign switch
273 deviceId = main.ONOScli1.getDevice( "1000" ).get( 'id' )
274 assert deviceId, "No device id for s1 in ONOS"
Jon Hall8f89dda2015-01-22 16:03:33 -0800275 roleCall = roleCall and main.ONOScli1.deviceRole(
276 deviceId,
Jon Hall58c76b72015-02-23 11:09:24 -0800277 ONOS1Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800278 # Check assignment
Jon Hall58c76b72015-02-23 11:09:24 -0800279 if ONOS1Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800280 roleCheck = roleCheck and main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800281 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800282 roleCheck = roleCheck and main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800283
Jon Hall58c76b72015-02-23 11:09:24 -0800284 # Assign switch
285 deviceId = main.ONOScli1.getDevice( "2800" ).get( 'id' )
286 assert deviceId, "No device id for s28 in ONOS"
Jon Hall8f89dda2015-01-22 16:03:33 -0800287 roleCall = roleCall and main.ONOScli1.deviceRole(
288 deviceId,
Jon Hall58c76b72015-02-23 11:09:24 -0800289 ONOS1Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800290 # Check assignment
Jon Hall58c76b72015-02-23 11:09:24 -0800291 if ONOS1Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800292 roleCheck = roleCheck and main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800293 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800294 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800295
Jon Hall58c76b72015-02-23 11:09:24 -0800296 # Assign switch
297 deviceId = main.ONOScli1.getDevice( "2000" ).get( 'id' )
298 assert deviceId, "No device id for s2 in ONOS"
299 roleCall = roleCall and main.ONOScli1.deviceRole(
300 deviceId,
301 ONOS2Ip )
302 # Check assignment
303 if ONOS2Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
304 roleCheck = roleCheck and main.TRUE
305 else:
306 roleCheck = roleCheck and main.FALSE
307
308 # Assign switch
309 deviceId = main.ONOScli1.getDevice( "3000" ).get( 'id' )
310 assert deviceId, "No device id for s3 in ONOS"
311 roleCall = roleCall and main.ONOScli1.deviceRole(
312 deviceId,
313 ONOS2Ip )
314 # Check assignment
315 if ONOS2Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
316 roleCheck = roleCheck and main.TRUE
317 else:
318 roleCheck = roleCheck and main.FALSE
319
320 # Assign switch
321 deviceId = main.ONOScli1.getDevice( "5000" ).get( 'id' )
322 assert deviceId, "No device id for s5 in ONOS"
323 roleCall = roleCall and main.ONOScli1.deviceRole(
324 deviceId,
325 ONOS3Ip )
326 # Check assignment
327 if ONOS3Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
328 roleCheck = roleCheck and main.TRUE
329 else:
330 roleCheck = roleCheck and main.FALSE
331
332 # Assign switch
333 deviceId = main.ONOScli1.getDevice( "6000" ).get( 'id' )
334 assert deviceId, "No device id for s6 in ONOS"
335 roleCall = roleCall and main.ONOScli1.deviceRole(
336 deviceId,
337 ONOS3Ip )
338 # Check assignment
339 if ONOS3Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
340 roleCheck = roleCheck and main.TRUE
341 else:
342 roleCheck = roleCheck and main.FALSE
343
344 # Assign switch
345 deviceId = main.ONOScli1.getDevice( "3004" ).get( 'id' )
346 assert deviceId, "No device id for s4 in ONOS"
347 roleCall = roleCall and main.ONOScli1.deviceRole(
348 deviceId,
349 ONOS4Ip )
350 # Check assignment
351 if ONOS4Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
352 roleCheck = roleCheck and main.TRUE
353 else:
354 roleCheck = roleCheck and main.FALSE
355
356 for i in range( 8, 18 ):
357 dpid = '3' + str( i ).zfill( 3 )
358 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
359 assert deviceId, "No device id for s%i in ONOS" % i
360 roleCall = roleCall and main.ONOScli1.deviceRole(
361 deviceId,
362 ONOS5Ip )
363 # Check assignment
364 if ONOS5Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
365 roleCheck = roleCheck and main.TRUE
366 else:
367 roleCheck = roleCheck and main.FALSE
368
369 deviceId = main.ONOScli1.getDevice( "6007" ).get( 'id' )
370 assert deviceId, "No device id for s7 in ONOS"
371 roleCall = roleCall and main.ONOScli1.deviceRole(
372 deviceId,
373 ONOS6Ip )
374 # Check assignment
375 if ONOS6Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
376 roleCheck = roleCheck and main.TRUE
377 else:
378 roleCheck = roleCheck and main.FALSE
379
380 for i in range( 18, 28 ):
381 dpid = '6' + str( i ).zfill( 3 )
382 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
383 assert deviceId, "No device id for s%i in ONOS" % i
384 roleCall = roleCall and main.ONOScli1.deviceRole(
385 deviceId,
386 ONOS7Ip )
387 # Check assignment
388 if ONOS7Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
389 roleCheck = roleCheck and main.TRUE
390 else:
391 roleCheck = roleCheck and main.FALSE
392 except ( AttributeError, AssertionError ):
393 main.log.exception( "Something is wrong with ONOS device view" )
394 main.log.info( main.ONOScli1.devices() )
395
Jon Hall6aec96b2015-01-19 14:49:31 -0800396 utilities.assert_equals(
397 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800398 actual=roleCall,
Jon Hall6aec96b2015-01-19 14:49:31 -0800399 onpass="Re-assigned switch mastership to designated controller",
Jon Hall8f89dda2015-01-22 16:03:33 -0800400 onfail="Something wrong with deviceRole calls" )
Jon Hall94fd0472014-12-08 11:52:42 -0800401
Jon Hall6aec96b2015-01-19 14:49:31 -0800402 utilities.assert_equals(
403 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800404 actual=roleCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800405 onpass="Switches were successfully reassigned to designated " +
406 "controller",
407 onfail="Switches were not successfully reassigned" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800408 mastershipCheck = mastershipCheck and roleCall and roleCheck
409 utilities.assert_equals( expect=main.TRUE, actual=mastershipCheck,
Jon Hall21270ac2015-02-16 17:59:55 -0800410 onpass="Switch mastership correctly assigned",
411 onfail="Error in (re)assigning switch" +
412 " mastership" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800413
Jon Hall6aec96b2015-01-19 14:49:31 -0800414 def CASE3( self, main ):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800415 """
416 Assign intents
Jon Hall73cf9cc2014-11-20 22:28:38 -0800417 """
418 import time
Jon Hall58c76b72015-02-23 11:09:24 -0800419 import json
Jon Hall6aec96b2015-01-19 14:49:31 -0800420 main.log.report( "Adding host intents" )
421 main.case( "Adding host Intents" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800422
Jon Hall8f89dda2015-01-22 16:03:33 -0800423 main.step( "Discovering Hosts( Via pingall for now )" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800424 # FIXME: Once we have a host discovery mechanism, use that instead
Jon Hall73cf9cc2014-11-20 22:28:38 -0800425
Jon Hall6aec96b2015-01-19 14:49:31 -0800426 # install onos-app-fwd
427 main.log.info( "Install reactive forwarding app" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800428 main.ONOScli1.featureInstall( "onos-app-fwd" )
429 main.ONOScli2.featureInstall( "onos-app-fwd" )
430 main.ONOScli3.featureInstall( "onos-app-fwd" )
431 main.ONOScli4.featureInstall( "onos-app-fwd" )
432 main.ONOScli5.featureInstall( "onos-app-fwd" )
433 main.ONOScli6.featureInstall( "onos-app-fwd" )
434 main.ONOScli7.featureInstall( "onos-app-fwd" )
Jon Hall94fd0472014-12-08 11:52:42 -0800435
Jon Hall6aec96b2015-01-19 14:49:31 -0800436 # REACTIVE FWD test
Jon Hall8f89dda2015-01-22 16:03:33 -0800437 pingResult = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800438 time1 = time.time()
Jon Hall8f89dda2015-01-22 16:03:33 -0800439 pingResult = main.Mininet1.pingall()
Jon Hall529a37f2015-01-28 10:02:00 -0800440 utilities.assert_equals(
441 expect=main.TRUE,
442 actual=pingResult,
443 onpass="Reactive Pingall test passed",
444 onfail="Reactive Pingall failed, one or more ping pairs failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800445 time2 = time.time()
Jon Hall6aec96b2015-01-19 14:49:31 -0800446 main.log.info( "Time for pingall: %2f seconds" % ( time2 - time1 ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800447
Jon Hall6aec96b2015-01-19 14:49:31 -0800448 # uninstall onos-app-fwd
449 main.log.info( "Uninstall reactive forwarding app" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800450 main.ONOScli1.featureUninstall( "onos-app-fwd" )
451 main.ONOScli2.featureUninstall( "onos-app-fwd" )
452 main.ONOScli3.featureUninstall( "onos-app-fwd" )
453 main.ONOScli4.featureUninstall( "onos-app-fwd" )
454 main.ONOScli5.featureUninstall( "onos-app-fwd" )
455 main.ONOScli6.featureUninstall( "onos-app-fwd" )
456 main.ONOScli7.featureUninstall( "onos-app-fwd" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800457 # timeout for fwd flows
458 time.sleep( 10 )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800459
Jon Hall6aec96b2015-01-19 14:49:31 -0800460 main.step( "Add host intents" )
Jon Hall58c76b72015-02-23 11:09:24 -0800461 intentIds = []
Jon Hall6aec96b2015-01-19 14:49:31 -0800462 # TODO: move the host numbers to params
Jon Hall58c76b72015-02-23 11:09:24 -0800463 # Maybe look at all the paths we ping?
Jon Hall8f89dda2015-01-22 16:03:33 -0800464 intentAddResult = True
Jon Hall58c76b72015-02-23 11:09:24 -0800465 hostResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800466 for i in range( 8, 18 ):
467 main.log.info( "Adding host intent between h" + str( i ) +
468 " and h" + str( i + 10 ) )
469 host1 = "00:00:00:00:00:" + \
470 str( hex( i )[ 2: ] ).zfill( 2 ).upper()
471 host2 = "00:00:00:00:00:" + \
472 str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper()
Jon Hall1b8f54a2015-02-04 13:24:20 -0800473 # NOTE: getHost can return None
474 host1Dict = main.ONOScli1.getHost( host1 )
475 host2Dict = main.ONOScli1.getHost( host2 )
476 host1Id = None
477 host2Id = None
478 if host1Dict and host2Dict:
479 host1Id = host1Dict.get( 'id', None )
480 host2Id = host2Dict.get( 'id', None )
Jon Hall8f89dda2015-01-22 16:03:33 -0800481 if host1Id and host2Id:
Jon Hall58c76b72015-02-23 11:09:24 -0800482 # Changed onos node to test something
483 tmpId = main.ONOScli4.addHostIntent(
Jon Hall8f89dda2015-01-22 16:03:33 -0800484 host1Id,
485 host2Id )
Jon Hall63604932015-02-26 17:09:50 -0800486 if tmpId:
487 main.log.info( "Added intent with id: " + tmpId )
488 intentIds.append( tmpId )
489 else:
490 main.log.error( "addHostIntent reutrned None" )
Jon Hall669173b2014-12-17 11:36:30 -0800491 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800492 main.log.error( "Error, getHost() failed" )
Jon Hall1b8f54a2015-02-04 13:24:20 -0800493 main.log.warn( json.dumps( json.loads( main.ONOScli1.hosts() ),
494 sort_keys=True,
495 indent=4,
496 separators=( ',', ': ' ) ) )
Jon Hall58c76b72015-02-23 11:09:24 -0800497 hostResult = main.FALSE
498 onosIds = main.ONOScli1.getAllIntentsId()
499 main.log.info( "Submitted intents: " + str( intentIds ) )
500 main.log.info( "Intents in ONOS: " + str( onosIds ) )
501 for intent in intentIds:
502 if intent in onosIds:
503 pass # intent submitted is still in onos
504 else:
505 intentAddResult = False
Jon Hall1b8f54a2015-02-04 13:24:20 -0800506 # Print the intent states
Jon Hall58c76b72015-02-23 11:09:24 -0800507 intents = main.ONOScli1.intents()
Jon Hall1b8f54a2015-02-04 13:24:20 -0800508 intentStates = []
Jon Hall63604932015-02-26 17:09:50 -0800509 installedCheck = True
Jon Hall58c76b72015-02-23 11:09:24 -0800510 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
511 count = 0
Jon Hall1b8f54a2015-02-04 13:24:20 -0800512 for intent in json.loads( intents ): # Iter through intents of a node
Jon Hall58c76b72015-02-23 11:09:24 -0800513 state = intent.get( 'state', None )
Jon Hall63604932015-02-26 17:09:50 -0800514 if "INSTALLED" not in state:
515 installedCheck = False
Jon Hall58c76b72015-02-23 11:09:24 -0800516 intentId = intent.get( 'id', None )
517 intentStates.append( ( intentId, state ) )
518 # add submitted intents not in the store
519 tmplist = [ i for i, s in intentStates ]
520 missingIntents = False
521 for i in intentIds:
522 if i not in tmplist:
523 intentStates.append( ( i, " - " ) )
524 missingIntents = True
525 intentStates.sort()
526 for i, s in intentStates:
527 count += 1
528 main.log.info( "%-6s%-15s%-15s" %
529 ( str( count ), str( i ), str( s ) ) )
Jon Hall63604932015-02-26 17:09:50 -0800530 main.ONOScli1.leaders()
531 main.ONOScli1.partitions()
532 # for node in nodes:
533 # node.pendingMap()
534 pendingMap = main.ONOScli1.pendingMap()
535 main.ONOScli2.pendingMap()
536 main.ONOScli3.pendingMap()
537 main.ONOScli4.pendingMap()
538 main.ONOScli5.pendingMap()
539 main.ONOScli6.pendingMap()
540 main.ONOScli7.pendingMap()
Jon Hall58c76b72015-02-23 11:09:24 -0800541 intentAddResult = bool( pingResult and hostResult and intentAddResult
Jon Hall63604932015-02-26 17:09:50 -0800542 and not missingIntents and installedCheck )
Jon Hall6aec96b2015-01-19 14:49:31 -0800543 utilities.assert_equals(
544 expect=True,
Jon Hall8f89dda2015-01-22 16:03:33 -0800545 actual=intentAddResult,
Jon Hall529a37f2015-01-28 10:02:00 -0800546 onpass="Pushed host intents to ONOS",
547 onfail="Error in pushing host intents to ONOS" )
Jon Hall58c76b72015-02-23 11:09:24 -0800548
Jon Hall63604932015-02-26 17:09:50 -0800549 if not intentAddResult or "key" in pendingMap:
Jon Hall58c76b72015-02-23 11:09:24 -0800550 import time
Jon Hall63604932015-02-26 17:09:50 -0800551 installedCheck = True
Jon Hall58c76b72015-02-23 11:09:24 -0800552 main.log.info( "Sleeping 60 seconds to see if intents are found" )
553 time.sleep( 60 )
554 onosIds = main.ONOScli1.getAllIntentsId()
555 main.log.info( "Submitted intents: " + str( intentIds ) )
556 main.log.info( "Intents in ONOS: " + str( onosIds ) )
557 # Print the intent states
558 intents = main.ONOScli1.intents()
559 intentStates = []
560 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
561 count = 0
562 for intent in json.loads( intents ):
563 # Iter through intents of a node
564 state = intent.get( 'state', None )
Jon Hall63604932015-02-26 17:09:50 -0800565 if "INSTALLED" not in state:
566 installedCheck = False
Jon Hall58c76b72015-02-23 11:09:24 -0800567 intentId = intent.get( 'id', None )
568 intentStates.append( ( intentId, state ) )
569 # add submitted intents not in the store
570 tmplist = [ i for i, s in intentStates ]
571 for i in intentIds:
572 if i not in tmplist:
573 intentStates.append( ( i, " - " ) )
574 intentStates.sort()
575 for i, s in intentStates:
576 count += 1
577 main.log.info( "%-6s%-15s%-15s" %
578 ( str( count ), str( i ), str( s ) ) )
Jon Hall63604932015-02-26 17:09:50 -0800579 main.ONOScli1.leaders()
580 main.ONOScli1.pendingMap()
581 main.ONOScli2.pendingMap()
582 main.ONOScli3.pendingMap()
583 main.ONOScli4.pendingMap()
584 main.ONOScli5.pendingMap()
585 main.ONOScli6.pendingMap()
586 main.ONOScli7.pendingMap()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800587
Jon Hall6aec96b2015-01-19 14:49:31 -0800588 def CASE4( self, main ):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800589 """
590 Ping across added host intents
591 """
Jon Hall58c76b72015-02-23 11:09:24 -0800592 import json
Jon Hall73cf9cc2014-11-20 22:28:38 -0800593 description = " Ping across added host intents"
Jon Hall6aec96b2015-01-19 14:49:31 -0800594 main.log.report( description )
595 main.case( description )
Jon Hall8f89dda2015-01-22 16:03:33 -0800596 PingResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800597 for i in range( 8, 18 ):
Jon Hall21270ac2015-02-16 17:59:55 -0800598 ping = main.Mininet1.pingHost( src="h" + str( i ),
599 target="h" + str( i + 10 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800600 PingResult = PingResult and ping
Jon Hall6aec96b2015-01-19 14:49:31 -0800601 if ping == main.FALSE:
602 main.log.warn( "Ping failed between h" + str( i ) +
603 " and h" + str( i + 10 ) )
604 elif ping == main.TRUE:
605 main.log.info( "Ping test passed!" )
Jon Hall21270ac2015-02-16 17:59:55 -0800606 # Don't set PingResult or you'd override failures
Jon Hall8f89dda2015-01-22 16:03:33 -0800607 if PingResult == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800608 main.log.report(
609 "Intents have not been installed correctly, pings failed." )
Jon Hall58c76b72015-02-23 11:09:24 -0800610 # TODO: pretty print
Jon Hall529a37f2015-01-28 10:02:00 -0800611 main.log.warn( "ONSO1 intents: " )
612 main.log.warn( json.dumps( json.loads( main.ONOScli1.intents() ),
613 sort_keys=True,
614 indent=4,
615 separators=( ',', ': ' ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800616 if PingResult == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800617 main.log.report(
618 "Intents have been installed correctly and verified by pings" )
619 utilities.assert_equals(
620 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800621 actual=PingResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800622 onpass="Intents have been installed correctly and pings work",
623 onfail="Intents have not been installed correctly, pings failed." )
Jon Hall63604932015-02-26 17:09:50 -0800624
625 installedCheck = True
Jon Hall58c76b72015-02-23 11:09:24 -0800626 if PingResult is not main.TRUE:
627 # Print the intent states
628 intents = main.ONOScli1.intents()
629 intentStates = []
630 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
631 count = 0
632 # Iter through intents of a node
633 for intent in json.loads( intents ):
634 state = intent.get( 'state', None )
Jon Hall63604932015-02-26 17:09:50 -0800635 if "INSTALLED" not in state:
636 installedCheck = False
Jon Hall58c76b72015-02-23 11:09:24 -0800637 intentId = intent.get( 'id', None )
638 intentStates.append( ( intentId, state ) )
639 intentStates.sort()
640 for i, s in intentStates:
641 count += 1
642 main.log.info( "%-6s%-15s%-15s" %
643 ( str( count ), str( i ), str( s ) ) )
Jon Hall63604932015-02-26 17:09:50 -0800644 main.ONOScli1.leaders()
645 main.ONOScli1.partitions()
646 main.ONOScli1.pendingMap()
647 main.ONOScli2.pendingMap()
648 main.ONOScli3.pendingMap()
649 main.ONOScli4.pendingMap()
650 main.ONOScli5.pendingMap()
651 main.ONOScli6.pendingMap()
652 main.ONOScli7.pendingMap()
653 if not installedCheck:
654 main.log.info( "Waiting 60 seconds to see if intent states change" )
655 time.sleep( 60 )
656 # Print the intent states
657 intents = main.ONOScli1.intents()
658 intentStates = []
659 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
660 count = 0
661 # Iter through intents of a node
662 for intent in json.loads( intents ):
663 state = intent.get( 'state', None )
664 if "INSTALLED" not in state:
665 installedCheck = False
666 intentId = intent.get( 'id', None )
667 intentStates.append( ( intentId, state ) )
668 intentStates.sort()
669 for i, s in intentStates:
670 count += 1
671 main.log.info( "%-6s%-15s%-15s" %
672 ( str( count ), str( i ), str( s ) ) )
673 main.ONOScli1.leaders()
674 main.ONOScli1.partitions()
675 main.ONOScli1.pendingMap()
676 main.ONOScli2.pendingMap()
677 main.ONOScli3.pendingMap()
678 main.ONOScli4.pendingMap()
679 main.ONOScli5.pendingMap()
680 main.ONOScli6.pendingMap()
681 main.ONOScli7.pendingMap()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800682
Jon Hall6aec96b2015-01-19 14:49:31 -0800683 def CASE5( self, main ):
684 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800685 Reading state of ONOS
Jon Hall6aec96b2015-01-19 14:49:31 -0800686 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800687 import json
Jon Hall6aec96b2015-01-19 14:49:31 -0800688 # assumes that sts is already in you PYTHONPATH
689 from sts.topology.teston_topology import TestONTopology
Jon Hall73cf9cc2014-11-20 22:28:38 -0800690
Jon Hall6aec96b2015-01-19 14:49:31 -0800691 main.log.report( "Setting up and gathering data for current state" )
692 main.case( "Setting up and gathering data for current state" )
693 # The general idea for this test case is to pull the state of
694 # ( intents,flows, topology,... ) from each ONOS node
695 # We can then compare them with eachother and also with past states
Jon Hall73cf9cc2014-11-20 22:28:38 -0800696
Jon Hall6aec96b2015-01-19 14:49:31 -0800697 main.step( "Get the Mastership of each switch from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800698 global mastershipState
699 mastershipState = []
Jon Hall94fd0472014-12-08 11:52:42 -0800700
Jon Hall6aec96b2015-01-19 14:49:31 -0800701 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -0800702 ONOS1MasterNotNull = main.ONOScli1.rolesNotNull()
703 ONOS2MasterNotNull = main.ONOScli2.rolesNotNull()
704 ONOS3MasterNotNull = main.ONOScli3.rolesNotNull()
705 ONOS4MasterNotNull = main.ONOScli4.rolesNotNull()
706 ONOS5MasterNotNull = main.ONOScli5.rolesNotNull()
707 ONOS6MasterNotNull = main.ONOScli6.rolesNotNull()
708 ONOS7MasterNotNull = main.ONOScli7.rolesNotNull()
709 rolesNotNull = ONOS1MasterNotNull and ONOS2MasterNotNull and\
710 ONOS3MasterNotNull and ONOS4MasterNotNull and\
711 ONOS5MasterNotNull and ONOS6MasterNotNull and\
712 ONOS7MasterNotNull
Jon Hall6aec96b2015-01-19 14:49:31 -0800713 utilities.assert_equals(
714 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800715 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -0800716 onpass="Each device has a master",
717 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -0800718
Jon Hall8f89dda2015-01-22 16:03:33 -0800719 ONOS1Mastership = main.ONOScli1.roles()
720 ONOS2Mastership = main.ONOScli2.roles()
721 ONOS3Mastership = main.ONOScli3.roles()
722 ONOS4Mastership = main.ONOScli4.roles()
723 ONOS5Mastership = main.ONOScli5.roles()
724 ONOS6Mastership = main.ONOScli6.roles()
725 ONOS7Mastership = main.ONOScli7.roles()
726 if "Error" in ONOS1Mastership or not ONOS1Mastership\
727 or "Error" in ONOS2Mastership or not ONOS2Mastership\
728 or "Error" in ONOS3Mastership or not ONOS3Mastership\
729 or "Error" in ONOS4Mastership or not ONOS4Mastership\
730 or "Error" in ONOS5Mastership or not ONOS5Mastership\
731 or "Error" in ONOS6Mastership or not ONOS6Mastership\
732 or "Error" in ONOS7Mastership or not ONOS7Mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -0800733 main.log.report( "Error in getting ONOS roles" )
734 main.log.warn(
735 "ONOS1 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800736 repr( ONOS1Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800737 main.log.warn(
738 "ONOS2 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800739 repr( ONOS2Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800740 main.log.warn(
741 "ONOS3 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800742 repr( ONOS3Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800743 main.log.warn(
744 "ONOS4 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800745 repr( ONOS4Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800746 main.log.warn(
747 "ONOS5 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800748 repr( ONOS5Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800749 main.log.warn(
750 "ONOS6 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800751 repr( ONOS6Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800752 main.log.warn(
753 "ONOS7 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800754 repr( ONOS7Mastership ) )
755 consistentMastership = main.FALSE
756 elif ONOS1Mastership == ONOS2Mastership\
757 and ONOS1Mastership == ONOS3Mastership\
758 and ONOS1Mastership == ONOS4Mastership\
759 and ONOS1Mastership == ONOS5Mastership\
760 and ONOS1Mastership == ONOS6Mastership\
761 and ONOS1Mastership == ONOS7Mastership:
762 mastershipState = ONOS1Mastership
763 consistentMastership = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800764 main.log.report(
765 "Switch roles are consistent across all ONOS nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800766 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800767 main.log.warn(
768 "ONOS1 roles: ",
769 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800770 json.loads( ONOS1Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800771 sort_keys=True,
772 indent=4,
773 separators=(
774 ',',
775 ': ' ) ) )
776 main.log.warn(
777 "ONOS2 roles: ",
778 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800779 json.loads( ONOS2Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800780 sort_keys=True,
781 indent=4,
782 separators=(
783 ',',
784 ': ' ) ) )
785 main.log.warn(
786 "ONOS3 roles: ",
787 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800788 json.loads( ONOS3Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800789 sort_keys=True,
790 indent=4,
791 separators=(
792 ',',
793 ': ' ) ) )
794 main.log.warn(
795 "ONOS4 roles: ",
796 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800797 json.loads( ONOS4Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800798 sort_keys=True,
799 indent=4,
800 separators=(
801 ',',
802 ': ' ) ) )
803 main.log.warn(
804 "ONOS5 roles: ",
805 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800806 json.loads( ONOS5Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800807 sort_keys=True,
808 indent=4,
809 separators=(
810 ',',
811 ': ' ) ) )
812 main.log.warn(
813 "ONOS6 roles: ",
814 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800815 json.loads( ONOS6Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800816 sort_keys=True,
817 indent=4,
818 separators=(
819 ',',
820 ': ' ) ) )
821 main.log.warn(
822 "ONOS7 roles: ",
823 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800824 json.loads( ONOS7Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800825 sort_keys=True,
826 indent=4,
827 separators=(
828 ',',
829 ': ' ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800830 consistentMastership = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800831 utilities.assert_equals(
832 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800833 actual=consistentMastership,
Jon Hall6aec96b2015-01-19 14:49:31 -0800834 onpass="Switch roles are consistent across all ONOS nodes",
835 onfail="ONOS nodes have different views of switch roles" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800836
Jon Hall6aec96b2015-01-19 14:49:31 -0800837 main.step( "Get the intents from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800838 global intentState
839 intentState = []
840 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
841 ONOS2Intents = main.ONOScli2.intents( jsonFormat=True )
842 ONOS3Intents = main.ONOScli3.intents( jsonFormat=True )
843 ONOS4Intents = main.ONOScli4.intents( jsonFormat=True )
844 ONOS5Intents = main.ONOScli5.intents( jsonFormat=True )
845 ONOS6Intents = main.ONOScli6.intents( jsonFormat=True )
846 ONOS7Intents = main.ONOScli7.intents( jsonFormat=True )
847 intentCheck = main.FALSE
848 if "Error" in ONOS1Intents or not ONOS1Intents\
849 or "Error" in ONOS2Intents or not ONOS2Intents\
850 or "Error" in ONOS3Intents or not ONOS3Intents\
851 or "Error" in ONOS4Intents or not ONOS4Intents\
852 or "Error" in ONOS5Intents or not ONOS5Intents\
853 or "Error" in ONOS6Intents or not ONOS6Intents\
854 or "Error" in ONOS7Intents or not ONOS7Intents:
Jon Hall6aec96b2015-01-19 14:49:31 -0800855 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800856 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
857 main.log.warn( "ONOS2 intents response: " + repr( ONOS2Intents ) )
858 main.log.warn( "ONOS3 intents response: " + repr( ONOS3Intents ) )
859 main.log.warn( "ONOS4 intents response: " + repr( ONOS4Intents ) )
860 main.log.warn( "ONOS5 intents response: " + repr( ONOS5Intents ) )
861 main.log.warn( "ONOS6 intents response: " + repr( ONOS6Intents ) )
862 main.log.warn( "ONOS7 intents response: " + repr( ONOS7Intents ) )
863 elif ONOS1Intents == ONOS2Intents\
864 and ONOS1Intents == ONOS3Intents\
865 and ONOS1Intents == ONOS4Intents\
866 and ONOS1Intents == ONOS5Intents\
867 and ONOS1Intents == ONOS6Intents\
868 and ONOS1Intents == ONOS7Intents:
869 intentState = ONOS1Intents
870 intentCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800871 main.log.report( "Intents are consistent across all ONOS nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800872 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800873 main.log.warn(
874 "ONOS1 intents: ",
875 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800876 json.loads( ONOS1Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800877 sort_keys=True,
878 indent=4,
879 separators=(
880 ',',
881 ': ' ) ) )
882 main.log.warn(
883 "ONOS2 intents: ",
884 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800885 json.loads( ONOS2Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800886 sort_keys=True,
887 indent=4,
888 separators=(
889 ',',
890 ': ' ) ) )
891 main.log.warn(
892 "ONOS3 intents: ",
893 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800894 json.loads( ONOS3Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800895 sort_keys=True,
896 indent=4,
897 separators=(
898 ',',
899 ': ' ) ) )
900 main.log.warn(
901 "ONOS4 intents: ",
902 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800903 json.loads( ONOS4Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800904 sort_keys=True,
905 indent=4,
906 separators=(
907 ',',
908 ': ' ) ) )
909 main.log.warn(
910 "ONOS5 intents: ",
911 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800912 json.loads( ONOS5Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800913 sort_keys=True,
914 indent=4,
915 separators=(
916 ',',
917 ': ' ) ) )
918 main.log.warn(
919 "ONOS6 intents: ",
920 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800921 json.loads( ONOS6Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800922 sort_keys=True,
923 indent=4,
924 separators=(
925 ',',
926 ': ' ) ) )
927 main.log.warn(
928 "ONOS7 intents: ",
929 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800930 json.loads( ONOS7Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800931 sort_keys=True,
932 indent=4,
933 separators=(
934 ',',
935 ': ' ) ) )
936 utilities.assert_equals(
937 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800938 actual=intentCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800939 onpass="Intents are consistent across all ONOS nodes",
940 onfail="ONOS nodes have different views of intents" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800941
Jon Hall6aec96b2015-01-19 14:49:31 -0800942 main.step( "Get the flows from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800943 global flowState
944 flowState = []
Jon Hall8f89dda2015-01-22 16:03:33 -0800945 flowCheck = main.FALSE
Jon Hall58c76b72015-02-23 11:09:24 -0800946 try:
947 ONOS1Flows = main.ONOScli1.flows( jsonFormat=True )
948 ONOS2Flows = main.ONOScli2.flows( jsonFormat=True )
949 ONOS3Flows = main.ONOScli3.flows( jsonFormat=True )
950 ONOS4Flows = main.ONOScli4.flows( jsonFormat=True )
951 ONOS5Flows = main.ONOScli5.flows( jsonFormat=True )
952 ONOS6Flows = main.ONOScli6.flows( jsonFormat=True )
953 ONOS7Flows = main.ONOScli7.flows( jsonFormat=True )
954 assert ONOS1Flows, "ONOS1 Flows should not be empty"
955 assert ONOS2Flows, "ONOS2 Flows should not be empty"
956 assert ONOS3Flows, "ONOS3 Flows should not be empty"
957 assert ONOS4Flows, "ONOS4 Flows should not be empty"
958 assert ONOS5Flows, "ONOS5 Flows should not be empty"
959 assert ONOS6Flows, "ONOS6 Flows should not be empty"
960 assert ONOS7Flows, "ONOS7 Flows should not be empty"
961 assert "Error" not in ONOS1Flows, "ONOS1 Flows contains 'Error'"
962 assert "Error" not in ONOS2Flows, "ONOS2 Flows contains 'Error'"
963 assert "Error" not in ONOS3Flows, "ONOS3 Flows contains 'Error'"
964 assert "Error" not in ONOS4Flows, "ONOS4 Flows contains 'Error'"
965 assert "Error" not in ONOS5Flows, "ONOS5 Flows contains 'Error'"
966 assert "Error" not in ONOS6Flows, "ONOS6 Flows contains 'Error'"
967 assert "Error" not in ONOS7Flows, "ONOS7 Flows contains 'Error'"
968 ONOS1FlowsJson = json.loads( ONOS1Flows )
969 ONOS2FlowsJson = json.loads( ONOS2Flows )
970 ONOS3FlowsJson = json.loads( ONOS3Flows )
971 ONOS4FlowsJson = json.loads( ONOS4Flows )
972 ONOS5FlowsJson = json.loads( ONOS5Flows )
973 ONOS6FlowsJson = json.loads( ONOS6Flows )
974 ONOS7FlowsJson = json.loads( ONOS7Flows )
975 except ( ValueError, AssertionError ): # From json.loads, or asserts
976 main.log.exception( "One or more 'flows' responses from " +
977 "ONOS couldn't be decoded." )
Jon Hall8f89dda2015-01-22 16:03:33 -0800978 main.log.warn( "ONOS1 flows repsponse: " + ONOS1Flows )
979 main.log.warn( "ONOS2 flows repsponse: " + ONOS2Flows )
980 main.log.warn( "ONOS3 flows repsponse: " + ONOS3Flows )
981 main.log.warn( "ONOS4 flows repsponse: " + ONOS4Flows )
982 main.log.warn( "ONOS5 flows repsponse: " + ONOS5Flows )
983 main.log.warn( "ONOS6 flows repsponse: " + ONOS6Flows )
984 main.log.warn( "ONOS7 flows repsponse: " + ONOS7Flows )
Jon Hall58c76b72015-02-23 11:09:24 -0800985 else: # No exceptions
986 if len( ONOS1FlowsJson ) == len( ONOS2FlowsJson )\
987 and len( ONOS1FlowsJson ) == len( ONOS3FlowsJson )\
988 and len( ONOS1FlowsJson ) == len( ONOS4FlowsJson )\
989 and len( ONOS1FlowsJson ) == len( ONOS5FlowsJson )\
990 and len( ONOS1FlowsJson ) == len( ONOS6FlowsJson )\
991 and len( ONOS1FlowsJson ) == len( ONOS7FlowsJson ):
Jon Hall6aec96b2015-01-19 14:49:31 -0800992 # TODO: Do a better check, maybe compare flows on switches?
Jon Hall58c76b72015-02-23 11:09:24 -0800993 # NOTE Possible issue with this not always being set?
994 flowState = ONOS1Flows
995 flowCheck = main.TRUE
996 main.log.report( "Flow count is consistent across all" +
997 " ONOS nodes" )
998 else:
999 main.log.warn( "ONOS1 flows: " +
1000 json.dumps( ONOS1FlowsJson, sort_keys=True,
1001 indent=4,
1002 separators=( ',', ': ' ) ) )
1003 main.log.warn( "ONOS2 flows: " +
1004 json.dumps( ONOS2FlowsJson, sort_keys=True,
1005 indent=4,
1006 separators=( ',', ': ' ) ) )
1007 main.log.warn( "ONOS3 flows: " +
1008 json.dumps( ONOS3FlowsJson, sort_keys=True,
1009 indent=4,
1010 separators=( ',', ': ' ) ) )
1011 main.log.warn( "ONOS4 flows: " +
1012 json.dumps( ONOS4FlowsJson, sort_keys=True,
1013 indent=4,
1014 separators=( ',', ': ' ) ) )
1015 main.log.warn( "ONOS5 flows: " +
1016 json.dumps( ONOS5FlowsJson, sort_keys=True,
1017 indent=4,
1018 separators=( ',', ': ' ) ) )
1019 main.log.warn( "ONOS6 flows: " +
1020 json.dumps( ONOS6FlowsJson, sort_keys=True,
1021 indent=4,
1022 separators=( ',', ': ' ) ) )
1023 main.log.warn( "ONOS7 flows: " +
1024 json.dumps( ONOS7FlowsJson, sort_keys=True,
1025 indent=4,
1026 separators=( ',', ': ' ) ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001027 utilities.assert_equals(
1028 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001029 actual=flowCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -08001030 onpass="The flow count is consistent across all ONOS nodes",
1031 onfail="ONOS nodes have different flow counts" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001032
Jon Hall6aec96b2015-01-19 14:49:31 -08001033 main.step( "Get the OF Table entries" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001034 global flows
Jon Hall6aec96b2015-01-19 14:49:31 -08001035 flows = []
1036 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -08001037 flows.append( main.Mininet2.getFlowTable( 1.3, "s" + str( i ) ) )
Jon Hall58c76b72015-02-23 11:09:24 -08001038 if flowCheck == main.FALSE:
1039 for table in flows:
1040 main.log.warn( table )
Jon Hall6aec96b2015-01-19 14:49:31 -08001041 # TODO: Compare switch flow tables with ONOS flow tables
Jon Hall73cf9cc2014-11-20 22:28:38 -08001042
Jon Hall6aec96b2015-01-19 14:49:31 -08001043 main.step( "Start continuous pings" )
1044 main.Mininet2.pingLong(
1045 src=main.params[ 'PING' ][ 'source1' ],
1046 target=main.params[ 'PING' ][ 'target1' ],
1047 pingTime=500 )
1048 main.Mininet2.pingLong(
1049 src=main.params[ 'PING' ][ 'source2' ],
1050 target=main.params[ 'PING' ][ 'target2' ],
1051 pingTime=500 )
1052 main.Mininet2.pingLong(
1053 src=main.params[ 'PING' ][ 'source3' ],
1054 target=main.params[ 'PING' ][ 'target3' ],
1055 pingTime=500 )
1056 main.Mininet2.pingLong(
1057 src=main.params[ 'PING' ][ 'source4' ],
1058 target=main.params[ 'PING' ][ 'target4' ],
1059 pingTime=500 )
1060 main.Mininet2.pingLong(
1061 src=main.params[ 'PING' ][ 'source5' ],
1062 target=main.params[ 'PING' ][ 'target5' ],
1063 pingTime=500 )
1064 main.Mininet2.pingLong(
1065 src=main.params[ 'PING' ][ 'source6' ],
1066 target=main.params[ 'PING' ][ 'target6' ],
1067 pingTime=500 )
1068 main.Mininet2.pingLong(
1069 src=main.params[ 'PING' ][ 'source7' ],
1070 target=main.params[ 'PING' ][ 'target7' ],
1071 pingTime=500 )
1072 main.Mininet2.pingLong(
1073 src=main.params[ 'PING' ][ 'source8' ],
1074 target=main.params[ 'PING' ][ 'target8' ],
1075 pingTime=500 )
1076 main.Mininet2.pingLong(
1077 src=main.params[ 'PING' ][ 'source9' ],
1078 target=main.params[ 'PING' ][ 'target9' ],
1079 pingTime=500 )
1080 main.Mininet2.pingLong(
1081 src=main.params[ 'PING' ][ 'source10' ],
1082 target=main.params[ 'PING' ][ 'target10' ],
1083 pingTime=500 )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001084
Jon Hall6aec96b2015-01-19 14:49:31 -08001085 main.step( "Create TestONTopology object" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001086 ctrls = []
1087 count = 1
1088 while True:
1089 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -08001090 if ( 'ip' + str( count ) ) in main.params[ 'CTRL' ]:
1091 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
1092 temp = temp + ( "ONOS" + str( count ), )
1093 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
1094 temp = temp + \
1095 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
1096 ctrls.append( temp )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001097 count = count + 1
1098 else:
1099 break
Jon Hall6aec96b2015-01-19 14:49:31 -08001100 MNTopo = TestONTopology(
1101 main.Mininet1,
1102 ctrls ) # can also add Intent API info for intent operations
Jon Hall73cf9cc2014-11-20 22:28:38 -08001103
Jon Hall6aec96b2015-01-19 14:49:31 -08001104 main.step( "Collecting topology information from ONOS" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001105 devices = []
1106 devices.append( main.ONOScli1.devices() )
1107 devices.append( main.ONOScli2.devices() )
1108 devices.append( main.ONOScli3.devices() )
1109 devices.append( main.ONOScli4.devices() )
1110 devices.append( main.ONOScli5.devices() )
1111 devices.append( main.ONOScli6.devices() )
1112 devices.append( main.ONOScli7.devices() )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001113 hosts = []
Jon Hall58c76b72015-02-23 11:09:24 -08001114 hosts.append( json.loads( main.ONOScli1.hosts() ) )
1115 hosts.append( json.loads( main.ONOScli2.hosts() ) )
1116 hosts.append( json.loads( main.ONOScli3.hosts() ) )
1117 hosts.append( json.loads( main.ONOScli4.hosts() ) )
1118 hosts.append( json.loads( main.ONOScli5.hosts() ) )
1119 hosts.append( json.loads( main.ONOScli6.hosts() ) )
1120 hosts.append( json.loads( main.ONOScli7.hosts() ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001121 ports = []
1122 ports.append( main.ONOScli1.ports() )
1123 ports.append( main.ONOScli2.ports() )
1124 ports.append( main.ONOScli3.ports() )
1125 ports.append( main.ONOScli4.ports() )
1126 ports.append( main.ONOScli5.ports() )
1127 ports.append( main.ONOScli6.ports() )
1128 ports.append( main.ONOScli7.ports() )
1129 links = []
1130 links.append( main.ONOScli1.links() )
1131 links.append( main.ONOScli2.links() )
1132 links.append( main.ONOScli3.links() )
1133 links.append( main.ONOScli4.links() )
1134 links.append( main.ONOScli5.links() )
1135 links.append( main.ONOScli6.links() )
1136 links.append( main.ONOScli7.links() )
Jon Hall94fd0472014-12-08 11:52:42 -08001137 clusters = []
1138 clusters.append( main.ONOScli1.clusters() )
1139 clusters.append( main.ONOScli2.clusters() )
1140 clusters.append( main.ONOScli3.clusters() )
1141 clusters.append( main.ONOScli4.clusters() )
1142 clusters.append( main.ONOScli5.clusters() )
1143 clusters.append( main.ONOScli6.clusters() )
1144 clusters.append( main.ONOScli7.clusters() )
Jon Hall529a37f2015-01-28 10:02:00 -08001145 # Compare json objects for hosts and dataplane clusters
Jon Hall94fd0472014-12-08 11:52:42 -08001146
Jon Hall6aec96b2015-01-19 14:49:31 -08001147 # hosts
Jon Hall8f89dda2015-01-22 16:03:33 -08001148 consistentHostsResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -08001149 for controller in range( len( hosts ) ):
Jon Hall8f89dda2015-01-22 16:03:33 -08001150 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001151 if "Error" not in hosts[ controller ]:
1152 if hosts[ controller ] == hosts[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001153 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001154 else: # hosts not consistent
1155 main.log.report( "hosts from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001156 controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001157 " is inconsistent with ONOS1" )
1158 main.log.warn( repr( hosts[ controller ] ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001159 consistentHostsResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001160
1161 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001162 main.log.report( "Error in getting ONOS hosts from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001163 controllerStr )
1164 consistentHostsResult = main.FALSE
1165 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001166 " hosts response: " +
1167 repr( hosts[ controller ] ) )
1168 utilities.assert_equals(
1169 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001170 actual=consistentHostsResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001171 onpass="Hosts view is consistent across all ONOS nodes",
1172 onfail="ONOS nodes have different views of hosts" )
Jon Hall94fd0472014-12-08 11:52:42 -08001173
Jon Hall58c76b72015-02-23 11:09:24 -08001174 ipResult = main.TRUE
1175 for controller in range( 0, len( hosts ) ):
1176 controllerStr = str( controller + 1 )
1177 for host in hosts[ controller ]:
1178 if host.get( 'ips', [] ) == []:
1179 main.log.error(
1180 "DEBUG:Error with host ips on controller" +
1181 controllerStr + ": " + str( host ) )
1182 ipResult = main.FALSE
1183 utilities.assert_equals(
1184 expect=main.TRUE,
1185 actual=ipResult,
1186 onpass="The ips of the hosts aren't empty",
1187 onfail="The ip of at least one host is missing" )
1188
Jon Hall6aec96b2015-01-19 14:49:31 -08001189 # Strongly connected clusters of devices
Jon Hall8f89dda2015-01-22 16:03:33 -08001190 consistentClustersResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -08001191 for controller in range( len( clusters ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001192 if "Error" not in clusters[ controller ]:
1193 if clusters[ controller ] == clusters[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001194 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001195 else: # clusters not consistent
1196 main.log.report( "clusters from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001197 controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001198 " is inconsistent with ONOS1" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001199 consistentClustersResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001200
1201 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001202 main.log.report( "Error in getting dataplane clusters " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001203 "from ONOS" + controllerStr )
1204 consistentClustersResult = main.FALSE
1205 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001206 " clusters response: " +
1207 repr( clusters[ controller ] ) )
1208 utilities.assert_equals(
1209 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001210 actual=consistentClustersResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001211 onpass="Clusters view is consistent across all ONOS nodes",
1212 onfail="ONOS nodes have different views of clusters" )
1213 # there should always only be one cluster
Jon Hall8f89dda2015-01-22 16:03:33 -08001214 numClusters = len( json.loads( clusters[ 0 ] ) )
Jon Hall58c76b72015-02-23 11:09:24 -08001215 clusterResults = main.FALSE
1216 if numClusters == 1:
1217 clusterResults = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001218 utilities.assert_equals(
1219 expect=1,
Jon Hall8f89dda2015-01-22 16:03:33 -08001220 actual=numClusters,
Jon Hall6aec96b2015-01-19 14:49:31 -08001221 onpass="ONOS shows 1 SCC",
Jon Hall58c76b72015-02-23 11:09:24 -08001222 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
Jon Hall94fd0472014-12-08 11:52:42 -08001223
Jon Hall6aec96b2015-01-19 14:49:31 -08001224 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001225 devicesResults = main.TRUE
1226 portsResults = main.TRUE
1227 linksResults = main.TRUE
1228 for controller in range( numControllers ):
1229 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001230 if devices[ controller ] or "Error" not in devices[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001231 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -08001232 MNTopo,
1233 json.loads(
1234 devices[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001235 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001236 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001237 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001238 actual=currentDevicesResult,
1239 onpass="ONOS" + controllerStr +
1240 " Switches view is correct",
1241 onfail="ONOS" + controllerStr +
1242 " Switches view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001243
Jon Hall6aec96b2015-01-19 14:49:31 -08001244 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001245 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -08001246 MNTopo,
1247 json.loads(
1248 ports[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001249 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001250 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001251 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001252 actual=currentPortsResult,
1253 onpass="ONOS" + controllerStr +
1254 " ports view is correct",
1255 onfail="ONOS" + controllerStr +
1256 " ports view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001257
Jon Hall6aec96b2015-01-19 14:49:31 -08001258 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001259 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -08001260 MNTopo,
1261 json.loads(
1262 links[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001263 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001264 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001265 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001266 actual=currentLinksResult,
1267 onpass="ONOS" + controllerStr +
1268 " links view is correct",
1269 onfail="ONOS" + controllerStr +
1270 " links view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001271
Jon Hall8f89dda2015-01-22 16:03:33 -08001272 devicesResults = devicesResults and currentDevicesResult
1273 portsResults = portsResults and currentPortsResult
1274 linksResults = linksResults and currentLinksResult
Jon Hall73cf9cc2014-11-20 22:28:38 -08001275
Jon Hall8f89dda2015-01-22 16:03:33 -08001276 topoResult = devicesResults and portsResults and linksResults\
Jon Hall58c76b72015-02-23 11:09:24 -08001277 and consistentHostsResult and consistentClustersResult\
1278 and clusterResults and ipResult
Jon Hall8f89dda2015-01-22 16:03:33 -08001279 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
Jon Hall58c76b72015-02-23 11:09:24 -08001280 onpass="Topology Check Test successful",
1281 onfail="Topology Check Test NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001282
Jon Hall8f89dda2015-01-22 16:03:33 -08001283 finalAssert = main.TRUE
1284 finalAssert = finalAssert and topoResult and flowCheck \
Jon Hall58c76b72015-02-23 11:09:24 -08001285 and intentCheck and consistentMastership and rolesNotNull
Jon Hall8f89dda2015-01-22 16:03:33 -08001286 utilities.assert_equals( expect=main.TRUE, actual=finalAssert,
Jon Hall58c76b72015-02-23 11:09:24 -08001287 onpass="State check successful",
1288 onfail="State check NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001289
Jon Hall6aec96b2015-01-19 14:49:31 -08001290 def CASE6( self, main ):
1291 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001292 The Failure case.
Jon Hall6aec96b2015-01-19 14:49:31 -08001293 """
Jon Hall94fd0472014-12-08 11:52:42 -08001294 import time
Jon Hall6aec96b2015-01-19 14:49:31 -08001295 main.log.report( "Killing 3 ONOS nodes" )
1296 main.log.case( "Restart minority of ONOS nodes" )
1297 # TODO: Randomize these nodes
Jon Hall8f89dda2015-01-22 16:03:33 -08001298 main.ONOSbench.onosKill( ONOS1Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -08001299 time.sleep( 10 )
Jon Hall8f89dda2015-01-22 16:03:33 -08001300 main.ONOSbench.onosKill( ONOS2Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -08001301 time.sleep( 10 )
Jon Hall8f89dda2015-01-22 16:03:33 -08001302 main.ONOSbench.onosKill( ONOS3Ip )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001303
Jon Hall6aec96b2015-01-19 14:49:31 -08001304 main.step( "Checking if ONOS is up yet" )
Jon Hallffb386d2014-11-21 13:43:38 -08001305 count = 0
Jon Hall8f89dda2015-01-22 16:03:33 -08001306 onosIsupResult = main.FALSE
1307 while onosIsupResult == main.FALSE and count < 10:
1308 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
1309 onos2Isup = main.ONOSbench.isup( ONOS2Ip )
1310 onos3Isup = main.ONOSbench.isup( ONOS3Ip )
1311 onosIsupResult = onos1Isup and onos2Isup and onos3Isup
Jon Hallffb386d2014-11-21 13:43:38 -08001312 count = count + 1
Jon Hall73cf9cc2014-11-20 22:28:38 -08001313 # TODO: if it becomes an issue, we can retry this step a few times
1314
Jon Hall8f89dda2015-01-22 16:03:33 -08001315 cliResult1 = main.ONOScli1.startOnosCli( ONOS1Ip )
1316 cliResult2 = main.ONOScli2.startOnosCli( ONOS2Ip )
1317 cliResult3 = main.ONOScli3.startOnosCli( ONOS3Ip )
1318 cliResults = cliResult1 and cliResult2 and cliResult3
Jon Hall73cf9cc2014-11-20 22:28:38 -08001319
Jon Hall21270ac2015-02-16 17:59:55 -08001320 # Grab the time of restart so we chan check how long the gossip
1321 # protocol has had time to work
1322 main.restartTime = time.time()
Jon Hall8f89dda2015-01-22 16:03:33 -08001323 caseResults = main.TRUE and onosIsupResult and cliResults
1324 utilities.assert_equals( expect=main.TRUE, actual=caseResults,
Jon Hall58c76b72015-02-23 11:09:24 -08001325 onpass="ONOS restart successful",
1326 onfail="ONOS restart NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001327
Jon Hall6aec96b2015-01-19 14:49:31 -08001328 def CASE7( self, main ):
1329 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001330 Check state after ONOS failure
Jon Hall6aec96b2015-01-19 14:49:31 -08001331 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001332 import json
Jon Hall6aec96b2015-01-19 14:49:31 -08001333 main.case( "Running ONOS Constant State Tests" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001334
Jon Hall6aec96b2015-01-19 14:49:31 -08001335 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -08001336 ONOS1MasterNotNull = main.ONOScli1.rolesNotNull()
1337 ONOS2MasterNotNull = main.ONOScli2.rolesNotNull()
1338 ONOS3MasterNotNull = main.ONOScli3.rolesNotNull()
1339 ONOS4MasterNotNull = main.ONOScli4.rolesNotNull()
1340 ONOS5MasterNotNull = main.ONOScli5.rolesNotNull()
1341 ONOS6MasterNotNull = main.ONOScli6.rolesNotNull()
1342 ONOS7MasterNotNull = main.ONOScli7.rolesNotNull()
1343 rolesNotNull = ONOS1MasterNotNull and ONOS2MasterNotNull and\
1344 ONOS3MasterNotNull and ONOS4MasterNotNull and\
1345 ONOS5MasterNotNull and ONOS6MasterNotNull and\
1346 ONOS7MasterNotNull
Jon Hall6aec96b2015-01-19 14:49:31 -08001347 utilities.assert_equals(
1348 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001349 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -08001350 onpass="Each device has a master",
1351 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -08001352
Jon Hall6aec96b2015-01-19 14:49:31 -08001353 main.step( "Check if switch roles are consistent across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001354 ONOS1Mastership = main.ONOScli1.roles()
1355 ONOS2Mastership = main.ONOScli2.roles()
1356 ONOS3Mastership = main.ONOScli3.roles()
1357 ONOS4Mastership = main.ONOScli4.roles()
1358 ONOS5Mastership = main.ONOScli5.roles()
1359 ONOS6Mastership = main.ONOScli6.roles()
1360 ONOS7Mastership = main.ONOScli7.roles()
Jon Hall8f89dda2015-01-22 16:03:33 -08001361 if "Error" in ONOS1Mastership or not ONOS1Mastership\
1362 or "Error" in ONOS2Mastership or not ONOS2Mastership\
1363 or "Error" in ONOS3Mastership or not ONOS3Mastership\
1364 or "Error" in ONOS4Mastership or not ONOS4Mastership\
1365 or "Error" in ONOS5Mastership or not ONOS5Mastership\
1366 or "Error" in ONOS6Mastership or not ONOS6Mastership\
1367 or "Error" in ONOS7Mastership or not ONOS7Mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -08001368 main.log.error( "Error in getting ONOS mastership" )
1369 main.log.warn( "ONOS1 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001370 repr( ONOS1Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001371 main.log.warn( "ONOS2 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001372 repr( ONOS2Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001373 main.log.warn( "ONOS3 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001374 repr( ONOS3Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001375 main.log.warn( "ONOS4 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001376 repr( ONOS4Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001377 main.log.warn( "ONOS5 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001378 repr( ONOS5Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001379 main.log.warn( "ONOS6 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001380 repr( ONOS6Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001381 main.log.warn( "ONOS7 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001382 repr( ONOS7Mastership ) )
1383 consistentMastership = main.FALSE
1384 elif ONOS1Mastership == ONOS2Mastership\
1385 and ONOS1Mastership == ONOS3Mastership\
1386 and ONOS1Mastership == ONOS4Mastership\
1387 and ONOS1Mastership == ONOS5Mastership\
1388 and ONOS1Mastership == ONOS6Mastership\
1389 and ONOS1Mastership == ONOS7Mastership:
1390 consistentMastership = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001391 main.log.report(
1392 "Switch roles are consistent across all ONOS nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001393 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001394 main.log.warn( "ONOS1 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001395 json.loads( ONOS1Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001396 separators=( ',', ': ' ) ) )
1397 main.log.warn( "ONOS2 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001398 json.loads( ONOS2Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001399 separators=( ',', ': ' ) ) )
1400 main.log.warn( "ONOS3 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001401 json.loads( ONOS3Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001402 separators=( ',', ': ' ) ) )
1403 main.log.warn( "ONOS4 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001404 json.loads( ONOS4Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001405 separators=( ',', ': ' ) ) )
1406 main.log.warn( "ONOS5 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001407 json.loads( ONOS5Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001408 separators=( ',', ': ' ) ) )
1409 main.log.warn( "ONOS6 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001410 json.loads( ONOS6Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001411 separators=( ',', ': ' ) ) )
1412 main.log.warn( "ONOS7 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001413 json.loads( ONOS7Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001414 separators=( ',', ': ' ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001415 consistentMastership = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001416 utilities.assert_equals(
1417 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001418 actual=consistentMastership,
Jon Hall6aec96b2015-01-19 14:49:31 -08001419 onpass="Switch roles are consistent across all ONOS nodes",
1420 onfail="ONOS nodes have different views of switch roles" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001421
1422 description2 = "Compare switch roles from before failure"
Jon Hall6aec96b2015-01-19 14:49:31 -08001423 main.step( description2 )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001424
Jon Hall8f89dda2015-01-22 16:03:33 -08001425 currentJson = json.loads( ONOS1Mastership )
1426 oldJson = json.loads( mastershipState )
1427 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001428 for i in range( 1, 29 ):
1429 switchDPID = str(
1430 main.Mininet1.getSwitchDPID(
1431 switch="s" +
1432 str( i ) ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001433
Jon Hall8f89dda2015-01-22 16:03:33 -08001434 current = [ switch[ 'master' ] for switch in currentJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001435 if switchDPID in switch[ 'id' ] ]
Jon Hall8f89dda2015-01-22 16:03:33 -08001436 old = [ switch[ 'master' ] for switch in oldJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001437 if switchDPID in switch[ 'id' ] ]
Jon Hall73cf9cc2014-11-20 22:28:38 -08001438 if current == old:
Jon Hall8f89dda2015-01-22 16:03:33 -08001439 mastershipCheck = mastershipCheck and main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001440 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001441 main.log.warn( "Mastership of switch %s changed" % switchDPID )
Jon Hall8f89dda2015-01-22 16:03:33 -08001442 mastershipCheck = main.FALSE
1443 if mastershipCheck == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001444 main.log.report( "Mastership of Switches was not changed" )
1445 utilities.assert_equals(
1446 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001447 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -08001448 onpass="Mastership of Switches was not changed",
1449 onfail="Mastership of some switches changed" )
1450 # NOTE: we expect mastership to change on controller failure
Jon Hall8f89dda2015-01-22 16:03:33 -08001451 mastershipCheck = consistentMastership
Jon Hall73cf9cc2014-11-20 22:28:38 -08001452
Jon Hall58c76b72015-02-23 11:09:24 -08001453 main.step( "Get the intents and compare across all nodes" )
1454 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
1455 ONOS2Intents = main.ONOScli2.intents( jsonFormat=True )
1456 ONOS3Intents = main.ONOScli3.intents( jsonFormat=True )
1457 ONOS4Intents = main.ONOScli4.intents( jsonFormat=True )
1458 ONOS5Intents = main.ONOScli5.intents( jsonFormat=True )
1459 ONOS6Intents = main.ONOScli6.intents( jsonFormat=True )
1460 ONOS7Intents = main.ONOScli7.intents( jsonFormat=True )
1461 intentCheck = main.FALSE
1462 if "Error" in ONOS1Intents or not ONOS1Intents\
1463 or "Error" in ONOS2Intents or not ONOS2Intents\
1464 or "Error" in ONOS3Intents or not ONOS3Intents\
1465 or "Error" in ONOS4Intents or not ONOS4Intents\
1466 or "Error" in ONOS5Intents or not ONOS5Intents\
1467 or "Error" in ONOS6Intents or not ONOS6Intents\
1468 or "Error" in ONOS7Intents or not ONOS7Intents:
1469 main.log.report( "Error in getting ONOS intents" )
1470 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
1471 main.log.warn( "ONOS2 intents response: " + repr( ONOS2Intents ) )
1472 main.log.warn( "ONOS3 intents response: " + repr( ONOS3Intents ) )
1473 main.log.warn( "ONOS4 intents response: " + repr( ONOS4Intents ) )
1474 main.log.warn( "ONOS5 intents response: " + repr( ONOS5Intents ) )
1475 main.log.warn( "ONOS6 intents response: " + repr( ONOS6Intents ) )
1476 main.log.warn( "ONOS7 intents response: " + repr( ONOS7Intents ) )
1477 elif ONOS1Intents == ONOS2Intents\
1478 and ONOS1Intents == ONOS3Intents\
1479 and ONOS1Intents == ONOS4Intents\
1480 and ONOS1Intents == ONOS5Intents\
1481 and ONOS1Intents == ONOS6Intents\
1482 and ONOS1Intents == ONOS7Intents:
1483 intentCheck = main.TRUE
1484 main.log.report( "Intents are consistent across all ONOS nodes" )
1485 else:
1486 main.log.warn( "ONOS1 intents: " )
1487 print json.dumps( json.loads( ONOS1Intents ), sort_keys=True,
1488 indent=4, separators=( ',', ': ' ) )
1489 main.log.warn( "ONOS2 intents: " )
1490 print json.dumps( json.loads( ONOS2Intents ), sort_keys=True,
1491 indent=4, separators=( ',', ': ' ) )
1492 main.log.warn( "ONOS3 intents: " )
1493 print json.dumps( json.loads( ONOS3Intents ), sort_keys=True,
1494 indent=4, separators=( ',', ': ' ) )
1495 main.log.warn( "ONOS4 intents: " )
1496 print json.dumps( json.loads( ONOS4Intents ), sort_keys=True,
1497 indent=4, separators=( ',', ': ' ) )
1498 main.log.warn( "ONOS5 intents: " )
1499 print json.dumps( json.loads( ONOS5Intents ), sort_keys=True,
1500 indent=4, separators=( ',', ': ' ) )
1501 main.log.warn( "ONOS6 intents: " )
1502 print json.dumps( json.loads( ONOS6Intents ), sort_keys=True,
1503 indent=4, separators=( ',', ': ' ) )
1504 main.log.warn( "ONOS7 intents: " )
1505 print json.dumps( json.loads( ONOS7Intents ), sort_keys=True,
1506 indent=4, separators=( ',', ': ' ) )
1507 utilities.assert_equals(
1508 expect=main.TRUE,
1509 actual=intentCheck,
1510 onpass="Intents are consistent across all ONOS nodes",
1511 onfail="ONOS nodes have different views of intents" )
1512 # Print the intent states
1513 intents = []
1514 intents.append( ONOS1Intents )
1515 intents.append( ONOS2Intents )
1516 intents.append( ONOS3Intents )
1517 intents.append( ONOS4Intents )
1518 intents.append( ONOS5Intents )
1519 intents.append( ONOS6Intents )
1520 intents.append( ONOS7Intents )
1521 intentStates = []
1522 for node in intents: # Iter through ONOS nodes
1523 nodeStates = []
1524 # Iter through intents of a node
1525 for intent in json.loads( node ):
1526 nodeStates.append( intent[ 'state' ] )
1527 intentStates.append( nodeStates )
1528 out = [ (i, nodeStates.count( i ) ) for i in set( nodeStates ) ]
1529 main.log.info( dict( out ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001530
Jon Hall58c76b72015-02-23 11:09:24 -08001531 # NOTE: Store has no durability, so intents are lost across system
1532 # restarts
1533 main.step( "Compare current intents with intents before the failure" )
1534 # NOTE: this requires case 5 to pass for intentState to be set.
1535 # maybe we should stop the test if that fails?
1536 sameIntents = main.TRUE
1537 if intentState and intentState == ONOS1Intents:
Jon Hall21270ac2015-02-16 17:59:55 -08001538 sameIntents = main.TRUE
Jon Hall58c76b72015-02-23 11:09:24 -08001539 main.log.report( "Intents are consistent with before failure" )
1540 # TODO: possibly the states have changed? we may need to figure out
1541 # what the aceptable states are
1542 else:
1543 try:
1544 main.log.warn( "ONOS1 intents: " )
1545 print json.dumps( json.loads( ONOS1Intents ),
1546 sort_keys=True, indent=4,
1547 separators=( ',', ': ' ) )
1548 except:
1549 pass
1550 sameIntents = main.FALSE
1551 utilities.assert_equals(
1552 expect=main.TRUE,
1553 actual=sameIntents,
1554 onpass="Intents are consistent with before failure",
1555 onfail="The Intents changed during failure" )
1556 intentCheck = intentCheck and sameIntents
Jon Hall21270ac2015-02-16 17:59:55 -08001557
Jon Hall58c76b72015-02-23 11:09:24 -08001558 main.step( "Get the OF Table entries and compare to before " +
1559 "component failure" )
1560 FlowTables = main.TRUE
1561 flows2 = []
1562 for i in range( 28 ):
1563 main.log.info( "Checking flow table on s" + str( i + 1 ) )
1564 tmpFlows = main.Mininet2.getFlowTable( 1.3, "s" + str( i + 1 ) )
1565 flows2.append( tmpFlows )
1566 tempResult = main.Mininet2.flowComp(
1567 flow1=flows[ i ],
1568 flow2=tmpFlows )
1569 FlowTables = FlowTables and tempResult
1570 if FlowTables == main.FALSE:
1571 main.log.info( "Differences in flow table for switch: s" +
1572 str( i + 1 ) )
1573 if FlowTables == main.TRUE:
1574 main.log.report( "No changes were found in the flow tables" )
1575 utilities.assert_equals(
1576 expect=main.TRUE,
1577 actual=FlowTables,
1578 onpass="No changes were found in the flow tables",
1579 onfail="Changes were found in the flow tables" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001580
Jon Hall6aec96b2015-01-19 14:49:31 -08001581 main.step( "Check the continuous pings to ensure that no packets " +
1582 "were dropped during component failure" )
1583 # FIXME: This check is always failing. Investigate cause
1584 # NOTE: this may be something to do with file permsissions
Jon Hall73cf9cc2014-11-20 22:28:38 -08001585 # or slight change in format
Jon Hall6aec96b2015-01-19 14:49:31 -08001586 main.Mininet2.pingKill(
1587 main.params[ 'TESTONUSER' ],
1588 main.params[ 'TESTONIP' ] )
Jon Hall8f89dda2015-01-22 16:03:33 -08001589 LossInPings = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001590 # NOTE: checkForLoss returns main.FALSE with 0% packet loss
1591 for i in range( 8, 18 ):
1592 main.log.info(
1593 "Checking for a loss in pings along flow from s" +
1594 str( i ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001595 LossInPings = main.Mininet2.checkForLoss(
Jon Hall6aec96b2015-01-19 14:49:31 -08001596 "/tmp/ping.h" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001597 str( i ) ) or LossInPings
1598 if LossInPings == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001599 main.log.info( "Loss in ping detected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001600 elif LossInPings == main.ERROR:
Jon Hall6aec96b2015-01-19 14:49:31 -08001601 main.log.info( "There are multiple mininet process running" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001602 elif LossInPings == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001603 main.log.info( "No Loss in the pings" )
1604 main.log.report( "No loss of dataplane connectivity" )
1605 utilities.assert_equals(
1606 expect=main.FALSE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001607 actual=LossInPings,
Jon Hall6aec96b2015-01-19 14:49:31 -08001608 onpass="No Loss of connectivity",
1609 onfail="Loss of dataplane connectivity detected" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001610
Jon Hall6aec96b2015-01-19 14:49:31 -08001611 # Test of LeadershipElection
Jon Hall8f89dda2015-01-22 16:03:33 -08001612 leaderList = []
1613 leaderResult = main.TRUE
1614 for controller in range( 1, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001615 # loop through ONOScli handlers
1616 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001617 leaderN = node.electionTestLeader()
1618 leaderList.append( leaderN )
Jon Hall669173b2014-12-17 11:36:30 -08001619 if leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001620 # error in response
1621 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001622 "electionTestLeader function, check the" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001623 " error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001624 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001625 elif leaderN is None:
1626 main.log.report( "ONOS" + str( controller ) +
1627 " shows no leader for the election-app was" +
1628 " elected after the old one died" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001629 leaderResult = main.FALSE
1630 elif leaderN == ONOS1Ip or leaderN == ONOS2Ip or\
1631 leaderN == ONOS3Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08001632 main.log.report( "ONOS" + str( controller ) +
1633 " shows " + str( leaderN ) +
1634 " as leader for the election-app, but it " +
1635 "was restarted" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001636 leaderResult = main.FALSE
1637 if len( set( leaderList ) ) != 1:
1638 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001639 main.log.error(
1640 "Inconsistent view of leader for the election test app" )
1641 # TODO: print the list
Jon Hall8f89dda2015-01-22 16:03:33 -08001642 if leaderResult:
1643 main.log.report( "Leadership election tests passed( consistent " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001644 "view of leader across listeners and a new " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001645 "leader was re-elected if applicable )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001646 utilities.assert_equals(
1647 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001648 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001649 onpass="Leadership election passed",
1650 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08001651
Jon Hall58c76b72015-02-23 11:09:24 -08001652 result = ( mastershipCheck and intentCheck and FlowTables and
1653 ( not LossInPings ) and rolesNotNull and leaderResult )
Jon Hall6aec96b2015-01-19 14:49:31 -08001654 result = int( result )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001655 if result == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001656 main.log.report( "Constant State Tests Passed" )
1657 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall58c76b72015-02-23 11:09:24 -08001658 onpass="Constant State Tests Passed",
1659 onfail="Constant state tests failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001660
Jon Hall6aec96b2015-01-19 14:49:31 -08001661 def CASE8( self, main ):
1662 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001663 Compare topo
Jon Hall6aec96b2015-01-19 14:49:31 -08001664 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001665 import sys
Jon Hall6aec96b2015-01-19 14:49:31 -08001666 # FIXME add this path to params
1667 sys.path.append( "/home/admin/sts" )
1668 # assumes that sts is already in you PYTHONPATH
1669 from sts.topology.teston_topology import TestONTopology
Jon Hall73cf9cc2014-11-20 22:28:38 -08001670 import json
1671 import time
1672
Jon Hall6aec96b2015-01-19 14:49:31 -08001673 description = "Compare ONOS Topology view to Mininet topology"
1674 main.case( description )
1675 main.log.report( description )
1676 main.step( "Create TestONTopology object" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001677 ctrls = []
1678 count = 1
1679 while True:
1680 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -08001681 if ( 'ip' + str( count ) ) in main.params[ 'CTRL' ]:
1682 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
1683 temp = temp + ( "ONOS" + str( count ), )
1684 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
1685 temp = temp + \
1686 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
1687 ctrls.append( temp )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001688 count = count + 1
1689 else:
1690 break
Jon Hall6aec96b2015-01-19 14:49:31 -08001691 MNTopo = TestONTopology(
1692 main.Mininet1,
1693 ctrls ) # can also add Intent API info for intent operations
Jon Hall73cf9cc2014-11-20 22:28:38 -08001694
Jon Hall6aec96b2015-01-19 14:49:31 -08001695 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001696 devicesResults = main.TRUE
1697 portsResults = main.TRUE
1698 linksResults = main.TRUE
Jon Hall58c76b72015-02-23 11:09:24 -08001699 hostsResults = main.TRUE
Jon Hall8f89dda2015-01-22 16:03:33 -08001700 topoResult = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001701 elapsed = 0
Jon Hallffb386d2014-11-21 13:43:38 -08001702 count = 0
Jon Hall6aec96b2015-01-19 14:49:31 -08001703 main.step( "Collecting topology information from ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001704 startTime = time.time()
Jon Hall21270ac2015-02-16 17:59:55 -08001705 # Give time for Gossip to work
Jon Hall8f89dda2015-01-22 16:03:33 -08001706 while topoResult == main.FALSE and elapsed < 60:
Jon Hallffb386d2014-11-21 13:43:38 -08001707 count = count + 1
Jon Hall94fd0472014-12-08 11:52:42 -08001708 if count > 1:
Jon Hall6aec96b2015-01-19 14:49:31 -08001709 # TODO: Depricate STS usage
Jon Hall58c76b72015-02-23 11:09:24 -08001710 MNTopo = TestONTopology( main.Mininet1, ctrls )
Jon Hall8f89dda2015-01-22 16:03:33 -08001711 cliStart = time.time()
Jon Hall94fd0472014-12-08 11:52:42 -08001712 devices = []
1713 devices.append( main.ONOScli1.devices() )
1714 devices.append( main.ONOScli2.devices() )
1715 devices.append( main.ONOScli3.devices() )
1716 devices.append( main.ONOScli4.devices() )
1717 devices.append( main.ONOScli5.devices() )
1718 devices.append( main.ONOScli6.devices() )
1719 devices.append( main.ONOScli7.devices() )
1720 hosts = []
Jon Hall669173b2014-12-17 11:36:30 -08001721 hosts.append( json.loads( main.ONOScli1.hosts() ) )
1722 hosts.append( json.loads( main.ONOScli2.hosts() ) )
1723 hosts.append( json.loads( main.ONOScli3.hosts() ) )
1724 hosts.append( json.loads( main.ONOScli4.hosts() ) )
1725 hosts.append( json.loads( main.ONOScli5.hosts() ) )
1726 hosts.append( json.loads( main.ONOScli6.hosts() ) )
1727 hosts.append( json.loads( main.ONOScli7.hosts() ) )
Jon Hall58c76b72015-02-23 11:09:24 -08001728 ipResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001729 for controller in range( 0, len( hosts ) ):
Jon Hall8f89dda2015-01-22 16:03:33 -08001730 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001731 for host in hosts[ controller ]:
Jon Hall58c76b72015-02-23 11:09:24 -08001732 if host is None or host.get( 'ips', [] ) == []:
Jon Hall6aec96b2015-01-19 14:49:31 -08001733 main.log.error(
1734 "DEBUG:Error with host ips on controller" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001735 controllerStr + ": " + str( host ) )
Jon Hall58c76b72015-02-23 11:09:24 -08001736 ipResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001737 ports = []
1738 ports.append( main.ONOScli1.ports() )
1739 ports.append( main.ONOScli2.ports() )
1740 ports.append( main.ONOScli3.ports() )
1741 ports.append( main.ONOScli4.ports() )
1742 ports.append( main.ONOScli5.ports() )
1743 ports.append( main.ONOScli6.ports() )
1744 ports.append( main.ONOScli7.ports() )
1745 links = []
1746 links.append( main.ONOScli1.links() )
1747 links.append( main.ONOScli2.links() )
1748 links.append( main.ONOScli3.links() )
1749 links.append( main.ONOScli4.links() )
1750 links.append( main.ONOScli5.links() )
1751 links.append( main.ONOScli6.links() )
1752 links.append( main.ONOScli7.links() )
1753 clusters = []
1754 clusters.append( main.ONOScli1.clusters() )
1755 clusters.append( main.ONOScli2.clusters() )
1756 clusters.append( main.ONOScli3.clusters() )
1757 clusters.append( main.ONOScli4.clusters() )
1758 clusters.append( main.ONOScli5.clusters() )
1759 clusters.append( main.ONOScli6.clusters() )
1760 clusters.append( main.ONOScli7.clusters() )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001761
Jon Hall8f89dda2015-01-22 16:03:33 -08001762 elapsed = time.time() - startTime
1763 cliTime = time.time() - cliStart
1764 print "CLI time: " + str( cliTime )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001765
Jon Hall8f89dda2015-01-22 16:03:33 -08001766 for controller in range( numControllers ):
1767 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001768 if devices[ controller ] or "Error" not in devices[
1769 controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001770 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -08001771 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001772 json.loads( devices[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001773 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001774 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001775 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001776 actual=currentDevicesResult,
1777 onpass="ONOS" + controllerStr +
1778 " Switches view is correct",
1779 onfail="ONOS" + controllerStr +
1780 " Switches view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001781
Jon Hall6aec96b2015-01-19 14:49:31 -08001782 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001783 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -08001784 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001785 json.loads( ports[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001786 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001787 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001788 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001789 actual=currentPortsResult,
1790 onpass="ONOS" + controllerStr +
1791 " ports view is correct",
1792 onfail="ONOS" + controllerStr +
1793 " ports view is incorrect" )
Jon Hall94fd0472014-12-08 11:52:42 -08001794
Jon Hall6aec96b2015-01-19 14:49:31 -08001795 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001796 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -08001797 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001798 json.loads( links[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001799 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001800 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001801 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001802 actual=currentLinksResult,
1803 onpass="ONOS" + controllerStr +
1804 " links view is correct",
1805 onfail="ONOS" + controllerStr +
1806 " links view is incorrect" )
1807
1808 if hosts[ controller ] or "Error" not in hosts[ controller ]:
1809 currentHostsResult = main.Mininet1.compareHosts(
1810 MNTopo, hosts[ controller ] )
1811 else:
1812 currentHostsResult = main.FALSE
1813 utilities.assert_equals( expect=main.TRUE,
1814 actual=currentHostsResult,
1815 onpass="ONOS" + controllerStr +
1816 " hosts exist in Mininet",
1817 onfail="ONOS" + controllerStr +
1818 " hosts don't match Mininet" )
1819
1820 devicesResults = devicesResults and currentDevicesResult
1821 portsResults = portsResults and currentPortsResult
1822 linksResults = linksResults and currentLinksResult
1823 hostsResults = hostsResults and currentHostsResult
Jon Hall94fd0472014-12-08 11:52:42 -08001824
Jon Hall529a37f2015-01-28 10:02:00 -08001825 # Compare json objects for hosts and dataplane clusters
Jon Hall94fd0472014-12-08 11:52:42 -08001826
Jon Hall6aec96b2015-01-19 14:49:31 -08001827 # hosts
Jon Hall8f89dda2015-01-22 16:03:33 -08001828 consistentHostsResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -08001829 for controller in range( len( hosts ) ):
Jon Hall8f89dda2015-01-22 16:03:33 -08001830 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001831 if "Error" not in hosts[ controller ]:
1832 if hosts[ controller ] == hosts[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001833 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001834 else: # hosts not consistent
Jon Hall8f89dda2015-01-22 16:03:33 -08001835 main.log.report( "hosts from ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001836 " is inconsistent with ONOS1" )
1837 main.log.warn( repr( hosts[ controller ] ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001838 consistentHostsResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001839
1840 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001841 main.log.report( "Error in getting ONOS hosts from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001842 controllerStr )
1843 consistentHostsResult = main.FALSE
1844 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001845 " hosts response: " +
1846 repr( hosts[ controller ] ) )
1847 utilities.assert_equals(
1848 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001849 actual=consistentHostsResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001850 onpass="Hosts view is consistent across all ONOS nodes",
1851 onfail="ONOS nodes have different views of hosts" )
Jon Hall94fd0472014-12-08 11:52:42 -08001852
Jon Hall6aec96b2015-01-19 14:49:31 -08001853 # Strongly connected clusters of devices
Jon Hall8f89dda2015-01-22 16:03:33 -08001854 consistentClustersResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -08001855 for controller in range( len( clusters ) ):
Jon Hall8f89dda2015-01-22 16:03:33 -08001856 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001857 if "Error" not in clusters[ controller ]:
1858 if clusters[ controller ] == clusters[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001859 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001860 else: # clusters not consistent
1861 main.log.report( "clusters from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001862 controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001863 " is inconsistent with ONOS1" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001864 consistentClustersResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001865
1866 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001867 main.log.report( "Error in getting dataplane clusters " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001868 "from ONOS" + controllerStr )
1869 consistentClustersResult = main.FALSE
1870 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001871 " clusters response: " +
1872 repr( clusters[ controller ] ) )
1873 utilities.assert_equals(
1874 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001875 actual=consistentClustersResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001876 onpass="Clusters view is consistent across all ONOS nodes",
1877 onfail="ONOS nodes have different views of clusters" )
1878 # there should always only be one cluster
Jon Hall8f89dda2015-01-22 16:03:33 -08001879 numClusters = len( json.loads( clusters[ 0 ] ) )
Jon Hall58c76b72015-02-23 11:09:24 -08001880 clusterResults = main.FALSE
1881 if numClusters == 1:
1882 clusterResults = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001883 utilities.assert_equals(
1884 expect=1,
Jon Hall8f89dda2015-01-22 16:03:33 -08001885 actual=numClusters,
Jon Hall6aec96b2015-01-19 14:49:31 -08001886 onpass="ONOS shows 1 SCC",
Jon Hall58c76b72015-02-23 11:09:24 -08001887 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
Jon Hall94fd0472014-12-08 11:52:42 -08001888
Jon Hall8f89dda2015-01-22 16:03:33 -08001889 topoResult = ( devicesResults and portsResults and linksResults
Jon Hall58c76b72015-02-23 11:09:24 -08001890 and hostsResults and consistentHostsResult
1891 and consistentClustersResult and clusterResults
1892 and ipResult )
Jon Hall94fd0472014-12-08 11:52:42 -08001893
Jon Hall8f89dda2015-01-22 16:03:33 -08001894 topoResult = topoResult and int( count <= 2 )
1895 note = "note it takes about " + str( int( cliTime ) ) + \
1896 " seconds for the test to make all the cli calls to fetch " +\
1897 "the topology from each ONOS instance"
Jon Hall1b8f54a2015-02-04 13:24:20 -08001898 main.log.info(
Jon Hall8f89dda2015-01-22 16:03:33 -08001899 "Very crass estimate for topology discovery/convergence( " +
1900 str( note ) + " ): " + str( elapsed ) + " seconds, " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001901 str( count ) + " tries" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001902 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
Jon Hall58c76b72015-02-23 11:09:24 -08001903 onpass="Topology Check Test successful",
1904 onfail="Topology Check Test NOT successful" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001905 if topoResult == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001906 main.log.report( "ONOS topology view matches Mininet topology" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001907
Jon Hall6aec96b2015-01-19 14:49:31 -08001908 def CASE9( self, main ):
1909 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001910 Link s3-s28 down
Jon Hall6aec96b2015-01-19 14:49:31 -08001911 """
1912 import time
1913 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001914
Jon Hall8f89dda2015-01-22 16:03:33 -08001915 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001916
Jon Hall6aec96b2015-01-19 14:49:31 -08001917 description = "Turn off a link to ensure that Link Discovery " +\
Jon Hall58c76b72015-02-23 11:09:24 -08001918 "is working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001919 main.log.report( description )
1920 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001921
Jon Hall6aec96b2015-01-19 14:49:31 -08001922 main.step( "Kill Link between s3 and s28" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001923 LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" )
Jon Hall58c76b72015-02-23 11:09:24 -08001924 main.log.info( "Waiting " + str( linkSleep ) +
1925 " seconds for link down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001926 time.sleep( linkSleep )
1927 utilities.assert_equals( expect=main.TRUE, actual=LinkDown,
Jon Hall58c76b72015-02-23 11:09:24 -08001928 onpass="Link down succesful",
1929 onfail="Failed to bring link down" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001930 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -08001931
Jon Hall6aec96b2015-01-19 14:49:31 -08001932 def CASE10( self, main ):
1933 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001934 Link s3-s28 up
Jon Hall6aec96b2015-01-19 14:49:31 -08001935 """
1936 import time
1937 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001938
Jon Hall8f89dda2015-01-22 16:03:33 -08001939 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001940
Jon Hall6aec96b2015-01-19 14:49:31 -08001941 description = "Restore a link to ensure that Link Discovery is " + \
Jon Hall63604932015-02-26 17:09:50 -08001942 "working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001943 main.log.report( description )
1944 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001945
Jon Hall6aec96b2015-01-19 14:49:31 -08001946 main.step( "Bring link between s3 and s28 back up" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001947 LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" )
Jon Hall58c76b72015-02-23 11:09:24 -08001948 main.log.info( "Waiting " + str( linkSleep ) +
1949 " seconds for link up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001950 time.sleep( linkSleep )
1951 utilities.assert_equals( expect=main.TRUE, actual=LinkUp,
Jon Hall58c76b72015-02-23 11:09:24 -08001952 onpass="Link up succesful",
1953 onfail="Failed to bring link up" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001954 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -08001955
Jon Hall6aec96b2015-01-19 14:49:31 -08001956 def CASE11( self, main ):
1957 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001958 Switch Down
Jon Hall6aec96b2015-01-19 14:49:31 -08001959 """
1960 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001961 import time
1962
Jon Hall8f89dda2015-01-22 16:03:33 -08001963 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001964
1965 description = "Killing a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001966 main.log.report( description )
1967 main.case( description )
1968 switch = main.params[ 'kill' ][ 'switch' ]
1969 switchDPID = main.params[ 'kill' ][ 'dpid' ]
Jon Hall73cf9cc2014-11-20 22:28:38 -08001970
Jon Hall6aec96b2015-01-19 14:49:31 -08001971 # TODO: Make this switch parameterizable
1972 main.step( "Kill " + switch )
1973 main.log.report( "Deleting " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001974 main.Mininet1.delSwitch( switch )
1975 main.log.info( "Waiting " + str( switchSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001976 " seconds for switch down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001977 time.sleep( switchSleep )
1978 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001979 # Peek at the deleted switch
1980 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001981 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001982 if device and device[ 'available' ] is False:
Jon Hall94fd0472014-12-08 11:52:42 -08001983 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001984 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall58c76b72015-02-23 11:09:24 -08001985 onpass="Kill switch succesful",
1986 onfail="Failed to kill switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001987
Jon Hall6aec96b2015-01-19 14:49:31 -08001988 def CASE12( self, main ):
1989 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001990 Switch Up
Jon Hall6aec96b2015-01-19 14:49:31 -08001991 """
1992 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001993 import time
Jon Hall669173b2014-12-17 11:36:30 -08001994
Jon Hall8f89dda2015-01-22 16:03:33 -08001995 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall6aec96b2015-01-19 14:49:31 -08001996 switch = main.params[ 'kill' ][ 'switch' ]
1997 switchDPID = main.params[ 'kill' ][ 'dpid' ]
1998 links = main.params[ 'kill' ][ 'links' ].split()
Jon Hall73cf9cc2014-11-20 22:28:38 -08001999 description = "Adding a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08002000 main.log.report( description )
2001 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08002002
Jon Hall6aec96b2015-01-19 14:49:31 -08002003 main.step( "Add back " + switch )
2004 main.log.report( "Adding back " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08002005 main.Mininet1.addSwitch( switch, dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08002006 # TODO: New dpid or same? Ask Thomas?
2007 for peer in links:
Jon Hall8f89dda2015-01-22 16:03:33 -08002008 main.Mininet1.addLink( switch, peer )
Jon Hall58c76b72015-02-23 11:09:24 -08002009 main.Mininet1.assignSwController( sw=switch.split( 's' )[ 1 ],
2010 count=numControllers,
2011 ip1=ONOS1Ip,
2012 port1=ONOS1Port,
2013 ip2=ONOS2Ip,
2014 port2=ONOS2Port,
2015 ip3=ONOS3Ip,
2016 port3=ONOS3Port,
2017 ip4=ONOS4Ip,
2018 port4=ONOS4Port,
2019 ip5=ONOS5Ip,
2020 port5=ONOS5Port,
2021 ip6=ONOS6Ip,
2022 port6=ONOS6Port,
2023 ip7=ONOS7Ip,
2024 port7=ONOS7Port )
2025 main.log.info( "Waiting " + str( switchSleep ) +
2026 " seconds for switch up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002027 time.sleep( switchSleep )
2028 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08002029 # Peek at the deleted switch
2030 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08002031 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08002032 if device and device[ 'available' ]:
Jon Hall94fd0472014-12-08 11:52:42 -08002033 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08002034 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall58c76b72015-02-23 11:09:24 -08002035 onpass="add switch succesful",
2036 onfail="Failed to add switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08002037
Jon Hall6aec96b2015-01-19 14:49:31 -08002038 def CASE13( self, main ):
2039 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08002040 Clean up
Jon Hall6aec96b2015-01-19 14:49:31 -08002041 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08002042 import os
2043 import time
Jon Hall6aec96b2015-01-19 14:49:31 -08002044 # TODO: make use of this elsewhere
2045 ips = []
Jon Hall8f89dda2015-01-22 16:03:33 -08002046 ips.append( ONOS1Ip )
2047 ips.append( ONOS2Ip )
2048 ips.append( ONOS3Ip )
2049 ips.append( ONOS4Ip )
2050 ips.append( ONOS5Ip )
2051 ips.append( ONOS6Ip )
2052 ips.append( ONOS7Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -08002053
2054 # printing colors to terminal
Jon Hall669173b2014-12-17 11:36:30 -08002055 colors = {}
Jon Hall6aec96b2015-01-19 14:49:31 -08002056 colors[ 'cyan' ] = '\033[96m'
2057 colors[ 'purple' ] = '\033[95m'
2058 colors[ 'blue' ] = '\033[94m'
2059 colors[ 'green' ] = '\033[92m'
2060 colors[ 'yellow' ] = '\033[93m'
2061 colors[ 'red' ] = '\033[91m'
2062 colors[ 'end' ] = '\033[0m'
Jon Hall73cf9cc2014-11-20 22:28:38 -08002063 description = "Test Cleanup"
Jon Hall6aec96b2015-01-19 14:49:31 -08002064 main.log.report( description )
2065 main.case( description )
2066 main.step( "Killing tcpdumps" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002067 main.Mininet2.stopTcpdump()
Jon Hall73cf9cc2014-11-20 22:28:38 -08002068
Jon Hall6aec96b2015-01-19 14:49:31 -08002069 main.step( "Checking ONOS Logs for errors" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002070 for i in range( 7 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08002071 print colors[ 'purple' ] + "Checking logs for errors on " + \
Jon Hall8f89dda2015-01-22 16:03:33 -08002072 "ONOS" + str( i + 1 ) + ":" + colors[ 'end' ]
2073 print main.ONOSbench.checkLogs( ips[ i ] )
Jon Hall94fd0472014-12-08 11:52:42 -08002074
Jon Hall6aec96b2015-01-19 14:49:31 -08002075 main.step( "Copying MN pcap and ONOS log files to test station" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08002076 testname = main.TEST
Jon Hall8f89dda2015-01-22 16:03:33 -08002077 teststationUser = main.params[ 'TESTONUSER' ]
2078 teststationIP = main.params[ 'TESTONIP' ]
Jon Hall6aec96b2015-01-19 14:49:31 -08002079 # NOTE: MN Pcap file is being saved to ~/packet_captures
Jon Hall73cf9cc2014-11-20 22:28:38 -08002080 # scp this file as MN and TestON aren't necessarily the same vm
Jon Hall6aec96b2015-01-19 14:49:31 -08002081 # FIXME: scp
2082 # mn files
2083 # TODO: Load these from params
2084 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08002085 logFolder = "/opt/onos/log/"
2086 logFiles = [ "karaf.log", "karaf.log.1" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08002087 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08002088 dstDir = "~/packet_captures/"
2089 for f in logFiles:
2090 for i in range( 7 ):
2091 main.ONOSbench.handle.sendline( "scp sdn@" + ips[ i ] + ":" +
2092 logFolder + f + " " +
2093 teststationUser + "@" +
2094 teststationIP + ":" +
2095 dstDir + str( testname ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08002096 "-ONOS" + str( i + 1 ) + "-" +
2097 f )
Jon Hall58c76b72015-02-23 11:09:24 -08002098 main.ONOSbench.handle.expect( "\$" )
2099
Jon Hall6aec96b2015-01-19 14:49:31 -08002100 # std*.log's
2101 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08002102 logFolder = "/opt/onos/var/"
2103 logFiles = [ "stderr.log", "stdout.log" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08002104 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08002105 dstDir = "~/packet_captures/"
2106 for f in logFiles:
2107 for i in range( 7 ):
2108 main.ONOSbench.handle.sendline( "scp sdn@" + ips[ i ] + ":" +
2109 logFolder + f + " " +
2110 teststationUser + "@" +
2111 teststationIP + ":" +
2112 dstDir + str( testname ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08002113 "-ONOS" + str( i + 1 ) + "-" +
2114 f )
Jon Hall58c76b72015-02-23 11:09:24 -08002115 main.ONOSbench.handle.expect( "\$" )
Jon Hall6aec96b2015-01-19 14:49:31 -08002116 # sleep so scp can finish
2117 time.sleep( 10 )
Jon Hall58c76b72015-02-23 11:09:24 -08002118 main.Mininet1.stopNet()
Jon Hall6aec96b2015-01-19 14:49:31 -08002119 main.step( "Packing and rotating pcap archives" )
2120 os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08002121
Jon Hall6aec96b2015-01-19 14:49:31 -08002122 # TODO: actually check something here
2123 utilities.assert_equals( expect=main.TRUE, actual=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08002124 onpass="Test cleanup successful",
2125 onfail="Test cleanup NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08002126
Jon Hall6aec96b2015-01-19 14:49:31 -08002127 def CASE14( self, main ):
2128 """
Jon Hall669173b2014-12-17 11:36:30 -08002129 start election app on all onos nodes
Jon Hall6aec96b2015-01-19 14:49:31 -08002130 """
Jon Hall8f89dda2015-01-22 16:03:33 -08002131 leaderResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08002132 # install app on onos 1
2133 main.log.info( "Install leadership election app" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002134 main.ONOScli1.featureInstall( "onos-app-election" )
Jon Hall6aec96b2015-01-19 14:49:31 -08002135 # wait for election
2136 # check for leader
Jon Hall8f89dda2015-01-22 16:03:33 -08002137 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08002138 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08002139 if leader == ONOS1Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08002140 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08002141 pass
Jon Hall6aec96b2015-01-19 14:49:31 -08002142 elif leader is None:
2143 # No leader elected
2144 main.log.report( "No leader was elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002145 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08002146 elif leader == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08002147 # error in response
2148 # TODO: add check for "Command not found:" in the driver, this
2149 # means the app isn't loaded
Jon Hall8f89dda2015-01-22 16:03:33 -08002150 main.log.report( "Something is wrong with electionTestLeader" +
Jon Hall6aec96b2015-01-19 14:49:31 -08002151 " function, check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002152 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08002153 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08002154 # error in response
2155 main.log.report(
Jon Hall8f89dda2015-01-22 16:03:33 -08002156 "Unexpected response from electionTestLeader function:'" +
2157 str( leader ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08002158 "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002159 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08002160
Jon Hall6aec96b2015-01-19 14:49:31 -08002161 # install on other nodes and check for leader.
2162 # Should be onos1 and each app should show the same leader
Jon Hall8f89dda2015-01-22 16:03:33 -08002163 for controller in range( 2, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08002164 # loop through ONOScli handlers
2165 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08002166 node.featureInstall( "onos-app-election" )
2167 leaderN = node.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08002168 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08002169 if leaderN == ONOS1Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08002170 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08002171 pass
2172 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08002173 # error in response
2174 # TODO: add check for "Command not found:" in the driver, this
2175 # means the app isn't loaded
2176 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002177 "electionTestLeader function, check the" +
Jon Hall6aec96b2015-01-19 14:49:31 -08002178 " error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002179 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08002180 elif leader != leaderN:
Jon Hall8f89dda2015-01-22 16:03:33 -08002181 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08002182 main.log.report( "ONOS" + str( controller ) + " sees " +
2183 str( leaderN ) +
2184 " as the leader of the election app. Leader" +
2185 " should be " +
2186 str( leader ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08002187 if leaderResult:
Jon Hall6aec96b2015-01-19 14:49:31 -08002188 main.log.report( "Leadership election tests passed( consistent " +
2189 "view of leader across listeners and a leader " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002190 "was elected )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08002191 utilities.assert_equals(
2192 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002193 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002194 onpass="Leadership election passed",
2195 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08002196
Jon Hall6aec96b2015-01-19 14:49:31 -08002197 def CASE15( self, main ):
2198 """
Jon Hall669173b2014-12-17 11:36:30 -08002199 Check that Leadership Election is still functional
Jon Hall6aec96b2015-01-19 14:49:31 -08002200 """
Jon Hall8f89dda2015-01-22 16:03:33 -08002201 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08002202 description = "Check that Leadership Election is still functional"
Jon Hall6aec96b2015-01-19 14:49:31 -08002203 main.log.report( description )
2204 main.case( description )
2205 main.step( "Find current leader and withdraw" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002206 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08002207 # TODO: do some sanity checking on leader before using it
Jon Hall8f89dda2015-01-22 16:03:33 -08002208 withdrawResult = main.FALSE
2209 if leader == ONOS1Ip:
2210 oldLeader = getattr( main, "ONOScli1" )
2211 elif leader == ONOS2Ip:
2212 oldLeader = getattr( main, "ONOScli2" )
2213 elif leader == ONOS3Ip:
2214 oldLeader = getattr( main, "ONOScli3" )
2215 elif leader == ONOS4Ip:
2216 oldLeader = getattr( main, "ONOScli4" )
2217 elif leader == ONOS5Ip:
2218 oldLeader = getattr( main, "ONOScli5" )
2219 elif leader == ONOS6Ip:
2220 oldLeader = getattr( main, "ONOScli6" )
2221 elif leader == ONOS7Ip:
2222 oldLeader = getattr( main, "ONOScli7" )
Jon Hall6aec96b2015-01-19 14:49:31 -08002223 elif leader is None or leader == main.FALSE:
2224 main.log.report(
2225 "Leader for the election app should be an ONOS node," +
Jon Hall58c76b72015-02-23 11:09:24 -08002226 "instead got '" + str( leader ) + "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002227 leaderResult = main.FALSE
Jon Hall63604932015-02-26 17:09:50 -08002228 oldLeader = None
2229 else:
2230 main.log.error( "Leader election --- why am I HERE?!?")
2231 if oldLeader:
2232 withdrawResult = oldLeader.electionTestWithdraw()
Jon Hall6aec96b2015-01-19 14:49:31 -08002233 utilities.assert_equals(
2234 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002235 actual=withdrawResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002236 onpass="App was withdrawn from election",
2237 onfail="App was not withdrawn from election" )
Jon Hall669173b2014-12-17 11:36:30 -08002238
Jon Hall6aec96b2015-01-19 14:49:31 -08002239 main.step( "Make sure new leader is elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002240 leaderList = []
2241 for controller in range( 1, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08002242 # loop through ONOScli handlers
2243 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08002244 leaderList.append( node.electionTestLeader() )
2245 for leaderN in leaderList:
Jon Hall669173b2014-12-17 11:36:30 -08002246 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08002247 main.log.report(
Jon Hall58c76b72015-02-23 11:09:24 -08002248 "ONOS" + str( controller ) +
2249 " still sees " + str( leader ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08002250 " as leader after they withdrew" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002251 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08002252 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08002253 # error in response
2254 # TODO: add check for "Command not found:" in the driver, this
2255 # means the app isn't loaded
2256 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002257 "electionTestLeader function, " +
Jon Hall6aec96b2015-01-19 14:49:31 -08002258 "check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002259 leaderResult = main.FALSE
2260 consistentLeader = main.FALSE
2261 if len( set( leaderList ) ) == 1:
Jon Hall6aec96b2015-01-19 14:49:31 -08002262 main.log.info( "Each Election-app sees '" +
Jon Hall8f89dda2015-01-22 16:03:33 -08002263 str( leaderList[ 0 ] ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08002264 "' as the leader" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002265 consistentLeader = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08002266 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08002267 main.log.report(
2268 "Inconsistent responses for leader of Election-app:" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002269 for n in range( len( leaderList ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -08002270 main.log.report( "ONOS" + str( n + 1 ) + " response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002271 str( leaderList[ n ] ) )
2272 if leaderResult:
2273 main.log.report( "Leadership election tests passed( consistent " +
Jon Hall6aec96b2015-01-19 14:49:31 -08002274 "view of leader across listeners and a new " +
2275 "leader was elected when the old leader " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002276 "resigned )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08002277 utilities.assert_equals(
2278 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002279 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002280 onpass="Leadership election passed",
2281 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08002282
Jon Hall58c76b72015-02-23 11:09:24 -08002283 main.step( "Run for election on old leader( just so everyone " +
2284 "is in the hat )" )
Jon Hall63604932015-02-26 17:09:50 -08002285 if oldLeader:
2286 runResult = oldLeader.electionTestRun()
2287 else:
2288 runResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08002289 utilities.assert_equals(
2290 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002291 actual=runResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002292 onpass="App re-ran for election",
2293 onfail="App failed to run for election" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002294 if consistentLeader == main.TRUE:
2295 afterRun = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08002296 # verify leader didn't just change
Jon Hall8f89dda2015-01-22 16:03:33 -08002297 if afterRun == leaderList[ 0 ]:
2298 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08002299 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08002300 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08002301 # TODO: assert on run and withdraw results?
Jon Hall669173b2014-12-17 11:36:30 -08002302
Jon Hall6aec96b2015-01-19 14:49:31 -08002303 utilities.assert_equals(
2304 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002305 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002306 onpass="Leadership election passed",
2307 onfail="Something went wrong with Leadership election after " +
2308 "the old leader re-ran for election" )