blob: 9d800a779bee999cf314ed88fd78503bd718129e [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" )
81 topoResult = main.ONOSbench.onosNetCfg( controllerIps=main.activeONOSip, path=main.dependencyPath,
82 fileName="TopoDDriver" )
83 #Exit if topology did not load properly
84 if not topoResult:
85 main.cleanup()
86 main.exit()
87
acsmars51a7fe02015-10-29 18:33:32 -070088 main.caseExplanation = "Start opticalTest.py topology included with ONOS"
89 main.step( "Starting mininet and LINC-OE" )
acsmars51a7fe02015-10-29 18:33:32 -070090 time.sleep( 10 )
Devin Lim752dd7b2017-06-27 14:40:03 -070091 controllerIPs = ','.join( main.activeONOSip )
92 cIps = ""
Devin Lim58046fa2017-07-05 16:55:00 -070093 for i in range( 0, 4 ):
Devin Lim752dd7b2017-06-27 14:40:03 -070094 cIps += controllerIPs + ' '
95 opticalMnScript = main.LincOE.runOpticalMnScript( ctrllerIP=cIps, topology=main.opticalTopo )
acsmars51a7fe02015-10-29 18:33:32 -070096 topoResult = opticalMnScript
97 utilities.assert_equals(
98 expect=main.TRUE,
99 actual=topoResult,
100 onpass="Started the topology successfully ",
Jon Halle02505a2017-05-24 16:36:43 -0700101 onfail="Failed to start the topology" )
acsmars51a7fe02015-10-29 18:33:32 -0700102
acsmars51a7fe02015-10-29 18:33:32 -0700103 def CASE14( self, main ):
104 """
105 Stop mininet
106 """
Devin Lim58046fa2017-07-05 16:55:00 -0700107 try:
108 from tests.dependencies.utils import Utils
109 except ImportError:
110 main.log.error( "Utils not found exiting the test" )
111 main.exit()
112 try:
113 main.Utils
114 except ( NameError, AttributeError ):
115 main.Utils = Utils()
116 main.Utils.mininetCleanIntro()
117 topoResult = main.Utils.mininetCleanup( main.LincOE, timeout=180 )
acsmars51a7fe02015-10-29 18:33:32 -0700118 # Exit if topology did not load properly
119 if not topoResult:
120 main.cleanup()
121 main.exit()
122
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700123 def CASE16( self, main ):
124 """
125 Balance Masters
126 """
127 main.case( "Balance mastership of switches" )
128 main.step( "Balancing mastership of switches" )
129
130 balanceResult = main.FALSE
131 balanceResult = utilities.retry( f=main.CLIs[ 0 ].balanceMasters, retValue=main.FALSE, args=[] )
132
133 utilities.assert_equals( expect=main.TRUE,
134 actual=balanceResult,
135 onpass="Successfully balanced mastership of switches",
136 onfail="Failed to balance mastership of switches" )
137 if not balanceResult:
138 main.initialized = main.FALSE
139
Jeremye4bc7132016-03-30 14:04:01 -0700140 def CASE17( self, main ):
141 """
142 Use Flow Objectives
143 """
144 main.case( "Enable intent compilation using Flow Objectives" )
145 main.step( "Enabling Flow Objectives" )
146
147 main.flowCompiler = "Flow Objectives"
148
149 cmd = "org.onosproject.net.intent.impl.compiler.IntentConfigurableRegistrator"
150
151 stepResult = main.CLIs[ 0 ].setCfg( component=cmd,
152 propName="useFlowObjectives", value="true" )
You Wang106d0fa2017-05-15 17:22:15 -0700153 stepResult &= main.CLIs[ 0 ].setCfg( component=cmd,
154 propName="defaultFlowObjectiveCompiler",
Jon Halle02505a2017-05-24 16:36:43 -0700155 value='org.onosproject.net.intent.impl.compiler.LinkCollectionIntentObjectiveCompiler' )
Jeremye4bc7132016-03-30 14:04:01 -0700156
157 utilities.assert_equals( expect=main.TRUE,
158 actual=stepResult,
159 onpass="Successfully activated Flow Objectives",
160 onfail="Failed to activate Flow Objectives" )
161
Jeremy Songster17147f22016-05-31 18:30:52 -0700162 def CASE19( self, main ):
163 """
164 Copy the karaf.log files after each testcase cycle
165 """
Devin Lim58046fa2017-07-05 16:55:00 -0700166 try:
167 from tests.dependencies.utils import Utils
168 except ImportError:
169 main.log.error( "Utils not found exiting the test" )
170 main.exit()
171 try:
172 main.Utils
173 except ( NameError, AttributeError ):
174 main.Utils = Utils()
175 main.Utils.copyKarafLog()
Jon Halle02505a2017-05-24 16:36:43 -0700176 def CASE21( self, main ):
acsmars51a7fe02015-10-29 18:33:32 -0700177 """
178 Run pingall to discover all hosts
179 """
180 main.case( "Running Pingall" )
181 main.caseExplanation = "Use pingall to discover all hosts. Pingall is expected to fail."
182 main.step( "Discover Hosts through Pingall" )
Jon Halle02505a2017-05-24 16:36:43 -0700183 pingResult = main.LincOE.pingall( timeout=120 )
acsmars51a7fe02015-10-29 18:33:32 -0700184
185 utilities.assert_equals( expect=main.FALSE,
186 actual=pingResult,
187 onpass="Pingall Completed",
188 onfail="Pingall did not complete or did not return fales" )
189
Jon Halle02505a2017-05-24 16:36:43 -0700190 def CASE22( self, main ):
acsmars51a7fe02015-10-29 18:33:32 -0700191 """
192 Send arpings to discover all hosts
193 """
194 main.case( "Discover Hosts with arping" )
195 main.caseExplanation = "Send arpings between all the hosts to discover and verify them"
196
197 main.step( "Send arping between all hosts" )
198
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700199 hosts = []
200 for i in range( main.hosts ):
201 hosts.append( 'h{}'.format( i + 1 ) )
acsmars51a7fe02015-10-29 18:33:32 -0700202
203 arpingHostResults = main.TRUE
204 for host in hosts:
Devin Lim752dd7b2017-06-27 14:40:03 -0700205 if main.LincOE.arping( host, ethDevice=host+"-eth0" ):
acsmars51a7fe02015-10-29 18:33:32 -0700206 main.log.info( "Successfully reached host {} with arping".format( host ) )
207 else:
208 main.log.error( "Could not reach host {} with arping".format( host ) )
209 arpingHostResults = main.FALSE
210
211 utilities.assert_equals( expect=main.TRUE,
212 actual=arpingHostResults,
213 onpass="Successfully discovered all hosts",
214 onfail="Could not descover some hosts" )
215
216 def CASE23( self, main ):
217 """
218 Compare ONOS Topology to Mininet Topology
219 """
220 import json
Devin Lim58046fa2017-07-05 16:55:00 -0700221 try:
222 from tests.dependencies.topology import Topology
223 except ImportError:
224 main.log.error( "Topology not found exiting the test" )
225 main.exit()
226 try:
227 main.topoRelated
228 except ( NameError, AttributeError ):
229 main.topoRelated = Topology()
acsmars51a7fe02015-10-29 18:33:32 -0700230 main.case( "Compare ONOS Topology view to Mininet topology" )
231 main.caseExplanation = "Compare topology elements between Mininet" +\
232 " and ONOS"
233
234 main.log.info( "Gathering topology information from Mininet" )
235 devicesResults = main.FALSE # Overall Boolean for device correctness
236 linksResults = main.FALSE # Overall Boolean for link correctness
237 hostsResults = main.FALSE # Overall Boolean for host correctness
238 deviceFails = [] # Nodes where devices are incorrect
239 linkFails = [] # Nodes where links are incorrect
240 hostFails = [] # Nodes where hosts are incorrect
241 attempts = main.checkTopoAttempts # Remaining Attempts
242
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700243 mnSwitches = main.switches
244 mnLinks = main.links
245 mnHosts = main.hosts
acsmars51a7fe02015-10-29 18:33:32 -0700246
Jon Hall70b2ff42015-11-17 15:49:44 -0800247 main.step( "Comparing Mininet topology to ONOS topology" )
acsmars51a7fe02015-10-29 18:33:32 -0700248
249 while ( attempts >= 0 ) and\
Jon Halle02505a2017-05-24 16:36:43 -0700250 ( not devicesResults or not linksResults or not hostsResults ):
acsmars51a7fe02015-10-29 18:33:32 -0700251 time.sleep( 2 )
252 if not devicesResults:
Devin Lim58046fa2017-07-05 16:55:00 -0700253 devices = main.topoRelated.getAllDevices( main.numCtrls, False )
254 ports = main.topoRelated.getAllPorts( main.numCtrls, False )
acsmars51a7fe02015-10-29 18:33:32 -0700255 devicesResults = main.TRUE
256 deviceFails = [] # Reset for each attempt
257 if not linksResults:
Devin Lim58046fa2017-07-05 16:55:00 -0700258 links = main.topoRelated.getAllLinks( main.numCtrls, False )
acsmars51a7fe02015-10-29 18:33:32 -0700259 linksResults = main.TRUE
260 linkFails = [] # Reset for each attempt
261 if not hostsResults:
Devin Lim58046fa2017-07-05 16:55:00 -0700262 hosts = main.topoRelated.getAllHosts( main.numCtrls, False )
acsmars51a7fe02015-10-29 18:33:32 -0700263 hostsResults = main.TRUE
264 hostFails = [] # Reset for each attempt
265
266 # Check for matching topology on each node
267 for controller in range( main.numCtrls ):
268 controllerStr = str( controller + 1 ) # ONOS node number
269 # Compare Devices
270 if devices[ controller ] and ports[ controller ] and\
Jon Halle02505a2017-05-24 16:36:43 -0700271 "Error" not in devices[ controller ] and\
272 "Error" not in ports[ controller ]:
acsmars51a7fe02015-10-29 18:33:32 -0700273
274 try:
275 deviceData = json.loads( devices[ controller ] )
276 portData = json.loads( ports[ controller ] )
Jon Halle02505a2017-05-24 16:36:43 -0700277 except ( TypeError, ValueError ):
278 main.log.error( "Could not load json:" + str( devices[ controller ] ) + ' or ' + str( ports[ controller ] ) )
acsmars51a7fe02015-10-29 18:33:32 -0700279 currentDevicesResult = main.FALSE
280 else:
281 if mnSwitches == len( deviceData ):
282 currentDevicesResult = main.TRUE
283 else:
284 currentDevicesResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700285 main.log.error( "Node {} only sees {} device(s) but {} exist".format(
Jon Halle02505a2017-05-24 16:36:43 -0700286 controllerStr, len( deviceData ), mnSwitches ) )
acsmars51a7fe02015-10-29 18:33:32 -0700287 else:
288 currentDevicesResult = main.FALSE
289 if not currentDevicesResult:
290 deviceFails.append( controllerStr )
291 devicesResults = devicesResults and currentDevicesResult
292 # Compare Links
293 if links[ controller ] and "Error" not in links[ controller ]:
294 try:
295 linkData = json.loads( links[ controller ] )
Jon Halle02505a2017-05-24 16:36:43 -0700296 except ( TypeError, ValueError ):
297 main.log.error( "Could not load json:" + str( links[ controller ] ) )
acsmars51a7fe02015-10-29 18:33:32 -0700298 currentLinksResult = main.FALSE
299 else:
300 if mnLinks == len( linkData ):
301 currentLinksResult = main.TRUE
302 else:
303 currentLinksResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700304 main.log.error( "Node {} only sees {} link(s) but {} exist".format(
Jon Halle02505a2017-05-24 16:36:43 -0700305 controllerStr, len( linkData ), mnLinks ) )
acsmars51a7fe02015-10-29 18:33:32 -0700306 else:
307 currentLinksResult = main.FALSE
308 if not currentLinksResult:
309 linkFails.append( controllerStr )
310 linksResults = linksResults and currentLinksResult
311 # Compare Hosts
312 if hosts[ controller ] and "Error" not in hosts[ controller ]:
313 try:
314 hostData = json.loads( hosts[ controller ] )
Jon Halle02505a2017-05-24 16:36:43 -0700315 except ( TypeError, ValueError ):
316 main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
acsmars51a7fe02015-10-29 18:33:32 -0700317 currentHostsResult = main.FALSE
318 else:
319 if mnHosts == len( hostData ):
320 currentHostsResult = main.TRUE
321 else:
322 currentHostsResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700323 main.log.error( "Node {} only sees {} host(s) but {} exist".format(
Jon Halle02505a2017-05-24 16:36:43 -0700324 controllerStr, len( hostData ), mnHosts ) )
acsmars51a7fe02015-10-29 18:33:32 -0700325 else:
326 currentHostsResult = main.FALSE
327 if not currentHostsResult:
328 hostFails.append( controllerStr )
329 hostsResults = hostsResults and currentHostsResult
330 # Decrement Attempts Remaining
331 attempts -= 1
332
333 utilities.assert_equals( expect=[],
334 actual=deviceFails,
335 onpass="ONOS correctly discovered all devices",
336 onfail="ONOS incorrectly discovered devices on nodes: " +
337 str( deviceFails ) )
338 utilities.assert_equals( expect=[],
339 actual=linkFails,
340 onpass="ONOS correctly discovered all links",
341 onfail="ONOS incorrectly discovered links on nodes: " +
342 str( linkFails ) )
343 utilities.assert_equals( expect=[],
344 actual=hostFails,
345 onpass="ONOS correctly discovered all hosts",
346 onfail="ONOS incorrectly discovered hosts on nodes: " +
347 str( hostFails ) )
348 if hostsResults and linksResults and devicesResults:
349 topoResults = main.TRUE
350 else:
351 topoResults = main.FALSE
352 utilities.assert_equals( expect=main.TRUE,
353 actual=topoResults,
354 onpass="ONOS correctly discovered the topology",
355 onfail="ONOS incorrectly discovered the topology" )
356
Devin Lim58046fa2017-07-05 16:55:00 -0700357
acsmars51a7fe02015-10-29 18:33:32 -0700358 def CASE31( self, main ):
359 import time
360 """
361 Add bidirectional point intents between 2 packet layer( mininet )
362 devices and ping mininet hosts
363 """
364 main.log.report(
365 "This testcase adds bidirectional point intents between 2 " +
366 "packet layer( mininet ) devices and ping mininet hosts" )
367 main.case( "Install point intents between 2 packet layer device and " +
368 "ping the hosts" )
369 main.caseExplanation = "This testcase adds bidirectional point intents between 2 " +\
370 "packet layer( mininet ) devices and ping mininet hosts"
371
372 main.step( "Adding point intents" )
373 checkFlowResult = main.TRUE
374 main.pIntentsId = []
375 pIntent1 = main.CLIs[ 0 ].addPointIntent(
Devin Lim752dd7b2017-06-27 14:40:03 -0700376 "of:0000000000000015/1",
377 "of:000000000000000b/2" )
acsmars51a7fe02015-10-29 18:33:32 -0700378 time.sleep( 10 )
379 pIntent2 = main.CLIs[ 0 ].addPointIntent(
Devin Lim752dd7b2017-06-27 14:40:03 -0700380 "of:000000000000000b/2",
381 "of:0000000000000015/1" )
acsmars51a7fe02015-10-29 18:33:32 -0700382 main.pIntentsId.append( pIntent1 )
383 main.pIntentsId.append( pIntent2 )
384 time.sleep( 10 )
Jon Halle02505a2017-05-24 16:36:43 -0700385 main.log.info( "Checking intents state" )
acsmars51a7fe02015-10-29 18:33:32 -0700386 checkStateResult = main.CLIs[ 0 ].checkIntentState(
Jon Halle02505a2017-05-24 16:36:43 -0700387 intentsId=main.pIntentsId )
acsmars51a7fe02015-10-29 18:33:32 -0700388 time.sleep( 10 )
Devin Lim752dd7b2017-06-27 14:40:03 -0700389 checkStateResult = utilities.retry( f=main.CLIs[0].checkIntentState,
390 retValue=main.FALSE, args=( main.pIntentsId, "INSTALLED" ),
391 sleep=main.checkIntentSleep, attempts=10 )
Jon Halle02505a2017-05-24 16:36:43 -0700392 main.log.info( "Checking flows state" )
acsmars51a7fe02015-10-29 18:33:32 -0700393 checkFlowResult = main.CLIs[ 0 ].checkFlowsState()
394 # Sleep for 10 seconds to provide time for the intent state to change
395 time.sleep( 10 )
Jon Halle02505a2017-05-24 16:36:43 -0700396 main.log.info( "Checking intents state one more time" )
acsmars51a7fe02015-10-29 18:33:32 -0700397 checkStateResult = main.CLIs[ 0 ].checkIntentState(
Jon Halle02505a2017-05-24 16:36:43 -0700398 intentsId=main.pIntentsId )
Jeremye4bc7132016-03-30 14:04:01 -0700399
acsmars51a7fe02015-10-29 18:33:32 -0700400 if checkStateResult and checkFlowResult:
401 addIntentsResult = main.TRUE
402 else:
403 addIntentsResult = main.FALSE
404 utilities.assert_equals(
405 expect=main.TRUE,
406 actual=addIntentsResult,
407 onpass="Successfully added point intents",
Jon Halle02505a2017-05-24 16:36:43 -0700408 onfail="Failed to add point intents" )
acsmars51a7fe02015-10-29 18:33:32 -0700409
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700410 pingResult = main.FALSE
acsmars51a7fe02015-10-29 18:33:32 -0700411
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700412 if not addIntentsResult:
413 main.log.error( "Intents were not properly installed. Skipping ping." )
414
415 else:
416 main.step( "Ping h1 and h2" )
417 pingResult = main.LincOE.pingHostOptical( src="h1", target="h2" )
acsmars51a7fe02015-10-29 18:33:32 -0700418 utilities.assert_equals(
419 expect=main.TRUE,
420 actual=pingResult,
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700421 onpass="Successfully pinged h1 and h2",
Jon Halle02505a2017-05-24 16:36:43 -0700422 onfail="Failed to ping between h1 and h2" )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700423
424 main.step( "Remove Point to Point intents" )
Devin Lim752dd7b2017-06-27 14:40:03 -0700425 removeResult = main.TRUE
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700426 # Check remaining intents
427 try:
428 intentsJson = json.loads( main.CLIs[ 0 ].intents() )
429 main.log.debug( intentsJson )
430 main.CLIs[ 0 ].removeIntent( intentId=pIntent1, purge=True )
431 main.CLIs[ 0 ].removeIntent( intentId=pIntent2, purge=True )
432 for intents in intentsJson:
433 main.CLIs[ 0 ].removeIntent( intentId=intents.get( 'id' ),
434 app='org.onosproject.cli',
435 purge=True )
436 time.sleep( 15 )
437
438 for i in range( main.numCtrls ):
Devin Lim752dd7b2017-06-27 14:40:03 -0700439 if not any ( intent.get('state') == 'WITHDRAWING' for intent
440 in json.loads( main.CLIs[i].intents() ) ):
441 main.log.debug( json.loads( main.CLIs[i].intents ) )
442 removeResult = main.FALSE
443 break
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700444 else:
445 removeResult = main.TRUE
446 except ( TypeError, ValueError ):
Jon Halle02505a2017-05-24 16:36:43 -0700447 main.log.error( "Cannot see intents on Node " + str( main.CLIs[ 0 ] ) +
448 ". Removing all intents." )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700449 main.CLIs[ 0 ].removeAllIntents( purge=True )
Jon Halle02505a2017-05-24 16:36:43 -0700450 main.CLIs[ 0 ].removeAllIntents( purge=True, app='org.onosproject.cli' )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700451
452 utilities.assert_equals( expect=main.TRUE,
453 actual=removeResult,
454 onpass="Successfully removed host intents",
455 onfail="Failed to remove host intents" )
acsmars51a7fe02015-10-29 18:33:32 -0700456
457 def CASE32( self ):
458 """
459 Add host intents between 2 packet layer host
460 """
461 import time
462 import json
463 main.log.report( "Adding host intents between 2 optical layer host" )
464 main.case( "Test add host intents between optical layer host" )
465 main.caseExplanation = "Test host intents between 2 optical layer host"
466
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700467 main.step( "Creating list of hosts" )
468 hostnum = 0
469 try:
470 hostData = json.loads( hosts[ controller ] )
471 except( TypeError, ValueError ):
Jon Halle02505a2017-05-24 16:36:43 -0700472 main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700473
acsmars51a7fe02015-10-29 18:33:32 -0700474 main.step( "Adding host intents to h1 and h2" )
acsmars51a7fe02015-10-29 18:33:32 -0700475 hostId = []
476 # Listing host MAC addresses
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700477 for host in hostData:
Jon Halle02505a2017-05-24 16:36:43 -0700478 hostId.append( host.get( "id" ) )
acsmars51a7fe02015-10-29 18:33:32 -0700479 host1 = hostId[ 0 ]
480 host2 = hostId[ 1 ]
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700481 main.log.debug( host1 )
482 main.log.debug( host2 )
acsmars51a7fe02015-10-29 18:33:32 -0700483
484 intentsId = []
Jon Halle02505a2017-05-24 16:36:43 -0700485 intent1 = main.CLIs[ 0 ].addHostIntent( hostIdOne=host1,
486 hostIdTwo=host2 )
acsmars51a7fe02015-10-29 18:33:32 -0700487 intentsId.append( intent1 )
488 # Checking intents state before pinging
489 main.log.info( "Checking intents state" )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700490 intentResult = utilities.retry( f=main.CLIs[ 0 ].checkIntentState,
491 retValue=main.FALSE, args=intentsId,
492 sleep=main.checkIntentSleep, attempts=10 )
acsmars51a7fe02015-10-29 18:33:32 -0700493
494 # If intent state is still wrong, display intent states
495 if not intentResult:
496 main.log.error( main.CLIs[ 0 ].intents() )
Jeremye4bc7132016-03-30 14:04:01 -0700497
acsmars51a7fe02015-10-29 18:33:32 -0700498 utilities.assert_equals( expect=main.TRUE,
499 actual=intentResult,
500 onpass="All intents are in INSTALLED state ",
501 onfail="Some of the intents are not in " +
502 "INSTALLED state " )
503
504 if not intentResult:
505 main.log.error( "Intents were not properly installed. Skipping Ping" )
506 else:
507 # Pinging h1 to h2 and then ping h2 to h1
508 main.step( "Pinging h1 and h2" )
509 pingResult = main.TRUE
510 pingResult = main.LincOE.pingHostOptical( src="h1", target="h2" ) \
Jon Halle02505a2017-05-24 16:36:43 -0700511 and main.LincOE.pingHostOptical( src="h2", target="h1" )
Jeremye4bc7132016-03-30 14:04:01 -0700512
acsmars51a7fe02015-10-29 18:33:32 -0700513 utilities.assert_equals( expect=main.TRUE,
514 actual=pingResult,
515 onpass="Pinged successfully between h1 and h2",
516 onfail="Pinged failed between h1 and h2" )
517
518 # Removed all added host intents
519 main.step( "Removing host intents" )
520 removeResult = main.TRUE
521 # Check remaining intents
Jeremy7134f5b2016-04-05 13:50:21 -0700522 try:
523 intentsJson = json.loads( main.CLIs[ 0 ].intents() )
524 main.CLIs[ 0 ].removeIntent( intentId=intent1, purge=True )
525 #main.CLIs[ 0 ].removeIntent( intentId=intent2, purge=True )
Jon Halle02505a2017-05-24 16:36:43 -0700526 main.log.debug( intentsJson )
Jeremy7134f5b2016-04-05 13:50:21 -0700527 for intents in intentsJson:
Jeremye4bc7132016-03-30 14:04:01 -0700528 main.CLIs[ 0 ].removeIntent( intentId=intents.get( 'id' ),
529 app='org.onosproject.optical',
530 purge=True )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700531 time.sleep( 15 )
acsmars51a7fe02015-10-29 18:33:32 -0700532
Jeremy7134f5b2016-04-05 13:50:21 -0700533 for i in range( main.numCtrls ):
Devin Lim752dd7b2017-06-27 14:40:03 -0700534 if not any ( intent.get('state') == 'WITHDRAWING' for intent
535 in json.loads( main.CLIs[i].intents() ) ):
536 main.log.debug( json.loads( main.CLIs[i].intents ) )
537 removeResult = main.FALSE
538 break
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700539 else:
540 removeResult = main.TRUE
Jeremy7134f5b2016-04-05 13:50:21 -0700541 except ( TypeError, ValueError ):
Jon Halle02505a2017-05-24 16:36:43 -0700542 main.log.error( "Cannot see intents on Node " + str( main.CLIs[ 0 ] ) +
543 ". Removing all intents." )
Jeremy7134f5b2016-04-05 13:50:21 -0700544 main.CLIs[ 0 ].removeAllIntents( purge=True )
Jon Halle02505a2017-05-24 16:36:43 -0700545 main.CLIs[ 0 ].removeAllIntents( purge=True, app='org.onosproject.optical' )
Jeremy7134f5b2016-04-05 13:50:21 -0700546
547 utilities.assert_equals( expect=main.TRUE,
548 actual=removeResult,
549 onpass="Successfully removed host intents",
Chiyu Chengef109502016-11-21 15:51:38 -0800550 onfail="Failed to remove host intents" )