blob: 2c4b0ca423a1de742a0754b856d7c8190ac0ed0e [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" )
155 packageResult = main.ONOSbench.onosPackage()
156 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
188 time.sleep( main.startUpSleep )
189 main.step( "Starting ONOS service" )
190 stopResult = main.TRUE
191 startResult = main.TRUE
192 onosIsUp = main.TRUE
193
194 for i in range( main.numCtrls ):
Jeremy Songster7edb6632016-04-28 15:44:28 -0700195 isUp = main.ONOSbench.isup( main.ONOSip[ i ] )
196 onosIsUp = onosIsUp and isUp
197 if isUp == main.TRUE:
198 main.log.report( "ONOS instance {0} is up and ready".format( i + 1 ) )
199 else:
200 main.log.report( "ONOS instance {0} may not be up, stop and ".format( i + 1 ) +
201 "start ONOS again " )
202 stopResult = stopResult and main.ONOSbench.onosStop( main.ONOSip[ i ] )
203 startResult = startResult and main.ONOSbench.onosStart( main.ONOSip[ i ] )
204 if not startResult or stopResult:
205 main.log.report( "ONOS instance {0} did not start correctly.".format( i + 1) )
acsmars51a7fe02015-10-29 18:33:32 -0700206 stepResult = onosIsUp and stopResult and startResult
207 utilities.assert_equals( expect=main.TRUE,
208 actual=stepResult,
Jeremy Songster7edb6632016-04-28 15:44:28 -0700209 onpass="ONOS service is ready on all nodes",
210 onfail="ONOS service did not start properly on all nodes" )
acsmars51a7fe02015-10-29 18:33:32 -0700211
212 main.step( "Start ONOS cli" )
213 cliResult = main.TRUE
214 for i in range( main.numCtrls ):
215 cliResult = cliResult and \
216 main.CLIs[ i ].startOnosCli( main.ONOSip[ i ] )
217 stepResult = cliResult
218 utilities.assert_equals( expect=main.TRUE,
219 actual=stepResult,
220 onpass="Successfully start ONOS cli",
221 onfail="Failed to start ONOS cli" )
222
223 # Remove the first element in main.scale list
224 main.scale.remove( main.scale[ 0 ] )
225
acsmars51a7fe02015-10-29 18:33:32 -0700226 def CASE10( self, main ):
227 """
228 Start Mininet opticalTest Topology
229 """
230 main.case( "Mininet with Linc-OE startup")
231 main.caseExplanation = "Start opticalTest.py topology included with ONOS"
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700232 if main.opticalTopo:
233 main.step( "Copying optical topology to $ONOS_ROOT/tools/test/topos/" )
234 main.ONOSbench.scp( main.ONOSbench,
235 "{0}{1}.py".format( main.dependencyPath, main.opticalTopo ),
236 "~/onos/tools/test/topos/{0}.py".format( main.opticalTopo ) )
acsmars51a7fe02015-10-29 18:33:32 -0700237 main.step( "Starting mininet and LINC-OE" )
238 topoResult = main.TRUE
239 time.sleep( 10 )
240 controllerIPs = ' '.join( main.activeONOSip )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700241 opticalMnScript = main.LincOE.runOpticalMnScript(ctrllerIP = controllerIPs, topology=main.opticalTopo )
acsmars51a7fe02015-10-29 18:33:32 -0700242 topoResult = opticalMnScript
243 utilities.assert_equals(
244 expect=main.TRUE,
245 actual=topoResult,
246 onpass="Started the topology successfully ",
247 onfail="Failed to start the topology")
248
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700249 main.step( "Push Topology.json to ONOS through onos-netcfg" )
250 pushResult = main.TRUE
251 time.sleep( 20 )
252 main.ONOSbench.onosNetCfg( controllerIps=controllerIPs, path=main.dependencyPath, fileName="Topology" )
253
acsmars51a7fe02015-10-29 18:33:32 -0700254 # Exit if topology did not load properly
255 if not topoResult:
256 main.cleanup()
257 main.exit()
258
Jeremye4bc7132016-03-30 14:04:01 -0700259
acsmars51a7fe02015-10-29 18:33:32 -0700260
261
262 def CASE14( self, main ):
263 """
264 Stop mininet
265 """
266 main.log.report( "Stop Mininet topology" )
267 main.case( "Stop Mininet topology" )
268 main.caseExplanation = "Stopping the current mininet topology " +\
269 "to start up fresh"
270
271 main.step( "Stopping Mininet Topology" )
272 topoResult = main.LincOE.stopNet( timeout=180 )
273 utilities.assert_equals( expect=main.TRUE,
274 actual=topoResult,
275 onpass="Successfully stopped mininet",
276 onfail="Failed to stopped mininet" )
277 # Exit if topology did not load properly
278 if not topoResult:
279 main.cleanup()
280 main.exit()
281
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700282 def CASE16( self, main ):
283 """
284 Balance Masters
285 """
286 main.case( "Balance mastership of switches" )
287 main.step( "Balancing mastership of switches" )
288
289 balanceResult = main.FALSE
290 balanceResult = utilities.retry( f=main.CLIs[ 0 ].balanceMasters, retValue=main.FALSE, args=[] )
291
292 utilities.assert_equals( expect=main.TRUE,
293 actual=balanceResult,
294 onpass="Successfully balanced mastership of switches",
295 onfail="Failed to balance mastership of switches" )
296 if not balanceResult:
297 main.initialized = main.FALSE
298
Jeremye4bc7132016-03-30 14:04:01 -0700299 def CASE17( self, main ):
300 """
301 Use Flow Objectives
302 """
303 main.case( "Enable intent compilation using Flow Objectives" )
304 main.step( "Enabling Flow Objectives" )
305
306 main.flowCompiler = "Flow Objectives"
307
308 cmd = "org.onosproject.net.intent.impl.compiler.IntentConfigurableRegistrator"
309
310 stepResult = main.CLIs[ 0 ].setCfg( component=cmd,
311 propName="useFlowObjectives", value="true" )
312
313 utilities.assert_equals( expect=main.TRUE,
314 actual=stepResult,
315 onpass="Successfully activated Flow Objectives",
316 onfail="Failed to activate Flow Objectives" )
317
Jeremy Songster17147f22016-05-31 18:30:52 -0700318 def CASE19( self, main ):
319 """
320 Copy the karaf.log files after each testcase cycle
321 """
322 main.log.report( "Copy karaf logs" )
323 main.case( "Copy karaf logs" )
324 main.caseExplanation = "Copying the karaf logs to preserve them through" +\
325 "reinstalling ONOS"
326 main.step( "Copying karaf logs" )
Jeremy Songster31aad312016-06-13 16:32:11 -0700327 stepResult = main.TRUE
328 scpResult = main.TRUE
329 copyResult = main.TRUE
Jeremy Songstercc5414b2016-07-11 10:59:53 -0700330 for i in range( main.numCtrls ):
331 main.node = main.CLIs[ i ]
Jeremy Songster17147f22016-05-31 18:30:52 -0700332 ip = main.ONOSip[ i ]
333 main.node.ip_address = ip
Jeremy Songster31aad312016-06-13 16:32:11 -0700334 scpResult = scpResult and main.ONOSbench.scp( main.node ,
335 "/opt/onos/log/karaf.log",
336 "/tmp/karaf.log",
337 direction="from" )
338 copyResult = copyResult and main.ONOSbench.cpLogsToDir( "/tmp/karaf.log", main.logdir,
339 copyFileName=( "karaf.log.node{0}.cycle{1}".format( str( i + 1 ), str( main.cycle ) ) ) )
340 if scpResult and copyResult:
341 stepResult = main.TRUE and stepResult
342 else:
343 stepResult = main.FALSE and stepResult
Jeremy Songster31aad312016-06-13 16:32:11 -0700344 utilities.assert_equals( expect=main.TRUE,
345 actual=stepResult,
346 onpass="Successfully copied remote ONOS logs",
347 onfail="Failed to copy remote ONOS logs" )
Jeremy Songster17147f22016-05-31 18:30:52 -0700348
acsmars51a7fe02015-10-29 18:33:32 -0700349 def CASE21( self,main ):
350 """
351 Run pingall to discover all hosts
352 """
353 main.case( "Running Pingall" )
354 main.caseExplanation = "Use pingall to discover all hosts. Pingall is expected to fail."
355 main.step( "Discover Hosts through Pingall" )
Jeremy Songster7edb6632016-04-28 15:44:28 -0700356 pingResult = main.LincOE.pingall( timeout = 120 )
acsmars51a7fe02015-10-29 18:33:32 -0700357
358 utilities.assert_equals( expect=main.FALSE,
359 actual=pingResult,
360 onpass="Pingall Completed",
361 onfail="Pingall did not complete or did not return fales" )
362
363 def CASE22( self,main ):
364 """
365 Send arpings to discover all hosts
366 """
367 main.case( "Discover Hosts with arping" )
368 main.caseExplanation = "Send arpings between all the hosts to discover and verify them"
369
370 main.step( "Send arping between all hosts" )
371
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700372 hosts = []
373 for i in range( main.hosts ):
374 hosts.append( 'h{}'.format( i + 1 ) )
acsmars51a7fe02015-10-29 18:33:32 -0700375
376 arpingHostResults = main.TRUE
377 for host in hosts:
378 if main.LincOE.arping( host ):
379 main.log.info( "Successfully reached host {} with arping".format( host ) )
380 else:
381 main.log.error( "Could not reach host {} with arping".format( host ) )
382 arpingHostResults = main.FALSE
383
384 utilities.assert_equals( expect=main.TRUE,
385 actual=arpingHostResults,
386 onpass="Successfully discovered all hosts",
387 onfail="Could not descover some hosts" )
388
389 def CASE23( self, main ):
390 """
391 Compare ONOS Topology to Mininet Topology
392 """
393 import json
394
395 main.case( "Compare ONOS Topology view to Mininet topology" )
396 main.caseExplanation = "Compare topology elements between Mininet" +\
397 " and ONOS"
398
399 main.log.info( "Gathering topology information from Mininet" )
400 devicesResults = main.FALSE # Overall Boolean for device correctness
401 linksResults = main.FALSE # Overall Boolean for link correctness
402 hostsResults = main.FALSE # Overall Boolean for host correctness
403 deviceFails = [] # Nodes where devices are incorrect
404 linkFails = [] # Nodes where links are incorrect
405 hostFails = [] # Nodes where hosts are incorrect
406 attempts = main.checkTopoAttempts # Remaining Attempts
407
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700408 mnSwitches = main.switches
409 mnLinks = main.links
410 mnHosts = main.hosts
acsmars51a7fe02015-10-29 18:33:32 -0700411
Jon Hall70b2ff42015-11-17 15:49:44 -0800412 main.step( "Comparing Mininet topology to ONOS topology" )
acsmars51a7fe02015-10-29 18:33:32 -0700413
414 while ( attempts >= 0 ) and\
415 ( not devicesResults or not linksResults or not hostsResults ):
416 time.sleep( 2 )
417 if not devicesResults:
418 devices = main.topo.getAllDevices( main )
419 ports = main.topo.getAllPorts( main )
420 devicesResults = main.TRUE
421 deviceFails = [] # Reset for each attempt
422 if not linksResults:
423 links = main.topo.getAllLinks( main )
424 linksResults = main.TRUE
425 linkFails = [] # Reset for each attempt
426 if not hostsResults:
427 hosts = main.topo.getAllHosts( main )
428 hostsResults = main.TRUE
429 hostFails = [] # Reset for each attempt
430
431 # Check for matching topology on each node
432 for controller in range( main.numCtrls ):
433 controllerStr = str( controller + 1 ) # ONOS node number
434 # Compare Devices
435 if devices[ controller ] and ports[ controller ] and\
436 "Error" not in devices[ controller ] and\
437 "Error" not in ports[ controller ]:
438
439 try:
440 deviceData = json.loads( devices[ controller ] )
441 portData = json.loads( ports[ controller ] )
442 except (TypeError,ValueError):
443 main.log.error("Could not load json:" + str( devices[ controller ] ) + ' or ' + str( ports[ controller ] ))
444 currentDevicesResult = main.FALSE
445 else:
446 if mnSwitches == len( deviceData ):
447 currentDevicesResult = main.TRUE
448 else:
449 currentDevicesResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700450 main.log.error( "Node {} only sees {} device(s) but {} exist".format(
acsmars51a7fe02015-10-29 18:33:32 -0700451 controllerStr,len( deviceData ),mnSwitches ) )
452 else:
453 currentDevicesResult = main.FALSE
454 if not currentDevicesResult:
455 deviceFails.append( controllerStr )
456 devicesResults = devicesResults and currentDevicesResult
457 # Compare Links
458 if links[ controller ] and "Error" not in links[ controller ]:
459 try:
460 linkData = json.loads( links[ controller ] )
461 except (TypeError,ValueError):
462 main.log.error("Could not load json:" + str( links[ controller ] ) )
463 currentLinksResult = main.FALSE
464 else:
465 if mnLinks == len( linkData ):
466 currentLinksResult = main.TRUE
467 else:
468 currentLinksResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700469 main.log.error( "Node {} only sees {} link(s) but {} exist".format(
acsmars51a7fe02015-10-29 18:33:32 -0700470 controllerStr,len( linkData ),mnLinks ) )
471 else:
472 currentLinksResult = main.FALSE
473 if not currentLinksResult:
474 linkFails.append( controllerStr )
475 linksResults = linksResults and currentLinksResult
476 # Compare Hosts
477 if hosts[ controller ] and "Error" not in hosts[ controller ]:
478 try:
479 hostData = json.loads( hosts[ controller ] )
480 except (TypeError,ValueError):
481 main.log.error("Could not load json:" + str( hosts[ controller ] ) )
482 currentHostsResult = main.FALSE
483 else:
484 if mnHosts == len( hostData ):
485 currentHostsResult = main.TRUE
486 else:
487 currentHostsResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700488 main.log.error( "Node {} only sees {} host(s) but {} exist".format(
acsmars51a7fe02015-10-29 18:33:32 -0700489 controllerStr,len( hostData ),mnHosts ) )
490 else:
491 currentHostsResult = main.FALSE
492 if not currentHostsResult:
493 hostFails.append( controllerStr )
494 hostsResults = hostsResults and currentHostsResult
495 # Decrement Attempts Remaining
496 attempts -= 1
497
498 utilities.assert_equals( expect=[],
499 actual=deviceFails,
500 onpass="ONOS correctly discovered all devices",
501 onfail="ONOS incorrectly discovered devices on nodes: " +
502 str( deviceFails ) )
503 utilities.assert_equals( expect=[],
504 actual=linkFails,
505 onpass="ONOS correctly discovered all links",
506 onfail="ONOS incorrectly discovered links on nodes: " +
507 str( linkFails ) )
508 utilities.assert_equals( expect=[],
509 actual=hostFails,
510 onpass="ONOS correctly discovered all hosts",
511 onfail="ONOS incorrectly discovered hosts on nodes: " +
512 str( hostFails ) )
513 if hostsResults and linksResults and devicesResults:
514 topoResults = main.TRUE
515 else:
516 topoResults = main.FALSE
517 utilities.assert_equals( expect=main.TRUE,
518 actual=topoResults,
519 onpass="ONOS correctly discovered the topology",
520 onfail="ONOS incorrectly discovered the topology" )
521
522
523 def CASE31( self, main ):
524 import time
525 """
526 Add bidirectional point intents between 2 packet layer( mininet )
527 devices and ping mininet hosts
528 """
529 main.log.report(
530 "This testcase adds bidirectional point intents between 2 " +
531 "packet layer( mininet ) devices and ping mininet hosts" )
532 main.case( "Install point intents between 2 packet layer device and " +
533 "ping the hosts" )
534 main.caseExplanation = "This testcase adds bidirectional point intents between 2 " +\
535 "packet layer( mininet ) devices and ping mininet hosts"
536
537 main.step( "Adding point intents" )
538 checkFlowResult = main.TRUE
539 main.pIntentsId = []
540 pIntent1 = main.CLIs[ 0 ].addPointIntent(
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700541 "of:0000000000000001/1",
542 "of:0000000000000002/1" )
acsmars51a7fe02015-10-29 18:33:32 -0700543 time.sleep( 10 )
544 pIntent2 = main.CLIs[ 0 ].addPointIntent(
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700545 "of:0000000000000002/1",
546 "of:0000000000000001/1" )
acsmars51a7fe02015-10-29 18:33:32 -0700547 main.pIntentsId.append( pIntent1 )
548 main.pIntentsId.append( pIntent2 )
549 time.sleep( 10 )
550 main.log.info( "Checking intents state")
551 checkStateResult = main.CLIs[ 0 ].checkIntentState(
552 intentsId = main.pIntentsId )
553 time.sleep( 10 )
554 main.log.info( "Checking flows state")
555 checkFlowResult = main.CLIs[ 0 ].checkFlowsState()
556 # Sleep for 10 seconds to provide time for the intent state to change
557 time.sleep( 10 )
558 main.log.info( "Checking intents state one more time")
559 checkStateResult = main.CLIs[ 0 ].checkIntentState(
560 intentsId = main.pIntentsId )
Jeremye4bc7132016-03-30 14:04:01 -0700561
acsmars51a7fe02015-10-29 18:33:32 -0700562 if checkStateResult and checkFlowResult:
563 addIntentsResult = main.TRUE
564 else:
565 addIntentsResult = main.FALSE
566 utilities.assert_equals(
567 expect=main.TRUE,
568 actual=addIntentsResult,
569 onpass="Successfully added point intents",
570 onfail="Failed to add point intents")
571
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700572 pingResult = main.FALSE
acsmars51a7fe02015-10-29 18:33:32 -0700573
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700574 if not addIntentsResult:
575 main.log.error( "Intents were not properly installed. Skipping ping." )
576
577 else:
578 main.step( "Ping h1 and h2" )
579 pingResult = main.LincOE.pingHostOptical( src="h1", target="h2" )
acsmars51a7fe02015-10-29 18:33:32 -0700580 utilities.assert_equals(
581 expect=main.TRUE,
582 actual=pingResult,
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700583 onpass="Successfully pinged h1 and h2",
584 onfail="Failed to ping between h1 and h2")
585
586 main.step( "Remove Point to Point intents" )
587 removeResult = main.FALSE
588 # Check remaining intents
589 try:
590 intentsJson = json.loads( main.CLIs[ 0 ].intents() )
591 main.log.debug( intentsJson )
592 main.CLIs[ 0 ].removeIntent( intentId=pIntent1, purge=True )
593 main.CLIs[ 0 ].removeIntent( intentId=pIntent2, purge=True )
594 for intents in intentsJson:
595 main.CLIs[ 0 ].removeIntent( intentId=intents.get( 'id' ),
596 app='org.onosproject.cli',
597 purge=True )
598 time.sleep( 15 )
599
600 for i in range( main.numCtrls ):
601 if len( json.loads( main.CLIs[ i ].intents() ) ):
602 print json.loads( main.CLIs[ i ].intents() )
603 removeResult = main.FALSE
604 else:
605 removeResult = main.TRUE
606 except ( TypeError, ValueError ):
607 main.log.error( "Cannot see intents on Node " + str( main.CLIs[ 0 ] ) +\
608 ". Removing all intents.")
609 main.CLIs[ 0 ].removeAllIntents( purge=True )
610 main.CLIs[ 0 ].removeAllIntents( purge=True, app='org.onosproject.cli')
611
612 utilities.assert_equals( expect=main.TRUE,
613 actual=removeResult,
614 onpass="Successfully removed host intents",
615 onfail="Failed to remove host intents" )
acsmars51a7fe02015-10-29 18:33:32 -0700616
617 def CASE32( self ):
618 """
619 Add host intents between 2 packet layer host
620 """
621 import time
622 import json
623 main.log.report( "Adding host intents between 2 optical layer host" )
624 main.case( "Test add host intents between optical layer host" )
625 main.caseExplanation = "Test host intents between 2 optical layer host"
626
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700627 main.step( "Creating list of hosts" )
628 hostnum = 0
629 try:
630 hostData = json.loads( hosts[ controller ] )
631 except( TypeError, ValueError ):
632 main.log.error("Could not load json:" + str( hosts[ controller ] ) )
633
acsmars51a7fe02015-10-29 18:33:32 -0700634 main.step( "Adding host intents to h1 and h2" )
acsmars51a7fe02015-10-29 18:33:32 -0700635 hostId = []
636 # Listing host MAC addresses
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700637 for host in hostData:
638 hostId.append( host.get("id") )
acsmars51a7fe02015-10-29 18:33:32 -0700639 host1 = hostId[ 0 ]
640 host2 = hostId[ 1 ]
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700641 main.log.debug( host1 )
642 main.log.debug( host2 )
acsmars51a7fe02015-10-29 18:33:32 -0700643
644 intentsId = []
645 intent1 = main.CLIs[ 0 ].addHostIntent( hostIdOne = host1,
646 hostIdTwo = host2 )
647 intentsId.append( intent1 )
648 # Checking intents state before pinging
649 main.log.info( "Checking intents state" )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700650 intentResult = utilities.retry( f=main.CLIs[ 0 ].checkIntentState,
651 retValue=main.FALSE, args=intentsId,
652 sleep=main.checkIntentSleep, attempts=10 )
acsmars51a7fe02015-10-29 18:33:32 -0700653
654 # If intent state is still wrong, display intent states
655 if not intentResult:
656 main.log.error( main.CLIs[ 0 ].intents() )
Jeremye4bc7132016-03-30 14:04:01 -0700657
acsmars51a7fe02015-10-29 18:33:32 -0700658 utilities.assert_equals( expect=main.TRUE,
659 actual=intentResult,
660 onpass="All intents are in INSTALLED state ",
661 onfail="Some of the intents are not in " +
662 "INSTALLED state " )
663
664 if not intentResult:
665 main.log.error( "Intents were not properly installed. Skipping Ping" )
666 else:
667 # Pinging h1 to h2 and then ping h2 to h1
668 main.step( "Pinging h1 and h2" )
669 pingResult = main.TRUE
670 pingResult = main.LincOE.pingHostOptical( src="h1", target="h2" ) \
671 and main.LincOE.pingHostOptical( src="h2",target="h1" )
Jeremye4bc7132016-03-30 14:04:01 -0700672
acsmars51a7fe02015-10-29 18:33:32 -0700673 utilities.assert_equals( expect=main.TRUE,
674 actual=pingResult,
675 onpass="Pinged successfully between h1 and h2",
676 onfail="Pinged failed between h1 and h2" )
677
678 # Removed all added host intents
679 main.step( "Removing host intents" )
680 removeResult = main.TRUE
681 # Check remaining intents
Jeremy7134f5b2016-04-05 13:50:21 -0700682 try:
683 intentsJson = json.loads( main.CLIs[ 0 ].intents() )
684 main.CLIs[ 0 ].removeIntent( intentId=intent1, purge=True )
685 #main.CLIs[ 0 ].removeIntent( intentId=intent2, purge=True )
686 main.log.debug(intentsJson)
687 for intents in intentsJson:
Jeremye4bc7132016-03-30 14:04:01 -0700688 main.CLIs[ 0 ].removeIntent( intentId=intents.get( 'id' ),
689 app='org.onosproject.optical',
690 purge=True )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700691 time.sleep( 15 )
acsmars51a7fe02015-10-29 18:33:32 -0700692
Jeremy7134f5b2016-04-05 13:50:21 -0700693 for i in range( main.numCtrls ):
694 if len( json.loads( main.CLIs[ i ].intents() ) ):
695 print json.loads( main.CLIs[ i ].intents() )
696 removeResult = main.FALSE
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700697 else:
698 removeResult = main.TRUE
Jeremy7134f5b2016-04-05 13:50:21 -0700699 except ( TypeError, ValueError ):
700 main.log.error( "Cannot see intents on Node " + str( main.CLIs[ 0 ] ) +\
701 ". Removing all intents.")
702 main.CLIs[ 0 ].removeAllIntents( purge=True )
703 main.CLIs[ 0 ].removeAllIntents( purge=True, app='org.onosproject.optical')
704
705 utilities.assert_equals( expect=main.TRUE,
706 actual=removeResult,
707 onpass="Successfully removed host intents",
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700708 onfail="Failed to remove host intents" )