blob: 44c5b51fb0aa27d9345d38c36b83a6840701c448 [file] [log] [blame]
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07001"""
2Copyright 2015 Open Networking Foundation (ONF)
3
4Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
5the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
6or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
7
8 TestON is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
11 (at your option) any later version.
12
13 TestON is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with TestON. If not, see <http://www.gnu.org/licenses/>.
20"""
21
acsmars51a7fe02015-10-29 18:33:32 -070022# Testing the basic intent functionality of ONOS
23
Jon Halle02505a2017-05-24 16:36:43 -070024
acsmars51a7fe02015-10-29 18:33:32 -070025class FUNCoptical:
26
27 def __init__( self ):
28 self.default = ''
29
30 def CASE1( self, main ):
acsmars51a7fe02015-10-29 18:33:32 -070031 import imp
Devin Lim58046fa2017-07-05 16:55:00 -070032 import time
acsmars51a7fe02015-10-29 18:33:32 -070033 import re
acsmars51a7fe02015-10-29 18:33:32 -070034 """
Devin Lim58046fa2017-07-05 16:55:00 -070035 - Construct tests variables
36 - GIT ( optional )
37 - Checkout ONOS master branch
38 - Pull latest ONOS code
39 - Building ONOS ( optional )
40 - Install ONOS package
41 - Build ONOS package
acsmars51a7fe02015-10-29 18:33:32 -070042 """
Devin Lim58046fa2017-07-05 16:55:00 -070043 try:
44 from tests.dependencies.ONOSSetup import ONOSSetup
45 main.testSetUp = ONOSSetup()
46 except ImportError:
47 main.log.error( "ONOSSetup not found. exiting the test" )
48 main.exit()
49 main.testSetUp.envSetupDescription()
acsmars51a7fe02015-10-29 18:33:32 -070050 stepResult = main.FALSE
acsmars51a7fe02015-10-29 18:33:32 -070051 # Test variables
52 try:
acsmars51a7fe02015-10-29 18:33:32 -070053 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
acsmars51a7fe02015-10-29 18:33:32 -070054 main.dependencyPath = main.testOnDirectory + \
55 main.params[ 'DEPENDENCY' ][ 'path' ]
56 main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," )
acsmars51a7fe02015-10-29 18:33:32 -070057 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
acsmars51a7fe02015-10-29 18:33:32 -070058 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
59 main.checkIntentSleep = int( main.params[ 'SLEEP' ][ 'checkintent' ] )
acsmars51a7fe02015-10-29 18:33:32 -070060 main.checkTopoAttempts = int( main.params[ 'SLEEP' ][ 'topoAttempts' ] )
Jeremy Songster5665f1b2016-06-20 14:38:22 -070061 main.switches = int( main.params[ 'MININET' ][ 'switch' ] )
62 main.links = int( main.params[ 'MININET' ][ 'links' ] )
63 main.hosts = int( main.params[ 'MININET' ][ 'hosts' ] )
64 main.opticalTopo = main.params[ 'MININET' ][ 'toponame' ]
acsmars51a7fe02015-10-29 18:33:32 -070065 main.hostsData = {}
acsmars51a7fe02015-10-29 18:33:32 -070066 main.activeONOSip = []
67 main.assertReturnString = '' # Assembled assert return string
Jon Halle02505a2017-05-24 16:36:43 -070068 main.cycle = 0 # How many times FUNCintent has run through its tests
acsmars51a7fe02015-10-29 18:33:32 -070069
acsmars51a7fe02015-10-29 18:33:32 -070070 # -- INIT SECTION, ONLY RUNS ONCE -- #
Devin Lim58046fa2017-07-05 16:55:00 -070071 stepResult = main.testSetUp.envSetup( True )
acsmars51a7fe02015-10-29 18:33:32 -070072 except Exception as e:
Devin Lim58046fa2017-07-05 16:55:00 -070073 main.testSetUp.envSetupException( e )
74 main.testSetUp.evnSetupConclusion( stepResult )
acsmars51a7fe02015-10-29 18:33:32 -070075
76 def CASE2( self, main ):
77 """
Devin Lim58046fa2017-07-05 16:55:00 -070078 - Set up cell
79 - Create cell file
80 - Set cell file
81 - Verify cell file
82 - Kill ONOS process
83 - Uninstall ONOS cluster
84 - Verify ONOS start up
85 - Install ONOS cluster
86 - Connect to cli
acsmars51a7fe02015-10-29 18:33:32 -070087 """
Jeremye4bc7132016-03-30 14:04:01 -070088 main.flowCompiler = "Flow Rules"
Devin Lim58046fa2017-07-05 16:55:00 -070089 main.testSetUp.ONOSSetUp( main.LincOE, True )
acsmars51a7fe02015-10-29 18:33:32 -070090
acsmars51a7fe02015-10-29 18:33:32 -070091 def CASE10( self, main ):
92 """
93 Start Mininet opticalTest Topology
94 """
Devin Lim58046fa2017-07-05 16:55:00 -070095 del main.activeONOSip[:]
96 for i in range( main.numCtrls ):
97 # Populate activeONOSip
98 main.activeONOSip.append( main.ONOSip[ i ] )
99
Jon Halle02505a2017-05-24 16:36:43 -0700100 main.case( "Mininet with Linc-OE startup" )
Devin Lim752dd7b2017-06-27 14:40:03 -0700101 main.step( "Push TopoDDriver.json to ONOS through onos-netcfg" )
Devin Lim02075272017-07-10 15:33:21 -0700102 topoResult = True
103 for ip in main.activeONOSip:
104 topoResult = topoResult and \
105 main.ONOSbench.onosNetCfg(controllerIp=ip, path=main.dependencyPath,
106 fileName="TopoDDriver.json")
107
Devin Lim752dd7b2017-06-27 14:40:03 -0700108 #Exit if topology did not load properly
109 if not topoResult:
110 main.cleanup()
111 main.exit()
112
acsmars51a7fe02015-10-29 18:33:32 -0700113 main.caseExplanation = "Start opticalTest.py topology included with ONOS"
114 main.step( "Starting mininet and LINC-OE" )
acsmars51a7fe02015-10-29 18:33:32 -0700115 time.sleep( 10 )
Devin Lim752dd7b2017-06-27 14:40:03 -0700116 controllerIPs = ','.join( main.activeONOSip )
117 cIps = ""
Devin Lim58046fa2017-07-05 16:55:00 -0700118 for i in range( 0, 4 ):
Devin Lim752dd7b2017-06-27 14:40:03 -0700119 cIps += controllerIPs + ' '
120 opticalMnScript = main.LincOE.runOpticalMnScript( ctrllerIP=cIps, topology=main.opticalTopo )
acsmars51a7fe02015-10-29 18:33:32 -0700121 topoResult = opticalMnScript
122 utilities.assert_equals(
123 expect=main.TRUE,
124 actual=topoResult,
125 onpass="Started the topology successfully ",
Jon Halle02505a2017-05-24 16:36:43 -0700126 onfail="Failed to start the topology" )
acsmars51a7fe02015-10-29 18:33:32 -0700127
acsmars51a7fe02015-10-29 18:33:32 -0700128 def CASE14( self, main ):
129 """
130 Stop mininet
131 """
Devin Lim58046fa2017-07-05 16:55:00 -0700132 try:
133 from tests.dependencies.utils import Utils
134 except ImportError:
135 main.log.error( "Utils not found exiting the test" )
136 main.exit()
137 try:
138 main.Utils
139 except ( NameError, AttributeError ):
140 main.Utils = Utils()
141 main.Utils.mininetCleanIntro()
142 topoResult = main.Utils.mininetCleanup( main.LincOE, timeout=180 )
acsmars51a7fe02015-10-29 18:33:32 -0700143 # Exit if topology did not load properly
144 if not topoResult:
145 main.cleanup()
146 main.exit()
147
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700148 def CASE16( self, main ):
149 """
150 Balance Masters
151 """
152 main.case( "Balance mastership of switches" )
153 main.step( "Balancing mastership of switches" )
154
155 balanceResult = main.FALSE
156 balanceResult = utilities.retry( f=main.CLIs[ 0 ].balanceMasters, retValue=main.FALSE, args=[] )
157
158 utilities.assert_equals( expect=main.TRUE,
159 actual=balanceResult,
160 onpass="Successfully balanced mastership of switches",
161 onfail="Failed to balance mastership of switches" )
162 if not balanceResult:
163 main.initialized = main.FALSE
164
Jeremye4bc7132016-03-30 14:04:01 -0700165 def CASE17( self, main ):
166 """
167 Use Flow Objectives
168 """
169 main.case( "Enable intent compilation using Flow Objectives" )
170 main.step( "Enabling Flow Objectives" )
171
172 main.flowCompiler = "Flow Objectives"
173
174 cmd = "org.onosproject.net.intent.impl.compiler.IntentConfigurableRegistrator"
175
176 stepResult = main.CLIs[ 0 ].setCfg( component=cmd,
177 propName="useFlowObjectives", value="true" )
You Wang106d0fa2017-05-15 17:22:15 -0700178 stepResult &= main.CLIs[ 0 ].setCfg( component=cmd,
179 propName="defaultFlowObjectiveCompiler",
Jon Halle02505a2017-05-24 16:36:43 -0700180 value='org.onosproject.net.intent.impl.compiler.LinkCollectionIntentObjectiveCompiler' )
Jeremye4bc7132016-03-30 14:04:01 -0700181
182 utilities.assert_equals( expect=main.TRUE,
183 actual=stepResult,
184 onpass="Successfully activated Flow Objectives",
185 onfail="Failed to activate Flow Objectives" )
186
Jeremy Songster17147f22016-05-31 18:30:52 -0700187 def CASE19( self, main ):
188 """
189 Copy the karaf.log files after each testcase cycle
190 """
Devin Lim58046fa2017-07-05 16:55:00 -0700191 try:
192 from tests.dependencies.utils import Utils
193 except ImportError:
194 main.log.error( "Utils not found exiting the test" )
195 main.exit()
196 try:
197 main.Utils
198 except ( NameError, AttributeError ):
199 main.Utils = Utils()
200 main.Utils.copyKarafLog()
Jon Halle02505a2017-05-24 16:36:43 -0700201 def CASE21( self, main ):
acsmars51a7fe02015-10-29 18:33:32 -0700202 """
203 Run pingall to discover all hosts
204 """
205 main.case( "Running Pingall" )
206 main.caseExplanation = "Use pingall to discover all hosts. Pingall is expected to fail."
207 main.step( "Discover Hosts through Pingall" )
Jon Halle02505a2017-05-24 16:36:43 -0700208 pingResult = main.LincOE.pingall( timeout=120 )
acsmars51a7fe02015-10-29 18:33:32 -0700209
210 utilities.assert_equals( expect=main.FALSE,
211 actual=pingResult,
212 onpass="Pingall Completed",
213 onfail="Pingall did not complete or did not return fales" )
214
Jon Halle02505a2017-05-24 16:36:43 -0700215 def CASE22( self, main ):
acsmars51a7fe02015-10-29 18:33:32 -0700216 """
217 Send arpings to discover all hosts
218 """
219 main.case( "Discover Hosts with arping" )
220 main.caseExplanation = "Send arpings between all the hosts to discover and verify them"
221
222 main.step( "Send arping between all hosts" )
223
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700224 hosts = []
225 for i in range( main.hosts ):
226 hosts.append( 'h{}'.format( i + 1 ) )
acsmars51a7fe02015-10-29 18:33:32 -0700227
228 arpingHostResults = main.TRUE
229 for host in hosts:
Devin Lim752dd7b2017-06-27 14:40:03 -0700230 if main.LincOE.arping( host, ethDevice=host+"-eth0" ):
acsmars51a7fe02015-10-29 18:33:32 -0700231 main.log.info( "Successfully reached host {} with arping".format( host ) )
232 else:
233 main.log.error( "Could not reach host {} with arping".format( host ) )
234 arpingHostResults = main.FALSE
235
236 utilities.assert_equals( expect=main.TRUE,
237 actual=arpingHostResults,
238 onpass="Successfully discovered all hosts",
239 onfail="Could not descover some hosts" )
240
241 def CASE23( self, main ):
242 """
243 Compare ONOS Topology to Mininet Topology
244 """
245 import json
Devin Lim58046fa2017-07-05 16:55:00 -0700246 try:
247 from tests.dependencies.topology import Topology
248 except ImportError:
249 main.log.error( "Topology not found exiting the test" )
250 main.exit()
251 try:
252 main.topoRelated
253 except ( NameError, AttributeError ):
254 main.topoRelated = Topology()
acsmars51a7fe02015-10-29 18:33:32 -0700255 main.case( "Compare ONOS Topology view to Mininet topology" )
256 main.caseExplanation = "Compare topology elements between Mininet" +\
257 " and ONOS"
258
259 main.log.info( "Gathering topology information from Mininet" )
260 devicesResults = main.FALSE # Overall Boolean for device correctness
261 linksResults = main.FALSE # Overall Boolean for link correctness
262 hostsResults = main.FALSE # Overall Boolean for host correctness
263 deviceFails = [] # Nodes where devices are incorrect
264 linkFails = [] # Nodes where links are incorrect
265 hostFails = [] # Nodes where hosts are incorrect
266 attempts = main.checkTopoAttempts # Remaining Attempts
267
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700268 mnSwitches = main.switches
269 mnLinks = main.links
270 mnHosts = main.hosts
acsmars51a7fe02015-10-29 18:33:32 -0700271
Jon Hall70b2ff42015-11-17 15:49:44 -0800272 main.step( "Comparing Mininet topology to ONOS topology" )
acsmars51a7fe02015-10-29 18:33:32 -0700273
274 while ( attempts >= 0 ) and\
Jon Halle02505a2017-05-24 16:36:43 -0700275 ( not devicesResults or not linksResults or not hostsResults ):
acsmars51a7fe02015-10-29 18:33:32 -0700276 time.sleep( 2 )
277 if not devicesResults:
Devin Lim58046fa2017-07-05 16:55:00 -0700278 devices = main.topoRelated.getAllDevices( main.numCtrls, False )
279 ports = main.topoRelated.getAllPorts( main.numCtrls, False )
acsmars51a7fe02015-10-29 18:33:32 -0700280 devicesResults = main.TRUE
281 deviceFails = [] # Reset for each attempt
282 if not linksResults:
Devin Lim58046fa2017-07-05 16:55:00 -0700283 links = main.topoRelated.getAllLinks( main.numCtrls, False )
acsmars51a7fe02015-10-29 18:33:32 -0700284 linksResults = main.TRUE
285 linkFails = [] # Reset for each attempt
286 if not hostsResults:
Devin Lim58046fa2017-07-05 16:55:00 -0700287 hosts = main.topoRelated.getAllHosts( main.numCtrls, False )
acsmars51a7fe02015-10-29 18:33:32 -0700288 hostsResults = main.TRUE
289 hostFails = [] # Reset for each attempt
290
291 # Check for matching topology on each node
292 for controller in range( main.numCtrls ):
293 controllerStr = str( controller + 1 ) # ONOS node number
294 # Compare Devices
295 if devices[ controller ] and ports[ controller ] and\
Jon Halle02505a2017-05-24 16:36:43 -0700296 "Error" not in devices[ controller ] and\
297 "Error" not in ports[ controller ]:
acsmars51a7fe02015-10-29 18:33:32 -0700298
299 try:
300 deviceData = json.loads( devices[ controller ] )
301 portData = json.loads( ports[ controller ] )
Jon Halle02505a2017-05-24 16:36:43 -0700302 except ( TypeError, ValueError ):
303 main.log.error( "Could not load json:" + str( devices[ controller ] ) + ' or ' + str( ports[ controller ] ) )
acsmars51a7fe02015-10-29 18:33:32 -0700304 currentDevicesResult = main.FALSE
305 else:
306 if mnSwitches == len( deviceData ):
307 currentDevicesResult = main.TRUE
308 else:
309 currentDevicesResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700310 main.log.error( "Node {} only sees {} device(s) but {} exist".format(
Jon Halle02505a2017-05-24 16:36:43 -0700311 controllerStr, len( deviceData ), mnSwitches ) )
acsmars51a7fe02015-10-29 18:33:32 -0700312 else:
313 currentDevicesResult = main.FALSE
314 if not currentDevicesResult:
315 deviceFails.append( controllerStr )
316 devicesResults = devicesResults and currentDevicesResult
317 # Compare Links
318 if links[ controller ] and "Error" not in links[ controller ]:
319 try:
320 linkData = json.loads( links[ controller ] )
Jon Halle02505a2017-05-24 16:36:43 -0700321 except ( TypeError, ValueError ):
322 main.log.error( "Could not load json:" + str( links[ controller ] ) )
acsmars51a7fe02015-10-29 18:33:32 -0700323 currentLinksResult = main.FALSE
324 else:
325 if mnLinks == len( linkData ):
326 currentLinksResult = main.TRUE
327 else:
328 currentLinksResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700329 main.log.error( "Node {} only sees {} link(s) but {} exist".format(
Jon Halle02505a2017-05-24 16:36:43 -0700330 controllerStr, len( linkData ), mnLinks ) )
acsmars51a7fe02015-10-29 18:33:32 -0700331 else:
332 currentLinksResult = main.FALSE
333 if not currentLinksResult:
334 linkFails.append( controllerStr )
335 linksResults = linksResults and currentLinksResult
336 # Compare Hosts
337 if hosts[ controller ] and "Error" not in hosts[ controller ]:
338 try:
339 hostData = json.loads( hosts[ controller ] )
Jon Halle02505a2017-05-24 16:36:43 -0700340 except ( TypeError, ValueError ):
341 main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
acsmars51a7fe02015-10-29 18:33:32 -0700342 currentHostsResult = main.FALSE
343 else:
344 if mnHosts == len( hostData ):
345 currentHostsResult = main.TRUE
346 else:
347 currentHostsResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700348 main.log.error( "Node {} only sees {} host(s) but {} exist".format(
Jon Halle02505a2017-05-24 16:36:43 -0700349 controllerStr, len( hostData ), mnHosts ) )
acsmars51a7fe02015-10-29 18:33:32 -0700350 else:
351 currentHostsResult = main.FALSE
352 if not currentHostsResult:
353 hostFails.append( controllerStr )
354 hostsResults = hostsResults and currentHostsResult
355 # Decrement Attempts Remaining
356 attempts -= 1
357
358 utilities.assert_equals( expect=[],
359 actual=deviceFails,
360 onpass="ONOS correctly discovered all devices",
361 onfail="ONOS incorrectly discovered devices on nodes: " +
362 str( deviceFails ) )
363 utilities.assert_equals( expect=[],
364 actual=linkFails,
365 onpass="ONOS correctly discovered all links",
366 onfail="ONOS incorrectly discovered links on nodes: " +
367 str( linkFails ) )
368 utilities.assert_equals( expect=[],
369 actual=hostFails,
370 onpass="ONOS correctly discovered all hosts",
371 onfail="ONOS incorrectly discovered hosts on nodes: " +
372 str( hostFails ) )
373 if hostsResults and linksResults and devicesResults:
374 topoResults = main.TRUE
375 else:
376 topoResults = main.FALSE
377 utilities.assert_equals( expect=main.TRUE,
378 actual=topoResults,
379 onpass="ONOS correctly discovered the topology",
380 onfail="ONOS incorrectly discovered the topology" )
381
Devin Lim58046fa2017-07-05 16:55:00 -0700382
acsmars51a7fe02015-10-29 18:33:32 -0700383 def CASE31( self, main ):
384 import time
385 """
386 Add bidirectional point intents between 2 packet layer( mininet )
387 devices and ping mininet hosts
388 """
389 main.log.report(
390 "This testcase adds bidirectional point intents between 2 " +
391 "packet layer( mininet ) devices and ping mininet hosts" )
392 main.case( "Install point intents between 2 packet layer device and " +
393 "ping the hosts" )
394 main.caseExplanation = "This testcase adds bidirectional point intents between 2 " +\
395 "packet layer( mininet ) devices and ping mininet hosts"
396
397 main.step( "Adding point intents" )
398 checkFlowResult = main.TRUE
399 main.pIntentsId = []
400 pIntent1 = main.CLIs[ 0 ].addPointIntent(
Devin Lim752dd7b2017-06-27 14:40:03 -0700401 "of:0000000000000015/1",
402 "of:000000000000000b/2" )
acsmars51a7fe02015-10-29 18:33:32 -0700403 time.sleep( 10 )
404 pIntent2 = main.CLIs[ 0 ].addPointIntent(
Devin Lim752dd7b2017-06-27 14:40:03 -0700405 "of:000000000000000b/2",
406 "of:0000000000000015/1" )
acsmars51a7fe02015-10-29 18:33:32 -0700407 main.pIntentsId.append( pIntent1 )
408 main.pIntentsId.append( pIntent2 )
409 time.sleep( 10 )
Jon Halle02505a2017-05-24 16:36:43 -0700410 main.log.info( "Checking intents state" )
acsmars51a7fe02015-10-29 18:33:32 -0700411 checkStateResult = main.CLIs[ 0 ].checkIntentState(
Jon Halle02505a2017-05-24 16:36:43 -0700412 intentsId=main.pIntentsId )
acsmars51a7fe02015-10-29 18:33:32 -0700413 time.sleep( 10 )
Devin Lim752dd7b2017-06-27 14:40:03 -0700414 checkStateResult = utilities.retry( f=main.CLIs[0].checkIntentState,
415 retValue=main.FALSE, args=( main.pIntentsId, "INSTALLED" ),
416 sleep=main.checkIntentSleep, attempts=10 )
Jon Halle02505a2017-05-24 16:36:43 -0700417 main.log.info( "Checking flows state" )
acsmars51a7fe02015-10-29 18:33:32 -0700418 checkFlowResult = main.CLIs[ 0 ].checkFlowsState()
419 # Sleep for 10 seconds to provide time for the intent state to change
420 time.sleep( 10 )
Jon Halle02505a2017-05-24 16:36:43 -0700421 main.log.info( "Checking intents state one more time" )
acsmars51a7fe02015-10-29 18:33:32 -0700422 checkStateResult = main.CLIs[ 0 ].checkIntentState(
Jon Halle02505a2017-05-24 16:36:43 -0700423 intentsId=main.pIntentsId )
Jeremye4bc7132016-03-30 14:04:01 -0700424
acsmars51a7fe02015-10-29 18:33:32 -0700425 if checkStateResult and checkFlowResult:
426 addIntentsResult = main.TRUE
427 else:
428 addIntentsResult = main.FALSE
429 utilities.assert_equals(
430 expect=main.TRUE,
431 actual=addIntentsResult,
432 onpass="Successfully added point intents",
Jon Halle02505a2017-05-24 16:36:43 -0700433 onfail="Failed to add point intents" )
acsmars51a7fe02015-10-29 18:33:32 -0700434
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700435 pingResult = main.FALSE
acsmars51a7fe02015-10-29 18:33:32 -0700436
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700437 if not addIntentsResult:
438 main.log.error( "Intents were not properly installed. Skipping ping." )
439
440 else:
441 main.step( "Ping h1 and h2" )
442 pingResult = main.LincOE.pingHostOptical( src="h1", target="h2" )
acsmars51a7fe02015-10-29 18:33:32 -0700443 utilities.assert_equals(
444 expect=main.TRUE,
445 actual=pingResult,
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700446 onpass="Successfully pinged h1 and h2",
Jon Halle02505a2017-05-24 16:36:43 -0700447 onfail="Failed to ping between h1 and h2" )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700448
449 main.step( "Remove Point to Point intents" )
Devin Lim752dd7b2017-06-27 14:40:03 -0700450 removeResult = main.TRUE
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700451 # Check remaining intents
452 try:
453 intentsJson = json.loads( main.CLIs[ 0 ].intents() )
454 main.log.debug( intentsJson )
455 main.CLIs[ 0 ].removeIntent( intentId=pIntent1, purge=True )
456 main.CLIs[ 0 ].removeIntent( intentId=pIntent2, purge=True )
457 for intents in intentsJson:
458 main.CLIs[ 0 ].removeIntent( intentId=intents.get( 'id' ),
459 app='org.onosproject.cli',
460 purge=True )
461 time.sleep( 15 )
462
463 for i in range( main.numCtrls ):
Devin Lim752dd7b2017-06-27 14:40:03 -0700464 if not any ( intent.get('state') == 'WITHDRAWING' for intent
465 in json.loads( main.CLIs[i].intents() ) ):
466 main.log.debug( json.loads( main.CLIs[i].intents ) )
467 removeResult = main.FALSE
468 break
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700469 else:
470 removeResult = main.TRUE
471 except ( TypeError, ValueError ):
Jon Halle02505a2017-05-24 16:36:43 -0700472 main.log.error( "Cannot see intents on Node " + str( main.CLIs[ 0 ] ) +
473 ". Removing all intents." )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700474 main.CLIs[ 0 ].removeAllIntents( purge=True )
Jon Halle02505a2017-05-24 16:36:43 -0700475 main.CLIs[ 0 ].removeAllIntents( purge=True, app='org.onosproject.cli' )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700476
477 utilities.assert_equals( expect=main.TRUE,
478 actual=removeResult,
479 onpass="Successfully removed host intents",
480 onfail="Failed to remove host intents" )
acsmars51a7fe02015-10-29 18:33:32 -0700481
482 def CASE32( self ):
483 """
484 Add host intents between 2 packet layer host
485 """
486 import time
487 import json
488 main.log.report( "Adding host intents between 2 optical layer host" )
489 main.case( "Test add host intents between optical layer host" )
490 main.caseExplanation = "Test host intents between 2 optical layer host"
491
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700492 main.step( "Creating list of hosts" )
493 hostnum = 0
494 try:
495 hostData = json.loads( hosts[ controller ] )
496 except( TypeError, ValueError ):
Jon Halle02505a2017-05-24 16:36:43 -0700497 main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700498
acsmars51a7fe02015-10-29 18:33:32 -0700499 main.step( "Adding host intents to h1 and h2" )
acsmars51a7fe02015-10-29 18:33:32 -0700500 hostId = []
501 # Listing host MAC addresses
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700502 for host in hostData:
Jon Halle02505a2017-05-24 16:36:43 -0700503 hostId.append( host.get( "id" ) )
acsmars51a7fe02015-10-29 18:33:32 -0700504 host1 = hostId[ 0 ]
505 host2 = hostId[ 1 ]
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700506 main.log.debug( host1 )
507 main.log.debug( host2 )
acsmars51a7fe02015-10-29 18:33:32 -0700508
509 intentsId = []
Jon Halle02505a2017-05-24 16:36:43 -0700510 intent1 = main.CLIs[ 0 ].addHostIntent( hostIdOne=host1,
511 hostIdTwo=host2 )
acsmars51a7fe02015-10-29 18:33:32 -0700512 intentsId.append( intent1 )
513 # Checking intents state before pinging
514 main.log.info( "Checking intents state" )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700515 intentResult = utilities.retry( f=main.CLIs[ 0 ].checkIntentState,
516 retValue=main.FALSE, args=intentsId,
517 sleep=main.checkIntentSleep, attempts=10 )
acsmars51a7fe02015-10-29 18:33:32 -0700518
519 # If intent state is still wrong, display intent states
520 if not intentResult:
521 main.log.error( main.CLIs[ 0 ].intents() )
Jeremye4bc7132016-03-30 14:04:01 -0700522
acsmars51a7fe02015-10-29 18:33:32 -0700523 utilities.assert_equals( expect=main.TRUE,
524 actual=intentResult,
525 onpass="All intents are in INSTALLED state ",
526 onfail="Some of the intents are not in " +
527 "INSTALLED state " )
528
529 if not intentResult:
530 main.log.error( "Intents were not properly installed. Skipping Ping" )
531 else:
532 # Pinging h1 to h2 and then ping h2 to h1
533 main.step( "Pinging h1 and h2" )
534 pingResult = main.TRUE
535 pingResult = main.LincOE.pingHostOptical( src="h1", target="h2" ) \
Jon Halle02505a2017-05-24 16:36:43 -0700536 and main.LincOE.pingHostOptical( src="h2", target="h1" )
Jeremye4bc7132016-03-30 14:04:01 -0700537
acsmars51a7fe02015-10-29 18:33:32 -0700538 utilities.assert_equals( expect=main.TRUE,
539 actual=pingResult,
540 onpass="Pinged successfully between h1 and h2",
541 onfail="Pinged failed between h1 and h2" )
542
543 # Removed all added host intents
544 main.step( "Removing host intents" )
545 removeResult = main.TRUE
546 # Check remaining intents
Jeremy7134f5b2016-04-05 13:50:21 -0700547 try:
548 intentsJson = json.loads( main.CLIs[ 0 ].intents() )
549 main.CLIs[ 0 ].removeIntent( intentId=intent1, purge=True )
550 #main.CLIs[ 0 ].removeIntent( intentId=intent2, purge=True )
Jon Halle02505a2017-05-24 16:36:43 -0700551 main.log.debug( intentsJson )
Jeremy7134f5b2016-04-05 13:50:21 -0700552 for intents in intentsJson:
Jeremye4bc7132016-03-30 14:04:01 -0700553 main.CLIs[ 0 ].removeIntent( intentId=intents.get( 'id' ),
554 app='org.onosproject.optical',
555 purge=True )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700556 time.sleep( 15 )
acsmars51a7fe02015-10-29 18:33:32 -0700557
Jeremy7134f5b2016-04-05 13:50:21 -0700558 for i in range( main.numCtrls ):
Devin Lim752dd7b2017-06-27 14:40:03 -0700559 if not any ( intent.get('state') == 'WITHDRAWING' for intent
560 in json.loads( main.CLIs[i].intents() ) ):
561 main.log.debug( json.loads( main.CLIs[i].intents ) )
562 removeResult = main.FALSE
563 break
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700564 else:
565 removeResult = main.TRUE
Jeremy7134f5b2016-04-05 13:50:21 -0700566 except ( TypeError, ValueError ):
Jon Halle02505a2017-05-24 16:36:43 -0700567 main.log.error( "Cannot see intents on Node " + str( main.CLIs[ 0 ] ) +
568 ". Removing all intents." )
Jeremy7134f5b2016-04-05 13:50:21 -0700569 main.CLIs[ 0 ].removeAllIntents( purge=True )
Jon Halle02505a2017-05-24 16:36:43 -0700570 main.CLIs[ 0 ].removeAllIntents( purge=True, app='org.onosproject.optical' )
Jeremy7134f5b2016-04-05 13:50:21 -0700571
572 utilities.assert_equals( expect=main.TRUE,
573 actual=removeResult,
574 onpass="Successfully removed host intents",
Chiyu Chengef109502016-11-21 15:51:38 -0800575 onfail="Failed to remove host intents" )