blob: 6cca54b0a2bf44e778b46168be56bc682af46c78 [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:
34 git pull
35 mvn clean install
36 onos-package
37 cell <name>
38 onos-verify-cell
39 NOTE: temporary - onos-remove-raft-logs
40 onos-install -f
41 onos-wait-for-start
Jon Hall6aec96b2015-01-19 14:49:31 -080042 """
43 main.log.report(
44 "ONOS HA test: Restart minority of ONOS nodes - initialization" )
45 main.case( "Setting up test environment" )
46 # TODO: save all the timers and output them for plotting
Jon Hall73cf9cc2014-11-20 22:28:38 -080047
48 # load some vairables from the params file
Jon Hall8f89dda2015-01-22 16:03:33 -080049 PULLCODE = False
Jon Hall6aec96b2015-01-19 14:49:31 -080050 if main.params[ 'Git' ] == 'True':
Jon Hall8f89dda2015-01-22 16:03:33 -080051 PULLCODE = True
Jon Hall529a37f2015-01-28 10:02:00 -080052 gitBranch = main.params[ 'branch' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080053 cellName = main.params[ 'ENV' ][ 'cellName' ]
Jon Hall6aec96b2015-01-19 14:49:31 -080054
55 # set global variables
Jon Hall8f89dda2015-01-22 16:03:33 -080056 global ONOS1Ip
57 global ONOS1Port
58 global ONOS2Ip
59 global ONOS2Port
60 global ONOS3Ip
61 global ONOS3Port
62 global ONOS4Ip
63 global ONOS4Port
64 global ONOS5Ip
65 global ONOS5Port
66 global ONOS6Ip
67 global ONOS6Port
68 global ONOS7Ip
69 global ONOS7Port
70 global numControllers
Jon Hall73cf9cc2014-11-20 22:28:38 -080071
Jon Hall8f89dda2015-01-22 16:03:33 -080072 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
73 ONOS1Port = main.params[ 'CTRL' ][ 'port1' ]
74 ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
75 ONOS2Port = main.params[ 'CTRL' ][ 'port2' ]
76 ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ]
77 ONOS3Port = main.params[ 'CTRL' ][ 'port3' ]
78 ONOS4Ip = main.params[ 'CTRL' ][ 'ip4' ]
79 ONOS4Port = main.params[ 'CTRL' ][ 'port4' ]
80 ONOS5Ip = main.params[ 'CTRL' ][ 'ip5' ]
81 ONOS5Port = main.params[ 'CTRL' ][ 'port5' ]
82 ONOS6Ip = main.params[ 'CTRL' ][ 'ip6' ]
83 ONOS6Port = main.params[ 'CTRL' ][ 'port6' ]
84 ONOS7Ip = main.params[ 'CTRL' ][ 'ip7' ]
85 ONOS7Port = main.params[ 'CTRL' ][ 'port7' ]
86 numControllers = int( main.params[ 'num_controllers' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -080087
Jon Hall6aec96b2015-01-19 14:49:31 -080088 main.step( "Applying cell variable to environment" )
Jon Hall8f89dda2015-01-22 16:03:33 -080089 cellResult = main.ONOSbench.setCell( cellName )
90 verifyResult = main.ONOSbench.verifyCell()
Jon Hall73cf9cc2014-11-20 22:28:38 -080091
Jon Hall6aec96b2015-01-19 14:49:31 -080092 # FIXME:this is short term fix
93 main.log.report( "Removing raft logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -080094 main.ONOSbench.onosRemoveRaftLogs()
Jon Hall6aec96b2015-01-19 14:49:31 -080095 main.log.report( "Uninstalling ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -080096 main.ONOSbench.onosUninstall( ONOS1Ip )
97 main.ONOSbench.onosUninstall( ONOS2Ip )
98 main.ONOSbench.onosUninstall( ONOS3Ip )
99 main.ONOSbench.onosUninstall( ONOS4Ip )
100 main.ONOSbench.onosUninstall( ONOS5Ip )
101 main.ONOSbench.onosUninstall( ONOS6Ip )
102 main.ONOSbench.onosUninstall( ONOS7Ip )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800103
Jon Hall8f89dda2015-01-22 16:03:33 -0800104 cleanInstallResult = main.TRUE
105 gitPullResult = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800106
Jon Hall6aec96b2015-01-19 14:49:31 -0800107 main.step( "Compiling the latest version of ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800108 if PULLCODE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800109 # TODO Configure branch in params
110 main.step( "Git checkout and pull master" )
Jon Hall529a37f2015-01-28 10:02:00 -0800111 main.ONOSbench.gitCheckout( gitBranch )
Jon Hall8f89dda2015-01-22 16:03:33 -0800112 gitPullResult = main.ONOSbench.gitPull()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800113
Jon Hall6aec96b2015-01-19 14:49:31 -0800114 main.step( "Using mvn clean & install" )
Jon Hall529a37f2015-01-28 10:02:00 -0800115 cleanInstallResult = main.ONOSbench.cleanInstall()
116 else:
117 main.log.warn( "Did not pull new code so skipping mvn " +
118 "clean install" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800119 main.ONOSbench.getVersion( report=True )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800120
Jon Hall6aec96b2015-01-19 14:49:31 -0800121 main.step( "Creating ONOS package" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800122 packageResult = main.ONOSbench.onosPackage()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800123
Jon Hall6aec96b2015-01-19 14:49:31 -0800124 main.step( "Installing ONOS package" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800125 onos1InstallResult = main.ONOSbench.onosInstall( options="-f",
126 node=ONOS1Ip )
127 onos2InstallResult = main.ONOSbench.onosInstall( options="-f",
128 node=ONOS2Ip )
129 onos3InstallResult = main.ONOSbench.onosInstall( options="-f",
130 node=ONOS3Ip )
131 onos4InstallResult = main.ONOSbench.onosInstall( options="-f",
132 node=ONOS4Ip )
133 onos5InstallResult = main.ONOSbench.onosInstall( options="-f",
134 node=ONOS5Ip )
135 onos6InstallResult = main.ONOSbench.onosInstall( options="-f",
136 node=ONOS6Ip )
137 onos7InstallResult = main.ONOSbench.onosInstall( options="-f",
138 node=ONOS7Ip )
139 onosInstallResult = onos1InstallResult and onos2InstallResult\
140 and onos3InstallResult and onos4InstallResult\
141 and onos5InstallResult and onos6InstallResult\
142 and onos7InstallResult
Jon Hall73cf9cc2014-11-20 22:28:38 -0800143
Jon Hall6aec96b2015-01-19 14:49:31 -0800144 main.step( "Checking if ONOS is up yet" )
145 # TODO check bundle:list?
146 for i in range( 2 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800147 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
148 if not onos1Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800149 main.log.report( "ONOS1 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800150 onos2Isup = main.ONOSbench.isup( ONOS2Ip )
151 if not onos2Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800152 main.log.report( "ONOS2 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800153 onos3Isup = main.ONOSbench.isup( ONOS3Ip )
154 if not onos3Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800155 main.log.report( "ONOS3 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800156 onos4Isup = main.ONOSbench.isup( ONOS4Ip )
157 if not onos4Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800158 main.log.report( "ONOS4 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800159 onos5Isup = main.ONOSbench.isup( ONOS5Ip )
160 if not onos5Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800161 main.log.report( "ONOS5 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800162 onos6Isup = main.ONOSbench.isup( ONOS6Ip )
163 if not onos6Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800164 main.log.report( "ONOS6 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800165 onos7Isup = main.ONOSbench.isup( ONOS7Ip )
166 if not onos7Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800167 main.log.report( "ONOS7 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800168 onosIsupResult = onos1Isup and onos2Isup and onos3Isup\
169 and onos4Isup and onos5Isup and onos6Isup and onos7Isup
170 if onosIsupResult == main.TRUE:
Jon Hall94fd0472014-12-08 11:52:42 -0800171 break
Jon Hall73cf9cc2014-11-20 22:28:38 -0800172
Jon Hall8f89dda2015-01-22 16:03:33 -0800173 cliResult1 = main.ONOScli1.startOnosCli( ONOS1Ip )
174 cliResult2 = main.ONOScli2.startOnosCli( ONOS2Ip )
175 cliResult3 = main.ONOScli3.startOnosCli( ONOS3Ip )
176 cliResult4 = main.ONOScli4.startOnosCli( ONOS4Ip )
177 cliResult5 = main.ONOScli5.startOnosCli( ONOS5Ip )
178 cliResult6 = main.ONOScli6.startOnosCli( ONOS6Ip )
179 cliResult7 = main.ONOScli7.startOnosCli( ONOS7Ip )
180 cliResults = cliResult1 and cliResult2 and cliResult3 and\
181 cliResult4 and cliResult5 and cliResult6 and cliResult7
Jon Hall73cf9cc2014-11-20 22:28:38 -0800182
Jon Hall6aec96b2015-01-19 14:49:31 -0800183 main.step( "Start Packet Capture MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800184 main.Mininet2.startTcpdump(
Jon Hall6aec96b2015-01-19 14:49:31 -0800185 str( main.params[ 'MNtcpdump' ][ 'folder' ] ) + str( main.TEST )
186 + "-MN.pcap",
187 intf=main.params[ 'MNtcpdump' ][ 'intf' ],
188 port=main.params[ 'MNtcpdump' ][ 'port' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800189
Jon Hall8f89dda2015-01-22 16:03:33 -0800190 case1Result = ( cleanInstallResult and packageResult and
191 cellResult and verifyResult and onosInstallResult
192 and onosIsupResult and cliResults )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800193
Jon Hall8f89dda2015-01-22 16:03:33 -0800194 utilities.assert_equals( expect=main.TRUE, actual=case1Result,
195 onpass="Test startup successful",
196 onfail="Test startup NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800197
Jon Hall8f89dda2015-01-22 16:03:33 -0800198 if case1Result == main.FALSE:
Jon Hall94fd0472014-12-08 11:52:42 -0800199 main.cleanup()
200 main.exit()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800201
Jon Hall6aec96b2015-01-19 14:49:31 -0800202 def CASE2( self, main ):
203 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800204 Assign mastership to controllers
Jon Hall6aec96b2015-01-19 14:49:31 -0800205 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800206 import re
207
Jon Hall6aec96b2015-01-19 14:49:31 -0800208 main.log.report( "Assigning switches to controllers" )
209 main.case( "Assigning Controllers" )
210 main.step( "Assign switches to controllers" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800211
Jon Hall6aec96b2015-01-19 14:49:31 -0800212 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800213 main.Mininet1.assignSwController(
Jon Hall6aec96b2015-01-19 14:49:31 -0800214 sw=str( i ),
Jon Hall8f89dda2015-01-22 16:03:33 -0800215 count=numControllers,
216 ip1=ONOS1Ip, port1=ONOS1Port,
217 ip2=ONOS2Ip, port2=ONOS2Port,
218 ip3=ONOS3Ip, port3=ONOS3Port,
219 ip4=ONOS4Ip, port4=ONOS4Port,
220 ip5=ONOS5Ip, port5=ONOS5Port,
221 ip6=ONOS6Ip, port6=ONOS6Port,
222 ip7=ONOS7Ip, port7=ONOS7Port )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800223
Jon Hall8f89dda2015-01-22 16:03:33 -0800224 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800225 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800226 response = main.Mininet1.getSwController( "s" + str( i ) )
Jon Hallffb386d2014-11-21 13:43:38 -0800227 try:
Jon Hall6aec96b2015-01-19 14:49:31 -0800228 main.log.info( str( response ) )
Jon Hallffb386d2014-11-21 13:43:38 -0800229 except:
Jon Hall6aec96b2015-01-19 14:49:31 -0800230 main.log.info( repr( response ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800231 if re.search( "tcp:" + ONOS1Ip, response )\
232 and re.search( "tcp:" + ONOS2Ip, response )\
233 and re.search( "tcp:" + ONOS3Ip, response )\
234 and re.search( "tcp:" + ONOS4Ip, response )\
235 and re.search( "tcp:" + ONOS5Ip, response )\
236 and re.search( "tcp:" + ONOS6Ip, response )\
237 and re.search( "tcp:" + ONOS7Ip, response ):
238 mastershipCheck = mastershipCheck and main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800239 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800240 mastershipCheck = main.FALSE
241 if mastershipCheck == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800242 main.log.report( "Switch mastership assigned correctly" )
243 utilities.assert_equals(
244 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800245 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800246 onpass="Switch mastership assigned correctly",
247 onfail="Switches not assigned correctly to controllers" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800248
Jon Hall6aec96b2015-01-19 14:49:31 -0800249 # Manually assign mastership to the controller we want
Jon Hall8f89dda2015-01-22 16:03:33 -0800250 roleCall = main.TRUE
251 roleCheck = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800252
Jon Hall6aec96b2015-01-19 14:49:31 -0800253 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800254 deviceId = main.ONOScli1.getDevice( "1000" ).get( 'id' )
255 roleCall = roleCall and main.ONOScli1.deviceRole(
256 deviceId,
257 ONOS1Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800258 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800259 if ONOS1Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
260 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800261 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800262 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800263
Jon Hall6aec96b2015-01-19 14:49:31 -0800264 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800265 deviceId = main.ONOScli1.getDevice( "2800" ).get( 'id' )
266 roleCall = roleCall and main.ONOScli1.deviceRole(
267 deviceId,
268 ONOS1Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800269 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800270 if ONOS1Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
271 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800272 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800273 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800274
Jon Hall6aec96b2015-01-19 14:49:31 -0800275 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800276 deviceId = main.ONOScli1.getDevice( "2000" ).get( 'id' )
277 roleCall = roleCall and main.ONOScli1.deviceRole(
278 deviceId,
279 ONOS2Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800280 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800281 if ONOS2Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
282 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800283 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800284 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800285
Jon Hall6aec96b2015-01-19 14:49:31 -0800286 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800287 deviceId = main.ONOScli1.getDevice( "3000" ).get( 'id' )
288 roleCall = roleCall and main.ONOScli1.deviceRole(
289 deviceId,
290 ONOS2Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800291 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800292 if ONOS2Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
293 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800294 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800295 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800296
Jon Hall6aec96b2015-01-19 14:49:31 -0800297 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800298 deviceId = main.ONOScli1.getDevice( "5000" ).get( 'id' )
299 roleCall = roleCall and main.ONOScli1.deviceRole(
300 deviceId,
301 ONOS3Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800302 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800303 if ONOS3Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
304 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800305 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800306 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800307
Jon Hall6aec96b2015-01-19 14:49:31 -0800308 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800309 deviceId = main.ONOScli1.getDevice( "6000" ).get( 'id' )
310 roleCall = roleCall and main.ONOScli1.deviceRole(
311 deviceId,
312 ONOS3Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800313 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800314 if ONOS3Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
315 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800316 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800317 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800318
Jon Hall6aec96b2015-01-19 14:49:31 -0800319 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800320 deviceId = main.ONOScli1.getDevice( "3004" ).get( 'id' )
321 roleCall = roleCall and main.ONOScli1.deviceRole(
322 deviceId,
323 ONOS4Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800324 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800325 if ONOS4Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
326 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800327 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800328 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800329
Jon Hall6aec96b2015-01-19 14:49:31 -0800330 for i in range( 8, 18 ):
331 dpid = '3' + str( i ).zfill( 3 )
Jon Hall8f89dda2015-01-22 16:03:33 -0800332 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
333 roleCall = roleCall and main.ONOScli1.deviceRole(
334 deviceId,
335 ONOS5Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800336 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800337 if ONOS5Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
338 roleCheck = roleCheck and main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800339 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800340 roleCheck = roleCheck and main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800341
Jon Hall8f89dda2015-01-22 16:03:33 -0800342 deviceId = main.ONOScli1.getDevice( "6007" ).get( 'id' )
343 roleCall = roleCall and main.ONOScli1.deviceRole(
344 deviceId,
345 ONOS6Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800346 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800347 if ONOS6Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
348 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800349 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800350 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800351
Jon Hall6aec96b2015-01-19 14:49:31 -0800352 for i in range( 18, 28 ):
353 dpid = '6' + str( i ).zfill( 3 )
Jon Hall8f89dda2015-01-22 16:03:33 -0800354 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
355 roleCall = roleCall and main.ONOScli1.deviceRole(
356 deviceId,
357 ONOS7Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800358 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800359 if ONOS7Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
360 roleCheck = roleCheck and main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800361 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800362 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800363
Jon Hall6aec96b2015-01-19 14:49:31 -0800364 utilities.assert_equals(
365 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800366 actual=roleCall,
Jon Hall6aec96b2015-01-19 14:49:31 -0800367 onpass="Re-assigned switch mastership to designated controller",
Jon Hall8f89dda2015-01-22 16:03:33 -0800368 onfail="Something wrong with deviceRole calls" )
Jon Hall94fd0472014-12-08 11:52:42 -0800369
Jon Hall6aec96b2015-01-19 14:49:31 -0800370 utilities.assert_equals(
371 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800372 actual=roleCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800373 onpass="Switches were successfully reassigned to designated " +
374 "controller",
375 onfail="Switches were not successfully reassigned" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800376 mastershipCheck = mastershipCheck and roleCall and roleCheck
377 utilities.assert_equals( expect=main.TRUE, actual=mastershipCheck,
378 onpass="Switch mastership correctly assigned",
379 onfail="Error in ( re )assigning switch" +
380 " mastership" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800381
Jon Hall6aec96b2015-01-19 14:49:31 -0800382 def CASE3( self, main ):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800383 """
384 Assign intents
Jon Hall73cf9cc2014-11-20 22:28:38 -0800385 """
386 import time
Jon Hall6aec96b2015-01-19 14:49:31 -0800387 main.log.report( "Adding host intents" )
388 main.case( "Adding host Intents" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800389
Jon Hall8f89dda2015-01-22 16:03:33 -0800390 main.step( "Discovering Hosts( Via pingall for now )" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800391 # FIXME: Once we have a host discovery mechanism, use that instead
Jon Hall73cf9cc2014-11-20 22:28:38 -0800392
Jon Hall6aec96b2015-01-19 14:49:31 -0800393 # install onos-app-fwd
394 main.log.info( "Install reactive forwarding app" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800395 main.ONOScli1.featureInstall( "onos-app-fwd" )
396 main.ONOScli2.featureInstall( "onos-app-fwd" )
397 main.ONOScli3.featureInstall( "onos-app-fwd" )
398 main.ONOScli4.featureInstall( "onos-app-fwd" )
399 main.ONOScli5.featureInstall( "onos-app-fwd" )
400 main.ONOScli6.featureInstall( "onos-app-fwd" )
401 main.ONOScli7.featureInstall( "onos-app-fwd" )
Jon Hall94fd0472014-12-08 11:52:42 -0800402
Jon Hall6aec96b2015-01-19 14:49:31 -0800403 # REACTIVE FWD test
Jon Hall8f89dda2015-01-22 16:03:33 -0800404 pingResult = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800405 time1 = time.time()
Jon Hall8f89dda2015-01-22 16:03:33 -0800406 pingResult = main.Mininet1.pingall()
Jon Hall529a37f2015-01-28 10:02:00 -0800407 utilities.assert_equals(
408 expect=main.TRUE,
409 actual=pingResult,
410 onpass="Reactive Pingall test passed",
411 onfail="Reactive Pingall failed, one or more ping pairs failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800412 time2 = time.time()
Jon Hall6aec96b2015-01-19 14:49:31 -0800413 main.log.info( "Time for pingall: %2f seconds" % ( time2 - time1 ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800414
Jon Hall6aec96b2015-01-19 14:49:31 -0800415 # uninstall onos-app-fwd
416 main.log.info( "Uninstall reactive forwarding app" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800417 main.ONOScli1.featureUninstall( "onos-app-fwd" )
418 main.ONOScli2.featureUninstall( "onos-app-fwd" )
419 main.ONOScli3.featureUninstall( "onos-app-fwd" )
420 main.ONOScli4.featureUninstall( "onos-app-fwd" )
421 main.ONOScli5.featureUninstall( "onos-app-fwd" )
422 main.ONOScli6.featureUninstall( "onos-app-fwd" )
423 main.ONOScli7.featureUninstall( "onos-app-fwd" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800424 # timeout for fwd flows
425 time.sleep( 10 )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800426
Jon Hall6aec96b2015-01-19 14:49:31 -0800427 main.step( "Add host intents" )
428 # TODO: move the host numbers to params
Jon Hall8f89dda2015-01-22 16:03:33 -0800429 intentAddResult = True
Jon Hall6aec96b2015-01-19 14:49:31 -0800430 for i in range( 8, 18 ):
431 main.log.info( "Adding host intent between h" + str( i ) +
432 " and h" + str( i + 10 ) )
433 host1 = "00:00:00:00:00:" + \
434 str( hex( i )[ 2: ] ).zfill( 2 ).upper()
435 host2 = "00:00:00:00:00:" + \
436 str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper()
Jon Hall8f89dda2015-01-22 16:03:33 -0800437 host1Id = main.ONOScli1.getHost( host1 )[ 'id' ]
438 host2Id = main.ONOScli1.getHost( host2 )[ 'id' ]
Jon Hall6aec96b2015-01-19 14:49:31 -0800439 # NOTE: get host can return None
Jon Hall8f89dda2015-01-22 16:03:33 -0800440 if host1Id and host2Id:
441 tmpResult = main.ONOScli1.addHostIntent(
442 host1Id,
443 host2Id )
Jon Hall669173b2014-12-17 11:36:30 -0800444 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800445 main.log.error( "Error, getHost() failed" )
446 tmpResult = main.FALSE
447 intentAddResult = bool( pingResult and intentAddResult
448 and tmpResult )
Jon Hall529a37f2015-01-28 10:02:00 -0800449 # TODO Check that intents were added?
Jon Hall6aec96b2015-01-19 14:49:31 -0800450 utilities.assert_equals(
451 expect=True,
Jon Hall8f89dda2015-01-22 16:03:33 -0800452 actual=intentAddResult,
Jon Hall529a37f2015-01-28 10:02:00 -0800453 onpass="Pushed host intents to ONOS",
454 onfail="Error in pushing host intents to ONOS" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800455 # TODO Check if intents all exist in datastore
Jon Hall73cf9cc2014-11-20 22:28:38 -0800456
Jon Hall6aec96b2015-01-19 14:49:31 -0800457 def CASE4( self, main ):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800458 """
459 Ping across added host intents
460 """
461 description = " Ping across added host intents"
Jon Hall6aec96b2015-01-19 14:49:31 -0800462 main.log.report( description )
463 main.case( description )
Jon Hall8f89dda2015-01-22 16:03:33 -0800464 PingResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800465 for i in range( 8, 18 ):
466 ping = main.Mininet1.pingHost(
467 src="h" + str( i ), target="h" + str( i + 10 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800468 PingResult = PingResult and ping
Jon Hall6aec96b2015-01-19 14:49:31 -0800469 if ping == main.FALSE:
470 main.log.warn( "Ping failed between h" + str( i ) +
471 " and h" + str( i + 10 ) )
472 elif ping == main.TRUE:
473 main.log.info( "Ping test passed!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800474 PingResult = main.TRUE
475 if PingResult == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800476 main.log.report(
477 "Intents have not been installed correctly, pings failed." )
Jon Hall529a37f2015-01-28 10:02:00 -0800478 #TODO: pretty print
479 main.log.warn( "ONSO1 intents: " )
480 main.log.warn( json.dumps( json.loads( main.ONOScli1.intents() ),
481 sort_keys=True,
482 indent=4,
483 separators=( ',', ': ' ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800484 if PingResult == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800485 main.log.report(
486 "Intents have been installed correctly and verified by pings" )
487 utilities.assert_equals(
488 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800489 actual=PingResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800490 onpass="Intents have been installed correctly and pings work",
491 onfail="Intents have not been installed correctly, pings failed." )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800492
Jon Hall6aec96b2015-01-19 14:49:31 -0800493 def CASE5( self, main ):
494 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800495 Reading state of ONOS
Jon Hall6aec96b2015-01-19 14:49:31 -0800496 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800497 import json
Jon Hall6aec96b2015-01-19 14:49:31 -0800498 # assumes that sts is already in you PYTHONPATH
499 from sts.topology.teston_topology import TestONTopology
Jon Hall73cf9cc2014-11-20 22:28:38 -0800500
Jon Hall6aec96b2015-01-19 14:49:31 -0800501 main.log.report( "Setting up and gathering data for current state" )
502 main.case( "Setting up and gathering data for current state" )
503 # The general idea for this test case is to pull the state of
504 # ( intents,flows, topology,... ) from each ONOS node
505 # We can then compare them with eachother and also with past states
Jon Hall73cf9cc2014-11-20 22:28:38 -0800506
Jon Hall6aec96b2015-01-19 14:49:31 -0800507 main.step( "Get the Mastership of each switch from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800508 global mastershipState
509 mastershipState = []
Jon Hall94fd0472014-12-08 11:52:42 -0800510
Jon Hall6aec96b2015-01-19 14:49:31 -0800511 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -0800512 ONOS1MasterNotNull = main.ONOScli1.rolesNotNull()
513 ONOS2MasterNotNull = main.ONOScli2.rolesNotNull()
514 ONOS3MasterNotNull = main.ONOScli3.rolesNotNull()
515 ONOS4MasterNotNull = main.ONOScli4.rolesNotNull()
516 ONOS5MasterNotNull = main.ONOScli5.rolesNotNull()
517 ONOS6MasterNotNull = main.ONOScli6.rolesNotNull()
518 ONOS7MasterNotNull = main.ONOScli7.rolesNotNull()
519 rolesNotNull = ONOS1MasterNotNull and ONOS2MasterNotNull and\
520 ONOS3MasterNotNull and ONOS4MasterNotNull and\
521 ONOS5MasterNotNull and ONOS6MasterNotNull and\
522 ONOS7MasterNotNull
Jon Hall6aec96b2015-01-19 14:49:31 -0800523 utilities.assert_equals(
524 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800525 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -0800526 onpass="Each device has a master",
527 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -0800528
Jon Hall8f89dda2015-01-22 16:03:33 -0800529 ONOS1Mastership = main.ONOScli1.roles()
530 ONOS2Mastership = main.ONOScli2.roles()
531 ONOS3Mastership = main.ONOScli3.roles()
532 ONOS4Mastership = main.ONOScli4.roles()
533 ONOS5Mastership = main.ONOScli5.roles()
534 ONOS6Mastership = main.ONOScli6.roles()
535 ONOS7Mastership = main.ONOScli7.roles()
536 if "Error" in ONOS1Mastership or not ONOS1Mastership\
537 or "Error" in ONOS2Mastership or not ONOS2Mastership\
538 or "Error" in ONOS3Mastership or not ONOS3Mastership\
539 or "Error" in ONOS4Mastership or not ONOS4Mastership\
540 or "Error" in ONOS5Mastership or not ONOS5Mastership\
541 or "Error" in ONOS6Mastership or not ONOS6Mastership\
542 or "Error" in ONOS7Mastership or not ONOS7Mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -0800543 main.log.report( "Error in getting ONOS roles" )
544 main.log.warn(
545 "ONOS1 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800546 repr( ONOS1Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800547 main.log.warn(
548 "ONOS2 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800549 repr( ONOS2Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800550 main.log.warn(
551 "ONOS3 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800552 repr( ONOS3Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800553 main.log.warn(
554 "ONOS4 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800555 repr( ONOS4Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800556 main.log.warn(
557 "ONOS5 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800558 repr( ONOS5Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800559 main.log.warn(
560 "ONOS6 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800561 repr( ONOS6Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800562 main.log.warn(
563 "ONOS7 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800564 repr( ONOS7Mastership ) )
565 consistentMastership = main.FALSE
566 elif ONOS1Mastership == ONOS2Mastership\
567 and ONOS1Mastership == ONOS3Mastership\
568 and ONOS1Mastership == ONOS4Mastership\
569 and ONOS1Mastership == ONOS5Mastership\
570 and ONOS1Mastership == ONOS6Mastership\
571 and ONOS1Mastership == ONOS7Mastership:
572 mastershipState = ONOS1Mastership
573 consistentMastership = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800574 main.log.report(
575 "Switch roles are consistent across all ONOS nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800576 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800577 main.log.warn(
578 "ONOS1 roles: ",
579 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800580 json.loads( ONOS1Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800581 sort_keys=True,
582 indent=4,
583 separators=(
584 ',',
585 ': ' ) ) )
586 main.log.warn(
587 "ONOS2 roles: ",
588 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800589 json.loads( ONOS2Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800590 sort_keys=True,
591 indent=4,
592 separators=(
593 ',',
594 ': ' ) ) )
595 main.log.warn(
596 "ONOS3 roles: ",
597 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800598 json.loads( ONOS3Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800599 sort_keys=True,
600 indent=4,
601 separators=(
602 ',',
603 ': ' ) ) )
604 main.log.warn(
605 "ONOS4 roles: ",
606 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800607 json.loads( ONOS4Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800608 sort_keys=True,
609 indent=4,
610 separators=(
611 ',',
612 ': ' ) ) )
613 main.log.warn(
614 "ONOS5 roles: ",
615 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800616 json.loads( ONOS5Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800617 sort_keys=True,
618 indent=4,
619 separators=(
620 ',',
621 ': ' ) ) )
622 main.log.warn(
623 "ONOS6 roles: ",
624 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800625 json.loads( ONOS6Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800626 sort_keys=True,
627 indent=4,
628 separators=(
629 ',',
630 ': ' ) ) )
631 main.log.warn(
632 "ONOS7 roles: ",
633 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800634 json.loads( ONOS7Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800635 sort_keys=True,
636 indent=4,
637 separators=(
638 ',',
639 ': ' ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800640 consistentMastership = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800641 utilities.assert_equals(
642 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800643 actual=consistentMastership,
Jon Hall6aec96b2015-01-19 14:49:31 -0800644 onpass="Switch roles are consistent across all ONOS nodes",
645 onfail="ONOS nodes have different views of switch roles" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800646
Jon Hall6aec96b2015-01-19 14:49:31 -0800647 main.step( "Get the intents from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800648 global intentState
649 intentState = []
650 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
651 ONOS2Intents = main.ONOScli2.intents( jsonFormat=True )
652 ONOS3Intents = main.ONOScli3.intents( jsonFormat=True )
653 ONOS4Intents = main.ONOScli4.intents( jsonFormat=True )
654 ONOS5Intents = main.ONOScli5.intents( jsonFormat=True )
655 ONOS6Intents = main.ONOScli6.intents( jsonFormat=True )
656 ONOS7Intents = main.ONOScli7.intents( jsonFormat=True )
657 intentCheck = main.FALSE
658 if "Error" in ONOS1Intents or not ONOS1Intents\
659 or "Error" in ONOS2Intents or not ONOS2Intents\
660 or "Error" in ONOS3Intents or not ONOS3Intents\
661 or "Error" in ONOS4Intents or not ONOS4Intents\
662 or "Error" in ONOS5Intents or not ONOS5Intents\
663 or "Error" in ONOS6Intents or not ONOS6Intents\
664 or "Error" in ONOS7Intents or not ONOS7Intents:
Jon Hall6aec96b2015-01-19 14:49:31 -0800665 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800666 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
667 main.log.warn( "ONOS2 intents response: " + repr( ONOS2Intents ) )
668 main.log.warn( "ONOS3 intents response: " + repr( ONOS3Intents ) )
669 main.log.warn( "ONOS4 intents response: " + repr( ONOS4Intents ) )
670 main.log.warn( "ONOS5 intents response: " + repr( ONOS5Intents ) )
671 main.log.warn( "ONOS6 intents response: " + repr( ONOS6Intents ) )
672 main.log.warn( "ONOS7 intents response: " + repr( ONOS7Intents ) )
673 elif ONOS1Intents == ONOS2Intents\
674 and ONOS1Intents == ONOS3Intents\
675 and ONOS1Intents == ONOS4Intents\
676 and ONOS1Intents == ONOS5Intents\
677 and ONOS1Intents == ONOS6Intents\
678 and ONOS1Intents == ONOS7Intents:
679 intentState = ONOS1Intents
680 intentCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800681 main.log.report( "Intents are consistent across all ONOS nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800682 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800683 main.log.warn(
684 "ONOS1 intents: ",
685 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800686 json.loads( ONOS1Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800687 sort_keys=True,
688 indent=4,
689 separators=(
690 ',',
691 ': ' ) ) )
692 main.log.warn(
693 "ONOS2 intents: ",
694 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800695 json.loads( ONOS2Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800696 sort_keys=True,
697 indent=4,
698 separators=(
699 ',',
700 ': ' ) ) )
701 main.log.warn(
702 "ONOS3 intents: ",
703 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800704 json.loads( ONOS3Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800705 sort_keys=True,
706 indent=4,
707 separators=(
708 ',',
709 ': ' ) ) )
710 main.log.warn(
711 "ONOS4 intents: ",
712 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800713 json.loads( ONOS4Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800714 sort_keys=True,
715 indent=4,
716 separators=(
717 ',',
718 ': ' ) ) )
719 main.log.warn(
720 "ONOS5 intents: ",
721 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800722 json.loads( ONOS5Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800723 sort_keys=True,
724 indent=4,
725 separators=(
726 ',',
727 ': ' ) ) )
728 main.log.warn(
729 "ONOS6 intents: ",
730 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800731 json.loads( ONOS6Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800732 sort_keys=True,
733 indent=4,
734 separators=(
735 ',',
736 ': ' ) ) )
737 main.log.warn(
738 "ONOS7 intents: ",
739 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800740 json.loads( ONOS7Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800741 sort_keys=True,
742 indent=4,
743 separators=(
744 ',',
745 ': ' ) ) )
746 utilities.assert_equals(
747 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800748 actual=intentCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800749 onpass="Intents are consistent across all ONOS nodes",
750 onfail="ONOS nodes have different views of intents" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800751
Jon Hall6aec96b2015-01-19 14:49:31 -0800752 main.step( "Get the flows from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800753 global flowState
754 flowState = []
755 ONOS1Flows = main.ONOScli1.flows( jsonFormat=True )
756 ONOS2Flows = main.ONOScli2.flows( jsonFormat=True )
757 ONOS3Flows = main.ONOScli3.flows( jsonFormat=True )
758 ONOS4Flows = main.ONOScli4.flows( jsonFormat=True )
759 ONOS5Flows = main.ONOScli5.flows( jsonFormat=True )
760 ONOS6Flows = main.ONOScli6.flows( jsonFormat=True )
761 ONOS7Flows = main.ONOScli7.flows( jsonFormat=True )
762 ONOS1FlowsJson = json.loads( ONOS1Flows )
763 ONOS2FlowsJson = json.loads( ONOS2Flows )
764 ONOS3FlowsJson = json.loads( ONOS3Flows )
765 ONOS4FlowsJson = json.loads( ONOS4Flows )
766 ONOS5FlowsJson = json.loads( ONOS5Flows )
767 ONOS6FlowsJson = json.loads( ONOS6Flows )
768 ONOS7FlowsJson = json.loads( ONOS7Flows )
769 flowCheck = main.FALSE
770 if "Error" in ONOS1Flows or not ONOS1Flows\
771 or "Error" in ONOS2Flows or not ONOS2Flows\
772 or "Error" in ONOS3Flows or not ONOS3Flows\
773 or "Error" in ONOS4Flows or not ONOS4Flows\
774 or "Error" in ONOS5Flows or not ONOS5Flows\
775 or "Error" in ONOS6Flows or not ONOS6Flows\
776 or "Error" in ONOS7Flows or not ONOS7Flows:
Jon Hall6aec96b2015-01-19 14:49:31 -0800777 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800778 main.log.warn( "ONOS1 flows repsponse: " + ONOS1Flows )
779 main.log.warn( "ONOS2 flows repsponse: " + ONOS2Flows )
780 main.log.warn( "ONOS3 flows repsponse: " + ONOS3Flows )
781 main.log.warn( "ONOS4 flows repsponse: " + ONOS4Flows )
782 main.log.warn( "ONOS5 flows repsponse: " + ONOS5Flows )
783 main.log.warn( "ONOS6 flows repsponse: " + ONOS6Flows )
784 main.log.warn( "ONOS7 flows repsponse: " + ONOS7Flows )
785 elif len( ONOS1FlowsJson ) == len( ONOS2FlowsJson )\
786 and len( ONOS1FlowsJson ) == len( ONOS3FlowsJson )\
787 and len( ONOS1FlowsJson ) == len( ONOS4FlowsJson )\
788 and len( ONOS1FlowsJson ) == len( ONOS5FlowsJson )\
789 and len( ONOS1FlowsJson ) == len( ONOS6FlowsJson )\
790 and len( ONOS1FlowsJson ) == len( ONOS7FlowsJson ):
Jon Hall6aec96b2015-01-19 14:49:31 -0800791 # TODO: Do a better check, maybe compare flows on switches?
Jon Hall8f89dda2015-01-22 16:03:33 -0800792 flowState = ONOS1Flows
793 flowCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800794 main.log.report( "Flow count is consistent across all ONOS nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800795 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800796 main.log.warn( "ONOS1 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800797 json.dumps( ONOS1FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800798 indent=4, separators=( ',', ': ' ) ) )
799 main.log.warn( "ONOS2 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800800 json.dumps( ONOS2FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800801 indent=4, separators=( ',', ': ' ) ) )
802 main.log.warn( "ONOS3 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800803 json.dumps( ONOS3FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800804 indent=4, separators=( ',', ': ' ) ) )
805 main.log.warn( "ONOS4 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800806 json.dumps( ONOS4FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800807 indent=4, separators=( ',', ': ' ) ) )
808 main.log.warn( "ONOS5 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800809 json.dumps( ONOS5FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800810 indent=4, separators=( ',', ': ' ) ) )
811 main.log.warn( "ONOS6 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800812 json.dumps( ONOS6FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800813 indent=4, separators=( ',', ': ' ) ) )
814 main.log.warn( "ONOS7 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800815 json.dumps( ONOS7FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800816 indent=4, separators=( ',', ': ' ) ) )
817 utilities.assert_equals(
818 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800819 actual=flowCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800820 onpass="The flow count is consistent across all ONOS nodes",
821 onfail="ONOS nodes have different flow counts" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800822
Jon Hall6aec96b2015-01-19 14:49:31 -0800823 main.step( "Get the OF Table entries" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800824 global flows
Jon Hall6aec96b2015-01-19 14:49:31 -0800825 flows = []
826 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800827 flows.append( main.Mininet2.getFlowTable( 1.3, "s" + str( i ) ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800828
Jon Hall6aec96b2015-01-19 14:49:31 -0800829 # TODO: Compare switch flow tables with ONOS flow tables
Jon Hall73cf9cc2014-11-20 22:28:38 -0800830
Jon Hall6aec96b2015-01-19 14:49:31 -0800831 main.step( "Start continuous pings" )
832 main.Mininet2.pingLong(
833 src=main.params[ 'PING' ][ 'source1' ],
834 target=main.params[ 'PING' ][ 'target1' ],
835 pingTime=500 )
836 main.Mininet2.pingLong(
837 src=main.params[ 'PING' ][ 'source2' ],
838 target=main.params[ 'PING' ][ 'target2' ],
839 pingTime=500 )
840 main.Mininet2.pingLong(
841 src=main.params[ 'PING' ][ 'source3' ],
842 target=main.params[ 'PING' ][ 'target3' ],
843 pingTime=500 )
844 main.Mininet2.pingLong(
845 src=main.params[ 'PING' ][ 'source4' ],
846 target=main.params[ 'PING' ][ 'target4' ],
847 pingTime=500 )
848 main.Mininet2.pingLong(
849 src=main.params[ 'PING' ][ 'source5' ],
850 target=main.params[ 'PING' ][ 'target5' ],
851 pingTime=500 )
852 main.Mininet2.pingLong(
853 src=main.params[ 'PING' ][ 'source6' ],
854 target=main.params[ 'PING' ][ 'target6' ],
855 pingTime=500 )
856 main.Mininet2.pingLong(
857 src=main.params[ 'PING' ][ 'source7' ],
858 target=main.params[ 'PING' ][ 'target7' ],
859 pingTime=500 )
860 main.Mininet2.pingLong(
861 src=main.params[ 'PING' ][ 'source8' ],
862 target=main.params[ 'PING' ][ 'target8' ],
863 pingTime=500 )
864 main.Mininet2.pingLong(
865 src=main.params[ 'PING' ][ 'source9' ],
866 target=main.params[ 'PING' ][ 'target9' ],
867 pingTime=500 )
868 main.Mininet2.pingLong(
869 src=main.params[ 'PING' ][ 'source10' ],
870 target=main.params[ 'PING' ][ 'target10' ],
871 pingTime=500 )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800872
Jon Hall6aec96b2015-01-19 14:49:31 -0800873 main.step( "Create TestONTopology object" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800874 ctrls = []
875 count = 1
876 while True:
877 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -0800878 if ( 'ip' + str( count ) ) in main.params[ 'CTRL' ]:
879 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
880 temp = temp + ( "ONOS" + str( count ), )
881 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
882 temp = temp + \
883 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
884 ctrls.append( temp )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800885 count = count + 1
886 else:
887 break
Jon Hall6aec96b2015-01-19 14:49:31 -0800888 MNTopo = TestONTopology(
889 main.Mininet1,
890 ctrls ) # can also add Intent API info for intent operations
Jon Hall73cf9cc2014-11-20 22:28:38 -0800891
Jon Hall6aec96b2015-01-19 14:49:31 -0800892 main.step( "Collecting topology information from ONOS" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800893 devices = []
894 devices.append( main.ONOScli1.devices() )
895 devices.append( main.ONOScli2.devices() )
896 devices.append( main.ONOScli3.devices() )
897 devices.append( main.ONOScli4.devices() )
898 devices.append( main.ONOScli5.devices() )
899 devices.append( main.ONOScli6.devices() )
900 devices.append( main.ONOScli7.devices() )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800901 hosts = []
Jon Hall6aec96b2015-01-19 14:49:31 -0800902 hosts.append( main.ONOScli1.hosts() )
903 hosts.append( main.ONOScli2.hosts() )
904 hosts.append( main.ONOScli3.hosts() )
905 hosts.append( main.ONOScli4.hosts() )
906 hosts.append( main.ONOScli5.hosts() )
907 hosts.append( main.ONOScli6.hosts() )
908 hosts.append( main.ONOScli7.hosts() )
909 for controller in range( 0, len( hosts ) ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800910 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -0800911 for host in hosts[ controller ]:
912 if host[ 'ips' ] == []:
913 main.log.error( "DEBUG:Error with host ips on controller" +
Jon Hall8f89dda2015-01-22 16:03:33 -0800914 controllerStr + ": " + str( host ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800915 ports = []
916 ports.append( main.ONOScli1.ports() )
917 ports.append( main.ONOScli2.ports() )
918 ports.append( main.ONOScli3.ports() )
919 ports.append( main.ONOScli4.ports() )
920 ports.append( main.ONOScli5.ports() )
921 ports.append( main.ONOScli6.ports() )
922 ports.append( main.ONOScli7.ports() )
923 links = []
924 links.append( main.ONOScli1.links() )
925 links.append( main.ONOScli2.links() )
926 links.append( main.ONOScli3.links() )
927 links.append( main.ONOScli4.links() )
928 links.append( main.ONOScli5.links() )
929 links.append( main.ONOScli6.links() )
930 links.append( main.ONOScli7.links() )
Jon Hall94fd0472014-12-08 11:52:42 -0800931 clusters = []
932 clusters.append( main.ONOScli1.clusters() )
933 clusters.append( main.ONOScli2.clusters() )
934 clusters.append( main.ONOScli3.clusters() )
935 clusters.append( main.ONOScli4.clusters() )
936 clusters.append( main.ONOScli5.clusters() )
937 clusters.append( main.ONOScli6.clusters() )
938 clusters.append( main.ONOScli7.clusters() )
Jon Hall529a37f2015-01-28 10:02:00 -0800939 # Compare json objects for hosts and dataplane clusters
Jon Hall94fd0472014-12-08 11:52:42 -0800940
Jon Hall6aec96b2015-01-19 14:49:31 -0800941 # hosts
Jon Hall8f89dda2015-01-22 16:03:33 -0800942 consistentHostsResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800943 for controller in range( len( hosts ) ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800944 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -0800945 if "Error" not in hosts[ controller ]:
946 if hosts[ controller ] == hosts[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -0800947 continue
Jon Hall6aec96b2015-01-19 14:49:31 -0800948 else: # hosts not consistent
949 main.log.report( "hosts from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -0800950 controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -0800951 " is inconsistent with ONOS1" )
952 main.log.warn( repr( hosts[ controller ] ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800953 consistentHostsResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800954
955 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800956 main.log.report( "Error in getting ONOS hosts from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -0800957 controllerStr )
958 consistentHostsResult = main.FALSE
959 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -0800960 " hosts response: " +
961 repr( hosts[ controller ] ) )
962 utilities.assert_equals(
963 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800964 actual=consistentHostsResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800965 onpass="Hosts view is consistent across all ONOS nodes",
966 onfail="ONOS nodes have different views of hosts" )
Jon Hall94fd0472014-12-08 11:52:42 -0800967
Jon Hall6aec96b2015-01-19 14:49:31 -0800968 # Strongly connected clusters of devices
Jon Hall8f89dda2015-01-22 16:03:33 -0800969 consistentClustersResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800970 for controller in range( len( clusters ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -0800971 if "Error" not in clusters[ controller ]:
972 if clusters[ controller ] == clusters[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -0800973 continue
Jon Hall6aec96b2015-01-19 14:49:31 -0800974 else: # clusters not consistent
975 main.log.report( "clusters from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -0800976 controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -0800977 " is inconsistent with ONOS1" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800978 consistentClustersResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800979
980 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800981 main.log.report( "Error in getting dataplane clusters " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800982 "from ONOS" + controllerStr )
983 consistentClustersResult = main.FALSE
984 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -0800985 " clusters response: " +
986 repr( clusters[ controller ] ) )
987 utilities.assert_equals(
988 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800989 actual=consistentClustersResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800990 onpass="Clusters view is consistent across all ONOS nodes",
991 onfail="ONOS nodes have different views of clusters" )
992 # there should always only be one cluster
Jon Hall8f89dda2015-01-22 16:03:33 -0800993 numClusters = len( json.loads( clusters[ 0 ] ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800994 utilities.assert_equals(
995 expect=1,
Jon Hall8f89dda2015-01-22 16:03:33 -0800996 actual=numClusters,
Jon Hall6aec96b2015-01-19 14:49:31 -0800997 onpass="ONOS shows 1 SCC",
998 onfail="ONOS shows " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800999 str( numClusters ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001000 " SCCs" )
Jon Hall94fd0472014-12-08 11:52:42 -08001001
Jon Hall6aec96b2015-01-19 14:49:31 -08001002 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001003 devicesResults = main.TRUE
1004 portsResults = main.TRUE
1005 linksResults = main.TRUE
1006 for controller in range( numControllers ):
1007 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001008 if devices[ controller ] or "Error" not in devices[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001009 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -08001010 MNTopo,
1011 json.loads(
1012 devices[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001013 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001014 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001015 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001016 actual=currentDevicesResult,
1017 onpass="ONOS" + controllerStr +
1018 " Switches view is correct",
1019 onfail="ONOS" + controllerStr +
1020 " Switches view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001021
Jon Hall6aec96b2015-01-19 14:49:31 -08001022 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001023 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -08001024 MNTopo,
1025 json.loads(
1026 ports[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001027 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001028 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001029 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001030 actual=currentPortsResult,
1031 onpass="ONOS" + controllerStr +
1032 " ports view is correct",
1033 onfail="ONOS" + controllerStr +
1034 " ports view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001035
Jon Hall6aec96b2015-01-19 14:49:31 -08001036 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001037 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -08001038 MNTopo,
1039 json.loads(
1040 links[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001041 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001042 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001043 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001044 actual=currentLinksResult,
1045 onpass="ONOS" + controllerStr +
1046 " links view is correct",
1047 onfail="ONOS" + controllerStr +
1048 " links view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001049
Jon Hall8f89dda2015-01-22 16:03:33 -08001050 devicesResults = devicesResults and currentDevicesResult
1051 portsResults = portsResults and currentPortsResult
1052 linksResults = linksResults and currentLinksResult
Jon Hall73cf9cc2014-11-20 22:28:38 -08001053
Jon Hall8f89dda2015-01-22 16:03:33 -08001054 topoResult = devicesResults and portsResults and linksResults\
Jon Hall529a37f2015-01-28 10:02:00 -08001055 and consistentHostsResult and consistentClustersResult
Jon Hall8f89dda2015-01-22 16:03:33 -08001056 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
1057 onpass="Topology Check Test successful",
1058 onfail="Topology Check Test NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001059
Jon Hall8f89dda2015-01-22 16:03:33 -08001060 finalAssert = main.TRUE
1061 finalAssert = finalAssert and topoResult and flowCheck \
1062 and intentCheck and consistentMastership and rolesNotNull
1063 utilities.assert_equals( expect=main.TRUE, actual=finalAssert,
1064 onpass="State check successful",
1065 onfail="State check NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001066
Jon Hall6aec96b2015-01-19 14:49:31 -08001067 def CASE6( self, main ):
1068 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001069 The Failure case.
Jon Hall6aec96b2015-01-19 14:49:31 -08001070 """
Jon Hall94fd0472014-12-08 11:52:42 -08001071 import time
Jon Hall6aec96b2015-01-19 14:49:31 -08001072 main.log.report( "Killing 3 ONOS nodes" )
1073 main.log.case( "Restart minority of ONOS nodes" )
1074 # TODO: Randomize these nodes
Jon Hall8f89dda2015-01-22 16:03:33 -08001075 main.ONOSbench.onosKill( ONOS1Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -08001076 time.sleep( 10 )
Jon Hall8f89dda2015-01-22 16:03:33 -08001077 main.ONOSbench.onosKill( ONOS2Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -08001078 time.sleep( 10 )
Jon Hall8f89dda2015-01-22 16:03:33 -08001079 main.ONOSbench.onosKill( ONOS3Ip )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001080
Jon Hall6aec96b2015-01-19 14:49:31 -08001081 main.step( "Checking if ONOS is up yet" )
Jon Hallffb386d2014-11-21 13:43:38 -08001082 count = 0
Jon Hall8f89dda2015-01-22 16:03:33 -08001083 onosIsupResult = main.FALSE
1084 while onosIsupResult == main.FALSE and count < 10:
1085 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
1086 onos2Isup = main.ONOSbench.isup( ONOS2Ip )
1087 onos3Isup = main.ONOSbench.isup( ONOS3Ip )
1088 onosIsupResult = onos1Isup and onos2Isup and onos3Isup
Jon Hallffb386d2014-11-21 13:43:38 -08001089 count = count + 1
Jon Hall73cf9cc2014-11-20 22:28:38 -08001090 # TODO: if it becomes an issue, we can retry this step a few times
1091
Jon Hall8f89dda2015-01-22 16:03:33 -08001092 cliResult1 = main.ONOScli1.startOnosCli( ONOS1Ip )
1093 cliResult2 = main.ONOScli2.startOnosCli( ONOS2Ip )
1094 cliResult3 = main.ONOScli3.startOnosCli( ONOS3Ip )
1095 cliResults = cliResult1 and cliResult2 and cliResult3
Jon Hall73cf9cc2014-11-20 22:28:38 -08001096
Jon Hall6aec96b2015-01-19 14:49:31 -08001097 main.log.info( "Install leadership election app on restarted node" )
Jon Hall669173b2014-12-17 11:36:30 -08001098
Jon Hall8f89dda2015-01-22 16:03:33 -08001099 caseResults = main.TRUE and onosIsupResult and cliResults
1100 utilities.assert_equals( expect=main.TRUE, actual=caseResults,
1101 onpass="ONOS restart successful",
1102 onfail="ONOS restart NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001103
Jon Hall6aec96b2015-01-19 14:49:31 -08001104 def CASE7( self, main ):
1105 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001106 Check state after ONOS failure
Jon Hall6aec96b2015-01-19 14:49:31 -08001107 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001108 import json
Jon Hall6aec96b2015-01-19 14:49:31 -08001109 main.case( "Running ONOS Constant State Tests" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001110
Jon Hall6aec96b2015-01-19 14:49:31 -08001111 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -08001112 ONOS1MasterNotNull = main.ONOScli1.rolesNotNull()
1113 ONOS2MasterNotNull = main.ONOScli2.rolesNotNull()
1114 ONOS3MasterNotNull = main.ONOScli3.rolesNotNull()
1115 ONOS4MasterNotNull = main.ONOScli4.rolesNotNull()
1116 ONOS5MasterNotNull = main.ONOScli5.rolesNotNull()
1117 ONOS6MasterNotNull = main.ONOScli6.rolesNotNull()
1118 ONOS7MasterNotNull = main.ONOScli7.rolesNotNull()
1119 rolesNotNull = ONOS1MasterNotNull and ONOS2MasterNotNull and\
1120 ONOS3MasterNotNull and ONOS4MasterNotNull and\
1121 ONOS5MasterNotNull and ONOS6MasterNotNull and\
1122 ONOS7MasterNotNull
Jon Hall6aec96b2015-01-19 14:49:31 -08001123 utilities.assert_equals(
1124 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001125 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -08001126 onpass="Each device has a master",
1127 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -08001128
Jon Hall6aec96b2015-01-19 14:49:31 -08001129 main.step( "Check if switch roles are consistent across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001130 ONOS1Mastership = main.ONOScli1.roles()
1131 ONOS2Mastership = main.ONOScli2.roles()
1132 ONOS3Mastership = main.ONOScli3.roles()
1133 ONOS4Mastership = main.ONOScli4.roles()
1134 ONOS5Mastership = main.ONOScli5.roles()
1135 ONOS6Mastership = main.ONOScli6.roles()
1136 ONOS7Mastership = main.ONOScli7.roles()
1137 # print json.dumps( json.loads( ONOS1Mastership ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001138 # indent=4, separators=( ',', ': ' ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001139 if "Error" in ONOS1Mastership or not ONOS1Mastership\
1140 or "Error" in ONOS2Mastership or not ONOS2Mastership\
1141 or "Error" in ONOS3Mastership or not ONOS3Mastership\
1142 or "Error" in ONOS4Mastership or not ONOS4Mastership\
1143 or "Error" in ONOS5Mastership or not ONOS5Mastership\
1144 or "Error" in ONOS6Mastership or not ONOS6Mastership\
1145 or "Error" in ONOS7Mastership or not ONOS7Mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -08001146 main.log.error( "Error in getting ONOS mastership" )
1147 main.log.warn( "ONOS1 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001148 repr( ONOS1Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001149 main.log.warn( "ONOS2 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001150 repr( ONOS2Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001151 main.log.warn( "ONOS3 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001152 repr( ONOS3Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001153 main.log.warn( "ONOS4 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001154 repr( ONOS4Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001155 main.log.warn( "ONOS5 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001156 repr( ONOS5Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001157 main.log.warn( "ONOS6 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001158 repr( ONOS6Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001159 main.log.warn( "ONOS7 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001160 repr( ONOS7Mastership ) )
1161 consistentMastership = main.FALSE
1162 elif ONOS1Mastership == ONOS2Mastership\
1163 and ONOS1Mastership == ONOS3Mastership\
1164 and ONOS1Mastership == ONOS4Mastership\
1165 and ONOS1Mastership == ONOS5Mastership\
1166 and ONOS1Mastership == ONOS6Mastership\
1167 and ONOS1Mastership == ONOS7Mastership:
1168 consistentMastership = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001169 main.log.report(
1170 "Switch roles are consistent across all ONOS nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001171 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001172 main.log.warn( "ONOS1 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001173 json.loads( ONOS1Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001174 separators=( ',', ': ' ) ) )
1175 main.log.warn( "ONOS2 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001176 json.loads( ONOS2Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001177 separators=( ',', ': ' ) ) )
1178 main.log.warn( "ONOS3 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001179 json.loads( ONOS3Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001180 separators=( ',', ': ' ) ) )
1181 main.log.warn( "ONOS4 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001182 json.loads( ONOS4Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001183 separators=( ',', ': ' ) ) )
1184 main.log.warn( "ONOS5 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001185 json.loads( ONOS5Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001186 separators=( ',', ': ' ) ) )
1187 main.log.warn( "ONOS6 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001188 json.loads( ONOS6Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001189 separators=( ',', ': ' ) ) )
1190 main.log.warn( "ONOS7 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001191 json.loads( ONOS7Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001192 separators=( ',', ': ' ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001193 consistentMastership = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001194 utilities.assert_equals(
1195 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001196 actual=consistentMastership,
Jon Hall6aec96b2015-01-19 14:49:31 -08001197 onpass="Switch roles are consistent across all ONOS nodes",
1198 onfail="ONOS nodes have different views of switch roles" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001199
1200 description2 = "Compare switch roles from before failure"
Jon Hall6aec96b2015-01-19 14:49:31 -08001201 main.step( description2 )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001202
Jon Hall8f89dda2015-01-22 16:03:33 -08001203 currentJson = json.loads( ONOS1Mastership )
1204 oldJson = json.loads( mastershipState )
1205 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001206 for i in range( 1, 29 ):
1207 switchDPID = str(
1208 main.Mininet1.getSwitchDPID(
1209 switch="s" +
1210 str( i ) ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001211
Jon Hall8f89dda2015-01-22 16:03:33 -08001212 current = [ switch[ 'master' ] for switch in currentJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001213 if switchDPID in switch[ 'id' ] ]
Jon Hall8f89dda2015-01-22 16:03:33 -08001214 old = [ switch[ 'master' ] for switch in oldJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001215 if switchDPID in switch[ 'id' ] ]
Jon Hall73cf9cc2014-11-20 22:28:38 -08001216 if current == old:
Jon Hall8f89dda2015-01-22 16:03:33 -08001217 mastershipCheck = mastershipCheck and main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001218 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001219 main.log.warn( "Mastership of switch %s changed" % switchDPID )
Jon Hall8f89dda2015-01-22 16:03:33 -08001220 mastershipCheck = main.FALSE
1221 if mastershipCheck == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001222 main.log.report( "Mastership of Switches was not changed" )
1223 utilities.assert_equals(
1224 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001225 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -08001226 onpass="Mastership of Switches was not changed",
1227 onfail="Mastership of some switches changed" )
1228 # NOTE: we expect mastership to change on controller failure
Jon Hall8f89dda2015-01-22 16:03:33 -08001229 mastershipCheck = consistentMastership
Jon Hall73cf9cc2014-11-20 22:28:38 -08001230
Jon Hall6aec96b2015-01-19 14:49:31 -08001231 main.step( "Get the intents and compare across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001232 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
1233 ONOS2Intents = main.ONOScli2.intents( jsonFormat=True )
1234 ONOS3Intents = main.ONOScli3.intents( jsonFormat=True )
1235 ONOS4Intents = main.ONOScli4.intents( jsonFormat=True )
1236 ONOS5Intents = main.ONOScli5.intents( jsonFormat=True )
1237 ONOS6Intents = main.ONOScli6.intents( jsonFormat=True )
1238 ONOS7Intents = main.ONOScli7.intents( jsonFormat=True )
1239 intentCheck = main.FALSE
1240 if "Error" in ONOS1Intents or not ONOS1Intents\
1241 or "Error" in ONOS2Intents or not ONOS2Intents\
1242 or "Error" in ONOS3Intents or not ONOS3Intents\
1243 or "Error" in ONOS4Intents or not ONOS4Intents\
1244 or "Error" in ONOS5Intents or not ONOS5Intents\
1245 or "Error" in ONOS6Intents or not ONOS6Intents\
1246 or "Error" in ONOS7Intents or not ONOS7Intents:
Jon Hall6aec96b2015-01-19 14:49:31 -08001247 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001248 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
1249 main.log.warn( "ONOS2 intents response: " + repr( ONOS2Intents ) )
1250 main.log.warn( "ONOS3 intents response: " + repr( ONOS3Intents ) )
1251 main.log.warn( "ONOS4 intents response: " + repr( ONOS4Intents ) )
1252 main.log.warn( "ONOS5 intents response: " + repr( ONOS5Intents ) )
1253 main.log.warn( "ONOS6 intents response: " + repr( ONOS6Intents ) )
1254 main.log.warn( "ONOS7 intents response: " + repr( ONOS7Intents ) )
1255 elif ONOS1Intents == ONOS2Intents\
1256 and ONOS1Intents == ONOS3Intents\
1257 and ONOS1Intents == ONOS4Intents\
1258 and ONOS1Intents == ONOS5Intents\
1259 and ONOS1Intents == ONOS6Intents\
1260 and ONOS1Intents == ONOS7Intents:
1261 intentCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001262 main.log.report( "Intents are consistent across all ONOS nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001263 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001264 main.log.warn( "ONOS1 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001265 print json.dumps( json.loads( ONOS1Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001266 indent=4, separators=( ',', ': ' ) )
1267 main.log.warn( "ONOS2 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001268 print json.dumps( json.loads( ONOS2Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001269 indent=4, separators=( ',', ': ' ) )
1270 main.log.warn( "ONOS3 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001271 print json.dumps( json.loads( ONOS3Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001272 indent=4, separators=( ',', ': ' ) )
1273 main.log.warn( "ONOS4 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001274 print json.dumps( json.loads( ONOS4Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001275 indent=4, separators=( ',', ': ' ) )
1276 main.log.warn( "ONOS5 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001277 print json.dumps( json.loads( ONOS5Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001278 indent=4, separators=( ',', ': ' ) )
1279 main.log.warn( "ONOS6 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001280 print json.dumps( json.loads( ONOS6Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001281 indent=4, separators=( ',', ': ' ) )
1282 main.log.warn( "ONOS7 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001283 print json.dumps( json.loads( ONOS7Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001284 indent=4, separators=( ',', ': ' ) )
1285 utilities.assert_equals(
1286 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001287 actual=intentCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -08001288 onpass="Intents are consistent across all ONOS nodes",
1289 onfail="ONOS nodes have different views of intents" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001290
Jon Hall6aec96b2015-01-19 14:49:31 -08001291 # NOTE: Hazelcast has no durability, so intents are lost across system
1292 # restarts
1293 main.step( "Compare current intents with intents before the failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001294 # NOTE: this requires case 5 to pass for intentState to be set.
Jon Hall94fd0472014-12-08 11:52:42 -08001295 # maybe we should stop the test if that fails?
Jon Hall8f89dda2015-01-22 16:03:33 -08001296 if intentState == ONOS1Intents:
1297 sameIntents = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001298 main.log.report( "Intents are consistent with before failure" )
1299 # TODO: possibly the states have changed? we may need to figure out
1300 # what the aceptable states are
Jon Hall73cf9cc2014-11-20 22:28:38 -08001301 else:
Jon Hall669173b2014-12-17 11:36:30 -08001302 try:
Jon Hall6aec96b2015-01-19 14:49:31 -08001303 main.log.warn( "ONOS1 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001304 print json.dumps( json.loads( ONOS1Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -08001305 sort_keys=True, indent=4,
1306 separators=( ',', ': ' ) )
Jon Hall669173b2014-12-17 11:36:30 -08001307 except:
1308 pass
Jon Hall8f89dda2015-01-22 16:03:33 -08001309 sameIntents = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001310 utilities.assert_equals(
1311 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001312 actual=sameIntents,
Jon Hall6aec96b2015-01-19 14:49:31 -08001313 onpass="Intents are consistent with before failure",
1314 onfail="The Intents changed during failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001315 intentCheck = intentCheck and sameIntents
Jon Hall73cf9cc2014-11-20 22:28:38 -08001316
Jon Hall6aec96b2015-01-19 14:49:31 -08001317 main.step( "Get the OF Table entries and compare to before " +
1318 "component failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001319 FlowTables = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001320 flows2 = []
1321 for i in range( 28 ):
1322 main.log.info( "Checking flow table on s" + str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001323 tmpFlows = main.Mininet2.getFlowTable( 1.3, "s" + str( i + 1 ) )
1324 flows2.append( tmpFlows )
1325 tempResult = main.Mininet2.flowComp(
Jon Hall6aec96b2015-01-19 14:49:31 -08001326 flow1=flows[ i ],
Jon Hall8f89dda2015-01-22 16:03:33 -08001327 flow2=tmpFlows )
1328 FlowTables = FlowTables and tempResult
1329 if FlowTables == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001330 main.log.info( "Differences in flow table for switch: s" +
1331 str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001332 if FlowTables == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001333 main.log.report( "No changes were found in the flow tables" )
1334 utilities.assert_equals(
1335 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001336 actual=FlowTables,
Jon Hall6aec96b2015-01-19 14:49:31 -08001337 onpass="No changes were found in the flow tables",
1338 onfail="Changes were found in the flow tables" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001339
Jon Hall6aec96b2015-01-19 14:49:31 -08001340 main.step( "Check the continuous pings to ensure that no packets " +
1341 "were dropped during component failure" )
1342 # FIXME: This check is always failing. Investigate cause
1343 # NOTE: this may be something to do with file permsissions
Jon Hall73cf9cc2014-11-20 22:28:38 -08001344 # or slight change in format
Jon Hall6aec96b2015-01-19 14:49:31 -08001345 main.Mininet2.pingKill(
1346 main.params[ 'TESTONUSER' ],
1347 main.params[ 'TESTONIP' ] )
Jon Hall8f89dda2015-01-22 16:03:33 -08001348 LossInPings = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001349 # NOTE: checkForLoss returns main.FALSE with 0% packet loss
1350 for i in range( 8, 18 ):
1351 main.log.info(
1352 "Checking for a loss in pings along flow from s" +
1353 str( i ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001354 LossInPings = main.Mininet2.checkForLoss(
Jon Hall6aec96b2015-01-19 14:49:31 -08001355 "/tmp/ping.h" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001356 str( i ) ) or LossInPings
1357 if LossInPings == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001358 main.log.info( "Loss in ping detected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001359 elif LossInPings == main.ERROR:
Jon Hall6aec96b2015-01-19 14:49:31 -08001360 main.log.info( "There are multiple mininet process running" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001361 elif LossInPings == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001362 main.log.info( "No Loss in the pings" )
1363 main.log.report( "No loss of dataplane connectivity" )
1364 utilities.assert_equals(
1365 expect=main.FALSE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001366 actual=LossInPings,
Jon Hall6aec96b2015-01-19 14:49:31 -08001367 onpass="No Loss of connectivity",
1368 onfail="Loss of dataplane connectivity detected" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001369
Jon Hall6aec96b2015-01-19 14:49:31 -08001370 # Test of LeadershipElection
Jon Hall8f89dda2015-01-22 16:03:33 -08001371 leaderList = []
1372 leaderResult = main.TRUE
1373 for controller in range( 1, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001374 # loop through ONOScli handlers
1375 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001376 leaderN = node.electionTestLeader()
1377 leaderList.append( leaderN )
Jon Hall669173b2014-12-17 11:36:30 -08001378 if leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001379 # error in response
1380 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001381 "electionTestLeader function, check the" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001382 " error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001383 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001384 elif leaderN is None:
1385 main.log.report( "ONOS" + str( controller ) +
1386 " shows no leader for the election-app was" +
1387 " elected after the old one died" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001388 leaderResult = main.FALSE
1389 elif leaderN == ONOS1Ip or leaderN == ONOS2Ip or\
1390 leaderN == ONOS3Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08001391 main.log.report( "ONOS" + str( controller ) +
1392 " shows " + str( leaderN ) +
1393 " as leader for the election-app, but it " +
1394 "was restarted" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001395 leaderResult = main.FALSE
1396 if len( set( leaderList ) ) != 1:
1397 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001398 main.log.error(
1399 "Inconsistent view of leader for the election test app" )
1400 # TODO: print the list
Jon Hall8f89dda2015-01-22 16:03:33 -08001401 if leaderResult:
1402 main.log.report( "Leadership election tests passed( consistent " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001403 "view of leader across listeners and a new " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001404 "leader was re-elected if applicable )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001405 utilities.assert_equals(
1406 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001407 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001408 onpass="Leadership election passed",
1409 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08001410
Jon Hall8f89dda2015-01-22 16:03:33 -08001411 result = mastershipCheck and intentCheck and FlowTables and\
1412 ( not LossInPings ) and rolesNotNull and leaderResult
Jon Hall6aec96b2015-01-19 14:49:31 -08001413 result = int( result )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001414 if result == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001415 main.log.report( "Constant State Tests Passed" )
1416 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall8f89dda2015-01-22 16:03:33 -08001417 onpass="Constant State Tests Passed",
1418 onfail="Constant state tests failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001419
Jon Hall6aec96b2015-01-19 14:49:31 -08001420 def CASE8( self, main ):
1421 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001422 Compare topo
Jon Hall6aec96b2015-01-19 14:49:31 -08001423 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001424 import sys
Jon Hall6aec96b2015-01-19 14:49:31 -08001425 # FIXME add this path to params
1426 sys.path.append( "/home/admin/sts" )
1427 # assumes that sts is already in you PYTHONPATH
1428 from sts.topology.teston_topology import TestONTopology
Jon Hall73cf9cc2014-11-20 22:28:38 -08001429 import json
1430 import time
1431
Jon Hall6aec96b2015-01-19 14:49:31 -08001432 description = "Compare ONOS Topology view to Mininet topology"
1433 main.case( description )
1434 main.log.report( description )
1435 main.step( "Create TestONTopology object" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001436 ctrls = []
1437 count = 1
1438 while True:
1439 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -08001440 if ( 'ip' + str( count ) ) in main.params[ 'CTRL' ]:
1441 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
1442 temp = temp + ( "ONOS" + str( count ), )
1443 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
1444 temp = temp + \
1445 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
1446 ctrls.append( temp )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001447 count = count + 1
1448 else:
1449 break
Jon Hall6aec96b2015-01-19 14:49:31 -08001450 MNTopo = TestONTopology(
1451 main.Mininet1,
1452 ctrls ) # can also add Intent API info for intent operations
Jon Hall73cf9cc2014-11-20 22:28:38 -08001453
Jon Hall6aec96b2015-01-19 14:49:31 -08001454 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001455 devicesResults = main.TRUE
1456 portsResults = main.TRUE
1457 linksResults = main.TRUE
1458 topoResult = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001459 elapsed = 0
Jon Hallffb386d2014-11-21 13:43:38 -08001460 count = 0
Jon Hall6aec96b2015-01-19 14:49:31 -08001461 main.step( "Collecting topology information from ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001462 startTime = time.time()
1463 while topoResult == main.FALSE and elapsed < 60:
Jon Hallffb386d2014-11-21 13:43:38 -08001464 count = count + 1
Jon Hall94fd0472014-12-08 11:52:42 -08001465 if count > 1:
Jon Hall6aec96b2015-01-19 14:49:31 -08001466 # TODO: Depricate STS usage
1467 MNTopo = TestONTopology(
1468 main.Mininet1,
1469 ctrls )
Jon Hall8f89dda2015-01-22 16:03:33 -08001470 cliStart = time.time()
Jon Hall94fd0472014-12-08 11:52:42 -08001471 devices = []
1472 devices.append( main.ONOScli1.devices() )
1473 devices.append( main.ONOScli2.devices() )
1474 devices.append( main.ONOScli3.devices() )
1475 devices.append( main.ONOScli4.devices() )
1476 devices.append( main.ONOScli5.devices() )
1477 devices.append( main.ONOScli6.devices() )
1478 devices.append( main.ONOScli7.devices() )
1479 hosts = []
Jon Hall669173b2014-12-17 11:36:30 -08001480 hosts.append( json.loads( main.ONOScli1.hosts() ) )
1481 hosts.append( json.loads( main.ONOScli2.hosts() ) )
1482 hosts.append( json.loads( main.ONOScli3.hosts() ) )
1483 hosts.append( json.loads( main.ONOScli4.hosts() ) )
1484 hosts.append( json.loads( main.ONOScli5.hosts() ) )
1485 hosts.append( json.loads( main.ONOScli6.hosts() ) )
1486 hosts.append( json.loads( main.ONOScli7.hosts() ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001487 for controller in range( 0, len( hosts ) ):
Jon Hall8f89dda2015-01-22 16:03:33 -08001488 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001489 for host in hosts[ controller ]:
Jon Hall669173b2014-12-17 11:36:30 -08001490 host
Jon Hall6aec96b2015-01-19 14:49:31 -08001491 if host[ 'ips' ] == []:
1492 main.log.error(
1493 "DEBUG:Error with host ips on controller" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001494 controllerStr + ": " + str( host ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001495 ports = []
1496 ports.append( main.ONOScli1.ports() )
1497 ports.append( main.ONOScli2.ports() )
1498 ports.append( main.ONOScli3.ports() )
1499 ports.append( main.ONOScli4.ports() )
1500 ports.append( main.ONOScli5.ports() )
1501 ports.append( main.ONOScli6.ports() )
1502 ports.append( main.ONOScli7.ports() )
1503 links = []
1504 links.append( main.ONOScli1.links() )
1505 links.append( main.ONOScli2.links() )
1506 links.append( main.ONOScli3.links() )
1507 links.append( main.ONOScli4.links() )
1508 links.append( main.ONOScli5.links() )
1509 links.append( main.ONOScli6.links() )
1510 links.append( main.ONOScli7.links() )
1511 clusters = []
1512 clusters.append( main.ONOScli1.clusters() )
1513 clusters.append( main.ONOScli2.clusters() )
1514 clusters.append( main.ONOScli3.clusters() )
1515 clusters.append( main.ONOScli4.clusters() )
1516 clusters.append( main.ONOScli5.clusters() )
1517 clusters.append( main.ONOScli6.clusters() )
1518 clusters.append( main.ONOScli7.clusters() )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001519
Jon Hall8f89dda2015-01-22 16:03:33 -08001520 elapsed = time.time() - startTime
1521 cliTime = time.time() - cliStart
1522 print "CLI time: " + str( cliTime )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001523
Jon Hall8f89dda2015-01-22 16:03:33 -08001524 for controller in range( numControllers ):
1525 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001526 if devices[ controller ] or "Error" not in devices[
1527 controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001528 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -08001529 MNTopo,
1530 json.loads(
1531 devices[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001532 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001533 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001534 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001535 actual=currentDevicesResult,
1536 onpass="ONOS" + controllerStr +
1537 " Switches view is correct",
1538 onfail="ONOS" + controllerStr +
1539 " Switches view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001540
Jon Hall6aec96b2015-01-19 14:49:31 -08001541 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001542 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -08001543 MNTopo,
1544 json.loads(
1545 ports[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001546 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001547 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001548 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001549 actual=currentPortsResult,
1550 onpass="ONOS" + controllerStr +
1551 " ports view is correct",
1552 onfail="ONOS" + controllerStr +
1553 " ports view is incorrect" )
Jon Hall94fd0472014-12-08 11:52:42 -08001554
Jon Hall6aec96b2015-01-19 14:49:31 -08001555 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001556 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -08001557 MNTopo,
1558 json.loads(
1559 links[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001560 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001561 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001562 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001563 actual=currentLinksResult,
1564 onpass="ONOS" + controllerStr +
1565 " links view is correct",
1566 onfail="ONOS" + controllerStr +
1567 " links view is incorrect" )
1568 devicesResults = devicesResults and currentDevicesResult
1569 portsResults = portsResults and currentPortsResult
1570 linksResults = linksResults and currentLinksResult
Jon Hall94fd0472014-12-08 11:52:42 -08001571
Jon Hall529a37f2015-01-28 10:02:00 -08001572 # Compare json objects for hosts and dataplane clusters
Jon Hall94fd0472014-12-08 11:52:42 -08001573
Jon Hall6aec96b2015-01-19 14:49:31 -08001574 # hosts
Jon Hall8f89dda2015-01-22 16:03:33 -08001575 consistentHostsResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -08001576 for controller in range( len( hosts ) ):
Jon Hall8f89dda2015-01-22 16:03:33 -08001577 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001578 if "Error" not in hosts[ controller ]:
1579 if hosts[ controller ] == hosts[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001580 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001581 else: # hosts not consistent
Jon Hall8f89dda2015-01-22 16:03:33 -08001582 main.log.report( "hosts from ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001583 " is inconsistent with ONOS1" )
1584 main.log.warn( repr( hosts[ controller ] ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001585 consistentHostsResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001586
1587 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001588 main.log.report( "Error in getting ONOS hosts from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001589 controllerStr )
1590 consistentHostsResult = main.FALSE
1591 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001592 " hosts response: " +
1593 repr( hosts[ controller ] ) )
1594 utilities.assert_equals(
1595 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001596 actual=consistentHostsResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001597 onpass="Hosts view is consistent across all ONOS nodes",
1598 onfail="ONOS nodes have different views of hosts" )
Jon Hall94fd0472014-12-08 11:52:42 -08001599
Jon Hall6aec96b2015-01-19 14:49:31 -08001600 # Strongly connected clusters of devices
Jon Hall8f89dda2015-01-22 16:03:33 -08001601 consistentClustersResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -08001602 for controller in range( len( clusters ) ):
Jon Hall8f89dda2015-01-22 16:03:33 -08001603 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001604 if "Error" not in clusters[ controller ]:
1605 if clusters[ controller ] == clusters[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001606 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001607 else: # clusters not consistent
1608 main.log.report( "clusters from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001609 controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001610 " is inconsistent with ONOS1" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001611 consistentClustersResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001612
1613 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001614 main.log.report( "Error in getting dataplane clusters " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001615 "from ONOS" + controllerStr )
1616 consistentClustersResult = main.FALSE
1617 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001618 " clusters response: " +
1619 repr( clusters[ controller ] ) )
1620 utilities.assert_equals(
1621 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001622 actual=consistentClustersResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001623 onpass="Clusters view is consistent across all ONOS nodes",
1624 onfail="ONOS nodes have different views of clusters" )
1625 # there should always only be one cluster
Jon Hall8f89dda2015-01-22 16:03:33 -08001626 numClusters = len( json.loads( clusters[ 0 ] ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001627 utilities.assert_equals(
1628 expect=1,
Jon Hall8f89dda2015-01-22 16:03:33 -08001629 actual=numClusters,
Jon Hall6aec96b2015-01-19 14:49:31 -08001630 onpass="ONOS shows 1 SCC",
1631 onfail="ONOS shows " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001632 str( numClusters ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001633 " SCCs" )
Jon Hall94fd0472014-12-08 11:52:42 -08001634
Jon Hall8f89dda2015-01-22 16:03:33 -08001635 topoResult = ( devicesResults and portsResults and linksResults
1636 and consistentHostsResult
Jon Hall529a37f2015-01-28 10:02:00 -08001637 and consistentClustersResult )
Jon Hall94fd0472014-12-08 11:52:42 -08001638
Jon Hall8f89dda2015-01-22 16:03:33 -08001639 topoResult = topoResult and int( count <= 2 )
1640 note = "note it takes about " + str( int( cliTime ) ) + \
1641 " seconds for the test to make all the cli calls to fetch " +\
1642 "the topology from each ONOS instance"
Jon Hall6aec96b2015-01-19 14:49:31 -08001643 main.log.report(
Jon Hall8f89dda2015-01-22 16:03:33 -08001644 "Very crass estimate for topology discovery/convergence( " +
1645 str( note ) + " ): " + str( elapsed ) + " seconds, " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001646 str( count ) + " tries" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001647 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
1648 onpass="Topology Check Test successful",
1649 onfail="Topology Check Test NOT successful" )
1650 if topoResult == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001651 main.log.report( "ONOS topology view matches Mininet topology" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001652
Jon Hall6aec96b2015-01-19 14:49:31 -08001653 def CASE9( self, main ):
1654 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001655 Link s3-s28 down
Jon Hall6aec96b2015-01-19 14:49:31 -08001656 """
1657 import time
1658 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001659
Jon Hall8f89dda2015-01-22 16:03:33 -08001660 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001661
Jon Hall6aec96b2015-01-19 14:49:31 -08001662 description = "Turn off a link to ensure that Link Discovery " +\
Jon Hall8f89dda2015-01-22 16:03:33 -08001663 "is working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001664 main.log.report( description )
1665 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001666
Jon Hall6aec96b2015-01-19 14:49:31 -08001667 main.step( "Kill Link between s3 and s28" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001668 LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001669 main.log.info(
1670 "Waiting " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001671 str( linkSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001672 " seconds for link down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001673 time.sleep( linkSleep )
1674 utilities.assert_equals( expect=main.TRUE, actual=LinkDown,
1675 onpass="Link down succesful",
1676 onfail="Failed to bring link down" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001677 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -08001678
Jon Hall6aec96b2015-01-19 14:49:31 -08001679 def CASE10( self, main ):
1680 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001681 Link s3-s28 up
Jon Hall6aec96b2015-01-19 14:49:31 -08001682 """
1683 import time
1684 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001685
Jon Hall8f89dda2015-01-22 16:03:33 -08001686 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001687
Jon Hall6aec96b2015-01-19 14:49:31 -08001688 description = "Restore a link to ensure that Link Discovery is " + \
Jon Hall8f89dda2015-01-22 16:03:33 -08001689 "working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001690 main.log.report( description )
1691 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001692
Jon Hall6aec96b2015-01-19 14:49:31 -08001693 main.step( "Bring link between s3 and s28 back up" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001694 LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001695 main.log.info(
1696 "Waiting " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001697 str( linkSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001698 " seconds for link up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001699 time.sleep( linkSleep )
1700 utilities.assert_equals( expect=main.TRUE, actual=LinkUp,
1701 onpass="Link up succesful",
1702 onfail="Failed to bring link up" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001703 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -08001704
Jon Hall6aec96b2015-01-19 14:49:31 -08001705 def CASE11( self, main ):
1706 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001707 Switch Down
Jon Hall6aec96b2015-01-19 14:49:31 -08001708 """
1709 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001710 import time
1711
Jon Hall8f89dda2015-01-22 16:03:33 -08001712 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001713
1714 description = "Killing a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001715 main.log.report( description )
1716 main.case( description )
1717 switch = main.params[ 'kill' ][ 'switch' ]
1718 switchDPID = main.params[ 'kill' ][ 'dpid' ]
Jon Hall73cf9cc2014-11-20 22:28:38 -08001719
Jon Hall6aec96b2015-01-19 14:49:31 -08001720 # TODO: Make this switch parameterizable
1721 main.step( "Kill " + switch )
1722 main.log.report( "Deleting " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001723 main.Mininet1.delSwitch( switch )
1724 main.log.info( "Waiting " + str( switchSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001725 " seconds for switch down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001726 time.sleep( switchSleep )
1727 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001728 # Peek at the deleted switch
1729 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001730 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001731 if device and device[ 'available' ] is False:
Jon Hall94fd0472014-12-08 11:52:42 -08001732 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001733 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall8f89dda2015-01-22 16:03:33 -08001734 onpass="Kill switch succesful",
1735 onfail="Failed to kill switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001736
Jon Hall6aec96b2015-01-19 14:49:31 -08001737 def CASE12( self, main ):
1738 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001739 Switch Up
Jon Hall6aec96b2015-01-19 14:49:31 -08001740 """
1741 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001742 import time
Jon Hall669173b2014-12-17 11:36:30 -08001743
Jon Hall8f89dda2015-01-22 16:03:33 -08001744 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall6aec96b2015-01-19 14:49:31 -08001745 switch = main.params[ 'kill' ][ 'switch' ]
1746 switchDPID = main.params[ 'kill' ][ 'dpid' ]
1747 links = main.params[ 'kill' ][ 'links' ].split()
Jon Hall73cf9cc2014-11-20 22:28:38 -08001748 description = "Adding a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001749 main.log.report( description )
1750 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001751
Jon Hall6aec96b2015-01-19 14:49:31 -08001752 main.step( "Add back " + switch )
1753 main.log.report( "Adding back " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001754 main.Mininet1.addSwitch( switch, dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001755 # TODO: New dpid or same? Ask Thomas?
1756 for peer in links:
Jon Hall8f89dda2015-01-22 16:03:33 -08001757 main.Mininet1.addLink( switch, peer )
1758 main.Mininet1.assignSwController(
Jon Hall6aec96b2015-01-19 14:49:31 -08001759 sw=switch.split( 's' )[ 1 ],
Jon Hall8f89dda2015-01-22 16:03:33 -08001760 count=numControllers,
1761 ip1=ONOS1Ip,
1762 port1=ONOS1Port,
1763 ip2=ONOS2Ip,
1764 port2=ONOS2Port,
1765 ip3=ONOS3Ip,
1766 port3=ONOS3Port,
1767 ip4=ONOS4Ip,
1768 port4=ONOS4Port,
1769 ip5=ONOS5Ip,
1770 port5=ONOS5Port,
1771 ip6=ONOS6Ip,
1772 port6=ONOS6Port,
1773 ip7=ONOS7Ip,
1774 port7=ONOS7Port )
Jon Hall6aec96b2015-01-19 14:49:31 -08001775 main.log.info(
1776 "Waiting " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001777 str( switchSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001778 " seconds for switch up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001779 time.sleep( switchSleep )
1780 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001781 # Peek at the deleted switch
1782 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001783 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001784 if device and device[ 'available' ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001785 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001786 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall8f89dda2015-01-22 16:03:33 -08001787 onpass="add switch succesful",
1788 onfail="Failed to add switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001789
Jon Hall6aec96b2015-01-19 14:49:31 -08001790 def CASE13( self, main ):
1791 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001792 Clean up
Jon Hall6aec96b2015-01-19 14:49:31 -08001793 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001794 import os
1795 import time
Jon Hall6aec96b2015-01-19 14:49:31 -08001796 # TODO: make use of this elsewhere
1797 ips = []
Jon Hall8f89dda2015-01-22 16:03:33 -08001798 ips.append( ONOS1Ip )
1799 ips.append( ONOS2Ip )
1800 ips.append( ONOS3Ip )
1801 ips.append( ONOS4Ip )
1802 ips.append( ONOS5Ip )
1803 ips.append( ONOS6Ip )
1804 ips.append( ONOS7Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -08001805
1806 # printing colors to terminal
Jon Hall669173b2014-12-17 11:36:30 -08001807 colors = {}
Jon Hall6aec96b2015-01-19 14:49:31 -08001808 colors[ 'cyan' ] = '\033[96m'
1809 colors[ 'purple' ] = '\033[95m'
1810 colors[ 'blue' ] = '\033[94m'
1811 colors[ 'green' ] = '\033[92m'
1812 colors[ 'yellow' ] = '\033[93m'
1813 colors[ 'red' ] = '\033[91m'
1814 colors[ 'end' ] = '\033[0m'
Jon Hall73cf9cc2014-11-20 22:28:38 -08001815 description = "Test Cleanup"
Jon Hall6aec96b2015-01-19 14:49:31 -08001816 main.log.report( description )
1817 main.case( description )
1818 main.step( "Killing tcpdumps" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001819 main.Mininet2.stopTcpdump()
Jon Hall73cf9cc2014-11-20 22:28:38 -08001820
Jon Hall6aec96b2015-01-19 14:49:31 -08001821 main.step( "Checking ONOS Logs for errors" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001822 for i in range( 7 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001823 print colors[ 'purple' ] + "Checking logs for errors on " + \
Jon Hall8f89dda2015-01-22 16:03:33 -08001824 "ONOS" + str( i + 1 ) + ":" + colors[ 'end' ]
1825 print main.ONOSbench.checkLogs( ips[ i ] )
Jon Hall94fd0472014-12-08 11:52:42 -08001826
Jon Hall6aec96b2015-01-19 14:49:31 -08001827 main.step( "Copying MN pcap and ONOS log files to test station" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001828 testname = main.TEST
Jon Hall8f89dda2015-01-22 16:03:33 -08001829 teststationUser = main.params[ 'TESTONUSER' ]
1830 teststationIP = main.params[ 'TESTONIP' ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001831 # NOTE: MN Pcap file is being saved to ~/packet_captures
Jon Hall73cf9cc2014-11-20 22:28:38 -08001832 # scp this file as MN and TestON aren't necessarily the same vm
Jon Hall6aec96b2015-01-19 14:49:31 -08001833 # FIXME: scp
1834 # mn files
1835 # TODO: Load these from params
1836 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001837 logFolder = "/opt/onos/log/"
1838 logFiles = [ "karaf.log", "karaf.log.1" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001839 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001840 dstDir = "~/packet_captures/"
1841 for f in logFiles:
1842 for i in range( 7 ):
1843 main.ONOSbench.handle.sendline( "scp sdn@" + ips[ i ] + ":" +
1844 logFolder + f + " " +
1845 teststationUser + "@" +
1846 teststationIP + ":" +
1847 dstDir + str( testname ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001848 "-ONOS" + str( i + 1 ) + "-" +
1849 f )
1850 # std*.log's
1851 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001852 logFolder = "/opt/onos/var/"
1853 logFiles = [ "stderr.log", "stdout.log" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001854 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001855 dstDir = "~/packet_captures/"
1856 for f in logFiles:
1857 for i in range( 7 ):
1858 main.ONOSbench.handle.sendline( "scp sdn@" + ips[ i ] + ":" +
1859 logFolder + f + " " +
1860 teststationUser + "@" +
1861 teststationIP + ":" +
1862 dstDir + str( testname ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001863 "-ONOS" + str( i + 1 ) + "-" +
1864 f )
1865 # sleep so scp can finish
1866 time.sleep( 10 )
1867 main.step( "Packing and rotating pcap archives" )
1868 os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001869
Jon Hall6aec96b2015-01-19 14:49:31 -08001870 # TODO: actually check something here
1871 utilities.assert_equals( expect=main.TRUE, actual=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001872 onpass="Test cleanup successful",
1873 onfail="Test cleanup NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001874
Jon Hall6aec96b2015-01-19 14:49:31 -08001875 def CASE14( self, main ):
1876 """
Jon Hall669173b2014-12-17 11:36:30 -08001877 start election app on all onos nodes
Jon Hall6aec96b2015-01-19 14:49:31 -08001878 """
Jon Hall8f89dda2015-01-22 16:03:33 -08001879 leaderResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001880 # install app on onos 1
1881 main.log.info( "Install leadership election app" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001882 main.ONOScli1.featureInstall( "onos-app-election" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001883 # wait for election
1884 # check for leader
Jon Hall8f89dda2015-01-22 16:03:33 -08001885 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001886 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08001887 if leader == ONOS1Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08001888 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001889 pass
Jon Hall6aec96b2015-01-19 14:49:31 -08001890 elif leader is None:
1891 # No leader elected
1892 main.log.report( "No leader was elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001893 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001894 elif leader == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001895 # error in response
1896 # TODO: add check for "Command not found:" in the driver, this
1897 # means the app isn't loaded
Jon Hall8f89dda2015-01-22 16:03:33 -08001898 main.log.report( "Something is wrong with electionTestLeader" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001899 " function, check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001900 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001901 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001902 # error in response
1903 main.log.report(
Jon Hall8f89dda2015-01-22 16:03:33 -08001904 "Unexpected response from electionTestLeader function:'" +
1905 str( leader ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001906 "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001907 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001908
Jon Hall6aec96b2015-01-19 14:49:31 -08001909 # install on other nodes and check for leader.
1910 # Should be onos1 and each app should show the same leader
Jon Hall8f89dda2015-01-22 16:03:33 -08001911 for controller in range( 2, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001912 # loop through ONOScli handlers
1913 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001914 node.featureInstall( "onos-app-election" )
1915 leaderN = node.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001916 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08001917 if leaderN == ONOS1Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08001918 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001919 pass
1920 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001921 # error in response
1922 # TODO: add check for "Command not found:" in the driver, this
1923 # means the app isn't loaded
1924 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001925 "electionTestLeader function, check the" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001926 " error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001927 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001928 elif leader != leaderN:
Jon Hall8f89dda2015-01-22 16:03:33 -08001929 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001930 main.log.report( "ONOS" + str( controller ) + " sees " +
1931 str( leaderN ) +
1932 " as the leader of the election app. Leader" +
1933 " should be " +
1934 str( leader ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001935 if leaderResult:
Jon Hall6aec96b2015-01-19 14:49:31 -08001936 main.log.report( "Leadership election tests passed( consistent " +
1937 "view of leader across listeners and a leader " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001938 "was elected )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001939 utilities.assert_equals(
1940 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001941 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001942 onpass="Leadership election passed",
1943 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08001944
Jon Hall6aec96b2015-01-19 14:49:31 -08001945 def CASE15( self, main ):
1946 """
Jon Hall669173b2014-12-17 11:36:30 -08001947 Check that Leadership Election is still functional
Jon Hall6aec96b2015-01-19 14:49:31 -08001948 """
Jon Hall8f89dda2015-01-22 16:03:33 -08001949 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08001950 description = "Check that Leadership Election is still functional"
Jon Hall6aec96b2015-01-19 14:49:31 -08001951 main.log.report( description )
1952 main.case( description )
1953 main.step( "Find current leader and withdraw" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001954 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001955 # TODO: do some sanity checking on leader before using it
Jon Hall8f89dda2015-01-22 16:03:33 -08001956 withdrawResult = main.FALSE
1957 if leader == ONOS1Ip:
1958 oldLeader = getattr( main, "ONOScli1" )
1959 elif leader == ONOS2Ip:
1960 oldLeader = getattr( main, "ONOScli2" )
1961 elif leader == ONOS3Ip:
1962 oldLeader = getattr( main, "ONOScli3" )
1963 elif leader == ONOS4Ip:
1964 oldLeader = getattr( main, "ONOScli4" )
1965 elif leader == ONOS5Ip:
1966 oldLeader = getattr( main, "ONOScli5" )
1967 elif leader == ONOS6Ip:
1968 oldLeader = getattr( main, "ONOScli6" )
1969 elif leader == ONOS7Ip:
1970 oldLeader = getattr( main, "ONOScli7" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001971 elif leader is None or leader == main.FALSE:
1972 main.log.report(
1973 "Leader for the election app should be an ONOS node," +
1974 "instead got '" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001975 str( leader ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001976 "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001977 leaderResult = main.FALSE
1978 withdrawResult = oldLeader.electionTestWithdraw()
Jon Hall6aec96b2015-01-19 14:49:31 -08001979 utilities.assert_equals(
1980 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001981 actual=withdrawResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001982 onpass="App was withdrawn from election",
1983 onfail="App was not withdrawn from election" )
Jon Hall669173b2014-12-17 11:36:30 -08001984
Jon Hall6aec96b2015-01-19 14:49:31 -08001985 main.step( "Make sure new leader is elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001986 leaderList = []
1987 for controller in range( 1, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001988 # loop through ONOScli handlers
1989 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001990 leaderList.append( node.electionTestLeader() )
1991 for leaderN in leaderList:
Jon Hall669173b2014-12-17 11:36:30 -08001992 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08001993 main.log.report(
1994 "ONOS" +
1995 str( controller ) +
1996 " still sees " +
1997 str( leader ) +
1998 " as leader after they withdrew" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001999 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08002000 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08002001 # error in response
2002 # TODO: add check for "Command not found:" in the driver, this
2003 # means the app isn't loaded
2004 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002005 "electionTestLeader function, " +
Jon Hall6aec96b2015-01-19 14:49:31 -08002006 "check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002007 leaderResult = main.FALSE
2008 consistentLeader = main.FALSE
2009 if len( set( leaderList ) ) == 1:
Jon Hall6aec96b2015-01-19 14:49:31 -08002010 main.log.info( "Each Election-app sees '" +
Jon Hall8f89dda2015-01-22 16:03:33 -08002011 str( leaderList[ 0 ] ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08002012 "' as the leader" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002013 consistentLeader = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08002014 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08002015 main.log.report(
2016 "Inconsistent responses for leader of Election-app:" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002017 for n in range( len( leaderList ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -08002018 main.log.report( "ONOS" + str( n + 1 ) + " response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002019 str( leaderList[ n ] ) )
2020 if leaderResult:
2021 main.log.report( "Leadership election tests passed( consistent " +
Jon Hall6aec96b2015-01-19 14:49:31 -08002022 "view of leader across listeners and a new " +
2023 "leader was elected when the old leader " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002024 "resigned )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08002025 utilities.assert_equals(
2026 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002027 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002028 onpass="Leadership election passed",
2029 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08002030
Jon Hall6aec96b2015-01-19 14:49:31 -08002031 main.step(
Jon Hall8f89dda2015-01-22 16:03:33 -08002032 "Run for election on old leader( just so everyone is in the hat )" )
2033 runResult = oldLeader.electionTestRun()
Jon Hall6aec96b2015-01-19 14:49:31 -08002034 utilities.assert_equals(
2035 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002036 actual=runResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002037 onpass="App re-ran for election",
2038 onfail="App failed to run for election" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002039 if consistentLeader == main.TRUE:
2040 afterRun = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08002041 # verify leader didn't just change
Jon Hall8f89dda2015-01-22 16:03:33 -08002042 if afterRun == leaderList[ 0 ]:
2043 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08002044 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08002045 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08002046 # TODO: assert on run and withdraw results?
Jon Hall669173b2014-12-17 11:36:30 -08002047
Jon Hall6aec96b2015-01-19 14:49:31 -08002048 utilities.assert_equals(
2049 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002050 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002051 onpass="Leadership election passed",
2052 onfail="Something went wrong with Leadership election after " +
2053 "the old leader re-ran for election" )