blob: 75178278d31dd7a81793d7f3fafd5053126873b8 [file] [log] [blame]
Jon Hall6aec96b2015-01-19 14:49:31 -08001"""
Jon Hall73cf9cc2014-11-20 22:28:38 -08002Description: This test is to determine if ONOS can handle
3 a minority of it's nodes restarting
4
5List of test cases:
6CASE1: Compile ONOS and push it to the test machines
7CASE2: Assign mastership to controllers
8CASE3: Assign intents
9CASE4: Ping across added host intents
10CASE5: Reading state of ONOS
11CASE6: The Failure case.
12CASE7: Check state after control plane failure
13CASE8: Compare topo
14CASE9: Link s3-s28 down
15CASE10: Link s3-s28 up
16CASE11: Switch down
17CASE12: Switch up
18CASE13: Clean up
Jon Hall669173b2014-12-17 11:36:30 -080019CASE14: start election app on all onos nodes
20CASE15: Check that Leadership Election is still functional
Jon Hall6aec96b2015-01-19 14:49:31 -080021"""
Jon Hall8f89dda2015-01-22 16:03:33 -080022
23
Jon Hall73cf9cc2014-11-20 22:28:38 -080024class HATestMinorityRestart:
25
Jon Hall6aec96b2015-01-19 14:49:31 -080026 def __init__( self ):
Jon Hall73cf9cc2014-11-20 22:28:38 -080027 self.default = ''
28
Jon Hall6aec96b2015-01-19 14:49:31 -080029 def CASE1( self, main ):
30 """
Jon Hall73cf9cc2014-11-20 22:28:38 -080031 CASE1 is to compile ONOS and push it to the test machines
32
33 Startup sequence:
34 git pull
35 mvn clean install
36 onos-package
37 cell <name>
38 onos-verify-cell
39 NOTE: temporary - onos-remove-raft-logs
40 onos-install -f
41 onos-wait-for-start
Jon Hall6aec96b2015-01-19 14:49:31 -080042 """
43 main.log.report(
44 "ONOS HA test: Restart minority of ONOS nodes - initialization" )
45 main.case( "Setting up test environment" )
46 # TODO: save all the timers and output them for plotting
Jon Hall73cf9cc2014-11-20 22:28:38 -080047
48 # load some vairables from the params file
Jon Hall8f89dda2015-01-22 16:03:33 -080049 PULLCODE = False
Jon Hall6aec96b2015-01-19 14:49:31 -080050 if main.params[ 'Git' ] == 'True':
Jon Hall8f89dda2015-01-22 16:03:33 -080051 PULLCODE = True
Jon Hall73cf9cc2014-11-20 22:28:38 -080052
Jon Hall8f89dda2015-01-22 16:03:33 -080053 cellName = main.params[ 'ENV' ][ 'cellName' ]
Jon Hall6aec96b2015-01-19 14:49:31 -080054
55 # set global variables
Jon Hall8f89dda2015-01-22 16:03:33 -080056 global ONOS1Ip
57 global ONOS1Port
58 global ONOS2Ip
59 global ONOS2Port
60 global ONOS3Ip
61 global ONOS3Port
62 global ONOS4Ip
63 global ONOS4Port
64 global ONOS5Ip
65 global ONOS5Port
66 global ONOS6Ip
67 global ONOS6Port
68 global ONOS7Ip
69 global ONOS7Port
70 global numControllers
Jon Hall73cf9cc2014-11-20 22:28:38 -080071
Jon Hall8f89dda2015-01-22 16:03:33 -080072 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
73 ONOS1Port = main.params[ 'CTRL' ][ 'port1' ]
74 ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
75 ONOS2Port = main.params[ 'CTRL' ][ 'port2' ]
76 ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ]
77 ONOS3Port = main.params[ 'CTRL' ][ 'port3' ]
78 ONOS4Ip = main.params[ 'CTRL' ][ 'ip4' ]
79 ONOS4Port = main.params[ 'CTRL' ][ 'port4' ]
80 ONOS5Ip = main.params[ 'CTRL' ][ 'ip5' ]
81 ONOS5Port = main.params[ 'CTRL' ][ 'port5' ]
82 ONOS6Ip = main.params[ 'CTRL' ][ 'ip6' ]
83 ONOS6Port = main.params[ 'CTRL' ][ 'port6' ]
84 ONOS7Ip = main.params[ 'CTRL' ][ 'ip7' ]
85 ONOS7Port = main.params[ 'CTRL' ][ 'port7' ]
86 numControllers = int( main.params[ 'num_controllers' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -080087
Jon Hall6aec96b2015-01-19 14:49:31 -080088 main.step( "Applying cell variable to environment" )
Jon Hall8f89dda2015-01-22 16:03:33 -080089 cellResult = main.ONOSbench.setCell( cellName )
90 verifyResult = main.ONOSbench.verifyCell()
Jon Hall73cf9cc2014-11-20 22:28:38 -080091
Jon Hall6aec96b2015-01-19 14:49:31 -080092 # FIXME:this is short term fix
93 main.log.report( "Removing raft logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -080094 main.ONOSbench.onosRemoveRaftLogs()
Jon Hall6aec96b2015-01-19 14:49:31 -080095 main.log.report( "Uninstalling ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -080096 main.ONOSbench.onosUninstall( ONOS1Ip )
97 main.ONOSbench.onosUninstall( ONOS2Ip )
98 main.ONOSbench.onosUninstall( ONOS3Ip )
99 main.ONOSbench.onosUninstall( ONOS4Ip )
100 main.ONOSbench.onosUninstall( ONOS5Ip )
101 main.ONOSbench.onosUninstall( ONOS6Ip )
102 main.ONOSbench.onosUninstall( ONOS7Ip )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800103
Jon Hall8f89dda2015-01-22 16:03:33 -0800104 cleanInstallResult = main.TRUE
105 gitPullResult = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800106
Jon Hall6aec96b2015-01-19 14:49:31 -0800107 main.step( "Compiling the latest version of ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800108 if PULLCODE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800109 # TODO Configure branch in params
110 main.step( "Git checkout and pull master" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800111 main.ONOSbench.gitCheckout( "master" )
112 gitPullResult = main.ONOSbench.gitPull()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800113
Jon Hall6aec96b2015-01-19 14:49:31 -0800114 main.step( "Using mvn clean & install" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800115 cleanInstallResult = main.TRUE
116
117 if gitPullResult == main.TRUE:
118 cleanInstallResult = main.ONOSbench.cleanInstall()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800119 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800120 main.log.warn( "Did not pull new code so skipping mvn " +
121 "clean install" )
Jon Hall8f89dda2015-01-22 16:03:33 -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
388
389 """
390 import time
Jon Hall6aec96b2015-01-19 14:49:31 -0800391 main.log.report( "Adding host intents" )
392 main.case( "Adding host Intents" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800393
Jon Hall8f89dda2015-01-22 16:03:33 -0800394 main.step( "Discovering Hosts( Via pingall for now )" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800395 # FIXME: Once we have a host discovery mechanism, use that instead
Jon Hall73cf9cc2014-11-20 22:28:38 -0800396
Jon Hall6aec96b2015-01-19 14:49:31 -0800397 # install onos-app-fwd
398 main.log.info( "Install reactive forwarding app" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800399 main.ONOScli1.featureInstall( "onos-app-fwd" )
400 main.ONOScli2.featureInstall( "onos-app-fwd" )
401 main.ONOScli3.featureInstall( "onos-app-fwd" )
402 main.ONOScli4.featureInstall( "onos-app-fwd" )
403 main.ONOScli5.featureInstall( "onos-app-fwd" )
404 main.ONOScli6.featureInstall( "onos-app-fwd" )
405 main.ONOScli7.featureInstall( "onos-app-fwd" )
Jon Hall94fd0472014-12-08 11:52:42 -0800406
Jon Hall6aec96b2015-01-19 14:49:31 -0800407 # REACTIVE FWD test
Jon Hall8f89dda2015-01-22 16:03:33 -0800408 pingResult = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800409 time1 = time.time()
Jon Hall8f89dda2015-01-22 16:03:33 -0800410 pingResult = main.Mininet1.pingall()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800411 time2 = time.time()
Jon Hall6aec96b2015-01-19 14:49:31 -0800412 main.log.info( "Time for pingall: %2f seconds" % ( time2 - time1 ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800413
Jon Hall6aec96b2015-01-19 14:49:31 -0800414 # uninstall onos-app-fwd
415 main.log.info( "Uninstall reactive forwarding app" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800416 main.ONOScli1.featureUninstall( "onos-app-fwd" )
417 main.ONOScli2.featureUninstall( "onos-app-fwd" )
418 main.ONOScli3.featureUninstall( "onos-app-fwd" )
419 main.ONOScli4.featureUninstall( "onos-app-fwd" )
420 main.ONOScli5.featureUninstall( "onos-app-fwd" )
421 main.ONOScli6.featureUninstall( "onos-app-fwd" )
422 main.ONOScli7.featureUninstall( "onos-app-fwd" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800423 # timeout for fwd flows
424 time.sleep( 10 )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800425
Jon Hall6aec96b2015-01-19 14:49:31 -0800426 main.step( "Add host intents" )
427 # TODO: move the host numbers to params
Jon Hall8f89dda2015-01-22 16:03:33 -0800428 intentAddResult = True
Jon Hall6aec96b2015-01-19 14:49:31 -0800429 for i in range( 8, 18 ):
430 main.log.info( "Adding host intent between h" + str( i ) +
431 " and h" + str( i + 10 ) )
432 host1 = "00:00:00:00:00:" + \
433 str( hex( i )[ 2: ] ).zfill( 2 ).upper()
434 host2 = "00:00:00:00:00:" + \
435 str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper()
Jon Hall8f89dda2015-01-22 16:03:33 -0800436 host1Id = main.ONOScli1.getHost( host1 )[ 'id' ]
437 host2Id = main.ONOScli1.getHost( host2 )[ 'id' ]
Jon Hall6aec96b2015-01-19 14:49:31 -0800438 # NOTE: get host can return None
Jon Hall8f89dda2015-01-22 16:03:33 -0800439 if host1Id and host2Id:
440 tmpResult = main.ONOScli1.addHostIntent(
441 host1Id,
442 host2Id )
Jon Hall669173b2014-12-17 11:36:30 -0800443 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800444 main.log.error( "Error, getHost() failed" )
445 tmpResult = main.FALSE
446 intentAddResult = bool( pingResult and intentAddResult
447 and tmpResult )
Jon Hall6aec96b2015-01-19 14:49:31 -0800448 utilities.assert_equals(
449 expect=True,
Jon Hall8f89dda2015-01-22 16:03:33 -0800450 actual=intentAddResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800451 onpass="Switch mastership correctly assigned",
Jon Hall8f89dda2015-01-22 16:03:33 -0800452 onfail="Error in ( re )assigning switch mastership" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800453 # TODO Check if intents all exist in datastore
Jon Hall73cf9cc2014-11-20 22:28:38 -0800454
Jon Hall6aec96b2015-01-19 14:49:31 -0800455 def CASE4( self, main ):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800456 """
457 Ping across added host intents
458 """
459 description = " Ping across added host intents"
Jon Hall6aec96b2015-01-19 14:49:31 -0800460 main.log.report( description )
461 main.case( description )
Jon Hall8f89dda2015-01-22 16:03:33 -0800462 PingResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800463 for i in range( 8, 18 ):
464 ping = main.Mininet1.pingHost(
465 src="h" + str( i ), target="h" + str( i + 10 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800466 PingResult = PingResult and ping
Jon Hall6aec96b2015-01-19 14:49:31 -0800467 if ping == main.FALSE:
468 main.log.warn( "Ping failed between h" + str( i ) +
469 " and h" + str( i + 10 ) )
470 elif ping == main.TRUE:
471 main.log.info( "Ping test passed!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800472 PingResult = main.TRUE
473 if PingResult == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800474 main.log.report(
475 "Intents have not been installed correctly, pings failed." )
Jon Hall8f89dda2015-01-22 16:03:33 -0800476 if PingResult == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800477 main.log.report(
478 "Intents have been installed correctly and verified by pings" )
479 utilities.assert_equals(
480 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800481 actual=PingResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800482 onpass="Intents have been installed correctly and pings work",
483 onfail="Intents have not been installed correctly, pings failed." )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800484
Jon Hall6aec96b2015-01-19 14:49:31 -0800485 def CASE5( self, main ):
486 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800487 Reading state of ONOS
Jon Hall6aec96b2015-01-19 14:49:31 -0800488 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800489 import json
Jon Hall6aec96b2015-01-19 14:49:31 -0800490 # assumes that sts is already in you PYTHONPATH
491 from sts.topology.teston_topology import TestONTopology
Jon Hall73cf9cc2014-11-20 22:28:38 -0800492
Jon Hall6aec96b2015-01-19 14:49:31 -0800493 main.log.report( "Setting up and gathering data for current state" )
494 main.case( "Setting up and gathering data for current state" )
495 # The general idea for this test case is to pull the state of
496 # ( intents,flows, topology,... ) from each ONOS node
497 # We can then compare them with eachother and also with past states
Jon Hall73cf9cc2014-11-20 22:28:38 -0800498
Jon Hall6aec96b2015-01-19 14:49:31 -0800499 main.step( "Get the Mastership of each switch from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800500 global mastershipState
501 mastershipState = []
Jon Hall94fd0472014-12-08 11:52:42 -0800502
Jon Hall6aec96b2015-01-19 14:49:31 -0800503 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -0800504 ONOS1MasterNotNull = main.ONOScli1.rolesNotNull()
505 ONOS2MasterNotNull = main.ONOScli2.rolesNotNull()
506 ONOS3MasterNotNull = main.ONOScli3.rolesNotNull()
507 ONOS4MasterNotNull = main.ONOScli4.rolesNotNull()
508 ONOS5MasterNotNull = main.ONOScli5.rolesNotNull()
509 ONOS6MasterNotNull = main.ONOScli6.rolesNotNull()
510 ONOS7MasterNotNull = main.ONOScli7.rolesNotNull()
511 rolesNotNull = ONOS1MasterNotNull and ONOS2MasterNotNull and\
512 ONOS3MasterNotNull and ONOS4MasterNotNull and\
513 ONOS5MasterNotNull and ONOS6MasterNotNull and\
514 ONOS7MasterNotNull
Jon Hall6aec96b2015-01-19 14:49:31 -0800515 utilities.assert_equals(
516 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800517 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -0800518 onpass="Each device has a master",
519 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -0800520
Jon Hall8f89dda2015-01-22 16:03:33 -0800521 ONOS1Mastership = main.ONOScli1.roles()
522 ONOS2Mastership = main.ONOScli2.roles()
523 ONOS3Mastership = main.ONOScli3.roles()
524 ONOS4Mastership = main.ONOScli4.roles()
525 ONOS5Mastership = main.ONOScli5.roles()
526 ONOS6Mastership = main.ONOScli6.roles()
527 ONOS7Mastership = main.ONOScli7.roles()
528 if "Error" in ONOS1Mastership or not ONOS1Mastership\
529 or "Error" in ONOS2Mastership or not ONOS2Mastership\
530 or "Error" in ONOS3Mastership or not ONOS3Mastership\
531 or "Error" in ONOS4Mastership or not ONOS4Mastership\
532 or "Error" in ONOS5Mastership or not ONOS5Mastership\
533 or "Error" in ONOS6Mastership or not ONOS6Mastership\
534 or "Error" in ONOS7Mastership or not ONOS7Mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -0800535 main.log.report( "Error in getting ONOS roles" )
536 main.log.warn(
537 "ONOS1 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800538 repr( ONOS1Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800539 main.log.warn(
540 "ONOS2 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800541 repr( ONOS2Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800542 main.log.warn(
543 "ONOS3 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800544 repr( ONOS3Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800545 main.log.warn(
546 "ONOS4 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800547 repr( ONOS4Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800548 main.log.warn(
549 "ONOS5 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800550 repr( ONOS5Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800551 main.log.warn(
552 "ONOS6 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800553 repr( ONOS6Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800554 main.log.warn(
555 "ONOS7 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800556 repr( ONOS7Mastership ) )
557 consistentMastership = main.FALSE
558 elif ONOS1Mastership == ONOS2Mastership\
559 and ONOS1Mastership == ONOS3Mastership\
560 and ONOS1Mastership == ONOS4Mastership\
561 and ONOS1Mastership == ONOS5Mastership\
562 and ONOS1Mastership == ONOS6Mastership\
563 and ONOS1Mastership == ONOS7Mastership:
564 mastershipState = ONOS1Mastership
565 consistentMastership = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800566 main.log.report(
567 "Switch roles are consistent across all ONOS nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800568 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800569 main.log.warn(
570 "ONOS1 roles: ",
571 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800572 json.loads( ONOS1Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800573 sort_keys=True,
574 indent=4,
575 separators=(
576 ',',
577 ': ' ) ) )
578 main.log.warn(
579 "ONOS2 roles: ",
580 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800581 json.loads( ONOS2Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800582 sort_keys=True,
583 indent=4,
584 separators=(
585 ',',
586 ': ' ) ) )
587 main.log.warn(
588 "ONOS3 roles: ",
589 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800590 json.loads( ONOS3Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800591 sort_keys=True,
592 indent=4,
593 separators=(
594 ',',
595 ': ' ) ) )
596 main.log.warn(
597 "ONOS4 roles: ",
598 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800599 json.loads( ONOS4Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800600 sort_keys=True,
601 indent=4,
602 separators=(
603 ',',
604 ': ' ) ) )
605 main.log.warn(
606 "ONOS5 roles: ",
607 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800608 json.loads( ONOS5Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800609 sort_keys=True,
610 indent=4,
611 separators=(
612 ',',
613 ': ' ) ) )
614 main.log.warn(
615 "ONOS6 roles: ",
616 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800617 json.loads( ONOS6Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800618 sort_keys=True,
619 indent=4,
620 separators=(
621 ',',
622 ': ' ) ) )
623 main.log.warn(
624 "ONOS7 roles: ",
625 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800626 json.loads( ONOS7Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800627 sort_keys=True,
628 indent=4,
629 separators=(
630 ',',
631 ': ' ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800632 consistentMastership = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800633 utilities.assert_equals(
634 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800635 actual=consistentMastership,
Jon Hall6aec96b2015-01-19 14:49:31 -0800636 onpass="Switch roles are consistent across all ONOS nodes",
637 onfail="ONOS nodes have different views of switch roles" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800638
Jon Hall6aec96b2015-01-19 14:49:31 -0800639 main.step( "Get the intents from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800640 global intentState
641 intentState = []
642 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
643 ONOS2Intents = main.ONOScli2.intents( jsonFormat=True )
644 ONOS3Intents = main.ONOScli3.intents( jsonFormat=True )
645 ONOS4Intents = main.ONOScli4.intents( jsonFormat=True )
646 ONOS5Intents = main.ONOScli5.intents( jsonFormat=True )
647 ONOS6Intents = main.ONOScli6.intents( jsonFormat=True )
648 ONOS7Intents = main.ONOScli7.intents( jsonFormat=True )
649 intentCheck = main.FALSE
650 if "Error" in ONOS1Intents or not ONOS1Intents\
651 or "Error" in ONOS2Intents or not ONOS2Intents\
652 or "Error" in ONOS3Intents or not ONOS3Intents\
653 or "Error" in ONOS4Intents or not ONOS4Intents\
654 or "Error" in ONOS5Intents or not ONOS5Intents\
655 or "Error" in ONOS6Intents or not ONOS6Intents\
656 or "Error" in ONOS7Intents or not ONOS7Intents:
Jon Hall6aec96b2015-01-19 14:49:31 -0800657 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800658 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
659 main.log.warn( "ONOS2 intents response: " + repr( ONOS2Intents ) )
660 main.log.warn( "ONOS3 intents response: " + repr( ONOS3Intents ) )
661 main.log.warn( "ONOS4 intents response: " + repr( ONOS4Intents ) )
662 main.log.warn( "ONOS5 intents response: " + repr( ONOS5Intents ) )
663 main.log.warn( "ONOS6 intents response: " + repr( ONOS6Intents ) )
664 main.log.warn( "ONOS7 intents response: " + repr( ONOS7Intents ) )
665 elif ONOS1Intents == ONOS2Intents\
666 and ONOS1Intents == ONOS3Intents\
667 and ONOS1Intents == ONOS4Intents\
668 and ONOS1Intents == ONOS5Intents\
669 and ONOS1Intents == ONOS6Intents\
670 and ONOS1Intents == ONOS7Intents:
671 intentState = ONOS1Intents
672 intentCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800673 main.log.report( "Intents are consistent across all ONOS nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800674 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800675 main.log.warn(
676 "ONOS1 intents: ",
677 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800678 json.loads( ONOS1Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800679 sort_keys=True,
680 indent=4,
681 separators=(
682 ',',
683 ': ' ) ) )
684 main.log.warn(
685 "ONOS2 intents: ",
686 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800687 json.loads( ONOS2Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800688 sort_keys=True,
689 indent=4,
690 separators=(
691 ',',
692 ': ' ) ) )
693 main.log.warn(
694 "ONOS3 intents: ",
695 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800696 json.loads( ONOS3Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800697 sort_keys=True,
698 indent=4,
699 separators=(
700 ',',
701 ': ' ) ) )
702 main.log.warn(
703 "ONOS4 intents: ",
704 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800705 json.loads( ONOS4Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800706 sort_keys=True,
707 indent=4,
708 separators=(
709 ',',
710 ': ' ) ) )
711 main.log.warn(
712 "ONOS5 intents: ",
713 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800714 json.loads( ONOS5Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800715 sort_keys=True,
716 indent=4,
717 separators=(
718 ',',
719 ': ' ) ) )
720 main.log.warn(
721 "ONOS6 intents: ",
722 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800723 json.loads( ONOS6Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800724 sort_keys=True,
725 indent=4,
726 separators=(
727 ',',
728 ': ' ) ) )
729 main.log.warn(
730 "ONOS7 intents: ",
731 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800732 json.loads( ONOS7Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800733 sort_keys=True,
734 indent=4,
735 separators=(
736 ',',
737 ': ' ) ) )
738 utilities.assert_equals(
739 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800740 actual=intentCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800741 onpass="Intents are consistent across all ONOS nodes",
742 onfail="ONOS nodes have different views of intents" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800743
Jon Hall6aec96b2015-01-19 14:49:31 -0800744 main.step( "Get the flows from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800745 global flowState
746 flowState = []
747 ONOS1Flows = main.ONOScli1.flows( jsonFormat=True )
748 ONOS2Flows = main.ONOScli2.flows( jsonFormat=True )
749 ONOS3Flows = main.ONOScli3.flows( jsonFormat=True )
750 ONOS4Flows = main.ONOScli4.flows( jsonFormat=True )
751 ONOS5Flows = main.ONOScli5.flows( jsonFormat=True )
752 ONOS6Flows = main.ONOScli6.flows( jsonFormat=True )
753 ONOS7Flows = main.ONOScli7.flows( jsonFormat=True )
754 ONOS1FlowsJson = json.loads( ONOS1Flows )
755 ONOS2FlowsJson = json.loads( ONOS2Flows )
756 ONOS3FlowsJson = json.loads( ONOS3Flows )
757 ONOS4FlowsJson = json.loads( ONOS4Flows )
758 ONOS5FlowsJson = json.loads( ONOS5Flows )
759 ONOS6FlowsJson = json.loads( ONOS6Flows )
760 ONOS7FlowsJson = json.loads( ONOS7Flows )
761 flowCheck = main.FALSE
762 if "Error" in ONOS1Flows or not ONOS1Flows\
763 or "Error" in ONOS2Flows or not ONOS2Flows\
764 or "Error" in ONOS3Flows or not ONOS3Flows\
765 or "Error" in ONOS4Flows or not ONOS4Flows\
766 or "Error" in ONOS5Flows or not ONOS5Flows\
767 or "Error" in ONOS6Flows or not ONOS6Flows\
768 or "Error" in ONOS7Flows or not ONOS7Flows:
Jon Hall6aec96b2015-01-19 14:49:31 -0800769 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800770 main.log.warn( "ONOS1 flows repsponse: " + ONOS1Flows )
771 main.log.warn( "ONOS2 flows repsponse: " + ONOS2Flows )
772 main.log.warn( "ONOS3 flows repsponse: " + ONOS3Flows )
773 main.log.warn( "ONOS4 flows repsponse: " + ONOS4Flows )
774 main.log.warn( "ONOS5 flows repsponse: " + ONOS5Flows )
775 main.log.warn( "ONOS6 flows repsponse: " + ONOS6Flows )
776 main.log.warn( "ONOS7 flows repsponse: " + ONOS7Flows )
777 elif len( ONOS1FlowsJson ) == len( ONOS2FlowsJson )\
778 and len( ONOS1FlowsJson ) == len( ONOS3FlowsJson )\
779 and len( ONOS1FlowsJson ) == len( ONOS4FlowsJson )\
780 and len( ONOS1FlowsJson ) == len( ONOS5FlowsJson )\
781 and len( ONOS1FlowsJson ) == len( ONOS6FlowsJson )\
782 and len( ONOS1FlowsJson ) == len( ONOS7FlowsJson ):
Jon Hall6aec96b2015-01-19 14:49:31 -0800783 # TODO: Do a better check, maybe compare flows on switches?
Jon Hall8f89dda2015-01-22 16:03:33 -0800784 flowState = ONOS1Flows
785 flowCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800786 main.log.report( "Flow count is consistent across all ONOS nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800787 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800788 main.log.warn( "ONOS1 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800789 json.dumps( ONOS1FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800790 indent=4, separators=( ',', ': ' ) ) )
791 main.log.warn( "ONOS2 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800792 json.dumps( ONOS2FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800793 indent=4, separators=( ',', ': ' ) ) )
794 main.log.warn( "ONOS3 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800795 json.dumps( ONOS3FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800796 indent=4, separators=( ',', ': ' ) ) )
797 main.log.warn( "ONOS4 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800798 json.dumps( ONOS4FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800799 indent=4, separators=( ',', ': ' ) ) )
800 main.log.warn( "ONOS5 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800801 json.dumps( ONOS5FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800802 indent=4, separators=( ',', ': ' ) ) )
803 main.log.warn( "ONOS6 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800804 json.dumps( ONOS6FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800805 indent=4, separators=( ',', ': ' ) ) )
806 main.log.warn( "ONOS7 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800807 json.dumps( ONOS7FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800808 indent=4, separators=( ',', ': ' ) ) )
809 utilities.assert_equals(
810 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800811 actual=flowCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800812 onpass="The flow count is consistent across all ONOS nodes",
813 onfail="ONOS nodes have different flow counts" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800814
Jon Hall6aec96b2015-01-19 14:49:31 -0800815 main.step( "Get the OF Table entries" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800816 global flows
Jon Hall6aec96b2015-01-19 14:49:31 -0800817 flows = []
818 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800819 flows.append( main.Mininet2.getFlowTable( 1.3, "s" + str( i ) ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800820
Jon Hall6aec96b2015-01-19 14:49:31 -0800821 # TODO: Compare switch flow tables with ONOS flow tables
Jon Hall73cf9cc2014-11-20 22:28:38 -0800822
Jon Hall6aec96b2015-01-19 14:49:31 -0800823 main.step( "Start continuous pings" )
824 main.Mininet2.pingLong(
825 src=main.params[ 'PING' ][ 'source1' ],
826 target=main.params[ 'PING' ][ 'target1' ],
827 pingTime=500 )
828 main.Mininet2.pingLong(
829 src=main.params[ 'PING' ][ 'source2' ],
830 target=main.params[ 'PING' ][ 'target2' ],
831 pingTime=500 )
832 main.Mininet2.pingLong(
833 src=main.params[ 'PING' ][ 'source3' ],
834 target=main.params[ 'PING' ][ 'target3' ],
835 pingTime=500 )
836 main.Mininet2.pingLong(
837 src=main.params[ 'PING' ][ 'source4' ],
838 target=main.params[ 'PING' ][ 'target4' ],
839 pingTime=500 )
840 main.Mininet2.pingLong(
841 src=main.params[ 'PING' ][ 'source5' ],
842 target=main.params[ 'PING' ][ 'target5' ],
843 pingTime=500 )
844 main.Mininet2.pingLong(
845 src=main.params[ 'PING' ][ 'source6' ],
846 target=main.params[ 'PING' ][ 'target6' ],
847 pingTime=500 )
848 main.Mininet2.pingLong(
849 src=main.params[ 'PING' ][ 'source7' ],
850 target=main.params[ 'PING' ][ 'target7' ],
851 pingTime=500 )
852 main.Mininet2.pingLong(
853 src=main.params[ 'PING' ][ 'source8' ],
854 target=main.params[ 'PING' ][ 'target8' ],
855 pingTime=500 )
856 main.Mininet2.pingLong(
857 src=main.params[ 'PING' ][ 'source9' ],
858 target=main.params[ 'PING' ][ 'target9' ],
859 pingTime=500 )
860 main.Mininet2.pingLong(
861 src=main.params[ 'PING' ][ 'source10' ],
862 target=main.params[ 'PING' ][ 'target10' ],
863 pingTime=500 )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800864
Jon Hall6aec96b2015-01-19 14:49:31 -0800865 main.step( "Create TestONTopology object" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800866 ctrls = []
867 count = 1
868 while True:
869 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -0800870 if ( 'ip' + str( count ) ) in main.params[ 'CTRL' ]:
871 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
872 temp = temp + ( "ONOS" + str( count ), )
873 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
874 temp = temp + \
875 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
876 ctrls.append( temp )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800877 count = count + 1
878 else:
879 break
Jon Hall6aec96b2015-01-19 14:49:31 -0800880 MNTopo = TestONTopology(
881 main.Mininet1,
882 ctrls ) # can also add Intent API info for intent operations
Jon Hall73cf9cc2014-11-20 22:28:38 -0800883
Jon Hall6aec96b2015-01-19 14:49:31 -0800884 main.step( "Collecting topology information from ONOS" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800885 devices = []
886 devices.append( main.ONOScli1.devices() )
887 devices.append( main.ONOScli2.devices() )
888 devices.append( main.ONOScli3.devices() )
889 devices.append( main.ONOScli4.devices() )
890 devices.append( main.ONOScli5.devices() )
891 devices.append( main.ONOScli6.devices() )
892 devices.append( main.ONOScli7.devices() )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800893 hosts = []
Jon Hall6aec96b2015-01-19 14:49:31 -0800894 hosts.append( main.ONOScli1.hosts() )
895 hosts.append( main.ONOScli2.hosts() )
896 hosts.append( main.ONOScli3.hosts() )
897 hosts.append( main.ONOScli4.hosts() )
898 hosts.append( main.ONOScli5.hosts() )
899 hosts.append( main.ONOScli6.hosts() )
900 hosts.append( main.ONOScli7.hosts() )
901 for controller in range( 0, len( hosts ) ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800902 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -0800903 for host in hosts[ controller ]:
904 if host[ 'ips' ] == []:
905 main.log.error( "DEBUG:Error with host ips on controller" +
Jon Hall8f89dda2015-01-22 16:03:33 -0800906 controllerStr + ": " + str( host ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800907 ports = []
908 ports.append( main.ONOScli1.ports() )
909 ports.append( main.ONOScli2.ports() )
910 ports.append( main.ONOScli3.ports() )
911 ports.append( main.ONOScli4.ports() )
912 ports.append( main.ONOScli5.ports() )
913 ports.append( main.ONOScli6.ports() )
914 ports.append( main.ONOScli7.ports() )
915 links = []
916 links.append( main.ONOScli1.links() )
917 links.append( main.ONOScli2.links() )
918 links.append( main.ONOScli3.links() )
919 links.append( main.ONOScli4.links() )
920 links.append( main.ONOScli5.links() )
921 links.append( main.ONOScli6.links() )
922 links.append( main.ONOScli7.links() )
Jon Hall94fd0472014-12-08 11:52:42 -0800923 clusters = []
924 clusters.append( main.ONOScli1.clusters() )
925 clusters.append( main.ONOScli2.clusters() )
926 clusters.append( main.ONOScli3.clusters() )
927 clusters.append( main.ONOScli4.clusters() )
928 clusters.append( main.ONOScli5.clusters() )
929 clusters.append( main.ONOScli6.clusters() )
930 clusters.append( main.ONOScli7.clusters() )
931 paths = []
Jon Hall8f89dda2015-01-22 16:03:33 -0800932 tempTopo = main.ONOSbench.getTopology( main.ONOScli1.topology() )
933 paths.append( tempTopo.get( 'paths', False ) )
934 tempTopo = main.ONOSbench.getTopology( main.ONOScli2.topology() )
935 paths.append( tempTopo.get( 'paths', False ) )
936 tempTopo = main.ONOSbench.getTopology( main.ONOScli3.topology() )
937 paths.append( tempTopo.get( 'paths', False ) )
938 tempTopo = main.ONOSbench.getTopology( main.ONOScli4.topology() )
939 paths.append( tempTopo.get( 'paths', False ) )
940 tempTopo = main.ONOSbench.getTopology( main.ONOScli5.topology() )
941 paths.append( tempTopo.get( 'paths', False ) )
942 tempTopo = main.ONOSbench.getTopology( main.ONOScli6.topology() )
943 paths.append( tempTopo.get( 'paths', False ) )
944 tempTopo = main.ONOSbench.getTopology( main.ONOScli7.topology() )
945 paths.append( tempTopo.get( 'paths', False ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800946
Jon Hall6aec96b2015-01-19 14:49:31 -0800947 # Compare json objects for hosts, dataplane clusters and paths
Jon Hall94fd0472014-12-08 11:52:42 -0800948
Jon Hall6aec96b2015-01-19 14:49:31 -0800949 # hosts
Jon Hall8f89dda2015-01-22 16:03:33 -0800950 consistentHostsResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800951 for controller in range( len( hosts ) ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800952 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -0800953 if "Error" not in hosts[ controller ]:
954 if hosts[ controller ] == hosts[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -0800955 continue
Jon Hall6aec96b2015-01-19 14:49:31 -0800956 else: # hosts not consistent
957 main.log.report( "hosts from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -0800958 controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -0800959 " is inconsistent with ONOS1" )
960 main.log.warn( repr( hosts[ controller ] ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800961 consistentHostsResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800962
963 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800964 main.log.report( "Error in getting ONOS hosts from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -0800965 controllerStr )
966 consistentHostsResult = main.FALSE
967 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -0800968 " hosts response: " +
969 repr( hosts[ controller ] ) )
970 utilities.assert_equals(
971 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800972 actual=consistentHostsResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800973 onpass="Hosts view is consistent across all ONOS nodes",
974 onfail="ONOS nodes have different views of hosts" )
Jon Hall94fd0472014-12-08 11:52:42 -0800975
Jon Hall6aec96b2015-01-19 14:49:31 -0800976 # Strongly connected clusters of devices
Jon Hall8f89dda2015-01-22 16:03:33 -0800977 consistentClustersResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800978 for controller in range( len( clusters ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -0800979 if "Error" not in clusters[ controller ]:
980 if clusters[ controller ] == clusters[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -0800981 continue
Jon Hall6aec96b2015-01-19 14:49:31 -0800982 else: # clusters not consistent
983 main.log.report( "clusters from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -0800984 controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -0800985 " is inconsistent with ONOS1" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800986 consistentClustersResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800987
988 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800989 main.log.report( "Error in getting dataplane clusters " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800990 "from ONOS" + controllerStr )
991 consistentClustersResult = main.FALSE
992 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -0800993 " clusters response: " +
994 repr( clusters[ controller ] ) )
995 utilities.assert_equals(
996 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800997 actual=consistentClustersResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800998 onpass="Clusters view is consistent across all ONOS nodes",
999 onfail="ONOS nodes have different views of clusters" )
1000 # there should always only be one cluster
Jon Hall8f89dda2015-01-22 16:03:33 -08001001 numClusters = len( json.loads( clusters[ 0 ] ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001002 utilities.assert_equals(
1003 expect=1,
Jon Hall8f89dda2015-01-22 16:03:33 -08001004 actual=numClusters,
Jon Hall6aec96b2015-01-19 14:49:31 -08001005 onpass="ONOS shows 1 SCC",
1006 onfail="ONOS shows " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001007 str( numClusters ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001008 " SCCs" )
Jon Hall94fd0472014-12-08 11:52:42 -08001009
Jon Hall6aec96b2015-01-19 14:49:31 -08001010 # paths
Jon Hall8f89dda2015-01-22 16:03:33 -08001011 consistentPathsResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -08001012 for controller in range( len( paths ) ):
Jon Hall8f89dda2015-01-22 16:03:33 -08001013 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001014 if "Error" not in paths[ controller ]:
1015 if paths[ controller ] == paths[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001016 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001017 else: # paths not consistent
Jon Hall8f89dda2015-01-22 16:03:33 -08001018 main.log.report( "paths from ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001019 " is inconsistent with ONOS1" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001020 consistentPathsResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001021
1022 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001023 main.log.report( "Error in getting paths from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001024 controllerStr )
1025 consistentPathsResult = main.FALSE
1026 main.log.warn( "ONOS" + controllerStr + " paths response: " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001027 repr( paths[ controller ] ) )
1028 utilities.assert_equals(
1029 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001030 actual=consistentPathsResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001031 onpass="Paths count is consistent across all ONOS nodes",
1032 onfail="ONOS nodes have different counts of paths" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001033
Jon Hall6aec96b2015-01-19 14:49:31 -08001034 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001035 devicesResults = main.TRUE
1036 portsResults = main.TRUE
1037 linksResults = main.TRUE
1038 for controller in range( numControllers ):
1039 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001040 if devices[ controller ] or "Error" not in devices[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001041 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -08001042 MNTopo,
1043 json.loads(
1044 devices[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001045 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001046 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001047 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001048 actual=currentDevicesResult,
1049 onpass="ONOS" + controllerStr +
1050 " Switches view is correct",
1051 onfail="ONOS" + controllerStr +
1052 " Switches view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001053
Jon Hall6aec96b2015-01-19 14:49:31 -08001054 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001055 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -08001056 MNTopo,
1057 json.loads(
1058 ports[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001059 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001060 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001061 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001062 actual=currentPortsResult,
1063 onpass="ONOS" + controllerStr +
1064 " ports view is correct",
1065 onfail="ONOS" + controllerStr +
1066 " ports view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001067
Jon Hall6aec96b2015-01-19 14:49:31 -08001068 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001069 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -08001070 MNTopo,
1071 json.loads(
1072 links[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001073 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001074 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001075 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001076 actual=currentLinksResult,
1077 onpass="ONOS" + controllerStr +
1078 " links view is correct",
1079 onfail="ONOS" + controllerStr +
1080 " links view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001081
Jon Hall8f89dda2015-01-22 16:03:33 -08001082 devicesResults = devicesResults and currentDevicesResult
1083 portsResults = portsResults and currentPortsResult
1084 linksResults = linksResults and currentLinksResult
Jon Hall73cf9cc2014-11-20 22:28:38 -08001085
Jon Hall8f89dda2015-01-22 16:03:33 -08001086 topoResult = devicesResults and portsResults and linksResults\
1087 and consistentHostsResult and consistentClustersResult\
1088 and consistentPathsResult
1089 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
1090 onpass="Topology Check Test successful",
1091 onfail="Topology Check Test NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001092
Jon Hall8f89dda2015-01-22 16:03:33 -08001093 finalAssert = main.TRUE
1094 finalAssert = finalAssert and topoResult and flowCheck \
1095 and intentCheck and consistentMastership and rolesNotNull
1096 utilities.assert_equals( expect=main.TRUE, actual=finalAssert,
1097 onpass="State check successful",
1098 onfail="State check NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001099
Jon Hall6aec96b2015-01-19 14:49:31 -08001100 def CASE6( self, main ):
1101 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001102 The Failure case.
Jon Hall6aec96b2015-01-19 14:49:31 -08001103 """
Jon Hall94fd0472014-12-08 11:52:42 -08001104 import time
Jon Hall6aec96b2015-01-19 14:49:31 -08001105 main.log.report( "Killing 3 ONOS nodes" )
1106 main.log.case( "Restart minority of ONOS nodes" )
1107 # TODO: Randomize these nodes
Jon Hall8f89dda2015-01-22 16:03:33 -08001108 main.ONOSbench.onosKill( ONOS1Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -08001109 time.sleep( 10 )
Jon Hall8f89dda2015-01-22 16:03:33 -08001110 main.ONOSbench.onosKill( ONOS2Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -08001111 time.sleep( 10 )
Jon Hall8f89dda2015-01-22 16:03:33 -08001112 main.ONOSbench.onosKill( ONOS3Ip )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001113
Jon Hall6aec96b2015-01-19 14:49:31 -08001114 main.step( "Checking if ONOS is up yet" )
Jon Hallffb386d2014-11-21 13:43:38 -08001115 count = 0
Jon Hall8f89dda2015-01-22 16:03:33 -08001116 onosIsupResult = main.FALSE
1117 while onosIsupResult == main.FALSE and count < 10:
1118 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
1119 onos2Isup = main.ONOSbench.isup( ONOS2Ip )
1120 onos3Isup = main.ONOSbench.isup( ONOS3Ip )
1121 onosIsupResult = onos1Isup and onos2Isup and onos3Isup
Jon Hallffb386d2014-11-21 13:43:38 -08001122 count = count + 1
Jon Hall73cf9cc2014-11-20 22:28:38 -08001123 # TODO: if it becomes an issue, we can retry this step a few times
1124
Jon Hall8f89dda2015-01-22 16:03:33 -08001125 cliResult1 = main.ONOScli1.startOnosCli( ONOS1Ip )
1126 cliResult2 = main.ONOScli2.startOnosCli( ONOS2Ip )
1127 cliResult3 = main.ONOScli3.startOnosCli( ONOS3Ip )
1128 cliResults = cliResult1 and cliResult2 and cliResult3
Jon Hall73cf9cc2014-11-20 22:28:38 -08001129
Jon Hall6aec96b2015-01-19 14:49:31 -08001130 main.log.info( "Install leadership election app on restarted node" )
Jon Hall669173b2014-12-17 11:36:30 -08001131
Jon Hall8f89dda2015-01-22 16:03:33 -08001132 caseResults = main.TRUE and onosIsupResult and cliResults
1133 utilities.assert_equals( expect=main.TRUE, actual=caseResults,
1134 onpass="ONOS restart successful",
1135 onfail="ONOS restart NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001136
Jon Hall6aec96b2015-01-19 14:49:31 -08001137 def CASE7( self, main ):
1138 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001139 Check state after ONOS failure
Jon Hall6aec96b2015-01-19 14:49:31 -08001140 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001141 import json
Jon Hall6aec96b2015-01-19 14:49:31 -08001142 main.case( "Running ONOS Constant State Tests" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001143
Jon Hall6aec96b2015-01-19 14:49:31 -08001144 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -08001145 ONOS1MasterNotNull = main.ONOScli1.rolesNotNull()
1146 ONOS2MasterNotNull = main.ONOScli2.rolesNotNull()
1147 ONOS3MasterNotNull = main.ONOScli3.rolesNotNull()
1148 ONOS4MasterNotNull = main.ONOScli4.rolesNotNull()
1149 ONOS5MasterNotNull = main.ONOScli5.rolesNotNull()
1150 ONOS6MasterNotNull = main.ONOScli6.rolesNotNull()
1151 ONOS7MasterNotNull = main.ONOScli7.rolesNotNull()
1152 rolesNotNull = ONOS1MasterNotNull and ONOS2MasterNotNull and\
1153 ONOS3MasterNotNull and ONOS4MasterNotNull and\
1154 ONOS5MasterNotNull and ONOS6MasterNotNull and\
1155 ONOS7MasterNotNull
Jon Hall6aec96b2015-01-19 14:49:31 -08001156 utilities.assert_equals(
1157 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001158 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -08001159 onpass="Each device has a master",
1160 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -08001161
Jon Hall6aec96b2015-01-19 14:49:31 -08001162 main.step( "Check if switch roles are consistent across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001163 ONOS1Mastership = main.ONOScli1.roles()
1164 ONOS2Mastership = main.ONOScli2.roles()
1165 ONOS3Mastership = main.ONOScli3.roles()
1166 ONOS4Mastership = main.ONOScli4.roles()
1167 ONOS5Mastership = main.ONOScli5.roles()
1168 ONOS6Mastership = main.ONOScli6.roles()
1169 ONOS7Mastership = main.ONOScli7.roles()
1170 # print json.dumps( json.loads( ONOS1Mastership ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001171 # indent=4, separators=( ',', ': ' ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001172 if "Error" in ONOS1Mastership or not ONOS1Mastership\
1173 or "Error" in ONOS2Mastership or not ONOS2Mastership\
1174 or "Error" in ONOS3Mastership or not ONOS3Mastership\
1175 or "Error" in ONOS4Mastership or not ONOS4Mastership\
1176 or "Error" in ONOS5Mastership or not ONOS5Mastership\
1177 or "Error" in ONOS6Mastership or not ONOS6Mastership\
1178 or "Error" in ONOS7Mastership or not ONOS7Mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -08001179 main.log.error( "Error in getting ONOS mastership" )
1180 main.log.warn( "ONOS1 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001181 repr( ONOS1Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001182 main.log.warn( "ONOS2 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001183 repr( ONOS2Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001184 main.log.warn( "ONOS3 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001185 repr( ONOS3Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001186 main.log.warn( "ONOS4 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001187 repr( ONOS4Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001188 main.log.warn( "ONOS5 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001189 repr( ONOS5Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001190 main.log.warn( "ONOS6 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001191 repr( ONOS6Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001192 main.log.warn( "ONOS7 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001193 repr( ONOS7Mastership ) )
1194 consistentMastership = main.FALSE
1195 elif ONOS1Mastership == ONOS2Mastership\
1196 and ONOS1Mastership == ONOS3Mastership\
1197 and ONOS1Mastership == ONOS4Mastership\
1198 and ONOS1Mastership == ONOS5Mastership\
1199 and ONOS1Mastership == ONOS6Mastership\
1200 and ONOS1Mastership == ONOS7Mastership:
1201 consistentMastership = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001202 main.log.report(
1203 "Switch roles are consistent across all ONOS nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001204 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001205 main.log.warn( "ONOS1 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001206 json.loads( ONOS1Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001207 separators=( ',', ': ' ) ) )
1208 main.log.warn( "ONOS2 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001209 json.loads( ONOS2Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001210 separators=( ',', ': ' ) ) )
1211 main.log.warn( "ONOS3 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001212 json.loads( ONOS3Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001213 separators=( ',', ': ' ) ) )
1214 main.log.warn( "ONOS4 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001215 json.loads( ONOS4Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001216 separators=( ',', ': ' ) ) )
1217 main.log.warn( "ONOS5 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001218 json.loads( ONOS5Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001219 separators=( ',', ': ' ) ) )
1220 main.log.warn( "ONOS6 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001221 json.loads( ONOS6Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001222 separators=( ',', ': ' ) ) )
1223 main.log.warn( "ONOS7 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001224 json.loads( ONOS7Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001225 separators=( ',', ': ' ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001226 consistentMastership = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001227 utilities.assert_equals(
1228 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001229 actual=consistentMastership,
Jon Hall6aec96b2015-01-19 14:49:31 -08001230 onpass="Switch roles are consistent across all ONOS nodes",
1231 onfail="ONOS nodes have different views of switch roles" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001232
1233 description2 = "Compare switch roles from before failure"
Jon Hall6aec96b2015-01-19 14:49:31 -08001234 main.step( description2 )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001235
Jon Hall8f89dda2015-01-22 16:03:33 -08001236 currentJson = json.loads( ONOS1Mastership )
1237 oldJson = json.loads( mastershipState )
1238 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001239 for i in range( 1, 29 ):
1240 switchDPID = str(
1241 main.Mininet1.getSwitchDPID(
1242 switch="s" +
1243 str( i ) ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001244
Jon Hall8f89dda2015-01-22 16:03:33 -08001245 current = [ switch[ 'master' ] for switch in currentJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001246 if switchDPID in switch[ 'id' ] ]
Jon Hall8f89dda2015-01-22 16:03:33 -08001247 old = [ switch[ 'master' ] for switch in oldJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001248 if switchDPID in switch[ 'id' ] ]
Jon Hall73cf9cc2014-11-20 22:28:38 -08001249 if current == old:
Jon Hall8f89dda2015-01-22 16:03:33 -08001250 mastershipCheck = mastershipCheck and main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001251 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001252 main.log.warn( "Mastership of switch %s changed" % switchDPID )
Jon Hall8f89dda2015-01-22 16:03:33 -08001253 mastershipCheck = main.FALSE
1254 if mastershipCheck == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001255 main.log.report( "Mastership of Switches was not changed" )
1256 utilities.assert_equals(
1257 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001258 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -08001259 onpass="Mastership of Switches was not changed",
1260 onfail="Mastership of some switches changed" )
1261 # NOTE: we expect mastership to change on controller failure
Jon Hall8f89dda2015-01-22 16:03:33 -08001262 mastershipCheck = consistentMastership
Jon Hall73cf9cc2014-11-20 22:28:38 -08001263
Jon Hall6aec96b2015-01-19 14:49:31 -08001264 main.step( "Get the intents and compare across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001265 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
1266 ONOS2Intents = main.ONOScli2.intents( jsonFormat=True )
1267 ONOS3Intents = main.ONOScli3.intents( jsonFormat=True )
1268 ONOS4Intents = main.ONOScli4.intents( jsonFormat=True )
1269 ONOS5Intents = main.ONOScli5.intents( jsonFormat=True )
1270 ONOS6Intents = main.ONOScli6.intents( jsonFormat=True )
1271 ONOS7Intents = main.ONOScli7.intents( jsonFormat=True )
1272 intentCheck = main.FALSE
1273 if "Error" in ONOS1Intents or not ONOS1Intents\
1274 or "Error" in ONOS2Intents or not ONOS2Intents\
1275 or "Error" in ONOS3Intents or not ONOS3Intents\
1276 or "Error" in ONOS4Intents or not ONOS4Intents\
1277 or "Error" in ONOS5Intents or not ONOS5Intents\
1278 or "Error" in ONOS6Intents or not ONOS6Intents\
1279 or "Error" in ONOS7Intents or not ONOS7Intents:
Jon Hall6aec96b2015-01-19 14:49:31 -08001280 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001281 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
1282 main.log.warn( "ONOS2 intents response: " + repr( ONOS2Intents ) )
1283 main.log.warn( "ONOS3 intents response: " + repr( ONOS3Intents ) )
1284 main.log.warn( "ONOS4 intents response: " + repr( ONOS4Intents ) )
1285 main.log.warn( "ONOS5 intents response: " + repr( ONOS5Intents ) )
1286 main.log.warn( "ONOS6 intents response: " + repr( ONOS6Intents ) )
1287 main.log.warn( "ONOS7 intents response: " + repr( ONOS7Intents ) )
1288 elif ONOS1Intents == ONOS2Intents\
1289 and ONOS1Intents == ONOS3Intents\
1290 and ONOS1Intents == ONOS4Intents\
1291 and ONOS1Intents == ONOS5Intents\
1292 and ONOS1Intents == ONOS6Intents\
1293 and ONOS1Intents == ONOS7Intents:
1294 intentCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001295 main.log.report( "Intents are consistent across all ONOS nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001296 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001297 main.log.warn( "ONOS1 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001298 print json.dumps( json.loads( ONOS1Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001299 indent=4, separators=( ',', ': ' ) )
1300 main.log.warn( "ONOS2 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001301 print json.dumps( json.loads( ONOS2Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001302 indent=4, separators=( ',', ': ' ) )
1303 main.log.warn( "ONOS3 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001304 print json.dumps( json.loads( ONOS3Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001305 indent=4, separators=( ',', ': ' ) )
1306 main.log.warn( "ONOS4 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001307 print json.dumps( json.loads( ONOS4Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001308 indent=4, separators=( ',', ': ' ) )
1309 main.log.warn( "ONOS5 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001310 print json.dumps( json.loads( ONOS5Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001311 indent=4, separators=( ',', ': ' ) )
1312 main.log.warn( "ONOS6 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001313 print json.dumps( json.loads( ONOS6Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001314 indent=4, separators=( ',', ': ' ) )
1315 main.log.warn( "ONOS7 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001316 print json.dumps( json.loads( ONOS7Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001317 indent=4, separators=( ',', ': ' ) )
1318 utilities.assert_equals(
1319 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001320 actual=intentCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -08001321 onpass="Intents are consistent across all ONOS nodes",
1322 onfail="ONOS nodes have different views of intents" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001323
Jon Hall6aec96b2015-01-19 14:49:31 -08001324 # NOTE: Hazelcast has no durability, so intents are lost across system
1325 # restarts
1326 main.step( "Compare current intents with intents before the failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001327 # NOTE: this requires case 5 to pass for intentState to be set.
Jon Hall94fd0472014-12-08 11:52:42 -08001328 # maybe we should stop the test if that fails?
Jon Hall8f89dda2015-01-22 16:03:33 -08001329 if intentState == ONOS1Intents:
1330 sameIntents = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001331 main.log.report( "Intents are consistent with before failure" )
1332 # TODO: possibly the states have changed? we may need to figure out
1333 # what the aceptable states are
Jon Hall73cf9cc2014-11-20 22:28:38 -08001334 else:
Jon Hall669173b2014-12-17 11:36:30 -08001335 try:
Jon Hall6aec96b2015-01-19 14:49:31 -08001336 main.log.warn( "ONOS1 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001337 print json.dumps( json.loads( ONOS1Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -08001338 sort_keys=True, indent=4,
1339 separators=( ',', ': ' ) )
Jon Hall669173b2014-12-17 11:36:30 -08001340 except:
1341 pass
Jon Hall8f89dda2015-01-22 16:03:33 -08001342 sameIntents = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001343 utilities.assert_equals(
1344 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001345 actual=sameIntents,
Jon Hall6aec96b2015-01-19 14:49:31 -08001346 onpass="Intents are consistent with before failure",
1347 onfail="The Intents changed during failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001348 intentCheck = intentCheck and sameIntents
Jon Hall73cf9cc2014-11-20 22:28:38 -08001349
Jon Hall6aec96b2015-01-19 14:49:31 -08001350 main.step( "Get the OF Table entries and compare to before " +
1351 "component failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001352 FlowTables = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001353 flows2 = []
1354 for i in range( 28 ):
1355 main.log.info( "Checking flow table on s" + str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001356 tmpFlows = main.Mininet2.getFlowTable( 1.3, "s" + str( i + 1 ) )
1357 flows2.append( tmpFlows )
1358 tempResult = main.Mininet2.flowComp(
Jon Hall6aec96b2015-01-19 14:49:31 -08001359 flow1=flows[ i ],
Jon Hall8f89dda2015-01-22 16:03:33 -08001360 flow2=tmpFlows )
1361 FlowTables = FlowTables and tempResult
1362 if FlowTables == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001363 main.log.info( "Differences in flow table for switch: s" +
1364 str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001365 if FlowTables == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001366 main.log.report( "No changes were found in the flow tables" )
1367 utilities.assert_equals(
1368 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001369 actual=FlowTables,
Jon Hall6aec96b2015-01-19 14:49:31 -08001370 onpass="No changes were found in the flow tables",
1371 onfail="Changes were found in the flow tables" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001372
Jon Hall6aec96b2015-01-19 14:49:31 -08001373 main.step( "Check the continuous pings to ensure that no packets " +
1374 "were dropped during component failure" )
1375 # FIXME: This check is always failing. Investigate cause
1376 # NOTE: this may be something to do with file permsissions
Jon Hall73cf9cc2014-11-20 22:28:38 -08001377 # or slight change in format
Jon Hall6aec96b2015-01-19 14:49:31 -08001378 main.Mininet2.pingKill(
1379 main.params[ 'TESTONUSER' ],
1380 main.params[ 'TESTONIP' ] )
Jon Hall8f89dda2015-01-22 16:03:33 -08001381 LossInPings = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001382 # NOTE: checkForLoss returns main.FALSE with 0% packet loss
1383 for i in range( 8, 18 ):
1384 main.log.info(
1385 "Checking for a loss in pings along flow from s" +
1386 str( i ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001387 LossInPings = main.Mininet2.checkForLoss(
Jon Hall6aec96b2015-01-19 14:49:31 -08001388 "/tmp/ping.h" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001389 str( i ) ) or LossInPings
1390 if LossInPings == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001391 main.log.info( "Loss in ping detected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001392 elif LossInPings == main.ERROR:
Jon Hall6aec96b2015-01-19 14:49:31 -08001393 main.log.info( "There are multiple mininet process running" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001394 elif LossInPings == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001395 main.log.info( "No Loss in the pings" )
1396 main.log.report( "No loss of dataplane connectivity" )
1397 utilities.assert_equals(
1398 expect=main.FALSE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001399 actual=LossInPings,
Jon Hall6aec96b2015-01-19 14:49:31 -08001400 onpass="No Loss of connectivity",
1401 onfail="Loss of dataplane connectivity detected" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001402
Jon Hall6aec96b2015-01-19 14:49:31 -08001403 # Test of LeadershipElection
Jon Hall8f89dda2015-01-22 16:03:33 -08001404 leaderList = []
1405 leaderResult = main.TRUE
1406 for controller in range( 1, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001407 # loop through ONOScli handlers
1408 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001409 leaderN = node.electionTestLeader()
1410 leaderList.append( leaderN )
Jon Hall669173b2014-12-17 11:36:30 -08001411 if leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001412 # error in response
1413 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001414 "electionTestLeader function, check the" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001415 " error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001416 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001417 elif leaderN is None:
1418 main.log.report( "ONOS" + str( controller ) +
1419 " shows no leader for the election-app was" +
1420 " elected after the old one died" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001421 leaderResult = main.FALSE
1422 elif leaderN == ONOS1Ip or leaderN == ONOS2Ip or\
1423 leaderN == ONOS3Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08001424 main.log.report( "ONOS" + str( controller ) +
1425 " shows " + str( leaderN ) +
1426 " as leader for the election-app, but it " +
1427 "was restarted" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001428 leaderResult = main.FALSE
1429 if len( set( leaderList ) ) != 1:
1430 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001431 main.log.error(
1432 "Inconsistent view of leader for the election test app" )
1433 # TODO: print the list
Jon Hall8f89dda2015-01-22 16:03:33 -08001434 if leaderResult:
1435 main.log.report( "Leadership election tests passed( consistent " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001436 "view of leader across listeners and a new " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001437 "leader was re-elected if applicable )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001438 utilities.assert_equals(
1439 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001440 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001441 onpass="Leadership election passed",
1442 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08001443
Jon Hall8f89dda2015-01-22 16:03:33 -08001444 result = mastershipCheck and intentCheck and FlowTables and\
1445 ( not LossInPings ) and rolesNotNull and leaderResult
Jon Hall6aec96b2015-01-19 14:49:31 -08001446 result = int( result )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001447 if result == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001448 main.log.report( "Constant State Tests Passed" )
1449 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall8f89dda2015-01-22 16:03:33 -08001450 onpass="Constant State Tests Passed",
1451 onfail="Constant state tests failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001452
Jon Hall6aec96b2015-01-19 14:49:31 -08001453 def CASE8( self, main ):
1454 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001455 Compare topo
Jon Hall6aec96b2015-01-19 14:49:31 -08001456 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001457 import sys
Jon Hall6aec96b2015-01-19 14:49:31 -08001458 # FIXME add this path to params
1459 sys.path.append( "/home/admin/sts" )
1460 # assumes that sts is already in you PYTHONPATH
1461 from sts.topology.teston_topology import TestONTopology
Jon Hall73cf9cc2014-11-20 22:28:38 -08001462 import json
1463 import time
1464
Jon Hall6aec96b2015-01-19 14:49:31 -08001465 description = "Compare ONOS Topology view to Mininet topology"
1466 main.case( description )
1467 main.log.report( description )
1468 main.step( "Create TestONTopology object" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001469 ctrls = []
1470 count = 1
1471 while True:
1472 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -08001473 if ( 'ip' + str( count ) ) in main.params[ 'CTRL' ]:
1474 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
1475 temp = temp + ( "ONOS" + str( count ), )
1476 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
1477 temp = temp + \
1478 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
1479 ctrls.append( temp )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001480 count = count + 1
1481 else:
1482 break
Jon Hall6aec96b2015-01-19 14:49:31 -08001483 MNTopo = TestONTopology(
1484 main.Mininet1,
1485 ctrls ) # can also add Intent API info for intent operations
Jon Hall73cf9cc2014-11-20 22:28:38 -08001486
Jon Hall6aec96b2015-01-19 14:49:31 -08001487 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001488 devicesResults = main.TRUE
1489 portsResults = main.TRUE
1490 linksResults = main.TRUE
1491 topoResult = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001492 elapsed = 0
Jon Hallffb386d2014-11-21 13:43:38 -08001493 count = 0
Jon Hall6aec96b2015-01-19 14:49:31 -08001494 main.step( "Collecting topology information from ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001495 startTime = time.time()
1496 while topoResult == main.FALSE and elapsed < 60:
Jon Hallffb386d2014-11-21 13:43:38 -08001497 count = count + 1
Jon Hall94fd0472014-12-08 11:52:42 -08001498 if count > 1:
Jon Hall6aec96b2015-01-19 14:49:31 -08001499 # TODO: Depricate STS usage
1500 MNTopo = TestONTopology(
1501 main.Mininet1,
1502 ctrls )
Jon Hall8f89dda2015-01-22 16:03:33 -08001503 cliStart = time.time()
Jon Hall94fd0472014-12-08 11:52:42 -08001504 devices = []
1505 devices.append( main.ONOScli1.devices() )
1506 devices.append( main.ONOScli2.devices() )
1507 devices.append( main.ONOScli3.devices() )
1508 devices.append( main.ONOScli4.devices() )
1509 devices.append( main.ONOScli5.devices() )
1510 devices.append( main.ONOScli6.devices() )
1511 devices.append( main.ONOScli7.devices() )
1512 hosts = []
Jon Hall669173b2014-12-17 11:36:30 -08001513 hosts.append( json.loads( main.ONOScli1.hosts() ) )
1514 hosts.append( json.loads( main.ONOScli2.hosts() ) )
1515 hosts.append( json.loads( main.ONOScli3.hosts() ) )
1516 hosts.append( json.loads( main.ONOScli4.hosts() ) )
1517 hosts.append( json.loads( main.ONOScli5.hosts() ) )
1518 hosts.append( json.loads( main.ONOScli6.hosts() ) )
1519 hosts.append( json.loads( main.ONOScli7.hosts() ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001520 for controller in range( 0, len( hosts ) ):
Jon Hall8f89dda2015-01-22 16:03:33 -08001521 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001522 for host in hosts[ controller ]:
Jon Hall669173b2014-12-17 11:36:30 -08001523 host
Jon Hall6aec96b2015-01-19 14:49:31 -08001524 if host[ 'ips' ] == []:
1525 main.log.error(
1526 "DEBUG:Error with host ips on controller" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001527 controllerStr + ": " + str( host ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001528 ports = []
1529 ports.append( main.ONOScli1.ports() )
1530 ports.append( main.ONOScli2.ports() )
1531 ports.append( main.ONOScli3.ports() )
1532 ports.append( main.ONOScli4.ports() )
1533 ports.append( main.ONOScli5.ports() )
1534 ports.append( main.ONOScli6.ports() )
1535 ports.append( main.ONOScli7.ports() )
1536 links = []
1537 links.append( main.ONOScli1.links() )
1538 links.append( main.ONOScli2.links() )
1539 links.append( main.ONOScli3.links() )
1540 links.append( main.ONOScli4.links() )
1541 links.append( main.ONOScli5.links() )
1542 links.append( main.ONOScli6.links() )
1543 links.append( main.ONOScli7.links() )
1544 clusters = []
1545 clusters.append( main.ONOScli1.clusters() )
1546 clusters.append( main.ONOScli2.clusters() )
1547 clusters.append( main.ONOScli3.clusters() )
1548 clusters.append( main.ONOScli4.clusters() )
1549 clusters.append( main.ONOScli5.clusters() )
1550 clusters.append( main.ONOScli6.clusters() )
1551 clusters.append( main.ONOScli7.clusters() )
1552 paths = []
Jon Hall8f89dda2015-01-22 16:03:33 -08001553 tempTopo = main.ONOSbench.getTopology( main.ONOScli1.topology() )
1554 paths.append( tempTopo.get( 'paths', False ) )
1555 tempTopo = main.ONOSbench.getTopology( main.ONOScli2.topology() )
1556 paths.append( tempTopo.get( 'paths', False ) )
1557 tempTopo = main.ONOSbench.getTopology( main.ONOScli3.topology() )
1558 paths.append( tempTopo.get( 'paths', False ) )
1559 tempTopo = main.ONOSbench.getTopology( main.ONOScli4.topology() )
1560 paths.append( tempTopo.get( 'paths', False ) )
1561 tempTopo = main.ONOSbench.getTopology( main.ONOScli5.topology() )
1562 paths.append( tempTopo.get( 'paths', False ) )
1563 tempTopo = main.ONOSbench.getTopology( main.ONOScli6.topology() )
1564 paths.append( tempTopo.get( 'paths', False ) )
1565 tempTopo = main.ONOSbench.getTopology( main.ONOScli7.topology() )
1566 paths.append( tempTopo.get( 'paths', False ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001567
Jon Hall8f89dda2015-01-22 16:03:33 -08001568 elapsed = time.time() - startTime
1569 cliTime = time.time() - cliStart
1570 print "CLI time: " + str( cliTime )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001571
Jon Hall8f89dda2015-01-22 16:03:33 -08001572 for controller in range( numControllers ):
1573 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001574 if devices[ controller ] or "Error" not in devices[
1575 controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001576 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -08001577 MNTopo,
1578 json.loads(
1579 devices[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001580 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001581 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001582 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001583 actual=currentDevicesResult,
1584 onpass="ONOS" + controllerStr +
1585 " Switches view is correct",
1586 onfail="ONOS" + controllerStr +
1587 " Switches view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001588
Jon Hall6aec96b2015-01-19 14:49:31 -08001589 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001590 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -08001591 MNTopo,
1592 json.loads(
1593 ports[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001594 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001595 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001596 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001597 actual=currentPortsResult,
1598 onpass="ONOS" + controllerStr +
1599 " ports view is correct",
1600 onfail="ONOS" + controllerStr +
1601 " ports view is incorrect" )
Jon Hall94fd0472014-12-08 11:52:42 -08001602
Jon Hall6aec96b2015-01-19 14:49:31 -08001603 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001604 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -08001605 MNTopo,
1606 json.loads(
1607 links[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001608 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001609 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001610 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001611 actual=currentLinksResult,
1612 onpass="ONOS" + controllerStr +
1613 " links view is correct",
1614 onfail="ONOS" + controllerStr +
1615 " links view is incorrect" )
1616 devicesResults = devicesResults and currentDevicesResult
1617 portsResults = portsResults and currentPortsResult
1618 linksResults = linksResults and currentLinksResult
Jon Hall94fd0472014-12-08 11:52:42 -08001619
Jon Hall6aec96b2015-01-19 14:49:31 -08001620 # Compare json objects for hosts, dataplane clusters and paths
Jon Hall94fd0472014-12-08 11:52:42 -08001621
Jon Hall6aec96b2015-01-19 14:49:31 -08001622 # hosts
Jon Hall8f89dda2015-01-22 16:03:33 -08001623 consistentHostsResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -08001624 for controller in range( len( hosts ) ):
Jon Hall8f89dda2015-01-22 16:03:33 -08001625 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001626 if "Error" not in hosts[ controller ]:
1627 if hosts[ controller ] == hosts[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001628 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001629 else: # hosts not consistent
Jon Hall8f89dda2015-01-22 16:03:33 -08001630 main.log.report( "hosts from ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001631 " is inconsistent with ONOS1" )
1632 main.log.warn( repr( hosts[ controller ] ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001633 consistentHostsResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001634
1635 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001636 main.log.report( "Error in getting ONOS hosts from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001637 controllerStr )
1638 consistentHostsResult = main.FALSE
1639 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001640 " hosts response: " +
1641 repr( hosts[ controller ] ) )
1642 utilities.assert_equals(
1643 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001644 actual=consistentHostsResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001645 onpass="Hosts view is consistent across all ONOS nodes",
1646 onfail="ONOS nodes have different views of hosts" )
Jon Hall94fd0472014-12-08 11:52:42 -08001647
Jon Hall6aec96b2015-01-19 14:49:31 -08001648 # Strongly connected clusters of devices
Jon Hall8f89dda2015-01-22 16:03:33 -08001649 consistentClustersResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -08001650 for controller in range( len( clusters ) ):
Jon Hall8f89dda2015-01-22 16:03:33 -08001651 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001652 if "Error" not in clusters[ controller ]:
1653 if clusters[ controller ] == clusters[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001654 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001655 else: # clusters not consistent
1656 main.log.report( "clusters from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001657 controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001658 " is inconsistent with ONOS1" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001659 consistentClustersResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001660
1661 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001662 main.log.report( "Error in getting dataplane clusters " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001663 "from ONOS" + controllerStr )
1664 consistentClustersResult = main.FALSE
1665 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001666 " clusters response: " +
1667 repr( clusters[ controller ] ) )
1668 utilities.assert_equals(
1669 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001670 actual=consistentClustersResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001671 onpass="Clusters view is consistent across all ONOS nodes",
1672 onfail="ONOS nodes have different views of clusters" )
1673 # there should always only be one cluster
Jon Hall8f89dda2015-01-22 16:03:33 -08001674 numClusters = len( json.loads( clusters[ 0 ] ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001675 utilities.assert_equals(
1676 expect=1,
Jon Hall8f89dda2015-01-22 16:03:33 -08001677 actual=numClusters,
Jon Hall6aec96b2015-01-19 14:49:31 -08001678 onpass="ONOS shows 1 SCC",
1679 onfail="ONOS shows " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001680 str( numClusters ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001681 " SCCs" )
Jon Hall94fd0472014-12-08 11:52:42 -08001682
Jon Hall6aec96b2015-01-19 14:49:31 -08001683 # paths
Jon Hall8f89dda2015-01-22 16:03:33 -08001684 consistentPathsResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -08001685 for controller in range( len( paths ) ):
Jon Hall8f89dda2015-01-22 16:03:33 -08001686 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001687 if "Error" not in paths[ controller ]:
1688 if paths[ controller ] == paths[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001689 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001690 else: # paths not consistent
Jon Hall8f89dda2015-01-22 16:03:33 -08001691 main.log.report( "paths from ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001692 " is inconsistent with ONOS1" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001693 consistentPathsResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001694
1695 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001696 main.log.report( "Error in getting paths from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001697 controllerStr )
1698 consistentPathsResult = main.FALSE
1699 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001700 " paths response: " +
1701 repr( paths[ controller ] ) )
1702 utilities.assert_equals(
1703 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001704 actual=consistentPathsResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001705 onpass="Paths count is consistent across all ONOS nodes",
1706 onfail="ONOS nodes have different counts of paths" )
Jon Hall94fd0472014-12-08 11:52:42 -08001707
Jon Hall8f89dda2015-01-22 16:03:33 -08001708 topoResult = ( devicesResults and portsResults and linksResults
1709 and consistentHostsResult
1710 and consistentClustersResult
1711 and consistentPathsResult )
Jon Hall94fd0472014-12-08 11:52:42 -08001712
Jon Hall8f89dda2015-01-22 16:03:33 -08001713 topoResult = topoResult and int( count <= 2 )
1714 note = "note it takes about " + str( int( cliTime ) ) + \
1715 " seconds for the test to make all the cli calls to fetch " +\
1716 "the topology from each ONOS instance"
Jon Hall6aec96b2015-01-19 14:49:31 -08001717 main.log.report(
Jon Hall8f89dda2015-01-22 16:03:33 -08001718 "Very crass estimate for topology discovery/convergence( " +
1719 str( note ) + " ): " + str( elapsed ) + " seconds, " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001720 str( count ) + " tries" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001721 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
1722 onpass="Topology Check Test successful",
1723 onfail="Topology Check Test NOT successful" )
1724 if topoResult == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001725 main.log.report( "ONOS topology view matches Mininet topology" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001726
Jon Hall6aec96b2015-01-19 14:49:31 -08001727 def CASE9( self, main ):
1728 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001729 Link s3-s28 down
Jon Hall6aec96b2015-01-19 14:49:31 -08001730 """
1731 import time
1732 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001733
Jon Hall8f89dda2015-01-22 16:03:33 -08001734 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001735
Jon Hall6aec96b2015-01-19 14:49:31 -08001736 description = "Turn off a link to ensure that Link Discovery " +\
Jon Hall8f89dda2015-01-22 16:03:33 -08001737 "is working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001738 main.log.report( description )
1739 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001740
Jon Hall6aec96b2015-01-19 14:49:31 -08001741 main.step( "Kill Link between s3 and s28" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001742 LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001743 main.log.info(
1744 "Waiting " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001745 str( linkSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001746 " seconds for link down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001747 time.sleep( linkSleep )
1748 utilities.assert_equals( expect=main.TRUE, actual=LinkDown,
1749 onpass="Link down succesful",
1750 onfail="Failed to bring link down" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001751 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -08001752
Jon Hall6aec96b2015-01-19 14:49:31 -08001753 def CASE10( self, main ):
1754 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001755 Link s3-s28 up
Jon Hall6aec96b2015-01-19 14:49:31 -08001756 """
1757 import time
1758 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001759
Jon Hall8f89dda2015-01-22 16:03:33 -08001760 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001761
Jon Hall6aec96b2015-01-19 14:49:31 -08001762 description = "Restore a link to ensure that Link Discovery is " + \
Jon Hall8f89dda2015-01-22 16:03:33 -08001763 "working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001764 main.log.report( description )
1765 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001766
Jon Hall6aec96b2015-01-19 14:49:31 -08001767 main.step( "Bring link between s3 and s28 back up" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001768 LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001769 main.log.info(
1770 "Waiting " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001771 str( linkSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001772 " seconds for link up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001773 time.sleep( linkSleep )
1774 utilities.assert_equals( expect=main.TRUE, actual=LinkUp,
1775 onpass="Link up succesful",
1776 onfail="Failed to bring link up" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001777 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -08001778
Jon Hall6aec96b2015-01-19 14:49:31 -08001779 def CASE11( self, main ):
1780 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001781 Switch Down
Jon Hall6aec96b2015-01-19 14:49:31 -08001782 """
1783 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001784 import time
1785
Jon Hall8f89dda2015-01-22 16:03:33 -08001786 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001787
1788 description = "Killing a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001789 main.log.report( description )
1790 main.case( description )
1791 switch = main.params[ 'kill' ][ 'switch' ]
1792 switchDPID = main.params[ 'kill' ][ 'dpid' ]
Jon Hall73cf9cc2014-11-20 22:28:38 -08001793
Jon Hall6aec96b2015-01-19 14:49:31 -08001794 # TODO: Make this switch parameterizable
1795 main.step( "Kill " + switch )
1796 main.log.report( "Deleting " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001797 main.Mininet1.delSwitch( switch )
1798 main.log.info( "Waiting " + str( switchSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001799 " seconds for switch down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001800 time.sleep( switchSleep )
1801 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001802 # Peek at the deleted switch
1803 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001804 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001805 if device and device[ 'available' ] is False:
Jon Hall94fd0472014-12-08 11:52:42 -08001806 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001807 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall8f89dda2015-01-22 16:03:33 -08001808 onpass="Kill switch succesful",
1809 onfail="Failed to kill switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001810
Jon Hall6aec96b2015-01-19 14:49:31 -08001811 def CASE12( self, main ):
1812 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001813 Switch Up
Jon Hall6aec96b2015-01-19 14:49:31 -08001814 """
1815 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001816 import time
Jon Hall669173b2014-12-17 11:36:30 -08001817
Jon Hall8f89dda2015-01-22 16:03:33 -08001818 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall6aec96b2015-01-19 14:49:31 -08001819 switch = main.params[ 'kill' ][ 'switch' ]
1820 switchDPID = main.params[ 'kill' ][ 'dpid' ]
1821 links = main.params[ 'kill' ][ 'links' ].split()
Jon Hall73cf9cc2014-11-20 22:28:38 -08001822 description = "Adding a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001823 main.log.report( description )
1824 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001825
Jon Hall6aec96b2015-01-19 14:49:31 -08001826 main.step( "Add back " + switch )
1827 main.log.report( "Adding back " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001828 main.Mininet1.addSwitch( switch, dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001829 # TODO: New dpid or same? Ask Thomas?
1830 for peer in links:
Jon Hall8f89dda2015-01-22 16:03:33 -08001831 main.Mininet1.addLink( switch, peer )
1832 main.Mininet1.assignSwController(
Jon Hall6aec96b2015-01-19 14:49:31 -08001833 sw=switch.split( 's' )[ 1 ],
Jon Hall8f89dda2015-01-22 16:03:33 -08001834 count=numControllers,
1835 ip1=ONOS1Ip,
1836 port1=ONOS1Port,
1837 ip2=ONOS2Ip,
1838 port2=ONOS2Port,
1839 ip3=ONOS3Ip,
1840 port3=ONOS3Port,
1841 ip4=ONOS4Ip,
1842 port4=ONOS4Port,
1843 ip5=ONOS5Ip,
1844 port5=ONOS5Port,
1845 ip6=ONOS6Ip,
1846 port6=ONOS6Port,
1847 ip7=ONOS7Ip,
1848 port7=ONOS7Port )
Jon Hall6aec96b2015-01-19 14:49:31 -08001849 main.log.info(
1850 "Waiting " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001851 str( switchSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001852 " seconds for switch up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001853 time.sleep( switchSleep )
1854 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001855 # Peek at the deleted switch
1856 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001857 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001858 if device and device[ 'available' ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001859 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001860 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall8f89dda2015-01-22 16:03:33 -08001861 onpass="add switch succesful",
1862 onfail="Failed to add switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001863
Jon Hall6aec96b2015-01-19 14:49:31 -08001864 def CASE13( self, main ):
1865 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001866 Clean up
Jon Hall6aec96b2015-01-19 14:49:31 -08001867 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001868 import os
1869 import time
Jon Hall6aec96b2015-01-19 14:49:31 -08001870 # TODO: make use of this elsewhere
1871 ips = []
Jon Hall8f89dda2015-01-22 16:03:33 -08001872 ips.append( ONOS1Ip )
1873 ips.append( ONOS2Ip )
1874 ips.append( ONOS3Ip )
1875 ips.append( ONOS4Ip )
1876 ips.append( ONOS5Ip )
1877 ips.append( ONOS6Ip )
1878 ips.append( ONOS7Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -08001879
1880 # printing colors to terminal
Jon Hall669173b2014-12-17 11:36:30 -08001881 colors = {}
Jon Hall6aec96b2015-01-19 14:49:31 -08001882 colors[ 'cyan' ] = '\033[96m'
1883 colors[ 'purple' ] = '\033[95m'
1884 colors[ 'blue' ] = '\033[94m'
1885 colors[ 'green' ] = '\033[92m'
1886 colors[ 'yellow' ] = '\033[93m'
1887 colors[ 'red' ] = '\033[91m'
1888 colors[ 'end' ] = '\033[0m'
Jon Hall73cf9cc2014-11-20 22:28:38 -08001889 description = "Test Cleanup"
Jon Hall6aec96b2015-01-19 14:49:31 -08001890 main.log.report( description )
1891 main.case( description )
1892 main.step( "Killing tcpdumps" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001893 main.Mininet2.stopTcpdump()
Jon Hall73cf9cc2014-11-20 22:28:38 -08001894
Jon Hall6aec96b2015-01-19 14:49:31 -08001895 main.step( "Checking ONOS Logs for errors" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001896 for i in range( 7 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001897 print colors[ 'purple' ] + "Checking logs for errors on " + \
Jon Hall8f89dda2015-01-22 16:03:33 -08001898 "ONOS" + str( i + 1 ) + ":" + colors[ 'end' ]
1899 print main.ONOSbench.checkLogs( ips[ i ] )
Jon Hall94fd0472014-12-08 11:52:42 -08001900
Jon Hall6aec96b2015-01-19 14:49:31 -08001901 main.step( "Copying MN pcap and ONOS log files to test station" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001902 testname = main.TEST
Jon Hall8f89dda2015-01-22 16:03:33 -08001903 teststationUser = main.params[ 'TESTONUSER' ]
1904 teststationIP = main.params[ 'TESTONIP' ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001905 # NOTE: MN Pcap file is being saved to ~/packet_captures
Jon Hall73cf9cc2014-11-20 22:28:38 -08001906 # scp this file as MN and TestON aren't necessarily the same vm
Jon Hall6aec96b2015-01-19 14:49:31 -08001907 # FIXME: scp
1908 # mn files
1909 # TODO: Load these from params
1910 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001911 logFolder = "/opt/onos/log/"
1912 logFiles = [ "karaf.log", "karaf.log.1" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001913 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001914 dstDir = "~/packet_captures/"
1915 for f in logFiles:
1916 for i in range( 7 ):
1917 main.ONOSbench.handle.sendline( "scp sdn@" + ips[ i ] + ":" +
1918 logFolder + f + " " +
1919 teststationUser + "@" +
1920 teststationIP + ":" +
1921 dstDir + str( testname ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001922 "-ONOS" + str( i + 1 ) + "-" +
1923 f )
1924 # std*.log's
1925 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001926 logFolder = "/opt/onos/var/"
1927 logFiles = [ "stderr.log", "stdout.log" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001928 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001929 dstDir = "~/packet_captures/"
1930 for f in logFiles:
1931 for i in range( 7 ):
1932 main.ONOSbench.handle.sendline( "scp sdn@" + ips[ i ] + ":" +
1933 logFolder + f + " " +
1934 teststationUser + "@" +
1935 teststationIP + ":" +
1936 dstDir + str( testname ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001937 "-ONOS" + str( i + 1 ) + "-" +
1938 f )
1939 # sleep so scp can finish
1940 time.sleep( 10 )
1941 main.step( "Packing and rotating pcap archives" )
1942 os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001943
Jon Hall6aec96b2015-01-19 14:49:31 -08001944 # TODO: actually check something here
1945 utilities.assert_equals( expect=main.TRUE, actual=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001946 onpass="Test cleanup successful",
1947 onfail="Test cleanup NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001948
Jon Hall6aec96b2015-01-19 14:49:31 -08001949 def CASE14( self, main ):
1950 """
Jon Hall669173b2014-12-17 11:36:30 -08001951 start election app on all onos nodes
Jon Hall6aec96b2015-01-19 14:49:31 -08001952 """
Jon Hall8f89dda2015-01-22 16:03:33 -08001953 leaderResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001954 # install app on onos 1
1955 main.log.info( "Install leadership election app" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001956 main.ONOScli1.featureInstall( "onos-app-election" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001957 # wait for election
1958 # check for leader
Jon Hall8f89dda2015-01-22 16:03:33 -08001959 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001960 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08001961 if leader == ONOS1Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08001962 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001963 pass
Jon Hall6aec96b2015-01-19 14:49:31 -08001964 elif leader is None:
1965 # No leader elected
1966 main.log.report( "No leader was elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001967 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001968 elif leader == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001969 # error in response
1970 # TODO: add check for "Command not found:" in the driver, this
1971 # means the app isn't loaded
Jon Hall8f89dda2015-01-22 16:03:33 -08001972 main.log.report( "Something is wrong with electionTestLeader" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001973 " function, check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001974 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001975 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001976 # error in response
1977 main.log.report(
Jon Hall8f89dda2015-01-22 16:03:33 -08001978 "Unexpected response from electionTestLeader function:'" +
1979 str( leader ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001980 "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001981 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001982
Jon Hall6aec96b2015-01-19 14:49:31 -08001983 # install on other nodes and check for leader.
1984 # Should be onos1 and each app should show the same leader
Jon Hall8f89dda2015-01-22 16:03:33 -08001985 for controller in range( 2, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001986 # loop through ONOScli handlers
1987 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001988 node.featureInstall( "onos-app-election" )
1989 leaderN = node.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001990 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08001991 if leaderN == ONOS1Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08001992 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001993 pass
1994 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001995 # error in response
1996 # TODO: add check for "Command not found:" in the driver, this
1997 # means the app isn't loaded
1998 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001999 "electionTestLeader function, check the" +
Jon Hall6aec96b2015-01-19 14:49:31 -08002000 " error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002001 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08002002 elif leader != leaderN:
Jon Hall8f89dda2015-01-22 16:03:33 -08002003 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08002004 main.log.report( "ONOS" + str( controller ) + " sees " +
2005 str( leaderN ) +
2006 " as the leader of the election app. Leader" +
2007 " should be " +
2008 str( leader ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08002009 if leaderResult:
Jon Hall6aec96b2015-01-19 14:49:31 -08002010 main.log.report( "Leadership election tests passed( consistent " +
2011 "view of leader across listeners and a leader " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002012 "was elected )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08002013 utilities.assert_equals(
2014 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002015 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002016 onpass="Leadership election passed",
2017 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08002018
Jon Hall6aec96b2015-01-19 14:49:31 -08002019 def CASE15( self, main ):
2020 """
Jon Hall669173b2014-12-17 11:36:30 -08002021 Check that Leadership Election is still functional
Jon Hall6aec96b2015-01-19 14:49:31 -08002022 """
Jon Hall8f89dda2015-01-22 16:03:33 -08002023 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08002024 description = "Check that Leadership Election is still functional"
Jon Hall6aec96b2015-01-19 14:49:31 -08002025 main.log.report( description )
2026 main.case( description )
2027 main.step( "Find current leader and withdraw" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002028 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08002029 # TODO: do some sanity checking on leader before using it
Jon Hall8f89dda2015-01-22 16:03:33 -08002030 withdrawResult = main.FALSE
2031 if leader == ONOS1Ip:
2032 oldLeader = getattr( main, "ONOScli1" )
2033 elif leader == ONOS2Ip:
2034 oldLeader = getattr( main, "ONOScli2" )
2035 elif leader == ONOS3Ip:
2036 oldLeader = getattr( main, "ONOScli3" )
2037 elif leader == ONOS4Ip:
2038 oldLeader = getattr( main, "ONOScli4" )
2039 elif leader == ONOS5Ip:
2040 oldLeader = getattr( main, "ONOScli5" )
2041 elif leader == ONOS6Ip:
2042 oldLeader = getattr( main, "ONOScli6" )
2043 elif leader == ONOS7Ip:
2044 oldLeader = getattr( main, "ONOScli7" )
Jon Hall6aec96b2015-01-19 14:49:31 -08002045 elif leader is None or leader == main.FALSE:
2046 main.log.report(
2047 "Leader for the election app should be an ONOS node," +
2048 "instead got '" +
Jon Hall8f89dda2015-01-22 16:03:33 -08002049 str( leader ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08002050 "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002051 leaderResult = main.FALSE
2052 withdrawResult = oldLeader.electionTestWithdraw()
Jon Hall6aec96b2015-01-19 14:49:31 -08002053 utilities.assert_equals(
2054 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002055 actual=withdrawResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002056 onpass="App was withdrawn from election",
2057 onfail="App was not withdrawn from election" )
Jon Hall669173b2014-12-17 11:36:30 -08002058
Jon Hall6aec96b2015-01-19 14:49:31 -08002059 main.step( "Make sure new leader is elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002060 leaderList = []
2061 for controller in range( 1, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08002062 # loop through ONOScli handlers
2063 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08002064 leaderList.append( node.electionTestLeader() )
2065 for leaderN in leaderList:
Jon Hall669173b2014-12-17 11:36:30 -08002066 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08002067 main.log.report(
2068 "ONOS" +
2069 str( controller ) +
2070 " still sees " +
2071 str( leader ) +
2072 " as leader after they withdrew" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002073 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08002074 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08002075 # error in response
2076 # TODO: add check for "Command not found:" in the driver, this
2077 # means the app isn't loaded
2078 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002079 "electionTestLeader function, " +
Jon Hall6aec96b2015-01-19 14:49:31 -08002080 "check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002081 leaderResult = main.FALSE
2082 consistentLeader = main.FALSE
2083 if len( set( leaderList ) ) == 1:
Jon Hall6aec96b2015-01-19 14:49:31 -08002084 main.log.info( "Each Election-app sees '" +
Jon Hall8f89dda2015-01-22 16:03:33 -08002085 str( leaderList[ 0 ] ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08002086 "' as the leader" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002087 consistentLeader = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08002088 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08002089 main.log.report(
2090 "Inconsistent responses for leader of Election-app:" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002091 for n in range( len( leaderList ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -08002092 main.log.report( "ONOS" + str( n + 1 ) + " response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002093 str( leaderList[ n ] ) )
2094 if leaderResult:
2095 main.log.report( "Leadership election tests passed( consistent " +
Jon Hall6aec96b2015-01-19 14:49:31 -08002096 "view of leader across listeners and a new " +
2097 "leader was elected when the old leader " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002098 "resigned )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08002099 utilities.assert_equals(
2100 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002101 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002102 onpass="Leadership election passed",
2103 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08002104
Jon Hall6aec96b2015-01-19 14:49:31 -08002105 main.step(
Jon Hall8f89dda2015-01-22 16:03:33 -08002106 "Run for election on old leader( just so everyone is in the hat )" )
2107 runResult = oldLeader.electionTestRun()
Jon Hall6aec96b2015-01-19 14:49:31 -08002108 utilities.assert_equals(
2109 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002110 actual=runResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002111 onpass="App re-ran for election",
2112 onfail="App failed to run for election" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002113 if consistentLeader == main.TRUE:
2114 afterRun = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08002115 # verify leader didn't just change
Jon Hall8f89dda2015-01-22 16:03:33 -08002116 if afterRun == leaderList[ 0 ]:
2117 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08002118 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08002119 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08002120 # TODO: assert on run and withdraw results?
Jon Hall669173b2014-12-17 11:36:30 -08002121
Jon Hall6aec96b2015-01-19 14:49:31 -08002122 utilities.assert_equals(
2123 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002124 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002125 onpass="Leadership election passed",
2126 onfail="Something went wrong with Leadership election after " +
2127 "the old leader re-ran for election" )