blob: 759f64c753ddb74aff148666cf5f5ad4e1898bd5 [file] [log] [blame]
acsmars51a7fe02015-10-29 18:33:32 -07001# Testing the basic intent functionality of ONOS
2
3class FUNCoptical:
4
5 def __init__( self ):
6 self.default = ''
7
8 def CASE1( self, main ):
9 import time
10 import imp
11 import re
12
13 """
14 - Construct tests variables
15 - GIT ( optional )
16 - Checkout ONOS master branch
17 - Pull latest ONOS code
18 - Building ONOS ( optional )
19 - Install ONOS package
20 - Build ONOS package
21 """
22
23 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' ]
acsmars51a7fe02015-10-29 18:33:32 -070051 main.cellData = {} # For creating cell file
52 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
Jeremy Songster17147f22016-05-31 18:30:52 -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
62 for i in range( 1, main.maxNodes + 1 ):
63 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:
76 main.log.exception(e)
77 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
86 if gitPull == 'True':
87 main.step( "Building ONOS in " + gitBranch + " branch" )
88 onosBuildResult = main.startUp.onosBuild( main, gitBranch )
89 stepResult = onosBuildResult
90 utilities.assert_equals( expect=main.TRUE,
91 actual=stepResult,
92 onpass="Successfully compiled " +
93 "latest ONOS",
94 onfail="Failed to compile " +
95 "latest ONOS" )
96 else:
97 main.log.warn( "Did not pull new code so skipping mvn " +
98 "clean install" )
99 main.ONOSbench.getVersion( report=True )
100
101 def CASE2( self, main ):
102 """
103 - Set up cell
104 - Create cell file
105 - Set cell file
106 - Verify cell file
107 - Kill ONOS process
108 - Uninstall ONOS cluster
109 - Verify ONOS start up
110 - Install ONOS cluster
111 - Connect to cli
112 """
113
Jeremy Songster17147f22016-05-31 18:30:52 -0700114 main.cycle += 1
115
acsmars51a7fe02015-10-29 18:33:32 -0700116 # main.scale[ 0 ] determines the current number of ONOS controller
117 main.numCtrls = int( main.scale[ 0 ] )
Jeremye4bc7132016-03-30 14:04:01 -0700118 main.flowCompiler = "Flow Rules"
acsmars51a7fe02015-10-29 18:33:32 -0700119
120 main.case( "Starting up " + str( main.numCtrls ) +
121 " node(s) ONOS cluster" )
122 main.caseExplanation = "Set up ONOS with " + str( main.numCtrls ) +\
123 " node(s) ONOS cluster"
124
125
126
127 #kill off all onos processes
128 main.log.info( "Safety check, killing all ONOS processes" +
Jon Hall70b2ff42015-11-17 15:49:44 -0800129 " before initiating environment setup" )
acsmars51a7fe02015-10-29 18:33:32 -0700130
131 for i in range( main.maxNodes ):
132 main.ONOSbench.onosDie( main.ONOSip[ i ] )
133
134 print "NODE COUNT = ", main.numCtrls
135
136 tempOnosIp = []
137 for i in range( main.numCtrls ):
138 tempOnosIp.append( main.ONOSip[i] )
139
140 main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
141 "temp", main.Mininet1.ip_address,
142 main.apps, tempOnosIp )
143
144 main.step( "Apply cell to environment" )
145 cellResult = main.ONOSbench.setCell( "temp" )
146 verifyResult = main.ONOSbench.verifyCell()
147 stepResult = cellResult and verifyResult
148 utilities.assert_equals( expect=main.TRUE,
149 actual=stepResult,
150 onpass="Successfully applied cell to " + \
151 "environment",
152 onfail="Failed to apply cell to environment " )
153
154 main.step( "Creating ONOS package" )
Jon Hallbd60ea02016-08-23 10:03:59 -0700155 packageResult = main.ONOSbench.buckBuild()
acsmars51a7fe02015-10-29 18:33:32 -0700156 stepResult = packageResult
157 utilities.assert_equals( expect=main.TRUE,
158 actual=stepResult,
159 onpass="Successfully created ONOS package",
160 onfail="Failed to create ONOS package" )
161
162 time.sleep( main.startUpSleep )
163 main.step( "Uninstalling ONOS package" )
164 onosUninstallResult = main.TRUE
165 for ip in main.ONOSip:
166 onosUninstallResult = onosUninstallResult and \
167 main.ONOSbench.onosUninstall( nodeIp=ip )
168 stepResult = onosUninstallResult
169 utilities.assert_equals( expect=main.TRUE,
170 actual=stepResult,
171 onpass="Successfully uninstalled ONOS package",
172 onfail="Failed to uninstall ONOS package" )
173
174 time.sleep( main.startUpSleep )
175 main.step( "Installing ONOS package" )
176 onosInstallResult = main.TRUE
177 for i in range( main.numCtrls ):
178 onosInstallResult = onosInstallResult and \
179 main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
180 # Populate activeONOSip
181 main.activeONOSip.append( main.ONOSip[ i ] )
182 stepResult = onosInstallResult
183 utilities.assert_equals( expect=main.TRUE,
184 actual=stepResult,
185 onpass="Successfully installed ONOS package",
186 onfail="Failed to install ONOS package" )
187
You Wangf5de25b2017-01-06 15:13:01 -0800188 main.step( "Set up ONOS secure SSH" )
189 secureSshResult = main.TRUE
190 for i in range( int( main.numCtrls ) ):
191 secureSshResult = secureSshResult and main.ONOSbench.onosSecureSSH( node=main.ONOSip[i] )
192 utilities.assert_equals( expect=main.TRUE, actual=secureSshResult,
193 onpass="Test step PASS",
194 onfail="Test step FAIL" )
195
acsmars51a7fe02015-10-29 18:33:32 -0700196 time.sleep( main.startUpSleep )
197 main.step( "Starting ONOS service" )
198 stopResult = main.TRUE
199 startResult = main.TRUE
200 onosIsUp = main.TRUE
201
202 for i in range( main.numCtrls ):
Jeremy Songster7edb6632016-04-28 15:44:28 -0700203 isUp = main.ONOSbench.isup( main.ONOSip[ i ] )
204 onosIsUp = onosIsUp and isUp
205 if isUp == main.TRUE:
206 main.log.report( "ONOS instance {0} is up and ready".format( i + 1 ) )
207 else:
208 main.log.report( "ONOS instance {0} may not be up, stop and ".format( i + 1 ) +
209 "start ONOS again " )
210 stopResult = stopResult and main.ONOSbench.onosStop( main.ONOSip[ i ] )
211 startResult = startResult and main.ONOSbench.onosStart( main.ONOSip[ i ] )
212 if not startResult or stopResult:
213 main.log.report( "ONOS instance {0} did not start correctly.".format( i + 1) )
acsmars51a7fe02015-10-29 18:33:32 -0700214 stepResult = onosIsUp and stopResult and startResult
215 utilities.assert_equals( expect=main.TRUE,
216 actual=stepResult,
Jeremy Songster7edb6632016-04-28 15:44:28 -0700217 onpass="ONOS service is ready on all nodes",
218 onfail="ONOS service did not start properly on all nodes" )
acsmars51a7fe02015-10-29 18:33:32 -0700219
220 main.step( "Start ONOS cli" )
221 cliResult = main.TRUE
222 for i in range( main.numCtrls ):
223 cliResult = cliResult and \
224 main.CLIs[ i ].startOnosCli( main.ONOSip[ i ] )
225 stepResult = cliResult
226 utilities.assert_equals( expect=main.TRUE,
227 actual=stepResult,
228 onpass="Successfully start ONOS cli",
229 onfail="Failed to start ONOS cli" )
230
231 # Remove the first element in main.scale list
232 main.scale.remove( main.scale[ 0 ] )
233
acsmars51a7fe02015-10-29 18:33:32 -0700234 def CASE10( self, main ):
235 """
236 Start Mininet opticalTest Topology
237 """
238 main.case( "Mininet with Linc-OE startup")
239 main.caseExplanation = "Start opticalTest.py topology included with ONOS"
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700240 if main.opticalTopo:
241 main.step( "Copying optical topology to $ONOS_ROOT/tools/test/topos/" )
242 main.ONOSbench.scp( main.ONOSbench,
243 "{0}{1}.py".format( main.dependencyPath, main.opticalTopo ),
244 "~/onos/tools/test/topos/{0}.py".format( main.opticalTopo ) )
acsmars51a7fe02015-10-29 18:33:32 -0700245 main.step( "Starting mininet and LINC-OE" )
246 topoResult = main.TRUE
247 time.sleep( 10 )
248 controllerIPs = ' '.join( main.activeONOSip )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700249 opticalMnScript = main.LincOE.runOpticalMnScript(ctrllerIP = controllerIPs, topology=main.opticalTopo )
acsmars51a7fe02015-10-29 18:33:32 -0700250 topoResult = opticalMnScript
251 utilities.assert_equals(
252 expect=main.TRUE,
253 actual=topoResult,
254 onpass="Started the topology successfully ",
255 onfail="Failed to start the topology")
256
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700257 main.step( "Push Topology.json to ONOS through onos-netcfg" )
258 pushResult = main.TRUE
259 time.sleep( 20 )
260 main.ONOSbench.onosNetCfg( controllerIps=controllerIPs, path=main.dependencyPath, fileName="Topology" )
261
acsmars51a7fe02015-10-29 18:33:32 -0700262 # Exit if topology did not load properly
263 if not topoResult:
264 main.cleanup()
265 main.exit()
266
Jeremye4bc7132016-03-30 14:04:01 -0700267
acsmars51a7fe02015-10-29 18:33:32 -0700268
269
270 def CASE14( self, main ):
271 """
272 Stop mininet
273 """
274 main.log.report( "Stop Mininet topology" )
275 main.case( "Stop Mininet topology" )
276 main.caseExplanation = "Stopping the current mininet topology " +\
277 "to start up fresh"
278
279 main.step( "Stopping Mininet Topology" )
280 topoResult = main.LincOE.stopNet( timeout=180 )
281 utilities.assert_equals( expect=main.TRUE,
282 actual=topoResult,
283 onpass="Successfully stopped mininet",
284 onfail="Failed to stopped mininet" )
285 # Exit if topology did not load properly
286 if not topoResult:
287 main.cleanup()
288 main.exit()
289
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700290 def CASE16( self, main ):
291 """
292 Balance Masters
293 """
294 main.case( "Balance mastership of switches" )
295 main.step( "Balancing mastership of switches" )
296
297 balanceResult = main.FALSE
298 balanceResult = utilities.retry( f=main.CLIs[ 0 ].balanceMasters, retValue=main.FALSE, args=[] )
299
300 utilities.assert_equals( expect=main.TRUE,
301 actual=balanceResult,
302 onpass="Successfully balanced mastership of switches",
303 onfail="Failed to balance mastership of switches" )
304 if not balanceResult:
305 main.initialized = main.FALSE
306
Jeremye4bc7132016-03-30 14:04:01 -0700307 def CASE17( self, main ):
308 """
309 Use Flow Objectives
310 """
311 main.case( "Enable intent compilation using Flow Objectives" )
312 main.step( "Enabling Flow Objectives" )
313
314 main.flowCompiler = "Flow Objectives"
315
316 cmd = "org.onosproject.net.intent.impl.compiler.IntentConfigurableRegistrator"
317
318 stepResult = main.CLIs[ 0 ].setCfg( component=cmd,
319 propName="useFlowObjectives", value="true" )
You Wang106d0fa2017-05-15 17:22:15 -0700320 stepResult &= main.CLIs[ 0 ].setCfg( component=cmd,
321 propName="defaultFlowObjectiveCompiler",
322 value='org.onosproject.net.intent.impl.compiler.LinkCollectionIntentObjectiveCompiler')
Jeremye4bc7132016-03-30 14:04:01 -0700323
324 utilities.assert_equals( expect=main.TRUE,
325 actual=stepResult,
326 onpass="Successfully activated Flow Objectives",
327 onfail="Failed to activate Flow Objectives" )
328
Jeremy Songster17147f22016-05-31 18:30:52 -0700329 def CASE19( self, main ):
330 """
331 Copy the karaf.log files after each testcase cycle
332 """
333 main.log.report( "Copy karaf logs" )
334 main.case( "Copy karaf logs" )
335 main.caseExplanation = "Copying the karaf logs to preserve them through" +\
336 "reinstalling ONOS"
337 main.step( "Copying karaf logs" )
Jeremy Songster31aad312016-06-13 16:32:11 -0700338 stepResult = main.TRUE
339 scpResult = main.TRUE
340 copyResult = main.TRUE
Jeremy Songstercc5414b2016-07-11 10:59:53 -0700341 for i in range( main.numCtrls ):
342 main.node = main.CLIs[ i ]
Jeremy Songster17147f22016-05-31 18:30:52 -0700343 ip = main.ONOSip[ i ]
344 main.node.ip_address = ip
Jeremy Songster31aad312016-06-13 16:32:11 -0700345 scpResult = scpResult and main.ONOSbench.scp( main.node ,
346 "/opt/onos/log/karaf.log",
347 "/tmp/karaf.log",
348 direction="from" )
349 copyResult = copyResult and main.ONOSbench.cpLogsToDir( "/tmp/karaf.log", main.logdir,
350 copyFileName=( "karaf.log.node{0}.cycle{1}".format( str( i + 1 ), str( main.cycle ) ) ) )
351 if scpResult and copyResult:
352 stepResult = main.TRUE and stepResult
353 else:
354 stepResult = main.FALSE and stepResult
Jeremy Songster31aad312016-06-13 16:32:11 -0700355 utilities.assert_equals( expect=main.TRUE,
356 actual=stepResult,
357 onpass="Successfully copied remote ONOS logs",
358 onfail="Failed to copy remote ONOS logs" )
Jeremy Songster17147f22016-05-31 18:30:52 -0700359
acsmars51a7fe02015-10-29 18:33:32 -0700360 def CASE21( self,main ):
361 """
362 Run pingall to discover all hosts
363 """
364 main.case( "Running Pingall" )
365 main.caseExplanation = "Use pingall to discover all hosts. Pingall is expected to fail."
366 main.step( "Discover Hosts through Pingall" )
Jeremy Songster7edb6632016-04-28 15:44:28 -0700367 pingResult = main.LincOE.pingall( timeout = 120 )
acsmars51a7fe02015-10-29 18:33:32 -0700368
369 utilities.assert_equals( expect=main.FALSE,
370 actual=pingResult,
371 onpass="Pingall Completed",
372 onfail="Pingall did not complete or did not return fales" )
373
374 def CASE22( self,main ):
375 """
376 Send arpings to discover all hosts
377 """
378 main.case( "Discover Hosts with arping" )
379 main.caseExplanation = "Send arpings between all the hosts to discover and verify them"
380
381 main.step( "Send arping between all hosts" )
382
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700383 hosts = []
384 for i in range( main.hosts ):
385 hosts.append( 'h{}'.format( i + 1 ) )
acsmars51a7fe02015-10-29 18:33:32 -0700386
387 arpingHostResults = main.TRUE
388 for host in hosts:
389 if main.LincOE.arping( host ):
390 main.log.info( "Successfully reached host {} with arping".format( host ) )
391 else:
392 main.log.error( "Could not reach host {} with arping".format( host ) )
393 arpingHostResults = main.FALSE
394
395 utilities.assert_equals( expect=main.TRUE,
396 actual=arpingHostResults,
397 onpass="Successfully discovered all hosts",
398 onfail="Could not descover some hosts" )
399
400 def CASE23( self, main ):
401 """
402 Compare ONOS Topology to Mininet Topology
403 """
404 import json
405
406 main.case( "Compare ONOS Topology view to Mininet topology" )
407 main.caseExplanation = "Compare topology elements between Mininet" +\
408 " and ONOS"
409
410 main.log.info( "Gathering topology information from Mininet" )
411 devicesResults = main.FALSE # Overall Boolean for device correctness
412 linksResults = main.FALSE # Overall Boolean for link correctness
413 hostsResults = main.FALSE # Overall Boolean for host correctness
414 deviceFails = [] # Nodes where devices are incorrect
415 linkFails = [] # Nodes where links are incorrect
416 hostFails = [] # Nodes where hosts are incorrect
417 attempts = main.checkTopoAttempts # Remaining Attempts
418
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700419 mnSwitches = main.switches
420 mnLinks = main.links
421 mnHosts = main.hosts
acsmars51a7fe02015-10-29 18:33:32 -0700422
Jon Hall70b2ff42015-11-17 15:49:44 -0800423 main.step( "Comparing Mininet topology to ONOS topology" )
acsmars51a7fe02015-10-29 18:33:32 -0700424
425 while ( attempts >= 0 ) and\
426 ( not devicesResults or not linksResults or not hostsResults ):
427 time.sleep( 2 )
428 if not devicesResults:
429 devices = main.topo.getAllDevices( main )
430 ports = main.topo.getAllPorts( main )
431 devicesResults = main.TRUE
432 deviceFails = [] # Reset for each attempt
433 if not linksResults:
434 links = main.topo.getAllLinks( main )
435 linksResults = main.TRUE
436 linkFails = [] # Reset for each attempt
437 if not hostsResults:
438 hosts = main.topo.getAllHosts( main )
439 hostsResults = main.TRUE
440 hostFails = [] # Reset for each attempt
441
442 # Check for matching topology on each node
443 for controller in range( main.numCtrls ):
444 controllerStr = str( controller + 1 ) # ONOS node number
445 # Compare Devices
446 if devices[ controller ] and ports[ controller ] and\
447 "Error" not in devices[ controller ] and\
448 "Error" not in ports[ controller ]:
449
450 try:
451 deviceData = json.loads( devices[ controller ] )
452 portData = json.loads( ports[ controller ] )
453 except (TypeError,ValueError):
454 main.log.error("Could not load json:" + str( devices[ controller ] ) + ' or ' + str( ports[ controller ] ))
455 currentDevicesResult = main.FALSE
456 else:
457 if mnSwitches == len( deviceData ):
458 currentDevicesResult = main.TRUE
459 else:
460 currentDevicesResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700461 main.log.error( "Node {} only sees {} device(s) but {} exist".format(
acsmars51a7fe02015-10-29 18:33:32 -0700462 controllerStr,len( deviceData ),mnSwitches ) )
463 else:
464 currentDevicesResult = main.FALSE
465 if not currentDevicesResult:
466 deviceFails.append( controllerStr )
467 devicesResults = devicesResults and currentDevicesResult
468 # Compare Links
469 if links[ controller ] and "Error" not in links[ controller ]:
470 try:
471 linkData = json.loads( links[ controller ] )
472 except (TypeError,ValueError):
473 main.log.error("Could not load json:" + str( links[ controller ] ) )
474 currentLinksResult = main.FALSE
475 else:
476 if mnLinks == len( linkData ):
477 currentLinksResult = main.TRUE
478 else:
479 currentLinksResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700480 main.log.error( "Node {} only sees {} link(s) but {} exist".format(
acsmars51a7fe02015-10-29 18:33:32 -0700481 controllerStr,len( linkData ),mnLinks ) )
482 else:
483 currentLinksResult = main.FALSE
484 if not currentLinksResult:
485 linkFails.append( controllerStr )
486 linksResults = linksResults and currentLinksResult
487 # Compare Hosts
488 if hosts[ controller ] and "Error" not in hosts[ controller ]:
489 try:
490 hostData = json.loads( hosts[ controller ] )
491 except (TypeError,ValueError):
492 main.log.error("Could not load json:" + str( hosts[ controller ] ) )
493 currentHostsResult = main.FALSE
494 else:
495 if mnHosts == len( hostData ):
496 currentHostsResult = main.TRUE
497 else:
498 currentHostsResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700499 main.log.error( "Node {} only sees {} host(s) but {} exist".format(
acsmars51a7fe02015-10-29 18:33:32 -0700500 controllerStr,len( hostData ),mnHosts ) )
501 else:
502 currentHostsResult = main.FALSE
503 if not currentHostsResult:
504 hostFails.append( controllerStr )
505 hostsResults = hostsResults and currentHostsResult
506 # Decrement Attempts Remaining
507 attempts -= 1
508
509 utilities.assert_equals( expect=[],
510 actual=deviceFails,
511 onpass="ONOS correctly discovered all devices",
512 onfail="ONOS incorrectly discovered devices on nodes: " +
513 str( deviceFails ) )
514 utilities.assert_equals( expect=[],
515 actual=linkFails,
516 onpass="ONOS correctly discovered all links",
517 onfail="ONOS incorrectly discovered links on nodes: " +
518 str( linkFails ) )
519 utilities.assert_equals( expect=[],
520 actual=hostFails,
521 onpass="ONOS correctly discovered all hosts",
522 onfail="ONOS incorrectly discovered hosts on nodes: " +
523 str( hostFails ) )
524 if hostsResults and linksResults and devicesResults:
525 topoResults = main.TRUE
526 else:
527 topoResults = main.FALSE
528 utilities.assert_equals( expect=main.TRUE,
529 actual=topoResults,
530 onpass="ONOS correctly discovered the topology",
531 onfail="ONOS incorrectly discovered the topology" )
532
533
534 def CASE31( self, main ):
535 import time
536 """
537 Add bidirectional point intents between 2 packet layer( mininet )
538 devices and ping mininet hosts
539 """
540 main.log.report(
541 "This testcase adds bidirectional point intents between 2 " +
542 "packet layer( mininet ) devices and ping mininet hosts" )
543 main.case( "Install point intents between 2 packet layer device and " +
544 "ping the hosts" )
545 main.caseExplanation = "This testcase adds bidirectional point intents between 2 " +\
546 "packet layer( mininet ) devices and ping mininet hosts"
547
548 main.step( "Adding point intents" )
549 checkFlowResult = main.TRUE
550 main.pIntentsId = []
551 pIntent1 = main.CLIs[ 0 ].addPointIntent(
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700552 "of:0000000000000001/1",
553 "of:0000000000000002/1" )
acsmars51a7fe02015-10-29 18:33:32 -0700554 time.sleep( 10 )
555 pIntent2 = main.CLIs[ 0 ].addPointIntent(
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700556 "of:0000000000000002/1",
557 "of:0000000000000001/1" )
acsmars51a7fe02015-10-29 18:33:32 -0700558 main.pIntentsId.append( pIntent1 )
559 main.pIntentsId.append( pIntent2 )
560 time.sleep( 10 )
561 main.log.info( "Checking intents state")
562 checkStateResult = main.CLIs[ 0 ].checkIntentState(
563 intentsId = main.pIntentsId )
564 time.sleep( 10 )
565 main.log.info( "Checking flows state")
566 checkFlowResult = main.CLIs[ 0 ].checkFlowsState()
567 # Sleep for 10 seconds to provide time for the intent state to change
568 time.sleep( 10 )
569 main.log.info( "Checking intents state one more time")
570 checkStateResult = main.CLIs[ 0 ].checkIntentState(
571 intentsId = main.pIntentsId )
Jeremye4bc7132016-03-30 14:04:01 -0700572
acsmars51a7fe02015-10-29 18:33:32 -0700573 if checkStateResult and checkFlowResult:
574 addIntentsResult = main.TRUE
575 else:
576 addIntentsResult = main.FALSE
577 utilities.assert_equals(
578 expect=main.TRUE,
579 actual=addIntentsResult,
580 onpass="Successfully added point intents",
581 onfail="Failed to add point intents")
582
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700583 pingResult = main.FALSE
acsmars51a7fe02015-10-29 18:33:32 -0700584
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700585 if not addIntentsResult:
586 main.log.error( "Intents were not properly installed. Skipping ping." )
587
588 else:
589 main.step( "Ping h1 and h2" )
590 pingResult = main.LincOE.pingHostOptical( src="h1", target="h2" )
acsmars51a7fe02015-10-29 18:33:32 -0700591 utilities.assert_equals(
592 expect=main.TRUE,
593 actual=pingResult,
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700594 onpass="Successfully pinged h1 and h2",
595 onfail="Failed to ping between h1 and h2")
596
597 main.step( "Remove Point to Point intents" )
598 removeResult = main.FALSE
599 # Check remaining intents
600 try:
601 intentsJson = json.loads( main.CLIs[ 0 ].intents() )
602 main.log.debug( intentsJson )
603 main.CLIs[ 0 ].removeIntent( intentId=pIntent1, purge=True )
604 main.CLIs[ 0 ].removeIntent( intentId=pIntent2, purge=True )
605 for intents in intentsJson:
606 main.CLIs[ 0 ].removeIntent( intentId=intents.get( 'id' ),
607 app='org.onosproject.cli',
608 purge=True )
609 time.sleep( 15 )
610
611 for i in range( main.numCtrls ):
612 if len( json.loads( main.CLIs[ i ].intents() ) ):
613 print json.loads( main.CLIs[ i ].intents() )
614 removeResult = main.FALSE
615 else:
616 removeResult = main.TRUE
617 except ( TypeError, ValueError ):
618 main.log.error( "Cannot see intents on Node " + str( main.CLIs[ 0 ] ) +\
619 ". Removing all intents.")
620 main.CLIs[ 0 ].removeAllIntents( purge=True )
621 main.CLIs[ 0 ].removeAllIntents( purge=True, app='org.onosproject.cli')
622
623 utilities.assert_equals( expect=main.TRUE,
624 actual=removeResult,
625 onpass="Successfully removed host intents",
626 onfail="Failed to remove host intents" )
acsmars51a7fe02015-10-29 18:33:32 -0700627
628 def CASE32( self ):
629 """
630 Add host intents between 2 packet layer host
631 """
632 import time
633 import json
634 main.log.report( "Adding host intents between 2 optical layer host" )
635 main.case( "Test add host intents between optical layer host" )
636 main.caseExplanation = "Test host intents between 2 optical layer host"
637
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700638 main.step( "Creating list of hosts" )
639 hostnum = 0
640 try:
641 hostData = json.loads( hosts[ controller ] )
642 except( TypeError, ValueError ):
643 main.log.error("Could not load json:" + str( hosts[ controller ] ) )
644
acsmars51a7fe02015-10-29 18:33:32 -0700645 main.step( "Adding host intents to h1 and h2" )
acsmars51a7fe02015-10-29 18:33:32 -0700646 hostId = []
647 # Listing host MAC addresses
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700648 for host in hostData:
649 hostId.append( host.get("id") )
acsmars51a7fe02015-10-29 18:33:32 -0700650 host1 = hostId[ 0 ]
651 host2 = hostId[ 1 ]
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700652 main.log.debug( host1 )
653 main.log.debug( host2 )
acsmars51a7fe02015-10-29 18:33:32 -0700654
655 intentsId = []
656 intent1 = main.CLIs[ 0 ].addHostIntent( hostIdOne = host1,
657 hostIdTwo = host2 )
658 intentsId.append( intent1 )
659 # Checking intents state before pinging
660 main.log.info( "Checking intents state" )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700661 intentResult = utilities.retry( f=main.CLIs[ 0 ].checkIntentState,
662 retValue=main.FALSE, args=intentsId,
663 sleep=main.checkIntentSleep, attempts=10 )
acsmars51a7fe02015-10-29 18:33:32 -0700664
665 # If intent state is still wrong, display intent states
666 if not intentResult:
667 main.log.error( main.CLIs[ 0 ].intents() )
Jeremye4bc7132016-03-30 14:04:01 -0700668
acsmars51a7fe02015-10-29 18:33:32 -0700669 utilities.assert_equals( expect=main.TRUE,
670 actual=intentResult,
671 onpass="All intents are in INSTALLED state ",
672 onfail="Some of the intents are not in " +
673 "INSTALLED state " )
674
675 if not intentResult:
676 main.log.error( "Intents were not properly installed. Skipping Ping" )
677 else:
678 # Pinging h1 to h2 and then ping h2 to h1
679 main.step( "Pinging h1 and h2" )
680 pingResult = main.TRUE
681 pingResult = main.LincOE.pingHostOptical( src="h1", target="h2" ) \
682 and main.LincOE.pingHostOptical( src="h2",target="h1" )
Jeremye4bc7132016-03-30 14:04:01 -0700683
acsmars51a7fe02015-10-29 18:33:32 -0700684 utilities.assert_equals( expect=main.TRUE,
685 actual=pingResult,
686 onpass="Pinged successfully between h1 and h2",
687 onfail="Pinged failed between h1 and h2" )
688
689 # Removed all added host intents
690 main.step( "Removing host intents" )
691 removeResult = main.TRUE
692 # Check remaining intents
Jeremy7134f5b2016-04-05 13:50:21 -0700693 try:
694 intentsJson = json.loads( main.CLIs[ 0 ].intents() )
695 main.CLIs[ 0 ].removeIntent( intentId=intent1, purge=True )
696 #main.CLIs[ 0 ].removeIntent( intentId=intent2, purge=True )
697 main.log.debug(intentsJson)
698 for intents in intentsJson:
Jeremye4bc7132016-03-30 14:04:01 -0700699 main.CLIs[ 0 ].removeIntent( intentId=intents.get( 'id' ),
700 app='org.onosproject.optical',
701 purge=True )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700702 time.sleep( 15 )
acsmars51a7fe02015-10-29 18:33:32 -0700703
Jeremy7134f5b2016-04-05 13:50:21 -0700704 for i in range( main.numCtrls ):
705 if len( json.loads( main.CLIs[ i ].intents() ) ):
706 print json.loads( main.CLIs[ i ].intents() )
707 removeResult = main.FALSE
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700708 else:
709 removeResult = main.TRUE
Jeremy7134f5b2016-04-05 13:50:21 -0700710 except ( TypeError, ValueError ):
711 main.log.error( "Cannot see intents on Node " + str( main.CLIs[ 0 ] ) +\
712 ". Removing all intents.")
713 main.CLIs[ 0 ].removeAllIntents( purge=True )
714 main.CLIs[ 0 ].removeAllIntents( purge=True, app='org.onosproject.optical')
715
716 utilities.assert_equals( expect=main.TRUE,
717 actual=removeResult,
718 onpass="Successfully removed host intents",
Chiyu Chengef109502016-11-21 15:51:38 -0800719 onfail="Failed to remove host intents" )