blob: a3a8a66c2db3e2aacb5d1dc3d25752c12841de9f [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 Hall0f523f22015-07-06 09:31:09 -0700236 ipList = []
237 for i in range( numControllers ):
238 ipList.append( nodes[ i ].ip_address )
239 swList = []
Jon Hall6aec96b2015-01-19 14:49:31 -0800240 for i in range( 1, 29 ):
Jon Hall0f523f22015-07-06 09:31:09 -0700241 swList.append( "s" + str( i ) )
242 main.Mininet1.assignSwController( sw=swList, ip=ipList )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800243
Jon Hall8f89dda2015-01-22 16:03:33 -0800244 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800245 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800246 response = main.Mininet1.getSwController( "s" + str( i ) )
Jon Hallffb386d2014-11-21 13:43:38 -0800247 try:
Jon Hall6aec96b2015-01-19 14:49:31 -0800248 main.log.info( str( response ) )
Jon Hallfebb1c72015-03-05 13:30:09 -0800249 except Exception:
Jon Hall6aec96b2015-01-19 14:49:31 -0800250 main.log.info( repr( response ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800251 if re.search( "tcp:" + ONOS1Ip, response ):
252 mastershipCheck = mastershipCheck and main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800253 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800254 mastershipCheck = main.FALSE
255 if mastershipCheck == main.TRUE:
Jon Hallfeff3082015-05-19 10:23:26 -0700256 main.log.info( "Switch mastership assigned correctly" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800257 utilities.assert_equals(
258 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800259 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800260 onpass="Switch mastership assigned correctly",
261 onfail="Switches not assigned correctly to controllers" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800262
Jon Hallc9eabec2015-06-10 14:33:14 -0700263 def CASE21( self, main ):
264 """
265 Assign mastership to controllers
266 """
267 import re
268 import time
269 assert numControllers, "numControllers not defined"
270 assert main, "main not defined"
271 assert utilities.assert_equals, "utilities.assert_equals not defined"
272 assert CLIs, "CLIs not defined"
273 assert nodes, "nodes not defined"
274 assert ONOS1Port, "ONOS1Port not defined"
275 assert ONOS2Port, "ONOS2Port not defined"
276 assert ONOS3Port, "ONOS3Port not defined"
277 assert ONOS4Port, "ONOS4Port not defined"
278 assert ONOS5Port, "ONOS5Port not defined"
279 assert ONOS6Port, "ONOS6Port not defined"
280 assert ONOS7Port, "ONOS7Port not defined"
281
282 main.case( "Assigning Controller roles for switches" )
283 main.caseExplaination = "Check that ONOS is connected to each " +\
284 "device. Then manually assign" +\
285 " mastership to specific ONOS nodes using" +\
286 " 'device-role'"
Jon Hall390696c2015-05-05 17:13:41 -0700287 main.step( "Assign mastership of switches to specific controllers" )
Jon Halla9d26da2015-03-30 16:45:32 -0700288 roleCall = main.TRUE
289 roleCheck = main.TRUE
290 try:
291 for i in range( 1, 29 ): # switches 1 through 28
292 ip = nodes[ 0 ].ip_address # ONOS1
293 # set up correct variables:
294 if i == 1:
295 deviceId = main.ONOScli1.getDevice( "1000" ).get( 'id' )
296 elif i == 2:
297 deviceId = main.ONOScli1.getDevice( "2000" ).get( 'id' )
298 elif i == 3:
299 deviceId = main.ONOScli1.getDevice( "3000" ).get( 'id' )
300 elif i == 4:
301 deviceId = main.ONOScli1.getDevice( "3004" ).get( 'id' )
302 elif i == 5:
303 deviceId = main.ONOScli1.getDevice( "5000" ).get( 'id' )
304 elif i == 6:
305 deviceId = main.ONOScli1.getDevice( "6000" ).get( 'id' )
306 elif i == 7:
307 deviceId = main.ONOScli1.getDevice( "6007" ).get( 'id' )
308 elif i >= 8 and i <= 17:
309 dpid = '3' + str( i ).zfill( 3 )
310 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
311 elif i >= 18 and i <= 27:
312 dpid = '6' + str( i ).zfill( 3 )
313 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
314 elif i == 28:
315 deviceId = main.ONOScli1.getDevice( "2800" ).get( 'id' )
316 else:
317 main.log.error( "You didn't write an else statement for " +
318 "switch s" + str( i ) )
319 # Assign switch
320 assert deviceId, "No device id for s" + str( i ) + " in ONOS"
321 # TODO: make this controller dynamic
322 roleCall = roleCall and main.ONOScli1.deviceRole( deviceId,
323 ip )
324 # Check assignment
Jon Hall390696c2015-05-05 17:13:41 -0700325 master = main.ONOScli1.getRole( deviceId ).get( 'master' )
Jon Hall678f4512015-03-31 09:48:31 -0700326 if ip in master:
Jon Halla9d26da2015-03-30 16:45:32 -0700327 roleCheck = roleCheck and main.TRUE
328 else:
329 roleCheck = roleCheck and main.FALSE
330 main.log.error( "Error, controller " + ip + " is not" +
331 " master " + "of device " +
Jon Hall678f4512015-03-31 09:48:31 -0700332 str( deviceId ) + ". Master is " +
333 repr( master ) + "." )
Jon Halla9d26da2015-03-30 16:45:32 -0700334 except ( AttributeError, AssertionError ):
335 main.log.exception( "Something is wrong with ONOS device view" )
336 main.log.info( main.ONOScli1.devices() )
337 utilities.assert_equals(
338 expect=main.TRUE,
339 actual=roleCall,
340 onpass="Re-assigned switch mastership to designated controller",
341 onfail="Something wrong with deviceRole calls" )
342
Jon Hall390696c2015-05-05 17:13:41 -0700343 main.step( "Check mastership was correctly assigned" )
Jon Halla9d26da2015-03-30 16:45:32 -0700344 utilities.assert_equals(
345 expect=main.TRUE,
346 actual=roleCheck,
347 onpass="Switches were successfully reassigned to designated " +
348 "controller",
349 onfail="Switches were not successfully reassigned" )
Jon Halla9d26da2015-03-30 16:45:32 -0700350
Jon Hall6aec96b2015-01-19 14:49:31 -0800351 def CASE3( self, main ):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800352 """
353 Assign intents
Jon Hall73cf9cc2014-11-20 22:28:38 -0800354 """
355 import time
Jon Hallfebb1c72015-03-05 13:30:09 -0800356 import json
Jon Hall5cfd23c2015-03-19 11:40:57 -0700357 assert numControllers, "numControllers not defined"
358 assert main, "main not defined"
359 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hallfeff3082015-05-19 10:23:26 -0700360 # NOTE: we must reinstall intents until we have a persistant intent
361 # datastore!
Jon Hall6aec96b2015-01-19 14:49:31 -0800362 main.case( "Adding host Intents" )
Jon Hallfeff3082015-05-19 10:23:26 -0700363 main.caseExplaination = "Discover hosts by using pingall then " +\
364 "assign predetermined host-to-host intents." +\
365 " After installation, check that the intent" +\
366 " is distributed to all nodes and the state" +\
367 " is INSTALLED"
Jon Hall73cf9cc2014-11-20 22:28:38 -0800368
Jon Hall6aec96b2015-01-19 14:49:31 -0800369 # install onos-app-fwd
Jon Hall390696c2015-05-05 17:13:41 -0700370 main.step( "Install reactive forwarding app" )
371 installResults = CLIs[0].activateApp( "org.onosproject.fwd" )
372 utilities.assert_equals( expect=main.TRUE, actual=installResults,
373 onpass="Install fwd successful",
374 onfail="Install fwd failed" )
Jon Halla9d26da2015-03-30 16:45:32 -0700375
Jon Hallfeff3082015-05-19 10:23:26 -0700376 main.step( "Check app ids" )
Jon Halla9d26da2015-03-30 16:45:32 -0700377 appCheck = main.ONOScli1.appToIDCheck()
378 if appCheck != main.TRUE:
379 main.log.warn( CLIs[0].apps() )
380 main.log.warn( CLIs[0].appIDs() )
Jon Hall390696c2015-05-05 17:13:41 -0700381 utilities.assert_equals( expect=main.TRUE, actual=appCheck,
382 onpass="App Ids seem to be correct",
383 onfail="Something is wrong with app Ids" )
Jon Hall94fd0472014-12-08 11:52:42 -0800384
Jon Hallfeff3082015-05-19 10:23:26 -0700385 main.step( "Discovering Hosts( Via pingall for now )" )
386 # FIXME: Once we have a host discovery mechanism, use that instead
Jon Hall6aec96b2015-01-19 14:49:31 -0800387 # REACTIVE FWD test
Jon Hall8f89dda2015-01-22 16:03:33 -0800388 pingResult = main.FALSE
Jon Hall5cfd23c2015-03-19 11:40:57 -0700389 for i in range(2): # Retry if pingall fails first time
390 time1 = time.time()
391 pingResult = main.Mininet1.pingall()
Jon Hall0f523f22015-07-06 09:31:09 -0700392 if i == 0:
393 utilities.assert_equals(
394 expect=main.TRUE,
395 actual=pingResult,
396 onpass="Reactive Pingall test passed",
397 onfail="Reactive Pingall failed, " +
398 "one or more ping pairs failed" )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700399 time2 = time.time()
Jon Hall390696c2015-05-05 17:13:41 -0700400 main.log.info( "Time for pingall: %2f seconds" %
401 ( time2 - time1 ) )
402 # timeout for fwd flows
403 time.sleep( 11 )
Jon Hall6aec96b2015-01-19 14:49:31 -0800404 # uninstall onos-app-fwd
Jon Hall390696c2015-05-05 17:13:41 -0700405 main.step( "Uninstall reactive forwarding app" )
406 uninstallResult = CLIs[0].deactivateApp( "org.onosproject.fwd" )
407 utilities.assert_equals( expect=main.TRUE, actual=uninstallResult,
408 onpass="Uninstall fwd successful",
409 onfail="Uninstall fwd failed" )
Jon Hallfeff3082015-05-19 10:23:26 -0700410
411 main.step( "Check app ids" )
Jon Halla9d26da2015-03-30 16:45:32 -0700412 appCheck2 = main.ONOScli1.appToIDCheck()
413 if appCheck2 != main.TRUE:
414 main.log.warn( CLIs[0].apps() )
415 main.log.warn( CLIs[0].appIDs() )
Jon Hall390696c2015-05-05 17:13:41 -0700416 utilities.assert_equals( expect=main.TRUE, actual=appCheck2,
417 onpass="App Ids seem to be correct",
418 onfail="Something is wrong with app Ids" )
Jon Halla9d26da2015-03-30 16:45:32 -0700419
Jon Hallfeff3082015-05-19 10:23:26 -0700420 main.step( "Add host intents via cli" )
Jon Hall58c76b72015-02-23 11:09:24 -0800421 intentIds = []
Jon Hall6aec96b2015-01-19 14:49:31 -0800422 # TODO: move the host numbers to params
Jon Hall58c76b72015-02-23 11:09:24 -0800423 # Maybe look at all the paths we ping?
Jon Hall8f89dda2015-01-22 16:03:33 -0800424 intentAddResult = True
Jon Hall58c76b72015-02-23 11:09:24 -0800425 hostResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800426 for i in range( 8, 18 ):
427 main.log.info( "Adding host intent between h" + str( i ) +
428 " and h" + str( i + 10 ) )
429 host1 = "00:00:00:00:00:" + \
430 str( hex( i )[ 2: ] ).zfill( 2 ).upper()
431 host2 = "00:00:00:00:00:" + \
432 str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper()
Jon Hall1b8f54a2015-02-04 13:24:20 -0800433 # NOTE: getHost can return None
434 host1Dict = main.ONOScli1.getHost( host1 )
435 host2Dict = main.ONOScli1.getHost( host2 )
436 host1Id = None
437 host2Id = None
438 if host1Dict and host2Dict:
439 host1Id = host1Dict.get( 'id', None )
440 host2Id = host2Dict.get( 'id', None )
Jon Hall8f89dda2015-01-22 16:03:33 -0800441 if host1Id and host2Id:
Jon Halla9d26da2015-03-30 16:45:32 -0700442 tmpId = main.ONOScli1.addHostIntent( host1Id, host2Id )
Jon Hall63604932015-02-26 17:09:50 -0800443 if tmpId:
444 main.log.info( "Added intent with id: " + tmpId )
445 intentIds.append( tmpId )
446 else:
Jon Halla9d26da2015-03-30 16:45:32 -0700447 main.log.error( "addHostIntent returned: " +
448 repr( tmpId ) )
Jon Hall669173b2014-12-17 11:36:30 -0800449 else:
Jon Halla9d26da2015-03-30 16:45:32 -0700450 main.log.error( "Error, getHost() failed for h" + str( i ) +
451 " and/or h" + str( i + 10 ) )
452 hosts = main.ONOScli1.hosts()
453 main.log.warn( "Hosts output: " )
454 try:
455 main.log.warn( json.dumps( json.loads( hosts ),
456 sort_keys=True,
457 indent=4,
458 separators=( ',', ': ' ) ) )
459 except ( ValueError, TypeError ):
460 main.log.warn( repr( hosts ) )
Jon Hall58c76b72015-02-23 11:09:24 -0800461 hostResult = main.FALSE
Jon Hallfeff3082015-05-19 10:23:26 -0700462 utilities.assert_equals( expect=main.TRUE, actual=hostResult,
463 onpass="Found a host id for each host",
464 onfail="Error looking up host ids" )
465
Jon Halla9d26da2015-03-30 16:45:32 -0700466 intentStart = time.time()
Jon Hall58c76b72015-02-23 11:09:24 -0800467 onosIds = main.ONOScli1.getAllIntentsId()
468 main.log.info( "Submitted intents: " + str( intentIds ) )
469 main.log.info( "Intents in ONOS: " + str( onosIds ) )
470 for intent in intentIds:
471 if intent in onosIds:
Jon Halla9d26da2015-03-30 16:45:32 -0700472 pass # intent submitted is in onos
Jon Hall58c76b72015-02-23 11:09:24 -0800473 else:
474 intentAddResult = False
Jon Hallb87f3db2015-07-06 03:10:27 -0700475 # FIXME: DEBUG
Jon Halla9d26da2015-03-30 16:45:32 -0700476 if intentAddResult:
477 intentStop = time.time()
478 else:
479 intentStop = None
Jon Hall1b8f54a2015-02-04 13:24:20 -0800480 # Print the intent states
Jon Hall58c76b72015-02-23 11:09:24 -0800481 intents = main.ONOScli1.intents()
Jon Hall1b8f54a2015-02-04 13:24:20 -0800482 intentStates = []
Jon Halla9d26da2015-03-30 16:45:32 -0700483 installedCheck = True
Jon Hall58c76b72015-02-23 11:09:24 -0800484 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
485 count = 0
Jon Hall5cfd23c2015-03-19 11:40:57 -0700486 try:
487 for intent in json.loads( intents ):
488 state = intent.get( 'state', None )
489 if "INSTALLED" not in state:
490 installedCheck = False
491 intentId = intent.get( 'id', None )
492 intentStates.append( ( intentId, state ) )
493 except ( ValueError, TypeError ):
494 main.log.exception( "Error parsing intents" )
Jon Hall58c76b72015-02-23 11:09:24 -0800495 # add submitted intents not in the store
496 tmplist = [ i for i, s in intentStates ]
497 missingIntents = False
498 for i in intentIds:
499 if i not in tmplist:
500 intentStates.append( ( i, " - " ) )
501 missingIntents = True
502 intentStates.sort()
503 for i, s in intentStates:
504 count += 1
505 main.log.info( "%-6s%-15s%-15s" %
506 ( str( count ), str( i ), str( s ) ) )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700507 leaders = main.ONOScli1.leaders()
508 try:
509 if leaders:
510 parsedLeaders = json.loads( leaders )
511 main.log.warn( json.dumps( parsedLeaders,
512 sort_keys=True,
513 indent=4,
514 separators=( ',', ': ' ) ) )
515 # check for all intent partitions
Jon Hall5cfd23c2015-03-19 11:40:57 -0700516 topics = []
517 for i in range( 14 ):
518 topics.append( "intent-partition-" + str( i ) )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700519 main.log.debug( topics )
520 ONOStopics = [ j['topic'] for j in parsedLeaders ]
521 for topic in topics:
522 if topic not in ONOStopics:
523 main.log.error( "Error: " + topic +
524 " not in leaders" )
525 else:
526 main.log.error( "leaders() returned None" )
527 except ( ValueError, TypeError ):
528 main.log.exception( "Error parsing leaders" )
529 main.log.error( repr( leaders ) )
530 partitions = main.ONOScli1.partitions()
531 try:
532 if partitions :
533 parsedPartitions = json.loads( partitions )
534 main.log.warn( json.dumps( parsedPartitions,
535 sort_keys=True,
536 indent=4,
537 separators=( ',', ': ' ) ) )
538 # TODO check for a leader in all paritions
539 # TODO check for consistency among nodes
540 else:
541 main.log.error( "partitions() returned None" )
542 except ( ValueError, TypeError ):
543 main.log.exception( "Error parsing partitions" )
544 main.log.error( repr( partitions ) )
Jon Hall63604932015-02-26 17:09:50 -0800545 pendingMap = main.ONOScli1.pendingMap()
Jon Hall5cfd23c2015-03-19 11:40:57 -0700546 try:
547 if pendingMap :
548 parsedPending = json.loads( pendingMap )
549 main.log.warn( json.dumps( parsedPending,
550 sort_keys=True,
551 indent=4,
552 separators=( ',', ': ' ) ) )
553 # TODO check something here?
554 else:
555 main.log.error( "pendingMap() returned None" )
556 except ( ValueError, TypeError ):
557 main.log.exception( "Error parsing pending map" )
558 main.log.error( repr( pendingMap ) )
559
Jon Hallfeff3082015-05-19 10:23:26 -0700560 intentAddResult = bool( intentAddResult and not missingIntents and
561 installedCheck )
562 if not intentAddResult:
563 main.log.error( "Error in pushing host intents to ONOS" )
564
Jon Hall390696c2015-05-05 17:13:41 -0700565 main.step( "Intent Anti-Entropy dispersion" )
566 for i in range(100):
567 correct = True
568 main.log.info( "Submitted intents: " + str( sorted( intentIds ) ) )
569 for cli in CLIs:
570 onosIds = []
571 ids = cli.getAllIntentsId()
572 onosIds.append( ids )
573 main.log.debug( "Intents in " + cli.name + ": " +
574 str( sorted( onosIds ) ) )
575 if sorted( ids ) != sorted( intentIds ):
576 correct = False
577 if correct:
578 break
579 else:
580 time.sleep(1)
581 if not intentStop:
582 intentStop = time.time()
583 global gossipTime
584 gossipTime = intentStop - intentStart
585 main.log.info( "It took about " + str( gossipTime ) +
586 " seconds for all intents to appear in each node" )
587 # FIXME: make this time configurable/calculate based off of number of
588 # nodes and gossip rounds
589 utilities.assert_greater_equals(
590 expect=40, actual=gossipTime,
591 onpass="ECM anti-entropy for intents worked within " +
592 "expected time",
593 onfail="Intent ECM anti-entropy took too long" )
594 if gossipTime <= 40:
595 intentAddResult = True
Jon Hall58c76b72015-02-23 11:09:24 -0800596
Jon Hall63604932015-02-26 17:09:50 -0800597 if not intentAddResult or "key" in pendingMap:
Jon Hall58c76b72015-02-23 11:09:24 -0800598 import time
Jon Hall63604932015-02-26 17:09:50 -0800599 installedCheck = True
Jon Hall58c76b72015-02-23 11:09:24 -0800600 main.log.info( "Sleeping 60 seconds to see if intents are found" )
601 time.sleep( 60 )
602 onosIds = main.ONOScli1.getAllIntentsId()
603 main.log.info( "Submitted intents: " + str( intentIds ) )
604 main.log.info( "Intents in ONOS: " + str( onosIds ) )
605 # Print the intent states
606 intents = main.ONOScli1.intents()
607 intentStates = []
608 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
609 count = 0
Jon Hall5cfd23c2015-03-19 11:40:57 -0700610 try:
611 for intent in json.loads( intents ):
612 # Iter through intents of a node
613 state = intent.get( 'state', None )
614 if "INSTALLED" not in state:
615 installedCheck = False
616 intentId = intent.get( 'id', None )
617 intentStates.append( ( intentId, state ) )
618 except ( ValueError, TypeError ):
619 main.log.exception( "Error parsing intents" )
Jon Hall58c76b72015-02-23 11:09:24 -0800620 # add submitted intents not in the store
621 tmplist = [ i for i, s in intentStates ]
622 for i in intentIds:
623 if i not in tmplist:
624 intentStates.append( ( i, " - " ) )
625 intentStates.sort()
626 for i, s in intentStates:
627 count += 1
628 main.log.info( "%-6s%-15s%-15s" %
629 ( str( count ), str( i ), str( s ) ) )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700630 leaders = main.ONOScli1.leaders()
631 try:
632 if leaders:
633 parsedLeaders = json.loads( leaders )
634 main.log.warn( json.dumps( parsedLeaders,
635 sort_keys=True,
636 indent=4,
637 separators=( ',', ': ' ) ) )
638 # check for all intent partitions
639 # check for election
640 topics = []
641 for i in range( 14 ):
642 topics.append( "intent-partition-" + str( i ) )
643 # FIXME: this should only be after we start the app
644 topics.append( "org.onosproject.election" )
645 main.log.debug( topics )
646 ONOStopics = [ j['topic'] for j in parsedLeaders ]
647 for topic in topics:
648 if topic not in ONOStopics:
649 main.log.error( "Error: " + topic +
650 " not in leaders" )
651 else:
652 main.log.error( "leaders() returned None" )
653 except ( ValueError, TypeError ):
654 main.log.exception( "Error parsing leaders" )
655 main.log.error( repr( leaders ) )
656 partitions = main.ONOScli1.partitions()
657 try:
658 if partitions :
659 parsedPartitions = json.loads( partitions )
660 main.log.warn( json.dumps( parsedPartitions,
661 sort_keys=True,
662 indent=4,
663 separators=( ',', ': ' ) ) )
664 # TODO check for a leader in all paritions
665 # TODO check for consistency among nodes
666 else:
667 main.log.error( "partitions() returned None" )
668 except ( ValueError, TypeError ):
669 main.log.exception( "Error parsing partitions" )
670 main.log.error( repr( partitions ) )
671 pendingMap = main.ONOScli1.pendingMap()
672 try:
673 if pendingMap :
674 parsedPending = json.loads( pendingMap )
675 main.log.warn( json.dumps( parsedPending,
676 sort_keys=True,
677 indent=4,
678 separators=( ',', ': ' ) ) )
679 # TODO check something here?
680 else:
681 main.log.error( "pendingMap() returned None" )
682 except ( ValueError, TypeError ):
683 main.log.exception( "Error parsing pending map" )
684 main.log.error( repr( pendingMap ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800685
Jon Hall6aec96b2015-01-19 14:49:31 -0800686 def CASE4( self, main ):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800687 """
688 Ping across added host intents
689 """
Jon Hallfebb1c72015-03-05 13:30:09 -0800690 import json
Jon Halla9d26da2015-03-30 16:45:32 -0700691 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -0700692 assert numControllers, "numControllers not defined"
693 assert main, "main not defined"
694 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hallfeff3082015-05-19 10:23:26 -0700695 main.case( "Verify connectivity by sendind traffic across Intents" )
696 main.caseExplaination = "Ping across added host intents to check " +\
697 "functionality and check the state of " +\
698 "the intent"
699 main.step( "Ping across added host intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800700 PingResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800701 for i in range( 8, 18 ):
Jon Hall58c76b72015-02-23 11:09:24 -0800702 ping = main.Mininet1.pingHost( src="h" + str( i ),
703 target="h" + str( i + 10 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800704 PingResult = PingResult and ping
Jon Hall6aec96b2015-01-19 14:49:31 -0800705 if ping == main.FALSE:
706 main.log.warn( "Ping failed between h" + str( i ) +
707 " and h" + str( i + 10 ) )
708 elif ping == main.TRUE:
709 main.log.info( "Ping test passed!" )
Jon Hall21270ac2015-02-16 17:59:55 -0800710 # Don't set PingResult or you'd override failures
Jon Hall8f89dda2015-01-22 16:03:33 -0800711 if PingResult == main.FALSE:
Jon Hall40d2cbd2015-06-03 16:24:29 -0700712 main.log.error(
Jon Hall6aec96b2015-01-19 14:49:31 -0800713 "Intents have not been installed correctly, pings failed." )
Jon Hall58c76b72015-02-23 11:09:24 -0800714 # TODO: pretty print
Jon Hall5cfd23c2015-03-19 11:40:57 -0700715 main.log.warn( "ONOS1 intents: " )
716 try:
717 tmpIntents = main.ONOScli1.intents()
718 main.log.warn( json.dumps( json.loads( tmpIntents ),
719 sort_keys=True,
720 indent=4,
721 separators=( ',', ': ' ) ) )
722 except ( ValueError, TypeError ):
723 main.log.warn( repr( tmpIntents ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800724 utilities.assert_equals(
725 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800726 actual=PingResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800727 onpass="Intents have been installed correctly and pings work",
728 onfail="Intents have not been installed correctly, pings failed." )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800729
Jon Hallfeff3082015-05-19 10:23:26 -0700730 main.step( "Check Intent state" )
Jon Hall63604932015-02-26 17:09:50 -0800731 installedCheck = True
Jon Hallfeff3082015-05-19 10:23:26 -0700732 # Print the intent states
733 intents = main.ONOScli1.intents()
734 intentStates = []
735 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
736 count = 0
737 # Iter through intents of a node
738 try:
739 for intent in json.loads( intents ):
740 state = intent.get( 'state', None )
741 if "INSTALLED" not in state:
742 installedCheck = False
743 intentId = intent.get( 'id', None )
744 intentStates.append( ( intentId, state ) )
745 except ( ValueError, TypeError ):
746 main.log.exception( "Error parsing intents." )
747 # Print states
748 intentStates.sort()
749 for i, s in intentStates:
750 count += 1
751 main.log.info( "%-6s%-15s%-15s" %
752 ( str( count ), str( i ), str( s ) ) )
753 utilities.assert_equals( expect=True, actual=installedCheck,
754 onpass="Intents are all INSTALLED",
Jon Hall40d2cbd2015-06-03 16:24:29 -0700755 onfail="Intents are not all in " +
Jon Hallfeff3082015-05-19 10:23:26 -0700756 "INSTALLED state" )
757
758 main.step( "Check leadership of topics" )
759 leaders = main.ONOScli1.leaders()
760 topicCheck = main.TRUE
761 try:
762 if leaders:
763 parsedLeaders = json.loads( leaders )
764 main.log.warn( json.dumps( parsedLeaders,
765 sort_keys=True,
766 indent=4,
767 separators=( ',', ': ' ) ) )
768 # check for all intent partitions
769 # check for election
770 # TODO: Look at Devices as topics now that it uses this system
771 topics = []
772 for i in range( 14 ):
773 topics.append( "intent-partition-" + str( i ) )
774 # FIXME: this should only be after we start the app
775 # FIXME: topics.append( "org.onosproject.election" )
776 # Print leaders output
777 main.log.debug( topics )
778 ONOStopics = [ j['topic'] for j in parsedLeaders ]
779 for topic in topics:
780 if topic not in ONOStopics:
781 main.log.error( "Error: " + topic +
782 " not in leaders" )
783 topicCheck = main.FALSE
784 else:
785 main.log.error( "leaders() returned None" )
786 topicCheck = main.FALSE
787 except ( ValueError, TypeError ):
788 topicCheck = main.FALSE
789 main.log.exception( "Error parsing leaders" )
790 main.log.error( repr( leaders ) )
791 # TODO: Check for a leader of these topics
792 utilities.assert_equals( expect=main.TRUE, actual=topicCheck,
793 onpass="intent Partitions is in leaders",
794 onfail="Some topics were lost " )
795 # Print partitions
796 partitions = main.ONOScli1.partitions()
797 try:
798 if partitions :
799 parsedPartitions = json.loads( partitions )
800 main.log.warn( json.dumps( parsedPartitions,
801 sort_keys=True,
802 indent=4,
803 separators=( ',', ': ' ) ) )
804 # TODO check for a leader in all paritions
805 # TODO check for consistency among nodes
806 else:
807 main.log.error( "partitions() returned None" )
808 except ( ValueError, TypeError ):
809 main.log.exception( "Error parsing partitions" )
810 main.log.error( repr( partitions ) )
811 # Print Pending Map
812 pendingMap = main.ONOScli1.pendingMap()
813 try:
814 if pendingMap :
815 parsedPending = json.loads( pendingMap )
816 main.log.warn( json.dumps( parsedPending,
817 sort_keys=True,
818 indent=4,
819 separators=( ',', ': ' ) ) )
820 # TODO check something here?
821 else:
822 main.log.error( "pendingMap() returned None" )
823 except ( ValueError, TypeError ):
824 main.log.exception( "Error parsing pending map" )
825 main.log.error( repr( pendingMap ) )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700826
Jon Hall63604932015-02-26 17:09:50 -0800827 if not installedCheck:
Jon Hall5cfd23c2015-03-19 11:40:57 -0700828 main.log.info( "Waiting 60 seconds to see if the state of " +
829 "intents change" )
Jon Hall63604932015-02-26 17:09:50 -0800830 time.sleep( 60 )
831 # Print the intent states
832 intents = main.ONOScli1.intents()
833 intentStates = []
834 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
835 count = 0
836 # Iter through intents of a node
Jon Hall5cfd23c2015-03-19 11:40:57 -0700837 try:
838 for intent in json.loads( intents ):
839 state = intent.get( 'state', None )
840 if "INSTALLED" not in state:
841 installedCheck = False
842 intentId = intent.get( 'id', None )
843 intentStates.append( ( intentId, state ) )
844 except ( ValueError, TypeError ):
845 main.log.exception( "Error parsing intents." )
Jon Hall63604932015-02-26 17:09:50 -0800846 intentStates.sort()
847 for i, s in intentStates:
848 count += 1
849 main.log.info( "%-6s%-15s%-15s" %
850 ( str( count ), str( i ), str( s ) ) )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700851 leaders = main.ONOScli1.leaders()
852 try:
853 if leaders:
854 parsedLeaders = json.loads( leaders )
855 main.log.warn( json.dumps( parsedLeaders,
856 sort_keys=True,
857 indent=4,
858 separators=( ',', ': ' ) ) )
859 # check for all intent partitions
860 # check for election
861 topics = []
862 for i in range( 14 ):
863 topics.append( "intent-partition-" + str( i ) )
864 # FIXME: this should only be after we start the app
865 topics.append( "org.onosproject.election" )
866 main.log.debug( topics )
867 ONOStopics = [ j['topic'] for j in parsedLeaders ]
868 for topic in topics:
869 if topic not in ONOStopics:
870 main.log.error( "Error: " + topic +
871 " not in leaders" )
872 else:
873 main.log.error( "leaders() returned None" )
874 except ( ValueError, TypeError ):
875 main.log.exception( "Error parsing leaders" )
876 main.log.error( repr( leaders ) )
877 partitions = main.ONOScli1.partitions()
878 try:
879 if partitions :
880 parsedPartitions = json.loads( partitions )
881 main.log.warn( json.dumps( parsedPartitions,
882 sort_keys=True,
883 indent=4,
884 separators=( ',', ': ' ) ) )
885 # TODO check for a leader in all paritions
886 # TODO check for consistency among nodes
887 else:
888 main.log.error( "partitions() returned None" )
889 except ( ValueError, TypeError ):
890 main.log.exception( "Error parsing partitions" )
891 main.log.error( repr( partitions ) )
892 pendingMap = main.ONOScli1.pendingMap()
893 try:
894 if pendingMap :
895 parsedPending = json.loads( pendingMap )
896 main.log.warn( json.dumps( parsedPending,
897 sort_keys=True,
898 indent=4,
899 separators=( ',', ': ' ) ) )
900 # TODO check something here?
901 else:
902 main.log.error( "pendingMap() returned None" )
903 except ( ValueError, TypeError ):
904 main.log.exception( "Error parsing pending map" )
905 main.log.error( repr( pendingMap ) )
Jon Hall40d2cbd2015-06-03 16:24:29 -0700906 # Print flowrules
907 main.log.debug( CLIs[0].flows( jsonFormat=False ) )
Jon Hallfeff3082015-05-19 10:23:26 -0700908 main.step( "Wait a minute then ping again" )
Jon Hall40d2cbd2015-06-03 16:24:29 -0700909 # the wait is above
Jon Hallfeff3082015-05-19 10:23:26 -0700910 PingResult = main.TRUE
911 for i in range( 8, 18 ):
912 ping = main.Mininet1.pingHost( src="h" + str( i ),
913 target="h" + str( i + 10 ) )
914 PingResult = PingResult and ping
915 if ping == main.FALSE:
916 main.log.warn( "Ping failed between h" + str( i ) +
917 " and h" + str( i + 10 ) )
918 elif ping == main.TRUE:
919 main.log.info( "Ping test passed!" )
920 # Don't set PingResult or you'd override failures
921 if PingResult == main.FALSE:
Jon Hall40d2cbd2015-06-03 16:24:29 -0700922 main.log.error(
Jon Hallfeff3082015-05-19 10:23:26 -0700923 "Intents have not been installed correctly, pings failed." )
924 # TODO: pretty print
925 main.log.warn( "ONOS1 intents: " )
926 try:
927 tmpIntents = main.ONOScli1.intents()
928 main.log.warn( json.dumps( json.loads( tmpIntents ),
929 sort_keys=True,
930 indent=4,
931 separators=( ',', ': ' ) ) )
932 except ( ValueError, TypeError ):
933 main.log.warn( repr( tmpIntents ) )
934 utilities.assert_equals(
935 expect=main.TRUE,
936 actual=PingResult,
937 onpass="Intents have been installed correctly and pings work",
938 onfail="Intents have not been installed correctly, pings failed." )
939
Jon Hall6aec96b2015-01-19 14:49:31 -0800940 def CASE5( self, main ):
941 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800942 Reading state of ONOS
Jon Hall6aec96b2015-01-19 14:49:31 -0800943 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800944 import json
Jon Hall5cfd23c2015-03-19 11:40:57 -0700945 assert numControllers, "numControllers not defined"
946 assert main, "main not defined"
947 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hallb87f3db2015-07-06 03:10:27 -0700948 # assumes that sts is already in you PYTHONPATH
949 from sts.topology.teston_topology import TestONTopology
Jon Hall73cf9cc2014-11-20 22:28:38 -0800950
Jon Hall6aec96b2015-01-19 14:49:31 -0800951 main.case( "Setting up and gathering data for current state" )
952 # The general idea for this test case is to pull the state of
953 # ( intents,flows, topology,... ) from each ONOS node
Jon Hall5cfd23c2015-03-19 11:40:57 -0700954 # We can then compare them with each other and also with past states
Jon Hall73cf9cc2014-11-20 22:28:38 -0800955
Jon Halla9d26da2015-03-30 16:45:32 -0700956 main.step( "Check that each switch has a master" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800957 global mastershipState
Jon Halla9d26da2015-03-30 16:45:32 -0700958 mastershipState = '[]'
Jon Hall94fd0472014-12-08 11:52:42 -0800959
Jon Hall6aec96b2015-01-19 14:49:31 -0800960 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -0800961 rolesNotNull = main.ONOScli1.rolesNotNull()
Jon Hall6aec96b2015-01-19 14:49:31 -0800962 utilities.assert_equals(
963 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800964 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -0800965 onpass="Each device has a master",
966 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -0800967
Jon Hall390696c2015-05-05 17:13:41 -0700968 main.step( "Get the Mastership of each switch" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800969 ONOS1Mastership = main.ONOScli1.roles()
Jon Hall6aec96b2015-01-19 14:49:31 -0800970 # TODO: Make this a meaningful check
Jon Hall8f89dda2015-01-22 16:03:33 -0800971 if "Error" in ONOS1Mastership or not ONOS1Mastership:
Jon Hall40d2cbd2015-06-03 16:24:29 -0700972 main.log.error( "Error in getting ONOS roles" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800973 main.log.warn(
974 "ONOS1 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800975 repr( ONOS1Mastership ) )
976 consistentMastership = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800977 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800978 mastershipState = ONOS1Mastership
979 consistentMastership = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800980
Jon Hall6aec96b2015-01-19 14:49:31 -0800981 main.step( "Get the intents from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800982 global intentState
983 intentState = []
984 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
985 intentCheck = main.FALSE
986 if "Error" in ONOS1Intents or not ONOS1Intents:
Jon Hall40d2cbd2015-06-03 16:24:29 -0700987 main.log.error( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800988 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800989 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800990 intentCheck = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800991
Jon Hall6aec96b2015-01-19 14:49:31 -0800992 main.step( "Get the flows from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800993 global flowState
994 flowState = []
Jon Hall8f89dda2015-01-22 16:03:33 -0800995 flowCheck = main.FALSE
Jon Hall58c76b72015-02-23 11:09:24 -0800996 ONOS1Flows = main.ONOScli1.flows( jsonFormat=True )
Jon Hall8f89dda2015-01-22 16:03:33 -0800997 if "Error" in ONOS1Flows or not ONOS1Flows:
Jon Hall40d2cbd2015-06-03 16:24:29 -0700998 main.log.error( "Error in getting ONOS flows" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800999 main.log.warn( "ONOS1 flows repsponse: " + ONOS1Flows )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001000 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001001 # TODO: Do a better check, maybe compare flows on switches?
Jon Hall8f89dda2015-01-22 16:03:33 -08001002 flowState = ONOS1Flows
1003 flowCheck = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001004
Jon Hall6aec96b2015-01-19 14:49:31 -08001005 main.step( "Get the OF Table entries" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001006 global flows
Jon Hall6aec96b2015-01-19 14:49:31 -08001007 flows = []
1008 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -08001009 flows.append( main.Mininet2.getFlowTable( 1.3, "s" + str( i ) ) )
Jon Hall58c76b72015-02-23 11:09:24 -08001010 if flowCheck == main.FALSE:
1011 for table in flows:
1012 main.log.warn( table )
Jon Hall6aec96b2015-01-19 14:49:31 -08001013 # TODO: Compare switch flow tables with ONOS flow tables
Jon Hall73cf9cc2014-11-20 22:28:38 -08001014
Jon Hallb87f3db2015-07-06 03:10:27 -07001015 main.step( "Create TestONTopology object" )
1016 ctrls = []
1017 temp = ( nodes[0], nodes[0].name, nodes[0].ip_address, 6633 )
1018 ctrls.append( temp )
1019 MNTopo = TestONTopology( main.Mininet1, ctrls )
1020
Jon Hall6aec96b2015-01-19 14:49:31 -08001021 main.step( "Collecting topology information from ONOS" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001022 devices = []
1023 devices.append( main.ONOScli1.devices() )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001024 hosts = []
Jon Hall58c76b72015-02-23 11:09:24 -08001025 hosts.append( json.loads( main.ONOScli1.hosts() ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001026 ports = []
1027 ports.append( main.ONOScli1.ports() )
1028 links = []
1029 links.append( main.ONOScli1.links() )
Jon Hall58c76b72015-02-23 11:09:24 -08001030 clusters = []
1031 clusters.append( main.ONOScli1.clusters() )
Jon Hall390696c2015-05-05 17:13:41 -07001032
1033 main.step( "Each host has an IP address" )
Jon Hall58c76b72015-02-23 11:09:24 -08001034 ipResult = main.TRUE
1035 for controller in range( 0, len( hosts ) ):
1036 controllerStr = str( controller + 1 )
1037 for host in hosts[ controller ]:
Jon Hallfeff3082015-05-19 10:23:26 -07001038 if host is None or host.get( 'ipAddresses', [] ) == []:
Jon Hall58c76b72015-02-23 11:09:24 -08001039 main.log.error(
1040 "DEBUG:Error with host ips on controller" +
1041 controllerStr + ": " + str( host ) )
1042 ipResult = main.FALSE
Jon Hall390696c2015-05-05 17:13:41 -07001043 utilities.assert_equals(
1044 expect=main.TRUE,
1045 actual=ipResult,
1046 onpass="The ips of the hosts aren't empty",
1047 onfail="The ip of at least one host is missing" )
Jon Hall58c76b72015-02-23 11:09:24 -08001048
1049 # there should always only be one cluster
Jon Hall390696c2015-05-05 17:13:41 -07001050 main.step( "There is only one dataplane cluster" )
1051 try:
1052 numClusters = len( json.loads( clusters[ 0 ] ) )
1053 except ( ValueError, TypeError ):
1054 main.log.exception( "Error parsing clusters[0]: " +
1055 repr( clusters[ 0 ] ) )
Jon Hall58c76b72015-02-23 11:09:24 -08001056 clusterResults = main.FALSE
1057 if numClusters == 1:
1058 clusterResults = main.TRUE
1059 utilities.assert_equals(
1060 expect=1,
1061 actual=numClusters,
1062 onpass="ONOS shows 1 SCC",
1063 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001064
Jon Hall6aec96b2015-01-19 14:49:31 -08001065 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001066 devicesResults = main.TRUE
Jon Hallb87f3db2015-07-06 03:10:27 -07001067 portsResults = main.TRUE
Jon Hall8f89dda2015-01-22 16:03:33 -08001068 linksResults = main.TRUE
Jon Hall58c76b72015-02-23 11:09:24 -08001069 hostsResults = main.TRUE
Jon Hall8f89dda2015-01-22 16:03:33 -08001070 for controller in range( numControllers ):
1071 controllerStr = str( controller + 1 )
Jon Hallb87f3db2015-07-06 03:10:27 -07001072 if devices[ controller ] or "Error" not in devices[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001073 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hallb87f3db2015-07-06 03:10:27 -07001074 MNTopo,
1075 json.loads( devices[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001076 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001077 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001078 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001079 actual=currentDevicesResult,
1080 onpass="ONOS" + controllerStr +
1081 " Switches view is correct",
1082 onfail="ONOS" + controllerStr +
1083 " Switches view is incorrect" )
Jon Hallb87f3db2015-07-06 03:10:27 -07001084
1085 if ports[ controller ] or "Error" not in ports[ controller ]:
1086 currentPortsResult = main.Mininet1.comparePorts(
1087 MNTopo,
1088 json.loads( ports[ controller ] ) )
1089 else:
1090 currentPortsResult = main.FALSE
1091 utilities.assert_equals( expect=main.TRUE,
1092 actual=currentPortsResult,
1093 onpass="ONOS" + controllerStr +
1094 " ports view is correct",
1095 onfail="ONOS" + controllerStr +
1096 " ports view is incorrect" )
1097
1098 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001099 currentLinksResult = main.Mininet1.compareLinks(
Jon Hallb87f3db2015-07-06 03:10:27 -07001100 MNTopo,
1101 json.loads( links[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001102 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001103 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001104 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001105 actual=currentLinksResult,
1106 onpass="ONOS" + controllerStr +
1107 " links view is correct",
1108 onfail="ONOS" + controllerStr +
1109 " links view is incorrect" )
1110
1111 if hosts[ controller ] or "Error" not in hosts[ controller ]:
1112 currentHostsResult = main.Mininet1.compareHosts(
Jon Hallb87f3db2015-07-06 03:10:27 -07001113 MNTopo, hosts[ controller ] )
Jon Hall58c76b72015-02-23 11:09:24 -08001114 else:
1115 currentHostsResult = main.FALSE
1116 utilities.assert_equals( expect=main.TRUE,
1117 actual=currentHostsResult,
1118 onpass="ONOS" + controllerStr +
1119 " hosts exist in Mininet",
1120 onfail="ONOS" + controllerStr +
1121 " hosts don't match Mininet" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001122
Jon Hall8f89dda2015-01-22 16:03:33 -08001123 devicesResults = devicesResults and currentDevicesResult
Jon Hallb87f3db2015-07-06 03:10:27 -07001124 portsResults = portsResults and currentPortsResult
Jon Hall8f89dda2015-01-22 16:03:33 -08001125 linksResults = linksResults and currentLinksResult
Jon Hall58c76b72015-02-23 11:09:24 -08001126 hostsResults = hostsResults and currentHostsResult
Jon Hall73cf9cc2014-11-20 22:28:38 -08001127
Jon Hallb87f3db2015-07-06 03:10:27 -07001128 topoResult = devicesResults and portsResults and linksResults\
1129 and clusterResults and ipResult and hostsResults
1130 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
1131 onpass="Topology Check Test successful",
1132 onfail="Topology Check Test NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001133
Jon Hall6aec96b2015-01-19 14:49:31 -08001134 def CASE6( self, main ):
1135 """
Jon Hallffb386d2014-11-21 13:43:38 -08001136 The Failure case.
Jon Hall6aec96b2015-01-19 14:49:31 -08001137 """
Jon Hallffb386d2014-11-21 13:43:38 -08001138 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001139 assert numControllers, "numControllers not defined"
1140 assert main, "main not defined"
1141 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall73cf9cc2014-11-20 22:28:38 -08001142
Jon Hall390696c2015-05-05 17:13:41 -07001143 # Reset non-persistent variables
1144 try:
1145 iCounterValue = 0
1146 except NameError:
1147 main.log.error( "iCounterValue not defined, setting to 0" )
1148 iCounterValue = 0
1149
Jon Hallfeff3082015-05-19 10:23:26 -07001150 main.case( "Restart ONOS node" )
1151 main.caseExplaination = "Killing ONOS process and restart cli " +\
1152 "sessions once onos is up."
Jon Hall390696c2015-05-05 17:13:41 -07001153 main.step( "Killing ONOS processes" )
1154 killResult = main.ONOSbench.onosKill( ONOS1Ip )
Jon Hallffb386d2014-11-21 13:43:38 -08001155 start = time.time()
Jon Hall390696c2015-05-05 17:13:41 -07001156 utilities.assert_equals( expect=main.TRUE, actual=killResult,
1157 onpass="ONOS Killed",
1158 onfail="Error killing ONOS" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001159
Jon Hall6aec96b2015-01-19 14:49:31 -08001160 main.step( "Checking if ONOS is up yet" )
Jon Hallffb386d2014-11-21 13:43:38 -08001161 count = 0
Jon Hall94fd0472014-12-08 11:52:42 -08001162 while count < 10:
Jon Hall8f89dda2015-01-22 16:03:33 -08001163 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
1164 if onos1Isup == main.TRUE:
Jon Hallffb386d2014-11-21 13:43:38 -08001165 elapsed = time.time() - start
1166 break
1167 else:
1168 count = count + 1
Jon Hall390696c2015-05-05 17:13:41 -07001169 utilities.assert_equals( expect=main.TRUE, actual=onos1Isup,
1170 onpass="ONOS is back up",
1171 onfail="ONOS failed to start" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001172
Jon Hall390696c2015-05-05 17:13:41 -07001173 main.log.step( "Starting ONOS CLI sessions" )
1174 cliResults = main.ONOScli1.startOnosCli( ONOS1Ip )
1175 utilities.assert_equals( expect=main.TRUE, actual=cliResults,
1176 onpass="ONOS cli startup successful",
1177 onfail="ONOS cli startup failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001178
Jon Hallfebb1c72015-03-05 13:30:09 -08001179 if elapsed:
1180 main.log.info( "ESTIMATE: ONOS took %s seconds to restart" %
1181 str( elapsed ) )
Jon Hall40d2cbd2015-06-03 16:24:29 -07001182 main.restartTime = elapsed
1183 else:
1184 main.restartTime = -1
Jon Hall6aec96b2015-01-19 14:49:31 -08001185 time.sleep( 5 )
Jon Hallfeff3082015-05-19 10:23:26 -07001186 # rerun on election apps
1187 main.ONOScli1.electionTestRun()
Jon Hall73cf9cc2014-11-20 22:28:38 -08001188
Jon Hall6aec96b2015-01-19 14:49:31 -08001189 def CASE7( self, main ):
1190 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001191 Check state after ONOS failure
Jon Hall6aec96b2015-01-19 14:49:31 -08001192 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001193 import json
Jon Hall5cfd23c2015-03-19 11:40:57 -07001194 assert numControllers, "numControllers not defined"
1195 assert main, "main not defined"
1196 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -08001197 main.case( "Running ONOS Constant State Tests" )
Jon Hall390696c2015-05-05 17:13:41 -07001198 main.step( "Check that each switch has a master" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001199 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -08001200 rolesNotNull = main.ONOScli1.rolesNotNull()
Jon Hall6aec96b2015-01-19 14:49:31 -08001201 utilities.assert_equals(
1202 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001203 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -08001204 onpass="Each device has a master",
1205 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -08001206
Jon Hall6aec96b2015-01-19 14:49:31 -08001207 main.step( "Check if switch roles are consistent across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001208 ONOS1Mastership = main.ONOScli1.roles()
Jon Hall6aec96b2015-01-19 14:49:31 -08001209 # FIXME: Refactor this whole case for single instance
Jon Hall8f89dda2015-01-22 16:03:33 -08001210 if "Error" in ONOS1Mastership or not ONOS1Mastership:
Jon Hall40d2cbd2015-06-03 16:24:29 -07001211 main.log.error( "Error in getting ONOS mastership" )
Jon Hall58c76b72015-02-23 11:09:24 -08001212 main.log.warn( "ONOS1 mastership response: " +
1213 repr( ONOS1Mastership ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001214 consistentMastership = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001215 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001216 consistentMastership = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001217 utilities.assert_equals(
1218 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001219 actual=consistentMastership,
Jon Hall6aec96b2015-01-19 14:49:31 -08001220 onpass="Switch roles are consistent across all ONOS nodes",
1221 onfail="ONOS nodes have different views of switch roles" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001222
1223 description2 = "Compare switch roles from before failure"
Jon Hall6aec96b2015-01-19 14:49:31 -08001224 main.step( description2 )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001225
Jon Hall8f89dda2015-01-22 16:03:33 -08001226 currentJson = json.loads( ONOS1Mastership )
1227 oldJson = json.loads( mastershipState )
1228 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001229 for i in range( 1, 29 ):
1230 switchDPID = str(
Jon Hall58c76b72015-02-23 11:09:24 -08001231 main.Mininet1.getSwitchDPID( switch="s" + str( i ) ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001232
Jon Hall8f89dda2015-01-22 16:03:33 -08001233 current = [ switch[ 'master' ] for switch in currentJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001234 if switchDPID in switch[ 'id' ] ]
Jon Hall8f89dda2015-01-22 16:03:33 -08001235 old = [ switch[ 'master' ] for switch in oldJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001236 if switchDPID in switch[ 'id' ] ]
Jon Hall73cf9cc2014-11-20 22:28:38 -08001237 if current == old:
Jon Hall8f89dda2015-01-22 16:03:33 -08001238 mastershipCheck = mastershipCheck and main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001239 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001240 main.log.warn( "Mastership of switch %s changed" % switchDPID )
Jon Hall8f89dda2015-01-22 16:03:33 -08001241 mastershipCheck = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001242 utilities.assert_equals(
1243 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001244 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -08001245 onpass="Mastership of Switches was not changed",
1246 onfail="Mastership of some switches changed" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001247 mastershipCheck = mastershipCheck and consistentMastership
Jon Hall73cf9cc2014-11-20 22:28:38 -08001248
Jon Hall6aec96b2015-01-19 14:49:31 -08001249 main.step( "Get the intents and compare across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001250 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
1251 intentCheck = main.FALSE
1252 if "Error" in ONOS1Intents or not ONOS1Intents:
Jon Hall40d2cbd2015-06-03 16:24:29 -07001253 main.log.error( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001254 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001255 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001256 intentCheck = main.TRUE
Jon Hallb87f3db2015-07-06 03:10:27 -07001257 main.log.error( "Intents are consistent across all ONOS nodes" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001258 utilities.assert_equals(
1259 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001260 actual=intentCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -08001261 onpass="Intents are consistent across all ONOS nodes",
1262 onfail="ONOS nodes have different views of intents" )
Jon Hall1b8f54a2015-02-04 13:24:20 -08001263 # Print the intent states
1264 intents = []
1265 intents.append( ONOS1Intents )
1266 intentStates = []
1267 for node in intents: # Iter through ONOS nodes
1268 nodeStates = []
Jon Hall58c76b72015-02-23 11:09:24 -08001269 # Iter through intents of a node
1270 for intent in json.loads( node ):
Jon Hall1b8f54a2015-02-04 13:24:20 -08001271 nodeStates.append( intent[ 'state' ] )
1272 intentStates.append( nodeStates )
1273 out = [ (i, nodeStates.count( i ) ) for i in set( nodeStates ) ]
1274 main.log.info( dict( out ) )
1275
Jon Hall58c76b72015-02-23 11:09:24 -08001276 # NOTE: Store has no durability, so intents are lost across system
1277 # restarts
Jon Hall6aec96b2015-01-19 14:49:31 -08001278 """
1279 main.step( "Compare current intents with intents before the failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001280 # NOTE: this requires case 5 to pass for intentState to be set.
Jon Hall6aec96b2015-01-19 14:49:31 -08001281 # maybe we should stop the test if that fails?
Jon Hall40d2cbd2015-06-03 16:24:29 -07001282 sameIntents = main.FALSE
1283 if intentState and intentState == ONOSIntents[ 0 ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001284 sameIntents = main.TRUE
Jon Hallfeff3082015-05-19 10:23:26 -07001285 main.log.info( "Intents are consistent with before failure" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001286 # TODO: possibly the states have changed? we may need to figure out
Jon Hallfeff3082015-05-19 10:23:26 -07001287 # what the acceptable states are
Jon Hall40d2cbd2015-06-03 16:24:29 -07001288 elif len( intentState ) == len( ONOSIntents[ 0 ] ):
1289 sameIntents = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001290 try:
Jon Hall40d2cbd2015-06-03 16:24:29 -07001291 before = json.loads( intentState )
1292 after = json.loads( ONOSIntents[ 0 ] )
1293 for intent in before:
1294 if intent not in after:
1295 sameIntents = main.FALSE
Jon Hallc9eabec2015-06-10 14:33:14 -07001296 main.log.debug( "Intent is not currently in ONOS " +
Jon Hall40d2cbd2015-06-03 16:24:29 -07001297 "(at least in the same form):" )
1298 main.log.debug( json.dumps( intent ) )
1299 except ( ValueError, TypeError ):
1300 main.log.exception( "Exception printing intents" )
1301 main.log.debug( repr( ONOSIntents[0] ) )
1302 main.log.debug( repr( intentState ) )
1303 if sameIntents == main.FALSE:
1304 try:
1305 main.log.debug( "ONOS intents before: " )
1306 main.log.debug( json.dumps( json.loads( intentState ),
1307 sort_keys=True, indent=4,
1308 separators=( ',', ': ' ) ) )
1309 main.log.debug( "Current ONOS intents: " )
1310 main.log.debug( json.dumps( json.loads( ONOSIntents[ 0 ] ),
1311 sort_keys=True, indent=4,
1312 separators=( ',', ': ' ) ) )
1313 except ( ValueError, TypeError ):
1314 main.log.exception( "Exception printing intents" )
1315 main.log.debug( repr( ONOSIntents[0] ) )
1316 main.log.debug( repr( intentState ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001317 utilities.assert_equals(
1318 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001319 actual=sameIntents,
Jon Hall6aec96b2015-01-19 14:49:31 -08001320 onpass="Intents are consistent with before failure",
1321 onfail="The Intents changed during failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001322 intentCheck = intentCheck and sameIntents
Jon Hall6aec96b2015-01-19 14:49:31 -08001323 """
1324 main.step( "Get the OF Table entries and compare to before " +
1325 "component failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001326 FlowTables = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001327 flows2 = []
1328 for i in range( 28 ):
1329 main.log.info( "Checking flow table on s" + str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001330 tmpFlows = main.Mininet2.getFlowTable( 1.3, "s" + str( i + 1 ) )
1331 flows2.append( tmpFlows )
1332 tempResult = main.Mininet2.flowComp(
Jon Hall6aec96b2015-01-19 14:49:31 -08001333 flow1=flows[ i ],
Jon Hall8f89dda2015-01-22 16:03:33 -08001334 flow2=tmpFlows )
1335 FlowTables = FlowTables and tempResult
1336 if FlowTables == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001337 main.log.info( "Differences in flow table for switch: s" +
1338 str( i + 1 ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001339 utilities.assert_equals(
1340 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001341 actual=FlowTables,
Jon Hall6aec96b2015-01-19 14:49:31 -08001342 onpass="No changes were found in the flow tables",
1343 onfail="Changes were found in the flow tables" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001344
Jon Hallfeff3082015-05-19 10:23:26 -07001345 main.step( "Leadership Election is still functional" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001346 # Test of LeadershipElection
Jon Hall669173b2014-12-17 11:36:30 -08001347
Jon Hall8f89dda2015-01-22 16:03:33 -08001348 leader = ONOS1Ip
1349 leaderResult = main.TRUE
1350 for controller in range( 1, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001351 # loop through ONOScli handlers
1352 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001353 leaderN = node.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001354 # verify leader is ONOS1
1355 # NOTE even though we restarted ONOS, it is the only one so onos 1
1356 # must be leader
Jon Hall669173b2014-12-17 11:36:30 -08001357 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08001358 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001359 pass
1360 elif leaderN == main.FALSE:
Jon Hallfeff3082015-05-19 10:23:26 -07001361 # error in response
Jon Hall40d2cbd2015-06-03 16:24:29 -07001362 main.log.error( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001363 "electionTestLeader function, check the" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001364 " error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001365 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001366 elif leader != leaderN:
Jon Hall8f89dda2015-01-22 16:03:33 -08001367 leaderResult = main.FALSE
Jon Hall40d2cbd2015-06-03 16:24:29 -07001368 main.log.error( "ONOS" + str( controller ) + " sees " +
Jon Hall58c76b72015-02-23 11:09:24 -08001369 str( leaderN ) +
1370 " as the leader of the election app. " +
1371 "Leader should be " + str( leader ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001372 utilities.assert_equals(
1373 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001374 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001375 onpass="Leadership election passed",
1376 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08001377
Jon Hall6aec96b2015-01-19 14:49:31 -08001378 def CASE8( self, main ):
1379 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001380 Compare topo
Jon Hall6aec96b2015-01-19 14:49:31 -08001381 """
Jon Hallb87f3db2015-07-06 03:10:27 -07001382 import sys
1383 # FIXME add this path to params
1384 sys.path.append( "/home/admin/sts" )
1385 # assumes that sts is already in you PYTHONPATH
1386 from sts.topology.teston_topology import TestONTopology
Jon Hall73cf9cc2014-11-20 22:28:38 -08001387 import json
1388 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001389 assert numControllers, "numControllers not defined"
1390 assert main, "main not defined"
1391 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall73cf9cc2014-11-20 22:28:38 -08001392
Jon Hallfeff3082015-05-19 10:23:26 -07001393 main.case( "Compare ONOS Topology view to Mininet topology" )
1394 main.caseExplaination = "Compare topology objects between Mininet" +\
1395 " and ONOS"
Jon Hallb87f3db2015-07-06 03:10:27 -07001396 main.step( "Create TestONTopology object" )
1397 try:
1398 ctrls = []
1399 node = main.ONOS1
1400 temp = ( node, node.name, node.ip_address, 6633 )
1401 ctrls.append( temp )
1402 MNTopo = TestONTopology( main.Mininet1, ctrls )
1403 except Exception:
1404 objResult = main.FALSE
1405 else:
1406 objResult = main.TRUE
1407 utilities.assert_equals( expect=main.TRUE, actual=objResult,
1408 onpass="Created TestONTopology object",
1409 onfail="Exception while creating " +
1410 "TestONTopology object" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001411
Jon Hall6aec96b2015-01-19 14:49:31 -08001412 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001413 devicesResults = main.TRUE
Jon Hallb87f3db2015-07-06 03:10:27 -07001414 portsResults = main.TRUE
Jon Hall8f89dda2015-01-22 16:03:33 -08001415 linksResults = main.TRUE
Jon Hall58c76b72015-02-23 11:09:24 -08001416 hostsResults = main.TRUE
Jon Hall8f89dda2015-01-22 16:03:33 -08001417 topoResult = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001418 elapsed = 0
Jon Hallffb386d2014-11-21 13:43:38 -08001419 count = 0
Jon Hall6aec96b2015-01-19 14:49:31 -08001420 main.step( "Collecting topology information from ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001421 startTime = time.time()
Jon Hall58c76b72015-02-23 11:09:24 -08001422 # Give time for Gossip to work
Jon Hall8f89dda2015-01-22 16:03:33 -08001423 while topoResult == main.FALSE and elapsed < 60:
Jon Halla9d26da2015-03-30 16:45:32 -07001424 count += 1
Jon Hallb87f3db2015-07-06 03:10:27 -07001425 if count > 1:
1426 # TODO: Deprecate STS usage
1427 MNTopo = TestONTopology( main.Mininet1, ctrls )
Jon Hall8f89dda2015-01-22 16:03:33 -08001428 cliStart = time.time()
Jon Hall94fd0472014-12-08 11:52:42 -08001429 devices = []
1430 devices.append( main.ONOScli1.devices() )
Jon Hall94fd0472014-12-08 11:52:42 -08001431 hosts = []
Jon Hall58c76b72015-02-23 11:09:24 -08001432 hosts.append( json.loads( main.ONOScli1.hosts() ) )
1433 ipResult = main.TRUE
1434 for controller in range( 0, len( hosts ) ):
1435 controllerStr = str( controller + 1 )
1436 for host in hosts[ controller ]:
Jon Hallfeff3082015-05-19 10:23:26 -07001437 if host is None or host.get( 'ipAddresses', [] ) == []:
Jon Hall58c76b72015-02-23 11:09:24 -08001438 main.log.error(
1439 "DEBUG:Error with host ips on controller" +
1440 controllerStr + ": " + str( host ) )
1441 ipResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001442 ports = []
1443 ports.append( main.ONOScli1.ports() )
1444 links = []
1445 links.append( main.ONOScli1.links() )
Jon Hall58c76b72015-02-23 11:09:24 -08001446 clusters = []
1447 clusters.append( main.ONOScli1.clusters() )
1448
Jon Hall8f89dda2015-01-22 16:03:33 -08001449 elapsed = time.time() - startTime
1450 cliTime = time.time() - cliStart
1451 print "CLI time: " + str( cliTime )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001452
Jon Hall8f89dda2015-01-22 16:03:33 -08001453 for controller in range( numControllers ):
1454 controllerStr = str( controller + 1 )
Jon Hallb87f3db2015-07-06 03:10:27 -07001455 if devices[ controller ] or "Error" not in devices[
1456 controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001457 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hallb87f3db2015-07-06 03:10:27 -07001458 MNTopo,
1459 json.loads( devices[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001460 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001461 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001462 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001463 actual=currentDevicesResult,
1464 onpass="ONOS" + controllerStr +
1465 " Switches view is correct",
1466 onfail="ONOS" + controllerStr +
1467 " Switches view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001468
Jon Hallb87f3db2015-07-06 03:10:27 -07001469 if ports[ controller ] or "Error" not in ports[ controller ]:
1470 currentPortsResult = main.Mininet1.comparePorts(
1471 MNTopo,
1472 json.loads( ports[ controller ] ) )
1473 else:
1474 currentPortsResult = main.FALSE
1475 utilities.assert_equals( expect=main.TRUE,
1476 actual=currentPortsResult,
1477 onpass="ONOS" + controllerStr +
1478 " ports view is correct",
1479 onfail="ONOS" + controllerStr +
1480 " ports view is incorrect" )
1481
1482 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001483 currentLinksResult = main.Mininet1.compareLinks(
Jon Hallb87f3db2015-07-06 03:10:27 -07001484 MNTopo,
1485 json.loads( links[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001486 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001487 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001488 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001489 actual=currentLinksResult,
1490 onpass="ONOS" + controllerStr +
1491 " links view is correct",
1492 onfail="ONOS" + controllerStr +
1493 " links view is incorrect" )
1494
1495 if hosts[ controller ] or "Error" not in hosts[ controller ]:
1496 currentHostsResult = main.Mininet1.compareHosts(
Jon Hallb87f3db2015-07-06 03:10:27 -07001497 MNTopo, hosts[ controller ] )
Jon Hall58c76b72015-02-23 11:09:24 -08001498 else:
1499 currentHostsResult = main.FALSE
1500 utilities.assert_equals( expect=main.TRUE,
1501 actual=currentHostsResult,
1502 onpass="ONOS" + controllerStr +
1503 " hosts exist in Mininet",
1504 onfail="ONOS" + controllerStr +
1505 " hosts don't match Mininet" )
1506
1507 devicesResults = devicesResults and currentDevicesResult
Jon Hallb87f3db2015-07-06 03:10:27 -07001508 portsResults = portsResults and currentPortsResult
Jon Hall58c76b72015-02-23 11:09:24 -08001509 linksResults = linksResults and currentLinksResult
1510 hostsResults = hostsResults and currentHostsResult
1511
Jon Hall63604932015-02-26 17:09:50 -08001512 # "consistent" results don't make sense for single instance
Jon Hall58c76b72015-02-23 11:09:24 -08001513 # there should always only be one cluster
1514 numClusters = len( json.loads( clusters[ 0 ] ) )
1515 clusterResults = main.FALSE
1516 if numClusters == 1:
1517 clusterResults = main.TRUE
1518 utilities.assert_equals(
1519 expect=1,
1520 actual=numClusters,
1521 onpass="ONOS shows 1 SCC",
1522 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
1523
Jon Hallb87f3db2015-07-06 03:10:27 -07001524 topoResult = ( devicesResults and portsResults and linksResults
1525 and hostsResults and ipResult and clusterResults )
Jon Hall94fd0472014-12-08 11:52:42 -08001526
Jon Hall8f89dda2015-01-22 16:03:33 -08001527 topoResult = topoResult and int( count <= 2 )
1528 note = "note it takes about " + str( int( cliTime ) ) + \
1529 " seconds for the test to make all the cli calls to fetch " +\
1530 "the topology from each ONOS instance"
Jon Hall1b8f54a2015-02-04 13:24:20 -08001531 main.log.info(
Jon Hall8f89dda2015-01-22 16:03:33 -08001532 "Very crass estimate for topology discovery/convergence( " +
1533 str( note ) + " ): " + str( elapsed ) + " seconds, " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001534 str( count ) + " tries" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001535 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
Jon Hall58c76b72015-02-23 11:09:24 -08001536 onpass="Topology Check Test successful",
1537 onfail="Topology Check Test NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001538
Jon Hall6aec96b2015-01-19 14:49:31 -08001539 def CASE9( self, main ):
1540 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001541 Link s3-s28 down
Jon Hall6aec96b2015-01-19 14:49:31 -08001542 """
1543 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001544 assert numControllers, "numControllers not defined"
1545 assert main, "main not defined"
1546 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -08001547 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001548
Jon Hall8f89dda2015-01-22 16:03:33 -08001549 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001550
Jon Hall6aec96b2015-01-19 14:49:31 -08001551 description = "Turn off a link to ensure that Link Discovery " +\
Jon Hall58c76b72015-02-23 11:09:24 -08001552 "is working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001553 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001554
Jon Hall6aec96b2015-01-19 14:49:31 -08001555 main.step( "Kill Link between s3 and s28" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001556 LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" )
Jon Hall58c76b72015-02-23 11:09:24 -08001557 main.log.info( "Waiting " + str( linkSleep ) +
1558 " seconds for link down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001559 time.sleep( linkSleep )
1560 utilities.assert_equals( expect=main.TRUE, actual=LinkDown,
Jon Halla9d26da2015-03-30 16:45:32 -07001561 onpass="Link down successful",
Jon Hall58c76b72015-02-23 11:09:24 -08001562 onfail="Failed to bring link down" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001563 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -08001564
Jon Hall6aec96b2015-01-19 14:49:31 -08001565 def CASE10( self, main ):
1566 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001567 Link s3-s28 up
Jon Hall6aec96b2015-01-19 14:49:31 -08001568 """
1569 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001570 assert numControllers, "numControllers not defined"
1571 assert main, "main not defined"
1572 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -08001573 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001574
Jon Hall8f89dda2015-01-22 16:03:33 -08001575 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001576
Jon Hall6aec96b2015-01-19 14:49:31 -08001577 description = "Restore a link to ensure that Link Discovery is " + \
Jon Hall58c76b72015-02-23 11:09:24 -08001578 "working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001579 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001580
Jon Hall6aec96b2015-01-19 14:49:31 -08001581 main.step( "Bring link between s3 and s28 back up" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001582 LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" )
Jon Hall58c76b72015-02-23 11:09:24 -08001583 main.log.info( "Waiting " + str( linkSleep ) +
1584 " seconds for link up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001585 time.sleep( linkSleep )
1586 utilities.assert_equals( expect=main.TRUE, actual=LinkUp,
Jon Halla9d26da2015-03-30 16:45:32 -07001587 onpass="Link up successful",
Jon Hall58c76b72015-02-23 11:09:24 -08001588 onfail="Failed to bring link up" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001589 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -08001590
Jon Hall6aec96b2015-01-19 14:49:31 -08001591 def CASE11( self, main ):
1592 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001593 Switch Down
Jon Hall6aec96b2015-01-19 14:49:31 -08001594 """
1595 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001596 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001597 assert numControllers, "numControllers not defined"
1598 assert main, "main not defined"
1599 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall73cf9cc2014-11-20 22:28:38 -08001600
Jon Hall8f89dda2015-01-22 16:03:33 -08001601 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001602
1603 description = "Killing a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001604 main.case( description )
1605 switch = main.params[ 'kill' ][ 'switch' ]
1606 switchDPID = main.params[ 'kill' ][ 'dpid' ]
Jon Hall73cf9cc2014-11-20 22:28:38 -08001607
Jon Hall6aec96b2015-01-19 14:49:31 -08001608 # TODO: Make this switch parameterizable
1609 main.step( "Kill " + switch )
Jon Hall40d2cbd2015-06-03 16:24:29 -07001610 main.log.info( "Deleting " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001611 main.Mininet1.delSwitch( switch )
1612 main.log.info( "Waiting " + str( switchSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001613 " seconds for switch down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001614 time.sleep( switchSleep )
1615 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001616 # Peek at the deleted switch
1617 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001618 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001619 if device and device[ 'available' ] is False:
Jon Hall94fd0472014-12-08 11:52:42 -08001620 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001621 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Halla9d26da2015-03-30 16:45:32 -07001622 onpass="Kill switch successful",
Jon Hall58c76b72015-02-23 11:09:24 -08001623 onfail="Failed to kill switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001624
Jon Hall6aec96b2015-01-19 14:49:31 -08001625 def CASE12( self, main ):
1626 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001627 Switch Up
Jon Hall6aec96b2015-01-19 14:49:31 -08001628 """
1629 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001630 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001631 assert numControllers, "numControllers not defined"
1632 assert main, "main not defined"
1633 assert utilities.assert_equals, "utilities.assert_equals not defined"
1634 assert ONOS1Port, "ONOS1Port not defined"
1635 assert ONOS2Port, "ONOS2Port not defined"
1636 assert ONOS3Port, "ONOS3Port not defined"
1637 assert ONOS4Port, "ONOS4Port not defined"
1638 assert ONOS5Port, "ONOS5Port not defined"
1639 assert ONOS6Port, "ONOS6Port not defined"
1640 assert ONOS7Port, "ONOS7Port not defined"
Jon Hall669173b2014-12-17 11:36:30 -08001641
Jon Hall8f89dda2015-01-22 16:03:33 -08001642 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall6aec96b2015-01-19 14:49:31 -08001643 switch = main.params[ 'kill' ][ 'switch' ]
1644 switchDPID = main.params[ 'kill' ][ 'dpid' ]
1645 links = main.params[ 'kill' ][ 'links' ].split()
Jon Hall73cf9cc2014-11-20 22:28:38 -08001646 description = "Adding a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001647 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001648
Jon Hall6aec96b2015-01-19 14:49:31 -08001649 main.step( "Add back " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001650 main.Mininet1.addSwitch( switch, dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001651 for peer in links:
Jon Hall8f89dda2015-01-22 16:03:33 -08001652 main.Mininet1.addLink( switch, peer )
Jon Hall0f523f22015-07-06 09:31:09 -07001653 ipList = []
1654 for i in range( numControllers ):
1655 ipList.append( nodes[ i ].ip_address )
1656 main.Mininet1.assignSwController( sw=switch, ip=ipList )
Jon Hall58c76b72015-02-23 11:09:24 -08001657 main.log.info( "Waiting " + str( switchSleep ) +
1658 " seconds for switch up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001659 time.sleep( switchSleep )
1660 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001661 # Peek at the deleted switch
1662 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001663 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001664 if device and device[ 'available' ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001665 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001666 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Halla9d26da2015-03-30 16:45:32 -07001667 onpass="add switch successful",
Jon Hall58c76b72015-02-23 11:09:24 -08001668 onfail="Failed to add switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001669
Jon Hall6aec96b2015-01-19 14:49:31 -08001670 def CASE13( self, main ):
1671 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001672 Clean up
Jon Hall6aec96b2015-01-19 14:49:31 -08001673 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001674 import os
1675 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001676 assert numControllers, "numControllers not defined"
1677 assert main, "main not defined"
1678 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -08001679 # printing colors to terminal
Jon Halla9d26da2015-03-30 16:45:32 -07001680 colors = { 'cyan': '\033[96m', 'purple': '\033[95m',
1681 'blue': '\033[94m', 'green': '\033[92m',
1682 'yellow': '\033[93m', 'red': '\033[91m', 'end': '\033[0m' }
Jon Hall40d2cbd2015-06-03 16:24:29 -07001683 main.case( "Test Cleanup" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001684 main.step( "Killing tcpdumps" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001685 main.Mininet2.stopTcpdump()
Jon Hall73cf9cc2014-11-20 22:28:38 -08001686
Jon Hall6aec96b2015-01-19 14:49:31 -08001687 main.step( "Copying MN pcap and ONOS log files to test station" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001688 testname = main.TEST
Jon Hall8f89dda2015-01-22 16:03:33 -08001689 teststationUser = main.params[ 'TESTONUSER' ]
1690 teststationIP = main.params[ 'TESTONIP' ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001691 # NOTE: MN Pcap file is being saved to ~/packet_captures
Jon Hall73cf9cc2014-11-20 22:28:38 -08001692 # scp this file as MN and TestON aren't necessarily the same vm
Jon Hall6aec96b2015-01-19 14:49:31 -08001693 # FIXME: scp
1694 # mn files
1695 # TODO: Load these from params
1696 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001697 logFolder = "/opt/onos/log/"
1698 logFiles = [ "karaf.log", "karaf.log.1" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001699 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001700 dstDir = "~/packet_captures/"
1701 for f in logFiles:
1702 main.ONOSbench.handle.sendline( "scp sdn@" + ONOS1Ip + ":" +
1703 logFolder + f + " " +
1704 teststationUser + "@" +
1705 teststationIP + ":" + dstDir +
Jon Hall6aec96b2015-01-19 14:49:31 -08001706 str( testname ) + "-ONOS1-" + f )
1707 main.ONOSbench.handle.expect( "\$" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001708
Jon Hall6aec96b2015-01-19 14:49:31 -08001709 # std*.log's
1710 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001711 logFolder = "/opt/onos/var/"
1712 logFiles = [ "stderr.log", "stdout.log" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001713 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001714 dstDir = "~/packet_captures/"
1715 for f in logFiles:
1716 main.ONOSbench.handle.sendline( "scp sdn@" + ONOS1Ip + ":" +
1717 logFolder + f + " " +
1718 teststationUser + "@" +
1719 teststationIP + ":" + dstDir +
Jon Hall6aec96b2015-01-19 14:49:31 -08001720 str( testname ) + "-ONOS1-" + f )
Jon Hall58c76b72015-02-23 11:09:24 -08001721 main.ONOSbench.handle.expect( "\$" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001722 # sleep so scp can finish
1723 time.sleep( 10 )
Jon Halla9d26da2015-03-30 16:45:32 -07001724
1725 main.step( "Stopping Mininet" )
Jon Hall390696c2015-05-05 17:13:41 -07001726 mnResult = main.Mininet1.stopNet()
1727 utilities.assert_equals( expect=main.TRUE, actual=mnResult,
1728 onpass="Mininet stopped",
1729 onfail="MN cleanup NOT successful" )
Jon Halla9d26da2015-03-30 16:45:32 -07001730
1731 main.step( "Checking ONOS Logs for errors" )
1732 print colors[ 'purple' ] + "Checking logs for errors on ONOS1:" + \
1733 colors[ 'end' ]
Jon Hall40d2cbd2015-06-03 16:24:29 -07001734 print main.ONOSbench.checkLogs( ONOS1Ip, restart=True )
Jon Halla9d26da2015-03-30 16:45:32 -07001735
Jon Hall6aec96b2015-01-19 14:49:31 -08001736 main.step( "Packing and rotating pcap archives" )
1737 os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001738
Jon Hall40d2cbd2015-06-03 16:24:29 -07001739 try:
1740 timerLog = open( main.logdir + "/Timers.csv", 'w')
1741 # Overwrite with empty line and close
1742 labels = "Gossip Intents, Restart"
1743 data = str( gossipTime ) + ", " + str( main.restartTime )
1744 timerLog.write( labels + "\n" + data )
1745 timerLog.close()
1746 except NameError, e:
1747 main.log.exception(e)
1748
Jon Hall6aec96b2015-01-19 14:49:31 -08001749 def CASE14( self, main ):
1750 """
Jon Hall669173b2014-12-17 11:36:30 -08001751 start election app on all onos nodes
Jon Hall6aec96b2015-01-19 14:49:31 -08001752 """
Jon Hall5cfd23c2015-03-19 11:40:57 -07001753 assert numControllers, "numControllers not defined"
1754 assert main, "main not defined"
1755 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halla9d26da2015-03-30 16:45:32 -07001756
Jon Hall390696c2015-05-05 17:13:41 -07001757 main.case("Start Leadership Election app")
1758 main.step( "Install leadership election app" )
Jon Hallfeff3082015-05-19 10:23:26 -07001759 appResult = main.ONOScli1.activateApp( "org.onosproject.election" )
1760 utilities.assert_equals(
1761 expect=main.TRUE,
1762 actual=appResult,
1763 onpass="Election app installed",
1764 onfail="Something went wrong with installing Leadership election" )
1765
1766 main.step( "Run for election on each node" )
1767 leaderResult = main.ONOScli1.electionTestRun()
Jon Hall6aec96b2015-01-19 14:49:31 -08001768 # check for leader
Jon Hall8f89dda2015-01-22 16:03:33 -08001769 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001770 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08001771 if leader == ONOS1Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08001772 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001773 pass
Jon Hall6aec96b2015-01-19 14:49:31 -08001774 elif leader is None:
1775 # No leader elected
Jon Hallfeff3082015-05-19 10:23:26 -07001776 main.log.error( "No leader was elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001777 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001778 elif leader == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001779 # error in response
1780 # TODO: add check for "Command not found:" in the driver, this
1781 # means the app isn't loaded
Jon Hallfeff3082015-05-19 10:23:26 -07001782 main.log.error( "Something is wrong with electionTestLeader" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001783 " function, check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001784 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001785 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001786 # error in response
Jon Hallfeff3082015-05-19 10:23:26 -07001787 main.log.error(
Jon Hall8f89dda2015-01-22 16:03:33 -08001788 "Unexpected response from electionTestLeader function:'" +
1789 str( leader ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001790 "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001791 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001792 utilities.assert_equals(
1793 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001794 actual=leaderResult,
Jon Hallfeff3082015-05-19 10:23:26 -07001795 onpass="Successfully ran for leadership",
1796 onfail="Failed to run for leadership" )
Jon Hall669173b2014-12-17 11:36:30 -08001797
Jon Hall6aec96b2015-01-19 14:49:31 -08001798 def CASE15( self, main ):
1799 """
Jon Hall669173b2014-12-17 11:36:30 -08001800 Check that Leadership Election is still functional
Jon Hall6aec96b2015-01-19 14:49:31 -08001801 """
Jon Hall5cfd23c2015-03-19 11:40:57 -07001802 assert numControllers, "numControllers not defined"
1803 assert main, "main not defined"
1804 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall8f89dda2015-01-22 16:03:33 -08001805 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08001806 description = "Check that Leadership Election is still functional"
Jon Hall6aec96b2015-01-19 14:49:31 -08001807 main.case( description )
1808 main.step( "Find current leader and withdraw" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001809 leader = main.ONOScli1.electionTestLeader()
Jon Halla9d26da2015-03-30 16:45:32 -07001810 # do some sanity checking on leader before using it
Jon Hall8f89dda2015-01-22 16:03:33 -08001811 withdrawResult = main.FALSE
1812 if leader == ONOS1Ip:
1813 oldLeader = getattr( main, "ONOScli1" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001814 elif leader is None or leader == main.FALSE:
Jon Hall40d2cbd2015-06-03 16:24:29 -07001815 main.log.error(
Jon Hall6aec96b2015-01-19 14:49:31 -08001816 "Leader for the election app should be an ONOS node," +
Jon Hall58c76b72015-02-23 11:09:24 -08001817 "instead got '" + str( leader ) + "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001818 leaderResult = main.FALSE
Jon Hall63604932015-02-26 17:09:50 -08001819 oldLeader = None
1820 else:
1821 main.log.error( "Leader election --- why am I HERE?!?")
Jon Hallfeff3082015-05-19 10:23:26 -07001822 leaderResult = main.FALSE
1823 oldLeader = None
Jon Hall63604932015-02-26 17:09:50 -08001824 if oldLeader:
1825 withdrawResult = oldLeader.electionTestWithdraw()
Jon Hall6aec96b2015-01-19 14:49:31 -08001826 utilities.assert_equals(
1827 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001828 actual=withdrawResult,
Jon Hallfeff3082015-05-19 10:23:26 -07001829 onpass="Node was withdrawn from election",
1830 onfail="Node was not withdrawn from election" )
Jon Hall669173b2014-12-17 11:36:30 -08001831
Jon Hall6aec96b2015-01-19 14:49:31 -08001832 main.step( "Make sure new leader is elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001833 leaderN = main.ONOScli1.electionTestLeader()
Jon Hall669173b2014-12-17 11:36:30 -08001834 if leaderN == leader:
Jon Hall40d2cbd2015-06-03 16:24:29 -07001835 main.log.error( "ONOS still sees " + str( leaderN ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001836 " as leader after they withdrew" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001837 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001838 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001839 # error in response
1840 # TODO: add check for "Command not found:" in the driver, this
1841 # means the app isn't loaded
Jon Hall40d2cbd2015-06-03 16:24:29 -07001842 main.log.error( "Something is wrong with electionTestLeader " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001843 "function, check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001844 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001845 elif leaderN is None:
1846 main.log.info(
1847 "There is no leader after the app withdrew from election" )
Jon Hallfeff3082015-05-19 10:23:26 -07001848 leaderResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001849 utilities.assert_equals(
1850 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001851 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001852 onpass="Leadership election passed",
1853 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08001854
Jon Hall58c76b72015-02-23 11:09:24 -08001855 main.step( "Run for election on old leader( just so everyone " +
1856 "is in the hat )" )
Jon Hall63604932015-02-26 17:09:50 -08001857 if oldLeader:
1858 runResult = oldLeader.electionTestRun()
1859 else:
1860 runResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001861 utilities.assert_equals(
1862 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001863 actual=runResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001864 onpass="App re-ran for election",
1865 onfail="App failed to run for election" )
Jon Hallfeff3082015-05-19 10:23:26 -07001866
1867 main.step( "Node became leader when it ran for election" )
1868 afterRun = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001869 # verify leader is ONOS1
Jon Hallfeff3082015-05-19 10:23:26 -07001870 if afterRun == ONOS1Ip:
1871 afterResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08001872 else:
Jon Hallfeff3082015-05-19 10:23:26 -07001873 afterResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001874
Jon Hall6aec96b2015-01-19 14:49:31 -08001875 utilities.assert_equals(
1876 expect=main.TRUE,
Jon Hallfeff3082015-05-19 10:23:26 -07001877 actual=afterResult,
1878 onpass="Old leader successfully re-ran for election",
1879 onfail="Something went wrong with Leadership election after " +
1880 "the old leader re-ran for election" )
Jon Hall390696c2015-05-05 17:13:41 -07001881
1882 def CASE16( self, main ):
1883 """
1884 Install Distributed Primitives app
1885 """
1886 assert numControllers, "numControllers not defined"
1887 assert main, "main not defined"
1888 assert utilities.assert_equals, "utilities.assert_equals not defined"
1889 assert CLIs, "CLIs not defined"
1890 assert nodes, "nodes not defined"
1891
1892 # Variables for the distributed primitives tests
1893 global pCounterName
1894 global iCounterName
1895 global pCounterValue
1896 global iCounterValue
1897 global onosSet
1898 global onosSetName
1899 pCounterName = "TestON-Partitions"
1900 iCounterName = "TestON-inMemory"
1901 pCounterValue = 0
1902 iCounterValue = 0
1903 onosSet = set([])
1904 onosSetName = "TestON-set"
1905
1906 description = "Install Primitives app"
1907 main.case( description )
1908 main.step( "Install Primitives app" )
1909 appName = "org.onosproject.distributedprimitives"
1910 appResults = CLIs[0].activateApp( appName )
1911 utilities.assert_equals( expect=main.TRUE,
1912 actual=appResults,
1913 onpass="Primitives app activated",
1914 onfail="Primitives app not activated" )
1915
1916 def CASE17( self, main ):
1917 """
1918 Check for basic functionality with distributed primitives
1919 """
Jon Hall40d2cbd2015-06-03 16:24:29 -07001920 import json
Jon Hall390696c2015-05-05 17:13:41 -07001921 # Make sure variables are defined/set
1922 assert numControllers, "numControllers not defined"
1923 assert main, "main not defined"
1924 assert utilities.assert_equals, "utilities.assert_equals not defined"
1925 assert CLIs, "CLIs not defined"
1926 assert nodes, "nodes not defined"
1927 assert pCounterName, "pCounterName not defined"
1928 assert iCounterName, "iCounterName not defined"
1929 assert onosSetName, "onosSetName not defined"
1930 # NOTE: assert fails if value is 0/None/Empty/False
1931 try:
1932 pCounterValue
1933 except NameError:
1934 main.log.error( "pCounterValue not defined, setting to 0" )
1935 pCounterValue = 0
1936 try:
1937 iCounterValue
1938 except NameError:
1939 main.log.error( "iCounterValue not defined, setting to 0" )
1940 iCounterValue = 0
1941 try:
1942 onosSet
1943 except NameError:
1944 main.log.error( "onosSet not defined, setting to empty Set" )
1945 onosSet = set([])
1946 # Variables for the distributed primitives tests. These are local only
1947 addValue = "a"
1948 addAllValue = "a b c d e f"
1949 retainValue = "c d e f"
1950
1951 description = "Check for basic functionality with distributed " +\
1952 "primitives"
1953 main.case( description )
1954 main.caseExplaination = "Test the methods of the distributed primitives (counters and sets) throught the cli"
1955 # DISTRIBUTED ATOMIC COUNTERS
1956 main.step( "Increment and get a default counter on each node" )
1957 pCounters = []
1958 threads = []
Jon Hallfeff3082015-05-19 10:23:26 -07001959 addedPValues = []
Jon Hall390696c2015-05-05 17:13:41 -07001960 for i in range( numControllers ):
1961 t = main.Thread( target=CLIs[i].counterTestIncrement,
1962 name="counterIncrement-" + str( i ),
1963 args=[ pCounterName ] )
1964 pCounterValue += 1
Jon Hallfeff3082015-05-19 10:23:26 -07001965 addedPValues.append( pCounterValue )
Jon Hall390696c2015-05-05 17:13:41 -07001966 threads.append( t )
1967 t.start()
1968
1969 for t in threads:
1970 t.join()
1971 pCounters.append( t.result )
1972 # Check that counter incremented numController times
1973 pCounterResults = True
Jon Hallfeff3082015-05-19 10:23:26 -07001974 for i in addedPValues:
Jon Hall40d2cbd2015-06-03 16:24:29 -07001975 tmpResult = i in pCounters
Jon Hallfeff3082015-05-19 10:23:26 -07001976 pCounterResults = pCounterResults and tmpResult
1977 if not tmpResult:
1978 main.log.error( str( i ) + " is not in partitioned "
1979 "counter incremented results" )
Jon Hall390696c2015-05-05 17:13:41 -07001980 utilities.assert_equals( expect=True,
1981 actual=pCounterResults,
1982 onpass="Default counter incremented",
1983 onfail="Error incrementing default" +
1984 " counter" )
1985
1986 main.step( "Increment and get an in memory counter on each node" )
1987 iCounters = []
Jon Hallfeff3082015-05-19 10:23:26 -07001988 addedIValues = []
Jon Hall390696c2015-05-05 17:13:41 -07001989 threads = []
1990 for i in range( numControllers ):
1991 t = main.Thread( target=CLIs[i].counterTestIncrement,
1992 name="icounterIncrement-" + str( i ),
1993 args=[ iCounterName ],
1994 kwargs={ "inMemory": True } )
1995 iCounterValue += 1
Jon Hallfeff3082015-05-19 10:23:26 -07001996 addedIValues.append( iCounterValue )
Jon Hall390696c2015-05-05 17:13:41 -07001997 threads.append( t )
1998 t.start()
1999
2000 for t in threads:
2001 t.join()
2002 iCounters.append( t.result )
2003 # Check that counter incremented numController times
2004 iCounterResults = True
Jon Hallfeff3082015-05-19 10:23:26 -07002005 for i in addedIValues:
2006 tmpResult = i in iCounters
2007 iCounterResults = iCounterResults and tmpResult
2008 if not tmpResult:
2009 main.log.error( str( i ) + " is not in the in-memory "
2010 "counter incremented results" )
Jon Hall390696c2015-05-05 17:13:41 -07002011 utilities.assert_equals( expect=True,
2012 actual=iCounterResults,
2013 onpass="In memory counter incremented",
2014 onfail="Error incrementing in memory" +
2015 " counter" )
2016
2017 main.step( "Check counters are consistant across nodes" )
2018 onosCounters = []
2019 threads = []
2020 for i in range( numControllers ):
2021 t = main.Thread( target=CLIs[i].counters,
2022 name="counters-" + str( i ) )
2023 threads.append( t )
2024 t.start()
2025 for t in threads:
2026 t.join()
2027 onosCounters.append( t.result )
2028 tmp = [ i == onosCounters[ 0 ] for i in onosCounters ]
2029 if all( tmp ):
2030 main.log.info( "Counters are consistent across all nodes" )
2031 consistentCounterResults = main.TRUE
2032 else:
2033 main.log.error( "Counters are not consistent across all nodes" )
2034 consistentCounterResults = main.FALSE
2035 utilities.assert_equals( expect=main.TRUE,
2036 actual=consistentCounterResults,
2037 onpass="ONOS counters are consistent " +
2038 "across nodes",
2039 onfail="ONOS Counters are inconsistent " +
2040 "across nodes" )
2041
2042 main.step( "Counters we added have the correct values" )
2043 correctResults = main.TRUE
2044 for i in range( numControllers ):
Jon Hall40d2cbd2015-06-03 16:24:29 -07002045 current = json.loads( onosCounters[i] )
2046 pValue = None
2047 iValue = None
Jon Hall390696c2015-05-05 17:13:41 -07002048 try:
Jon Hall40d2cbd2015-06-03 16:24:29 -07002049 for database in current:
2050 partitioned = database.get( 'partitionedDatabaseCounters' )
2051 if partitioned:
2052 for value in partitioned:
2053 if value.get( 'name' ) == pCounterName:
2054 pValue = value.get( 'value' )
2055 break
2056 inMemory = database.get( 'inMemoryDatabaseCounters' )
2057 if inMemory:
2058 for value in inMemory:
2059 if value.get( 'name' ) == iCounterName:
2060 iValue = value.get( 'value' )
2061 break
Jon Hall390696c2015-05-05 17:13:41 -07002062 except AttributeError, e:
2063 main.log.error( "ONOS" + str( i + 1 ) + " counters result " +
2064 "is not as expected" )
2065 correctResults = main.FALSE
Jon Hall40d2cbd2015-06-03 16:24:29 -07002066 if pValue == pCounterValue:
2067 main.log.info( "Partitioned counter value is correct" )
2068 else:
2069 main.log.error( "Partitioned counter value is incorrect," +
2070 " expected value: " + str( pCounterValue )
2071 + " current value: " + str( pValue ) )
2072 correctResults = main.FALSE
2073 if iValue == iCounterValue:
2074 main.log.info( "In memory counter value is correct" )
2075 else:
2076 main.log.error( "In memory counter value is incorrect, " +
2077 "expected value: " + str( iCounterValue ) +
2078 " current value: " + str( iValue ) )
2079 correctResults = main.FALSE
Jon Hall390696c2015-05-05 17:13:41 -07002080 utilities.assert_equals( expect=main.TRUE,
2081 actual=correctResults,
2082 onpass="Added counters are correct",
2083 onfail="Added counters are incorrect" )
2084 # DISTRIBUTED SETS
2085 main.step( "Distributed Set get" )
2086 size = len( onosSet )
2087 getResponses = []
2088 threads = []
2089 for i in range( numControllers ):
2090 t = main.Thread( target=CLIs[i].setTestGet,
2091 name="setTestGet-" + str( i ),
2092 args=[ onosSetName ] )
2093 threads.append( t )
2094 t.start()
2095 for t in threads:
2096 t.join()
2097 getResponses.append( t.result )
2098
2099 getResults = main.TRUE
2100 for i in range( numControllers ):
2101 if isinstance( getResponses[ i ], list):
2102 current = set( getResponses[ i ] )
2103 if len( current ) == len( getResponses[ i ] ):
2104 # no repeats
2105 if onosSet != current:
2106 main.log.error( "ONOS" + str( i + 1 ) +
2107 " has incorrect view" +
2108 " of set " + onosSetName + ":\n" +
2109 str( getResponses[ i ] ) )
2110 main.log.debug( "Expected: " + str( onosSet ) )
2111 main.log.debug( "Actual: " + str( current ) )
2112 getResults = main.FALSE
2113 else:
2114 # error, set is not a set
2115 main.log.error( "ONOS" + str( i + 1 ) +
2116 " has repeat elements in" +
2117 " set " + onosSetName + ":\n" +
2118 str( getResponses[ i ] ) )
2119 getResults = main.FALSE
2120 elif getResponses[ i ] == main.ERROR:
2121 getResults = main.FALSE
2122 utilities.assert_equals( expect=main.TRUE,
2123 actual=getResults,
2124 onpass="Set elements are correct",
2125 onfail="Set elements are incorrect" )
2126
2127 main.step( "Distributed Set size" )
2128 sizeResponses = []
2129 threads = []
2130 for i in range( numControllers ):
2131 t = main.Thread( target=CLIs[i].setTestSize,
2132 name="setTestSize-" + str( i ),
2133 args=[ onosSetName ] )
2134 threads.append( t )
2135 t.start()
2136 for t in threads:
2137 t.join()
2138 sizeResponses.append( t.result )
2139
2140 sizeResults = main.TRUE
2141 for i in range( numControllers ):
2142 if size != sizeResponses[ i ]:
2143 sizeResults = main.FALSE
2144 main.log.error( "ONOS" + str( i + 1 ) +
2145 " expected a size of " + str( size ) +
2146 " for set " + onosSetName +
2147 " but got " + str( sizeResponses[ i ] ) )
2148 utilities.assert_equals( expect=main.TRUE,
2149 actual=sizeResults,
2150 onpass="Set sizes are correct",
2151 onfail="Set sizes are incorrect" )
2152
2153 main.step( "Distributed Set add()" )
2154 onosSet.add( addValue )
2155 addResponses = []
2156 threads = []
2157 for i in range( numControllers ):
2158 t = main.Thread( target=CLIs[i].setTestAdd,
2159 name="setTestAdd-" + str( i ),
2160 args=[ onosSetName, addValue ] )
2161 threads.append( t )
2162 t.start()
2163 for t in threads:
2164 t.join()
2165 addResponses.append( t.result )
2166
2167 # main.TRUE = successfully changed the set
2168 # main.FALSE = action resulted in no change in set
2169 # main.ERROR - Some error in executing the function
2170 addResults = main.TRUE
2171 for i in range( numControllers ):
2172 if addResponses[ i ] == main.TRUE:
2173 # All is well
2174 pass
2175 elif addResponses[ i ] == main.FALSE:
2176 # Already in set, probably fine
2177 pass
2178 elif addResponses[ i ] == main.ERROR:
2179 # Error in execution
2180 addResults = main.FALSE
2181 else:
2182 # unexpected result
2183 addResults = main.FALSE
2184 if addResults != main.TRUE:
2185 main.log.error( "Error executing set add" )
2186
2187 # Check if set is still correct
2188 size = len( onosSet )
2189 getResponses = []
2190 threads = []
2191 for i in range( numControllers ):
2192 t = main.Thread( target=CLIs[i].setTestGet,
2193 name="setTestGet-" + str( i ),
2194 args=[ onosSetName ] )
2195 threads.append( t )
2196 t.start()
2197 for t in threads:
2198 t.join()
2199 getResponses.append( t.result )
2200 getResults = main.TRUE
2201 for i in range( numControllers ):
2202 if isinstance( getResponses[ i ], list):
2203 current = set( getResponses[ i ] )
2204 if len( current ) == len( getResponses[ i ] ):
2205 # no repeats
2206 if onosSet != current:
2207 main.log.error( "ONOS" + str( i + 1 ) +
2208 " has incorrect view" +
2209 " of set " + onosSetName + ":\n" +
2210 str( getResponses[ i ] ) )
2211 main.log.debug( "Expected: " + str( onosSet ) )
2212 main.log.debug( "Actual: " + str( current ) )
2213 getResults = main.FALSE
2214 else:
2215 # error, set is not a set
2216 main.log.error( "ONOS" + str( i + 1 ) +
2217 " has repeat elements in" +
2218 " set " + onosSetName + ":\n" +
2219 str( getResponses[ i ] ) )
2220 getResults = main.FALSE
2221 elif getResponses[ i ] == main.ERROR:
2222 getResults = main.FALSE
2223 sizeResponses = []
2224 threads = []
2225 for i in range( numControllers ):
2226 t = main.Thread( target=CLIs[i].setTestSize,
2227 name="setTestSize-" + str( i ),
2228 args=[ onosSetName ] )
2229 threads.append( t )
2230 t.start()
2231 for t in threads:
2232 t.join()
2233 sizeResponses.append( t.result )
2234 sizeResults = main.TRUE
2235 for i in range( numControllers ):
2236 if size != sizeResponses[ i ]:
2237 sizeResults = main.FALSE
2238 main.log.error( "ONOS" + str( i + 1 ) +
2239 " expected a size of " + str( size ) +
2240 " for set " + onosSetName +
2241 " but got " + str( sizeResponses[ i ] ) )
2242 addResults = addResults and getResults and sizeResults
2243 utilities.assert_equals( expect=main.TRUE,
2244 actual=addResults,
2245 onpass="Set add correct",
2246 onfail="Set add was incorrect" )
2247
2248 main.step( "Distributed Set addAll()" )
2249 onosSet.update( addAllValue.split() )
2250 addResponses = []
2251 threads = []
2252 for i in range( numControllers ):
2253 t = main.Thread( target=CLIs[i].setTestAdd,
2254 name="setTestAddAll-" + str( i ),
2255 args=[ onosSetName, addAllValue ] )
2256 threads.append( t )
2257 t.start()
2258 for t in threads:
2259 t.join()
2260 addResponses.append( t.result )
2261
2262 # main.TRUE = successfully changed the set
2263 # main.FALSE = action resulted in no change in set
2264 # main.ERROR - Some error in executing the function
2265 addAllResults = main.TRUE
2266 for i in range( numControllers ):
2267 if addResponses[ i ] == main.TRUE:
2268 # All is well
2269 pass
2270 elif addResponses[ i ] == main.FALSE:
2271 # Already in set, probably fine
2272 pass
2273 elif addResponses[ i ] == main.ERROR:
2274 # Error in execution
2275 addAllResults = main.FALSE
2276 else:
2277 # unexpected result
2278 addAllResults = main.FALSE
2279 if addAllResults != main.TRUE:
2280 main.log.error( "Error executing set addAll" )
2281
2282 # Check if set is still correct
2283 size = len( onosSet )
2284 getResponses = []
2285 threads = []
2286 for i in range( numControllers ):
2287 t = main.Thread( target=CLIs[i].setTestGet,
2288 name="setTestGet-" + str( i ),
2289 args=[ onosSetName ] )
2290 threads.append( t )
2291 t.start()
2292 for t in threads:
2293 t.join()
2294 getResponses.append( t.result )
2295 getResults = main.TRUE
2296 for i in range( numControllers ):
2297 if isinstance( getResponses[ i ], list):
2298 current = set( getResponses[ i ] )
2299 if len( current ) == len( getResponses[ i ] ):
2300 # no repeats
2301 if onosSet != current:
2302 main.log.error( "ONOS" + str( i + 1 ) +
2303 " has incorrect view" +
2304 " of set " + onosSetName + ":\n" +
2305 str( getResponses[ i ] ) )
2306 main.log.debug( "Expected: " + str( onosSet ) )
2307 main.log.debug( "Actual: " + str( current ) )
2308 getResults = main.FALSE
2309 else:
2310 # error, set is not a set
2311 main.log.error( "ONOS" + str( i + 1 ) +
2312 " has repeat elements in" +
2313 " set " + onosSetName + ":\n" +
2314 str( getResponses[ i ] ) )
2315 getResults = main.FALSE
2316 elif getResponses[ i ] == main.ERROR:
2317 getResults = main.FALSE
2318 sizeResponses = []
2319 threads = []
2320 for i in range( numControllers ):
2321 t = main.Thread( target=CLIs[i].setTestSize,
2322 name="setTestSize-" + str( i ),
2323 args=[ onosSetName ] )
2324 threads.append( t )
2325 t.start()
2326 for t in threads:
2327 t.join()
2328 sizeResponses.append( t.result )
2329 sizeResults = main.TRUE
2330 for i in range( numControllers ):
2331 if size != sizeResponses[ i ]:
2332 sizeResults = main.FALSE
2333 main.log.error( "ONOS" + str( i + 1 ) +
2334 " expected a size of " + str( size ) +
2335 " for set " + onosSetName +
2336 " but got " + str( sizeResponses[ i ] ) )
2337 addAllResults = addAllResults and getResults and sizeResults
2338 utilities.assert_equals( expect=main.TRUE,
2339 actual=addAllResults,
2340 onpass="Set addAll correct",
2341 onfail="Set addAll was incorrect" )
2342
2343 main.step( "Distributed Set contains()" )
2344 containsResponses = []
2345 threads = []
2346 for i in range( numControllers ):
2347 t = main.Thread( target=CLIs[i].setTestGet,
2348 name="setContains-" + str( i ),
2349 args=[ onosSetName ],
2350 kwargs={ "values": addValue } )
2351 threads.append( t )
2352 t.start()
2353 for t in threads:
2354 t.join()
2355 # NOTE: This is the tuple
2356 containsResponses.append( t.result )
2357
2358 containsResults = main.TRUE
2359 for i in range( numControllers ):
2360 if containsResponses[ i ] == main.ERROR:
2361 containsResults = main.FALSE
2362 else:
2363 containsResults = containsResults and\
2364 containsResponses[ i ][ 1 ]
2365 utilities.assert_equals( expect=main.TRUE,
2366 actual=containsResults,
2367 onpass="Set contains is functional",
2368 onfail="Set contains failed" )
2369
2370 main.step( "Distributed Set containsAll()" )
2371 containsAllResponses = []
2372 threads = []
2373 for i in range( numControllers ):
2374 t = main.Thread( target=CLIs[i].setTestGet,
2375 name="setContainsAll-" + str( i ),
2376 args=[ onosSetName ],
2377 kwargs={ "values": addAllValue } )
2378 threads.append( t )
2379 t.start()
2380 for t in threads:
2381 t.join()
2382 # NOTE: This is the tuple
2383 containsAllResponses.append( t.result )
2384
2385 containsAllResults = main.TRUE
2386 for i in range( numControllers ):
2387 if containsResponses[ i ] == main.ERROR:
2388 containsResults = main.FALSE
2389 else:
2390 containsResults = containsResults and\
2391 containsResponses[ i ][ 1 ]
2392 utilities.assert_equals( expect=main.TRUE,
2393 actual=containsAllResults,
2394 onpass="Set containsAll is functional",
2395 onfail="Set containsAll failed" )
2396
2397 main.step( "Distributed Set remove()" )
2398 onosSet.remove( addValue )
2399 removeResponses = []
2400 threads = []
2401 for i in range( numControllers ):
2402 t = main.Thread( target=CLIs[i].setTestRemove,
2403 name="setTestRemove-" + str( i ),
2404 args=[ onosSetName, addValue ] )
2405 threads.append( t )
2406 t.start()
2407 for t in threads:
2408 t.join()
2409 removeResponses.append( t.result )
2410
2411 # main.TRUE = successfully changed the set
2412 # main.FALSE = action resulted in no change in set
2413 # main.ERROR - Some error in executing the function
2414 removeResults = main.TRUE
2415 for i in range( numControllers ):
2416 if removeResponses[ i ] == main.TRUE:
2417 # All is well
2418 pass
2419 elif removeResponses[ i ] == main.FALSE:
2420 # not in set, probably fine
2421 pass
2422 elif removeResponses[ i ] == main.ERROR:
2423 # Error in execution
2424 removeResults = main.FALSE
2425 else:
2426 # unexpected result
2427 removeResults = main.FALSE
2428 if removeResults != main.TRUE:
2429 main.log.error( "Error executing set remove" )
2430
2431 # Check if set is still correct
2432 size = len( onosSet )
2433 getResponses = []
2434 threads = []
2435 for i in range( numControllers ):
2436 t = main.Thread( target=CLIs[i].setTestGet,
2437 name="setTestGet-" + str( i ),
2438 args=[ onosSetName ] )
2439 threads.append( t )
2440 t.start()
2441 for t in threads:
2442 t.join()
2443 getResponses.append( t.result )
2444 getResults = main.TRUE
2445 for i in range( numControllers ):
2446 if isinstance( getResponses[ i ], list):
2447 current = set( getResponses[ i ] )
2448 if len( current ) == len( getResponses[ i ] ):
2449 # no repeats
2450 if onosSet != current:
2451 main.log.error( "ONOS" + str( i + 1 ) +
2452 " has incorrect view" +
2453 " of set " + onosSetName + ":\n" +
2454 str( getResponses[ i ] ) )
2455 main.log.debug( "Expected: " + str( onosSet ) )
2456 main.log.debug( "Actual: " + str( current ) )
2457 getResults = main.FALSE
2458 else:
2459 # error, set is not a set
2460 main.log.error( "ONOS" + str( i + 1 ) +
2461 " has repeat elements in" +
2462 " set " + onosSetName + ":\n" +
2463 str( getResponses[ i ] ) )
2464 getResults = main.FALSE
2465 elif getResponses[ i ] == main.ERROR:
2466 getResults = main.FALSE
2467 sizeResponses = []
2468 threads = []
2469 for i in range( numControllers ):
2470 t = main.Thread( target=CLIs[i].setTestSize,
2471 name="setTestSize-" + str( i ),
2472 args=[ onosSetName ] )
2473 threads.append( t )
2474 t.start()
2475 for t in threads:
2476 t.join()
2477 sizeResponses.append( t.result )
2478 sizeResults = main.TRUE
2479 for i in range( numControllers ):
2480 if size != sizeResponses[ i ]:
2481 sizeResults = main.FALSE
2482 main.log.error( "ONOS" + str( i + 1 ) +
2483 " expected a size of " + str( size ) +
2484 " for set " + onosSetName +
2485 " but got " + str( sizeResponses[ i ] ) )
2486 removeResults = removeResults and getResults and sizeResults
2487 utilities.assert_equals( expect=main.TRUE,
2488 actual=removeResults,
2489 onpass="Set remove correct",
2490 onfail="Set remove was incorrect" )
2491
2492 main.step( "Distributed Set removeAll()" )
2493 onosSet.difference_update( addAllValue.split() )
2494 removeAllResponses = []
2495 threads = []
2496 try:
2497 for i in range( numControllers ):
2498 t = main.Thread( target=CLIs[i].setTestRemove,
2499 name="setTestRemoveAll-" + str( i ),
2500 args=[ onosSetName, addAllValue ] )
2501 threads.append( t )
2502 t.start()
2503 for t in threads:
2504 t.join()
2505 removeAllResponses.append( t.result )
2506 except Exception, e:
2507 main.log.exception(e)
2508
2509 # main.TRUE = successfully changed the set
2510 # main.FALSE = action resulted in no change in set
2511 # main.ERROR - Some error in executing the function
2512 removeAllResults = main.TRUE
2513 for i in range( numControllers ):
2514 if removeAllResponses[ i ] == main.TRUE:
2515 # All is well
2516 pass
2517 elif removeAllResponses[ i ] == main.FALSE:
2518 # not in set, probably fine
2519 pass
2520 elif removeAllResponses[ i ] == main.ERROR:
2521 # Error in execution
2522 removeAllResults = main.FALSE
2523 else:
2524 # unexpected result
2525 removeAllResults = main.FALSE
2526 if removeAllResults != main.TRUE:
2527 main.log.error( "Error executing set removeAll" )
2528
2529 # Check if set is still correct
2530 size = len( onosSet )
2531 getResponses = []
2532 threads = []
2533 for i in range( numControllers ):
2534 t = main.Thread( target=CLIs[i].setTestGet,
2535 name="setTestGet-" + str( i ),
2536 args=[ onosSetName ] )
2537 threads.append( t )
2538 t.start()
2539 for t in threads:
2540 t.join()
2541 getResponses.append( t.result )
2542 getResults = main.TRUE
2543 for i in range( numControllers ):
2544 if isinstance( getResponses[ i ], list):
2545 current = set( getResponses[ i ] )
2546 if len( current ) == len( getResponses[ i ] ):
2547 # no repeats
2548 if onosSet != current:
2549 main.log.error( "ONOS" + str( i + 1 ) +
2550 " has incorrect view" +
2551 " of set " + onosSetName + ":\n" +
2552 str( getResponses[ i ] ) )
2553 main.log.debug( "Expected: " + str( onosSet ) )
2554 main.log.debug( "Actual: " + str( current ) )
2555 getResults = main.FALSE
2556 else:
2557 # error, set is not a set
2558 main.log.error( "ONOS" + str( i + 1 ) +
2559 " has repeat elements in" +
2560 " set " + onosSetName + ":\n" +
2561 str( getResponses[ i ] ) )
2562 getResults = main.FALSE
2563 elif getResponses[ i ] == main.ERROR:
2564 getResults = main.FALSE
2565 sizeResponses = []
2566 threads = []
2567 for i in range( numControllers ):
2568 t = main.Thread( target=CLIs[i].setTestSize,
2569 name="setTestSize-" + str( i ),
2570 args=[ onosSetName ] )
2571 threads.append( t )
2572 t.start()
2573 for t in threads:
2574 t.join()
2575 sizeResponses.append( t.result )
2576 sizeResults = main.TRUE
2577 for i in range( numControllers ):
2578 if size != sizeResponses[ i ]:
2579 sizeResults = main.FALSE
2580 main.log.error( "ONOS" + str( i + 1 ) +
2581 " expected a size of " + str( size ) +
2582 " for set " + onosSetName +
2583 " but got " + str( sizeResponses[ i ] ) )
2584 removeAllResults = removeAllResults and getResults and sizeResults
2585 utilities.assert_equals( expect=main.TRUE,
2586 actual=removeAllResults,
2587 onpass="Set removeAll correct",
2588 onfail="Set removeAll was incorrect" )
2589
2590 main.step( "Distributed Set addAll()" )
2591 onosSet.update( addAllValue.split() )
2592 addResponses = []
2593 threads = []
2594 for i in range( numControllers ):
2595 t = main.Thread( target=CLIs[i].setTestAdd,
2596 name="setTestAddAll-" + str( i ),
2597 args=[ onosSetName, addAllValue ] )
2598 threads.append( t )
2599 t.start()
2600 for t in threads:
2601 t.join()
2602 addResponses.append( t.result )
2603
2604 # main.TRUE = successfully changed the set
2605 # main.FALSE = action resulted in no change in set
2606 # main.ERROR - Some error in executing the function
2607 addAllResults = main.TRUE
2608 for i in range( numControllers ):
2609 if addResponses[ i ] == main.TRUE:
2610 # All is well
2611 pass
2612 elif addResponses[ i ] == main.FALSE:
2613 # Already in set, probably fine
2614 pass
2615 elif addResponses[ i ] == main.ERROR:
2616 # Error in execution
2617 addAllResults = main.FALSE
2618 else:
2619 # unexpected result
2620 addAllResults = main.FALSE
2621 if addAllResults != main.TRUE:
2622 main.log.error( "Error executing set addAll" )
2623
2624 # Check if set is still correct
2625 size = len( onosSet )
2626 getResponses = []
2627 threads = []
2628 for i in range( numControllers ):
2629 t = main.Thread( target=CLIs[i].setTestGet,
2630 name="setTestGet-" + str( i ),
2631 args=[ onosSetName ] )
2632 threads.append( t )
2633 t.start()
2634 for t in threads:
2635 t.join()
2636 getResponses.append( t.result )
2637 getResults = main.TRUE
2638 for i in range( numControllers ):
2639 if isinstance( getResponses[ i ], list):
2640 current = set( getResponses[ i ] )
2641 if len( current ) == len( getResponses[ i ] ):
2642 # no repeats
2643 if onosSet != current:
2644 main.log.error( "ONOS" + str( i + 1 ) +
2645 " has incorrect view" +
2646 " of set " + onosSetName + ":\n" +
2647 str( getResponses[ i ] ) )
2648 main.log.debug( "Expected: " + str( onosSet ) )
2649 main.log.debug( "Actual: " + str( current ) )
2650 getResults = main.FALSE
2651 else:
2652 # error, set is not a set
2653 main.log.error( "ONOS" + str( i + 1 ) +
2654 " has repeat elements in" +
2655 " set " + onosSetName + ":\n" +
2656 str( getResponses[ i ] ) )
2657 getResults = main.FALSE
2658 elif getResponses[ i ] == main.ERROR:
2659 getResults = main.FALSE
2660 sizeResponses = []
2661 threads = []
2662 for i in range( numControllers ):
2663 t = main.Thread( target=CLIs[i].setTestSize,
2664 name="setTestSize-" + str( i ),
2665 args=[ onosSetName ] )
2666 threads.append( t )
2667 t.start()
2668 for t in threads:
2669 t.join()
2670 sizeResponses.append( t.result )
2671 sizeResults = main.TRUE
2672 for i in range( numControllers ):
2673 if size != sizeResponses[ i ]:
2674 sizeResults = main.FALSE
2675 main.log.error( "ONOS" + str( i + 1 ) +
2676 " expected a size of " + str( size ) +
2677 " for set " + onosSetName +
2678 " but got " + str( sizeResponses[ i ] ) )
2679 addAllResults = addAllResults and getResults and sizeResults
2680 utilities.assert_equals( expect=main.TRUE,
2681 actual=addAllResults,
2682 onpass="Set addAll correct",
2683 onfail="Set addAll was incorrect" )
2684
2685 main.step( "Distributed Set clear()" )
2686 onosSet.clear()
2687 clearResponses = []
2688 threads = []
2689 for i in range( numControllers ):
2690 t = main.Thread( target=CLIs[i].setTestRemove,
2691 name="setTestClear-" + str( i ),
2692 args=[ onosSetName, " "], # Values doesn't matter
2693 kwargs={ "clear": True } )
2694 threads.append( t )
2695 t.start()
2696 for t in threads:
2697 t.join()
2698 clearResponses.append( t.result )
2699
2700 # main.TRUE = successfully changed the set
2701 # main.FALSE = action resulted in no change in set
2702 # main.ERROR - Some error in executing the function
2703 clearResults = main.TRUE
2704 for i in range( numControllers ):
2705 if clearResponses[ i ] == main.TRUE:
2706 # All is well
2707 pass
2708 elif clearResponses[ i ] == main.FALSE:
2709 # Nothing set, probably fine
2710 pass
2711 elif clearResponses[ i ] == main.ERROR:
2712 # Error in execution
2713 clearResults = main.FALSE
2714 else:
2715 # unexpected result
2716 clearResults = main.FALSE
2717 if clearResults != main.TRUE:
2718 main.log.error( "Error executing set clear" )
2719
2720 # Check if set is still correct
2721 size = len( onosSet )
2722 getResponses = []
2723 threads = []
2724 for i in range( numControllers ):
2725 t = main.Thread( target=CLIs[i].setTestGet,
2726 name="setTestGet-" + str( i ),
2727 args=[ onosSetName ] )
2728 threads.append( t )
2729 t.start()
2730 for t in threads:
2731 t.join()
2732 getResponses.append( t.result )
2733 getResults = main.TRUE
2734 for i in range( numControllers ):
2735 if isinstance( getResponses[ i ], list):
2736 current = set( getResponses[ i ] )
2737 if len( current ) == len( getResponses[ i ] ):
2738 # no repeats
2739 if onosSet != current:
2740 main.log.error( "ONOS" + str( i + 1 ) +
2741 " has incorrect view" +
2742 " of set " + onosSetName + ":\n" +
2743 str( getResponses[ i ] ) )
2744 main.log.debug( "Expected: " + str( onosSet ) )
2745 main.log.debug( "Actual: " + str( current ) )
2746 getResults = main.FALSE
2747 else:
2748 # error, set is not a set
2749 main.log.error( "ONOS" + str( i + 1 ) +
2750 " has repeat elements in" +
2751 " set " + onosSetName + ":\n" +
2752 str( getResponses[ i ] ) )
2753 getResults = main.FALSE
2754 elif getResponses[ i ] == main.ERROR:
2755 getResults = main.FALSE
2756 sizeResponses = []
2757 threads = []
2758 for i in range( numControllers ):
2759 t = main.Thread( target=CLIs[i].setTestSize,
2760 name="setTestSize-" + str( i ),
2761 args=[ onosSetName ] )
2762 threads.append( t )
2763 t.start()
2764 for t in threads:
2765 t.join()
2766 sizeResponses.append( t.result )
2767 sizeResults = main.TRUE
2768 for i in range( numControllers ):
2769 if size != sizeResponses[ i ]:
2770 sizeResults = main.FALSE
2771 main.log.error( "ONOS" + str( i + 1 ) +
2772 " expected a size of " + str( size ) +
2773 " for set " + onosSetName +
2774 " but got " + str( sizeResponses[ i ] ) )
2775 clearResults = clearResults and getResults and sizeResults
2776 utilities.assert_equals( expect=main.TRUE,
2777 actual=clearResults,
2778 onpass="Set clear correct",
2779 onfail="Set clear was incorrect" )
2780
2781 main.step( "Distributed Set addAll()" )
2782 onosSet.update( addAllValue.split() )
2783 addResponses = []
2784 threads = []
2785 for i in range( numControllers ):
2786 t = main.Thread( target=CLIs[i].setTestAdd,
2787 name="setTestAddAll-" + str( i ),
2788 args=[ onosSetName, addAllValue ] )
2789 threads.append( t )
2790 t.start()
2791 for t in threads:
2792 t.join()
2793 addResponses.append( t.result )
2794
2795 # main.TRUE = successfully changed the set
2796 # main.FALSE = action resulted in no change in set
2797 # main.ERROR - Some error in executing the function
2798 addAllResults = main.TRUE
2799 for i in range( numControllers ):
2800 if addResponses[ i ] == main.TRUE:
2801 # All is well
2802 pass
2803 elif addResponses[ i ] == main.FALSE:
2804 # Already in set, probably fine
2805 pass
2806 elif addResponses[ i ] == main.ERROR:
2807 # Error in execution
2808 addAllResults = main.FALSE
2809 else:
2810 # unexpected result
2811 addAllResults = main.FALSE
2812 if addAllResults != main.TRUE:
2813 main.log.error( "Error executing set addAll" )
2814
2815 # Check if set is still correct
2816 size = len( onosSet )
2817 getResponses = []
2818 threads = []
2819 for i in range( numControllers ):
2820 t = main.Thread( target=CLIs[i].setTestGet,
2821 name="setTestGet-" + str( i ),
2822 args=[ onosSetName ] )
2823 threads.append( t )
2824 t.start()
2825 for t in threads:
2826 t.join()
2827 getResponses.append( t.result )
2828 getResults = main.TRUE
2829 for i in range( numControllers ):
2830 if isinstance( getResponses[ i ], list):
2831 current = set( getResponses[ i ] )
2832 if len( current ) == len( getResponses[ i ] ):
2833 # no repeats
2834 if onosSet != current:
2835 main.log.error( "ONOS" + str( i + 1 ) +
2836 " has incorrect view" +
2837 " of set " + onosSetName + ":\n" +
2838 str( getResponses[ i ] ) )
2839 main.log.debug( "Expected: " + str( onosSet ) )
2840 main.log.debug( "Actual: " + str( current ) )
2841 getResults = main.FALSE
2842 else:
2843 # error, set is not a set
2844 main.log.error( "ONOS" + str( i + 1 ) +
2845 " has repeat elements in" +
2846 " set " + onosSetName + ":\n" +
2847 str( getResponses[ i ] ) )
2848 getResults = main.FALSE
2849 elif getResponses[ i ] == main.ERROR:
2850 getResults = main.FALSE
2851 sizeResponses = []
2852 threads = []
2853 for i in range( numControllers ):
2854 t = main.Thread( target=CLIs[i].setTestSize,
2855 name="setTestSize-" + str( i ),
2856 args=[ onosSetName ] )
2857 threads.append( t )
2858 t.start()
2859 for t in threads:
2860 t.join()
2861 sizeResponses.append( t.result )
2862 sizeResults = main.TRUE
2863 for i in range( numControllers ):
2864 if size != sizeResponses[ i ]:
2865 sizeResults = main.FALSE
2866 main.log.error( "ONOS" + str( i + 1 ) +
2867 " expected a size of " + str( size ) +
2868 " for set " + onosSetName +
2869 " but got " + str( sizeResponses[ i ] ) )
2870 addAllResults = addAllResults and getResults and sizeResults
2871 utilities.assert_equals( expect=main.TRUE,
2872 actual=addAllResults,
2873 onpass="Set addAll correct",
2874 onfail="Set addAll was incorrect" )
2875
2876 main.step( "Distributed Set retain()" )
2877 onosSet.intersection_update( retainValue.split() )
2878 retainResponses = []
2879 threads = []
2880 for i in range( numControllers ):
2881 t = main.Thread( target=CLIs[i].setTestRemove,
2882 name="setTestRetain-" + str( i ),
2883 args=[ onosSetName, retainValue ],
2884 kwargs={ "retain": True } )
2885 threads.append( t )
2886 t.start()
2887 for t in threads:
2888 t.join()
2889 retainResponses.append( t.result )
2890
2891 # main.TRUE = successfully changed the set
2892 # main.FALSE = action resulted in no change in set
2893 # main.ERROR - Some error in executing the function
2894 retainResults = main.TRUE
2895 for i in range( numControllers ):
2896 if retainResponses[ i ] == main.TRUE:
2897 # All is well
2898 pass
2899 elif retainResponses[ i ] == main.FALSE:
2900 # Already in set, probably fine
2901 pass
2902 elif retainResponses[ i ] == main.ERROR:
2903 # Error in execution
2904 retainResults = main.FALSE
2905 else:
2906 # unexpected result
2907 retainResults = main.FALSE
2908 if retainResults != main.TRUE:
2909 main.log.error( "Error executing set retain" )
2910
2911 # Check if set is still correct
2912 size = len( onosSet )
2913 getResponses = []
2914 threads = []
2915 for i in range( numControllers ):
2916 t = main.Thread( target=CLIs[i].setTestGet,
2917 name="setTestGet-" + str( i ),
2918 args=[ onosSetName ] )
2919 threads.append( t )
2920 t.start()
2921 for t in threads:
2922 t.join()
2923 getResponses.append( t.result )
2924 getResults = main.TRUE
2925 for i in range( numControllers ):
2926 if isinstance( getResponses[ i ], list):
2927 current = set( getResponses[ i ] )
2928 if len( current ) == len( getResponses[ i ] ):
2929 # no repeats
2930 if onosSet != current:
2931 main.log.error( "ONOS" + str( i + 1 ) +
2932 " has incorrect view" +
2933 " of set " + onosSetName + ":\n" +
2934 str( getResponses[ i ] ) )
2935 main.log.debug( "Expected: " + str( onosSet ) )
2936 main.log.debug( "Actual: " + str( current ) )
2937 getResults = main.FALSE
2938 else:
2939 # error, set is not a set
2940 main.log.error( "ONOS" + str( i + 1 ) +
2941 " has repeat elements in" +
2942 " set " + onosSetName + ":\n" +
2943 str( getResponses[ i ] ) )
2944 getResults = main.FALSE
2945 elif getResponses[ i ] == main.ERROR:
2946 getResults = main.FALSE
2947 sizeResponses = []
2948 threads = []
2949 for i in range( numControllers ):
2950 t = main.Thread( target=CLIs[i].setTestSize,
2951 name="setTestSize-" + str( i ),
2952 args=[ onosSetName ] )
2953 threads.append( t )
2954 t.start()
2955 for t in threads:
2956 t.join()
2957 sizeResponses.append( t.result )
2958 sizeResults = main.TRUE
2959 for i in range( numControllers ):
2960 if size != sizeResponses[ i ]:
2961 sizeResults = main.FALSE
2962 main.log.error( "ONOS" + str( i + 1 ) +
2963 " expected a size of " +
2964 str( size ) + " for set " + onosSetName +
2965 " but got " + str( sizeResponses[ i ] ) )
2966 retainResults = retainResults and getResults and sizeResults
2967 utilities.assert_equals( expect=main.TRUE,
2968 actual=retainResults,
2969 onpass="Set retain correct",
2970 onfail="Set retain was incorrect" )
2971