blob: ff38cfe074e395815561fe470220da68fc457f1f [file] [log] [blame]
Jon Hall6aec96b2015-01-19 14:49:31 -08001"""
Jon Hall73cf9cc2014-11-20 22:28:38 -08002Description: This test is to determine if ONOS can handle
3 all of it's nodes restarting
4
5List of test cases:
6CASE1: Compile ONOS and push it to the test machines
7CASE2: Assign mastership to controllers
8CASE3: Assign intents
9CASE4: Ping across added host intents
10CASE5: Reading state of ONOS
11CASE6: The Failure case.
12CASE7: Check state after control plane failure
13CASE8: Compare topo
14CASE9: Link s3-s28 down
15CASE10: Link s3-s28 up
16CASE11: Switch down
17CASE12: Switch up
18CASE13: Clean up
Jon Hall669173b2014-12-17 11:36:30 -080019CASE14: start election app on all onos nodes
20CASE15: Check that Leadership Election is still functional
Jon Hall6aec96b2015-01-19 14:49:31 -080021"""
Jon Hall8f89dda2015-01-22 16:03:33 -080022
23
Jon Hall73cf9cc2014-11-20 22:28:38 -080024class HATestClusterRestart:
25
Jon Hall6aec96b2015-01-19 14:49:31 -080026 def __init__( self ):
Jon Hall73cf9cc2014-11-20 22:28:38 -080027 self.default = ''
28
Jon Hall6aec96b2015-01-19 14:49:31 -080029 def CASE1( self, main ):
30 """
Jon Hall73cf9cc2014-11-20 22:28:38 -080031 CASE1 is to compile ONOS and push it to the test machines
32
33 Startup sequence:
34 git pull
35 mvn clean install
36 onos-package
37 cell <name>
38 onos-verify-cell
39 NOTE: temporary - onos-remove-raft-logs
40 onos-install -f
41 onos-wait-for-start
Jon Hall6aec96b2015-01-19 14:49:31 -080042 """
43 main.log.report( "ONOS HA test: Restart all ONOS nodes - " +
44 "initialization" )
45 main.case( "Setting up test environment" )
46 # TODO: save all the timers and output them for plotting
Jon Hall73cf9cc2014-11-20 22:28:38 -080047
48 # load some vairables from the params file
Jon Hall8f89dda2015-01-22 16:03:33 -080049 PULLCODE = False
Jon Hall6aec96b2015-01-19 14:49:31 -080050 if main.params[ 'Git' ] == 'True':
Jon Hall8f89dda2015-01-22 16:03:33 -080051 PULLCODE = True
Jon Hall529a37f2015-01-28 10:02:00 -080052 gitBranch = main.params[ 'branch' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080053 cellName = main.params[ 'ENV' ][ 'cellName' ]
Jon Hall6aec96b2015-01-19 14:49:31 -080054
55 # set global variables
Jon Hall8f89dda2015-01-22 16:03:33 -080056 global ONOS1Ip
57 global ONOS1Port
58 global ONOS2Ip
59 global ONOS2Port
60 global ONOS3Ip
61 global ONOS3Port
62 global ONOS4Ip
63 global ONOS4Port
64 global ONOS5Ip
65 global ONOS5Port
66 global ONOS6Ip
67 global ONOS6Port
68 global ONOS7Ip
69 global ONOS7Port
70 global numControllers
Jon Hall73cf9cc2014-11-20 22:28:38 -080071
Jon Hall8f89dda2015-01-22 16:03:33 -080072 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
73 ONOS1Port = main.params[ 'CTRL' ][ 'port1' ]
74 ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
75 ONOS2Port = main.params[ 'CTRL' ][ 'port2' ]
76 ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ]
77 ONOS3Port = main.params[ 'CTRL' ][ 'port3' ]
78 ONOS4Ip = main.params[ 'CTRL' ][ 'ip4' ]
79 ONOS4Port = main.params[ 'CTRL' ][ 'port4' ]
80 ONOS5Ip = main.params[ 'CTRL' ][ 'ip5' ]
81 ONOS5Port = main.params[ 'CTRL' ][ 'port5' ]
82 ONOS6Ip = main.params[ 'CTRL' ][ 'ip6' ]
83 ONOS6Port = main.params[ 'CTRL' ][ 'port6' ]
84 ONOS7Ip = main.params[ 'CTRL' ][ 'ip7' ]
85 ONOS7Port = main.params[ 'CTRL' ][ 'port7' ]
86 numControllers = int( main.params[ 'num_controllers' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -080087
Jon Hall6aec96b2015-01-19 14:49:31 -080088 main.step( "Applying cell variable to environment" )
Jon Hall8f89dda2015-01-22 16:03:33 -080089 cellResult = main.ONOSbench.setCell( cellName )
90 verifyResult = main.ONOSbench.verifyCell()
Jon Hall73cf9cc2014-11-20 22:28:38 -080091
Jon Hall6aec96b2015-01-19 14:49:31 -080092 # FIXME:this is short term fix
93 main.log.report( "Removing raft logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -080094 main.ONOSbench.onosRemoveRaftLogs()
Jon Hall6aec96b2015-01-19 14:49:31 -080095 main.log.report( "Uninstalling ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -080096 main.ONOSbench.onosUninstall( ONOS1Ip )
97 main.ONOSbench.onosUninstall( ONOS2Ip )
98 main.ONOSbench.onosUninstall( ONOS3Ip )
99 main.ONOSbench.onosUninstall( ONOS4Ip )
100 main.ONOSbench.onosUninstall( ONOS5Ip )
101 main.ONOSbench.onosUninstall( ONOS6Ip )
102 main.ONOSbench.onosUninstall( ONOS7Ip )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800103
Jon Hall8f89dda2015-01-22 16:03:33 -0800104 cleanInstallResult = main.TRUE
105 gitPullResult = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800106
Jon Hall97f31752015-02-04 12:01:04 -0800107 main.step( "Starting Mininet" )
108 main.Mininet1.startNet( )
109
Jon Hall6aec96b2015-01-19 14:49:31 -0800110 main.step( "Compiling the latest version of ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800111 if PULLCODE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800112 # TODO Configure branch in params
113 main.step( "Git checkout and pull master" )
Jon Hall529a37f2015-01-28 10:02:00 -0800114 main.ONOSbench.gitCheckout( gitBranch )
Jon Hall8f89dda2015-01-22 16:03:33 -0800115 gitPullResult = main.ONOSbench.gitPull()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800116
Jon Hall6aec96b2015-01-19 14:49:31 -0800117 main.step( "Using mvn clean & install" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800118 cleanInstallResult = main.ONOSbench.cleanInstall()
Jon Hall6aec96b2015-01-19 14:49:31 -0800119 else:
120 main.log.warn( "Did not pull new code so skipping mvn " +
121 "clean install" )
Jon Hall1b8f54a2015-02-04 13:24:20 -0800122 main.ONOSbench.getVersion( report=True )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800123
Jon Hall6aec96b2015-01-19 14:49:31 -0800124 main.step( "Creating ONOS package" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800125 packageResult = main.ONOSbench.onosPackage()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800126
Jon Hall6aec96b2015-01-19 14:49:31 -0800127 main.step( "Installing ONOS package" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800128 onos1InstallResult = main.ONOSbench.onosInstall( options="-f",
129 node=ONOS1Ip )
130 onos2InstallResult = main.ONOSbench.onosInstall( options="-f",
131 node=ONOS2Ip )
132 onos3InstallResult = main.ONOSbench.onosInstall( options="-f",
133 node=ONOS3Ip )
134 onos4InstallResult = main.ONOSbench.onosInstall( options="-f",
135 node=ONOS4Ip )
136 onos5InstallResult = main.ONOSbench.onosInstall( options="-f",
137 node=ONOS5Ip )
138 onos6InstallResult = main.ONOSbench.onosInstall( options="-f",
139 node=ONOS6Ip )
140 onos7InstallResult = main.ONOSbench.onosInstall( options="-f",
141 node=ONOS7Ip )
142 onosInstallResult = onos1InstallResult and onos2InstallResult\
143 and onos3InstallResult and onos4InstallResult\
144 and onos5InstallResult and onos6InstallResult\
145 and onos7InstallResult
Jon Hall73cf9cc2014-11-20 22:28:38 -0800146
Jon Hall6aec96b2015-01-19 14:49:31 -0800147 main.step( "Checking if ONOS is up yet" )
148 # TODO check bundle:list?
149 for i in range( 2 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800150 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
151 if not onos1Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800152 main.log.report( "ONOS1 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800153 onos2Isup = main.ONOSbench.isup( ONOS2Ip )
154 if not onos2Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800155 main.log.report( "ONOS2 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800156 onos3Isup = main.ONOSbench.isup( ONOS3Ip )
157 if not onos3Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800158 main.log.report( "ONOS3 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800159 onos4Isup = main.ONOSbench.isup( ONOS4Ip )
160 if not onos4Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800161 main.log.report( "ONOS4 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800162 onos5Isup = main.ONOSbench.isup( ONOS5Ip )
163 if not onos5Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800164 main.log.report( "ONOS5 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800165 onos6Isup = main.ONOSbench.isup( ONOS6Ip )
166 if not onos6Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800167 main.log.report( "ONOS6 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800168 onos7Isup = main.ONOSbench.isup( ONOS7Ip )
169 if not onos7Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800170 main.log.report( "ONOS7 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800171 onosIsupResult = onos1Isup and onos2Isup and onos3Isup\
172 and onos4Isup and onos5Isup and onos6Isup and onos7Isup
173 if onosIsupResult == main.TRUE:
Jon Hall94fd0472014-12-08 11:52:42 -0800174 break
Jon Hall73cf9cc2014-11-20 22:28:38 -0800175
Jon Hall8f89dda2015-01-22 16:03:33 -0800176 cliResult1 = main.ONOScli1.startOnosCli( ONOS1Ip )
177 cliResult2 = main.ONOScli2.startOnosCli( ONOS2Ip )
178 cliResult3 = main.ONOScli3.startOnosCli( ONOS3Ip )
179 cliResult4 = main.ONOScli4.startOnosCli( ONOS4Ip )
180 cliResult5 = main.ONOScli5.startOnosCli( ONOS5Ip )
181 cliResult6 = main.ONOScli6.startOnosCli( ONOS6Ip )
182 cliResult7 = main.ONOScli7.startOnosCli( ONOS7Ip )
183 cliResults = cliResult1 and cliResult2 and cliResult3 and\
184 cliResult4 and cliResult5 and cliResult6 and cliResult7
Jon Hall73cf9cc2014-11-20 22:28:38 -0800185
Jon Hall6aec96b2015-01-19 14:49:31 -0800186 main.step( "Start Packet Capture MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800187 main.Mininet2.startTcpdump(
Jon Hall6aec96b2015-01-19 14:49:31 -0800188 str( main.params[ 'MNtcpdump' ][ 'folder' ] ) + str( main.TEST )
189 + "-MN.pcap",
190 intf=main.params[ 'MNtcpdump' ][ 'intf' ],
191 port=main.params[ 'MNtcpdump' ][ 'port' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800192
Jon Hall8f89dda2015-01-22 16:03:33 -0800193 case1Result = ( cleanInstallResult and packageResult and
194 cellResult and verifyResult and onosInstallResult
195 and onosIsupResult and cliResults )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800196
Jon Hall8f89dda2015-01-22 16:03:33 -0800197 utilities.assert_equals( expect=main.TRUE, actual=case1Result,
198 onpass="Test startup successful",
199 onfail="Test startup NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800200
Jon Hall8f89dda2015-01-22 16:03:33 -0800201 if case1Result == main.FALSE:
Jon Hall94fd0472014-12-08 11:52:42 -0800202 main.cleanup()
203 main.exit()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800204
Jon Hall6aec96b2015-01-19 14:49:31 -0800205 def CASE2( self, main ):
206 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800207 Assign mastership to controllers
Jon Hall6aec96b2015-01-19 14:49:31 -0800208 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800209 import re
210
Jon Hall6aec96b2015-01-19 14:49:31 -0800211 main.log.report( "Assigning switches to controllers" )
212 main.case( "Assigning Controllers" )
213 main.step( "Assign switches to controllers" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800214
Jon Hall6aec96b2015-01-19 14:49:31 -0800215 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800216 main.Mininet1.assignSwController(
Jon Hall6aec96b2015-01-19 14:49:31 -0800217 sw=str( i ),
Jon Hall8f89dda2015-01-22 16:03:33 -0800218 count=numControllers,
219 ip1=ONOS1Ip, port1=ONOS1Port,
220 ip2=ONOS2Ip, port2=ONOS2Port,
221 ip3=ONOS3Ip, port3=ONOS3Port,
222 ip4=ONOS4Ip, port4=ONOS4Port,
223 ip5=ONOS5Ip, port5=ONOS5Port,
224 ip6=ONOS6Ip, port6=ONOS6Port,
225 ip7=ONOS7Ip, port7=ONOS7Port )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800226
Jon Hall8f89dda2015-01-22 16:03:33 -0800227 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800228 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800229 response = main.Mininet1.getSwController( "s" + str( i ) )
Jon Hallffb386d2014-11-21 13:43:38 -0800230 try:
Jon Hall6aec96b2015-01-19 14:49:31 -0800231 main.log.info( str( response ) )
Jon Hallffb386d2014-11-21 13:43:38 -0800232 except:
Jon Hall6aec96b2015-01-19 14:49:31 -0800233 main.log.info( repr( response ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800234 if re.search( "tcp:" + ONOS1Ip, response )\
235 and re.search( "tcp:" + ONOS2Ip, response )\
236 and re.search( "tcp:" + ONOS3Ip, response )\
237 and re.search( "tcp:" + ONOS4Ip, response )\
238 and re.search( "tcp:" + ONOS5Ip, response )\
239 and re.search( "tcp:" + ONOS6Ip, response )\
240 and re.search( "tcp:" + ONOS7Ip, response ):
241 mastershipCheck = mastershipCheck and main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800242 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800243 mastershipCheck = main.FALSE
244 if mastershipCheck == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800245 main.log.report( "Switch mastership assigned correctly" )
246 utilities.assert_equals(
247 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800248 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800249 onpass="Switch mastership assigned correctly",
250 onfail="Switches not assigned correctly to controllers" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800251
Jon Hall6aec96b2015-01-19 14:49:31 -0800252 # Manually assign mastership to the controller we want
Jon Hall8f89dda2015-01-22 16:03:33 -0800253 roleCall = main.TRUE
254 roleCheck = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800255
Jon Hall6aec96b2015-01-19 14:49:31 -0800256 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800257 deviceId = main.ONOScli1.getDevice( "1000" ).get( 'id' )
258 roleCall = roleCall and main.ONOScli1.deviceRole(
259 deviceId,
260 ONOS1Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800261 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800262 if ONOS1Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
263 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800264 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800265 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800266
Jon Hall6aec96b2015-01-19 14:49:31 -0800267 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800268 deviceId = main.ONOScli1.getDevice( "2800" ).get( 'id' )
269 roleCall = roleCall and main.ONOScli1.deviceRole(
270 deviceId,
271 ONOS1Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800272 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800273 if ONOS1Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
274 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800275 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800276 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800277
Jon Hall6aec96b2015-01-19 14:49:31 -0800278 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800279 deviceId = main.ONOScli1.getDevice( "2000" ).get( 'id' )
280 roleCall = roleCall and main.ONOScli1.deviceRole(
281 deviceId,
282 ONOS2Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800283 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800284 if ONOS2Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
285 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800286 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800287 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800288
Jon Hall6aec96b2015-01-19 14:49:31 -0800289 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800290 deviceId = main.ONOScli1.getDevice( "3000" ).get( 'id' )
291 roleCall = roleCall and main.ONOScli1.deviceRole(
292 deviceId,
293 ONOS2Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800294 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800295 if ONOS2Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
296 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800297 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800298 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800299
Jon Hall6aec96b2015-01-19 14:49:31 -0800300 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800301 deviceId = main.ONOScli1.getDevice( "5000" ).get( 'id' )
302 roleCall = roleCall and main.ONOScli1.deviceRole(
303 deviceId,
304 ONOS3Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800305 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800306 if ONOS3Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
307 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800308 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800309 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800310
Jon Hall6aec96b2015-01-19 14:49:31 -0800311 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800312 deviceId = main.ONOScli1.getDevice( "6000" ).get( 'id' )
313 roleCall = roleCall and main.ONOScli1.deviceRole(
314 deviceId,
315 ONOS3Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800316 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800317 if ONOS3Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
318 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800319 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800320 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800321
Jon Hall6aec96b2015-01-19 14:49:31 -0800322 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800323 deviceId = main.ONOScli1.getDevice( "3004" ).get( 'id' )
324 roleCall = roleCall and main.ONOScli1.deviceRole(
325 deviceId,
326 ONOS4Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800327 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800328 if ONOS4Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
329 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800330 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800331 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800332
Jon Hall6aec96b2015-01-19 14:49:31 -0800333 for i in range( 8, 18 ):
334 dpid = '3' + str( i ).zfill( 3 )
Jon Hall8f89dda2015-01-22 16:03:33 -0800335 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
336 roleCall = roleCall and main.ONOScli1.deviceRole(
337 deviceId,
338 ONOS5Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800339 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800340 if ONOS5Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
341 roleCheck = roleCheck and main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800342 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800343 roleCheck = roleCheck and main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800344
Jon Hall8f89dda2015-01-22 16:03:33 -0800345 deviceId = main.ONOScli1.getDevice( "6007" ).get( 'id' )
346 roleCall = roleCall and main.ONOScli1.deviceRole(
347 deviceId,
348 ONOS6Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800349 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800350 if ONOS6Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
351 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800352 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800353 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800354
Jon Hall6aec96b2015-01-19 14:49:31 -0800355 for i in range( 18, 28 ):
356 dpid = '6' + str( i ).zfill( 3 )
Jon Hall8f89dda2015-01-22 16:03:33 -0800357 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
358 roleCall = roleCall and main.ONOScli1.deviceRole(
359 deviceId,
360 ONOS7Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800361 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800362 if ONOS7Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
363 roleCheck = roleCheck and main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800364 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800365 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800366
Jon Hall6aec96b2015-01-19 14:49:31 -0800367 utilities.assert_equals(
368 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800369 actual=roleCall,
Jon Hall6aec96b2015-01-19 14:49:31 -0800370 onpass="Re-assigned switch mastership to designated controller",
Jon Hall8f89dda2015-01-22 16:03:33 -0800371 onfail="Something wrong with deviceRole calls" )
Jon Hall94fd0472014-12-08 11:52:42 -0800372
Jon Hall6aec96b2015-01-19 14:49:31 -0800373 utilities.assert_equals(
374 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800375 actual=roleCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800376 onpass="Switches were successfully reassigned to designated " +
377 "controller",
378 onfail="Switches were not successfully reassigned" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800379 mastershipCheck = mastershipCheck and roleCall and roleCheck
380 utilities.assert_equals( expect=main.TRUE, actual=mastershipCheck,
381 onpass="Switch mastership correctly assigned",
382 onfail="Error in ( re )assigning switch" +
383 " mastership" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800384
Jon Hall6aec96b2015-01-19 14:49:31 -0800385 def CASE3( self, main ):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800386 """
387 Assign intents
Jon Hall73cf9cc2014-11-20 22:28:38 -0800388 """
Jon Hall6aec96b2015-01-19 14:49:31 -0800389 # FIXME: we must reinstall intents until we have a persistant
390 # datastore!
Jon Hall73cf9cc2014-11-20 22:28:38 -0800391 import time
Jon Hall6aec96b2015-01-19 14:49:31 -0800392 main.log.report( "Adding host intents" )
393 main.case( "Adding host Intents" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800394
Jon Hall8f89dda2015-01-22 16:03:33 -0800395 main.step( "Discovering Hosts( Via pingall for now )" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800396 # FIXME: Once we have a host discovery mechanism, use that instead
Jon Hall73cf9cc2014-11-20 22:28:38 -0800397
Jon Hall6aec96b2015-01-19 14:49:31 -0800398 # install onos-app-fwd
399 main.log.info( "Install reactive forwarding app" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800400 main.ONOScli1.featureInstall( "onos-app-fwd" )
401 main.ONOScli2.featureInstall( "onos-app-fwd" )
402 main.ONOScli3.featureInstall( "onos-app-fwd" )
403 main.ONOScli4.featureInstall( "onos-app-fwd" )
404 main.ONOScli5.featureInstall( "onos-app-fwd" )
405 main.ONOScli6.featureInstall( "onos-app-fwd" )
406 main.ONOScli7.featureInstall( "onos-app-fwd" )
Jon Hall94fd0472014-12-08 11:52:42 -0800407
Jon Hall6aec96b2015-01-19 14:49:31 -0800408 # REACTIVE FWD test
Jon Hall8f89dda2015-01-22 16:03:33 -0800409 pingResult = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800410 time1 = time.time()
Jon Hall8f89dda2015-01-22 16:03:33 -0800411 pingResult = main.Mininet1.pingall()
Jon Hall529a37f2015-01-28 10:02:00 -0800412 utilities.assert_equals(
413 expect=main.TRUE,
414 actual=pingResult,
415 onpass="Reactive Pingall test passed",
416 onfail="Reactive Pingall failed, one or more ping pairs failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800417 time2 = time.time()
Jon Hall6aec96b2015-01-19 14:49:31 -0800418 main.log.info( "Time for pingall: %2f seconds" % ( time2 - time1 ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800419
Jon Hall6aec96b2015-01-19 14:49:31 -0800420 # uninstall onos-app-fwd
421 main.log.info( "Uninstall reactive forwarding app" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800422 main.ONOScli1.featureUninstall( "onos-app-fwd" )
423 main.ONOScli2.featureUninstall( "onos-app-fwd" )
424 main.ONOScli3.featureUninstall( "onos-app-fwd" )
425 main.ONOScli4.featureUninstall( "onos-app-fwd" )
426 main.ONOScli5.featureUninstall( "onos-app-fwd" )
427 main.ONOScli6.featureUninstall( "onos-app-fwd" )
428 main.ONOScli7.featureUninstall( "onos-app-fwd" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800429 # timeout for fwd flows
430 time.sleep( 10 )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800431
Jon Hall6aec96b2015-01-19 14:49:31 -0800432 main.step( "Add host intents" )
433 # TODO: move the host numbers to params
Jon Hall8f89dda2015-01-22 16:03:33 -0800434 intentAddResult = True
Jon Hall6aec96b2015-01-19 14:49:31 -0800435 for i in range( 8, 18 ):
436 main.log.info( "Adding host intent between h" + str( i ) +
437 " and h" + str( i + 10 ) )
438 host1 = "00:00:00:00:00:" + \
439 str( hex( i )[ 2: ] ).zfill( 2 ).upper()
440 host2 = "00:00:00:00:00:" + \
441 str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper()
Jon Hall1b8f54a2015-02-04 13:24:20 -0800442 # NOTE: getHost can return None
443 host1Dict = main.ONOScli1.getHost( host1 )
444 host2Dict = main.ONOScli1.getHost( host2 )
445 host1Id = None
446 host2Id = None
447 if host1Dict and host2Dict:
448 host1Id = host1Dict.get( 'id', None )
449 host2Id = host2Dict.get( 'id', None )
Jon Hall8f89dda2015-01-22 16:03:33 -0800450 if host1Id and host2Id:
451 tmpResult = main.ONOScli1.addHostIntent(
452 host1Id,
453 host2Id )
Jon Hall669173b2014-12-17 11:36:30 -0800454 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800455 main.log.error( "Error, getHost() failed" )
Jon Hall1b8f54a2015-02-04 13:24:20 -0800456 main.log.warn( json.dumps( json.loads( main.ONOScli1.hosts() ),
457 sort_keys=True,
458 indent=4,
459 separators=( ',', ': ' ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800460 tmpResult = main.FALSE
461 intentAddResult = bool( pingResult and intentAddResult
462 and tmpResult )
Jon Hall529a37f2015-01-28 10:02:00 -0800463 # TODO Check that intents were added?
Jon Hall1b8f54a2015-02-04 13:24:20 -0800464 # Print the intent states
465 intents = main.ONOScli1.intents( )
466 intentStates = []
467 for intent in json.loads( intents ): # Iter through intents of a node
468 intentStates.append( intent.get( 'state', None ) )
469 out = [ (i, intentStates.count( i ) ) for i in set( intentStates ) ]
470 main.log.info( dict( out ) )
471
Jon Hall6aec96b2015-01-19 14:49:31 -0800472 utilities.assert_equals(
473 expect=True,
Jon Hall8f89dda2015-01-22 16:03:33 -0800474 actual=intentAddResult,
Jon Hall529a37f2015-01-28 10:02:00 -0800475 onpass="Pushed host intents to ONOS",
476 onfail="Error in pushing host intents to ONOS" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800477 # TODO Check if intents all exist in datastore
Jon Hall73cf9cc2014-11-20 22:28:38 -0800478
Jon Hall6aec96b2015-01-19 14:49:31 -0800479 def CASE4( self, main ):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800480 """
481 Ping across added host intents
482 """
483 description = " Ping across added host intents"
Jon Hall6aec96b2015-01-19 14:49:31 -0800484 main.log.report( description )
485 main.case( description )
Jon Hall8f89dda2015-01-22 16:03:33 -0800486 PingResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800487 for i in range( 8, 18 ):
488 ping = main.Mininet1.pingHost(
489 src="h" + str( i ), target="h" + str( i + 10 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800490 PingResult = PingResult and ping
Jon Hall6aec96b2015-01-19 14:49:31 -0800491 if ping == main.FALSE:
492 main.log.warn( "Ping failed between h" + str( i ) +
493 " and h" + str( i + 10 ) )
494 elif ping == main.TRUE:
495 main.log.info( "Ping test passed!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800496 PingResult = main.TRUE
497 if PingResult == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800498 main.log.report(
499 "Intents have not been installed correctly, pings failed." )
Jon Hall529a37f2015-01-28 10:02:00 -0800500 #TODO: pretty print
501 main.log.warn( "ONSO1 intents: " )
502 main.log.warn( json.dumps( json.loads( main.ONOScli1.intents() ),
503 sort_keys=True,
504 indent=4,
505 separators=( ',', ': ' ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800506 if PingResult == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800507 main.log.report(
508 "Intents have been installed correctly and verified by pings" )
509 utilities.assert_equals(
510 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800511 actual=PingResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800512 onpass="Intents have been installed correctly and pings work",
513 onfail="Intents have not been installed correctly, pings failed." )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800514
Jon Hall6aec96b2015-01-19 14:49:31 -0800515 def CASE5( self, main ):
516 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800517 Reading state of ONOS
Jon Hall6aec96b2015-01-19 14:49:31 -0800518 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800519 import json
Jon Hall6aec96b2015-01-19 14:49:31 -0800520 # assumes that sts is already in you PYTHONPATH
521 from sts.topology.teston_topology import TestONTopology
Jon Hall73cf9cc2014-11-20 22:28:38 -0800522
Jon Hall6aec96b2015-01-19 14:49:31 -0800523 main.log.report( "Setting up and gathering data for current state" )
524 main.case( "Setting up and gathering data for current state" )
525 # The general idea for this test case is to pull the state of
526 # ( intents,flows, topology,... ) from each ONOS node
527 # We can then compare them with eachother and also with past states
Jon Hall73cf9cc2014-11-20 22:28:38 -0800528
Jon Hall6aec96b2015-01-19 14:49:31 -0800529 main.step( "Get the Mastership of each switch from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800530 global mastershipState
531 mastershipState = []
Jon Hall94fd0472014-12-08 11:52:42 -0800532
Jon Hall6aec96b2015-01-19 14:49:31 -0800533 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -0800534 ONOS1MasterNotNull = main.ONOScli1.rolesNotNull()
535 ONOS2MasterNotNull = main.ONOScli2.rolesNotNull()
536 ONOS3MasterNotNull = main.ONOScli3.rolesNotNull()
537 ONOS4MasterNotNull = main.ONOScli4.rolesNotNull()
538 ONOS5MasterNotNull = main.ONOScli5.rolesNotNull()
539 ONOS6MasterNotNull = main.ONOScli6.rolesNotNull()
540 ONOS7MasterNotNull = main.ONOScli7.rolesNotNull()
541 rolesNotNull = ONOS1MasterNotNull and ONOS2MasterNotNull and\
542 ONOS3MasterNotNull and ONOS4MasterNotNull and\
543 ONOS5MasterNotNull and ONOS6MasterNotNull and\
544 ONOS7MasterNotNull
Jon Hall6aec96b2015-01-19 14:49:31 -0800545 utilities.assert_equals(
546 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800547 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -0800548 onpass="Each device has a master",
549 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -0800550
Jon Hall8f89dda2015-01-22 16:03:33 -0800551 ONOS1Mastership = main.ONOScli1.roles()
552 ONOS2Mastership = main.ONOScli2.roles()
553 ONOS3Mastership = main.ONOScli3.roles()
554 ONOS4Mastership = main.ONOScli4.roles()
555 ONOS5Mastership = main.ONOScli5.roles()
556 ONOS6Mastership = main.ONOScli6.roles()
557 ONOS7Mastership = main.ONOScli7.roles()
558 if "Error" in ONOS1Mastership or not ONOS1Mastership\
559 or "Error" in ONOS2Mastership or not ONOS2Mastership\
560 or "Error" in ONOS3Mastership or not ONOS3Mastership\
561 or "Error" in ONOS4Mastership or not ONOS4Mastership\
562 or "Error" in ONOS5Mastership or not ONOS5Mastership\
563 or "Error" in ONOS6Mastership or not ONOS6Mastership\
564 or "Error" in ONOS7Mastership or not ONOS7Mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -0800565 main.log.report( "Error in getting ONOS roles" )
566 main.log.warn(
567 "ONOS1 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800568 repr( ONOS1Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800569 main.log.warn(
570 "ONOS2 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800571 repr( ONOS2Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800572 main.log.warn(
573 "ONOS3 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800574 repr( ONOS3Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800575 main.log.warn(
576 "ONOS4 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800577 repr( ONOS4Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800578 main.log.warn(
579 "ONOS5 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800580 repr( ONOS5Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800581 main.log.warn(
582 "ONOS6 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800583 repr( ONOS6Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800584 main.log.warn(
585 "ONOS7 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800586 repr( ONOS7Mastership ) )
587 consistentMastership = main.FALSE
588 elif ONOS1Mastership == ONOS2Mastership\
589 and ONOS1Mastership == ONOS3Mastership\
590 and ONOS1Mastership == ONOS4Mastership\
591 and ONOS1Mastership == ONOS5Mastership\
592 and ONOS1Mastership == ONOS6Mastership\
593 and ONOS1Mastership == ONOS7Mastership:
594 mastershipState = ONOS1Mastership
595 consistentMastership = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800596 main.log.report(
597 "Switch roles are consistent across all ONOS nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800598 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800599 main.log.warn(
600 "ONOS1 roles: ",
601 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800602 json.loads( ONOS1Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800603 sort_keys=True,
604 indent=4,
605 separators=(
606 ',',
607 ': ' ) ) )
608 main.log.warn(
609 "ONOS2 roles: ",
610 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800611 json.loads( ONOS2Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800612 sort_keys=True,
613 indent=4,
614 separators=(
615 ',',
616 ': ' ) ) )
617 main.log.warn(
618 "ONOS3 roles: ",
619 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800620 json.loads( ONOS3Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800621 sort_keys=True,
622 indent=4,
623 separators=(
624 ',',
625 ': ' ) ) )
626 main.log.warn(
627 "ONOS4 roles: ",
628 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800629 json.loads( ONOS4Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800630 sort_keys=True,
631 indent=4,
632 separators=(
633 ',',
634 ': ' ) ) )
635 main.log.warn(
636 "ONOS5 roles: ",
637 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800638 json.loads( ONOS5Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800639 sort_keys=True,
640 indent=4,
641 separators=(
642 ',',
643 ': ' ) ) )
644 main.log.warn(
645 "ONOS6 roles: ",
646 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800647 json.loads( ONOS6Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800648 sort_keys=True,
649 indent=4,
650 separators=(
651 ',',
652 ': ' ) ) )
653 main.log.warn(
654 "ONOS7 roles: ",
655 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800656 json.loads( ONOS7Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800657 sort_keys=True,
658 indent=4,
659 separators=(
660 ',',
661 ': ' ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800662 consistentMastership = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800663 utilities.assert_equals(
664 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800665 actual=consistentMastership,
Jon Hall6aec96b2015-01-19 14:49:31 -0800666 onpass="Switch roles are consistent across all ONOS nodes",
667 onfail="ONOS nodes have different views of switch roles" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800668
Jon Hall6aec96b2015-01-19 14:49:31 -0800669 main.step( "Get the intents from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800670 global intentState
671 intentState = []
672 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
673 ONOS2Intents = main.ONOScli2.intents( jsonFormat=True )
674 ONOS3Intents = main.ONOScli3.intents( jsonFormat=True )
675 ONOS4Intents = main.ONOScli4.intents( jsonFormat=True )
676 ONOS5Intents = main.ONOScli5.intents( jsonFormat=True )
677 ONOS6Intents = main.ONOScli6.intents( jsonFormat=True )
678 ONOS7Intents = main.ONOScli7.intents( jsonFormat=True )
679 intentCheck = main.FALSE
680 if "Error" in ONOS1Intents or not ONOS1Intents\
681 or "Error" in ONOS2Intents or not ONOS2Intents\
682 or "Error" in ONOS3Intents or not ONOS3Intents\
683 or "Error" in ONOS4Intents or not ONOS4Intents\
684 or "Error" in ONOS5Intents or not ONOS5Intents\
685 or "Error" in ONOS6Intents or not ONOS6Intents\
686 or "Error" in ONOS7Intents or not ONOS7Intents:
Jon Hall6aec96b2015-01-19 14:49:31 -0800687 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800688 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
689 main.log.warn( "ONOS2 intents response: " + repr( ONOS2Intents ) )
690 main.log.warn( "ONOS3 intents response: " + repr( ONOS3Intents ) )
691 main.log.warn( "ONOS4 intents response: " + repr( ONOS4Intents ) )
692 main.log.warn( "ONOS5 intents response: " + repr( ONOS5Intents ) )
693 main.log.warn( "ONOS6 intents response: " + repr( ONOS6Intents ) )
694 main.log.warn( "ONOS7 intents response: " + repr( ONOS7Intents ) )
695 elif ONOS1Intents == ONOS2Intents\
696 and ONOS1Intents == ONOS3Intents\
697 and ONOS1Intents == ONOS4Intents\
698 and ONOS1Intents == ONOS5Intents\
699 and ONOS1Intents == ONOS6Intents\
700 and ONOS1Intents == ONOS7Intents:
701 intentState = ONOS1Intents
702 intentCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800703 main.log.report( "Intents are consistent across all ONOS nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800704 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800705 main.log.warn(
706 "ONOS1 intents: ",
707 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800708 json.loads( ONOS1Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800709 sort_keys=True,
710 indent=4,
711 separators=(
712 ',',
713 ': ' ) ) )
714 main.log.warn(
715 "ONOS2 intents: ",
716 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800717 json.loads( ONOS2Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800718 sort_keys=True,
719 indent=4,
720 separators=(
721 ',',
722 ': ' ) ) )
723 main.log.warn(
724 "ONOS3 intents: ",
725 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800726 json.loads( ONOS3Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800727 sort_keys=True,
728 indent=4,
729 separators=(
730 ',',
731 ': ' ) ) )
732 main.log.warn(
733 "ONOS4 intents: ",
734 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800735 json.loads( ONOS4Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800736 sort_keys=True,
737 indent=4,
738 separators=(
739 ',',
740 ': ' ) ) )
741 main.log.warn(
742 "ONOS5 intents: ",
743 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800744 json.loads( ONOS5Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800745 sort_keys=True,
746 indent=4,
747 separators=(
748 ',',
749 ': ' ) ) )
750 main.log.warn(
751 "ONOS6 intents: ",
752 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800753 json.loads( ONOS6Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800754 sort_keys=True,
755 indent=4,
756 separators=(
757 ',',
758 ': ' ) ) )
759 main.log.warn(
760 "ONOS7 intents: ",
761 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800762 json.loads( ONOS7Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800763 sort_keys=True,
764 indent=4,
765 separators=(
766 ',',
767 ': ' ) ) )
768 utilities.assert_equals(
769 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800770 actual=intentCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800771 onpass="Intents are consistent across all ONOS nodes",
772 onfail="ONOS nodes have different views of intents" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800773
Jon Hall6aec96b2015-01-19 14:49:31 -0800774 main.step( "Get the flows from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800775 global flowState
776 flowState = []
777 ONOS1Flows = main.ONOScli1.flows( jsonFormat=True )
778 ONOS2Flows = main.ONOScli2.flows( jsonFormat=True )
779 ONOS3Flows = main.ONOScli3.flows( jsonFormat=True )
780 ONOS4Flows = main.ONOScli4.flows( jsonFormat=True )
781 ONOS5Flows = main.ONOScli5.flows( jsonFormat=True )
782 ONOS6Flows = main.ONOScli6.flows( jsonFormat=True )
783 ONOS7Flows = main.ONOScli7.flows( jsonFormat=True )
784 ONOS1FlowsJson = json.loads( ONOS1Flows )
785 ONOS2FlowsJson = json.loads( ONOS2Flows )
786 ONOS3FlowsJson = json.loads( ONOS3Flows )
787 ONOS4FlowsJson = json.loads( ONOS4Flows )
788 ONOS5FlowsJson = json.loads( ONOS5Flows )
789 ONOS6FlowsJson = json.loads( ONOS6Flows )
790 ONOS7FlowsJson = json.loads( ONOS7Flows )
791 flowCheck = main.FALSE
792 if "Error" in ONOS1Flows or not ONOS1Flows\
793 or "Error" in ONOS2Flows or not ONOS2Flows\
794 or "Error" in ONOS3Flows or not ONOS3Flows\
795 or "Error" in ONOS4Flows or not ONOS4Flows\
796 or "Error" in ONOS5Flows or not ONOS5Flows\
797 or "Error" in ONOS6Flows or not ONOS6Flows\
798 or "Error" in ONOS7Flows or not ONOS7Flows:
Jon Hall6aec96b2015-01-19 14:49:31 -0800799 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800800 main.log.warn( "ONOS1 flows repsponse: " + ONOS1Flows )
801 main.log.warn( "ONOS2 flows repsponse: " + ONOS2Flows )
802 main.log.warn( "ONOS3 flows repsponse: " + ONOS3Flows )
803 main.log.warn( "ONOS4 flows repsponse: " + ONOS4Flows )
804 main.log.warn( "ONOS5 flows repsponse: " + ONOS5Flows )
805 main.log.warn( "ONOS6 flows repsponse: " + ONOS6Flows )
806 main.log.warn( "ONOS7 flows repsponse: " + ONOS7Flows )
807 elif len( ONOS1FlowsJson ) == len( ONOS2FlowsJson )\
808 and len( ONOS1FlowsJson ) == len( ONOS3FlowsJson )\
809 and len( ONOS1FlowsJson ) == len( ONOS4FlowsJson )\
810 and len( ONOS1FlowsJson ) == len( ONOS5FlowsJson )\
811 and len( ONOS1FlowsJson ) == len( ONOS6FlowsJson )\
812 and len( ONOS1FlowsJson ) == len( ONOS7FlowsJson ):
Jon Hall6aec96b2015-01-19 14:49:31 -0800813 # TODO: Do a better check, maybe compare flows on switches?
Jon Hall8f89dda2015-01-22 16:03:33 -0800814 flowState = ONOS1Flows
815 flowCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800816 main.log.report( "Flow count is consistent across all ONOS nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800817 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800818 main.log.warn( "ONOS1 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800819 json.dumps( ONOS1FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800820 indent=4, separators=( ',', ': ' ) ) )
821 main.log.warn( "ONOS2 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800822 json.dumps( ONOS2FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800823 indent=4, separators=( ',', ': ' ) ) )
824 main.log.warn( "ONOS3 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800825 json.dumps( ONOS3FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800826 indent=4, separators=( ',', ': ' ) ) )
827 main.log.warn( "ONOS4 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800828 json.dumps( ONOS4FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800829 indent=4, separators=( ',', ': ' ) ) )
830 main.log.warn( "ONOS5 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800831 json.dumps( ONOS5FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800832 indent=4, separators=( ',', ': ' ) ) )
833 main.log.warn( "ONOS6 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800834 json.dumps( ONOS6FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800835 indent=4, separators=( ',', ': ' ) ) )
836 main.log.warn( "ONOS7 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800837 json.dumps( ONOS7FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800838 indent=4, separators=( ',', ': ' ) ) )
839 utilities.assert_equals(
840 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800841 actual=flowCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800842 onpass="The flow count is consistent across all ONOS nodes",
843 onfail="ONOS nodes have different flow counts" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800844
Jon Hall6aec96b2015-01-19 14:49:31 -0800845 main.step( "Get the OF Table entries" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800846 global flows
Jon Hall6aec96b2015-01-19 14:49:31 -0800847 flows = []
848 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800849 flows.append( main.Mininet2.getFlowTable( 1.3, "s" + str( i ) ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800850
Jon Hall6aec96b2015-01-19 14:49:31 -0800851 # TODO: Compare switch flow tables with ONOS flow tables
Jon Hall73cf9cc2014-11-20 22:28:38 -0800852
Jon Hall6aec96b2015-01-19 14:49:31 -0800853 main.step( "Start continuous pings" )
854 main.Mininet2.pingLong(
855 src=main.params[ 'PING' ][ 'source1' ],
856 target=main.params[ 'PING' ][ 'target1' ],
857 pingTime=500 )
858 main.Mininet2.pingLong(
859 src=main.params[ 'PING' ][ 'source2' ],
860 target=main.params[ 'PING' ][ 'target2' ],
861 pingTime=500 )
862 main.Mininet2.pingLong(
863 src=main.params[ 'PING' ][ 'source3' ],
864 target=main.params[ 'PING' ][ 'target3' ],
865 pingTime=500 )
866 main.Mininet2.pingLong(
867 src=main.params[ 'PING' ][ 'source4' ],
868 target=main.params[ 'PING' ][ 'target4' ],
869 pingTime=500 )
870 main.Mininet2.pingLong(
871 src=main.params[ 'PING' ][ 'source5' ],
872 target=main.params[ 'PING' ][ 'target5' ],
873 pingTime=500 )
874 main.Mininet2.pingLong(
875 src=main.params[ 'PING' ][ 'source6' ],
876 target=main.params[ 'PING' ][ 'target6' ],
877 pingTime=500 )
878 main.Mininet2.pingLong(
879 src=main.params[ 'PING' ][ 'source7' ],
880 target=main.params[ 'PING' ][ 'target7' ],
881 pingTime=500 )
882 main.Mininet2.pingLong(
883 src=main.params[ 'PING' ][ 'source8' ],
884 target=main.params[ 'PING' ][ 'target8' ],
885 pingTime=500 )
886 main.Mininet2.pingLong(
887 src=main.params[ 'PING' ][ 'source9' ],
888 target=main.params[ 'PING' ][ 'target9' ],
889 pingTime=500 )
890 main.Mininet2.pingLong(
891 src=main.params[ 'PING' ][ 'source10' ],
892 target=main.params[ 'PING' ][ 'target10' ],
893 pingTime=500 )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800894
Jon Hall6aec96b2015-01-19 14:49:31 -0800895 main.step( "Create TestONTopology object" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800896 ctrls = []
897 count = 1
898 while True:
899 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -0800900 if ( 'ip' + str( count ) ) in main.params[ 'CTRL' ]:
901 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
902 temp = temp + ( "ONOS" + str( count ), )
903 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
904 temp = temp + \
905 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
906 ctrls.append( temp )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800907 count = count + 1
908 else:
909 break
Jon Hall6aec96b2015-01-19 14:49:31 -0800910 MNTopo = TestONTopology(
911 main.Mininet1,
912 ctrls ) # can also add Intent API info for intent operations
Jon Hall73cf9cc2014-11-20 22:28:38 -0800913
Jon Hall6aec96b2015-01-19 14:49:31 -0800914 main.step( "Collecting topology information from ONOS" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800915 devices = []
916 devices.append( main.ONOScli1.devices() )
917 devices.append( main.ONOScli2.devices() )
918 devices.append( main.ONOScli3.devices() )
919 devices.append( main.ONOScli4.devices() )
920 devices.append( main.ONOScli5.devices() )
921 devices.append( main.ONOScli6.devices() )
922 devices.append( main.ONOScli7.devices() )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800923 hosts = []
924 hosts.append( main.ONOScli1.hosts() )
925 hosts.append( main.ONOScli2.hosts() )
926 hosts.append( main.ONOScli3.hosts() )
927 hosts.append( main.ONOScli4.hosts() )
928 hosts.append( main.ONOScli5.hosts() )
929 hosts.append( main.ONOScli6.hosts() )
930 hosts.append( main.ONOScli7.hosts() )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800931 ports = []
932 ports.append( main.ONOScli1.ports() )
933 ports.append( main.ONOScli2.ports() )
934 ports.append( main.ONOScli3.ports() )
935 ports.append( main.ONOScli4.ports() )
936 ports.append( main.ONOScli5.ports() )
937 ports.append( main.ONOScli6.ports() )
938 ports.append( main.ONOScli7.ports() )
939 links = []
940 links.append( main.ONOScli1.links() )
941 links.append( main.ONOScli2.links() )
942 links.append( main.ONOScli3.links() )
943 links.append( main.ONOScli4.links() )
944 links.append( main.ONOScli5.links() )
945 links.append( main.ONOScli6.links() )
946 links.append( main.ONOScli7.links() )
Jon Hall94fd0472014-12-08 11:52:42 -0800947 clusters = []
948 clusters.append( main.ONOScli1.clusters() )
949 clusters.append( main.ONOScli2.clusters() )
950 clusters.append( main.ONOScli3.clusters() )
951 clusters.append( main.ONOScli4.clusters() )
952 clusters.append( main.ONOScli5.clusters() )
953 clusters.append( main.ONOScli6.clusters() )
954 clusters.append( main.ONOScli7.clusters() )
Jon Hall529a37f2015-01-28 10:02:00 -0800955 # Compare json objects for hosts and dataplane clusters
Jon Hall94fd0472014-12-08 11:52:42 -0800956
Jon Hall6aec96b2015-01-19 14:49:31 -0800957 # hosts
Jon Hall8f89dda2015-01-22 16:03:33 -0800958 consistentHostsResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800959 for controller in range( len( hosts ) ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800960 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -0800961 if "Error" not in hosts[ controller ]:
962 if hosts[ controller ] == hosts[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -0800963 continue
Jon Hall6aec96b2015-01-19 14:49:31 -0800964 else: # hosts not consistent
965 main.log.report( "hosts from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -0800966 controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -0800967 " is inconsistent with ONOS1" )
968 main.log.warn( repr( hosts[ controller ] ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800969 consistentHostsResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800970
971 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800972 main.log.report( "Error in getting ONOS hosts from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -0800973 controllerStr )
974 consistentHostsResult = main.FALSE
975 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -0800976 " hosts response: " +
977 repr( hosts[ controller ] ) )
978 utilities.assert_equals(
979 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800980 actual=consistentHostsResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800981 onpass="Hosts view is consistent across all ONOS nodes",
982 onfail="ONOS nodes have different views of hosts" )
Jon Hall94fd0472014-12-08 11:52:42 -0800983
Jon Hall6aec96b2015-01-19 14:49:31 -0800984 # Strongly connected clusters of devices
Jon Hall8f89dda2015-01-22 16:03:33 -0800985 consistentClustersResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800986 for controller in range( len( clusters ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -0800987 if "Error" not in clusters[ controller ]:
988 if clusters[ controller ] == clusters[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -0800989 continue
Jon Hall6aec96b2015-01-19 14:49:31 -0800990 else: # clusters not consistent
991 main.log.report( "clusters from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -0800992 controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -0800993 " is inconsistent with ONOS1" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800994 consistentClustersResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800995
996 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800997 main.log.report( "Error in getting dataplane clusters " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800998 "from ONOS" + controllerStr )
999 consistentClustersResult = main.FALSE
1000 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001001 " clusters response: " +
1002 repr( clusters[ controller ] ) )
1003 utilities.assert_equals(
1004 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001005 actual=consistentClustersResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001006 onpass="Clusters view is consistent across all ONOS nodes",
1007 onfail="ONOS nodes have different views of clusters" )
1008 # there should always only be one cluster
Jon Hall8f89dda2015-01-22 16:03:33 -08001009 numClusters = len( json.loads( clusters[ 0 ] ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001010 utilities.assert_equals(
1011 expect=1,
Jon Hall8f89dda2015-01-22 16:03:33 -08001012 actual=numClusters,
Jon Hall6aec96b2015-01-19 14:49:31 -08001013 onpass="ONOS shows 1 SCC",
1014 onfail="ONOS shows " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001015 str( numClusters ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001016 " SCCs" )
Jon Hall94fd0472014-12-08 11:52:42 -08001017
Jon Hall6aec96b2015-01-19 14:49:31 -08001018 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001019 devicesResults = main.TRUE
1020 portsResults = main.TRUE
1021 linksResults = main.TRUE
1022 for controller in range( numControllers ):
1023 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001024 if devices[ controller ] or "Error" not in devices[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001025 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -08001026 MNTopo,
1027 json.loads(
1028 devices[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001029 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001030 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001031 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001032 actual=currentDevicesResult,
1033 onpass="ONOS" + controllerStr +
1034 " Switches view is correct",
1035 onfail="ONOS" + controllerStr +
1036 " Switches view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001037
Jon Hall6aec96b2015-01-19 14:49:31 -08001038 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001039 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -08001040 MNTopo,
1041 json.loads(
1042 ports[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001043 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001044 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001045 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001046 actual=currentPortsResult,
1047 onpass="ONOS" + controllerStr +
1048 " ports view is correct",
1049 onfail="ONOS" + controllerStr +
1050 " ports view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001051
Jon Hall6aec96b2015-01-19 14:49:31 -08001052 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001053 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -08001054 MNTopo,
1055 json.loads(
1056 links[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001057 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001058 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001059 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001060 actual=currentLinksResult,
1061 onpass="ONOS" + controllerStr +
1062 " links view is correct",
1063 onfail="ONOS" + controllerStr +
1064 " links view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001065
Jon Hall8f89dda2015-01-22 16:03:33 -08001066 devicesResults = devicesResults and currentDevicesResult
1067 portsResults = portsResults and currentPortsResult
1068 linksResults = linksResults and currentLinksResult
Jon Hall73cf9cc2014-11-20 22:28:38 -08001069
Jon Hall8f89dda2015-01-22 16:03:33 -08001070 topoResult = devicesResults and portsResults and linksResults\
Jon Hall529a37f2015-01-28 10:02:00 -08001071 and consistentHostsResult and consistentClustersResult
Jon Hall8f89dda2015-01-22 16:03:33 -08001072 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
1073 onpass="Topology Check Test successful",
1074 onfail="Topology Check Test NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001075
Jon Hall8f89dda2015-01-22 16:03:33 -08001076 finalAssert = main.TRUE
1077 finalAssert = finalAssert and topoResult and flowCheck \
1078 and intentCheck and consistentMastership and rolesNotNull
1079 utilities.assert_equals( expect=main.TRUE, actual=finalAssert,
1080 onpass="State check successful",
1081 onfail="State check NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001082
Jon Hall6aec96b2015-01-19 14:49:31 -08001083 def CASE6( self, main ):
1084 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001085 The Failure case.
Jon Hall6aec96b2015-01-19 14:49:31 -08001086 """
1087 main.log.report( "Restart entire ONOS cluster" )
1088 main.log.case( "Restart entire ONOS cluster" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001089 main.ONOSbench.onosKill( ONOS1Ip )
1090 main.ONOSbench.onosKill( ONOS2Ip )
1091 main.ONOSbench.onosKill( ONOS3Ip )
1092 main.ONOSbench.onosKill( ONOS4Ip )
1093 main.ONOSbench.onosKill( ONOS5Ip )
1094 main.ONOSbench.onosKill( ONOS6Ip )
1095 main.ONOSbench.onosKill( ONOS7Ip )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001096
Jon Hall6aec96b2015-01-19 14:49:31 -08001097 main.step( "Checking if ONOS is up yet" )
Jon Hallffb386d2014-11-21 13:43:38 -08001098 count = 0
Jon Hall8f89dda2015-01-22 16:03:33 -08001099 onosIsupResult = main.FALSE
1100 while onosIsupResult == main.FALSE and count < 10:
1101 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
1102 onos2Isup = main.ONOSbench.isup( ONOS2Ip )
1103 onos3Isup = main.ONOSbench.isup( ONOS3Ip )
1104 onos4Isup = main.ONOSbench.isup( ONOS4Ip )
1105 onos5Isup = main.ONOSbench.isup( ONOS5Ip )
1106 onos6Isup = main.ONOSbench.isup( ONOS6Ip )
1107 onos7Isup = main.ONOSbench.isup( ONOS7Ip )
1108 onosIsupResult = onos1Isup and onos2Isup and onos3Isup\
1109 and onos4Isup and onos5Isup and onos6Isup and onos7Isup
Jon Hallffb386d2014-11-21 13:43:38 -08001110 count = count + 1
Jon Hall73cf9cc2014-11-20 22:28:38 -08001111 # TODO: if it becomes an issue, we can retry this step a few times
1112
Jon Hall8f89dda2015-01-22 16:03:33 -08001113 cliResult1 = main.ONOScli1.startOnosCli( ONOS1Ip )
1114 cliResult2 = main.ONOScli2.startOnosCli( ONOS2Ip )
1115 cliResult3 = main.ONOScli3.startOnosCli( ONOS3Ip )
1116 cliResult4 = main.ONOScli4.startOnosCli( ONOS4Ip )
1117 cliResult5 = main.ONOScli5.startOnosCli( ONOS5Ip )
1118 cliResult6 = main.ONOScli6.startOnosCli( ONOS6Ip )
1119 cliResult7 = main.ONOScli7.startOnosCli( ONOS7Ip )
1120 cliResults = cliResult1 and cliResult2 and cliResult3\
1121 and cliResult4 and cliResult5 and cliResult6\
1122 and cliResult7
Jon Hall73cf9cc2014-11-20 22:28:38 -08001123
Jon Hall8f89dda2015-01-22 16:03:33 -08001124 caseResults = main.TRUE and onosIsupResult and cliResults
1125 utilities.assert_equals( expect=main.TRUE, actual=caseResults,
1126 onpass="ONOS restart successful",
1127 onfail="ONOS restart NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001128
Jon Hall6aec96b2015-01-19 14:49:31 -08001129 def CASE7( self, main ):
1130 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001131 Check state after ONOS failure
Jon Hall6aec96b2015-01-19 14:49:31 -08001132 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001133 import json
Jon Hall6aec96b2015-01-19 14:49:31 -08001134 main.case( "Running ONOS Constant State Tests" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001135
Jon Hall6aec96b2015-01-19 14:49:31 -08001136 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -08001137 ONOS1MasterNotNull = main.ONOScli1.rolesNotNull()
1138 ONOS2MasterNotNull = main.ONOScli2.rolesNotNull()
1139 ONOS3MasterNotNull = main.ONOScli3.rolesNotNull()
1140 ONOS4MasterNotNull = main.ONOScli4.rolesNotNull()
1141 ONOS5MasterNotNull = main.ONOScli5.rolesNotNull()
1142 ONOS6MasterNotNull = main.ONOScli6.rolesNotNull()
1143 ONOS7MasterNotNull = main.ONOScli7.rolesNotNull()
1144 rolesNotNull = ONOS1MasterNotNull and ONOS2MasterNotNull and\
1145 ONOS3MasterNotNull and ONOS4MasterNotNull and\
1146 ONOS5MasterNotNull and ONOS6MasterNotNull and\
1147 ONOS7MasterNotNull
Jon Hall6aec96b2015-01-19 14:49:31 -08001148 utilities.assert_equals(
1149 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001150 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -08001151 onpass="Each device has a master",
1152 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -08001153
Jon Hall6aec96b2015-01-19 14:49:31 -08001154 main.step( "Check if switch roles are consistent across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001155 ONOS1Mastership = main.ONOScli1.roles()
1156 ONOS2Mastership = main.ONOScli2.roles()
1157 ONOS3Mastership = main.ONOScli3.roles()
1158 ONOS4Mastership = main.ONOScli4.roles()
1159 ONOS5Mastership = main.ONOScli5.roles()
1160 ONOS6Mastership = main.ONOScli6.roles()
1161 ONOS7Mastership = main.ONOScli7.roles()
1162 if "Error" in ONOS1Mastership or not ONOS1Mastership\
1163 or "Error" in ONOS2Mastership or not ONOS2Mastership\
1164 or "Error" in ONOS3Mastership or not ONOS3Mastership\
1165 or "Error" in ONOS4Mastership or not ONOS4Mastership\
1166 or "Error" in ONOS5Mastership or not ONOS5Mastership\
1167 or "Error" in ONOS6Mastership or not ONOS6Mastership\
1168 or "Error" in ONOS7Mastership or not ONOS7Mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -08001169 main.log.error( "Error in getting ONOS mastership" )
1170 main.log.warn( "ONOS1 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001171 repr( ONOS1Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001172 main.log.warn( "ONOS2 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001173 repr( ONOS2Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001174 main.log.warn( "ONOS3 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001175 repr( ONOS3Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001176 main.log.warn( "ONOS4 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001177 repr( ONOS4Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001178 main.log.warn( "ONOS5 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001179 repr( ONOS5Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001180 main.log.warn( "ONOS6 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001181 repr( ONOS6Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001182 main.log.warn( "ONOS7 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001183 repr( ONOS7Mastership ) )
1184 consistentMastership = main.FALSE
1185 elif ONOS1Mastership == ONOS2Mastership\
1186 and ONOS1Mastership == ONOS3Mastership\
1187 and ONOS1Mastership == ONOS4Mastership\
1188 and ONOS1Mastership == ONOS5Mastership\
1189 and ONOS1Mastership == ONOS6Mastership\
1190 and ONOS1Mastership == ONOS7Mastership:
1191 consistentMastership = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001192 main.log.report(
1193 "Switch roles are consistent across all ONOS nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001194 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001195 main.log.warn( "ONOS1 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001196 json.loads( ONOS1Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001197 separators=( ',', ': ' ) ) )
1198 main.log.warn( "ONOS2 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001199 json.loads( ONOS2Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001200 separators=( ',', ': ' ) ) )
1201 main.log.warn( "ONOS3 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001202 json.loads( ONOS3Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001203 separators=( ',', ': ' ) ) )
1204 main.log.warn( "ONOS4 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001205 json.loads( ONOS4Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001206 separators=( ',', ': ' ) ) )
1207 main.log.warn( "ONOS5 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001208 json.loads( ONOS5Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001209 separators=( ',', ': ' ) ) )
1210 main.log.warn( "ONOS6 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001211 json.loads( ONOS6Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001212 separators=( ',', ': ' ) ) )
1213 main.log.warn( "ONOS7 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001214 json.loads( ONOS7Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001215 separators=( ',', ': ' ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001216 consistentMastership = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001217 utilities.assert_equals(
1218 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001219 actual=consistentMastership,
Jon Hall6aec96b2015-01-19 14:49:31 -08001220 onpass="Switch roles are consistent across all ONOS nodes",
1221 onfail="ONOS nodes have different views of switch roles" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001222
1223 description2 = "Compare switch roles from before failure"
Jon Hall6aec96b2015-01-19 14:49:31 -08001224 main.step( description2 )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001225
Jon Hall8f89dda2015-01-22 16:03:33 -08001226 currentJson = json.loads( ONOS1Mastership )
1227 oldJson = json.loads( mastershipState )
1228 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001229 for i in range( 1, 29 ):
1230 switchDPID = str(
1231 main.Mininet1.getSwitchDPID(
1232 switch="s" +
1233 str( i ) ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001234
Jon Hall8f89dda2015-01-22 16:03:33 -08001235 current = [ switch[ 'master' ] for switch in currentJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001236 if switchDPID in switch[ 'id' ] ]
Jon Hall8f89dda2015-01-22 16:03:33 -08001237 old = [ switch[ 'master' ] for switch in oldJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001238 if switchDPID in switch[ 'id' ] ]
Jon Hall73cf9cc2014-11-20 22:28:38 -08001239 if current == old:
Jon Hall8f89dda2015-01-22 16:03:33 -08001240 mastershipCheck = mastershipCheck and main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001241 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001242 main.log.warn( "Mastership of switch %s changed" % switchDPID )
Jon Hall8f89dda2015-01-22 16:03:33 -08001243 mastershipCheck = main.FALSE
1244 if mastershipCheck == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001245 main.log.report( "Mastership of Switches was not changed" )
1246 utilities.assert_equals(
1247 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001248 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -08001249 onpass="Mastership of Switches was not changed",
1250 onfail="Mastership of some switches changed" )
1251 # NOTE: we expect mastership to change on controller failure
Jon Hall8f89dda2015-01-22 16:03:33 -08001252 mastershipCheck = mastershipCheck and consistentMastership
Jon Hall73cf9cc2014-11-20 22:28:38 -08001253
Jon Hall6aec96b2015-01-19 14:49:31 -08001254 main.step( "Get the intents and compare across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001255 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
1256 ONOS2Intents = main.ONOScli2.intents( jsonFormat=True )
1257 ONOS3Intents = main.ONOScli3.intents( jsonFormat=True )
1258 ONOS4Intents = main.ONOScli4.intents( jsonFormat=True )
1259 ONOS5Intents = main.ONOScli5.intents( jsonFormat=True )
1260 ONOS6Intents = main.ONOScli6.intents( jsonFormat=True )
1261 ONOS7Intents = main.ONOScli7.intents( jsonFormat=True )
1262 intentCheck = main.FALSE
1263 if "Error" in ONOS1Intents or not ONOS1Intents\
1264 or "Error" in ONOS2Intents or not ONOS2Intents\
1265 or "Error" in ONOS3Intents or not ONOS3Intents\
1266 or "Error" in ONOS4Intents or not ONOS4Intents\
1267 or "Error" in ONOS5Intents or not ONOS5Intents\
1268 or "Error" in ONOS6Intents or not ONOS6Intents\
1269 or "Error" in ONOS7Intents or not ONOS7Intents:
Jon Hall6aec96b2015-01-19 14:49:31 -08001270 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001271 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
1272 main.log.warn( "ONOS2 intents response: " + repr( ONOS2Intents ) )
1273 main.log.warn( "ONOS3 intents response: " + repr( ONOS3Intents ) )
1274 main.log.warn( "ONOS4 intents response: " + repr( ONOS4Intents ) )
1275 main.log.warn( "ONOS5 intents response: " + repr( ONOS5Intents ) )
1276 main.log.warn( "ONOS6 intents response: " + repr( ONOS6Intents ) )
1277 main.log.warn( "ONOS7 intents response: " + repr( ONOS7Intents ) )
1278 elif ONOS1Intents == ONOS2Intents\
1279 and ONOS1Intents == ONOS3Intents\
1280 and ONOS1Intents == ONOS4Intents\
1281 and ONOS1Intents == ONOS5Intents\
1282 and ONOS1Intents == ONOS6Intents\
1283 and ONOS1Intents == ONOS7Intents:
1284 intentCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001285 main.log.report( "Intents are consistent across all ONOS nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001286 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001287 main.log.warn( "ONOS1 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001288 print json.dumps( json.loads( ONOS1Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001289 indent=4, separators=( ',', ': ' ) )
1290 main.log.warn( "ONOS2 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001291 print json.dumps( json.loads( ONOS2Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001292 indent=4, separators=( ',', ': ' ) )
1293 main.log.warn( "ONOS3 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001294 print json.dumps( json.loads( ONOS3Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001295 indent=4, separators=( ',', ': ' ) )
1296 main.log.warn( "ONOS4 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001297 print json.dumps( json.loads( ONOS4Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001298 indent=4, separators=( ',', ': ' ) )
1299 main.log.warn( "ONOS5 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001300 print json.dumps( json.loads( ONOS5Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001301 indent=4, separators=( ',', ': ' ) )
1302 main.log.warn( "ONOS6 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001303 print json.dumps( json.loads( ONOS6Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001304 indent=4, separators=( ',', ': ' ) )
1305 main.log.warn( "ONOS7 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001306 print json.dumps( json.loads( ONOS7Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001307 indent=4, separators=( ',', ': ' ) )
1308 utilities.assert_equals(
1309 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001310 actual=intentCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -08001311 onpass="Intents are consistent across all ONOS nodes",
1312 onfail="ONOS nodes have different views of intents" )
Jon Hall1b8f54a2015-02-04 13:24:20 -08001313 # Print the intent states
1314 intents = []
1315 intents.append( ONOS1Intents )
1316 intents.append( ONOS2Intents )
1317 intents.append( ONOS3Intents )
1318 intents.append( ONOS4Intents )
1319 intents.append( ONOS5Intents )
1320 intents.append( ONOS6Intents )
1321 intents.append( ONOS7Intents )
1322 intentStates = []
1323 for node in intents: # Iter through ONOS nodes
1324 nodeStates = []
1325 for intent in json.loads( node ): # Iter through intents of a node
1326 nodeStates.append( intent[ 'state' ] )
1327 intentStates.append( nodeStates )
1328 out = [ (i, nodeStates.count( i ) ) for i in set( nodeStates ) ]
1329 main.log.info( dict( out ) )
1330
Jon Hall73cf9cc2014-11-20 22:28:38 -08001331
Jon Hall6aec96b2015-01-19 14:49:31 -08001332 # NOTE: Hazelcast has no durability, so intents are lost across system
1333 # restarts
1334 """
1335 main.step( "Compare current intents with intents before the failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001336 # NOTE: this requires case 5 to pass for intentState to be set.
Jon Hall94fd0472014-12-08 11:52:42 -08001337 # maybe we should stop the test if that fails?
Jon Hall1b8f54a2015-02-04 13:24:20 -08001338 sameIntents = main.TRUE
1339 if intentState and intentState == ONOS1Intents:
Jon Hall8f89dda2015-01-22 16:03:33 -08001340 sameIntents = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001341 main.log.report( "Intents are consistent with before failure" )
1342 # TODO: possibly the states have changed? we may need to figure out
1343 # what the aceptable states are
Jon Hall73cf9cc2014-11-20 22:28:38 -08001344 else:
Jon Hall669173b2014-12-17 11:36:30 -08001345 try:
Jon Hall6aec96b2015-01-19 14:49:31 -08001346 main.log.warn( "ONOS1 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001347 print json.dumps( json.loads( ONOS1Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -08001348 sort_keys=True, indent=4,
1349 separators=( ',', ': ' ) )
Jon Hall669173b2014-12-17 11:36:30 -08001350 except:
1351 pass
Jon Hall8f89dda2015-01-22 16:03:33 -08001352 sameIntents = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001353 utilities.assert_equals(
1354 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001355 actual=sameIntents,
Jon Hall6aec96b2015-01-19 14:49:31 -08001356 onpass="Intents are consistent with before failure",
1357 onfail="The Intents changed during failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001358 intentCheck = intentCheck and sameIntents
Jon Hall6aec96b2015-01-19 14:49:31 -08001359 """
1360 main.step( "Get the OF Table entries and compare to before " +
1361 "component failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001362 FlowTables = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001363 flows2 = []
1364 for i in range( 28 ):
1365 main.log.info( "Checking flow table on s" + str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001366 tmpFlows = main.Mininet2.getFlowTable( 1.3, "s" + str( i + 1 ) )
1367 flows2.append( tmpFlows )
1368 tempResult = main.Mininet2.flowComp(
Jon Hall6aec96b2015-01-19 14:49:31 -08001369 flow1=flows[ i ],
Jon Hall8f89dda2015-01-22 16:03:33 -08001370 flow2=tmpFlows )
1371 FlowTables = FlowTables and tempResult
1372 if FlowTables == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001373 main.log.info( "Differences in flow table for switch: s" +
1374 str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001375 if FlowTables == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001376 main.log.report( "No changes were found in the flow tables" )
1377 utilities.assert_equals(
1378 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001379 actual=FlowTables,
Jon Hall6aec96b2015-01-19 14:49:31 -08001380 onpass="No changes were found in the flow tables",
1381 onfail="Changes were found in the flow tables" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001382
Jon Hall6aec96b2015-01-19 14:49:31 -08001383 main.step( "Check the continuous pings to ensure that no packets " +
1384 "were dropped during component failure" )
1385 # FIXME: This check is always failing. Investigate cause
1386 # NOTE: this may be something to do with file permsissions
Jon Hall73cf9cc2014-11-20 22:28:38 -08001387 # or slight change in format
Jon Hall6aec96b2015-01-19 14:49:31 -08001388 main.Mininet2.pingKill(
1389 main.params[ 'TESTONUSER' ],
1390 main.params[ 'TESTONIP' ] )
Jon Hall8f89dda2015-01-22 16:03:33 -08001391 LossInPings = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001392 # NOTE: checkForLoss returns main.FALSE with 0% packet loss
1393 for i in range( 8, 18 ):
1394 main.log.info(
1395 "Checking for a loss in pings along flow from s" +
1396 str( i ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001397 LossInPings = main.Mininet2.checkForLoss(
Jon Hall6aec96b2015-01-19 14:49:31 -08001398 "/tmp/ping.h" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001399 str( i ) ) or LossInPings
1400 if LossInPings == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001401 main.log.info( "Loss in ping detected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001402 elif LossInPings == main.ERROR:
Jon Hall6aec96b2015-01-19 14:49:31 -08001403 main.log.info( "There are multiple mininet process running" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001404 elif LossInPings == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001405 main.log.info( "No Loss in the pings" )
1406 main.log.report( "No loss of dataplane connectivity" )
1407 utilities.assert_equals(
1408 expect=main.FALSE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001409 actual=LossInPings,
Jon Hall6aec96b2015-01-19 14:49:31 -08001410 onpass="No Loss of connectivity",
1411 onfail="Loss of dataplane connectivity detected" )
1412 # NOTE: Since intents are not persisted with Hazelcast, we expect this
Jon Hall8f89dda2015-01-22 16:03:33 -08001413 LossInPings = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001414
Jon Hall6aec96b2015-01-19 14:49:31 -08001415 # Test of LeadershipElection
Jon Hall8f89dda2015-01-22 16:03:33 -08001416 leaderList = []
1417 leaderResult = main.TRUE
1418 for controller in range( 1, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001419 # loop through ONOScli handlers
1420 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001421 leaderN = node.electionTestLeader()
1422 leaderList.append( leaderN )
Jon Hall669173b2014-12-17 11:36:30 -08001423 if leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001424 # error in response
1425 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001426 "electionTestLeader function, check the" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001427 " error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001428 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001429 elif leaderN is None:
1430 main.log.report( "ONOS" + str( controller ) +
1431 " shows no leader for the election-app was" +
1432 " elected after the old one died" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001433 leaderResult = main.FALSE
1434 if len( set( leaderList ) ) != 1:
1435 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001436 main.log.error(
1437 "Inconsistent view of leader for the election test app" )
1438 # TODO: print the list
Jon Hall8f89dda2015-01-22 16:03:33 -08001439 if leaderResult:
1440 main.log.report( "Leadership election tests passed( consistent " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001441 "view of leader across listeners and a new " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001442 "leader was re-elected if applicable )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001443 utilities.assert_equals(
1444 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001445 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001446 onpass="Leadership election passed",
1447 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08001448
Jon Hall8f89dda2015-01-22 16:03:33 -08001449 result = ( mastershipCheck and intentCheck and FlowTables and
1450 ( not LossInPings ) and rolesNotNull and leaderResult )
Jon Hall6aec96b2015-01-19 14:49:31 -08001451 result = int( result )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001452 if result == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001453 main.log.report( "Constant State Tests Passed" )
1454 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall8f89dda2015-01-22 16:03:33 -08001455 onpass="Constant State Tests Passed",
1456 onfail="Constant state tests failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001457
Jon Hall6aec96b2015-01-19 14:49:31 -08001458 def CASE8( self, main ):
1459 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001460 Compare topo
Jon Hall6aec96b2015-01-19 14:49:31 -08001461 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001462 import sys
Jon Hall6aec96b2015-01-19 14:49:31 -08001463 # FIXME add this path to params
1464 sys.path.append( "/home/admin/sts" )
1465 # assumes that sts is already in you PYTHONPATH
1466 from sts.topology.teston_topology import TestONTopology
Jon Hall73cf9cc2014-11-20 22:28:38 -08001467 import json
1468 import time
1469
Jon Hall6aec96b2015-01-19 14:49:31 -08001470 description = "Compare ONOS Topology view to Mininet topology"
1471 main.case( description )
1472 main.log.report( description )
1473 main.step( "Create TestONTopology object" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001474 ctrls = []
1475 count = 1
1476 while True:
1477 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -08001478 if ( 'ip' + str( count ) ) in main.params[ 'CTRL' ]:
1479 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
1480 temp = temp + ( "ONOS" + str( count ), )
1481 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
1482 temp = temp + \
1483 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
1484 ctrls.append( temp )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001485 count = count + 1
1486 else:
1487 break
Jon Hall6aec96b2015-01-19 14:49:31 -08001488 MNTopo = TestONTopology(
1489 main.Mininet1,
1490 ctrls ) # can also add Intent API info for intent operations
Jon Hall73cf9cc2014-11-20 22:28:38 -08001491
Jon Hall6aec96b2015-01-19 14:49:31 -08001492 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001493 devicesResults = main.TRUE
1494 portsResults = main.TRUE
1495 linksResults = main.TRUE
1496 topoResult = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001497 elapsed = 0
Jon Hallffb386d2014-11-21 13:43:38 -08001498 count = 0
Jon Hall6aec96b2015-01-19 14:49:31 -08001499 main.step( "Collecting topology information from ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001500 startTime = time.time()
1501 while topoResult == main.FALSE and elapsed < 60:
Jon Hallffb386d2014-11-21 13:43:38 -08001502 count = count + 1
Jon Hall94fd0472014-12-08 11:52:42 -08001503 if count > 1:
Jon Hall6aec96b2015-01-19 14:49:31 -08001504 # TODO: Depricate STS usage
1505 MNTopo = TestONTopology(
1506 main.Mininet1,
1507 ctrls )
Jon Hall8f89dda2015-01-22 16:03:33 -08001508 cliStart = time.time()
Jon Hall94fd0472014-12-08 11:52:42 -08001509 devices = []
1510 devices.append( main.ONOScli1.devices() )
1511 devices.append( main.ONOScli2.devices() )
1512 devices.append( main.ONOScli3.devices() )
1513 devices.append( main.ONOScli4.devices() )
1514 devices.append( main.ONOScli5.devices() )
1515 devices.append( main.ONOScli6.devices() )
1516 devices.append( main.ONOScli7.devices() )
1517 hosts = []
Jon Hall529a37f2015-01-28 10:02:00 -08001518 hosts.append( json.loads( main.ONOScli1.hosts() ) )
1519 hosts.append( json.loads( main.ONOScli2.hosts() ) )
1520 hosts.append( json.loads( main.ONOScli3.hosts() ) )
1521 hosts.append( json.loads( main.ONOScli4.hosts() ) )
1522 hosts.append( json.loads( main.ONOScli5.hosts() ) )
1523 hosts.append( json.loads( main.ONOScli6.hosts() ) )
1524 hosts.append( json.loads( main.ONOScli7.hosts() ) )
1525 for controller in range( 0, len( hosts ) ):
1526 controllerStr = str( controller + 1 )
1527 for host in hosts[ controller ]:
Jon Hall529a37f2015-01-28 10:02:00 -08001528 if host[ 'ips' ] == []:
1529 main.log.error(
1530 "DEBUG:Error with host ips on controller" +
1531 controllerStr + ": " + str( host ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001532 ports = []
1533 ports.append( main.ONOScli1.ports() )
1534 ports.append( main.ONOScli2.ports() )
1535 ports.append( main.ONOScli3.ports() )
1536 ports.append( main.ONOScli4.ports() )
1537 ports.append( main.ONOScli5.ports() )
1538 ports.append( main.ONOScli6.ports() )
1539 ports.append( main.ONOScli7.ports() )
1540 links = []
1541 links.append( main.ONOScli1.links() )
1542 links.append( main.ONOScli2.links() )
1543 links.append( main.ONOScli3.links() )
1544 links.append( main.ONOScli4.links() )
1545 links.append( main.ONOScli5.links() )
1546 links.append( main.ONOScli6.links() )
1547 links.append( main.ONOScli7.links() )
1548 clusters = []
1549 clusters.append( main.ONOScli1.clusters() )
1550 clusters.append( main.ONOScli2.clusters() )
1551 clusters.append( main.ONOScli3.clusters() )
1552 clusters.append( main.ONOScli4.clusters() )
1553 clusters.append( main.ONOScli5.clusters() )
1554 clusters.append( main.ONOScli6.clusters() )
1555 clusters.append( main.ONOScli7.clusters() )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001556
Jon Hall8f89dda2015-01-22 16:03:33 -08001557 elapsed = time.time() - startTime
1558 cliTime = time.time() - cliStart
1559 print "CLI time: " + str( cliTime )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001560
Jon Hall8f89dda2015-01-22 16:03:33 -08001561 for controller in range( numControllers ):
1562 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001563 if devices[ controller ] or "Error" not in devices[
1564 controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001565 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -08001566 MNTopo,
1567 json.loads(
1568 devices[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001569 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001570 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001571 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001572 actual=currentDevicesResult,
1573 onpass="ONOS" + controllerStr +
1574 " Switches view is correct",
1575 onfail="ONOS" + controllerStr +
1576 " Switches view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001577
Jon Hall6aec96b2015-01-19 14:49:31 -08001578 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001579 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -08001580 MNTopo,
1581 json.loads(
1582 ports[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001583 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001584 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001585 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001586 actual=currentPortsResult,
1587 onpass="ONOS" + controllerStr +
1588 " ports view is correct",
1589 onfail="ONOS" + controllerStr +
1590 " ports view is incorrect" )
Jon Hall94fd0472014-12-08 11:52:42 -08001591
Jon Hall6aec96b2015-01-19 14:49:31 -08001592 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001593 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -08001594 MNTopo,
1595 json.loads(
1596 links[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001597 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001598 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001599 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001600 actual=currentLinksResult,
1601 onpass="ONOS" + controllerStr +
1602 " links view is correct",
1603 onfail="ONOS" + controllerStr +
1604 " links view is incorrect" )
1605 devicesResults = devicesResults and currentDevicesResult
1606 portsResults = portsResults and currentPortsResult
1607 linksResults = linksResults and currentLinksResult
Jon Hall94fd0472014-12-08 11:52:42 -08001608
Jon Hall529a37f2015-01-28 10:02:00 -08001609 # Compare json objects for hosts and dataplane clusters
Jon Hall94fd0472014-12-08 11:52:42 -08001610
Jon Hall6aec96b2015-01-19 14:49:31 -08001611 # hosts
Jon Hall8f89dda2015-01-22 16:03:33 -08001612 consistentHostsResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -08001613 for controller in range( len( hosts ) ):
Jon Hall8f89dda2015-01-22 16:03:33 -08001614 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001615 if "Error" not in hosts[ controller ]:
1616 if hosts[ controller ] == hosts[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001617 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001618 else: # hosts not consistent
Jon Hall8f89dda2015-01-22 16:03:33 -08001619 main.log.report( "hosts from ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001620 " is inconsistent with ONOS1" )
1621 main.log.warn( repr( hosts[ controller ] ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001622 consistentHostsResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001623
1624 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001625 main.log.report( "Error in getting ONOS hosts from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001626 controllerStr )
1627 consistentHostsResult = main.FALSE
1628 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001629 " hosts response: " +
1630 repr( hosts[ controller ] ) )
1631 utilities.assert_equals(
1632 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001633 actual=consistentHostsResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001634 onpass="Hosts view is consistent across all ONOS nodes",
1635 onfail="ONOS nodes have different views of hosts" )
Jon Hall94fd0472014-12-08 11:52:42 -08001636
Jon Hall6aec96b2015-01-19 14:49:31 -08001637 # Strongly connected clusters of devices
Jon Hall8f89dda2015-01-22 16:03:33 -08001638 consistentClustersResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -08001639 for controller in range( len( clusters ) ):
Jon Hall8f89dda2015-01-22 16:03:33 -08001640 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001641 if "Error" not in clusters[ controller ]:
1642 if clusters[ controller ] == clusters[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001643 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001644 else: # clusters not consistent
1645 main.log.report( "clusters from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001646 controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001647 " is inconsistent with ONOS1" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001648 consistentClustersResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001649
1650 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001651 main.log.report( "Error in getting dataplane clusters " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001652 "from ONOS" + controllerStr )
1653 consistentClustersResult = main.FALSE
1654 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001655 " clusters response: " +
1656 repr( clusters[ controller ] ) )
1657 utilities.assert_equals(
1658 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001659 actual=consistentClustersResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001660 onpass="Clusters view is consistent across all ONOS nodes",
1661 onfail="ONOS nodes have different views of clusters" )
1662 # there should always only be one cluster
Jon Hall8f89dda2015-01-22 16:03:33 -08001663 numClusters = len( json.loads( clusters[ 0 ] ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001664 utilities.assert_equals(
1665 expect=1,
Jon Hall8f89dda2015-01-22 16:03:33 -08001666 actual=numClusters,
Jon Hall6aec96b2015-01-19 14:49:31 -08001667 onpass="ONOS shows 1 SCC",
1668 onfail="ONOS shows " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001669 str( numClusters ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001670 " SCCs" )
Jon Hall94fd0472014-12-08 11:52:42 -08001671
Jon Hall8f89dda2015-01-22 16:03:33 -08001672 topoResult = ( devicesResults and portsResults and linksResults
1673 and consistentHostsResult
Jon Hall529a37f2015-01-28 10:02:00 -08001674 and consistentClustersResult )
Jon Hall94fd0472014-12-08 11:52:42 -08001675
Jon Hall8f89dda2015-01-22 16:03:33 -08001676 topoResult = topoResult and int( count <= 2 )
1677 note = "note it takes about " + str( int( cliTime ) ) + \
1678 " seconds for the test to make all the cli calls to fetch " +\
1679 "the topology from each ONOS instance"
Jon Hall1b8f54a2015-02-04 13:24:20 -08001680 main.log.info(
Jon Hall8f89dda2015-01-22 16:03:33 -08001681 "Very crass estimate for topology discovery/convergence( " +
1682 str( note ) + " ): " + str( elapsed ) + " seconds, " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001683 str( count ) + " tries" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001684 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
1685 onpass="Topology Check Test successful",
1686 onfail="Topology Check Test NOT successful" )
1687 if topoResult == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001688 main.log.report( "ONOS topology view matches Mininet topology" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001689
Jon Hall6aec96b2015-01-19 14:49:31 -08001690 def CASE9( self, main ):
1691 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001692 Link s3-s28 down
Jon Hall6aec96b2015-01-19 14:49:31 -08001693 """
1694 import time
1695 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001696
Jon Hall8f89dda2015-01-22 16:03:33 -08001697 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001698
Jon Hall6aec96b2015-01-19 14:49:31 -08001699 description = "Turn off a link to ensure that Link Discovery " +\
Jon Hall8f89dda2015-01-22 16:03:33 -08001700 "is working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001701 main.log.report( description )
1702 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001703
Jon Hall6aec96b2015-01-19 14:49:31 -08001704 main.step( "Kill Link between s3 and s28" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001705 LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001706 main.log.info(
1707 "Waiting " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001708 str( linkSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001709 " seconds for link down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001710 time.sleep( linkSleep )
1711 utilities.assert_equals( expect=main.TRUE, actual=LinkDown,
1712 onpass="Link down succesful",
1713 onfail="Failed to bring link down" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001714 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -08001715
Jon Hall6aec96b2015-01-19 14:49:31 -08001716 def CASE10( self, main ):
1717 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001718 Link s3-s28 up
Jon Hall6aec96b2015-01-19 14:49:31 -08001719 """
1720 import time
1721 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001722
Jon Hall8f89dda2015-01-22 16:03:33 -08001723 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001724
Jon Hall6aec96b2015-01-19 14:49:31 -08001725 description = "Restore a link to ensure that Link Discovery is " + \
Jon Hall8f89dda2015-01-22 16:03:33 -08001726 "working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001727 main.log.report( description )
1728 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001729
Jon Hall6aec96b2015-01-19 14:49:31 -08001730 main.step( "Bring link between s3 and s28 back up" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001731 LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001732 main.log.info(
1733 "Waiting " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001734 str( linkSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001735 " seconds for link up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001736 time.sleep( linkSleep )
1737 utilities.assert_equals( expect=main.TRUE, actual=LinkUp,
1738 onpass="Link up succesful",
1739 onfail="Failed to bring link up" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001740 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -08001741
Jon Hall6aec96b2015-01-19 14:49:31 -08001742 def CASE11( self, main ):
1743 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001744 Switch Down
Jon Hall6aec96b2015-01-19 14:49:31 -08001745 """
1746 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001747 import time
1748
Jon Hall8f89dda2015-01-22 16:03:33 -08001749 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001750
1751 description = "Killing a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001752 main.log.report( description )
1753 main.case( description )
1754 switch = main.params[ 'kill' ][ 'switch' ]
1755 switchDPID = main.params[ 'kill' ][ 'dpid' ]
Jon Hall73cf9cc2014-11-20 22:28:38 -08001756
Jon Hall6aec96b2015-01-19 14:49:31 -08001757 # TODO: Make this switch parameterizable
1758 main.step( "Kill " + switch )
1759 main.log.report( "Deleting " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001760 main.Mininet1.delSwitch( switch )
1761 main.log.info( "Waiting " + str( switchSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001762 " seconds for switch down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001763 time.sleep( switchSleep )
1764 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001765 # Peek at the deleted switch
1766 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001767 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001768 if device and device[ 'available' ] is False:
Jon Hall94fd0472014-12-08 11:52:42 -08001769 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001770 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall8f89dda2015-01-22 16:03:33 -08001771 onpass="Kill switch succesful",
1772 onfail="Failed to kill switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001773
Jon Hall6aec96b2015-01-19 14:49:31 -08001774 def CASE12( self, main ):
1775 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001776 Switch Up
Jon Hall6aec96b2015-01-19 14:49:31 -08001777 """
1778 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001779 import time
Jon Hall669173b2014-12-17 11:36:30 -08001780
Jon Hall8f89dda2015-01-22 16:03:33 -08001781 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall6aec96b2015-01-19 14:49:31 -08001782 switch = main.params[ 'kill' ][ 'switch' ]
1783 switchDPID = main.params[ 'kill' ][ 'dpid' ]
1784 links = main.params[ 'kill' ][ 'links' ].split()
Jon Hall73cf9cc2014-11-20 22:28:38 -08001785 description = "Adding a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001786 main.log.report( description )
1787 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001788
Jon Hall6aec96b2015-01-19 14:49:31 -08001789 main.step( "Add back " + switch )
1790 main.log.report( "Adding back " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001791 main.Mininet1.addSwitch( switch, dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001792 # TODO: New dpid or same? Ask Thomas?
1793 for peer in links:
Jon Hall8f89dda2015-01-22 16:03:33 -08001794 main.Mininet1.addLink( switch, peer )
1795 main.Mininet1.assignSwController(
Jon Hall6aec96b2015-01-19 14:49:31 -08001796 sw=switch.split( 's' )[ 1 ],
Jon Hall8f89dda2015-01-22 16:03:33 -08001797 count=numControllers,
1798 ip1=ONOS1Ip,
1799 port1=ONOS1Port,
1800 ip2=ONOS2Ip,
1801 port2=ONOS2Port,
1802 ip3=ONOS3Ip,
1803 port3=ONOS3Port,
1804 ip4=ONOS4Ip,
1805 port4=ONOS4Port,
1806 ip5=ONOS5Ip,
1807 port5=ONOS5Port,
1808 ip6=ONOS6Ip,
1809 port6=ONOS6Port,
1810 ip7=ONOS7Ip,
1811 port7=ONOS7Port )
Jon Hall6aec96b2015-01-19 14:49:31 -08001812 main.log.info(
1813 "Waiting " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001814 str( switchSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001815 " seconds for switch up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001816 time.sleep( switchSleep )
1817 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001818 # Peek at the deleted switch
1819 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001820 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001821 if device and device[ 'available' ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001822 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001823 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall8f89dda2015-01-22 16:03:33 -08001824 onpass="add switch succesful",
1825 onfail="Failed to add switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001826
Jon Hall6aec96b2015-01-19 14:49:31 -08001827 def CASE13( self, main ):
1828 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001829 Clean up
Jon Hall6aec96b2015-01-19 14:49:31 -08001830 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001831 import os
1832 import time
Jon Hall6aec96b2015-01-19 14:49:31 -08001833 # TODO: make use of this elsewhere
1834 ips = []
Jon Hall8f89dda2015-01-22 16:03:33 -08001835 ips.append( ONOS1Ip )
1836 ips.append( ONOS2Ip )
1837 ips.append( ONOS3Ip )
1838 ips.append( ONOS4Ip )
1839 ips.append( ONOS5Ip )
1840 ips.append( ONOS6Ip )
1841 ips.append( ONOS7Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -08001842
1843 # printing colors to terminal
Jon Hall669173b2014-12-17 11:36:30 -08001844 colors = {}
Jon Hall6aec96b2015-01-19 14:49:31 -08001845 colors[ 'cyan' ] = '\033[96m'
1846 colors[ 'purple' ] = '\033[95m'
1847 colors[ 'blue' ] = '\033[94m'
1848 colors[ 'green' ] = '\033[92m'
1849 colors[ 'yellow' ] = '\033[93m'
1850 colors[ 'red' ] = '\033[91m'
1851 colors[ 'end' ] = '\033[0m'
Jon Hall73cf9cc2014-11-20 22:28:38 -08001852 description = "Test Cleanup"
Jon Hall6aec96b2015-01-19 14:49:31 -08001853 main.log.report( description )
1854 main.case( description )
1855 main.step( "Killing tcpdumps" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001856 main.Mininet2.stopTcpdump()
Jon Hall73cf9cc2014-11-20 22:28:38 -08001857
Jon Hall6aec96b2015-01-19 14:49:31 -08001858 main.step( "Checking ONOS Logs for errors" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001859 for i in range( 7 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001860 print colors[ 'purple' ] + "Checking logs for errors on " + \
Jon Hall8f89dda2015-01-22 16:03:33 -08001861 "ONOS" + str( i + 1 ) + ":" + colors[ 'end' ]
1862 print main.ONOSbench.checkLogs( ips[ i ] )
Jon Hall94fd0472014-12-08 11:52:42 -08001863
Jon Hall6aec96b2015-01-19 14:49:31 -08001864 main.step( "Copying MN pcap and ONOS log files to test station" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001865 testname = main.TEST
Jon Hall8f89dda2015-01-22 16:03:33 -08001866 teststationUser = main.params[ 'TESTONUSER' ]
1867 teststationIP = main.params[ 'TESTONIP' ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001868 # NOTE: MN Pcap file is being saved to ~/packet_captures
Jon Hall73cf9cc2014-11-20 22:28:38 -08001869 # scp this file as MN and TestON aren't necessarily the same vm
Jon Hall6aec96b2015-01-19 14:49:31 -08001870 # FIXME: scp
1871 # mn files
1872 # TODO: Load these from params
1873 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001874 logFolder = "/opt/onos/log/"
1875 logFiles = [ "karaf.log", "karaf.log.1" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001876 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001877 dstDir = "~/packet_captures/"
1878 for f in logFiles:
1879 for i in range( 7 ):
1880 main.ONOSbench.handle.sendline( "scp sdn@" + ips[ i ] + ":" +
1881 logFolder + f + " " +
1882 teststationUser + "@" +
1883 teststationIP + ":" +
1884 dstDir + str( testname ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001885 "-ONOS" + str( i + 1 ) + "-" +
1886 f )
1887 # std*.log's
1888 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001889 logFolder = "/opt/onos/var/"
1890 logFiles = [ "stderr.log", "stdout.log" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001891 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001892 dstDir = "~/packet_captures/"
1893 for f in logFiles:
1894 for i in range( 7 ):
1895 main.ONOSbench.handle.sendline( "scp sdn@" + ips[ i ] + ":" +
1896 logFolder + f + " " +
1897 teststationUser + "@" +
1898 teststationIP + ":" +
1899 dstDir + str( testname ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001900 "-ONOS" + str( i + 1 ) + "-" +
1901 f )
1902 # sleep so scp can finish
1903 time.sleep( 10 )
1904 main.step( "Packing and rotating pcap archives" )
1905 os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001906
Jon Hall6aec96b2015-01-19 14:49:31 -08001907 # TODO: actually check something here
1908 utilities.assert_equals( expect=main.TRUE, actual=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001909 onpass="Test cleanup successful",
1910 onfail="Test cleanup NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001911
Jon Hall6aec96b2015-01-19 14:49:31 -08001912 def CASE14( self, main ):
1913 """
Jon Hall669173b2014-12-17 11:36:30 -08001914 start election app on all onos nodes
Jon Hall6aec96b2015-01-19 14:49:31 -08001915 """
Jon Hall8f89dda2015-01-22 16:03:33 -08001916 leaderResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001917 # install app on onos 1
1918 main.log.info( "Install leadership election app" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001919 main.ONOScli1.featureInstall( "onos-app-election" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001920 # wait for election
1921 # check for leader
Jon Hall8f89dda2015-01-22 16:03:33 -08001922 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001923 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08001924 if leader == ONOS1Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08001925 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001926 pass
Jon Hall6aec96b2015-01-19 14:49:31 -08001927 elif leader is None:
1928 # No leader elected
1929 main.log.report( "No leader was elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001930 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001931 elif leader == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001932 # error in response
1933 # TODO: add check for "Command not found:" in the driver, this
1934 # means the app isn't loaded
Jon Hall8f89dda2015-01-22 16:03:33 -08001935 main.log.report( "Something is wrong with electionTestLeader" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001936 " function, check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001937 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001938 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001939 # error in response
1940 main.log.report(
Jon Hall8f89dda2015-01-22 16:03:33 -08001941 "Unexpected response from electionTestLeader function:'" +
1942 str( leader ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001943 "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001944 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001945
Jon Hall6aec96b2015-01-19 14:49:31 -08001946 # install on other nodes and check for leader.
1947 # Should be onos1 and each app should show the same leader
Jon Hall8f89dda2015-01-22 16:03:33 -08001948 for controller in range( 2, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001949 # loop through ONOScli handlers
1950 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001951 node.featureInstall( "onos-app-election" )
1952 leaderN = node.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001953 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08001954 if leaderN == ONOS1Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08001955 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001956 pass
1957 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001958 # error in response
1959 # TODO: add check for "Command not found:" in the driver, this
1960 # means the app isn't loaded
1961 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001962 "electionTestLeader function, check the" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001963 " error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001964 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001965 elif leader != leaderN:
Jon Hall8f89dda2015-01-22 16:03:33 -08001966 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001967 main.log.report( "ONOS" + str( controller ) + " sees " +
1968 str( leaderN ) +
1969 " as the leader of the election app. Leader" +
1970 " should be " +
1971 str( leader ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001972 if leaderResult:
Jon Hall6aec96b2015-01-19 14:49:31 -08001973 main.log.report( "Leadership election tests passed( consistent " +
1974 "view of leader across listeners and a leader " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001975 "was elected )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001976 utilities.assert_equals(
1977 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001978 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001979 onpass="Leadership election passed",
1980 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08001981
Jon Hall6aec96b2015-01-19 14:49:31 -08001982 def CASE15( self, main ):
1983 """
Jon Hall669173b2014-12-17 11:36:30 -08001984 Check that Leadership Election is still functional
Jon Hall6aec96b2015-01-19 14:49:31 -08001985 """
Jon Hall8f89dda2015-01-22 16:03:33 -08001986 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08001987 description = "Check that Leadership Election is still functional"
Jon Hall6aec96b2015-01-19 14:49:31 -08001988 main.log.report( description )
1989 main.case( description )
1990 main.step( "Find current leader and withdraw" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001991 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001992 # TODO: do some sanity checking on leader before using it
Jon Hall8f89dda2015-01-22 16:03:33 -08001993 withdrawResult = main.FALSE
1994 if leader == ONOS1Ip:
1995 oldLeader = getattr( main, "ONOScli1" )
1996 elif leader == ONOS2Ip:
1997 oldLeader = getattr( main, "ONOScli2" )
1998 elif leader == ONOS3Ip:
1999 oldLeader = getattr( main, "ONOScli3" )
2000 elif leader == ONOS4Ip:
2001 oldLeader = getattr( main, "ONOScli4" )
2002 elif leader == ONOS5Ip:
2003 oldLeader = getattr( main, "ONOScli5" )
2004 elif leader == ONOS6Ip:
2005 oldLeader = getattr( main, "ONOScli6" )
2006 elif leader == ONOS7Ip:
2007 oldLeader = getattr( main, "ONOScli7" )
Jon Hall6aec96b2015-01-19 14:49:31 -08002008 elif leader is None or leader == main.FALSE:
2009 main.log.report(
2010 "Leader for the election app should be an ONOS node," +
2011 "instead got '" +
Jon Hall8f89dda2015-01-22 16:03:33 -08002012 str( leader ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08002013 "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002014 leaderResult = main.FALSE
2015 withdrawResult = oldLeader.electionTestWithdraw()
Jon Hall6aec96b2015-01-19 14:49:31 -08002016 utilities.assert_equals(
2017 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002018 actual=withdrawResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002019 onpass="App was withdrawn from election",
2020 onfail="App was not withdrawn from election" )
Jon Hall669173b2014-12-17 11:36:30 -08002021
Jon Hall6aec96b2015-01-19 14:49:31 -08002022 main.step( "Make sure new leader is elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002023 leaderList = []
2024 for controller in range( 1, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08002025 # loop through ONOScli handlers
2026 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08002027 leaderList.append( node.electionTestLeader() )
2028 for leaderN in leaderList:
Jon Hall669173b2014-12-17 11:36:30 -08002029 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08002030 main.log.report(
2031 "ONOS" +
2032 str( controller ) +
2033 " still sees " +
2034 str( leader ) +
2035 " as leader after they withdrew" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002036 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08002037 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08002038 # error in response
2039 # TODO: add check for "Command not found:" in the driver, this
2040 # means the app isn't loaded
2041 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002042 "electionTestLeader function, " +
Jon Hall6aec96b2015-01-19 14:49:31 -08002043 "check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002044 leaderResult = main.FALSE
2045 consistentLeader = main.FALSE
2046 if len( set( leaderList ) ) == 1:
Jon Hall6aec96b2015-01-19 14:49:31 -08002047 main.log.info( "Each Election-app sees '" +
Jon Hall8f89dda2015-01-22 16:03:33 -08002048 str( leaderList[ 0 ] ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08002049 "' as the leader" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002050 consistentLeader = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08002051 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08002052 main.log.report(
2053 "Inconsistent responses for leader of Election-app:" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002054 for n in range( len( leaderList ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -08002055 main.log.report( "ONOS" + str( n + 1 ) + " response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002056 str( leaderList[ n ] ) )
2057 if leaderResult:
2058 main.log.report( "Leadership election tests passed( consistent " +
Jon Hall6aec96b2015-01-19 14:49:31 -08002059 "view of leader across listeners and a new " +
2060 "leader was elected when the old leader " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002061 "resigned )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08002062 utilities.assert_equals(
2063 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002064 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002065 onpass="Leadership election passed",
2066 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08002067
Jon Hall6aec96b2015-01-19 14:49:31 -08002068 main.step(
Jon Hall8f89dda2015-01-22 16:03:33 -08002069 "Run for election on old leader( just so everyone is in the hat )" )
2070 runResult = oldLeader.electionTestRun()
Jon Hall6aec96b2015-01-19 14:49:31 -08002071 utilities.assert_equals(
2072 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002073 actual=runResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002074 onpass="App re-ran for election",
2075 onfail="App failed to run for election" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002076 if consistentLeader == main.TRUE:
2077 afterRun = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08002078 # verify leader didn't just change
Jon Hall8f89dda2015-01-22 16:03:33 -08002079 if afterRun == leaderList[ 0 ]:
2080 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08002081 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08002082 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08002083 # TODO: assert on run and withdraw results?
Jon Hall669173b2014-12-17 11:36:30 -08002084
Jon Hall6aec96b2015-01-19 14:49:31 -08002085 utilities.assert_equals(
2086 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002087 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002088 onpass="Leadership election passed",
2089 onfail="Something went wrong with Leadership election after " +
2090 "the old leader re-ran for election" )