blob: aae4b15f159a23fcc64152e6aba56272f4126e39 [file] [log] [blame]
acsmars51a7fe02015-10-29 18:33:32 -07001# Testing the basic intent functionality of ONOS
2
Jon Halle02505a2017-05-24 16:36:43 -07003
acsmars51a7fe02015-10-29 18:33:32 -07004class FUNCoptical:
5
6 def __init__( self ):
7 self.default = ''
8
9 def CASE1( self, main ):
10 import time
11 import imp
12 import re
13
14 """
15 - Construct tests variables
16 - GIT ( optional )
17 - Checkout ONOS master branch
18 - Pull latest ONOS code
19 - Building ONOS ( optional )
20 - Install ONOS package
21 - Build ONOS package
22 """
acsmars51a7fe02015-10-29 18:33:32 -070023 main.case( "Constructing test variables and building ONOS package" )
24 main.step( "Constructing test variables" )
25 main.caseExplanation = "This test case is mainly for loading " +\
26 "from params file, and pull and build the " +\
27 " latest ONOS package"
28 stepResult = main.FALSE
29
30 # Test variables
31 try:
32 main.testOnDirectory = re.sub( "(/tests)$", "", main.testDir )
33 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
34 gitBranch = main.params[ 'GIT' ][ 'branch' ]
35 main.dependencyPath = main.testOnDirectory + \
36 main.params[ 'DEPENDENCY' ][ 'path' ]
37 main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," )
38 if main.ONOSbench.maxNodes:
39 main.maxNodes = int( main.ONOSbench.maxNodes )
40 else:
41 main.maxNodes = 0
42 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
acsmars51a7fe02015-10-29 18:33:32 -070043 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
44 main.checkIntentSleep = int( main.params[ 'SLEEP' ][ 'checkintent' ] )
acsmars51a7fe02015-10-29 18:33:32 -070045 main.checkTopoAttempts = int( main.params[ 'SLEEP' ][ 'topoAttempts' ] )
46 gitPull = main.params[ 'GIT' ][ 'pull' ]
Jeremy Songster5665f1b2016-06-20 14:38:22 -070047 main.switches = int( main.params[ 'MININET' ][ 'switch' ] )
48 main.links = int( main.params[ 'MININET' ][ 'links' ] )
49 main.hosts = int( main.params[ 'MININET' ][ 'hosts' ] )
50 main.opticalTopo = main.params[ 'MININET' ][ 'toponame' ]
Jon Halle02505a2017-05-24 16:36:43 -070051 main.cellData = {} # For creating cell file
acsmars51a7fe02015-10-29 18:33:32 -070052 main.hostsData = {}
53 main.CLIs = []
54 main.ONOSip = [] # List of IPs of active ONOS nodes. CASE 2
55 main.activeONOSip = []
56 main.assertReturnString = '' # Assembled assert return string
Jon Halle02505a2017-05-24 16:36:43 -070057 main.cycle = 0 # How many times FUNCintent has run through its tests
acsmars51a7fe02015-10-29 18:33:32 -070058
59 main.ONOSip = main.ONOSbench.getOnosIps()
60
61 # Assigning ONOS cli handles to a list
Jon Halle02505a2017-05-24 16:36:43 -070062 for i in range( 1, main.maxNodes + 1 ):
acsmars51a7fe02015-10-29 18:33:32 -070063 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
64
65 # -- INIT SECTION, ONLY RUNS ONCE -- #
Jeremy Songster5665f1b2016-06-20 14:38:22 -070066 main.topo = imp.load_source( wrapperFile1,
acsmars51a7fe02015-10-29 18:33:32 -070067 main.dependencyPath +
Jeremy Songster5665f1b2016-06-20 14:38:22 -070068 wrapperFile1 +
acsmars51a7fe02015-10-29 18:33:32 -070069 ".py" )
acsmars51a7fe02015-10-29 18:33:32 -070070 if main.CLIs:
71 stepResult = main.TRUE
72 else:
73 main.log.error( "Did not properly created list of ONOS CLI handle" )
74 stepResult = main.FALSE
75 except Exception as e:
Jon Halle02505a2017-05-24 16:36:43 -070076 main.log.exception( e )
acsmars51a7fe02015-10-29 18:33:32 -070077 main.cleanup()
78 main.exit()
79
80 utilities.assert_equals( expect=main.TRUE,
81 actual=stepResult,
82 onpass="Successfully construct " +
83 "test variables ",
84 onfail="Failed to construct test variables" )
85
acsmars51a7fe02015-10-29 18:33:32 -070086 main.ONOSbench.getVersion( report=True )
87
88 def CASE2( self, main ):
89 """
90 - Set up cell
91 - Create cell file
92 - Set cell file
93 - Verify cell file
94 - Kill ONOS process
95 - Uninstall ONOS cluster
96 - Verify ONOS start up
97 - Install ONOS cluster
98 - Connect to cli
99 """
Jeremy Songster17147f22016-05-31 18:30:52 -0700100 main.cycle += 1
101
acsmars51a7fe02015-10-29 18:33:32 -0700102 # main.scale[ 0 ] determines the current number of ONOS controller
103 main.numCtrls = int( main.scale[ 0 ] )
Jeremye4bc7132016-03-30 14:04:01 -0700104 main.flowCompiler = "Flow Rules"
acsmars51a7fe02015-10-29 18:33:32 -0700105
106 main.case( "Starting up " + str( main.numCtrls ) +
107 " node(s) ONOS cluster" )
108 main.caseExplanation = "Set up ONOS with " + str( main.numCtrls ) +\
109 " node(s) ONOS cluster"
110
acsmars51a7fe02015-10-29 18:33:32 -0700111 #kill off all onos processes
112 main.log.info( "Safety check, killing all ONOS processes" +
Jon Hall70b2ff42015-11-17 15:49:44 -0800113 " before initiating environment setup" )
acsmars51a7fe02015-10-29 18:33:32 -0700114
115 for i in range( main.maxNodes ):
116 main.ONOSbench.onosDie( main.ONOSip[ i ] )
117
118 print "NODE COUNT = ", main.numCtrls
119
120 tempOnosIp = []
121 for i in range( main.numCtrls ):
Jon Halle02505a2017-05-24 16:36:43 -0700122 tempOnosIp.append( main.ONOSip[ i ] )
acsmars51a7fe02015-10-29 18:33:32 -0700123
124 main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
125 "temp", main.Mininet1.ip_address,
Devin Limdc78e202017-06-09 18:30:07 -0700126 main.apps, tempOnosIp, main.ONOScli1.karafUser )
acsmars51a7fe02015-10-29 18:33:32 -0700127
128 main.step( "Apply cell to environment" )
129 cellResult = main.ONOSbench.setCell( "temp" )
130 verifyResult = main.ONOSbench.verifyCell()
131 stepResult = cellResult and verifyResult
132 utilities.assert_equals( expect=main.TRUE,
133 actual=stepResult,
Jon Halle02505a2017-05-24 16:36:43 -0700134 onpass="Successfully applied cell to " +
acsmars51a7fe02015-10-29 18:33:32 -0700135 "environment",
136 onfail="Failed to apply cell to environment " )
137
138 main.step( "Creating ONOS package" )
Jon Hallbd60ea02016-08-23 10:03:59 -0700139 packageResult = main.ONOSbench.buckBuild()
acsmars51a7fe02015-10-29 18:33:32 -0700140 stepResult = packageResult
141 utilities.assert_equals( expect=main.TRUE,
142 actual=stepResult,
143 onpass="Successfully created ONOS package",
144 onfail="Failed to create ONOS package" )
145
146 time.sleep( main.startUpSleep )
147 main.step( "Uninstalling ONOS package" )
148 onosUninstallResult = main.TRUE
149 for ip in main.ONOSip:
150 onosUninstallResult = onosUninstallResult and \
151 main.ONOSbench.onosUninstall( nodeIp=ip )
152 stepResult = onosUninstallResult
153 utilities.assert_equals( expect=main.TRUE,
154 actual=stepResult,
155 onpass="Successfully uninstalled ONOS package",
156 onfail="Failed to uninstall ONOS package" )
157
158 time.sleep( main.startUpSleep )
159 main.step( "Installing ONOS package" )
160 onosInstallResult = main.TRUE
Devin Lim752dd7b2017-06-27 14:40:03 -0700161 del main.activeONOSip[:]
acsmars51a7fe02015-10-29 18:33:32 -0700162 for i in range( main.numCtrls ):
163 onosInstallResult = onosInstallResult and \
164 main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
165 # Populate activeONOSip
166 main.activeONOSip.append( main.ONOSip[ i ] )
167 stepResult = onosInstallResult
168 utilities.assert_equals( expect=main.TRUE,
169 actual=stepResult,
170 onpass="Successfully installed ONOS package",
171 onfail="Failed to install ONOS package" )
172
You Wangf5de25b2017-01-06 15:13:01 -0800173 main.step( "Set up ONOS secure SSH" )
174 secureSshResult = main.TRUE
175 for i in range( int( main.numCtrls ) ):
Jon Halle02505a2017-05-24 16:36:43 -0700176 secureSshResult = secureSshResult and main.ONOSbench.onosSecureSSH( node=main.ONOSip[ i ] )
You Wangf5de25b2017-01-06 15:13:01 -0800177 utilities.assert_equals( expect=main.TRUE, actual=secureSshResult,
178 onpass="Test step PASS",
179 onfail="Test step FAIL" )
180
acsmars51a7fe02015-10-29 18:33:32 -0700181 time.sleep( main.startUpSleep )
182 main.step( "Starting ONOS service" )
183 stopResult = main.TRUE
184 startResult = main.TRUE
185 onosIsUp = main.TRUE
186
187 for i in range( main.numCtrls ):
Jeremy Songster7edb6632016-04-28 15:44:28 -0700188 isUp = main.ONOSbench.isup( main.ONOSip[ i ] )
189 onosIsUp = onosIsUp and isUp
190 if isUp == main.TRUE:
191 main.log.report( "ONOS instance {0} is up and ready".format( i + 1 ) )
192 else:
193 main.log.report( "ONOS instance {0} may not be up, stop and ".format( i + 1 ) +
194 "start ONOS again " )
195 stopResult = stopResult and main.ONOSbench.onosStop( main.ONOSip[ i ] )
196 startResult = startResult and main.ONOSbench.onosStart( main.ONOSip[ i ] )
197 if not startResult or stopResult:
Jon Halle02505a2017-05-24 16:36:43 -0700198 main.log.report( "ONOS instance {0} did not start correctly.".format( i + 1 ) )
acsmars51a7fe02015-10-29 18:33:32 -0700199 stepResult = onosIsUp and stopResult and startResult
200 utilities.assert_equals( expect=main.TRUE,
201 actual=stepResult,
Jeremy Songster7edb6632016-04-28 15:44:28 -0700202 onpass="ONOS service is ready on all nodes",
203 onfail="ONOS service did not start properly on all nodes" )
acsmars51a7fe02015-10-29 18:33:32 -0700204
205 main.step( "Start ONOS cli" )
206 cliResult = main.TRUE
207 for i in range( main.numCtrls ):
208 cliResult = cliResult and \
209 main.CLIs[ i ].startOnosCli( main.ONOSip[ i ] )
210 stepResult = cliResult
211 utilities.assert_equals( expect=main.TRUE,
212 actual=stepResult,
213 onpass="Successfully start ONOS cli",
214 onfail="Failed to start ONOS cli" )
215
216 # Remove the first element in main.scale list
217 main.scale.remove( main.scale[ 0 ] )
218
acsmars51a7fe02015-10-29 18:33:32 -0700219 def CASE10( self, main ):
220 """
221 Start Mininet opticalTest Topology
222 """
Jon Halle02505a2017-05-24 16:36:43 -0700223 main.case( "Mininet with Linc-OE startup" )
Devin Lim752dd7b2017-06-27 14:40:03 -0700224 main.step( "Push TopoDDriver.json to ONOS through onos-netcfg" )
Devin Lim02075272017-07-10 15:33:21 -0700225 topoResult = True
226 for ip in main.activeONOSip:
227 topoResult = topoResult and \
228 main.ONOSbench.onosNetCfg(controllerIp=ip, path=main.dependencyPath,
229 fileName="TopoDDriver.json")
230
Devin Lim752dd7b2017-06-27 14:40:03 -0700231 #Exit if topology did not load properly
232 if not topoResult:
233 main.cleanup()
234 main.exit()
235
acsmars51a7fe02015-10-29 18:33:32 -0700236 main.caseExplanation = "Start opticalTest.py topology included with ONOS"
237 main.step( "Starting mininet and LINC-OE" )
acsmars51a7fe02015-10-29 18:33:32 -0700238 time.sleep( 10 )
Devin Lim752dd7b2017-06-27 14:40:03 -0700239 controllerIPs = ','.join( main.activeONOSip )
240 cIps = ""
241 for i in range(0,4):
242 cIps += controllerIPs + ' '
243 opticalMnScript = main.LincOE.runOpticalMnScript( ctrllerIP=cIps, topology=main.opticalTopo )
acsmars51a7fe02015-10-29 18:33:32 -0700244 topoResult = opticalMnScript
245 utilities.assert_equals(
246 expect=main.TRUE,
247 actual=topoResult,
248 onpass="Started the topology successfully ",
Jon Halle02505a2017-05-24 16:36:43 -0700249 onfail="Failed to start the topology" )
acsmars51a7fe02015-10-29 18:33:32 -0700250
acsmars51a7fe02015-10-29 18:33:32 -0700251 def CASE14( self, main ):
252 """
253 Stop mininet
254 """
255 main.log.report( "Stop Mininet topology" )
256 main.case( "Stop Mininet topology" )
257 main.caseExplanation = "Stopping the current mininet topology " +\
258 "to start up fresh"
259
260 main.step( "Stopping Mininet Topology" )
261 topoResult = main.LincOE.stopNet( timeout=180 )
262 utilities.assert_equals( expect=main.TRUE,
263 actual=topoResult,
264 onpass="Successfully stopped mininet",
265 onfail="Failed to stopped mininet" )
266 # Exit if topology did not load properly
267 if not topoResult:
268 main.cleanup()
269 main.exit()
270
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700271 def CASE16( self, main ):
272 """
273 Balance Masters
274 """
275 main.case( "Balance mastership of switches" )
276 main.step( "Balancing mastership of switches" )
277
278 balanceResult = main.FALSE
279 balanceResult = utilities.retry( f=main.CLIs[ 0 ].balanceMasters, retValue=main.FALSE, args=[] )
280
281 utilities.assert_equals( expect=main.TRUE,
282 actual=balanceResult,
283 onpass="Successfully balanced mastership of switches",
284 onfail="Failed to balance mastership of switches" )
285 if not balanceResult:
286 main.initialized = main.FALSE
287
Jeremye4bc7132016-03-30 14:04:01 -0700288 def CASE17( self, main ):
289 """
290 Use Flow Objectives
291 """
292 main.case( "Enable intent compilation using Flow Objectives" )
293 main.step( "Enabling Flow Objectives" )
294
295 main.flowCompiler = "Flow Objectives"
296
297 cmd = "org.onosproject.net.intent.impl.compiler.IntentConfigurableRegistrator"
298
299 stepResult = main.CLIs[ 0 ].setCfg( component=cmd,
300 propName="useFlowObjectives", value="true" )
You Wang106d0fa2017-05-15 17:22:15 -0700301 stepResult &= main.CLIs[ 0 ].setCfg( component=cmd,
302 propName="defaultFlowObjectiveCompiler",
Jon Halle02505a2017-05-24 16:36:43 -0700303 value='org.onosproject.net.intent.impl.compiler.LinkCollectionIntentObjectiveCompiler' )
Jeremye4bc7132016-03-30 14:04:01 -0700304
305 utilities.assert_equals( expect=main.TRUE,
306 actual=stepResult,
307 onpass="Successfully activated Flow Objectives",
308 onfail="Failed to activate Flow Objectives" )
309
Jeremy Songster17147f22016-05-31 18:30:52 -0700310 def CASE19( self, main ):
311 """
312 Copy the karaf.log files after each testcase cycle
313 """
314 main.log.report( "Copy karaf logs" )
315 main.case( "Copy karaf logs" )
316 main.caseExplanation = "Copying the karaf logs to preserve them through" +\
317 "reinstalling ONOS"
318 main.step( "Copying karaf logs" )
Jeremy Songster31aad312016-06-13 16:32:11 -0700319 stepResult = main.TRUE
320 scpResult = main.TRUE
321 copyResult = main.TRUE
Jeremy Songstercc5414b2016-07-11 10:59:53 -0700322 for i in range( main.numCtrls ):
323 main.node = main.CLIs[ i ]
Jeremy Songster17147f22016-05-31 18:30:52 -0700324 ip = main.ONOSip[ i ]
325 main.node.ip_address = ip
Jon Halle02505a2017-05-24 16:36:43 -0700326 scpResult = scpResult and main.ONOSbench.scp( main.node,
327 "/opt/onos/log/karaf.log",
328 "/tmp/karaf.log",
329 direction="from" )
Jeremy Songster31aad312016-06-13 16:32:11 -0700330 copyResult = copyResult and main.ONOSbench.cpLogsToDir( "/tmp/karaf.log", main.logdir,
331 copyFileName=( "karaf.log.node{0}.cycle{1}".format( str( i + 1 ), str( main.cycle ) ) ) )
332 if scpResult and copyResult:
Jon Halle02505a2017-05-24 16:36:43 -0700333 stepResult = main.TRUE and stepResult
Jeremy Songster31aad312016-06-13 16:32:11 -0700334 else:
335 stepResult = main.FALSE and stepResult
Jeremy Songster31aad312016-06-13 16:32:11 -0700336 utilities.assert_equals( expect=main.TRUE,
337 actual=stepResult,
338 onpass="Successfully copied remote ONOS logs",
339 onfail="Failed to copy remote ONOS logs" )
Jeremy Songster17147f22016-05-31 18:30:52 -0700340
Jon Halle02505a2017-05-24 16:36:43 -0700341 def CASE21( self, main ):
acsmars51a7fe02015-10-29 18:33:32 -0700342 """
343 Run pingall to discover all hosts
344 """
345 main.case( "Running Pingall" )
346 main.caseExplanation = "Use pingall to discover all hosts. Pingall is expected to fail."
347 main.step( "Discover Hosts through Pingall" )
Jon Halle02505a2017-05-24 16:36:43 -0700348 pingResult = main.LincOE.pingall( timeout=120 )
acsmars51a7fe02015-10-29 18:33:32 -0700349
350 utilities.assert_equals( expect=main.FALSE,
351 actual=pingResult,
352 onpass="Pingall Completed",
353 onfail="Pingall did not complete or did not return fales" )
354
Jon Halle02505a2017-05-24 16:36:43 -0700355 def CASE22( self, main ):
acsmars51a7fe02015-10-29 18:33:32 -0700356 """
357 Send arpings to discover all hosts
358 """
359 main.case( "Discover Hosts with arping" )
360 main.caseExplanation = "Send arpings between all the hosts to discover and verify them"
361
362 main.step( "Send arping between all hosts" )
363
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700364 hosts = []
365 for i in range( main.hosts ):
366 hosts.append( 'h{}'.format( i + 1 ) )
acsmars51a7fe02015-10-29 18:33:32 -0700367
368 arpingHostResults = main.TRUE
369 for host in hosts:
Devin Lim752dd7b2017-06-27 14:40:03 -0700370 if main.LincOE.arping( host, ethDevice=host+"-eth0" ):
acsmars51a7fe02015-10-29 18:33:32 -0700371 main.log.info( "Successfully reached host {} with arping".format( host ) )
372 else:
373 main.log.error( "Could not reach host {} with arping".format( host ) )
374 arpingHostResults = main.FALSE
375
376 utilities.assert_equals( expect=main.TRUE,
377 actual=arpingHostResults,
378 onpass="Successfully discovered all hosts",
379 onfail="Could not descover some hosts" )
380
381 def CASE23( self, main ):
382 """
383 Compare ONOS Topology to Mininet Topology
384 """
385 import json
386
387 main.case( "Compare ONOS Topology view to Mininet topology" )
388 main.caseExplanation = "Compare topology elements between Mininet" +\
389 " and ONOS"
390
391 main.log.info( "Gathering topology information from Mininet" )
392 devicesResults = main.FALSE # Overall Boolean for device correctness
393 linksResults = main.FALSE # Overall Boolean for link correctness
394 hostsResults = main.FALSE # Overall Boolean for host correctness
395 deviceFails = [] # Nodes where devices are incorrect
396 linkFails = [] # Nodes where links are incorrect
397 hostFails = [] # Nodes where hosts are incorrect
398 attempts = main.checkTopoAttempts # Remaining Attempts
399
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700400 mnSwitches = main.switches
401 mnLinks = main.links
402 mnHosts = main.hosts
acsmars51a7fe02015-10-29 18:33:32 -0700403
Jon Hall70b2ff42015-11-17 15:49:44 -0800404 main.step( "Comparing Mininet topology to ONOS topology" )
acsmars51a7fe02015-10-29 18:33:32 -0700405
406 while ( attempts >= 0 ) and\
Jon Halle02505a2017-05-24 16:36:43 -0700407 ( not devicesResults or not linksResults or not hostsResults ):
acsmars51a7fe02015-10-29 18:33:32 -0700408 time.sleep( 2 )
409 if not devicesResults:
410 devices = main.topo.getAllDevices( main )
411 ports = main.topo.getAllPorts( main )
412 devicesResults = main.TRUE
413 deviceFails = [] # Reset for each attempt
414 if not linksResults:
415 links = main.topo.getAllLinks( main )
416 linksResults = main.TRUE
417 linkFails = [] # Reset for each attempt
418 if not hostsResults:
419 hosts = main.topo.getAllHosts( main )
420 hostsResults = main.TRUE
421 hostFails = [] # Reset for each attempt
422
423 # Check for matching topology on each node
424 for controller in range( main.numCtrls ):
425 controllerStr = str( controller + 1 ) # ONOS node number
426 # Compare Devices
427 if devices[ controller ] and ports[ controller ] and\
Jon Halle02505a2017-05-24 16:36:43 -0700428 "Error" not in devices[ controller ] and\
429 "Error" not in ports[ controller ]:
acsmars51a7fe02015-10-29 18:33:32 -0700430
431 try:
432 deviceData = json.loads( devices[ controller ] )
433 portData = json.loads( ports[ controller ] )
Jon Halle02505a2017-05-24 16:36:43 -0700434 except ( TypeError, ValueError ):
435 main.log.error( "Could not load json:" + str( devices[ controller ] ) + ' or ' + str( ports[ controller ] ) )
acsmars51a7fe02015-10-29 18:33:32 -0700436 currentDevicesResult = main.FALSE
437 else:
438 if mnSwitches == len( deviceData ):
439 currentDevicesResult = main.TRUE
440 else:
441 currentDevicesResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700442 main.log.error( "Node {} only sees {} device(s) but {} exist".format(
Jon Halle02505a2017-05-24 16:36:43 -0700443 controllerStr, len( deviceData ), mnSwitches ) )
acsmars51a7fe02015-10-29 18:33:32 -0700444 else:
445 currentDevicesResult = main.FALSE
446 if not currentDevicesResult:
447 deviceFails.append( controllerStr )
448 devicesResults = devicesResults and currentDevicesResult
449 # Compare Links
450 if links[ controller ] and "Error" not in links[ controller ]:
451 try:
452 linkData = json.loads( links[ controller ] )
Jon Halle02505a2017-05-24 16:36:43 -0700453 except ( TypeError, ValueError ):
454 main.log.error( "Could not load json:" + str( links[ controller ] ) )
acsmars51a7fe02015-10-29 18:33:32 -0700455 currentLinksResult = main.FALSE
456 else:
457 if mnLinks == len( linkData ):
458 currentLinksResult = main.TRUE
459 else:
460 currentLinksResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700461 main.log.error( "Node {} only sees {} link(s) but {} exist".format(
Jon Halle02505a2017-05-24 16:36:43 -0700462 controllerStr, len( linkData ), mnLinks ) )
acsmars51a7fe02015-10-29 18:33:32 -0700463 else:
464 currentLinksResult = main.FALSE
465 if not currentLinksResult:
466 linkFails.append( controllerStr )
467 linksResults = linksResults and currentLinksResult
468 # Compare Hosts
469 if hosts[ controller ] and "Error" not in hosts[ controller ]:
470 try:
471 hostData = json.loads( hosts[ controller ] )
Jon Halle02505a2017-05-24 16:36:43 -0700472 except ( TypeError, ValueError ):
473 main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
acsmars51a7fe02015-10-29 18:33:32 -0700474 currentHostsResult = main.FALSE
475 else:
476 if mnHosts == len( hostData ):
477 currentHostsResult = main.TRUE
478 else:
479 currentHostsResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700480 main.log.error( "Node {} only sees {} host(s) but {} exist".format(
Jon Halle02505a2017-05-24 16:36:43 -0700481 controllerStr, len( hostData ), mnHosts ) )
acsmars51a7fe02015-10-29 18:33:32 -0700482 else:
483 currentHostsResult = main.FALSE
484 if not currentHostsResult:
485 hostFails.append( controllerStr )
486 hostsResults = hostsResults and currentHostsResult
487 # Decrement Attempts Remaining
488 attempts -= 1
489
490 utilities.assert_equals( expect=[],
491 actual=deviceFails,
492 onpass="ONOS correctly discovered all devices",
493 onfail="ONOS incorrectly discovered devices on nodes: " +
494 str( deviceFails ) )
495 utilities.assert_equals( expect=[],
496 actual=linkFails,
497 onpass="ONOS correctly discovered all links",
498 onfail="ONOS incorrectly discovered links on nodes: " +
499 str( linkFails ) )
500 utilities.assert_equals( expect=[],
501 actual=hostFails,
502 onpass="ONOS correctly discovered all hosts",
503 onfail="ONOS incorrectly discovered hosts on nodes: " +
504 str( hostFails ) )
505 if hostsResults and linksResults and devicesResults:
506 topoResults = main.TRUE
507 else:
508 topoResults = main.FALSE
509 utilities.assert_equals( expect=main.TRUE,
510 actual=topoResults,
511 onpass="ONOS correctly discovered the topology",
512 onfail="ONOS incorrectly discovered the topology" )
513
acsmars51a7fe02015-10-29 18:33:32 -0700514 def CASE31( self, main ):
515 import time
516 """
517 Add bidirectional point intents between 2 packet layer( mininet )
518 devices and ping mininet hosts
519 """
520 main.log.report(
521 "This testcase adds bidirectional point intents between 2 " +
522 "packet layer( mininet ) devices and ping mininet hosts" )
523 main.case( "Install point intents between 2 packet layer device and " +
524 "ping the hosts" )
525 main.caseExplanation = "This testcase adds bidirectional point intents between 2 " +\
526 "packet layer( mininet ) devices and ping mininet hosts"
527
528 main.step( "Adding point intents" )
529 checkFlowResult = main.TRUE
530 main.pIntentsId = []
531 pIntent1 = main.CLIs[ 0 ].addPointIntent(
Devin Lim752dd7b2017-06-27 14:40:03 -0700532 "of:0000000000000015/1",
533 "of:000000000000000b/2" )
acsmars51a7fe02015-10-29 18:33:32 -0700534 time.sleep( 10 )
535 pIntent2 = main.CLIs[ 0 ].addPointIntent(
Devin Lim752dd7b2017-06-27 14:40:03 -0700536 "of:000000000000000b/2",
537 "of:0000000000000015/1" )
acsmars51a7fe02015-10-29 18:33:32 -0700538 main.pIntentsId.append( pIntent1 )
539 main.pIntentsId.append( pIntent2 )
540 time.sleep( 10 )
Jon Halle02505a2017-05-24 16:36:43 -0700541 main.log.info( "Checking intents state" )
acsmars51a7fe02015-10-29 18:33:32 -0700542 checkStateResult = main.CLIs[ 0 ].checkIntentState(
Jon Halle02505a2017-05-24 16:36:43 -0700543 intentsId=main.pIntentsId )
acsmars51a7fe02015-10-29 18:33:32 -0700544 time.sleep( 10 )
Devin Lim752dd7b2017-06-27 14:40:03 -0700545 checkStateResult = utilities.retry( f=main.CLIs[0].checkIntentState,
546 retValue=main.FALSE, args=( main.pIntentsId, "INSTALLED" ),
547 sleep=main.checkIntentSleep, attempts=10 )
Jon Halle02505a2017-05-24 16:36:43 -0700548 main.log.info( "Checking flows state" )
acsmars51a7fe02015-10-29 18:33:32 -0700549 checkFlowResult = main.CLIs[ 0 ].checkFlowsState()
550 # Sleep for 10 seconds to provide time for the intent state to change
551 time.sleep( 10 )
Jon Halle02505a2017-05-24 16:36:43 -0700552 main.log.info( "Checking intents state one more time" )
acsmars51a7fe02015-10-29 18:33:32 -0700553 checkStateResult = main.CLIs[ 0 ].checkIntentState(
Jon Halle02505a2017-05-24 16:36:43 -0700554 intentsId=main.pIntentsId )
Jeremye4bc7132016-03-30 14:04:01 -0700555
acsmars51a7fe02015-10-29 18:33:32 -0700556 if checkStateResult and checkFlowResult:
557 addIntentsResult = main.TRUE
558 else:
559 addIntentsResult = main.FALSE
560 utilities.assert_equals(
561 expect=main.TRUE,
562 actual=addIntentsResult,
563 onpass="Successfully added point intents",
Jon Halle02505a2017-05-24 16:36:43 -0700564 onfail="Failed to add point intents" )
acsmars51a7fe02015-10-29 18:33:32 -0700565
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700566 pingResult = main.FALSE
acsmars51a7fe02015-10-29 18:33:32 -0700567
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700568 if not addIntentsResult:
569 main.log.error( "Intents were not properly installed. Skipping ping." )
570
571 else:
572 main.step( "Ping h1 and h2" )
573 pingResult = main.LincOE.pingHostOptical( src="h1", target="h2" )
acsmars51a7fe02015-10-29 18:33:32 -0700574 utilities.assert_equals(
575 expect=main.TRUE,
576 actual=pingResult,
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700577 onpass="Successfully pinged h1 and h2",
Jon Halle02505a2017-05-24 16:36:43 -0700578 onfail="Failed to ping between h1 and h2" )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700579
580 main.step( "Remove Point to Point intents" )
Devin Lim752dd7b2017-06-27 14:40:03 -0700581 removeResult = main.TRUE
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700582 # Check remaining intents
583 try:
584 intentsJson = json.loads( main.CLIs[ 0 ].intents() )
585 main.log.debug( intentsJson )
586 main.CLIs[ 0 ].removeIntent( intentId=pIntent1, purge=True )
587 main.CLIs[ 0 ].removeIntent( intentId=pIntent2, purge=True )
588 for intents in intentsJson:
589 main.CLIs[ 0 ].removeIntent( intentId=intents.get( 'id' ),
590 app='org.onosproject.cli',
591 purge=True )
592 time.sleep( 15 )
593
594 for i in range( main.numCtrls ):
Devin Lim752dd7b2017-06-27 14:40:03 -0700595 if not any ( intent.get('state') == 'WITHDRAWING' for intent
596 in json.loads( main.CLIs[i].intents() ) ):
597 main.log.debug( json.loads( main.CLIs[i].intents ) )
598 removeResult = main.FALSE
599 break
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700600 else:
601 removeResult = main.TRUE
602 except ( TypeError, ValueError ):
Jon Halle02505a2017-05-24 16:36:43 -0700603 main.log.error( "Cannot see intents on Node " + str( main.CLIs[ 0 ] ) +
604 ". Removing all intents." )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700605 main.CLIs[ 0 ].removeAllIntents( purge=True )
Jon Halle02505a2017-05-24 16:36:43 -0700606 main.CLIs[ 0 ].removeAllIntents( purge=True, app='org.onosproject.cli' )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700607
608 utilities.assert_equals( expect=main.TRUE,
609 actual=removeResult,
610 onpass="Successfully removed host intents",
611 onfail="Failed to remove host intents" )
acsmars51a7fe02015-10-29 18:33:32 -0700612
613 def CASE32( self ):
614 """
615 Add host intents between 2 packet layer host
616 """
617 import time
618 import json
619 main.log.report( "Adding host intents between 2 optical layer host" )
620 main.case( "Test add host intents between optical layer host" )
621 main.caseExplanation = "Test host intents between 2 optical layer host"
622
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700623 main.step( "Creating list of hosts" )
624 hostnum = 0
625 try:
626 hostData = json.loads( hosts[ controller ] )
627 except( TypeError, ValueError ):
Jon Halle02505a2017-05-24 16:36:43 -0700628 main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700629
acsmars51a7fe02015-10-29 18:33:32 -0700630 main.step( "Adding host intents to h1 and h2" )
acsmars51a7fe02015-10-29 18:33:32 -0700631 hostId = []
632 # Listing host MAC addresses
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700633 for host in hostData:
Jon Halle02505a2017-05-24 16:36:43 -0700634 hostId.append( host.get( "id" ) )
acsmars51a7fe02015-10-29 18:33:32 -0700635 host1 = hostId[ 0 ]
636 host2 = hostId[ 1 ]
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700637 main.log.debug( host1 )
638 main.log.debug( host2 )
acsmars51a7fe02015-10-29 18:33:32 -0700639
640 intentsId = []
Jon Halle02505a2017-05-24 16:36:43 -0700641 intent1 = main.CLIs[ 0 ].addHostIntent( hostIdOne=host1,
642 hostIdTwo=host2 )
acsmars51a7fe02015-10-29 18:33:32 -0700643 intentsId.append( intent1 )
644 # Checking intents state before pinging
645 main.log.info( "Checking intents state" )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700646 intentResult = utilities.retry( f=main.CLIs[ 0 ].checkIntentState,
647 retValue=main.FALSE, args=intentsId,
648 sleep=main.checkIntentSleep, attempts=10 )
acsmars51a7fe02015-10-29 18:33:32 -0700649
650 # If intent state is still wrong, display intent states
651 if not intentResult:
652 main.log.error( main.CLIs[ 0 ].intents() )
Jeremye4bc7132016-03-30 14:04:01 -0700653
acsmars51a7fe02015-10-29 18:33:32 -0700654 utilities.assert_equals( expect=main.TRUE,
655 actual=intentResult,
656 onpass="All intents are in INSTALLED state ",
657 onfail="Some of the intents are not in " +
658 "INSTALLED state " )
659
660 if not intentResult:
661 main.log.error( "Intents were not properly installed. Skipping Ping" )
662 else:
663 # Pinging h1 to h2 and then ping h2 to h1
664 main.step( "Pinging h1 and h2" )
665 pingResult = main.TRUE
666 pingResult = main.LincOE.pingHostOptical( src="h1", target="h2" ) \
Jon Halle02505a2017-05-24 16:36:43 -0700667 and main.LincOE.pingHostOptical( src="h2", target="h1" )
Jeremye4bc7132016-03-30 14:04:01 -0700668
acsmars51a7fe02015-10-29 18:33:32 -0700669 utilities.assert_equals( expect=main.TRUE,
670 actual=pingResult,
671 onpass="Pinged successfully between h1 and h2",
672 onfail="Pinged failed between h1 and h2" )
673
674 # Removed all added host intents
675 main.step( "Removing host intents" )
676 removeResult = main.TRUE
677 # Check remaining intents
Jeremy7134f5b2016-04-05 13:50:21 -0700678 try:
679 intentsJson = json.loads( main.CLIs[ 0 ].intents() )
680 main.CLIs[ 0 ].removeIntent( intentId=intent1, purge=True )
681 #main.CLIs[ 0 ].removeIntent( intentId=intent2, purge=True )
Jon Halle02505a2017-05-24 16:36:43 -0700682 main.log.debug( intentsJson )
Jeremy7134f5b2016-04-05 13:50:21 -0700683 for intents in intentsJson:
Jeremye4bc7132016-03-30 14:04:01 -0700684 main.CLIs[ 0 ].removeIntent( intentId=intents.get( 'id' ),
685 app='org.onosproject.optical',
686 purge=True )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700687 time.sleep( 15 )
acsmars51a7fe02015-10-29 18:33:32 -0700688
Jeremy7134f5b2016-04-05 13:50:21 -0700689 for i in range( main.numCtrls ):
Devin Lim752dd7b2017-06-27 14:40:03 -0700690 if not any ( intent.get('state') == 'WITHDRAWING' for intent
691 in json.loads( main.CLIs[i].intents() ) ):
692 main.log.debug( json.loads( main.CLIs[i].intents ) )
693 removeResult = main.FALSE
694 break
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700695 else:
696 removeResult = main.TRUE
Jeremy7134f5b2016-04-05 13:50:21 -0700697 except ( TypeError, ValueError ):
Jon Halle02505a2017-05-24 16:36:43 -0700698 main.log.error( "Cannot see intents on Node " + str( main.CLIs[ 0 ] ) +
699 ". Removing all intents." )
Jeremy7134f5b2016-04-05 13:50:21 -0700700 main.CLIs[ 0 ].removeAllIntents( purge=True )
Jon Halle02505a2017-05-24 16:36:43 -0700701 main.CLIs[ 0 ].removeAllIntents( purge=True, app='org.onosproject.optical' )
Jeremy7134f5b2016-04-05 13:50:21 -0700702
703 utilities.assert_equals( expect=main.TRUE,
704 actual=removeResult,
705 onpass="Successfully removed host intents",
Chiyu Chengef109502016-11-21 15:51:38 -0800706 onfail="Failed to remove host intents" )