blob: 4dcf0dd58d22b3a77bbf5c769913ffd37991949d [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 Halla9d26da2015-03-30 16:45:32 -0700475 if intentAddResult:
476 intentStop = time.time()
477 else:
478 intentStop = None
Jon Hall1b8f54a2015-02-04 13:24:20 -0800479 # Print the intent states
Jon Hall58c76b72015-02-23 11:09:24 -0800480 intents = main.ONOScli1.intents()
Jon Hall1b8f54a2015-02-04 13:24:20 -0800481 intentStates = []
Jon Halla9d26da2015-03-30 16:45:32 -0700482 installedCheck = True
Jon Hall58c76b72015-02-23 11:09:24 -0800483 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
484 count = 0
Jon Hall5cfd23c2015-03-19 11:40:57 -0700485 try:
486 for intent in json.loads( intents ):
487 state = intent.get( 'state', None )
488 if "INSTALLED" not in state:
489 installedCheck = False
490 intentId = intent.get( 'id', None )
491 intentStates.append( ( intentId, state ) )
492 except ( ValueError, TypeError ):
493 main.log.exception( "Error parsing intents" )
Jon Hall58c76b72015-02-23 11:09:24 -0800494 # add submitted intents not in the store
495 tmplist = [ i for i, s in intentStates ]
496 missingIntents = False
497 for i in intentIds:
498 if i not in tmplist:
499 intentStates.append( ( i, " - " ) )
500 missingIntents = True
501 intentStates.sort()
502 for i, s in intentStates:
503 count += 1
504 main.log.info( "%-6s%-15s%-15s" %
505 ( str( count ), str( i ), str( s ) ) )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700506 leaders = main.ONOScli1.leaders()
507 try:
Jon Hallafa8a472015-06-12 14:02:42 -0700508 missing = False
Jon Hall5cfd23c2015-03-19 11:40:57 -0700509 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" )
Jon Hallafa8a472015-06-12 14:02:42 -0700525 missing = True
Jon Hall5cfd23c2015-03-19 11:40:57 -0700526 else:
527 main.log.error( "leaders() returned None" )
528 except ( ValueError, TypeError ):
529 main.log.exception( "Error parsing leaders" )
530 main.log.error( repr( leaders ) )
Jon Hallafa8a472015-06-12 14:02:42 -0700531 # Check all nodes
532 if missing:
533 response = main.ONOScli1.leaders( jsonFormat=False)
534 main.log.warn( "ONOS1 leaders output: \n" +
535 str( response ) )
536
Jon Hall5cfd23c2015-03-19 11:40:57 -0700537 partitions = main.ONOScli1.partitions()
538 try:
539 if partitions :
540 parsedPartitions = json.loads( partitions )
541 main.log.warn( json.dumps( parsedPartitions,
542 sort_keys=True,
543 indent=4,
544 separators=( ',', ': ' ) ) )
545 # TODO check for a leader in all paritions
546 # TODO check for consistency among nodes
547 else:
548 main.log.error( "partitions() returned None" )
549 except ( ValueError, TypeError ):
550 main.log.exception( "Error parsing partitions" )
551 main.log.error( repr( partitions ) )
Jon Hall63604932015-02-26 17:09:50 -0800552 pendingMap = main.ONOScli1.pendingMap()
Jon Hall5cfd23c2015-03-19 11:40:57 -0700553 try:
554 if pendingMap :
555 parsedPending = json.loads( pendingMap )
556 main.log.warn( json.dumps( parsedPending,
557 sort_keys=True,
558 indent=4,
559 separators=( ',', ': ' ) ) )
560 # TODO check something here?
561 else:
562 main.log.error( "pendingMap() returned None" )
563 except ( ValueError, TypeError ):
564 main.log.exception( "Error parsing pending map" )
565 main.log.error( repr( pendingMap ) )
566
Jon Hallfeff3082015-05-19 10:23:26 -0700567 intentAddResult = bool( intentAddResult and not missingIntents and
568 installedCheck )
569 if not intentAddResult:
570 main.log.error( "Error in pushing host intents to ONOS" )
571
Jon Hall390696c2015-05-05 17:13:41 -0700572 main.step( "Intent Anti-Entropy dispersion" )
573 for i in range(100):
574 correct = True
575 main.log.info( "Submitted intents: " + str( sorted( intentIds ) ) )
576 for cli in CLIs:
577 onosIds = []
578 ids = cli.getAllIntentsId()
579 onosIds.append( ids )
580 main.log.debug( "Intents in " + cli.name + ": " +
581 str( sorted( onosIds ) ) )
582 if sorted( ids ) != sorted( intentIds ):
Jon Hallafa8a472015-06-12 14:02:42 -0700583 main.log.warn( "Set of intent IDs doesn't match" )
Jon Hall390696c2015-05-05 17:13:41 -0700584 correct = False
Jon Hallafa8a472015-06-12 14:02:42 -0700585 break
586 else:
587 intents = json.loads( cli.intents() )
588 for intent in intents:
589 if intent[ 'state' ] != "INSTALLED":
590 main.log.warn( "Intent " + intent[ 'id' ] +
591 " is " + intent[ 'state' ] )
592 correct = False
593 break
Jon Hall390696c2015-05-05 17:13:41 -0700594 if correct:
595 break
596 else:
597 time.sleep(1)
598 if not intentStop:
599 intentStop = time.time()
600 global gossipTime
601 gossipTime = intentStop - intentStart
602 main.log.info( "It took about " + str( gossipTime ) +
603 " seconds for all intents to appear in each node" )
604 # FIXME: make this time configurable/calculate based off of number of
605 # nodes and gossip rounds
606 utilities.assert_greater_equals(
607 expect=40, actual=gossipTime,
608 onpass="ECM anti-entropy for intents worked within " +
609 "expected time",
610 onfail="Intent ECM anti-entropy took too long" )
611 if gossipTime <= 40:
612 intentAddResult = True
Jon Hall58c76b72015-02-23 11:09:24 -0800613
Jon Hall63604932015-02-26 17:09:50 -0800614 if not intentAddResult or "key" in pendingMap:
Jon Hall58c76b72015-02-23 11:09:24 -0800615 import time
Jon Hall63604932015-02-26 17:09:50 -0800616 installedCheck = True
Jon Hall58c76b72015-02-23 11:09:24 -0800617 main.log.info( "Sleeping 60 seconds to see if intents are found" )
618 time.sleep( 60 )
619 onosIds = main.ONOScli1.getAllIntentsId()
620 main.log.info( "Submitted intents: " + str( intentIds ) )
621 main.log.info( "Intents in ONOS: " + str( onosIds ) )
622 # Print the intent states
623 intents = main.ONOScli1.intents()
624 intentStates = []
625 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
626 count = 0
Jon Hall5cfd23c2015-03-19 11:40:57 -0700627 try:
628 for intent in json.loads( intents ):
629 # Iter through intents of a node
630 state = intent.get( 'state', None )
631 if "INSTALLED" not in state:
632 installedCheck = False
633 intentId = intent.get( 'id', None )
634 intentStates.append( ( intentId, state ) )
635 except ( ValueError, TypeError ):
636 main.log.exception( "Error parsing intents" )
Jon Hall58c76b72015-02-23 11:09:24 -0800637 # add submitted intents not in the store
638 tmplist = [ i for i, s in intentStates ]
639 for i in intentIds:
640 if i not in tmplist:
641 intentStates.append( ( i, " - " ) )
642 intentStates.sort()
643 for i, s in intentStates:
644 count += 1
645 main.log.info( "%-6s%-15s%-15s" %
646 ( str( count ), str( i ), str( s ) ) )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700647 leaders = main.ONOScli1.leaders()
648 try:
Jon Hallafa8a472015-06-12 14:02:42 -0700649 missing = False
Jon Hall5cfd23c2015-03-19 11:40:57 -0700650 if leaders:
651 parsedLeaders = json.loads( leaders )
652 main.log.warn( json.dumps( parsedLeaders,
653 sort_keys=True,
654 indent=4,
655 separators=( ',', ': ' ) ) )
656 # check for all intent partitions
657 # check for election
658 topics = []
659 for i in range( 14 ):
660 topics.append( "intent-partition-" + str( i ) )
661 # FIXME: this should only be after we start the app
662 topics.append( "org.onosproject.election" )
663 main.log.debug( topics )
664 ONOStopics = [ j['topic'] for j in parsedLeaders ]
665 for topic in topics:
666 if topic not in ONOStopics:
667 main.log.error( "Error: " + topic +
668 " not in leaders" )
Jon Hallafa8a472015-06-12 14:02:42 -0700669 missing = True
Jon Hall5cfd23c2015-03-19 11:40:57 -0700670 else:
671 main.log.error( "leaders() returned None" )
672 except ( ValueError, TypeError ):
673 main.log.exception( "Error parsing leaders" )
674 main.log.error( repr( leaders ) )
Jon Hallafa8a472015-06-12 14:02:42 -0700675 # Check all nodes
676 if missing:
677 response = main.ONOScli1.leaders( jsonFormat=False)
678 main.log.warn( "ONOS1 leaders output: \n" +
679 str( response ) )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700680 partitions = main.ONOScli1.partitions()
681 try:
682 if partitions :
683 parsedPartitions = json.loads( partitions )
684 main.log.warn( json.dumps( parsedPartitions,
685 sort_keys=True,
686 indent=4,
687 separators=( ',', ': ' ) ) )
688 # TODO check for a leader in all paritions
689 # TODO check for consistency among nodes
690 else:
691 main.log.error( "partitions() returned None" )
692 except ( ValueError, TypeError ):
693 main.log.exception( "Error parsing partitions" )
694 main.log.error( repr( partitions ) )
695 pendingMap = main.ONOScli1.pendingMap()
696 try:
697 if pendingMap :
698 parsedPending = json.loads( pendingMap )
699 main.log.warn( json.dumps( parsedPending,
700 sort_keys=True,
701 indent=4,
702 separators=( ',', ': ' ) ) )
703 # TODO check something here?
704 else:
705 main.log.error( "pendingMap() returned None" )
706 except ( ValueError, TypeError ):
707 main.log.exception( "Error parsing pending map" )
708 main.log.error( repr( pendingMap ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800709
Jon Hall6aec96b2015-01-19 14:49:31 -0800710 def CASE4( self, main ):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800711 """
712 Ping across added host intents
713 """
Jon Hallfebb1c72015-03-05 13:30:09 -0800714 import json
Jon Halla9d26da2015-03-30 16:45:32 -0700715 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -0700716 assert numControllers, "numControllers not defined"
717 assert main, "main not defined"
718 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hallfeff3082015-05-19 10:23:26 -0700719 main.case( "Verify connectivity by sendind traffic across Intents" )
720 main.caseExplaination = "Ping across added host intents to check " +\
721 "functionality and check the state of " +\
722 "the intent"
723 main.step( "Ping across added host intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800724 PingResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800725 for i in range( 8, 18 ):
Jon Hall58c76b72015-02-23 11:09:24 -0800726 ping = main.Mininet1.pingHost( src="h" + str( i ),
727 target="h" + str( i + 10 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800728 PingResult = PingResult and ping
Jon Hall6aec96b2015-01-19 14:49:31 -0800729 if ping == main.FALSE:
730 main.log.warn( "Ping failed between h" + str( i ) +
731 " and h" + str( i + 10 ) )
732 elif ping == main.TRUE:
733 main.log.info( "Ping test passed!" )
Jon Hall21270ac2015-02-16 17:59:55 -0800734 # Don't set PingResult or you'd override failures
Jon Hall8f89dda2015-01-22 16:03:33 -0800735 if PingResult == main.FALSE:
Jon Hall40d2cbd2015-06-03 16:24:29 -0700736 main.log.error(
Jon Hall6aec96b2015-01-19 14:49:31 -0800737 "Intents have not been installed correctly, pings failed." )
Jon Hall58c76b72015-02-23 11:09:24 -0800738 # TODO: pretty print
Jon Hall5cfd23c2015-03-19 11:40:57 -0700739 main.log.warn( "ONOS1 intents: " )
740 try:
741 tmpIntents = main.ONOScli1.intents()
742 main.log.warn( json.dumps( json.loads( tmpIntents ),
743 sort_keys=True,
744 indent=4,
745 separators=( ',', ': ' ) ) )
746 except ( ValueError, TypeError ):
747 main.log.warn( repr( tmpIntents ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800748 utilities.assert_equals(
749 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800750 actual=PingResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800751 onpass="Intents have been installed correctly and pings work",
752 onfail="Intents have not been installed correctly, pings failed." )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800753
Jon Hallfeff3082015-05-19 10:23:26 -0700754 main.step( "Check Intent state" )
Jon Hall63604932015-02-26 17:09:50 -0800755 installedCheck = True
Jon Hallfeff3082015-05-19 10:23:26 -0700756 # Print the intent states
757 intents = main.ONOScli1.intents()
758 intentStates = []
759 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
760 count = 0
761 # Iter through intents of a node
762 try:
763 for intent in json.loads( intents ):
764 state = intent.get( 'state', None )
765 if "INSTALLED" not in state:
766 installedCheck = False
767 intentId = intent.get( 'id', None )
768 intentStates.append( ( intentId, state ) )
769 except ( ValueError, TypeError ):
770 main.log.exception( "Error parsing intents." )
771 # Print states
772 intentStates.sort()
773 for i, s in intentStates:
774 count += 1
775 main.log.info( "%-6s%-15s%-15s" %
776 ( str( count ), str( i ), str( s ) ) )
777 utilities.assert_equals( expect=True, actual=installedCheck,
778 onpass="Intents are all INSTALLED",
Jon Hall40d2cbd2015-06-03 16:24:29 -0700779 onfail="Intents are not all in " +
Jon Hallfeff3082015-05-19 10:23:26 -0700780 "INSTALLED state" )
781
782 main.step( "Check leadership of topics" )
783 leaders = main.ONOScli1.leaders()
784 topicCheck = main.TRUE
785 try:
786 if leaders:
787 parsedLeaders = json.loads( leaders )
788 main.log.warn( json.dumps( parsedLeaders,
789 sort_keys=True,
790 indent=4,
791 separators=( ',', ': ' ) ) )
792 # check for all intent partitions
793 # check for election
794 # TODO: Look at Devices as topics now that it uses this system
795 topics = []
796 for i in range( 14 ):
797 topics.append( "intent-partition-" + str( i ) )
798 # FIXME: this should only be after we start the app
799 # FIXME: topics.append( "org.onosproject.election" )
800 # Print leaders output
801 main.log.debug( topics )
802 ONOStopics = [ j['topic'] for j in parsedLeaders ]
803 for topic in topics:
804 if topic not in ONOStopics:
805 main.log.error( "Error: " + topic +
806 " not in leaders" )
807 topicCheck = main.FALSE
808 else:
809 main.log.error( "leaders() returned None" )
810 topicCheck = main.FALSE
811 except ( ValueError, TypeError ):
812 topicCheck = main.FALSE
813 main.log.exception( "Error parsing leaders" )
814 main.log.error( repr( leaders ) )
815 # TODO: Check for a leader of these topics
816 utilities.assert_equals( expect=main.TRUE, actual=topicCheck,
817 onpass="intent Partitions is in leaders",
818 onfail="Some topics were lost " )
819 # Print partitions
820 partitions = main.ONOScli1.partitions()
821 try:
822 if partitions :
823 parsedPartitions = json.loads( partitions )
824 main.log.warn( json.dumps( parsedPartitions,
825 sort_keys=True,
826 indent=4,
827 separators=( ',', ': ' ) ) )
828 # TODO check for a leader in all paritions
829 # TODO check for consistency among nodes
830 else:
831 main.log.error( "partitions() returned None" )
832 except ( ValueError, TypeError ):
833 main.log.exception( "Error parsing partitions" )
834 main.log.error( repr( partitions ) )
835 # Print Pending Map
836 pendingMap = main.ONOScli1.pendingMap()
837 try:
838 if pendingMap :
839 parsedPending = json.loads( pendingMap )
840 main.log.warn( json.dumps( parsedPending,
841 sort_keys=True,
842 indent=4,
843 separators=( ',', ': ' ) ) )
844 # TODO check something here?
845 else:
846 main.log.error( "pendingMap() returned None" )
847 except ( ValueError, TypeError ):
848 main.log.exception( "Error parsing pending map" )
849 main.log.error( repr( pendingMap ) )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700850
Jon Hall63604932015-02-26 17:09:50 -0800851 if not installedCheck:
Jon Hall5cfd23c2015-03-19 11:40:57 -0700852 main.log.info( "Waiting 60 seconds to see if the state of " +
853 "intents change" )
Jon Hall63604932015-02-26 17:09:50 -0800854 time.sleep( 60 )
855 # Print the intent states
856 intents = main.ONOScli1.intents()
857 intentStates = []
858 main.log.info( "%-6s%-15s%-15s" % ( 'Count', 'ID', 'State' ) )
859 count = 0
860 # Iter through intents of a node
Jon Hall5cfd23c2015-03-19 11:40:57 -0700861 try:
862 for intent in json.loads( intents ):
863 state = intent.get( 'state', None )
864 if "INSTALLED" not in state:
865 installedCheck = False
866 intentId = intent.get( 'id', None )
867 intentStates.append( ( intentId, state ) )
868 except ( ValueError, TypeError ):
869 main.log.exception( "Error parsing intents." )
Jon Hall63604932015-02-26 17:09:50 -0800870 intentStates.sort()
871 for i, s in intentStates:
872 count += 1
873 main.log.info( "%-6s%-15s%-15s" %
874 ( str( count ), str( i ), str( s ) ) )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700875 leaders = main.ONOScli1.leaders()
876 try:
Jon Hallafa8a472015-06-12 14:02:42 -0700877 missing = False
Jon Hall5cfd23c2015-03-19 11:40:57 -0700878 if leaders:
879 parsedLeaders = json.loads( leaders )
880 main.log.warn( json.dumps( parsedLeaders,
881 sort_keys=True,
882 indent=4,
883 separators=( ',', ': ' ) ) )
884 # check for all intent partitions
885 # check for election
886 topics = []
887 for i in range( 14 ):
888 topics.append( "intent-partition-" + str( i ) )
889 # FIXME: this should only be after we start the app
890 topics.append( "org.onosproject.election" )
891 main.log.debug( topics )
892 ONOStopics = [ j['topic'] for j in parsedLeaders ]
893 for topic in topics:
894 if topic not in ONOStopics:
895 main.log.error( "Error: " + topic +
896 " not in leaders" )
Jon Hallafa8a472015-06-12 14:02:42 -0700897 missing = True
Jon Hall5cfd23c2015-03-19 11:40:57 -0700898 else:
899 main.log.error( "leaders() returned None" )
900 except ( ValueError, TypeError ):
901 main.log.exception( "Error parsing leaders" )
902 main.log.error( repr( leaders ) )
Jon Hallafa8a472015-06-12 14:02:42 -0700903 if missing:
904 response = main.ONOScli1.leaders( jsonFormat=False)
905 main.log.warn( "ONOS1 leaders output: \n" +
906 str( response ) )
Jon Hall5cfd23c2015-03-19 11:40:57 -0700907 partitions = main.ONOScli1.partitions()
908 try:
909 if partitions :
910 parsedPartitions = json.loads( partitions )
911 main.log.warn( json.dumps( parsedPartitions,
912 sort_keys=True,
913 indent=4,
914 separators=( ',', ': ' ) ) )
915 # TODO check for a leader in all paritions
916 # TODO check for consistency among nodes
917 else:
918 main.log.error( "partitions() returned None" )
919 except ( ValueError, TypeError ):
920 main.log.exception( "Error parsing partitions" )
921 main.log.error( repr( partitions ) )
922 pendingMap = main.ONOScli1.pendingMap()
923 try:
924 if pendingMap :
925 parsedPending = json.loads( pendingMap )
926 main.log.warn( json.dumps( parsedPending,
927 sort_keys=True,
928 indent=4,
929 separators=( ',', ': ' ) ) )
930 # TODO check something here?
931 else:
932 main.log.error( "pendingMap() returned None" )
933 except ( ValueError, TypeError ):
934 main.log.exception( "Error parsing pending map" )
935 main.log.error( repr( pendingMap ) )
Jon Hall40d2cbd2015-06-03 16:24:29 -0700936 # Print flowrules
937 main.log.debug( CLIs[0].flows( jsonFormat=False ) )
Jon Hallfeff3082015-05-19 10:23:26 -0700938 main.step( "Wait a minute then ping again" )
Jon Hall40d2cbd2015-06-03 16:24:29 -0700939 # the wait is above
Jon Hallfeff3082015-05-19 10:23:26 -0700940 PingResult = main.TRUE
941 for i in range( 8, 18 ):
942 ping = main.Mininet1.pingHost( src="h" + str( i ),
943 target="h" + str( i + 10 ) )
944 PingResult = PingResult and ping
945 if ping == main.FALSE:
946 main.log.warn( "Ping failed between h" + str( i ) +
947 " and h" + str( i + 10 ) )
948 elif ping == main.TRUE:
949 main.log.info( "Ping test passed!" )
950 # Don't set PingResult or you'd override failures
951 if PingResult == main.FALSE:
Jon Hall40d2cbd2015-06-03 16:24:29 -0700952 main.log.error(
Jon Hallfeff3082015-05-19 10:23:26 -0700953 "Intents have not been installed correctly, pings failed." )
954 # TODO: pretty print
955 main.log.warn( "ONOS1 intents: " )
956 try:
957 tmpIntents = main.ONOScli1.intents()
958 main.log.warn( json.dumps( json.loads( tmpIntents ),
959 sort_keys=True,
960 indent=4,
961 separators=( ',', ': ' ) ) )
962 except ( ValueError, TypeError ):
963 main.log.warn( repr( tmpIntents ) )
964 utilities.assert_equals(
965 expect=main.TRUE,
966 actual=PingResult,
967 onpass="Intents have been installed correctly and pings work",
968 onfail="Intents have not been installed correctly, pings failed." )
969
Jon Hall6aec96b2015-01-19 14:49:31 -0800970 def CASE5( self, main ):
971 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800972 Reading state of ONOS
Jon Hall6aec96b2015-01-19 14:49:31 -0800973 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800974 import json
Jon Hall5cfd23c2015-03-19 11:40:57 -0700975 assert numControllers, "numControllers not defined"
976 assert main, "main not defined"
977 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall73cf9cc2014-11-20 22:28:38 -0800978
Jon Hall6aec96b2015-01-19 14:49:31 -0800979 main.case( "Setting up and gathering data for current state" )
980 # The general idea for this test case is to pull the state of
981 # ( intents,flows, topology,... ) from each ONOS node
Jon Hall5cfd23c2015-03-19 11:40:57 -0700982 # We can then compare them with each other and also with past states
Jon Hall73cf9cc2014-11-20 22:28:38 -0800983
Jon Halla9d26da2015-03-30 16:45:32 -0700984 main.step( "Check that each switch has a master" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800985 global mastershipState
Jon Halla9d26da2015-03-30 16:45:32 -0700986 mastershipState = '[]'
Jon Hall94fd0472014-12-08 11:52:42 -0800987
Jon Hall6aec96b2015-01-19 14:49:31 -0800988 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -0800989 rolesNotNull = main.ONOScli1.rolesNotNull()
Jon Hall6aec96b2015-01-19 14:49:31 -0800990 utilities.assert_equals(
991 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800992 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -0800993 onpass="Each device has a master",
994 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -0800995
Jon Hall390696c2015-05-05 17:13:41 -0700996 main.step( "Get the Mastership of each switch" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800997 ONOS1Mastership = main.ONOScli1.roles()
Jon Hall6aec96b2015-01-19 14:49:31 -0800998 # TODO: Make this a meaningful check
Jon Hall8f89dda2015-01-22 16:03:33 -0800999 if "Error" in ONOS1Mastership or not ONOS1Mastership:
Jon Hall40d2cbd2015-06-03 16:24:29 -07001000 main.log.error( "Error in getting ONOS roles" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001001 main.log.warn(
1002 "ONOS1 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001003 repr( ONOS1Mastership ) )
1004 consistentMastership = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001005 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001006 mastershipState = ONOS1Mastership
1007 consistentMastership = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001008
Jon Hall6aec96b2015-01-19 14:49:31 -08001009 main.step( "Get the intents from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001010 global intentState
1011 intentState = []
1012 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
1013 intentCheck = main.FALSE
1014 if "Error" in ONOS1Intents or not ONOS1Intents:
Jon Hall40d2cbd2015-06-03 16:24:29 -07001015 main.log.error( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001016 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001017 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001018 intentCheck = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001019
Jon Hall6aec96b2015-01-19 14:49:31 -08001020 main.step( "Get the flows from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001021 global flowState
1022 flowState = []
Jon Hall8f89dda2015-01-22 16:03:33 -08001023 flowCheck = main.FALSE
Jon Hall58c76b72015-02-23 11:09:24 -08001024 ONOS1Flows = main.ONOScli1.flows( jsonFormat=True )
Jon Hall8f89dda2015-01-22 16:03:33 -08001025 if "Error" in ONOS1Flows or not ONOS1Flows:
Jon Hall40d2cbd2015-06-03 16:24:29 -07001026 main.log.error( "Error in getting ONOS flows" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001027 main.log.warn( "ONOS1 flows repsponse: " + ONOS1Flows )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001028 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001029 # TODO: Do a better check, maybe compare flows on switches?
Jon Hall8f89dda2015-01-22 16:03:33 -08001030 flowState = ONOS1Flows
1031 flowCheck = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001032
Jon Hall6aec96b2015-01-19 14:49:31 -08001033 main.step( "Get the OF Table entries" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001034 global flows
Jon Hall6aec96b2015-01-19 14:49:31 -08001035 flows = []
1036 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -08001037 flows.append( main.Mininet2.getFlowTable( 1.3, "s" + str( i ) ) )
Jon Hall58c76b72015-02-23 11:09:24 -08001038 if flowCheck == main.FALSE:
1039 for table in flows:
1040 main.log.warn( table )
Jon Hall6aec96b2015-01-19 14:49:31 -08001041 # TODO: Compare switch flow tables with ONOS flow tables
Jon Hall73cf9cc2014-11-20 22:28:38 -08001042
Jon Hall6aec96b2015-01-19 14:49:31 -08001043 main.step( "Collecting topology information from ONOS" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001044 devices = []
1045 devices.append( main.ONOScli1.devices() )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001046 hosts = []
Jon Hall58c76b72015-02-23 11:09:24 -08001047 hosts.append( json.loads( main.ONOScli1.hosts() ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001048 ports = []
1049 ports.append( main.ONOScli1.ports() )
1050 links = []
1051 links.append( main.ONOScli1.links() )
Jon Hall58c76b72015-02-23 11:09:24 -08001052 clusters = []
1053 clusters.append( main.ONOScli1.clusters() )
Jon Hall390696c2015-05-05 17:13:41 -07001054
1055 main.step( "Each host has an IP address" )
Jon Hall58c76b72015-02-23 11:09:24 -08001056 ipResult = main.TRUE
1057 for controller in range( 0, len( hosts ) ):
1058 controllerStr = str( controller + 1 )
1059 for host in hosts[ controller ]:
Jon Hallfeff3082015-05-19 10:23:26 -07001060 if host is None or host.get( 'ipAddresses', [] ) == []:
Jon Hall58c76b72015-02-23 11:09:24 -08001061 main.log.error(
1062 "DEBUG:Error with host ips on controller" +
1063 controllerStr + ": " + str( host ) )
1064 ipResult = main.FALSE
Jon Hall390696c2015-05-05 17:13:41 -07001065 utilities.assert_equals(
1066 expect=main.TRUE,
1067 actual=ipResult,
1068 onpass="The ips of the hosts aren't empty",
1069 onfail="The ip of at least one host is missing" )
Jon Hall58c76b72015-02-23 11:09:24 -08001070
1071 # there should always only be one cluster
Jon Hall390696c2015-05-05 17:13:41 -07001072 main.step( "There is only one dataplane cluster" )
1073 try:
1074 numClusters = len( json.loads( clusters[ 0 ] ) )
1075 except ( ValueError, TypeError ):
1076 main.log.exception( "Error parsing clusters[0]: " +
1077 repr( clusters[ 0 ] ) )
Jon Hall58c76b72015-02-23 11:09:24 -08001078 clusterResults = main.FALSE
1079 if numClusters == 1:
1080 clusterResults = main.TRUE
1081 utilities.assert_equals(
1082 expect=1,
1083 actual=numClusters,
1084 onpass="ONOS shows 1 SCC",
1085 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001086
Jon Hall6aec96b2015-01-19 14:49:31 -08001087 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001088 devicesResults = main.TRUE
Jon Hall8f89dda2015-01-22 16:03:33 -08001089 linksResults = main.TRUE
Jon Hall58c76b72015-02-23 11:09:24 -08001090 hostsResults = main.TRUE
Jon Hallafa8a472015-06-12 14:02:42 -07001091 mnSwitches = main.Mininet1.getSwitches()
1092 mnLinks = main.Mininet1.getLinks()
1093 mnHosts = main.Mininet1.getHosts()
Jon Hall8f89dda2015-01-22 16:03:33 -08001094 for controller in range( numControllers ):
1095 controllerStr = str( controller + 1 )
Jon Hallafa8a472015-06-12 14:02:42 -07001096 if devices[ controller ] and ports[ controller ] and\
1097 "Error" not in devices[ controller ] and\
1098 "Error" not in ports[ controller ]:
1099
Jon Hall8f89dda2015-01-22 16:03:33 -08001100 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hallafa8a472015-06-12 14:02:42 -07001101 mnSwitches,
1102 json.loads( devices[ controller ] ),
1103 json.loads( ports[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001104 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001105 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001106 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001107 actual=currentDevicesResult,
1108 onpass="ONOS" + controllerStr +
1109 " Switches view is correct",
1110 onfail="ONOS" + controllerStr +
1111 " Switches view is incorrect" )
Jon Hallafa8a472015-06-12 14:02:42 -07001112 if links[ controller ] and "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001113 currentLinksResult = main.Mininet1.compareLinks(
Jon Hallafa8a472015-06-12 14:02:42 -07001114 mnSwitches, mnLinks,
1115 json.loads( links[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001116 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001117 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001118 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001119 actual=currentLinksResult,
1120 onpass="ONOS" + controllerStr +
1121 " links view is correct",
1122 onfail="ONOS" + controllerStr +
1123 " links view is incorrect" )
1124
1125 if hosts[ controller ] or "Error" not in hosts[ controller ]:
1126 currentHostsResult = main.Mininet1.compareHosts(
Jon Hallafa8a472015-06-12 14:02:42 -07001127 mnHosts,
1128 hosts[ controller ] )
Jon Hall58c76b72015-02-23 11:09:24 -08001129 else:
1130 currentHostsResult = main.FALSE
1131 utilities.assert_equals( expect=main.TRUE,
1132 actual=currentHostsResult,
1133 onpass="ONOS" + controllerStr +
1134 " hosts exist in Mininet",
1135 onfail="ONOS" + controllerStr +
1136 " hosts don't match Mininet" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001137
Jon Hall8f89dda2015-01-22 16:03:33 -08001138 devicesResults = devicesResults and currentDevicesResult
Jon Hall8f89dda2015-01-22 16:03:33 -08001139 linksResults = linksResults and currentLinksResult
Jon Hall58c76b72015-02-23 11:09:24 -08001140 hostsResults = hostsResults and currentHostsResult
Jon Hall73cf9cc2014-11-20 22:28:38 -08001141
Jon Hallafa8a472015-06-12 14:02:42 -07001142 main.step( "Device information is correct" )
1143 utilities.assert_equals(
1144 expect=main.TRUE,
1145 actual=devicesResults,
1146 onpass="Device information is correct",
1147 onfail="Device information is incorrect" )
1148
1149 main.step( "Links are correct" )
1150 utilities.assert_equals(
1151 expect=main.TRUE,
1152 actual=linksResults,
1153 onpass="Link are correct",
1154 onfail="Links are incorrect" )
1155
1156 main.step( "Hosts are correct" )
1157 utilities.assert_equals(
1158 expect=main.TRUE,
1159 actual=hostsResults,
1160 onpass="Hosts are correct",
1161 onfail="Hosts are incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001162
Jon Hall6aec96b2015-01-19 14:49:31 -08001163 def CASE6( self, main ):
1164 """
Jon Hallffb386d2014-11-21 13:43:38 -08001165 The Failure case.
Jon Hall6aec96b2015-01-19 14:49:31 -08001166 """
Jon Hallffb386d2014-11-21 13:43:38 -08001167 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001168 assert numControllers, "numControllers not defined"
1169 assert main, "main not defined"
1170 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall73cf9cc2014-11-20 22:28:38 -08001171
Jon Hall390696c2015-05-05 17:13:41 -07001172 # Reset non-persistent variables
1173 try:
1174 iCounterValue = 0
1175 except NameError:
1176 main.log.error( "iCounterValue not defined, setting to 0" )
1177 iCounterValue = 0
1178
Jon Hallfeff3082015-05-19 10:23:26 -07001179 main.case( "Restart ONOS node" )
1180 main.caseExplaination = "Killing ONOS process and restart cli " +\
1181 "sessions once onos is up."
Jon Hall390696c2015-05-05 17:13:41 -07001182 main.step( "Killing ONOS processes" )
1183 killResult = main.ONOSbench.onosKill( ONOS1Ip )
Jon Hallffb386d2014-11-21 13:43:38 -08001184 start = time.time()
Jon Hall390696c2015-05-05 17:13:41 -07001185 utilities.assert_equals( expect=main.TRUE, actual=killResult,
1186 onpass="ONOS Killed",
1187 onfail="Error killing ONOS" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001188
Jon Hall6aec96b2015-01-19 14:49:31 -08001189 main.step( "Checking if ONOS is up yet" )
Jon Hallffb386d2014-11-21 13:43:38 -08001190 count = 0
Jon Hall94fd0472014-12-08 11:52:42 -08001191 while count < 10:
Jon Hall8f89dda2015-01-22 16:03:33 -08001192 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
1193 if onos1Isup == main.TRUE:
Jon Hallffb386d2014-11-21 13:43:38 -08001194 elapsed = time.time() - start
1195 break
1196 else:
1197 count = count + 1
Jon Hall390696c2015-05-05 17:13:41 -07001198 utilities.assert_equals( expect=main.TRUE, actual=onos1Isup,
1199 onpass="ONOS is back up",
1200 onfail="ONOS failed to start" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001201
Jon Hall390696c2015-05-05 17:13:41 -07001202 main.log.step( "Starting ONOS CLI sessions" )
1203 cliResults = main.ONOScli1.startOnosCli( ONOS1Ip )
1204 utilities.assert_equals( expect=main.TRUE, actual=cliResults,
1205 onpass="ONOS cli startup successful",
1206 onfail="ONOS cli startup failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001207
Jon Hallfebb1c72015-03-05 13:30:09 -08001208 if elapsed:
1209 main.log.info( "ESTIMATE: ONOS took %s seconds to restart" %
1210 str( elapsed ) )
Jon Hall40d2cbd2015-06-03 16:24:29 -07001211 main.restartTime = elapsed
1212 else:
1213 main.restartTime = -1
Jon Hall6aec96b2015-01-19 14:49:31 -08001214 time.sleep( 5 )
Jon Hallfeff3082015-05-19 10:23:26 -07001215 # rerun on election apps
1216 main.ONOScli1.electionTestRun()
Jon Hall73cf9cc2014-11-20 22:28:38 -08001217
Jon Hall6aec96b2015-01-19 14:49:31 -08001218 def CASE7( self, main ):
1219 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001220 Check state after ONOS failure
Jon Hall6aec96b2015-01-19 14:49:31 -08001221 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001222 import json
Jon Hall5cfd23c2015-03-19 11:40:57 -07001223 assert numControllers, "numControllers not defined"
1224 assert main, "main not defined"
1225 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -08001226 main.case( "Running ONOS Constant State Tests" )
Jon Hall390696c2015-05-05 17:13:41 -07001227 main.step( "Check that each switch has a master" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001228 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -08001229 rolesNotNull = main.ONOScli1.rolesNotNull()
Jon Hall6aec96b2015-01-19 14:49:31 -08001230 utilities.assert_equals(
1231 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001232 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -08001233 onpass="Each device has a master",
1234 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -08001235
Jon Hall6aec96b2015-01-19 14:49:31 -08001236 main.step( "Check if switch roles are consistent across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001237 ONOS1Mastership = main.ONOScli1.roles()
Jon Hall6aec96b2015-01-19 14:49:31 -08001238 # FIXME: Refactor this whole case for single instance
Jon Hall8f89dda2015-01-22 16:03:33 -08001239 if "Error" in ONOS1Mastership or not ONOS1Mastership:
Jon Hall40d2cbd2015-06-03 16:24:29 -07001240 main.log.error( "Error in getting ONOS mastership" )
Jon Hall58c76b72015-02-23 11:09:24 -08001241 main.log.warn( "ONOS1 mastership response: " +
1242 repr( ONOS1Mastership ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001243 consistentMastership = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001244 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001245 consistentMastership = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001246 utilities.assert_equals(
1247 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001248 actual=consistentMastership,
Jon Hall6aec96b2015-01-19 14:49:31 -08001249 onpass="Switch roles are consistent across all ONOS nodes",
1250 onfail="ONOS nodes have different views of switch roles" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001251
1252 description2 = "Compare switch roles from before failure"
Jon Hall6aec96b2015-01-19 14:49:31 -08001253 main.step( description2 )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001254
Jon Hall8f89dda2015-01-22 16:03:33 -08001255 currentJson = json.loads( ONOS1Mastership )
1256 oldJson = json.loads( mastershipState )
1257 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001258 for i in range( 1, 29 ):
1259 switchDPID = str(
Jon Hall58c76b72015-02-23 11:09:24 -08001260 main.Mininet1.getSwitchDPID( switch="s" + str( i ) ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001261
Jon Hall8f89dda2015-01-22 16:03:33 -08001262 current = [ switch[ 'master' ] for switch in currentJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001263 if switchDPID in switch[ 'id' ] ]
Jon Hall8f89dda2015-01-22 16:03:33 -08001264 old = [ switch[ 'master' ] for switch in oldJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001265 if switchDPID in switch[ 'id' ] ]
Jon Hall73cf9cc2014-11-20 22:28:38 -08001266 if current == old:
Jon Hall8f89dda2015-01-22 16:03:33 -08001267 mastershipCheck = mastershipCheck and main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001268 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001269 main.log.warn( "Mastership of switch %s changed" % switchDPID )
Jon Hall8f89dda2015-01-22 16:03:33 -08001270 mastershipCheck = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001271 utilities.assert_equals(
1272 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001273 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -08001274 onpass="Mastership of Switches was not changed",
1275 onfail="Mastership of some switches changed" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001276 mastershipCheck = mastershipCheck and consistentMastership
Jon Hall73cf9cc2014-11-20 22:28:38 -08001277
Jon Hall6aec96b2015-01-19 14:49:31 -08001278 main.step( "Get the intents and compare across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001279 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
1280 intentCheck = main.FALSE
1281 if "Error" in ONOS1Intents or not ONOS1Intents:
Jon Hall40d2cbd2015-06-03 16:24:29 -07001282 main.log.error( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001283 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001284 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001285 intentCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001286 utilities.assert_equals(
1287 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001288 actual=intentCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -08001289 onpass="Intents are consistent across all ONOS nodes",
1290 onfail="ONOS nodes have different views of intents" )
Jon Hall1b8f54a2015-02-04 13:24:20 -08001291 # Print the intent states
1292 intents = []
1293 intents.append( ONOS1Intents )
1294 intentStates = []
1295 for node in intents: # Iter through ONOS nodes
1296 nodeStates = []
Jon Hall58c76b72015-02-23 11:09:24 -08001297 # Iter through intents of a node
1298 for intent in json.loads( node ):
Jon Hall1b8f54a2015-02-04 13:24:20 -08001299 nodeStates.append( intent[ 'state' ] )
1300 intentStates.append( nodeStates )
1301 out = [ (i, nodeStates.count( i ) ) for i in set( nodeStates ) ]
1302 main.log.info( dict( out ) )
1303
Jon Hall58c76b72015-02-23 11:09:24 -08001304 # NOTE: Store has no durability, so intents are lost across system
1305 # restarts
Jon Hall6aec96b2015-01-19 14:49:31 -08001306 """
1307 main.step( "Compare current intents with intents before the failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001308 # NOTE: this requires case 5 to pass for intentState to be set.
Jon Hall6aec96b2015-01-19 14:49:31 -08001309 # maybe we should stop the test if that fails?
Jon Hall40d2cbd2015-06-03 16:24:29 -07001310 sameIntents = main.FALSE
1311 if intentState and intentState == ONOSIntents[ 0 ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001312 sameIntents = main.TRUE
Jon Hallfeff3082015-05-19 10:23:26 -07001313 main.log.info( "Intents are consistent with before failure" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001314 # TODO: possibly the states have changed? we may need to figure out
Jon Hallfeff3082015-05-19 10:23:26 -07001315 # what the acceptable states are
Jon Hall40d2cbd2015-06-03 16:24:29 -07001316 elif len( intentState ) == len( ONOSIntents[ 0 ] ):
1317 sameIntents = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001318 try:
Jon Hall40d2cbd2015-06-03 16:24:29 -07001319 before = json.loads( intentState )
1320 after = json.loads( ONOSIntents[ 0 ] )
1321 for intent in before:
1322 if intent not in after:
1323 sameIntents = main.FALSE
Jon Hallc9eabec2015-06-10 14:33:14 -07001324 main.log.debug( "Intent is not currently in ONOS " +
Jon Hall40d2cbd2015-06-03 16:24:29 -07001325 "(at least in the same form):" )
1326 main.log.debug( json.dumps( intent ) )
1327 except ( ValueError, TypeError ):
1328 main.log.exception( "Exception printing intents" )
1329 main.log.debug( repr( ONOSIntents[0] ) )
1330 main.log.debug( repr( intentState ) )
1331 if sameIntents == main.FALSE:
1332 try:
1333 main.log.debug( "ONOS intents before: " )
1334 main.log.debug( json.dumps( json.loads( intentState ),
1335 sort_keys=True, indent=4,
1336 separators=( ',', ': ' ) ) )
1337 main.log.debug( "Current ONOS intents: " )
1338 main.log.debug( json.dumps( json.loads( ONOSIntents[ 0 ] ),
1339 sort_keys=True, indent=4,
1340 separators=( ',', ': ' ) ) )
1341 except ( ValueError, TypeError ):
1342 main.log.exception( "Exception printing intents" )
1343 main.log.debug( repr( ONOSIntents[0] ) )
1344 main.log.debug( repr( intentState ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001345 utilities.assert_equals(
1346 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001347 actual=sameIntents,
Jon Hall6aec96b2015-01-19 14:49:31 -08001348 onpass="Intents are consistent with before failure",
1349 onfail="The Intents changed during failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001350 intentCheck = intentCheck and sameIntents
Jon Hall6aec96b2015-01-19 14:49:31 -08001351 """
1352 main.step( "Get the OF Table entries and compare to before " +
1353 "component failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001354 FlowTables = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001355 flows2 = []
1356 for i in range( 28 ):
1357 main.log.info( "Checking flow table on s" + str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001358 tmpFlows = main.Mininet2.getFlowTable( 1.3, "s" + str( i + 1 ) )
1359 flows2.append( tmpFlows )
1360 tempResult = main.Mininet2.flowComp(
Jon Hall6aec96b2015-01-19 14:49:31 -08001361 flow1=flows[ i ],
Jon Hall8f89dda2015-01-22 16:03:33 -08001362 flow2=tmpFlows )
1363 FlowTables = FlowTables and tempResult
1364 if FlowTables == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001365 main.log.info( "Differences in flow table for switch: s" +
1366 str( i + 1 ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001367 utilities.assert_equals(
1368 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001369 actual=FlowTables,
Jon Hall6aec96b2015-01-19 14:49:31 -08001370 onpass="No changes were found in the flow tables",
1371 onfail="Changes were found in the flow tables" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001372
Jon Hallfeff3082015-05-19 10:23:26 -07001373 main.step( "Leadership Election is still functional" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001374 # Test of LeadershipElection
Jon Hall669173b2014-12-17 11:36:30 -08001375
Jon Hall8f89dda2015-01-22 16:03:33 -08001376 leader = ONOS1Ip
1377 leaderResult = main.TRUE
1378 for controller in range( 1, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001379 # loop through ONOScli handlers
1380 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001381 leaderN = node.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001382 # verify leader is ONOS1
1383 # NOTE even though we restarted ONOS, it is the only one so onos 1
1384 # must be leader
Jon Hall669173b2014-12-17 11:36:30 -08001385 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08001386 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001387 pass
1388 elif leaderN == main.FALSE:
Jon Hallfeff3082015-05-19 10:23:26 -07001389 # error in response
Jon Hall40d2cbd2015-06-03 16:24:29 -07001390 main.log.error( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001391 "electionTestLeader function, check the" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001392 " error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001393 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001394 elif leader != leaderN:
Jon Hall8f89dda2015-01-22 16:03:33 -08001395 leaderResult = main.FALSE
Jon Hall40d2cbd2015-06-03 16:24:29 -07001396 main.log.error( "ONOS" + str( controller ) + " sees " +
Jon Hall58c76b72015-02-23 11:09:24 -08001397 str( leaderN ) +
1398 " as the leader of the election app. " +
1399 "Leader should be " + str( leader ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001400 utilities.assert_equals(
1401 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001402 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001403 onpass="Leadership election passed",
1404 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08001405
Jon Hall6aec96b2015-01-19 14:49:31 -08001406 def CASE8( self, main ):
1407 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001408 Compare topo
Jon Hall6aec96b2015-01-19 14:49:31 -08001409 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001410 import json
1411 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001412 assert numControllers, "numControllers not defined"
1413 assert main, "main not defined"
1414 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall73cf9cc2014-11-20 22:28:38 -08001415
Jon Hallfeff3082015-05-19 10:23:26 -07001416 main.case( "Compare ONOS Topology view to Mininet topology" )
1417 main.caseExplaination = "Compare topology objects between Mininet" +\
1418 " and ONOS"
Jon Hall73cf9cc2014-11-20 22:28:38 -08001419
Jon Hall6aec96b2015-01-19 14:49:31 -08001420 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001421 devicesResults = main.TRUE
Jon Hall8f89dda2015-01-22 16:03:33 -08001422 linksResults = main.TRUE
Jon Hall58c76b72015-02-23 11:09:24 -08001423 hostsResults = main.TRUE
Jon Hallafa8a472015-06-12 14:02:42 -07001424 hostAttachmentResults = True
Jon Hall8f89dda2015-01-22 16:03:33 -08001425 topoResult = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001426 elapsed = 0
Jon Hallffb386d2014-11-21 13:43:38 -08001427 count = 0
Jon Hall6aec96b2015-01-19 14:49:31 -08001428 main.step( "Collecting topology information from ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001429 startTime = time.time()
Jon Hall58c76b72015-02-23 11:09:24 -08001430 # Give time for Gossip to work
Jon Hall8f89dda2015-01-22 16:03:33 -08001431 while topoResult == main.FALSE and elapsed < 60:
Jon Halla9d26da2015-03-30 16:45:32 -07001432 count += 1
Jon Hall8f89dda2015-01-22 16:03:33 -08001433 cliStart = time.time()
Jon Hall94fd0472014-12-08 11:52:42 -08001434 devices = []
1435 devices.append( main.ONOScli1.devices() )
Jon Hall94fd0472014-12-08 11:52:42 -08001436 hosts = []
Jon Hall58c76b72015-02-23 11:09:24 -08001437 hosts.append( json.loads( main.ONOScli1.hosts() ) )
1438 ipResult = main.TRUE
1439 for controller in range( 0, len( hosts ) ):
1440 controllerStr = str( controller + 1 )
1441 for host in hosts[ controller ]:
Jon Hallfeff3082015-05-19 10:23:26 -07001442 if host is None or host.get( 'ipAddresses', [] ) == []:
Jon Hall58c76b72015-02-23 11:09:24 -08001443 main.log.error(
1444 "DEBUG:Error with host ips on controller" +
1445 controllerStr + ": " + str( host ) )
1446 ipResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001447 ports = []
1448 ports.append( main.ONOScli1.ports() )
1449 links = []
1450 links.append( main.ONOScli1.links() )
Jon Hall58c76b72015-02-23 11:09:24 -08001451 clusters = []
1452 clusters.append( main.ONOScli1.clusters() )
1453
Jon Hall8f89dda2015-01-22 16:03:33 -08001454 elapsed = time.time() - startTime
1455 cliTime = time.time() - cliStart
1456 print "CLI time: " + str( cliTime )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001457
Jon Hallafa8a472015-06-12 14:02:42 -07001458 mnSwitches = main.Mininet1.getSwitches()
1459 mnLinks = main.Mininet1.getLinks()
1460 mnHosts = main.Mininet1.getHosts()
Jon Hall8f89dda2015-01-22 16:03:33 -08001461 for controller in range( numControllers ):
1462 controllerStr = str( controller + 1 )
Jon Hallafa8a472015-06-12 14:02:42 -07001463 if devices[ controller ] and ports[ controller ] and\
1464 "Error" not in devices[ controller ] and\
1465 "Error" not in ports[ controller ]:
1466
Jon Hall8f89dda2015-01-22 16:03:33 -08001467 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hallafa8a472015-06-12 14:02:42 -07001468 mnSwitches,
1469 json.loads( devices[ controller ] ),
1470 json.loads( ports[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001471 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001472 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001473 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001474 actual=currentDevicesResult,
1475 onpass="ONOS" + controllerStr +
1476 " Switches view is correct",
1477 onfail="ONOS" + controllerStr +
1478 " Switches view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001479
Jon Hallafa8a472015-06-12 14:02:42 -07001480 if links[ controller ] and "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001481 currentLinksResult = main.Mininet1.compareLinks(
Jon Hallafa8a472015-06-12 14:02:42 -07001482 mnSwitches, mnLinks,
1483 json.loads( links[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001484 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001485 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001486 utilities.assert_equals( expect=main.TRUE,
Jon Hall58c76b72015-02-23 11:09:24 -08001487 actual=currentLinksResult,
1488 onpass="ONOS" + controllerStr +
1489 " links view is correct",
1490 onfail="ONOS" + controllerStr +
1491 " links view is incorrect" )
1492
1493 if hosts[ controller ] or "Error" not in hosts[ controller ]:
1494 currentHostsResult = main.Mininet1.compareHosts(
Jon Hallafa8a472015-06-12 14:02:42 -07001495 mnHosts,
1496 hosts[ controller ] )
Jon Hall58c76b72015-02-23 11:09:24 -08001497 else:
1498 currentHostsResult = main.FALSE
1499 utilities.assert_equals( expect=main.TRUE,
1500 actual=currentHostsResult,
1501 onpass="ONOS" + controllerStr +
1502 " hosts exist in Mininet",
1503 onfail="ONOS" + controllerStr +
1504 " hosts don't match Mininet" )
Jon Hallafa8a472015-06-12 14:02:42 -07001505 # CHECKING HOST ATTACHMENT POINTS
1506 hostAttachment = True
1507 zeroHosts = False
1508 # FIXME: topo-HA/obelisk specific mappings:
1509 # key is mac and value is dpid
1510 mappings = {}
1511 for i in range( 1, 29 ): # hosts 1 through 28
1512 # set up correct variables:
1513 macId = "00:" * 5 + hex( i ).split( "0x" )[1].upper().zfill(2)
1514 if i == 1:
1515 deviceId = "1000".zfill(16)
1516 elif i == 2:
1517 deviceId = "2000".zfill(16)
1518 elif i == 3:
1519 deviceId = "3000".zfill(16)
1520 elif i == 4:
1521 deviceId = "3004".zfill(16)
1522 elif i == 5:
1523 deviceId = "5000".zfill(16)
1524 elif i == 6:
1525 deviceId = "6000".zfill(16)
1526 elif i == 7:
1527 deviceId = "6007".zfill(16)
1528 elif i >= 8 and i <= 17:
1529 dpid = '3' + str( i ).zfill( 3 )
1530 deviceId = dpid.zfill(16)
1531 elif i >= 18 and i <= 27:
1532 dpid = '6' + str( i ).zfill( 3 )
1533 deviceId = dpid.zfill(16)
1534 elif i == 28:
1535 deviceId = "2800".zfill(16)
1536 mappings[ macId ] = deviceId
1537 if hosts[ controller ] or "Error" not in hosts[ controller ]:
1538 if hosts[ controller ] == []:
1539 main.log.warn( "There are no hosts discovered" )
1540 zeroHosts = True
1541 else:
1542 for host in hosts[ controller ]:
1543 mac = None
1544 location = None
1545 device = None
1546 port = None
1547 try:
1548 mac = host.get( 'mac' )
1549 assert mac, "mac field could not be found for this host object"
1550
1551 location = host.get( 'location' )
1552 assert location, "location field could not be found for this host object"
1553
1554 # Trim the protocol identifier off deviceId
1555 device = str( location.get( 'elementId' ) ).split(':')[1]
1556 assert device, "elementId field could not be found for this host location object"
1557
1558 port = location.get( 'port' )
1559 assert port, "port field could not be found for this host location object"
1560
1561 # Now check if this matches where they should be
1562 if mac and device and port:
1563 if str( port ) != "1":
1564 main.log.error( "The attachment port is incorrect for " +
1565 "host " + str( mac ) +
1566 ". Expected: 1 Actual: " + str( port) )
1567 hostAttachment = False
1568 if device != mappings[ str( mac ) ]:
1569 main.log.error( "The attachment device is incorrect for " +
1570 "host " + str( mac ) +
1571 ". Expected: " + mappings[ str( mac ) ] +
1572 " Actual: " + device )
1573 hostAttachment = False
1574 else:
1575 hostAttachment = False
1576 except AssertionError:
1577 main.log.exception( "Json object not as expected" )
1578 main.log.error( repr( host ) )
1579 hostAttachment = False
1580 else:
1581 main.log.error( "No hosts json output or \"Error\"" +
1582 " in output. hosts = " +
1583 repr( hosts[ controller ] ) )
1584 if zeroHosts is False:
1585 hostAttachment = True
1586
Jon Hall58c76b72015-02-23 11:09:24 -08001587
1588 devicesResults = devicesResults and currentDevicesResult
Jon Hall58c76b72015-02-23 11:09:24 -08001589 linksResults = linksResults and currentLinksResult
1590 hostsResults = hostsResults and currentHostsResult
Jon Hallafa8a472015-06-12 14:02:42 -07001591 hostAttachmentResults = hostAttachmentResults and\
1592 hostAttachment
Jon Hall58c76b72015-02-23 11:09:24 -08001593
Jon Hall63604932015-02-26 17:09:50 -08001594 # "consistent" results don't make sense for single instance
Jon Hall58c76b72015-02-23 11:09:24 -08001595 # there should always only be one cluster
1596 numClusters = len( json.loads( clusters[ 0 ] ) )
1597 clusterResults = main.FALSE
1598 if numClusters == 1:
1599 clusterResults = main.TRUE
1600 utilities.assert_equals(
1601 expect=1,
1602 actual=numClusters,
1603 onpass="ONOS shows 1 SCC",
1604 onfail="ONOS shows " + str( numClusters ) + " SCCs" )
1605
Jon Hallafa8a472015-06-12 14:02:42 -07001606 topoResult = ( devicesResults and linksResults
1607 and hostsResults and ipResult and clusterResults and
1608 hostAttachmentResults )
Jon Hall94fd0472014-12-08 11:52:42 -08001609
Jon Hall8f89dda2015-01-22 16:03:33 -08001610 topoResult = topoResult and int( count <= 2 )
1611 note = "note it takes about " + str( int( cliTime ) ) + \
1612 " seconds for the test to make all the cli calls to fetch " +\
1613 "the topology from each ONOS instance"
Jon Hall1b8f54a2015-02-04 13:24:20 -08001614 main.log.info(
Jon Hall8f89dda2015-01-22 16:03:33 -08001615 "Very crass estimate for topology discovery/convergence( " +
1616 str( note ) + " ): " + str( elapsed ) + " seconds, " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001617 str( count ) + " tries" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001618 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
Jon Hall58c76b72015-02-23 11:09:24 -08001619 onpass="Topology Check Test successful",
1620 onfail="Topology Check Test NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001621
Jon Hall6aec96b2015-01-19 14:49:31 -08001622 def CASE9( self, main ):
1623 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001624 Link s3-s28 down
Jon Hall6aec96b2015-01-19 14:49:31 -08001625 """
1626 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001627 assert numControllers, "numControllers not defined"
1628 assert main, "main not defined"
1629 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -08001630 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001631
Jon Hall8f89dda2015-01-22 16:03:33 -08001632 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001633
Jon Hall6aec96b2015-01-19 14:49:31 -08001634 description = "Turn off a link to ensure that Link Discovery " +\
Jon Hall58c76b72015-02-23 11:09:24 -08001635 "is working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001636 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001637
Jon Hall6aec96b2015-01-19 14:49:31 -08001638 main.step( "Kill Link between s3 and s28" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001639 LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" )
Jon Hall58c76b72015-02-23 11:09:24 -08001640 main.log.info( "Waiting " + str( linkSleep ) +
1641 " seconds for link down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001642 time.sleep( linkSleep )
1643 utilities.assert_equals( expect=main.TRUE, actual=LinkDown,
Jon Halla9d26da2015-03-30 16:45:32 -07001644 onpass="Link down successful",
Jon Hall58c76b72015-02-23 11:09:24 -08001645 onfail="Failed to bring link down" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001646 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -08001647
Jon Hall6aec96b2015-01-19 14:49:31 -08001648 def CASE10( self, main ):
1649 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001650 Link s3-s28 up
Jon Hall6aec96b2015-01-19 14:49:31 -08001651 """
1652 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001653 assert numControllers, "numControllers not defined"
1654 assert main, "main not defined"
1655 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -08001656 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001657
Jon Hall8f89dda2015-01-22 16:03:33 -08001658 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001659
Jon Hall6aec96b2015-01-19 14:49:31 -08001660 description = "Restore a link to ensure that Link Discovery is " + \
Jon Hall58c76b72015-02-23 11:09:24 -08001661 "working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001662 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001663
Jon Hall6aec96b2015-01-19 14:49:31 -08001664 main.step( "Bring link between s3 and s28 back up" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001665 LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" )
Jon Hall58c76b72015-02-23 11:09:24 -08001666 main.log.info( "Waiting " + str( linkSleep ) +
1667 " seconds for link up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001668 time.sleep( linkSleep )
1669 utilities.assert_equals( expect=main.TRUE, actual=LinkUp,
Jon Halla9d26da2015-03-30 16:45:32 -07001670 onpass="Link up successful",
Jon Hall58c76b72015-02-23 11:09:24 -08001671 onfail="Failed to bring link up" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001672 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -08001673
Jon Hall6aec96b2015-01-19 14:49:31 -08001674 def CASE11( self, main ):
1675 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001676 Switch Down
Jon Hall6aec96b2015-01-19 14:49:31 -08001677 """
1678 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001679 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001680 assert numControllers, "numControllers not defined"
1681 assert main, "main not defined"
1682 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall73cf9cc2014-11-20 22:28:38 -08001683
Jon Hall8f89dda2015-01-22 16:03:33 -08001684 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001685
1686 description = "Killing a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001687 main.case( description )
1688 switch = main.params[ 'kill' ][ 'switch' ]
1689 switchDPID = main.params[ 'kill' ][ 'dpid' ]
Jon Hall73cf9cc2014-11-20 22:28:38 -08001690
Jon Hall6aec96b2015-01-19 14:49:31 -08001691 # TODO: Make this switch parameterizable
1692 main.step( "Kill " + switch )
Jon Hall40d2cbd2015-06-03 16:24:29 -07001693 main.log.info( "Deleting " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001694 main.Mininet1.delSwitch( switch )
1695 main.log.info( "Waiting " + str( switchSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001696 " seconds for switch down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001697 time.sleep( switchSleep )
1698 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001699 # Peek at the deleted switch
1700 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001701 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001702 if device and device[ 'available' ] is False:
Jon Hall94fd0472014-12-08 11:52:42 -08001703 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001704 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Halla9d26da2015-03-30 16:45:32 -07001705 onpass="Kill switch successful",
Jon Hall58c76b72015-02-23 11:09:24 -08001706 onfail="Failed to kill switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001707
Jon Hall6aec96b2015-01-19 14:49:31 -08001708 def CASE12( self, main ):
1709 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001710 Switch Up
Jon Hall6aec96b2015-01-19 14:49:31 -08001711 """
1712 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001713 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001714 assert numControllers, "numControllers not defined"
1715 assert main, "main not defined"
1716 assert utilities.assert_equals, "utilities.assert_equals not defined"
1717 assert ONOS1Port, "ONOS1Port not defined"
1718 assert ONOS2Port, "ONOS2Port not defined"
1719 assert ONOS3Port, "ONOS3Port not defined"
1720 assert ONOS4Port, "ONOS4Port not defined"
1721 assert ONOS5Port, "ONOS5Port not defined"
1722 assert ONOS6Port, "ONOS6Port not defined"
1723 assert ONOS7Port, "ONOS7Port not defined"
Jon Hall669173b2014-12-17 11:36:30 -08001724
Jon Hall8f89dda2015-01-22 16:03:33 -08001725 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall6aec96b2015-01-19 14:49:31 -08001726 switch = main.params[ 'kill' ][ 'switch' ]
1727 switchDPID = main.params[ 'kill' ][ 'dpid' ]
1728 links = main.params[ 'kill' ][ 'links' ].split()
Jon Hall73cf9cc2014-11-20 22:28:38 -08001729 description = "Adding a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001730 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001731
Jon Hall6aec96b2015-01-19 14:49:31 -08001732 main.step( "Add back " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001733 main.Mininet1.addSwitch( switch, dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001734 for peer in links:
Jon Hall8f89dda2015-01-22 16:03:33 -08001735 main.Mininet1.addLink( switch, peer )
Jon Hall0f523f22015-07-06 09:31:09 -07001736 ipList = []
1737 for i in range( numControllers ):
1738 ipList.append( nodes[ i ].ip_address )
1739 main.Mininet1.assignSwController( sw=switch, ip=ipList )
Jon Hall58c76b72015-02-23 11:09:24 -08001740 main.log.info( "Waiting " + str( switchSleep ) +
1741 " seconds for switch up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001742 time.sleep( switchSleep )
1743 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001744 # Peek at the deleted switch
1745 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001746 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001747 if device and device[ 'available' ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001748 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001749 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Halla9d26da2015-03-30 16:45:32 -07001750 onpass="add switch successful",
Jon Hall58c76b72015-02-23 11:09:24 -08001751 onfail="Failed to add switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001752
Jon Hall6aec96b2015-01-19 14:49:31 -08001753 def CASE13( self, main ):
1754 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001755 Clean up
Jon Hall6aec96b2015-01-19 14:49:31 -08001756 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001757 import os
1758 import time
Jon Hall5cfd23c2015-03-19 11:40:57 -07001759 assert numControllers, "numControllers not defined"
1760 assert main, "main not defined"
1761 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall6aec96b2015-01-19 14:49:31 -08001762 # printing colors to terminal
Jon Halla9d26da2015-03-30 16:45:32 -07001763 colors = { 'cyan': '\033[96m', 'purple': '\033[95m',
1764 'blue': '\033[94m', 'green': '\033[92m',
1765 'yellow': '\033[93m', 'red': '\033[91m', 'end': '\033[0m' }
Jon Hall40d2cbd2015-06-03 16:24:29 -07001766 main.case( "Test Cleanup" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001767 main.step( "Killing tcpdumps" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001768 main.Mininet2.stopTcpdump()
Jon Hall73cf9cc2014-11-20 22:28:38 -08001769
Jon Hall6aec96b2015-01-19 14:49:31 -08001770 main.step( "Copying MN pcap and ONOS log files to test station" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001771 testname = main.TEST
Jon Hall8f89dda2015-01-22 16:03:33 -08001772 teststationUser = main.params[ 'TESTONUSER' ]
1773 teststationIP = main.params[ 'TESTONIP' ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001774 # NOTE: MN Pcap file is being saved to ~/packet_captures
Jon Hall73cf9cc2014-11-20 22:28:38 -08001775 # scp this file as MN and TestON aren't necessarily the same vm
Jon Hall6aec96b2015-01-19 14:49:31 -08001776 # FIXME: scp
1777 # mn files
1778 # TODO: Load these from params
1779 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001780 logFolder = "/opt/onos/log/"
1781 logFiles = [ "karaf.log", "karaf.log.1" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001782 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001783 dstDir = "~/packet_captures/"
1784 for f in logFiles:
1785 main.ONOSbench.handle.sendline( "scp sdn@" + ONOS1Ip + ":" +
1786 logFolder + f + " " +
1787 teststationUser + "@" +
1788 teststationIP + ":" + dstDir +
Jon Hall6aec96b2015-01-19 14:49:31 -08001789 str( testname ) + "-ONOS1-" + f )
1790 main.ONOSbench.handle.expect( "\$" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001791
Jon Hall6aec96b2015-01-19 14:49:31 -08001792 # std*.log's
1793 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001794 logFolder = "/opt/onos/var/"
1795 logFiles = [ "stderr.log", "stdout.log" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001796 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001797 dstDir = "~/packet_captures/"
1798 for f in logFiles:
1799 main.ONOSbench.handle.sendline( "scp sdn@" + ONOS1Ip + ":" +
1800 logFolder + f + " " +
1801 teststationUser + "@" +
1802 teststationIP + ":" + dstDir +
Jon Hall6aec96b2015-01-19 14:49:31 -08001803 str( testname ) + "-ONOS1-" + f )
Jon Hall58c76b72015-02-23 11:09:24 -08001804 main.ONOSbench.handle.expect( "\$" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001805 # sleep so scp can finish
1806 time.sleep( 10 )
Jon Halla9d26da2015-03-30 16:45:32 -07001807
1808 main.step( "Stopping Mininet" )
Jon Hall390696c2015-05-05 17:13:41 -07001809 mnResult = main.Mininet1.stopNet()
1810 utilities.assert_equals( expect=main.TRUE, actual=mnResult,
1811 onpass="Mininet stopped",
1812 onfail="MN cleanup NOT successful" )
Jon Halla9d26da2015-03-30 16:45:32 -07001813
1814 main.step( "Checking ONOS Logs for errors" )
1815 print colors[ 'purple' ] + "Checking logs for errors on ONOS1:" + \
1816 colors[ 'end' ]
Jon Hall40d2cbd2015-06-03 16:24:29 -07001817 print main.ONOSbench.checkLogs( ONOS1Ip, restart=True )
Jon Halla9d26da2015-03-30 16:45:32 -07001818
Jon Hall6aec96b2015-01-19 14:49:31 -08001819 main.step( "Packing and rotating pcap archives" )
1820 os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001821
Jon Hall40d2cbd2015-06-03 16:24:29 -07001822 try:
1823 timerLog = open( main.logdir + "/Timers.csv", 'w')
1824 # Overwrite with empty line and close
1825 labels = "Gossip Intents, Restart"
1826 data = str( gossipTime ) + ", " + str( main.restartTime )
1827 timerLog.write( labels + "\n" + data )
1828 timerLog.close()
1829 except NameError, e:
1830 main.log.exception(e)
1831
Jon Hall6aec96b2015-01-19 14:49:31 -08001832 def CASE14( self, main ):
1833 """
Jon Hall669173b2014-12-17 11:36:30 -08001834 start election app on all onos nodes
Jon Hall6aec96b2015-01-19 14:49:31 -08001835 """
Jon Hall5cfd23c2015-03-19 11:40:57 -07001836 assert numControllers, "numControllers not defined"
1837 assert main, "main not defined"
1838 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Halla9d26da2015-03-30 16:45:32 -07001839
Jon Hall390696c2015-05-05 17:13:41 -07001840 main.case("Start Leadership Election app")
1841 main.step( "Install leadership election app" )
Jon Hallfeff3082015-05-19 10:23:26 -07001842 appResult = main.ONOScli1.activateApp( "org.onosproject.election" )
1843 utilities.assert_equals(
1844 expect=main.TRUE,
1845 actual=appResult,
1846 onpass="Election app installed",
1847 onfail="Something went wrong with installing Leadership election" )
1848
1849 main.step( "Run for election on each node" )
1850 leaderResult = main.ONOScli1.electionTestRun()
Jon Hall6aec96b2015-01-19 14:49:31 -08001851 # check for leader
Jon Hall8f89dda2015-01-22 16:03:33 -08001852 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001853 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08001854 if leader == ONOS1Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08001855 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001856 pass
Jon Hall6aec96b2015-01-19 14:49:31 -08001857 elif leader is None:
1858 # No leader elected
Jon Hallfeff3082015-05-19 10:23:26 -07001859 main.log.error( "No leader was elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001860 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001861 elif leader == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001862 # error in response
1863 # TODO: add check for "Command not found:" in the driver, this
1864 # means the app isn't loaded
Jon Hallfeff3082015-05-19 10:23:26 -07001865 main.log.error( "Something is wrong with electionTestLeader" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001866 " function, check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001867 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001868 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001869 # error in response
Jon Hallfeff3082015-05-19 10:23:26 -07001870 main.log.error(
Jon Hall8f89dda2015-01-22 16:03:33 -08001871 "Unexpected response from electionTestLeader function:'" +
1872 str( leader ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001873 "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001874 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001875 utilities.assert_equals(
1876 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001877 actual=leaderResult,
Jon Hallfeff3082015-05-19 10:23:26 -07001878 onpass="Successfully ran for leadership",
1879 onfail="Failed to run for leadership" )
Jon Hall669173b2014-12-17 11:36:30 -08001880
Jon Hall6aec96b2015-01-19 14:49:31 -08001881 def CASE15( self, main ):
1882 """
Jon Hall669173b2014-12-17 11:36:30 -08001883 Check that Leadership Election is still functional
Jon Hall6aec96b2015-01-19 14:49:31 -08001884 """
Jon Hall5cfd23c2015-03-19 11:40:57 -07001885 assert numControllers, "numControllers not defined"
1886 assert main, "main not defined"
1887 assert utilities.assert_equals, "utilities.assert_equals not defined"
Jon Hall8f89dda2015-01-22 16:03:33 -08001888 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08001889 description = "Check that Leadership Election is still functional"
Jon Hall6aec96b2015-01-19 14:49:31 -08001890 main.case( description )
1891 main.step( "Find current leader and withdraw" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001892 leader = main.ONOScli1.electionTestLeader()
Jon Halla9d26da2015-03-30 16:45:32 -07001893 # do some sanity checking on leader before using it
Jon Hall8f89dda2015-01-22 16:03:33 -08001894 withdrawResult = main.FALSE
1895 if leader == ONOS1Ip:
1896 oldLeader = getattr( main, "ONOScli1" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001897 elif leader is None or leader == main.FALSE:
Jon Hall40d2cbd2015-06-03 16:24:29 -07001898 main.log.error(
Jon Hall6aec96b2015-01-19 14:49:31 -08001899 "Leader for the election app should be an ONOS node," +
Jon Hall58c76b72015-02-23 11:09:24 -08001900 "instead got '" + str( leader ) + "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001901 leaderResult = main.FALSE
Jon Hall63604932015-02-26 17:09:50 -08001902 oldLeader = None
1903 else:
1904 main.log.error( "Leader election --- why am I HERE?!?")
Jon Hallfeff3082015-05-19 10:23:26 -07001905 leaderResult = main.FALSE
1906 oldLeader = None
Jon Hall63604932015-02-26 17:09:50 -08001907 if oldLeader:
1908 withdrawResult = oldLeader.electionTestWithdraw()
Jon Hall6aec96b2015-01-19 14:49:31 -08001909 utilities.assert_equals(
1910 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001911 actual=withdrawResult,
Jon Hallfeff3082015-05-19 10:23:26 -07001912 onpass="Node was withdrawn from election",
1913 onfail="Node was not withdrawn from election" )
Jon Hall669173b2014-12-17 11:36:30 -08001914
Jon Hall6aec96b2015-01-19 14:49:31 -08001915 main.step( "Make sure new leader is elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001916 leaderN = main.ONOScli1.electionTestLeader()
Jon Hall669173b2014-12-17 11:36:30 -08001917 if leaderN == leader:
Jon Hall40d2cbd2015-06-03 16:24:29 -07001918 main.log.error( "ONOS still sees " + str( leaderN ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001919 " as leader after they withdrew" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001920 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001921 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001922 # error in response
1923 # TODO: add check for "Command not found:" in the driver, this
1924 # means the app isn't loaded
Jon Hall40d2cbd2015-06-03 16:24:29 -07001925 main.log.error( "Something is wrong with electionTestLeader " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001926 "function, check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001927 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001928 elif leaderN is None:
1929 main.log.info(
1930 "There is no leader after the app withdrew from election" )
Jon Hallfeff3082015-05-19 10:23:26 -07001931 leaderResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001932 utilities.assert_equals(
1933 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001934 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001935 onpass="Leadership election passed",
1936 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08001937
Jon Hall58c76b72015-02-23 11:09:24 -08001938 main.step( "Run for election on old leader( just so everyone " +
1939 "is in the hat )" )
Jon Hall63604932015-02-26 17:09:50 -08001940 if oldLeader:
1941 runResult = oldLeader.electionTestRun()
1942 else:
1943 runResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001944 utilities.assert_equals(
1945 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001946 actual=runResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001947 onpass="App re-ran for election",
1948 onfail="App failed to run for election" )
Jon Hallfeff3082015-05-19 10:23:26 -07001949
1950 main.step( "Node became leader when it ran for election" )
1951 afterRun = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001952 # verify leader is ONOS1
Jon Hallfeff3082015-05-19 10:23:26 -07001953 if afterRun == ONOS1Ip:
1954 afterResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08001955 else:
Jon Hallfeff3082015-05-19 10:23:26 -07001956 afterResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001957
Jon Hall6aec96b2015-01-19 14:49:31 -08001958 utilities.assert_equals(
1959 expect=main.TRUE,
Jon Hallfeff3082015-05-19 10:23:26 -07001960 actual=afterResult,
1961 onpass="Old leader successfully re-ran for election",
1962 onfail="Something went wrong with Leadership election after " +
1963 "the old leader re-ran for election" )
Jon Hall390696c2015-05-05 17:13:41 -07001964
1965 def CASE16( self, main ):
1966 """
1967 Install Distributed Primitives app
1968 """
1969 assert numControllers, "numControllers not defined"
1970 assert main, "main not defined"
1971 assert utilities.assert_equals, "utilities.assert_equals not defined"
1972 assert CLIs, "CLIs not defined"
1973 assert nodes, "nodes not defined"
1974
1975 # Variables for the distributed primitives tests
1976 global pCounterName
1977 global iCounterName
1978 global pCounterValue
1979 global iCounterValue
1980 global onosSet
1981 global onosSetName
1982 pCounterName = "TestON-Partitions"
1983 iCounterName = "TestON-inMemory"
1984 pCounterValue = 0
1985 iCounterValue = 0
1986 onosSet = set([])
1987 onosSetName = "TestON-set"
1988
1989 description = "Install Primitives app"
1990 main.case( description )
1991 main.step( "Install Primitives app" )
1992 appName = "org.onosproject.distributedprimitives"
1993 appResults = CLIs[0].activateApp( appName )
1994 utilities.assert_equals( expect=main.TRUE,
1995 actual=appResults,
1996 onpass="Primitives app activated",
1997 onfail="Primitives app not activated" )
1998
1999 def CASE17( self, main ):
2000 """
2001 Check for basic functionality with distributed primitives
2002 """
Jon Hall40d2cbd2015-06-03 16:24:29 -07002003 import json
Jon Hall390696c2015-05-05 17:13:41 -07002004 # Make sure variables are defined/set
2005 assert numControllers, "numControllers not defined"
2006 assert main, "main not defined"
2007 assert utilities.assert_equals, "utilities.assert_equals not defined"
2008 assert CLIs, "CLIs not defined"
2009 assert nodes, "nodes not defined"
2010 assert pCounterName, "pCounterName not defined"
2011 assert iCounterName, "iCounterName not defined"
2012 assert onosSetName, "onosSetName not defined"
2013 # NOTE: assert fails if value is 0/None/Empty/False
2014 try:
2015 pCounterValue
2016 except NameError:
2017 main.log.error( "pCounterValue not defined, setting to 0" )
2018 pCounterValue = 0
2019 try:
2020 iCounterValue
2021 except NameError:
2022 main.log.error( "iCounterValue not defined, setting to 0" )
2023 iCounterValue = 0
2024 try:
2025 onosSet
2026 except NameError:
2027 main.log.error( "onosSet not defined, setting to empty Set" )
2028 onosSet = set([])
2029 # Variables for the distributed primitives tests. These are local only
2030 addValue = "a"
2031 addAllValue = "a b c d e f"
2032 retainValue = "c d e f"
2033
2034 description = "Check for basic functionality with distributed " +\
2035 "primitives"
2036 main.case( description )
2037 main.caseExplaination = "Test the methods of the distributed primitives (counters and sets) throught the cli"
2038 # DISTRIBUTED ATOMIC COUNTERS
2039 main.step( "Increment and get a default counter on each node" )
2040 pCounters = []
2041 threads = []
Jon Hallfeff3082015-05-19 10:23:26 -07002042 addedPValues = []
Jon Hall390696c2015-05-05 17:13:41 -07002043 for i in range( numControllers ):
2044 t = main.Thread( target=CLIs[i].counterTestIncrement,
2045 name="counterIncrement-" + str( i ),
2046 args=[ pCounterName ] )
2047 pCounterValue += 1
Jon Hallfeff3082015-05-19 10:23:26 -07002048 addedPValues.append( pCounterValue )
Jon Hall390696c2015-05-05 17:13:41 -07002049 threads.append( t )
2050 t.start()
2051
2052 for t in threads:
2053 t.join()
2054 pCounters.append( t.result )
2055 # Check that counter incremented numController times
2056 pCounterResults = True
Jon Hallfeff3082015-05-19 10:23:26 -07002057 for i in addedPValues:
Jon Hall40d2cbd2015-06-03 16:24:29 -07002058 tmpResult = i in pCounters
Jon Hallfeff3082015-05-19 10:23:26 -07002059 pCounterResults = pCounterResults and tmpResult
2060 if not tmpResult:
2061 main.log.error( str( i ) + " is not in partitioned "
2062 "counter incremented results" )
Jon Hall390696c2015-05-05 17:13:41 -07002063 utilities.assert_equals( expect=True,
2064 actual=pCounterResults,
2065 onpass="Default counter incremented",
2066 onfail="Error incrementing default" +
2067 " counter" )
2068
2069 main.step( "Increment and get an in memory counter on each node" )
2070 iCounters = []
Jon Hallfeff3082015-05-19 10:23:26 -07002071 addedIValues = []
Jon Hall390696c2015-05-05 17:13:41 -07002072 threads = []
2073 for i in range( numControllers ):
2074 t = main.Thread( target=CLIs[i].counterTestIncrement,
2075 name="icounterIncrement-" + str( i ),
2076 args=[ iCounterName ],
2077 kwargs={ "inMemory": True } )
2078 iCounterValue += 1
Jon Hallfeff3082015-05-19 10:23:26 -07002079 addedIValues.append( iCounterValue )
Jon Hall390696c2015-05-05 17:13:41 -07002080 threads.append( t )
2081 t.start()
2082
2083 for t in threads:
2084 t.join()
2085 iCounters.append( t.result )
2086 # Check that counter incremented numController times
2087 iCounterResults = True
Jon Hallfeff3082015-05-19 10:23:26 -07002088 for i in addedIValues:
2089 tmpResult = i in iCounters
2090 iCounterResults = iCounterResults and tmpResult
2091 if not tmpResult:
2092 main.log.error( str( i ) + " is not in the in-memory "
2093 "counter incremented results" )
Jon Hall390696c2015-05-05 17:13:41 -07002094 utilities.assert_equals( expect=True,
2095 actual=iCounterResults,
2096 onpass="In memory counter incremented",
2097 onfail="Error incrementing in memory" +
2098 " counter" )
2099
2100 main.step( "Check counters are consistant across nodes" )
2101 onosCounters = []
2102 threads = []
2103 for i in range( numControllers ):
2104 t = main.Thread( target=CLIs[i].counters,
2105 name="counters-" + str( i ) )
2106 threads.append( t )
2107 t.start()
2108 for t in threads:
2109 t.join()
2110 onosCounters.append( t.result )
2111 tmp = [ i == onosCounters[ 0 ] for i in onosCounters ]
2112 if all( tmp ):
2113 main.log.info( "Counters are consistent across all nodes" )
2114 consistentCounterResults = main.TRUE
2115 else:
2116 main.log.error( "Counters are not consistent across all nodes" )
2117 consistentCounterResults = main.FALSE
2118 utilities.assert_equals( expect=main.TRUE,
2119 actual=consistentCounterResults,
2120 onpass="ONOS counters are consistent " +
2121 "across nodes",
2122 onfail="ONOS Counters are inconsistent " +
2123 "across nodes" )
2124
2125 main.step( "Counters we added have the correct values" )
2126 correctResults = main.TRUE
2127 for i in range( numControllers ):
Jon Hall40d2cbd2015-06-03 16:24:29 -07002128 current = json.loads( onosCounters[i] )
2129 pValue = None
2130 iValue = None
Jon Hall390696c2015-05-05 17:13:41 -07002131 try:
Jon Hall40d2cbd2015-06-03 16:24:29 -07002132 for database in current:
2133 partitioned = database.get( 'partitionedDatabaseCounters' )
2134 if partitioned:
2135 for value in partitioned:
2136 if value.get( 'name' ) == pCounterName:
2137 pValue = value.get( 'value' )
2138 break
2139 inMemory = database.get( 'inMemoryDatabaseCounters' )
2140 if inMemory:
2141 for value in inMemory:
2142 if value.get( 'name' ) == iCounterName:
2143 iValue = value.get( 'value' )
2144 break
Jon Hall390696c2015-05-05 17:13:41 -07002145 except AttributeError, e:
2146 main.log.error( "ONOS" + str( i + 1 ) + " counters result " +
2147 "is not as expected" )
2148 correctResults = main.FALSE
Jon Hall40d2cbd2015-06-03 16:24:29 -07002149 if pValue == pCounterValue:
2150 main.log.info( "Partitioned counter value is correct" )
2151 else:
2152 main.log.error( "Partitioned counter value is incorrect," +
2153 " expected value: " + str( pCounterValue )
2154 + " current value: " + str( pValue ) )
2155 correctResults = main.FALSE
2156 if iValue == iCounterValue:
2157 main.log.info( "In memory counter value is correct" )
2158 else:
2159 main.log.error( "In memory counter value is incorrect, " +
2160 "expected value: " + str( iCounterValue ) +
2161 " current value: " + str( iValue ) )
2162 correctResults = main.FALSE
Jon Hall390696c2015-05-05 17:13:41 -07002163 utilities.assert_equals( expect=main.TRUE,
2164 actual=correctResults,
2165 onpass="Added counters are correct",
2166 onfail="Added counters are incorrect" )
2167 # DISTRIBUTED SETS
2168 main.step( "Distributed Set get" )
2169 size = len( onosSet )
2170 getResponses = []
2171 threads = []
2172 for i in range( numControllers ):
2173 t = main.Thread( target=CLIs[i].setTestGet,
2174 name="setTestGet-" + str( i ),
2175 args=[ onosSetName ] )
2176 threads.append( t )
2177 t.start()
2178 for t in threads:
2179 t.join()
2180 getResponses.append( t.result )
2181
2182 getResults = main.TRUE
2183 for i in range( numControllers ):
2184 if isinstance( getResponses[ i ], list):
2185 current = set( getResponses[ i ] )
2186 if len( current ) == len( getResponses[ i ] ):
2187 # no repeats
2188 if onosSet != current:
2189 main.log.error( "ONOS" + str( i + 1 ) +
2190 " has incorrect view" +
2191 " of set " + onosSetName + ":\n" +
2192 str( getResponses[ i ] ) )
2193 main.log.debug( "Expected: " + str( onosSet ) )
2194 main.log.debug( "Actual: " + str( current ) )
2195 getResults = main.FALSE
2196 else:
2197 # error, set is not a set
2198 main.log.error( "ONOS" + str( i + 1 ) +
2199 " has repeat elements in" +
2200 " set " + onosSetName + ":\n" +
2201 str( getResponses[ i ] ) )
2202 getResults = main.FALSE
2203 elif getResponses[ i ] == main.ERROR:
2204 getResults = main.FALSE
2205 utilities.assert_equals( expect=main.TRUE,
2206 actual=getResults,
2207 onpass="Set elements are correct",
2208 onfail="Set elements are incorrect" )
2209
2210 main.step( "Distributed Set size" )
2211 sizeResponses = []
2212 threads = []
2213 for i in range( numControllers ):
2214 t = main.Thread( target=CLIs[i].setTestSize,
2215 name="setTestSize-" + str( i ),
2216 args=[ onosSetName ] )
2217 threads.append( t )
2218 t.start()
2219 for t in threads:
2220 t.join()
2221 sizeResponses.append( t.result )
2222
2223 sizeResults = main.TRUE
2224 for i in range( numControllers ):
2225 if size != sizeResponses[ i ]:
2226 sizeResults = main.FALSE
2227 main.log.error( "ONOS" + str( i + 1 ) +
2228 " expected a size of " + str( size ) +
2229 " for set " + onosSetName +
2230 " but got " + str( sizeResponses[ i ] ) )
2231 utilities.assert_equals( expect=main.TRUE,
2232 actual=sizeResults,
2233 onpass="Set sizes are correct",
2234 onfail="Set sizes are incorrect" )
2235
2236 main.step( "Distributed Set add()" )
2237 onosSet.add( addValue )
2238 addResponses = []
2239 threads = []
2240 for i in range( numControllers ):
2241 t = main.Thread( target=CLIs[i].setTestAdd,
2242 name="setTestAdd-" + str( i ),
2243 args=[ onosSetName, addValue ] )
2244 threads.append( t )
2245 t.start()
2246 for t in threads:
2247 t.join()
2248 addResponses.append( t.result )
2249
2250 # main.TRUE = successfully changed the set
2251 # main.FALSE = action resulted in no change in set
2252 # main.ERROR - Some error in executing the function
2253 addResults = main.TRUE
2254 for i in range( numControllers ):
2255 if addResponses[ i ] == main.TRUE:
2256 # All is well
2257 pass
2258 elif addResponses[ i ] == main.FALSE:
2259 # Already in set, probably fine
2260 pass
2261 elif addResponses[ i ] == main.ERROR:
2262 # Error in execution
2263 addResults = main.FALSE
2264 else:
2265 # unexpected result
2266 addResults = main.FALSE
2267 if addResults != main.TRUE:
2268 main.log.error( "Error executing set add" )
2269
2270 # Check if set is still correct
2271 size = len( onosSet )
2272 getResponses = []
2273 threads = []
2274 for i in range( numControllers ):
2275 t = main.Thread( target=CLIs[i].setTestGet,
2276 name="setTestGet-" + str( i ),
2277 args=[ onosSetName ] )
2278 threads.append( t )
2279 t.start()
2280 for t in threads:
2281 t.join()
2282 getResponses.append( t.result )
2283 getResults = main.TRUE
2284 for i in range( numControllers ):
2285 if isinstance( getResponses[ i ], list):
2286 current = set( getResponses[ i ] )
2287 if len( current ) == len( getResponses[ i ] ):
2288 # no repeats
2289 if onosSet != current:
2290 main.log.error( "ONOS" + str( i + 1 ) +
2291 " has incorrect view" +
2292 " of set " + onosSetName + ":\n" +
2293 str( getResponses[ i ] ) )
2294 main.log.debug( "Expected: " + str( onosSet ) )
2295 main.log.debug( "Actual: " + str( current ) )
2296 getResults = main.FALSE
2297 else:
2298 # error, set is not a set
2299 main.log.error( "ONOS" + str( i + 1 ) +
2300 " has repeat elements in" +
2301 " set " + onosSetName + ":\n" +
2302 str( getResponses[ i ] ) )
2303 getResults = main.FALSE
2304 elif getResponses[ i ] == main.ERROR:
2305 getResults = main.FALSE
2306 sizeResponses = []
2307 threads = []
2308 for i in range( numControllers ):
2309 t = main.Thread( target=CLIs[i].setTestSize,
2310 name="setTestSize-" + str( i ),
2311 args=[ onosSetName ] )
2312 threads.append( t )
2313 t.start()
2314 for t in threads:
2315 t.join()
2316 sizeResponses.append( t.result )
2317 sizeResults = main.TRUE
2318 for i in range( numControllers ):
2319 if size != sizeResponses[ i ]:
2320 sizeResults = main.FALSE
2321 main.log.error( "ONOS" + str( i + 1 ) +
2322 " expected a size of " + str( size ) +
2323 " for set " + onosSetName +
2324 " but got " + str( sizeResponses[ i ] ) )
2325 addResults = addResults and getResults and sizeResults
2326 utilities.assert_equals( expect=main.TRUE,
2327 actual=addResults,
2328 onpass="Set add correct",
2329 onfail="Set add was incorrect" )
2330
2331 main.step( "Distributed Set addAll()" )
2332 onosSet.update( addAllValue.split() )
2333 addResponses = []
2334 threads = []
2335 for i in range( numControllers ):
2336 t = main.Thread( target=CLIs[i].setTestAdd,
2337 name="setTestAddAll-" + str( i ),
2338 args=[ onosSetName, addAllValue ] )
2339 threads.append( t )
2340 t.start()
2341 for t in threads:
2342 t.join()
2343 addResponses.append( t.result )
2344
2345 # main.TRUE = successfully changed the set
2346 # main.FALSE = action resulted in no change in set
2347 # main.ERROR - Some error in executing the function
2348 addAllResults = main.TRUE
2349 for i in range( numControllers ):
2350 if addResponses[ i ] == main.TRUE:
2351 # All is well
2352 pass
2353 elif addResponses[ i ] == main.FALSE:
2354 # Already in set, probably fine
2355 pass
2356 elif addResponses[ i ] == main.ERROR:
2357 # Error in execution
2358 addAllResults = main.FALSE
2359 else:
2360 # unexpected result
2361 addAllResults = main.FALSE
2362 if addAllResults != main.TRUE:
2363 main.log.error( "Error executing set addAll" )
2364
2365 # Check if set is still correct
2366 size = len( onosSet )
2367 getResponses = []
2368 threads = []
2369 for i in range( numControllers ):
2370 t = main.Thread( target=CLIs[i].setTestGet,
2371 name="setTestGet-" + str( i ),
2372 args=[ onosSetName ] )
2373 threads.append( t )
2374 t.start()
2375 for t in threads:
2376 t.join()
2377 getResponses.append( t.result )
2378 getResults = main.TRUE
2379 for i in range( numControllers ):
2380 if isinstance( getResponses[ i ], list):
2381 current = set( getResponses[ i ] )
2382 if len( current ) == len( getResponses[ i ] ):
2383 # no repeats
2384 if onosSet != current:
2385 main.log.error( "ONOS" + str( i + 1 ) +
2386 " has incorrect view" +
2387 " of set " + onosSetName + ":\n" +
2388 str( getResponses[ i ] ) )
2389 main.log.debug( "Expected: " + str( onosSet ) )
2390 main.log.debug( "Actual: " + str( current ) )
2391 getResults = main.FALSE
2392 else:
2393 # error, set is not a set
2394 main.log.error( "ONOS" + str( i + 1 ) +
2395 " has repeat elements in" +
2396 " set " + onosSetName + ":\n" +
2397 str( getResponses[ i ] ) )
2398 getResults = main.FALSE
2399 elif getResponses[ i ] == main.ERROR:
2400 getResults = main.FALSE
2401 sizeResponses = []
2402 threads = []
2403 for i in range( numControllers ):
2404 t = main.Thread( target=CLIs[i].setTestSize,
2405 name="setTestSize-" + str( i ),
2406 args=[ onosSetName ] )
2407 threads.append( t )
2408 t.start()
2409 for t in threads:
2410 t.join()
2411 sizeResponses.append( t.result )
2412 sizeResults = main.TRUE
2413 for i in range( numControllers ):
2414 if size != sizeResponses[ i ]:
2415 sizeResults = main.FALSE
2416 main.log.error( "ONOS" + str( i + 1 ) +
2417 " expected a size of " + str( size ) +
2418 " for set " + onosSetName +
2419 " but got " + str( sizeResponses[ i ] ) )
2420 addAllResults = addAllResults and getResults and sizeResults
2421 utilities.assert_equals( expect=main.TRUE,
2422 actual=addAllResults,
2423 onpass="Set addAll correct",
2424 onfail="Set addAll was incorrect" )
2425
2426 main.step( "Distributed Set contains()" )
2427 containsResponses = []
2428 threads = []
2429 for i in range( numControllers ):
2430 t = main.Thread( target=CLIs[i].setTestGet,
2431 name="setContains-" + str( i ),
2432 args=[ onosSetName ],
2433 kwargs={ "values": addValue } )
2434 threads.append( t )
2435 t.start()
2436 for t in threads:
2437 t.join()
2438 # NOTE: This is the tuple
2439 containsResponses.append( t.result )
2440
2441 containsResults = main.TRUE
2442 for i in range( numControllers ):
2443 if containsResponses[ i ] == main.ERROR:
2444 containsResults = main.FALSE
2445 else:
2446 containsResults = containsResults and\
2447 containsResponses[ i ][ 1 ]
2448 utilities.assert_equals( expect=main.TRUE,
2449 actual=containsResults,
2450 onpass="Set contains is functional",
2451 onfail="Set contains failed" )
2452
2453 main.step( "Distributed Set containsAll()" )
2454 containsAllResponses = []
2455 threads = []
2456 for i in range( numControllers ):
2457 t = main.Thread( target=CLIs[i].setTestGet,
2458 name="setContainsAll-" + str( i ),
2459 args=[ onosSetName ],
2460 kwargs={ "values": addAllValue } )
2461 threads.append( t )
2462 t.start()
2463 for t in threads:
2464 t.join()
2465 # NOTE: This is the tuple
2466 containsAllResponses.append( t.result )
2467
2468 containsAllResults = main.TRUE
2469 for i in range( numControllers ):
2470 if containsResponses[ i ] == main.ERROR:
2471 containsResults = main.FALSE
2472 else:
2473 containsResults = containsResults and\
2474 containsResponses[ i ][ 1 ]
2475 utilities.assert_equals( expect=main.TRUE,
2476 actual=containsAllResults,
2477 onpass="Set containsAll is functional",
2478 onfail="Set containsAll failed" )
2479
2480 main.step( "Distributed Set remove()" )
2481 onosSet.remove( addValue )
2482 removeResponses = []
2483 threads = []
2484 for i in range( numControllers ):
2485 t = main.Thread( target=CLIs[i].setTestRemove,
2486 name="setTestRemove-" + str( i ),
2487 args=[ onosSetName, addValue ] )
2488 threads.append( t )
2489 t.start()
2490 for t in threads:
2491 t.join()
2492 removeResponses.append( t.result )
2493
2494 # main.TRUE = successfully changed the set
2495 # main.FALSE = action resulted in no change in set
2496 # main.ERROR - Some error in executing the function
2497 removeResults = main.TRUE
2498 for i in range( numControllers ):
2499 if removeResponses[ i ] == main.TRUE:
2500 # All is well
2501 pass
2502 elif removeResponses[ i ] == main.FALSE:
2503 # not in set, probably fine
2504 pass
2505 elif removeResponses[ i ] == main.ERROR:
2506 # Error in execution
2507 removeResults = main.FALSE
2508 else:
2509 # unexpected result
2510 removeResults = main.FALSE
2511 if removeResults != main.TRUE:
2512 main.log.error( "Error executing set remove" )
2513
2514 # Check if set is still correct
2515 size = len( onosSet )
2516 getResponses = []
2517 threads = []
2518 for i in range( numControllers ):
2519 t = main.Thread( target=CLIs[i].setTestGet,
2520 name="setTestGet-" + str( i ),
2521 args=[ onosSetName ] )
2522 threads.append( t )
2523 t.start()
2524 for t in threads:
2525 t.join()
2526 getResponses.append( t.result )
2527 getResults = main.TRUE
2528 for i in range( numControllers ):
2529 if isinstance( getResponses[ i ], list):
2530 current = set( getResponses[ i ] )
2531 if len( current ) == len( getResponses[ i ] ):
2532 # no repeats
2533 if onosSet != current:
2534 main.log.error( "ONOS" + str( i + 1 ) +
2535 " has incorrect view" +
2536 " of set " + onosSetName + ":\n" +
2537 str( getResponses[ i ] ) )
2538 main.log.debug( "Expected: " + str( onosSet ) )
2539 main.log.debug( "Actual: " + str( current ) )
2540 getResults = main.FALSE
2541 else:
2542 # error, set is not a set
2543 main.log.error( "ONOS" + str( i + 1 ) +
2544 " has repeat elements in" +
2545 " set " + onosSetName + ":\n" +
2546 str( getResponses[ i ] ) )
2547 getResults = main.FALSE
2548 elif getResponses[ i ] == main.ERROR:
2549 getResults = main.FALSE
2550 sizeResponses = []
2551 threads = []
2552 for i in range( numControllers ):
2553 t = main.Thread( target=CLIs[i].setTestSize,
2554 name="setTestSize-" + str( i ),
2555 args=[ onosSetName ] )
2556 threads.append( t )
2557 t.start()
2558 for t in threads:
2559 t.join()
2560 sizeResponses.append( t.result )
2561 sizeResults = main.TRUE
2562 for i in range( numControllers ):
2563 if size != sizeResponses[ i ]:
2564 sizeResults = main.FALSE
2565 main.log.error( "ONOS" + str( i + 1 ) +
2566 " expected a size of " + str( size ) +
2567 " for set " + onosSetName +
2568 " but got " + str( sizeResponses[ i ] ) )
2569 removeResults = removeResults and getResults and sizeResults
2570 utilities.assert_equals( expect=main.TRUE,
2571 actual=removeResults,
2572 onpass="Set remove correct",
2573 onfail="Set remove was incorrect" )
2574
2575 main.step( "Distributed Set removeAll()" )
2576 onosSet.difference_update( addAllValue.split() )
2577 removeAllResponses = []
2578 threads = []
2579 try:
2580 for i in range( numControllers ):
2581 t = main.Thread( target=CLIs[i].setTestRemove,
2582 name="setTestRemoveAll-" + str( i ),
2583 args=[ onosSetName, addAllValue ] )
2584 threads.append( t )
2585 t.start()
2586 for t in threads:
2587 t.join()
2588 removeAllResponses.append( t.result )
2589 except Exception, e:
2590 main.log.exception(e)
2591
2592 # main.TRUE = successfully changed the set
2593 # main.FALSE = action resulted in no change in set
2594 # main.ERROR - Some error in executing the function
2595 removeAllResults = main.TRUE
2596 for i in range( numControllers ):
2597 if removeAllResponses[ i ] == main.TRUE:
2598 # All is well
2599 pass
2600 elif removeAllResponses[ i ] == main.FALSE:
2601 # not in set, probably fine
2602 pass
2603 elif removeAllResponses[ i ] == main.ERROR:
2604 # Error in execution
2605 removeAllResults = main.FALSE
2606 else:
2607 # unexpected result
2608 removeAllResults = main.FALSE
2609 if removeAllResults != main.TRUE:
2610 main.log.error( "Error executing set removeAll" )
2611
2612 # Check if set is still correct
2613 size = len( onosSet )
2614 getResponses = []
2615 threads = []
2616 for i in range( numControllers ):
2617 t = main.Thread( target=CLIs[i].setTestGet,
2618 name="setTestGet-" + str( i ),
2619 args=[ onosSetName ] )
2620 threads.append( t )
2621 t.start()
2622 for t in threads:
2623 t.join()
2624 getResponses.append( t.result )
2625 getResults = main.TRUE
2626 for i in range( numControllers ):
2627 if isinstance( getResponses[ i ], list):
2628 current = set( getResponses[ i ] )
2629 if len( current ) == len( getResponses[ i ] ):
2630 # no repeats
2631 if onosSet != current:
2632 main.log.error( "ONOS" + str( i + 1 ) +
2633 " has incorrect view" +
2634 " of set " + onosSetName + ":\n" +
2635 str( getResponses[ i ] ) )
2636 main.log.debug( "Expected: " + str( onosSet ) )
2637 main.log.debug( "Actual: " + str( current ) )
2638 getResults = main.FALSE
2639 else:
2640 # error, set is not a set
2641 main.log.error( "ONOS" + str( i + 1 ) +
2642 " has repeat elements in" +
2643 " set " + onosSetName + ":\n" +
2644 str( getResponses[ i ] ) )
2645 getResults = main.FALSE
2646 elif getResponses[ i ] == main.ERROR:
2647 getResults = main.FALSE
2648 sizeResponses = []
2649 threads = []
2650 for i in range( numControllers ):
2651 t = main.Thread( target=CLIs[i].setTestSize,
2652 name="setTestSize-" + str( i ),
2653 args=[ onosSetName ] )
2654 threads.append( t )
2655 t.start()
2656 for t in threads:
2657 t.join()
2658 sizeResponses.append( t.result )
2659 sizeResults = main.TRUE
2660 for i in range( numControllers ):
2661 if size != sizeResponses[ i ]:
2662 sizeResults = main.FALSE
2663 main.log.error( "ONOS" + str( i + 1 ) +
2664 " expected a size of " + str( size ) +
2665 " for set " + onosSetName +
2666 " but got " + str( sizeResponses[ i ] ) )
2667 removeAllResults = removeAllResults and getResults and sizeResults
2668 utilities.assert_equals( expect=main.TRUE,
2669 actual=removeAllResults,
2670 onpass="Set removeAll correct",
2671 onfail="Set removeAll was incorrect" )
2672
2673 main.step( "Distributed Set addAll()" )
2674 onosSet.update( addAllValue.split() )
2675 addResponses = []
2676 threads = []
2677 for i in range( numControllers ):
2678 t = main.Thread( target=CLIs[i].setTestAdd,
2679 name="setTestAddAll-" + str( i ),
2680 args=[ onosSetName, addAllValue ] )
2681 threads.append( t )
2682 t.start()
2683 for t in threads:
2684 t.join()
2685 addResponses.append( t.result )
2686
2687 # main.TRUE = successfully changed the set
2688 # main.FALSE = action resulted in no change in set
2689 # main.ERROR - Some error in executing the function
2690 addAllResults = main.TRUE
2691 for i in range( numControllers ):
2692 if addResponses[ i ] == main.TRUE:
2693 # All is well
2694 pass
2695 elif addResponses[ i ] == main.FALSE:
2696 # Already in set, probably fine
2697 pass
2698 elif addResponses[ i ] == main.ERROR:
2699 # Error in execution
2700 addAllResults = main.FALSE
2701 else:
2702 # unexpected result
2703 addAllResults = main.FALSE
2704 if addAllResults != main.TRUE:
2705 main.log.error( "Error executing set addAll" )
2706
2707 # Check if set is still correct
2708 size = len( onosSet )
2709 getResponses = []
2710 threads = []
2711 for i in range( numControllers ):
2712 t = main.Thread( target=CLIs[i].setTestGet,
2713 name="setTestGet-" + str( i ),
2714 args=[ onosSetName ] )
2715 threads.append( t )
2716 t.start()
2717 for t in threads:
2718 t.join()
2719 getResponses.append( t.result )
2720 getResults = main.TRUE
2721 for i in range( numControllers ):
2722 if isinstance( getResponses[ i ], list):
2723 current = set( getResponses[ i ] )
2724 if len( current ) == len( getResponses[ i ] ):
2725 # no repeats
2726 if onosSet != current:
2727 main.log.error( "ONOS" + str( i + 1 ) +
2728 " has incorrect view" +
2729 " of set " + onosSetName + ":\n" +
2730 str( getResponses[ i ] ) )
2731 main.log.debug( "Expected: " + str( onosSet ) )
2732 main.log.debug( "Actual: " + str( current ) )
2733 getResults = main.FALSE
2734 else:
2735 # error, set is not a set
2736 main.log.error( "ONOS" + str( i + 1 ) +
2737 " has repeat elements in" +
2738 " set " + onosSetName + ":\n" +
2739 str( getResponses[ i ] ) )
2740 getResults = main.FALSE
2741 elif getResponses[ i ] == main.ERROR:
2742 getResults = main.FALSE
2743 sizeResponses = []
2744 threads = []
2745 for i in range( numControllers ):
2746 t = main.Thread( target=CLIs[i].setTestSize,
2747 name="setTestSize-" + str( i ),
2748 args=[ onosSetName ] )
2749 threads.append( t )
2750 t.start()
2751 for t in threads:
2752 t.join()
2753 sizeResponses.append( t.result )
2754 sizeResults = main.TRUE
2755 for i in range( numControllers ):
2756 if size != sizeResponses[ i ]:
2757 sizeResults = main.FALSE
2758 main.log.error( "ONOS" + str( i + 1 ) +
2759 " expected a size of " + str( size ) +
2760 " for set " + onosSetName +
2761 " but got " + str( sizeResponses[ i ] ) )
2762 addAllResults = addAllResults and getResults and sizeResults
2763 utilities.assert_equals( expect=main.TRUE,
2764 actual=addAllResults,
2765 onpass="Set addAll correct",
2766 onfail="Set addAll was incorrect" )
2767
2768 main.step( "Distributed Set clear()" )
2769 onosSet.clear()
2770 clearResponses = []
2771 threads = []
2772 for i in range( numControllers ):
2773 t = main.Thread( target=CLIs[i].setTestRemove,
2774 name="setTestClear-" + str( i ),
2775 args=[ onosSetName, " "], # Values doesn't matter
2776 kwargs={ "clear": True } )
2777 threads.append( t )
2778 t.start()
2779 for t in threads:
2780 t.join()
2781 clearResponses.append( t.result )
2782
2783 # main.TRUE = successfully changed the set
2784 # main.FALSE = action resulted in no change in set
2785 # main.ERROR - Some error in executing the function
2786 clearResults = main.TRUE
2787 for i in range( numControllers ):
2788 if clearResponses[ i ] == main.TRUE:
2789 # All is well
2790 pass
2791 elif clearResponses[ i ] == main.FALSE:
2792 # Nothing set, probably fine
2793 pass
2794 elif clearResponses[ i ] == main.ERROR:
2795 # Error in execution
2796 clearResults = main.FALSE
2797 else:
2798 # unexpected result
2799 clearResults = main.FALSE
2800 if clearResults != main.TRUE:
2801 main.log.error( "Error executing set clear" )
2802
2803 # Check if set is still correct
2804 size = len( onosSet )
2805 getResponses = []
2806 threads = []
2807 for i in range( numControllers ):
2808 t = main.Thread( target=CLIs[i].setTestGet,
2809 name="setTestGet-" + str( i ),
2810 args=[ onosSetName ] )
2811 threads.append( t )
2812 t.start()
2813 for t in threads:
2814 t.join()
2815 getResponses.append( t.result )
2816 getResults = main.TRUE
2817 for i in range( numControllers ):
2818 if isinstance( getResponses[ i ], list):
2819 current = set( getResponses[ i ] )
2820 if len( current ) == len( getResponses[ i ] ):
2821 # no repeats
2822 if onosSet != current:
2823 main.log.error( "ONOS" + str( i + 1 ) +
2824 " has incorrect view" +
2825 " of set " + onosSetName + ":\n" +
2826 str( getResponses[ i ] ) )
2827 main.log.debug( "Expected: " + str( onosSet ) )
2828 main.log.debug( "Actual: " + str( current ) )
2829 getResults = main.FALSE
2830 else:
2831 # error, set is not a set
2832 main.log.error( "ONOS" + str( i + 1 ) +
2833 " has repeat elements in" +
2834 " set " + onosSetName + ":\n" +
2835 str( getResponses[ i ] ) )
2836 getResults = main.FALSE
2837 elif getResponses[ i ] == main.ERROR:
2838 getResults = main.FALSE
2839 sizeResponses = []
2840 threads = []
2841 for i in range( numControllers ):
2842 t = main.Thread( target=CLIs[i].setTestSize,
2843 name="setTestSize-" + str( i ),
2844 args=[ onosSetName ] )
2845 threads.append( t )
2846 t.start()
2847 for t in threads:
2848 t.join()
2849 sizeResponses.append( t.result )
2850 sizeResults = main.TRUE
2851 for i in range( numControllers ):
2852 if size != sizeResponses[ i ]:
2853 sizeResults = main.FALSE
2854 main.log.error( "ONOS" + str( i + 1 ) +
2855 " expected a size of " + str( size ) +
2856 " for set " + onosSetName +
2857 " but got " + str( sizeResponses[ i ] ) )
2858 clearResults = clearResults and getResults and sizeResults
2859 utilities.assert_equals( expect=main.TRUE,
2860 actual=clearResults,
2861 onpass="Set clear correct",
2862 onfail="Set clear was incorrect" )
2863
2864 main.step( "Distributed Set addAll()" )
2865 onosSet.update( addAllValue.split() )
2866 addResponses = []
2867 threads = []
2868 for i in range( numControllers ):
2869 t = main.Thread( target=CLIs[i].setTestAdd,
2870 name="setTestAddAll-" + str( i ),
2871 args=[ onosSetName, addAllValue ] )
2872 threads.append( t )
2873 t.start()
2874 for t in threads:
2875 t.join()
2876 addResponses.append( t.result )
2877
2878 # main.TRUE = successfully changed the set
2879 # main.FALSE = action resulted in no change in set
2880 # main.ERROR - Some error in executing the function
2881 addAllResults = main.TRUE
2882 for i in range( numControllers ):
2883 if addResponses[ i ] == main.TRUE:
2884 # All is well
2885 pass
2886 elif addResponses[ i ] == main.FALSE:
2887 # Already in set, probably fine
2888 pass
2889 elif addResponses[ i ] == main.ERROR:
2890 # Error in execution
2891 addAllResults = main.FALSE
2892 else:
2893 # unexpected result
2894 addAllResults = main.FALSE
2895 if addAllResults != main.TRUE:
2896 main.log.error( "Error executing set addAll" )
2897
2898 # Check if set is still correct
2899 size = len( onosSet )
2900 getResponses = []
2901 threads = []
2902 for i in range( numControllers ):
2903 t = main.Thread( target=CLIs[i].setTestGet,
2904 name="setTestGet-" + str( i ),
2905 args=[ onosSetName ] )
2906 threads.append( t )
2907 t.start()
2908 for t in threads:
2909 t.join()
2910 getResponses.append( t.result )
2911 getResults = main.TRUE
2912 for i in range( numControllers ):
2913 if isinstance( getResponses[ i ], list):
2914 current = set( getResponses[ i ] )
2915 if len( current ) == len( getResponses[ i ] ):
2916 # no repeats
2917 if onosSet != current:
2918 main.log.error( "ONOS" + str( i + 1 ) +
2919 " has incorrect view" +
2920 " of set " + onosSetName + ":\n" +
2921 str( getResponses[ i ] ) )
2922 main.log.debug( "Expected: " + str( onosSet ) )
2923 main.log.debug( "Actual: " + str( current ) )
2924 getResults = main.FALSE
2925 else:
2926 # error, set is not a set
2927 main.log.error( "ONOS" + str( i + 1 ) +
2928 " has repeat elements in" +
2929 " set " + onosSetName + ":\n" +
2930 str( getResponses[ i ] ) )
2931 getResults = main.FALSE
2932 elif getResponses[ i ] == main.ERROR:
2933 getResults = main.FALSE
2934 sizeResponses = []
2935 threads = []
2936 for i in range( numControllers ):
2937 t = main.Thread( target=CLIs[i].setTestSize,
2938 name="setTestSize-" + str( i ),
2939 args=[ onosSetName ] )
2940 threads.append( t )
2941 t.start()
2942 for t in threads:
2943 t.join()
2944 sizeResponses.append( t.result )
2945 sizeResults = main.TRUE
2946 for i in range( numControllers ):
2947 if size != sizeResponses[ i ]:
2948 sizeResults = main.FALSE
2949 main.log.error( "ONOS" + str( i + 1 ) +
2950 " expected a size of " + str( size ) +
2951 " for set " + onosSetName +
2952 " but got " + str( sizeResponses[ i ] ) )
2953 addAllResults = addAllResults and getResults and sizeResults
2954 utilities.assert_equals( expect=main.TRUE,
2955 actual=addAllResults,
2956 onpass="Set addAll correct",
2957 onfail="Set addAll was incorrect" )
2958
2959 main.step( "Distributed Set retain()" )
2960 onosSet.intersection_update( retainValue.split() )
2961 retainResponses = []
2962 threads = []
2963 for i in range( numControllers ):
2964 t = main.Thread( target=CLIs[i].setTestRemove,
2965 name="setTestRetain-" + str( i ),
2966 args=[ onosSetName, retainValue ],
2967 kwargs={ "retain": True } )
2968 threads.append( t )
2969 t.start()
2970 for t in threads:
2971 t.join()
2972 retainResponses.append( t.result )
2973
2974 # main.TRUE = successfully changed the set
2975 # main.FALSE = action resulted in no change in set
2976 # main.ERROR - Some error in executing the function
2977 retainResults = main.TRUE
2978 for i in range( numControllers ):
2979 if retainResponses[ i ] == main.TRUE:
2980 # All is well
2981 pass
2982 elif retainResponses[ i ] == main.FALSE:
2983 # Already in set, probably fine
2984 pass
2985 elif retainResponses[ i ] == main.ERROR:
2986 # Error in execution
2987 retainResults = main.FALSE
2988 else:
2989 # unexpected result
2990 retainResults = main.FALSE
2991 if retainResults != main.TRUE:
2992 main.log.error( "Error executing set retain" )
2993
2994 # Check if set is still correct
2995 size = len( onosSet )
2996 getResponses = []
2997 threads = []
2998 for i in range( numControllers ):
2999 t = main.Thread( target=CLIs[i].setTestGet,
3000 name="setTestGet-" + str( i ),
3001 args=[ onosSetName ] )
3002 threads.append( t )
3003 t.start()
3004 for t in threads:
3005 t.join()
3006 getResponses.append( t.result )
3007 getResults = main.TRUE
3008 for i in range( numControllers ):
3009 if isinstance( getResponses[ i ], list):
3010 current = set( getResponses[ i ] )
3011 if len( current ) == len( getResponses[ i ] ):
3012 # no repeats
3013 if onosSet != current:
3014 main.log.error( "ONOS" + str( i + 1 ) +
3015 " has incorrect view" +
3016 " of set " + onosSetName + ":\n" +
3017 str( getResponses[ i ] ) )
3018 main.log.debug( "Expected: " + str( onosSet ) )
3019 main.log.debug( "Actual: " + str( current ) )
3020 getResults = main.FALSE
3021 else:
3022 # error, set is not a set
3023 main.log.error( "ONOS" + str( i + 1 ) +
3024 " has repeat elements in" +
3025 " set " + onosSetName + ":\n" +
3026 str( getResponses[ i ] ) )
3027 getResults = main.FALSE
3028 elif getResponses[ i ] == main.ERROR:
3029 getResults = main.FALSE
3030 sizeResponses = []
3031 threads = []
3032 for i in range( numControllers ):
3033 t = main.Thread( target=CLIs[i].setTestSize,
3034 name="setTestSize-" + str( i ),
3035 args=[ onosSetName ] )
3036 threads.append( t )
3037 t.start()
3038 for t in threads:
3039 t.join()
3040 sizeResponses.append( t.result )
3041 sizeResults = main.TRUE
3042 for i in range( numControllers ):
3043 if size != sizeResponses[ i ]:
3044 sizeResults = main.FALSE
3045 main.log.error( "ONOS" + str( i + 1 ) +
3046 " expected a size of " +
3047 str( size ) + " for set " + onosSetName +
3048 " but got " + str( sizeResponses[ i ] ) )
3049 retainResults = retainResults and getResults and sizeResults
3050 utilities.assert_equals( expect=main.TRUE,
3051 actual=retainResults,
3052 onpass="Set retain correct",
3053 onfail="Set retain was incorrect" )
3054