blob: f4ac6ce22e7eb5c7dcbd6dc766f296e050397f1e [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' ]
43 wrapperFile2 = main.params[ 'DEPENDENCY' ][ 'wrapper2' ]
44 wrapperFile3 = main.params[ 'DEPENDENCY' ][ 'wrapper3' ]
45 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
46 main.checkIntentSleep = int( main.params[ 'SLEEP' ][ 'checkintent' ] )
47 main.removeIntentSleep = int( main.params[ 'SLEEP' ][ 'removeintent' ] )
48 main.rerouteSleep = int( main.params[ 'SLEEP' ][ 'reroute' ] )
49 main.fwdSleep = int( main.params[ 'SLEEP' ][ 'fwd' ] )
50 main.checkTopoAttempts = int( main.params[ 'SLEEP' ][ 'topoAttempts' ] )
51 gitPull = main.params[ 'GIT' ][ 'pull' ]
52 main.numSwitch = int( main.params[ 'MININET' ][ 'switch' ] )
53 main.numLinks = int( main.params[ 'MININET' ][ 'links' ] )
54 main.cellData = {} # For creating cell file
55 main.hostsData = {}
56 main.CLIs = []
57 main.ONOSip = [] # List of IPs of active ONOS nodes. CASE 2
58 main.activeONOSip = []
59 main.assertReturnString = '' # Assembled assert return string
Jeremy Songster17147f22016-05-31 18:30:52 -070060 main.cycle = 0 # How many times FUNCintent has run through its tests
acsmars51a7fe02015-10-29 18:33:32 -070061
62 main.ONOSip = main.ONOSbench.getOnosIps()
63
64 # Assigning ONOS cli handles to a list
65 for i in range( 1, main.maxNodes + 1 ):
66 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
67
68 # -- INIT SECTION, ONLY RUNS ONCE -- #
69 main.startUp = imp.load_source( wrapperFile1,
70 main.dependencyPath +
71 wrapperFile1 +
72 ".py" )
73
74 main.intentFunction = imp.load_source( wrapperFile2,
75 main.dependencyPath +
76 wrapperFile2 +
77 ".py" )
78
79 main.topo = imp.load_source( wrapperFile3,
80 main.dependencyPath +
81 wrapperFile3 +
82 ".py" )
83
84 if main.CLIs:
85 stepResult = main.TRUE
86 else:
87 main.log.error( "Did not properly created list of ONOS CLI handle" )
88 stepResult = main.FALSE
89 except Exception as e:
90 main.log.exception(e)
91 main.cleanup()
92 main.exit()
93
94 utilities.assert_equals( expect=main.TRUE,
95 actual=stepResult,
96 onpass="Successfully construct " +
97 "test variables ",
98 onfail="Failed to construct test variables" )
99
100 if gitPull == 'True':
101 main.step( "Building ONOS in " + gitBranch + " branch" )
102 onosBuildResult = main.startUp.onosBuild( main, gitBranch )
103 stepResult = onosBuildResult
104 utilities.assert_equals( expect=main.TRUE,
105 actual=stepResult,
106 onpass="Successfully compiled " +
107 "latest ONOS",
108 onfail="Failed to compile " +
109 "latest ONOS" )
110 else:
111 main.log.warn( "Did not pull new code so skipping mvn " +
112 "clean install" )
113 main.ONOSbench.getVersion( report=True )
114
115 def CASE2( self, main ):
116 """
117 - Set up cell
118 - Create cell file
119 - Set cell file
120 - Verify cell file
121 - Kill ONOS process
122 - Uninstall ONOS cluster
123 - Verify ONOS start up
124 - Install ONOS cluster
125 - Connect to cli
126 """
127
Jeremy Songster17147f22016-05-31 18:30:52 -0700128 main.cycle += 1
129
acsmars51a7fe02015-10-29 18:33:32 -0700130 # main.scale[ 0 ] determines the current number of ONOS controller
131 main.numCtrls = int( main.scale[ 0 ] )
Jeremye4bc7132016-03-30 14:04:01 -0700132 main.flowCompiler = "Flow Rules"
acsmars51a7fe02015-10-29 18:33:32 -0700133
134 main.case( "Starting up " + str( main.numCtrls ) +
135 " node(s) ONOS cluster" )
136 main.caseExplanation = "Set up ONOS with " + str( main.numCtrls ) +\
137 " node(s) ONOS cluster"
138
139
140
141 #kill off all onos processes
142 main.log.info( "Safety check, killing all ONOS processes" +
Jon Hall70b2ff42015-11-17 15:49:44 -0800143 " before initiating environment setup" )
acsmars51a7fe02015-10-29 18:33:32 -0700144
145 for i in range( main.maxNodes ):
146 main.ONOSbench.onosDie( main.ONOSip[ i ] )
147
148 print "NODE COUNT = ", main.numCtrls
149
150 tempOnosIp = []
151 for i in range( main.numCtrls ):
152 tempOnosIp.append( main.ONOSip[i] )
153
154 main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
155 "temp", main.Mininet1.ip_address,
156 main.apps, tempOnosIp )
157
158 main.step( "Apply cell to environment" )
159 cellResult = main.ONOSbench.setCell( "temp" )
160 verifyResult = main.ONOSbench.verifyCell()
161 stepResult = cellResult and verifyResult
162 utilities.assert_equals( expect=main.TRUE,
163 actual=stepResult,
164 onpass="Successfully applied cell to " + \
165 "environment",
166 onfail="Failed to apply cell to environment " )
167
168 main.step( "Creating ONOS package" )
169 packageResult = main.ONOSbench.onosPackage()
170 stepResult = packageResult
171 utilities.assert_equals( expect=main.TRUE,
172 actual=stepResult,
173 onpass="Successfully created ONOS package",
174 onfail="Failed to create ONOS package" )
175
176 time.sleep( main.startUpSleep )
177 main.step( "Uninstalling ONOS package" )
178 onosUninstallResult = main.TRUE
179 for ip in main.ONOSip:
180 onosUninstallResult = onosUninstallResult and \
181 main.ONOSbench.onosUninstall( nodeIp=ip )
182 stepResult = onosUninstallResult
183 utilities.assert_equals( expect=main.TRUE,
184 actual=stepResult,
185 onpass="Successfully uninstalled ONOS package",
186 onfail="Failed to uninstall ONOS package" )
187
188 time.sleep( main.startUpSleep )
189 main.step( "Installing ONOS package" )
190 onosInstallResult = main.TRUE
191 for i in range( main.numCtrls ):
192 onosInstallResult = onosInstallResult and \
193 main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
194 # Populate activeONOSip
195 main.activeONOSip.append( main.ONOSip[ i ] )
196 stepResult = onosInstallResult
197 utilities.assert_equals( expect=main.TRUE,
198 actual=stepResult,
199 onpass="Successfully installed ONOS package",
200 onfail="Failed to install ONOS package" )
201
202 time.sleep( main.startUpSleep )
203 main.step( "Starting ONOS service" )
204 stopResult = main.TRUE
205 startResult = main.TRUE
206 onosIsUp = main.TRUE
207
208 for i in range( main.numCtrls ):
Jeremy Songster7edb6632016-04-28 15:44:28 -0700209 isUp = main.ONOSbench.isup( main.ONOSip[ i ] )
210 onosIsUp = onosIsUp and isUp
211 if isUp == main.TRUE:
212 main.log.report( "ONOS instance {0} is up and ready".format( i + 1 ) )
213 else:
214 main.log.report( "ONOS instance {0} may not be up, stop and ".format( i + 1 ) +
215 "start ONOS again " )
216 stopResult = stopResult and main.ONOSbench.onosStop( main.ONOSip[ i ] )
217 startResult = startResult and main.ONOSbench.onosStart( main.ONOSip[ i ] )
218 if not startResult or stopResult:
219 main.log.report( "ONOS instance {0} did not start correctly.".format( i + 1) )
acsmars51a7fe02015-10-29 18:33:32 -0700220 stepResult = onosIsUp and stopResult and startResult
221 utilities.assert_equals( expect=main.TRUE,
222 actual=stepResult,
Jeremy Songster7edb6632016-04-28 15:44:28 -0700223 onpass="ONOS service is ready on all nodes",
224 onfail="ONOS service did not start properly on all nodes" )
acsmars51a7fe02015-10-29 18:33:32 -0700225
226 main.step( "Start ONOS cli" )
227 cliResult = main.TRUE
228 for i in range( main.numCtrls ):
229 cliResult = cliResult and \
230 main.CLIs[ i ].startOnosCli( main.ONOSip[ i ] )
231 stepResult = cliResult
232 utilities.assert_equals( expect=main.TRUE,
233 actual=stepResult,
234 onpass="Successfully start ONOS cli",
235 onfail="Failed to start ONOS cli" )
236
237 # Remove the first element in main.scale list
238 main.scale.remove( main.scale[ 0 ] )
239
240 main.intentFunction.report( main )
241
242
243 def CASE10( self, main ):
244 """
245 Start Mininet opticalTest Topology
246 """
247 main.case( "Mininet with Linc-OE startup")
248 main.caseExplanation = "Start opticalTest.py topology included with ONOS"
249 main.step( "Starting mininet and LINC-OE" )
250 topoResult = main.TRUE
251 time.sleep( 10 )
252 controllerIPs = ' '.join( main.activeONOSip )
253 opticalMnScript = main.LincOE.runOpticalMnScript(ctrllerIP = controllerIPs)
254 topoResult = opticalMnScript
255 utilities.assert_equals(
256 expect=main.TRUE,
257 actual=topoResult,
258 onpass="Started the topology successfully ",
259 onfail="Failed to start the topology")
260
261 # Exit if topology did not load properly
262 if not topoResult:
263 main.cleanup()
264 main.exit()
265
Jeremye4bc7132016-03-30 14:04:01 -0700266
acsmars51a7fe02015-10-29 18:33:32 -0700267
268
269 def CASE14( self, main ):
270 """
271 Stop mininet
272 """
273 main.log.report( "Stop Mininet topology" )
274 main.case( "Stop Mininet topology" )
275 main.caseExplanation = "Stopping the current mininet topology " +\
276 "to start up fresh"
277
278 main.step( "Stopping Mininet Topology" )
279 topoResult = main.LincOE.stopNet( timeout=180 )
280 utilities.assert_equals( expect=main.TRUE,
281 actual=topoResult,
282 onpass="Successfully stopped mininet",
283 onfail="Failed to stopped mininet" )
284 # Exit if topology did not load properly
285 if not topoResult:
286 main.cleanup()
287 main.exit()
288
Jeremye4bc7132016-03-30 14:04:01 -0700289 def CASE17( self, main ):
290 """
291 Use Flow Objectives
292 """
293 main.case( "Enable intent compilation using Flow Objectives" )
294 main.step( "Enabling Flow Objectives" )
295
296 main.flowCompiler = "Flow Objectives"
297
298 cmd = "org.onosproject.net.intent.impl.compiler.IntentConfigurableRegistrator"
299
300 stepResult = main.CLIs[ 0 ].setCfg( component=cmd,
301 propName="useFlowObjectives", value="true" )
302
303 utilities.assert_equals( expect=main.TRUE,
304 actual=stepResult,
305 onpass="Successfully activated Flow Objectives",
306 onfail="Failed to activate Flow Objectives" )
307
Jeremy Songster17147f22016-05-31 18:30:52 -0700308 def CASE19( self, main ):
309 """
310 Copy the karaf.log files after each testcase cycle
311 """
312 main.log.report( "Copy karaf logs" )
313 main.case( "Copy karaf logs" )
314 main.caseExplanation = "Copying the karaf logs to preserve them through" +\
315 "reinstalling ONOS"
316 main.step( "Copying karaf logs" )
317 i = 0
318 for cli in main.CLIs:
319 main.node = cli
320 ip = main.ONOSip[ i ]
321 main.node.ip_address = ip
322 main.ONOSbench.scp( main.node ,
323 "/opt/onos/log/karaf.log",
324 "/tmp/karaf.log",
325 direction="from" )
326 main.ONOSbench.cpLogsToDir( "/tmp/karaf.log", main.logdir,
327 copyFileName=( "karaf.log.node{0}.cycle{1}".format( str( i + 1 ), str( main.cycle ) ) ) )
328 i += 1
329
acsmars51a7fe02015-10-29 18:33:32 -0700330 def CASE21( self,main ):
331 """
332 Run pingall to discover all hosts
333 """
334 main.case( "Running Pingall" )
335 main.caseExplanation = "Use pingall to discover all hosts. Pingall is expected to fail."
336 main.step( "Discover Hosts through Pingall" )
Jeremy Songster7edb6632016-04-28 15:44:28 -0700337 pingResult = main.LincOE.pingall( timeout = 120 )
acsmars51a7fe02015-10-29 18:33:32 -0700338
339 utilities.assert_equals( expect=main.FALSE,
340 actual=pingResult,
341 onpass="Pingall Completed",
342 onfail="Pingall did not complete or did not return fales" )
343
344 def CASE22( self,main ):
345 """
346 Send arpings to discover all hosts
347 """
348 main.case( "Discover Hosts with arping" )
349 main.caseExplanation = "Send arpings between all the hosts to discover and verify them"
350
351 main.step( "Send arping between all hosts" )
352
353 hosts = [ "h1","h2","h3","h4","h5","h6" ]
354
355 arpingHostResults = main.TRUE
356 for host in hosts:
357 if main.LincOE.arping( host ):
358 main.log.info( "Successfully reached host {} with arping".format( host ) )
359 else:
360 main.log.error( "Could not reach host {} with arping".format( host ) )
361 arpingHostResults = main.FALSE
362
363 utilities.assert_equals( expect=main.TRUE,
364 actual=arpingHostResults,
365 onpass="Successfully discovered all hosts",
366 onfail="Could not descover some hosts" )
367
368 def CASE23( self, main ):
369 """
370 Compare ONOS Topology to Mininet Topology
371 """
372 import json
373
374 main.case( "Compare ONOS Topology view to Mininet topology" )
375 main.caseExplanation = "Compare topology elements between Mininet" +\
376 " and ONOS"
377
378 main.log.info( "Gathering topology information from Mininet" )
379 devicesResults = main.FALSE # Overall Boolean for device correctness
380 linksResults = main.FALSE # Overall Boolean for link correctness
381 hostsResults = main.FALSE # Overall Boolean for host correctness
382 deviceFails = [] # Nodes where devices are incorrect
383 linkFails = [] # Nodes where links are incorrect
384 hostFails = [] # Nodes where hosts are incorrect
385 attempts = main.checkTopoAttempts # Remaining Attempts
386
387 mnSwitches = 16
388 mnLinks = 46
389 mnHosts = 6
390
Jon Hall70b2ff42015-11-17 15:49:44 -0800391 main.step( "Comparing Mininet topology to ONOS topology" )
acsmars51a7fe02015-10-29 18:33:32 -0700392
393 while ( attempts >= 0 ) and\
394 ( not devicesResults or not linksResults or not hostsResults ):
395 time.sleep( 2 )
396 if not devicesResults:
397 devices = main.topo.getAllDevices( main )
398 ports = main.topo.getAllPorts( main )
399 devicesResults = main.TRUE
400 deviceFails = [] # Reset for each attempt
401 if not linksResults:
402 links = main.topo.getAllLinks( main )
403 linksResults = main.TRUE
404 linkFails = [] # Reset for each attempt
405 if not hostsResults:
406 hosts = main.topo.getAllHosts( main )
407 hostsResults = main.TRUE
408 hostFails = [] # Reset for each attempt
409
410 # Check for matching topology on each node
411 for controller in range( main.numCtrls ):
412 controllerStr = str( controller + 1 ) # ONOS node number
413 # Compare Devices
414 if devices[ controller ] and ports[ controller ] and\
415 "Error" not in devices[ controller ] and\
416 "Error" not in ports[ controller ]:
417
418 try:
419 deviceData = json.loads( devices[ controller ] )
420 portData = json.loads( ports[ controller ] )
421 except (TypeError,ValueError):
422 main.log.error("Could not load json:" + str( devices[ controller ] ) + ' or ' + str( ports[ controller ] ))
423 currentDevicesResult = main.FALSE
424 else:
425 if mnSwitches == len( deviceData ):
426 currentDevicesResult = main.TRUE
427 else:
428 currentDevicesResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700429 main.log.error( "Node {} only sees {} device(s) but {} exist".format(
acsmars51a7fe02015-10-29 18:33:32 -0700430 controllerStr,len( deviceData ),mnSwitches ) )
431 else:
432 currentDevicesResult = main.FALSE
433 if not currentDevicesResult:
434 deviceFails.append( controllerStr )
435 devicesResults = devicesResults and currentDevicesResult
436 # Compare Links
437 if links[ controller ] and "Error" not in links[ controller ]:
438 try:
439 linkData = json.loads( links[ controller ] )
440 except (TypeError,ValueError):
441 main.log.error("Could not load json:" + str( links[ controller ] ) )
442 currentLinksResult = main.FALSE
443 else:
444 if mnLinks == len( linkData ):
445 currentLinksResult = main.TRUE
446 else:
447 currentLinksResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700448 main.log.error( "Node {} only sees {} link(s) but {} exist".format(
acsmars51a7fe02015-10-29 18:33:32 -0700449 controllerStr,len( linkData ),mnLinks ) )
450 else:
451 currentLinksResult = main.FALSE
452 if not currentLinksResult:
453 linkFails.append( controllerStr )
454 linksResults = linksResults and currentLinksResult
455 # Compare Hosts
456 if hosts[ controller ] and "Error" not in hosts[ controller ]:
457 try:
458 hostData = json.loads( hosts[ controller ] )
459 except (TypeError,ValueError):
460 main.log.error("Could not load json:" + str( hosts[ controller ] ) )
461 currentHostsResult = main.FALSE
462 else:
463 if mnHosts == len( hostData ):
464 currentHostsResult = main.TRUE
465 else:
466 currentHostsResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700467 main.log.error( "Node {} only sees {} host(s) but {} exist".format(
acsmars51a7fe02015-10-29 18:33:32 -0700468 controllerStr,len( hostData ),mnHosts ) )
469 else:
470 currentHostsResult = main.FALSE
471 if not currentHostsResult:
472 hostFails.append( controllerStr )
473 hostsResults = hostsResults and currentHostsResult
474 # Decrement Attempts Remaining
475 attempts -= 1
476
477 utilities.assert_equals( expect=[],
478 actual=deviceFails,
479 onpass="ONOS correctly discovered all devices",
480 onfail="ONOS incorrectly discovered devices on nodes: " +
481 str( deviceFails ) )
482 utilities.assert_equals( expect=[],
483 actual=linkFails,
484 onpass="ONOS correctly discovered all links",
485 onfail="ONOS incorrectly discovered links on nodes: " +
486 str( linkFails ) )
487 utilities.assert_equals( expect=[],
488 actual=hostFails,
489 onpass="ONOS correctly discovered all hosts",
490 onfail="ONOS incorrectly discovered hosts on nodes: " +
491 str( hostFails ) )
492 if hostsResults and linksResults and devicesResults:
493 topoResults = main.TRUE
494 else:
495 topoResults = main.FALSE
496 utilities.assert_equals( expect=main.TRUE,
497 actual=topoResults,
498 onpass="ONOS correctly discovered the topology",
499 onfail="ONOS incorrectly discovered the topology" )
500
501
502 def CASE31( self, main ):
503 import time
504 """
505 Add bidirectional point intents between 2 packet layer( mininet )
506 devices and ping mininet hosts
507 """
508 main.log.report(
509 "This testcase adds bidirectional point intents between 2 " +
510 "packet layer( mininet ) devices and ping mininet hosts" )
511 main.case( "Install point intents between 2 packet layer device and " +
512 "ping the hosts" )
513 main.caseExplanation = "This testcase adds bidirectional point intents between 2 " +\
514 "packet layer( mininet ) devices and ping mininet hosts"
515
516 main.step( "Adding point intents" )
517 checkFlowResult = main.TRUE
518 main.pIntentsId = []
519 pIntent1 = main.CLIs[ 0 ].addPointIntent(
520 "of:0000ffffffff0001/1",
521 "of:0000ffffffff0005/1" )
522 time.sleep( 10 )
523 pIntent2 = main.CLIs[ 0 ].addPointIntent(
524 "of:0000ffffffff0005/1",
525 "of:0000ffffffff0001/1" )
526 main.pIntentsId.append( pIntent1 )
527 main.pIntentsId.append( pIntent2 )
528 time.sleep( 10 )
529 main.log.info( "Checking intents state")
530 checkStateResult = main.CLIs[ 0 ].checkIntentState(
531 intentsId = main.pIntentsId )
532 time.sleep( 10 )
533 main.log.info( "Checking flows state")
534 checkFlowResult = main.CLIs[ 0 ].checkFlowsState()
535 # Sleep for 10 seconds to provide time for the intent state to change
536 time.sleep( 10 )
537 main.log.info( "Checking intents state one more time")
538 checkStateResult = main.CLIs[ 0 ].checkIntentState(
539 intentsId = main.pIntentsId )
Jeremye4bc7132016-03-30 14:04:01 -0700540
acsmars51a7fe02015-10-29 18:33:32 -0700541 if checkStateResult and checkFlowResult:
542 addIntentsResult = main.TRUE
543 else:
544 addIntentsResult = main.FALSE
545 utilities.assert_equals(
546 expect=main.TRUE,
547 actual=addIntentsResult,
548 onpass="Successfully added point intents",
549 onfail="Failed to add point intents")
550
551 if not addIntentsResult:
552 main.log.error( "Intents were not properly installed. Exiting case." )
553 main.skipCase()
554
555 main.step( "Ping h1 and h5" )
556 pingResult = main.LincOE.pingHostOptical( src="h1", target="h5" )
557 utilities.assert_equals(
558 expect=main.TRUE,
559 actual=pingResult,
560 onpass="Successfully pinged h1 and h5",
561 onfail="Failed to ping between h1 and h5")
562
563 def CASE32( self ):
564 """
565 Add host intents between 2 packet layer host
566 """
567 import time
568 import json
569 main.log.report( "Adding host intents between 2 optical layer host" )
570 main.case( "Test add host intents between optical layer host" )
571 main.caseExplanation = "Test host intents between 2 optical layer host"
572
573 main.step( "Adding host intents to h1 and h2" )
574 hostMACs = []
575 hostId = []
576 # Listing host MAC addresses
577 for i in range( 1 , 7 ):
578 hostMACs.append( "00:00:00:00:00:" +
579 str( hex( i )[ 2: ] ).zfill( 2 ).upper() )
580 for macs in hostMACs:
581 hostId.append( macs + "/-1" )
582 host1 = hostId[ 0 ]
583 host2 = hostId[ 1 ]
584
585 intentsId = []
586 intent1 = main.CLIs[ 0 ].addHostIntent( hostIdOne = host1,
587 hostIdTwo = host2 )
588 intentsId.append( intent1 )
589 # Checking intents state before pinging
590 main.log.info( "Checking intents state" )
591 intentResult = main.CLIs[ 0 ].checkIntentState( intentsId = intentsId )
592 # Check intent state again if intents are not in installed state
Jeremye4bc7132016-03-30 14:04:01 -0700593
acsmars51a7fe02015-10-29 18:33:32 -0700594
595 # If intent state is wrong, wait 3 sec and try again
596 if not intentResult:
597 time.sleep( 3 )
598 intentResult = main.CLIs[ 0 ].checkIntentState( intentsId = intentsId )
599
600 # If intent state is still wrong, display intent states
601 if not intentResult:
602 main.log.error( main.CLIs[ 0 ].intents() )
Jeremye4bc7132016-03-30 14:04:01 -0700603
acsmars51a7fe02015-10-29 18:33:32 -0700604 utilities.assert_equals( expect=main.TRUE,
605 actual=intentResult,
606 onpass="All intents are in INSTALLED state ",
607 onfail="Some of the intents are not in " +
608 "INSTALLED state " )
609
610 if not intentResult:
611 main.log.error( "Intents were not properly installed. Skipping Ping" )
612 else:
613 # Pinging h1 to h2 and then ping h2 to h1
614 main.step( "Pinging h1 and h2" )
615 pingResult = main.TRUE
616 pingResult = main.LincOE.pingHostOptical( src="h1", target="h2" ) \
617 and main.LincOE.pingHostOptical( src="h2",target="h1" )
Jeremye4bc7132016-03-30 14:04:01 -0700618
acsmars51a7fe02015-10-29 18:33:32 -0700619 utilities.assert_equals( expect=main.TRUE,
620 actual=pingResult,
621 onpass="Pinged successfully between h1 and h2",
622 onfail="Pinged failed between h1 and h2" )
623
624 # Removed all added host intents
625 main.step( "Removing host intents" )
626 removeResult = main.TRUE
627 # Check remaining intents
Jeremy7134f5b2016-04-05 13:50:21 -0700628 try:
629 intentsJson = json.loads( main.CLIs[ 0 ].intents() )
630 main.CLIs[ 0 ].removeIntent( intentId=intent1, purge=True )
631 #main.CLIs[ 0 ].removeIntent( intentId=intent2, purge=True )
632 main.log.debug(intentsJson)
633 for intents in intentsJson:
Jeremye4bc7132016-03-30 14:04:01 -0700634 main.CLIs[ 0 ].removeIntent( intentId=intents.get( 'id' ),
635 app='org.onosproject.optical',
636 purge=True )
acsmars51a7fe02015-10-29 18:33:32 -0700637
Jeremy7134f5b2016-04-05 13:50:21 -0700638 for i in range( main.numCtrls ):
639 if len( json.loads( main.CLIs[ i ].intents() ) ):
640 print json.loads( main.CLIs[ i ].intents() )
641 removeResult = main.FALSE
642 except ( TypeError, ValueError ):
643 main.log.error( "Cannot see intents on Node " + str( main.CLIs[ 0 ] ) +\
644 ". Removing all intents.")
645 main.CLIs[ 0 ].removeAllIntents( purge=True )
646 main.CLIs[ 0 ].removeAllIntents( purge=True, app='org.onosproject.optical')
647
648 utilities.assert_equals( expect=main.TRUE,
649 actual=removeResult,
650 onpass="Successfully removed host intents",
651 onfail="Failed to remove host intents" )