blob: 2933c932012992f6e9f5eb3958d68977ae16facc [file] [log] [blame]
Jon Hall6aec96b2015-01-19 14:49:31 -08001"""
Jon Hall73cf9cc2014-11-20 22:28:38 -08002Description: This test is to determine if ONOS can handle
3 all of it's nodes restarting
4
5List of test cases:
6CASE1: Compile ONOS and push it to the test machines
7CASE2: Assign mastership to controllers
8CASE3: Assign intents
9CASE4: Ping across added host intents
10CASE5: Reading state of ONOS
11CASE6: The Failure case.
12CASE7: Check state after control plane failure
13CASE8: Compare topo
14CASE9: Link s3-s28 down
15CASE10: Link s3-s28 up
16CASE11: Switch down
17CASE12: Switch up
18CASE13: Clean up
Jon Hall669173b2014-12-17 11:36:30 -080019CASE14: start election app on all onos nodes
20CASE15: Check that Leadership Election is still functional
Jon Hall6aec96b2015-01-19 14:49:31 -080021"""
Jon Hall8f89dda2015-01-22 16:03:33 -080022
23
Jon Hall73cf9cc2014-11-20 22:28:38 -080024class HATestClusterRestart:
25
Jon Hall6aec96b2015-01-19 14:49:31 -080026 def __init__( self ):
Jon Hall73cf9cc2014-11-20 22:28:38 -080027 self.default = ''
28
Jon Hall6aec96b2015-01-19 14:49:31 -080029 def CASE1( self, main ):
30 """
Jon Hall73cf9cc2014-11-20 22:28:38 -080031 CASE1 is to compile ONOS and push it to the test machines
32
33 Startup sequence:
34 git pull
35 mvn clean install
36 onos-package
37 cell <name>
38 onos-verify-cell
39 NOTE: temporary - onos-remove-raft-logs
40 onos-install -f
41 onos-wait-for-start
Jon Hall6aec96b2015-01-19 14:49:31 -080042 """
43 main.log.report( "ONOS HA test: Restart all ONOS nodes - " +
44 "initialization" )
45 main.case( "Setting up test environment" )
46 # TODO: save all the timers and output them for plotting
Jon Hall73cf9cc2014-11-20 22:28:38 -080047
48 # load some vairables from the params file
Jon Hall8f89dda2015-01-22 16:03:33 -080049 PULLCODE = False
Jon Hall6aec96b2015-01-19 14:49:31 -080050 if main.params[ 'Git' ] == 'True':
Jon Hall8f89dda2015-01-22 16:03:33 -080051 PULLCODE = True
Jon Hall529a37f2015-01-28 10:02:00 -080052 gitBranch = main.params[ 'branch' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080053 cellName = main.params[ 'ENV' ][ 'cellName' ]
Jon Hall6aec96b2015-01-19 14:49:31 -080054
55 # set global variables
Jon Hall8f89dda2015-01-22 16:03:33 -080056 global ONOS1Ip
57 global ONOS1Port
58 global ONOS2Ip
59 global ONOS2Port
60 global ONOS3Ip
61 global ONOS3Port
62 global ONOS4Ip
63 global ONOS4Port
64 global ONOS5Ip
65 global ONOS5Port
66 global ONOS6Ip
67 global ONOS6Port
68 global ONOS7Ip
69 global ONOS7Port
70 global numControllers
Jon Hall73cf9cc2014-11-20 22:28:38 -080071
Jon Hall8f89dda2015-01-22 16:03:33 -080072 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
73 ONOS1Port = main.params[ 'CTRL' ][ 'port1' ]
74 ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
75 ONOS2Port = main.params[ 'CTRL' ][ 'port2' ]
76 ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ]
77 ONOS3Port = main.params[ 'CTRL' ][ 'port3' ]
78 ONOS4Ip = main.params[ 'CTRL' ][ 'ip4' ]
79 ONOS4Port = main.params[ 'CTRL' ][ 'port4' ]
80 ONOS5Ip = main.params[ 'CTRL' ][ 'ip5' ]
81 ONOS5Port = main.params[ 'CTRL' ][ 'port5' ]
82 ONOS6Ip = main.params[ 'CTRL' ][ 'ip6' ]
83 ONOS6Port = main.params[ 'CTRL' ][ 'port6' ]
84 ONOS7Ip = main.params[ 'CTRL' ][ 'ip7' ]
85 ONOS7Port = main.params[ 'CTRL' ][ 'port7' ]
86 numControllers = int( main.params[ 'num_controllers' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -080087
Jon Hall6aec96b2015-01-19 14:49:31 -080088 main.step( "Applying cell variable to environment" )
Jon Hall8f89dda2015-01-22 16:03:33 -080089 cellResult = main.ONOSbench.setCell( cellName )
90 verifyResult = main.ONOSbench.verifyCell()
Jon Hall73cf9cc2014-11-20 22:28:38 -080091
Jon Hall6aec96b2015-01-19 14:49:31 -080092 # FIXME:this is short term fix
93 main.log.report( "Removing raft logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -080094 main.ONOSbench.onosRemoveRaftLogs()
Jon Hall6aec96b2015-01-19 14:49:31 -080095 main.log.report( "Uninstalling ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -080096 main.ONOSbench.onosUninstall( ONOS1Ip )
97 main.ONOSbench.onosUninstall( ONOS2Ip )
98 main.ONOSbench.onosUninstall( ONOS3Ip )
99 main.ONOSbench.onosUninstall( ONOS4Ip )
100 main.ONOSbench.onosUninstall( ONOS5Ip )
101 main.ONOSbench.onosUninstall( ONOS6Ip )
102 main.ONOSbench.onosUninstall( ONOS7Ip )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800103
Jon Hall8f89dda2015-01-22 16:03:33 -0800104 cleanInstallResult = main.TRUE
105 gitPullResult = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800106
Jon Hall97f31752015-02-04 12:01:04 -0800107 main.step( "Starting Mininet" )
108 main.Mininet1.startNet( )
109
Jon Hall6aec96b2015-01-19 14:49:31 -0800110 main.step( "Compiling the latest version of ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800111 if PULLCODE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800112 # TODO Configure branch in params
113 main.step( "Git checkout and pull master" )
Jon Hall529a37f2015-01-28 10:02:00 -0800114 main.ONOSbench.gitCheckout( gitBranch )
Jon Hall8f89dda2015-01-22 16:03:33 -0800115 gitPullResult = main.ONOSbench.gitPull()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800116
Jon Hall6aec96b2015-01-19 14:49:31 -0800117 main.step( "Using mvn clean & install" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800118 cleanInstallResult = main.ONOSbench.cleanInstall()
Jon Hall6aec96b2015-01-19 14:49:31 -0800119 else:
120 main.log.warn( "Did not pull new code so skipping mvn " +
121 "clean install" )
Jon Hall529a37f2015-01-28 10:02:00 -0800122 main.ONOSbench.getVersion( report=True )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800123
Jon Hall6aec96b2015-01-19 14:49:31 -0800124 main.step( "Creating ONOS package" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800125 packageResult = main.ONOSbench.onosPackage()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800126
Jon Hall6aec96b2015-01-19 14:49:31 -0800127 main.step( "Installing ONOS package" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800128 onos1InstallResult = main.ONOSbench.onosInstall( options="-f",
129 node=ONOS1Ip )
130 onos2InstallResult = main.ONOSbench.onosInstall( options="-f",
131 node=ONOS2Ip )
132 onos3InstallResult = main.ONOSbench.onosInstall( options="-f",
133 node=ONOS3Ip )
134 onos4InstallResult = main.ONOSbench.onosInstall( options="-f",
135 node=ONOS4Ip )
136 onos5InstallResult = main.ONOSbench.onosInstall( options="-f",
137 node=ONOS5Ip )
138 onos6InstallResult = main.ONOSbench.onosInstall( options="-f",
139 node=ONOS6Ip )
140 onos7InstallResult = main.ONOSbench.onosInstall( options="-f",
141 node=ONOS7Ip )
142 onosInstallResult = onos1InstallResult and onos2InstallResult\
143 and onos3InstallResult and onos4InstallResult\
144 and onos5InstallResult and onos6InstallResult\
145 and onos7InstallResult
Jon Hall73cf9cc2014-11-20 22:28:38 -0800146
Jon Hall6aec96b2015-01-19 14:49:31 -0800147 main.step( "Checking if ONOS is up yet" )
148 # TODO check bundle:list?
149 for i in range( 2 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800150 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
151 if not onos1Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800152 main.log.report( "ONOS1 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800153 onos2Isup = main.ONOSbench.isup( ONOS2Ip )
154 if not onos2Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800155 main.log.report( "ONOS2 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800156 onos3Isup = main.ONOSbench.isup( ONOS3Ip )
157 if not onos3Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800158 main.log.report( "ONOS3 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800159 onos4Isup = main.ONOSbench.isup( ONOS4Ip )
160 if not onos4Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800161 main.log.report( "ONOS4 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800162 onos5Isup = main.ONOSbench.isup( ONOS5Ip )
163 if not onos5Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800164 main.log.report( "ONOS5 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800165 onos6Isup = main.ONOSbench.isup( ONOS6Ip )
166 if not onos6Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800167 main.log.report( "ONOS6 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800168 onos7Isup = main.ONOSbench.isup( ONOS7Ip )
169 if not onos7Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800170 main.log.report( "ONOS7 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800171 onosIsupResult = onos1Isup and onos2Isup and onos3Isup\
172 and onos4Isup and onos5Isup and onos6Isup and onos7Isup
173 if onosIsupResult == main.TRUE:
Jon Hall94fd0472014-12-08 11:52:42 -0800174 break
Jon Hall73cf9cc2014-11-20 22:28:38 -0800175
Jon Hall8f89dda2015-01-22 16:03:33 -0800176 cliResult1 = main.ONOScli1.startOnosCli( ONOS1Ip )
177 cliResult2 = main.ONOScli2.startOnosCli( ONOS2Ip )
178 cliResult3 = main.ONOScli3.startOnosCli( ONOS3Ip )
179 cliResult4 = main.ONOScli4.startOnosCli( ONOS4Ip )
180 cliResult5 = main.ONOScli5.startOnosCli( ONOS5Ip )
181 cliResult6 = main.ONOScli6.startOnosCli( ONOS6Ip )
182 cliResult7 = main.ONOScli7.startOnosCli( ONOS7Ip )
183 cliResults = cliResult1 and cliResult2 and cliResult3 and\
184 cliResult4 and cliResult5 and cliResult6 and cliResult7
Jon Hall73cf9cc2014-11-20 22:28:38 -0800185
Jon Hall6aec96b2015-01-19 14:49:31 -0800186 main.step( "Start Packet Capture MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800187 main.Mininet2.startTcpdump(
Jon Hall6aec96b2015-01-19 14:49:31 -0800188 str( main.params[ 'MNtcpdump' ][ 'folder' ] ) + str( main.TEST )
189 + "-MN.pcap",
190 intf=main.params[ 'MNtcpdump' ][ 'intf' ],
191 port=main.params[ 'MNtcpdump' ][ 'port' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800192
Jon Hall8f89dda2015-01-22 16:03:33 -0800193 case1Result = ( cleanInstallResult and packageResult and
194 cellResult and verifyResult and onosInstallResult
195 and onosIsupResult and cliResults )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800196
Jon Hall8f89dda2015-01-22 16:03:33 -0800197 utilities.assert_equals( expect=main.TRUE, actual=case1Result,
198 onpass="Test startup successful",
199 onfail="Test startup NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800200
Jon Hall8f89dda2015-01-22 16:03:33 -0800201 if case1Result == main.FALSE:
Jon Hall94fd0472014-12-08 11:52:42 -0800202 main.cleanup()
203 main.exit()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800204
Jon Hall6aec96b2015-01-19 14:49:31 -0800205 def CASE2( self, main ):
206 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800207 Assign mastership to controllers
Jon Hall6aec96b2015-01-19 14:49:31 -0800208 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800209 import re
210
Jon Hall6aec96b2015-01-19 14:49:31 -0800211 main.log.report( "Assigning switches to controllers" )
212 main.case( "Assigning Controllers" )
213 main.step( "Assign switches to controllers" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800214
Jon Hall6aec96b2015-01-19 14:49:31 -0800215 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800216 main.Mininet1.assignSwController(
Jon Hall6aec96b2015-01-19 14:49:31 -0800217 sw=str( i ),
Jon Hall8f89dda2015-01-22 16:03:33 -0800218 count=numControllers,
219 ip1=ONOS1Ip, port1=ONOS1Port,
220 ip2=ONOS2Ip, port2=ONOS2Port,
221 ip3=ONOS3Ip, port3=ONOS3Port,
222 ip4=ONOS4Ip, port4=ONOS4Port,
223 ip5=ONOS5Ip, port5=ONOS5Port,
224 ip6=ONOS6Ip, port6=ONOS6Port,
225 ip7=ONOS7Ip, port7=ONOS7Port )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800226
Jon Hall8f89dda2015-01-22 16:03:33 -0800227 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800228 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800229 response = main.Mininet1.getSwController( "s" + str( i ) )
Jon Hallffb386d2014-11-21 13:43:38 -0800230 try:
Jon Hall6aec96b2015-01-19 14:49:31 -0800231 main.log.info( str( response ) )
Jon Hallffb386d2014-11-21 13:43:38 -0800232 except:
Jon Hall6aec96b2015-01-19 14:49:31 -0800233 main.log.info( repr( response ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800234 if re.search( "tcp:" + ONOS1Ip, response )\
235 and re.search( "tcp:" + ONOS2Ip, response )\
236 and re.search( "tcp:" + ONOS3Ip, response )\
237 and re.search( "tcp:" + ONOS4Ip, response )\
238 and re.search( "tcp:" + ONOS5Ip, response )\
239 and re.search( "tcp:" + ONOS6Ip, response )\
240 and re.search( "tcp:" + ONOS7Ip, response ):
241 mastershipCheck = mastershipCheck and main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800242 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800243 mastershipCheck = main.FALSE
244 if mastershipCheck == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800245 main.log.report( "Switch mastership assigned correctly" )
246 utilities.assert_equals(
247 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800248 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800249 onpass="Switch mastership assigned correctly",
250 onfail="Switches not assigned correctly to controllers" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800251
Jon Hall6aec96b2015-01-19 14:49:31 -0800252 # Manually assign mastership to the controller we want
Jon Hall8f89dda2015-01-22 16:03:33 -0800253 roleCall = main.TRUE
254 roleCheck = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800255
Jon Hall6aec96b2015-01-19 14:49:31 -0800256 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800257 deviceId = main.ONOScli1.getDevice( "1000" ).get( 'id' )
258 roleCall = roleCall and main.ONOScli1.deviceRole(
259 deviceId,
260 ONOS1Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800261 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800262 if ONOS1Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
263 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800264 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800265 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800266
Jon Hall6aec96b2015-01-19 14:49:31 -0800267 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800268 deviceId = main.ONOScli1.getDevice( "2800" ).get( 'id' )
269 roleCall = roleCall and main.ONOScli1.deviceRole(
270 deviceId,
271 ONOS1Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800272 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800273 if ONOS1Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
274 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800275 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800276 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800277
Jon Hall6aec96b2015-01-19 14:49:31 -0800278 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800279 deviceId = main.ONOScli1.getDevice( "2000" ).get( 'id' )
280 roleCall = roleCall and main.ONOScli1.deviceRole(
281 deviceId,
282 ONOS2Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800283 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800284 if ONOS2Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
285 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800286 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800287 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800288
Jon Hall6aec96b2015-01-19 14:49:31 -0800289 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800290 deviceId = main.ONOScli1.getDevice( "3000" ).get( 'id' )
291 roleCall = roleCall and main.ONOScli1.deviceRole(
292 deviceId,
293 ONOS2Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800294 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800295 if ONOS2Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
296 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800297 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800298 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800299
Jon Hall6aec96b2015-01-19 14:49:31 -0800300 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800301 deviceId = main.ONOScli1.getDevice( "5000" ).get( 'id' )
302 roleCall = roleCall and main.ONOScli1.deviceRole(
303 deviceId,
304 ONOS3Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800305 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800306 if ONOS3Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
307 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800308 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800309 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800310
Jon Hall6aec96b2015-01-19 14:49:31 -0800311 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800312 deviceId = main.ONOScli1.getDevice( "6000" ).get( 'id' )
313 roleCall = roleCall and main.ONOScli1.deviceRole(
314 deviceId,
315 ONOS3Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800316 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800317 if ONOS3Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
318 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800319 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800320 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800321
Jon Hall6aec96b2015-01-19 14:49:31 -0800322 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800323 deviceId = main.ONOScli1.getDevice( "3004" ).get( 'id' )
324 roleCall = roleCall and main.ONOScli1.deviceRole(
325 deviceId,
326 ONOS4Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800327 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800328 if ONOS4Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
329 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800330 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800331 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800332
Jon Hall6aec96b2015-01-19 14:49:31 -0800333 for i in range( 8, 18 ):
334 dpid = '3' + str( i ).zfill( 3 )
Jon Hall8f89dda2015-01-22 16:03:33 -0800335 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
336 roleCall = roleCall and main.ONOScli1.deviceRole(
337 deviceId,
338 ONOS5Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800339 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800340 if ONOS5Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
341 roleCheck = roleCheck and main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800342 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800343 roleCheck = roleCheck and main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800344
Jon Hall8f89dda2015-01-22 16:03:33 -0800345 deviceId = main.ONOScli1.getDevice( "6007" ).get( 'id' )
346 roleCall = roleCall and main.ONOScli1.deviceRole(
347 deviceId,
348 ONOS6Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800349 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800350 if ONOS6Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
351 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800352 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800353 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800354
Jon Hall6aec96b2015-01-19 14:49:31 -0800355 for i in range( 18, 28 ):
356 dpid = '6' + str( i ).zfill( 3 )
Jon Hall8f89dda2015-01-22 16:03:33 -0800357 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
358 roleCall = roleCall and main.ONOScli1.deviceRole(
359 deviceId,
360 ONOS7Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800361 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800362 if ONOS7Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
363 roleCheck = roleCheck and main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800364 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800365 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800366
Jon Hall6aec96b2015-01-19 14:49:31 -0800367 utilities.assert_equals(
368 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800369 actual=roleCall,
Jon Hall6aec96b2015-01-19 14:49:31 -0800370 onpass="Re-assigned switch mastership to designated controller",
Jon Hall8f89dda2015-01-22 16:03:33 -0800371 onfail="Something wrong with deviceRole calls" )
Jon Hall94fd0472014-12-08 11:52:42 -0800372
Jon Hall6aec96b2015-01-19 14:49:31 -0800373 utilities.assert_equals(
374 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800375 actual=roleCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800376 onpass="Switches were successfully reassigned to designated " +
377 "controller",
378 onfail="Switches were not successfully reassigned" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800379 mastershipCheck = mastershipCheck and roleCall and roleCheck
380 utilities.assert_equals( expect=main.TRUE, actual=mastershipCheck,
381 onpass="Switch mastership correctly assigned",
382 onfail="Error in ( re )assigning switch" +
383 " mastership" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800384
Jon Hall6aec96b2015-01-19 14:49:31 -0800385 def CASE3( self, main ):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800386 """
387 Assign intents
Jon Hall73cf9cc2014-11-20 22:28:38 -0800388 """
Jon Hall6aec96b2015-01-19 14:49:31 -0800389 # FIXME: we must reinstall intents until we have a persistant
390 # datastore!
Jon Hall73cf9cc2014-11-20 22:28:38 -0800391 import time
Jon Hall6aec96b2015-01-19 14:49:31 -0800392 main.log.report( "Adding host intents" )
393 main.case( "Adding host Intents" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800394
Jon Hall8f89dda2015-01-22 16:03:33 -0800395 main.step( "Discovering Hosts( Via pingall for now )" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800396 # FIXME: Once we have a host discovery mechanism, use that instead
Jon Hall73cf9cc2014-11-20 22:28:38 -0800397
Jon Hall6aec96b2015-01-19 14:49:31 -0800398 # install onos-app-fwd
399 main.log.info( "Install reactive forwarding app" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800400 main.ONOScli1.featureInstall( "onos-app-fwd" )
401 main.ONOScli2.featureInstall( "onos-app-fwd" )
402 main.ONOScli3.featureInstall( "onos-app-fwd" )
403 main.ONOScli4.featureInstall( "onos-app-fwd" )
404 main.ONOScli5.featureInstall( "onos-app-fwd" )
405 main.ONOScli6.featureInstall( "onos-app-fwd" )
406 main.ONOScli7.featureInstall( "onos-app-fwd" )
Jon Hall94fd0472014-12-08 11:52:42 -0800407
Jon Hall6aec96b2015-01-19 14:49:31 -0800408 # REACTIVE FWD test
Jon Hall8f89dda2015-01-22 16:03:33 -0800409 pingResult = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800410 time1 = time.time()
Jon Hall8f89dda2015-01-22 16:03:33 -0800411 pingResult = main.Mininet1.pingall()
Jon Hall529a37f2015-01-28 10:02:00 -0800412 utilities.assert_equals(
413 expect=main.TRUE,
414 actual=pingResult,
415 onpass="Reactive Pingall test passed",
416 onfail="Reactive Pingall failed, one or more ping pairs failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800417 time2 = time.time()
Jon Hall6aec96b2015-01-19 14:49:31 -0800418 main.log.info( "Time for pingall: %2f seconds" % ( time2 - time1 ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800419
Jon Hall6aec96b2015-01-19 14:49:31 -0800420 # uninstall onos-app-fwd
421 main.log.info( "Uninstall reactive forwarding app" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800422 main.ONOScli1.featureUninstall( "onos-app-fwd" )
423 main.ONOScli2.featureUninstall( "onos-app-fwd" )
424 main.ONOScli3.featureUninstall( "onos-app-fwd" )
425 main.ONOScli4.featureUninstall( "onos-app-fwd" )
426 main.ONOScli5.featureUninstall( "onos-app-fwd" )
427 main.ONOScli6.featureUninstall( "onos-app-fwd" )
428 main.ONOScli7.featureUninstall( "onos-app-fwd" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800429 # timeout for fwd flows
430 time.sleep( 10 )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800431
Jon Hall6aec96b2015-01-19 14:49:31 -0800432 main.step( "Add host intents" )
433 # TODO: move the host numbers to params
Jon Hall8f89dda2015-01-22 16:03:33 -0800434 intentAddResult = True
Jon Hall6aec96b2015-01-19 14:49:31 -0800435 for i in range( 8, 18 ):
436 main.log.info( "Adding host intent between h" + str( i ) +
437 " and h" + str( i + 10 ) )
438 host1 = "00:00:00:00:00:" + \
439 str( hex( i )[ 2: ] ).zfill( 2 ).upper()
440 host2 = "00:00:00:00:00:" + \
441 str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper()
Jon Hall8f89dda2015-01-22 16:03:33 -0800442 host1Id = main.ONOScli1.getHost( host1 )[ 'id' ]
443 host2Id = main.ONOScli1.getHost( host2 )[ 'id' ]
Jon Hall6aec96b2015-01-19 14:49:31 -0800444 # NOTE: get host can return None
Jon Hall8f89dda2015-01-22 16:03:33 -0800445 if host1Id and host2Id:
446 tmpResult = main.ONOScli1.addHostIntent(
447 host1Id,
448 host2Id )
Jon Hall669173b2014-12-17 11:36:30 -0800449 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800450 main.log.error( "Error, getHost() failed" )
451 tmpResult = main.FALSE
452 intentAddResult = bool( pingResult and intentAddResult
453 and tmpResult )
Jon Hall529a37f2015-01-28 10:02:00 -0800454 # TODO Check that intents were added?
Jon Hall6aec96b2015-01-19 14:49:31 -0800455 utilities.assert_equals(
456 expect=True,
Jon Hall8f89dda2015-01-22 16:03:33 -0800457 actual=intentAddResult,
Jon Hall529a37f2015-01-28 10:02:00 -0800458 onpass="Pushed host intents to ONOS",
459 onfail="Error in pushing host intents to ONOS" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800460 # TODO Check if intents all exist in datastore
Jon Hall73cf9cc2014-11-20 22:28:38 -0800461
Jon Hall6aec96b2015-01-19 14:49:31 -0800462 def CASE4( self, main ):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800463 """
464 Ping across added host intents
465 """
466 description = " Ping across added host intents"
Jon Hall6aec96b2015-01-19 14:49:31 -0800467 main.log.report( description )
468 main.case( description )
Jon Hall8f89dda2015-01-22 16:03:33 -0800469 PingResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800470 for i in range( 8, 18 ):
471 ping = main.Mininet1.pingHost(
472 src="h" + str( i ), target="h" + str( i + 10 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800473 PingResult = PingResult and ping
Jon Hall6aec96b2015-01-19 14:49:31 -0800474 if ping == main.FALSE:
475 main.log.warn( "Ping failed between h" + str( i ) +
476 " and h" + str( i + 10 ) )
477 elif ping == main.TRUE:
478 main.log.info( "Ping test passed!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800479 PingResult = main.TRUE
480 if PingResult == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800481 main.log.report(
482 "Intents have not been installed correctly, pings failed." )
Jon Hall529a37f2015-01-28 10:02:00 -0800483 #TODO: pretty print
484 main.log.warn( "ONSO1 intents: " )
485 main.log.warn( json.dumps( json.loads( main.ONOScli1.intents() ),
486 sort_keys=True,
487 indent=4,
488 separators=( ',', ': ' ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800489 if PingResult == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800490 main.log.report(
491 "Intents have been installed correctly and verified by pings" )
492 utilities.assert_equals(
493 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800494 actual=PingResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800495 onpass="Intents have been installed correctly and pings work",
496 onfail="Intents have not been installed correctly, pings failed." )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800497
Jon Hall6aec96b2015-01-19 14:49:31 -0800498 def CASE5( self, main ):
499 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800500 Reading state of ONOS
Jon Hall6aec96b2015-01-19 14:49:31 -0800501 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800502 import json
Jon Hall6aec96b2015-01-19 14:49:31 -0800503 # assumes that sts is already in you PYTHONPATH
504 from sts.topology.teston_topology import TestONTopology
Jon Hall73cf9cc2014-11-20 22:28:38 -0800505
Jon Hall6aec96b2015-01-19 14:49:31 -0800506 main.log.report( "Setting up and gathering data for current state" )
507 main.case( "Setting up and gathering data for current state" )
508 # The general idea for this test case is to pull the state of
509 # ( intents,flows, topology,... ) from each ONOS node
510 # We can then compare them with eachother and also with past states
Jon Hall73cf9cc2014-11-20 22:28:38 -0800511
Jon Hall6aec96b2015-01-19 14:49:31 -0800512 main.step( "Get the Mastership of each switch from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800513 global mastershipState
514 mastershipState = []
Jon Hall94fd0472014-12-08 11:52:42 -0800515
Jon Hall6aec96b2015-01-19 14:49:31 -0800516 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -0800517 ONOS1MasterNotNull = main.ONOScli1.rolesNotNull()
518 ONOS2MasterNotNull = main.ONOScli2.rolesNotNull()
519 ONOS3MasterNotNull = main.ONOScli3.rolesNotNull()
520 ONOS4MasterNotNull = main.ONOScli4.rolesNotNull()
521 ONOS5MasterNotNull = main.ONOScli5.rolesNotNull()
522 ONOS6MasterNotNull = main.ONOScli6.rolesNotNull()
523 ONOS7MasterNotNull = main.ONOScli7.rolesNotNull()
524 rolesNotNull = ONOS1MasterNotNull and ONOS2MasterNotNull and\
525 ONOS3MasterNotNull and ONOS4MasterNotNull and\
526 ONOS5MasterNotNull and ONOS6MasterNotNull and\
527 ONOS7MasterNotNull
Jon Hall6aec96b2015-01-19 14:49:31 -0800528 utilities.assert_equals(
529 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800530 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -0800531 onpass="Each device has a master",
532 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -0800533
Jon Hall8f89dda2015-01-22 16:03:33 -0800534 ONOS1Mastership = main.ONOScli1.roles()
535 ONOS2Mastership = main.ONOScli2.roles()
536 ONOS3Mastership = main.ONOScli3.roles()
537 ONOS4Mastership = main.ONOScli4.roles()
538 ONOS5Mastership = main.ONOScli5.roles()
539 ONOS6Mastership = main.ONOScli6.roles()
540 ONOS7Mastership = main.ONOScli7.roles()
541 if "Error" in ONOS1Mastership or not ONOS1Mastership\
542 or "Error" in ONOS2Mastership or not ONOS2Mastership\
543 or "Error" in ONOS3Mastership or not ONOS3Mastership\
544 or "Error" in ONOS4Mastership or not ONOS4Mastership\
545 or "Error" in ONOS5Mastership or not ONOS5Mastership\
546 or "Error" in ONOS6Mastership or not ONOS6Mastership\
547 or "Error" in ONOS7Mastership or not ONOS7Mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -0800548 main.log.report( "Error in getting ONOS roles" )
549 main.log.warn(
550 "ONOS1 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800551 repr( ONOS1Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800552 main.log.warn(
553 "ONOS2 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800554 repr( ONOS2Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800555 main.log.warn(
556 "ONOS3 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800557 repr( ONOS3Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800558 main.log.warn(
559 "ONOS4 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800560 repr( ONOS4Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800561 main.log.warn(
562 "ONOS5 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800563 repr( ONOS5Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800564 main.log.warn(
565 "ONOS6 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800566 repr( ONOS6Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800567 main.log.warn(
568 "ONOS7 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800569 repr( ONOS7Mastership ) )
570 consistentMastership = main.FALSE
571 elif ONOS1Mastership == ONOS2Mastership\
572 and ONOS1Mastership == ONOS3Mastership\
573 and ONOS1Mastership == ONOS4Mastership\
574 and ONOS1Mastership == ONOS5Mastership\
575 and ONOS1Mastership == ONOS6Mastership\
576 and ONOS1Mastership == ONOS7Mastership:
577 mastershipState = ONOS1Mastership
578 consistentMastership = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800579 main.log.report(
580 "Switch roles are consistent across all ONOS nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800581 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800582 main.log.warn(
583 "ONOS1 roles: ",
584 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800585 json.loads( ONOS1Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800586 sort_keys=True,
587 indent=4,
588 separators=(
589 ',',
590 ': ' ) ) )
591 main.log.warn(
592 "ONOS2 roles: ",
593 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800594 json.loads( ONOS2Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800595 sort_keys=True,
596 indent=4,
597 separators=(
598 ',',
599 ': ' ) ) )
600 main.log.warn(
601 "ONOS3 roles: ",
602 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800603 json.loads( ONOS3Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800604 sort_keys=True,
605 indent=4,
606 separators=(
607 ',',
608 ': ' ) ) )
609 main.log.warn(
610 "ONOS4 roles: ",
611 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800612 json.loads( ONOS4Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800613 sort_keys=True,
614 indent=4,
615 separators=(
616 ',',
617 ': ' ) ) )
618 main.log.warn(
619 "ONOS5 roles: ",
620 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800621 json.loads( ONOS5Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800622 sort_keys=True,
623 indent=4,
624 separators=(
625 ',',
626 ': ' ) ) )
627 main.log.warn(
628 "ONOS6 roles: ",
629 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800630 json.loads( ONOS6Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800631 sort_keys=True,
632 indent=4,
633 separators=(
634 ',',
635 ': ' ) ) )
636 main.log.warn(
637 "ONOS7 roles: ",
638 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800639 json.loads( ONOS7Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800640 sort_keys=True,
641 indent=4,
642 separators=(
643 ',',
644 ': ' ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800645 consistentMastership = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800646 utilities.assert_equals(
647 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800648 actual=consistentMastership,
Jon Hall6aec96b2015-01-19 14:49:31 -0800649 onpass="Switch roles are consistent across all ONOS nodes",
650 onfail="ONOS nodes have different views of switch roles" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800651
Jon Hall6aec96b2015-01-19 14:49:31 -0800652 main.step( "Get the intents from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800653 global intentState
654 intentState = []
655 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
656 ONOS2Intents = main.ONOScli2.intents( jsonFormat=True )
657 ONOS3Intents = main.ONOScli3.intents( jsonFormat=True )
658 ONOS4Intents = main.ONOScli4.intents( jsonFormat=True )
659 ONOS5Intents = main.ONOScli5.intents( jsonFormat=True )
660 ONOS6Intents = main.ONOScli6.intents( jsonFormat=True )
661 ONOS7Intents = main.ONOScli7.intents( jsonFormat=True )
662 intentCheck = main.FALSE
663 if "Error" in ONOS1Intents or not ONOS1Intents\
664 or "Error" in ONOS2Intents or not ONOS2Intents\
665 or "Error" in ONOS3Intents or not ONOS3Intents\
666 or "Error" in ONOS4Intents or not ONOS4Intents\
667 or "Error" in ONOS5Intents or not ONOS5Intents\
668 or "Error" in ONOS6Intents or not ONOS6Intents\
669 or "Error" in ONOS7Intents or not ONOS7Intents:
Jon Hall6aec96b2015-01-19 14:49:31 -0800670 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800671 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
672 main.log.warn( "ONOS2 intents response: " + repr( ONOS2Intents ) )
673 main.log.warn( "ONOS3 intents response: " + repr( ONOS3Intents ) )
674 main.log.warn( "ONOS4 intents response: " + repr( ONOS4Intents ) )
675 main.log.warn( "ONOS5 intents response: " + repr( ONOS5Intents ) )
676 main.log.warn( "ONOS6 intents response: " + repr( ONOS6Intents ) )
677 main.log.warn( "ONOS7 intents response: " + repr( ONOS7Intents ) )
678 elif ONOS1Intents == ONOS2Intents\
679 and ONOS1Intents == ONOS3Intents\
680 and ONOS1Intents == ONOS4Intents\
681 and ONOS1Intents == ONOS5Intents\
682 and ONOS1Intents == ONOS6Intents\
683 and ONOS1Intents == ONOS7Intents:
684 intentState = ONOS1Intents
685 intentCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800686 main.log.report( "Intents are consistent across all ONOS nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800687 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800688 main.log.warn(
689 "ONOS1 intents: ",
690 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800691 json.loads( ONOS1Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800692 sort_keys=True,
693 indent=4,
694 separators=(
695 ',',
696 ': ' ) ) )
697 main.log.warn(
698 "ONOS2 intents: ",
699 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800700 json.loads( ONOS2Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800701 sort_keys=True,
702 indent=4,
703 separators=(
704 ',',
705 ': ' ) ) )
706 main.log.warn(
707 "ONOS3 intents: ",
708 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800709 json.loads( ONOS3Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800710 sort_keys=True,
711 indent=4,
712 separators=(
713 ',',
714 ': ' ) ) )
715 main.log.warn(
716 "ONOS4 intents: ",
717 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800718 json.loads( ONOS4Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800719 sort_keys=True,
720 indent=4,
721 separators=(
722 ',',
723 ': ' ) ) )
724 main.log.warn(
725 "ONOS5 intents: ",
726 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800727 json.loads( ONOS5Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800728 sort_keys=True,
729 indent=4,
730 separators=(
731 ',',
732 ': ' ) ) )
733 main.log.warn(
734 "ONOS6 intents: ",
735 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800736 json.loads( ONOS6Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800737 sort_keys=True,
738 indent=4,
739 separators=(
740 ',',
741 ': ' ) ) )
742 main.log.warn(
743 "ONOS7 intents: ",
744 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800745 json.loads( ONOS7Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800746 sort_keys=True,
747 indent=4,
748 separators=(
749 ',',
750 ': ' ) ) )
751 utilities.assert_equals(
752 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800753 actual=intentCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800754 onpass="Intents are consistent across all ONOS nodes",
755 onfail="ONOS nodes have different views of intents" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800756
Jon Hall6aec96b2015-01-19 14:49:31 -0800757 main.step( "Get the flows from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800758 global flowState
759 flowState = []
760 ONOS1Flows = main.ONOScli1.flows( jsonFormat=True )
761 ONOS2Flows = main.ONOScli2.flows( jsonFormat=True )
762 ONOS3Flows = main.ONOScli3.flows( jsonFormat=True )
763 ONOS4Flows = main.ONOScli4.flows( jsonFormat=True )
764 ONOS5Flows = main.ONOScli5.flows( jsonFormat=True )
765 ONOS6Flows = main.ONOScli6.flows( jsonFormat=True )
766 ONOS7Flows = main.ONOScli7.flows( jsonFormat=True )
767 ONOS1FlowsJson = json.loads( ONOS1Flows )
768 ONOS2FlowsJson = json.loads( ONOS2Flows )
769 ONOS3FlowsJson = json.loads( ONOS3Flows )
770 ONOS4FlowsJson = json.loads( ONOS4Flows )
771 ONOS5FlowsJson = json.loads( ONOS5Flows )
772 ONOS6FlowsJson = json.loads( ONOS6Flows )
773 ONOS7FlowsJson = json.loads( ONOS7Flows )
774 flowCheck = main.FALSE
775 if "Error" in ONOS1Flows or not ONOS1Flows\
776 or "Error" in ONOS2Flows or not ONOS2Flows\
777 or "Error" in ONOS3Flows or not ONOS3Flows\
778 or "Error" in ONOS4Flows or not ONOS4Flows\
779 or "Error" in ONOS5Flows or not ONOS5Flows\
780 or "Error" in ONOS6Flows or not ONOS6Flows\
781 or "Error" in ONOS7Flows or not ONOS7Flows:
Jon Hall6aec96b2015-01-19 14:49:31 -0800782 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800783 main.log.warn( "ONOS1 flows repsponse: " + ONOS1Flows )
784 main.log.warn( "ONOS2 flows repsponse: " + ONOS2Flows )
785 main.log.warn( "ONOS3 flows repsponse: " + ONOS3Flows )
786 main.log.warn( "ONOS4 flows repsponse: " + ONOS4Flows )
787 main.log.warn( "ONOS5 flows repsponse: " + ONOS5Flows )
788 main.log.warn( "ONOS6 flows repsponse: " + ONOS6Flows )
789 main.log.warn( "ONOS7 flows repsponse: " + ONOS7Flows )
790 elif len( ONOS1FlowsJson ) == len( ONOS2FlowsJson )\
791 and len( ONOS1FlowsJson ) == len( ONOS3FlowsJson )\
792 and len( ONOS1FlowsJson ) == len( ONOS4FlowsJson )\
793 and len( ONOS1FlowsJson ) == len( ONOS5FlowsJson )\
794 and len( ONOS1FlowsJson ) == len( ONOS6FlowsJson )\
795 and len( ONOS1FlowsJson ) == len( ONOS7FlowsJson ):
Jon Hall6aec96b2015-01-19 14:49:31 -0800796 # TODO: Do a better check, maybe compare flows on switches?
Jon Hall8f89dda2015-01-22 16:03:33 -0800797 flowState = ONOS1Flows
798 flowCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800799 main.log.report( "Flow count is consistent across all ONOS nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800800 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800801 main.log.warn( "ONOS1 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800802 json.dumps( ONOS1FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800803 indent=4, separators=( ',', ': ' ) ) )
804 main.log.warn( "ONOS2 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800805 json.dumps( ONOS2FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800806 indent=4, separators=( ',', ': ' ) ) )
807 main.log.warn( "ONOS3 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800808 json.dumps( ONOS3FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800809 indent=4, separators=( ',', ': ' ) ) )
810 main.log.warn( "ONOS4 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800811 json.dumps( ONOS4FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800812 indent=4, separators=( ',', ': ' ) ) )
813 main.log.warn( "ONOS5 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800814 json.dumps( ONOS5FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800815 indent=4, separators=( ',', ': ' ) ) )
816 main.log.warn( "ONOS6 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800817 json.dumps( ONOS6FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800818 indent=4, separators=( ',', ': ' ) ) )
819 main.log.warn( "ONOS7 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800820 json.dumps( ONOS7FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800821 indent=4, separators=( ',', ': ' ) ) )
822 utilities.assert_equals(
823 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800824 actual=flowCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800825 onpass="The flow count is consistent across all ONOS nodes",
826 onfail="ONOS nodes have different flow counts" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800827
Jon Hall6aec96b2015-01-19 14:49:31 -0800828 main.step( "Get the OF Table entries" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800829 global flows
Jon Hall6aec96b2015-01-19 14:49:31 -0800830 flows = []
831 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800832 flows.append( main.Mininet2.getFlowTable( 1.3, "s" + str( i ) ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800833
Jon Hall6aec96b2015-01-19 14:49:31 -0800834 # TODO: Compare switch flow tables with ONOS flow tables
Jon Hall73cf9cc2014-11-20 22:28:38 -0800835
Jon Hall6aec96b2015-01-19 14:49:31 -0800836 main.step( "Start continuous pings" )
837 main.Mininet2.pingLong(
838 src=main.params[ 'PING' ][ 'source1' ],
839 target=main.params[ 'PING' ][ 'target1' ],
840 pingTime=500 )
841 main.Mininet2.pingLong(
842 src=main.params[ 'PING' ][ 'source2' ],
843 target=main.params[ 'PING' ][ 'target2' ],
844 pingTime=500 )
845 main.Mininet2.pingLong(
846 src=main.params[ 'PING' ][ 'source3' ],
847 target=main.params[ 'PING' ][ 'target3' ],
848 pingTime=500 )
849 main.Mininet2.pingLong(
850 src=main.params[ 'PING' ][ 'source4' ],
851 target=main.params[ 'PING' ][ 'target4' ],
852 pingTime=500 )
853 main.Mininet2.pingLong(
854 src=main.params[ 'PING' ][ 'source5' ],
855 target=main.params[ 'PING' ][ 'target5' ],
856 pingTime=500 )
857 main.Mininet2.pingLong(
858 src=main.params[ 'PING' ][ 'source6' ],
859 target=main.params[ 'PING' ][ 'target6' ],
860 pingTime=500 )
861 main.Mininet2.pingLong(
862 src=main.params[ 'PING' ][ 'source7' ],
863 target=main.params[ 'PING' ][ 'target7' ],
864 pingTime=500 )
865 main.Mininet2.pingLong(
866 src=main.params[ 'PING' ][ 'source8' ],
867 target=main.params[ 'PING' ][ 'target8' ],
868 pingTime=500 )
869 main.Mininet2.pingLong(
870 src=main.params[ 'PING' ][ 'source9' ],
871 target=main.params[ 'PING' ][ 'target9' ],
872 pingTime=500 )
873 main.Mininet2.pingLong(
874 src=main.params[ 'PING' ][ 'source10' ],
875 target=main.params[ 'PING' ][ 'target10' ],
876 pingTime=500 )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800877
Jon Hall6aec96b2015-01-19 14:49:31 -0800878 main.step( "Create TestONTopology object" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800879 ctrls = []
880 count = 1
881 while True:
882 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -0800883 if ( 'ip' + str( count ) ) in main.params[ 'CTRL' ]:
884 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
885 temp = temp + ( "ONOS" + str( count ), )
886 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
887 temp = temp + \
888 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
889 ctrls.append( temp )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800890 count = count + 1
891 else:
892 break
Jon Hall6aec96b2015-01-19 14:49:31 -0800893 MNTopo = TestONTopology(
894 main.Mininet1,
895 ctrls ) # can also add Intent API info for intent operations
Jon Hall73cf9cc2014-11-20 22:28:38 -0800896
Jon Hall6aec96b2015-01-19 14:49:31 -0800897 main.step( "Collecting topology information from ONOS" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800898 devices = []
899 devices.append( main.ONOScli1.devices() )
900 devices.append( main.ONOScli2.devices() )
901 devices.append( main.ONOScli3.devices() )
902 devices.append( main.ONOScli4.devices() )
903 devices.append( main.ONOScli5.devices() )
904 devices.append( main.ONOScli6.devices() )
905 devices.append( main.ONOScli7.devices() )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800906 hosts = []
907 hosts.append( main.ONOScli1.hosts() )
908 hosts.append( main.ONOScli2.hosts() )
909 hosts.append( main.ONOScli3.hosts() )
910 hosts.append( main.ONOScli4.hosts() )
911 hosts.append( main.ONOScli5.hosts() )
912 hosts.append( main.ONOScli6.hosts() )
913 hosts.append( main.ONOScli7.hosts() )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800914 ports = []
915 ports.append( main.ONOScli1.ports() )
916 ports.append( main.ONOScli2.ports() )
917 ports.append( main.ONOScli3.ports() )
918 ports.append( main.ONOScli4.ports() )
919 ports.append( main.ONOScli5.ports() )
920 ports.append( main.ONOScli6.ports() )
921 ports.append( main.ONOScli7.ports() )
922 links = []
923 links.append( main.ONOScli1.links() )
924 links.append( main.ONOScli2.links() )
925 links.append( main.ONOScli3.links() )
926 links.append( main.ONOScli4.links() )
927 links.append( main.ONOScli5.links() )
928 links.append( main.ONOScli6.links() )
929 links.append( main.ONOScli7.links() )
Jon Hall94fd0472014-12-08 11:52:42 -0800930 clusters = []
931 clusters.append( main.ONOScli1.clusters() )
932 clusters.append( main.ONOScli2.clusters() )
933 clusters.append( main.ONOScli3.clusters() )
934 clusters.append( main.ONOScli4.clusters() )
935 clusters.append( main.ONOScli5.clusters() )
936 clusters.append( main.ONOScli6.clusters() )
937 clusters.append( main.ONOScli7.clusters() )
Jon Hall529a37f2015-01-28 10:02:00 -0800938 # Compare json objects for hosts and dataplane clusters
Jon Hall94fd0472014-12-08 11:52:42 -0800939
Jon Hall6aec96b2015-01-19 14:49:31 -0800940 # hosts
Jon Hall8f89dda2015-01-22 16:03:33 -0800941 consistentHostsResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800942 for controller in range( len( hosts ) ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800943 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -0800944 if "Error" not in hosts[ controller ]:
945 if hosts[ controller ] == hosts[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -0800946 continue
Jon Hall6aec96b2015-01-19 14:49:31 -0800947 else: # hosts not consistent
948 main.log.report( "hosts from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -0800949 controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -0800950 " is inconsistent with ONOS1" )
951 main.log.warn( repr( hosts[ controller ] ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800952 consistentHostsResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800953
954 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800955 main.log.report( "Error in getting ONOS hosts from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -0800956 controllerStr )
957 consistentHostsResult = main.FALSE
958 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -0800959 " hosts response: " +
960 repr( hosts[ controller ] ) )
961 utilities.assert_equals(
962 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800963 actual=consistentHostsResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800964 onpass="Hosts view is consistent across all ONOS nodes",
965 onfail="ONOS nodes have different views of hosts" )
Jon Hall94fd0472014-12-08 11:52:42 -0800966
Jon Hall6aec96b2015-01-19 14:49:31 -0800967 # Strongly connected clusters of devices
Jon Hall8f89dda2015-01-22 16:03:33 -0800968 consistentClustersResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800969 for controller in range( len( clusters ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -0800970 if "Error" not in clusters[ controller ]:
971 if clusters[ controller ] == clusters[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -0800972 continue
Jon Hall6aec96b2015-01-19 14:49:31 -0800973 else: # clusters not consistent
974 main.log.report( "clusters from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -0800975 controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -0800976 " is inconsistent with ONOS1" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800977 consistentClustersResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800978
979 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800980 main.log.report( "Error in getting dataplane clusters " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800981 "from ONOS" + controllerStr )
982 consistentClustersResult = main.FALSE
983 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -0800984 " clusters response: " +
985 repr( clusters[ controller ] ) )
986 utilities.assert_equals(
987 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800988 actual=consistentClustersResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800989 onpass="Clusters view is consistent across all ONOS nodes",
990 onfail="ONOS nodes have different views of clusters" )
991 # there should always only be one cluster
Jon Hall8f89dda2015-01-22 16:03:33 -0800992 numClusters = len( json.loads( clusters[ 0 ] ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800993 utilities.assert_equals(
994 expect=1,
Jon Hall8f89dda2015-01-22 16:03:33 -0800995 actual=numClusters,
Jon Hall6aec96b2015-01-19 14:49:31 -0800996 onpass="ONOS shows 1 SCC",
997 onfail="ONOS shows " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800998 str( numClusters ) +
Jon Hall6aec96b2015-01-19 14:49:31 -0800999 " SCCs" )
Jon Hall94fd0472014-12-08 11:52:42 -08001000
Jon Hall6aec96b2015-01-19 14:49:31 -08001001 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001002 devicesResults = main.TRUE
1003 portsResults = main.TRUE
1004 linksResults = main.TRUE
1005 for controller in range( numControllers ):
1006 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001007 if devices[ controller ] or "Error" not in devices[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001008 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -08001009 MNTopo,
1010 json.loads(
1011 devices[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001012 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001013 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001014 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001015 actual=currentDevicesResult,
1016 onpass="ONOS" + controllerStr +
1017 " Switches view is correct",
1018 onfail="ONOS" + controllerStr +
1019 " Switches view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001020
Jon Hall6aec96b2015-01-19 14:49:31 -08001021 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001022 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -08001023 MNTopo,
1024 json.loads(
1025 ports[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001026 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001027 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001028 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001029 actual=currentPortsResult,
1030 onpass="ONOS" + controllerStr +
1031 " ports view is correct",
1032 onfail="ONOS" + controllerStr +
1033 " ports view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001034
Jon Hall6aec96b2015-01-19 14:49:31 -08001035 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001036 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -08001037 MNTopo,
1038 json.loads(
1039 links[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001040 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001041 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001042 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001043 actual=currentLinksResult,
1044 onpass="ONOS" + controllerStr +
1045 " links view is correct",
1046 onfail="ONOS" + controllerStr +
1047 " links view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001048
Jon Hall8f89dda2015-01-22 16:03:33 -08001049 devicesResults = devicesResults and currentDevicesResult
1050 portsResults = portsResults and currentPortsResult
1051 linksResults = linksResults and currentLinksResult
Jon Hall73cf9cc2014-11-20 22:28:38 -08001052
Jon Hall8f89dda2015-01-22 16:03:33 -08001053 topoResult = devicesResults and portsResults and linksResults\
Jon Hall529a37f2015-01-28 10:02:00 -08001054 and consistentHostsResult and consistentClustersResult
Jon Hall8f89dda2015-01-22 16:03:33 -08001055 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
1056 onpass="Topology Check Test successful",
1057 onfail="Topology Check Test NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001058
Jon Hall8f89dda2015-01-22 16:03:33 -08001059 finalAssert = main.TRUE
1060 finalAssert = finalAssert and topoResult and flowCheck \
1061 and intentCheck and consistentMastership and rolesNotNull
1062 utilities.assert_equals( expect=main.TRUE, actual=finalAssert,
1063 onpass="State check successful",
1064 onfail="State check NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001065
Jon Hall6aec96b2015-01-19 14:49:31 -08001066 def CASE6( self, main ):
1067 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001068 The Failure case.
Jon Hall6aec96b2015-01-19 14:49:31 -08001069 """
1070 main.log.report( "Restart entire ONOS cluster" )
1071 main.log.case( "Restart entire ONOS cluster" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001072 main.ONOSbench.onosKill( ONOS1Ip )
1073 main.ONOSbench.onosKill( ONOS2Ip )
1074 main.ONOSbench.onosKill( ONOS3Ip )
1075 main.ONOSbench.onosKill( ONOS4Ip )
1076 main.ONOSbench.onosKill( ONOS5Ip )
1077 main.ONOSbench.onosKill( ONOS6Ip )
1078 main.ONOSbench.onosKill( ONOS7Ip )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001079
Jon Hall6aec96b2015-01-19 14:49:31 -08001080 main.step( "Checking if ONOS is up yet" )
Jon Hallffb386d2014-11-21 13:43:38 -08001081 count = 0
Jon Hall8f89dda2015-01-22 16:03:33 -08001082 onosIsupResult = main.FALSE
1083 while onosIsupResult == main.FALSE and count < 10:
1084 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
1085 onos2Isup = main.ONOSbench.isup( ONOS2Ip )
1086 onos3Isup = main.ONOSbench.isup( ONOS3Ip )
1087 onos4Isup = main.ONOSbench.isup( ONOS4Ip )
1088 onos5Isup = main.ONOSbench.isup( ONOS5Ip )
1089 onos6Isup = main.ONOSbench.isup( ONOS6Ip )
1090 onos7Isup = main.ONOSbench.isup( ONOS7Ip )
1091 onosIsupResult = onos1Isup and onos2Isup and onos3Isup\
1092 and onos4Isup and onos5Isup and onos6Isup and onos7Isup
Jon Hallffb386d2014-11-21 13:43:38 -08001093 count = count + 1
Jon Hall73cf9cc2014-11-20 22:28:38 -08001094 # TODO: if it becomes an issue, we can retry this step a few times
1095
Jon Hall8f89dda2015-01-22 16:03:33 -08001096 cliResult1 = main.ONOScli1.startOnosCli( ONOS1Ip )
1097 cliResult2 = main.ONOScli2.startOnosCli( ONOS2Ip )
1098 cliResult3 = main.ONOScli3.startOnosCli( ONOS3Ip )
1099 cliResult4 = main.ONOScli4.startOnosCli( ONOS4Ip )
1100 cliResult5 = main.ONOScli5.startOnosCli( ONOS5Ip )
1101 cliResult6 = main.ONOScli6.startOnosCli( ONOS6Ip )
1102 cliResult7 = main.ONOScli7.startOnosCli( ONOS7Ip )
1103 cliResults = cliResult1 and cliResult2 and cliResult3\
1104 and cliResult4 and cliResult5 and cliResult6\
1105 and cliResult7
Jon Hall73cf9cc2014-11-20 22:28:38 -08001106
Jon Hall8f89dda2015-01-22 16:03:33 -08001107 caseResults = main.TRUE and onosIsupResult and cliResults
1108 utilities.assert_equals( expect=main.TRUE, actual=caseResults,
1109 onpass="ONOS restart successful",
1110 onfail="ONOS restart NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001111
Jon Hall6aec96b2015-01-19 14:49:31 -08001112 def CASE7( self, main ):
1113 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001114 Check state after ONOS failure
Jon Hall6aec96b2015-01-19 14:49:31 -08001115 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001116 import json
Jon Hall6aec96b2015-01-19 14:49:31 -08001117 main.case( "Running ONOS Constant State Tests" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001118
Jon Hall6aec96b2015-01-19 14:49:31 -08001119 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -08001120 ONOS1MasterNotNull = main.ONOScli1.rolesNotNull()
1121 ONOS2MasterNotNull = main.ONOScli2.rolesNotNull()
1122 ONOS3MasterNotNull = main.ONOScli3.rolesNotNull()
1123 ONOS4MasterNotNull = main.ONOScli4.rolesNotNull()
1124 ONOS5MasterNotNull = main.ONOScli5.rolesNotNull()
1125 ONOS6MasterNotNull = main.ONOScli6.rolesNotNull()
1126 ONOS7MasterNotNull = main.ONOScli7.rolesNotNull()
1127 rolesNotNull = ONOS1MasterNotNull and ONOS2MasterNotNull and\
1128 ONOS3MasterNotNull and ONOS4MasterNotNull and\
1129 ONOS5MasterNotNull and ONOS6MasterNotNull and\
1130 ONOS7MasterNotNull
Jon Hall6aec96b2015-01-19 14:49:31 -08001131 utilities.assert_equals(
1132 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001133 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -08001134 onpass="Each device has a master",
1135 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -08001136
Jon Hall6aec96b2015-01-19 14:49:31 -08001137 main.step( "Check if switch roles are consistent across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001138 ONOS1Mastership = main.ONOScli1.roles()
1139 ONOS2Mastership = main.ONOScli2.roles()
1140 ONOS3Mastership = main.ONOScli3.roles()
1141 ONOS4Mastership = main.ONOScli4.roles()
1142 ONOS5Mastership = main.ONOScli5.roles()
1143 ONOS6Mastership = main.ONOScli6.roles()
1144 ONOS7Mastership = main.ONOScli7.roles()
1145 if "Error" in ONOS1Mastership or not ONOS1Mastership\
1146 or "Error" in ONOS2Mastership or not ONOS2Mastership\
1147 or "Error" in ONOS3Mastership or not ONOS3Mastership\
1148 or "Error" in ONOS4Mastership or not ONOS4Mastership\
1149 or "Error" in ONOS5Mastership or not ONOS5Mastership\
1150 or "Error" in ONOS6Mastership or not ONOS6Mastership\
1151 or "Error" in ONOS7Mastership or not ONOS7Mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -08001152 main.log.error( "Error in getting ONOS mastership" )
1153 main.log.warn( "ONOS1 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001154 repr( ONOS1Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001155 main.log.warn( "ONOS2 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001156 repr( ONOS2Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001157 main.log.warn( "ONOS3 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001158 repr( ONOS3Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001159 main.log.warn( "ONOS4 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001160 repr( ONOS4Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001161 main.log.warn( "ONOS5 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001162 repr( ONOS5Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001163 main.log.warn( "ONOS6 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001164 repr( ONOS6Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001165 main.log.warn( "ONOS7 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001166 repr( ONOS7Mastership ) )
1167 consistentMastership = main.FALSE
1168 elif ONOS1Mastership == ONOS2Mastership\
1169 and ONOS1Mastership == ONOS3Mastership\
1170 and ONOS1Mastership == ONOS4Mastership\
1171 and ONOS1Mastership == ONOS5Mastership\
1172 and ONOS1Mastership == ONOS6Mastership\
1173 and ONOS1Mastership == ONOS7Mastership:
1174 consistentMastership = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001175 main.log.report(
1176 "Switch roles are consistent across all ONOS nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001177 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001178 main.log.warn( "ONOS1 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001179 json.loads( ONOS1Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001180 separators=( ',', ': ' ) ) )
1181 main.log.warn( "ONOS2 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001182 json.loads( ONOS2Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001183 separators=( ',', ': ' ) ) )
1184 main.log.warn( "ONOS3 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001185 json.loads( ONOS3Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001186 separators=( ',', ': ' ) ) )
1187 main.log.warn( "ONOS4 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001188 json.loads( ONOS4Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001189 separators=( ',', ': ' ) ) )
1190 main.log.warn( "ONOS5 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001191 json.loads( ONOS5Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001192 separators=( ',', ': ' ) ) )
1193 main.log.warn( "ONOS6 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001194 json.loads( ONOS6Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001195 separators=( ',', ': ' ) ) )
1196 main.log.warn( "ONOS7 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001197 json.loads( ONOS7Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001198 separators=( ',', ': ' ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001199 consistentMastership = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001200 utilities.assert_equals(
1201 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001202 actual=consistentMastership,
Jon Hall6aec96b2015-01-19 14:49:31 -08001203 onpass="Switch roles are consistent across all ONOS nodes",
1204 onfail="ONOS nodes have different views of switch roles" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001205
1206 description2 = "Compare switch roles from before failure"
Jon Hall6aec96b2015-01-19 14:49:31 -08001207 main.step( description2 )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001208
Jon Hall8f89dda2015-01-22 16:03:33 -08001209 currentJson = json.loads( ONOS1Mastership )
1210 oldJson = json.loads( mastershipState )
1211 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001212 for i in range( 1, 29 ):
1213 switchDPID = str(
1214 main.Mininet1.getSwitchDPID(
1215 switch="s" +
1216 str( i ) ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001217
Jon Hall8f89dda2015-01-22 16:03:33 -08001218 current = [ switch[ 'master' ] for switch in currentJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001219 if switchDPID in switch[ 'id' ] ]
Jon Hall8f89dda2015-01-22 16:03:33 -08001220 old = [ switch[ 'master' ] for switch in oldJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001221 if switchDPID in switch[ 'id' ] ]
Jon Hall73cf9cc2014-11-20 22:28:38 -08001222 if current == old:
Jon Hall8f89dda2015-01-22 16:03:33 -08001223 mastershipCheck = mastershipCheck and main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001224 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001225 main.log.warn( "Mastership of switch %s changed" % switchDPID )
Jon Hall8f89dda2015-01-22 16:03:33 -08001226 mastershipCheck = main.FALSE
1227 if mastershipCheck == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001228 main.log.report( "Mastership of Switches was not changed" )
1229 utilities.assert_equals(
1230 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001231 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -08001232 onpass="Mastership of Switches was not changed",
1233 onfail="Mastership of some switches changed" )
1234 # NOTE: we expect mastership to change on controller failure
Jon Hall8f89dda2015-01-22 16:03:33 -08001235 mastershipCheck = mastershipCheck and consistentMastership
Jon Hall73cf9cc2014-11-20 22:28:38 -08001236
Jon Hall6aec96b2015-01-19 14:49:31 -08001237 main.step( "Get the intents and compare across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001238 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
1239 ONOS2Intents = main.ONOScli2.intents( jsonFormat=True )
1240 ONOS3Intents = main.ONOScli3.intents( jsonFormat=True )
1241 ONOS4Intents = main.ONOScli4.intents( jsonFormat=True )
1242 ONOS5Intents = main.ONOScli5.intents( jsonFormat=True )
1243 ONOS6Intents = main.ONOScli6.intents( jsonFormat=True )
1244 ONOS7Intents = main.ONOScli7.intents( jsonFormat=True )
1245 intentCheck = main.FALSE
1246 if "Error" in ONOS1Intents or not ONOS1Intents\
1247 or "Error" in ONOS2Intents or not ONOS2Intents\
1248 or "Error" in ONOS3Intents or not ONOS3Intents\
1249 or "Error" in ONOS4Intents or not ONOS4Intents\
1250 or "Error" in ONOS5Intents or not ONOS5Intents\
1251 or "Error" in ONOS6Intents or not ONOS6Intents\
1252 or "Error" in ONOS7Intents or not ONOS7Intents:
Jon Hall6aec96b2015-01-19 14:49:31 -08001253 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001254 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
1255 main.log.warn( "ONOS2 intents response: " + repr( ONOS2Intents ) )
1256 main.log.warn( "ONOS3 intents response: " + repr( ONOS3Intents ) )
1257 main.log.warn( "ONOS4 intents response: " + repr( ONOS4Intents ) )
1258 main.log.warn( "ONOS5 intents response: " + repr( ONOS5Intents ) )
1259 main.log.warn( "ONOS6 intents response: " + repr( ONOS6Intents ) )
1260 main.log.warn( "ONOS7 intents response: " + repr( ONOS7Intents ) )
1261 elif ONOS1Intents == ONOS2Intents\
1262 and ONOS1Intents == ONOS3Intents\
1263 and ONOS1Intents == ONOS4Intents\
1264 and ONOS1Intents == ONOS5Intents\
1265 and ONOS1Intents == ONOS6Intents\
1266 and ONOS1Intents == ONOS7Intents:
1267 intentCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001268 main.log.report( "Intents are consistent across all ONOS nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001269 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001270 main.log.warn( "ONOS1 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001271 print json.dumps( json.loads( ONOS1Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001272 indent=4, separators=( ',', ': ' ) )
1273 main.log.warn( "ONOS2 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001274 print json.dumps( json.loads( ONOS2Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001275 indent=4, separators=( ',', ': ' ) )
1276 main.log.warn( "ONOS3 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001277 print json.dumps( json.loads( ONOS3Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001278 indent=4, separators=( ',', ': ' ) )
1279 main.log.warn( "ONOS4 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001280 print json.dumps( json.loads( ONOS4Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001281 indent=4, separators=( ',', ': ' ) )
1282 main.log.warn( "ONOS5 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001283 print json.dumps( json.loads( ONOS5Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001284 indent=4, separators=( ',', ': ' ) )
1285 main.log.warn( "ONOS6 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001286 print json.dumps( json.loads( ONOS6Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001287 indent=4, separators=( ',', ': ' ) )
1288 main.log.warn( "ONOS7 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001289 print json.dumps( json.loads( ONOS7Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001290 indent=4, separators=( ',', ': ' ) )
1291 utilities.assert_equals(
1292 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001293 actual=intentCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -08001294 onpass="Intents are consistent across all ONOS nodes",
1295 onfail="ONOS nodes have different views of intents" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001296
Jon Hall6aec96b2015-01-19 14:49:31 -08001297 # NOTE: Hazelcast has no durability, so intents are lost across system
1298 # restarts
1299 """
1300 main.step( "Compare current intents with intents before the failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001301 # NOTE: this requires case 5 to pass for intentState to be set.
Jon Hall94fd0472014-12-08 11:52:42 -08001302 # maybe we should stop the test if that fails?
Jon Hall8f89dda2015-01-22 16:03:33 -08001303 if intentState == ONOS1Intents:
1304 sameIntents = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001305 main.log.report( "Intents are consistent with before failure" )
1306 # TODO: possibly the states have changed? we may need to figure out
1307 # what the aceptable states are
Jon Hall73cf9cc2014-11-20 22:28:38 -08001308 else:
Jon Hall669173b2014-12-17 11:36:30 -08001309 try:
Jon Hall6aec96b2015-01-19 14:49:31 -08001310 main.log.warn( "ONOS1 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001311 print json.dumps( json.loads( ONOS1Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -08001312 sort_keys=True, indent=4,
1313 separators=( ',', ': ' ) )
Jon Hall669173b2014-12-17 11:36:30 -08001314 except:
1315 pass
Jon Hall8f89dda2015-01-22 16:03:33 -08001316 sameIntents = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001317 utilities.assert_equals(
1318 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001319 actual=sameIntents,
Jon Hall6aec96b2015-01-19 14:49:31 -08001320 onpass="Intents are consistent with before failure",
1321 onfail="The Intents changed during failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001322 intentCheck = intentCheck and sameIntents
Jon Hall6aec96b2015-01-19 14:49:31 -08001323 """
1324 main.step( "Get the OF Table entries and compare to before " +
1325 "component failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001326 FlowTables = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001327 flows2 = []
1328 for i in range( 28 ):
1329 main.log.info( "Checking flow table on s" + str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001330 tmpFlows = main.Mininet2.getFlowTable( 1.3, "s" + str( i + 1 ) )
1331 flows2.append( tmpFlows )
1332 tempResult = main.Mininet2.flowComp(
Jon Hall6aec96b2015-01-19 14:49:31 -08001333 flow1=flows[ i ],
Jon Hall8f89dda2015-01-22 16:03:33 -08001334 flow2=tmpFlows )
1335 FlowTables = FlowTables and tempResult
1336 if FlowTables == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001337 main.log.info( "Differences in flow table for switch: s" +
1338 str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001339 if FlowTables == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001340 main.log.report( "No changes were found in the flow tables" )
1341 utilities.assert_equals(
1342 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001343 actual=FlowTables,
Jon Hall6aec96b2015-01-19 14:49:31 -08001344 onpass="No changes were found in the flow tables",
1345 onfail="Changes were found in the flow tables" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001346
Jon Hall6aec96b2015-01-19 14:49:31 -08001347 main.step( "Check the continuous pings to ensure that no packets " +
1348 "were dropped during component failure" )
1349 # FIXME: This check is always failing. Investigate cause
1350 # NOTE: this may be something to do with file permsissions
Jon Hall73cf9cc2014-11-20 22:28:38 -08001351 # or slight change in format
Jon Hall6aec96b2015-01-19 14:49:31 -08001352 main.Mininet2.pingKill(
1353 main.params[ 'TESTONUSER' ],
1354 main.params[ 'TESTONIP' ] )
Jon Hall8f89dda2015-01-22 16:03:33 -08001355 LossInPings = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001356 # NOTE: checkForLoss returns main.FALSE with 0% packet loss
1357 for i in range( 8, 18 ):
1358 main.log.info(
1359 "Checking for a loss in pings along flow from s" +
1360 str( i ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001361 LossInPings = main.Mininet2.checkForLoss(
Jon Hall6aec96b2015-01-19 14:49:31 -08001362 "/tmp/ping.h" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001363 str( i ) ) or LossInPings
1364 if LossInPings == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001365 main.log.info( "Loss in ping detected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001366 elif LossInPings == main.ERROR:
Jon Hall6aec96b2015-01-19 14:49:31 -08001367 main.log.info( "There are multiple mininet process running" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001368 elif LossInPings == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001369 main.log.info( "No Loss in the pings" )
1370 main.log.report( "No loss of dataplane connectivity" )
1371 utilities.assert_equals(
1372 expect=main.FALSE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001373 actual=LossInPings,
Jon Hall6aec96b2015-01-19 14:49:31 -08001374 onpass="No Loss of connectivity",
1375 onfail="Loss of dataplane connectivity detected" )
1376 # NOTE: Since intents are not persisted with Hazelcast, we expect this
Jon Hall8f89dda2015-01-22 16:03:33 -08001377 LossInPings = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001378
Jon Hall6aec96b2015-01-19 14:49:31 -08001379 # Test of LeadershipElection
Jon Hall8f89dda2015-01-22 16:03:33 -08001380 leaderList = []
1381 leaderResult = main.TRUE
1382 for controller in range( 1, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001383 # loop through ONOScli handlers
1384 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001385 leaderN = node.electionTestLeader()
1386 leaderList.append( leaderN )
Jon Hall669173b2014-12-17 11:36:30 -08001387 if leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001388 # error in response
1389 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001390 "electionTestLeader function, check the" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001391 " error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001392 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001393 elif leaderN is None:
1394 main.log.report( "ONOS" + str( controller ) +
1395 " shows no leader for the election-app was" +
1396 " elected after the old one died" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001397 leaderResult = main.FALSE
1398 if len( set( leaderList ) ) != 1:
1399 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001400 main.log.error(
1401 "Inconsistent view of leader for the election test app" )
1402 # TODO: print the list
Jon Hall8f89dda2015-01-22 16:03:33 -08001403 if leaderResult:
1404 main.log.report( "Leadership election tests passed( consistent " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001405 "view of leader across listeners and a new " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001406 "leader was re-elected if applicable )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001407 utilities.assert_equals(
1408 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001409 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001410 onpass="Leadership election passed",
1411 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08001412
Jon Hall8f89dda2015-01-22 16:03:33 -08001413 result = ( mastershipCheck and intentCheck and FlowTables and
1414 ( not LossInPings ) and rolesNotNull and leaderResult )
Jon Hall6aec96b2015-01-19 14:49:31 -08001415 result = int( result )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001416 if result == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001417 main.log.report( "Constant State Tests Passed" )
1418 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall8f89dda2015-01-22 16:03:33 -08001419 onpass="Constant State Tests Passed",
1420 onfail="Constant state tests failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001421
Jon Hall6aec96b2015-01-19 14:49:31 -08001422 def CASE8( self, main ):
1423 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001424 Compare topo
Jon Hall6aec96b2015-01-19 14:49:31 -08001425 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001426 import sys
Jon Hall6aec96b2015-01-19 14:49:31 -08001427 # FIXME add this path to params
1428 sys.path.append( "/home/admin/sts" )
1429 # assumes that sts is already in you PYTHONPATH
1430 from sts.topology.teston_topology import TestONTopology
Jon Hall73cf9cc2014-11-20 22:28:38 -08001431 import json
1432 import time
1433
Jon Hall6aec96b2015-01-19 14:49:31 -08001434 description = "Compare ONOS Topology view to Mininet topology"
1435 main.case( description )
1436 main.log.report( description )
1437 main.step( "Create TestONTopology object" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001438 ctrls = []
1439 count = 1
1440 while True:
1441 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -08001442 if ( 'ip' + str( count ) ) in main.params[ 'CTRL' ]:
1443 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
1444 temp = temp + ( "ONOS" + str( count ), )
1445 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
1446 temp = temp + \
1447 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
1448 ctrls.append( temp )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001449 count = count + 1
1450 else:
1451 break
Jon Hall6aec96b2015-01-19 14:49:31 -08001452 MNTopo = TestONTopology(
1453 main.Mininet1,
1454 ctrls ) # can also add Intent API info for intent operations
Jon Hall73cf9cc2014-11-20 22:28:38 -08001455
Jon Hall6aec96b2015-01-19 14:49:31 -08001456 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001457 devicesResults = main.TRUE
1458 portsResults = main.TRUE
1459 linksResults = main.TRUE
1460 topoResult = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001461 elapsed = 0
Jon Hallffb386d2014-11-21 13:43:38 -08001462 count = 0
Jon Hall6aec96b2015-01-19 14:49:31 -08001463 main.step( "Collecting topology information from ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001464 startTime = time.time()
1465 while topoResult == main.FALSE and elapsed < 60:
Jon Hallffb386d2014-11-21 13:43:38 -08001466 count = count + 1
Jon Hall94fd0472014-12-08 11:52:42 -08001467 if count > 1:
Jon Hall6aec96b2015-01-19 14:49:31 -08001468 # TODO: Depricate STS usage
1469 MNTopo = TestONTopology(
1470 main.Mininet1,
1471 ctrls )
Jon Hall8f89dda2015-01-22 16:03:33 -08001472 cliStart = time.time()
Jon Hall94fd0472014-12-08 11:52:42 -08001473 devices = []
1474 devices.append( main.ONOScli1.devices() )
1475 devices.append( main.ONOScli2.devices() )
1476 devices.append( main.ONOScli3.devices() )
1477 devices.append( main.ONOScli4.devices() )
1478 devices.append( main.ONOScli5.devices() )
1479 devices.append( main.ONOScli6.devices() )
1480 devices.append( main.ONOScli7.devices() )
1481 hosts = []
Jon Hall529a37f2015-01-28 10:02:00 -08001482 hosts.append( json.loads( main.ONOScli1.hosts() ) )
1483 hosts.append( json.loads( main.ONOScli2.hosts() ) )
1484 hosts.append( json.loads( main.ONOScli3.hosts() ) )
1485 hosts.append( json.loads( main.ONOScli4.hosts() ) )
1486 hosts.append( json.loads( main.ONOScli5.hosts() ) )
1487 hosts.append( json.loads( main.ONOScli6.hosts() ) )
1488 hosts.append( json.loads( main.ONOScli7.hosts() ) )
1489 for controller in range( 0, len( hosts ) ):
1490 controllerStr = str( controller + 1 )
1491 for host in hosts[ controller ]:
1492 host
1493 if host[ 'ips' ] == []:
1494 main.log.error(
1495 "DEBUG:Error with host ips on controller" +
1496 controllerStr + ": " + str( host ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001497 ports = []
1498 ports.append( main.ONOScli1.ports() )
1499 ports.append( main.ONOScli2.ports() )
1500 ports.append( main.ONOScli3.ports() )
1501 ports.append( main.ONOScli4.ports() )
1502 ports.append( main.ONOScli5.ports() )
1503 ports.append( main.ONOScli6.ports() )
1504 ports.append( main.ONOScli7.ports() )
1505 links = []
1506 links.append( main.ONOScli1.links() )
1507 links.append( main.ONOScli2.links() )
1508 links.append( main.ONOScli3.links() )
1509 links.append( main.ONOScli4.links() )
1510 links.append( main.ONOScli5.links() )
1511 links.append( main.ONOScli6.links() )
1512 links.append( main.ONOScli7.links() )
1513 clusters = []
1514 clusters.append( main.ONOScli1.clusters() )
1515 clusters.append( main.ONOScli2.clusters() )
1516 clusters.append( main.ONOScli3.clusters() )
1517 clusters.append( main.ONOScli4.clusters() )
1518 clusters.append( main.ONOScli5.clusters() )
1519 clusters.append( main.ONOScli6.clusters() )
1520 clusters.append( main.ONOScli7.clusters() )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001521
Jon Hall8f89dda2015-01-22 16:03:33 -08001522 elapsed = time.time() - startTime
1523 cliTime = time.time() - cliStart
1524 print "CLI time: " + str( cliTime )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001525
Jon Hall8f89dda2015-01-22 16:03:33 -08001526 for controller in range( numControllers ):
1527 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001528 if devices[ controller ] or "Error" not in devices[
1529 controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001530 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -08001531 MNTopo,
1532 json.loads(
1533 devices[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001534 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001535 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001536 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001537 actual=currentDevicesResult,
1538 onpass="ONOS" + controllerStr +
1539 " Switches view is correct",
1540 onfail="ONOS" + controllerStr +
1541 " Switches view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001542
Jon Hall6aec96b2015-01-19 14:49:31 -08001543 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001544 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -08001545 MNTopo,
1546 json.loads(
1547 ports[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001548 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001549 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001550 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001551 actual=currentPortsResult,
1552 onpass="ONOS" + controllerStr +
1553 " ports view is correct",
1554 onfail="ONOS" + controllerStr +
1555 " ports view is incorrect" )
Jon Hall94fd0472014-12-08 11:52:42 -08001556
Jon Hall6aec96b2015-01-19 14:49:31 -08001557 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001558 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -08001559 MNTopo,
1560 json.loads(
1561 links[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001562 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001563 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001564 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001565 actual=currentLinksResult,
1566 onpass="ONOS" + controllerStr +
1567 " links view is correct",
1568 onfail="ONOS" + controllerStr +
1569 " links view is incorrect" )
1570 devicesResults = devicesResults and currentDevicesResult
1571 portsResults = portsResults and currentPortsResult
1572 linksResults = linksResults and currentLinksResult
Jon Hall94fd0472014-12-08 11:52:42 -08001573
Jon Hall529a37f2015-01-28 10:02:00 -08001574 # Compare json objects for hosts and dataplane clusters
Jon Hall94fd0472014-12-08 11:52:42 -08001575
Jon Hall6aec96b2015-01-19 14:49:31 -08001576 # hosts
Jon Hall8f89dda2015-01-22 16:03:33 -08001577 consistentHostsResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -08001578 for controller in range( len( hosts ) ):
Jon Hall8f89dda2015-01-22 16:03:33 -08001579 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001580 if "Error" not in hosts[ controller ]:
1581 if hosts[ controller ] == hosts[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001582 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001583 else: # hosts not consistent
Jon Hall8f89dda2015-01-22 16:03:33 -08001584 main.log.report( "hosts from ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001585 " is inconsistent with ONOS1" )
1586 main.log.warn( repr( hosts[ controller ] ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001587 consistentHostsResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001588
1589 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001590 main.log.report( "Error in getting ONOS hosts from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001591 controllerStr )
1592 consistentHostsResult = main.FALSE
1593 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001594 " hosts response: " +
1595 repr( hosts[ controller ] ) )
1596 utilities.assert_equals(
1597 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001598 actual=consistentHostsResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001599 onpass="Hosts view is consistent across all ONOS nodes",
1600 onfail="ONOS nodes have different views of hosts" )
Jon Hall94fd0472014-12-08 11:52:42 -08001601
Jon Hall6aec96b2015-01-19 14:49:31 -08001602 # Strongly connected clusters of devices
Jon Hall8f89dda2015-01-22 16:03:33 -08001603 consistentClustersResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -08001604 for controller in range( len( clusters ) ):
Jon Hall8f89dda2015-01-22 16:03:33 -08001605 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001606 if "Error" not in clusters[ controller ]:
1607 if clusters[ controller ] == clusters[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001608 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001609 else: # clusters not consistent
1610 main.log.report( "clusters from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001611 controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001612 " is inconsistent with ONOS1" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001613 consistentClustersResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001614
1615 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001616 main.log.report( "Error in getting dataplane clusters " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001617 "from ONOS" + controllerStr )
1618 consistentClustersResult = main.FALSE
1619 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001620 " clusters response: " +
1621 repr( clusters[ controller ] ) )
1622 utilities.assert_equals(
1623 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001624 actual=consistentClustersResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001625 onpass="Clusters view is consistent across all ONOS nodes",
1626 onfail="ONOS nodes have different views of clusters" )
1627 # there should always only be one cluster
Jon Hall8f89dda2015-01-22 16:03:33 -08001628 numClusters = len( json.loads( clusters[ 0 ] ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001629 utilities.assert_equals(
1630 expect=1,
Jon Hall8f89dda2015-01-22 16:03:33 -08001631 actual=numClusters,
Jon Hall6aec96b2015-01-19 14:49:31 -08001632 onpass="ONOS shows 1 SCC",
1633 onfail="ONOS shows " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001634 str( numClusters ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001635 " SCCs" )
Jon Hall94fd0472014-12-08 11:52:42 -08001636
Jon Hall8f89dda2015-01-22 16:03:33 -08001637 topoResult = ( devicesResults and portsResults and linksResults
1638 and consistentHostsResult
Jon Hall529a37f2015-01-28 10:02:00 -08001639 and consistentClustersResult )
Jon Hall94fd0472014-12-08 11:52:42 -08001640
Jon Hall8f89dda2015-01-22 16:03:33 -08001641 topoResult = topoResult and int( count <= 2 )
1642 note = "note it takes about " + str( int( cliTime ) ) + \
1643 " seconds for the test to make all the cli calls to fetch " +\
1644 "the topology from each ONOS instance"
Jon Hall6aec96b2015-01-19 14:49:31 -08001645 main.log.report(
Jon Hall8f89dda2015-01-22 16:03:33 -08001646 "Very crass estimate for topology discovery/convergence( " +
1647 str( note ) + " ): " + str( elapsed ) + " seconds, " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001648 str( count ) + " tries" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001649 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
1650 onpass="Topology Check Test successful",
1651 onfail="Topology Check Test NOT successful" )
1652 if topoResult == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001653 main.log.report( "ONOS topology view matches Mininet topology" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001654
Jon Hall6aec96b2015-01-19 14:49:31 -08001655 def CASE9( self, main ):
1656 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001657 Link s3-s28 down
Jon Hall6aec96b2015-01-19 14:49:31 -08001658 """
1659 import time
1660 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001661
Jon Hall8f89dda2015-01-22 16:03:33 -08001662 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001663
Jon Hall6aec96b2015-01-19 14:49:31 -08001664 description = "Turn off a link to ensure that Link Discovery " +\
Jon Hall8f89dda2015-01-22 16:03:33 -08001665 "is working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001666 main.log.report( description )
1667 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001668
Jon Hall6aec96b2015-01-19 14:49:31 -08001669 main.step( "Kill Link between s3 and s28" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001670 LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001671 main.log.info(
1672 "Waiting " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001673 str( linkSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001674 " seconds for link down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001675 time.sleep( linkSleep )
1676 utilities.assert_equals( expect=main.TRUE, actual=LinkDown,
1677 onpass="Link down succesful",
1678 onfail="Failed to bring link down" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001679 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -08001680
Jon Hall6aec96b2015-01-19 14:49:31 -08001681 def CASE10( self, main ):
1682 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001683 Link s3-s28 up
Jon Hall6aec96b2015-01-19 14:49:31 -08001684 """
1685 import time
1686 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001687
Jon Hall8f89dda2015-01-22 16:03:33 -08001688 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001689
Jon Hall6aec96b2015-01-19 14:49:31 -08001690 description = "Restore a link to ensure that Link Discovery is " + \
Jon Hall8f89dda2015-01-22 16:03:33 -08001691 "working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001692 main.log.report( description )
1693 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001694
Jon Hall6aec96b2015-01-19 14:49:31 -08001695 main.step( "Bring link between s3 and s28 back up" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001696 LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001697 main.log.info(
1698 "Waiting " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001699 str( linkSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001700 " seconds for link up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001701 time.sleep( linkSleep )
1702 utilities.assert_equals( expect=main.TRUE, actual=LinkUp,
1703 onpass="Link up succesful",
1704 onfail="Failed to bring link up" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001705 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -08001706
Jon Hall6aec96b2015-01-19 14:49:31 -08001707 def CASE11( self, main ):
1708 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001709 Switch Down
Jon Hall6aec96b2015-01-19 14:49:31 -08001710 """
1711 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001712 import time
1713
Jon Hall8f89dda2015-01-22 16:03:33 -08001714 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001715
1716 description = "Killing a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001717 main.log.report( description )
1718 main.case( description )
1719 switch = main.params[ 'kill' ][ 'switch' ]
1720 switchDPID = main.params[ 'kill' ][ 'dpid' ]
Jon Hall73cf9cc2014-11-20 22:28:38 -08001721
Jon Hall6aec96b2015-01-19 14:49:31 -08001722 # TODO: Make this switch parameterizable
1723 main.step( "Kill " + switch )
1724 main.log.report( "Deleting " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001725 main.Mininet1.delSwitch( switch )
1726 main.log.info( "Waiting " + str( switchSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001727 " seconds for switch down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001728 time.sleep( switchSleep )
1729 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001730 # Peek at the deleted switch
1731 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001732 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001733 if device and device[ 'available' ] is False:
Jon Hall94fd0472014-12-08 11:52:42 -08001734 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001735 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall8f89dda2015-01-22 16:03:33 -08001736 onpass="Kill switch succesful",
1737 onfail="Failed to kill switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001738
Jon Hall6aec96b2015-01-19 14:49:31 -08001739 def CASE12( self, main ):
1740 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001741 Switch Up
Jon Hall6aec96b2015-01-19 14:49:31 -08001742 """
1743 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001744 import time
Jon Hall669173b2014-12-17 11:36:30 -08001745
Jon Hall8f89dda2015-01-22 16:03:33 -08001746 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall6aec96b2015-01-19 14:49:31 -08001747 switch = main.params[ 'kill' ][ 'switch' ]
1748 switchDPID = main.params[ 'kill' ][ 'dpid' ]
1749 links = main.params[ 'kill' ][ 'links' ].split()
Jon Hall73cf9cc2014-11-20 22:28:38 -08001750 description = "Adding a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001751 main.log.report( description )
1752 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001753
Jon Hall6aec96b2015-01-19 14:49:31 -08001754 main.step( "Add back " + switch )
1755 main.log.report( "Adding back " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001756 main.Mininet1.addSwitch( switch, dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001757 # TODO: New dpid or same? Ask Thomas?
1758 for peer in links:
Jon Hall8f89dda2015-01-22 16:03:33 -08001759 main.Mininet1.addLink( switch, peer )
1760 main.Mininet1.assignSwController(
Jon Hall6aec96b2015-01-19 14:49:31 -08001761 sw=switch.split( 's' )[ 1 ],
Jon Hall8f89dda2015-01-22 16:03:33 -08001762 count=numControllers,
1763 ip1=ONOS1Ip,
1764 port1=ONOS1Port,
1765 ip2=ONOS2Ip,
1766 port2=ONOS2Port,
1767 ip3=ONOS3Ip,
1768 port3=ONOS3Port,
1769 ip4=ONOS4Ip,
1770 port4=ONOS4Port,
1771 ip5=ONOS5Ip,
1772 port5=ONOS5Port,
1773 ip6=ONOS6Ip,
1774 port6=ONOS6Port,
1775 ip7=ONOS7Ip,
1776 port7=ONOS7Port )
Jon Hall6aec96b2015-01-19 14:49:31 -08001777 main.log.info(
1778 "Waiting " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001779 str( switchSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001780 " seconds for switch up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001781 time.sleep( switchSleep )
1782 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001783 # Peek at the deleted switch
1784 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001785 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001786 if device and device[ 'available' ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001787 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001788 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall8f89dda2015-01-22 16:03:33 -08001789 onpass="add switch succesful",
1790 onfail="Failed to add switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001791
Jon Hall6aec96b2015-01-19 14:49:31 -08001792 def CASE13( self, main ):
1793 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001794 Clean up
Jon Hall6aec96b2015-01-19 14:49:31 -08001795 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001796 import os
1797 import time
Jon Hall6aec96b2015-01-19 14:49:31 -08001798 # TODO: make use of this elsewhere
1799 ips = []
Jon Hall8f89dda2015-01-22 16:03:33 -08001800 ips.append( ONOS1Ip )
1801 ips.append( ONOS2Ip )
1802 ips.append( ONOS3Ip )
1803 ips.append( ONOS4Ip )
1804 ips.append( ONOS5Ip )
1805 ips.append( ONOS6Ip )
1806 ips.append( ONOS7Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -08001807
1808 # printing colors to terminal
Jon Hall669173b2014-12-17 11:36:30 -08001809 colors = {}
Jon Hall6aec96b2015-01-19 14:49:31 -08001810 colors[ 'cyan' ] = '\033[96m'
1811 colors[ 'purple' ] = '\033[95m'
1812 colors[ 'blue' ] = '\033[94m'
1813 colors[ 'green' ] = '\033[92m'
1814 colors[ 'yellow' ] = '\033[93m'
1815 colors[ 'red' ] = '\033[91m'
1816 colors[ 'end' ] = '\033[0m'
Jon Hall73cf9cc2014-11-20 22:28:38 -08001817 description = "Test Cleanup"
Jon Hall6aec96b2015-01-19 14:49:31 -08001818 main.log.report( description )
1819 main.case( description )
1820 main.step( "Killing tcpdumps" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001821 main.Mininet2.stopTcpdump()
Jon Hall73cf9cc2014-11-20 22:28:38 -08001822
Jon Hall6aec96b2015-01-19 14:49:31 -08001823 main.step( "Checking ONOS Logs for errors" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001824 for i in range( 7 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001825 print colors[ 'purple' ] + "Checking logs for errors on " + \
Jon Hall8f89dda2015-01-22 16:03:33 -08001826 "ONOS" + str( i + 1 ) + ":" + colors[ 'end' ]
1827 print main.ONOSbench.checkLogs( ips[ i ] )
Jon Hall94fd0472014-12-08 11:52:42 -08001828
Jon Hall6aec96b2015-01-19 14:49:31 -08001829 main.step( "Copying MN pcap and ONOS log files to test station" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001830 testname = main.TEST
Jon Hall8f89dda2015-01-22 16:03:33 -08001831 teststationUser = main.params[ 'TESTONUSER' ]
1832 teststationIP = main.params[ 'TESTONIP' ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001833 # NOTE: MN Pcap file is being saved to ~/packet_captures
Jon Hall73cf9cc2014-11-20 22:28:38 -08001834 # scp this file as MN and TestON aren't necessarily the same vm
Jon Hall6aec96b2015-01-19 14:49:31 -08001835 # FIXME: scp
1836 # mn files
1837 # TODO: Load these from params
1838 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001839 logFolder = "/opt/onos/log/"
1840 logFiles = [ "karaf.log", "karaf.log.1" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001841 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001842 dstDir = "~/packet_captures/"
1843 for f in logFiles:
1844 for i in range( 7 ):
1845 main.ONOSbench.handle.sendline( "scp sdn@" + ips[ i ] + ":" +
1846 logFolder + f + " " +
1847 teststationUser + "@" +
1848 teststationIP + ":" +
1849 dstDir + str( testname ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001850 "-ONOS" + str( i + 1 ) + "-" +
1851 f )
1852 # std*.log's
1853 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001854 logFolder = "/opt/onos/var/"
1855 logFiles = [ "stderr.log", "stdout.log" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001856 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001857 dstDir = "~/packet_captures/"
1858 for f in logFiles:
1859 for i in range( 7 ):
1860 main.ONOSbench.handle.sendline( "scp sdn@" + ips[ i ] + ":" +
1861 logFolder + f + " " +
1862 teststationUser + "@" +
1863 teststationIP + ":" +
1864 dstDir + str( testname ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001865 "-ONOS" + str( i + 1 ) + "-" +
1866 f )
1867 # sleep so scp can finish
1868 time.sleep( 10 )
1869 main.step( "Packing and rotating pcap archives" )
1870 os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001871
Jon Hall6aec96b2015-01-19 14:49:31 -08001872 # TODO: actually check something here
1873 utilities.assert_equals( expect=main.TRUE, actual=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001874 onpass="Test cleanup successful",
1875 onfail="Test cleanup NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001876
Jon Hall6aec96b2015-01-19 14:49:31 -08001877 def CASE14( self, main ):
1878 """
Jon Hall669173b2014-12-17 11:36:30 -08001879 start election app on all onos nodes
Jon Hall6aec96b2015-01-19 14:49:31 -08001880 """
Jon Hall8f89dda2015-01-22 16:03:33 -08001881 leaderResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001882 # install app on onos 1
1883 main.log.info( "Install leadership election app" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001884 main.ONOScli1.featureInstall( "onos-app-election" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001885 # wait for election
1886 # check for leader
Jon Hall8f89dda2015-01-22 16:03:33 -08001887 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001888 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08001889 if leader == ONOS1Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08001890 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001891 pass
Jon Hall6aec96b2015-01-19 14:49:31 -08001892 elif leader is None:
1893 # No leader elected
1894 main.log.report( "No leader was elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001895 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001896 elif leader == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001897 # error in response
1898 # TODO: add check for "Command not found:" in the driver, this
1899 # means the app isn't loaded
Jon Hall8f89dda2015-01-22 16:03:33 -08001900 main.log.report( "Something is wrong with electionTestLeader" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001901 " function, check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001902 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001903 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001904 # error in response
1905 main.log.report(
Jon Hall8f89dda2015-01-22 16:03:33 -08001906 "Unexpected response from electionTestLeader function:'" +
1907 str( leader ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001908 "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001909 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001910
Jon Hall6aec96b2015-01-19 14:49:31 -08001911 # install on other nodes and check for leader.
1912 # Should be onos1 and each app should show the same leader
Jon Hall8f89dda2015-01-22 16:03:33 -08001913 for controller in range( 2, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001914 # loop through ONOScli handlers
1915 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001916 node.featureInstall( "onos-app-election" )
1917 leaderN = node.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001918 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08001919 if leaderN == ONOS1Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08001920 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001921 pass
1922 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001923 # error in response
1924 # TODO: add check for "Command not found:" in the driver, this
1925 # means the app isn't loaded
1926 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001927 "electionTestLeader function, check the" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001928 " error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001929 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001930 elif leader != leaderN:
Jon Hall8f89dda2015-01-22 16:03:33 -08001931 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001932 main.log.report( "ONOS" + str( controller ) + " sees " +
1933 str( leaderN ) +
1934 " as the leader of the election app. Leader" +
1935 " should be " +
1936 str( leader ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001937 if leaderResult:
Jon Hall6aec96b2015-01-19 14:49:31 -08001938 main.log.report( "Leadership election tests passed( consistent " +
1939 "view of leader across listeners and a leader " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001940 "was elected )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001941 utilities.assert_equals(
1942 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001943 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001944 onpass="Leadership election passed",
1945 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08001946
Jon Hall6aec96b2015-01-19 14:49:31 -08001947 def CASE15( self, main ):
1948 """
Jon Hall669173b2014-12-17 11:36:30 -08001949 Check that Leadership Election is still functional
Jon Hall6aec96b2015-01-19 14:49:31 -08001950 """
Jon Hall8f89dda2015-01-22 16:03:33 -08001951 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08001952 description = "Check that Leadership Election is still functional"
Jon Hall6aec96b2015-01-19 14:49:31 -08001953 main.log.report( description )
1954 main.case( description )
1955 main.step( "Find current leader and withdraw" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001956 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001957 # TODO: do some sanity checking on leader before using it
Jon Hall8f89dda2015-01-22 16:03:33 -08001958 withdrawResult = main.FALSE
1959 if leader == ONOS1Ip:
1960 oldLeader = getattr( main, "ONOScli1" )
1961 elif leader == ONOS2Ip:
1962 oldLeader = getattr( main, "ONOScli2" )
1963 elif leader == ONOS3Ip:
1964 oldLeader = getattr( main, "ONOScli3" )
1965 elif leader == ONOS4Ip:
1966 oldLeader = getattr( main, "ONOScli4" )
1967 elif leader == ONOS5Ip:
1968 oldLeader = getattr( main, "ONOScli5" )
1969 elif leader == ONOS6Ip:
1970 oldLeader = getattr( main, "ONOScli6" )
1971 elif leader == ONOS7Ip:
1972 oldLeader = getattr( main, "ONOScli7" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001973 elif leader is None or leader == main.FALSE:
1974 main.log.report(
1975 "Leader for the election app should be an ONOS node," +
1976 "instead got '" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001977 str( leader ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001978 "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001979 leaderResult = main.FALSE
1980 withdrawResult = oldLeader.electionTestWithdraw()
Jon Hall6aec96b2015-01-19 14:49:31 -08001981 utilities.assert_equals(
1982 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001983 actual=withdrawResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001984 onpass="App was withdrawn from election",
1985 onfail="App was not withdrawn from election" )
Jon Hall669173b2014-12-17 11:36:30 -08001986
Jon Hall6aec96b2015-01-19 14:49:31 -08001987 main.step( "Make sure new leader is elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001988 leaderList = []
1989 for controller in range( 1, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001990 # loop through ONOScli handlers
1991 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001992 leaderList.append( node.electionTestLeader() )
1993 for leaderN in leaderList:
Jon Hall669173b2014-12-17 11:36:30 -08001994 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08001995 main.log.report(
1996 "ONOS" +
1997 str( controller ) +
1998 " still sees " +
1999 str( leader ) +
2000 " as leader after they withdrew" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002001 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08002002 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08002003 # error in response
2004 # TODO: add check for "Command not found:" in the driver, this
2005 # means the app isn't loaded
2006 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002007 "electionTestLeader function, " +
Jon Hall6aec96b2015-01-19 14:49:31 -08002008 "check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002009 leaderResult = main.FALSE
2010 consistentLeader = main.FALSE
2011 if len( set( leaderList ) ) == 1:
Jon Hall6aec96b2015-01-19 14:49:31 -08002012 main.log.info( "Each Election-app sees '" +
Jon Hall8f89dda2015-01-22 16:03:33 -08002013 str( leaderList[ 0 ] ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08002014 "' as the leader" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002015 consistentLeader = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08002016 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08002017 main.log.report(
2018 "Inconsistent responses for leader of Election-app:" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002019 for n in range( len( leaderList ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -08002020 main.log.report( "ONOS" + str( n + 1 ) + " response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002021 str( leaderList[ n ] ) )
2022 if leaderResult:
2023 main.log.report( "Leadership election tests passed( consistent " +
Jon Hall6aec96b2015-01-19 14:49:31 -08002024 "view of leader across listeners and a new " +
2025 "leader was elected when the old leader " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002026 "resigned )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08002027 utilities.assert_equals(
2028 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002029 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002030 onpass="Leadership election passed",
2031 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08002032
Jon Hall6aec96b2015-01-19 14:49:31 -08002033 main.step(
Jon Hall8f89dda2015-01-22 16:03:33 -08002034 "Run for election on old leader( just so everyone is in the hat )" )
2035 runResult = oldLeader.electionTestRun()
Jon Hall6aec96b2015-01-19 14:49:31 -08002036 utilities.assert_equals(
2037 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002038 actual=runResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002039 onpass="App re-ran for election",
2040 onfail="App failed to run for election" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002041 if consistentLeader == main.TRUE:
2042 afterRun = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08002043 # verify leader didn't just change
Jon Hall8f89dda2015-01-22 16:03:33 -08002044 if afterRun == leaderList[ 0 ]:
2045 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08002046 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08002047 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08002048 # TODO: assert on run and withdraw results?
Jon Hall669173b2014-12-17 11:36:30 -08002049
Jon Hall6aec96b2015-01-19 14:49:31 -08002050 utilities.assert_equals(
2051 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002052 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002053 onpass="Leadership election passed",
2054 onfail="Something went wrong with Leadership election after " +
2055 "the old leader re-ran for election" )