blob: 12b3c8cc3a0976b6d4b65c6c7a3fa785edb2e0d2 [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.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:
104 main.cleanup()
105 main.exit()
106
acsmars51a7fe02015-10-29 18:33:32 -0700107 main.caseExplanation = "Start opticalTest.py topology included with ONOS"
108 main.step( "Starting mininet and LINC-OE" )
acsmars51a7fe02015-10-29 18:33:32 -0700109 time.sleep( 10 )
Devin Lim142b5342017-07-20 15:22:39 -0700110 controllerIPs = ','.join( main.Cluster.getIps() )
Devin Lim752dd7b2017-06-27 14:40:03 -0700111 cIps = ""
Devin Lim58046fa2017-07-05 16:55:00 -0700112 for i in range( 0, 4 ):
Devin Lim752dd7b2017-06-27 14:40:03 -0700113 cIps += controllerIPs + ' '
114 opticalMnScript = main.LincOE.runOpticalMnScript( ctrllerIP=cIps, topology=main.opticalTopo )
acsmars51a7fe02015-10-29 18:33:32 -0700115 topoResult = opticalMnScript
116 utilities.assert_equals(
117 expect=main.TRUE,
118 actual=topoResult,
119 onpass="Started the topology successfully ",
Jon Halle02505a2017-05-24 16:36:43 -0700120 onfail="Failed to start the topology" )
acsmars51a7fe02015-10-29 18:33:32 -0700121
acsmars51a7fe02015-10-29 18:33:32 -0700122 def CASE14( self, main ):
123 """
124 Stop mininet
125 """
Devin Lim58046fa2017-07-05 16:55:00 -0700126 try:
127 from tests.dependencies.utils import Utils
128 except ImportError:
129 main.log.error( "Utils not found exiting the test" )
130 main.exit()
131 try:
132 main.Utils
133 except ( NameError, AttributeError ):
134 main.Utils = Utils()
135 main.Utils.mininetCleanIntro()
136 topoResult = main.Utils.mininetCleanup( main.LincOE, timeout=180 )
acsmars51a7fe02015-10-29 18:33:32 -0700137 # Exit if topology did not load properly
138 if not topoResult:
139 main.cleanup()
140 main.exit()
141
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700142 def CASE16( self, main ):
143 """
144 Balance Masters
145 """
146 main.case( "Balance mastership of switches" )
147 main.step( "Balancing mastership of switches" )
148
149 balanceResult = main.FALSE
Devin Lim142b5342017-07-20 15:22:39 -0700150 balanceResult = utilities.retry( f=main.Cluster.active( 0 ).CLI.balanceMasters, retValue=main.FALSE, args=[] )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700151
152 utilities.assert_equals( expect=main.TRUE,
153 actual=balanceResult,
154 onpass="Successfully balanced mastership of switches",
155 onfail="Failed to balance mastership of switches" )
156 if not balanceResult:
157 main.initialized = main.FALSE
158
Jeremye4bc7132016-03-30 14:04:01 -0700159 def CASE17( self, main ):
160 """
161 Use Flow Objectives
162 """
163 main.case( "Enable intent compilation using Flow Objectives" )
164 main.step( "Enabling Flow Objectives" )
165
166 main.flowCompiler = "Flow Objectives"
167
168 cmd = "org.onosproject.net.intent.impl.compiler.IntentConfigurableRegistrator"
169
Devin Lim142b5342017-07-20 15:22:39 -0700170 stepResult = main.Cluster.active( 0 ).CLI.setCfg( component=cmd,
171 propName="useFlowObjectives", value="true" )
172 stepResult &= main.Cluster.active( 0 ).CLI.setCfg( component=cmd,
173 propName="defaultFlowObjectiveCompiler",
174 value='org.onosproject.net.intent.impl.compiler.LinkCollectionIntentObjectiveCompiler' )
Jeremye4bc7132016-03-30 14:04:01 -0700175
176 utilities.assert_equals( expect=main.TRUE,
177 actual=stepResult,
178 onpass="Successfully activated Flow Objectives",
179 onfail="Failed to activate Flow Objectives" )
180
Jeremy Songster17147f22016-05-31 18:30:52 -0700181 def CASE19( self, main ):
182 """
183 Copy the karaf.log files after each testcase cycle
184 """
Devin Lim58046fa2017-07-05 16:55:00 -0700185 try:
186 from tests.dependencies.utils import Utils
187 except ImportError:
188 main.log.error( "Utils not found exiting the test" )
189 main.exit()
190 try:
191 main.Utils
192 except ( NameError, AttributeError ):
193 main.Utils = Utils()
Devin Lim142b5342017-07-20 15:22:39 -0700194 main.Utils.copyKarafLog( "cycle" + str( main.cycle ) )
Jon Halle02505a2017-05-24 16:36:43 -0700195 def CASE21( self, main ):
acsmars51a7fe02015-10-29 18:33:32 -0700196 """
197 Run pingall to discover all hosts
198 """
199 main.case( "Running Pingall" )
200 main.caseExplanation = "Use pingall to discover all hosts. Pingall is expected to fail."
201 main.step( "Discover Hosts through Pingall" )
Jon Halle02505a2017-05-24 16:36:43 -0700202 pingResult = main.LincOE.pingall( timeout=120 )
acsmars51a7fe02015-10-29 18:33:32 -0700203
204 utilities.assert_equals( expect=main.FALSE,
205 actual=pingResult,
206 onpass="Pingall Completed",
207 onfail="Pingall did not complete or did not return fales" )
208
Jon Halle02505a2017-05-24 16:36:43 -0700209 def CASE22( self, main ):
acsmars51a7fe02015-10-29 18:33:32 -0700210 """
211 Send arpings to discover all hosts
212 """
213 main.case( "Discover Hosts with arping" )
214 main.caseExplanation = "Send arpings between all the hosts to discover and verify them"
215
216 main.step( "Send arping between all hosts" )
217
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700218 hosts = []
219 for i in range( main.hosts ):
220 hosts.append( 'h{}'.format( i + 1 ) )
acsmars51a7fe02015-10-29 18:33:32 -0700221
222 arpingHostResults = main.TRUE
223 for host in hosts:
Devin Lim752dd7b2017-06-27 14:40:03 -0700224 if main.LincOE.arping( host, ethDevice=host+"-eth0" ):
acsmars51a7fe02015-10-29 18:33:32 -0700225 main.log.info( "Successfully reached host {} with arping".format( host ) )
226 else:
227 main.log.error( "Could not reach host {} with arping".format( host ) )
228 arpingHostResults = main.FALSE
229
230 utilities.assert_equals( expect=main.TRUE,
231 actual=arpingHostResults,
232 onpass="Successfully discovered all hosts",
233 onfail="Could not descover some hosts" )
234
235 def CASE23( self, main ):
236 """
237 Compare ONOS Topology to Mininet Topology
238 """
239 import json
Devin Lim58046fa2017-07-05 16:55:00 -0700240 try:
241 from tests.dependencies.topology import Topology
242 except ImportError:
243 main.log.error( "Topology not found exiting the test" )
244 main.exit()
245 try:
246 main.topoRelated
247 except ( NameError, AttributeError ):
248 main.topoRelated = Topology()
acsmars51a7fe02015-10-29 18:33:32 -0700249 main.case( "Compare ONOS Topology view to Mininet topology" )
250 main.caseExplanation = "Compare topology elements between Mininet" +\
251 " and ONOS"
252
253 main.log.info( "Gathering topology information from Mininet" )
254 devicesResults = main.FALSE # Overall Boolean for device correctness
255 linksResults = main.FALSE # Overall Boolean for link correctness
256 hostsResults = main.FALSE # Overall Boolean for host correctness
257 deviceFails = [] # Nodes where devices are incorrect
258 linkFails = [] # Nodes where links are incorrect
259 hostFails = [] # Nodes where hosts are incorrect
260 attempts = main.checkTopoAttempts # Remaining Attempts
261
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700262 mnSwitches = main.switches
263 mnLinks = main.links
264 mnHosts = main.hosts
acsmars51a7fe02015-10-29 18:33:32 -0700265
Jon Hall70b2ff42015-11-17 15:49:44 -0800266 main.step( "Comparing Mininet topology to ONOS topology" )
acsmars51a7fe02015-10-29 18:33:32 -0700267
268 while ( attempts >= 0 ) and\
Jon Halle02505a2017-05-24 16:36:43 -0700269 ( not devicesResults or not linksResults or not hostsResults ):
acsmars51a7fe02015-10-29 18:33:32 -0700270 time.sleep( 2 )
271 if not devicesResults:
Devin Lim142b5342017-07-20 15:22:39 -0700272 devices = main.topoRelated.getAll( "devices", False )
273 ports = main.topoRelated.getAll( "ports", False )
acsmars51a7fe02015-10-29 18:33:32 -0700274 devicesResults = main.TRUE
275 deviceFails = [] # Reset for each attempt
276 if not linksResults:
Devin Lim142b5342017-07-20 15:22:39 -0700277 links = main.topoRelated.getAll( "links", False )
acsmars51a7fe02015-10-29 18:33:32 -0700278 linksResults = main.TRUE
279 linkFails = [] # Reset for each attempt
280 if not hostsResults:
Devin Lim142b5342017-07-20 15:22:39 -0700281 hosts = main.topoRelated.getAll( "hosts", False )
acsmars51a7fe02015-10-29 18:33:32 -0700282 hostsResults = main.TRUE
283 hostFails = [] # Reset for each attempt
284
285 # Check for matching topology on each node
Devin Lim142b5342017-07-20 15:22:39 -0700286 for controller in range( main.Cluster.numCtrls ):
acsmars51a7fe02015-10-29 18:33:32 -0700287 controllerStr = str( controller + 1 ) # ONOS node number
288 # Compare Devices
289 if devices[ controller ] and ports[ controller ] and\
Jon Halle02505a2017-05-24 16:36:43 -0700290 "Error" not in devices[ controller ] and\
291 "Error" not in ports[ controller ]:
acsmars51a7fe02015-10-29 18:33:32 -0700292
293 try:
294 deviceData = json.loads( devices[ controller ] )
295 portData = json.loads( ports[ controller ] )
Jon Halle02505a2017-05-24 16:36:43 -0700296 except ( TypeError, ValueError ):
297 main.log.error( "Could not load json:" + str( devices[ controller ] ) + ' or ' + str( ports[ controller ] ) )
acsmars51a7fe02015-10-29 18:33:32 -0700298 currentDevicesResult = main.FALSE
299 else:
300 if mnSwitches == len( deviceData ):
301 currentDevicesResult = main.TRUE
302 else:
303 currentDevicesResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700304 main.log.error( "Node {} only sees {} device(s) but {} exist".format(
Jon Halle02505a2017-05-24 16:36:43 -0700305 controllerStr, len( deviceData ), mnSwitches ) )
acsmars51a7fe02015-10-29 18:33:32 -0700306 else:
307 currentDevicesResult = main.FALSE
308 if not currentDevicesResult:
309 deviceFails.append( controllerStr )
310 devicesResults = devicesResults and currentDevicesResult
311 # Compare Links
312 if links[ controller ] and "Error" not in links[ controller ]:
313 try:
314 linkData = json.loads( links[ controller ] )
Jon Halle02505a2017-05-24 16:36:43 -0700315 except ( TypeError, ValueError ):
316 main.log.error( "Could not load json:" + str( links[ controller ] ) )
acsmars51a7fe02015-10-29 18:33:32 -0700317 currentLinksResult = main.FALSE
318 else:
319 if mnLinks == len( linkData ):
320 currentLinksResult = main.TRUE
321 else:
322 currentLinksResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700323 main.log.error( "Node {} only sees {} link(s) but {} exist".format(
Jon Halle02505a2017-05-24 16:36:43 -0700324 controllerStr, len( linkData ), mnLinks ) )
acsmars51a7fe02015-10-29 18:33:32 -0700325 else:
326 currentLinksResult = main.FALSE
327 if not currentLinksResult:
328 linkFails.append( controllerStr )
329 linksResults = linksResults and currentLinksResult
330 # Compare Hosts
331 if hosts[ controller ] and "Error" not in hosts[ controller ]:
332 try:
333 hostData = json.loads( hosts[ controller ] )
Jon Halle02505a2017-05-24 16:36:43 -0700334 except ( TypeError, ValueError ):
335 main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
acsmars51a7fe02015-10-29 18:33:32 -0700336 currentHostsResult = main.FALSE
337 else:
338 if mnHosts == len( hostData ):
339 currentHostsResult = main.TRUE
340 else:
341 currentHostsResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700342 main.log.error( "Node {} only sees {} host(s) but {} exist".format(
Jon Halle02505a2017-05-24 16:36:43 -0700343 controllerStr, len( hostData ), mnHosts ) )
acsmars51a7fe02015-10-29 18:33:32 -0700344 else:
345 currentHostsResult = main.FALSE
346 if not currentHostsResult:
347 hostFails.append( controllerStr )
348 hostsResults = hostsResults and currentHostsResult
349 # Decrement Attempts Remaining
350 attempts -= 1
351
352 utilities.assert_equals( expect=[],
353 actual=deviceFails,
354 onpass="ONOS correctly discovered all devices",
355 onfail="ONOS incorrectly discovered devices on nodes: " +
356 str( deviceFails ) )
357 utilities.assert_equals( expect=[],
358 actual=linkFails,
359 onpass="ONOS correctly discovered all links",
360 onfail="ONOS incorrectly discovered links on nodes: " +
361 str( linkFails ) )
362 utilities.assert_equals( expect=[],
363 actual=hostFails,
364 onpass="ONOS correctly discovered all hosts",
365 onfail="ONOS incorrectly discovered hosts on nodes: " +
366 str( hostFails ) )
367 if hostsResults and linksResults and devicesResults:
368 topoResults = main.TRUE
369 else:
370 topoResults = main.FALSE
371 utilities.assert_equals( expect=main.TRUE,
372 actual=topoResults,
373 onpass="ONOS correctly discovered the topology",
374 onfail="ONOS incorrectly discovered the topology" )
375
Devin Lim58046fa2017-07-05 16:55:00 -0700376
acsmars51a7fe02015-10-29 18:33:32 -0700377 def CASE31( self, main ):
378 import time
379 """
380 Add bidirectional point intents between 2 packet layer( mininet )
381 devices and ping mininet hosts
382 """
383 main.log.report(
384 "This testcase adds bidirectional point intents between 2 " +
385 "packet layer( mininet ) devices and ping mininet hosts" )
386 main.case( "Install point intents between 2 packet layer device and " +
387 "ping the hosts" )
388 main.caseExplanation = "This testcase adds bidirectional point intents between 2 " +\
389 "packet layer( mininet ) devices and ping mininet hosts"
390
391 main.step( "Adding point intents" )
392 checkFlowResult = main.TRUE
393 main.pIntentsId = []
Devin Lim142b5342017-07-20 15:22:39 -0700394 pIntent1 = main.Cluster.active( 0 ).CLI.addPointIntent(
Devin Lim752dd7b2017-06-27 14:40:03 -0700395 "of:0000000000000015/1",
396 "of:000000000000000b/2" )
acsmars51a7fe02015-10-29 18:33:32 -0700397 time.sleep( 10 )
Devin Lim142b5342017-07-20 15:22:39 -0700398 pIntent2 = main.Cluster.active( 0 ).CLI.addPointIntent(
Devin Lim752dd7b2017-06-27 14:40:03 -0700399 "of:000000000000000b/2",
400 "of:0000000000000015/1" )
acsmars51a7fe02015-10-29 18:33:32 -0700401 main.pIntentsId.append( pIntent1 )
402 main.pIntentsId.append( pIntent2 )
403 time.sleep( 10 )
Jon Halle02505a2017-05-24 16:36:43 -0700404 main.log.info( "Checking intents state" )
Devin Lim142b5342017-07-20 15:22:39 -0700405 checkStateResult = main.Cluster.active( 0 ).CLI.checkIntentState(
406 intentsId=main.pIntentsId )
acsmars51a7fe02015-10-29 18:33:32 -0700407 time.sleep( 10 )
Devin Lim142b5342017-07-20 15:22:39 -0700408 checkStateResult = utilities.retry( f=main.Cluster.active( 0 ).CLI.checkIntentState,
Devin Lim752dd7b2017-06-27 14:40:03 -0700409 retValue=main.FALSE, args=( main.pIntentsId, "INSTALLED" ),
410 sleep=main.checkIntentSleep, attempts=10 )
Jon Halle02505a2017-05-24 16:36:43 -0700411 main.log.info( "Checking flows state" )
Devin Lim142b5342017-07-20 15:22:39 -0700412 checkFlowResult = main.Cluster.active( 0 ).CLI.checkFlowsState()
acsmars51a7fe02015-10-29 18:33:32 -0700413 # Sleep for 10 seconds to provide time for the intent state to change
414 time.sleep( 10 )
Jon Halle02505a2017-05-24 16:36:43 -0700415 main.log.info( "Checking intents state one more time" )
Devin Lim142b5342017-07-20 15:22:39 -0700416 checkStateResult = main.Cluster.active( 0 ).CLI.checkIntentState(
Jon Halle02505a2017-05-24 16:36:43 -0700417 intentsId=main.pIntentsId )
Jeremye4bc7132016-03-30 14:04:01 -0700418
acsmars51a7fe02015-10-29 18:33:32 -0700419 if checkStateResult and checkFlowResult:
420 addIntentsResult = main.TRUE
421 else:
422 addIntentsResult = main.FALSE
423 utilities.assert_equals(
424 expect=main.TRUE,
425 actual=addIntentsResult,
426 onpass="Successfully added point intents",
Jon Halle02505a2017-05-24 16:36:43 -0700427 onfail="Failed to add point intents" )
acsmars51a7fe02015-10-29 18:33:32 -0700428
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700429 pingResult = main.FALSE
acsmars51a7fe02015-10-29 18:33:32 -0700430
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700431 if not addIntentsResult:
432 main.log.error( "Intents were not properly installed. Skipping ping." )
433
434 else:
435 main.step( "Ping h1 and h2" )
436 pingResult = main.LincOE.pingHostOptical( src="h1", target="h2" )
acsmars51a7fe02015-10-29 18:33:32 -0700437 utilities.assert_equals(
438 expect=main.TRUE,
439 actual=pingResult,
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700440 onpass="Successfully pinged h1 and h2",
Jon Halle02505a2017-05-24 16:36:43 -0700441 onfail="Failed to ping between h1 and h2" )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700442
443 main.step( "Remove Point to Point intents" )
Devin Lim752dd7b2017-06-27 14:40:03 -0700444 removeResult = main.TRUE
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700445 # Check remaining intents
446 try:
Devin Lim142b5342017-07-20 15:22:39 -0700447 intentsJson = json.loads( main.Cluster.active( 0 ).CLI.intents() )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700448 main.log.debug( intentsJson )
Devin Lim142b5342017-07-20 15:22:39 -0700449 main.Cluster.active( 0 ).CLI.removeIntent( intentId=pIntent1, purge=True )
450 main.Cluster.active( 0 ).CLI.removeIntent( intentId=pIntent2, purge=True )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700451 for intents in intentsJson:
Devin Lim142b5342017-07-20 15:22:39 -0700452 main.Cluster.active( 0 ).CLI.removeIntent( intentId=intents.get( 'id' ),
453 app='org.onosproject.cli',
454 purge=True )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700455 time.sleep( 15 )
456
Devin Lim142b5342017-07-20 15:22:39 -0700457 for ctrl in main.Cluster.active():
Devin Lim752dd7b2017-06-27 14:40:03 -0700458 if not any ( intent.get('state') == 'WITHDRAWING' for intent
Devin Lim142b5342017-07-20 15:22:39 -0700459 in json.loads( ctrl.CLI.intents() ) ):
460 main.log.debug( json.loads( ctrl.CLI.intents() ) )
Devin Lim752dd7b2017-06-27 14:40:03 -0700461 removeResult = main.FALSE
462 break
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700463 else:
464 removeResult = main.TRUE
465 except ( TypeError, ValueError ):
Devin Lim142b5342017-07-20 15:22:39 -0700466 main.log.error( "Cannot see intents on " + main.Cluster.active( 0 ).name +
Jon Halle02505a2017-05-24 16:36:43 -0700467 ". Removing all intents." )
Devin Lim142b5342017-07-20 15:22:39 -0700468 main.Cluster.active( 0 ).CLI.removeAllIntents( purge=True )
469 main.Cluster.active( 0 ).CLI.removeAllIntents( purge=True, app='org.onosproject.cli' )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700470
471 utilities.assert_equals( expect=main.TRUE,
472 actual=removeResult,
473 onpass="Successfully removed host intents",
474 onfail="Failed to remove host intents" )
acsmars51a7fe02015-10-29 18:33:32 -0700475
476 def CASE32( self ):
477 """
478 Add host intents between 2 packet layer host
479 """
480 import time
481 import json
482 main.log.report( "Adding host intents between 2 optical layer host" )
483 main.case( "Test add host intents between optical layer host" )
484 main.caseExplanation = "Test host intents between 2 optical layer host"
485
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700486 main.step( "Creating list of hosts" )
487 hostnum = 0
488 try:
489 hostData = json.loads( hosts[ controller ] )
490 except( TypeError, ValueError ):
Jon Halle02505a2017-05-24 16:36:43 -0700491 main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700492
acsmars51a7fe02015-10-29 18:33:32 -0700493 main.step( "Adding host intents to h1 and h2" )
acsmars51a7fe02015-10-29 18:33:32 -0700494 hostId = []
495 # Listing host MAC addresses
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700496 for host in hostData:
Jon Halle02505a2017-05-24 16:36:43 -0700497 hostId.append( host.get( "id" ) )
acsmars51a7fe02015-10-29 18:33:32 -0700498 host1 = hostId[ 0 ]
499 host2 = hostId[ 1 ]
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700500 main.log.debug( host1 )
501 main.log.debug( host2 )
acsmars51a7fe02015-10-29 18:33:32 -0700502
503 intentsId = []
Devin Lim142b5342017-07-20 15:22:39 -0700504 intent1 = main.Cluster.active( 0 ).CLI.addHostIntent( hostIdOne=host1,
505 hostIdTwo=host2 )
acsmars51a7fe02015-10-29 18:33:32 -0700506 intentsId.append( intent1 )
507 # Checking intents state before pinging
508 main.log.info( "Checking intents state" )
Devin Lim142b5342017-07-20 15:22:39 -0700509 intentResult = utilities.retry( f=main.Cluster.active( 0 ).CLI.checkIntentState,
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700510 retValue=main.FALSE, args=intentsId,
511 sleep=main.checkIntentSleep, attempts=10 )
acsmars51a7fe02015-10-29 18:33:32 -0700512
513 # If intent state is still wrong, display intent states
514 if not intentResult:
Devin Lim142b5342017-07-20 15:22:39 -0700515 main.log.error( main.Cluster.active( 0 ).CLI.intents() )
Jeremye4bc7132016-03-30 14:04:01 -0700516
acsmars51a7fe02015-10-29 18:33:32 -0700517 utilities.assert_equals( expect=main.TRUE,
518 actual=intentResult,
519 onpass="All intents are in INSTALLED state ",
520 onfail="Some of the intents are not in " +
521 "INSTALLED state " )
522
523 if not intentResult:
524 main.log.error( "Intents were not properly installed. Skipping Ping" )
525 else:
526 # Pinging h1 to h2 and then ping h2 to h1
527 main.step( "Pinging h1 and h2" )
528 pingResult = main.TRUE
529 pingResult = main.LincOE.pingHostOptical( src="h1", target="h2" ) \
Jon Halle02505a2017-05-24 16:36:43 -0700530 and main.LincOE.pingHostOptical( src="h2", target="h1" )
Jeremye4bc7132016-03-30 14:04:01 -0700531
acsmars51a7fe02015-10-29 18:33:32 -0700532 utilities.assert_equals( expect=main.TRUE,
533 actual=pingResult,
534 onpass="Pinged successfully between h1 and h2",
535 onfail="Pinged failed between h1 and h2" )
536
537 # Removed all added host intents
538 main.step( "Removing host intents" )
539 removeResult = main.TRUE
540 # Check remaining intents
Jeremy7134f5b2016-04-05 13:50:21 -0700541 try:
Devin Lim142b5342017-07-20 15:22:39 -0700542 intentsJson = json.loads( main.Cluster.active( 0 ).CLI.intents() )
543 main.Cluster.active( 0 ).CLI.removeIntent( intentId=intent1, purge=True )
Jon Halle02505a2017-05-24 16:36:43 -0700544 main.log.debug( intentsJson )
Jeremy7134f5b2016-04-05 13:50:21 -0700545 for intents in intentsJson:
Devin Lim142b5342017-07-20 15:22:39 -0700546 main.Cluster.active( 0 ).CLI.removeIntent( intentId=intents.get( 'id' ),
547 app='org.onosproject.optical',
548 purge=True )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700549 time.sleep( 15 )
acsmars51a7fe02015-10-29 18:33:32 -0700550
Devin Lim142b5342017-07-20 15:22:39 -0700551 for ctrl in main.Cluster.active():
Devin Lim752dd7b2017-06-27 14:40:03 -0700552 if not any ( intent.get('state') == 'WITHDRAWING' for intent
Devin Lim142b5342017-07-20 15:22:39 -0700553 in json.loads( ctrl.CLI.intents() ) ):
554 main.log.debug( json.loads( ctrl.CLI.intents() ) )
Devin Lim752dd7b2017-06-27 14:40:03 -0700555 removeResult = main.FALSE
556 break
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700557 else:
558 removeResult = main.TRUE
Jeremy7134f5b2016-04-05 13:50:21 -0700559 except ( TypeError, ValueError ):
Devin Lim142b5342017-07-20 15:22:39 -0700560 main.log.error( "Cannot see intents on " + main.Cluster.active( 0 ).name +
Jon Halle02505a2017-05-24 16:36:43 -0700561 ". Removing all intents." )
Devin Lim142b5342017-07-20 15:22:39 -0700562 main.Cluster.active( 0 ).CLI.removeAllIntents( purge=True )
563 main.Cluster.active( 0 ).CLI.removeAllIntents( purge=True, app='org.onosproject.optical' )
Jeremy7134f5b2016-04-05 13:50:21 -0700564
565 utilities.assert_equals( expect=main.TRUE,
566 actual=removeResult,
567 onpass="Successfully removed host intents",
Chiyu Chengef109502016-11-21 15:51:38 -0800568 onfail="Failed to remove host intents" )