blob: f77ca3d23ed64843f9bd1dfba6823e43fc63b709 [file] [log] [blame]
Jon Hall6aec96b2015-01-19 14:49:31 -08001"""
Jon Hall73cf9cc2014-11-20 22:28:38 -08002Description: This test is to determine if a single
3 instance ONOS 'cluster' can handle a restart
4
5List of test cases:
6CASE1: Compile ONOS and push it to the test machines
Jon Hallc9eabec2015-06-10 14:33:14 -07007CASE2: Assign devices to controllers
8CASE21: Assign mastership to controllers
Jon Hall73cf9cc2014-11-20 22:28:38 -08009CASE3: Assign intents
10CASE4: Ping across added host intents
11CASE5: Reading state of ONOS
Jon Hallc9eabec2015-06-10 14:33:14 -070012CASE6: The Failure case.
Jon Hall73cf9cc2014-11-20 22:28:38 -080013CASE7: Check state after control plane failure
14CASE8: 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 Hall390696c2015-05-05 17:13:41 -070022CASE16: Install Distributed Primitives app
23CASE17: Check for basic functionality with distributed primitives
Jon Hall6aec96b2015-01-19 14:49:31 -080024"""
Jon Hall8f89dda2015-01-22 16:03:33 -080025
26
Jon Hall48cf3ce2015-01-12 15:43:18 -080027class HATestSingleInstanceRestart:
Jon Hall73cf9cc2014-11-20 22:28:38 -080028
Jon Hall6aec96b2015-01-19 14:49:31 -080029 def __init__( self ):
Jon Hall73cf9cc2014-11-20 22:28:38 -080030 self.default = ''
31
Jon Hall6aec96b2015-01-19 14:49:31 -080032 def CASE1( self, main ):
33 """
Jon Hall73cf9cc2014-11-20 22:28:38 -080034 CASE1 is to compile ONOS and push it to the test machines
35
36 Startup sequence:
Jon Hall73cf9cc2014-11-20 22:28:38 -080037 cell <name>
38 onos-verify-cell
39 NOTE: temporary - onos-remove-raft-logs
Jon Hall58c76b72015-02-23 11:09:24 -080040 onos-uninstall
41 start mininet
42 git pull
43 mvn clean install
44 onos-package
Jon Hall73cf9cc2014-11-20 22:28:38 -080045 onos-install -f
46 onos-wait-for-start
Jon Hall58c76b72015-02-23 11:09:24 -080047 start cli sessions
48 start tcpdump
Jon Hall6aec96b2015-01-19 14:49:31 -080049 """
Jon Hall40d2cbd2015-06-03 16:24:29 -070050 main.log.info( "ONOS Single node cluster restart " +
Jon Hall6aec96b2015-01-19 14:49:31 -080051 "HA test - initialization" )
52 main.case( "Setting up test environment" )
Jon Hallfeff3082015-05-19 10:23:26 -070053 main.caseExplaination = "Setup the test environment including " +\
54 "installing ONOS, starting Mininet and ONOS" +\
55 "cli sessions."
Jon Hall6aec96b2015-01-19 14:49:31 -080056 # TODO: save all the timers and output them for plotting
Jon Hall73cf9cc2014-11-20 22:28:38 -080057
Jon Hall5cfd23c2015-03-19 11:40:57 -070058 # load some variables from the params file
Jon Hall8f89dda2015-01-22 16:03:33 -080059 PULLCODE = False
Jon Hall6aec96b2015-01-19 14:49:31 -080060 if main.params[ 'Git' ] == 'True':
Jon Hall8f89dda2015-01-22 16:03:33 -080061 PULLCODE = True
Jon Hall529a37f2015-01-28 10:02:00 -080062 gitBranch = main.params[ 'branch' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080063 cellName = main.params[ 'ENV' ][ 'cellName' ]
Jon Hall6aec96b2015-01-19 14:49:31 -080064
65 # set global variables
Jon Hall8f89dda2015-01-22 16:03:33 -080066 global ONOS1Ip
67 global ONOS1Port
Jon Hall8f89dda2015-01-22 16:03:33 -080068 global ONOS2Port
Jon Hall8f89dda2015-01-22 16:03:33 -080069 global ONOS3Port
Jon Hall8f89dda2015-01-22 16:03:33 -080070 global ONOS4Port
Jon Hall8f89dda2015-01-22 16:03:33 -080071 global ONOS5Port
Jon Hall8f89dda2015-01-22 16:03:33 -080072 global ONOS6Port
Jon Hall8f89dda2015-01-22 16:03:33 -080073 global ONOS7Port
74 global numControllers
Jon Hall5cfd23c2015-03-19 11:40:57 -070075 numControllers = int( main.params[ 'num_controllers' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -080076
Jon Hall8f89dda2015-01-22 16:03:33 -080077 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
78 ONOS1Port = main.params[ 'CTRL' ][ 'port1' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080079 ONOS2Port = main.params[ 'CTRL' ][ 'port2' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080080 ONOS3Port = main.params[ 'CTRL' ][ 'port3' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080081 ONOS4Port = main.params[ 'CTRL' ][ 'port4' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080082 ONOS5Port = main.params[ 'CTRL' ][ 'port5' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080083 ONOS6Port = main.params[ 'CTRL' ][ 'port6' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080084 ONOS7Port = main.params[ 'CTRL' ][ 'port7' ]
Jon Hall73cf9cc2014-11-20 22:28:38 -080085
Jon Halla9d26da2015-03-30 16:45:32 -070086 global CLIs
87 CLIs = []
88 global nodes
89 nodes = []
90 for i in range( 1, numControllers + 1 ):
91 CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
92 nodes.append( getattr( main, 'ONOS' + str( i ) ) )
93
Jon Hall6aec96b2015-01-19 14:49:31 -080094 main.step( "Applying cell variable to environment" )
Jon Hall8f89dda2015-01-22 16:03:33 -080095 cellResult = main.ONOSbench.setCell( cellName )
96 verifyResult = main.ONOSbench.verifyCell()
Jon Hall73cf9cc2014-11-20 22:28:38 -080097
Jon Hall6aec96b2015-01-19 14:49:31 -080098 # FIXME:this is short term fix
Jon Hallfeff3082015-05-19 10:23:26 -070099 main.log.info( "Removing raft logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800100 main.ONOSbench.onosRemoveRaftLogs()
Jon Halla9d26da2015-03-30 16:45:32 -0700101
Jon Hallfeff3082015-05-19 10:23:26 -0700102 main.log.info( "Uninstalling ONOS" )
Jon Halla9d26da2015-03-30 16:45:32 -0700103 for node in nodes:
104 main.ONOSbench.onosUninstall( node.ip_address )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800105
Jon Hall390696c2015-05-05 17:13:41 -0700106 # Make sure ONOS is DEAD
Jon Hallfeff3082015-05-19 10:23:26 -0700107 main.log.info( "Killing any ONOS processes" )
Jon Hall390696c2015-05-05 17:13:41 -0700108 killResults = main.TRUE
109 for node in nodes:
110 killed = main.ONOSbench.onosKill( node.ip_address )
111 killResults = killResults and killed
112
Jon Hall8f89dda2015-01-22 16:03:33 -0800113 cleanInstallResult = main.TRUE
114 gitPullResult = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800115
Jon Hall97f31752015-02-04 12:01:04 -0800116 main.step( "Starting Mininet" )
Jon Hall390696c2015-05-05 17:13:41 -0700117 mnResult = main.Mininet1.startNet( )
118 utilities.assert_equals( expect=main.TRUE, actual=mnResult,
119 onpass="Mininet Started",
120 onfail="Error starting Mininet" )
Jon Hall97f31752015-02-04 12:01:04 -0800121
Jon Hallfeff3082015-05-19 10:23:26 -0700122 main.step( "Git checkout and pull " + gitBranch )
Jon Hall8f89dda2015-01-22 16:03:33 -0800123 if PULLCODE:
Jon Hall529a37f2015-01-28 10:02:00 -0800124 main.ONOSbench.gitCheckout( gitBranch )
Jon Hall8f89dda2015-01-22 16:03:33 -0800125 gitPullResult = main.ONOSbench.gitPull()
Jon Hall390696c2015-05-05 17:13:41 -0700126 # values of 1 or 3 are good
127 utilities.assert_lesser( expect=0, actual=gitPullResult,
128 onpass="Git pull successful",
129 onfail="Git pull failed" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800130 main.ONOSbench.getVersion( report=True )
Jon Hallfeff3082015-05-19 10:23:26 -0700131
132 main.step( "Using mvn clean install" )
133 cleanInstallResult = main.TRUE
Jon Hall40d2cbd2015-06-03 16:24:29 -0700134 if PULLCODE and gitPullResult == main.TRUE:
Jon Hallfeff3082015-05-19 10:23:26 -0700135 cleanInstallResult = main.ONOSbench.cleanInstall()
Jon Hall40d2cbd2015-06-03 16:24:29 -0700136 else:
137 main.log.warn( "Did not pull new code so skipping mvn " +
138 "clean install" )
Jon Hallfeff3082015-05-19 10:23:26 -0700139 utilities.assert_equals( expect=main.TRUE,
140 actual=cleanInstallResult,
141 onpass="MCI successful",
142 onfail="MCI failed" )
Jon Hall390696c2015-05-05 17:13:41 -0700143 # GRAPHS
144 # NOTE: important params here:
145 # job = name of Jenkins job
146 # Plot Name = Plot-HA, only can be used if multiple plots
147 # index = The number of the graph under plot name
148 job = "HASingleInstanceRestart"
Jon Hall40d2cbd2015-06-03 16:24:29 -0700149 plotName = "Plot-HA"
Jon Hall390696c2015-05-05 17:13:41 -0700150 graphs = '<ac:structured-macro ac:name="html">\n'
151 graphs += '<ac:plain-text-body><![CDATA[\n'
152 graphs += '<iframe src="https://onos-jenkins.onlab.us/job/' + job +\
Jon Hall40d2cbd2015-06-03 16:24:29 -0700153 '/plot/' + plotName + '/getPlot?index=0' +\
154 '&width=500&height=300"' +\
Jon Hall390696c2015-05-05 17:13:41 -0700155 'noborder="0" width="500" height="300" scrolling="yes" ' +\
156 'seamless="seamless"></iframe>\n'
157 graphs += ']]></ac:plain-text-body>\n'
158 graphs += '</ac:structured-macro>\n'
159 main.log.wiki(graphs)
Jon Hall73cf9cc2014-11-20 22:28:38 -0800160
Jon Hall8f89dda2015-01-22 16:03:33 -0800161 cellResult = main.ONOSbench.setCell( "SingleHA" )
162 verifyResult = main.ONOSbench.verifyCell()
Jon Hall6aec96b2015-01-19 14:49:31 -0800163 main.step( "Creating ONOS package" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800164 packageResult = main.ONOSbench.onosPackage()
Jon Hall390696c2015-05-05 17:13:41 -0700165 utilities.assert_equals( expect=main.TRUE, actual=packageResult,
166 onpass="ONOS package successful",
167 onfail="ONOS package failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800168
Jon Hall6aec96b2015-01-19 14:49:31 -0800169 main.step( "Installing ONOS package" )
Jon Hall390696c2015-05-05 17:13:41 -0700170 onosInstallResult = main.ONOSbench.onosInstall( options="-f",
Jon Hall8f89dda2015-01-22 16:03:33 -0800171 node=ONOS1Ip )
Jon Hall390696c2015-05-05 17:13:41 -0700172 utilities.assert_equals( expect=main.TRUE, actual=onosInstallResult,
173 onpass="ONOS install successful",
174 onfail="ONOS install failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800175
Jon Hall6aec96b2015-01-19 14:49:31 -0800176 main.step( "Checking if ONOS is up yet" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800177 for i in range( 2 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800178 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
179 if onos1Isup:
Jon Hall94fd0472014-12-08 11:52:42 -0800180 break
Jon Hall390696c2015-05-05 17:13:41 -0700181 utilities.assert_equals( expect=main.TRUE, actual=onos1Isup,
182 onpass="ONOS startup successful",
183 onfail="ONOS startup failed" )
Jon Hall94fd0472014-12-08 11:52:42 -0800184
Jon Hall390696c2015-05-05 17:13:41 -0700185 main.log.step( "Starting ONOS CLI sessions" )
186 cliResults = main.ONOScli1.startOnosCli( ONOS1Ip )
187 utilities.assert_equals( expect=main.TRUE, actual=cliResults,
188 onpass="ONOS cli startup successful",
189 onfail="ONOS cli startup failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800190
Jon Hall40d2cbd2015-06-03 16:24:29 -0700191 if main.params[ 'tcpdump' ].lower() == "true":
192 main.step( "Start Packet Capture MN" )
193 main.Mininet2.startTcpdump(
194 str( main.params[ 'MNtcpdump' ][ 'folder' ] ) + str( main.TEST )
195 + "-MN.pcap",
196 intf=main.params[ 'MNtcpdump' ][ 'intf' ],
197 port=main.params[ 'MNtcpdump' ][ 'port' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800198
Jon Hall390696c2015-05-05 17:13:41 -0700199 main.step( "App Ids check" )
Jon Hallfeff3082015-05-19 10:23:26 -0700200 appCheck = main.ONOScli1.appToIDCheck()
Jon Hall390696c2015-05-05 17:13:41 -0700201 if appCheck != main.TRUE:
202 main.log.warn( CLIs[0].apps() )
203 main.log.warn( CLIs[0].appIDs() )
204 utilities.assert_equals( expect=main.TRUE, actual=appCheck,
205 onpass="App Ids seem to be correct",
206 onfail="Something is wrong with app Ids" )
207
Jon Hallfeff3082015-05-19 10:23:26 -0700208 if cliResults == main.FALSE:
209 main.log.error( "Failed to start ONOS, stopping test" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800210 main.cleanup()
211 main.exit()
212
Jon Hall6aec96b2015-01-19 14:49:31 -0800213 def CASE2( self, main ):
214 """
Jon Hallc9eabec2015-06-10 14:33:14 -0700215 Assign devices to controllers
Jon Hall6aec96b2015-01-19 14:49:31 -0800216 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800217 import re
Jon Hallc9eabec2015-06-10 14:33:14 -0700218 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -0700219 assert numControllers, "numControllers not defined"
220 assert main, "main not defined"
221 assert utilities.assert_equals, "utilities.assert_equals not defined"
222 assert ONOS1Port, "ONOS1Port not defined"
223 assert ONOS2Port, "ONOS2Port not defined"
224 assert ONOS3Port, "ONOS3Port not defined"
225 assert ONOS4Port, "ONOS4Port not defined"
226 assert ONOS5Port, "ONOS5Port not defined"
227 assert ONOS6Port, "ONOS6Port not defined"
228 assert ONOS7Port, "ONOS7Port not defined"
Jon Hall73cf9cc2014-11-20 22:28:38 -0800229
Jon Hallc9eabec2015-06-10 14:33:14 -0700230 main.case( "Assigning devices to controllers" )
Jon Hallfeff3082015-05-19 10:23:26 -0700231 main.caseExplaination = "Assign switches to ONOS using 'ovs-vsctl' " +\
232 "and check that an ONOS node becomes the " +\
233 "master of the device."
Jon Hall6aec96b2015-01-19 14:49:31 -0800234 main.step( "Assign switches to controllers" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800235
Jon Hall6aec96b2015-01-19 14:49:31 -0800236 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800237 main.Mininet1.assignSwController(
Jon Hall6aec96b2015-01-19 14:49:31 -0800238 sw=str( i ),
Jon Hall8f89dda2015-01-22 16:03:33 -0800239 ip1=ONOS1Ip, port1=ONOS1Port )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800240
Jon Hall8f89dda2015-01-22 16:03:33 -0800241 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800242 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800243 response = main.Mininet1.getSwController( "s" + str( i ) )
Jon Hallffb386d2014-11-21 13:43:38 -0800244 try:
Jon Hall6aec96b2015-01-19 14:49:31 -0800245 main.log.info( str( response ) )
Jon Hallfebb1c72015-03-05 13:30:09 -0800246 except Exception:
Jon Hall6aec96b2015-01-19 14:49:31 -0800247 main.log.info( repr( response ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800248 if re.search( "tcp:" + ONOS1Ip, response ):
249 mastershipCheck = mastershipCheck and main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800250 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800251 mastershipCheck = main.FALSE
252 if mastershipCheck == main.TRUE:
Jon Hallfeff3082015-05-19 10:23:26 -0700253 main.log.info( "Switch mastership assigned correctly" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800254 utilities.assert_equals(
255 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800256 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800257 onpass="Switch mastership assigned correctly",
258 onfail="Switches not assigned correctly to controllers" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800259
Jon Hallc9eabec2015-06-10 14:33:14 -0700260 def CASE21( self, main ):
261 """
262 Assign mastership to controllers
263 """
264 import re
265 import time
266 assert numControllers, "numControllers not defined"
267 assert main, "main not defined"
268 assert utilities.assert_equals, "utilities.assert_equals not defined"
269 assert CLIs, "CLIs not defined"
270 assert nodes, "nodes not defined"
271 assert ONOS1Port, "ONOS1Port not defined"
272 assert ONOS2Port, "ONOS2Port not defined"
273 assert ONOS3Port, "ONOS3Port not defined"
274 assert ONOS4Port, "ONOS4Port not defined"
275 assert ONOS5Port, "ONOS5Port not defined"
276 assert ONOS6Port, "ONOS6Port not defined"
277 assert ONOS7Port, "ONOS7Port not defined"
278
279 main.case( "Assigning Controller roles for switches" )
280 main.caseExplaination = "Check that ONOS is connected to each " +\
281 "device. Then manually assign" +\
282 " mastership to specific ONOS nodes using" +\
283 " 'device-role'"
Jon Hall390696c2015-05-05 17:13:41 -0700284 main.step( "Assign mastership of switches to specific controllers" )
Jon Halla9d26da2015-03-30 16:45:32 -0700285 roleCall = main.TRUE
286 roleCheck = main.TRUE
287 try:
288 for i in range( 1, 29 ): # switches 1 through 28
289 ip = nodes[ 0 ].ip_address # ONOS1
290 # set up correct variables:
291 if i == 1:
292 deviceId = main.ONOScli1.getDevice( "1000" ).get( 'id' )
293 elif i == 2:
294 deviceId = main.ONOScli1.getDevice( "2000" ).get( 'id' )
295 elif i == 3:
296 deviceId = main.ONOScli1.getDevice( "3000" ).get( 'id' )
297 elif i == 4:
298 deviceId = main.ONOScli1.getDevice( "3004" ).get( 'id' )
299 elif i == 5:
300 deviceId = main.ONOScli1.getDevice( "5000" ).get( 'id' )
301 elif i == 6:
302 deviceId = main.ONOScli1.getDevice( "6000" ).get( 'id' )
303 elif i == 7:
304 deviceId = main.ONOScli1.getDevice( "6007" ).get( 'id' )
305 elif i >= 8 and i <= 17:
306 dpid = '3' + str( i ).zfill( 3 )
307 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
308 elif i >= 18 and i <= 27:
309 dpid = '6' + str( i ).zfill( 3 )
310 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
311 elif i == 28:
312 deviceId = main.ONOScli1.getDevice( "2800" ).get( 'id' )
313 else:
314 main.log.error( "You didn't write an else statement for " +
315 "switch s" + str( i ) )
316 # Assign switch
317 assert deviceId, "No device id for s" + str( i ) + " in ONOS"
318 # TODO: make this controller dynamic
319 roleCall = roleCall and main.ONOScli1.deviceRole( deviceId,
320 ip )
321 # Check assignment
Jon Hall390696c2015-05-05 17:13:41 -0700322 master = main.ONOScli1.getRole( deviceId ).get( 'master' )
Jon Hall678f4512015-03-31 09:48:31 -0700323 if ip in master:
Jon Halla9d26da2015-03-30 16:45:32 -0700324 roleCheck = roleCheck and main.TRUE
325 else:
326 roleCheck = roleCheck and main.FALSE
327 main.log.error( "Error, controller " + ip + " is not" +
328 " master " + "of device " +
Jon Hall678f4512015-03-31 09:48:31 -0700329 str( deviceId ) + ". Master is " +
330 repr( master ) + "." )
Jon Halla9d26da2015-03-30 16:45:32 -0700331 except ( AttributeError, AssertionError ):
332 main.log.exception( "Something is wrong with ONOS device view" )
333 main.log.info( main.ONOScli1.devices() )
334 utilities.assert_equals(
335 expect=main.TRUE,
336 actual=roleCall,
337 onpass="Re-assigned switch mastership to designated controller",
338 onfail="Something wrong with deviceRole calls" )
339
Jon Hall390696c2015-05-05 17:13:41 -0700340 main.step( "Check mastership was correctly assigned" )
Jon Halla9d26da2015-03-30 16:45:32 -0700341 utilities.assert_equals(
342 expect=main.TRUE,
343 actual=roleCheck,
344 onpass="Switches were successfully reassigned to designated " +
345 "controller",
346 onfail="Switches were not successfully reassigned" )
Jon Halla9d26da2015-03-30 16:45:32 -0700347
Jon Hall6aec96b2015-01-19 14:49:31 -0800348 def CASE3( self, main ):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800349 """
350 Assign intents
Jon Hall73cf9cc2014-11-20 22:28:38 -0800351 """
352 import time
Jon Hallfebb1c72015-03-05 13:30:09 -0800353 import json
Jon Hall5cfd23c2015-03-19 11:40:57 -0700354 assert numControllers, "numControllers not defined"
355 assert main, "main not defined"
356 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hallfeff3082015-05-19 10:23:26 -0700357 # NOTE: we must reinstall intents until we have a persistant intent
358 # datastore!
Jon Hall6aec96b2015-01-19 14:49:31 -0800359 main.case( "Adding host Intents" )
Jon Hallfeff3082015-05-19 10:23:26 -0700360 main.caseExplaination = "Discover hosts by using pingall then " +\
361 "assign predetermined host-to-host intents." +\
362 " After installation, check that the intent" +\
363 " is distributed to all nodes and the state" +\
364 " is INSTALLED"
Jon Hall73cf9cc2014-11-20 22:28:38 -0800365
Jon Hall6aec96b2015-01-19 14:49:31 -0800366 # install onos-app-fwd
Jon Hall390696c2015-05-05 17:13:41 -0700367 main.step( "Install reactive forwarding app" )
368 installResults = CLIs[0].activateApp( "org.onosproject.fwd" )
369 utilities.assert_equals( expect=main.TRUE, actual=installResults,
370 onpass="Install fwd successful",
371 onfail="Install fwd failed" )
Jon Halla9d26da2015-03-30 16:45:32 -0700372
Jon Hallfeff3082015-05-19 10:23:26 -0700373 main.step( "Check app ids" )
Jon Halla9d26da2015-03-30 16:45:32 -0700374 appCheck = main.ONOScli1.appToIDCheck()
375 if appCheck != main.TRUE:
376 main.log.warn( CLIs[0].apps() )
377 main.log.warn( CLIs[0].appIDs() )
Jon Hall390696c2015-05-05 17:13:41 -0700378 utilities.assert_equals( expect=main.TRUE, actual=appCheck,
379 onpass="App Ids seem to be correct",
380 onfail="Something is wrong with app Ids" )
Jon Hall94fd0472014-12-08 11:52:42 -0800381
Jon Hallfeff3082015-05-19 10:23:26 -0700382 main.step( "Discovering Hosts( Via pingall for now )" )
383 # FIXME: Once we have a host discovery mechanism, use that instead
Jon Hall6aec96b2015-01-19 14:49:31 -0800384 # REACTIVE FWD test
Jon Hall8f89dda2015-01-22 16:03:33 -0800385 pingResult = main.FALSE
Jon Hall5cfd23c2015-03-19 11:40:57 -0700386 for i in range(2): # Retry if pingall fails first time
387 time1 = time.time()
388 pingResult = main.Mininet1.pingall()
389 utilities.assert_equals(
390 expect=main.TRUE,
391 actual=pingResult,
392 onpass="Reactive Pingall test passed",
Jon Hall390696c2015-05-05 17:13:41 -0700393 onfail="Reactive Pingall failed, " +
394 "one or more ping pairs failed" )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700395 time2 = time.time()
Jon Hall390696c2015-05-05 17:13:41 -0700396 main.log.info( "Time for pingall: %2f seconds" %
397 ( time2 - time1 ) )
398 # timeout for fwd flows
399 time.sleep( 11 )
Jon Hall6aec96b2015-01-19 14:49:31 -0800400 # uninstall onos-app-fwd
Jon Hall390696c2015-05-05 17:13:41 -0700401 main.step( "Uninstall reactive forwarding app" )
402 uninstallResult = CLIs[0].deactivateApp( "org.onosproject.fwd" )
403 utilities.assert_equals( expect=main.TRUE, actual=uninstallResult,
404 onpass="Uninstall fwd successful",
405 onfail="Uninstall fwd failed" )
Jon Hallfeff3082015-05-19 10:23:26 -0700406
407 main.step( "Check app ids" )
Jon Halla9d26da2015-03-30 16:45:32 -0700408 appCheck2 = main.ONOScli1.appToIDCheck()
409 if appCheck2 != main.TRUE:
410 main.log.warn( CLIs[0].apps() )
411 main.log.warn( CLIs[0].appIDs() )
Jon Hall390696c2015-05-05 17:13:41 -0700412 utilities.assert_equals( expect=main.TRUE, actual=appCheck2,
413 onpass="App Ids seem to be correct",
414 onfail="Something is wrong with app Ids" )
Jon Halla9d26da2015-03-30 16:45:32 -0700415
Jon Hallfeff3082015-05-19 10:23:26 -0700416 main.step( "Add host intents via cli" )
Jon Hall58c76b72015-02-23 11:09:24 -0800417 intentIds = []
Jon Hall6aec96b2015-01-19 14:49:31 -0800418 # TODO: move the host numbers to params
Jon Hall58c76b72015-02-23 11:09:24 -0800419 # Maybe look at all the paths we ping?
Jon Hall8f89dda2015-01-22 16:03:33 -0800420 intentAddResult = True
Jon Hall58c76b72015-02-23 11:09:24 -0800421 hostResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800422 for i in range( 8, 18 ):
423 main.log.info( "Adding host intent between h" + str( i ) +
424 " and h" + str( i + 10 ) )
425 host1 = "00:00:00:00:00:" + \
426 str( hex( i )[ 2: ] ).zfill( 2 ).upper()
427 host2 = "00:00:00:00:00:" + \
428 str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper()
Jon Hall1b8f54a2015-02-04 13:24:20 -0800429 # NOTE: getHost can return None
430 host1Dict = main.ONOScli1.getHost( host1 )
431 host2Dict = main.ONOScli1.getHost( host2 )
432 host1Id = None
433 host2Id = None
434 if host1Dict and host2Dict:
435 host1Id = host1Dict.get( 'id', None )
436 host2Id = host2Dict.get( 'id', None )
Jon Hall8f89dda2015-01-22 16:03:33 -0800437 if host1Id and host2Id:
Jon Halla9d26da2015-03-30 16:45:32 -0700438 tmpId = main.ONOScli1.addHostIntent( host1Id, host2Id )
Jon Hall63604932015-02-26 17:09:50 -0800439 if tmpId:
440 main.log.info( "Added intent with id: " + tmpId )
441 intentIds.append( tmpId )
442 else:
Jon Halla9d26da2015-03-30 16:45:32 -0700443 main.log.error( "addHostIntent returned: " +
444 repr( tmpId ) )
Jon Hall669173b2014-12-17 11:36:30 -0800445 else:
Jon Halla9d26da2015-03-30 16:45:32 -0700446 main.log.error( "Error, getHost() failed for h" + str( i ) +
447 " and/or h" + str( i + 10 ) )
448 hosts = main.ONOScli1.hosts()
449 main.log.warn( "Hosts output: " )
450 try:
451 main.log.warn( json.dumps( json.loads( hosts ),
452 sort_keys=True,
453 indent=4,
454 separators=( ',', ': ' ) ) )
455 except ( ValueError, TypeError ):
456 main.log.warn( repr( hosts ) )
Jon Hall58c76b72015-02-23 11:09:24 -0800457 hostResult = main.FALSE
Jon Hallfeff3082015-05-19 10:23:26 -0700458 utilities.assert_equals( expect=main.TRUE, actual=hostResult,
459 onpass="Found a host id for each host",
460 onfail="Error looking up host ids" )
461
Jon Halla9d26da2015-03-30 16:45:32 -0700462 intentStart = time.time()
Jon Hall58c76b72015-02-23 11:09:24 -0800463 onosIds = main.ONOScli1.getAllIntentsId()
464 main.log.info( "Submitted intents: " + str( intentIds ) )
465 main.log.info( "Intents in ONOS: " + str( onosIds ) )
466 for intent in intentIds:
467 if intent in onosIds:
Jon Halla9d26da2015-03-30 16:45:32 -0700468 pass # intent submitted is in onos
Jon Hall58c76b72015-02-23 11:09:24 -0800469 else:
470 intentAddResult = False
Jon Halla9d26da2015-03-30 16:45:32 -0700471 # FIXME: DEBUG
472 if intentAddResult:
473 intentStop = time.time()
474 else:
475 intentStop = None
Jon Hall1b8f54a2015-02-04 13:24:20 -0800476 # Print the intent states
Jon Hall58c76b72015-02-23 11:09:24 -0800477 intents = main.ONOScli1.intents()
Jon Hall1b8f54a2015-02-04 13:24:20 -0800478 intentStates = []
Jon Halla9d26da2015-03-30 16:45:32 -0700479 installedCheck = True
Jon Hall58c76b72015-02-23 11:09:24 -0800480 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
481 count = 0
Jon Hall5cfd23c2015-03-19 11:40:57 -0700482 try:
483 for intent in json.loads( intents ):
484 state = intent.get( 'state', None )
485 if "INSTALLED" not in state:
486 installedCheck = False
487 intentId = intent.get( 'id', None )
488 intentStates.append( ( intentId, state ) )
489 except ( ValueError, TypeError ):
490 main.log.exception( "Error parsing intents" )
Jon Hall58c76b72015-02-23 11:09:24 -0800491 # 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 Hall5cfd23c2015-03-19 11:40:57 -0700503 leaders = main.ONOScli1.leaders()
504 try:
505 if leaders:
506 parsedLeaders = json.loads( leaders )
507 main.log.warn( json.dumps( parsedLeaders,
508 sort_keys=True,
509 indent=4,
510 separators=( ',', ': ' ) ) )
511 # check for all intent partitions
Jon Hall5cfd23c2015-03-19 11:40:57 -0700512 topics = []
513 for i in range( 14 ):
514 topics.append( "intent-partition-" + str( i ) )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700515 main.log.debug( topics )
516 ONOStopics = [ j['topic'] for j in parsedLeaders ]
517 for topic in topics:
518 if topic not in ONOStopics:
519 main.log.error( "Error: " + topic +
520 " not in leaders" )
521 else:
522 main.log.error( "leaders() returned None" )
523 except ( ValueError, TypeError ):
524 main.log.exception( "Error parsing leaders" )
525 main.log.error( repr( leaders ) )
526 partitions = main.ONOScli1.partitions()
527 try:
528 if partitions :
529 parsedPartitions = json.loads( partitions )
530 main.log.warn( json.dumps( parsedPartitions,
531 sort_keys=True,
532 indent=4,
533 separators=( ',', ': ' ) ) )
534 # TODO check for a leader in all paritions
535 # TODO check for consistency among nodes
536 else:
537 main.log.error( "partitions() returned None" )
538 except ( ValueError, TypeError ):
539 main.log.exception( "Error parsing partitions" )
540 main.log.error( repr( partitions ) )
Jon Hall63604932015-02-26 17:09:50 -0800541 pendingMap = main.ONOScli1.pendingMap()
Jon Hall5cfd23c2015-03-19 11:40:57 -0700542 try:
543 if pendingMap :
544 parsedPending = json.loads( pendingMap )
545 main.log.warn( json.dumps( parsedPending,
546 sort_keys=True,
547 indent=4,
548 separators=( ',', ': ' ) ) )
549 # TODO check something here?
550 else:
551 main.log.error( "pendingMap() returned None" )
552 except ( ValueError, TypeError ):
553 main.log.exception( "Error parsing pending map" )
554 main.log.error( repr( pendingMap ) )
555
Jon Hallfeff3082015-05-19 10:23:26 -0700556 intentAddResult = bool( intentAddResult and not missingIntents and
557 installedCheck )
558 if not intentAddResult:
559 main.log.error( "Error in pushing host intents to ONOS" )
560
Jon Hall390696c2015-05-05 17:13:41 -0700561 main.step( "Intent Anti-Entropy dispersion" )
562 for i in range(100):
563 correct = True
564 main.log.info( "Submitted intents: " + str( sorted( intentIds ) ) )
565 for cli in CLIs:
566 onosIds = []
567 ids = cli.getAllIntentsId()
568 onosIds.append( ids )
569 main.log.debug( "Intents in " + cli.name + ": " +
570 str( sorted( onosIds ) ) )
571 if sorted( ids ) != sorted( intentIds ):
572 correct = False
573 if correct:
574 break
575 else:
576 time.sleep(1)
577 if not intentStop:
578 intentStop = time.time()
579 global gossipTime
580 gossipTime = intentStop - intentStart
581 main.log.info( "It took about " + str( gossipTime ) +
582 " seconds for all intents to appear in each node" )
583 # FIXME: make this time configurable/calculate based off of number of
584 # nodes and gossip rounds
585 utilities.assert_greater_equals(
586 expect=40, actual=gossipTime,
587 onpass="ECM anti-entropy for intents worked within " +
588 "expected time",
589 onfail="Intent ECM anti-entropy took too long" )
590 if gossipTime <= 40:
591 intentAddResult = True
Jon Hall58c76b72015-02-23 11:09:24 -0800592
Jon Hall63604932015-02-26 17:09:50 -0800593 if not intentAddResult or "key" in pendingMap:
Jon Hall58c76b72015-02-23 11:09:24 -0800594 import time
Jon Hall63604932015-02-26 17:09:50 -0800595 installedCheck = True
Jon Hall58c76b72015-02-23 11:09:24 -0800596 main.log.info( "Sleeping 60 seconds to see if intents are found" )
597 time.sleep( 60 )
598 onosIds = main.ONOScli1.getAllIntentsId()
599 main.log.info( "Submitted intents: " + str( intentIds ) )
600 main.log.info( "Intents in ONOS: " + str( onosIds ) )
601 # Print the intent states
602 intents = main.ONOScli1.intents()
603 intentStates = []
604 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
605 count = 0
Jon Hall5cfd23c2015-03-19 11:40:57 -0700606 try:
607 for intent in json.loads( intents ):
608 # Iter through intents of a node
609 state = intent.get( 'state', None )
610 if "INSTALLED" not in state:
611 installedCheck = False
612 intentId = intent.get( 'id', None )
613 intentStates.append( ( intentId, state ) )
614 except ( ValueError, TypeError ):
615 main.log.exception( "Error parsing intents" )
Jon Hall58c76b72015-02-23 11:09:24 -0800616 # add submitted intents not in the store
617 tmplist = [ i for i, s in intentStates ]
618 for i in intentIds:
619 if i not in tmplist:
620 intentStates.append( ( i, " - " ) )
621 intentStates.sort()
622 for i, s in intentStates:
623 count += 1
624 main.log.info( "%-6s%-15s%-15s" %
625 ( str( count ), str( i ), str( s ) ) )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700626 leaders = main.ONOScli1.leaders()
627 try:
628 if leaders:
629 parsedLeaders = json.loads( leaders )
630 main.log.warn( json.dumps( parsedLeaders,
631 sort_keys=True,
632 indent=4,
633 separators=( ',', ': ' ) ) )
634 # check for all intent partitions
635 # check for election
636 topics = []
637 for i in range( 14 ):
638 topics.append( "intent-partition-" + str( i ) )
639 # FIXME: this should only be after we start the app
640 topics.append( "org.onosproject.election" )
641 main.log.debug( topics )
642 ONOStopics = [ j['topic'] for j in parsedLeaders ]
643 for topic in topics:
644 if topic not in ONOStopics:
645 main.log.error( "Error: " + topic +
646 " not in leaders" )
647 else:
648 main.log.error( "leaders() returned None" )
649 except ( ValueError, TypeError ):
650 main.log.exception( "Error parsing leaders" )
651 main.log.error( repr( leaders ) )
652 partitions = main.ONOScli1.partitions()
653 try:
654 if partitions :
655 parsedPartitions = json.loads( partitions )
656 main.log.warn( json.dumps( parsedPartitions,
657 sort_keys=True,
658 indent=4,
659 separators=( ',', ': ' ) ) )
660 # TODO check for a leader in all paritions
661 # TODO check for consistency among nodes
662 else:
663 main.log.error( "partitions() returned None" )
664 except ( ValueError, TypeError ):
665 main.log.exception( "Error parsing partitions" )
666 main.log.error( repr( partitions ) )
667 pendingMap = main.ONOScli1.pendingMap()
668 try:
669 if pendingMap :
670 parsedPending = json.loads( pendingMap )
671 main.log.warn( json.dumps( parsedPending,
672 sort_keys=True,
673 indent=4,
674 separators=( ',', ': ' ) ) )
675 # TODO check something here?
676 else:
677 main.log.error( "pendingMap() returned None" )
678 except ( ValueError, TypeError ):
679 main.log.exception( "Error parsing pending map" )
680 main.log.error( repr( pendingMap ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800681
Jon Hall6aec96b2015-01-19 14:49:31 -0800682 def CASE4( self, main ):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800683 """
684 Ping across added host intents
685 """
Jon Hallfebb1c72015-03-05 13:30:09 -0800686 import json
Jon Halla9d26da2015-03-30 16:45:32 -0700687 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -0700688 assert numControllers, "numControllers not defined"
689 assert main, "main not defined"
690 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hallfeff3082015-05-19 10:23:26 -0700691 main.case( "Verify connectivity by sendind traffic across Intents" )
692 main.caseExplaination = "Ping across added host intents to check " +\
693 "functionality and check the state of " +\
694 "the intent"
695 main.step( "Ping across added host intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800696 PingResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800697 for i in range( 8, 18 ):
Jon Hall58c76b72015-02-23 11:09:24 -0800698 ping = main.Mininet1.pingHost( src="h" + str( i ),
699 target="h" + str( i + 10 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800700 PingResult = PingResult and ping
Jon Hall6aec96b2015-01-19 14:49:31 -0800701 if ping == main.FALSE:
702 main.log.warn( "Ping failed between h" + str( i ) +
703 " and h" + str( i + 10 ) )
704 elif ping == main.TRUE:
705 main.log.info( "Ping test passed!" )
Jon Hall21270ac2015-02-16 17:59:55 -0800706 # Don't set PingResult or you'd override failures
Jon Hall8f89dda2015-01-22 16:03:33 -0800707 if PingResult == main.FALSE:
Jon Hall40d2cbd2015-06-03 16:24:29 -0700708 main.log.error(
Jon Hall6aec96b2015-01-19 14:49:31 -0800709 "Intents have not been installed correctly, pings failed." )
Jon Hall58c76b72015-02-23 11:09:24 -0800710 # TODO: pretty print
Jon Hall5cfd23c2015-03-19 11:40:57 -0700711 main.log.warn( "ONOS1 intents: " )
712 try:
713 tmpIntents = main.ONOScli1.intents()
714 main.log.warn( json.dumps( json.loads( tmpIntents ),
715 sort_keys=True,
716 indent=4,
717 separators=( ',', ': ' ) ) )
718 except ( ValueError, TypeError ):
719 main.log.warn( repr( tmpIntents ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800720 utilities.assert_equals(
721 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800722 actual=PingResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800723 onpass="Intents have been installed correctly and pings work",
724 onfail="Intents have not been installed correctly, pings failed." )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800725
Jon Hallfeff3082015-05-19 10:23:26 -0700726 main.step( "Check Intent state" )
Jon Hall63604932015-02-26 17:09:50 -0800727 installedCheck = True
Jon Hallfeff3082015-05-19 10:23:26 -0700728 # Print the intent states
729 intents = main.ONOScli1.intents()
730 intentStates = []
731 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
732 count = 0
733 # Iter through intents of a node
734 try:
735 for intent in json.loads( intents ):
736 state = intent.get( 'state', None )
737 if "INSTALLED" not in state:
738 installedCheck = False
739 intentId = intent.get( 'id', None )
740 intentStates.append( ( intentId, state ) )
741 except ( ValueError, TypeError ):
742 main.log.exception( "Error parsing intents." )
743 # Print states
744 intentStates.sort()
745 for i, s in intentStates:
746 count += 1
747 main.log.info( "%-6s%-15s%-15s" %
748 ( str( count ), str( i ), str( s ) ) )
749 utilities.assert_equals( expect=True, actual=installedCheck,
750 onpass="Intents are all INSTALLED",
Jon Hall40d2cbd2015-06-03 16:24:29 -0700751 onfail="Intents are not all in " +
Jon Hallfeff3082015-05-19 10:23:26 -0700752 "INSTALLED state" )
753
754 main.step( "Check leadership of topics" )
755 leaders = main.ONOScli1.leaders()
756 topicCheck = main.TRUE
757 try:
758 if leaders:
759 parsedLeaders = json.loads( leaders )
760 main.log.warn( json.dumps( parsedLeaders,
761 sort_keys=True,
762 indent=4,
763 separators=( ',', ': ' ) ) )
764 # check for all intent partitions
765 # check for election
766 # TODO: Look at Devices as topics now that it uses this system
767 topics = []
768 for i in range( 14 ):
769 topics.append( "intent-partition-" + str( i ) )
770 # FIXME: this should only be after we start the app
771 # FIXME: topics.append( "org.onosproject.election" )
772 # Print leaders output
773 main.log.debug( topics )
774 ONOStopics = [ j['topic'] for j in parsedLeaders ]
775 for topic in topics:
776 if topic not in ONOStopics:
777 main.log.error( "Error: " + topic +
778 " not in leaders" )
779 topicCheck = main.FALSE
780 else:
781 main.log.error( "leaders() returned None" )
782 topicCheck = main.FALSE
783 except ( ValueError, TypeError ):
784 topicCheck = main.FALSE
785 main.log.exception( "Error parsing leaders" )
786 main.log.error( repr( leaders ) )
787 # TODO: Check for a leader of these topics
788 utilities.assert_equals( expect=main.TRUE, actual=topicCheck,
789 onpass="intent Partitions is in leaders",
790 onfail="Some topics were lost " )
791 # Print partitions
792 partitions = main.ONOScli1.partitions()
793 try:
794 if partitions :
795 parsedPartitions = json.loads( partitions )
796 main.log.warn( json.dumps( parsedPartitions,
797 sort_keys=True,
798 indent=4,
799 separators=( ',', ': ' ) ) )
800 # TODO check for a leader in all paritions
801 # TODO check for consistency among nodes
802 else:
803 main.log.error( "partitions() returned None" )
804 except ( ValueError, TypeError ):
805 main.log.exception( "Error parsing partitions" )
806 main.log.error( repr( partitions ) )
807 # Print Pending Map
808 pendingMap = main.ONOScli1.pendingMap()
809 try:
810 if pendingMap :
811 parsedPending = json.loads( pendingMap )
812 main.log.warn( json.dumps( parsedPending,
813 sort_keys=True,
814 indent=4,
815 separators=( ',', ': ' ) ) )
816 # TODO check something here?
817 else:
818 main.log.error( "pendingMap() returned None" )
819 except ( ValueError, TypeError ):
820 main.log.exception( "Error parsing pending map" )
821 main.log.error( repr( pendingMap ) )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700822
Jon Hall63604932015-02-26 17:09:50 -0800823 if not installedCheck:
Jon Hall5cfd23c2015-03-19 11:40:57 -0700824 main.log.info( "Waiting 60 seconds to see if the state of " +
825 "intents change" )
Jon Hall63604932015-02-26 17:09:50 -0800826 time.sleep( 60 )
827 # Print the intent states
828 intents = main.ONOScli1.intents()
829 intentStates = []
830 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
831 count = 0
832 # Iter through intents of a node
Jon Hall5cfd23c2015-03-19 11:40:57 -0700833 try:
834 for intent in json.loads( intents ):
835 state = intent.get( 'state', None )
836 if "INSTALLED" not in state:
837 installedCheck = False
838 intentId = intent.get( 'id', None )
839 intentStates.append( ( intentId, state ) )
840 except ( ValueError, TypeError ):
841 main.log.exception( "Error parsing intents." )
Jon Hall63604932015-02-26 17:09:50 -0800842 intentStates.sort()
843 for i, s in intentStates:
844 count += 1
845 main.log.info( "%-6s%-15s%-15s" %
846 ( str( count ), str( i ), str( s ) ) )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700847 leaders = main.ONOScli1.leaders()
848 try:
849 if leaders:
850 parsedLeaders = json.loads( leaders )
851 main.log.warn( json.dumps( parsedLeaders,
852 sort_keys=True,
853 indent=4,
854 separators=( ',', ': ' ) ) )
855 # check for all intent partitions
856 # check for election
857 topics = []
858 for i in range( 14 ):
859 topics.append( "intent-partition-" + str( i ) )
860 # FIXME: this should only be after we start the app
861 topics.append( "org.onosproject.election" )
862 main.log.debug( topics )
863 ONOStopics = [ j['topic'] for j in parsedLeaders ]
864 for topic in topics:
865 if topic not in ONOStopics:
866 main.log.error( "Error: " + topic +
867 " not in leaders" )
868 else:
869 main.log.error( "leaders() returned None" )
870 except ( ValueError, TypeError ):
871 main.log.exception( "Error parsing leaders" )
872 main.log.error( repr( leaders ) )
873 partitions = main.ONOScli1.partitions()
874 try:
875 if partitions :
876 parsedPartitions = json.loads( partitions )
877 main.log.warn( json.dumps( parsedPartitions,
878 sort_keys=True,
879 indent=4,
880 separators=( ',', ': ' ) ) )
881 # TODO check for a leader in all paritions
882 # TODO check for consistency among nodes
883 else:
884 main.log.error( "partitions() returned None" )
885 except ( ValueError, TypeError ):
886 main.log.exception( "Error parsing partitions" )
887 main.log.error( repr( partitions ) )
888 pendingMap = main.ONOScli1.pendingMap()
889 try:
890 if pendingMap :
891 parsedPending = json.loads( pendingMap )
892 main.log.warn( json.dumps( parsedPending,
893 sort_keys=True,
894 indent=4,
895 separators=( ',', ': ' ) ) )
896 # TODO check something here?
897 else:
898 main.log.error( "pendingMap() returned None" )
899 except ( ValueError, TypeError ):
900 main.log.exception( "Error parsing pending map" )
901 main.log.error( repr( pendingMap ) )
Jon Hall40d2cbd2015-06-03 16:24:29 -0700902 # Print flowrules
903 main.log.debug( CLIs[0].flows( jsonFormat=False ) )
Jon Hallfeff3082015-05-19 10:23:26 -0700904 main.step( "Wait a minute then ping again" )
Jon Hall40d2cbd2015-06-03 16:24:29 -0700905 # the wait is above
Jon Hallfeff3082015-05-19 10:23:26 -0700906 PingResult = main.TRUE
907 for i in range( 8, 18 ):
908 ping = main.Mininet1.pingHost( src="h" + str( i ),
909 target="h" + str( i + 10 ) )
910 PingResult = PingResult and ping
911 if ping == main.FALSE:
912 main.log.warn( "Ping failed between h" + str( i ) +
913 " and h" + str( i + 10 ) )
914 elif ping == main.TRUE:
915 main.log.info( "Ping test passed!" )
916 # Don't set PingResult or you'd override failures
917 if PingResult == main.FALSE:
Jon Hall40d2cbd2015-06-03 16:24:29 -0700918 main.log.error(
Jon Hallfeff3082015-05-19 10:23:26 -0700919 "Intents have not been installed correctly, pings failed." )
920 # TODO: pretty print
921 main.log.warn( "ONOS1 intents: " )
922 try:
923 tmpIntents = main.ONOScli1.intents()
924 main.log.warn( json.dumps( json.loads( tmpIntents ),
925 sort_keys=True,
926 indent=4,
927 separators=( ',', ': ' ) ) )
928 except ( ValueError, TypeError ):
929 main.log.warn( repr( tmpIntents ) )
930 utilities.assert_equals(
931 expect=main.TRUE,
932 actual=PingResult,
933 onpass="Intents have been installed correctly and pings work",
934 onfail="Intents have not been installed correctly, pings failed." )
935
Jon Hall6aec96b2015-01-19 14:49:31 -0800936 def CASE5( self, main ):
937 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800938 Reading state of ONOS
Jon Hall6aec96b2015-01-19 14:49:31 -0800939 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800940 import json
Jon Hall5cfd23c2015-03-19 11:40:57 -0700941 assert numControllers, "numControllers not defined"
942 assert main, "main not defined"
943 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -0800944 # assumes that sts is already in you PYTHONPATH
945 from sts.topology.teston_topology import TestONTopology
Jon Hall73cf9cc2014-11-20 22:28:38 -0800946
Jon Hall6aec96b2015-01-19 14:49:31 -0800947 main.case( "Setting up and gathering data for current state" )
948 # The general idea for this test case is to pull the state of
949 # ( intents,flows, topology,... ) from each ONOS node
Jon Hall5cfd23c2015-03-19 11:40:57 -0700950 # We can then compare them with each other and also with past states
Jon Hall73cf9cc2014-11-20 22:28:38 -0800951
Jon Halla9d26da2015-03-30 16:45:32 -0700952 main.step( "Check that each switch has a master" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800953 global mastershipState
Jon Halla9d26da2015-03-30 16:45:32 -0700954 mastershipState = '[]'
Jon Hall94fd0472014-12-08 11:52:42 -0800955
Jon Hall6aec96b2015-01-19 14:49:31 -0800956 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -0800957 rolesNotNull = main.ONOScli1.rolesNotNull()
Jon Hall6aec96b2015-01-19 14:49:31 -0800958 utilities.assert_equals(
959 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800960 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -0800961 onpass="Each device has a master",
962 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -0800963
Jon Hall390696c2015-05-05 17:13:41 -0700964 main.step( "Get the Mastership of each switch" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800965 ONOS1Mastership = main.ONOScli1.roles()
Jon Hall6aec96b2015-01-19 14:49:31 -0800966 # TODO: Make this a meaningful check
Jon Hall8f89dda2015-01-22 16:03:33 -0800967 if "Error" in ONOS1Mastership or not ONOS1Mastership:
Jon Hall40d2cbd2015-06-03 16:24:29 -0700968 main.log.error( "Error in getting ONOS roles" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800969 main.log.warn(
970 "ONOS1 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800971 repr( ONOS1Mastership ) )
972 consistentMastership = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800973 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800974 mastershipState = ONOS1Mastership
975 consistentMastership = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800976
Jon Hall6aec96b2015-01-19 14:49:31 -0800977 main.step( "Get the intents from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800978 global intentState
979 intentState = []
980 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
981 intentCheck = main.FALSE
982 if "Error" in ONOS1Intents or not ONOS1Intents:
Jon Hall40d2cbd2015-06-03 16:24:29 -0700983 main.log.error( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800984 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800985 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800986 intentCheck = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800987
Jon Hall6aec96b2015-01-19 14:49:31 -0800988 main.step( "Get the flows from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800989 global flowState
990 flowState = []
Jon Hall8f89dda2015-01-22 16:03:33 -0800991 flowCheck = main.FALSE
Jon Hall58c76b72015-02-23 11:09:24 -0800992 ONOS1Flows = main.ONOScli1.flows( jsonFormat=True )
Jon Hall8f89dda2015-01-22 16:03:33 -0800993 if "Error" in ONOS1Flows or not ONOS1Flows:
Jon Hall40d2cbd2015-06-03 16:24:29 -0700994 main.log.error( "Error in getting ONOS flows" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800995 main.log.warn( "ONOS1 flows repsponse: " + ONOS1Flows )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800996 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800997 # TODO: Do a better check, maybe compare flows on switches?
Jon Hall8f89dda2015-01-22 16:03:33 -0800998 flowState = ONOS1Flows
999 flowCheck = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001000
Jon Hall6aec96b2015-01-19 14:49:31 -08001001 main.step( "Get the OF Table entries" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001002 global flows
Jon Hall6aec96b2015-01-19 14:49:31 -08001003 flows = []
1004 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -08001005 flows.append( main.Mininet2.getFlowTable( 1.3, "s" + str( i ) ) )
Jon Hall58c76b72015-02-23 11:09:24 -08001006 if flowCheck == main.FALSE:
1007 for table in flows:
1008 main.log.warn( table )
Jon Hall6aec96b2015-01-19 14:49:31 -08001009 # TODO: Compare switch flow tables with ONOS flow tables
Jon Hall73cf9cc2014-11-20 22:28:38 -08001010
Jon Hall6aec96b2015-01-19 14:49:31 -08001011 main.step( "Create TestONTopology object" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001012 ctrls = []
Jon Hall390696c2015-05-05 17:13:41 -07001013 temp = ( nodes[0], nodes[0].name, nodes[0].ip_address, 6633 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001014 ctrls.append( temp )
Jon Hall390696c2015-05-05 17:13:41 -07001015 MNTopo = TestONTopology( main.Mininet1, ctrls )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001016
Jon Hall6aec96b2015-01-19 14:49:31 -08001017 main.step( "Collecting topology information from ONOS" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001018 devices = []
1019 devices.append( main.ONOScli1.devices() )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001020 hosts = []
Jon Hall58c76b72015-02-23 11:09:24 -08001021 hosts.append( json.loads( main.ONOScli1.hosts() ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001022 ports = []
1023 ports.append( main.ONOScli1.ports() )
1024 links = []
1025 links.append( main.ONOScli1.links() )
Jon Hall58c76b72015-02-23 11:09:24 -08001026 clusters = []
1027 clusters.append( main.ONOScli1.clusters() )
Jon Hall390696c2015-05-05 17:13:41 -07001028
1029 main.step( "Each host has an IP address" )
Jon Hall58c76b72015-02-23 11:09:24 -08001030 ipResult = main.TRUE
1031 for controller in range( 0, len( hosts ) ):
1032 controllerStr = str( controller + 1 )
1033 for host in hosts[ controller ]:
Jon Hallfeff3082015-05-19 10:23:26 -07001034 if host is None or host.get( 'ipAddresses', [] ) == []:
Jon Hall58c76b72015-02-23 11:09:24 -08001035 main.log.error(
1036 "DEBUG:Error with host ips on controller" +
1037 controllerStr + ": " + str( host ) )
1038 ipResult = main.FALSE
Jon Hall390696c2015-05-05 17:13:41 -07001039 utilities.assert_equals(
1040 expect=main.TRUE,
1041 actual=ipResult,
1042 onpass="The ips of the hosts aren't empty",
1043 onfail="The ip of at least one host is missing" )
Jon Hall58c76b72015-02-23 11:09:24 -08001044
1045 # there should always only be one cluster
Jon Hall390696c2015-05-05 17:13:41 -07001046 main.step( "There is only one dataplane cluster" )
1047 try:
1048 numClusters = len( json.loads( clusters[ 0 ] ) )
1049 except ( ValueError, TypeError ):
1050 main.log.exception( "Error parsing clusters[0]: " +
1051 repr( clusters[ 0 ] ) )
Jon Hall58c76b72015-02-23 11:09:24 -08001052 clusterResults = main.FALSE
1053 if numClusters == 1:
1054 clusterResults = main.TRUE
1055 utilities.assert_equals(
1056 expect=1,
1057 actual=numClusters,
1058 onpass="ONOS shows 1 SCC",
1059 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001060
Jon Hall6aec96b2015-01-19 14:49:31 -08001061 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001062 devicesResults = main.TRUE
1063 portsResults = main.TRUE
1064 linksResults = main.TRUE
Jon Hall58c76b72015-02-23 11:09:24 -08001065 hostsResults = main.TRUE
Jon Hall8f89dda2015-01-22 16:03:33 -08001066 for controller in range( numControllers ):
1067 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001068 if devices[ controller ] or "Error" not in devices[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001069 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -08001070 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001071 json.loads( devices[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001072 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001073 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001074 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001075 actual=currentDevicesResult,
1076 onpass="ONOS" + controllerStr +
1077 " Switches view is correct",
1078 onfail="ONOS" + controllerStr +
1079 " Switches view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001080
Jon Hall6aec96b2015-01-19 14:49:31 -08001081 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001082 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -08001083 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001084 json.loads( ports[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001085 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001086 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001087 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001088 actual=currentPortsResult,
1089 onpass="ONOS" + controllerStr +
1090 " ports view is correct",
1091 onfail="ONOS" + controllerStr +
1092 " ports view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001093
Jon Hall6aec96b2015-01-19 14:49:31 -08001094 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001095 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -08001096 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001097 json.loads( links[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001098 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001099 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001100 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001101 actual=currentLinksResult,
1102 onpass="ONOS" + controllerStr +
1103 " links view is correct",
1104 onfail="ONOS" + controllerStr +
1105 " links view is incorrect" )
1106
1107 if hosts[ controller ] or "Error" not in hosts[ controller ]:
1108 currentHostsResult = main.Mininet1.compareHosts(
1109 MNTopo, hosts[ controller ] )
1110 else:
1111 currentHostsResult = main.FALSE
1112 utilities.assert_equals( expect=main.TRUE,
1113 actual=currentHostsResult,
1114 onpass="ONOS" + controllerStr +
1115 " hosts exist in Mininet",
1116 onfail="ONOS" + controllerStr +
1117 " hosts don't match Mininet" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001118
Jon Hall8f89dda2015-01-22 16:03:33 -08001119 devicesResults = devicesResults and currentDevicesResult
1120 portsResults = portsResults and currentPortsResult
1121 linksResults = linksResults and currentLinksResult
Jon Hall58c76b72015-02-23 11:09:24 -08001122 hostsResults = hostsResults and currentHostsResult
Jon Hall73cf9cc2014-11-20 22:28:38 -08001123
Jon Hall58c76b72015-02-23 11:09:24 -08001124 topoResult = devicesResults and portsResults and linksResults\
1125 and clusterResults and ipResult and hostsResults
Jon Hall8f89dda2015-01-22 16:03:33 -08001126 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
Jon Hall58c76b72015-02-23 11:09:24 -08001127 onpass="Topology Check Test successful",
1128 onfail="Topology Check Test NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001129
Jon Hall6aec96b2015-01-19 14:49:31 -08001130 def CASE6( self, main ):
1131 """
Jon Hallffb386d2014-11-21 13:43:38 -08001132 The Failure case.
Jon Hall6aec96b2015-01-19 14:49:31 -08001133 """
Jon Hallffb386d2014-11-21 13:43:38 -08001134 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001135 assert numControllers, "numControllers not defined"
1136 assert main, "main not defined"
1137 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall73cf9cc2014-11-20 22:28:38 -08001138
Jon Hall390696c2015-05-05 17:13:41 -07001139 # Reset non-persistent variables
1140 try:
1141 iCounterValue = 0
1142 except NameError:
1143 main.log.error( "iCounterValue not defined, setting to 0" )
1144 iCounterValue = 0
1145
Jon Hallfeff3082015-05-19 10:23:26 -07001146 main.case( "Restart ONOS node" )
1147 main.caseExplaination = "Killing ONOS process and restart cli " +\
1148 "sessions once onos is up."
Jon Hall390696c2015-05-05 17:13:41 -07001149 main.step( "Killing ONOS processes" )
1150 killResult = main.ONOSbench.onosKill( ONOS1Ip )
Jon Hallffb386d2014-11-21 13:43:38 -08001151 start = time.time()
Jon Hall390696c2015-05-05 17:13:41 -07001152 utilities.assert_equals( expect=main.TRUE, actual=killResult,
1153 onpass="ONOS Killed",
1154 onfail="Error killing ONOS" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001155
Jon Hall6aec96b2015-01-19 14:49:31 -08001156 main.step( "Checking if ONOS is up yet" )
Jon Hallffb386d2014-11-21 13:43:38 -08001157 count = 0
Jon Hall94fd0472014-12-08 11:52:42 -08001158 while count < 10:
Jon Hall8f89dda2015-01-22 16:03:33 -08001159 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
1160 if onos1Isup == main.TRUE:
Jon Hallffb386d2014-11-21 13:43:38 -08001161 elapsed = time.time() - start
1162 break
1163 else:
1164 count = count + 1
Jon Hall390696c2015-05-05 17:13:41 -07001165 utilities.assert_equals( expect=main.TRUE, actual=onos1Isup,
1166 onpass="ONOS is back up",
1167 onfail="ONOS failed to start" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001168
Jon Hall390696c2015-05-05 17:13:41 -07001169 main.log.step( "Starting ONOS CLI sessions" )
1170 cliResults = main.ONOScli1.startOnosCli( ONOS1Ip )
1171 utilities.assert_equals( expect=main.TRUE, actual=cliResults,
1172 onpass="ONOS cli startup successful",
1173 onfail="ONOS cli startup failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001174
Jon Hallfebb1c72015-03-05 13:30:09 -08001175 if elapsed:
1176 main.log.info( "ESTIMATE: ONOS took %s seconds to restart" %
1177 str( elapsed ) )
Jon Hall40d2cbd2015-06-03 16:24:29 -07001178 main.restartTime = elapsed
1179 else:
1180 main.restartTime = -1
Jon Hall6aec96b2015-01-19 14:49:31 -08001181 time.sleep( 5 )
Jon Hallfeff3082015-05-19 10:23:26 -07001182 # rerun on election apps
1183 main.ONOScli1.electionTestRun()
Jon Hall73cf9cc2014-11-20 22:28:38 -08001184
Jon Hall6aec96b2015-01-19 14:49:31 -08001185 def CASE7( self, main ):
1186 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001187 Check state after ONOS failure
Jon Hall6aec96b2015-01-19 14:49:31 -08001188 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001189 import json
Jon Hall5cfd23c2015-03-19 11:40:57 -07001190 assert numControllers, "numControllers not defined"
1191 assert main, "main not defined"
1192 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -08001193 main.case( "Running ONOS Constant State Tests" )
Jon Hall390696c2015-05-05 17:13:41 -07001194 main.step( "Check that each switch has a master" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001195 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -08001196 rolesNotNull = main.ONOScli1.rolesNotNull()
Jon Hall6aec96b2015-01-19 14:49:31 -08001197 utilities.assert_equals(
1198 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001199 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -08001200 onpass="Each device has a master",
1201 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -08001202
Jon Hall6aec96b2015-01-19 14:49:31 -08001203 main.step( "Check if switch roles are consistent across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001204 ONOS1Mastership = main.ONOScli1.roles()
Jon Hall6aec96b2015-01-19 14:49:31 -08001205 # FIXME: Refactor this whole case for single instance
Jon Hall8f89dda2015-01-22 16:03:33 -08001206 if "Error" in ONOS1Mastership or not ONOS1Mastership:
Jon Hall40d2cbd2015-06-03 16:24:29 -07001207 main.log.error( "Error in getting ONOS mastership" )
Jon Hall58c76b72015-02-23 11:09:24 -08001208 main.log.warn( "ONOS1 mastership response: " +
1209 repr( ONOS1Mastership ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001210 consistentMastership = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001211 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001212 consistentMastership = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001213 utilities.assert_equals(
1214 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001215 actual=consistentMastership,
Jon Hall6aec96b2015-01-19 14:49:31 -08001216 onpass="Switch roles are consistent across all ONOS nodes",
1217 onfail="ONOS nodes have different views of switch roles" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001218
1219 description2 = "Compare switch roles from before failure"
Jon Hall6aec96b2015-01-19 14:49:31 -08001220 main.step( description2 )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001221
Jon Hall8f89dda2015-01-22 16:03:33 -08001222 currentJson = json.loads( ONOS1Mastership )
1223 oldJson = json.loads( mastershipState )
1224 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001225 for i in range( 1, 29 ):
1226 switchDPID = str(
Jon Hall58c76b72015-02-23 11:09:24 -08001227 main.Mininet1.getSwitchDPID( switch="s" + str( i ) ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001228
Jon Hall8f89dda2015-01-22 16:03:33 -08001229 current = [ switch[ 'master' ] for switch in currentJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001230 if switchDPID in switch[ 'id' ] ]
Jon Hall8f89dda2015-01-22 16:03:33 -08001231 old = [ switch[ 'master' ] for switch in oldJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001232 if switchDPID in switch[ 'id' ] ]
Jon Hall73cf9cc2014-11-20 22:28:38 -08001233 if current == old:
Jon Hall8f89dda2015-01-22 16:03:33 -08001234 mastershipCheck = mastershipCheck and main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001235 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001236 main.log.warn( "Mastership of switch %s changed" % switchDPID )
Jon Hall8f89dda2015-01-22 16:03:33 -08001237 mastershipCheck = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001238 utilities.assert_equals(
1239 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001240 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -08001241 onpass="Mastership of Switches was not changed",
1242 onfail="Mastership of some switches changed" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001243 mastershipCheck = mastershipCheck and consistentMastership
Jon Hall73cf9cc2014-11-20 22:28:38 -08001244
Jon Hall6aec96b2015-01-19 14:49:31 -08001245 main.step( "Get the intents and compare across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001246 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
1247 intentCheck = main.FALSE
1248 if "Error" in ONOS1Intents or not ONOS1Intents:
Jon Hall40d2cbd2015-06-03 16:24:29 -07001249 main.log.error( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001250 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001251 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001252 intentCheck = main.TRUE
Jon Hall40d2cbd2015-06-03 16:24:29 -07001253 main.log.error( "Intents are consistent across all ONOS nodes" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001254 utilities.assert_equals(
1255 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001256 actual=intentCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -08001257 onpass="Intents are consistent across all ONOS nodes",
1258 onfail="ONOS nodes have different views of intents" )
Jon Hall1b8f54a2015-02-04 13:24:20 -08001259 # Print the intent states
1260 intents = []
1261 intents.append( ONOS1Intents )
1262 intentStates = []
1263 for node in intents: # Iter through ONOS nodes
1264 nodeStates = []
Jon Hall58c76b72015-02-23 11:09:24 -08001265 # Iter through intents of a node
1266 for intent in json.loads( node ):
Jon Hall1b8f54a2015-02-04 13:24:20 -08001267 nodeStates.append( intent[ 'state' ] )
1268 intentStates.append( nodeStates )
1269 out = [ (i, nodeStates.count( i ) ) for i in set( nodeStates ) ]
1270 main.log.info( dict( out ) )
1271
Jon Hall58c76b72015-02-23 11:09:24 -08001272 # NOTE: Store has no durability, so intents are lost across system
1273 # restarts
Jon Hall6aec96b2015-01-19 14:49:31 -08001274 """
1275 main.step( "Compare current intents with intents before the failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001276 # NOTE: this requires case 5 to pass for intentState to be set.
Jon Hall6aec96b2015-01-19 14:49:31 -08001277 # maybe we should stop the test if that fails?
Jon Hall40d2cbd2015-06-03 16:24:29 -07001278 sameIntents = main.FALSE
1279 if intentState and intentState == ONOSIntents[ 0 ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001280 sameIntents = main.TRUE
Jon Hallfeff3082015-05-19 10:23:26 -07001281 main.log.info( "Intents are consistent with before failure" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001282 # TODO: possibly the states have changed? we may need to figure out
Jon Hallfeff3082015-05-19 10:23:26 -07001283 # what the acceptable states are
Jon Hall40d2cbd2015-06-03 16:24:29 -07001284 elif len( intentState ) == len( ONOSIntents[ 0 ] ):
1285 sameIntents = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001286 try:
Jon Hall40d2cbd2015-06-03 16:24:29 -07001287 before = json.loads( intentState )
1288 after = json.loads( ONOSIntents[ 0 ] )
1289 for intent in before:
1290 if intent not in after:
1291 sameIntents = main.FALSE
Jon Hallc9eabec2015-06-10 14:33:14 -07001292 main.log.debug( "Intent is not currently in ONOS " +
Jon Hall40d2cbd2015-06-03 16:24:29 -07001293 "(at least in the same form):" )
1294 main.log.debug( json.dumps( intent ) )
1295 except ( ValueError, TypeError ):
1296 main.log.exception( "Exception printing intents" )
1297 main.log.debug( repr( ONOSIntents[0] ) )
1298 main.log.debug( repr( intentState ) )
1299 if sameIntents == main.FALSE:
1300 try:
1301 main.log.debug( "ONOS intents before: " )
1302 main.log.debug( json.dumps( json.loads( intentState ),
1303 sort_keys=True, indent=4,
1304 separators=( ',', ': ' ) ) )
1305 main.log.debug( "Current ONOS intents: " )
1306 main.log.debug( json.dumps( json.loads( ONOSIntents[ 0 ] ),
1307 sort_keys=True, indent=4,
1308 separators=( ',', ': ' ) ) )
1309 except ( ValueError, TypeError ):
1310 main.log.exception( "Exception printing intents" )
1311 main.log.debug( repr( ONOSIntents[0] ) )
1312 main.log.debug( repr( intentState ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001313 utilities.assert_equals(
1314 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001315 actual=sameIntents,
Jon Hall6aec96b2015-01-19 14:49:31 -08001316 onpass="Intents are consistent with before failure",
1317 onfail="The Intents changed during failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001318 intentCheck = intentCheck and sameIntents
Jon Hall6aec96b2015-01-19 14:49:31 -08001319 """
1320 main.step( "Get the OF Table entries and compare to before " +
1321 "component failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001322 FlowTables = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001323 flows2 = []
1324 for i in range( 28 ):
1325 main.log.info( "Checking flow table on s" + str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001326 tmpFlows = main.Mininet2.getFlowTable( 1.3, "s" + str( i + 1 ) )
1327 flows2.append( tmpFlows )
1328 tempResult = main.Mininet2.flowComp(
Jon Hall6aec96b2015-01-19 14:49:31 -08001329 flow1=flows[ i ],
Jon Hall8f89dda2015-01-22 16:03:33 -08001330 flow2=tmpFlows )
1331 FlowTables = FlowTables and tempResult
1332 if FlowTables == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001333 main.log.info( "Differences in flow table for switch: s" +
1334 str( i + 1 ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001335 utilities.assert_equals(
1336 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001337 actual=FlowTables,
Jon Hall6aec96b2015-01-19 14:49:31 -08001338 onpass="No changes were found in the flow tables",
1339 onfail="Changes were found in the flow tables" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001340
Jon Hallfeff3082015-05-19 10:23:26 -07001341 main.step( "Leadership Election is still functional" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001342 # Test of LeadershipElection
Jon Hall669173b2014-12-17 11:36:30 -08001343
Jon Hall8f89dda2015-01-22 16:03:33 -08001344 leader = ONOS1Ip
1345 leaderResult = main.TRUE
1346 for controller in range( 1, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001347 # loop through ONOScli handlers
1348 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001349 leaderN = node.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001350 # verify leader is ONOS1
1351 # NOTE even though we restarted ONOS, it is the only one so onos 1
1352 # must be leader
Jon Hall669173b2014-12-17 11:36:30 -08001353 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08001354 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001355 pass
1356 elif leaderN == main.FALSE:
Jon Hallfeff3082015-05-19 10:23:26 -07001357 # error in response
Jon Hall40d2cbd2015-06-03 16:24:29 -07001358 main.log.error( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001359 "electionTestLeader function, check the" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001360 " error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001361 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001362 elif leader != leaderN:
Jon Hall8f89dda2015-01-22 16:03:33 -08001363 leaderResult = main.FALSE
Jon Hall40d2cbd2015-06-03 16:24:29 -07001364 main.log.error( "ONOS" + str( controller ) + " sees " +
Jon Hall58c76b72015-02-23 11:09:24 -08001365 str( leaderN ) +
1366 " as the leader of the election app. " +
1367 "Leader should be " + str( leader ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001368 utilities.assert_equals(
1369 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001370 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001371 onpass="Leadership election passed",
1372 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08001373
Jon Hall6aec96b2015-01-19 14:49:31 -08001374 def CASE8( self, main ):
1375 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001376 Compare topo
Jon Hall6aec96b2015-01-19 14:49:31 -08001377 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001378 import sys
Jon Hall6aec96b2015-01-19 14:49:31 -08001379 # FIXME add this path to params
1380 sys.path.append( "/home/admin/sts" )
1381 # assumes that sts is already in you PYTHONPATH
1382 from sts.topology.teston_topology import TestONTopology
Jon Hall73cf9cc2014-11-20 22:28:38 -08001383 import json
1384 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001385 assert numControllers, "numControllers not defined"
1386 assert main, "main not defined"
1387 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall73cf9cc2014-11-20 22:28:38 -08001388
Jon Hallfeff3082015-05-19 10:23:26 -07001389 main.case( "Compare ONOS Topology view to Mininet topology" )
1390 main.caseExplaination = "Compare topology objects between Mininet" +\
1391 " and ONOS"
Jon Hall6aec96b2015-01-19 14:49:31 -08001392 main.step( "Create TestONTopology object" )
Jon Hallfeff3082015-05-19 10:23:26 -07001393 try:
1394 ctrls = []
1395 node = main.ONOS1
1396 temp = ( node, node.name, node.ip_address, 6633 )
1397 ctrls.append( temp )
1398 MNTopo = TestONTopology( main.Mininet1, ctrls )
1399 except Exception:
1400 objResult = main.FALSE
1401 else:
1402 objResult = main.TRUE
1403 utilities.assert_equals( expect=main.TRUE, actual=objResult,
1404 onpass="Created TestONTopology object",
1405 onfail="Exception while creating " +
1406 "TestONTopology object" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001407
Jon Hall6aec96b2015-01-19 14:49:31 -08001408 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001409 devicesResults = main.TRUE
1410 portsResults = main.TRUE
1411 linksResults = main.TRUE
Jon Hall58c76b72015-02-23 11:09:24 -08001412 hostsResults = main.TRUE
Jon Hall8f89dda2015-01-22 16:03:33 -08001413 topoResult = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001414 elapsed = 0
Jon Hallffb386d2014-11-21 13:43:38 -08001415 count = 0
Jon Hall6aec96b2015-01-19 14:49:31 -08001416 main.step( "Collecting topology information from ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001417 startTime = time.time()
Jon Hall58c76b72015-02-23 11:09:24 -08001418 # Give time for Gossip to work
Jon Hall8f89dda2015-01-22 16:03:33 -08001419 while topoResult == main.FALSE and elapsed < 60:
Jon Halla9d26da2015-03-30 16:45:32 -07001420 count += 1
Jon Hall94fd0472014-12-08 11:52:42 -08001421 if count > 1:
Jon Halla9d26da2015-03-30 16:45:32 -07001422 # TODO: Deprecate STS usage
Jon Hall58c76b72015-02-23 11:09:24 -08001423 MNTopo = TestONTopology( main.Mininet1, ctrls )
Jon Hall8f89dda2015-01-22 16:03:33 -08001424 cliStart = time.time()
Jon Hall94fd0472014-12-08 11:52:42 -08001425 devices = []
1426 devices.append( main.ONOScli1.devices() )
Jon Hall94fd0472014-12-08 11:52:42 -08001427 hosts = []
Jon Hall58c76b72015-02-23 11:09:24 -08001428 hosts.append( json.loads( main.ONOScli1.hosts() ) )
1429 ipResult = main.TRUE
1430 for controller in range( 0, len( hosts ) ):
1431 controllerStr = str( controller + 1 )
1432 for host in hosts[ controller ]:
Jon Hallfeff3082015-05-19 10:23:26 -07001433 if host is None or host.get( 'ipAddresses', [] ) == []:
Jon Hall58c76b72015-02-23 11:09:24 -08001434 main.log.error(
1435 "DEBUG:Error with host ips on controller" +
1436 controllerStr + ": " + str( host ) )
1437 ipResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001438 ports = []
1439 ports.append( main.ONOScli1.ports() )
1440 links = []
1441 links.append( main.ONOScli1.links() )
Jon Hall58c76b72015-02-23 11:09:24 -08001442 clusters = []
1443 clusters.append( main.ONOScli1.clusters() )
1444
Jon Hall8f89dda2015-01-22 16:03:33 -08001445 elapsed = time.time() - startTime
1446 cliTime = time.time() - cliStart
1447 print "CLI time: " + str( cliTime )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001448
Jon Hall8f89dda2015-01-22 16:03:33 -08001449 for controller in range( numControllers ):
1450 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001451 if devices[ controller ] or "Error" not in devices[
1452 controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001453 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -08001454 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001455 json.loads( devices[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001456 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001457 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001458 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001459 actual=currentDevicesResult,
1460 onpass="ONOS" + controllerStr +
1461 " Switches view is correct",
1462 onfail="ONOS" + controllerStr +
1463 " Switches view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001464
Jon Hall6aec96b2015-01-19 14:49:31 -08001465 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001466 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -08001467 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001468 json.loads( ports[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001469 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001470 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001471 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001472 actual=currentPortsResult,
1473 onpass="ONOS" + controllerStr +
1474 " ports view is correct",
1475 onfail="ONOS" + controllerStr +
1476 " ports view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001477
Jon Hall6aec96b2015-01-19 14:49:31 -08001478 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001479 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -08001480 MNTopo,
Jon Hall58c76b72015-02-23 11:09:24 -08001481 json.loads( links[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001482 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001483 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001484 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001485 actual=currentLinksResult,
1486 onpass="ONOS" + controllerStr +
1487 " links view is correct",
1488 onfail="ONOS" + controllerStr +
1489 " links view is incorrect" )
1490
1491 if hosts[ controller ] or "Error" not in hosts[ controller ]:
1492 currentHostsResult = main.Mininet1.compareHosts(
1493 MNTopo, hosts[ controller ] )
1494 else:
1495 currentHostsResult = main.FALSE
1496 utilities.assert_equals( expect=main.TRUE,
1497 actual=currentHostsResult,
1498 onpass="ONOS" + controllerStr +
1499 " hosts exist in Mininet",
1500 onfail="ONOS" + controllerStr +
1501 " hosts don't match Mininet" )
1502
1503 devicesResults = devicesResults and currentDevicesResult
1504 portsResults = portsResults and currentPortsResult
1505 linksResults = linksResults and currentLinksResult
1506 hostsResults = hostsResults and currentHostsResult
1507
Jon Hall63604932015-02-26 17:09:50 -08001508 # "consistent" results don't make sense for single instance
Jon Hall58c76b72015-02-23 11:09:24 -08001509 # there should always only be one cluster
1510 numClusters = len( json.loads( clusters[ 0 ] ) )
1511 clusterResults = main.FALSE
1512 if numClusters == 1:
1513 clusterResults = main.TRUE
1514 utilities.assert_equals(
1515 expect=1,
1516 actual=numClusters,
1517 onpass="ONOS shows 1 SCC",
1518 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
1519
1520 topoResult = ( devicesResults and portsResults and linksResults
1521 and hostsResults and ipResult and clusterResults )
Jon Hall94fd0472014-12-08 11:52:42 -08001522
Jon Hall8f89dda2015-01-22 16:03:33 -08001523 topoResult = topoResult and int( count <= 2 )
1524 note = "note it takes about " + str( int( cliTime ) ) + \
1525 " seconds for the test to make all the cli calls to fetch " +\
1526 "the topology from each ONOS instance"
Jon Hall1b8f54a2015-02-04 13:24:20 -08001527 main.log.info(
Jon Hall8f89dda2015-01-22 16:03:33 -08001528 "Very crass estimate for topology discovery/convergence( " +
1529 str( note ) + " ): " + str( elapsed ) + " seconds, " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001530 str( count ) + " tries" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001531 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
Jon Hall58c76b72015-02-23 11:09:24 -08001532 onpass="Topology Check Test successful",
1533 onfail="Topology Check Test NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001534
Jon Hall6aec96b2015-01-19 14:49:31 -08001535 def CASE9( self, main ):
1536 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001537 Link s3-s28 down
Jon Hall6aec96b2015-01-19 14:49:31 -08001538 """
1539 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001540 assert numControllers, "numControllers not defined"
1541 assert main, "main not defined"
1542 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -08001543 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001544
Jon Hall8f89dda2015-01-22 16:03:33 -08001545 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001546
Jon Hall6aec96b2015-01-19 14:49:31 -08001547 description = "Turn off a link to ensure that Link Discovery " +\
Jon Hall58c76b72015-02-23 11:09:24 -08001548 "is working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001549 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001550
Jon Hall6aec96b2015-01-19 14:49:31 -08001551 main.step( "Kill Link between s3 and s28" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001552 LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" )
Jon Hall58c76b72015-02-23 11:09:24 -08001553 main.log.info( "Waiting " + str( linkSleep ) +
1554 " seconds for link down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001555 time.sleep( linkSleep )
1556 utilities.assert_equals( expect=main.TRUE, actual=LinkDown,
Jon Halla9d26da2015-03-30 16:45:32 -07001557 onpass="Link down successful",
Jon Hall58c76b72015-02-23 11:09:24 -08001558 onfail="Failed to bring link down" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001559 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -08001560
Jon Hall6aec96b2015-01-19 14:49:31 -08001561 def CASE10( self, main ):
1562 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001563 Link s3-s28 up
Jon Hall6aec96b2015-01-19 14:49:31 -08001564 """
1565 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001566 assert numControllers, "numControllers not defined"
1567 assert main, "main not defined"
1568 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -08001569 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001570
Jon Hall8f89dda2015-01-22 16:03:33 -08001571 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001572
Jon Hall6aec96b2015-01-19 14:49:31 -08001573 description = "Restore a link to ensure that Link Discovery is " + \
Jon Hall58c76b72015-02-23 11:09:24 -08001574 "working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001575 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001576
Jon Hall6aec96b2015-01-19 14:49:31 -08001577 main.step( "Bring link between s3 and s28 back up" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001578 LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" )
Jon Hall58c76b72015-02-23 11:09:24 -08001579 main.log.info( "Waiting " + str( linkSleep ) +
1580 " seconds for link up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001581 time.sleep( linkSleep )
1582 utilities.assert_equals( expect=main.TRUE, actual=LinkUp,
Jon Halla9d26da2015-03-30 16:45:32 -07001583 onpass="Link up successful",
Jon Hall58c76b72015-02-23 11:09:24 -08001584 onfail="Failed to bring link up" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001585 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -08001586
Jon Hall6aec96b2015-01-19 14:49:31 -08001587 def CASE11( self, main ):
1588 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001589 Switch Down
Jon Hall6aec96b2015-01-19 14:49:31 -08001590 """
1591 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001592 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001593 assert numControllers, "numControllers not defined"
1594 assert main, "main not defined"
1595 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall73cf9cc2014-11-20 22:28:38 -08001596
Jon Hall8f89dda2015-01-22 16:03:33 -08001597 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001598
1599 description = "Killing a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001600 main.case( description )
1601 switch = main.params[ 'kill' ][ 'switch' ]
1602 switchDPID = main.params[ 'kill' ][ 'dpid' ]
Jon Hall73cf9cc2014-11-20 22:28:38 -08001603
Jon Hall6aec96b2015-01-19 14:49:31 -08001604 # TODO: Make this switch parameterizable
1605 main.step( "Kill " + switch )
Jon Hall40d2cbd2015-06-03 16:24:29 -07001606 main.log.info( "Deleting " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001607 main.Mininet1.delSwitch( switch )
1608 main.log.info( "Waiting " + str( switchSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001609 " seconds for switch down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001610 time.sleep( switchSleep )
1611 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001612 # Peek at the deleted switch
1613 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001614 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001615 if device and device[ 'available' ] is False:
Jon Hall94fd0472014-12-08 11:52:42 -08001616 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001617 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Halla9d26da2015-03-30 16:45:32 -07001618 onpass="Kill switch successful",
Jon Hall58c76b72015-02-23 11:09:24 -08001619 onfail="Failed to kill switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001620
Jon Hall6aec96b2015-01-19 14:49:31 -08001621 def CASE12( self, main ):
1622 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001623 Switch Up
Jon Hall6aec96b2015-01-19 14:49:31 -08001624 """
1625 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001626 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001627 assert numControllers, "numControllers not defined"
1628 assert main, "main not defined"
1629 assert utilities.assert_equals, "utilities.assert_equals not defined"
1630 assert ONOS1Port, "ONOS1Port not defined"
1631 assert ONOS2Port, "ONOS2Port not defined"
1632 assert ONOS3Port, "ONOS3Port not defined"
1633 assert ONOS4Port, "ONOS4Port not defined"
1634 assert ONOS5Port, "ONOS5Port not defined"
1635 assert ONOS6Port, "ONOS6Port not defined"
1636 assert ONOS7Port, "ONOS7Port not defined"
Jon Hall669173b2014-12-17 11:36:30 -08001637
Jon Hall8f89dda2015-01-22 16:03:33 -08001638 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall6aec96b2015-01-19 14:49:31 -08001639 switch = main.params[ 'kill' ][ 'switch' ]
1640 switchDPID = main.params[ 'kill' ][ 'dpid' ]
1641 links = main.params[ 'kill' ][ 'links' ].split()
Jon Hall73cf9cc2014-11-20 22:28:38 -08001642 description = "Adding a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001643 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001644
Jon Hall6aec96b2015-01-19 14:49:31 -08001645 main.step( "Add back " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001646 main.Mininet1.addSwitch( switch, dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001647 for peer in links:
Jon Hall8f89dda2015-01-22 16:03:33 -08001648 main.Mininet1.addLink( switch, peer )
1649 main.Mininet1.assignSwController( sw=switch.split( 's' )[ 1 ],
Jon Hall58c76b72015-02-23 11:09:24 -08001650 ip1=ONOS1Ip,
1651 port1=ONOS1Port )
1652 main.log.info( "Waiting " + str( switchSleep ) +
1653 " seconds for switch up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001654 time.sleep( switchSleep )
1655 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001656 # Peek at the deleted switch
1657 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001658 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001659 if device and device[ 'available' ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001660 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001661 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Halla9d26da2015-03-30 16:45:32 -07001662 onpass="add switch successful",
Jon Hall58c76b72015-02-23 11:09:24 -08001663 onfail="Failed to add switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001664
Jon Hall6aec96b2015-01-19 14:49:31 -08001665 def CASE13( self, main ):
1666 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001667 Clean up
Jon Hall6aec96b2015-01-19 14:49:31 -08001668 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001669 import os
1670 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001671 assert numControllers, "numControllers not defined"
1672 assert main, "main not defined"
1673 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -08001674 # printing colors to terminal
Jon Halla9d26da2015-03-30 16:45:32 -07001675 colors = { 'cyan': '\033[96m', 'purple': '\033[95m',
1676 'blue': '\033[94m', 'green': '\033[92m',
1677 'yellow': '\033[93m', 'red': '\033[91m', 'end': '\033[0m' }
Jon Hall40d2cbd2015-06-03 16:24:29 -07001678 main.case( "Test Cleanup" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001679 main.step( "Killing tcpdumps" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001680 main.Mininet2.stopTcpdump()
Jon Hall73cf9cc2014-11-20 22:28:38 -08001681
Jon Hall6aec96b2015-01-19 14:49:31 -08001682 main.step( "Copying MN pcap and ONOS log files to test station" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001683 testname = main.TEST
Jon Hall8f89dda2015-01-22 16:03:33 -08001684 teststationUser = main.params[ 'TESTONUSER' ]
1685 teststationIP = main.params[ 'TESTONIP' ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001686 # NOTE: MN Pcap file is being saved to ~/packet_captures
Jon Hall73cf9cc2014-11-20 22:28:38 -08001687 # scp this file as MN and TestON aren't necessarily the same vm
Jon Hall6aec96b2015-01-19 14:49:31 -08001688 # FIXME: scp
1689 # mn files
1690 # TODO: Load these from params
1691 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001692 logFolder = "/opt/onos/log/"
1693 logFiles = [ "karaf.log", "karaf.log.1" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001694 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001695 dstDir = "~/packet_captures/"
1696 for f in logFiles:
1697 main.ONOSbench.handle.sendline( "scp sdn@" + ONOS1Ip + ":" +
1698 logFolder + f + " " +
1699 teststationUser + "@" +
1700 teststationIP + ":" + dstDir +
Jon Hall6aec96b2015-01-19 14:49:31 -08001701 str( testname ) + "-ONOS1-" + f )
1702 main.ONOSbench.handle.expect( "\$" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001703
Jon Hall6aec96b2015-01-19 14:49:31 -08001704 # std*.log's
1705 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001706 logFolder = "/opt/onos/var/"
1707 logFiles = [ "stderr.log", "stdout.log" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001708 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001709 dstDir = "~/packet_captures/"
1710 for f in logFiles:
1711 main.ONOSbench.handle.sendline( "scp sdn@" + ONOS1Ip + ":" +
1712 logFolder + f + " " +
1713 teststationUser + "@" +
1714 teststationIP + ":" + dstDir +
Jon Hall6aec96b2015-01-19 14:49:31 -08001715 str( testname ) + "-ONOS1-" + f )
Jon Hall58c76b72015-02-23 11:09:24 -08001716 main.ONOSbench.handle.expect( "\$" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001717 # sleep so scp can finish
1718 time.sleep( 10 )
Jon Halla9d26da2015-03-30 16:45:32 -07001719
1720 main.step( "Stopping Mininet" )
Jon Hall390696c2015-05-05 17:13:41 -07001721 mnResult = main.Mininet1.stopNet()
1722 utilities.assert_equals( expect=main.TRUE, actual=mnResult,
1723 onpass="Mininet stopped",
1724 onfail="MN cleanup NOT successful" )
Jon Halla9d26da2015-03-30 16:45:32 -07001725
1726 main.step( "Checking ONOS Logs for errors" )
1727 print colors[ 'purple' ] + "Checking logs for errors on ONOS1:" + \
1728 colors[ 'end' ]
Jon Hall40d2cbd2015-06-03 16:24:29 -07001729 print main.ONOSbench.checkLogs( ONOS1Ip, restart=True )
Jon Halla9d26da2015-03-30 16:45:32 -07001730
Jon Hall6aec96b2015-01-19 14:49:31 -08001731 main.step( "Packing and rotating pcap archives" )
1732 os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001733
Jon Hall40d2cbd2015-06-03 16:24:29 -07001734 try:
1735 timerLog = open( main.logdir + "/Timers.csv", 'w')
1736 # Overwrite with empty line and close
1737 labels = "Gossip Intents, Restart"
1738 data = str( gossipTime ) + ", " + str( main.restartTime )
1739 timerLog.write( labels + "\n" + data )
1740 timerLog.close()
1741 except NameError, e:
1742 main.log.exception(e)
1743
Jon Hall6aec96b2015-01-19 14:49:31 -08001744 def CASE14( self, main ):
1745 """
Jon Hall669173b2014-12-17 11:36:30 -08001746 start election app on all onos nodes
Jon Hall6aec96b2015-01-19 14:49:31 -08001747 """
Jon Hall5cfd23c2015-03-19 11:40:57 -07001748 assert numControllers, "numControllers not defined"
1749 assert main, "main not defined"
1750 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halla9d26da2015-03-30 16:45:32 -07001751
Jon Hall390696c2015-05-05 17:13:41 -07001752 main.case("Start Leadership Election app")
1753 main.step( "Install leadership election app" )
Jon Hallfeff3082015-05-19 10:23:26 -07001754 appResult = main.ONOScli1.activateApp( "org.onosproject.election" )
1755 utilities.assert_equals(
1756 expect=main.TRUE,
1757 actual=appResult,
1758 onpass="Election app installed",
1759 onfail="Something went wrong with installing Leadership election" )
1760
1761 main.step( "Run for election on each node" )
1762 leaderResult = main.ONOScli1.electionTestRun()
Jon Hall6aec96b2015-01-19 14:49:31 -08001763 # check for leader
Jon Hall8f89dda2015-01-22 16:03:33 -08001764 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001765 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08001766 if leader == ONOS1Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08001767 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001768 pass
Jon Hall6aec96b2015-01-19 14:49:31 -08001769 elif leader is None:
1770 # No leader elected
Jon Hallfeff3082015-05-19 10:23:26 -07001771 main.log.error( "No leader was elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001772 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001773 elif leader == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001774 # error in response
1775 # TODO: add check for "Command not found:" in the driver, this
1776 # means the app isn't loaded
Jon Hallfeff3082015-05-19 10:23:26 -07001777 main.log.error( "Something is wrong with electionTestLeader" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001778 " function, check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001779 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001780 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001781 # error in response
Jon Hallfeff3082015-05-19 10:23:26 -07001782 main.log.error(
Jon Hall8f89dda2015-01-22 16:03:33 -08001783 "Unexpected response from electionTestLeader function:'" +
1784 str( leader ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001785 "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001786 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001787 utilities.assert_equals(
1788 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001789 actual=leaderResult,
Jon Hallfeff3082015-05-19 10:23:26 -07001790 onpass="Successfully ran for leadership",
1791 onfail="Failed to run for leadership" )
Jon Hall669173b2014-12-17 11:36:30 -08001792
Jon Hall6aec96b2015-01-19 14:49:31 -08001793 def CASE15( self, main ):
1794 """
Jon Hall669173b2014-12-17 11:36:30 -08001795 Check that Leadership Election is still functional
Jon Hall6aec96b2015-01-19 14:49:31 -08001796 """
Jon Hall5cfd23c2015-03-19 11:40:57 -07001797 assert numControllers, "numControllers not defined"
1798 assert main, "main not defined"
1799 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall8f89dda2015-01-22 16:03:33 -08001800 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08001801 description = "Check that Leadership Election is still functional"
Jon Hall6aec96b2015-01-19 14:49:31 -08001802 main.case( description )
1803 main.step( "Find current leader and withdraw" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001804 leader = main.ONOScli1.electionTestLeader()
Jon Halla9d26da2015-03-30 16:45:32 -07001805 # do some sanity checking on leader before using it
Jon Hall8f89dda2015-01-22 16:03:33 -08001806 withdrawResult = main.FALSE
1807 if leader == ONOS1Ip:
1808 oldLeader = getattr( main, "ONOScli1" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001809 elif leader is None or leader == main.FALSE:
Jon Hall40d2cbd2015-06-03 16:24:29 -07001810 main.log.error(
Jon Hall6aec96b2015-01-19 14:49:31 -08001811 "Leader for the election app should be an ONOS node," +
Jon Hall58c76b72015-02-23 11:09:24 -08001812 "instead got '" + str( leader ) + "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001813 leaderResult = main.FALSE
Jon Hall63604932015-02-26 17:09:50 -08001814 oldLeader = None
1815 else:
1816 main.log.error( "Leader election --- why am I HERE?!?")
Jon Hallfeff3082015-05-19 10:23:26 -07001817 leaderResult = main.FALSE
1818 oldLeader = None
Jon Hall63604932015-02-26 17:09:50 -08001819 if oldLeader:
1820 withdrawResult = oldLeader.electionTestWithdraw()
Jon Hall6aec96b2015-01-19 14:49:31 -08001821 utilities.assert_equals(
1822 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001823 actual=withdrawResult,
Jon Hallfeff3082015-05-19 10:23:26 -07001824 onpass="Node was withdrawn from election",
1825 onfail="Node was not withdrawn from election" )
Jon Hall669173b2014-12-17 11:36:30 -08001826
Jon Hall6aec96b2015-01-19 14:49:31 -08001827 main.step( "Make sure new leader is elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001828 leaderN = main.ONOScli1.electionTestLeader()
Jon Hall669173b2014-12-17 11:36:30 -08001829 if leaderN == leader:
Jon Hall40d2cbd2015-06-03 16:24:29 -07001830 main.log.error( "ONOS still sees " + str( leaderN ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001831 " as leader after they withdrew" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001832 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001833 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001834 # error in response
1835 # TODO: add check for "Command not found:" in the driver, this
1836 # means the app isn't loaded
Jon Hall40d2cbd2015-06-03 16:24:29 -07001837 main.log.error( "Something is wrong with electionTestLeader " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001838 "function, check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001839 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001840 elif leaderN is None:
1841 main.log.info(
1842 "There is no leader after the app withdrew from election" )
Jon Hallfeff3082015-05-19 10:23:26 -07001843 leaderResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001844 utilities.assert_equals(
1845 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001846 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001847 onpass="Leadership election passed",
1848 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08001849
Jon Hall58c76b72015-02-23 11:09:24 -08001850 main.step( "Run for election on old leader( just so everyone " +
1851 "is in the hat )" )
Jon Hall63604932015-02-26 17:09:50 -08001852 if oldLeader:
1853 runResult = oldLeader.electionTestRun()
1854 else:
1855 runResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001856 utilities.assert_equals(
1857 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001858 actual=runResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001859 onpass="App re-ran for election",
1860 onfail="App failed to run for election" )
Jon Hallfeff3082015-05-19 10:23:26 -07001861
1862 main.step( "Node became leader when it ran for election" )
1863 afterRun = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001864 # verify leader is ONOS1
Jon Hallfeff3082015-05-19 10:23:26 -07001865 if afterRun == ONOS1Ip:
1866 afterResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08001867 else:
Jon Hallfeff3082015-05-19 10:23:26 -07001868 afterResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001869
Jon Hall6aec96b2015-01-19 14:49:31 -08001870 utilities.assert_equals(
1871 expect=main.TRUE,
Jon Hallfeff3082015-05-19 10:23:26 -07001872 actual=afterResult,
1873 onpass="Old leader successfully re-ran for election",
1874 onfail="Something went wrong with Leadership election after " +
1875 "the old leader re-ran for election" )
Jon Hall390696c2015-05-05 17:13:41 -07001876
1877 def CASE16( self, main ):
1878 """
1879 Install Distributed Primitives app
1880 """
1881 assert numControllers, "numControllers not defined"
1882 assert main, "main not defined"
1883 assert utilities.assert_equals, "utilities.assert_equals not defined"
1884 assert CLIs, "CLIs not defined"
1885 assert nodes, "nodes not defined"
1886
1887 # Variables for the distributed primitives tests
1888 global pCounterName
1889 global iCounterName
1890 global pCounterValue
1891 global iCounterValue
1892 global onosSet
1893 global onosSetName
1894 pCounterName = "TestON-Partitions"
1895 iCounterName = "TestON-inMemory"
1896 pCounterValue = 0
1897 iCounterValue = 0
1898 onosSet = set([])
1899 onosSetName = "TestON-set"
1900
1901 description = "Install Primitives app"
1902 main.case( description )
1903 main.step( "Install Primitives app" )
1904 appName = "org.onosproject.distributedprimitives"
1905 appResults = CLIs[0].activateApp( appName )
1906 utilities.assert_equals( expect=main.TRUE,
1907 actual=appResults,
1908 onpass="Primitives app activated",
1909 onfail="Primitives app not activated" )
1910
1911 def CASE17( self, main ):
1912 """
1913 Check for basic functionality with distributed primitives
1914 """
Jon Hall40d2cbd2015-06-03 16:24:29 -07001915 import json
Jon Hall390696c2015-05-05 17:13:41 -07001916 # Make sure variables are defined/set
1917 assert numControllers, "numControllers not defined"
1918 assert main, "main not defined"
1919 assert utilities.assert_equals, "utilities.assert_equals not defined"
1920 assert CLIs, "CLIs not defined"
1921 assert nodes, "nodes not defined"
1922 assert pCounterName, "pCounterName not defined"
1923 assert iCounterName, "iCounterName not defined"
1924 assert onosSetName, "onosSetName not defined"
1925 # NOTE: assert fails if value is 0/None/Empty/False
1926 try:
1927 pCounterValue
1928 except NameError:
1929 main.log.error( "pCounterValue not defined, setting to 0" )
1930 pCounterValue = 0
1931 try:
1932 iCounterValue
1933 except NameError:
1934 main.log.error( "iCounterValue not defined, setting to 0" )
1935 iCounterValue = 0
1936 try:
1937 onosSet
1938 except NameError:
1939 main.log.error( "onosSet not defined, setting to empty Set" )
1940 onosSet = set([])
1941 # Variables for the distributed primitives tests. These are local only
1942 addValue = "a"
1943 addAllValue = "a b c d e f"
1944 retainValue = "c d e f"
1945
1946 description = "Check for basic functionality with distributed " +\
1947 "primitives"
1948 main.case( description )
1949 main.caseExplaination = "Test the methods of the distributed primitives (counters and sets) throught the cli"
1950 # DISTRIBUTED ATOMIC COUNTERS
1951 main.step( "Increment and get a default counter on each node" )
1952 pCounters = []
1953 threads = []
Jon Hallfeff3082015-05-19 10:23:26 -07001954 addedPValues = []
Jon Hall390696c2015-05-05 17:13:41 -07001955 for i in range( numControllers ):
1956 t = main.Thread( target=CLIs[i].counterTestIncrement,
1957 name="counterIncrement-" + str( i ),
1958 args=[ pCounterName ] )
1959 pCounterValue += 1
Jon Hallfeff3082015-05-19 10:23:26 -07001960 addedPValues.append( pCounterValue )
Jon Hall390696c2015-05-05 17:13:41 -07001961 threads.append( t )
1962 t.start()
1963
1964 for t in threads:
1965 t.join()
1966 pCounters.append( t.result )
1967 # Check that counter incremented numController times
1968 pCounterResults = True
Jon Hallfeff3082015-05-19 10:23:26 -07001969 for i in addedPValues:
Jon Hall40d2cbd2015-06-03 16:24:29 -07001970 tmpResult = i in pCounters
Jon Hallfeff3082015-05-19 10:23:26 -07001971 pCounterResults = pCounterResults and tmpResult
1972 if not tmpResult:
1973 main.log.error( str( i ) + " is not in partitioned "
1974 "counter incremented results" )
Jon Hall390696c2015-05-05 17:13:41 -07001975 utilities.assert_equals( expect=True,
1976 actual=pCounterResults,
1977 onpass="Default counter incremented",
1978 onfail="Error incrementing default" +
1979 " counter" )
1980
1981 main.step( "Increment and get an in memory counter on each node" )
1982 iCounters = []
Jon Hallfeff3082015-05-19 10:23:26 -07001983 addedIValues = []
Jon Hall390696c2015-05-05 17:13:41 -07001984 threads = []
1985 for i in range( numControllers ):
1986 t = main.Thread( target=CLIs[i].counterTestIncrement,
1987 name="icounterIncrement-" + str( i ),
1988 args=[ iCounterName ],
1989 kwargs={ "inMemory": True } )
1990 iCounterValue += 1
Jon Hallfeff3082015-05-19 10:23:26 -07001991 addedIValues.append( iCounterValue )
Jon Hall390696c2015-05-05 17:13:41 -07001992 threads.append( t )
1993 t.start()
1994
1995 for t in threads:
1996 t.join()
1997 iCounters.append( t.result )
1998 # Check that counter incremented numController times
1999 iCounterResults = True
Jon Hallfeff3082015-05-19 10:23:26 -07002000 for i in addedIValues:
2001 tmpResult = i in iCounters
2002 iCounterResults = iCounterResults and tmpResult
2003 if not tmpResult:
2004 main.log.error( str( i ) + " is not in the in-memory "
2005 "counter incremented results" )
Jon Hall390696c2015-05-05 17:13:41 -07002006 utilities.assert_equals( expect=True,
2007 actual=iCounterResults,
2008 onpass="In memory counter incremented",
2009 onfail="Error incrementing in memory" +
2010 " counter" )
2011
2012 main.step( "Check counters are consistant across nodes" )
2013 onosCounters = []
2014 threads = []
2015 for i in range( numControllers ):
2016 t = main.Thread( target=CLIs[i].counters,
2017 name="counters-" + str( i ) )
2018 threads.append( t )
2019 t.start()
2020 for t in threads:
2021 t.join()
2022 onosCounters.append( t.result )
2023 tmp = [ i == onosCounters[ 0 ] for i in onosCounters ]
2024 if all( tmp ):
2025 main.log.info( "Counters are consistent across all nodes" )
2026 consistentCounterResults = main.TRUE
2027 else:
2028 main.log.error( "Counters are not consistent across all nodes" )
2029 consistentCounterResults = main.FALSE
2030 utilities.assert_equals( expect=main.TRUE,
2031 actual=consistentCounterResults,
2032 onpass="ONOS counters are consistent " +
2033 "across nodes",
2034 onfail="ONOS Counters are inconsistent " +
2035 "across nodes" )
2036
2037 main.step( "Counters we added have the correct values" )
2038 correctResults = main.TRUE
2039 for i in range( numControllers ):
Jon Hall40d2cbd2015-06-03 16:24:29 -07002040 current = json.loads( onosCounters[i] )
2041 pValue = None
2042 iValue = None
Jon Hall390696c2015-05-05 17:13:41 -07002043 try:
Jon Hall40d2cbd2015-06-03 16:24:29 -07002044 for database in current:
2045 partitioned = database.get( 'partitionedDatabaseCounters' )
2046 if partitioned:
2047 for value in partitioned:
2048 if value.get( 'name' ) == pCounterName:
2049 pValue = value.get( 'value' )
2050 break
2051 inMemory = database.get( 'inMemoryDatabaseCounters' )
2052 if inMemory:
2053 for value in inMemory:
2054 if value.get( 'name' ) == iCounterName:
2055 iValue = value.get( 'value' )
2056 break
Jon Hall390696c2015-05-05 17:13:41 -07002057 except AttributeError, e:
2058 main.log.error( "ONOS" + str( i + 1 ) + " counters result " +
2059 "is not as expected" )
2060 correctResults = main.FALSE
Jon Hall40d2cbd2015-06-03 16:24:29 -07002061 if pValue == pCounterValue:
2062 main.log.info( "Partitioned counter value is correct" )
2063 else:
2064 main.log.error( "Partitioned counter value is incorrect," +
2065 " expected value: " + str( pCounterValue )
2066 + " current value: " + str( pValue ) )
2067 correctResults = main.FALSE
2068 if iValue == iCounterValue:
2069 main.log.info( "In memory counter value is correct" )
2070 else:
2071 main.log.error( "In memory counter value is incorrect, " +
2072 "expected value: " + str( iCounterValue ) +
2073 " current value: " + str( iValue ) )
2074 correctResults = main.FALSE
Jon Hall390696c2015-05-05 17:13:41 -07002075 utilities.assert_equals( expect=main.TRUE,
2076 actual=correctResults,
2077 onpass="Added counters are correct",
2078 onfail="Added counters are incorrect" )
2079 # DISTRIBUTED SETS
2080 main.step( "Distributed Set get" )
2081 size = len( onosSet )
2082 getResponses = []
2083 threads = []
2084 for i in range( numControllers ):
2085 t = main.Thread( target=CLIs[i].setTestGet,
2086 name="setTestGet-" + str( i ),
2087 args=[ onosSetName ] )
2088 threads.append( t )
2089 t.start()
2090 for t in threads:
2091 t.join()
2092 getResponses.append( t.result )
2093
2094 getResults = main.TRUE
2095 for i in range( numControllers ):
2096 if isinstance( getResponses[ i ], list):
2097 current = set( getResponses[ i ] )
2098 if len( current ) == len( getResponses[ i ] ):
2099 # no repeats
2100 if onosSet != current:
2101 main.log.error( "ONOS" + str( i + 1 ) +
2102 " has incorrect view" +
2103 " of set " + onosSetName + ":\n" +
2104 str( getResponses[ i ] ) )
2105 main.log.debug( "Expected: " + str( onosSet ) )
2106 main.log.debug( "Actual: " + str( current ) )
2107 getResults = main.FALSE
2108 else:
2109 # error, set is not a set
2110 main.log.error( "ONOS" + str( i + 1 ) +
2111 " has repeat elements in" +
2112 " set " + onosSetName + ":\n" +
2113 str( getResponses[ i ] ) )
2114 getResults = main.FALSE
2115 elif getResponses[ i ] == main.ERROR:
2116 getResults = main.FALSE
2117 utilities.assert_equals( expect=main.TRUE,
2118 actual=getResults,
2119 onpass="Set elements are correct",
2120 onfail="Set elements are incorrect" )
2121
2122 main.step( "Distributed Set size" )
2123 sizeResponses = []
2124 threads = []
2125 for i in range( numControllers ):
2126 t = main.Thread( target=CLIs[i].setTestSize,
2127 name="setTestSize-" + str( i ),
2128 args=[ onosSetName ] )
2129 threads.append( t )
2130 t.start()
2131 for t in threads:
2132 t.join()
2133 sizeResponses.append( t.result )
2134
2135 sizeResults = main.TRUE
2136 for i in range( numControllers ):
2137 if size != sizeResponses[ i ]:
2138 sizeResults = main.FALSE
2139 main.log.error( "ONOS" + str( i + 1 ) +
2140 " expected a size of " + str( size ) +
2141 " for set " + onosSetName +
2142 " but got " + str( sizeResponses[ i ] ) )
2143 utilities.assert_equals( expect=main.TRUE,
2144 actual=sizeResults,
2145 onpass="Set sizes are correct",
2146 onfail="Set sizes are incorrect" )
2147
2148 main.step( "Distributed Set add()" )
2149 onosSet.add( addValue )
2150 addResponses = []
2151 threads = []
2152 for i in range( numControllers ):
2153 t = main.Thread( target=CLIs[i].setTestAdd,
2154 name="setTestAdd-" + str( i ),
2155 args=[ onosSetName, addValue ] )
2156 threads.append( t )
2157 t.start()
2158 for t in threads:
2159 t.join()
2160 addResponses.append( t.result )
2161
2162 # main.TRUE = successfully changed the set
2163 # main.FALSE = action resulted in no change in set
2164 # main.ERROR - Some error in executing the function
2165 addResults = main.TRUE
2166 for i in range( numControllers ):
2167 if addResponses[ i ] == main.TRUE:
2168 # All is well
2169 pass
2170 elif addResponses[ i ] == main.FALSE:
2171 # Already in set, probably fine
2172 pass
2173 elif addResponses[ i ] == main.ERROR:
2174 # Error in execution
2175 addResults = main.FALSE
2176 else:
2177 # unexpected result
2178 addResults = main.FALSE
2179 if addResults != main.TRUE:
2180 main.log.error( "Error executing set add" )
2181
2182 # Check if set is still correct
2183 size = len( onosSet )
2184 getResponses = []
2185 threads = []
2186 for i in range( numControllers ):
2187 t = main.Thread( target=CLIs[i].setTestGet,
2188 name="setTestGet-" + str( i ),
2189 args=[ onosSetName ] )
2190 threads.append( t )
2191 t.start()
2192 for t in threads:
2193 t.join()
2194 getResponses.append( t.result )
2195 getResults = main.TRUE
2196 for i in range( numControllers ):
2197 if isinstance( getResponses[ i ], list):
2198 current = set( getResponses[ i ] )
2199 if len( current ) == len( getResponses[ i ] ):
2200 # no repeats
2201 if onosSet != current:
2202 main.log.error( "ONOS" + str( i + 1 ) +
2203 " has incorrect view" +
2204 " of set " + onosSetName + ":\n" +
2205 str( getResponses[ i ] ) )
2206 main.log.debug( "Expected: " + str( onosSet ) )
2207 main.log.debug( "Actual: " + str( current ) )
2208 getResults = main.FALSE
2209 else:
2210 # error, set is not a set
2211 main.log.error( "ONOS" + str( i + 1 ) +
2212 " has repeat elements in" +
2213 " set " + onosSetName + ":\n" +
2214 str( getResponses[ i ] ) )
2215 getResults = main.FALSE
2216 elif getResponses[ i ] == main.ERROR:
2217 getResults = main.FALSE
2218 sizeResponses = []
2219 threads = []
2220 for i in range( numControllers ):
2221 t = main.Thread( target=CLIs[i].setTestSize,
2222 name="setTestSize-" + str( i ),
2223 args=[ onosSetName ] )
2224 threads.append( t )
2225 t.start()
2226 for t in threads:
2227 t.join()
2228 sizeResponses.append( t.result )
2229 sizeResults = main.TRUE
2230 for i in range( numControllers ):
2231 if size != sizeResponses[ i ]:
2232 sizeResults = main.FALSE
2233 main.log.error( "ONOS" + str( i + 1 ) +
2234 " expected a size of " + str( size ) +
2235 " for set " + onosSetName +
2236 " but got " + str( sizeResponses[ i ] ) )
2237 addResults = addResults and getResults and sizeResults
2238 utilities.assert_equals( expect=main.TRUE,
2239 actual=addResults,
2240 onpass="Set add correct",
2241 onfail="Set add was incorrect" )
2242
2243 main.step( "Distributed Set addAll()" )
2244 onosSet.update( addAllValue.split() )
2245 addResponses = []
2246 threads = []
2247 for i in range( numControllers ):
2248 t = main.Thread( target=CLIs[i].setTestAdd,
2249 name="setTestAddAll-" + str( i ),
2250 args=[ onosSetName, addAllValue ] )
2251 threads.append( t )
2252 t.start()
2253 for t in threads:
2254 t.join()
2255 addResponses.append( t.result )
2256
2257 # main.TRUE = successfully changed the set
2258 # main.FALSE = action resulted in no change in set
2259 # main.ERROR - Some error in executing the function
2260 addAllResults = main.TRUE
2261 for i in range( numControllers ):
2262 if addResponses[ i ] == main.TRUE:
2263 # All is well
2264 pass
2265 elif addResponses[ i ] == main.FALSE:
2266 # Already in set, probably fine
2267 pass
2268 elif addResponses[ i ] == main.ERROR:
2269 # Error in execution
2270 addAllResults = main.FALSE
2271 else:
2272 # unexpected result
2273 addAllResults = main.FALSE
2274 if addAllResults != main.TRUE:
2275 main.log.error( "Error executing set addAll" )
2276
2277 # Check if set is still correct
2278 size = len( onosSet )
2279 getResponses = []
2280 threads = []
2281 for i in range( numControllers ):
2282 t = main.Thread( target=CLIs[i].setTestGet,
2283 name="setTestGet-" + str( i ),
2284 args=[ onosSetName ] )
2285 threads.append( t )
2286 t.start()
2287 for t in threads:
2288 t.join()
2289 getResponses.append( t.result )
2290 getResults = main.TRUE
2291 for i in range( numControllers ):
2292 if isinstance( getResponses[ i ], list):
2293 current = set( getResponses[ i ] )
2294 if len( current ) == len( getResponses[ i ] ):
2295 # no repeats
2296 if onosSet != current:
2297 main.log.error( "ONOS" + str( i + 1 ) +
2298 " has incorrect view" +
2299 " of set " + onosSetName + ":\n" +
2300 str( getResponses[ i ] ) )
2301 main.log.debug( "Expected: " + str( onosSet ) )
2302 main.log.debug( "Actual: " + str( current ) )
2303 getResults = main.FALSE
2304 else:
2305 # error, set is not a set
2306 main.log.error( "ONOS" + str( i + 1 ) +
2307 " has repeat elements in" +
2308 " set " + onosSetName + ":\n" +
2309 str( getResponses[ i ] ) )
2310 getResults = main.FALSE
2311 elif getResponses[ i ] == main.ERROR:
2312 getResults = main.FALSE
2313 sizeResponses = []
2314 threads = []
2315 for i in range( numControllers ):
2316 t = main.Thread( target=CLIs[i].setTestSize,
2317 name="setTestSize-" + str( i ),
2318 args=[ onosSetName ] )
2319 threads.append( t )
2320 t.start()
2321 for t in threads:
2322 t.join()
2323 sizeResponses.append( t.result )
2324 sizeResults = main.TRUE
2325 for i in range( numControllers ):
2326 if size != sizeResponses[ i ]:
2327 sizeResults = main.FALSE
2328 main.log.error( "ONOS" + str( i + 1 ) +
2329 " expected a size of " + str( size ) +
2330 " for set " + onosSetName +
2331 " but got " + str( sizeResponses[ i ] ) )
2332 addAllResults = addAllResults and getResults and sizeResults
2333 utilities.assert_equals( expect=main.TRUE,
2334 actual=addAllResults,
2335 onpass="Set addAll correct",
2336 onfail="Set addAll was incorrect" )
2337
2338 main.step( "Distributed Set contains()" )
2339 containsResponses = []
2340 threads = []
2341 for i in range( numControllers ):
2342 t = main.Thread( target=CLIs[i].setTestGet,
2343 name="setContains-" + str( i ),
2344 args=[ onosSetName ],
2345 kwargs={ "values": addValue } )
2346 threads.append( t )
2347 t.start()
2348 for t in threads:
2349 t.join()
2350 # NOTE: This is the tuple
2351 containsResponses.append( t.result )
2352
2353 containsResults = main.TRUE
2354 for i in range( numControllers ):
2355 if containsResponses[ i ] == main.ERROR:
2356 containsResults = main.FALSE
2357 else:
2358 containsResults = containsResults and\
2359 containsResponses[ i ][ 1 ]
2360 utilities.assert_equals( expect=main.TRUE,
2361 actual=containsResults,
2362 onpass="Set contains is functional",
2363 onfail="Set contains failed" )
2364
2365 main.step( "Distributed Set containsAll()" )
2366 containsAllResponses = []
2367 threads = []
2368 for i in range( numControllers ):
2369 t = main.Thread( target=CLIs[i].setTestGet,
2370 name="setContainsAll-" + str( i ),
2371 args=[ onosSetName ],
2372 kwargs={ "values": addAllValue } )
2373 threads.append( t )
2374 t.start()
2375 for t in threads:
2376 t.join()
2377 # NOTE: This is the tuple
2378 containsAllResponses.append( t.result )
2379
2380 containsAllResults = main.TRUE
2381 for i in range( numControllers ):
2382 if containsResponses[ i ] == main.ERROR:
2383 containsResults = main.FALSE
2384 else:
2385 containsResults = containsResults and\
2386 containsResponses[ i ][ 1 ]
2387 utilities.assert_equals( expect=main.TRUE,
2388 actual=containsAllResults,
2389 onpass="Set containsAll is functional",
2390 onfail="Set containsAll failed" )
2391
2392 main.step( "Distributed Set remove()" )
2393 onosSet.remove( addValue )
2394 removeResponses = []
2395 threads = []
2396 for i in range( numControllers ):
2397 t = main.Thread( target=CLIs[i].setTestRemove,
2398 name="setTestRemove-" + str( i ),
2399 args=[ onosSetName, addValue ] )
2400 threads.append( t )
2401 t.start()
2402 for t in threads:
2403 t.join()
2404 removeResponses.append( t.result )
2405
2406 # main.TRUE = successfully changed the set
2407 # main.FALSE = action resulted in no change in set
2408 # main.ERROR - Some error in executing the function
2409 removeResults = main.TRUE
2410 for i in range( numControllers ):
2411 if removeResponses[ i ] == main.TRUE:
2412 # All is well
2413 pass
2414 elif removeResponses[ i ] == main.FALSE:
2415 # not in set, probably fine
2416 pass
2417 elif removeResponses[ i ] == main.ERROR:
2418 # Error in execution
2419 removeResults = main.FALSE
2420 else:
2421 # unexpected result
2422 removeResults = main.FALSE
2423 if removeResults != main.TRUE:
2424 main.log.error( "Error executing set remove" )
2425
2426 # Check if set is still correct
2427 size = len( onosSet )
2428 getResponses = []
2429 threads = []
2430 for i in range( numControllers ):
2431 t = main.Thread( target=CLIs[i].setTestGet,
2432 name="setTestGet-" + str( i ),
2433 args=[ onosSetName ] )
2434 threads.append( t )
2435 t.start()
2436 for t in threads:
2437 t.join()
2438 getResponses.append( t.result )
2439 getResults = main.TRUE
2440 for i in range( numControllers ):
2441 if isinstance( getResponses[ i ], list):
2442 current = set( getResponses[ i ] )
2443 if len( current ) == len( getResponses[ i ] ):
2444 # no repeats
2445 if onosSet != current:
2446 main.log.error( "ONOS" + str( i + 1 ) +
2447 " has incorrect view" +
2448 " of set " + onosSetName + ":\n" +
2449 str( getResponses[ i ] ) )
2450 main.log.debug( "Expected: " + str( onosSet ) )
2451 main.log.debug( "Actual: " + str( current ) )
2452 getResults = main.FALSE
2453 else:
2454 # error, set is not a set
2455 main.log.error( "ONOS" + str( i + 1 ) +
2456 " has repeat elements in" +
2457 " set " + onosSetName + ":\n" +
2458 str( getResponses[ i ] ) )
2459 getResults = main.FALSE
2460 elif getResponses[ i ] == main.ERROR:
2461 getResults = main.FALSE
2462 sizeResponses = []
2463 threads = []
2464 for i in range( numControllers ):
2465 t = main.Thread( target=CLIs[i].setTestSize,
2466 name="setTestSize-" + str( i ),
2467 args=[ onosSetName ] )
2468 threads.append( t )
2469 t.start()
2470 for t in threads:
2471 t.join()
2472 sizeResponses.append( t.result )
2473 sizeResults = main.TRUE
2474 for i in range( numControllers ):
2475 if size != sizeResponses[ i ]:
2476 sizeResults = main.FALSE
2477 main.log.error( "ONOS" + str( i + 1 ) +
2478 " expected a size of " + str( size ) +
2479 " for set " + onosSetName +
2480 " but got " + str( sizeResponses[ i ] ) )
2481 removeResults = removeResults and getResults and sizeResults
2482 utilities.assert_equals( expect=main.TRUE,
2483 actual=removeResults,
2484 onpass="Set remove correct",
2485 onfail="Set remove was incorrect" )
2486
2487 main.step( "Distributed Set removeAll()" )
2488 onosSet.difference_update( addAllValue.split() )
2489 removeAllResponses = []
2490 threads = []
2491 try:
2492 for i in range( numControllers ):
2493 t = main.Thread( target=CLIs[i].setTestRemove,
2494 name="setTestRemoveAll-" + str( i ),
2495 args=[ onosSetName, addAllValue ] )
2496 threads.append( t )
2497 t.start()
2498 for t in threads:
2499 t.join()
2500 removeAllResponses.append( t.result )
2501 except Exception, e:
2502 main.log.exception(e)
2503
2504 # main.TRUE = successfully changed the set
2505 # main.FALSE = action resulted in no change in set
2506 # main.ERROR - Some error in executing the function
2507 removeAllResults = main.TRUE
2508 for i in range( numControllers ):
2509 if removeAllResponses[ i ] == main.TRUE:
2510 # All is well
2511 pass
2512 elif removeAllResponses[ i ] == main.FALSE:
2513 # not in set, probably fine
2514 pass
2515 elif removeAllResponses[ i ] == main.ERROR:
2516 # Error in execution
2517 removeAllResults = main.FALSE
2518 else:
2519 # unexpected result
2520 removeAllResults = main.FALSE
2521 if removeAllResults != main.TRUE:
2522 main.log.error( "Error executing set removeAll" )
2523
2524 # Check if set is still correct
2525 size = len( onosSet )
2526 getResponses = []
2527 threads = []
2528 for i in range( numControllers ):
2529 t = main.Thread( target=CLIs[i].setTestGet,
2530 name="setTestGet-" + str( i ),
2531 args=[ onosSetName ] )
2532 threads.append( t )
2533 t.start()
2534 for t in threads:
2535 t.join()
2536 getResponses.append( t.result )
2537 getResults = main.TRUE
2538 for i in range( numControllers ):
2539 if isinstance( getResponses[ i ], list):
2540 current = set( getResponses[ i ] )
2541 if len( current ) == len( getResponses[ i ] ):
2542 # no repeats
2543 if onosSet != current:
2544 main.log.error( "ONOS" + str( i + 1 ) +
2545 " has incorrect view" +
2546 " of set " + onosSetName + ":\n" +
2547 str( getResponses[ i ] ) )
2548 main.log.debug( "Expected: " + str( onosSet ) )
2549 main.log.debug( "Actual: " + str( current ) )
2550 getResults = main.FALSE
2551 else:
2552 # error, set is not a set
2553 main.log.error( "ONOS" + str( i + 1 ) +
2554 " has repeat elements in" +
2555 " set " + onosSetName + ":\n" +
2556 str( getResponses[ i ] ) )
2557 getResults = main.FALSE
2558 elif getResponses[ i ] == main.ERROR:
2559 getResults = main.FALSE
2560 sizeResponses = []
2561 threads = []
2562 for i in range( numControllers ):
2563 t = main.Thread( target=CLIs[i].setTestSize,
2564 name="setTestSize-" + str( i ),
2565 args=[ onosSetName ] )
2566 threads.append( t )
2567 t.start()
2568 for t in threads:
2569 t.join()
2570 sizeResponses.append( t.result )
2571 sizeResults = main.TRUE
2572 for i in range( numControllers ):
2573 if size != sizeResponses[ i ]:
2574 sizeResults = main.FALSE
2575 main.log.error( "ONOS" + str( i + 1 ) +
2576 " expected a size of " + str( size ) +
2577 " for set " + onosSetName +
2578 " but got " + str( sizeResponses[ i ] ) )
2579 removeAllResults = removeAllResults and getResults and sizeResults
2580 utilities.assert_equals( expect=main.TRUE,
2581 actual=removeAllResults,
2582 onpass="Set removeAll correct",
2583 onfail="Set removeAll was incorrect" )
2584
2585 main.step( "Distributed Set addAll()" )
2586 onosSet.update( addAllValue.split() )
2587 addResponses = []
2588 threads = []
2589 for i in range( numControllers ):
2590 t = main.Thread( target=CLIs[i].setTestAdd,
2591 name="setTestAddAll-" + str( i ),
2592 args=[ onosSetName, addAllValue ] )
2593 threads.append( t )
2594 t.start()
2595 for t in threads:
2596 t.join()
2597 addResponses.append( t.result )
2598
2599 # main.TRUE = successfully changed the set
2600 # main.FALSE = action resulted in no change in set
2601 # main.ERROR - Some error in executing the function
2602 addAllResults = main.TRUE
2603 for i in range( numControllers ):
2604 if addResponses[ i ] == main.TRUE:
2605 # All is well
2606 pass
2607 elif addResponses[ i ] == main.FALSE:
2608 # Already in set, probably fine
2609 pass
2610 elif addResponses[ i ] == main.ERROR:
2611 # Error in execution
2612 addAllResults = main.FALSE
2613 else:
2614 # unexpected result
2615 addAllResults = main.FALSE
2616 if addAllResults != main.TRUE:
2617 main.log.error( "Error executing set addAll" )
2618
2619 # Check if set is still correct
2620 size = len( onosSet )
2621 getResponses = []
2622 threads = []
2623 for i in range( numControllers ):
2624 t = main.Thread( target=CLIs[i].setTestGet,
2625 name="setTestGet-" + str( i ),
2626 args=[ onosSetName ] )
2627 threads.append( t )
2628 t.start()
2629 for t in threads:
2630 t.join()
2631 getResponses.append( t.result )
2632 getResults = main.TRUE
2633 for i in range( numControllers ):
2634 if isinstance( getResponses[ i ], list):
2635 current = set( getResponses[ i ] )
2636 if len( current ) == len( getResponses[ i ] ):
2637 # no repeats
2638 if onosSet != current:
2639 main.log.error( "ONOS" + str( i + 1 ) +
2640 " has incorrect view" +
2641 " of set " + onosSetName + ":\n" +
2642 str( getResponses[ i ] ) )
2643 main.log.debug( "Expected: " + str( onosSet ) )
2644 main.log.debug( "Actual: " + str( current ) )
2645 getResults = main.FALSE
2646 else:
2647 # error, set is not a set
2648 main.log.error( "ONOS" + str( i + 1 ) +
2649 " has repeat elements in" +
2650 " set " + onosSetName + ":\n" +
2651 str( getResponses[ i ] ) )
2652 getResults = main.FALSE
2653 elif getResponses[ i ] == main.ERROR:
2654 getResults = main.FALSE
2655 sizeResponses = []
2656 threads = []
2657 for i in range( numControllers ):
2658 t = main.Thread( target=CLIs[i].setTestSize,
2659 name="setTestSize-" + str( i ),
2660 args=[ onosSetName ] )
2661 threads.append( t )
2662 t.start()
2663 for t in threads:
2664 t.join()
2665 sizeResponses.append( t.result )
2666 sizeResults = main.TRUE
2667 for i in range( numControllers ):
2668 if size != sizeResponses[ i ]:
2669 sizeResults = main.FALSE
2670 main.log.error( "ONOS" + str( i + 1 ) +
2671 " expected a size of " + str( size ) +
2672 " for set " + onosSetName +
2673 " but got " + str( sizeResponses[ i ] ) )
2674 addAllResults = addAllResults and getResults and sizeResults
2675 utilities.assert_equals( expect=main.TRUE,
2676 actual=addAllResults,
2677 onpass="Set addAll correct",
2678 onfail="Set addAll was incorrect" )
2679
2680 main.step( "Distributed Set clear()" )
2681 onosSet.clear()
2682 clearResponses = []
2683 threads = []
2684 for i in range( numControllers ):
2685 t = main.Thread( target=CLIs[i].setTestRemove,
2686 name="setTestClear-" + str( i ),
2687 args=[ onosSetName, " "], # Values doesn't matter
2688 kwargs={ "clear": True } )
2689 threads.append( t )
2690 t.start()
2691 for t in threads:
2692 t.join()
2693 clearResponses.append( t.result )
2694
2695 # main.TRUE = successfully changed the set
2696 # main.FALSE = action resulted in no change in set
2697 # main.ERROR - Some error in executing the function
2698 clearResults = main.TRUE
2699 for i in range( numControllers ):
2700 if clearResponses[ i ] == main.TRUE:
2701 # All is well
2702 pass
2703 elif clearResponses[ i ] == main.FALSE:
2704 # Nothing set, probably fine
2705 pass
2706 elif clearResponses[ i ] == main.ERROR:
2707 # Error in execution
2708 clearResults = main.FALSE
2709 else:
2710 # unexpected result
2711 clearResults = main.FALSE
2712 if clearResults != main.TRUE:
2713 main.log.error( "Error executing set clear" )
2714
2715 # Check if set is still correct
2716 size = len( onosSet )
2717 getResponses = []
2718 threads = []
2719 for i in range( numControllers ):
2720 t = main.Thread( target=CLIs[i].setTestGet,
2721 name="setTestGet-" + str( i ),
2722 args=[ onosSetName ] )
2723 threads.append( t )
2724 t.start()
2725 for t in threads:
2726 t.join()
2727 getResponses.append( t.result )
2728 getResults = main.TRUE
2729 for i in range( numControllers ):
2730 if isinstance( getResponses[ i ], list):
2731 current = set( getResponses[ i ] )
2732 if len( current ) == len( getResponses[ i ] ):
2733 # no repeats
2734 if onosSet != current:
2735 main.log.error( "ONOS" + str( i + 1 ) +
2736 " has incorrect view" +
2737 " of set " + onosSetName + ":\n" +
2738 str( getResponses[ i ] ) )
2739 main.log.debug( "Expected: " + str( onosSet ) )
2740 main.log.debug( "Actual: " + str( current ) )
2741 getResults = main.FALSE
2742 else:
2743 # error, set is not a set
2744 main.log.error( "ONOS" + str( i + 1 ) +
2745 " has repeat elements in" +
2746 " set " + onosSetName + ":\n" +
2747 str( getResponses[ i ] ) )
2748 getResults = main.FALSE
2749 elif getResponses[ i ] == main.ERROR:
2750 getResults = main.FALSE
2751 sizeResponses = []
2752 threads = []
2753 for i in range( numControllers ):
2754 t = main.Thread( target=CLIs[i].setTestSize,
2755 name="setTestSize-" + str( i ),
2756 args=[ onosSetName ] )
2757 threads.append( t )
2758 t.start()
2759 for t in threads:
2760 t.join()
2761 sizeResponses.append( t.result )
2762 sizeResults = main.TRUE
2763 for i in range( numControllers ):
2764 if size != sizeResponses[ i ]:
2765 sizeResults = main.FALSE
2766 main.log.error( "ONOS" + str( i + 1 ) +
2767 " expected a size of " + str( size ) +
2768 " for set " + onosSetName +
2769 " but got " + str( sizeResponses[ i ] ) )
2770 clearResults = clearResults and getResults and sizeResults
2771 utilities.assert_equals( expect=main.TRUE,
2772 actual=clearResults,
2773 onpass="Set clear correct",
2774 onfail="Set clear was incorrect" )
2775
2776 main.step( "Distributed Set addAll()" )
2777 onosSet.update( addAllValue.split() )
2778 addResponses = []
2779 threads = []
2780 for i in range( numControllers ):
2781 t = main.Thread( target=CLIs[i].setTestAdd,
2782 name="setTestAddAll-" + str( i ),
2783 args=[ onosSetName, addAllValue ] )
2784 threads.append( t )
2785 t.start()
2786 for t in threads:
2787 t.join()
2788 addResponses.append( t.result )
2789
2790 # main.TRUE = successfully changed the set
2791 # main.FALSE = action resulted in no change in set
2792 # main.ERROR - Some error in executing the function
2793 addAllResults = main.TRUE
2794 for i in range( numControllers ):
2795 if addResponses[ i ] == main.TRUE:
2796 # All is well
2797 pass
2798 elif addResponses[ i ] == main.FALSE:
2799 # Already in set, probably fine
2800 pass
2801 elif addResponses[ i ] == main.ERROR:
2802 # Error in execution
2803 addAllResults = main.FALSE
2804 else:
2805 # unexpected result
2806 addAllResults = main.FALSE
2807 if addAllResults != main.TRUE:
2808 main.log.error( "Error executing set addAll" )
2809
2810 # Check if set is still correct
2811 size = len( onosSet )
2812 getResponses = []
2813 threads = []
2814 for i in range( numControllers ):
2815 t = main.Thread( target=CLIs[i].setTestGet,
2816 name="setTestGet-" + str( i ),
2817 args=[ onosSetName ] )
2818 threads.append( t )
2819 t.start()
2820 for t in threads:
2821 t.join()
2822 getResponses.append( t.result )
2823 getResults = main.TRUE
2824 for i in range( numControllers ):
2825 if isinstance( getResponses[ i ], list):
2826 current = set( getResponses[ i ] )
2827 if len( current ) == len( getResponses[ i ] ):
2828 # no repeats
2829 if onosSet != current:
2830 main.log.error( "ONOS" + str( i + 1 ) +
2831 " has incorrect view" +
2832 " of set " + onosSetName + ":\n" +
2833 str( getResponses[ i ] ) )
2834 main.log.debug( "Expected: " + str( onosSet ) )
2835 main.log.debug( "Actual: " + str( current ) )
2836 getResults = main.FALSE
2837 else:
2838 # error, set is not a set
2839 main.log.error( "ONOS" + str( i + 1 ) +
2840 " has repeat elements in" +
2841 " set " + onosSetName + ":\n" +
2842 str( getResponses[ i ] ) )
2843 getResults = main.FALSE
2844 elif getResponses[ i ] == main.ERROR:
2845 getResults = main.FALSE
2846 sizeResponses = []
2847 threads = []
2848 for i in range( numControllers ):
2849 t = main.Thread( target=CLIs[i].setTestSize,
2850 name="setTestSize-" + str( i ),
2851 args=[ onosSetName ] )
2852 threads.append( t )
2853 t.start()
2854 for t in threads:
2855 t.join()
2856 sizeResponses.append( t.result )
2857 sizeResults = main.TRUE
2858 for i in range( numControllers ):
2859 if size != sizeResponses[ i ]:
2860 sizeResults = main.FALSE
2861 main.log.error( "ONOS" + str( i + 1 ) +
2862 " expected a size of " + str( size ) +
2863 " for set " + onosSetName +
2864 " but got " + str( sizeResponses[ i ] ) )
2865 addAllResults = addAllResults and getResults and sizeResults
2866 utilities.assert_equals( expect=main.TRUE,
2867 actual=addAllResults,
2868 onpass="Set addAll correct",
2869 onfail="Set addAll was incorrect" )
2870
2871 main.step( "Distributed Set retain()" )
2872 onosSet.intersection_update( retainValue.split() )
2873 retainResponses = []
2874 threads = []
2875 for i in range( numControllers ):
2876 t = main.Thread( target=CLIs[i].setTestRemove,
2877 name="setTestRetain-" + str( i ),
2878 args=[ onosSetName, retainValue ],
2879 kwargs={ "retain": True } )
2880 threads.append( t )
2881 t.start()
2882 for t in threads:
2883 t.join()
2884 retainResponses.append( t.result )
2885
2886 # main.TRUE = successfully changed the set
2887 # main.FALSE = action resulted in no change in set
2888 # main.ERROR - Some error in executing the function
2889 retainResults = main.TRUE
2890 for i in range( numControllers ):
2891 if retainResponses[ i ] == main.TRUE:
2892 # All is well
2893 pass
2894 elif retainResponses[ i ] == main.FALSE:
2895 # Already in set, probably fine
2896 pass
2897 elif retainResponses[ i ] == main.ERROR:
2898 # Error in execution
2899 retainResults = main.FALSE
2900 else:
2901 # unexpected result
2902 retainResults = main.FALSE
2903 if retainResults != main.TRUE:
2904 main.log.error( "Error executing set retain" )
2905
2906 # Check if set is still correct
2907 size = len( onosSet )
2908 getResponses = []
2909 threads = []
2910 for i in range( numControllers ):
2911 t = main.Thread( target=CLIs[i].setTestGet,
2912 name="setTestGet-" + str( i ),
2913 args=[ onosSetName ] )
2914 threads.append( t )
2915 t.start()
2916 for t in threads:
2917 t.join()
2918 getResponses.append( t.result )
2919 getResults = main.TRUE
2920 for i in range( numControllers ):
2921 if isinstance( getResponses[ i ], list):
2922 current = set( getResponses[ i ] )
2923 if len( current ) == len( getResponses[ i ] ):
2924 # no repeats
2925 if onosSet != current:
2926 main.log.error( "ONOS" + str( i + 1 ) +
2927 " has incorrect view" +
2928 " of set " + onosSetName + ":\n" +
2929 str( getResponses[ i ] ) )
2930 main.log.debug( "Expected: " + str( onosSet ) )
2931 main.log.debug( "Actual: " + str( current ) )
2932 getResults = main.FALSE
2933 else:
2934 # error, set is not a set
2935 main.log.error( "ONOS" + str( i + 1 ) +
2936 " has repeat elements in" +
2937 " set " + onosSetName + ":\n" +
2938 str( getResponses[ i ] ) )
2939 getResults = main.FALSE
2940 elif getResponses[ i ] == main.ERROR:
2941 getResults = main.FALSE
2942 sizeResponses = []
2943 threads = []
2944 for i in range( numControllers ):
2945 t = main.Thread( target=CLIs[i].setTestSize,
2946 name="setTestSize-" + str( i ),
2947 args=[ onosSetName ] )
2948 threads.append( t )
2949 t.start()
2950 for t in threads:
2951 t.join()
2952 sizeResponses.append( t.result )
2953 sizeResults = main.TRUE
2954 for i in range( numControllers ):
2955 if size != sizeResponses[ i ]:
2956 sizeResults = main.FALSE
2957 main.log.error( "ONOS" + str( i + 1 ) +
2958 " expected a size of " +
2959 str( size ) + " for set " + onosSetName +
2960 " but got " + str( sizeResponses[ i ] ) )
2961 retainResults = retainResults and getResults and sizeResults
2962 utilities.assert_equals( expect=main.TRUE,
2963 actual=retainResults,
2964 onpass="Set retain correct",
2965 onfail="Set retain was incorrect" )
2966