blob: 00d5cab67c92259c8327199c5231f92d2551d3ba [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" )
Devin Lim44075962017-08-11 10:56:37 -070048 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070049 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.assertReturnString = '' # Assembled assert return string
Jon Halle02505a2017-05-24 16:36:43 -070067 main.cycle = 0 # How many times FUNCintent has run through its tests
acsmars51a7fe02015-10-29 18:33:32 -070068 # -- INIT SECTION, ONLY RUNS ONCE -- #
Devin Lim142b5342017-07-20 15:22:39 -070069 stepResult = main.testSetUp.envSetup()
acsmars51a7fe02015-10-29 18:33:32 -070070 except Exception as e:
Devin Lim58046fa2017-07-05 16:55:00 -070071 main.testSetUp.envSetupException( e )
72 main.testSetUp.evnSetupConclusion( stepResult )
acsmars51a7fe02015-10-29 18:33:32 -070073
74 def CASE2( self, main ):
75 """
Devin Lim58046fa2017-07-05 16:55:00 -070076 - Set up cell
77 - Create cell file
78 - Set cell file
79 - Verify cell file
80 - Kill ONOS process
81 - Uninstall ONOS cluster
82 - Verify ONOS start up
83 - Install ONOS cluster
84 - Connect to cli
acsmars51a7fe02015-10-29 18:33:32 -070085 """
Jeremye4bc7132016-03-30 14:04:01 -070086 main.flowCompiler = "Flow Rules"
Devin Lim142b5342017-07-20 15:22:39 -070087 main.testSetUp.ONOSSetUp( main.LincOE, main.Cluster, True )
acsmars51a7fe02015-10-29 18:33:32 -070088
acsmars51a7fe02015-10-29 18:33:32 -070089 def CASE10( self, main ):
90 """
91 Start Mininet opticalTest Topology
92 """
Devin Lim58046fa2017-07-05 16:55:00 -070093
Jon Halle02505a2017-05-24 16:36:43 -070094 main.case( "Mininet with Linc-OE startup" )
Devin Lim752dd7b2017-06-27 14:40:03 -070095 main.step( "Push TopoDDriver.json to ONOS through onos-netcfg" )
Devin Lim02075272017-07-10 15:33:21 -070096 topoResult = True
Devin Lim142b5342017-07-20 15:22:39 -070097 for ctrl in main.Cluster.active():
Devin Lim02075272017-07-10 15:33:21 -070098 topoResult = topoResult and \
Devin Lim142b5342017-07-20 15:22:39 -070099 main.ONOSbench.onosNetCfg(controllerIp=ctrl.ipAddress,
100 path=main.dependencyPath,
Devin Lim02075272017-07-10 15:33:21 -0700101 fileName="TopoDDriver.json")
Devin Lim752dd7b2017-06-27 14:40:03 -0700102 #Exit if topology did not load properly
103 if not topoResult:
Devin Lim44075962017-08-11 10:56:37 -0700104 main.cleanAndExit()
Devin Lim752dd7b2017-06-27 14:40:03 -0700105
acsmars51a7fe02015-10-29 18:33:32 -0700106 main.caseExplanation = "Start opticalTest.py topology included with ONOS"
107 main.step( "Starting mininet and LINC-OE" )
acsmars51a7fe02015-10-29 18:33:32 -0700108 time.sleep( 10 )
Devin Lim142b5342017-07-20 15:22:39 -0700109 controllerIPs = ','.join( main.Cluster.getIps() )
Devin Lim752dd7b2017-06-27 14:40:03 -0700110 cIps = ""
Devin Lim58046fa2017-07-05 16:55:00 -0700111 for i in range( 0, 4 ):
Devin Lim752dd7b2017-06-27 14:40:03 -0700112 cIps += controllerIPs + ' '
113 opticalMnScript = main.LincOE.runOpticalMnScript( ctrllerIP=cIps, topology=main.opticalTopo )
acsmars51a7fe02015-10-29 18:33:32 -0700114 topoResult = opticalMnScript
115 utilities.assert_equals(
116 expect=main.TRUE,
117 actual=topoResult,
118 onpass="Started the topology successfully ",
Jon Halle02505a2017-05-24 16:36:43 -0700119 onfail="Failed to start the topology" )
acsmars51a7fe02015-10-29 18:33:32 -0700120
acsmars51a7fe02015-10-29 18:33:32 -0700121 def CASE14( self, main ):
122 """
123 Stop mininet
124 """
Devin Lim58046fa2017-07-05 16:55:00 -0700125 try:
126 from tests.dependencies.utils import Utils
127 except ImportError:
128 main.log.error( "Utils not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700129 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700130 try:
131 main.Utils
132 except ( NameError, AttributeError ):
133 main.Utils = Utils()
134 main.Utils.mininetCleanIntro()
135 topoResult = main.Utils.mininetCleanup( main.LincOE, timeout=180 )
acsmars51a7fe02015-10-29 18:33:32 -0700136 # Exit if topology did not load properly
137 if not topoResult:
Devin Lim44075962017-08-11 10:56:37 -0700138 main.cleanAndExit()
acsmars51a7fe02015-10-29 18:33:32 -0700139
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700140 def CASE16( self, main ):
141 """
142 Balance Masters
143 """
144 main.case( "Balance mastership of switches" )
145 main.step( "Balancing mastership of switches" )
146
147 balanceResult = main.FALSE
Devin Lim142b5342017-07-20 15:22:39 -0700148 balanceResult = utilities.retry( f=main.Cluster.active( 0 ).CLI.balanceMasters, retValue=main.FALSE, args=[] )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700149
150 utilities.assert_equals( expect=main.TRUE,
151 actual=balanceResult,
152 onpass="Successfully balanced mastership of switches",
153 onfail="Failed to balance mastership of switches" )
154 if not balanceResult:
155 main.initialized = main.FALSE
156
Jeremye4bc7132016-03-30 14:04:01 -0700157 def CASE17( self, main ):
158 """
159 Use Flow Objectives
160 """
161 main.case( "Enable intent compilation using Flow Objectives" )
162 main.step( "Enabling Flow Objectives" )
163
164 main.flowCompiler = "Flow Objectives"
165
166 cmd = "org.onosproject.net.intent.impl.compiler.IntentConfigurableRegistrator"
167
Devin Lim142b5342017-07-20 15:22:39 -0700168 stepResult = main.Cluster.active( 0 ).CLI.setCfg( component=cmd,
169 propName="useFlowObjectives", value="true" )
170 stepResult &= main.Cluster.active( 0 ).CLI.setCfg( component=cmd,
171 propName="defaultFlowObjectiveCompiler",
172 value='org.onosproject.net.intent.impl.compiler.LinkCollectionIntentObjectiveCompiler' )
Jeremye4bc7132016-03-30 14:04:01 -0700173
174 utilities.assert_equals( expect=main.TRUE,
175 actual=stepResult,
176 onpass="Successfully activated Flow Objectives",
177 onfail="Failed to activate Flow Objectives" )
178
Jeremy Songster17147f22016-05-31 18:30:52 -0700179 def CASE19( self, main ):
180 """
181 Copy the karaf.log files after each testcase cycle
182 """
Devin Lim58046fa2017-07-05 16:55:00 -0700183 try:
184 from tests.dependencies.utils import Utils
185 except ImportError:
186 main.log.error( "Utils not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700187 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700188 try:
189 main.Utils
190 except ( NameError, AttributeError ):
191 main.Utils = Utils()
Devin Lim142b5342017-07-20 15:22:39 -0700192 main.Utils.copyKarafLog( "cycle" + str( main.cycle ) )
Jon Halle02505a2017-05-24 16:36:43 -0700193 def CASE21( self, main ):
acsmars51a7fe02015-10-29 18:33:32 -0700194 """
195 Run pingall to discover all hosts
196 """
197 main.case( "Running Pingall" )
198 main.caseExplanation = "Use pingall to discover all hosts. Pingall is expected to fail."
199 main.step( "Discover Hosts through Pingall" )
Jon Halle02505a2017-05-24 16:36:43 -0700200 pingResult = main.LincOE.pingall( timeout=120 )
acsmars51a7fe02015-10-29 18:33:32 -0700201
202 utilities.assert_equals( expect=main.FALSE,
203 actual=pingResult,
204 onpass="Pingall Completed",
205 onfail="Pingall did not complete or did not return fales" )
206
Jon Halle02505a2017-05-24 16:36:43 -0700207 def CASE22( self, main ):
acsmars51a7fe02015-10-29 18:33:32 -0700208 """
209 Send arpings to discover all hosts
210 """
211 main.case( "Discover Hosts with arping" )
212 main.caseExplanation = "Send arpings between all the hosts to discover and verify them"
213
214 main.step( "Send arping between all hosts" )
215
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700216 hosts = []
217 for i in range( main.hosts ):
218 hosts.append( 'h{}'.format( i + 1 ) )
acsmars51a7fe02015-10-29 18:33:32 -0700219
220 arpingHostResults = main.TRUE
221 for host in hosts:
Devin Lim752dd7b2017-06-27 14:40:03 -0700222 if main.LincOE.arping( host, ethDevice=host+"-eth0" ):
acsmars51a7fe02015-10-29 18:33:32 -0700223 main.log.info( "Successfully reached host {} with arping".format( host ) )
224 else:
225 main.log.error( "Could not reach host {} with arping".format( host ) )
226 arpingHostResults = main.FALSE
227
228 utilities.assert_equals( expect=main.TRUE,
229 actual=arpingHostResults,
230 onpass="Successfully discovered all hosts",
231 onfail="Could not descover some hosts" )
232
233 def CASE23( self, main ):
234 """
235 Compare ONOS Topology to Mininet Topology
236 """
237 import json
Devin Lim58046fa2017-07-05 16:55:00 -0700238 try:
239 from tests.dependencies.topology import Topology
240 except ImportError:
241 main.log.error( "Topology not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700242 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700243 try:
244 main.topoRelated
245 except ( NameError, AttributeError ):
246 main.topoRelated = Topology()
acsmars51a7fe02015-10-29 18:33:32 -0700247 main.case( "Compare ONOS Topology view to Mininet topology" )
248 main.caseExplanation = "Compare topology elements between Mininet" +\
249 " and ONOS"
250
251 main.log.info( "Gathering topology information from Mininet" )
252 devicesResults = main.FALSE # Overall Boolean for device correctness
253 linksResults = main.FALSE # Overall Boolean for link correctness
254 hostsResults = main.FALSE # Overall Boolean for host correctness
255 deviceFails = [] # Nodes where devices are incorrect
256 linkFails = [] # Nodes where links are incorrect
257 hostFails = [] # Nodes where hosts are incorrect
258 attempts = main.checkTopoAttempts # Remaining Attempts
259
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700260 mnSwitches = main.switches
261 mnLinks = main.links
262 mnHosts = main.hosts
acsmars51a7fe02015-10-29 18:33:32 -0700263
Jon Hall70b2ff42015-11-17 15:49:44 -0800264 main.step( "Comparing Mininet topology to ONOS topology" )
acsmars51a7fe02015-10-29 18:33:32 -0700265
266 while ( attempts >= 0 ) and\
Jon Halle02505a2017-05-24 16:36:43 -0700267 ( not devicesResults or not linksResults or not hostsResults ):
acsmars51a7fe02015-10-29 18:33:32 -0700268 time.sleep( 2 )
269 if not devicesResults:
Devin Lim142b5342017-07-20 15:22:39 -0700270 devices = main.topoRelated.getAll( "devices", False )
271 ports = main.topoRelated.getAll( "ports", False )
acsmars51a7fe02015-10-29 18:33:32 -0700272 devicesResults = main.TRUE
273 deviceFails = [] # Reset for each attempt
274 if not linksResults:
Devin Lim142b5342017-07-20 15:22:39 -0700275 links = main.topoRelated.getAll( "links", False )
acsmars51a7fe02015-10-29 18:33:32 -0700276 linksResults = main.TRUE
277 linkFails = [] # Reset for each attempt
278 if not hostsResults:
Devin Lim142b5342017-07-20 15:22:39 -0700279 hosts = main.topoRelated.getAll( "hosts", False )
acsmars51a7fe02015-10-29 18:33:32 -0700280 hostsResults = main.TRUE
281 hostFails = [] # Reset for each attempt
282
283 # Check for matching topology on each node
Devin Lim142b5342017-07-20 15:22:39 -0700284 for controller in range( main.Cluster.numCtrls ):
acsmars51a7fe02015-10-29 18:33:32 -0700285 controllerStr = str( controller + 1 ) # ONOS node number
286 # Compare Devices
287 if devices[ controller ] and ports[ controller ] and\
Jon Halle02505a2017-05-24 16:36:43 -0700288 "Error" not in devices[ controller ] and\
289 "Error" not in ports[ controller ]:
acsmars51a7fe02015-10-29 18:33:32 -0700290
291 try:
292 deviceData = json.loads( devices[ controller ] )
293 portData = json.loads( ports[ controller ] )
Jon Halle02505a2017-05-24 16:36:43 -0700294 except ( TypeError, ValueError ):
295 main.log.error( "Could not load json:" + str( devices[ controller ] ) + ' or ' + str( ports[ controller ] ) )
acsmars51a7fe02015-10-29 18:33:32 -0700296 currentDevicesResult = main.FALSE
297 else:
298 if mnSwitches == len( deviceData ):
299 currentDevicesResult = main.TRUE
300 else:
301 currentDevicesResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700302 main.log.error( "Node {} only sees {} device(s) but {} exist".format(
Jon Halle02505a2017-05-24 16:36:43 -0700303 controllerStr, len( deviceData ), mnSwitches ) )
acsmars51a7fe02015-10-29 18:33:32 -0700304 else:
305 currentDevicesResult = main.FALSE
306 if not currentDevicesResult:
307 deviceFails.append( controllerStr )
308 devicesResults = devicesResults and currentDevicesResult
309 # Compare Links
310 if links[ controller ] and "Error" not in links[ controller ]:
311 try:
312 linkData = json.loads( links[ controller ] )
Jon Halle02505a2017-05-24 16:36:43 -0700313 except ( TypeError, ValueError ):
314 main.log.error( "Could not load json:" + str( links[ controller ] ) )
acsmars51a7fe02015-10-29 18:33:32 -0700315 currentLinksResult = main.FALSE
316 else:
317 if mnLinks == len( linkData ):
318 currentLinksResult = main.TRUE
319 else:
320 currentLinksResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700321 main.log.error( "Node {} only sees {} link(s) but {} exist".format(
Jon Halle02505a2017-05-24 16:36:43 -0700322 controllerStr, len( linkData ), mnLinks ) )
acsmars51a7fe02015-10-29 18:33:32 -0700323 else:
324 currentLinksResult = main.FALSE
325 if not currentLinksResult:
326 linkFails.append( controllerStr )
327 linksResults = linksResults and currentLinksResult
328 # Compare Hosts
329 if hosts[ controller ] and "Error" not in hosts[ controller ]:
330 try:
331 hostData = json.loads( hosts[ controller ] )
Jon Halle02505a2017-05-24 16:36:43 -0700332 except ( TypeError, ValueError ):
333 main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
acsmars51a7fe02015-10-29 18:33:32 -0700334 currentHostsResult = main.FALSE
335 else:
336 if mnHosts == len( hostData ):
337 currentHostsResult = main.TRUE
338 else:
339 currentHostsResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700340 main.log.error( "Node {} only sees {} host(s) but {} exist".format(
Jon Halle02505a2017-05-24 16:36:43 -0700341 controllerStr, len( hostData ), mnHosts ) )
acsmars51a7fe02015-10-29 18:33:32 -0700342 else:
343 currentHostsResult = main.FALSE
344 if not currentHostsResult:
345 hostFails.append( controllerStr )
346 hostsResults = hostsResults and currentHostsResult
347 # Decrement Attempts Remaining
348 attempts -= 1
349
350 utilities.assert_equals( expect=[],
351 actual=deviceFails,
352 onpass="ONOS correctly discovered all devices",
353 onfail="ONOS incorrectly discovered devices on nodes: " +
354 str( deviceFails ) )
355 utilities.assert_equals( expect=[],
356 actual=linkFails,
357 onpass="ONOS correctly discovered all links",
358 onfail="ONOS incorrectly discovered links on nodes: " +
359 str( linkFails ) )
360 utilities.assert_equals( expect=[],
361 actual=hostFails,
362 onpass="ONOS correctly discovered all hosts",
363 onfail="ONOS incorrectly discovered hosts on nodes: " +
364 str( hostFails ) )
365 if hostsResults and linksResults and devicesResults:
366 topoResults = main.TRUE
367 else:
368 topoResults = main.FALSE
369 utilities.assert_equals( expect=main.TRUE,
370 actual=topoResults,
371 onpass="ONOS correctly discovered the topology",
372 onfail="ONOS incorrectly discovered the topology" )
373
Devin Lim58046fa2017-07-05 16:55:00 -0700374
acsmars51a7fe02015-10-29 18:33:32 -0700375 def CASE31( self, main ):
376 import time
377 """
378 Add bidirectional point intents between 2 packet layer( mininet )
379 devices and ping mininet hosts
380 """
381 main.log.report(
382 "This testcase adds bidirectional point intents between 2 " +
383 "packet layer( mininet ) devices and ping mininet hosts" )
384 main.case( "Install point intents between 2 packet layer device and " +
385 "ping the hosts" )
386 main.caseExplanation = "This testcase adds bidirectional point intents between 2 " +\
387 "packet layer( mininet ) devices and ping mininet hosts"
388
389 main.step( "Adding point intents" )
390 checkFlowResult = main.TRUE
391 main.pIntentsId = []
Devin Lim142b5342017-07-20 15:22:39 -0700392 pIntent1 = main.Cluster.active( 0 ).CLI.addPointIntent(
Devin Lim752dd7b2017-06-27 14:40:03 -0700393 "of:0000000000000015/1",
394 "of:000000000000000b/2" )
acsmars51a7fe02015-10-29 18:33:32 -0700395 time.sleep( 10 )
Devin Lim142b5342017-07-20 15:22:39 -0700396 pIntent2 = main.Cluster.active( 0 ).CLI.addPointIntent(
Devin Lim752dd7b2017-06-27 14:40:03 -0700397 "of:000000000000000b/2",
398 "of:0000000000000015/1" )
acsmars51a7fe02015-10-29 18:33:32 -0700399 main.pIntentsId.append( pIntent1 )
400 main.pIntentsId.append( pIntent2 )
401 time.sleep( 10 )
Jon Halle02505a2017-05-24 16:36:43 -0700402 main.log.info( "Checking intents state" )
Devin Lim142b5342017-07-20 15:22:39 -0700403 checkStateResult = main.Cluster.active( 0 ).CLI.checkIntentState(
404 intentsId=main.pIntentsId )
acsmars51a7fe02015-10-29 18:33:32 -0700405 time.sleep( 10 )
Devin Lim142b5342017-07-20 15:22:39 -0700406 checkStateResult = utilities.retry( f=main.Cluster.active( 0 ).CLI.checkIntentState,
Devin Lim752dd7b2017-06-27 14:40:03 -0700407 retValue=main.FALSE, args=( main.pIntentsId, "INSTALLED" ),
408 sleep=main.checkIntentSleep, attempts=10 )
Jon Halle02505a2017-05-24 16:36:43 -0700409 main.log.info( "Checking flows state" )
Devin Lim142b5342017-07-20 15:22:39 -0700410 checkFlowResult = main.Cluster.active( 0 ).CLI.checkFlowsState()
acsmars51a7fe02015-10-29 18:33:32 -0700411 # Sleep for 10 seconds to provide time for the intent state to change
412 time.sleep( 10 )
Jon Halle02505a2017-05-24 16:36:43 -0700413 main.log.info( "Checking intents state one more time" )
Devin Lim142b5342017-07-20 15:22:39 -0700414 checkStateResult = main.Cluster.active( 0 ).CLI.checkIntentState(
Jon Halle02505a2017-05-24 16:36:43 -0700415 intentsId=main.pIntentsId )
Jeremye4bc7132016-03-30 14:04:01 -0700416
acsmars51a7fe02015-10-29 18:33:32 -0700417 if checkStateResult and checkFlowResult:
418 addIntentsResult = main.TRUE
419 else:
420 addIntentsResult = main.FALSE
421 utilities.assert_equals(
422 expect=main.TRUE,
423 actual=addIntentsResult,
424 onpass="Successfully added point intents",
Jon Halle02505a2017-05-24 16:36:43 -0700425 onfail="Failed to add point intents" )
acsmars51a7fe02015-10-29 18:33:32 -0700426
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700427 pingResult = main.FALSE
acsmars51a7fe02015-10-29 18:33:32 -0700428
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700429 if not addIntentsResult:
430 main.log.error( "Intents were not properly installed. Skipping ping." )
431
432 else:
433 main.step( "Ping h1 and h2" )
434 pingResult = main.LincOE.pingHostOptical( src="h1", target="h2" )
acsmars51a7fe02015-10-29 18:33:32 -0700435 utilities.assert_equals(
436 expect=main.TRUE,
437 actual=pingResult,
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700438 onpass="Successfully pinged h1 and h2",
Jon Halle02505a2017-05-24 16:36:43 -0700439 onfail="Failed to ping between h1 and h2" )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700440
441 main.step( "Remove Point to Point intents" )
Devin Lim752dd7b2017-06-27 14:40:03 -0700442 removeResult = main.TRUE
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700443 # Check remaining intents
444 try:
Devin Lim142b5342017-07-20 15:22:39 -0700445 intentsJson = json.loads( main.Cluster.active( 0 ).CLI.intents() )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700446 main.log.debug( intentsJson )
Devin Lim142b5342017-07-20 15:22:39 -0700447 main.Cluster.active( 0 ).CLI.removeIntent( intentId=pIntent1, purge=True )
448 main.Cluster.active( 0 ).CLI.removeIntent( intentId=pIntent2, purge=True )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700449 for intents in intentsJson:
Devin Lim142b5342017-07-20 15:22:39 -0700450 main.Cluster.active( 0 ).CLI.removeIntent( intentId=intents.get( 'id' ),
451 app='org.onosproject.cli',
452 purge=True )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700453 time.sleep( 15 )
454
Devin Lim142b5342017-07-20 15:22:39 -0700455 for ctrl in main.Cluster.active():
Devin Lim752dd7b2017-06-27 14:40:03 -0700456 if not any ( intent.get('state') == 'WITHDRAWING' for intent
Devin Lim142b5342017-07-20 15:22:39 -0700457 in json.loads( ctrl.CLI.intents() ) ):
458 main.log.debug( json.loads( ctrl.CLI.intents() ) )
Devin Lim752dd7b2017-06-27 14:40:03 -0700459 removeResult = main.FALSE
460 break
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700461 else:
462 removeResult = main.TRUE
463 except ( TypeError, ValueError ):
Devin Lim142b5342017-07-20 15:22:39 -0700464 main.log.error( "Cannot see intents on " + main.Cluster.active( 0 ).name +
Jon Halle02505a2017-05-24 16:36:43 -0700465 ". Removing all intents." )
Devin Lim142b5342017-07-20 15:22:39 -0700466 main.Cluster.active( 0 ).CLI.removeAllIntents( purge=True )
467 main.Cluster.active( 0 ).CLI.removeAllIntents( purge=True, app='org.onosproject.cli' )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700468
469 utilities.assert_equals( expect=main.TRUE,
470 actual=removeResult,
471 onpass="Successfully removed host intents",
472 onfail="Failed to remove host intents" )
acsmars51a7fe02015-10-29 18:33:32 -0700473
474 def CASE32( self ):
475 """
476 Add host intents between 2 packet layer host
477 """
478 import time
479 import json
480 main.log.report( "Adding host intents between 2 optical layer host" )
481 main.case( "Test add host intents between optical layer host" )
482 main.caseExplanation = "Test host intents between 2 optical layer host"
483
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700484 main.step( "Creating list of hosts" )
485 hostnum = 0
486 try:
487 hostData = json.loads( hosts[ controller ] )
488 except( TypeError, ValueError ):
Jon Halle02505a2017-05-24 16:36:43 -0700489 main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700490
acsmars51a7fe02015-10-29 18:33:32 -0700491 main.step( "Adding host intents to h1 and h2" )
acsmars51a7fe02015-10-29 18:33:32 -0700492 hostId = []
493 # Listing host MAC addresses
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700494 for host in hostData:
Jon Halle02505a2017-05-24 16:36:43 -0700495 hostId.append( host.get( "id" ) )
acsmars51a7fe02015-10-29 18:33:32 -0700496 host1 = hostId[ 0 ]
497 host2 = hostId[ 1 ]
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700498 main.log.debug( host1 )
499 main.log.debug( host2 )
acsmars51a7fe02015-10-29 18:33:32 -0700500
501 intentsId = []
Devin Lim142b5342017-07-20 15:22:39 -0700502 intent1 = main.Cluster.active( 0 ).CLI.addHostIntent( hostIdOne=host1,
503 hostIdTwo=host2 )
acsmars51a7fe02015-10-29 18:33:32 -0700504 intentsId.append( intent1 )
505 # Checking intents state before pinging
506 main.log.info( "Checking intents state" )
Devin Lim142b5342017-07-20 15:22:39 -0700507 intentResult = utilities.retry( f=main.Cluster.active( 0 ).CLI.checkIntentState,
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700508 retValue=main.FALSE, args=intentsId,
509 sleep=main.checkIntentSleep, attempts=10 )
acsmars51a7fe02015-10-29 18:33:32 -0700510
511 # If intent state is still wrong, display intent states
512 if not intentResult:
Devin Lim142b5342017-07-20 15:22:39 -0700513 main.log.error( main.Cluster.active( 0 ).CLI.intents() )
Jeremye4bc7132016-03-30 14:04:01 -0700514
acsmars51a7fe02015-10-29 18:33:32 -0700515 utilities.assert_equals( expect=main.TRUE,
516 actual=intentResult,
517 onpass="All intents are in INSTALLED state ",
518 onfail="Some of the intents are not in " +
519 "INSTALLED state " )
520
521 if not intentResult:
522 main.log.error( "Intents were not properly installed. Skipping Ping" )
523 else:
524 # Pinging h1 to h2 and then ping h2 to h1
525 main.step( "Pinging h1 and h2" )
526 pingResult = main.TRUE
527 pingResult = main.LincOE.pingHostOptical( src="h1", target="h2" ) \
Jon Halle02505a2017-05-24 16:36:43 -0700528 and main.LincOE.pingHostOptical( src="h2", target="h1" )
Jeremye4bc7132016-03-30 14:04:01 -0700529
acsmars51a7fe02015-10-29 18:33:32 -0700530 utilities.assert_equals( expect=main.TRUE,
531 actual=pingResult,
532 onpass="Pinged successfully between h1 and h2",
533 onfail="Pinged failed between h1 and h2" )
534
535 # Removed all added host intents
536 main.step( "Removing host intents" )
537 removeResult = main.TRUE
538 # Check remaining intents
Jeremy7134f5b2016-04-05 13:50:21 -0700539 try:
Devin Lim142b5342017-07-20 15:22:39 -0700540 intentsJson = json.loads( main.Cluster.active( 0 ).CLI.intents() )
541 main.Cluster.active( 0 ).CLI.removeIntent( intentId=intent1, purge=True )
Jon Halle02505a2017-05-24 16:36:43 -0700542 main.log.debug( intentsJson )
Jeremy7134f5b2016-04-05 13:50:21 -0700543 for intents in intentsJson:
Devin Lim142b5342017-07-20 15:22:39 -0700544 main.Cluster.active( 0 ).CLI.removeIntent( intentId=intents.get( 'id' ),
545 app='org.onosproject.optical',
546 purge=True )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700547 time.sleep( 15 )
acsmars51a7fe02015-10-29 18:33:32 -0700548
Devin Lim142b5342017-07-20 15:22:39 -0700549 for ctrl in main.Cluster.active():
Devin Lim752dd7b2017-06-27 14:40:03 -0700550 if not any ( intent.get('state') == 'WITHDRAWING' for intent
Devin Lim142b5342017-07-20 15:22:39 -0700551 in json.loads( ctrl.CLI.intents() ) ):
552 main.log.debug( json.loads( ctrl.CLI.intents() ) )
Devin Lim752dd7b2017-06-27 14:40:03 -0700553 removeResult = main.FALSE
554 break
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700555 else:
556 removeResult = main.TRUE
Jeremy7134f5b2016-04-05 13:50:21 -0700557 except ( TypeError, ValueError ):
Devin Lim142b5342017-07-20 15:22:39 -0700558 main.log.error( "Cannot see intents on " + main.Cluster.active( 0 ).name +
Jon Halle02505a2017-05-24 16:36:43 -0700559 ". Removing all intents." )
Devin Lim142b5342017-07-20 15:22:39 -0700560 main.Cluster.active( 0 ).CLI.removeAllIntents( purge=True )
561 main.Cluster.active( 0 ).CLI.removeAllIntents( purge=True, app='org.onosproject.optical' )
Jeremy7134f5b2016-04-05 13:50:21 -0700562
563 utilities.assert_equals( expect=main.TRUE,
564 actual=removeResult,
565 onpass="Successfully removed host intents",
Chiyu Chengef109502016-11-21 15:51:38 -0800566 onfail="Failed to remove host intents" )