blob: 0f09323ddbe61dc7992c8109f6cba8f8bc9017b9 [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 ):
acsmars51a7fe02015-10-29 18:33:32 -070010 import imp
Devin Lim58046fa2017-07-05 16:55:00 -070011 import time
acsmars51a7fe02015-10-29 18:33:32 -070012 import re
acsmars51a7fe02015-10-29 18:33:32 -070013 """
Devin Lim58046fa2017-07-05 16:55:00 -070014 - 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
acsmars51a7fe02015-10-29 18:33:32 -070021 """
Devin Lim58046fa2017-07-05 16:55:00 -070022 try:
23 from tests.dependencies.ONOSSetup import ONOSSetup
24 main.testSetUp = ONOSSetup()
25 except ImportError:
26 main.log.error( "ONOSSetup not found. exiting the test" )
27 main.exit()
28 main.testSetUp.envSetupDescription()
acsmars51a7fe02015-10-29 18:33:32 -070029 stepResult = main.FALSE
acsmars51a7fe02015-10-29 18:33:32 -070030 # Test variables
31 try:
acsmars51a7fe02015-10-29 18:33:32 -070032 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
acsmars51a7fe02015-10-29 18:33:32 -070033 main.dependencyPath = main.testOnDirectory + \
34 main.params[ 'DEPENDENCY' ][ 'path' ]
35 main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," )
acsmars51a7fe02015-10-29 18:33:32 -070036 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
acsmars51a7fe02015-10-29 18:33:32 -070037 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
38 main.checkIntentSleep = int( main.params[ 'SLEEP' ][ 'checkintent' ] )
acsmars51a7fe02015-10-29 18:33:32 -070039 main.checkTopoAttempts = int( main.params[ 'SLEEP' ][ 'topoAttempts' ] )
Jeremy Songster5665f1b2016-06-20 14:38:22 -070040 main.switches = int( main.params[ 'MININET' ][ 'switch' ] )
41 main.links = int( main.params[ 'MININET' ][ 'links' ] )
42 main.hosts = int( main.params[ 'MININET' ][ 'hosts' ] )
43 main.opticalTopo = main.params[ 'MININET' ][ 'toponame' ]
acsmars51a7fe02015-10-29 18:33:32 -070044 main.hostsData = {}
acsmars51a7fe02015-10-29 18:33:32 -070045 main.activeONOSip = []
46 main.assertReturnString = '' # Assembled assert return string
Jon Halle02505a2017-05-24 16:36:43 -070047 main.cycle = 0 # How many times FUNCintent has run through its tests
acsmars51a7fe02015-10-29 18:33:32 -070048
acsmars51a7fe02015-10-29 18:33:32 -070049 # -- INIT SECTION, ONLY RUNS ONCE -- #
Devin Lim58046fa2017-07-05 16:55:00 -070050 stepResult = main.testSetUp.envSetup( True )
acsmars51a7fe02015-10-29 18:33:32 -070051 except Exception as e:
Devin Lim58046fa2017-07-05 16:55:00 -070052 main.testSetUp.envSetupException( e )
53 main.testSetUp.evnSetupConclusion( stepResult )
acsmars51a7fe02015-10-29 18:33:32 -070054
55 def CASE2( self, main ):
56 """
Devin Lim58046fa2017-07-05 16:55:00 -070057 - Set up cell
58 - Create cell file
59 - Set cell file
60 - Verify cell file
61 - Kill ONOS process
62 - Uninstall ONOS cluster
63 - Verify ONOS start up
64 - Install ONOS cluster
65 - Connect to cli
acsmars51a7fe02015-10-29 18:33:32 -070066 """
Jeremye4bc7132016-03-30 14:04:01 -070067 main.flowCompiler = "Flow Rules"
Devin Lim58046fa2017-07-05 16:55:00 -070068 main.testSetUp.ONOSSetUp( main.LincOE, True )
acsmars51a7fe02015-10-29 18:33:32 -070069
acsmars51a7fe02015-10-29 18:33:32 -070070 def CASE10( self, main ):
71 """
72 Start Mininet opticalTest Topology
73 """
Devin Lim58046fa2017-07-05 16:55:00 -070074 del main.activeONOSip[:]
75 for i in range( main.numCtrls ):
76 # Populate activeONOSip
77 main.activeONOSip.append( main.ONOSip[ i ] )
78
Jon Halle02505a2017-05-24 16:36:43 -070079 main.case( "Mininet with Linc-OE startup" )
Devin Lim752dd7b2017-06-27 14:40:03 -070080 main.step( "Push TopoDDriver.json to ONOS through onos-netcfg" )
Devin Lim02075272017-07-10 15:33:21 -070081 topoResult = True
82 for ip in main.activeONOSip:
83 topoResult = topoResult and \
84 main.ONOSbench.onosNetCfg(controllerIp=ip, path=main.dependencyPath,
85 fileName="TopoDDriver.json")
86
Devin Lim752dd7b2017-06-27 14:40:03 -070087 #Exit if topology did not load properly
88 if not topoResult:
89 main.cleanup()
90 main.exit()
91
acsmars51a7fe02015-10-29 18:33:32 -070092 main.caseExplanation = "Start opticalTest.py topology included with ONOS"
93 main.step( "Starting mininet and LINC-OE" )
acsmars51a7fe02015-10-29 18:33:32 -070094 time.sleep( 10 )
Devin Lim752dd7b2017-06-27 14:40:03 -070095 controllerIPs = ','.join( main.activeONOSip )
96 cIps = ""
Devin Lim58046fa2017-07-05 16:55:00 -070097 for i in range( 0, 4 ):
Devin Lim752dd7b2017-06-27 14:40:03 -070098 cIps += controllerIPs + ' '
99 opticalMnScript = main.LincOE.runOpticalMnScript( ctrllerIP=cIps, topology=main.opticalTopo )
acsmars51a7fe02015-10-29 18:33:32 -0700100 topoResult = opticalMnScript
101 utilities.assert_equals(
102 expect=main.TRUE,
103 actual=topoResult,
104 onpass="Started the topology successfully ",
Jon Halle02505a2017-05-24 16:36:43 -0700105 onfail="Failed to start the topology" )
acsmars51a7fe02015-10-29 18:33:32 -0700106
acsmars51a7fe02015-10-29 18:33:32 -0700107 def CASE14( self, main ):
108 """
109 Stop mininet
110 """
Devin Lim58046fa2017-07-05 16:55:00 -0700111 try:
112 from tests.dependencies.utils import Utils
113 except ImportError:
114 main.log.error( "Utils not found exiting the test" )
115 main.exit()
116 try:
117 main.Utils
118 except ( NameError, AttributeError ):
119 main.Utils = Utils()
120 main.Utils.mininetCleanIntro()
121 topoResult = main.Utils.mininetCleanup( main.LincOE, timeout=180 )
acsmars51a7fe02015-10-29 18:33:32 -0700122 # Exit if topology did not load properly
123 if not topoResult:
124 main.cleanup()
125 main.exit()
126
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700127 def CASE16( self, main ):
128 """
129 Balance Masters
130 """
131 main.case( "Balance mastership of switches" )
132 main.step( "Balancing mastership of switches" )
133
134 balanceResult = main.FALSE
135 balanceResult = utilities.retry( f=main.CLIs[ 0 ].balanceMasters, retValue=main.FALSE, args=[] )
136
137 utilities.assert_equals( expect=main.TRUE,
138 actual=balanceResult,
139 onpass="Successfully balanced mastership of switches",
140 onfail="Failed to balance mastership of switches" )
141 if not balanceResult:
142 main.initialized = main.FALSE
143
Jeremye4bc7132016-03-30 14:04:01 -0700144 def CASE17( self, main ):
145 """
146 Use Flow Objectives
147 """
148 main.case( "Enable intent compilation using Flow Objectives" )
149 main.step( "Enabling Flow Objectives" )
150
151 main.flowCompiler = "Flow Objectives"
152
153 cmd = "org.onosproject.net.intent.impl.compiler.IntentConfigurableRegistrator"
154
155 stepResult = main.CLIs[ 0 ].setCfg( component=cmd,
156 propName="useFlowObjectives", value="true" )
You Wang106d0fa2017-05-15 17:22:15 -0700157 stepResult &= main.CLIs[ 0 ].setCfg( component=cmd,
158 propName="defaultFlowObjectiveCompiler",
Jon Halle02505a2017-05-24 16:36:43 -0700159 value='org.onosproject.net.intent.impl.compiler.LinkCollectionIntentObjectiveCompiler' )
Jeremye4bc7132016-03-30 14:04:01 -0700160
161 utilities.assert_equals( expect=main.TRUE,
162 actual=stepResult,
163 onpass="Successfully activated Flow Objectives",
164 onfail="Failed to activate Flow Objectives" )
165
Jeremy Songster17147f22016-05-31 18:30:52 -0700166 def CASE19( self, main ):
167 """
168 Copy the karaf.log files after each testcase cycle
169 """
Devin Lim58046fa2017-07-05 16:55:00 -0700170 try:
171 from tests.dependencies.utils import Utils
172 except ImportError:
173 main.log.error( "Utils not found exiting the test" )
174 main.exit()
175 try:
176 main.Utils
177 except ( NameError, AttributeError ):
178 main.Utils = Utils()
179 main.Utils.copyKarafLog()
Jon Halle02505a2017-05-24 16:36:43 -0700180 def CASE21( self, main ):
acsmars51a7fe02015-10-29 18:33:32 -0700181 """
182 Run pingall to discover all hosts
183 """
184 main.case( "Running Pingall" )
185 main.caseExplanation = "Use pingall to discover all hosts. Pingall is expected to fail."
186 main.step( "Discover Hosts through Pingall" )
Jon Halle02505a2017-05-24 16:36:43 -0700187 pingResult = main.LincOE.pingall( timeout=120 )
acsmars51a7fe02015-10-29 18:33:32 -0700188
189 utilities.assert_equals( expect=main.FALSE,
190 actual=pingResult,
191 onpass="Pingall Completed",
192 onfail="Pingall did not complete or did not return fales" )
193
Jon Halle02505a2017-05-24 16:36:43 -0700194 def CASE22( self, main ):
acsmars51a7fe02015-10-29 18:33:32 -0700195 """
196 Send arpings to discover all hosts
197 """
198 main.case( "Discover Hosts with arping" )
199 main.caseExplanation = "Send arpings between all the hosts to discover and verify them"
200
201 main.step( "Send arping between all hosts" )
202
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700203 hosts = []
204 for i in range( main.hosts ):
205 hosts.append( 'h{}'.format( i + 1 ) )
acsmars51a7fe02015-10-29 18:33:32 -0700206
207 arpingHostResults = main.TRUE
208 for host in hosts:
Devin Lim752dd7b2017-06-27 14:40:03 -0700209 if main.LincOE.arping( host, ethDevice=host+"-eth0" ):
acsmars51a7fe02015-10-29 18:33:32 -0700210 main.log.info( "Successfully reached host {} with arping".format( host ) )
211 else:
212 main.log.error( "Could not reach host {} with arping".format( host ) )
213 arpingHostResults = main.FALSE
214
215 utilities.assert_equals( expect=main.TRUE,
216 actual=arpingHostResults,
217 onpass="Successfully discovered all hosts",
218 onfail="Could not descover some hosts" )
219
220 def CASE23( self, main ):
221 """
222 Compare ONOS Topology to Mininet Topology
223 """
224 import json
Devin Lim58046fa2017-07-05 16:55:00 -0700225 try:
226 from tests.dependencies.topology import Topology
227 except ImportError:
228 main.log.error( "Topology not found exiting the test" )
229 main.exit()
230 try:
231 main.topoRelated
232 except ( NameError, AttributeError ):
233 main.topoRelated = Topology()
acsmars51a7fe02015-10-29 18:33:32 -0700234 main.case( "Compare ONOS Topology view to Mininet topology" )
235 main.caseExplanation = "Compare topology elements between Mininet" +\
236 " and ONOS"
237
238 main.log.info( "Gathering topology information from Mininet" )
239 devicesResults = main.FALSE # Overall Boolean for device correctness
240 linksResults = main.FALSE # Overall Boolean for link correctness
241 hostsResults = main.FALSE # Overall Boolean for host correctness
242 deviceFails = [] # Nodes where devices are incorrect
243 linkFails = [] # Nodes where links are incorrect
244 hostFails = [] # Nodes where hosts are incorrect
245 attempts = main.checkTopoAttempts # Remaining Attempts
246
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700247 mnSwitches = main.switches
248 mnLinks = main.links
249 mnHosts = main.hosts
acsmars51a7fe02015-10-29 18:33:32 -0700250
Jon Hall70b2ff42015-11-17 15:49:44 -0800251 main.step( "Comparing Mininet topology to ONOS topology" )
acsmars51a7fe02015-10-29 18:33:32 -0700252
253 while ( attempts >= 0 ) and\
Jon Halle02505a2017-05-24 16:36:43 -0700254 ( not devicesResults or not linksResults or not hostsResults ):
acsmars51a7fe02015-10-29 18:33:32 -0700255 time.sleep( 2 )
256 if not devicesResults:
Devin Lim58046fa2017-07-05 16:55:00 -0700257 devices = main.topoRelated.getAllDevices( main.numCtrls, False )
258 ports = main.topoRelated.getAllPorts( main.numCtrls, False )
acsmars51a7fe02015-10-29 18:33:32 -0700259 devicesResults = main.TRUE
260 deviceFails = [] # Reset for each attempt
261 if not linksResults:
Devin Lim58046fa2017-07-05 16:55:00 -0700262 links = main.topoRelated.getAllLinks( main.numCtrls, False )
acsmars51a7fe02015-10-29 18:33:32 -0700263 linksResults = main.TRUE
264 linkFails = [] # Reset for each attempt
265 if not hostsResults:
Devin Lim58046fa2017-07-05 16:55:00 -0700266 hosts = main.topoRelated.getAllHosts( main.numCtrls, False )
acsmars51a7fe02015-10-29 18:33:32 -0700267 hostsResults = main.TRUE
268 hostFails = [] # Reset for each attempt
269
270 # Check for matching topology on each node
271 for controller in range( main.numCtrls ):
272 controllerStr = str( controller + 1 ) # ONOS node number
273 # Compare Devices
274 if devices[ controller ] and ports[ controller ] and\
Jon Halle02505a2017-05-24 16:36:43 -0700275 "Error" not in devices[ controller ] and\
276 "Error" not in ports[ controller ]:
acsmars51a7fe02015-10-29 18:33:32 -0700277
278 try:
279 deviceData = json.loads( devices[ controller ] )
280 portData = json.loads( ports[ controller ] )
Jon Halle02505a2017-05-24 16:36:43 -0700281 except ( TypeError, ValueError ):
282 main.log.error( "Could not load json:" + str( devices[ controller ] ) + ' or ' + str( ports[ controller ] ) )
acsmars51a7fe02015-10-29 18:33:32 -0700283 currentDevicesResult = main.FALSE
284 else:
285 if mnSwitches == len( deviceData ):
286 currentDevicesResult = main.TRUE
287 else:
288 currentDevicesResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700289 main.log.error( "Node {} only sees {} device(s) but {} exist".format(
Jon Halle02505a2017-05-24 16:36:43 -0700290 controllerStr, len( deviceData ), mnSwitches ) )
acsmars51a7fe02015-10-29 18:33:32 -0700291 else:
292 currentDevicesResult = main.FALSE
293 if not currentDevicesResult:
294 deviceFails.append( controllerStr )
295 devicesResults = devicesResults and currentDevicesResult
296 # Compare Links
297 if links[ controller ] and "Error" not in links[ controller ]:
298 try:
299 linkData = json.loads( links[ controller ] )
Jon Halle02505a2017-05-24 16:36:43 -0700300 except ( TypeError, ValueError ):
301 main.log.error( "Could not load json:" + str( links[ controller ] ) )
acsmars51a7fe02015-10-29 18:33:32 -0700302 currentLinksResult = main.FALSE
303 else:
304 if mnLinks == len( linkData ):
305 currentLinksResult = main.TRUE
306 else:
307 currentLinksResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700308 main.log.error( "Node {} only sees {} link(s) but {} exist".format(
Jon Halle02505a2017-05-24 16:36:43 -0700309 controllerStr, len( linkData ), mnLinks ) )
acsmars51a7fe02015-10-29 18:33:32 -0700310 else:
311 currentLinksResult = main.FALSE
312 if not currentLinksResult:
313 linkFails.append( controllerStr )
314 linksResults = linksResults and currentLinksResult
315 # Compare Hosts
316 if hosts[ controller ] and "Error" not in hosts[ controller ]:
317 try:
318 hostData = json.loads( hosts[ controller ] )
Jon Halle02505a2017-05-24 16:36:43 -0700319 except ( TypeError, ValueError ):
320 main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
acsmars51a7fe02015-10-29 18:33:32 -0700321 currentHostsResult = main.FALSE
322 else:
323 if mnHosts == len( hostData ):
324 currentHostsResult = main.TRUE
325 else:
326 currentHostsResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700327 main.log.error( "Node {} only sees {} host(s) but {} exist".format(
Jon Halle02505a2017-05-24 16:36:43 -0700328 controllerStr, len( hostData ), mnHosts ) )
acsmars51a7fe02015-10-29 18:33:32 -0700329 else:
330 currentHostsResult = main.FALSE
331 if not currentHostsResult:
332 hostFails.append( controllerStr )
333 hostsResults = hostsResults and currentHostsResult
334 # Decrement Attempts Remaining
335 attempts -= 1
336
337 utilities.assert_equals( expect=[],
338 actual=deviceFails,
339 onpass="ONOS correctly discovered all devices",
340 onfail="ONOS incorrectly discovered devices on nodes: " +
341 str( deviceFails ) )
342 utilities.assert_equals( expect=[],
343 actual=linkFails,
344 onpass="ONOS correctly discovered all links",
345 onfail="ONOS incorrectly discovered links on nodes: " +
346 str( linkFails ) )
347 utilities.assert_equals( expect=[],
348 actual=hostFails,
349 onpass="ONOS correctly discovered all hosts",
350 onfail="ONOS incorrectly discovered hosts on nodes: " +
351 str( hostFails ) )
352 if hostsResults and linksResults and devicesResults:
353 topoResults = main.TRUE
354 else:
355 topoResults = main.FALSE
356 utilities.assert_equals( expect=main.TRUE,
357 actual=topoResults,
358 onpass="ONOS correctly discovered the topology",
359 onfail="ONOS incorrectly discovered the topology" )
360
Devin Lim58046fa2017-07-05 16:55:00 -0700361
acsmars51a7fe02015-10-29 18:33:32 -0700362 def CASE31( self, main ):
363 import time
364 """
365 Add bidirectional point intents between 2 packet layer( mininet )
366 devices and ping mininet hosts
367 """
368 main.log.report(
369 "This testcase adds bidirectional point intents between 2 " +
370 "packet layer( mininet ) devices and ping mininet hosts" )
371 main.case( "Install point intents between 2 packet layer device and " +
372 "ping the hosts" )
373 main.caseExplanation = "This testcase adds bidirectional point intents between 2 " +\
374 "packet layer( mininet ) devices and ping mininet hosts"
375
376 main.step( "Adding point intents" )
377 checkFlowResult = main.TRUE
378 main.pIntentsId = []
379 pIntent1 = main.CLIs[ 0 ].addPointIntent(
Devin Lim752dd7b2017-06-27 14:40:03 -0700380 "of:0000000000000015/1",
381 "of:000000000000000b/2" )
acsmars51a7fe02015-10-29 18:33:32 -0700382 time.sleep( 10 )
383 pIntent2 = main.CLIs[ 0 ].addPointIntent(
Devin Lim752dd7b2017-06-27 14:40:03 -0700384 "of:000000000000000b/2",
385 "of:0000000000000015/1" )
acsmars51a7fe02015-10-29 18:33:32 -0700386 main.pIntentsId.append( pIntent1 )
387 main.pIntentsId.append( pIntent2 )
388 time.sleep( 10 )
Jon Halle02505a2017-05-24 16:36:43 -0700389 main.log.info( "Checking intents state" )
acsmars51a7fe02015-10-29 18:33:32 -0700390 checkStateResult = main.CLIs[ 0 ].checkIntentState(
Jon Halle02505a2017-05-24 16:36:43 -0700391 intentsId=main.pIntentsId )
acsmars51a7fe02015-10-29 18:33:32 -0700392 time.sleep( 10 )
Devin Lim752dd7b2017-06-27 14:40:03 -0700393 checkStateResult = utilities.retry( f=main.CLIs[0].checkIntentState,
394 retValue=main.FALSE, args=( main.pIntentsId, "INSTALLED" ),
395 sleep=main.checkIntentSleep, attempts=10 )
Jon Halle02505a2017-05-24 16:36:43 -0700396 main.log.info( "Checking flows state" )
acsmars51a7fe02015-10-29 18:33:32 -0700397 checkFlowResult = main.CLIs[ 0 ].checkFlowsState()
398 # Sleep for 10 seconds to provide time for the intent state to change
399 time.sleep( 10 )
Jon Halle02505a2017-05-24 16:36:43 -0700400 main.log.info( "Checking intents state one more time" )
acsmars51a7fe02015-10-29 18:33:32 -0700401 checkStateResult = main.CLIs[ 0 ].checkIntentState(
Jon Halle02505a2017-05-24 16:36:43 -0700402 intentsId=main.pIntentsId )
Jeremye4bc7132016-03-30 14:04:01 -0700403
acsmars51a7fe02015-10-29 18:33:32 -0700404 if checkStateResult and checkFlowResult:
405 addIntentsResult = main.TRUE
406 else:
407 addIntentsResult = main.FALSE
408 utilities.assert_equals(
409 expect=main.TRUE,
410 actual=addIntentsResult,
411 onpass="Successfully added point intents",
Jon Halle02505a2017-05-24 16:36:43 -0700412 onfail="Failed to add point intents" )
acsmars51a7fe02015-10-29 18:33:32 -0700413
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700414 pingResult = main.FALSE
acsmars51a7fe02015-10-29 18:33:32 -0700415
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700416 if not addIntentsResult:
417 main.log.error( "Intents were not properly installed. Skipping ping." )
418
419 else:
420 main.step( "Ping h1 and h2" )
421 pingResult = main.LincOE.pingHostOptical( src="h1", target="h2" )
acsmars51a7fe02015-10-29 18:33:32 -0700422 utilities.assert_equals(
423 expect=main.TRUE,
424 actual=pingResult,
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700425 onpass="Successfully pinged h1 and h2",
Jon Halle02505a2017-05-24 16:36:43 -0700426 onfail="Failed to ping between h1 and h2" )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700427
428 main.step( "Remove Point to Point intents" )
Devin Lim752dd7b2017-06-27 14:40:03 -0700429 removeResult = main.TRUE
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700430 # Check remaining intents
431 try:
432 intentsJson = json.loads( main.CLIs[ 0 ].intents() )
433 main.log.debug( intentsJson )
434 main.CLIs[ 0 ].removeIntent( intentId=pIntent1, purge=True )
435 main.CLIs[ 0 ].removeIntent( intentId=pIntent2, purge=True )
436 for intents in intentsJson:
437 main.CLIs[ 0 ].removeIntent( intentId=intents.get( 'id' ),
438 app='org.onosproject.cli',
439 purge=True )
440 time.sleep( 15 )
441
442 for i in range( main.numCtrls ):
Devin Lim752dd7b2017-06-27 14:40:03 -0700443 if not any ( intent.get('state') == 'WITHDRAWING' for intent
444 in json.loads( main.CLIs[i].intents() ) ):
445 main.log.debug( json.loads( main.CLIs[i].intents ) )
446 removeResult = main.FALSE
447 break
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700448 else:
449 removeResult = main.TRUE
450 except ( TypeError, ValueError ):
Jon Halle02505a2017-05-24 16:36:43 -0700451 main.log.error( "Cannot see intents on Node " + str( main.CLIs[ 0 ] ) +
452 ". Removing all intents." )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700453 main.CLIs[ 0 ].removeAllIntents( purge=True )
Jon Halle02505a2017-05-24 16:36:43 -0700454 main.CLIs[ 0 ].removeAllIntents( purge=True, app='org.onosproject.cli' )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700455
456 utilities.assert_equals( expect=main.TRUE,
457 actual=removeResult,
458 onpass="Successfully removed host intents",
459 onfail="Failed to remove host intents" )
acsmars51a7fe02015-10-29 18:33:32 -0700460
461 def CASE32( self ):
462 """
463 Add host intents between 2 packet layer host
464 """
465 import time
466 import json
467 main.log.report( "Adding host intents between 2 optical layer host" )
468 main.case( "Test add host intents between optical layer host" )
469 main.caseExplanation = "Test host intents between 2 optical layer host"
470
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700471 main.step( "Creating list of hosts" )
472 hostnum = 0
473 try:
474 hostData = json.loads( hosts[ controller ] )
475 except( TypeError, ValueError ):
Jon Halle02505a2017-05-24 16:36:43 -0700476 main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700477
acsmars51a7fe02015-10-29 18:33:32 -0700478 main.step( "Adding host intents to h1 and h2" )
acsmars51a7fe02015-10-29 18:33:32 -0700479 hostId = []
480 # Listing host MAC addresses
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700481 for host in hostData:
Jon Halle02505a2017-05-24 16:36:43 -0700482 hostId.append( host.get( "id" ) )
acsmars51a7fe02015-10-29 18:33:32 -0700483 host1 = hostId[ 0 ]
484 host2 = hostId[ 1 ]
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700485 main.log.debug( host1 )
486 main.log.debug( host2 )
acsmars51a7fe02015-10-29 18:33:32 -0700487
488 intentsId = []
Jon Halle02505a2017-05-24 16:36:43 -0700489 intent1 = main.CLIs[ 0 ].addHostIntent( hostIdOne=host1,
490 hostIdTwo=host2 )
acsmars51a7fe02015-10-29 18:33:32 -0700491 intentsId.append( intent1 )
492 # Checking intents state before pinging
493 main.log.info( "Checking intents state" )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700494 intentResult = utilities.retry( f=main.CLIs[ 0 ].checkIntentState,
495 retValue=main.FALSE, args=intentsId,
496 sleep=main.checkIntentSleep, attempts=10 )
acsmars51a7fe02015-10-29 18:33:32 -0700497
498 # If intent state is still wrong, display intent states
499 if not intentResult:
500 main.log.error( main.CLIs[ 0 ].intents() )
Jeremye4bc7132016-03-30 14:04:01 -0700501
acsmars51a7fe02015-10-29 18:33:32 -0700502 utilities.assert_equals( expect=main.TRUE,
503 actual=intentResult,
504 onpass="All intents are in INSTALLED state ",
505 onfail="Some of the intents are not in " +
506 "INSTALLED state " )
507
508 if not intentResult:
509 main.log.error( "Intents were not properly installed. Skipping Ping" )
510 else:
511 # Pinging h1 to h2 and then ping h2 to h1
512 main.step( "Pinging h1 and h2" )
513 pingResult = main.TRUE
514 pingResult = main.LincOE.pingHostOptical( src="h1", target="h2" ) \
Jon Halle02505a2017-05-24 16:36:43 -0700515 and main.LincOE.pingHostOptical( src="h2", target="h1" )
Jeremye4bc7132016-03-30 14:04:01 -0700516
acsmars51a7fe02015-10-29 18:33:32 -0700517 utilities.assert_equals( expect=main.TRUE,
518 actual=pingResult,
519 onpass="Pinged successfully between h1 and h2",
520 onfail="Pinged failed between h1 and h2" )
521
522 # Removed all added host intents
523 main.step( "Removing host intents" )
524 removeResult = main.TRUE
525 # Check remaining intents
Jeremy7134f5b2016-04-05 13:50:21 -0700526 try:
527 intentsJson = json.loads( main.CLIs[ 0 ].intents() )
528 main.CLIs[ 0 ].removeIntent( intentId=intent1, purge=True )
529 #main.CLIs[ 0 ].removeIntent( intentId=intent2, purge=True )
Jon Halle02505a2017-05-24 16:36:43 -0700530 main.log.debug( intentsJson )
Jeremy7134f5b2016-04-05 13:50:21 -0700531 for intents in intentsJson:
Jeremye4bc7132016-03-30 14:04:01 -0700532 main.CLIs[ 0 ].removeIntent( intentId=intents.get( 'id' ),
533 app='org.onosproject.optical',
534 purge=True )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700535 time.sleep( 15 )
acsmars51a7fe02015-10-29 18:33:32 -0700536
Jeremy7134f5b2016-04-05 13:50:21 -0700537 for i in range( main.numCtrls ):
Devin Lim752dd7b2017-06-27 14:40:03 -0700538 if not any ( intent.get('state') == 'WITHDRAWING' for intent
539 in json.loads( main.CLIs[i].intents() ) ):
540 main.log.debug( json.loads( main.CLIs[i].intents ) )
541 removeResult = main.FALSE
542 break
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700543 else:
544 removeResult = main.TRUE
Jeremy7134f5b2016-04-05 13:50:21 -0700545 except ( TypeError, ValueError ):
Jon Halle02505a2017-05-24 16:36:43 -0700546 main.log.error( "Cannot see intents on Node " + str( main.CLIs[ 0 ] ) +
547 ". Removing all intents." )
Jeremy7134f5b2016-04-05 13:50:21 -0700548 main.CLIs[ 0 ].removeAllIntents( purge=True )
Jon Halle02505a2017-05-24 16:36:43 -0700549 main.CLIs[ 0 ].removeAllIntents( purge=True, app='org.onosproject.optical' )
Jeremy7134f5b2016-04-05 13:50:21 -0700550
551 utilities.assert_equals( expect=main.TRUE,
552 actual=removeResult,
553 onpass="Successfully removed host intents",
Chiyu Chengef109502016-11-21 15:51:38 -0800554 onfail="Failed to remove host intents" )