blob: dfa6a03c1734a7b759820c18812f02c681d3fdf0 [file] [log] [blame]
Jon Hall6aec96b2015-01-19 14:49:31 -08001"""
Jon Hallb1290e82014-11-18 16:17:48 -05002Description: This test is to determine if the HA test setup is
3 working correctly. There are no failures so this test should
4 have a 100% pass rate
5
6List of test cases:
7CASE1: Compile ONOS and push it to the test machines
8CASE2: Assign mastership to controllers
9CASE3: Assign intents
10CASE4: Ping across added host intents
11CASE5: Reading state of ONOS
12CASE6: The Failure case. Since this is the Sanity test, we do nothing.
Jon Hall368769f2014-11-19 15:43:35 -080013CASE7: Check state after control plane failure
Jon Hallb1290e82014-11-18 16:17:48 -050014CASE8: Compare topo
15CASE9: Link s3-s28 down
16CASE10: Link s3-s28 up
17CASE11: Switch down
18CASE12: Switch up
19CASE13: Clean up
Jon Hall669173b2014-12-17 11:36:30 -080020CASE14: start election app on all onos nodes
21CASE15: Check that Leadership Election is still functional
Jon Hall6aec96b2015-01-19 14:49:31 -080022"""
Jon Hall8f89dda2015-01-22 16:03:33 -080023
24
Jon Hallb1290e82014-11-18 16:17:48 -050025class HATestSanity:
26
Jon Hall6aec96b2015-01-19 14:49:31 -080027 def __init__( self ):
Jon Hallb1290e82014-11-18 16:17:48 -050028 self.default = ''
29
Jon Hall6aec96b2015-01-19 14:49:31 -080030 def CASE1( self, main ):
31 """
Jon Hallb1290e82014-11-18 16:17:48 -050032 CASE1 is to compile ONOS and push it to the test machines
33
34 Startup sequence:
Jon Hallb1290e82014-11-18 16:17:48 -050035 cell <name>
36 onos-verify-cell
37 NOTE: temporary - onos-remove-raft-logs
Jon Hall58c76b72015-02-23 11:09:24 -080038 onos-uninstall
39 start mininet
40 git pull
41 mvn clean install
42 onos-package
Jon Hallb1290e82014-11-18 16:17:48 -050043 onos-install -f
44 onos-wait-for-start
Jon Hall58c76b72015-02-23 11:09:24 -080045 start cli sessions
46 start tcpdump
Jon Hall6aec96b2015-01-19 14:49:31 -080047 """
48 main.log.report( "ONOS HA Sanity test - initialization" )
49 main.case( "Setting up test environment" )
50 # TODO: save all the timers and output them for plotting
Jon Hallb1290e82014-11-18 16:17:48 -050051
52 # load some vairables from the params file
Jon Hall8f89dda2015-01-22 16:03:33 -080053 PULLCODE = False
Jon Hall6aec96b2015-01-19 14:49:31 -080054 if main.params[ 'Git' ] == 'True':
Jon Hall8f89dda2015-01-22 16:03:33 -080055 PULLCODE = True
Jon Hall529a37f2015-01-28 10:02:00 -080056 gitBranch = main.params[ 'branch' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080057 cellName = main.params[ 'ENV' ][ 'cellName' ]
Jon Hall6aec96b2015-01-19 14:49:31 -080058
59 # set global variables
Jon Hall8f89dda2015-01-22 16:03:33 -080060 global ONOS1Ip
61 global ONOS1Port
62 global ONOS2Ip
63 global ONOS2Port
64 global ONOS3Ip
65 global ONOS3Port
66 global ONOS4Ip
67 global ONOS4Port
68 global ONOS5Ip
69 global ONOS5Port
70 global ONOS6Ip
71 global ONOS6Port
72 global ONOS7Ip
73 global ONOS7Port
74 global numControllers
Jon Hallb1290e82014-11-18 16:17:48 -050075
Jon Hall8f89dda2015-01-22 16:03:33 -080076 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
77 ONOS1Port = main.params[ 'CTRL' ][ 'port1' ]
78 ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
79 ONOS2Port = main.params[ 'CTRL' ][ 'port2' ]
80 ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ]
81 ONOS3Port = main.params[ 'CTRL' ][ 'port3' ]
82 ONOS4Ip = main.params[ 'CTRL' ][ 'ip4' ]
83 ONOS4Port = main.params[ 'CTRL' ][ 'port4' ]
84 ONOS5Ip = main.params[ 'CTRL' ][ 'ip5' ]
85 ONOS5Port = main.params[ 'CTRL' ][ 'port5' ]
86 ONOS6Ip = main.params[ 'CTRL' ][ 'ip6' ]
87 ONOS6Port = main.params[ 'CTRL' ][ 'port6' ]
88 ONOS7Ip = main.params[ 'CTRL' ][ 'ip7' ]
89 ONOS7Port = main.params[ 'CTRL' ][ 'port7' ]
90 numControllers = int( main.params[ 'num_controllers' ] )
Jon Hallb1290e82014-11-18 16:17:48 -050091
Jon Hall6aec96b2015-01-19 14:49:31 -080092 main.step( "Applying cell variable to environment" )
Jon Hall8f89dda2015-01-22 16:03:33 -080093 cellResult = main.ONOSbench.setCell( cellName )
94 verifyResult = main.ONOSbench.verifyCell()
Jon Hall368769f2014-11-19 15:43:35 -080095
Jon Hall6aec96b2015-01-19 14:49:31 -080096 # FIXME:this is short term fix
97 main.log.report( "Removing raft logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -080098 main.ONOSbench.onosRemoveRaftLogs()
Jon Hall6aec96b2015-01-19 14:49:31 -080099 main.log.report( "Uninstalling ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800100 main.ONOSbench.onosUninstall( ONOS1Ip )
101 main.ONOSbench.onosUninstall( ONOS2Ip )
102 main.ONOSbench.onosUninstall( ONOS3Ip )
103 main.ONOSbench.onosUninstall( ONOS4Ip )
104 main.ONOSbench.onosUninstall( ONOS5Ip )
105 main.ONOSbench.onosUninstall( ONOS6Ip )
106 main.ONOSbench.onosUninstall( ONOS7Ip )
Jon Hallb1290e82014-11-18 16:17:48 -0500107
Jon Hall8f89dda2015-01-22 16:03:33 -0800108 cleanInstallResult = main.TRUE
109 gitPullResult = main.TRUE
Jon Hallb1290e82014-11-18 16:17:48 -0500110
Jon Hall97f31752015-02-04 12:01:04 -0800111 main.step( "Starting Mininet" )
112 main.Mininet1.startNet( )
113
Jon Hall6aec96b2015-01-19 14:49:31 -0800114 main.step( "Compiling the latest version of ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800115 if PULLCODE:
Jon Hall58c76b72015-02-23 11:09:24 -0800116 main.step( "Git checkout and pull " + gitBranch )
Jon Hall529a37f2015-01-28 10:02:00 -0800117 main.ONOSbench.gitCheckout( gitBranch )
Jon Hall8f89dda2015-01-22 16:03:33 -0800118 gitPullResult = main.ONOSbench.gitPull()
Jon Hallb1290e82014-11-18 16:17:48 -0500119
Jon Hall6aec96b2015-01-19 14:49:31 -0800120 main.step( "Using mvn clean & install" )
Jon Hall529a37f2015-01-28 10:02:00 -0800121 cleanInstallResult = main.ONOSbench.cleanInstall()
122 else:
123 main.log.warn( "Did not pull new code so skipping mvn " +
124 "clean install" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800125 main.ONOSbench.getVersion( report=True )
Jon Hallb1290e82014-11-18 16:17:48 -0500126
Jon Hall6aec96b2015-01-19 14:49:31 -0800127 main.step( "Creating ONOS package" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800128 packageResult = main.ONOSbench.onosPackage()
Jon Hallb1290e82014-11-18 16:17:48 -0500129
Jon Hall6aec96b2015-01-19 14:49:31 -0800130 main.step( "Installing ONOS package" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800131 onos1InstallResult = main.ONOSbench.onosInstall( options="-f",
132 node=ONOS1Ip )
133 onos2InstallResult = main.ONOSbench.onosInstall( options="-f",
134 node=ONOS2Ip )
135 onos3InstallResult = main.ONOSbench.onosInstall( options="-f",
136 node=ONOS3Ip )
137 onos4InstallResult = main.ONOSbench.onosInstall( options="-f",
138 node=ONOS4Ip )
139 onos5InstallResult = main.ONOSbench.onosInstall( options="-f",
140 node=ONOS5Ip )
141 onos6InstallResult = main.ONOSbench.onosInstall( options="-f",
142 node=ONOS6Ip )
143 onos7InstallResult = main.ONOSbench.onosInstall( options="-f",
144 node=ONOS7Ip )
145 onosInstallResult = onos1InstallResult and onos2InstallResult\
146 and onos3InstallResult and onos4InstallResult\
147 and onos5InstallResult and onos6InstallResult\
148 and onos7InstallResult
Jon Hallb1290e82014-11-18 16:17:48 -0500149
Jon Hall6aec96b2015-01-19 14:49:31 -0800150 main.step( "Checking if ONOS is up yet" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800151 for i in range( 2 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800152 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
153 if not onos1Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800154 main.log.report( "ONOS1 didn't start!" )
Jon Hall21270ac2015-02-16 17:59:55 -0800155 main.ONOSbench.onosStop( ONOS1Ip )
156 main.ONOSbench.onosStart( ONOS1Ip )
Jon Hall8f89dda2015-01-22 16:03:33 -0800157 onos2Isup = main.ONOSbench.isup( ONOS2Ip )
158 if not onos2Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800159 main.log.report( "ONOS2 didn't start!" )
Jon Hall21270ac2015-02-16 17:59:55 -0800160 main.ONOSbench.onosStop( ONOS2Ip )
161 main.ONOSbench.onosStart( ONOS2Ip )
Jon Hall8f89dda2015-01-22 16:03:33 -0800162 onos3Isup = main.ONOSbench.isup( ONOS3Ip )
163 if not onos3Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800164 main.log.report( "ONOS3 didn't start!" )
Jon Hall21270ac2015-02-16 17:59:55 -0800165 main.ONOSbench.onosStop( ONOS3Ip )
166 main.ONOSbench.onosStart( ONOS3Ip )
Jon Hall8f89dda2015-01-22 16:03:33 -0800167 onos4Isup = main.ONOSbench.isup( ONOS4Ip )
168 if not onos4Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800169 main.log.report( "ONOS4 didn't start!" )
Jon Hall21270ac2015-02-16 17:59:55 -0800170 main.ONOSbench.onosStop( ONOS4Ip )
171 main.ONOSbench.onosStart( ONOS4Ip )
Jon Hall8f89dda2015-01-22 16:03:33 -0800172 onos5Isup = main.ONOSbench.isup( ONOS5Ip )
173 if not onos5Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800174 main.log.report( "ONOS5 didn't start!" )
Jon Hall21270ac2015-02-16 17:59:55 -0800175 main.ONOSbench.onosStop( ONOS5Ip )
176 main.ONOSbench.onosStart( ONOS5Ip )
Jon Hall8f89dda2015-01-22 16:03:33 -0800177 onos6Isup = main.ONOSbench.isup( ONOS6Ip )
178 if not onos6Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800179 main.log.report( "ONOS6 didn't start!" )
Jon Hall21270ac2015-02-16 17:59:55 -0800180 main.ONOSbench.onosStop( ONOS6Ip )
181 main.ONOSbench.onosStart( ONOS6Ip )
Jon Hall8f89dda2015-01-22 16:03:33 -0800182 onos7Isup = main.ONOSbench.isup( ONOS7Ip )
183 if not onos7Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800184 main.log.report( "ONOS7 didn't start!" )
Jon Hall21270ac2015-02-16 17:59:55 -0800185 main.ONOSbench.onosStop( ONOS7Ip )
186 main.ONOSbench.onosStart( ONOS7Ip )
Jon Hall8f89dda2015-01-22 16:03:33 -0800187 onosIsupResult = onos1Isup and onos2Isup and onos3Isup\
188 and onos4Isup and onos5Isup and onos6Isup and onos7Isup
189 if onosIsupResult == main.TRUE:
Jon Hallffb386d2014-11-21 13:43:38 -0800190 break
Jon Hallb1290e82014-11-18 16:17:48 -0500191
Jon Hall8f89dda2015-01-22 16:03:33 -0800192 cliResult1 = main.ONOScli1.startOnosCli( ONOS1Ip )
193 cliResult2 = main.ONOScli2.startOnosCli( ONOS2Ip )
194 cliResult3 = main.ONOScli3.startOnosCli( ONOS3Ip )
195 cliResult4 = main.ONOScli4.startOnosCli( ONOS4Ip )
196 cliResult5 = main.ONOScli5.startOnosCli( ONOS5Ip )
197 cliResult6 = main.ONOScli6.startOnosCli( ONOS6Ip )
198 cliResult7 = main.ONOScli7.startOnosCli( ONOS7Ip )
199 cliResults = cliResult1 and cliResult2 and cliResult3 and\
200 cliResult4 and cliResult5 and cliResult6 and cliResult7
Jon Hallb1290e82014-11-18 16:17:48 -0500201
Jon Hall6aec96b2015-01-19 14:49:31 -0800202 main.step( "Start Packet Capture MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800203 main.Mininet2.startTcpdump(
Jon Hall6aec96b2015-01-19 14:49:31 -0800204 str( main.params[ 'MNtcpdump' ][ 'folder' ] ) + str( main.TEST )
205 + "-MN.pcap",
206 intf=main.params[ 'MNtcpdump' ][ 'intf' ],
207 port=main.params[ 'MNtcpdump' ][ 'port' ] )
Jon Hallb1290e82014-11-18 16:17:48 -0500208
Jon Hall8f89dda2015-01-22 16:03:33 -0800209 case1Result = ( cleanInstallResult and packageResult and
210 cellResult and verifyResult and onosInstallResult
211 and onosIsupResult and cliResults )
Jon Hallb1290e82014-11-18 16:17:48 -0500212
Jon Hall8f89dda2015-01-22 16:03:33 -0800213 utilities.assert_equals( expect=main.TRUE, actual=case1Result,
Jon Hall58c76b72015-02-23 11:09:24 -0800214 onpass="Test startup successful",
215 onfail="Test startup NOT successful" )
Jon Hallb1290e82014-11-18 16:17:48 -0500216
Jon Hall8f89dda2015-01-22 16:03:33 -0800217 if case1Result == main.FALSE:
Jon Hallffb386d2014-11-21 13:43:38 -0800218 main.cleanup()
219 main.exit()
Jon Hallb1290e82014-11-18 16:17:48 -0500220
Jon Hall6aec96b2015-01-19 14:49:31 -0800221 def CASE2( self, main ):
222 """
Jon Hallb1290e82014-11-18 16:17:48 -0500223 Assign mastership to controllers
Jon Hall6aec96b2015-01-19 14:49:31 -0800224 """
Jon Hallb1290e82014-11-18 16:17:48 -0500225 import re
226
Jon Hall6aec96b2015-01-19 14:49:31 -0800227 main.log.report( "Assigning switches to controllers" )
228 main.case( "Assigning Controllers" )
229 main.step( "Assign switches to controllers" )
Jon Hallb1290e82014-11-18 16:17:48 -0500230
Jon Hall6aec96b2015-01-19 14:49:31 -0800231 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800232 main.Mininet1.assignSwController(
Jon Hall6aec96b2015-01-19 14:49:31 -0800233 sw=str( i ),
Jon Hall8f89dda2015-01-22 16:03:33 -0800234 count=numControllers,
235 ip1=ONOS1Ip, port1=ONOS1Port,
236 ip2=ONOS2Ip, port2=ONOS2Port,
237 ip3=ONOS3Ip, port3=ONOS3Port,
238 ip4=ONOS4Ip, port4=ONOS4Port,
239 ip5=ONOS5Ip, port5=ONOS5Port,
240 ip6=ONOS6Ip, port6=ONOS6Port,
241 ip7=ONOS7Ip, port7=ONOS7Port )
Jon Hallb1290e82014-11-18 16:17:48 -0500242
Jon Hall8f89dda2015-01-22 16:03:33 -0800243 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800244 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800245 response = main.Mininet1.getSwController( "s" + str( i ) )
Jon Hallffb386d2014-11-21 13:43:38 -0800246 try:
Jon Hall6aec96b2015-01-19 14:49:31 -0800247 main.log.info( str( response ) )
Jon Hallffb386d2014-11-21 13:43:38 -0800248 except:
Jon Hall6aec96b2015-01-19 14:49:31 -0800249 main.log.info( repr( response ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800250 if re.search( "tcp:" + ONOS1Ip, response )\
251 and re.search( "tcp:" + ONOS2Ip, response )\
252 and re.search( "tcp:" + ONOS3Ip, response )\
253 and re.search( "tcp:" + ONOS4Ip, response )\
254 and re.search( "tcp:" + ONOS5Ip, response )\
255 and re.search( "tcp:" + ONOS6Ip, response )\
256 and re.search( "tcp:" + ONOS7Ip, response ):
257 mastershipCheck = mastershipCheck and main.TRUE
Jon Hallb1290e82014-11-18 16:17:48 -0500258 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800259 mastershipCheck = main.FALSE
260 if mastershipCheck == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800261 main.log.report( "Switch mastership assigned correctly" )
262 utilities.assert_equals(
263 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800264 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800265 onpass="Switch mastership assigned correctly",
266 onfail="Switches not assigned correctly to controllers" )
Jon Hallb1290e82014-11-18 16:17:48 -0500267
Jon Hall6aec96b2015-01-19 14:49:31 -0800268 # Manually assign mastership to the controller we want
Jon Hall8f89dda2015-01-22 16:03:33 -0800269 roleCall = main.TRUE
270 roleCheck = main.TRUE
Jon Hall58c76b72015-02-23 11:09:24 -0800271 try:
272 # Assign switch
273 deviceId = main.ONOScli1.getDevice( "1000" ).get( 'id' )
274 assert deviceId, "No device id for s1 in ONOS"
Jon Hall8f89dda2015-01-22 16:03:33 -0800275 roleCall = roleCall and main.ONOScli1.deviceRole(
276 deviceId,
Jon Hall58c76b72015-02-23 11:09:24 -0800277 ONOS1Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800278 # Check assignment
Jon Hall58c76b72015-02-23 11:09:24 -0800279 if ONOS1Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800280 roleCheck = roleCheck and main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800281 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800282 roleCheck = roleCheck and main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800283
Jon Hall58c76b72015-02-23 11:09:24 -0800284 # Assign switch
285 deviceId = main.ONOScli1.getDevice( "2800" ).get( 'id' )
286 assert deviceId, "No device id for s28 in ONOS"
Jon Hall8f89dda2015-01-22 16:03:33 -0800287 roleCall = roleCall and main.ONOScli1.deviceRole(
288 deviceId,
Jon Hall58c76b72015-02-23 11:09:24 -0800289 ONOS1Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800290 # Check assignment
Jon Hall58c76b72015-02-23 11:09:24 -0800291 if ONOS1Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800292 roleCheck = roleCheck and main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800293 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800294 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800295
Jon Hall58c76b72015-02-23 11:09:24 -0800296 # Assign switch
297 deviceId = main.ONOScli1.getDevice( "2000" ).get( 'id' )
298 assert deviceId, "No device id for s2 in ONOS"
299 roleCall = roleCall and main.ONOScli1.deviceRole(
300 deviceId,
301 ONOS2Ip )
302 # Check assignment
303 if ONOS2Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
304 roleCheck = roleCheck and main.TRUE
305 else:
306 roleCheck = roleCheck and main.FALSE
307
308 # Assign switch
309 deviceId = main.ONOScli1.getDevice( "3000" ).get( 'id' )
310 assert deviceId, "No device id for s3 in ONOS"
311 roleCall = roleCall and main.ONOScli1.deviceRole(
312 deviceId,
313 ONOS2Ip )
314 # Check assignment
315 if ONOS2Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
316 roleCheck = roleCheck and main.TRUE
317 else:
318 roleCheck = roleCheck and main.FALSE
319
320 # Assign switch
321 deviceId = main.ONOScli1.getDevice( "5000" ).get( 'id' )
322 assert deviceId, "No device id for s5 in ONOS"
323 roleCall = roleCall and main.ONOScli1.deviceRole(
324 deviceId,
325 ONOS3Ip )
326 # Check assignment
327 if ONOS3Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
328 roleCheck = roleCheck and main.TRUE
329 else:
330 roleCheck = roleCheck and main.FALSE
331
332 # Assign switch
333 deviceId = main.ONOScli1.getDevice( "6000" ).get( 'id' )
334 assert deviceId, "No device id for s6 in ONOS"
335 roleCall = roleCall and main.ONOScli1.deviceRole(
336 deviceId,
337 ONOS3Ip )
338 # Check assignment
339 if ONOS3Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
340 roleCheck = roleCheck and main.TRUE
341 else:
342 roleCheck = roleCheck and main.FALSE
343
344 # Assign switch
345 deviceId = main.ONOScli1.getDevice( "3004" ).get( 'id' )
346 assert deviceId, "No device id for s4 in ONOS"
347 roleCall = roleCall and main.ONOScli1.deviceRole(
348 deviceId,
349 ONOS4Ip )
350 # Check assignment
351 if ONOS4Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
352 roleCheck = roleCheck and main.TRUE
353 else:
354 roleCheck = roleCheck and main.FALSE
355
356 for i in range( 8, 18 ):
357 dpid = '3' + str( i ).zfill( 3 )
358 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
359 assert deviceId, "No device id for s%i in ONOS" % i
360 roleCall = roleCall and main.ONOScli1.deviceRole(
361 deviceId,
362 ONOS5Ip )
363 # Check assignment
364 if ONOS5Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
365 roleCheck = roleCheck and main.TRUE
366 else:
367 roleCheck = roleCheck and main.FALSE
368
369 deviceId = main.ONOScli1.getDevice( "6007" ).get( 'id' )
370 assert deviceId, "No device id for s7 in ONOS"
371 roleCall = roleCall and main.ONOScli1.deviceRole(
372 deviceId,
373 ONOS6Ip )
374 # Check assignment
375 if ONOS6Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
376 roleCheck = roleCheck and main.TRUE
377 else:
378 roleCheck = roleCheck and main.FALSE
379
380 for i in range( 18, 28 ):
381 dpid = '6' + str( i ).zfill( 3 )
382 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
383 assert deviceId, "No device id for s%i in ONOS" % i
384 roleCall = roleCall and main.ONOScli1.deviceRole(
385 deviceId,
386 ONOS7Ip )
387 # Check assignment
388 if ONOS7Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
389 roleCheck = roleCheck and main.TRUE
390 else:
391 roleCheck = roleCheck and main.FALSE
392 except ( AttributeError, AssertionError ):
393 main.log.exception( "Something is wrong with ONOS device view" )
394 main.log.info( main.ONOScli1.devices() )
395
Jon Hall6aec96b2015-01-19 14:49:31 -0800396 utilities.assert_equals(
397 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800398 actual=roleCall,
Jon Hall6aec96b2015-01-19 14:49:31 -0800399 onpass="Re-assigned switch mastership to designated controller",
Jon Hall8f89dda2015-01-22 16:03:33 -0800400 onfail="Something wrong with deviceRole calls" )
Jon Hall94fd0472014-12-08 11:52:42 -0800401
Jon Hall6aec96b2015-01-19 14:49:31 -0800402 utilities.assert_equals(
403 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800404 actual=roleCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800405 onpass="Switches were successfully reassigned to designated " +
406 "controller",
407 onfail="Switches were not successfully reassigned" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800408 mastershipCheck = mastershipCheck and roleCall and roleCheck
409 utilities.assert_equals( expect=main.TRUE, actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800410 onpass="Switch mastership correctly assigned",
411 onfail="Error in (re)assigning switch" +
Jon Hall8f89dda2015-01-22 16:03:33 -0800412 " mastership" )
Jon Hallb1290e82014-11-18 16:17:48 -0500413
Jon Hall6aec96b2015-01-19 14:49:31 -0800414 def CASE3( self, main ):
Jon Hallb1290e82014-11-18 16:17:48 -0500415 """
416 Assign intents
Jon Hallb1290e82014-11-18 16:17:48 -0500417 """
418 import time
Jon Hall58c76b72015-02-23 11:09:24 -0800419 import json
Jon Hall6aec96b2015-01-19 14:49:31 -0800420 main.log.report( "Adding host intents" )
421 main.case( "Adding host Intents" )
Jon Hallb1290e82014-11-18 16:17:48 -0500422
Jon Hall8f89dda2015-01-22 16:03:33 -0800423 main.step( "Discovering Hosts( Via pingall for now )" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800424 # FIXME: Once we have a host discovery mechanism, use that instead
Jon Hallb1290e82014-11-18 16:17:48 -0500425
Jon Hall6aec96b2015-01-19 14:49:31 -0800426 # install onos-app-fwd
427 main.log.info( "Install reactive forwarding app" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800428 main.ONOScli1.featureInstall( "onos-app-fwd" )
429 main.ONOScli2.featureInstall( "onos-app-fwd" )
430 main.ONOScli3.featureInstall( "onos-app-fwd" )
431 main.ONOScli4.featureInstall( "onos-app-fwd" )
432 main.ONOScli5.featureInstall( "onos-app-fwd" )
433 main.ONOScli6.featureInstall( "onos-app-fwd" )
434 main.ONOScli7.featureInstall( "onos-app-fwd" )
Jon Hall94fd0472014-12-08 11:52:42 -0800435
Jon Hall6aec96b2015-01-19 14:49:31 -0800436 # REACTIVE FWD test
Jon Hall8f89dda2015-01-22 16:03:33 -0800437 pingResult = main.FALSE
Jon Hallb1290e82014-11-18 16:17:48 -0500438 time1 = time.time()
Jon Hall8f89dda2015-01-22 16:03:33 -0800439 pingResult = main.Mininet1.pingall()
Jon Hall529a37f2015-01-28 10:02:00 -0800440 utilities.assert_equals(
441 expect=main.TRUE,
442 actual=pingResult,
443 onpass="Reactive Pingall test passed",
444 onfail="Reactive Pingall failed, one or more ping pairs failed" )
Jon Hallb1290e82014-11-18 16:17:48 -0500445 time2 = time.time()
Jon Hall6aec96b2015-01-19 14:49:31 -0800446 main.log.info( "Time for pingall: %2f seconds" % ( time2 - time1 ) )
Jon Hallb1290e82014-11-18 16:17:48 -0500447
Jon Hall6aec96b2015-01-19 14:49:31 -0800448 # uninstall onos-app-fwd
449 main.log.info( "Uninstall reactive forwarding app" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800450 main.ONOScli1.featureUninstall( "onos-app-fwd" )
451 main.ONOScli2.featureUninstall( "onos-app-fwd" )
452 main.ONOScli3.featureUninstall( "onos-app-fwd" )
453 main.ONOScli4.featureUninstall( "onos-app-fwd" )
454 main.ONOScli5.featureUninstall( "onos-app-fwd" )
455 main.ONOScli6.featureUninstall( "onos-app-fwd" )
456 main.ONOScli7.featureUninstall( "onos-app-fwd" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800457 # timeout for fwd flows
458 time.sleep( 10 )
Jon Hallb1290e82014-11-18 16:17:48 -0500459
Jon Hall6aec96b2015-01-19 14:49:31 -0800460 main.step( "Add host intents" )
Jon Hall58c76b72015-02-23 11:09:24 -0800461 intentIds = []
Jon Hall6aec96b2015-01-19 14:49:31 -0800462 # TODO: move the host numbers to params
Jon Hall58c76b72015-02-23 11:09:24 -0800463 # Maybe look at all the paths we ping?
Jon Hall8f89dda2015-01-22 16:03:33 -0800464 intentAddResult = True
Jon Hall58c76b72015-02-23 11:09:24 -0800465 hostResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800466 for i in range( 8, 18 ):
467 main.log.info( "Adding host intent between h" + str( i ) +
468 " and h" + str( i + 10 ) )
469 host1 = "00:00:00:00:00:" + \
470 str( hex( i )[ 2: ] ).zfill( 2 ).upper()
471 host2 = "00:00:00:00:00:" + \
472 str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper()
Jon Hall1b8f54a2015-02-04 13:24:20 -0800473 # NOTE: getHost can return None
474 host1Dict = main.ONOScli1.getHost( host1 )
475 host2Dict = main.ONOScli1.getHost( host2 )
476 host1Id = None
477 host2Id = None
478 if host1Dict and host2Dict:
479 host1Id = host1Dict.get( 'id', None )
480 host2Id = host2Dict.get( 'id', None )
Jon Hall8f89dda2015-01-22 16:03:33 -0800481 if host1Id and host2Id:
Jon Hall58c76b72015-02-23 11:09:24 -0800482 '''
483 nodeNum = ( i % 7 ) + 1
484 node = getattr( main, ( 'ONOScli' + str( nodeNum ) ) )
485 tmpId = node.addHostIntent(
486 '''
487 tmpId = main.ONOScli1.addHostIntent(
Jon Hall8f89dda2015-01-22 16:03:33 -0800488 host1Id,
489 host2Id )
Jon Hall58c76b72015-02-23 11:09:24 -0800490 main.log.info( "Added intent with id: " + tmpId )
491 intentIds.append( tmpId )
Jon Hall669173b2014-12-17 11:36:30 -0800492 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800493 main.log.error( "Error, getHost() failed" )
Jon Hall1b8f54a2015-02-04 13:24:20 -0800494 main.log.warn( json.dumps( json.loads( main.ONOScli1.hosts() ),
495 sort_keys=True,
496 indent=4,
497 separators=( ',', ': ' ) ) )
Jon Hall58c76b72015-02-23 11:09:24 -0800498 hostResult = main.FALSE
499 onosIds = main.ONOScli1.getAllIntentsId()
500 main.log.info( "Submitted intents: " + str( intentIds ) )
501 main.log.info( "Intents in ONOS: " + str( onosIds ) )
502 for intent in intentIds:
503 if intent in onosIds:
504 pass # intent submitted is still in onos
505 else:
506 intentAddResult = False
Jon Hall1b8f54a2015-02-04 13:24:20 -0800507 # Print the intent states
Jon Hall58c76b72015-02-23 11:09:24 -0800508 intents = main.ONOScli1.intents()
Jon Hall1b8f54a2015-02-04 13:24:20 -0800509 intentStates = []
Jon Hall58c76b72015-02-23 11:09:24 -0800510 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
511 count = 0
Jon Hall1b8f54a2015-02-04 13:24:20 -0800512 for intent in json.loads( intents ): # Iter through intents of a node
Jon Hall58c76b72015-02-23 11:09:24 -0800513 state = intent.get( 'state', None )
514 intentId = intent.get( 'id', None )
515 intentStates.append( ( intentId, state ) )
516 # add submitted intents not in the store
517 tmplist = [ i for i, s in intentStates ]
518 missingIntents = False
519 for i in intentIds:
520 if i not in tmplist:
521 intentStates.append( ( i, " - " ) )
522 missingIntents = True
523 intentStates.sort()
524 for i, s in intentStates:
525 count += 1
526 main.log.info( "%-6s%-15s%-15s" %
527 ( str( count ), str( i ), str( s ) ) )
528 intentAddResult = bool( pingResult and hostResult and intentAddResult
529 and not missingIntents)
Jon Hall6aec96b2015-01-19 14:49:31 -0800530 utilities.assert_equals(
531 expect=True,
Jon Hall8f89dda2015-01-22 16:03:33 -0800532 actual=intentAddResult,
533 onpass="Pushed host intents to ONOS",
534 onfail="Error in pushing host intents to ONOS" )
Jon Hall58c76b72015-02-23 11:09:24 -0800535
536 if not intentAddResult:
537 import time
538 main.log.info( "Sleeping 60 seconds to see if intents are found" )
539 time.sleep( 60 )
540 onosIds = main.ONOScli1.getAllIntentsId()
541 main.log.info( "Submitted intents: " + str( intentIds ) )
542 main.log.info( "Intents in ONOS: " + str( onosIds ) )
543 # Print the intent states
544 intents = main.ONOScli1.intents()
545 intentStates = []
546 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
547 count = 0
548 for intent in json.loads( intents ):
549 # Iter through intents of a node
550 state = intent.get( 'state', None )
551 intentId = intent.get( 'id', None )
552 intentStates.append( ( intentId, state ) )
553 # add submitted intents not in the store
554 tmplist = [ i for i, s in intentStates ]
555 for i in intentIds:
556 if i not in tmplist:
557 intentStates.append( ( i, " - " ) )
558 intentStates.sort()
559 for i, s in intentStates:
560 count += 1
561 main.log.info( "%-6s%-15s%-15s" %
562 ( str( count ), str( i ), str( s ) ) )
Jon Hallb1290e82014-11-18 16:17:48 -0500563
Jon Hall6aec96b2015-01-19 14:49:31 -0800564 def CASE4( self, main ):
Jon Hallb1290e82014-11-18 16:17:48 -0500565 """
566 Ping across added host intents
567 """
Jon Hall58c76b72015-02-23 11:09:24 -0800568 import json
Jon Hall368769f2014-11-19 15:43:35 -0800569 description = " Ping across added host intents"
Jon Hall6aec96b2015-01-19 14:49:31 -0800570 main.log.report( description )
571 main.case( description )
Jon Hall8f89dda2015-01-22 16:03:33 -0800572 PingResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800573 for i in range( 8, 18 ):
Jon Hall58c76b72015-02-23 11:09:24 -0800574 ping = main.Mininet1.pingHost( src="h" + str( i ),
575 target="h" + str( i + 10 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800576 PingResult = PingResult and ping
Jon Hall6aec96b2015-01-19 14:49:31 -0800577 if ping == main.FALSE:
578 main.log.warn( "Ping failed between h" + str( i ) +
579 " and h" + str( i + 10 ) )
580 elif ping == main.TRUE:
581 main.log.info( "Ping test passed!" )
Jon Hall21270ac2015-02-16 17:59:55 -0800582 # Don't set PingResult or you'd override failures
Jon Hall8f89dda2015-01-22 16:03:33 -0800583 if PingResult == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800584 main.log.report(
585 "Intents have not been installed correctly, pings failed." )
Jon Hall58c76b72015-02-23 11:09:24 -0800586 # TODO: pretty print
Jon Hall529a37f2015-01-28 10:02:00 -0800587 main.log.warn( "ONSO1 intents: " )
588 main.log.warn( json.dumps( json.loads( main.ONOScli1.intents() ),
589 sort_keys=True,
590 indent=4,
591 separators=( ',', ': ' ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800592 if PingResult == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800593 main.log.report(
594 "Intents have been installed correctly and verified by pings" )
595 utilities.assert_equals(
596 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800597 actual=PingResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800598 onpass="Intents have been installed correctly and pings work",
599 onfail="Intents have not been installed correctly, pings failed." )
Jon Hall58c76b72015-02-23 11:09:24 -0800600 if PingResult is not main.TRUE:
601 # Print the intent states
602 intents = main.ONOScli1.intents()
603 intentStates = []
604 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
605 count = 0
606 # Iter through intents of a node
607 for intent in json.loads( intents ):
608 state = intent.get( 'state', None )
609 intentId = intent.get( 'id', None )
610 intentStates.append( ( intentId, state ) )
611 intentStates.sort()
612 for i, s in intentStates:
613 count += 1
614 main.log.info( "%-6s%-15s%-15s" %
615 ( str( count ), str( i ), str( s ) ) )
Jon Hallb1290e82014-11-18 16:17:48 -0500616
Jon Hall6aec96b2015-01-19 14:49:31 -0800617 def CASE5( self, main ):
618 """
Jon Hallb1290e82014-11-18 16:17:48 -0500619 Reading state of ONOS
Jon Hall6aec96b2015-01-19 14:49:31 -0800620 """
Jon Hallb1290e82014-11-18 16:17:48 -0500621 import json
Jon Hall6aec96b2015-01-19 14:49:31 -0800622 # assumes that sts is already in you PYTHONPATH
623 from sts.topology.teston_topology import TestONTopology
Jon Hallb1290e82014-11-18 16:17:48 -0500624
Jon Hall6aec96b2015-01-19 14:49:31 -0800625 main.log.report( "Setting up and gathering data for current state" )
626 main.case( "Setting up and gathering data for current state" )
627 # The general idea for this test case is to pull the state of
628 # ( intents,flows, topology,... ) from each ONOS node
629 # We can then compare them with eachother and also with past states
Jon Hallb1290e82014-11-18 16:17:48 -0500630
Jon Hall6aec96b2015-01-19 14:49:31 -0800631 main.step( "Get the Mastership of each switch from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800632 global mastershipState
633 mastershipState = []
Jon Hall94fd0472014-12-08 11:52:42 -0800634
Jon Hall6aec96b2015-01-19 14:49:31 -0800635 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -0800636 ONOS1MasterNotNull = main.ONOScli1.rolesNotNull()
637 ONOS2MasterNotNull = main.ONOScli2.rolesNotNull()
638 ONOS3MasterNotNull = main.ONOScli3.rolesNotNull()
639 ONOS4MasterNotNull = main.ONOScli4.rolesNotNull()
640 ONOS5MasterNotNull = main.ONOScli5.rolesNotNull()
641 ONOS6MasterNotNull = main.ONOScli6.rolesNotNull()
642 ONOS7MasterNotNull = main.ONOScli7.rolesNotNull()
643 rolesNotNull = ONOS1MasterNotNull and ONOS2MasterNotNull and\
644 ONOS3MasterNotNull and ONOS4MasterNotNull and\
645 ONOS5MasterNotNull and ONOS6MasterNotNull and\
646 ONOS7MasterNotNull
Jon Hall6aec96b2015-01-19 14:49:31 -0800647 utilities.assert_equals(
648 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800649 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -0800650 onpass="Each device has a master",
651 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -0800652
Jon Hall8f89dda2015-01-22 16:03:33 -0800653 ONOS1Mastership = main.ONOScli1.roles()
654 ONOS2Mastership = main.ONOScli2.roles()
655 ONOS3Mastership = main.ONOScli3.roles()
656 ONOS4Mastership = main.ONOScli4.roles()
657 ONOS5Mastership = main.ONOScli5.roles()
658 ONOS6Mastership = main.ONOScli6.roles()
659 ONOS7Mastership = main.ONOScli7.roles()
Jon Hall8f89dda2015-01-22 16:03:33 -0800660 if "Error" in ONOS1Mastership or not ONOS1Mastership\
661 or "Error" in ONOS2Mastership or not ONOS2Mastership\
662 or "Error" in ONOS3Mastership or not ONOS3Mastership\
663 or "Error" in ONOS4Mastership or not ONOS4Mastership\
664 or "Error" in ONOS5Mastership or not ONOS5Mastership\
665 or "Error" in ONOS6Mastership or not ONOS6Mastership\
666 or "Error" in ONOS7Mastership or not ONOS7Mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -0800667 main.log.report( "Error in getting ONOS roles" )
668 main.log.warn(
669 "ONOS1 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800670 repr( ONOS1Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800671 main.log.warn(
672 "ONOS2 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800673 repr( ONOS2Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800674 main.log.warn(
675 "ONOS3 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800676 repr( ONOS3Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800677 main.log.warn(
678 "ONOS4 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800679 repr( ONOS4Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800680 main.log.warn(
681 "ONOS5 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800682 repr( ONOS5Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800683 main.log.warn(
684 "ONOS6 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800685 repr( ONOS6Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800686 main.log.warn(
687 "ONOS7 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800688 repr( ONOS7Mastership ) )
689 consistentMastership = main.FALSE
690 elif ONOS1Mastership == ONOS2Mastership\
691 and ONOS1Mastership == ONOS3Mastership\
692 and ONOS1Mastership == ONOS4Mastership\
693 and ONOS1Mastership == ONOS5Mastership\
694 and ONOS1Mastership == ONOS6Mastership\
695 and ONOS1Mastership == ONOS7Mastership:
696 mastershipState = ONOS1Mastership
697 consistentMastership = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800698 main.log.report(
699 "Switch roles are consistent across all ONOS nodes" )
Jon Hallb1290e82014-11-18 16:17:48 -0500700 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800701 main.log.warn(
702 "ONOS1 roles: ",
703 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800704 json.loads( ONOS1Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800705 sort_keys=True,
706 indent=4,
707 separators=(
708 ',',
709 ': ' ) ) )
710 main.log.warn(
711 "ONOS2 roles: ",
712 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800713 json.loads( ONOS2Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800714 sort_keys=True,
715 indent=4,
716 separators=(
717 ',',
718 ': ' ) ) )
719 main.log.warn(
720 "ONOS3 roles: ",
721 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800722 json.loads( ONOS3Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800723 sort_keys=True,
724 indent=4,
725 separators=(
726 ',',
727 ': ' ) ) )
728 main.log.warn(
729 "ONOS4 roles: ",
730 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800731 json.loads( ONOS4Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800732 sort_keys=True,
733 indent=4,
734 separators=(
735 ',',
736 ': ' ) ) )
737 main.log.warn(
738 "ONOS5 roles: ",
739 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800740 json.loads( ONOS5Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800741 sort_keys=True,
742 indent=4,
743 separators=(
744 ',',
745 ': ' ) ) )
746 main.log.warn(
747 "ONOS6 roles: ",
748 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800749 json.loads( ONOS6Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800750 sort_keys=True,
751 indent=4,
752 separators=(
753 ',',
754 ': ' ) ) )
755 main.log.warn(
756 "ONOS7 roles: ",
757 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800758 json.loads( ONOS7Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800759 sort_keys=True,
760 indent=4,
761 separators=(
762 ',',
763 ': ' ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800764 consistentMastership = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800765 utilities.assert_equals(
766 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800767 actual=consistentMastership,
Jon Hall6aec96b2015-01-19 14:49:31 -0800768 onpass="Switch roles are consistent across all ONOS nodes",
769 onfail="ONOS nodes have different views of switch roles" )
Jon Hallb1290e82014-11-18 16:17:48 -0500770
Jon Hall6aec96b2015-01-19 14:49:31 -0800771 main.step( "Get the intents from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800772 global intentState
773 intentState = []
774 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
775 ONOS2Intents = main.ONOScli2.intents( jsonFormat=True )
776 ONOS3Intents = main.ONOScli3.intents( jsonFormat=True )
777 ONOS4Intents = main.ONOScli4.intents( jsonFormat=True )
778 ONOS5Intents = main.ONOScli5.intents( jsonFormat=True )
779 ONOS6Intents = main.ONOScli6.intents( jsonFormat=True )
780 ONOS7Intents = main.ONOScli7.intents( jsonFormat=True )
781 intentCheck = main.FALSE
782 if "Error" in ONOS1Intents or not ONOS1Intents\
783 or "Error" in ONOS2Intents or not ONOS2Intents\
784 or "Error" in ONOS3Intents or not ONOS3Intents\
785 or "Error" in ONOS4Intents or not ONOS4Intents\
786 or "Error" in ONOS5Intents or not ONOS5Intents\
787 or "Error" in ONOS6Intents or not ONOS6Intents\
788 or "Error" in ONOS7Intents or not ONOS7Intents:
Jon Hall6aec96b2015-01-19 14:49:31 -0800789 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800790 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
791 main.log.warn( "ONOS2 intents response: " + repr( ONOS2Intents ) )
792 main.log.warn( "ONOS3 intents response: " + repr( ONOS3Intents ) )
793 main.log.warn( "ONOS4 intents response: " + repr( ONOS4Intents ) )
794 main.log.warn( "ONOS5 intents response: " + repr( ONOS5Intents ) )
795 main.log.warn( "ONOS6 intents response: " + repr( ONOS6Intents ) )
796 main.log.warn( "ONOS7 intents response: " + repr( ONOS7Intents ) )
797 elif ONOS1Intents == ONOS2Intents\
798 and ONOS1Intents == ONOS3Intents\
799 and ONOS1Intents == ONOS4Intents\
800 and ONOS1Intents == ONOS5Intents\
801 and ONOS1Intents == ONOS6Intents\
802 and ONOS1Intents == ONOS7Intents:
803 intentState = ONOS1Intents
804 intentCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800805 main.log.report( "Intents are consistent across all ONOS nodes" )
Jon Hallb1290e82014-11-18 16:17:48 -0500806 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800807 main.log.warn(
808 "ONOS1 intents: ",
809 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800810 json.loads( ONOS1Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800811 sort_keys=True,
812 indent=4,
813 separators=(
814 ',',
815 ': ' ) ) )
816 main.log.warn(
817 "ONOS2 intents: ",
818 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800819 json.loads( ONOS2Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800820 sort_keys=True,
821 indent=4,
822 separators=(
823 ',',
824 ': ' ) ) )
825 main.log.warn(
826 "ONOS3 intents: ",
827 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800828 json.loads( ONOS3Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800829 sort_keys=True,
830 indent=4,
831 separators=(
832 ',',
833 ': ' ) ) )
834 main.log.warn(
835 "ONOS4 intents: ",
836 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800837 json.loads( ONOS4Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800838 sort_keys=True,
839 indent=4,
840 separators=(
841 ',',
842 ': ' ) ) )
843 main.log.warn(
844 "ONOS5 intents: ",
845 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800846 json.loads( ONOS5Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800847 sort_keys=True,
848 indent=4,
849 separators=(
850 ',',
851 ': ' ) ) )
852 main.log.warn(
853 "ONOS6 intents: ",
854 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800855 json.loads( ONOS6Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800856 sort_keys=True,
857 indent=4,
858 separators=(
859 ',',
860 ': ' ) ) )
861 main.log.warn(
862 "ONOS7 intents: ",
863 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800864 json.loads( ONOS7Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800865 sort_keys=True,
866 indent=4,
867 separators=(
868 ',',
869 ': ' ) ) )
870 utilities.assert_equals(
871 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800872 actual=intentCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800873 onpass="Intents are consistent across all ONOS nodes",
874 onfail="ONOS nodes have different views of intents" )
Jon Hallb1290e82014-11-18 16:17:48 -0500875
Jon Hall6aec96b2015-01-19 14:49:31 -0800876 main.step( "Get the flows from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800877 global flowState
878 flowState = []
Jon Hall8f89dda2015-01-22 16:03:33 -0800879 flowCheck = main.FALSE
Jon Hall58c76b72015-02-23 11:09:24 -0800880 try:
881 ONOS1Flows = main.ONOScli1.flows( jsonFormat=True )
882 ONOS2Flows = main.ONOScli2.flows( jsonFormat=True )
883 ONOS3Flows = main.ONOScli3.flows( jsonFormat=True )
884 ONOS4Flows = main.ONOScli4.flows( jsonFormat=True )
885 ONOS5Flows = main.ONOScli5.flows( jsonFormat=True )
886 ONOS6Flows = main.ONOScli6.flows( jsonFormat=True )
887 ONOS7Flows = main.ONOScli7.flows( jsonFormat=True )
888 assert ONOS1Flows, "ONOS1 Flows should not be empty"
889 assert ONOS2Flows, "ONOS2 Flows should not be empty"
890 assert ONOS3Flows, "ONOS3 Flows should not be empty"
891 assert ONOS4Flows, "ONOS4 Flows should not be empty"
892 assert ONOS5Flows, "ONOS5 Flows should not be empty"
893 assert ONOS6Flows, "ONOS6 Flows should not be empty"
894 assert ONOS7Flows, "ONOS7 Flows should not be empty"
895 assert "Error" not in ONOS1Flows, "ONOS1 Flows contains 'Error'"
896 assert "Error" not in ONOS2Flows, "ONOS2 Flows contains 'Error'"
897 assert "Error" not in ONOS3Flows, "ONOS3 Flows contains 'Error'"
898 assert "Error" not in ONOS4Flows, "ONOS4 Flows contains 'Error'"
899 assert "Error" not in ONOS5Flows, "ONOS5 Flows contains 'Error'"
900 assert "Error" not in ONOS6Flows, "ONOS6 Flows contains 'Error'"
901 assert "Error" not in ONOS7Flows, "ONOS7 Flows contains 'Error'"
902 ONOS1FlowsJson = json.loads( ONOS1Flows )
903 ONOS2FlowsJson = json.loads( ONOS2Flows )
904 ONOS3FlowsJson = json.loads( ONOS3Flows )
905 ONOS4FlowsJson = json.loads( ONOS4Flows )
906 ONOS5FlowsJson = json.loads( ONOS5Flows )
907 ONOS6FlowsJson = json.loads( ONOS6Flows )
908 ONOS7FlowsJson = json.loads( ONOS7Flows )
909 except ( ValueError, AssertionError ): # From json.loads, or asserts
910 main.log.exception( "One or more 'flows' responses from " +
911 "ONOS couldn't be decoded." )
Jon Hall8f89dda2015-01-22 16:03:33 -0800912 main.log.warn( "ONOS1 flows repsponse: " + ONOS1Flows )
913 main.log.warn( "ONOS2 flows repsponse: " + ONOS2Flows )
914 main.log.warn( "ONOS3 flows repsponse: " + ONOS3Flows )
915 main.log.warn( "ONOS4 flows repsponse: " + ONOS4Flows )
916 main.log.warn( "ONOS5 flows repsponse: " + ONOS5Flows )
917 main.log.warn( "ONOS6 flows repsponse: " + ONOS6Flows )
918 main.log.warn( "ONOS7 flows repsponse: " + ONOS7Flows )
Jon Hall58c76b72015-02-23 11:09:24 -0800919 else: # No exceptions
920 if len( ONOS1FlowsJson ) == len( ONOS2FlowsJson )\
921 and len( ONOS1FlowsJson ) == len( ONOS3FlowsJson )\
922 and len( ONOS1FlowsJson ) == len( ONOS4FlowsJson )\
923 and len( ONOS1FlowsJson ) == len( ONOS5FlowsJson )\
924 and len( ONOS1FlowsJson ) == len( ONOS6FlowsJson )\
925 and len( ONOS1FlowsJson ) == len( ONOS7FlowsJson ):
Jon Hall6aec96b2015-01-19 14:49:31 -0800926 # TODO: Do a better check, maybe compare flows on switches?
Jon Hall58c76b72015-02-23 11:09:24 -0800927 # NOTE Possible issue with this not always being set?
928 flowState = ONOS1Flows
929 flowCheck = main.TRUE
930 main.log.report( "Flow count is consistent across all" +
931 " ONOS nodes" )
932 else:
933 main.log.warn( "ONOS1 flows: " +
934 json.dumps( ONOS1FlowsJson, sort_keys=True,
935 indent=4,
936 separators=( ',', ': ' ) ) )
937 main.log.warn( "ONOS2 flows: " +
938 json.dumps( ONOS2FlowsJson, sort_keys=True,
939 indent=4,
940 separators=( ',', ': ' ) ) )
941 main.log.warn( "ONOS3 flows: " +
942 json.dumps( ONOS3FlowsJson, sort_keys=True,
943 indent=4,
944 separators=( ',', ': ' ) ) )
945 main.log.warn( "ONOS4 flows: " +
946 json.dumps( ONOS4FlowsJson, sort_keys=True,
947 indent=4,
948 separators=( ',', ': ' ) ) )
949 main.log.warn( "ONOS5 flows: " +
950 json.dumps( ONOS5FlowsJson, sort_keys=True,
951 indent=4,
952 separators=( ',', ': ' ) ) )
953 main.log.warn( "ONOS6 flows: " +
954 json.dumps( ONOS6FlowsJson, sort_keys=True,
955 indent=4,
956 separators=( ',', ': ' ) ) )
957 main.log.warn( "ONOS7 flows: " +
958 json.dumps( ONOS7FlowsJson, sort_keys=True,
959 indent=4,
960 separators=( ',', ': ' ) ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800961 utilities.assert_equals(
962 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800963 actual=flowCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800964 onpass="The flow count is consistent across all ONOS nodes",
965 onfail="ONOS nodes have different flow counts" )
Jon Hallb1290e82014-11-18 16:17:48 -0500966
Jon Hall6aec96b2015-01-19 14:49:31 -0800967 main.step( "Get the OF Table entries" )
Jon Hallb1290e82014-11-18 16:17:48 -0500968 global flows
Jon Hall6aec96b2015-01-19 14:49:31 -0800969 flows = []
970 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800971 flows.append( main.Mininet2.getFlowTable( 1.3, "s" + str( i ) ) )
Jon Hall58c76b72015-02-23 11:09:24 -0800972 if flowCheck == main.FALSE:
973 for table in flows:
974 main.log.warn( table )
Jon Hall6aec96b2015-01-19 14:49:31 -0800975 # TODO: Compare switch flow tables with ONOS flow tables
Jon Hallb1290e82014-11-18 16:17:48 -0500976
Jon Hall6aec96b2015-01-19 14:49:31 -0800977 main.step( "Start continuous pings" )
978 main.Mininet2.pingLong(
979 src=main.params[ 'PING' ][ 'source1' ],
980 target=main.params[ 'PING' ][ 'target1' ],
981 pingTime=500 )
982 main.Mininet2.pingLong(
983 src=main.params[ 'PING' ][ 'source2' ],
984 target=main.params[ 'PING' ][ 'target2' ],
985 pingTime=500 )
986 main.Mininet2.pingLong(
987 src=main.params[ 'PING' ][ 'source3' ],
988 target=main.params[ 'PING' ][ 'target3' ],
989 pingTime=500 )
990 main.Mininet2.pingLong(
991 src=main.params[ 'PING' ][ 'source4' ],
992 target=main.params[ 'PING' ][ 'target4' ],
993 pingTime=500 )
994 main.Mininet2.pingLong(
995 src=main.params[ 'PING' ][ 'source5' ],
996 target=main.params[ 'PING' ][ 'target5' ],
997 pingTime=500 )
998 main.Mininet2.pingLong(
999 src=main.params[ 'PING' ][ 'source6' ],
1000 target=main.params[ 'PING' ][ 'target6' ],
1001 pingTime=500 )
1002 main.Mininet2.pingLong(
1003 src=main.params[ 'PING' ][ 'source7' ],
1004 target=main.params[ 'PING' ][ 'target7' ],
1005 pingTime=500 )
1006 main.Mininet2.pingLong(
1007 src=main.params[ 'PING' ][ 'source8' ],
1008 target=main.params[ 'PING' ][ 'target8' ],
1009 pingTime=500 )
1010 main.Mininet2.pingLong(
1011 src=main.params[ 'PING' ][ 'source9' ],
1012 target=main.params[ 'PING' ][ 'target9' ],
1013 pingTime=500 )
1014 main.Mininet2.pingLong(
1015 src=main.params[ 'PING' ][ 'source10' ],
1016 target=main.params[ 'PING' ][ 'target10' ],
1017 pingTime=500 )
Jon Hallb1290e82014-11-18 16:17:48 -05001018
Jon Hall6aec96b2015-01-19 14:49:31 -08001019 main.step( "Create TestONTopology object" )
Jon Hallb1290e82014-11-18 16:17:48 -05001020 ctrls = []
1021 count = 1
1022 while True:
1023 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -08001024 if ( 'ip' + str( count ) ) in main.params[ 'CTRL' ]:
1025 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
1026 temp = temp + ( "ONOS" + str( count ), )
1027 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
1028 temp = temp + \
1029 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
1030 ctrls.append( temp )
Jon Hallb1290e82014-11-18 16:17:48 -05001031 count = count + 1
1032 else:
1033 break
Jon Hall6aec96b2015-01-19 14:49:31 -08001034 MNTopo = TestONTopology(
1035 main.Mininet1,
1036 ctrls ) # can also add Intent API info for intent operations
Jon Hallb1290e82014-11-18 16:17:48 -05001037
Jon Hall6aec96b2015-01-19 14:49:31 -08001038 main.step( "Collecting topology information from ONOS" )
Jon Hallb1290e82014-11-18 16:17:48 -05001039 devices = []
1040 devices.append( main.ONOScli1.devices() )
1041 devices.append( main.ONOScli2.devices() )
1042 devices.append( main.ONOScli3.devices() )
1043 devices.append( main.ONOScli4.devices() )
1044 devices.append( main.ONOScli5.devices() )
1045 devices.append( main.ONOScli6.devices() )
1046 devices.append( main.ONOScli7.devices() )
Jon Hallb1290e82014-11-18 16:17:48 -05001047 hosts = []
Jon Hall58c76b72015-02-23 11:09:24 -08001048 hosts.append( json.loads( main.ONOScli1.hosts() ) )
1049 hosts.append( json.loads( main.ONOScli2.hosts() ) )
1050 hosts.append( json.loads( main.ONOScli3.hosts() ) )
1051 hosts.append( json.loads( main.ONOScli4.hosts() ) )
1052 hosts.append( json.loads( main.ONOScli5.hosts() ) )
1053 hosts.append( json.loads( main.ONOScli6.hosts() ) )
1054 hosts.append( json.loads( main.ONOScli7.hosts() ) )
Jon Hallb1290e82014-11-18 16:17:48 -05001055 ports = []
1056 ports.append( main.ONOScli1.ports() )
1057 ports.append( main.ONOScli2.ports() )
1058 ports.append( main.ONOScli3.ports() )
1059 ports.append( main.ONOScli4.ports() )
1060 ports.append( main.ONOScli5.ports() )
1061 ports.append( main.ONOScli6.ports() )
1062 ports.append( main.ONOScli7.ports() )
1063 links = []
1064 links.append( main.ONOScli1.links() )
1065 links.append( main.ONOScli2.links() )
1066 links.append( main.ONOScli3.links() )
1067 links.append( main.ONOScli4.links() )
1068 links.append( main.ONOScli5.links() )
1069 links.append( main.ONOScli6.links() )
1070 links.append( main.ONOScli7.links() )
Jon Hall94fd0472014-12-08 11:52:42 -08001071 clusters = []
1072 clusters.append( main.ONOScli1.clusters() )
1073 clusters.append( main.ONOScli2.clusters() )
1074 clusters.append( main.ONOScli3.clusters() )
1075 clusters.append( main.ONOScli4.clusters() )
1076 clusters.append( main.ONOScli5.clusters() )
1077 clusters.append( main.ONOScli6.clusters() )
1078 clusters.append( main.ONOScli7.clusters() )
Jon Hall529a37f2015-01-28 10:02:00 -08001079 # Compare json objects for hosts and dataplane clusters
Jon Hall94fd0472014-12-08 11:52:42 -08001080
Jon Hall6aec96b2015-01-19 14:49:31 -08001081 # hosts
Jon Hall8f89dda2015-01-22 16:03:33 -08001082 consistentHostsResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -08001083 for controller in range( len( hosts ) ):
Jon Hall8f89dda2015-01-22 16:03:33 -08001084 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001085 if "Error" not in hosts[ controller ]:
1086 if hosts[ controller ] == hosts[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001087 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001088 else: # hosts not consistent
1089 main.log.report( "hosts from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001090 controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001091 " is inconsistent with ONOS1" )
1092 main.log.warn( repr( hosts[ controller ] ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001093 consistentHostsResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001094
1095 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001096 main.log.report( "Error in getting ONOS hosts from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001097 controllerStr )
1098 consistentHostsResult = main.FALSE
1099 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001100 " hosts response: " +
1101 repr( hosts[ controller ] ) )
1102 utilities.assert_equals(
1103 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001104 actual=consistentHostsResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001105 onpass="Hosts view is consistent across all ONOS nodes",
1106 onfail="ONOS nodes have different views of hosts" )
Jon Hall94fd0472014-12-08 11:52:42 -08001107
Jon Hall58c76b72015-02-23 11:09:24 -08001108 ipResult = main.TRUE
1109 for controller in range( 0, len( hosts ) ):
1110 controllerStr = str( controller + 1 )
1111 for host in hosts[ controller ]:
1112 if host.get( 'ips', [] ) == []:
1113 main.log.error(
1114 "DEBUG:Error with host ips on controller" +
1115 controllerStr + ": " + str( host ) )
1116 ipResult = main.FALSE
1117 utilities.assert_equals(
1118 expect=main.TRUE,
1119 actual=ipResult,
1120 onpass="The ips of the hosts aren't empty",
1121 onfail="The ip of at least one host is missing" )
1122
Jon Hall6aec96b2015-01-19 14:49:31 -08001123 # Strongly connected clusters of devices
Jon Hall8f89dda2015-01-22 16:03:33 -08001124 consistentClustersResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -08001125 for controller in range( len( clusters ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001126 if "Error" not in clusters[ controller ]:
1127 if clusters[ controller ] == clusters[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001128 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001129 else: # clusters not consistent
1130 main.log.report( "clusters from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001131 controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001132 " is inconsistent with ONOS1" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001133 consistentClustersResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001134
1135 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001136 main.log.report( "Error in getting dataplane clusters " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001137 "from ONOS" + controllerStr )
1138 consistentClustersResult = main.FALSE
1139 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001140 " clusters response: " +
1141 repr( clusters[ controller ] ) )
1142 utilities.assert_equals(
1143 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001144 actual=consistentClustersResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001145 onpass="Clusters view is consistent across all ONOS nodes",
1146 onfail="ONOS nodes have different views of clusters" )
1147 # there should always only be one cluster
Jon Hall8f89dda2015-01-22 16:03:33 -08001148 numClusters = len( json.loads( clusters[ 0 ] ) )
Jon Hall58c76b72015-02-23 11:09:24 -08001149 clusterResults = main.FALSE
1150 if numClusters == 1:
1151 clusterResults = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001152 utilities.assert_equals(
1153 expect=1,
Jon Hall8f89dda2015-01-22 16:03:33 -08001154 actual=numClusters,
Jon Hall6aec96b2015-01-19 14:49:31 -08001155 onpass="ONOS shows 1 SCC",
Jon Hall58c76b72015-02-23 11:09:24 -08001156 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
Jon Hall94fd0472014-12-08 11:52:42 -08001157
Jon Hall6aec96b2015-01-19 14:49:31 -08001158 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001159 devicesResults = main.TRUE
1160 portsResults = main.TRUE
1161 linksResults = main.TRUE
1162 for controller in range( numControllers ):
1163 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001164 if devices[ controller ] or "Error" not in devices[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001165 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -08001166 MNTopo,
1167 json.loads(
1168 devices[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001169 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001170 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001171 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001172 actual=currentDevicesResult,
1173 onpass="ONOS" + controllerStr +
1174 " Switches view is correct",
1175 onfail="ONOS" + controllerStr +
1176 " Switches view is incorrect" )
Jon Hallb1290e82014-11-18 16:17:48 -05001177
Jon Hall6aec96b2015-01-19 14:49:31 -08001178 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001179 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -08001180 MNTopo,
1181 json.loads(
1182 ports[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001183 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001184 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001185 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001186 actual=currentPortsResult,
1187 onpass="ONOS" + controllerStr +
1188 " ports view is correct",
1189 onfail="ONOS" + controllerStr +
1190 " ports view is incorrect" )
Jon Hallb1290e82014-11-18 16:17:48 -05001191
Jon Hall6aec96b2015-01-19 14:49:31 -08001192 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001193 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -08001194 MNTopo,
1195 json.loads(
1196 links[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001197 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001198 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001199 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001200 actual=currentLinksResult,
1201 onpass="ONOS" + controllerStr +
1202 " links view is correct",
1203 onfail="ONOS" + controllerStr +
1204 " links view is incorrect" )
Jon Hallb1290e82014-11-18 16:17:48 -05001205
Jon Hall8f89dda2015-01-22 16:03:33 -08001206 devicesResults = devicesResults and currentDevicesResult
1207 portsResults = portsResults and currentPortsResult
1208 linksResults = linksResults and currentLinksResult
Jon Hallb1290e82014-11-18 16:17:48 -05001209
Jon Hall8f89dda2015-01-22 16:03:33 -08001210 topoResult = devicesResults and portsResults and linksResults\
Jon Hall58c76b72015-02-23 11:09:24 -08001211 and consistentHostsResult and consistentClustersResult\
1212 and clusterResults and ipResult
Jon Hall8f89dda2015-01-22 16:03:33 -08001213 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
Jon Hall58c76b72015-02-23 11:09:24 -08001214 onpass="Topology Check Test successful",
1215 onfail="Topology Check Test NOT successful" )
Jon Hallb1290e82014-11-18 16:17:48 -05001216
Jon Hall8f89dda2015-01-22 16:03:33 -08001217 finalAssert = main.TRUE
1218 finalAssert = finalAssert and topoResult and flowCheck \
Jon Hall58c76b72015-02-23 11:09:24 -08001219 and intentCheck and consistentMastership and rolesNotNull
Jon Hall8f89dda2015-01-22 16:03:33 -08001220 utilities.assert_equals( expect=main.TRUE, actual=finalAssert,
Jon Hall58c76b72015-02-23 11:09:24 -08001221 onpass="State check successful",
1222 onfail="State check NOT successful" )
Jon Hallb1290e82014-11-18 16:17:48 -05001223
Jon Hall6aec96b2015-01-19 14:49:31 -08001224 def CASE6( self, main ):
1225 """
Jon Hallb1290e82014-11-18 16:17:48 -05001226 The Failure case. Since this is the Sanity test, we do nothing.
Jon Hall6aec96b2015-01-19 14:49:31 -08001227 """
Jon Hall368769f2014-11-19 15:43:35 -08001228 import time
Jon Hall6aec96b2015-01-19 14:49:31 -08001229 main.log.report( "Wait 60 seconds instead of inducing a failure" )
1230 time.sleep( 60 )
1231 utilities.assert_equals(
1232 expect=main.TRUE,
1233 actual=main.TRUE,
1234 onpass="Sleeping 60 seconds",
1235 onfail="Something is terribly wrong with my math" )
Jon Hallb1290e82014-11-18 16:17:48 -05001236
Jon Hall6aec96b2015-01-19 14:49:31 -08001237 def CASE7( self, main ):
1238 """
Jon Hall368769f2014-11-19 15:43:35 -08001239 Check state after ONOS failure
Jon Hall6aec96b2015-01-19 14:49:31 -08001240 """
Jon Hallb1290e82014-11-18 16:17:48 -05001241 import json
Jon Hall6aec96b2015-01-19 14:49:31 -08001242 main.case( "Running ONOS Constant State Tests" )
Jon Hallb1290e82014-11-18 16:17:48 -05001243
Jon Hall6aec96b2015-01-19 14:49:31 -08001244 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -08001245 ONOS1MasterNotNull = main.ONOScli1.rolesNotNull()
1246 ONOS2MasterNotNull = main.ONOScli2.rolesNotNull()
1247 ONOS3MasterNotNull = main.ONOScli3.rolesNotNull()
1248 ONOS4MasterNotNull = main.ONOScli4.rolesNotNull()
1249 ONOS5MasterNotNull = main.ONOScli5.rolesNotNull()
1250 ONOS6MasterNotNull = main.ONOScli6.rolesNotNull()
1251 ONOS7MasterNotNull = main.ONOScli7.rolesNotNull()
1252 rolesNotNull = ONOS1MasterNotNull and ONOS2MasterNotNull and\
1253 ONOS3MasterNotNull and ONOS4MasterNotNull and\
1254 ONOS5MasterNotNull and ONOS6MasterNotNull and\
1255 ONOS7MasterNotNull
Jon Hall6aec96b2015-01-19 14:49:31 -08001256 utilities.assert_equals(
1257 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001258 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -08001259 onpass="Each device has a master",
1260 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -08001261
Jon Hall6aec96b2015-01-19 14:49:31 -08001262 main.step( "Check if switch roles are consistent across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001263 ONOS1Mastership = main.ONOScli1.roles()
1264 ONOS2Mastership = main.ONOScli2.roles()
1265 ONOS3Mastership = main.ONOScli3.roles()
1266 ONOS4Mastership = main.ONOScli4.roles()
1267 ONOS5Mastership = main.ONOScli5.roles()
1268 ONOS6Mastership = main.ONOScli6.roles()
1269 ONOS7Mastership = main.ONOScli7.roles()
Jon Hall8f89dda2015-01-22 16:03:33 -08001270 if "Error" in ONOS1Mastership or not ONOS1Mastership\
1271 or "Error" in ONOS2Mastership or not ONOS2Mastership\
1272 or "Error" in ONOS3Mastership or not ONOS3Mastership\
1273 or "Error" in ONOS4Mastership or not ONOS4Mastership\
1274 or "Error" in ONOS5Mastership or not ONOS5Mastership\
1275 or "Error" in ONOS6Mastership or not ONOS6Mastership\
1276 or "Error" in ONOS7Mastership or not ONOS7Mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -08001277 main.log.error( "Error in getting ONOS mastership" )
1278 main.log.warn( "ONOS1 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001279 repr( ONOS1Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001280 main.log.warn( "ONOS2 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001281 repr( ONOS2Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001282 main.log.warn( "ONOS3 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001283 repr( ONOS3Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001284 main.log.warn( "ONOS4 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001285 repr( ONOS4Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001286 main.log.warn( "ONOS5 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001287 repr( ONOS5Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001288 main.log.warn( "ONOS6 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001289 repr( ONOS6Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001290 main.log.warn( "ONOS7 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001291 repr( ONOS7Mastership ) )
1292 consistentMastership = main.FALSE
1293 elif ONOS1Mastership == ONOS2Mastership\
1294 and ONOS1Mastership == ONOS3Mastership\
1295 and ONOS1Mastership == ONOS4Mastership\
1296 and ONOS1Mastership == ONOS5Mastership\
1297 and ONOS1Mastership == ONOS6Mastership\
1298 and ONOS1Mastership == ONOS7Mastership:
1299 consistentMastership = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001300 main.log.report(
1301 "Switch roles are consistent across all ONOS nodes" )
Jon Hallb1290e82014-11-18 16:17:48 -05001302 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001303 main.log.warn( "ONOS1 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001304 json.loads( ONOS1Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001305 separators=( ',', ': ' ) ) )
1306 main.log.warn( "ONOS2 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001307 json.loads( ONOS2Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001308 separators=( ',', ': ' ) ) )
1309 main.log.warn( "ONOS3 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001310 json.loads( ONOS3Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001311 separators=( ',', ': ' ) ) )
1312 main.log.warn( "ONOS4 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001313 json.loads( ONOS4Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001314 separators=( ',', ': ' ) ) )
1315 main.log.warn( "ONOS5 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001316 json.loads( ONOS5Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001317 separators=( ',', ': ' ) ) )
1318 main.log.warn( "ONOS6 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001319 json.loads( ONOS6Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001320 separators=( ',', ': ' ) ) )
1321 main.log.warn( "ONOS7 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001322 json.loads( ONOS7Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001323 separators=( ',', ': ' ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001324 consistentMastership = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001325 utilities.assert_equals(
1326 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001327 actual=consistentMastership,
Jon Hall6aec96b2015-01-19 14:49:31 -08001328 onpass="Switch roles are consistent across all ONOS nodes",
1329 onfail="ONOS nodes have different views of switch roles" )
Jon Hallb1290e82014-11-18 16:17:48 -05001330
1331 description2 = "Compare switch roles from before failure"
Jon Hall6aec96b2015-01-19 14:49:31 -08001332 main.step( description2 )
Jon Hallb1290e82014-11-18 16:17:48 -05001333
Jon Hall8f89dda2015-01-22 16:03:33 -08001334 currentJson = json.loads( ONOS1Mastership )
1335 oldJson = json.loads( mastershipState )
1336 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001337 for i in range( 1, 29 ):
1338 switchDPID = str(
1339 main.Mininet1.getSwitchDPID(
1340 switch="s" +
1341 str( i ) ) )
Jon Hallb1290e82014-11-18 16:17:48 -05001342
Jon Hall8f89dda2015-01-22 16:03:33 -08001343 current = [ switch[ 'master' ] for switch in currentJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001344 if switchDPID in switch[ 'id' ] ]
Jon Hall8f89dda2015-01-22 16:03:33 -08001345 old = [ switch[ 'master' ] for switch in oldJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001346 if switchDPID in switch[ 'id' ] ]
Jon Hallb1290e82014-11-18 16:17:48 -05001347 if current == old:
Jon Hall8f89dda2015-01-22 16:03:33 -08001348 mastershipCheck = mastershipCheck and main.TRUE
Jon Hallb1290e82014-11-18 16:17:48 -05001349 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001350 main.log.warn( "Mastership of switch %s changed" % switchDPID )
Jon Hall8f89dda2015-01-22 16:03:33 -08001351 mastershipCheck = main.FALSE
1352 if mastershipCheck == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001353 main.log.report( "Mastership of Switches was not changed" )
1354 utilities.assert_equals(
1355 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001356 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -08001357 onpass="Mastership of Switches was not changed",
1358 onfail="Mastership of some switches changed" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001359 mastershipCheck = mastershipCheck and consistentMastership
Jon Hallb1290e82014-11-18 16:17:48 -05001360
Jon Hall6aec96b2015-01-19 14:49:31 -08001361 main.step( "Get the intents and compare across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001362 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
1363 ONOS2Intents = main.ONOScli2.intents( jsonFormat=True )
1364 ONOS3Intents = main.ONOScli3.intents( jsonFormat=True )
1365 ONOS4Intents = main.ONOScli4.intents( jsonFormat=True )
1366 ONOS5Intents = main.ONOScli5.intents( jsonFormat=True )
1367 ONOS6Intents = main.ONOScli6.intents( jsonFormat=True )
1368 ONOS7Intents = main.ONOScli7.intents( jsonFormat=True )
1369 intentCheck = main.FALSE
1370 if "Error" in ONOS1Intents or not ONOS1Intents\
1371 or "Error" in ONOS2Intents or not ONOS2Intents\
1372 or "Error" in ONOS3Intents or not ONOS3Intents\
1373 or "Error" in ONOS4Intents or not ONOS4Intents\
1374 or "Error" in ONOS5Intents or not ONOS5Intents\
1375 or "Error" in ONOS6Intents or not ONOS6Intents\
1376 or "Error" in ONOS7Intents or not ONOS7Intents:
Jon Hall6aec96b2015-01-19 14:49:31 -08001377 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001378 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
1379 main.log.warn( "ONOS2 intents response: " + repr( ONOS2Intents ) )
1380 main.log.warn( "ONOS3 intents response: " + repr( ONOS3Intents ) )
1381 main.log.warn( "ONOS4 intents response: " + repr( ONOS4Intents ) )
1382 main.log.warn( "ONOS5 intents response: " + repr( ONOS5Intents ) )
1383 main.log.warn( "ONOS6 intents response: " + repr( ONOS6Intents ) )
1384 main.log.warn( "ONOS7 intents response: " + repr( ONOS7Intents ) )
1385 elif ONOS1Intents == ONOS2Intents\
1386 and ONOS1Intents == ONOS3Intents\
1387 and ONOS1Intents == ONOS4Intents\
1388 and ONOS1Intents == ONOS5Intents\
1389 and ONOS1Intents == ONOS6Intents\
1390 and ONOS1Intents == ONOS7Intents:
1391 intentCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001392 main.log.report( "Intents are consistent across all ONOS nodes" )
Jon Hallb1290e82014-11-18 16:17:48 -05001393 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001394 main.log.warn( "ONOS1 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001395 print json.dumps( json.loads( ONOS1Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001396 indent=4, separators=( ',', ': ' ) )
1397 main.log.warn( "ONOS2 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001398 print json.dumps( json.loads( ONOS2Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001399 indent=4, separators=( ',', ': ' ) )
1400 main.log.warn( "ONOS3 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001401 print json.dumps( json.loads( ONOS3Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001402 indent=4, separators=( ',', ': ' ) )
1403 main.log.warn( "ONOS4 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001404 print json.dumps( json.loads( ONOS4Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001405 indent=4, separators=( ',', ': ' ) )
1406 main.log.warn( "ONOS5 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001407 print json.dumps( json.loads( ONOS5Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001408 indent=4, separators=( ',', ': ' ) )
1409 main.log.warn( "ONOS6 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001410 print json.dumps( json.loads( ONOS6Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001411 indent=4, separators=( ',', ': ' ) )
1412 main.log.warn( "ONOS7 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001413 print json.dumps( json.loads( ONOS7Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001414 indent=4, separators=( ',', ': ' ) )
1415 utilities.assert_equals(
1416 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001417 actual=intentCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -08001418 onpass="Intents are consistent across all ONOS nodes",
1419 onfail="ONOS nodes have different views of intents" )
Jon Hall1b8f54a2015-02-04 13:24:20 -08001420 # Print the intent states
1421 intents = []
1422 intents.append( ONOS1Intents )
1423 intents.append( ONOS2Intents )
1424 intents.append( ONOS3Intents )
1425 intents.append( ONOS4Intents )
1426 intents.append( ONOS5Intents )
1427 intents.append( ONOS6Intents )
1428 intents.append( ONOS7Intents )
1429 intentStates = []
1430 for node in intents: # Iter through ONOS nodes
1431 nodeStates = []
Jon Hall58c76b72015-02-23 11:09:24 -08001432 # Iter through intents of a node
1433 for intent in json.loads( node ):
Jon Hall1b8f54a2015-02-04 13:24:20 -08001434 nodeStates.append( intent[ 'state' ] )
1435 intentStates.append( nodeStates )
1436 out = [ (i, nodeStates.count( i ) ) for i in set( nodeStates ) ]
1437 main.log.info( dict( out ) )
1438
Jon Hall58c76b72015-02-23 11:09:24 -08001439 # NOTE: Store has no durability, so intents are lost across system
1440 # restarts
Jon Hall6aec96b2015-01-19 14:49:31 -08001441 main.step( "Compare current intents with intents before the failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001442 # NOTE: this requires case 5 to pass for intentState to be set.
Jon Hall94fd0472014-12-08 11:52:42 -08001443 # maybe we should stop the test if that fails?
Jon Hall1b8f54a2015-02-04 13:24:20 -08001444 sameIntents = main.TRUE
1445 if intentState and intentState == ONOS1Intents:
Jon Hall8f89dda2015-01-22 16:03:33 -08001446 sameIntents = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001447 main.log.report( "Intents are consistent with before failure" )
1448 # TODO: possibly the states have changed? we may need to figure out
1449 # what the aceptable states are
Jon Hallb1290e82014-11-18 16:17:48 -05001450 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001451 try:
1452 main.log.warn( "ONOS1 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001453 print json.dumps( json.loads( ONOS1Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -08001454 sort_keys=True, indent=4,
1455 separators=( ',', ': ' ) )
1456 except:
1457 pass
Jon Hall8f89dda2015-01-22 16:03:33 -08001458 sameIntents = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001459 utilities.assert_equals(
1460 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001461 actual=sameIntents,
Jon Hall6aec96b2015-01-19 14:49:31 -08001462 onpass="Intents are consistent with before failure",
1463 onfail="The Intents changed during failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001464 intentCheck = intentCheck and sameIntents
Jon Hallb1290e82014-11-18 16:17:48 -05001465
Jon Hall6aec96b2015-01-19 14:49:31 -08001466 main.step( "Get the OF Table entries and compare to before " +
1467 "component failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001468 FlowTables = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001469 flows2 = []
1470 for i in range( 28 ):
1471 main.log.info( "Checking flow table on s" + str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001472 tmpFlows = main.Mininet2.getFlowTable( 1.3, "s" + str( i + 1 ) )
1473 flows2.append( tmpFlows )
1474 tempResult = main.Mininet2.flowComp(
Jon Hall6aec96b2015-01-19 14:49:31 -08001475 flow1=flows[ i ],
Jon Hall8f89dda2015-01-22 16:03:33 -08001476 flow2=tmpFlows )
1477 FlowTables = FlowTables and tempResult
1478 if FlowTables == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001479 main.log.info( "Differences in flow table for switch: s" +
1480 str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001481 if FlowTables == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001482 main.log.report( "No changes were found in the flow tables" )
1483 utilities.assert_equals(
1484 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001485 actual=FlowTables,
Jon Hall6aec96b2015-01-19 14:49:31 -08001486 onpass="No changes were found in the flow tables",
1487 onfail="Changes were found in the flow tables" )
Jon Hallb1290e82014-11-18 16:17:48 -05001488
Jon Hall6aec96b2015-01-19 14:49:31 -08001489 main.step( "Check the continuous pings to ensure that no packets " +
1490 "were dropped during component failure" )
1491 # FIXME: This check is always failing. Investigate cause
1492 # NOTE: this may be something to do with file permsissions
Jon Hallb1290e82014-11-18 16:17:48 -05001493 # or slight change in format
Jon Hall6aec96b2015-01-19 14:49:31 -08001494 main.Mininet2.pingKill(
1495 main.params[ 'TESTONUSER' ],
1496 main.params[ 'TESTONIP' ] )
Jon Hall8f89dda2015-01-22 16:03:33 -08001497 LossInPings = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001498 # NOTE: checkForLoss returns main.FALSE with 0% packet loss
1499 for i in range( 8, 18 ):
1500 main.log.info(
1501 "Checking for a loss in pings along flow from s" +
1502 str( i ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001503 LossInPings = main.Mininet2.checkForLoss(
Jon Hall6aec96b2015-01-19 14:49:31 -08001504 "/tmp/ping.h" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001505 str( i ) ) or LossInPings
1506 if LossInPings == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001507 main.log.info( "Loss in ping detected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001508 elif LossInPings == main.ERROR:
Jon Hall6aec96b2015-01-19 14:49:31 -08001509 main.log.info( "There are multiple mininet process running" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001510 elif LossInPings == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001511 main.log.info( "No Loss in the pings" )
1512 main.log.report( "No loss of dataplane connectivity" )
1513 utilities.assert_equals(
1514 expect=main.FALSE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001515 actual=LossInPings,
Jon Hall6aec96b2015-01-19 14:49:31 -08001516 onpass="No Loss of connectivity",
1517 onfail="Loss of dataplane connectivity detected" )
Jon Hallb1290e82014-11-18 16:17:48 -05001518
Jon Hall6aec96b2015-01-19 14:49:31 -08001519 # Test of LeadershipElection
1520 # NOTE: this only works for the sanity test. In case of failures,
Jon Hall58c76b72015-02-23 11:09:24 -08001521 # leader will likely change
Jon Hall8f89dda2015-01-22 16:03:33 -08001522 leader = ONOS1Ip
1523 leaderResult = main.TRUE
1524 for controller in range( 1, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001525 # loop through ONOScli handlers
1526 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001527 leaderN = node.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001528 # verify leader is ONOS1
Jon Hall669173b2014-12-17 11:36:30 -08001529 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08001530 # all is well
1531 # NOTE: In failure scenario, this could be a new node, maybe
1532 # check != ONOS1
Jon Hall669173b2014-12-17 11:36:30 -08001533 pass
1534 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001535 # error in response
1536 main.log.report( "Something is wrong with " +
Jon Hall58c76b72015-02-23 11:09:24 -08001537 "electionTestLeader function, check the" +
1538 " error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001539 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001540 elif leader != leaderN:
Jon Hall8f89dda2015-01-22 16:03:33 -08001541 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001542 main.log.report( "ONOS" + str( controller ) + " sees " +
1543 str( leaderN ) +
1544 " as the leader of the election app. " +
1545 "Leader should be " + str( leader ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001546 if leaderResult:
1547 main.log.report( "Leadership election tests passed( consistent " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001548 "view of leader across listeners and a new " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001549 "leader was re-elected if applicable )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001550 utilities.assert_equals(
1551 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001552 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001553 onpass="Leadership election passed",
1554 onfail="Something went wrong with Leadership election" )
Jon Hallb1290e82014-11-18 16:17:48 -05001555
Jon Hall58c76b72015-02-23 11:09:24 -08001556 result = ( mastershipCheck and intentCheck and FlowTables and
1557 ( not LossInPings ) and rolesNotNull and leaderResult )
Jon Hall6aec96b2015-01-19 14:49:31 -08001558 result = int( result )
Jon Hallb1290e82014-11-18 16:17:48 -05001559 if result == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001560 main.log.report( "Constant State Tests Passed" )
1561 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall58c76b72015-02-23 11:09:24 -08001562 onpass="Constant State Tests Passed",
1563 onfail="Constant state tests failed" )
Jon Hallb1290e82014-11-18 16:17:48 -05001564
Jon Hall6aec96b2015-01-19 14:49:31 -08001565 def CASE8( self, main ):
1566 """
Jon Hallb1290e82014-11-18 16:17:48 -05001567 Compare topo
Jon Hall6aec96b2015-01-19 14:49:31 -08001568 """
Jon Hallb1290e82014-11-18 16:17:48 -05001569 import sys
Jon Hall6aec96b2015-01-19 14:49:31 -08001570 # FIXME add this path to params
1571 sys.path.append( "/home/admin/sts" )
1572 # assumes that sts is already in you PYTHONPATH
1573 from sts.topology.teston_topology import TestONTopology
Jon Hallb1290e82014-11-18 16:17:48 -05001574 import json
Jon Hall73cf9cc2014-11-20 22:28:38 -08001575 import time
Jon Hallb1290e82014-11-18 16:17:48 -05001576
Jon Hall6aec96b2015-01-19 14:49:31 -08001577 description = "Compare ONOS Topology view to Mininet topology"
1578 main.case( description )
1579 main.log.report( description )
1580 main.step( "Create TestONTopology object" )
Jon Hallb1290e82014-11-18 16:17:48 -05001581 ctrls = []
1582 count = 1
1583 while True:
1584 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -08001585 if ( 'ip' + str( count ) ) in main.params[ 'CTRL' ]:
1586 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
1587 temp = temp + ( "ONOS" + str( count ), )
1588 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
1589 temp = temp + \
1590 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
1591 ctrls.append( temp )
Jon Hallb1290e82014-11-18 16:17:48 -05001592 count = count + 1
1593 else:
1594 break
Jon Hall6aec96b2015-01-19 14:49:31 -08001595 MNTopo = TestONTopology(
1596 main.Mininet1,
1597 ctrls ) # can also add Intent API info for intent operations
Jon Hallb1290e82014-11-18 16:17:48 -05001598
Jon Hall6aec96b2015-01-19 14:49:31 -08001599 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001600 devicesResults = main.TRUE
1601 portsResults = main.TRUE
1602 linksResults = main.TRUE
Jon Hall58c76b72015-02-23 11:09:24 -08001603 hostsResults = main.TRUE
Jon Hall8f89dda2015-01-22 16:03:33 -08001604 topoResult = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001605 elapsed = 0
Jon Hallffb386d2014-11-21 13:43:38 -08001606 count = 0
Jon Hall6aec96b2015-01-19 14:49:31 -08001607 main.step( "Collecting topology information from ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001608 startTime = time.time()
Jon Hall21270ac2015-02-16 17:59:55 -08001609 # Give time for Gossip to work
Jon Hall8f89dda2015-01-22 16:03:33 -08001610 while topoResult == main.FALSE and elapsed < 60:
Jon Hallffb386d2014-11-21 13:43:38 -08001611 count = count + 1
Jon Hall94fd0472014-12-08 11:52:42 -08001612 if count > 1:
Jon Hall6aec96b2015-01-19 14:49:31 -08001613 # TODO: Depricate STS usage
Jon Hall58c76b72015-02-23 11:09:24 -08001614 MNTopo = TestONTopology( main.Mininet1, ctrls )
Jon Hall8f89dda2015-01-22 16:03:33 -08001615 cliStart = time.time()
Jon Hall94fd0472014-12-08 11:52:42 -08001616 devices = []
1617 devices.append( main.ONOScli1.devices() )
1618 devices.append( main.ONOScli2.devices() )
1619 devices.append( main.ONOScli3.devices() )
1620 devices.append( main.ONOScli4.devices() )
1621 devices.append( main.ONOScli5.devices() )
1622 devices.append( main.ONOScli6.devices() )
1623 devices.append( main.ONOScli7.devices() )
1624 hosts = []
Jon Hall529a37f2015-01-28 10:02:00 -08001625 hosts.append( json.loads( main.ONOScli1.hosts() ) )
1626 hosts.append( json.loads( main.ONOScli2.hosts() ) )
1627 hosts.append( json.loads( main.ONOScli3.hosts() ) )
1628 hosts.append( json.loads( main.ONOScli4.hosts() ) )
1629 hosts.append( json.loads( main.ONOScli5.hosts() ) )
1630 hosts.append( json.loads( main.ONOScli6.hosts() ) )
1631 hosts.append( json.loads( main.ONOScli7.hosts() ) )
Jon Hall58c76b72015-02-23 11:09:24 -08001632 ipResult = main.TRUE
Jon Hall529a37f2015-01-28 10:02:00 -08001633 for controller in range( 0, len( hosts ) ):
1634 controllerStr = str( controller + 1 )
1635 for host in hosts[ controller ]:
Jon Hall58c76b72015-02-23 11:09:24 -08001636 if host is None or host.get( 'ips', [] ) == []:
Jon Hall529a37f2015-01-28 10:02:00 -08001637 main.log.error(
1638 "DEBUG:Error with host ips on controller" +
1639 controllerStr + ": " + str( host ) )
Jon Hall58c76b72015-02-23 11:09:24 -08001640 ipResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001641 ports = []
1642 ports.append( main.ONOScli1.ports() )
1643 ports.append( main.ONOScli2.ports() )
1644 ports.append( main.ONOScli3.ports() )
1645 ports.append( main.ONOScli4.ports() )
1646 ports.append( main.ONOScli5.ports() )
1647 ports.append( main.ONOScli6.ports() )
1648 ports.append( main.ONOScli7.ports() )
1649 links = []
1650 links.append( main.ONOScli1.links() )
1651 links.append( main.ONOScli2.links() )
1652 links.append( main.ONOScli3.links() )
1653 links.append( main.ONOScli4.links() )
1654 links.append( main.ONOScli5.links() )
1655 links.append( main.ONOScli6.links() )
1656 links.append( main.ONOScli7.links() )
1657 clusters = []
1658 clusters.append( main.ONOScli1.clusters() )
1659 clusters.append( main.ONOScli2.clusters() )
1660 clusters.append( main.ONOScli3.clusters() )
1661 clusters.append( main.ONOScli4.clusters() )
1662 clusters.append( main.ONOScli5.clusters() )
1663 clusters.append( main.ONOScli6.clusters() )
1664 clusters.append( main.ONOScli7.clusters() )
Jon Hallb1290e82014-11-18 16:17:48 -05001665
Jon Hall8f89dda2015-01-22 16:03:33 -08001666 elapsed = time.time() - startTime
1667 cliTime = time.time() - cliStart
1668 print "CLI time: " + str( cliTime )
Jon Hallb1290e82014-11-18 16:17:48 -05001669
Jon Hall21270ac2015-02-16 17:59:55 -08001670 for controller in range( numControllers ):
1671 controllerStr = str( controller + 1 )
1672 if devices[ controller ] or "Error" not in devices[
1673 controller ]:
1674 currentDevicesResult = main.Mininet1.compareSwitches(
1675 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001676 json.loads( devices[ controller ] ) )
Jon Hall21270ac2015-02-16 17:59:55 -08001677 else:
1678 currentDevicesResult = main.FALSE
1679 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001680 actual=currentDevicesResult,
1681 onpass="ONOS" + controllerStr +
1682 " Switches view is correct",
1683 onfail="ONOS" + controllerStr +
1684 " Switches view is incorrect" )
Jon Hallb1290e82014-11-18 16:17:48 -05001685
Jon Hall21270ac2015-02-16 17:59:55 -08001686 if ports[ controller ] or "Error" not in ports[ controller ]:
1687 currentPortsResult = main.Mininet1.comparePorts(
1688 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001689 json.loads( ports[ controller ] ) )
Jon Hall21270ac2015-02-16 17:59:55 -08001690 else:
1691 currentPortsResult = main.FALSE
1692 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001693 actual=currentPortsResult,
1694 onpass="ONOS" + controllerStr +
1695 " ports view is correct",
1696 onfail="ONOS" + controllerStr +
1697 " ports view is incorrect" )
Jon Hall94fd0472014-12-08 11:52:42 -08001698
Jon Hall21270ac2015-02-16 17:59:55 -08001699 if links[ controller ] or "Error" not in links[ controller ]:
1700 currentLinksResult = main.Mininet1.compareLinks(
1701 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001702 json.loads( links[ controller ] ) )
Jon Hall21270ac2015-02-16 17:59:55 -08001703 else:
1704 currentLinksResult = main.FALSE
1705 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001706 actual=currentLinksResult,
1707 onpass="ONOS" + controllerStr +
1708 " links view is correct",
1709 onfail="ONOS" + controllerStr +
1710 " links view is incorrect" )
1711
1712 if hosts[ controller ] or "Error" not in hosts[ controller ]:
1713 currentHostsResult = main.Mininet1.compareHosts(
1714 MNTopo, hosts[ controller ] )
1715 else:
1716 currentHostsResult = main.FALSE
1717 utilities.assert_equals( expect=main.TRUE,
1718 actual=currentHostsResult,
1719 onpass="ONOS" + controllerStr +
1720 " hosts exist in Mininet",
1721 onfail="ONOS" + controllerStr +
1722 " hosts don't match Mininet" )
1723
1724 devicesResults = devicesResults and currentDevicesResult
1725 portsResults = portsResults and currentPortsResult
1726 linksResults = linksResults and currentLinksResult
1727 hostsResults = hostsResults and currentHostsResult
Jon Hall94fd0472014-12-08 11:52:42 -08001728
Jon Hall21270ac2015-02-16 17:59:55 -08001729 # Compare json objects for hosts and dataplane clusters
Jon Hall94fd0472014-12-08 11:52:42 -08001730
Jon Hall21270ac2015-02-16 17:59:55 -08001731 # hosts
1732 consistentHostsResult = main.TRUE
1733 for controller in range( len( hosts ) ):
1734 controllerStr = str( controller + 1 )
1735 if "Error" not in hosts[ controller ]:
1736 if hosts[ controller ] == hosts[ 0 ]:
1737 continue
1738 else: # hosts not consistent
1739 main.log.report( "hosts from ONOS" + controllerStr +
1740 " is inconsistent with ONOS1" )
1741 main.log.warn( repr( hosts[ controller ] ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001742 consistentHostsResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001743
Jon Hall21270ac2015-02-16 17:59:55 -08001744 else:
1745 main.log.report( "Error in getting ONOS hosts from ONOS" +
1746 controllerStr )
1747 consistentHostsResult = main.FALSE
1748 main.log.warn( "ONOS" + controllerStr +
1749 " hosts response: " +
1750 repr( hosts[ controller ] ) )
1751 utilities.assert_equals(
1752 expect=main.TRUE,
1753 actual=consistentHostsResult,
1754 onpass="Hosts view is consistent across all ONOS nodes",
1755 onfail="ONOS nodes have different views of hosts" )
Jon Hall94fd0472014-12-08 11:52:42 -08001756
Jon Hall21270ac2015-02-16 17:59:55 -08001757 # Strongly connected clusters of devices
1758 consistentClustersResult = main.TRUE
1759 for controller in range( len( clusters ) ):
1760 controllerStr = str( controller + 1 )
1761 if "Error" not in clusters[ controller ]:
1762 if clusters[ controller ] == clusters[ 0 ]:
1763 continue
1764 else: # clusters not consistent
1765 main.log.report( "clusters from ONOS" +
1766 controllerStr +
1767 " is inconsistent with ONOS1" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001768 consistentClustersResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001769
Jon Hall21270ac2015-02-16 17:59:55 -08001770 else:
1771 main.log.report( "Error in getting dataplane clusters " +
1772 "from ONOS" + controllerStr )
1773 consistentClustersResult = main.FALSE
1774 main.log.warn( "ONOS" + controllerStr +
1775 " clusters response: " +
1776 repr( clusters[ controller ] ) )
1777 utilities.assert_equals(
1778 expect=main.TRUE,
1779 actual=consistentClustersResult,
1780 onpass="Clusters view is consistent across all ONOS nodes",
1781 onfail="ONOS nodes have different views of clusters" )
1782 # there should always only be one cluster
1783 numClusters = len( json.loads( clusters[ 0 ] ) )
Jon Hall58c76b72015-02-23 11:09:24 -08001784 clusterResults = main.FALSE
1785 if numClusters == 1:
1786 clusterResults = main.TRUE
Jon Hall21270ac2015-02-16 17:59:55 -08001787 utilities.assert_equals(
1788 expect=1,
1789 actual=numClusters,
1790 onpass="ONOS shows 1 SCC",
Jon Hall58c76b72015-02-23 11:09:24 -08001791 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
Jon Hall94fd0472014-12-08 11:52:42 -08001792
Jon Hall21270ac2015-02-16 17:59:55 -08001793 topoResult = ( devicesResults and portsResults and linksResults
Jon Hall58c76b72015-02-23 11:09:24 -08001794 and hostsResults and consistentHostsResult
1795 and consistentClustersResult and clusterResults
1796 and ipResult )
Jon Hall94fd0472014-12-08 11:52:42 -08001797
Jon Hall21270ac2015-02-16 17:59:55 -08001798 topoResult = topoResult and int( count <= 2 )
1799 note = "note it takes about " + str( int( cliTime ) ) + \
1800 " seconds for the test to make all the cli calls to fetch " +\
1801 "the topology from each ONOS instance"
1802 main.log.info(
1803 "Very crass estimate for topology discovery/convergence( " +
1804 str( note ) + " ): " + str( elapsed ) + " seconds, " +
1805 str( count ) + " tries" )
1806 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
Jon Hall58c76b72015-02-23 11:09:24 -08001807 onpass="Topology Check Test successful",
1808 onfail="Topology Check Test NOT successful" )
Jon Hall21270ac2015-02-16 17:59:55 -08001809 if topoResult == main.TRUE:
1810 main.log.report( "ONOS topology view matches Mininet topology" )
Jon Hallb1290e82014-11-18 16:17:48 -05001811
Jon Hall6aec96b2015-01-19 14:49:31 -08001812 def CASE9( self, main ):
1813 """
Jon Hallb1290e82014-11-18 16:17:48 -05001814 Link s3-s28 down
Jon Hall6aec96b2015-01-19 14:49:31 -08001815 """
1816 import time
1817 # NOTE: You should probably run a topology check after this
Jon Hallb1290e82014-11-18 16:17:48 -05001818
Jon Hall8f89dda2015-01-22 16:03:33 -08001819 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hallb1290e82014-11-18 16:17:48 -05001820
Jon Hall6aec96b2015-01-19 14:49:31 -08001821 description = "Turn off a link to ensure that Link Discovery " +\
Jon Hall58c76b72015-02-23 11:09:24 -08001822 "is working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001823 main.log.report( description )
1824 main.case( description )
Jon Hallb1290e82014-11-18 16:17:48 -05001825
Jon Hall6aec96b2015-01-19 14:49:31 -08001826 main.step( "Kill Link between s3 and s28" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001827 LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" )
Jon Hall58c76b72015-02-23 11:09:24 -08001828 main.log.info( "Waiting " + str( linkSleep ) +
1829 " seconds for link down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001830 time.sleep( linkSleep )
1831 utilities.assert_equals( expect=main.TRUE, actual=LinkDown,
Jon Hall58c76b72015-02-23 11:09:24 -08001832 onpass="Link down succesful",
1833 onfail="Failed to bring link down" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001834 # TODO do some sort of check here
Jon Hallb1290e82014-11-18 16:17:48 -05001835
Jon Hall6aec96b2015-01-19 14:49:31 -08001836 def CASE10( self, main ):
1837 """
Jon Hallb1290e82014-11-18 16:17:48 -05001838 Link s3-s28 up
Jon Hall6aec96b2015-01-19 14:49:31 -08001839 """
1840 import time
1841 # NOTE: You should probably run a topology check after this
Jon Hallb1290e82014-11-18 16:17:48 -05001842
Jon Hall8f89dda2015-01-22 16:03:33 -08001843 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hallb1290e82014-11-18 16:17:48 -05001844
Jon Hall6aec96b2015-01-19 14:49:31 -08001845 description = "Restore a link to ensure that Link Discovery is " + \
Jon Hall8f89dda2015-01-22 16:03:33 -08001846 "working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001847 main.log.report( description )
1848 main.case( description )
Jon Hallb1290e82014-11-18 16:17:48 -05001849
Jon Hall6aec96b2015-01-19 14:49:31 -08001850 main.step( "Bring link between s3 and s28 back up" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001851 LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" )
Jon Hall58c76b72015-02-23 11:09:24 -08001852 main.log.info( "Waiting " + str( linkSleep ) +
1853 " seconds for link up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001854 time.sleep( linkSleep )
1855 utilities.assert_equals( expect=main.TRUE, actual=LinkUp,
Jon Hall58c76b72015-02-23 11:09:24 -08001856 onpass="Link up succesful",
1857 onfail="Failed to bring link up" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001858 # TODO do some sort of check here
Jon Hallb1290e82014-11-18 16:17:48 -05001859
Jon Hall6aec96b2015-01-19 14:49:31 -08001860 def CASE11( self, main ):
1861 """
Jon Hallb1290e82014-11-18 16:17:48 -05001862 Switch Down
Jon Hall6aec96b2015-01-19 14:49:31 -08001863 """
1864 # NOTE: You should probably run a topology check after this
Jon Hallb1290e82014-11-18 16:17:48 -05001865 import time
1866
Jon Hall8f89dda2015-01-22 16:03:33 -08001867 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hallb1290e82014-11-18 16:17:48 -05001868
1869 description = "Killing a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001870 main.log.report( description )
1871 main.case( description )
1872 switch = main.params[ 'kill' ][ 'switch' ]
1873 switchDPID = main.params[ 'kill' ][ 'dpid' ]
Jon Hallb1290e82014-11-18 16:17:48 -05001874
Jon Hall6aec96b2015-01-19 14:49:31 -08001875 # TODO: Make this switch parameterizable
1876 main.step( "Kill " + switch )
1877 main.log.report( "Deleting " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001878 main.Mininet1.delSwitch( switch )
1879 main.log.info( "Waiting " + str( switchSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001880 " seconds for switch down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001881 time.sleep( switchSleep )
1882 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001883 # Peek at the deleted switch
1884 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001885 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001886 if device and device[ 'available' ] is False:
Jon Hall94fd0472014-12-08 11:52:42 -08001887 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001888 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall58c76b72015-02-23 11:09:24 -08001889 onpass="Kill switch succesful",
1890 onfail="Failed to kill switch?" )
Jon Hallb1290e82014-11-18 16:17:48 -05001891
Jon Hall6aec96b2015-01-19 14:49:31 -08001892 def CASE12( self, main ):
1893 """
Jon Hallb1290e82014-11-18 16:17:48 -05001894 Switch Up
Jon Hall6aec96b2015-01-19 14:49:31 -08001895 """
1896 # NOTE: You should probably run a topology check after this
Jon Hallb1290e82014-11-18 16:17:48 -05001897 import time
Jon Hall669173b2014-12-17 11:36:30 -08001898
Jon Hall8f89dda2015-01-22 16:03:33 -08001899 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall6aec96b2015-01-19 14:49:31 -08001900 switch = main.params[ 'kill' ][ 'switch' ]
1901 switchDPID = main.params[ 'kill' ][ 'dpid' ]
1902 links = main.params[ 'kill' ][ 'links' ].split()
Jon Hallb1290e82014-11-18 16:17:48 -05001903 description = "Adding a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001904 main.log.report( description )
1905 main.case( description )
Jon Hallb1290e82014-11-18 16:17:48 -05001906
Jon Hall6aec96b2015-01-19 14:49:31 -08001907 main.step( "Add back " + switch )
1908 main.log.report( "Adding back " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001909 main.Mininet1.addSwitch( switch, dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001910 # TODO: New dpid or same? Ask Thomas?
1911 for peer in links:
Jon Hall8f89dda2015-01-22 16:03:33 -08001912 main.Mininet1.addLink( switch, peer )
Jon Hall58c76b72015-02-23 11:09:24 -08001913 main.Mininet1.assignSwController( sw=switch.split( 's' )[ 1 ],
1914 count=numControllers,
1915 ip1=ONOS1Ip,
1916 port1=ONOS1Port,
1917 ip2=ONOS2Ip,
1918 port2=ONOS2Port,
1919 ip3=ONOS3Ip,
1920 port3=ONOS3Port,
1921 ip4=ONOS4Ip,
1922 port4=ONOS4Port,
1923 ip5=ONOS5Ip,
1924 port5=ONOS5Port,
1925 ip6=ONOS6Ip,
1926 port6=ONOS6Port,
1927 ip7=ONOS7Ip,
1928 port7=ONOS7Port )
1929 main.log.info( "Waiting " + str( switchSleep ) +
1930 " seconds for switch up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001931 time.sleep( switchSleep )
1932 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001933 # Peek at the deleted switch
1934 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001935 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001936 if device and device[ 'available' ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001937 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001938 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall58c76b72015-02-23 11:09:24 -08001939 onpass="add switch succesful",
1940 onfail="Failed to add switch?" )
Jon Hallb1290e82014-11-18 16:17:48 -05001941
Jon Hall6aec96b2015-01-19 14:49:31 -08001942 def CASE13( self, main ):
1943 """
Jon Hallb1290e82014-11-18 16:17:48 -05001944 Clean up
Jon Hall6aec96b2015-01-19 14:49:31 -08001945 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001946 import os
1947 import time
Jon Hall6aec96b2015-01-19 14:49:31 -08001948 # TODO: make use of this elsewhere
1949 ips = []
Jon Hall8f89dda2015-01-22 16:03:33 -08001950 ips.append( ONOS1Ip )
1951 ips.append( ONOS2Ip )
1952 ips.append( ONOS3Ip )
1953 ips.append( ONOS4Ip )
1954 ips.append( ONOS5Ip )
1955 ips.append( ONOS6Ip )
1956 ips.append( ONOS7Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -08001957
1958 # printing colors to terminal
Jon Hall669173b2014-12-17 11:36:30 -08001959 colors = {}
Jon Hall6aec96b2015-01-19 14:49:31 -08001960 colors[ 'cyan' ] = '\033[96m'
1961 colors[ 'purple' ] = '\033[95m'
1962 colors[ 'blue' ] = '\033[94m'
1963 colors[ 'green' ] = '\033[92m'
1964 colors[ 'yellow' ] = '\033[93m'
1965 colors[ 'red' ] = '\033[91m'
1966 colors[ 'end' ] = '\033[0m'
Jon Hall368769f2014-11-19 15:43:35 -08001967 description = "Test Cleanup"
Jon Hall6aec96b2015-01-19 14:49:31 -08001968 main.log.report( description )
1969 main.case( description )
1970 main.step( "Killing tcpdumps" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001971 main.Mininet2.stopTcpdump()
Jon Hallb1290e82014-11-18 16:17:48 -05001972
Jon Hall6aec96b2015-01-19 14:49:31 -08001973 main.step( "Checking ONOS Logs for errors" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001974 for i in range( 7 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001975 print colors[ 'purple' ] + "Checking logs for errors on " + \
Jon Hall8f89dda2015-01-22 16:03:33 -08001976 "ONOS" + str( i + 1 ) + ":" + colors[ 'end' ]
1977 print main.ONOSbench.checkLogs( ips[ i ] )
Jon Hall94fd0472014-12-08 11:52:42 -08001978
Jon Hall6aec96b2015-01-19 14:49:31 -08001979 main.step( "Copying MN pcap and ONOS log files to test station" )
Jon Hallb1290e82014-11-18 16:17:48 -05001980 testname = main.TEST
Jon Hall8f89dda2015-01-22 16:03:33 -08001981 teststationUser = main.params[ 'TESTONUSER' ]
1982 teststationIP = main.params[ 'TESTONIP' ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001983 # NOTE: MN Pcap file is being saved to ~/packet_captures
Jon Hall73cf9cc2014-11-20 22:28:38 -08001984 # scp this file as MN and TestON aren't necessarily the same vm
Jon Hall6aec96b2015-01-19 14:49:31 -08001985 # FIXME: scp
1986 # mn files
1987 # TODO: Load these from params
1988 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001989 logFolder = "/opt/onos/log/"
1990 logFiles = [ "karaf.log", "karaf.log.1" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001991 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001992 dstDir = "~/packet_captures/"
1993 for f in logFiles:
1994 for i in range( 7 ):
1995 main.ONOSbench.handle.sendline( "scp sdn@" + ips[ i ] + ":" +
1996 logFolder + f + " " +
1997 teststationUser + "@" +
1998 teststationIP + ":" +
1999 dstDir + str( testname ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08002000 "-ONOS" + str( i + 1 ) + "-" +
2001 f )
Jon Hall58c76b72015-02-23 11:09:24 -08002002 main.ONOSbench.handle.expect( "\$" )
2003
Jon Hall6aec96b2015-01-19 14:49:31 -08002004 # std*.log's
2005 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08002006 logFolder = "/opt/onos/var/"
2007 logFiles = [ "stderr.log", "stdout.log" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08002008 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08002009 dstDir = "~/packet_captures/"
2010 for f in logFiles:
2011 for i in range( 7 ):
2012 main.ONOSbench.handle.sendline( "scp sdn@" + ips[ i ] + ":" +
2013 logFolder + f + " " +
2014 teststationUser + "@" +
2015 teststationIP + ":" +
2016 dstDir + str( testname ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08002017 "-ONOS" + str( i + 1 ) + "-" +
2018 f )
Jon Hall58c76b72015-02-23 11:09:24 -08002019 main.ONOSbench.handle.expect( "\$" )
Jon Hall6aec96b2015-01-19 14:49:31 -08002020 # sleep so scp can finish
2021 time.sleep( 10 )
Jon Hall58c76b72015-02-23 11:09:24 -08002022 main.Mininet1.stopNet()
Jon Hall6aec96b2015-01-19 14:49:31 -08002023 main.step( "Packing and rotating pcap archives" )
2024 os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08002025
Jon Hall6aec96b2015-01-19 14:49:31 -08002026 # TODO: actually check something here
2027 utilities.assert_equals( expect=main.TRUE, actual=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08002028 onpass="Test cleanup successful",
2029 onfail="Test cleanup NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08002030
Jon Hall6aec96b2015-01-19 14:49:31 -08002031 def CASE14( self, main ):
2032 """
Jon Hall94fd0472014-12-08 11:52:42 -08002033 start election app on all onos nodes
Jon Hall6aec96b2015-01-19 14:49:31 -08002034 """
Jon Hall8f89dda2015-01-22 16:03:33 -08002035 leaderResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08002036 # install app on onos 1
2037 main.log.info( "Install leadership election app" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002038 main.ONOScli1.featureInstall( "onos-app-election" )
Jon Hall6aec96b2015-01-19 14:49:31 -08002039 # wait for election
2040 # check for leader
Jon Hall8f89dda2015-01-22 16:03:33 -08002041 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08002042 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08002043 if leader == ONOS1Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08002044 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08002045 pass
Jon Hall6aec96b2015-01-19 14:49:31 -08002046 elif leader is None:
2047 # No leader elected
2048 main.log.report( "No leader was elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002049 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08002050 elif leader == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08002051 # error in response
2052 # TODO: add check for "Command not found:" in the driver, this
2053 # means the app isn't loaded
Jon Hall8f89dda2015-01-22 16:03:33 -08002054 main.log.report( "Something is wrong with electionTestLeader" +
Jon Hall6aec96b2015-01-19 14:49:31 -08002055 " function, check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002056 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08002057 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08002058 # error in response
2059 main.log.report(
Jon Hall8f89dda2015-01-22 16:03:33 -08002060 "Unexpected response from electionTestLeader function:'" +
2061 str( leader ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08002062 "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002063 leaderResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08002064
Jon Hall6aec96b2015-01-19 14:49:31 -08002065 # install on other nodes and check for leader.
2066 # Should be onos1 and each app should show the same leader
Jon Hall8f89dda2015-01-22 16:03:33 -08002067 for controller in range( 2, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08002068 # loop through ONOScli handlers
2069 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08002070 node.featureInstall( "onos-app-election" )
2071 leaderN = node.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08002072 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08002073 if leaderN == ONOS1Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08002074 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08002075 pass
2076 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08002077 # error in response
2078 # TODO: add check for "Command not found:" in the driver, this
2079 # means the app isn't loaded
2080 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002081 "electionTestLeader function, check the" +
Jon Hall6aec96b2015-01-19 14:49:31 -08002082 " error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002083 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08002084 elif leader != leaderN:
Jon Hall8f89dda2015-01-22 16:03:33 -08002085 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08002086 main.log.report( "ONOS" + str( controller ) + " sees " +
2087 str( leaderN ) +
2088 " as the leader of the election app. Leader" +
2089 " should be " +
2090 str( leader ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08002091 if leaderResult:
Jon Hall6aec96b2015-01-19 14:49:31 -08002092 main.log.report( "Leadership election tests passed( consistent " +
2093 "view of leader across listeners and a leader " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002094 "was elected )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08002095 utilities.assert_equals(
2096 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002097 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002098 onpass="Leadership election passed",
2099 onfail="Something went wrong with Leadership election" )
Jon Hall94fd0472014-12-08 11:52:42 -08002100
Jon Hall6aec96b2015-01-19 14:49:31 -08002101 def CASE15( self, main ):
2102 """
Jon Hall669173b2014-12-17 11:36:30 -08002103 Check that Leadership Election is still functional
Jon Hall6aec96b2015-01-19 14:49:31 -08002104 """
Jon Hall8f89dda2015-01-22 16:03:33 -08002105 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08002106 description = "Check that Leadership Election is still functional"
Jon Hall6aec96b2015-01-19 14:49:31 -08002107 main.log.report( description )
2108 main.case( description )
2109 main.step( "Find current leader and withdraw" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002110 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08002111 # TODO: do some sanity checking on leader before using it
Jon Hall8f89dda2015-01-22 16:03:33 -08002112 withdrawResult = main.FALSE
2113 if leader == ONOS1Ip:
2114 oldLeader = getattr( main, "ONOScli1" )
2115 elif leader == ONOS2Ip:
2116 oldLeader = getattr( main, "ONOScli2" )
2117 elif leader == ONOS3Ip:
2118 oldLeader = getattr( main, "ONOScli3" )
2119 elif leader == ONOS4Ip:
2120 oldLeader = getattr( main, "ONOScli4" )
2121 elif leader == ONOS5Ip:
2122 oldLeader = getattr( main, "ONOScli5" )
2123 elif leader == ONOS6Ip:
2124 oldLeader = getattr( main, "ONOScli6" )
2125 elif leader == ONOS7Ip:
2126 oldLeader = getattr( main, "ONOScli7" )
Jon Hall6aec96b2015-01-19 14:49:31 -08002127 elif leader is None or leader == main.FALSE:
2128 main.log.report(
2129 "Leader for the election app should be an ONOS node," +
Jon Hall58c76b72015-02-23 11:09:24 -08002130 "instead got '" + str( leader ) + "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002131 leaderResult = main.FALSE
2132 withdrawResult = oldLeader.electionTestWithdraw()
Jon Hall6aec96b2015-01-19 14:49:31 -08002133 utilities.assert_equals(
2134 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002135 actual=withdrawResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002136 onpass="App was withdrawn from election",
2137 onfail="App was not withdrawn from election" )
Jon Hall669173b2014-12-17 11:36:30 -08002138
Jon Hall6aec96b2015-01-19 14:49:31 -08002139 main.step( "Make sure new leader is elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002140 leaderList = []
2141 for controller in range( 1, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08002142 # loop through ONOScli handlers
2143 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08002144 leaderList.append( node.electionTestLeader() )
2145 for leaderN in leaderList:
Jon Hall669173b2014-12-17 11:36:30 -08002146 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08002147 main.log.report(
Jon Hall58c76b72015-02-23 11:09:24 -08002148 "ONOS" + str( controller ) +
2149 " still sees " + str( leader ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08002150 " as leader after they withdrew" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002151 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08002152 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08002153 # error in response
2154 # TODO: add check for "Command not found:" in the driver, this
2155 # means the app isn't loaded
2156 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002157 "electionTestLeader function, " +
Jon Hall6aec96b2015-01-19 14:49:31 -08002158 "check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002159 leaderResult = main.FALSE
2160 consistentLeader = main.FALSE
2161 if len( set( leaderList ) ) == 1:
Jon Hall6aec96b2015-01-19 14:49:31 -08002162 main.log.info( "Each Election-app sees '" +
Jon Hall8f89dda2015-01-22 16:03:33 -08002163 str( leaderList[ 0 ] ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08002164 "' as the leader" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002165 consistentLeader = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08002166 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08002167 main.log.report(
2168 "Inconsistent responses for leader of Election-app:" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002169 for n in range( len( leaderList ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -08002170 main.log.report( "ONOS" + str( n + 1 ) + " response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002171 str( leaderList[ n ] ) )
2172 if leaderResult:
2173 main.log.report( "Leadership election tests passed( consistent " +
Jon Hall6aec96b2015-01-19 14:49:31 -08002174 "view of leader across listeners and a new " +
2175 "leader was elected when the old leader " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002176 "resigned )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08002177 utilities.assert_equals(
2178 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002179 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002180 onpass="Leadership election passed",
2181 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08002182
Jon Hall58c76b72015-02-23 11:09:24 -08002183 main.step( "Run for election on old leader( just so everyone " +
2184 "is in the hat )" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002185 runResult = oldLeader.electionTestRun()
Jon Hall6aec96b2015-01-19 14:49:31 -08002186 utilities.assert_equals(
2187 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002188 actual=runResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002189 onpass="App re-ran for election",
2190 onfail="App failed to run for election" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002191 if consistentLeader == main.TRUE:
2192 afterRun = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08002193 # verify leader didn't just change
Jon Hall8f89dda2015-01-22 16:03:33 -08002194 if afterRun == leaderList[ 0 ]:
2195 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08002196 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08002197 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08002198 # TODO: assert on run and withdraw results?
Jon Hall669173b2014-12-17 11:36:30 -08002199
Jon Hall6aec96b2015-01-19 14:49:31 -08002200 utilities.assert_equals(
2201 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002202 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002203 onpass="Leadership election passed",
2204 onfail="Something went wrong with Leadership election after " +
2205 "the old leader re-ran for election" )