blob: db02c68349ca70e9b9fe902be988ec3cad843125 [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 = ''
Jon Hall65844a32015-03-09 19:09:37 -070029 self.threadID = 0
Jon Hallb1290e82014-11-18 16:17:48 -050030
Jon Hall6aec96b2015-01-19 14:49:31 -080031 def CASE1( self, main ):
32 """
Jon Hallb1290e82014-11-18 16:17:48 -050033 CASE1 is to compile ONOS and push it to the test machines
34
35 Startup sequence:
Jon Hallb1290e82014-11-18 16:17:48 -050036 cell <name>
37 onos-verify-cell
38 NOTE: temporary - onos-remove-raft-logs
Jon Hall58c76b72015-02-23 11:09:24 -080039 onos-uninstall
40 start mininet
41 git pull
42 mvn clean install
43 onos-package
Jon Hallb1290e82014-11-18 16:17:48 -050044 onos-install -f
45 onos-wait-for-start
Jon Hall58c76b72015-02-23 11:09:24 -080046 start cli sessions
47 start tcpdump
Jon Hall6aec96b2015-01-19 14:49:31 -080048 """
49 main.log.report( "ONOS HA Sanity test - initialization" )
50 main.case( "Setting up test environment" )
51 # TODO: save all the timers and output them for plotting
Jon Hallb1290e82014-11-18 16:17:48 -050052
Jon Hall65844a32015-03-09 19:09:37 -070053 # load some variables from the params file
Jon Hall8f89dda2015-01-22 16:03:33 -080054 PULLCODE = False
Jon Hall6aec96b2015-01-19 14:49:31 -080055 if main.params[ 'Git' ] == 'True':
Jon Hall8f89dda2015-01-22 16:03:33 -080056 PULLCODE = True
Jon Hall529a37f2015-01-28 10:02:00 -080057 gitBranch = main.params[ 'branch' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080058 cellName = main.params[ 'ENV' ][ 'cellName' ]
Jon Hall6aec96b2015-01-19 14:49:31 -080059
60 # set global variables
Jon Hall8f89dda2015-01-22 16:03:33 -080061 global ONOS1Port
Jon Hall8f89dda2015-01-22 16:03:33 -080062 global ONOS2Port
Jon Hall8f89dda2015-01-22 16:03:33 -080063 global ONOS3Port
Jon Hall8f89dda2015-01-22 16:03:33 -080064 global ONOS4Port
Jon Hall8f89dda2015-01-22 16:03:33 -080065 global ONOS5Port
Jon Hall8f89dda2015-01-22 16:03:33 -080066 global ONOS6Port
Jon Hall8f89dda2015-01-22 16:03:33 -080067 global ONOS7Port
68 global numControllers
Jon Hallb1290e82014-11-18 16:17:48 -050069
Jon Hall8f89dda2015-01-22 16:03:33 -080070 numControllers = int( main.params[ 'num_controllers' ] )
Jon Hall65844a32015-03-09 19:09:37 -070071 # FIXME: just get controller port from params?
72 # TODO: do we really need all these?
73 ONOS1Port = main.params[ 'CTRL' ][ 'port1' ]
74 ONOS2Port = main.params[ 'CTRL' ][ 'port2' ]
75 ONOS3Port = main.params[ 'CTRL' ][ 'port3' ]
76 ONOS4Port = main.params[ 'CTRL' ][ 'port4' ]
77 ONOS5Port = main.params[ 'CTRL' ][ 'port5' ]
78 ONOS6Port = main.params[ 'CTRL' ][ 'port6' ]
79 ONOS7Port = main.params[ 'CTRL' ][ 'port7' ]
80
81 global CLIs
82 CLIs = []
83 global nodes
84 nodes = []
85 for i in range( 1, numControllers + 1 ):
86 CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
87 nodes.append( getattr( main, 'ONOS' + str( i ) ) )
Jon Hallb1290e82014-11-18 16:17:48 -050088
Jon Hall6aec96b2015-01-19 14:49:31 -080089 main.step( "Applying cell variable to environment" )
Jon Hall8f89dda2015-01-22 16:03:33 -080090 cellResult = main.ONOSbench.setCell( cellName )
91 verifyResult = main.ONOSbench.verifyCell()
Jon Hall368769f2014-11-19 15:43:35 -080092
Jon Hall6aec96b2015-01-19 14:49:31 -080093 # FIXME:this is short term fix
94 main.log.report( "Removing raft logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -080095 main.ONOSbench.onosRemoveRaftLogs()
Jon Hall65844a32015-03-09 19:09:37 -070096
Jon Hall6aec96b2015-01-19 14:49:31 -080097 main.log.report( "Uninstalling ONOS" )
Jon Hall65844a32015-03-09 19:09:37 -070098 for node in nodes:
99 main.ONOSbench.onosUninstall( node.ip_address )
Jon Hallb1290e82014-11-18 16:17:48 -0500100
Jon Hall8f89dda2015-01-22 16:03:33 -0800101 cleanInstallResult = main.TRUE
102 gitPullResult = main.TRUE
Jon Hallb1290e82014-11-18 16:17:48 -0500103
Jon Hall97f31752015-02-04 12:01:04 -0800104 main.step( "Starting Mininet" )
105 main.Mininet1.startNet( )
106
Jon Hall6aec96b2015-01-19 14:49:31 -0800107 main.step( "Compiling the latest version of ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800108 if PULLCODE:
Jon Hall58c76b72015-02-23 11:09:24 -0800109 main.step( "Git checkout and pull " + gitBranch )
Jon Hall529a37f2015-01-28 10:02:00 -0800110 main.ONOSbench.gitCheckout( gitBranch )
Jon Hall8f89dda2015-01-22 16:03:33 -0800111 gitPullResult = main.ONOSbench.gitPull()
Jon Hallb1290e82014-11-18 16:17:48 -0500112
Jon Hall6aec96b2015-01-19 14:49:31 -0800113 main.step( "Using mvn clean & install" )
Jon Hall529a37f2015-01-28 10:02:00 -0800114 cleanInstallResult = main.ONOSbench.cleanInstall()
115 else:
116 main.log.warn( "Did not pull new code so skipping mvn " +
117 "clean install" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800118 main.ONOSbench.getVersion( report=True )
Jon Hallb1290e82014-11-18 16:17:48 -0500119
Jon Hall6aec96b2015-01-19 14:49:31 -0800120 main.step( "Creating ONOS package" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800121 packageResult = main.ONOSbench.onosPackage()
Jon Hallb1290e82014-11-18 16:17:48 -0500122
Jon Hall6aec96b2015-01-19 14:49:31 -0800123 main.step( "Installing ONOS package" )
Jon Hall65844a32015-03-09 19:09:37 -0700124 onosInstallResult = main.TRUE
125 for node in nodes:
126 tmpResult = main.ONOSbench.onosInstall( options="-f",
127 node=node.ip_address )
128 onosInstallResult = onosInstallResult and tmpResult
Jon Hallb1290e82014-11-18 16:17:48 -0500129
Jon Hall6aec96b2015-01-19 14:49:31 -0800130 main.step( "Checking if ONOS is up yet" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800131 for i in range( 2 ):
Jon Hall65844a32015-03-09 19:09:37 -0700132 onosIsupResult = main.TRUE
133 for node in nodes:
134 started = main.ONOSbench.isup( node.ip_address )
135 if not started:
136 main.log.report( node.name + " didn't start!" )
137 main.ONOSbench.onosStop( node.ip_address )
138 main.ONOSbench.onosStart( node.ip_address )
139 onosIsupResult = onosIsupResult and started
Jon Hall8f89dda2015-01-22 16:03:33 -0800140 if onosIsupResult == main.TRUE:
Jon Hallffb386d2014-11-21 13:43:38 -0800141 break
Jon Hallb1290e82014-11-18 16:17:48 -0500142
Jon Hall65844a32015-03-09 19:09:37 -0700143 main.log.step( "Starting ONOS CLI sessions" )
144 cliResults = main.TRUE
145 threads = []
146 for i in range( numControllers ):
147 t = main.Thread( target=CLIs[i].startOnosCli,
148 threadID=self.threadID,
149 name="startOnosCli-" + str( i ),
150 args=[nodes[i].ip_address] )
151 threads.append( t )
152 t.start()
153 self.threadID += 1
154
155 for t in threads:
156 t.join()
157 cliResults = cliResults and t.result
Jon Hallb1290e82014-11-18 16:17:48 -0500158
Jon Hall6aec96b2015-01-19 14:49:31 -0800159 main.step( "Start Packet Capture MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800160 main.Mininet2.startTcpdump(
Jon Hall6aec96b2015-01-19 14:49:31 -0800161 str( main.params[ 'MNtcpdump' ][ 'folder' ] ) + str( main.TEST )
162 + "-MN.pcap",
163 intf=main.params[ 'MNtcpdump' ][ 'intf' ],
164 port=main.params[ 'MNtcpdump' ][ 'port' ] )
Jon Hallb1290e82014-11-18 16:17:48 -0500165
Jon Hall8f89dda2015-01-22 16:03:33 -0800166 case1Result = ( cleanInstallResult and packageResult and
167 cellResult and verifyResult and onosInstallResult
168 and onosIsupResult and cliResults )
Jon Hallb1290e82014-11-18 16:17:48 -0500169
Jon Hall8f89dda2015-01-22 16:03:33 -0800170 utilities.assert_equals( expect=main.TRUE, actual=case1Result,
Jon Hall58c76b72015-02-23 11:09:24 -0800171 onpass="Test startup successful",
172 onfail="Test startup NOT successful" )
Jon Hallb1290e82014-11-18 16:17:48 -0500173
Jon Hall8f89dda2015-01-22 16:03:33 -0800174 if case1Result == main.FALSE:
Jon Hallffb386d2014-11-21 13:43:38 -0800175 main.cleanup()
176 main.exit()
Jon Hallb1290e82014-11-18 16:17:48 -0500177
Jon Hall6aec96b2015-01-19 14:49:31 -0800178 def CASE2( self, main ):
179 """
Jon Hallb1290e82014-11-18 16:17:48 -0500180 Assign mastership to controllers
Jon Hall6aec96b2015-01-19 14:49:31 -0800181 """
Jon Hallb1290e82014-11-18 16:17:48 -0500182 import re
183
Jon Hall6aec96b2015-01-19 14:49:31 -0800184 main.log.report( "Assigning switches to controllers" )
185 main.case( "Assigning Controllers" )
186 main.step( "Assign switches to controllers" )
Jon Hallb1290e82014-11-18 16:17:48 -0500187
Jon Hall65844a32015-03-09 19:09:37 -0700188 # TODO: rewrite this function to take lists of ips and ports?
189 # or list of tuples?
Jon Hall6aec96b2015-01-19 14:49:31 -0800190 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800191 main.Mininet1.assignSwController(
Jon Hall6aec96b2015-01-19 14:49:31 -0800192 sw=str( i ),
Jon Hall8f89dda2015-01-22 16:03:33 -0800193 count=numControllers,
Jon Hall65844a32015-03-09 19:09:37 -0700194 ip1=nodes[ 0 ].ip_address, port1=ONOS1Port,
195 ip2=nodes[ 1 ].ip_address, port2=ONOS2Port,
196 ip3=nodes[ 2 ].ip_address, port3=ONOS3Port,
197 ip4=nodes[ 3 ].ip_address, port4=ONOS4Port,
198 ip5=nodes[ 4 ].ip_address, port5=ONOS5Port,
199 ip6=nodes[ 5 ].ip_address, port6=ONOS6Port,
200 ip7=nodes[ 6 ].ip_address, port7=ONOS7Port )
Jon Hallb1290e82014-11-18 16:17:48 -0500201
Jon Hall8f89dda2015-01-22 16:03:33 -0800202 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800203 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800204 response = main.Mininet1.getSwController( "s" + str( i ) )
Jon Hallffb386d2014-11-21 13:43:38 -0800205 try:
Jon Hall6aec96b2015-01-19 14:49:31 -0800206 main.log.info( str( response ) )
Jon Hallfebb1c72015-03-05 13:30:09 -0800207 except Exception:
Jon Hall6aec96b2015-01-19 14:49:31 -0800208 main.log.info( repr( response ) )
Jon Hall65844a32015-03-09 19:09:37 -0700209 for node in nodes:
210 if re.search( "tcp:" + node.ip_address, response ):
211 mastershipCheck = mastershipCheck and main.TRUE
212 else:
213 mastershipCheck = main.FALSE
Jon Hall8f89dda2015-01-22 16:03:33 -0800214 if mastershipCheck == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800215 main.log.report( "Switch mastership assigned correctly" )
216 utilities.assert_equals(
217 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800218 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800219 onpass="Switch mastership assigned correctly",
220 onfail="Switches not assigned correctly to controllers" )
Jon Hallb1290e82014-11-18 16:17:48 -0500221
Jon Hall6aec96b2015-01-19 14:49:31 -0800222 # Manually assign mastership to the controller we want
Jon Hall8f89dda2015-01-22 16:03:33 -0800223 roleCall = main.TRUE
224 roleCheck = main.TRUE
Jon Hall58c76b72015-02-23 11:09:24 -0800225 try:
226 # Assign switch
Jon Hall65844a32015-03-09 19:09:37 -0700227 ip = nodes[ 0 ].ip_address # ONOS1
Jon Hall58c76b72015-02-23 11:09:24 -0800228 deviceId = main.ONOScli1.getDevice( "1000" ).get( 'id' )
229 assert deviceId, "No device id for s1 in ONOS"
Jon Hall8f89dda2015-01-22 16:03:33 -0800230 roleCall = roleCall and main.ONOScli1.deviceRole(
231 deviceId,
Jon Hall65844a32015-03-09 19:09:37 -0700232 ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800233 # Check assignment
Jon Hall65844a32015-03-09 19:09:37 -0700234 if ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800235 roleCheck = roleCheck and main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800236 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800237 roleCheck = roleCheck and main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800238
Jon Hall58c76b72015-02-23 11:09:24 -0800239 # Assign switch
240 deviceId = main.ONOScli1.getDevice( "2800" ).get( 'id' )
241 assert deviceId, "No device id for s28 in ONOS"
Jon Hall8f89dda2015-01-22 16:03:33 -0800242 roleCall = roleCall and main.ONOScli1.deviceRole(
243 deviceId,
Jon Hall65844a32015-03-09 19:09:37 -0700244 ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800245 # Check assignment
Jon Hall65844a32015-03-09 19:09:37 -0700246 if ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800247 roleCheck = roleCheck and main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800248 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800249 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800250
Jon Hall65844a32015-03-09 19:09:37 -0700251 ip = nodes[ 1 ].ip_address # ONOS2
Jon Hall58c76b72015-02-23 11:09:24 -0800252 # Assign switch
253 deviceId = main.ONOScli1.getDevice( "2000" ).get( 'id' )
254 assert deviceId, "No device id for s2 in ONOS"
255 roleCall = roleCall and main.ONOScli1.deviceRole(
256 deviceId,
Jon Hall65844a32015-03-09 19:09:37 -0700257 ip )
Jon Hall58c76b72015-02-23 11:09:24 -0800258 # Check assignment
Jon Hall65844a32015-03-09 19:09:37 -0700259 if ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
Jon Hall58c76b72015-02-23 11:09:24 -0800260 roleCheck = roleCheck and main.TRUE
261 else:
262 roleCheck = roleCheck and main.FALSE
263
264 # Assign switch
265 deviceId = main.ONOScli1.getDevice( "3000" ).get( 'id' )
266 assert deviceId, "No device id for s3 in ONOS"
267 roleCall = roleCall and main.ONOScli1.deviceRole(
268 deviceId,
Jon Hall65844a32015-03-09 19:09:37 -0700269 ip )
Jon Hall58c76b72015-02-23 11:09:24 -0800270 # Check assignment
Jon Hall65844a32015-03-09 19:09:37 -0700271 if ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
Jon Hall58c76b72015-02-23 11:09:24 -0800272 roleCheck = roleCheck and main.TRUE
273 else:
274 roleCheck = roleCheck and main.FALSE
275
Jon Hall65844a32015-03-09 19:09:37 -0700276 ip = nodes[ 2 ].ip_address # ONOS3
Jon Hall58c76b72015-02-23 11:09:24 -0800277 # Assign switch
278 deviceId = main.ONOScli1.getDevice( "5000" ).get( 'id' )
279 assert deviceId, "No device id for s5 in ONOS"
280 roleCall = roleCall and main.ONOScli1.deviceRole(
281 deviceId,
Jon Hall65844a32015-03-09 19:09:37 -0700282 ip )
Jon Hall58c76b72015-02-23 11:09:24 -0800283 # Check assignment
Jon Hall65844a32015-03-09 19:09:37 -0700284 if ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
Jon Hall58c76b72015-02-23 11:09:24 -0800285 roleCheck = roleCheck and main.TRUE
286 else:
287 roleCheck = roleCheck and main.FALSE
288
289 # Assign switch
290 deviceId = main.ONOScli1.getDevice( "6000" ).get( 'id' )
291 assert deviceId, "No device id for s6 in ONOS"
292 roleCall = roleCall and main.ONOScli1.deviceRole(
293 deviceId,
Jon Hall65844a32015-03-09 19:09:37 -0700294 ip )
Jon Hall58c76b72015-02-23 11:09:24 -0800295 # Check assignment
Jon Hall65844a32015-03-09 19:09:37 -0700296 if ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
Jon Hall58c76b72015-02-23 11:09:24 -0800297 roleCheck = roleCheck and main.TRUE
298 else:
299 roleCheck = roleCheck and main.FALSE
300
Jon Hall65844a32015-03-09 19:09:37 -0700301 ip = nodes[ 3 ].ip_address # ONOS4
Jon Hall58c76b72015-02-23 11:09:24 -0800302 # Assign switch
303 deviceId = main.ONOScli1.getDevice( "3004" ).get( 'id' )
304 assert deviceId, "No device id for s4 in ONOS"
305 roleCall = roleCall and main.ONOScli1.deviceRole(
306 deviceId,
Jon Hall65844a32015-03-09 19:09:37 -0700307 ip )
Jon Hall58c76b72015-02-23 11:09:24 -0800308 # Check assignment
Jon Hall65844a32015-03-09 19:09:37 -0700309 if ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
Jon Hall58c76b72015-02-23 11:09:24 -0800310 roleCheck = roleCheck and main.TRUE
311 else:
312 roleCheck = roleCheck and main.FALSE
313
Jon Hall65844a32015-03-09 19:09:37 -0700314 ip = nodes[ 4 ].ip_address # ONOS5
Jon Hall58c76b72015-02-23 11:09:24 -0800315 for i in range( 8, 18 ):
316 dpid = '3' + str( i ).zfill( 3 )
317 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
318 assert deviceId, "No device id for s%i in ONOS" % i
319 roleCall = roleCall and main.ONOScli1.deviceRole(
320 deviceId,
Jon Hall65844a32015-03-09 19:09:37 -0700321 ip )
Jon Hall58c76b72015-02-23 11:09:24 -0800322 # Check assignment
Jon Hall65844a32015-03-09 19:09:37 -0700323 if ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
Jon Hall58c76b72015-02-23 11:09:24 -0800324 roleCheck = roleCheck and main.TRUE
325 else:
326 roleCheck = roleCheck and main.FALSE
327
Jon Hall65844a32015-03-09 19:09:37 -0700328 ip = nodes[ 5 ].ip_address # ONOS6
Jon Hall58c76b72015-02-23 11:09:24 -0800329 deviceId = main.ONOScli1.getDevice( "6007" ).get( 'id' )
330 assert deviceId, "No device id for s7 in ONOS"
331 roleCall = roleCall and main.ONOScli1.deviceRole(
332 deviceId,
Jon Hall65844a32015-03-09 19:09:37 -0700333 ip )
Jon Hall58c76b72015-02-23 11:09:24 -0800334 # Check assignment
Jon Hall65844a32015-03-09 19:09:37 -0700335 if ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
Jon Hall58c76b72015-02-23 11:09:24 -0800336 roleCheck = roleCheck and main.TRUE
337 else:
338 roleCheck = roleCheck and main.FALSE
339
Jon Hall65844a32015-03-09 19:09:37 -0700340 ip = nodes[ 6 ].ip_address # ONOS7
Jon Hall58c76b72015-02-23 11:09:24 -0800341 for i in range( 18, 28 ):
342 dpid = '6' + str( i ).zfill( 3 )
343 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
344 assert deviceId, "No device id for s%i in ONOS" % i
345 roleCall = roleCall and main.ONOScli1.deviceRole(
346 deviceId,
Jon Hall65844a32015-03-09 19:09:37 -0700347 ip )
Jon Hall58c76b72015-02-23 11:09:24 -0800348 # Check assignment
Jon Hall65844a32015-03-09 19:09:37 -0700349 if ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
Jon Hall58c76b72015-02-23 11:09:24 -0800350 roleCheck = roleCheck and main.TRUE
351 else:
352 roleCheck = roleCheck and main.FALSE
353 except ( AttributeError, AssertionError ):
354 main.log.exception( "Something is wrong with ONOS device view" )
355 main.log.info( main.ONOScli1.devices() )
356
Jon Hall6aec96b2015-01-19 14:49:31 -0800357 utilities.assert_equals(
358 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800359 actual=roleCall,
Jon Hall6aec96b2015-01-19 14:49:31 -0800360 onpass="Re-assigned switch mastership to designated controller",
Jon Hall8f89dda2015-01-22 16:03:33 -0800361 onfail="Something wrong with deviceRole calls" )
Jon Hall94fd0472014-12-08 11:52:42 -0800362
Jon Hall6aec96b2015-01-19 14:49:31 -0800363 utilities.assert_equals(
364 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800365 actual=roleCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800366 onpass="Switches were successfully reassigned to designated " +
367 "controller",
368 onfail="Switches were not successfully reassigned" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800369 mastershipCheck = mastershipCheck and roleCall and roleCheck
370 utilities.assert_equals( expect=main.TRUE, actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800371 onpass="Switch mastership correctly assigned",
372 onfail="Error in (re)assigning switch" +
Jon Hall8f89dda2015-01-22 16:03:33 -0800373 " mastership" )
Jon Hallb1290e82014-11-18 16:17:48 -0500374
Jon Hall6aec96b2015-01-19 14:49:31 -0800375 def CASE3( self, main ):
Jon Hallb1290e82014-11-18 16:17:48 -0500376 """
377 Assign intents
Jon Hallb1290e82014-11-18 16:17:48 -0500378 """
379 import time
Jon Hall58c76b72015-02-23 11:09:24 -0800380 import json
Jon Hall6aec96b2015-01-19 14:49:31 -0800381 main.log.report( "Adding host intents" )
382 main.case( "Adding host Intents" )
Jon Hallb1290e82014-11-18 16:17:48 -0500383
Jon Hall8f89dda2015-01-22 16:03:33 -0800384 main.step( "Discovering Hosts( Via pingall for now )" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800385 # FIXME: Once we have a host discovery mechanism, use that instead
Jon Hallb1290e82014-11-18 16:17:48 -0500386
Jon Hall6aec96b2015-01-19 14:49:31 -0800387 # install onos-app-fwd
388 main.log.info( "Install reactive forwarding app" )
Jon Hall65844a32015-03-09 19:09:37 -0700389 appResults = main.TRUE
390 threads = []
391 for i in range( numControllers ):
392 t = main.Thread( target=CLIs[i].featureInstall,
393 threadID=self.threadID,
394 name="featureInstall-" + str( i ),
395 args=["onos-app-fwd"] )
396 threads.append( t )
397 t.start()
398 self.threadID += 1
399
400 for t in threads:
401 t.join()
402 appResults = appResults and t.result
Jon Hall94fd0472014-12-08 11:52:42 -0800403
Jon Hall6aec96b2015-01-19 14:49:31 -0800404 # REACTIVE FWD test
Jon Hall8f89dda2015-01-22 16:03:33 -0800405 pingResult = main.FALSE
Jon Hallb1290e82014-11-18 16:17:48 -0500406 time1 = time.time()
Jon Hall8f89dda2015-01-22 16:03:33 -0800407 pingResult = main.Mininet1.pingall()
Jon Hall529a37f2015-01-28 10:02:00 -0800408 utilities.assert_equals(
409 expect=main.TRUE,
410 actual=pingResult,
411 onpass="Reactive Pingall test passed",
412 onfail="Reactive Pingall failed, one or more ping pairs failed" )
Jon Hallb1290e82014-11-18 16:17:48 -0500413 time2 = time.time()
Jon Hall6aec96b2015-01-19 14:49:31 -0800414 main.log.info( "Time for pingall: %2f seconds" % ( time2 - time1 ) )
Jon Hallb1290e82014-11-18 16:17:48 -0500415
Jon Hall6aec96b2015-01-19 14:49:31 -0800416 # uninstall onos-app-fwd
417 main.log.info( "Uninstall reactive forwarding app" )
Jon Hall65844a32015-03-09 19:09:37 -0700418 threads = []
419 for i in range( numControllers ):
420 t = main.Thread( target=CLIs[i].featureUninstall,
421 threadID=self.threadID,
422 name="featureUninstall-" + str( i ),
423 args=["onos-app-fwd"] )
424 threads.append( t )
425 t.start()
426 self.threadID += 1
427
428 for t in threads:
429 t.join()
430 appResults = appResults and t.result
431
Jon Hall6aec96b2015-01-19 14:49:31 -0800432 # timeout for fwd flows
433 time.sleep( 10 )
Jon Hallb1290e82014-11-18 16:17:48 -0500434
Jon Hall6aec96b2015-01-19 14:49:31 -0800435 main.step( "Add host intents" )
Jon Hall58c76b72015-02-23 11:09:24 -0800436 intentIds = []
Jon Hall6aec96b2015-01-19 14:49:31 -0800437 # TODO: move the host numbers to params
Jon Hall58c76b72015-02-23 11:09:24 -0800438 # Maybe look at all the paths we ping?
Jon Hall8f89dda2015-01-22 16:03:33 -0800439 intentAddResult = True
Jon Hall58c76b72015-02-23 11:09:24 -0800440 hostResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800441 for i in range( 8, 18 ):
442 main.log.info( "Adding host intent between h" + str( i ) +
443 " and h" + str( i + 10 ) )
444 host1 = "00:00:00:00:00:" + \
445 str( hex( i )[ 2: ] ).zfill( 2 ).upper()
446 host2 = "00:00:00:00:00:" + \
447 str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper()
Jon Hall1b8f54a2015-02-04 13:24:20 -0800448 # NOTE: getHost can return None
Jon Hall65844a32015-03-09 19:09:37 -0700449 host1Dict = CLIs[ 0 ].getHost( host1 )
450 host2Dict = CLIs[ 0 ].getHost( host2 )
Jon Hall1b8f54a2015-02-04 13:24:20 -0800451 host1Id = None
452 host2Id = None
453 if host1Dict and host2Dict:
454 host1Id = host1Dict.get( 'id', None )
455 host2Id = host2Dict.get( 'id', None )
Jon Hall8f89dda2015-01-22 16:03:33 -0800456 if host1Id and host2Id:
Jon Hall58c76b72015-02-23 11:09:24 -0800457 nodeNum = ( i % 7 ) + 1
Jon Hall65844a32015-03-09 19:09:37 -0700458 tmpId = nodes[ nodeNum ].addHostIntent( host1Id, host2Id )
Jon Hall63604932015-02-26 17:09:50 -0800459 if tmpId:
460 main.log.info( "Added intent with id: " + tmpId )
461 intentIds.append( tmpId )
462 else:
Jon Hall65844a32015-03-09 19:09:37 -0700463 main.log.error( "addHostIntent returned None" )
Jon Hall669173b2014-12-17 11:36:30 -0800464 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800465 main.log.error( "Error, getHost() failed" )
Jon Hall65844a32015-03-09 19:09:37 -0700466 main.log.warn( json.dumps( json.loads( CLIs[ 0 ].hosts() ),
Jon Hall1b8f54a2015-02-04 13:24:20 -0800467 sort_keys=True,
468 indent=4,
469 separators=( ',', ': ' ) ) )
Jon Hall58c76b72015-02-23 11:09:24 -0800470 hostResult = main.FALSE
471 onosIds = main.ONOScli1.getAllIntentsId()
472 main.log.info( "Submitted intents: " + str( intentIds ) )
473 main.log.info( "Intents in ONOS: " + str( onosIds ) )
474 for intent in intentIds:
475 if intent in onosIds:
476 pass # intent submitted is still in onos
477 else:
478 intentAddResult = False
Jon Hall1b8f54a2015-02-04 13:24:20 -0800479 # Print the intent states
Jon Hall58c76b72015-02-23 11:09:24 -0800480 intents = main.ONOScli1.intents()
Jon Hall1b8f54a2015-02-04 13:24:20 -0800481 intentStates = []
Jon Hall65844a32015-03-09 19:09:37 -0700482 installedCheck = True
Jon Hall58c76b72015-02-23 11:09:24 -0800483 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
484 count = 0
Jon Hall1b8f54a2015-02-04 13:24:20 -0800485 for intent in json.loads( intents ): # Iter through intents of a node
Jon Hall58c76b72015-02-23 11:09:24 -0800486 state = intent.get( 'state', None )
Jon Hall63604932015-02-26 17:09:50 -0800487 if "INSTALLED" not in state:
488 installedCheck = False
Jon Hall58c76b72015-02-23 11:09:24 -0800489 intentId = intent.get( 'id', None )
490 intentStates.append( ( intentId, state ) )
491 # add submitted intents not in the store
492 tmplist = [ i for i, s in intentStates ]
493 missingIntents = False
494 for i in intentIds:
495 if i not in tmplist:
496 intentStates.append( ( i, " - " ) )
497 missingIntents = True
498 intentStates.sort()
499 for i, s in intentStates:
500 count += 1
501 main.log.info( "%-6s%-15s%-15s" %
502 ( str( count ), str( i ), str( s ) ) )
Jon Hall63604932015-02-26 17:09:50 -0800503 main.ONOScli1.leaders()
504 main.ONOScli1.partitions()
505 # for node in nodes:
506 # node.pendingMap()
507 pendingMap = main.ONOScli1.pendingMap()
Jon Hall58c76b72015-02-23 11:09:24 -0800508 intentAddResult = bool( pingResult and hostResult and intentAddResult
Jon Hall63604932015-02-26 17:09:50 -0800509 and not missingIntents and installedCheck )
Jon Hall6aec96b2015-01-19 14:49:31 -0800510 utilities.assert_equals(
511 expect=True,
Jon Hall8f89dda2015-01-22 16:03:33 -0800512 actual=intentAddResult,
513 onpass="Pushed host intents to ONOS",
514 onfail="Error in pushing host intents to ONOS" )
Jon Hall58c76b72015-02-23 11:09:24 -0800515
Jon Hall63604932015-02-26 17:09:50 -0800516 if not intentAddResult or "key" in pendingMap:
Jon Hall58c76b72015-02-23 11:09:24 -0800517 import time
Jon Hall63604932015-02-26 17:09:50 -0800518 installedCheck = True
Jon Hall58c76b72015-02-23 11:09:24 -0800519 main.log.info( "Sleeping 60 seconds to see if intents are found" )
520 time.sleep( 60 )
521 onosIds = main.ONOScli1.getAllIntentsId()
522 main.log.info( "Submitted intents: " + str( intentIds ) )
523 main.log.info( "Intents in ONOS: " + str( onosIds ) )
524 # Print the intent states
525 intents = main.ONOScli1.intents()
526 intentStates = []
527 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
528 count = 0
529 for intent in json.loads( intents ):
530 # Iter through intents of a node
531 state = intent.get( 'state', None )
Jon Hall63604932015-02-26 17:09:50 -0800532 if "INSTALLED" not in state:
533 installedCheck = False
Jon Hall58c76b72015-02-23 11:09:24 -0800534 intentId = intent.get( 'id', None )
535 intentStates.append( ( intentId, state ) )
536 # add submitted intents not in the store
537 tmplist = [ i for i, s in intentStates ]
538 for i in intentIds:
539 if i not in tmplist:
540 intentStates.append( ( i, " - " ) )
541 intentStates.sort()
542 for i, s in intentStates:
543 count += 1
544 main.log.info( "%-6s%-15s%-15s" %
545 ( str( count ), str( i ), str( s ) ) )
Jon Hall63604932015-02-26 17:09:50 -0800546 main.ONOScli1.leaders()
547 main.ONOScli1.pendingMap()
Jon Hallb1290e82014-11-18 16:17:48 -0500548
Jon Hall6aec96b2015-01-19 14:49:31 -0800549 def CASE4( self, main ):
Jon Hallb1290e82014-11-18 16:17:48 -0500550 """
551 Ping across added host intents
552 """
Jon Hall58c76b72015-02-23 11:09:24 -0800553 import json
Jon Hall65844a32015-03-09 19:09:37 -0700554 import time
Jon Hall368769f2014-11-19 15:43:35 -0800555 description = " Ping across added host intents"
Jon Hall6aec96b2015-01-19 14:49:31 -0800556 main.log.report( description )
557 main.case( description )
Jon Hall8f89dda2015-01-22 16:03:33 -0800558 PingResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800559 for i in range( 8, 18 ):
Jon Hall58c76b72015-02-23 11:09:24 -0800560 ping = main.Mininet1.pingHost( src="h" + str( i ),
561 target="h" + str( i + 10 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800562 PingResult = PingResult and ping
Jon Hall6aec96b2015-01-19 14:49:31 -0800563 if ping == main.FALSE:
564 main.log.warn( "Ping failed between h" + str( i ) +
565 " and h" + str( i + 10 ) )
566 elif ping == main.TRUE:
567 main.log.info( "Ping test passed!" )
Jon Hall21270ac2015-02-16 17:59:55 -0800568 # Don't set PingResult or you'd override failures
Jon Hall8f89dda2015-01-22 16:03:33 -0800569 if PingResult == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800570 main.log.report(
571 "Intents have not been installed correctly, pings failed." )
Jon Hall58c76b72015-02-23 11:09:24 -0800572 # TODO: pretty print
Jon Hall65844a32015-03-09 19:09:37 -0700573 main.log.warn( "ONOS1 intents: " )
Jon Hall529a37f2015-01-28 10:02:00 -0800574 main.log.warn( json.dumps( json.loads( main.ONOScli1.intents() ),
575 sort_keys=True,
576 indent=4,
577 separators=( ',', ': ' ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800578 if PingResult == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800579 main.log.report(
580 "Intents have been installed correctly and verified by pings" )
581 utilities.assert_equals(
582 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800583 actual=PingResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800584 onpass="Intents have been installed correctly and pings work",
585 onfail="Intents have not been installed correctly, pings failed." )
Jon Hallb1290e82014-11-18 16:17:48 -0500586
Jon Hall63604932015-02-26 17:09:50 -0800587 installedCheck = True
Jon Hall58c76b72015-02-23 11:09:24 -0800588 if PingResult is not main.TRUE:
589 # Print the intent states
590 intents = main.ONOScli1.intents()
591 intentStates = []
592 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
593 count = 0
594 # Iter through intents of a node
595 for intent in json.loads( intents ):
596 state = intent.get( 'state', None )
Jon Hall63604932015-02-26 17:09:50 -0800597 if "INSTALLED" not in state:
598 installedCheck = False
Jon Hall58c76b72015-02-23 11:09:24 -0800599 intentId = intent.get( 'id', None )
600 intentStates.append( ( intentId, state ) )
601 intentStates.sort()
602 for i, s in intentStates:
603 count += 1
604 main.log.info( "%-6s%-15s%-15s" %
605 ( str( count ), str( i ), str( s ) ) )
Jon Hall63604932015-02-26 17:09:50 -0800606 main.ONOScli1.leaders()
607 main.ONOScli1.partitions()
608 main.ONOScli1.pendingMap()
Jon Hall63604932015-02-26 17:09:50 -0800609 if not installedCheck:
Jon Hall65844a32015-03-09 19:09:37 -0700610 main.log.info( "Waiting 60 seconds to see if the state of " +
611 "intents change" )
Jon Hall63604932015-02-26 17:09:50 -0800612 time.sleep( 60 )
613 # Print the intent states
614 intents = main.ONOScli1.intents()
615 intentStates = []
616 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
617 count = 0
618 # Iter through intents of a node
619 for intent in json.loads( intents ):
620 state = intent.get( 'state', None )
621 if "INSTALLED" not in state:
622 installedCheck = False
623 intentId = intent.get( 'id', None )
624 intentStates.append( ( intentId, state ) )
625 intentStates.sort()
626 for i, s in intentStates:
627 count += 1
628 main.log.info( "%-6s%-15s%-15s" %
629 ( str( count ), str( i ), str( s ) ) )
630 main.ONOScli1.leaders()
631 main.ONOScli1.partitions()
632 main.ONOScli1.pendingMap()
Jon Hallb1290e82014-11-18 16:17:48 -0500633
Jon Hall6aec96b2015-01-19 14:49:31 -0800634 def CASE5( self, main ):
635 """
Jon Hallb1290e82014-11-18 16:17:48 -0500636 Reading state of ONOS
Jon Hall6aec96b2015-01-19 14:49:31 -0800637 """
Jon Hallb1290e82014-11-18 16:17:48 -0500638 import json
Jon Hall6aec96b2015-01-19 14:49:31 -0800639 # assumes that sts is already in you PYTHONPATH
640 from sts.topology.teston_topology import TestONTopology
Jon Hallb1290e82014-11-18 16:17:48 -0500641
Jon Hall6aec96b2015-01-19 14:49:31 -0800642 main.log.report( "Setting up and gathering data for current state" )
643 main.case( "Setting up and gathering data for current state" )
644 # The general idea for this test case is to pull the state of
645 # ( intents,flows, topology,... ) from each ONOS node
Jon Hall65844a32015-03-09 19:09:37 -0700646 # We can then compare them with each other and also with past states
Jon Hallb1290e82014-11-18 16:17:48 -0500647
Jon Hall65844a32015-03-09 19:09:37 -0700648 main.step( "Check that each switch has a master" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800649 global mastershipState
650 mastershipState = []
Jon Hall94fd0472014-12-08 11:52:42 -0800651
Jon Hall6aec96b2015-01-19 14:49:31 -0800652 # Assert that each device has a master
Jon Hall65844a32015-03-09 19:09:37 -0700653 rolesNotNull = main.TRUE
654 threads = []
655 for i in range( numControllers ):
656 t = main.Thread( target=CLIs[i].rolesNotNull,
657 threadID=self.threadID,
658 name="rolesNotNull-" + str( i ),
659 args=[] )
660 threads.append( t )
661 t.start()
662 self.threadID += 1
663
664 for t in threads:
665 t.join()
666 rolesNotNull = rolesNotNull and t.result
Jon Hall6aec96b2015-01-19 14:49:31 -0800667 utilities.assert_equals(
668 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800669 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -0800670 onpass="Each device has a master",
671 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -0800672
Jon Hall65844a32015-03-09 19:09:37 -0700673 main.step( "Get the Mastership of each switch from each controller" )
674 ONOSMastership = []
675 mastershipCheck = main.FALSE
676 consistentMastership = True
677 rolesResults = True
678 threads = []
679 for i in range( numControllers ):
680 t = main.Thread( target=CLIs[i].roles,
681 threadID=self.threadID,
682 name="roles-" + str( i ),
683 args=[] )
684 threads.append( t )
685 t.start()
686 self.threadID += 1
687
688 for t in threads:
689 t.join()
690 ONOSMastership.append( t.result )
691
692 for i in range( numControllers ):
693 if not ONOSMastership[i] or "Error" in ONOSMastership[i]:
694 main.log.report( "Error in getting ONOS" + str( i + 1 ) +
695 " roles" )
696 main.log.warn(
697 "ONOS" + str( i + 1 ) + " mastership response: " +
698 repr( ONOSMastership[i] ) )
699 rolesResults = False
700 utilities.assert_equals(
701 expect=True,
702 actual=rolesResults,
703 onpass="No error in reading roles output",
704 onfail="Error in reading roles from ONOS" )
705
706 main.step( "Check for consistency in roles from each controller" )
707 if all([ i == ONOSMastership[ 0 ] for i in ONOSMastership ] ):
Jon Hall6aec96b2015-01-19 14:49:31 -0800708 main.log.report(
709 "Switch roles are consistent across all ONOS nodes" )
Jon Hallb1290e82014-11-18 16:17:48 -0500710 else:
Jon Hall65844a32015-03-09 19:09:37 -0700711 consistentMastership = False
Jon Hall6aec96b2015-01-19 14:49:31 -0800712 utilities.assert_equals(
Jon Hall65844a32015-03-09 19:09:37 -0700713 expect=True,
Jon Hall8f89dda2015-01-22 16:03:33 -0800714 actual=consistentMastership,
Jon Hall6aec96b2015-01-19 14:49:31 -0800715 onpass="Switch roles are consistent across all ONOS nodes",
716 onfail="ONOS nodes have different views of switch roles" )
Jon Hallb1290e82014-11-18 16:17:48 -0500717
Jon Hall65844a32015-03-09 19:09:37 -0700718 if rolesResults and not consistentMastership:
719 for i in range( numControllers ):
720 main.log.warn(
721 "ONOS" + str( i + 1 ) + " roles: ",
722 json.dumps(
723 json.loads( ONOSMastership[ i ] ),
724 sort_keys=True,
725 indent=4,
726 separators=( ',', ': ' ) ) )
727 elif rolesResults and not consistentMastership:
728 mastershipCheck = main.TRUE
729 mastershipState = ONOSMastership[ 0 ]
730
Jon Hall6aec96b2015-01-19 14:49:31 -0800731 main.step( "Get the intents from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800732 global intentState
733 intentState = []
Jon Hall65844a32015-03-09 19:09:37 -0700734 ONOSIntents = []
Jon Hall8f89dda2015-01-22 16:03:33 -0800735 intentCheck = main.FALSE
Jon Hall65844a32015-03-09 19:09:37 -0700736 consistentIntents = True
737 intentsResults = True
738 threads = []
739 for i in range( numControllers ):
740 t = main.Thread( target=CLIs[i].intents,
741 threadID=self.threadID,
742 name="intents-" + str( i ),
743 args=[],
744 kwargs={ 'jsonFormat': True } )
745 threads.append( t )
746 t.start()
747 self.threadID += 1
748
749 for t in threads:
750 t.join()
751 ONOSIntents.append( t.result )
752
753 for i in range( numControllers ):
754 if not ONOSIntents[ i ] or "Error" in ONOSIntents[ i ]:
755 main.log.report( "Error in getting ONOS" + str( i + 1 ) +
756 " intents" )
757 main.log.warn( "ONOS" + str( i + 1 ) + " intents response: " +
758 repr( ONOSIntents[ i ] ) )
759 intentsResults = False
Jon Hall6aec96b2015-01-19 14:49:31 -0800760 utilities.assert_equals(
Jon Hall65844a32015-03-09 19:09:37 -0700761 expect=True,
762 actual=intentsResults,
763 onpass="No error in reading intents output",
764 onfail="Error in reading intents from ONOS" )
765
766 main.step( "Check for consistency in Intents from each controller" )
767 if all([ i == ONOSIntents[ 0 ] for i in ONOSIntents ] ):
768 main.log.report( "Intents are consistent across all ONOS " +
769 "nodes" )
770 else:
771 consistentIntents = False
772 utilities.assert_equals(
773 expect=True,
774 actual=consistentIntents,
Jon Hall6aec96b2015-01-19 14:49:31 -0800775 onpass="Intents are consistent across all ONOS nodes",
776 onfail="ONOS nodes have different views of intents" )
Jon Hallb1290e82014-11-18 16:17:48 -0500777
Jon Hall65844a32015-03-09 19:09:37 -0700778 if intentsResults and not consistentIntents:
779 for i in range( numControllers ):
780 main.log.warn(
781 "ONOS" + str( i + 1 ) + " intents: ",
782 json.dumps(
783 json.loads( ONOSIntents[i] ),
784 sort_keys=True,
785 indent=4,
786 separators=( ',', ': ' ) ) )
787 elif intentsResults and consistentIntents:
788 intentCheck = main.TRUE
789 intentState = ONOSIntents[ 0 ]
790
Jon Hall6aec96b2015-01-19 14:49:31 -0800791 main.step( "Get the flows from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800792 global flowState
793 flowState = []
Jon Hall65844a32015-03-09 19:09:37 -0700794 ONOSFlows = []
795 ONOSFlowsJson = []
Jon Hall8f89dda2015-01-22 16:03:33 -0800796 flowCheck = main.FALSE
Jon Hall65844a32015-03-09 19:09:37 -0700797 consistentFlows = True
798 flowsResults = True
799 threads = []
800 for i in range( numControllers ):
801 t = main.Thread( target=CLIs[i].flows,
802 threadID=self.threadID,
803 name="flows-" + str( i ),
804 args=[],
805 kwargs={ 'jsonFormat': True } )
806 threads.append( t )
807 t.start()
808 self.threadID += 1
809
810 for t in threads:
811 t.join()
812 result = t.result()
813 ONOSFlows.append( result )
814
815 for i in range( numControllers ):
816 num = str( i + 1 )
817 if not ONOSFlows[ i ] or "Error" in ONOSFlows[ i ]:
818 main.log.report( "Error in getting ONOS" + num + " flows" )
819 main.log.warn( "ONOS" + num + " flows response: " +
820 repr( ONOSFlows[ i ] ) )
821 flowsResults = False
822 ONOSFlowsJson.append( None )
Jon Hall58c76b72015-02-23 11:09:24 -0800823 else:
Jon Hall65844a32015-03-09 19:09:37 -0700824 try:
825 ONOSFlowsJson.append( json.loads( ONOSFlows[ i ] ) )
826 except ( ValueError, TypeError ):
827 # FIXME: change this to log.error?
828 main.log.exception( "Error in parsing ONOS" + num +
829 " response as json." )
830 ONOSFlowsJson.append( None )
831 flowsResults = False
Jon Hall6aec96b2015-01-19 14:49:31 -0800832 utilities.assert_equals(
Jon Hall65844a32015-03-09 19:09:37 -0700833 expect=True,
834 actual=flowsResults,
835 onpass="No error in reading flows output",
836 onfail="Error in reading flows from ONOS" )
837
838 main.step( "Check for consistency in Flows from each controller" )
839 tmp = [ len( i ) == len( ONOSFlowsJson[ 0 ] ) for i in ONOSFlowsJson ]
840 if all( tmp ):
841 main.log.report( "Flow count is consistent across all ONOS nodes" )
842 else:
843 consistentFlows = False
844 utilities.assert_equals(
845 expect=True,
846 actual=consistentFlows,
Jon Hall6aec96b2015-01-19 14:49:31 -0800847 onpass="The flow count is consistent across all ONOS nodes",
848 onfail="ONOS nodes have different flow counts" )
Jon Hallb1290e82014-11-18 16:17:48 -0500849
Jon Hall65844a32015-03-09 19:09:37 -0700850 if flowsResults and not consistentFlows:
851 for i in range( numControllers ):
852 main.log.warn(
853 "ONOS" + str( i + 1 ) + " flows: ",
854 json.dumps( json.loads( ONOSFlows[i] ), sort_keys=True,
855 indent=4, separators=( ',', ': ' ) ) )
856 elif flowsResults and consistentFlows:
857 flowCheck = main.TRUE
858 flowState = ONOSFlows[ 0 ]
859
Jon Hall6aec96b2015-01-19 14:49:31 -0800860 main.step( "Get the OF Table entries" )
Jon Hallb1290e82014-11-18 16:17:48 -0500861 global flows
Jon Hall6aec96b2015-01-19 14:49:31 -0800862 flows = []
863 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800864 flows.append( main.Mininet2.getFlowTable( 1.3, "s" + str( i ) ) )
Jon Hall58c76b72015-02-23 11:09:24 -0800865 if flowCheck == main.FALSE:
866 for table in flows:
867 main.log.warn( table )
Jon Hall6aec96b2015-01-19 14:49:31 -0800868 # TODO: Compare switch flow tables with ONOS flow tables
Jon Hallb1290e82014-11-18 16:17:48 -0500869
Jon Hall6aec96b2015-01-19 14:49:31 -0800870 main.step( "Start continuous pings" )
871 main.Mininet2.pingLong(
872 src=main.params[ 'PING' ][ 'source1' ],
873 target=main.params[ 'PING' ][ 'target1' ],
874 pingTime=500 )
875 main.Mininet2.pingLong(
876 src=main.params[ 'PING' ][ 'source2' ],
877 target=main.params[ 'PING' ][ 'target2' ],
878 pingTime=500 )
879 main.Mininet2.pingLong(
880 src=main.params[ 'PING' ][ 'source3' ],
881 target=main.params[ 'PING' ][ 'target3' ],
882 pingTime=500 )
883 main.Mininet2.pingLong(
884 src=main.params[ 'PING' ][ 'source4' ],
885 target=main.params[ 'PING' ][ 'target4' ],
886 pingTime=500 )
887 main.Mininet2.pingLong(
888 src=main.params[ 'PING' ][ 'source5' ],
889 target=main.params[ 'PING' ][ 'target5' ],
890 pingTime=500 )
891 main.Mininet2.pingLong(
892 src=main.params[ 'PING' ][ 'source6' ],
893 target=main.params[ 'PING' ][ 'target6' ],
894 pingTime=500 )
895 main.Mininet2.pingLong(
896 src=main.params[ 'PING' ][ 'source7' ],
897 target=main.params[ 'PING' ][ 'target7' ],
898 pingTime=500 )
899 main.Mininet2.pingLong(
900 src=main.params[ 'PING' ][ 'source8' ],
901 target=main.params[ 'PING' ][ 'target8' ],
902 pingTime=500 )
903 main.Mininet2.pingLong(
904 src=main.params[ 'PING' ][ 'source9' ],
905 target=main.params[ 'PING' ][ 'target9' ],
906 pingTime=500 )
907 main.Mininet2.pingLong(
908 src=main.params[ 'PING' ][ 'source10' ],
909 target=main.params[ 'PING' ][ 'target10' ],
910 pingTime=500 )
Jon Hallb1290e82014-11-18 16:17:48 -0500911
Jon Hall6aec96b2015-01-19 14:49:31 -0800912 main.step( "Create TestONTopology object" )
Jon Hallb1290e82014-11-18 16:17:48 -0500913 ctrls = []
914 count = 1
Jon Hall65844a32015-03-09 19:09:37 -0700915 print " Testing new sts tuple..."
916 for node in nodes:
917 temp = ( node, node.name, node.ip_address, 6633 )
918 print temp
919 ctrls.append( temp )
920 print " Testing old sts tuple..."
Jon Hallb1290e82014-11-18 16:17:48 -0500921 while True:
922 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -0800923 if ( 'ip' + str( count ) ) in main.params[ 'CTRL' ]:
924 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
925 temp = temp + ( "ONOS" + str( count ), )
926 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
927 temp = temp + \
928 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
Jon Hall65844a32015-03-09 19:09:37 -0700929 print temp
Jon Hall6aec96b2015-01-19 14:49:31 -0800930 ctrls.append( temp )
Jon Hall65844a32015-03-09 19:09:37 -0700931 count += 1
Jon Hallb1290e82014-11-18 16:17:48 -0500932 else:
933 break
Jon Hall65844a32015-03-09 19:09:37 -0700934 MNTopo = TestONTopology( main.Mininet1, ctrls )
Jon Hallb1290e82014-11-18 16:17:48 -0500935
Jon Hall6aec96b2015-01-19 14:49:31 -0800936 main.step( "Collecting topology information from ONOS" )
Jon Hallb1290e82014-11-18 16:17:48 -0500937 devices = []
Jon Hall65844a32015-03-09 19:09:37 -0700938 threads = []
939 for i in range( numControllers ):
940 t = main.Thread( target=CLIs[i].devices,
941 threadID=self.threadID,
942 name="devices-" + str( i ),
943 args=[ ] )
944 threads.append( t )
945 t.start()
946 self.threadID += 1
947
948 for t in threads:
949 t.join()
950 devices.append( t.result )
Jon Hallb1290e82014-11-18 16:17:48 -0500951 hosts = []
Jon Hall65844a32015-03-09 19:09:37 -0700952 threads = []
953 for i in range( numControllers ):
954 t = main.Thread( target=CLIs[i].hosts,
955 threadID=self.threadID,
956 name="hosts-" + str( i ),
957 args=[ ] )
958 threads.append( t )
959 t.start()
960 self.threadID += 1
961
962 for t in threads:
963 t.join()
964 try:
965 hosts.append( json.loads( t.result ) )
966 except ( ValueError, TypeError ):
967 # FIXME: better handling of this, print which node
968 # Maybe use thread name?
969 main.log.exception( "Error parsing json output of hosts" )
970
Jon Hallb1290e82014-11-18 16:17:48 -0500971 ports = []
Jon Hall65844a32015-03-09 19:09:37 -0700972 threads = []
973 for i in range( numControllers ):
974 t = main.Thread( target=CLIs[i].ports,
975 threadID=self.threadID,
976 name="ports-" + str( i ),
977 args=[ ] )
978 threads.append( t )
979 t.start()
980 self.threadID += 1
981
982 for t in threads:
983 t.join()
984 ports.append( t.result )
Jon Hallb1290e82014-11-18 16:17:48 -0500985 links = []
Jon Hall65844a32015-03-09 19:09:37 -0700986 threads = []
987 for i in range( numControllers ):
988 t = main.Thread( target=CLIs[i].links,
989 threadID=self.threadID,
990 name="links-" + str( i ),
991 args=[ ] )
992 threads.append( t )
993 t.start()
994 self.threadID += 1
995
996 for t in threads:
997 t.join()
998 links.append( t.result )
Jon Hall94fd0472014-12-08 11:52:42 -0800999 clusters = []
Jon Hall65844a32015-03-09 19:09:37 -07001000 threads = []
1001 for i in range( numControllers ):
1002 t = main.Thread( target=CLIs[i].clusters,
1003 threadID=self.threadID,
1004 name="clusters-" + str( i ),
1005 args=[ ] )
1006 threads.append( t )
1007 t.start()
1008 self.threadID += 1
1009
1010 for t in threads:
1011 t.join()
1012 clusters.append( t.result )
Jon Hall529a37f2015-01-28 10:02:00 -08001013 # Compare json objects for hosts and dataplane clusters
Jon Hall94fd0472014-12-08 11:52:42 -08001014
Jon Hall6aec96b2015-01-19 14:49:31 -08001015 # hosts
Jon Hall8f89dda2015-01-22 16:03:33 -08001016 consistentHostsResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -08001017 for controller in range( len( hosts ) ):
Jon Hall8f89dda2015-01-22 16:03:33 -08001018 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001019 if "Error" not in hosts[ controller ]:
1020 if hosts[ controller ] == hosts[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001021 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001022 else: # hosts not consistent
1023 main.log.report( "hosts from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001024 controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001025 " is inconsistent with ONOS1" )
1026 main.log.warn( repr( hosts[ controller ] ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001027 consistentHostsResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001028
1029 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001030 main.log.report( "Error in getting ONOS hosts from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001031 controllerStr )
1032 consistentHostsResult = main.FALSE
1033 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001034 " hosts response: " +
1035 repr( hosts[ controller ] ) )
1036 utilities.assert_equals(
1037 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001038 actual=consistentHostsResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001039 onpass="Hosts view is consistent across all ONOS nodes",
1040 onfail="ONOS nodes have different views of hosts" )
Jon Hall94fd0472014-12-08 11:52:42 -08001041
Jon Hall58c76b72015-02-23 11:09:24 -08001042 ipResult = main.TRUE
1043 for controller in range( 0, len( hosts ) ):
1044 controllerStr = str( controller + 1 )
1045 for host in hosts[ controller ]:
Jon Hall65844a32015-03-09 19:09:37 -07001046 if not host.get( 'ips', [ ] ):
1047 main.log.error( "DEBUG:Error with host ips on controller" +
1048 controllerStr + ": " + str( host ) )
Jon Hall58c76b72015-02-23 11:09:24 -08001049 ipResult = main.FALSE
1050 utilities.assert_equals(
1051 expect=main.TRUE,
1052 actual=ipResult,
1053 onpass="The ips of the hosts aren't empty",
1054 onfail="The ip of at least one host is missing" )
1055
Jon Hall6aec96b2015-01-19 14:49:31 -08001056 # Strongly connected clusters of devices
Jon Hall8f89dda2015-01-22 16:03:33 -08001057 consistentClustersResult = main.TRUE
Jon Hall65844a32015-03-09 19:09:37 -07001058 for controller in range( 0, len( clusters ) ):
1059 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001060 if "Error" not in clusters[ controller ]:
1061 if clusters[ controller ] == clusters[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001062 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001063 else: # clusters not consistent
Jon Hall65844a32015-03-09 19:09:37 -07001064 main.log.report( "clusters from ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001065 " is inconsistent with ONOS1" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001066 consistentClustersResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001067
1068 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001069 main.log.report( "Error in getting dataplane clusters " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001070 "from ONOS" + controllerStr )
1071 consistentClustersResult = main.FALSE
1072 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001073 " clusters response: " +
1074 repr( clusters[ controller ] ) )
1075 utilities.assert_equals(
1076 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001077 actual=consistentClustersResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001078 onpass="Clusters view is consistent across all ONOS nodes",
1079 onfail="ONOS nodes have different views of clusters" )
1080 # there should always only be one cluster
Jon Hall8f89dda2015-01-22 16:03:33 -08001081 numClusters = len( json.loads( clusters[ 0 ] ) )
Jon Hall58c76b72015-02-23 11:09:24 -08001082 clusterResults = main.FALSE
1083 if numClusters == 1:
1084 clusterResults = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001085 utilities.assert_equals(
1086 expect=1,
Jon Hall8f89dda2015-01-22 16:03:33 -08001087 actual=numClusters,
Jon Hall6aec96b2015-01-19 14:49:31 -08001088 onpass="ONOS shows 1 SCC",
Jon Hall58c76b72015-02-23 11:09:24 -08001089 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
Jon Hall94fd0472014-12-08 11:52:42 -08001090
Jon Hall6aec96b2015-01-19 14:49:31 -08001091 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001092 devicesResults = main.TRUE
1093 portsResults = main.TRUE
1094 linksResults = main.TRUE
1095 for controller in range( numControllers ):
1096 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001097 if devices[ controller ] or "Error" not in devices[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001098 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -08001099 MNTopo,
Jon Hall65844a32015-03-09 19:09:37 -07001100 json.loads( devices[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001101 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001102 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001103 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001104 actual=currentDevicesResult,
1105 onpass="ONOS" + controllerStr +
1106 " Switches view is correct",
1107 onfail="ONOS" + controllerStr +
1108 " Switches view is incorrect" )
Jon Hallb1290e82014-11-18 16:17:48 -05001109
Jon Hall6aec96b2015-01-19 14:49:31 -08001110 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001111 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -08001112 MNTopo,
Jon Hall65844a32015-03-09 19:09:37 -07001113 json.loads( ports[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001114 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001115 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001116 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001117 actual=currentPortsResult,
1118 onpass="ONOS" + controllerStr +
1119 " ports view is correct",
1120 onfail="ONOS" + controllerStr +
1121 " ports view is incorrect" )
Jon Hallb1290e82014-11-18 16:17:48 -05001122
Jon Hall6aec96b2015-01-19 14:49:31 -08001123 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001124 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -08001125 MNTopo,
Jon Hall65844a32015-03-09 19:09:37 -07001126 json.loads( links[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001127 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001128 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001129 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001130 actual=currentLinksResult,
1131 onpass="ONOS" + controllerStr +
1132 " links view is correct",
1133 onfail="ONOS" + controllerStr +
1134 " links view is incorrect" )
Jon Hallb1290e82014-11-18 16:17:48 -05001135
Jon Hall8f89dda2015-01-22 16:03:33 -08001136 devicesResults = devicesResults and currentDevicesResult
1137 portsResults = portsResults and currentPortsResult
1138 linksResults = linksResults and currentLinksResult
Jon Hallb1290e82014-11-18 16:17:48 -05001139
Jon Hall65844a32015-03-09 19:09:37 -07001140 topoResult = ( devicesResults and portsResults and linksResults
1141 and consistentHostsResult and consistentClustersResult
1142 and clusterResults and ipResult )
Jon Hall8f89dda2015-01-22 16:03:33 -08001143 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
Jon Hall58c76b72015-02-23 11:09:24 -08001144 onpass="Topology Check Test successful",
1145 onfail="Topology Check Test NOT successful" )
Jon Hallb1290e82014-11-18 16:17:48 -05001146
Jon Hall8f89dda2015-01-22 16:03:33 -08001147 finalAssert = main.TRUE
Jon Hall65844a32015-03-09 19:09:37 -07001148 finalAssert = ( finalAssert and topoResult and flowCheck
1149 and intentCheck and consistentMastership
1150 and rolesNotNull )
Jon Hall8f89dda2015-01-22 16:03:33 -08001151 utilities.assert_equals( expect=main.TRUE, actual=finalAssert,
Jon Hall58c76b72015-02-23 11:09:24 -08001152 onpass="State check successful",
1153 onfail="State check NOT successful" )
Jon Hallb1290e82014-11-18 16:17:48 -05001154
Jon Hall6aec96b2015-01-19 14:49:31 -08001155 def CASE6( self, main ):
1156 """
Jon Hallb1290e82014-11-18 16:17:48 -05001157 The Failure case. Since this is the Sanity test, we do nothing.
Jon Hall6aec96b2015-01-19 14:49:31 -08001158 """
Jon Hall368769f2014-11-19 15:43:35 -08001159 import time
Jon Hall6aec96b2015-01-19 14:49:31 -08001160 main.log.report( "Wait 60 seconds instead of inducing a failure" )
1161 time.sleep( 60 )
1162 utilities.assert_equals(
1163 expect=main.TRUE,
1164 actual=main.TRUE,
1165 onpass="Sleeping 60 seconds",
1166 onfail="Something is terribly wrong with my math" )
Jon Hallb1290e82014-11-18 16:17:48 -05001167
Jon Hall6aec96b2015-01-19 14:49:31 -08001168 def CASE7( self, main ):
1169 """
Jon Hall368769f2014-11-19 15:43:35 -08001170 Check state after ONOS failure
Jon Hall6aec96b2015-01-19 14:49:31 -08001171 """
Jon Hallb1290e82014-11-18 16:17:48 -05001172 import json
Jon Hall6aec96b2015-01-19 14:49:31 -08001173 main.case( "Running ONOS Constant State Tests" )
Jon Hallb1290e82014-11-18 16:17:48 -05001174
Jon Hall65844a32015-03-09 19:09:37 -07001175 main.step( "Check that each switch has a master" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001176 # Assert that each device has a master
Jon Hall65844a32015-03-09 19:09:37 -07001177 rolesNotNull = main.TRUE
1178 threads = []
1179 for i in range( numControllers ):
1180 t = main.Thread( target=CLIs[i].rolesNotNull,
1181 threadID=self.threadID,
1182 name="rolesNotNull-" + str( i ),
1183 args=[ ] )
1184 threads.append( t )
1185 t.start()
1186 self.threadID += 1
1187
1188 for t in threads:
1189 t.join()
1190 rolesNotNull = rolesNotNull and t.result
Jon Hall6aec96b2015-01-19 14:49:31 -08001191 utilities.assert_equals(
1192 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001193 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -08001194 onpass="Each device has a master",
1195 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -08001196
Jon Hall65844a32015-03-09 19:09:37 -07001197 ONOSMastership = []
1198 mastershipCheck = main.FALSE
1199 consistentMastership = True
1200 rolesResults = True
1201 threads = []
1202 for i in range( numControllers ):
1203 t = main.Thread( target=CLIs[i].roles,
1204 threadID=self.threadID,
1205 name="roles-" + str( i ),
1206 args=[] )
1207 threads.append( t )
1208 t.start()
1209 self.threadID += 1
1210
1211 for t in threads:
1212 t.join()
1213 ONOSMastership.append( t.result )
1214
1215 for i in range( numControllers ):
1216 if not ONOSMastership[i] or "Error" in ONOSMastership[i]:
1217 main.log.report( "Error in getting ONOS" + str( i + 1 ) +
1218 " roles" )
1219 main.log.warn(
1220 "ONOS" + str( i + 1 ) + " mastership response: " +
1221 repr( ONOSMastership[i] ) )
1222 rolesResults = False
1223 utilities.assert_equals(
1224 expect=True,
1225 actual=rolesResults,
1226 onpass="No error in reading roles output",
1227 onfail="Error in reading roles from ONOS" )
1228
1229 main.step( "Check for consistency in roles from each controller" )
1230 if all([ i == ONOSMastership[ 0 ] for i in ONOSMastership ] ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001231 main.log.report(
1232 "Switch roles are consistent across all ONOS nodes" )
Jon Hallb1290e82014-11-18 16:17:48 -05001233 else:
Jon Hall65844a32015-03-09 19:09:37 -07001234 consistentMastership = False
Jon Hall6aec96b2015-01-19 14:49:31 -08001235 utilities.assert_equals(
Jon Hall65844a32015-03-09 19:09:37 -07001236 expect=True,
Jon Hall8f89dda2015-01-22 16:03:33 -08001237 actual=consistentMastership,
Jon Hall6aec96b2015-01-19 14:49:31 -08001238 onpass="Switch roles are consistent across all ONOS nodes",
1239 onfail="ONOS nodes have different views of switch roles" )
Jon Hallb1290e82014-11-18 16:17:48 -05001240
Jon Hall65844a32015-03-09 19:09:37 -07001241 if rolesResults and not consistentMastership:
1242 for i in range( numControllers ):
1243 main.log.warn(
1244 "ONOS" + str( i + 1 ) + " roles: ",
1245 json.dumps(
1246 json.loads( ONOSMastership[ i ] ),
1247 sort_keys=True,
1248 indent=4,
1249 separators=( ',', ': ' ) ) )
1250 elif rolesResults and not consistentMastership:
1251 mastershipCheck = main.TRUE
1252
Jon Hallb1290e82014-11-18 16:17:48 -05001253 description2 = "Compare switch roles from before failure"
Jon Hall6aec96b2015-01-19 14:49:31 -08001254 main.step( description2 )
Jon Hallb1290e82014-11-18 16:17:48 -05001255
Jon Hall65844a32015-03-09 19:09:37 -07001256 currentJson = json.loads( ONOSMastership[0] )
Jon Hall8f89dda2015-01-22 16:03:33 -08001257 oldJson = json.loads( mastershipState )
1258 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001259 for i in range( 1, 29 ):
1260 switchDPID = str(
Jon Hall65844a32015-03-09 19:09:37 -07001261 main.Mininet1.getSwitchDPID( switch="s" + str( i ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001262 current = [ switch[ 'master' ] for switch in currentJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001263 if switchDPID in switch[ 'id' ] ]
Jon Hall8f89dda2015-01-22 16:03:33 -08001264 old = [ switch[ 'master' ] for switch in oldJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001265 if switchDPID in switch[ 'id' ] ]
Jon Hallb1290e82014-11-18 16:17:48 -05001266 if current == old:
Jon Hall8f89dda2015-01-22 16:03:33 -08001267 mastershipCheck = mastershipCheck and main.TRUE
Jon Hallb1290e82014-11-18 16:17:48 -05001268 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001269 main.log.warn( "Mastership of switch %s changed" % switchDPID )
Jon Hall8f89dda2015-01-22 16:03:33 -08001270 mastershipCheck = main.FALSE
1271 if mastershipCheck == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001272 main.log.report( "Mastership of Switches was not changed" )
1273 utilities.assert_equals(
1274 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001275 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -08001276 onpass="Mastership of Switches was not changed",
1277 onfail="Mastership of some switches changed" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001278 mastershipCheck = mastershipCheck and consistentMastership
Jon Hallb1290e82014-11-18 16:17:48 -05001279
Jon Hall6aec96b2015-01-19 14:49:31 -08001280 main.step( "Get the intents and compare across all nodes" )
Jon Hall65844a32015-03-09 19:09:37 -07001281 ONOSIntents = []
Jon Hall8f89dda2015-01-22 16:03:33 -08001282 intentCheck = main.FALSE
Jon Hall65844a32015-03-09 19:09:37 -07001283 consistentIntents = True
1284 intentsResults = True
1285 threads = []
1286 for i in range( numControllers ):
1287 t = main.Thread( target=CLIs[i].intents,
1288 threadID=self.threadID,
1289 name="intents-" + str( i ),
1290 args=[],
1291 kwargs={ 'jsonFormat': True } )
1292 threads.append( t )
1293 t.start()
1294 self.threadID += 1
1295
1296 for t in threads:
1297 t.join()
1298 ONOSIntents.append( t.result )
1299
1300 for i in range( numControllers ):
1301 if not ONOSIntents[ i ] or "Error" in ONOSIntents[ i ]:
1302 main.log.report( "Error in getting ONOS" + str( i + 1 ) +
1303 " intents" )
1304 main.log.warn( "ONOS" + str( i + 1 ) + " intents response: " +
1305 repr( ONOSIntents[ i ] ) )
1306 intentsResults = False
Jon Hall6aec96b2015-01-19 14:49:31 -08001307 utilities.assert_equals(
Jon Hall65844a32015-03-09 19:09:37 -07001308 expect=True,
1309 actual=intentsResults,
1310 onpass="No error in reading intents output",
1311 onfail="Error in reading intents from ONOS" )
1312
1313 main.step( "Check for consistency in Intents from each controller" )
1314 if all( [ i == ONOSIntents[ 0 ] for i in ONOSIntents ] ):
1315 main.log.report( "Intents are consistent across all ONOS " +
1316 "nodes" )
1317 else:
1318 consistentIntents = False
1319 utilities.assert_equals(
1320 expect=True,
1321 actual=consistentIntents,
Jon Hall6aec96b2015-01-19 14:49:31 -08001322 onpass="Intents are consistent across all ONOS nodes",
1323 onfail="ONOS nodes have different views of intents" )
Jon Hall1b8f54a2015-02-04 13:24:20 -08001324 intentStates = []
Jon Hall65844a32015-03-09 19:09:37 -07001325 for node in ONOSIntents: # Iter through ONOS nodes
Jon Hall1b8f54a2015-02-04 13:24:20 -08001326 nodeStates = []
Jon Hall58c76b72015-02-23 11:09:24 -08001327 # Iter through intents of a node
1328 for intent in json.loads( node ):
Jon Hall1b8f54a2015-02-04 13:24:20 -08001329 nodeStates.append( intent[ 'state' ] )
1330 intentStates.append( nodeStates )
1331 out = [ (i, nodeStates.count( i ) ) for i in set( nodeStates ) ]
1332 main.log.info( dict( out ) )
1333
Jon Hall65844a32015-03-09 19:09:37 -07001334 if intentsResults and not consistentIntents:
1335 for i in range( numControllers ):
1336 main.log.warn(
1337 "ONOS" + str( i + 1 ) + " intents: ",
1338 json.dumps(
1339 json.loads( ONOSIntents[ i ] ),
1340 sort_keys=True,
1341 indent=4,
1342 separators=( ',', ': ' ) ) )
1343 elif intentsResults and consistentIntents:
1344 intentCheck = main.TRUE
1345 intentState = ONOSIntents[ 0 ]
1346
Jon Hall58c76b72015-02-23 11:09:24 -08001347 # NOTE: Store has no durability, so intents are lost across system
1348 # restarts
Jon Hall6aec96b2015-01-19 14:49:31 -08001349 main.step( "Compare current intents with intents before the failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001350 # NOTE: this requires case 5 to pass for intentState to be set.
Jon Hall94fd0472014-12-08 11:52:42 -08001351 # maybe we should stop the test if that fails?
Jon Hall1b8f54a2015-02-04 13:24:20 -08001352 sameIntents = main.TRUE
Jon Hall65844a32015-03-09 19:09:37 -07001353 if intentState and intentState == ONOSIntents[ 0 ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001354 sameIntents = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001355 main.log.report( "Intents are consistent with before failure" )
1356 # TODO: possibly the states have changed? we may need to figure out
Jon Hall65844a32015-03-09 19:09:37 -07001357 # what the acceptable states are
Jon Hallb1290e82014-11-18 16:17:48 -05001358 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001359 try:
Jon Hall65844a32015-03-09 19:09:37 -07001360 main.log.warn( "ONOS intents: " )
1361 print json.dumps( json.loads( ONOSIntents[ 0 ] ),
Jon Hall6aec96b2015-01-19 14:49:31 -08001362 sort_keys=True, indent=4,
1363 separators=( ',', ': ' ) )
Jon Hallfebb1c72015-03-05 13:30:09 -08001364 except Exception:
Jon Hall65844a32015-03-09 19:09:37 -07001365 main.log.exception( "Exception printing intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001366 sameIntents = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001367 utilities.assert_equals(
1368 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001369 actual=sameIntents,
Jon Hall6aec96b2015-01-19 14:49:31 -08001370 onpass="Intents are consistent with before failure",
1371 onfail="The Intents changed during failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001372 intentCheck = intentCheck and sameIntents
Jon Hallb1290e82014-11-18 16:17:48 -05001373
Jon Hall6aec96b2015-01-19 14:49:31 -08001374 main.step( "Get the OF Table entries and compare to before " +
1375 "component failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001376 FlowTables = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001377 flows2 = []
1378 for i in range( 28 ):
1379 main.log.info( "Checking flow table on s" + str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001380 tmpFlows = main.Mininet2.getFlowTable( 1.3, "s" + str( i + 1 ) )
1381 flows2.append( tmpFlows )
1382 tempResult = main.Mininet2.flowComp(
Jon Hall6aec96b2015-01-19 14:49:31 -08001383 flow1=flows[ i ],
Jon Hall8f89dda2015-01-22 16:03:33 -08001384 flow2=tmpFlows )
1385 FlowTables = FlowTables and tempResult
1386 if FlowTables == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001387 main.log.info( "Differences in flow table for switch: s" +
1388 str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001389 if FlowTables == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001390 main.log.report( "No changes were found in the flow tables" )
1391 utilities.assert_equals(
1392 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001393 actual=FlowTables,
Jon Hall6aec96b2015-01-19 14:49:31 -08001394 onpass="No changes were found in the flow tables",
1395 onfail="Changes were found in the flow tables" )
Jon Hallb1290e82014-11-18 16:17:48 -05001396
Jon Hall6aec96b2015-01-19 14:49:31 -08001397 main.step( "Check the continuous pings to ensure that no packets " +
1398 "were dropped during component failure" )
Jon Hall65844a32015-03-09 19:09:37 -07001399 main.Mininet2.pingKill( main.params[ 'TESTONUSER' ],
1400 main.params[ 'TESTONIP' ] )
Jon Hall8f89dda2015-01-22 16:03:33 -08001401 LossInPings = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001402 # NOTE: checkForLoss returns main.FALSE with 0% packet loss
1403 for i in range( 8, 18 ):
1404 main.log.info(
1405 "Checking for a loss in pings along flow from s" +
1406 str( i ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001407 LossInPings = main.Mininet2.checkForLoss(
Jon Hall6aec96b2015-01-19 14:49:31 -08001408 "/tmp/ping.h" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001409 str( i ) ) or LossInPings
1410 if LossInPings == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001411 main.log.info( "Loss in ping detected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001412 elif LossInPings == main.ERROR:
Jon Hall6aec96b2015-01-19 14:49:31 -08001413 main.log.info( "There are multiple mininet process running" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001414 elif LossInPings == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001415 main.log.info( "No Loss in the pings" )
1416 main.log.report( "No loss of dataplane connectivity" )
1417 utilities.assert_equals(
1418 expect=main.FALSE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001419 actual=LossInPings,
Jon Hall6aec96b2015-01-19 14:49:31 -08001420 onpass="No Loss of connectivity",
1421 onfail="Loss of dataplane connectivity detected" )
Jon Hallb1290e82014-11-18 16:17:48 -05001422
Jon Hall6aec96b2015-01-19 14:49:31 -08001423 # Test of LeadershipElection
1424 # NOTE: this only works for the sanity test. In case of failures,
Jon Hall58c76b72015-02-23 11:09:24 -08001425 # leader will likely change
Jon Hall65844a32015-03-09 19:09:37 -07001426 leader = nodes[ 0 ].ip_address
Jon Hall8f89dda2015-01-22 16:03:33 -08001427 leaderResult = main.TRUE
Jon Hall65844a32015-03-09 19:09:37 -07001428 for node in nodes:
Jon Hall8f89dda2015-01-22 16:03:33 -08001429 leaderN = node.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001430 # verify leader is ONOS1
Jon Hall669173b2014-12-17 11:36:30 -08001431 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08001432 # all is well
1433 # NOTE: In failure scenario, this could be a new node, maybe
1434 # check != ONOS1
Jon Hall669173b2014-12-17 11:36:30 -08001435 pass
1436 elif leaderN == main.FALSE:
Jon Hall65844a32015-03-09 19:09:37 -07001437 # error in response
Jon Hall6aec96b2015-01-19 14:49:31 -08001438 main.log.report( "Something is wrong with " +
Jon Hall58c76b72015-02-23 11:09:24 -08001439 "electionTestLeader function, check the" +
1440 " error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001441 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001442 elif leader != leaderN:
Jon Hall8f89dda2015-01-22 16:03:33 -08001443 leaderResult = main.FALSE
Jon Hall65844a32015-03-09 19:09:37 -07001444 main.log.report( node.name + " sees " + str( leaderN ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001445 " as the leader of the election app. " +
1446 "Leader should be " + str( leader ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001447 if leaderResult:
1448 main.log.report( "Leadership election tests passed( consistent " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001449 "view of leader across listeners and a new " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001450 "leader was re-elected if applicable )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001451 utilities.assert_equals(
1452 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001453 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001454 onpass="Leadership election passed",
1455 onfail="Something went wrong with Leadership election" )
Jon Hallb1290e82014-11-18 16:17:48 -05001456
Jon Hall58c76b72015-02-23 11:09:24 -08001457 result = ( mastershipCheck and intentCheck and FlowTables and
1458 ( not LossInPings ) and rolesNotNull and leaderResult )
Jon Hall6aec96b2015-01-19 14:49:31 -08001459 result = int( result )
Jon Hallb1290e82014-11-18 16:17:48 -05001460 if result == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001461 main.log.report( "Constant State Tests Passed" )
1462 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall58c76b72015-02-23 11:09:24 -08001463 onpass="Constant State Tests Passed",
1464 onfail="Constant state tests failed" )
Jon Hallb1290e82014-11-18 16:17:48 -05001465
Jon Hall6aec96b2015-01-19 14:49:31 -08001466 def CASE8( self, main ):
1467 """
Jon Hallb1290e82014-11-18 16:17:48 -05001468 Compare topo
Jon Hall6aec96b2015-01-19 14:49:31 -08001469 """
Jon Hallb1290e82014-11-18 16:17:48 -05001470 import sys
Jon Hall6aec96b2015-01-19 14:49:31 -08001471 # FIXME add this path to params
1472 sys.path.append( "/home/admin/sts" )
1473 # assumes that sts is already in you PYTHONPATH
1474 from sts.topology.teston_topology import TestONTopology
Jon Hallb1290e82014-11-18 16:17:48 -05001475 import json
Jon Hall73cf9cc2014-11-20 22:28:38 -08001476 import time
Jon Hallb1290e82014-11-18 16:17:48 -05001477
Jon Hall6aec96b2015-01-19 14:49:31 -08001478 description = "Compare ONOS Topology view to Mininet topology"
1479 main.case( description )
1480 main.log.report( description )
1481 main.step( "Create TestONTopology object" )
Jon Hallb1290e82014-11-18 16:17:48 -05001482 ctrls = []
1483 count = 1
Jon Hall65844a32015-03-09 19:09:37 -07001484 #FIXME: use the new method?
Jon Hallb1290e82014-11-18 16:17:48 -05001485 while True:
1486 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -08001487 if ( 'ip' + str( count ) ) in main.params[ 'CTRL' ]:
1488 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
1489 temp = temp + ( "ONOS" + str( count ), )
1490 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
1491 temp = temp + \
1492 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
1493 ctrls.append( temp )
Jon Hall65844a32015-03-09 19:09:37 -07001494 count += 1
Jon Hallb1290e82014-11-18 16:17:48 -05001495 else:
1496 break
Jon Hall65844a32015-03-09 19:09:37 -07001497 MNTopo = TestONTopology( main.Mininet1, ctrls )
Jon Hallb1290e82014-11-18 16:17:48 -05001498
Jon Hall6aec96b2015-01-19 14:49:31 -08001499 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001500 devicesResults = main.TRUE
1501 portsResults = main.TRUE
1502 linksResults = main.TRUE
Jon Hall58c76b72015-02-23 11:09:24 -08001503 hostsResults = main.TRUE
Jon Hall8f89dda2015-01-22 16:03:33 -08001504 topoResult = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001505 elapsed = 0
Jon Hallffb386d2014-11-21 13:43:38 -08001506 count = 0
Jon Hall6aec96b2015-01-19 14:49:31 -08001507 main.step( "Collecting topology information from ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001508 startTime = time.time()
Jon Hall21270ac2015-02-16 17:59:55 -08001509 # Give time for Gossip to work
Jon Hall8f89dda2015-01-22 16:03:33 -08001510 while topoResult == main.FALSE and elapsed < 60:
Jon Hall65844a32015-03-09 19:09:37 -07001511 count += 1
Jon Hall94fd0472014-12-08 11:52:42 -08001512 if count > 1:
Jon Hall65844a32015-03-09 19:09:37 -07001513 # TODO: Deprecate STS usage
Jon Hall58c76b72015-02-23 11:09:24 -08001514 MNTopo = TestONTopology( main.Mininet1, ctrls )
Jon Hall8f89dda2015-01-22 16:03:33 -08001515 cliStart = time.time()
Jon Hall94fd0472014-12-08 11:52:42 -08001516 devices = []
Jon Hall65844a32015-03-09 19:09:37 -07001517 threads = []
1518 for i in range( numControllers ):
1519 t = main.Thread( target=CLIs[i].devices,
1520 threadID=self.threadID,
1521 name="devices-" + str( i ),
1522 args=[ ] )
1523 threads.append( t )
1524 t.start()
1525 self.threadID += 1
1526
1527 for t in threads:
1528 t.join()
1529 devices.append( t.result )
Jon Hall94fd0472014-12-08 11:52:42 -08001530 hosts = []
Jon Hall58c76b72015-02-23 11:09:24 -08001531 ipResult = main.TRUE
Jon Hall65844a32015-03-09 19:09:37 -07001532 threads = []
1533 for i in range( numControllers ):
1534 t = main.Thread( target=CLIs[i].hosts,
1535 threadID=self.threadID,
1536 name="hosts-" + str( i ),
1537 args=[ ] )
1538 threads.append( t )
1539 t.start()
1540 self.threadID += 1
1541
1542 for t in threads:
1543 t.join()
1544 hosts.append( json.loads( t.result ) )
Jon Hall529a37f2015-01-28 10:02:00 -08001545 for controller in range( 0, len( hosts ) ):
1546 controllerStr = str( controller + 1 )
1547 for host in hosts[ controller ]:
Jon Hall58c76b72015-02-23 11:09:24 -08001548 if host is None or host.get( 'ips', [] ) == []:
Jon Hall529a37f2015-01-28 10:02:00 -08001549 main.log.error(
1550 "DEBUG:Error with host ips on controller" +
1551 controllerStr + ": " + str( host ) )
Jon Hall58c76b72015-02-23 11:09:24 -08001552 ipResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001553 ports = []
Jon Hall65844a32015-03-09 19:09:37 -07001554 threads = []
1555 for i in range( numControllers ):
1556 t = main.Thread( target=CLIs[i].ports,
1557 threadID=self.threadID,
1558 name="ports-" + str( i ),
1559 args=[ ] )
1560 threads.append( t )
1561 t.start()
1562 self.threadID += 1
1563
1564 for t in threads:
1565 t.join()
1566 ports.append( t.result )
Jon Hall94fd0472014-12-08 11:52:42 -08001567 links = []
Jon Hall65844a32015-03-09 19:09:37 -07001568 threads = []
1569 for i in range( numControllers ):
1570 t = main.Thread( target=CLIs[i].links,
1571 threadID=self.threadID,
1572 name="links-" + str( i ),
1573 args=[ ] )
1574 threads.append( t )
1575 t.start()
1576 self.threadID += 1
1577
1578 for t in threads:
1579 t.join()
1580 links.append( t.result )
Jon Hall94fd0472014-12-08 11:52:42 -08001581 clusters = []
Jon Hall65844a32015-03-09 19:09:37 -07001582 threads = []
1583 for i in range( numControllers ):
1584 t = main.Thread( target=CLIs[i].clusters,
1585 threadID=self.threadID,
1586 name="clusters-" + str( i ),
1587 args=[ ] )
1588 threads.append( t )
1589 t.start()
1590 self.threadID += 1
1591
1592 for t in threads:
1593 t.join()
1594 clusters.append( t.result )
Jon Hallb1290e82014-11-18 16:17:48 -05001595
Jon Hall8f89dda2015-01-22 16:03:33 -08001596 elapsed = time.time() - startTime
1597 cliTime = time.time() - cliStart
1598 print "CLI time: " + str( cliTime )
Jon Hallb1290e82014-11-18 16:17:48 -05001599
Jon Hall21270ac2015-02-16 17:59:55 -08001600 for controller in range( numControllers ):
1601 controllerStr = str( controller + 1 )
1602 if devices[ controller ] or "Error" not in devices[
1603 controller ]:
1604 currentDevicesResult = main.Mininet1.compareSwitches(
1605 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001606 json.loads( devices[ controller ] ) )
Jon Hall21270ac2015-02-16 17:59:55 -08001607 else:
1608 currentDevicesResult = main.FALSE
1609 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001610 actual=currentDevicesResult,
1611 onpass="ONOS" + controllerStr +
1612 " Switches view is correct",
1613 onfail="ONOS" + controllerStr +
1614 " Switches view is incorrect" )
Jon Hallb1290e82014-11-18 16:17:48 -05001615
Jon Hall21270ac2015-02-16 17:59:55 -08001616 if ports[ controller ] or "Error" not in ports[ controller ]:
1617 currentPortsResult = main.Mininet1.comparePorts(
1618 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001619 json.loads( ports[ controller ] ) )
Jon Hall21270ac2015-02-16 17:59:55 -08001620 else:
1621 currentPortsResult = main.FALSE
1622 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001623 actual=currentPortsResult,
1624 onpass="ONOS" + controllerStr +
1625 " ports view is correct",
1626 onfail="ONOS" + controllerStr +
1627 " ports view is incorrect" )
Jon Hall94fd0472014-12-08 11:52:42 -08001628
Jon Hall21270ac2015-02-16 17:59:55 -08001629 if links[ controller ] or "Error" not in links[ controller ]:
1630 currentLinksResult = main.Mininet1.compareLinks(
1631 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001632 json.loads( links[ controller ] ) )
Jon Hall21270ac2015-02-16 17:59:55 -08001633 else:
1634 currentLinksResult = main.FALSE
1635 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001636 actual=currentLinksResult,
1637 onpass="ONOS" + controllerStr +
1638 " links view is correct",
1639 onfail="ONOS" + controllerStr +
1640 " links view is incorrect" )
1641
1642 if hosts[ controller ] or "Error" not in hosts[ controller ]:
1643 currentHostsResult = main.Mininet1.compareHosts(
1644 MNTopo, hosts[ controller ] )
1645 else:
1646 currentHostsResult = main.FALSE
1647 utilities.assert_equals( expect=main.TRUE,
1648 actual=currentHostsResult,
1649 onpass="ONOS" + controllerStr +
1650 " hosts exist in Mininet",
1651 onfail="ONOS" + controllerStr +
1652 " hosts don't match Mininet" )
1653
1654 devicesResults = devicesResults and currentDevicesResult
1655 portsResults = portsResults and currentPortsResult
1656 linksResults = linksResults and currentLinksResult
1657 hostsResults = hostsResults and currentHostsResult
Jon Hall94fd0472014-12-08 11:52:42 -08001658
Jon Hall21270ac2015-02-16 17:59:55 -08001659 # Compare json objects for hosts and dataplane clusters
Jon Hall94fd0472014-12-08 11:52:42 -08001660
Jon Hall21270ac2015-02-16 17:59:55 -08001661 # hosts
1662 consistentHostsResult = main.TRUE
1663 for controller in range( len( hosts ) ):
1664 controllerStr = str( controller + 1 )
1665 if "Error" not in hosts[ controller ]:
1666 if hosts[ controller ] == hosts[ 0 ]:
1667 continue
1668 else: # hosts not consistent
1669 main.log.report( "hosts from ONOS" + controllerStr +
1670 " is inconsistent with ONOS1" )
1671 main.log.warn( repr( hosts[ controller ] ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001672 consistentHostsResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001673
Jon Hall21270ac2015-02-16 17:59:55 -08001674 else:
1675 main.log.report( "Error in getting ONOS hosts from ONOS" +
1676 controllerStr )
1677 consistentHostsResult = main.FALSE
1678 main.log.warn( "ONOS" + controllerStr +
1679 " hosts response: " +
1680 repr( hosts[ controller ] ) )
1681 utilities.assert_equals(
1682 expect=main.TRUE,
1683 actual=consistentHostsResult,
1684 onpass="Hosts view is consistent across all ONOS nodes",
1685 onfail="ONOS nodes have different views of hosts" )
Jon Hall94fd0472014-12-08 11:52:42 -08001686
Jon Hall21270ac2015-02-16 17:59:55 -08001687 # Strongly connected clusters of devices
1688 consistentClustersResult = main.TRUE
1689 for controller in range( len( clusters ) ):
1690 controllerStr = str( controller + 1 )
1691 if "Error" not in clusters[ controller ]:
1692 if clusters[ controller ] == clusters[ 0 ]:
1693 continue
1694 else: # clusters not consistent
1695 main.log.report( "clusters from ONOS" +
1696 controllerStr +
1697 " is inconsistent with ONOS1" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001698 consistentClustersResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001699
Jon Hall21270ac2015-02-16 17:59:55 -08001700 else:
1701 main.log.report( "Error in getting dataplane clusters " +
1702 "from ONOS" + controllerStr )
1703 consistentClustersResult = main.FALSE
1704 main.log.warn( "ONOS" + controllerStr +
1705 " clusters response: " +
1706 repr( clusters[ controller ] ) )
1707 utilities.assert_equals(
1708 expect=main.TRUE,
1709 actual=consistentClustersResult,
1710 onpass="Clusters view is consistent across all ONOS nodes",
1711 onfail="ONOS nodes have different views of clusters" )
1712 # there should always only be one cluster
1713 numClusters = len( json.loads( clusters[ 0 ] ) )
Jon Hall58c76b72015-02-23 11:09:24 -08001714 clusterResults = main.FALSE
1715 if numClusters == 1:
1716 clusterResults = main.TRUE
Jon Hall21270ac2015-02-16 17:59:55 -08001717 utilities.assert_equals(
1718 expect=1,
1719 actual=numClusters,
1720 onpass="ONOS shows 1 SCC",
Jon Hall58c76b72015-02-23 11:09:24 -08001721 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
Jon Hall94fd0472014-12-08 11:52:42 -08001722
Jon Hall21270ac2015-02-16 17:59:55 -08001723 topoResult = ( devicesResults and portsResults and linksResults
Jon Hall58c76b72015-02-23 11:09:24 -08001724 and hostsResults and consistentHostsResult
1725 and consistentClustersResult and clusterResults
1726 and ipResult )
Jon Hall94fd0472014-12-08 11:52:42 -08001727
Jon Hall21270ac2015-02-16 17:59:55 -08001728 topoResult = topoResult and int( count <= 2 )
1729 note = "note it takes about " + str( int( cliTime ) ) + \
1730 " seconds for the test to make all the cli calls to fetch " +\
1731 "the topology from each ONOS instance"
1732 main.log.info(
1733 "Very crass estimate for topology discovery/convergence( " +
1734 str( note ) + " ): " + str( elapsed ) + " seconds, " +
1735 str( count ) + " tries" )
1736 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
Jon Hall58c76b72015-02-23 11:09:24 -08001737 onpass="Topology Check Test successful",
1738 onfail="Topology Check Test NOT successful" )
Jon Hall21270ac2015-02-16 17:59:55 -08001739 if topoResult == main.TRUE:
1740 main.log.report( "ONOS topology view matches Mininet topology" )
Jon Hallb1290e82014-11-18 16:17:48 -05001741
Jon Hall6aec96b2015-01-19 14:49:31 -08001742 def CASE9( self, main ):
1743 """
Jon Hallb1290e82014-11-18 16:17:48 -05001744 Link s3-s28 down
Jon Hall6aec96b2015-01-19 14:49:31 -08001745 """
1746 import time
1747 # NOTE: You should probably run a topology check after this
Jon Hallb1290e82014-11-18 16:17:48 -05001748
Jon Hall8f89dda2015-01-22 16:03:33 -08001749 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hallb1290e82014-11-18 16:17:48 -05001750
Jon Hall6aec96b2015-01-19 14:49:31 -08001751 description = "Turn off a link to ensure that Link Discovery " +\
Jon Hall58c76b72015-02-23 11:09:24 -08001752 "is working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001753 main.log.report( description )
1754 main.case( description )
Jon Hallb1290e82014-11-18 16:17:48 -05001755
Jon Hall6aec96b2015-01-19 14:49:31 -08001756 main.step( "Kill Link between s3 and s28" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001757 LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" )
Jon Hall58c76b72015-02-23 11:09:24 -08001758 main.log.info( "Waiting " + str( linkSleep ) +
1759 " seconds for link down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001760 time.sleep( linkSleep )
1761 utilities.assert_equals( expect=main.TRUE, actual=LinkDown,
Jon Hall65844a32015-03-09 19:09:37 -07001762 onpass="Link down successful",
Jon Hall58c76b72015-02-23 11:09:24 -08001763 onfail="Failed to bring link down" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001764 # TODO do some sort of check here
Jon Hallb1290e82014-11-18 16:17:48 -05001765
Jon Hall6aec96b2015-01-19 14:49:31 -08001766 def CASE10( self, main ):
1767 """
Jon Hallb1290e82014-11-18 16:17:48 -05001768 Link s3-s28 up
Jon Hall6aec96b2015-01-19 14:49:31 -08001769 """
1770 import time
1771 # NOTE: You should probably run a topology check after this
Jon Hallb1290e82014-11-18 16:17:48 -05001772
Jon Hall8f89dda2015-01-22 16:03:33 -08001773 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hallb1290e82014-11-18 16:17:48 -05001774
Jon Hall6aec96b2015-01-19 14:49:31 -08001775 description = "Restore a link to ensure that Link Discovery is " + \
Jon Hall63604932015-02-26 17:09:50 -08001776 "working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001777 main.log.report( description )
1778 main.case( description )
Jon Hallb1290e82014-11-18 16:17:48 -05001779
Jon Hall6aec96b2015-01-19 14:49:31 -08001780 main.step( "Bring link between s3 and s28 back up" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001781 LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" )
Jon Hall58c76b72015-02-23 11:09:24 -08001782 main.log.info( "Waiting " + str( linkSleep ) +
1783 " seconds for link up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001784 time.sleep( linkSleep )
1785 utilities.assert_equals( expect=main.TRUE, actual=LinkUp,
Jon Hall65844a32015-03-09 19:09:37 -07001786 onpass="Link up successful",
Jon Hall58c76b72015-02-23 11:09:24 -08001787 onfail="Failed to bring link up" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001788 # TODO do some sort of check here
Jon Hallb1290e82014-11-18 16:17:48 -05001789
Jon Hall6aec96b2015-01-19 14:49:31 -08001790 def CASE11( self, main ):
1791 """
Jon Hallb1290e82014-11-18 16:17:48 -05001792 Switch Down
Jon Hall6aec96b2015-01-19 14:49:31 -08001793 """
1794 # NOTE: You should probably run a topology check after this
Jon Hallb1290e82014-11-18 16:17:48 -05001795 import time
1796
Jon Hall8f89dda2015-01-22 16:03:33 -08001797 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hallb1290e82014-11-18 16:17:48 -05001798
1799 description = "Killing a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001800 main.log.report( description )
1801 main.case( description )
1802 switch = main.params[ 'kill' ][ 'switch' ]
1803 switchDPID = main.params[ 'kill' ][ 'dpid' ]
Jon Hallb1290e82014-11-18 16:17:48 -05001804
Jon Hall6aec96b2015-01-19 14:49:31 -08001805 # TODO: Make this switch parameterizable
1806 main.step( "Kill " + switch )
1807 main.log.report( "Deleting " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001808 main.Mininet1.delSwitch( switch )
1809 main.log.info( "Waiting " + str( switchSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001810 " seconds for switch down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001811 time.sleep( switchSleep )
1812 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001813 # Peek at the deleted switch
1814 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001815 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001816 if device and device[ 'available' ] is False:
Jon Hall94fd0472014-12-08 11:52:42 -08001817 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001818 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall65844a32015-03-09 19:09:37 -07001819 onpass="Kill switch successful",
Jon Hall58c76b72015-02-23 11:09:24 -08001820 onfail="Failed to kill switch?" )
Jon Hallb1290e82014-11-18 16:17:48 -05001821
Jon Hall6aec96b2015-01-19 14:49:31 -08001822 def CASE12( self, main ):
1823 """
Jon Hallb1290e82014-11-18 16:17:48 -05001824 Switch Up
Jon Hall6aec96b2015-01-19 14:49:31 -08001825 """
1826 # NOTE: You should probably run a topology check after this
Jon Hallb1290e82014-11-18 16:17:48 -05001827 import time
Jon Hall669173b2014-12-17 11:36:30 -08001828
Jon Hall8f89dda2015-01-22 16:03:33 -08001829 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall6aec96b2015-01-19 14:49:31 -08001830 switch = main.params[ 'kill' ][ 'switch' ]
1831 switchDPID = main.params[ 'kill' ][ 'dpid' ]
1832 links = main.params[ 'kill' ][ 'links' ].split()
Jon Hallb1290e82014-11-18 16:17:48 -05001833 description = "Adding a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001834 main.log.report( description )
1835 main.case( description )
Jon Hallb1290e82014-11-18 16:17:48 -05001836
Jon Hall6aec96b2015-01-19 14:49:31 -08001837 main.step( "Add back " + switch )
1838 main.log.report( "Adding back " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001839 main.Mininet1.addSwitch( switch, dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001840 for peer in links:
Jon Hall8f89dda2015-01-22 16:03:33 -08001841 main.Mininet1.addLink( switch, peer )
Jon Hall58c76b72015-02-23 11:09:24 -08001842 main.Mininet1.assignSwController( sw=switch.split( 's' )[ 1 ],
1843 count=numControllers,
Jon Hall65844a32015-03-09 19:09:37 -07001844 ip1=nodes[ 0 ].ip_address,
Jon Hall58c76b72015-02-23 11:09:24 -08001845 port1=ONOS1Port,
Jon Hall65844a32015-03-09 19:09:37 -07001846 ip2=nodes[ 1 ].ip_address,
Jon Hall58c76b72015-02-23 11:09:24 -08001847 port2=ONOS2Port,
Jon Hall65844a32015-03-09 19:09:37 -07001848 ip3=nodes[ 2 ].ip_address,
Jon Hall58c76b72015-02-23 11:09:24 -08001849 port3=ONOS3Port,
Jon Hall65844a32015-03-09 19:09:37 -07001850 ip4=nodes[ 3 ].ip_address,
Jon Hall58c76b72015-02-23 11:09:24 -08001851 port4=ONOS4Port,
Jon Hall65844a32015-03-09 19:09:37 -07001852 ip5=nodes[ 4 ].ip_address,
Jon Hall58c76b72015-02-23 11:09:24 -08001853 port5=ONOS5Port,
Jon Hall65844a32015-03-09 19:09:37 -07001854 ip6=nodes[ 5 ].ip_address,
Jon Hall58c76b72015-02-23 11:09:24 -08001855 port6=ONOS6Port,
Jon Hall65844a32015-03-09 19:09:37 -07001856 ip7=nodes[ 6 ].ip_address,
Jon Hall58c76b72015-02-23 11:09:24 -08001857 port7=ONOS7Port )
1858 main.log.info( "Waiting " + str( switchSleep ) +
1859 " seconds for switch up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001860 time.sleep( switchSleep )
1861 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001862 # Peek at the deleted switch
1863 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001864 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001865 if device and device[ 'available' ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001866 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001867 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall65844a32015-03-09 19:09:37 -07001868 onpass="add switch successful",
Jon Hall58c76b72015-02-23 11:09:24 -08001869 onfail="Failed to add switch?" )
Jon Hallb1290e82014-11-18 16:17:48 -05001870
Jon Hall6aec96b2015-01-19 14:49:31 -08001871 def CASE13( self, main ):
1872 """
Jon Hallb1290e82014-11-18 16:17:48 -05001873 Clean up
Jon Hall6aec96b2015-01-19 14:49:31 -08001874 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001875 import os
1876 import time
Jon Hall6aec96b2015-01-19 14:49:31 -08001877
1878 # printing colors to terminal
Jon Hall65844a32015-03-09 19:09:37 -07001879 colors = { 'cyan': '\033[96m', 'purple': '\033[95m',
1880 'blue': '\033[94m', 'green': '\033[92m',
1881 'yellow': '\033[93m', 'red': '\033[91m', 'end': '\033[0m' }
Jon Hall368769f2014-11-19 15:43:35 -08001882 description = "Test Cleanup"
Jon Hall6aec96b2015-01-19 14:49:31 -08001883 main.log.report( description )
1884 main.case( description )
1885 main.step( "Killing tcpdumps" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001886 main.Mininet2.stopTcpdump()
Jon Hallb1290e82014-11-18 16:17:48 -05001887
Jon Hall6aec96b2015-01-19 14:49:31 -08001888 main.step( "Copying MN pcap and ONOS log files to test station" )
Jon Hallb1290e82014-11-18 16:17:48 -05001889 testname = main.TEST
Jon Hall8f89dda2015-01-22 16:03:33 -08001890 teststationUser = main.params[ 'TESTONUSER' ]
1891 teststationIP = main.params[ 'TESTONIP' ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001892 # NOTE: MN Pcap file is being saved to ~/packet_captures
Jon Hall73cf9cc2014-11-20 22:28:38 -08001893 # scp this file as MN and TestON aren't necessarily the same vm
Jon Hall6aec96b2015-01-19 14:49:31 -08001894 # FIXME: scp
1895 # mn files
1896 # TODO: Load these from params
1897 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001898 logFolder = "/opt/onos/log/"
1899 logFiles = [ "karaf.log", "karaf.log.1" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001900 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001901 dstDir = "~/packet_captures/"
1902 for f in logFiles:
Jon Hall65844a32015-03-09 19:09:37 -07001903 for node in nodes:
1904 main.ONOSbench.handle.sendline( "scp sdn@" + node.ip_address +
1905 ":" + logFolder + f + " " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001906 teststationUser + "@" +
1907 teststationIP + ":" +
1908 dstDir + str( testname ) +
Jon Hall65844a32015-03-09 19:09:37 -07001909 "-" + node.name + "-" + f )
Jon Hall58c76b72015-02-23 11:09:24 -08001910 main.ONOSbench.handle.expect( "\$" )
1911
Jon Hall6aec96b2015-01-19 14:49:31 -08001912 # std*.log's
1913 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001914 logFolder = "/opt/onos/var/"
1915 logFiles = [ "stderr.log", "stdout.log" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001916 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001917 dstDir = "~/packet_captures/"
1918 for f in logFiles:
Jon Hall65844a32015-03-09 19:09:37 -07001919 for node in nodes:
1920 main.ONOSbench.handle.sendline( "scp sdn@" + node.ip_address +
1921 ":" + logFolder + f + " " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001922 teststationUser + "@" +
1923 teststationIP + ":" +
1924 dstDir + str( testname ) +
Jon Hall65844a32015-03-09 19:09:37 -07001925 "-" + node.name + "-" + f )
Jon Hall58c76b72015-02-23 11:09:24 -08001926 main.ONOSbench.handle.expect( "\$" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001927 # sleep so scp can finish
1928 time.sleep( 10 )
Jon Hall65844a32015-03-09 19:09:37 -07001929
1930 main.step( "Stopping Mininet" )
Jon Hall58c76b72015-02-23 11:09:24 -08001931 main.Mininet1.stopNet()
Jon Hall65844a32015-03-09 19:09:37 -07001932
1933 main.step( "Checking ONOS Logs for errors" )
1934 for node in nodes:
1935 print colors[ 'purple' ] + "Checking logs for errors on " + \
1936 node.name + ":" + colors[ 'end' ]
1937 print main.ONOSbench.checkLogs( node.ip_address )
1938
Jon Hall6aec96b2015-01-19 14:49:31 -08001939 main.step( "Packing and rotating pcap archives" )
1940 os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001941
Jon Hall6aec96b2015-01-19 14:49:31 -08001942 # TODO: actually check something here
1943 utilities.assert_equals( expect=main.TRUE, actual=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001944 onpass="Test cleanup successful",
1945 onfail="Test cleanup NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001946
Jon Hall6aec96b2015-01-19 14:49:31 -08001947 def CASE14( self, main ):
1948 """
Jon Hall94fd0472014-12-08 11:52:42 -08001949 start election app on all onos nodes
Jon Hall6aec96b2015-01-19 14:49:31 -08001950 """
Jon Hall8f89dda2015-01-22 16:03:33 -08001951 leaderResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001952 # install app on onos 1
1953 main.log.info( "Install leadership election app" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001954 main.ONOScli1.featureInstall( "onos-app-election" )
Jon Hall65844a32015-03-09 19:09:37 -07001955 leader = nodes[0].ip_address
Jon Hall6aec96b2015-01-19 14:49:31 -08001956 # wait for election
1957 # check for leader
Jon Hall65844a32015-03-09 19:09:37 -07001958 leader1 = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001959 # verify leader is ONOS1
Jon Hall65844a32015-03-09 19:09:37 -07001960 if leader1 == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08001961 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001962 pass
Jon Hall65844a32015-03-09 19:09:37 -07001963 elif leader1 is None:
Jon Hall6aec96b2015-01-19 14:49:31 -08001964 # No leader elected
1965 main.log.report( "No leader was elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001966 leaderResult = main.FALSE
Jon Hall65844a32015-03-09 19:09:37 -07001967 elif leader1 == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001968 # error in response
1969 # TODO: add check for "Command not found:" in the driver, this
1970 # means the app isn't loaded
Jon Hall8f89dda2015-01-22 16:03:33 -08001971 main.log.report( "Something is wrong with electionTestLeader" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001972 " function, check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001973 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001974 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001975 # error in response
1976 main.log.report(
Jon Hall8f89dda2015-01-22 16:03:33 -08001977 "Unexpected response from electionTestLeader function:'" +
Jon Hall65844a32015-03-09 19:09:37 -07001978 str( leader1 ) + "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001979 leaderResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001980
Jon Hall6aec96b2015-01-19 14:49:31 -08001981 # install on other nodes and check for leader.
Jon Hall65844a32015-03-09 19:09:37 -07001982 # Leader should be ONOS1 and each app should show the same leader
1983 for node in nodes[ 1: ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001984 node.featureInstall( "onos-app-election" )
1985 leaderN = node.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001986 # verify leader is ONOS1
Jon Hall65844a32015-03-09 19:09:37 -07001987 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08001988 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001989 pass
1990 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001991 # error in response
1992 # TODO: add check for "Command not found:" in the driver, this
1993 # means the app isn't loaded
1994 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001995 "electionTestLeader function, check the" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001996 " error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001997 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001998 elif leader != leaderN:
Jon Hall8f89dda2015-01-22 16:03:33 -08001999 leaderResult = main.FALSE
Jon Hall65844a32015-03-09 19:09:37 -07002000 main.log.report( node.names + " sees " + str( leaderN ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08002001 " as the leader of the election app. Leader" +
2002 " should be " +
2003 str( leader ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08002004 if leaderResult:
Jon Hall6aec96b2015-01-19 14:49:31 -08002005 main.log.report( "Leadership election tests passed( consistent " +
2006 "view of leader across listeners and a leader " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002007 "was elected )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08002008 utilities.assert_equals(
2009 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002010 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002011 onpass="Leadership election passed",
2012 onfail="Something went wrong with Leadership election" )
Jon Hall94fd0472014-12-08 11:52:42 -08002013
Jon Hall6aec96b2015-01-19 14:49:31 -08002014 def CASE15( self, main ):
2015 """
Jon Hall669173b2014-12-17 11:36:30 -08002016 Check that Leadership Election is still functional
Jon Hall6aec96b2015-01-19 14:49:31 -08002017 """
Jon Hall8f89dda2015-01-22 16:03:33 -08002018 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08002019 description = "Check that Leadership Election is still functional"
Jon Hall6aec96b2015-01-19 14:49:31 -08002020 main.log.report( description )
2021 main.case( description )
2022 main.step( "Find current leader and withdraw" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002023 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08002024 # TODO: do some sanity checking on leader before using it
Jon Hall8f89dda2015-01-22 16:03:33 -08002025 withdrawResult = main.FALSE
Jon Hall65844a32015-03-09 19:09:37 -07002026 oldLeader = None
2027 if leader is None or leader == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08002028 main.log.report(
2029 "Leader for the election app should be an ONOS node," +
Jon Hall58c76b72015-02-23 11:09:24 -08002030 "instead got '" + str( leader ) + "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002031 leaderResult = main.FALSE
Jon Hall63604932015-02-26 17:09:50 -08002032 oldLeader = None
Jon Hall65844a32015-03-09 19:09:37 -07002033 for i in range( len( CLIs ) ):
2034 if leader == nodes[ i ].ip_address:
2035 oldLeader = CLIs[ i ]
2036 break
Jon Hall63604932015-02-26 17:09:50 -08002037 else:
Jon Hall65844a32015-03-09 19:09:37 -07002038 main.log.error( "Leader election, could not find current leader" )
Jon Hall63604932015-02-26 17:09:50 -08002039 if oldLeader:
2040 withdrawResult = oldLeader.electionTestWithdraw()
Jon Hall6aec96b2015-01-19 14:49:31 -08002041 utilities.assert_equals(
2042 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002043 actual=withdrawResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002044 onpass="App was withdrawn from election",
2045 onfail="App was not withdrawn from election" )
Jon Hall669173b2014-12-17 11:36:30 -08002046
Jon Hall6aec96b2015-01-19 14:49:31 -08002047 main.step( "Make sure new leader is elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002048 leaderList = []
Jon Hall65844a32015-03-09 19:09:37 -07002049 for node in nodes:
2050 leaderN = node.electionTestLeader()
2051 leaderList.append( leaderN )
Jon Hall669173b2014-12-17 11:36:30 -08002052 if leaderN == leader:
Jon Hall65844a32015-03-09 19:09:37 -07002053 main.log.report( node.name + " still sees " + str( leader ) +
2054 " as leader after they withdrew" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002055 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08002056 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08002057 # error in response
2058 # TODO: add check for "Command not found:" in the driver, this
Jon Hall65844a32015-03-09 19:09:37 -07002059 # means the app isn't loaded
Jon Hall6aec96b2015-01-19 14:49:31 -08002060 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002061 "electionTestLeader function, " +
Jon Hall6aec96b2015-01-19 14:49:31 -08002062 "check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002063 leaderResult = main.FALSE
2064 consistentLeader = main.FALSE
2065 if len( set( leaderList ) ) == 1:
Jon Hall6aec96b2015-01-19 14:49:31 -08002066 main.log.info( "Each Election-app sees '" +
Jon Hall8f89dda2015-01-22 16:03:33 -08002067 str( leaderList[ 0 ] ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08002068 "' as the leader" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002069 consistentLeader = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08002070 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08002071 main.log.report(
2072 "Inconsistent responses for leader of Election-app:" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002073 for n in range( len( leaderList ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -08002074 main.log.report( "ONOS" + str( n + 1 ) + " response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002075 str( leaderList[ n ] ) )
2076 if leaderResult:
2077 main.log.report( "Leadership election tests passed( consistent " +
Jon Hall6aec96b2015-01-19 14:49:31 -08002078 "view of leader across listeners and a new " +
2079 "leader was elected when the old leader " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002080 "resigned )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08002081 utilities.assert_equals(
2082 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002083 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002084 onpass="Leadership election passed",
2085 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08002086
Jon Hall58c76b72015-02-23 11:09:24 -08002087 main.step( "Run for election on old leader( just so everyone " +
2088 "is in the hat )" )
Jon Hall63604932015-02-26 17:09:50 -08002089 if oldLeader:
2090 runResult = oldLeader.electionTestRun()
2091 else:
2092 runResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08002093 utilities.assert_equals(
2094 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002095 actual=runResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002096 onpass="App re-ran for election",
2097 onfail="App failed to run for election" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002098 if consistentLeader == main.TRUE:
2099 afterRun = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08002100 # verify leader didn't just change
Jon Hall8f89dda2015-01-22 16:03:33 -08002101 if afterRun == leaderList[ 0 ]:
2102 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08002103 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08002104 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08002105 # TODO: assert on run and withdraw results?
Jon Hall669173b2014-12-17 11:36:30 -08002106
Jon Hall6aec96b2015-01-19 14:49:31 -08002107 utilities.assert_equals(
2108 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002109 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002110 onpass="Leadership election passed",
2111 onfail="Something went wrong with Leadership election after " +
2112 "the old leader re-ran for election" )