blob: aa298abc3222f0c77529eee07e8f4f6d1fbce263 [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"
Devin Lim142b5342017-07-20 15:22:39 -070086 main.testSetUp.ONOSSetUp( main.LincOE, main.Cluster, True )
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" )
168 stepResult &= main.Cluster.active( 0 ).CLI.setCfg( component=cmd,
169 propName="defaultFlowObjectiveCompiler",
170 value='org.onosproject.net.intent.impl.compiler.LinkCollectionIntentObjectiveCompiler' )
Jeremye4bc7132016-03-30 14:04:01 -0700171
172 utilities.assert_equals( expect=main.TRUE,
173 actual=stepResult,
174 onpass="Successfully activated Flow Objectives",
175 onfail="Failed to activate Flow Objectives" )
176
Jeremy Songster17147f22016-05-31 18:30:52 -0700177 def CASE19( self, main ):
178 """
179 Copy the karaf.log files after each testcase cycle
180 """
Devin Lim58046fa2017-07-05 16:55:00 -0700181 try:
182 from tests.dependencies.utils import Utils
183 except ImportError:
184 main.log.error( "Utils not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700185 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700186 try:
187 main.Utils
188 except ( NameError, AttributeError ):
189 main.Utils = Utils()
Devin Lim142b5342017-07-20 15:22:39 -0700190 main.Utils.copyKarafLog( "cycle" + str( main.cycle ) )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700191
Jon Halle02505a2017-05-24 16:36:43 -0700192 def CASE21( self, main ):
acsmars51a7fe02015-10-29 18:33:32 -0700193 """
194 Run pingall to discover all hosts
195 """
196 main.case( "Running Pingall" )
197 main.caseExplanation = "Use pingall to discover all hosts. Pingall is expected to fail."
198 main.step( "Discover Hosts through Pingall" )
Jon Halle02505a2017-05-24 16:36:43 -0700199 pingResult = main.LincOE.pingall( timeout=120 )
acsmars51a7fe02015-10-29 18:33:32 -0700200
201 utilities.assert_equals( expect=main.FALSE,
202 actual=pingResult,
203 onpass="Pingall Completed",
204 onfail="Pingall did not complete or did not return fales" )
205
Jon Halle02505a2017-05-24 16:36:43 -0700206 def CASE22( self, main ):
acsmars51a7fe02015-10-29 18:33:32 -0700207 """
208 Send arpings to discover all hosts
209 """
210 main.case( "Discover Hosts with arping" )
211 main.caseExplanation = "Send arpings between all the hosts to discover and verify them"
212
213 main.step( "Send arping between all hosts" )
214
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700215 hosts = []
216 for i in range( main.hosts ):
217 hosts.append( 'h{}'.format( i + 1 ) )
acsmars51a7fe02015-10-29 18:33:32 -0700218
219 arpingHostResults = main.TRUE
220 for host in hosts:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700221 if main.LincOE.arping( host, ethDevice=host + "-eth0" ):
acsmars51a7fe02015-10-29 18:33:32 -0700222 main.log.info( "Successfully reached host {} with arping".format( host ) )
223 else:
224 main.log.error( "Could not reach host {} with arping".format( host ) )
225 arpingHostResults = main.FALSE
226
227 utilities.assert_equals( expect=main.TRUE,
228 actual=arpingHostResults,
229 onpass="Successfully discovered all hosts",
230 onfail="Could not descover some hosts" )
231
232 def CASE23( self, main ):
233 """
234 Compare ONOS Topology to Mininet Topology
235 """
236 import json
Devin Lim58046fa2017-07-05 16:55:00 -0700237 try:
238 from tests.dependencies.topology import Topology
239 except ImportError:
240 main.log.error( "Topology not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700241 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700242 try:
243 main.topoRelated
244 except ( NameError, AttributeError ):
245 main.topoRelated = Topology()
acsmars51a7fe02015-10-29 18:33:32 -0700246 main.case( "Compare ONOS Topology view to Mininet topology" )
247 main.caseExplanation = "Compare topology elements between Mininet" +\
248 " and ONOS"
249
250 main.log.info( "Gathering topology information from Mininet" )
251 devicesResults = main.FALSE # Overall Boolean for device correctness
252 linksResults = main.FALSE # Overall Boolean for link correctness
253 hostsResults = main.FALSE # Overall Boolean for host correctness
254 deviceFails = [] # Nodes where devices are incorrect
255 linkFails = [] # Nodes where links are incorrect
256 hostFails = [] # Nodes where hosts are incorrect
257 attempts = main.checkTopoAttempts # Remaining Attempts
258
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700259 mnSwitches = main.switches
260 mnLinks = main.links
261 mnHosts = main.hosts
acsmars51a7fe02015-10-29 18:33:32 -0700262
Jon Hall70b2ff42015-11-17 15:49:44 -0800263 main.step( "Comparing Mininet topology to ONOS topology" )
acsmars51a7fe02015-10-29 18:33:32 -0700264
265 while ( attempts >= 0 ) and\
Jon Halle02505a2017-05-24 16:36:43 -0700266 ( not devicesResults or not linksResults or not hostsResults ):
acsmars51a7fe02015-10-29 18:33:32 -0700267 time.sleep( 2 )
268 if not devicesResults:
Devin Lim142b5342017-07-20 15:22:39 -0700269 devices = main.topoRelated.getAll( "devices", False )
270 ports = main.topoRelated.getAll( "ports", False )
acsmars51a7fe02015-10-29 18:33:32 -0700271 devicesResults = main.TRUE
272 deviceFails = [] # Reset for each attempt
273 if not linksResults:
Devin Lim142b5342017-07-20 15:22:39 -0700274 links = main.topoRelated.getAll( "links", False )
acsmars51a7fe02015-10-29 18:33:32 -0700275 linksResults = main.TRUE
276 linkFails = [] # Reset for each attempt
277 if not hostsResults:
Devin Lim142b5342017-07-20 15:22:39 -0700278 hosts = main.topoRelated.getAll( "hosts", False )
acsmars51a7fe02015-10-29 18:33:32 -0700279 hostsResults = main.TRUE
280 hostFails = [] # Reset for each attempt
281
282 # Check for matching topology on each node
Devin Lim142b5342017-07-20 15:22:39 -0700283 for controller in range( main.Cluster.numCtrls ):
acsmars51a7fe02015-10-29 18:33:32 -0700284 controllerStr = str( controller + 1 ) # ONOS node number
285 # Compare Devices
286 if devices[ controller ] and ports[ controller ] and\
Jon Halle02505a2017-05-24 16:36:43 -0700287 "Error" not in devices[ controller ] and\
288 "Error" not in ports[ controller ]:
acsmars51a7fe02015-10-29 18:33:32 -0700289
290 try:
291 deviceData = json.loads( devices[ controller ] )
292 portData = json.loads( ports[ controller ] )
Jon Halle02505a2017-05-24 16:36:43 -0700293 except ( TypeError, ValueError ):
294 main.log.error( "Could not load json:" + str( devices[ controller ] ) + ' or ' + str( ports[ controller ] ) )
acsmars51a7fe02015-10-29 18:33:32 -0700295 currentDevicesResult = main.FALSE
296 else:
297 if mnSwitches == len( deviceData ):
298 currentDevicesResult = main.TRUE
299 else:
300 currentDevicesResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700301 main.log.error( "Node {} only sees {} device(s) but {} exist".format(
Jon Halle02505a2017-05-24 16:36:43 -0700302 controllerStr, len( deviceData ), mnSwitches ) )
acsmars51a7fe02015-10-29 18:33:32 -0700303 else:
304 currentDevicesResult = main.FALSE
305 if not currentDevicesResult:
306 deviceFails.append( controllerStr )
307 devicesResults = devicesResults and currentDevicesResult
308 # Compare Links
309 if links[ controller ] and "Error" not in links[ controller ]:
310 try:
311 linkData = json.loads( links[ controller ] )
Jon Halle02505a2017-05-24 16:36:43 -0700312 except ( TypeError, ValueError ):
313 main.log.error( "Could not load json:" + str( links[ controller ] ) )
acsmars51a7fe02015-10-29 18:33:32 -0700314 currentLinksResult = main.FALSE
315 else:
316 if mnLinks == len( linkData ):
317 currentLinksResult = main.TRUE
318 else:
319 currentLinksResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700320 main.log.error( "Node {} only sees {} link(s) but {} exist".format(
Jon Halle02505a2017-05-24 16:36:43 -0700321 controllerStr, len( linkData ), mnLinks ) )
acsmars51a7fe02015-10-29 18:33:32 -0700322 else:
323 currentLinksResult = main.FALSE
324 if not currentLinksResult:
325 linkFails.append( controllerStr )
326 linksResults = linksResults and currentLinksResult
327 # Compare Hosts
328 if hosts[ controller ] and "Error" not in hosts[ controller ]:
329 try:
330 hostData = json.loads( hosts[ controller ] )
Jon Halle02505a2017-05-24 16:36:43 -0700331 except ( TypeError, ValueError ):
332 main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
acsmars51a7fe02015-10-29 18:33:32 -0700333 currentHostsResult = main.FALSE
334 else:
335 if mnHosts == len( hostData ):
336 currentHostsResult = main.TRUE
337 else:
338 currentHostsResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700339 main.log.error( "Node {} only sees {} host(s) but {} exist".format(
Jon Halle02505a2017-05-24 16:36:43 -0700340 controllerStr, len( hostData ), mnHosts ) )
acsmars51a7fe02015-10-29 18:33:32 -0700341 else:
342 currentHostsResult = main.FALSE
343 if not currentHostsResult:
344 hostFails.append( controllerStr )
345 hostsResults = hostsResults and currentHostsResult
346 # Decrement Attempts Remaining
347 attempts -= 1
348
349 utilities.assert_equals( expect=[],
350 actual=deviceFails,
351 onpass="ONOS correctly discovered all devices",
352 onfail="ONOS incorrectly discovered devices on nodes: " +
353 str( deviceFails ) )
354 utilities.assert_equals( expect=[],
355 actual=linkFails,
356 onpass="ONOS correctly discovered all links",
357 onfail="ONOS incorrectly discovered links on nodes: " +
358 str( linkFails ) )
359 utilities.assert_equals( expect=[],
360 actual=hostFails,
361 onpass="ONOS correctly discovered all hosts",
362 onfail="ONOS incorrectly discovered hosts on nodes: " +
363 str( hostFails ) )
364 if hostsResults and linksResults and devicesResults:
365 topoResults = main.TRUE
366 else:
367 topoResults = main.FALSE
368 utilities.assert_equals( expect=main.TRUE,
369 actual=topoResults,
370 onpass="ONOS correctly discovered the topology",
371 onfail="ONOS incorrectly discovered the topology" )
372
acsmars51a7fe02015-10-29 18:33:32 -0700373 def CASE31( self, main ):
374 import time
375 """
376 Add bidirectional point intents between 2 packet layer( mininet )
377 devices and ping mininet hosts
378 """
379 main.log.report(
380 "This testcase adds bidirectional point intents between 2 " +
381 "packet layer( mininet ) devices and ping mininet hosts" )
382 main.case( "Install point intents between 2 packet layer device and " +
383 "ping the hosts" )
384 main.caseExplanation = "This testcase adds bidirectional point intents between 2 " +\
385 "packet layer( mininet ) devices and ping mininet hosts"
386
387 main.step( "Adding point intents" )
388 checkFlowResult = main.TRUE
389 main.pIntentsId = []
Devin Lim142b5342017-07-20 15:22:39 -0700390 pIntent1 = main.Cluster.active( 0 ).CLI.addPointIntent(
Devin Lim752dd7b2017-06-27 14:40:03 -0700391 "of:0000000000000015/1",
392 "of:000000000000000b/2" )
acsmars51a7fe02015-10-29 18:33:32 -0700393 time.sleep( 10 )
Devin Lim142b5342017-07-20 15:22:39 -0700394 pIntent2 = main.Cluster.active( 0 ).CLI.addPointIntent(
Devin Lim752dd7b2017-06-27 14:40:03 -0700395 "of:000000000000000b/2",
396 "of:0000000000000015/1" )
acsmars51a7fe02015-10-29 18:33:32 -0700397 main.pIntentsId.append( pIntent1 )
398 main.pIntentsId.append( pIntent2 )
399 time.sleep( 10 )
Jon Halle02505a2017-05-24 16:36:43 -0700400 main.log.info( "Checking intents state" )
Devin Lim142b5342017-07-20 15:22:39 -0700401 checkStateResult = main.Cluster.active( 0 ).CLI.checkIntentState(
402 intentsId=main.pIntentsId )
acsmars51a7fe02015-10-29 18:33:32 -0700403 time.sleep( 10 )
Devin Lim142b5342017-07-20 15:22:39 -0700404 checkStateResult = utilities.retry( f=main.Cluster.active( 0 ).CLI.checkIntentState,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700405 retValue=main.FALSE, args=( main.pIntentsId, "INSTALLED" ),
406 sleep=main.checkIntentSleep, attempts=10 )
Jon Halle02505a2017-05-24 16:36:43 -0700407 main.log.info( "Checking flows state" )
Devin Lim142b5342017-07-20 15:22:39 -0700408 checkFlowResult = main.Cluster.active( 0 ).CLI.checkFlowsState()
acsmars51a7fe02015-10-29 18:33:32 -0700409 # Sleep for 10 seconds to provide time for the intent state to change
410 time.sleep( 10 )
Jon Halle02505a2017-05-24 16:36:43 -0700411 main.log.info( "Checking intents state one more time" )
Devin Lim142b5342017-07-20 15:22:39 -0700412 checkStateResult = main.Cluster.active( 0 ).CLI.checkIntentState(
Jon Halle02505a2017-05-24 16:36:43 -0700413 intentsId=main.pIntentsId )
Jeremye4bc7132016-03-30 14:04:01 -0700414
acsmars51a7fe02015-10-29 18:33:32 -0700415 if checkStateResult and checkFlowResult:
416 addIntentsResult = main.TRUE
417 else:
418 addIntentsResult = main.FALSE
419 utilities.assert_equals(
420 expect=main.TRUE,
421 actual=addIntentsResult,
422 onpass="Successfully added point intents",
Jon Halle02505a2017-05-24 16:36:43 -0700423 onfail="Failed to add point intents" )
acsmars51a7fe02015-10-29 18:33:32 -0700424
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700425 pingResult = main.FALSE
acsmars51a7fe02015-10-29 18:33:32 -0700426
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700427 if not addIntentsResult:
428 main.log.error( "Intents were not properly installed. Skipping ping." )
429
430 else:
431 main.step( "Ping h1 and h2" )
432 pingResult = main.LincOE.pingHostOptical( src="h1", target="h2" )
acsmars51a7fe02015-10-29 18:33:32 -0700433 utilities.assert_equals(
434 expect=main.TRUE,
435 actual=pingResult,
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700436 onpass="Successfully pinged h1 and h2",
Jon Halle02505a2017-05-24 16:36:43 -0700437 onfail="Failed to ping between h1 and h2" )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700438
439 main.step( "Remove Point to Point intents" )
Devin Lim752dd7b2017-06-27 14:40:03 -0700440 removeResult = main.TRUE
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700441 # Check remaining intents
442 try:
Devin Lim142b5342017-07-20 15:22:39 -0700443 intentsJson = json.loads( main.Cluster.active( 0 ).CLI.intents() )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700444 main.log.debug( intentsJson )
Devin Lim142b5342017-07-20 15:22:39 -0700445 main.Cluster.active( 0 ).CLI.removeIntent( intentId=pIntent1, purge=True )
446 main.Cluster.active( 0 ).CLI.removeIntent( intentId=pIntent2, purge=True )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700447 for intents in intentsJson:
Devin Lim142b5342017-07-20 15:22:39 -0700448 main.Cluster.active( 0 ).CLI.removeIntent( intentId=intents.get( 'id' ),
449 app='org.onosproject.cli',
450 purge=True )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700451 time.sleep( 15 )
452
Devin Lim142b5342017-07-20 15:22:39 -0700453 for ctrl in main.Cluster.active():
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700454 if not any( intent.get( 'state' ) == 'WITHDRAWING' for intent
455 in json.loads( ctrl.CLI.intents() ) ):
456 main.log.debug( json.loads( ctrl.CLI.intents() ) )
457 removeResult = main.FALSE
458 break
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700459 else:
460 removeResult = main.TRUE
461 except ( TypeError, ValueError ):
Devin Lim142b5342017-07-20 15:22:39 -0700462 main.log.error( "Cannot see intents on " + main.Cluster.active( 0 ).name +
Jon Halle02505a2017-05-24 16:36:43 -0700463 ". Removing all intents." )
Devin Lim142b5342017-07-20 15:22:39 -0700464 main.Cluster.active( 0 ).CLI.removeAllIntents( purge=True )
465 main.Cluster.active( 0 ).CLI.removeAllIntents( purge=True, app='org.onosproject.cli' )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700466
467 utilities.assert_equals( expect=main.TRUE,
468 actual=removeResult,
469 onpass="Successfully removed host intents",
470 onfail="Failed to remove host intents" )
acsmars51a7fe02015-10-29 18:33:32 -0700471
472 def CASE32( self ):
473 """
474 Add host intents between 2 packet layer host
475 """
476 import time
477 import json
478 main.log.report( "Adding host intents between 2 optical layer host" )
479 main.case( "Test add host intents between optical layer host" )
480 main.caseExplanation = "Test host intents between 2 optical layer host"
481
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700482 main.step( "Creating list of hosts" )
483 hostnum = 0
484 try:
485 hostData = json.loads( hosts[ controller ] )
486 except( TypeError, ValueError ):
Jon Halle02505a2017-05-24 16:36:43 -0700487 main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700488
acsmars51a7fe02015-10-29 18:33:32 -0700489 main.step( "Adding host intents to h1 and h2" )
acsmars51a7fe02015-10-29 18:33:32 -0700490 hostId = []
491 # Listing host MAC addresses
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700492 for host in hostData:
Jon Halle02505a2017-05-24 16:36:43 -0700493 hostId.append( host.get( "id" ) )
acsmars51a7fe02015-10-29 18:33:32 -0700494 host1 = hostId[ 0 ]
495 host2 = hostId[ 1 ]
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700496 main.log.debug( host1 )
497 main.log.debug( host2 )
acsmars51a7fe02015-10-29 18:33:32 -0700498
499 intentsId = []
Devin Lim142b5342017-07-20 15:22:39 -0700500 intent1 = main.Cluster.active( 0 ).CLI.addHostIntent( hostIdOne=host1,
501 hostIdTwo=host2 )
acsmars51a7fe02015-10-29 18:33:32 -0700502 intentsId.append( intent1 )
503 # Checking intents state before pinging
504 main.log.info( "Checking intents state" )
Devin Lim142b5342017-07-20 15:22:39 -0700505 intentResult = utilities.retry( f=main.Cluster.active( 0 ).CLI.checkIntentState,
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700506 retValue=main.FALSE, args=intentsId,
507 sleep=main.checkIntentSleep, attempts=10 )
acsmars51a7fe02015-10-29 18:33:32 -0700508
509 # If intent state is still wrong, display intent states
510 if not intentResult:
Devin Lim142b5342017-07-20 15:22:39 -0700511 main.log.error( main.Cluster.active( 0 ).CLI.intents() )
Jeremye4bc7132016-03-30 14:04:01 -0700512
acsmars51a7fe02015-10-29 18:33:32 -0700513 utilities.assert_equals( expect=main.TRUE,
514 actual=intentResult,
515 onpass="All intents are in INSTALLED state ",
516 onfail="Some of the intents are not in " +
517 "INSTALLED state " )
518
519 if not intentResult:
520 main.log.error( "Intents were not properly installed. Skipping Ping" )
521 else:
522 # Pinging h1 to h2 and then ping h2 to h1
523 main.step( "Pinging h1 and h2" )
524 pingResult = main.TRUE
525 pingResult = main.LincOE.pingHostOptical( src="h1", target="h2" ) \
Jon Halle02505a2017-05-24 16:36:43 -0700526 and main.LincOE.pingHostOptical( src="h2", target="h1" )
Jeremye4bc7132016-03-30 14:04:01 -0700527
acsmars51a7fe02015-10-29 18:33:32 -0700528 utilities.assert_equals( expect=main.TRUE,
529 actual=pingResult,
530 onpass="Pinged successfully between h1 and h2",
531 onfail="Pinged failed between h1 and h2" )
532
533 # Removed all added host intents
534 main.step( "Removing host intents" )
535 removeResult = main.TRUE
536 # Check remaining intents
Jeremy7134f5b2016-04-05 13:50:21 -0700537 try:
Devin Lim142b5342017-07-20 15:22:39 -0700538 intentsJson = json.loads( main.Cluster.active( 0 ).CLI.intents() )
539 main.Cluster.active( 0 ).CLI.removeIntent( intentId=intent1, purge=True )
Jon Halle02505a2017-05-24 16:36:43 -0700540 main.log.debug( intentsJson )
Jeremy7134f5b2016-04-05 13:50:21 -0700541 for intents in intentsJson:
Devin Lim142b5342017-07-20 15:22:39 -0700542 main.Cluster.active( 0 ).CLI.removeIntent( intentId=intents.get( 'id' ),
543 app='org.onosproject.optical',
544 purge=True )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700545 time.sleep( 15 )
acsmars51a7fe02015-10-29 18:33:32 -0700546
Devin Lim142b5342017-07-20 15:22:39 -0700547 for ctrl in main.Cluster.active():
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700548 if not any( intent.get( 'state' ) == 'WITHDRAWING' for intent
549 in json.loads( ctrl.CLI.intents() ) ):
550 main.log.debug( json.loads( ctrl.CLI.intents() ) )
551 removeResult = main.FALSE
552 break
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700553 else:
554 removeResult = main.TRUE
Jeremy7134f5b2016-04-05 13:50:21 -0700555 except ( TypeError, ValueError ):
Devin Lim142b5342017-07-20 15:22:39 -0700556 main.log.error( "Cannot see intents on " + main.Cluster.active( 0 ).name +
Jon Halle02505a2017-05-24 16:36:43 -0700557 ". Removing all intents." )
Devin Lim142b5342017-07-20 15:22:39 -0700558 main.Cluster.active( 0 ).CLI.removeAllIntents( purge=True )
559 main.Cluster.active( 0 ).CLI.removeAllIntents( purge=True, app='org.onosproject.optical' )
Jeremy7134f5b2016-04-05 13:50:21 -0700560
561 utilities.assert_equals( expect=main.TRUE,
562 actual=removeResult,
563 onpass="Successfully removed host intents",
Chiyu Chengef109502016-11-21 15:51:38 -0800564 onfail="Failed to remove host intents" )