blob: 1e68327b4f1e8a0abf414d02b4342656b37953c2 [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 Lim461f0872017-06-05 16:49:33 -0700126 main.apps, tempOnosIp, main.ONOScli1.user_name )
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
161 for i in range( main.numCtrls ):
162 onosInstallResult = onosInstallResult and \
163 main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
164 # Populate activeONOSip
165 main.activeONOSip.append( main.ONOSip[ i ] )
166 stepResult = onosInstallResult
167 utilities.assert_equals( expect=main.TRUE,
168 actual=stepResult,
169 onpass="Successfully installed ONOS package",
170 onfail="Failed to install ONOS package" )
171
You Wangf5de25b2017-01-06 15:13:01 -0800172 main.step( "Set up ONOS secure SSH" )
173 secureSshResult = main.TRUE
174 for i in range( int( main.numCtrls ) ):
Jon Halle02505a2017-05-24 16:36:43 -0700175 secureSshResult = secureSshResult and main.ONOSbench.onosSecureSSH( node=main.ONOSip[ i ] )
You Wangf5de25b2017-01-06 15:13:01 -0800176 utilities.assert_equals( expect=main.TRUE, actual=secureSshResult,
177 onpass="Test step PASS",
178 onfail="Test step FAIL" )
179
acsmars51a7fe02015-10-29 18:33:32 -0700180 time.sleep( main.startUpSleep )
181 main.step( "Starting ONOS service" )
182 stopResult = main.TRUE
183 startResult = main.TRUE
184 onosIsUp = main.TRUE
185
186 for i in range( main.numCtrls ):
Jeremy Songster7edb6632016-04-28 15:44:28 -0700187 isUp = main.ONOSbench.isup( main.ONOSip[ i ] )
188 onosIsUp = onosIsUp and isUp
189 if isUp == main.TRUE:
190 main.log.report( "ONOS instance {0} is up and ready".format( i + 1 ) )
191 else:
192 main.log.report( "ONOS instance {0} may not be up, stop and ".format( i + 1 ) +
193 "start ONOS again " )
194 stopResult = stopResult and main.ONOSbench.onosStop( main.ONOSip[ i ] )
195 startResult = startResult and main.ONOSbench.onosStart( main.ONOSip[ i ] )
196 if not startResult or stopResult:
Jon Halle02505a2017-05-24 16:36:43 -0700197 main.log.report( "ONOS instance {0} did not start correctly.".format( i + 1 ) )
acsmars51a7fe02015-10-29 18:33:32 -0700198 stepResult = onosIsUp and stopResult and startResult
199 utilities.assert_equals( expect=main.TRUE,
200 actual=stepResult,
Jeremy Songster7edb6632016-04-28 15:44:28 -0700201 onpass="ONOS service is ready on all nodes",
202 onfail="ONOS service did not start properly on all nodes" )
acsmars51a7fe02015-10-29 18:33:32 -0700203
204 main.step( "Start ONOS cli" )
205 cliResult = main.TRUE
206 for i in range( main.numCtrls ):
207 cliResult = cliResult and \
208 main.CLIs[ i ].startOnosCli( main.ONOSip[ i ] )
209 stepResult = cliResult
210 utilities.assert_equals( expect=main.TRUE,
211 actual=stepResult,
212 onpass="Successfully start ONOS cli",
213 onfail="Failed to start ONOS cli" )
214
215 # Remove the first element in main.scale list
216 main.scale.remove( main.scale[ 0 ] )
217
acsmars51a7fe02015-10-29 18:33:32 -0700218 def CASE10( self, main ):
219 """
220 Start Mininet opticalTest Topology
221 """
Jon Halle02505a2017-05-24 16:36:43 -0700222 main.case( "Mininet with Linc-OE startup" )
acsmars51a7fe02015-10-29 18:33:32 -0700223 main.caseExplanation = "Start opticalTest.py topology included with ONOS"
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700224 if main.opticalTopo:
225 main.step( "Copying optical topology to $ONOS_ROOT/tools/test/topos/" )
226 main.ONOSbench.scp( main.ONOSbench,
227 "{0}{1}.py".format( main.dependencyPath, main.opticalTopo ),
228 "~/onos/tools/test/topos/{0}.py".format( main.opticalTopo ) )
acsmars51a7fe02015-10-29 18:33:32 -0700229 main.step( "Starting mininet and LINC-OE" )
230 topoResult = main.TRUE
231 time.sleep( 10 )
232 controllerIPs = ' '.join( main.activeONOSip )
Jon Halle02505a2017-05-24 16:36:43 -0700233 opticalMnScript = main.LincOE.runOpticalMnScript( ctrllerIP=controllerIPs, topology=main.opticalTopo )
acsmars51a7fe02015-10-29 18:33:32 -0700234 topoResult = opticalMnScript
235 utilities.assert_equals(
236 expect=main.TRUE,
237 actual=topoResult,
238 onpass="Started the topology successfully ",
Jon Halle02505a2017-05-24 16:36:43 -0700239 onfail="Failed to start the topology" )
acsmars51a7fe02015-10-29 18:33:32 -0700240
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700241 main.step( "Push Topology.json to ONOS through onos-netcfg" )
242 pushResult = main.TRUE
243 time.sleep( 20 )
244 main.ONOSbench.onosNetCfg( controllerIps=controllerIPs, path=main.dependencyPath, fileName="Topology" )
245
acsmars51a7fe02015-10-29 18:33:32 -0700246 # Exit if topology did not load properly
247 if not topoResult:
248 main.cleanup()
249 main.exit()
250
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:
370 if main.LincOE.arping( host ):
371 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(
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700532 "of:0000000000000001/1",
533 "of:0000000000000002/1" )
acsmars51a7fe02015-10-29 18:33:32 -0700534 time.sleep( 10 )
535 pIntent2 = main.CLIs[ 0 ].addPointIntent(
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700536 "of:0000000000000002/1",
537 "of:0000000000000001/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 )
Jon Halle02505a2017-05-24 16:36:43 -0700545 main.log.info( "Checking flows state" )
acsmars51a7fe02015-10-29 18:33:32 -0700546 checkFlowResult = main.CLIs[ 0 ].checkFlowsState()
547 # Sleep for 10 seconds to provide time for the intent state to change
548 time.sleep( 10 )
Jon Halle02505a2017-05-24 16:36:43 -0700549 main.log.info( "Checking intents state one more time" )
acsmars51a7fe02015-10-29 18:33:32 -0700550 checkStateResult = main.CLIs[ 0 ].checkIntentState(
Jon Halle02505a2017-05-24 16:36:43 -0700551 intentsId=main.pIntentsId )
Jeremye4bc7132016-03-30 14:04:01 -0700552
acsmars51a7fe02015-10-29 18:33:32 -0700553 if checkStateResult and checkFlowResult:
554 addIntentsResult = main.TRUE
555 else:
556 addIntentsResult = main.FALSE
557 utilities.assert_equals(
558 expect=main.TRUE,
559 actual=addIntentsResult,
560 onpass="Successfully added point intents",
Jon Halle02505a2017-05-24 16:36:43 -0700561 onfail="Failed to add point intents" )
acsmars51a7fe02015-10-29 18:33:32 -0700562
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700563 pingResult = main.FALSE
acsmars51a7fe02015-10-29 18:33:32 -0700564
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700565 if not addIntentsResult:
566 main.log.error( "Intents were not properly installed. Skipping ping." )
567
568 else:
569 main.step( "Ping h1 and h2" )
570 pingResult = main.LincOE.pingHostOptical( src="h1", target="h2" )
acsmars51a7fe02015-10-29 18:33:32 -0700571 utilities.assert_equals(
572 expect=main.TRUE,
573 actual=pingResult,
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700574 onpass="Successfully pinged h1 and h2",
Jon Halle02505a2017-05-24 16:36:43 -0700575 onfail="Failed to ping between h1 and h2" )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700576
577 main.step( "Remove Point to Point intents" )
578 removeResult = main.FALSE
579 # Check remaining intents
580 try:
581 intentsJson = json.loads( main.CLIs[ 0 ].intents() )
582 main.log.debug( intentsJson )
583 main.CLIs[ 0 ].removeIntent( intentId=pIntent1, purge=True )
584 main.CLIs[ 0 ].removeIntent( intentId=pIntent2, purge=True )
585 for intents in intentsJson:
586 main.CLIs[ 0 ].removeIntent( intentId=intents.get( 'id' ),
587 app='org.onosproject.cli',
588 purge=True )
589 time.sleep( 15 )
590
591 for i in range( main.numCtrls ):
592 if len( json.loads( main.CLIs[ i ].intents() ) ):
593 print json.loads( main.CLIs[ i ].intents() )
594 removeResult = main.FALSE
595 else:
596 removeResult = main.TRUE
597 except ( TypeError, ValueError ):
Jon Halle02505a2017-05-24 16:36:43 -0700598 main.log.error( "Cannot see intents on Node " + str( main.CLIs[ 0 ] ) +
599 ". Removing all intents." )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700600 main.CLIs[ 0 ].removeAllIntents( purge=True )
Jon Halle02505a2017-05-24 16:36:43 -0700601 main.CLIs[ 0 ].removeAllIntents( purge=True, app='org.onosproject.cli' )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700602
603 utilities.assert_equals( expect=main.TRUE,
604 actual=removeResult,
605 onpass="Successfully removed host intents",
606 onfail="Failed to remove host intents" )
acsmars51a7fe02015-10-29 18:33:32 -0700607
608 def CASE32( self ):
609 """
610 Add host intents between 2 packet layer host
611 """
612 import time
613 import json
614 main.log.report( "Adding host intents between 2 optical layer host" )
615 main.case( "Test add host intents between optical layer host" )
616 main.caseExplanation = "Test host intents between 2 optical layer host"
617
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700618 main.step( "Creating list of hosts" )
619 hostnum = 0
620 try:
621 hostData = json.loads( hosts[ controller ] )
622 except( TypeError, ValueError ):
Jon Halle02505a2017-05-24 16:36:43 -0700623 main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700624
acsmars51a7fe02015-10-29 18:33:32 -0700625 main.step( "Adding host intents to h1 and h2" )
acsmars51a7fe02015-10-29 18:33:32 -0700626 hostId = []
627 # Listing host MAC addresses
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700628 for host in hostData:
Jon Halle02505a2017-05-24 16:36:43 -0700629 hostId.append( host.get( "id" ) )
acsmars51a7fe02015-10-29 18:33:32 -0700630 host1 = hostId[ 0 ]
631 host2 = hostId[ 1 ]
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700632 main.log.debug( host1 )
633 main.log.debug( host2 )
acsmars51a7fe02015-10-29 18:33:32 -0700634
635 intentsId = []
Jon Halle02505a2017-05-24 16:36:43 -0700636 intent1 = main.CLIs[ 0 ].addHostIntent( hostIdOne=host1,
637 hostIdTwo=host2 )
acsmars51a7fe02015-10-29 18:33:32 -0700638 intentsId.append( intent1 )
639 # Checking intents state before pinging
640 main.log.info( "Checking intents state" )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700641 intentResult = utilities.retry( f=main.CLIs[ 0 ].checkIntentState,
642 retValue=main.FALSE, args=intentsId,
643 sleep=main.checkIntentSleep, attempts=10 )
acsmars51a7fe02015-10-29 18:33:32 -0700644
645 # If intent state is still wrong, display intent states
646 if not intentResult:
647 main.log.error( main.CLIs[ 0 ].intents() )
Jeremye4bc7132016-03-30 14:04:01 -0700648
acsmars51a7fe02015-10-29 18:33:32 -0700649 utilities.assert_equals( expect=main.TRUE,
650 actual=intentResult,
651 onpass="All intents are in INSTALLED state ",
652 onfail="Some of the intents are not in " +
653 "INSTALLED state " )
654
655 if not intentResult:
656 main.log.error( "Intents were not properly installed. Skipping Ping" )
657 else:
658 # Pinging h1 to h2 and then ping h2 to h1
659 main.step( "Pinging h1 and h2" )
660 pingResult = main.TRUE
661 pingResult = main.LincOE.pingHostOptical( src="h1", target="h2" ) \
Jon Halle02505a2017-05-24 16:36:43 -0700662 and main.LincOE.pingHostOptical( src="h2", target="h1" )
Jeremye4bc7132016-03-30 14:04:01 -0700663
acsmars51a7fe02015-10-29 18:33:32 -0700664 utilities.assert_equals( expect=main.TRUE,
665 actual=pingResult,
666 onpass="Pinged successfully between h1 and h2",
667 onfail="Pinged failed between h1 and h2" )
668
669 # Removed all added host intents
670 main.step( "Removing host intents" )
671 removeResult = main.TRUE
672 # Check remaining intents
Jeremy7134f5b2016-04-05 13:50:21 -0700673 try:
674 intentsJson = json.loads( main.CLIs[ 0 ].intents() )
675 main.CLIs[ 0 ].removeIntent( intentId=intent1, purge=True )
676 #main.CLIs[ 0 ].removeIntent( intentId=intent2, purge=True )
Jon Halle02505a2017-05-24 16:36:43 -0700677 main.log.debug( intentsJson )
Jeremy7134f5b2016-04-05 13:50:21 -0700678 for intents in intentsJson:
Jeremye4bc7132016-03-30 14:04:01 -0700679 main.CLIs[ 0 ].removeIntent( intentId=intents.get( 'id' ),
680 app='org.onosproject.optical',
681 purge=True )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700682 time.sleep( 15 )
acsmars51a7fe02015-10-29 18:33:32 -0700683
Jeremy7134f5b2016-04-05 13:50:21 -0700684 for i in range( main.numCtrls ):
685 if len( json.loads( main.CLIs[ i ].intents() ) ):
686 print json.loads( main.CLIs[ i ].intents() )
687 removeResult = main.FALSE
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700688 else:
689 removeResult = main.TRUE
Jeremy7134f5b2016-04-05 13:50:21 -0700690 except ( TypeError, ValueError ):
Jon Halle02505a2017-05-24 16:36:43 -0700691 main.log.error( "Cannot see intents on Node " + str( main.CLIs[ 0 ] ) +
692 ". Removing all intents." )
Jeremy7134f5b2016-04-05 13:50:21 -0700693 main.CLIs[ 0 ].removeAllIntents( purge=True )
Jon Halle02505a2017-05-24 16:36:43 -0700694 main.CLIs[ 0 ].removeAllIntents( purge=True, app='org.onosproject.optical' )
Jeremy7134f5b2016-04-05 13:50:21 -0700695
696 utilities.assert_equals( expect=main.TRUE,
697 actual=removeResult,
698 onpass="Successfully removed host intents",
Chiyu Chengef109502016-11-21 15:51:38 -0800699 onfail="Failed to remove host intents" )