blob: 2b63a6478c100e9516e3d69c9bba25087141f361 [file] [log] [blame]
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07001"""
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07002Copyright 2015 Open Networking Foundation ( ONF )
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07003
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
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070011 ( at your option ) any later version.
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -070012
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"""
acsmars51a7fe02015-10-29 18:33:32 -070021# Testing the basic intent functionality of ONOS
22
Jon Halle02505a2017-05-24 16:36:43 -070023
acsmars51a7fe02015-10-29 18:33:32 -070024class FUNCoptical:
25
26 def __init__( self ):
27 self.default = ''
28
29 def CASE1( self, main ):
acsmars51a7fe02015-10-29 18:33:32 -070030 import imp
Devin Lim58046fa2017-07-05 16:55:00 -070031 import time
acsmars51a7fe02015-10-29 18:33:32 -070032 import re
acsmars51a7fe02015-10-29 18:33:32 -070033 """
Devin Lim58046fa2017-07-05 16:55:00 -070034 - Construct tests variables
35 - GIT ( optional )
36 - Checkout ONOS master branch
37 - Pull latest ONOS code
38 - Building ONOS ( optional )
39 - Install ONOS package
40 - Build ONOS package
acsmars51a7fe02015-10-29 18:33:32 -070041 """
Devin Lim58046fa2017-07-05 16:55:00 -070042 try:
43 from tests.dependencies.ONOSSetup import ONOSSetup
44 main.testSetUp = ONOSSetup()
45 except ImportError:
46 main.log.error( "ONOSSetup not found. exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -070047 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070048 main.testSetUp.envSetupDescription()
acsmars51a7fe02015-10-29 18:33:32 -070049 stepResult = main.FALSE
acsmars51a7fe02015-10-29 18:33:32 -070050 # Test variables
51 try:
acsmars51a7fe02015-10-29 18:33:32 -070052 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
acsmars51a7fe02015-10-29 18:33:32 -070053 main.dependencyPath = main.testOnDirectory + \
54 main.params[ 'DEPENDENCY' ][ 'path' ]
55 main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," )
acsmars51a7fe02015-10-29 18:33:32 -070056 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
acsmars51a7fe02015-10-29 18:33:32 -070057 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
58 main.checkIntentSleep = int( main.params[ 'SLEEP' ][ 'checkintent' ] )
acsmars51a7fe02015-10-29 18:33:32 -070059 main.checkTopoAttempts = int( main.params[ 'SLEEP' ][ 'topoAttempts' ] )
Jeremy Songster5665f1b2016-06-20 14:38:22 -070060 main.switches = int( main.params[ 'MININET' ][ 'switch' ] )
61 main.links = int( main.params[ 'MININET' ][ 'links' ] )
62 main.hosts = int( main.params[ 'MININET' ][ 'hosts' ] )
63 main.opticalTopo = main.params[ 'MININET' ][ 'toponame' ]
acsmars51a7fe02015-10-29 18:33:32 -070064 main.hostsData = {}
acsmars51a7fe02015-10-29 18:33:32 -070065 main.assertReturnString = '' # Assembled assert return string
Jon Halle02505a2017-05-24 16:36:43 -070066 main.cycle = 0 # How many times FUNCintent has run through its tests
acsmars51a7fe02015-10-29 18:33:32 -070067 # -- INIT SECTION, ONLY RUNS ONCE -- #
Devin Lim142b5342017-07-20 15:22:39 -070068 stepResult = main.testSetUp.envSetup()
acsmars51a7fe02015-10-29 18:33:32 -070069 except Exception as e:
Devin Lim58046fa2017-07-05 16:55:00 -070070 main.testSetUp.envSetupException( e )
71 main.testSetUp.evnSetupConclusion( stepResult )
acsmars51a7fe02015-10-29 18:33:32 -070072
73 def CASE2( self, main ):
74 """
Devin Lim58046fa2017-07-05 16:55:00 -070075 - Set up cell
76 - Create cell file
77 - Set cell file
78 - Verify cell file
79 - Kill ONOS process
80 - Uninstall ONOS cluster
81 - Verify ONOS start up
82 - Install ONOS cluster
83 - Connect to cli
acsmars51a7fe02015-10-29 18:33:32 -070084 """
Jeremye4bc7132016-03-30 14:04:01 -070085 main.flowCompiler = "Flow Rules"
You Wanga0f6ff62018-01-11 15:46:30 -080086 main.testSetUp.ONOSSetUp( main.Cluster, True, mininetIp=main.LincOE )
acsmars51a7fe02015-10-29 18:33:32 -070087
acsmars51a7fe02015-10-29 18:33:32 -070088 def CASE10( self, main ):
89 """
90 Start Mininet opticalTest Topology
91 """
Jon Halle02505a2017-05-24 16:36:43 -070092 main.case( "Mininet with Linc-OE startup" )
Devin Lim752dd7b2017-06-27 14:40:03 -070093 main.step( "Push TopoDDriver.json to ONOS through onos-netcfg" )
Devin Lim02075272017-07-10 15:33:21 -070094 topoResult = True
Devin Lim142b5342017-07-20 15:22:39 -070095 for ctrl in main.Cluster.active():
Devin Lim02075272017-07-10 15:33:21 -070096 topoResult = topoResult and \
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070097 main.ONOSbench.onosNetCfg( controllerIp=ctrl.ipAddress,
98 path=main.dependencyPath,
99 fileName="TopoDDriver.json" )
100 # Exit if topology did not load properly
Devin Lim752dd7b2017-06-27 14:40:03 -0700101 if not topoResult:
Devin Lim44075962017-08-11 10:56:37 -0700102 main.cleanAndExit()
Devin Lim752dd7b2017-06-27 14:40:03 -0700103
acsmars51a7fe02015-10-29 18:33:32 -0700104 main.caseExplanation = "Start opticalTest.py topology included with ONOS"
105 main.step( "Starting mininet and LINC-OE" )
acsmars51a7fe02015-10-29 18:33:32 -0700106 time.sleep( 10 )
Devin Lim142b5342017-07-20 15:22:39 -0700107 controllerIPs = ','.join( main.Cluster.getIps() )
Devin Lim752dd7b2017-06-27 14:40:03 -0700108 cIps = ""
Devin Lim58046fa2017-07-05 16:55:00 -0700109 for i in range( 0, 4 ):
Devin Lim752dd7b2017-06-27 14:40:03 -0700110 cIps += controllerIPs + ' '
111 opticalMnScript = main.LincOE.runOpticalMnScript( ctrllerIP=cIps, topology=main.opticalTopo )
acsmars51a7fe02015-10-29 18:33:32 -0700112 topoResult = opticalMnScript
113 utilities.assert_equals(
114 expect=main.TRUE,
115 actual=topoResult,
116 onpass="Started the topology successfully ",
Jon Halle02505a2017-05-24 16:36:43 -0700117 onfail="Failed to start the topology" )
acsmars51a7fe02015-10-29 18:33:32 -0700118
acsmars51a7fe02015-10-29 18:33:32 -0700119 def CASE14( self, main ):
120 """
121 Stop mininet
122 """
Devin Lim58046fa2017-07-05 16:55:00 -0700123 try:
124 from tests.dependencies.utils import Utils
125 except ImportError:
126 main.log.error( "Utils not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700127 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700128 try:
129 main.Utils
130 except ( NameError, AttributeError ):
131 main.Utils = Utils()
132 main.Utils.mininetCleanIntro()
133 topoResult = main.Utils.mininetCleanup( main.LincOE, timeout=180 )
acsmars51a7fe02015-10-29 18:33:32 -0700134 # Exit if topology did not load properly
135 if not topoResult:
Devin Lim44075962017-08-11 10:56:37 -0700136 main.cleanAndExit()
acsmars51a7fe02015-10-29 18:33:32 -0700137
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700138 def CASE16( self, main ):
139 """
140 Balance Masters
141 """
142 main.case( "Balance mastership of switches" )
143 main.step( "Balancing mastership of switches" )
144
145 balanceResult = main.FALSE
Devin Lim142b5342017-07-20 15:22:39 -0700146 balanceResult = utilities.retry( f=main.Cluster.active( 0 ).CLI.balanceMasters, retValue=main.FALSE, args=[] )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700147
148 utilities.assert_equals( expect=main.TRUE,
149 actual=balanceResult,
150 onpass="Successfully balanced mastership of switches",
151 onfail="Failed to balance mastership of switches" )
152 if not balanceResult:
153 main.initialized = main.FALSE
154
Jeremye4bc7132016-03-30 14:04:01 -0700155 def CASE17( self, main ):
156 """
157 Use Flow Objectives
158 """
159 main.case( "Enable intent compilation using Flow Objectives" )
160 main.step( "Enabling Flow Objectives" )
161
162 main.flowCompiler = "Flow Objectives"
163
164 cmd = "org.onosproject.net.intent.impl.compiler.IntentConfigurableRegistrator"
165
Devin Lim142b5342017-07-20 15:22:39 -0700166 stepResult = main.Cluster.active( 0 ).CLI.setCfg( component=cmd,
167 propName="useFlowObjectives", value="true" )
Jeremye4bc7132016-03-30 14:04:01 -0700168
169 utilities.assert_equals( expect=main.TRUE,
170 actual=stepResult,
171 onpass="Successfully activated Flow Objectives",
172 onfail="Failed to activate Flow Objectives" )
173
Jeremy Songster17147f22016-05-31 18:30:52 -0700174 def CASE19( self, main ):
175 """
176 Copy the karaf.log files after each testcase cycle
177 """
Devin Lim58046fa2017-07-05 16:55:00 -0700178 try:
179 from tests.dependencies.utils import Utils
180 except ImportError:
181 main.log.error( "Utils not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700182 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700183 try:
184 main.Utils
185 except ( NameError, AttributeError ):
186 main.Utils = Utils()
Devin Lim142b5342017-07-20 15:22:39 -0700187 main.Utils.copyKarafLog( "cycle" + str( main.cycle ) )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700188
Jon Halle02505a2017-05-24 16:36:43 -0700189 def CASE21( self, main ):
acsmars51a7fe02015-10-29 18:33:32 -0700190 """
191 Run pingall to discover all hosts
192 """
193 main.case( "Running Pingall" )
194 main.caseExplanation = "Use pingall to discover all hosts. Pingall is expected to fail."
195 main.step( "Discover Hosts through Pingall" )
Jon Halle02505a2017-05-24 16:36:43 -0700196 pingResult = main.LincOE.pingall( timeout=120 )
acsmars51a7fe02015-10-29 18:33:32 -0700197
198 utilities.assert_equals( expect=main.FALSE,
199 actual=pingResult,
200 onpass="Pingall Completed",
201 onfail="Pingall did not complete or did not return fales" )
202
Jon Halle02505a2017-05-24 16:36:43 -0700203 def CASE22( self, main ):
acsmars51a7fe02015-10-29 18:33:32 -0700204 """
205 Send arpings to discover all hosts
206 """
207 main.case( "Discover Hosts with arping" )
208 main.caseExplanation = "Send arpings between all the hosts to discover and verify them"
209
210 main.step( "Send arping between all hosts" )
211
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700212 hosts = []
213 for i in range( main.hosts ):
214 hosts.append( 'h{}'.format( i + 1 ) )
acsmars51a7fe02015-10-29 18:33:32 -0700215
216 arpingHostResults = main.TRUE
217 for host in hosts:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700218 if main.LincOE.arping( host, ethDevice=host + "-eth0" ):
acsmars51a7fe02015-10-29 18:33:32 -0700219 main.log.info( "Successfully reached host {} with arping".format( host ) )
220 else:
221 main.log.error( "Could not reach host {} with arping".format( host ) )
222 arpingHostResults = main.FALSE
223
224 utilities.assert_equals( expect=main.TRUE,
225 actual=arpingHostResults,
226 onpass="Successfully discovered all hosts",
227 onfail="Could not descover some hosts" )
228
229 def CASE23( self, main ):
230 """
231 Compare ONOS Topology to Mininet Topology
232 """
233 import json
Devin Lim58046fa2017-07-05 16:55:00 -0700234 try:
235 from tests.dependencies.topology import Topology
236 except ImportError:
237 main.log.error( "Topology not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700238 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700239 try:
240 main.topoRelated
241 except ( NameError, AttributeError ):
242 main.topoRelated = Topology()
acsmars51a7fe02015-10-29 18:33:32 -0700243 main.case( "Compare ONOS Topology view to Mininet topology" )
244 main.caseExplanation = "Compare topology elements between Mininet" +\
245 " and ONOS"
246
247 main.log.info( "Gathering topology information from Mininet" )
248 devicesResults = main.FALSE # Overall Boolean for device correctness
249 linksResults = main.FALSE # Overall Boolean for link correctness
250 hostsResults = main.FALSE # Overall Boolean for host correctness
251 deviceFails = [] # Nodes where devices are incorrect
252 linkFails = [] # Nodes where links are incorrect
253 hostFails = [] # Nodes where hosts are incorrect
254 attempts = main.checkTopoAttempts # Remaining Attempts
255
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700256 mnSwitches = main.switches
257 mnLinks = main.links
258 mnHosts = main.hosts
acsmars51a7fe02015-10-29 18:33:32 -0700259
Jon Hall70b2ff42015-11-17 15:49:44 -0800260 main.step( "Comparing Mininet topology to ONOS topology" )
acsmars51a7fe02015-10-29 18:33:32 -0700261
262 while ( attempts >= 0 ) and\
Jon Halle02505a2017-05-24 16:36:43 -0700263 ( not devicesResults or not linksResults or not hostsResults ):
acsmars51a7fe02015-10-29 18:33:32 -0700264 time.sleep( 2 )
265 if not devicesResults:
Devin Lim142b5342017-07-20 15:22:39 -0700266 devices = main.topoRelated.getAll( "devices", False )
267 ports = main.topoRelated.getAll( "ports", False )
acsmars51a7fe02015-10-29 18:33:32 -0700268 devicesResults = main.TRUE
269 deviceFails = [] # Reset for each attempt
270 if not linksResults:
Devin Lim142b5342017-07-20 15:22:39 -0700271 links = main.topoRelated.getAll( "links", False )
acsmars51a7fe02015-10-29 18:33:32 -0700272 linksResults = main.TRUE
273 linkFails = [] # Reset for each attempt
274 if not hostsResults:
Devin Lim142b5342017-07-20 15:22:39 -0700275 hosts = main.topoRelated.getAll( "hosts", False )
acsmars51a7fe02015-10-29 18:33:32 -0700276 hostsResults = main.TRUE
277 hostFails = [] # Reset for each attempt
278
279 # Check for matching topology on each node
Devin Lim142b5342017-07-20 15:22:39 -0700280 for controller in range( main.Cluster.numCtrls ):
acsmars51a7fe02015-10-29 18:33:32 -0700281 controllerStr = str( controller + 1 ) # ONOS node number
282 # Compare Devices
283 if devices[ controller ] and ports[ controller ] and\
Jon Halle02505a2017-05-24 16:36:43 -0700284 "Error" not in devices[ controller ] and\
285 "Error" not in ports[ controller ]:
acsmars51a7fe02015-10-29 18:33:32 -0700286
287 try:
288 deviceData = json.loads( devices[ controller ] )
289 portData = json.loads( ports[ controller ] )
Jon Halle02505a2017-05-24 16:36:43 -0700290 except ( TypeError, ValueError ):
291 main.log.error( "Could not load json:" + str( devices[ controller ] ) + ' or ' + str( ports[ controller ] ) )
acsmars51a7fe02015-10-29 18:33:32 -0700292 currentDevicesResult = main.FALSE
293 else:
294 if mnSwitches == len( deviceData ):
295 currentDevicesResult = main.TRUE
296 else:
297 currentDevicesResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700298 main.log.error( "Node {} only sees {} device(s) but {} exist".format(
Jon Halle02505a2017-05-24 16:36:43 -0700299 controllerStr, len( deviceData ), mnSwitches ) )
acsmars51a7fe02015-10-29 18:33:32 -0700300 else:
301 currentDevicesResult = main.FALSE
302 if not currentDevicesResult:
303 deviceFails.append( controllerStr )
304 devicesResults = devicesResults and currentDevicesResult
305 # Compare Links
306 if links[ controller ] and "Error" not in links[ controller ]:
307 try:
308 linkData = json.loads( links[ controller ] )
Jon Halle02505a2017-05-24 16:36:43 -0700309 except ( TypeError, ValueError ):
310 main.log.error( "Could not load json:" + str( links[ controller ] ) )
acsmars51a7fe02015-10-29 18:33:32 -0700311 currentLinksResult = main.FALSE
312 else:
313 if mnLinks == len( linkData ):
314 currentLinksResult = main.TRUE
315 else:
316 currentLinksResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700317 main.log.error( "Node {} only sees {} link(s) but {} exist".format(
Jon Halle02505a2017-05-24 16:36:43 -0700318 controllerStr, len( linkData ), mnLinks ) )
acsmars51a7fe02015-10-29 18:33:32 -0700319 else:
320 currentLinksResult = main.FALSE
321 if not currentLinksResult:
322 linkFails.append( controllerStr )
323 linksResults = linksResults and currentLinksResult
324 # Compare Hosts
325 if hosts[ controller ] and "Error" not in hosts[ controller ]:
326 try:
327 hostData = json.loads( hosts[ controller ] )
Jon Halle02505a2017-05-24 16:36:43 -0700328 except ( TypeError, ValueError ):
329 main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
acsmars51a7fe02015-10-29 18:33:32 -0700330 currentHostsResult = main.FALSE
331 else:
332 if mnHosts == len( hostData ):
333 currentHostsResult = main.TRUE
334 else:
335 currentHostsResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700336 main.log.error( "Node {} only sees {} host(s) but {} exist".format(
Jon Halle02505a2017-05-24 16:36:43 -0700337 controllerStr, len( hostData ), mnHosts ) )
acsmars51a7fe02015-10-29 18:33:32 -0700338 else:
339 currentHostsResult = main.FALSE
340 if not currentHostsResult:
341 hostFails.append( controllerStr )
342 hostsResults = hostsResults and currentHostsResult
343 # Decrement Attempts Remaining
344 attempts -= 1
345
346 utilities.assert_equals( expect=[],
347 actual=deviceFails,
348 onpass="ONOS correctly discovered all devices",
349 onfail="ONOS incorrectly discovered devices on nodes: " +
350 str( deviceFails ) )
351 utilities.assert_equals( expect=[],
352 actual=linkFails,
353 onpass="ONOS correctly discovered all links",
354 onfail="ONOS incorrectly discovered links on nodes: " +
355 str( linkFails ) )
356 utilities.assert_equals( expect=[],
357 actual=hostFails,
358 onpass="ONOS correctly discovered all hosts",
359 onfail="ONOS incorrectly discovered hosts on nodes: " +
360 str( hostFails ) )
361 if hostsResults and linksResults and devicesResults:
362 topoResults = main.TRUE
363 else:
364 topoResults = main.FALSE
365 utilities.assert_equals( expect=main.TRUE,
366 actual=topoResults,
367 onpass="ONOS correctly discovered the topology",
368 onfail="ONOS incorrectly discovered the topology" )
369
acsmars51a7fe02015-10-29 18:33:32 -0700370 def CASE31( self, main ):
371 import time
372 """
373 Add bidirectional point intents between 2 packet layer( mininet )
374 devices and ping mininet hosts
375 """
376 main.log.report(
377 "This testcase adds bidirectional point intents between 2 " +
378 "packet layer( mininet ) devices and ping mininet hosts" )
379 main.case( "Install point intents between 2 packet layer device and " +
380 "ping the hosts" )
381 main.caseExplanation = "This testcase adds bidirectional point intents between 2 " +\
382 "packet layer( mininet ) devices and ping mininet hosts"
383
384 main.step( "Adding point intents" )
385 checkFlowResult = main.TRUE
386 main.pIntentsId = []
Devin Lim142b5342017-07-20 15:22:39 -0700387 pIntent1 = main.Cluster.active( 0 ).CLI.addPointIntent(
Devin Lim752dd7b2017-06-27 14:40:03 -0700388 "of:0000000000000015/1",
389 "of:000000000000000b/2" )
acsmars51a7fe02015-10-29 18:33:32 -0700390 time.sleep( 10 )
Devin Lim142b5342017-07-20 15:22:39 -0700391 pIntent2 = main.Cluster.active( 0 ).CLI.addPointIntent(
Devin Lim752dd7b2017-06-27 14:40:03 -0700392 "of:000000000000000b/2",
393 "of:0000000000000015/1" )
acsmars51a7fe02015-10-29 18:33:32 -0700394 main.pIntentsId.append( pIntent1 )
395 main.pIntentsId.append( pIntent2 )
396 time.sleep( 10 )
Jon Halle02505a2017-05-24 16:36:43 -0700397 main.log.info( "Checking intents state" )
Devin Lim142b5342017-07-20 15:22:39 -0700398 checkStateResult = main.Cluster.active( 0 ).CLI.checkIntentState(
399 intentsId=main.pIntentsId )
acsmars51a7fe02015-10-29 18:33:32 -0700400 time.sleep( 10 )
Devin Lim142b5342017-07-20 15:22:39 -0700401 checkStateResult = utilities.retry( f=main.Cluster.active( 0 ).CLI.checkIntentState,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700402 retValue=main.FALSE, args=( main.pIntentsId, "INSTALLED" ),
403 sleep=main.checkIntentSleep, attempts=10 )
Jon Halle02505a2017-05-24 16:36:43 -0700404 main.log.info( "Checking flows state" )
Devin Lim142b5342017-07-20 15:22:39 -0700405 checkFlowResult = main.Cluster.active( 0 ).CLI.checkFlowsState()
acsmars51a7fe02015-10-29 18:33:32 -0700406 # Sleep for 10 seconds to provide time for the intent state to change
407 time.sleep( 10 )
Jon Halle02505a2017-05-24 16:36:43 -0700408 main.log.info( "Checking intents state one more time" )
Devin Lim142b5342017-07-20 15:22:39 -0700409 checkStateResult = main.Cluster.active( 0 ).CLI.checkIntentState(
Jon Halle02505a2017-05-24 16:36:43 -0700410 intentsId=main.pIntentsId )
Jeremye4bc7132016-03-30 14:04:01 -0700411
acsmars51a7fe02015-10-29 18:33:32 -0700412 if checkStateResult and checkFlowResult:
413 addIntentsResult = main.TRUE
414 else:
415 addIntentsResult = main.FALSE
416 utilities.assert_equals(
417 expect=main.TRUE,
418 actual=addIntentsResult,
419 onpass="Successfully added point intents",
Jon Halle02505a2017-05-24 16:36:43 -0700420 onfail="Failed to add point intents" )
acsmars51a7fe02015-10-29 18:33:32 -0700421
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700422 pingResult = main.FALSE
acsmars51a7fe02015-10-29 18:33:32 -0700423
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700424 if not addIntentsResult:
425 main.log.error( "Intents were not properly installed. Skipping ping." )
426
427 else:
428 main.step( "Ping h1 and h2" )
429 pingResult = main.LincOE.pingHostOptical( src="h1", target="h2" )
acsmars51a7fe02015-10-29 18:33:32 -0700430 utilities.assert_equals(
431 expect=main.TRUE,
432 actual=pingResult,
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700433 onpass="Successfully pinged h1 and h2",
Jon Halle02505a2017-05-24 16:36:43 -0700434 onfail="Failed to ping between h1 and h2" )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700435
436 main.step( "Remove Point to Point intents" )
Devin Lim752dd7b2017-06-27 14:40:03 -0700437 removeResult = main.TRUE
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700438 # Check remaining intents
439 try:
Devin Lim142b5342017-07-20 15:22:39 -0700440 intentsJson = json.loads( main.Cluster.active( 0 ).CLI.intents() )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700441 main.log.debug( intentsJson )
Devin Lim142b5342017-07-20 15:22:39 -0700442 main.Cluster.active( 0 ).CLI.removeIntent( intentId=pIntent1, purge=True )
443 main.Cluster.active( 0 ).CLI.removeIntent( intentId=pIntent2, purge=True )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700444 for intents in intentsJson:
Devin Lim142b5342017-07-20 15:22:39 -0700445 main.Cluster.active( 0 ).CLI.removeIntent( intentId=intents.get( 'id' ),
446 app='org.onosproject.cli',
447 purge=True )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700448 time.sleep( 15 )
449
Devin Lim142b5342017-07-20 15:22:39 -0700450 for ctrl in main.Cluster.active():
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700451 if not any( intent.get( 'state' ) == 'WITHDRAWING' for intent
452 in json.loads( ctrl.CLI.intents() ) ):
453 main.log.debug( json.loads( ctrl.CLI.intents() ) )
454 removeResult = main.FALSE
455 break
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700456 else:
457 removeResult = main.TRUE
458 except ( TypeError, ValueError ):
Devin Lim142b5342017-07-20 15:22:39 -0700459 main.log.error( "Cannot see intents on " + main.Cluster.active( 0 ).name +
Jon Halle02505a2017-05-24 16:36:43 -0700460 ". Removing all intents." )
Devin Lim142b5342017-07-20 15:22:39 -0700461 main.Cluster.active( 0 ).CLI.removeAllIntents( purge=True )
462 main.Cluster.active( 0 ).CLI.removeAllIntents( purge=True, app='org.onosproject.cli' )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700463
464 utilities.assert_equals( expect=main.TRUE,
465 actual=removeResult,
466 onpass="Successfully removed host intents",
467 onfail="Failed to remove host intents" )
acsmars51a7fe02015-10-29 18:33:32 -0700468
469 def CASE32( self ):
470 """
471 Add host intents between 2 packet layer host
472 """
473 import time
474 import json
475 main.log.report( "Adding host intents between 2 optical layer host" )
476 main.case( "Test add host intents between optical layer host" )
477 main.caseExplanation = "Test host intents between 2 optical layer host"
478
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700479 main.step( "Creating list of hosts" )
480 hostnum = 0
481 try:
482 hostData = json.loads( hosts[ controller ] )
483 except( TypeError, ValueError ):
Jon Halle02505a2017-05-24 16:36:43 -0700484 main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700485
acsmars51a7fe02015-10-29 18:33:32 -0700486 main.step( "Adding host intents to h1 and h2" )
acsmars51a7fe02015-10-29 18:33:32 -0700487 hostId = []
488 # Listing host MAC addresses
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700489 for host in hostData:
Jon Halle02505a2017-05-24 16:36:43 -0700490 hostId.append( host.get( "id" ) )
acsmars51a7fe02015-10-29 18:33:32 -0700491 host1 = hostId[ 0 ]
492 host2 = hostId[ 1 ]
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700493 main.log.debug( host1 )
494 main.log.debug( host2 )
acsmars51a7fe02015-10-29 18:33:32 -0700495
496 intentsId = []
Devin Lim142b5342017-07-20 15:22:39 -0700497 intent1 = main.Cluster.active( 0 ).CLI.addHostIntent( hostIdOne=host1,
498 hostIdTwo=host2 )
acsmars51a7fe02015-10-29 18:33:32 -0700499 intentsId.append( intent1 )
500 # Checking intents state before pinging
501 main.log.info( "Checking intents state" )
Devin Lim142b5342017-07-20 15:22:39 -0700502 intentResult = utilities.retry( f=main.Cluster.active( 0 ).CLI.checkIntentState,
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700503 retValue=main.FALSE, args=intentsId,
504 sleep=main.checkIntentSleep, attempts=10 )
acsmars51a7fe02015-10-29 18:33:32 -0700505
506 # If intent state is still wrong, display intent states
507 if not intentResult:
Devin Lim142b5342017-07-20 15:22:39 -0700508 main.log.error( main.Cluster.active( 0 ).CLI.intents() )
Jeremye4bc7132016-03-30 14:04:01 -0700509
acsmars51a7fe02015-10-29 18:33:32 -0700510 utilities.assert_equals( expect=main.TRUE,
511 actual=intentResult,
512 onpass="All intents are in INSTALLED state ",
513 onfail="Some of the intents are not in " +
514 "INSTALLED state " )
515
516 if not intentResult:
517 main.log.error( "Intents were not properly installed. Skipping Ping" )
518 else:
519 # Pinging h1 to h2 and then ping h2 to h1
520 main.step( "Pinging h1 and h2" )
521 pingResult = main.TRUE
522 pingResult = main.LincOE.pingHostOptical( src="h1", target="h2" ) \
Jon Halle02505a2017-05-24 16:36:43 -0700523 and main.LincOE.pingHostOptical( src="h2", target="h1" )
Jeremye4bc7132016-03-30 14:04:01 -0700524
acsmars51a7fe02015-10-29 18:33:32 -0700525 utilities.assert_equals( expect=main.TRUE,
526 actual=pingResult,
527 onpass="Pinged successfully between h1 and h2",
528 onfail="Pinged failed between h1 and h2" )
529
530 # Removed all added host intents
531 main.step( "Removing host intents" )
532 removeResult = main.TRUE
533 # Check remaining intents
Jeremy7134f5b2016-04-05 13:50:21 -0700534 try:
Devin Lim142b5342017-07-20 15:22:39 -0700535 intentsJson = json.loads( main.Cluster.active( 0 ).CLI.intents() )
536 main.Cluster.active( 0 ).CLI.removeIntent( intentId=intent1, purge=True )
Jon Halle02505a2017-05-24 16:36:43 -0700537 main.log.debug( intentsJson )
Jeremy7134f5b2016-04-05 13:50:21 -0700538 for intents in intentsJson:
Devin Lim142b5342017-07-20 15:22:39 -0700539 main.Cluster.active( 0 ).CLI.removeIntent( intentId=intents.get( 'id' ),
540 app='org.onosproject.optical',
541 purge=True )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700542 time.sleep( 15 )
acsmars51a7fe02015-10-29 18:33:32 -0700543
Devin Lim142b5342017-07-20 15:22:39 -0700544 for ctrl in main.Cluster.active():
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700545 if not any( intent.get( 'state' ) == 'WITHDRAWING' for intent
546 in json.loads( ctrl.CLI.intents() ) ):
547 main.log.debug( json.loads( ctrl.CLI.intents() ) )
548 removeResult = main.FALSE
549 break
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700550 else:
551 removeResult = main.TRUE
Jeremy7134f5b2016-04-05 13:50:21 -0700552 except ( TypeError, ValueError ):
Devin Lim142b5342017-07-20 15:22:39 -0700553 main.log.error( "Cannot see intents on " + main.Cluster.active( 0 ).name +
Jon Halle02505a2017-05-24 16:36:43 -0700554 ". Removing all intents." )
Devin Lim142b5342017-07-20 15:22:39 -0700555 main.Cluster.active( 0 ).CLI.removeAllIntents( purge=True )
556 main.Cluster.active( 0 ).CLI.removeAllIntents( purge=True, app='org.onosproject.optical' )
Jeremy7134f5b2016-04-05 13:50:21 -0700557
558 utilities.assert_equals( expect=main.TRUE,
559 actual=removeResult,
560 onpass="Successfully removed host intents",
Chiyu Chengef109502016-11-21 15:51:38 -0800561 onfail="Failed to remove host intents" )